GDB (xrefs)
Loading...
Searching...
No Matches
break-catch-exec.c
Go to the documentation of this file.
1/* Everything about exec catchpoints, for GDB.
2
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21
22#include "annotate.h"
23#include "arch-utils.h"
24#include "breakpoint.h"
25#include "cli/cli-decode.h"
26#include "inferior.h"
27#include "mi/mi-common.h"
28#include "target.h"
29#include "valprint.h"
30
31/* Exec catchpoints. */
32
33/* An instance of this type is used to represent an exec catchpoint.
34 A breakpoint is really of this type iff its ops pointer points to
35 CATCH_EXEC_BREAKPOINT_OPS. */
36
38{
39 exec_catchpoint (struct gdbarch *gdbarch, bool temp, const char *cond_string)
41 {
42 }
43
44 int insert_location (struct bp_location *) override;
45 int remove_location (struct bp_location *,
46 enum remove_bp_reason reason) override;
47 int breakpoint_hit (const struct bp_location *bl,
48 const address_space *aspace,
49 CORE_ADDR bp_addr,
50 const target_waitstatus &ws) override;
51 enum print_stop_action print_it (const bpstat *bs) const override;
52 bool print_one (const bp_location **) const override;
53 void print_mention () const override;
54 void print_recreate (struct ui_file *fp) const override;
55
56 /* Filename of a program whose exec triggered this catchpoint.
57 This field is only valid immediately after this catchpoint has
58 triggered. */
59 gdb::unique_xmalloc_ptr<char> exec_pathname;
60};
61
62int
67
68int
74
75int
77 const address_space *aspace,
78 CORE_ADDR bp_addr,
79 const target_waitstatus &ws)
80{
81 if (ws.kind () != TARGET_WAITKIND_EXECD)
82 return 0;
83
84 exec_pathname = make_unique_xstrdup (ws.execd_pathname ());
85 return 1;
86}
87
90{
91 struct ui_out *uiout = current_uiout;
92
95 if (disposition == disp_del)
96 uiout->text ("Temporary catchpoint ");
97 else
98 uiout->text ("Catchpoint ");
99 if (uiout->is_mi_like_p ())
100 {
102 uiout->field_string ("disp", bpdisp_text (disposition));
103 }
104 uiout->field_signed ("bkptno", number);
105 uiout->text (" (exec'd ");
106 uiout->field_string ("new-exec", exec_pathname.get ());
107 uiout->text ("), ");
108
109 return PRINT_SRC_AND_LOC;
110}
111
112bool
114{
115 struct value_print_options opts;
116 struct ui_out *uiout = current_uiout;
117
119
120 /* Field 4, the address, is omitted (which makes the columns
121 not line up too nicely with the headers, but the effect
122 is relatively readable). */
123 if (opts.addressprint)
124 uiout->field_skip ("addr");
125 annotate_field (5);
126 uiout->text ("exec");
127 if (exec_pathname != NULL)
128 {
129 uiout->text (", program \"");
130 uiout->field_string ("what", exec_pathname.get ());
131 uiout->text ("\" ");
132 }
133
134 if (uiout->is_mi_like_p ())
135 uiout->field_string ("catch-type", "exec");
136
137 return true;
138}
139
140void
142{
143 gdb_printf (_("Catchpoint %d (exec)"), number);
144}
145
146/* Implement the "print_recreate" method for exec catchpoints. */
147
148void
150{
151 gdb_printf (fp, "catch exec");
153}
154
155/* This function attempts to parse an optional "if <cond>" clause
156 from the arg string. If one is not found, it returns NULL.
157
158 Else, it returns a pointer to the condition string. (It does not
159 attempt to evaluate the string against a particular block.) And,
160 it updates arg to point to the first character following the parsed
161 if clause in the arg string. */
162
163const char *
165{
166 const char *cond_string;
167
168 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
169 return NULL;
170
171 /* Skip the "if" keyword. */
172 (*arg) += 2;
173
174 /* Skip any extra leading whitespace, and record the start of the
175 condition string. */
176 *arg = skip_spaces (*arg);
177 cond_string = *arg;
178
179 /* Assume that the condition occupies the remainder of the arg
180 string. */
181 (*arg) += strlen (cond_string);
182
183 return cond_string;
184}
185
186/* Commands to deal with catching events, such as signals, exceptions,
187 process start/exit, etc. */
188
189static void
190catch_exec_command_1 (const char *arg, int from_tty,
191 struct cmd_list_element *command)
192{
193 struct gdbarch *gdbarch = get_current_arch ();
194 const char *cond_string = NULL;
195 bool temp = command->context () == CATCH_TEMPORARY;
196
197 if (!arg)
198 arg = "";
199 arg = skip_spaces (arg);
200
201 /* The allowed syntax is:
202 catch exec
203 catch exec if <cond>
204
205 First, check if there's an if clause. */
206 cond_string = ep_parse_optional_if_clause (&arg);
207
208 if ((*arg != '\0') && !isspace (*arg))
209 error (_("Junk at end of arguments."));
210
211 std::unique_ptr<exec_catchpoint> c
212 (new exec_catchpoint (gdbarch, temp, cond_string));
213
214 install_breakpoint (0, std::move (c), 1);
215}
216
218void
220{
221 add_catch_command ("exec", _("Catch calls to exec."),
223 NULL,
226}
void annotate_field(int num)
Definition annotate.c:172
void annotate_catchpoint(int num)
Definition annotate.c:82
struct gdbarch * get_current_arch(void)
Definition arch-utils.c:846
void _initialize_break_catch_exec()
static void catch_exec_command_1(const char *arg, int from_tty, struct cmd_list_element *command)
const char * ep_parse_optional_if_clause(const char **arg)
void add_catch_command(const char *name, const char *docstring, cmd_func_ftype *func, completer_ftype *completer, void *user_data_catch, void *user_data_tcatch)
const char * bpdisp_text(enum bpdisp disp)
Definition breakpoint.c:505
breakpoint * install_breakpoint(int internal, std::unique_ptr< breakpoint > &&arg, int update_gll)
void maybe_print_thread_hit_breakpoint(struct ui_out *uiout)
#define CATCH_PERMANENT
@ disp_del
Definition breakpoint.h:237
#define CATCH_TEMPORARY
print_stop_action
Definition breakpoint.h:542
@ PRINT_SRC_AND_LOC
Definition breakpoint.h:548
remove_bp_reason
Definition breakpoint.h:64
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition ui-out.c:511
void field_signed(const char *fldname, LONGEST value)
Definition ui-out.c:437
void field_skip(const char *fldname)
Definition ui-out.c:499
void text(const char *string)
Definition ui-out.c:566
bool is_mi_like_p() const
Definition ui-out.c:810
ptid_t inferior_ptid
Definition infcmd.c:74
const char * async_reason_lookup(enum async_reply_reason reason)
Definition mi-common.c:50
@ EXEC_ASYNC_EXEC
Definition mi-common.h:44
gdb::unique_xmalloc_ptr< char > cond_string
Definition breakpoint.h:850
void print_recreate_thread(struct ui_file *fp) const
bpdisp disposition
Definition breakpoint.h:802
void * context() const
Definition cli-decode.h:109
gdb::unique_xmalloc_ptr< char > exec_pathname
exec_catchpoint(struct gdbarch *gdbarch, bool temp, const char *cond_string)
bool print_one(const bp_location **) const override
void print_recreate(struct ui_file *fp) const override
int insert_location(struct bp_location *) override
enum print_stop_action print_it(const bpstat *bs) const override
int breakpoint_hit(const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, const target_waitstatus &ws) override
int remove_location(struct bp_location *, enum remove_bp_reason reason) override
void print_mention() const override
target_waitkind kind() const
Definition waitstatus.h:345
int target_remove_exec_catchpoint(int pid)
Definition target.c:346
int target_insert_exec_catchpoint(int pid)
Definition target.c:338
#define current_uiout
Definition ui-out.h:40
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
void get_user_print_options(struct value_print_options *opts)
Definition valprint.c:135
@ TARGET_WAITKIND_EXECD
Definition waitstatus.h:57