Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
28e7fd62 | 3 | Copyright (C) 1986-2013 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
35 | #include "gdbthread.h" | |
36 | #include "target.h" | |
37 | #include "language.h" | |
38 | #include "gdb_string.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
0225421b | 50 | #include "gdb_assert.h" |
fe898f56 | 51 | #include "block.h" |
a77053c2 | 52 | #include "solib.h" |
84acb35a JJ |
53 | #include "solist.h" |
54 | #include "observer.h" | |
60250e8b | 55 | #include "exceptions.h" |
765dc015 | 56 | #include "memattr.h" |
f7f9143b | 57 | #include "ada-lang.h" |
d1aa2f50 | 58 | #include "top.h" |
79a45b7d | 59 | #include "valprint.h" |
4efc6507 | 60 | #include "jit.h" |
a96d9b2e | 61 | #include "xml-syscall.h" |
65d79d4b | 62 | #include "parser-defs.h" |
55aa24fb SDJ |
63 | #include "gdb_regex.h" |
64 | #include "probe.h" | |
e9cafbcc | 65 | #include "cli/cli-utils.h" |
be34f849 | 66 | #include "continuations.h" |
1bfeeb0f JL |
67 | #include "stack.h" |
68 | #include "skip.h" | |
edcc5120 | 69 | #include "gdb_regex.h" |
b775012e | 70 | #include "ax-gdb.h" |
e2e4d78b | 71 | #include "dummy-frame.h" |
c906108c | 72 | |
d3ce09f5 SS |
73 | #include "format.h" |
74 | ||
1042e4c0 SS |
75 | /* readline include files */ |
76 | #include "readline/readline.h" | |
77 | #include "readline/history.h" | |
78 | ||
79 | /* readline defines this. */ | |
80 | #undef savestring | |
81 | ||
034dad6f | 82 | #include "mi/mi-common.h" |
7371cf6d | 83 | #include "python/python.h" |
104c1213 | 84 | |
e7e8980f YQ |
85 | /* Enums for exception-handling support. */ |
86 | enum exception_event_kind | |
87 | { | |
88 | EX_EVENT_THROW, | |
591f19e8 | 89 | EX_EVENT_RETHROW, |
e7e8980f YQ |
90 | EX_EVENT_CATCH |
91 | }; | |
92 | ||
4a64f543 | 93 | /* Prototypes for local functions. */ |
c906108c | 94 | |
a14ed312 | 95 | static void enable_delete_command (char *, int); |
c906108c | 96 | |
a14ed312 | 97 | static void enable_once_command (char *, int); |
c906108c | 98 | |
816338b5 SS |
99 | static void enable_count_command (char *, int); |
100 | ||
a14ed312 | 101 | static void disable_command (char *, int); |
c906108c | 102 | |
a14ed312 | 103 | static void enable_command (char *, int); |
c906108c | 104 | |
95a42b64 TT |
105 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
106 | void *), | |
107 | void *); | |
c906108c | 108 | |
a14ed312 | 109 | static void ignore_command (char *, int); |
c906108c | 110 | |
4efb68b1 | 111 | static int breakpoint_re_set_one (void *); |
c906108c | 112 | |
348d480f PA |
113 | static void breakpoint_re_set_default (struct breakpoint *); |
114 | ||
983af33b SDJ |
115 | static void create_sals_from_address_default (char **, |
116 | struct linespec_result *, | |
117 | enum bptype, char *, | |
118 | char **); | |
119 | ||
120 | static void create_breakpoints_sal_default (struct gdbarch *, | |
121 | struct linespec_result *, | |
122 | struct linespec_sals *, | |
e7e0cddf | 123 | char *, char *, enum bptype, |
983af33b SDJ |
124 | enum bpdisp, int, int, |
125 | int, | |
126 | const struct breakpoint_ops *, | |
44f238bb | 127 | int, int, int, unsigned); |
983af33b SDJ |
128 | |
129 | static void decode_linespec_default (struct breakpoint *, char **, | |
130 | struct symtabs_and_lines *); | |
131 | ||
a14ed312 | 132 | static void clear_command (char *, int); |
c906108c | 133 | |
a14ed312 | 134 | static void catch_command (char *, int); |
c906108c | 135 | |
a9634178 | 136 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 137 | |
98deb0da | 138 | static void break_command_1 (char *, int, int); |
c906108c | 139 | |
a14ed312 | 140 | static void mention (struct breakpoint *); |
c906108c | 141 | |
348d480f PA |
142 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
143 | enum bptype, | |
c0a91b2b | 144 | const struct breakpoint_ops *); |
3742cc8b YQ |
145 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
146 | const struct symtab_and_line *); | |
147 | ||
4a64f543 MS |
148 | /* This function is used in gdbtk sources and thus can not be made |
149 | static. */ | |
63c252f8 | 150 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 151 | struct symtab_and_line, |
c0a91b2b TT |
152 | enum bptype, |
153 | const struct breakpoint_ops *); | |
c906108c | 154 | |
06edf0c0 PA |
155 | static struct breakpoint * |
156 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
157 | enum bptype type, | |
c0a91b2b | 158 | const struct breakpoint_ops *ops); |
06edf0c0 | 159 | |
76897487 KB |
160 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
161 | ||
a6d9a66e UW |
162 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
163 | CORE_ADDR bpaddr, | |
88f7da05 | 164 | enum bptype bptype); |
76897487 | 165 | |
6c95b8df PA |
166 | static void describe_other_breakpoints (struct gdbarch *, |
167 | struct program_space *, CORE_ADDR, | |
5af949e3 | 168 | struct obj_section *, int); |
c906108c | 169 | |
6c95b8df PA |
170 | static int breakpoint_address_match (struct address_space *aspace1, |
171 | CORE_ADDR addr1, | |
172 | struct address_space *aspace2, | |
173 | CORE_ADDR addr2); | |
174 | ||
85d721b8 PA |
175 | static int watchpoint_locations_match (struct bp_location *loc1, |
176 | struct bp_location *loc2); | |
177 | ||
f1310107 TJB |
178 | static int breakpoint_location_address_match (struct bp_location *bl, |
179 | struct address_space *aspace, | |
180 | CORE_ADDR addr); | |
181 | ||
a14ed312 | 182 | static void breakpoints_info (char *, int); |
c906108c | 183 | |
d77f58be SS |
184 | static void watchpoints_info (char *, int); |
185 | ||
e5a67952 MS |
186 | static int breakpoint_1 (char *, int, |
187 | int (*) (const struct breakpoint *)); | |
c906108c | 188 | |
4efb68b1 | 189 | static int breakpoint_cond_eval (void *); |
c906108c | 190 | |
4efb68b1 | 191 | static void cleanup_executing_breakpoints (void *); |
c906108c | 192 | |
a14ed312 | 193 | static void commands_command (char *, int); |
c906108c | 194 | |
a14ed312 | 195 | static void condition_command (char *, int); |
c906108c | 196 | |
c5aa993b JM |
197 | typedef enum |
198 | { | |
199 | mark_inserted, | |
200 | mark_uninserted | |
201 | } | |
202 | insertion_state_t; | |
c906108c | 203 | |
0bde7532 | 204 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 205 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 206 | |
e514a9d6 | 207 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 208 | |
4efb68b1 | 209 | static int watchpoint_check (void *); |
c906108c | 210 | |
a14ed312 | 211 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 212 | |
a14ed312 | 213 | static int hw_breakpoint_used_count (void); |
c906108c | 214 | |
a1398e0c PA |
215 | static int hw_watchpoint_use_count (struct breakpoint *); |
216 | ||
217 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
218 | enum bptype type, | |
219 | int *other_type_used); | |
c906108c | 220 | |
a14ed312 | 221 | static void hbreak_command (char *, int); |
c906108c | 222 | |
a14ed312 | 223 | static void thbreak_command (char *, int); |
c906108c | 224 | |
816338b5 SS |
225 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
226 | int count); | |
c906108c | 227 | |
a14ed312 | 228 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 229 | |
a14ed312 | 230 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 231 | |
a14ed312 | 232 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 233 | |
a14ed312 | 234 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 235 | |
d85310f7 MS |
236 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
237 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 238 | |
a14ed312 | 239 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 240 | |
d03285ec UW |
241 | static void detach_single_step_breakpoints (void); |
242 | ||
6c95b8df PA |
243 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
244 | CORE_ADDR pc); | |
1aafd4da | 245 | |
fe3f5fa8 | 246 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
247 | static void incref_bp_location (struct bp_location *loc); |
248 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 249 | |
39d61571 | 250 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 251 | |
b60e7edf | 252 | static void update_global_location_list (int); |
a5606eee | 253 | |
b60e7edf | 254 | static void update_global_location_list_nothrow (int); |
74960c60 | 255 | |
d77f58be | 256 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
257 | |
258 | static void insert_breakpoint_locations (void); | |
a5606eee | 259 | |
a96d9b2e SDJ |
260 | static int syscall_catchpoint_p (struct breakpoint *b); |
261 | ||
1042e4c0 SS |
262 | static void tracepoints_info (char *, int); |
263 | ||
264 | static void delete_trace_command (char *, int); | |
265 | ||
266 | static void enable_trace_command (char *, int); | |
267 | ||
268 | static void disable_trace_command (char *, int); | |
269 | ||
270 | static void trace_pass_command (char *, int); | |
271 | ||
558a9d82 YQ |
272 | static void set_tracepoint_count (int num); |
273 | ||
9c06b0b4 TJB |
274 | static int is_masked_watchpoint (const struct breakpoint *b); |
275 | ||
b775012e LM |
276 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
277 | ||
983af33b SDJ |
278 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
279 | otherwise. */ | |
280 | ||
281 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 282 | |
2060206e PA |
283 | /* The abstract base class all breakpoint_ops structures inherit |
284 | from. */ | |
ab04a2af | 285 | struct breakpoint_ops base_breakpoint_ops; |
2060206e PA |
286 | |
287 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
288 | that are implemented on top of software or hardware breakpoints | |
289 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
290 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
291 | ||
292 | /* Internal breakpoints class type. */ | |
06edf0c0 | 293 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
294 | |
295 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
296 | static struct breakpoint_ops momentary_breakpoint_ops; |
297 | ||
e2e4d78b JK |
298 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
299 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
300 | ||
2060206e PA |
301 | /* The breakpoint_ops structure to be used in regular user created |
302 | breakpoints. */ | |
303 | struct breakpoint_ops bkpt_breakpoint_ops; | |
304 | ||
55aa24fb SDJ |
305 | /* Breakpoints set on probes. */ |
306 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
307 | ||
e7e0cddf SS |
308 | /* Dynamic printf class type. */ |
309 | static struct breakpoint_ops dprintf_breakpoint_ops; | |
310 | ||
d3ce09f5 SS |
311 | /* The style in which to perform a dynamic printf. This is a user |
312 | option because different output options have different tradeoffs; | |
313 | if GDB does the printing, there is better error handling if there | |
314 | is a problem with any of the arguments, but using an inferior | |
315 | function lets you have special-purpose printers and sending of | |
316 | output to the same place as compiled-in print functions. */ | |
317 | ||
318 | static const char dprintf_style_gdb[] = "gdb"; | |
319 | static const char dprintf_style_call[] = "call"; | |
320 | static const char dprintf_style_agent[] = "agent"; | |
321 | static const char *const dprintf_style_enums[] = { | |
322 | dprintf_style_gdb, | |
323 | dprintf_style_call, | |
324 | dprintf_style_agent, | |
325 | NULL | |
326 | }; | |
327 | static const char *dprintf_style = dprintf_style_gdb; | |
328 | ||
329 | /* The function to use for dynamic printf if the preferred style is to | |
330 | call into the inferior. The value is simply a string that is | |
331 | copied into the command, so it can be anything that GDB can | |
332 | evaluate to a callable address, not necessarily a function name. */ | |
333 | ||
334 | static char *dprintf_function = ""; | |
335 | ||
336 | /* The channel to use for dynamic printf if the preferred style is to | |
337 | call into the inferior; if a nonempty string, it will be passed to | |
338 | the call as the first argument, with the format string as the | |
339 | second. As with the dprintf function, this can be anything that | |
340 | GDB knows how to evaluate, so in addition to common choices like | |
341 | "stderr", this could be an app-specific expression like | |
342 | "mystreams[curlogger]". */ | |
343 | ||
344 | static char *dprintf_channel = ""; | |
345 | ||
346 | /* True if dprintf commands should continue to operate even if GDB | |
347 | has disconnected. */ | |
348 | static int disconnected_dprintf = 1; | |
349 | ||
5cea2a26 PA |
350 | /* A reference-counted struct command_line. This lets multiple |
351 | breakpoints share a single command list. */ | |
352 | struct counted_command_line | |
353 | { | |
354 | /* The reference count. */ | |
355 | int refc; | |
356 | ||
357 | /* The command list. */ | |
358 | struct command_line *commands; | |
359 | }; | |
360 | ||
361 | struct command_line * | |
362 | breakpoint_commands (struct breakpoint *b) | |
363 | { | |
364 | return b->commands ? b->commands->commands : NULL; | |
365 | } | |
3daf8fe5 | 366 | |
f3b1572e PA |
367 | /* Flag indicating that a command has proceeded the inferior past the |
368 | current breakpoint. */ | |
369 | ||
370 | static int breakpoint_proceeded; | |
371 | ||
956a9fb9 | 372 | const char * |
2cec12e5 AR |
373 | bpdisp_text (enum bpdisp disp) |
374 | { | |
4a64f543 MS |
375 | /* NOTE: the following values are a part of MI protocol and |
376 | represent values of 'disp' field returned when inferior stops at | |
377 | a breakpoint. */ | |
bc043ef3 | 378 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 379 | |
2cec12e5 AR |
380 | return bpdisps[(int) disp]; |
381 | } | |
c906108c | 382 | |
4a64f543 | 383 | /* Prototypes for exported functions. */ |
c906108c | 384 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 385 | if such is available. */ |
c906108c SS |
386 | static int can_use_hw_watchpoints; |
387 | ||
920d2a44 AC |
388 | static void |
389 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
390 | struct cmd_list_element *c, | |
391 | const char *value) | |
392 | { | |
3e43a32a MS |
393 | fprintf_filtered (file, |
394 | _("Debugger's willingness to use " | |
395 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
396 | value); |
397 | } | |
398 | ||
fa8d40ab JJ |
399 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
400 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 401 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
402 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
403 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
404 | static void |
405 | show_pending_break_support (struct ui_file *file, int from_tty, | |
406 | struct cmd_list_element *c, | |
407 | const char *value) | |
408 | { | |
3e43a32a MS |
409 | fprintf_filtered (file, |
410 | _("Debugger's behavior regarding " | |
411 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
412 | value); |
413 | } | |
fa8d40ab | 414 | |
765dc015 | 415 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 416 | set with "break" but falling in read-only memory. |
765dc015 VP |
417 | If 0, gdb will warn about such breakpoints, but won't automatically |
418 | use hardware breakpoints. */ | |
419 | static int automatic_hardware_breakpoints; | |
420 | static void | |
421 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
422 | struct cmd_list_element *c, | |
423 | const char *value) | |
424 | { | |
3e43a32a MS |
425 | fprintf_filtered (file, |
426 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
427 | value); |
428 | } | |
429 | ||
33e5cbd6 PA |
430 | /* If on, gdb will keep breakpoints inserted even as inferior is |
431 | stopped, and immediately insert any new breakpoints. If off, gdb | |
432 | will insert breakpoints into inferior only when resuming it, and | |
433 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
434 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
435 | ||
72d0e2c5 YQ |
436 | static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO; |
437 | ||
33e5cbd6 | 438 | static void |
74960c60 | 439 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 440 | struct cmd_list_element *c, const char *value) |
74960c60 | 441 | { |
72d0e2c5 | 442 | if (always_inserted_mode == AUTO_BOOLEAN_AUTO) |
3e43a32a MS |
443 | fprintf_filtered (file, |
444 | _("Always inserted breakpoint " | |
445 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
446 | value, |
447 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
448 | else | |
3e43a32a MS |
449 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
450 | value); | |
74960c60 VP |
451 | } |
452 | ||
33e5cbd6 PA |
453 | int |
454 | breakpoints_always_inserted_mode (void) | |
455 | { | |
72d0e2c5 YQ |
456 | return (always_inserted_mode == AUTO_BOOLEAN_TRUE |
457 | || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop)); | |
33e5cbd6 | 458 | } |
765dc015 | 459 | |
b775012e LM |
460 | static const char condition_evaluation_both[] = "host or target"; |
461 | ||
462 | /* Modes for breakpoint condition evaluation. */ | |
463 | static const char condition_evaluation_auto[] = "auto"; | |
464 | static const char condition_evaluation_host[] = "host"; | |
465 | static const char condition_evaluation_target[] = "target"; | |
466 | static const char *const condition_evaluation_enums[] = { | |
467 | condition_evaluation_auto, | |
468 | condition_evaluation_host, | |
469 | condition_evaluation_target, | |
470 | NULL | |
471 | }; | |
472 | ||
473 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
474 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
475 | ||
476 | /* Global that we use to display information to the user (gets its value from | |
477 | condition_evaluation_mode_1. */ | |
478 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
479 | ||
480 | /* Translate a condition evaluation mode MODE into either "host" | |
481 | or "target". This is used mostly to translate from "auto" to the | |
482 | real setting that is being used. It returns the translated | |
483 | evaluation mode. */ | |
484 | ||
485 | static const char * | |
486 | translate_condition_evaluation_mode (const char *mode) | |
487 | { | |
488 | if (mode == condition_evaluation_auto) | |
489 | { | |
490 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
491 | return condition_evaluation_target; | |
492 | else | |
493 | return condition_evaluation_host; | |
494 | } | |
495 | else | |
496 | return mode; | |
497 | } | |
498 | ||
499 | /* Discovers what condition_evaluation_auto translates to. */ | |
500 | ||
501 | static const char * | |
502 | breakpoint_condition_evaluation_mode (void) | |
503 | { | |
504 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
505 | } | |
506 | ||
507 | /* Return true if GDB should evaluate breakpoint conditions or false | |
508 | otherwise. */ | |
509 | ||
510 | static int | |
511 | gdb_evaluates_breakpoint_condition_p (void) | |
512 | { | |
513 | const char *mode = breakpoint_condition_evaluation_mode (); | |
514 | ||
515 | return (mode == condition_evaluation_host); | |
516 | } | |
517 | ||
a14ed312 | 518 | void _initialize_breakpoint (void); |
c906108c | 519 | |
c906108c SS |
520 | /* Are we executing breakpoint commands? */ |
521 | static int executing_breakpoint_commands; | |
522 | ||
c02f5703 MS |
523 | /* Are overlay event breakpoints enabled? */ |
524 | static int overlay_events_enabled; | |
525 | ||
e09342b5 TJB |
526 | /* See description in breakpoint.h. */ |
527 | int target_exact_watchpoints = 0; | |
528 | ||
c906108c | 529 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 530 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 531 | current breakpoint. */ |
c906108c | 532 | |
5c44784c | 533 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 534 | |
5c44784c JM |
535 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
536 | for (B = breakpoint_chain; \ | |
537 | B ? (TMP=B->next, 1): 0; \ | |
538 | B = TMP) | |
c906108c | 539 | |
4a64f543 MS |
540 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
541 | not provided so update_global_location_list must not be called | |
542 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 543 | |
876fa593 JK |
544 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
545 | for (BP_TMP = bp_location; \ | |
546 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
547 | BP_TMP++) | |
7cc221ef | 548 | |
b775012e LM |
549 | /* Iterates through locations with address ADDRESS for the currently selected |
550 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
551 | to where the loop should start from. | |
552 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
553 | appropriate location to start with. */ | |
554 | ||
555 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
556 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
557 | BP_LOCP_TMP = BP_LOCP_START; \ | |
558 | BP_LOCP_START \ | |
559 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
560 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
561 | BP_LOCP_TMP++) | |
562 | ||
1042e4c0 SS |
563 | /* Iterator for tracepoints only. */ |
564 | ||
565 | #define ALL_TRACEPOINTS(B) \ | |
566 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 567 | if (is_tracepoint (B)) |
1042e4c0 | 568 | |
7cc221ef | 569 | /* Chains of all breakpoints defined. */ |
c906108c SS |
570 | |
571 | struct breakpoint *breakpoint_chain; | |
572 | ||
876fa593 JK |
573 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
574 | ||
575 | static struct bp_location **bp_location; | |
576 | ||
577 | /* Number of elements of BP_LOCATION. */ | |
578 | ||
579 | static unsigned bp_location_count; | |
580 | ||
4a64f543 MS |
581 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
582 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
583 | result from bp_location_has_shadow. You can use it for roughly | |
584 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
585 | an address you need to read. */ | |
876fa593 JK |
586 | |
587 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
588 | ||
4a64f543 MS |
589 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
590 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
591 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
592 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
593 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
594 | |
595 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 596 | |
4a64f543 MS |
597 | /* The locations that no longer correspond to any breakpoint, unlinked |
598 | from bp_location array, but for which a hit may still be reported | |
599 | by a target. */ | |
20874c92 VP |
600 | VEC(bp_location_p) *moribund_locations = NULL; |
601 | ||
c906108c SS |
602 | /* Number of last breakpoint made. */ |
603 | ||
95a42b64 TT |
604 | static int breakpoint_count; |
605 | ||
86b17b60 PA |
606 | /* The value of `breakpoint_count' before the last command that |
607 | created breakpoints. If the last (break-like) command created more | |
608 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
609 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
610 | static int prev_breakpoint_count; | |
c906108c | 611 | |
1042e4c0 SS |
612 | /* Number of last tracepoint made. */ |
613 | ||
95a42b64 | 614 | static int tracepoint_count; |
1042e4c0 | 615 | |
6149aea9 PA |
616 | static struct cmd_list_element *breakpoint_set_cmdlist; |
617 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 618 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 619 | |
468d015d JJ |
620 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
621 | static int | |
622 | breakpoint_enabled (struct breakpoint *b) | |
623 | { | |
0d381245 | 624 | return (b->enable_state == bp_enabled); |
468d015d JJ |
625 | } |
626 | ||
c906108c SS |
627 | /* Set breakpoint count to NUM. */ |
628 | ||
95a42b64 | 629 | static void |
fba45db2 | 630 | set_breakpoint_count (int num) |
c906108c | 631 | { |
86b17b60 | 632 | prev_breakpoint_count = breakpoint_count; |
c906108c | 633 | breakpoint_count = num; |
4fa62494 | 634 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
635 | } |
636 | ||
86b17b60 PA |
637 | /* Used by `start_rbreak_breakpoints' below, to record the current |
638 | breakpoint count before "rbreak" creates any breakpoint. */ | |
639 | static int rbreak_start_breakpoint_count; | |
640 | ||
95a42b64 TT |
641 | /* Called at the start an "rbreak" command to record the first |
642 | breakpoint made. */ | |
86b17b60 | 643 | |
95a42b64 TT |
644 | void |
645 | start_rbreak_breakpoints (void) | |
646 | { | |
86b17b60 | 647 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
648 | } |
649 | ||
650 | /* Called at the end of an "rbreak" command to record the last | |
651 | breakpoint made. */ | |
86b17b60 | 652 | |
95a42b64 TT |
653 | void |
654 | end_rbreak_breakpoints (void) | |
655 | { | |
86b17b60 | 656 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
657 | } |
658 | ||
4a64f543 | 659 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
660 | |
661 | void | |
fba45db2 | 662 | clear_breakpoint_hit_counts (void) |
c906108c SS |
663 | { |
664 | struct breakpoint *b; | |
665 | ||
666 | ALL_BREAKPOINTS (b) | |
667 | b->hit_count = 0; | |
668 | } | |
669 | ||
9add0f1b TT |
670 | /* Allocate a new counted_command_line with reference count of 1. |
671 | The new structure owns COMMANDS. */ | |
672 | ||
673 | static struct counted_command_line * | |
674 | alloc_counted_command_line (struct command_line *commands) | |
675 | { | |
676 | struct counted_command_line *result | |
677 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 678 | |
9add0f1b TT |
679 | result->refc = 1; |
680 | result->commands = commands; | |
681 | return result; | |
682 | } | |
683 | ||
684 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
685 | ||
686 | static void | |
687 | incref_counted_command_line (struct counted_command_line *cmd) | |
688 | { | |
689 | if (cmd) | |
690 | ++cmd->refc; | |
691 | } | |
692 | ||
693 | /* Decrement reference count. If the reference count reaches 0, | |
694 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
695 | nothing if *CMDP is NULL. */ | |
696 | ||
697 | static void | |
698 | decref_counted_command_line (struct counted_command_line **cmdp) | |
699 | { | |
700 | if (*cmdp) | |
701 | { | |
702 | if (--(*cmdp)->refc == 0) | |
703 | { | |
704 | free_command_lines (&(*cmdp)->commands); | |
705 | xfree (*cmdp); | |
706 | } | |
707 | *cmdp = NULL; | |
708 | } | |
709 | } | |
710 | ||
711 | /* A cleanup function that calls decref_counted_command_line. */ | |
712 | ||
713 | static void | |
714 | do_cleanup_counted_command_line (void *arg) | |
715 | { | |
716 | decref_counted_command_line (arg); | |
717 | } | |
718 | ||
719 | /* Create a cleanup that calls decref_counted_command_line on the | |
720 | argument. */ | |
721 | ||
722 | static struct cleanup * | |
723 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
724 | { | |
725 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
726 | } | |
727 | ||
c906108c | 728 | \f |
48cb2d85 VP |
729 | /* Return the breakpoint with the specified number, or NULL |
730 | if the number does not refer to an existing breakpoint. */ | |
731 | ||
732 | struct breakpoint * | |
733 | get_breakpoint (int num) | |
734 | { | |
735 | struct breakpoint *b; | |
736 | ||
737 | ALL_BREAKPOINTS (b) | |
738 | if (b->number == num) | |
739 | return b; | |
740 | ||
741 | return NULL; | |
742 | } | |
5c44784c | 743 | |
c906108c | 744 | \f |
adc36818 | 745 | |
b775012e LM |
746 | /* Mark locations as "conditions have changed" in case the target supports |
747 | evaluating conditions on its side. */ | |
748 | ||
749 | static void | |
750 | mark_breakpoint_modified (struct breakpoint *b) | |
751 | { | |
752 | struct bp_location *loc; | |
753 | ||
754 | /* This is only meaningful if the target is | |
755 | evaluating conditions and if the user has | |
756 | opted for condition evaluation on the target's | |
757 | side. */ | |
758 | if (gdb_evaluates_breakpoint_condition_p () | |
759 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
760 | return; | |
761 | ||
762 | if (!is_breakpoint (b)) | |
763 | return; | |
764 | ||
765 | for (loc = b->loc; loc; loc = loc->next) | |
766 | loc->condition_changed = condition_modified; | |
767 | } | |
768 | ||
769 | /* Mark location as "conditions have changed" in case the target supports | |
770 | evaluating conditions on its side. */ | |
771 | ||
772 | static void | |
773 | mark_breakpoint_location_modified (struct bp_location *loc) | |
774 | { | |
775 | /* This is only meaningful if the target is | |
776 | evaluating conditions and if the user has | |
777 | opted for condition evaluation on the target's | |
778 | side. */ | |
779 | if (gdb_evaluates_breakpoint_condition_p () | |
780 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
781 | ||
782 | return; | |
783 | ||
784 | if (!is_breakpoint (loc->owner)) | |
785 | return; | |
786 | ||
787 | loc->condition_changed = condition_modified; | |
788 | } | |
789 | ||
790 | /* Sets the condition-evaluation mode using the static global | |
791 | condition_evaluation_mode. */ | |
792 | ||
793 | static void | |
794 | set_condition_evaluation_mode (char *args, int from_tty, | |
795 | struct cmd_list_element *c) | |
796 | { | |
b775012e LM |
797 | const char *old_mode, *new_mode; |
798 | ||
799 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
800 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
801 | { | |
802 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
803 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
804 | "Using host evaluation mode instead.")); | |
805 | return; | |
806 | } | |
807 | ||
808 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
809 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
810 | ||
abf1152a JK |
811 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
812 | settings was "auto". */ | |
813 | condition_evaluation_mode = condition_evaluation_mode_1; | |
814 | ||
b775012e LM |
815 | /* Only update the mode if the user picked a different one. */ |
816 | if (new_mode != old_mode) | |
817 | { | |
818 | struct bp_location *loc, **loc_tmp; | |
819 | /* If the user switched to a different evaluation mode, we | |
820 | need to synch the changes with the target as follows: | |
821 | ||
822 | "host" -> "target": Send all (valid) conditions to the target. | |
823 | "target" -> "host": Remove all the conditions from the target. | |
824 | */ | |
825 | ||
b775012e LM |
826 | if (new_mode == condition_evaluation_target) |
827 | { | |
828 | /* Mark everything modified and synch conditions with the | |
829 | target. */ | |
830 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
831 | mark_breakpoint_location_modified (loc); | |
832 | } | |
833 | else | |
834 | { | |
835 | /* Manually mark non-duplicate locations to synch conditions | |
836 | with the target. We do this to remove all the conditions the | |
837 | target knows about. */ | |
838 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
839 | if (is_breakpoint (loc->owner) && loc->inserted) | |
840 | loc->needs_update = 1; | |
841 | } | |
842 | ||
843 | /* Do the update. */ | |
844 | update_global_location_list (1); | |
845 | } | |
846 | ||
847 | return; | |
848 | } | |
849 | ||
850 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
851 | what "auto" is translating to. */ | |
852 | ||
853 | static void | |
854 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
855 | struct cmd_list_element *c, const char *value) | |
856 | { | |
857 | if (condition_evaluation_mode == condition_evaluation_auto) | |
858 | fprintf_filtered (file, | |
859 | _("Breakpoint condition evaluation " | |
860 | "mode is %s (currently %s).\n"), | |
861 | value, | |
862 | breakpoint_condition_evaluation_mode ()); | |
863 | else | |
864 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
865 | value); | |
866 | } | |
867 | ||
868 | /* A comparison function for bp_location AP and BP that is used by | |
869 | bsearch. This comparison function only cares about addresses, unlike | |
870 | the more general bp_location_compare function. */ | |
871 | ||
872 | static int | |
873 | bp_location_compare_addrs (const void *ap, const void *bp) | |
874 | { | |
875 | struct bp_location *a = *(void **) ap; | |
876 | struct bp_location *b = *(void **) bp; | |
877 | ||
878 | if (a->address == b->address) | |
879 | return 0; | |
880 | else | |
881 | return ((a->address > b->address) - (a->address < b->address)); | |
882 | } | |
883 | ||
884 | /* Helper function to skip all bp_locations with addresses | |
885 | less than ADDRESS. It returns the first bp_location that | |
886 | is greater than or equal to ADDRESS. If none is found, just | |
887 | return NULL. */ | |
888 | ||
889 | static struct bp_location ** | |
890 | get_first_locp_gte_addr (CORE_ADDR address) | |
891 | { | |
892 | struct bp_location dummy_loc; | |
893 | struct bp_location *dummy_locp = &dummy_loc; | |
894 | struct bp_location **locp_found = NULL; | |
895 | ||
896 | /* Initialize the dummy location's address field. */ | |
897 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
898 | dummy_loc.address = address; | |
899 | ||
900 | /* Find a close match to the first location at ADDRESS. */ | |
901 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
902 | sizeof (struct bp_location **), | |
903 | bp_location_compare_addrs); | |
904 | ||
905 | /* Nothing was found, nothing left to do. */ | |
906 | if (locp_found == NULL) | |
907 | return NULL; | |
908 | ||
909 | /* We may have found a location that is at ADDRESS but is not the first in the | |
910 | location's list. Go backwards (if possible) and locate the first one. */ | |
911 | while ((locp_found - 1) >= bp_location | |
912 | && (*(locp_found - 1))->address == address) | |
913 | locp_found--; | |
914 | ||
915 | return locp_found; | |
916 | } | |
917 | ||
adc36818 PM |
918 | void |
919 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
920 | int from_tty) | |
921 | { | |
3a5c3e22 PA |
922 | xfree (b->cond_string); |
923 | b->cond_string = NULL; | |
adc36818 | 924 | |
3a5c3e22 | 925 | if (is_watchpoint (b)) |
adc36818 | 926 | { |
3a5c3e22 PA |
927 | struct watchpoint *w = (struct watchpoint *) b; |
928 | ||
929 | xfree (w->cond_exp); | |
930 | w->cond_exp = NULL; | |
931 | } | |
932 | else | |
933 | { | |
934 | struct bp_location *loc; | |
935 | ||
936 | for (loc = b->loc; loc; loc = loc->next) | |
937 | { | |
938 | xfree (loc->cond); | |
939 | loc->cond = NULL; | |
b775012e LM |
940 | |
941 | /* No need to free the condition agent expression | |
942 | bytecode (if we have one). We will handle this | |
943 | when we go through update_global_location_list. */ | |
3a5c3e22 | 944 | } |
adc36818 | 945 | } |
adc36818 PM |
946 | |
947 | if (*exp == 0) | |
948 | { | |
949 | if (from_tty) | |
950 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
951 | } | |
952 | else | |
953 | { | |
bbc13ae3 | 954 | const char *arg = exp; |
cc59ec59 | 955 | |
adc36818 PM |
956 | /* I don't know if it matters whether this is the string the user |
957 | typed in or the decompiled expression. */ | |
958 | b->cond_string = xstrdup (arg); | |
959 | b->condition_not_parsed = 0; | |
960 | ||
961 | if (is_watchpoint (b)) | |
962 | { | |
3a5c3e22 PA |
963 | struct watchpoint *w = (struct watchpoint *) b; |
964 | ||
adc36818 PM |
965 | innermost_block = NULL; |
966 | arg = exp; | |
1bb9788d | 967 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
968 | if (*arg) |
969 | error (_("Junk at end of expression")); | |
3a5c3e22 | 970 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
971 | } |
972 | else | |
973 | { | |
3a5c3e22 PA |
974 | struct bp_location *loc; |
975 | ||
adc36818 PM |
976 | for (loc = b->loc; loc; loc = loc->next) |
977 | { | |
978 | arg = exp; | |
979 | loc->cond = | |
1bb9788d TT |
980 | parse_exp_1 (&arg, loc->address, |
981 | block_for_pc (loc->address), 0); | |
adc36818 PM |
982 | if (*arg) |
983 | error (_("Junk at end of expression")); | |
984 | } | |
985 | } | |
986 | } | |
b775012e LM |
987 | mark_breakpoint_modified (b); |
988 | ||
8d3788bd | 989 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
990 | } |
991 | ||
d55637df TT |
992 | /* Completion for the "condition" command. */ |
993 | ||
994 | static VEC (char_ptr) * | |
6f937416 PA |
995 | condition_completer (struct cmd_list_element *cmd, |
996 | const char *text, const char *word) | |
d55637df | 997 | { |
6f937416 | 998 | const char *space; |
d55637df | 999 | |
6f937416 PA |
1000 | text = skip_spaces_const (text); |
1001 | space = skip_to_space_const (text); | |
d55637df TT |
1002 | if (*space == '\0') |
1003 | { | |
1004 | int len; | |
1005 | struct breakpoint *b; | |
1006 | VEC (char_ptr) *result = NULL; | |
1007 | ||
1008 | if (text[0] == '$') | |
1009 | { | |
1010 | /* We don't support completion of history indices. */ | |
1011 | if (isdigit (text[1])) | |
1012 | return NULL; | |
1013 | return complete_internalvar (&text[1]); | |
1014 | } | |
1015 | ||
1016 | /* We're completing the breakpoint number. */ | |
1017 | len = strlen (text); | |
1018 | ||
1019 | ALL_BREAKPOINTS (b) | |
1020 | { | |
1021 | int single = b->loc->next == NULL; | |
1022 | struct bp_location *loc; | |
1023 | int count = 1; | |
1024 | ||
1025 | for (loc = b->loc; loc; loc = loc->next) | |
1026 | { | |
1027 | char location[50]; | |
1028 | ||
1029 | if (single) | |
8c042590 | 1030 | xsnprintf (location, sizeof (location), "%d", b->number); |
d55637df | 1031 | else |
8c042590 PM |
1032 | xsnprintf (location, sizeof (location), "%d.%d", b->number, |
1033 | count); | |
d55637df TT |
1034 | |
1035 | if (strncmp (location, text, len) == 0) | |
1036 | VEC_safe_push (char_ptr, result, xstrdup (location)); | |
1037 | ||
1038 | ++count; | |
1039 | } | |
1040 | } | |
1041 | ||
1042 | return result; | |
1043 | } | |
1044 | ||
1045 | /* We're completing the expression part. */ | |
6f937416 | 1046 | text = skip_spaces_const (space); |
d55637df TT |
1047 | return expression_completer (cmd, text, word); |
1048 | } | |
1049 | ||
c906108c SS |
1050 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1051 | ||
1052 | static void | |
fba45db2 | 1053 | condition_command (char *arg, int from_tty) |
c906108c | 1054 | { |
52f0bd74 | 1055 | struct breakpoint *b; |
c906108c | 1056 | char *p; |
52f0bd74 | 1057 | int bnum; |
c906108c SS |
1058 | |
1059 | if (arg == 0) | |
e2e0b3e5 | 1060 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1061 | |
1062 | p = arg; | |
1063 | bnum = get_number (&p); | |
5c44784c | 1064 | if (bnum == 0) |
8a3fe4f8 | 1065 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1066 | |
1067 | ALL_BREAKPOINTS (b) | |
1068 | if (b->number == bnum) | |
2f069f6f | 1069 | { |
7371cf6d PM |
1070 | /* Check if this breakpoint has a Python object assigned to |
1071 | it, and if it has a definition of the "stop" | |
1072 | method. This method and conditions entered into GDB from | |
1073 | the CLI are mutually exclusive. */ | |
1074 | if (b->py_bp_object | |
1075 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
1076 | error (_("Cannot set a condition where a Python 'stop' " | |
1077 | "method has been defined in the breakpoint.")); | |
2566ad2d | 1078 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1079 | |
1080 | if (is_breakpoint (b)) | |
1081 | update_global_location_list (1); | |
1082 | ||
2f069f6f JB |
1083 | return; |
1084 | } | |
c906108c | 1085 | |
8a3fe4f8 | 1086 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1087 | } |
1088 | ||
a7bdde9e VP |
1089 | /* Check that COMMAND do not contain commands that are suitable |
1090 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1091 | Throw if any such commands is found. */ |
1092 | ||
a7bdde9e VP |
1093 | static void |
1094 | check_no_tracepoint_commands (struct command_line *commands) | |
1095 | { | |
1096 | struct command_line *c; | |
cc59ec59 | 1097 | |
a7bdde9e VP |
1098 | for (c = commands; c; c = c->next) |
1099 | { | |
1100 | int i; | |
1101 | ||
1102 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1103 | error (_("The 'while-stepping' command can " |
1104 | "only be used for tracepoints")); | |
a7bdde9e VP |
1105 | |
1106 | for (i = 0; i < c->body_count; ++i) | |
1107 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1108 | ||
1109 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1110 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1111 | command directly. */ |
1112 | if (strstr (c->line, "collect ") == c->line) | |
1113 | error (_("The 'collect' command can only be used for tracepoints")); | |
1114 | ||
51661e93 VP |
1115 | if (strstr (c->line, "teval ") == c->line) |
1116 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1117 | } |
1118 | } | |
1119 | ||
d77f58be SS |
1120 | /* Encapsulate tests for different types of tracepoints. */ |
1121 | ||
d9b3f62e PA |
1122 | static int |
1123 | is_tracepoint_type (enum bptype type) | |
1124 | { | |
1125 | return (type == bp_tracepoint | |
1126 | || type == bp_fast_tracepoint | |
1127 | || type == bp_static_tracepoint); | |
1128 | } | |
1129 | ||
a7bdde9e | 1130 | int |
d77f58be | 1131 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1132 | { |
d9b3f62e | 1133 | return is_tracepoint_type (b->type); |
a7bdde9e | 1134 | } |
d9b3f62e | 1135 | |
e5dd4106 | 1136 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1137 | breakpoint. This function will throw an exception if a problem is |
1138 | found. */ | |
48cb2d85 | 1139 | |
95a42b64 TT |
1140 | static void |
1141 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1142 | struct command_line *commands) | |
48cb2d85 | 1143 | { |
d77f58be | 1144 | if (is_tracepoint (b)) |
a7bdde9e | 1145 | { |
c9a6ce02 | 1146 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1147 | struct command_line *c; |
1148 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1149 | |
1150 | /* Reset the while-stepping step count. The previous commands | |
1151 | might have included a while-stepping action, while the new | |
1152 | ones might not. */ | |
1153 | t->step_count = 0; | |
1154 | ||
1155 | /* We need to verify that each top-level element of commands is | |
1156 | valid for tracepoints, that there's at most one | |
1157 | while-stepping element, and that the while-stepping's body | |
1158 | has valid tracing commands excluding nested while-stepping. | |
1159 | We also need to validate the tracepoint action line in the | |
1160 | context of the tracepoint --- validate_actionline actually | |
1161 | has side effects, like setting the tracepoint's | |
1162 | while-stepping STEP_COUNT, in addition to checking if the | |
1163 | collect/teval actions parse and make sense in the | |
1164 | tracepoint's context. */ | |
a7bdde9e VP |
1165 | for (c = commands; c; c = c->next) |
1166 | { | |
a7bdde9e VP |
1167 | if (c->control_type == while_stepping_control) |
1168 | { | |
1169 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1170 | error (_("The 'while-stepping' command " |
1171 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1172 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1173 | error (_("The 'while-stepping' command " |
1174 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1175 | |
1176 | if (while_stepping) | |
3e43a32a MS |
1177 | error (_("The 'while-stepping' command " |
1178 | "can be used only once")); | |
a7bdde9e VP |
1179 | else |
1180 | while_stepping = c; | |
1181 | } | |
c9a6ce02 PA |
1182 | |
1183 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1184 | } |
1185 | if (while_stepping) | |
1186 | { | |
1187 | struct command_line *c2; | |
1188 | ||
1189 | gdb_assert (while_stepping->body_count == 1); | |
1190 | c2 = while_stepping->body_list[0]; | |
1191 | for (; c2; c2 = c2->next) | |
1192 | { | |
a7bdde9e VP |
1193 | if (c2->control_type == while_stepping_control) |
1194 | error (_("The 'while-stepping' command cannot be nested")); | |
1195 | } | |
1196 | } | |
1197 | } | |
1198 | else | |
1199 | { | |
1200 | check_no_tracepoint_commands (commands); | |
1201 | } | |
95a42b64 TT |
1202 | } |
1203 | ||
0fb4aa4b PA |
1204 | /* Return a vector of all the static tracepoints set at ADDR. The |
1205 | caller is responsible for releasing the vector. */ | |
1206 | ||
1207 | VEC(breakpoint_p) * | |
1208 | static_tracepoints_here (CORE_ADDR addr) | |
1209 | { | |
1210 | struct breakpoint *b; | |
1211 | VEC(breakpoint_p) *found = 0; | |
1212 | struct bp_location *loc; | |
1213 | ||
1214 | ALL_BREAKPOINTS (b) | |
1215 | if (b->type == bp_static_tracepoint) | |
1216 | { | |
1217 | for (loc = b->loc; loc; loc = loc->next) | |
1218 | if (loc->address == addr) | |
1219 | VEC_safe_push(breakpoint_p, found, b); | |
1220 | } | |
1221 | ||
1222 | return found; | |
1223 | } | |
1224 | ||
95a42b64 | 1225 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1226 | validate that only allowed commands are included. */ |
95a42b64 TT |
1227 | |
1228 | void | |
4a64f543 MS |
1229 | breakpoint_set_commands (struct breakpoint *b, |
1230 | struct command_line *commands) | |
95a42b64 TT |
1231 | { |
1232 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1233 | |
9add0f1b TT |
1234 | decref_counted_command_line (&b->commands); |
1235 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1236 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1237 | } |
1238 | ||
45a43567 TT |
1239 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1240 | is not the same as the "silent" that may appear in the breakpoint's | |
1241 | commands. */ | |
1242 | ||
1243 | void | |
1244 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1245 | { | |
1246 | int old_silent = b->silent; | |
1247 | ||
1248 | b->silent = silent; | |
1249 | if (old_silent != silent) | |
8d3788bd | 1250 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1251 | } |
1252 | ||
1253 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1254 | breakpoint work for any thread. */ | |
1255 | ||
1256 | void | |
1257 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1258 | { | |
1259 | int old_thread = b->thread; | |
1260 | ||
1261 | b->thread = thread; | |
1262 | if (old_thread != thread) | |
8d3788bd | 1263 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1264 | } |
1265 | ||
1266 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1267 | breakpoint work for any task. */ | |
1268 | ||
1269 | void | |
1270 | breakpoint_set_task (struct breakpoint *b, int task) | |
1271 | { | |
1272 | int old_task = b->task; | |
1273 | ||
1274 | b->task = task; | |
1275 | if (old_task != task) | |
8d3788bd | 1276 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1277 | } |
1278 | ||
95a42b64 TT |
1279 | void |
1280 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1281 | { |
1282 | struct breakpoint *b = closure; | |
cc59ec59 | 1283 | |
6f937416 | 1284 | validate_actionline (line, b); |
a7bdde9e VP |
1285 | } |
1286 | ||
95a42b64 TT |
1287 | /* A structure used to pass information through |
1288 | map_breakpoint_numbers. */ | |
1289 | ||
1290 | struct commands_info | |
1291 | { | |
1292 | /* True if the command was typed at a tty. */ | |
1293 | int from_tty; | |
86b17b60 PA |
1294 | |
1295 | /* The breakpoint range spec. */ | |
1296 | char *arg; | |
1297 | ||
95a42b64 TT |
1298 | /* Non-NULL if the body of the commands are being read from this |
1299 | already-parsed command. */ | |
1300 | struct command_line *control; | |
86b17b60 | 1301 | |
95a42b64 TT |
1302 | /* The command lines read from the user, or NULL if they have not |
1303 | yet been read. */ | |
1304 | struct counted_command_line *cmd; | |
1305 | }; | |
1306 | ||
1307 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1308 | commands_command. */ | |
1309 | ||
c906108c | 1310 | static void |
95a42b64 | 1311 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1312 | { |
95a42b64 | 1313 | struct commands_info *info = data; |
c906108c | 1314 | |
95a42b64 TT |
1315 | if (info->cmd == NULL) |
1316 | { | |
1317 | struct command_line *l; | |
5c44784c | 1318 | |
95a42b64 TT |
1319 | if (info->control != NULL) |
1320 | l = copy_command_lines (info->control->body_list[0]); | |
1321 | else | |
86b17b60 PA |
1322 | { |
1323 | struct cleanup *old_chain; | |
1324 | char *str; | |
c5aa993b | 1325 | |
3e43a32a MS |
1326 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1327 | "%s, one per line."), | |
86b17b60 PA |
1328 | info->arg); |
1329 | ||
1330 | old_chain = make_cleanup (xfree, str); | |
1331 | ||
1332 | l = read_command_lines (str, | |
1333 | info->from_tty, 1, | |
d77f58be | 1334 | (is_tracepoint (b) |
86b17b60 PA |
1335 | ? check_tracepoint_command : 0), |
1336 | b); | |
1337 | ||
1338 | do_cleanups (old_chain); | |
1339 | } | |
a7bdde9e | 1340 | |
95a42b64 TT |
1341 | info->cmd = alloc_counted_command_line (l); |
1342 | } | |
1343 | ||
1344 | /* If a breakpoint was on the list more than once, we don't need to | |
1345 | do anything. */ | |
1346 | if (b->commands != info->cmd) | |
1347 | { | |
1348 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1349 | incref_counted_command_line (info->cmd); | |
1350 | decref_counted_command_line (&b->commands); | |
1351 | b->commands = info->cmd; | |
8d3788bd | 1352 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1353 | } |
95a42b64 TT |
1354 | } |
1355 | ||
1356 | static void | |
4a64f543 MS |
1357 | commands_command_1 (char *arg, int from_tty, |
1358 | struct command_line *control) | |
95a42b64 TT |
1359 | { |
1360 | struct cleanup *cleanups; | |
1361 | struct commands_info info; | |
1362 | ||
1363 | info.from_tty = from_tty; | |
1364 | info.control = control; | |
1365 | info.cmd = NULL; | |
1366 | /* If we read command lines from the user, then `info' will hold an | |
1367 | extra reference to the commands that we must clean up. */ | |
1368 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1369 | ||
1370 | if (arg == NULL || !*arg) | |
1371 | { | |
86b17b60 | 1372 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1373 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1374 | breakpoint_count); | |
95a42b64 TT |
1375 | else if (breakpoint_count > 0) |
1376 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1377 | else |
1378 | { | |
1379 | /* So that we don't try to free the incoming non-NULL | |
1380 | argument in the cleanup below. Mapping breakpoint | |
1381 | numbers will fail in this case. */ | |
1382 | arg = NULL; | |
1383 | } | |
95a42b64 | 1384 | } |
9766ced4 SS |
1385 | else |
1386 | /* The command loop has some static state, so we need to preserve | |
1387 | our argument. */ | |
1388 | arg = xstrdup (arg); | |
86b17b60 PA |
1389 | |
1390 | if (arg != NULL) | |
1391 | make_cleanup (xfree, arg); | |
1392 | ||
1393 | info.arg = arg; | |
95a42b64 TT |
1394 | |
1395 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1396 | ||
1397 | if (info.cmd == NULL) | |
1398 | error (_("No breakpoints specified.")); | |
1399 | ||
1400 | do_cleanups (cleanups); | |
1401 | } | |
1402 | ||
1403 | static void | |
1404 | commands_command (char *arg, int from_tty) | |
1405 | { | |
1406 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1407 | } |
40c03ae8 EZ |
1408 | |
1409 | /* Like commands_command, but instead of reading the commands from | |
1410 | input stream, takes them from an already parsed command structure. | |
1411 | ||
1412 | This is used by cli-script.c to DTRT with breakpoint commands | |
1413 | that are part of if and while bodies. */ | |
1414 | enum command_control_type | |
1415 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1416 | { | |
95a42b64 TT |
1417 | commands_command_1 (arg, 0, cmd); |
1418 | return simple_control; | |
40c03ae8 | 1419 | } |
876fa593 JK |
1420 | |
1421 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1422 | ||
1423 | static int | |
1424 | bp_location_has_shadow (struct bp_location *bl) | |
1425 | { | |
1426 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1427 | return 0; | |
1428 | if (!bl->inserted) | |
1429 | return 0; | |
1430 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1431 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1432 | return 0; |
1433 | return 1; | |
1434 | } | |
1435 | ||
8defab1a | 1436 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1437 | by replacing any memory breakpoints with their shadowed contents. |
1438 | ||
35c63cd8 JB |
1439 | If READBUF is not NULL, this buffer must not overlap with any of |
1440 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1441 | a failed assertion internal error will be raised. | |
1442 | ||
876fa593 | 1443 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1444 | bl->address - bp_location_placed_address_before_address_max |
1445 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1446 | The range we were requested to resolve shadows for is: |
1447 | memaddr ... memaddr + len | |
1448 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1449 | memaddr + len <= (bl->address |
1450 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1451 | and: |
35df4500 | 1452 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1453 | |
8defab1a | 1454 | void |
f0ba3972 PA |
1455 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1456 | const gdb_byte *writebuf_org, | |
1457 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1458 | { |
4a64f543 MS |
1459 | /* Left boundary, right boundary and median element of our binary |
1460 | search. */ | |
876fa593 JK |
1461 | unsigned bc_l, bc_r, bc; |
1462 | ||
4a64f543 MS |
1463 | /* Find BC_L which is a leftmost element which may affect BUF |
1464 | content. It is safe to report lower value but a failure to | |
1465 | report higher one. */ | |
876fa593 JK |
1466 | |
1467 | bc_l = 0; | |
1468 | bc_r = bp_location_count; | |
1469 | while (bc_l + 1 < bc_r) | |
1470 | { | |
35df4500 | 1471 | struct bp_location *bl; |
876fa593 JK |
1472 | |
1473 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1474 | bl = bp_location[bc]; |
876fa593 | 1475 | |
4a64f543 MS |
1476 | /* Check first BL->ADDRESS will not overflow due to the added |
1477 | constant. Then advance the left boundary only if we are sure | |
1478 | the BC element can in no way affect the BUF content (MEMADDR | |
1479 | to MEMADDR + LEN range). | |
876fa593 | 1480 | |
4a64f543 MS |
1481 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1482 | offset so that we cannot miss a breakpoint with its shadow | |
1483 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1484 | |
35df4500 TJB |
1485 | if ((bl->address + bp_location_shadow_len_after_address_max |
1486 | >= bl->address) | |
1487 | && (bl->address + bp_location_shadow_len_after_address_max | |
1488 | <= memaddr)) | |
876fa593 JK |
1489 | bc_l = bc; |
1490 | else | |
1491 | bc_r = bc; | |
1492 | } | |
1493 | ||
128070bb PA |
1494 | /* Due to the binary search above, we need to make sure we pick the |
1495 | first location that's at BC_L's address. E.g., if there are | |
1496 | multiple locations at the same address, BC_L may end up pointing | |
1497 | at a duplicate location, and miss the "master"/"inserted" | |
1498 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1499 | B: | |
1500 | ||
1501 | L1@A, L2@A, L3@B, ... | |
1502 | ||
1503 | BC_L could end up pointing at location L2, while the "master" | |
1504 | location could be L1. Since the `loc->inserted' flag is only set | |
1505 | on "master" locations, we'd forget to restore the shadow of L1 | |
1506 | and L2. */ | |
1507 | while (bc_l > 0 | |
1508 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1509 | bc_l--; | |
1510 | ||
876fa593 JK |
1511 | /* Now do full processing of the found relevant range of elements. */ |
1512 | ||
1513 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1514 | { |
35df4500 | 1515 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1516 | CORE_ADDR bp_addr = 0; |
1517 | int bp_size = 0; | |
1518 | int bptoffset = 0; | |
1519 | ||
35df4500 TJB |
1520 | /* bp_location array has BL->OWNER always non-NULL. */ |
1521 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1522 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1523 | bl->owner->number); |
ffce0d52 | 1524 | |
e5dd4106 | 1525 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1526 | content. */ |
1527 | ||
35df4500 TJB |
1528 | if (bl->address >= bp_location_placed_address_before_address_max |
1529 | && memaddr + len <= (bl->address | |
1530 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1531 | break; |
1532 | ||
35df4500 | 1533 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1534 | continue; |
35df4500 | 1535 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1536 | current_program_space->aspace, 0)) |
1537 | continue; | |
1538 | ||
c5aa993b JM |
1539 | /* Addresses and length of the part of the breakpoint that |
1540 | we need to copy. */ | |
35df4500 TJB |
1541 | bp_addr = bl->target_info.placed_address; |
1542 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1543 | |
c5aa993b JM |
1544 | if (bp_addr + bp_size <= memaddr) |
1545 | /* The breakpoint is entirely before the chunk of memory we | |
1546 | are reading. */ | |
1547 | continue; | |
8defab1a | 1548 | |
c5aa993b JM |
1549 | if (bp_addr >= memaddr + len) |
1550 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1551 | reading. */ |
c5aa993b | 1552 | continue; |
c5aa993b | 1553 | |
8defab1a DJ |
1554 | /* Offset within shadow_contents. */ |
1555 | if (bp_addr < memaddr) | |
1556 | { | |
1557 | /* Only copy the second part of the breakpoint. */ | |
1558 | bp_size -= memaddr - bp_addr; | |
1559 | bptoffset = memaddr - bp_addr; | |
1560 | bp_addr = memaddr; | |
1561 | } | |
c5aa993b | 1562 | |
8defab1a DJ |
1563 | if (bp_addr + bp_size > memaddr + len) |
1564 | { | |
1565 | /* Only copy the first part of the breakpoint. */ | |
1566 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1567 | } | |
c5aa993b | 1568 | |
f0ba3972 PA |
1569 | if (readbuf != NULL) |
1570 | { | |
35c63cd8 JB |
1571 | /* Verify that the readbuf buffer does not overlap with |
1572 | the shadow_contents buffer. */ | |
1573 | gdb_assert (bl->target_info.shadow_contents >= readbuf + len | |
1574 | || readbuf >= (bl->target_info.shadow_contents | |
1575 | + bl->target_info.shadow_len)); | |
1576 | ||
f0ba3972 PA |
1577 | /* Update the read buffer with this inserted breakpoint's |
1578 | shadow. */ | |
1579 | memcpy (readbuf + bp_addr - memaddr, | |
1580 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1581 | } | |
1582 | else | |
1583 | { | |
1584 | struct gdbarch *gdbarch = bl->gdbarch; | |
1585 | const unsigned char *bp; | |
1586 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
20ced3e4 | 1587 | int placed_size = bl->target_info.placed_size; |
f0ba3972 PA |
1588 | |
1589 | /* Update the shadow with what we want to write to memory. */ | |
1590 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1591 | writebuf_org + bp_addr - memaddr, bp_size); | |
1592 | ||
1593 | /* Determine appropriate breakpoint contents and size for this | |
1594 | address. */ | |
1595 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1596 | ||
1597 | /* Update the final write buffer with this inserted | |
1598 | breakpoint's INSN. */ | |
1599 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1600 | } | |
c5aa993b | 1601 | } |
c906108c | 1602 | } |
c906108c | 1603 | \f |
c5aa993b | 1604 | |
b775012e LM |
1605 | /* Return true if BPT is either a software breakpoint or a hardware |
1606 | breakpoint. */ | |
1607 | ||
1608 | int | |
1609 | is_breakpoint (const struct breakpoint *bpt) | |
1610 | { | |
1611 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1612 | || bpt->type == bp_hardware_breakpoint |
1613 | || bpt->type == bp_dprintf); | |
b775012e LM |
1614 | } |
1615 | ||
60e1c644 PA |
1616 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1617 | ||
a5606eee | 1618 | static int |
d77f58be | 1619 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1620 | { |
1621 | return (bpt->type == bp_hardware_watchpoint | |
1622 | || bpt->type == bp_read_watchpoint | |
1623 | || bpt->type == bp_access_watchpoint); | |
1624 | } | |
7270d8f2 | 1625 | |
60e1c644 PA |
1626 | /* Return true if BPT is of any watchpoint kind, hardware or |
1627 | software. */ | |
1628 | ||
3a5c3e22 | 1629 | int |
d77f58be | 1630 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1631 | { |
1632 | return (is_hardware_watchpoint (bpt) | |
1633 | || bpt->type == bp_watchpoint); | |
1634 | } | |
1635 | ||
3a5c3e22 PA |
1636 | /* Returns true if the current thread and its running state are safe |
1637 | to evaluate or update watchpoint B. Watchpoints on local | |
1638 | expressions need to be evaluated in the context of the thread that | |
1639 | was current when the watchpoint was created, and, that thread needs | |
1640 | to be stopped to be able to select the correct frame context. | |
1641 | Watchpoints on global expressions can be evaluated on any thread, | |
1642 | and in any state. It is presently left to the target allowing | |
1643 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1644 | |
1645 | static int | |
3a5c3e22 | 1646 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1647 | { |
d0d8b0c6 JK |
1648 | return (b->base.pspace == current_program_space |
1649 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1650 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1651 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1652 | } |
1653 | ||
d0fb5eae JK |
1654 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1655 | associated bp_watchpoint_scope breakpoint. */ | |
1656 | ||
1657 | static void | |
3a5c3e22 | 1658 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1659 | { |
3a5c3e22 | 1660 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1661 | |
1662 | if (b->related_breakpoint != b) | |
1663 | { | |
1664 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1665 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1666 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1667 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1668 | b->related_breakpoint = b; | |
1669 | } | |
1670 | b->disposition = disp_del_at_next_stop; | |
1671 | } | |
1672 | ||
567e1b4e JB |
1673 | /* Assuming that B is a watchpoint: |
1674 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1675 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1676 | - Evaluate the condition if there is one, and store the result |
1677 | in b->loc->cond. | |
a5606eee VP |
1678 | - Update the list of values that must be watched in B->loc. |
1679 | ||
4a64f543 MS |
1680 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1681 | nothing. If this is local watchpoint that is out of scope, delete | |
1682 | it. | |
1683 | ||
1684 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1685 | removed + inserted on each stop here. Normal breakpoints must | |
1686 | never be removed because they might be missed by a running thread | |
1687 | when debugging in non-stop mode. On the other hand, hardware | |
1688 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1689 | to each LWP since they are stored in each LWP's hardware debug | |
1690 | registers. Therefore, such LWP must be stopped first in order to | |
1691 | be able to modify its hardware watchpoints. | |
1692 | ||
1693 | Hardware watchpoints must be reset exactly once after being | |
1694 | presented to the user. It cannot be done sooner, because it would | |
1695 | reset the data used to present the watchpoint hit to the user. And | |
1696 | it must not be done later because it could display the same single | |
1697 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1698 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1699 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1700 | not user-visible - its hit is suppressed if the memory content has | |
1701 | not changed. | |
1702 | ||
1703 | The following constraints influence the location where we can reset | |
1704 | hardware watchpoints: | |
1705 | ||
1706 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1707 | called several times when GDB stops. | |
1708 | ||
1709 | [linux] | |
1710 | * Multiple hardware watchpoints can be hit at the same time, | |
1711 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1712 | hit at a time as the reason for stopping, and all the other hits | |
1713 | are presented later, one after the other, each time the user | |
1714 | requests the execution to be resumed. Execution is not resumed | |
1715 | for the threads still having pending hit event stored in | |
1716 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1717 | the inferior on the first stop the thread hit event is kept being | |
1718 | reported from its cached value by linux_nat_stopped_data_address | |
1719 | until the real thread resume happens after the watchpoint gets | |
1720 | presented and thus its LWP_INFO->STATUS gets reset. | |
1721 | ||
1722 | Therefore the hardware watchpoint hit can get safely reset on the | |
1723 | watchpoint removal from inferior. */ | |
a79d3c27 | 1724 | |
b40ce68a | 1725 | static void |
3a5c3e22 | 1726 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1727 | { |
a5606eee | 1728 | int within_current_scope; |
a5606eee | 1729 | struct frame_id saved_frame_id; |
66076460 | 1730 | int frame_saved; |
a5606eee | 1731 | |
f6bc2008 PA |
1732 | /* If this is a local watchpoint, we only want to check if the |
1733 | watchpoint frame is in scope if the current thread is the thread | |
1734 | that was used to create the watchpoint. */ | |
1735 | if (!watchpoint_in_thread_scope (b)) | |
1736 | return; | |
1737 | ||
3a5c3e22 | 1738 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1739 | return; |
1740 | ||
66076460 | 1741 | frame_saved = 0; |
a5606eee VP |
1742 | |
1743 | /* Determine if the watchpoint is within scope. */ | |
1744 | if (b->exp_valid_block == NULL) | |
1745 | within_current_scope = 1; | |
1746 | else | |
1747 | { | |
b5db5dfc UW |
1748 | struct frame_info *fi = get_current_frame (); |
1749 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1750 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1751 | ||
1752 | /* If we're in a function epilogue, unwinding may not work | |
1753 | properly, so do not attempt to recreate locations at this | |
1754 | point. See similar comments in watchpoint_check. */ | |
1755 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1756 | return; | |
66076460 DJ |
1757 | |
1758 | /* Save the current frame's ID so we can restore it after | |
1759 | evaluating the watchpoint expression on its own frame. */ | |
1760 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1761 | took a frame parameter, so that we didn't have to change the | |
1762 | selected frame. */ | |
1763 | frame_saved = 1; | |
1764 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1765 | ||
a5606eee VP |
1766 | fi = frame_find_by_id (b->watchpoint_frame); |
1767 | within_current_scope = (fi != NULL); | |
1768 | if (within_current_scope) | |
1769 | select_frame (fi); | |
1770 | } | |
1771 | ||
b5db5dfc UW |
1772 | /* We don't free locations. They are stored in the bp_location array |
1773 | and update_global_location_list will eventually delete them and | |
1774 | remove breakpoints if needed. */ | |
3a5c3e22 | 1775 | b->base.loc = NULL; |
b5db5dfc | 1776 | |
a5606eee VP |
1777 | if (within_current_scope && reparse) |
1778 | { | |
bbc13ae3 | 1779 | const char *s; |
d63d0675 | 1780 | |
a5606eee VP |
1781 | if (b->exp) |
1782 | { | |
1783 | xfree (b->exp); | |
1784 | b->exp = NULL; | |
1785 | } | |
d63d0675 | 1786 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1787 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1788 | /* If the meaning of expression itself changed, the old value is |
1789 | no longer relevant. We don't want to report a watchpoint hit | |
1790 | to the user when the old value and the new value may actually | |
1791 | be completely different objects. */ | |
1792 | value_free (b->val); | |
fa4727a6 DJ |
1793 | b->val = NULL; |
1794 | b->val_valid = 0; | |
60e1c644 PA |
1795 | |
1796 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1797 | expression is stored in the breakpoint object, not in the | |
1798 | locations (re)created below. */ | |
3a5c3e22 | 1799 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1800 | { |
1801 | if (b->cond_exp != NULL) | |
1802 | { | |
1803 | xfree (b->cond_exp); | |
1804 | b->cond_exp = NULL; | |
1805 | } | |
1806 | ||
3a5c3e22 | 1807 | s = b->base.cond_string; |
1bb9788d | 1808 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1809 | } |
a5606eee | 1810 | } |
a5606eee VP |
1811 | |
1812 | /* If we failed to parse the expression, for example because | |
1813 | it refers to a global variable in a not-yet-loaded shared library, | |
1814 | don't try to insert watchpoint. We don't automatically delete | |
1815 | such watchpoint, though, since failure to parse expression | |
1816 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1817 | if ( !target_has_execution) |
1818 | { | |
1819 | /* Without execution, memory can't change. No use to try and | |
1820 | set watchpoint locations. The watchpoint will be reset when | |
1821 | the target gains execution, through breakpoint_re_set. */ | |
1822 | } | |
1823 | else if (within_current_scope && b->exp) | |
a5606eee | 1824 | { |
0cf6dd15 | 1825 | int pc = 0; |
fa4727a6 | 1826 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1827 | struct program_space *frame_pspace; |
a5606eee | 1828 | |
0cf6dd15 | 1829 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1830 | |
a5606eee VP |
1831 | /* Avoid setting b->val if it's already set. The meaning of |
1832 | b->val is 'the last value' user saw, and we should update | |
1833 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1834 | happens, the code that reports it updates b->val directly. |
1835 | We don't keep track of the memory value for masked | |
1836 | watchpoints. */ | |
3a5c3e22 | 1837 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1838 | { |
1839 | b->val = v; | |
1840 | b->val_valid = 1; | |
1841 | } | |
a5606eee | 1842 | |
2d134ed3 PA |
1843 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1844 | ||
a5606eee | 1845 | /* Look at each value on the value chain. */ |
9fa40276 | 1846 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1847 | { |
1848 | /* If it's a memory location, and GDB actually needed | |
1849 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1850 | must watch it. If the first value returned is |
1851 | still lazy, that means an error occurred reading it; | |
1852 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1853 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1854 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1855 | { |
1856 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1857 | |
a5606eee VP |
1858 | /* We only watch structs and arrays if user asked |
1859 | for it explicitly, never if they just happen to | |
1860 | appear in the middle of some value chain. */ | |
fa4727a6 | 1861 | if (v == result |
a5606eee VP |
1862 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1863 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1864 | { | |
1865 | CORE_ADDR addr; | |
744a8059 | 1866 | int type; |
a5606eee VP |
1867 | struct bp_location *loc, **tmp; |
1868 | ||
42ae5230 | 1869 | addr = value_address (v); |
a5606eee | 1870 | type = hw_write; |
3a5c3e22 | 1871 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1872 | type = hw_read; |
3a5c3e22 | 1873 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1874 | type = hw_access; |
3a5c3e22 PA |
1875 | |
1876 | loc = allocate_bp_location (&b->base); | |
1877 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1878 | ; |
1879 | *tmp = loc; | |
a6d9a66e | 1880 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1881 | |
1882 | loc->pspace = frame_pspace; | |
a5606eee | 1883 | loc->address = addr; |
744a8059 | 1884 | loc->length = TYPE_LENGTH (value_type (v)); |
a5606eee VP |
1885 | loc->watchpoint_type = type; |
1886 | } | |
1887 | } | |
9fa40276 TJB |
1888 | } |
1889 | ||
1890 | /* Change the type of breakpoint between hardware assisted or | |
1891 | an ordinary watchpoint depending on the hardware support | |
1892 | and free hardware slots. REPARSE is set when the inferior | |
1893 | is started. */ | |
a9634178 | 1894 | if (reparse) |
9fa40276 | 1895 | { |
e09342b5 | 1896 | int reg_cnt; |
9fa40276 TJB |
1897 | enum bp_loc_type loc_type; |
1898 | struct bp_location *bl; | |
a5606eee | 1899 | |
a9634178 | 1900 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1901 | |
1902 | if (reg_cnt) | |
9fa40276 TJB |
1903 | { |
1904 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1905 | enum bptype type; |
9fa40276 | 1906 | |
a9634178 TJB |
1907 | /* Use an exact watchpoint when there's only one memory region to be |
1908 | watched, and only one debug register is needed to watch it. */ | |
1909 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1910 | ||
9fa40276 | 1911 | /* We need to determine how many resources are already |
e09342b5 TJB |
1912 | used for all other hardware watchpoints plus this one |
1913 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1914 | this watchpoint in as well. */ |
1915 | ||
1916 | /* If this is a software watchpoint, we try to turn it | |
1917 | to a hardware one -- count resources as if B was of | |
1918 | hardware watchpoint type. */ | |
1919 | type = b->base.type; | |
1920 | if (type == bp_watchpoint) | |
1921 | type = bp_hardware_watchpoint; | |
1922 | ||
1923 | /* This watchpoint may or may not have been placed on | |
1924 | the list yet at this point (it won't be in the list | |
1925 | if we're trying to create it for the first time, | |
1926 | through watch_command), so always account for it | |
1927 | manually. */ | |
1928 | ||
1929 | /* Count resources used by all watchpoints except B. */ | |
1930 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1931 | ||
1932 | /* Add in the resources needed for B. */ | |
1933 | i += hw_watchpoint_use_count (&b->base); | |
1934 | ||
1935 | target_resources_ok | |
1936 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1937 | if (target_resources_ok <= 0) |
a9634178 | 1938 | { |
3a5c3e22 | 1939 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1940 | |
1941 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1942 | error (_("Target does not support this type of " |
1943 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1944 | else if (target_resources_ok < 0 && !sw_mode) |
1945 | error (_("There are not enough available hardware " | |
1946 | "resources for this watchpoint.")); | |
a1398e0c PA |
1947 | |
1948 | /* Downgrade to software watchpoint. */ | |
1949 | b->base.type = bp_watchpoint; | |
1950 | } | |
1951 | else | |
1952 | { | |
1953 | /* If this was a software watchpoint, we've just | |
1954 | found we have enough resources to turn it to a | |
1955 | hardware watchpoint. Otherwise, this is a | |
1956 | nop. */ | |
1957 | b->base.type = type; | |
a9634178 | 1958 | } |
9fa40276 | 1959 | } |
3a5c3e22 | 1960 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1961 | error (_("Expression cannot be implemented with " |
1962 | "read/access watchpoint.")); | |
9fa40276 | 1963 | else |
3a5c3e22 | 1964 | b->base.type = bp_watchpoint; |
9fa40276 | 1965 | |
3a5c3e22 | 1966 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1967 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1968 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1969 | bl->loc_type = loc_type; |
1970 | } | |
1971 | ||
1972 | for (v = val_chain; v; v = next) | |
1973 | { | |
a5606eee VP |
1974 | next = value_next (v); |
1975 | if (v != b->val) | |
1976 | value_free (v); | |
1977 | } | |
1978 | ||
c7437ca6 PA |
1979 | /* If a software watchpoint is not watching any memory, then the |
1980 | above left it without any location set up. But, | |
1981 | bpstat_stop_status requires a location to be able to report | |
1982 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1983 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1984 | { |
3a5c3e22 PA |
1985 | struct breakpoint *base = &b->base; |
1986 | base->loc = allocate_bp_location (base); | |
1987 | base->loc->pspace = frame_pspace; | |
1988 | base->loc->address = -1; | |
1989 | base->loc->length = -1; | |
1990 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1991 | } |
a5606eee VP |
1992 | } |
1993 | else if (!within_current_scope) | |
7270d8f2 | 1994 | { |
ac74f770 MS |
1995 | printf_filtered (_("\ |
1996 | Watchpoint %d deleted because the program has left the block\n\ | |
1997 | in which its expression is valid.\n"), | |
3a5c3e22 | 1998 | b->base.number); |
d0fb5eae | 1999 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2000 | } |
a5606eee VP |
2001 | |
2002 | /* Restore the selected frame. */ | |
66076460 DJ |
2003 | if (frame_saved) |
2004 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2005 | } |
2006 | ||
a5606eee | 2007 | |
74960c60 | 2008 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2009 | inserted in the inferior. We don't differentiate the type of BL's owner |
2010 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2011 | breakpoint_ops is not defined, because in insert_bp_location, | |
2012 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2013 | static int |
35df4500 | 2014 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2015 | { |
35df4500 | 2016 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2017 | return 0; |
2018 | ||
35df4500 | 2019 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2020 | return 0; |
2021 | ||
35df4500 | 2022 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2023 | return 0; |
2024 | ||
f8eba3c6 TT |
2025 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2026 | return 0; | |
2027 | ||
56710373 PA |
2028 | /* This is set for example, when we're attached to the parent of a |
2029 | vfork, and have detached from the child. The child is running | |
2030 | free, and we expect it to do an exec or exit, at which point the | |
2031 | OS makes the parent schedulable again (and the target reports | |
2032 | that the vfork is done). Until the child is done with the shared | |
2033 | memory region, do not insert breakpoints in the parent, otherwise | |
2034 | the child could still trip on the parent's breakpoints. Since | |
2035 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2036 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2037 | return 0; |
2038 | ||
74960c60 VP |
2039 | return 1; |
2040 | } | |
2041 | ||
934709f0 PW |
2042 | /* Same as should_be_inserted but does the check assuming |
2043 | that the location is not duplicated. */ | |
2044 | ||
2045 | static int | |
2046 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2047 | { | |
2048 | int result; | |
2049 | const int save_duplicate = bl->duplicate; | |
2050 | ||
2051 | bl->duplicate = 0; | |
2052 | result = should_be_inserted (bl); | |
2053 | bl->duplicate = save_duplicate; | |
2054 | return result; | |
2055 | } | |
2056 | ||
b775012e LM |
2057 | /* Parses a conditional described by an expression COND into an |
2058 | agent expression bytecode suitable for evaluation | |
2059 | by the bytecode interpreter. Return NULL if there was | |
2060 | any error during parsing. */ | |
2061 | ||
2062 | static struct agent_expr * | |
2063 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2064 | { | |
2065 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2066 | volatile struct gdb_exception ex; |
2067 | ||
2068 | if (!cond) | |
2069 | return NULL; | |
2070 | ||
2071 | /* We don't want to stop processing, so catch any errors | |
2072 | that may show up. */ | |
2073 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2074 | { | |
2075 | aexpr = gen_eval_for_expr (scope, cond); | |
2076 | } | |
2077 | ||
2078 | if (ex.reason < 0) | |
2079 | { | |
2080 | /* If we got here, it means the condition could not be parsed to a valid | |
2081 | bytecode expression and thus can't be evaluated on the target's side. | |
2082 | It's no use iterating through the conditions. */ | |
2083 | return NULL; | |
2084 | } | |
2085 | ||
2086 | /* We have a valid agent expression. */ | |
2087 | return aexpr; | |
2088 | } | |
2089 | ||
2090 | /* Based on location BL, create a list of breakpoint conditions to be | |
2091 | passed on to the target. If we have duplicated locations with different | |
2092 | conditions, we will add such conditions to the list. The idea is that the | |
2093 | target will evaluate the list of conditions and will only notify GDB when | |
2094 | one of them is true. */ | |
2095 | ||
2096 | static void | |
2097 | build_target_condition_list (struct bp_location *bl) | |
2098 | { | |
2099 | struct bp_location **locp = NULL, **loc2p; | |
2100 | int null_condition_or_parse_error = 0; | |
2101 | int modified = bl->needs_update; | |
2102 | struct bp_location *loc; | |
2103 | ||
2104 | /* This is only meaningful if the target is | |
2105 | evaluating conditions and if the user has | |
2106 | opted for condition evaluation on the target's | |
2107 | side. */ | |
2108 | if (gdb_evaluates_breakpoint_condition_p () | |
2109 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2110 | return; | |
2111 | ||
2112 | /* Do a first pass to check for locations with no assigned | |
2113 | conditions or conditions that fail to parse to a valid agent expression | |
2114 | bytecode. If any of these happen, then it's no use to send conditions | |
2115 | to the target since this location will always trigger and generate a | |
2116 | response back to GDB. */ | |
2117 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2118 | { | |
2119 | loc = (*loc2p); | |
2120 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2121 | { | |
2122 | if (modified) | |
2123 | { | |
2124 | struct agent_expr *aexpr; | |
2125 | ||
2126 | /* Re-parse the conditions since something changed. In that | |
2127 | case we already freed the condition bytecodes (see | |
2128 | force_breakpoint_reinsertion). We just | |
2129 | need to parse the condition to bytecodes again. */ | |
2130 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2131 | loc->cond_bytecode = aexpr; | |
2132 | ||
2133 | /* Check if we managed to parse the conditional expression | |
2134 | correctly. If not, we will not send this condition | |
2135 | to the target. */ | |
2136 | if (aexpr) | |
2137 | continue; | |
2138 | } | |
2139 | ||
2140 | /* If we have a NULL bytecode expression, it means something | |
2141 | went wrong or we have a null condition expression. */ | |
2142 | if (!loc->cond_bytecode) | |
2143 | { | |
2144 | null_condition_or_parse_error = 1; | |
2145 | break; | |
2146 | } | |
2147 | } | |
2148 | } | |
2149 | ||
2150 | /* If any of these happened, it means we will have to evaluate the conditions | |
2151 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2152 | for all the other duplicate locations, thus we free all of them here. | |
2153 | ||
2154 | This is so we have a finer control over which locations' conditions are | |
2155 | being evaluated by GDB or the remote stub. */ | |
2156 | if (null_condition_or_parse_error) | |
2157 | { | |
2158 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2159 | { | |
2160 | loc = (*loc2p); | |
2161 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2162 | { | |
2163 | /* Only go as far as the first NULL bytecode is | |
2164 | located. */ | |
2165 | if (!loc->cond_bytecode) | |
2166 | return; | |
2167 | ||
2168 | free_agent_expr (loc->cond_bytecode); | |
2169 | loc->cond_bytecode = NULL; | |
2170 | } | |
2171 | } | |
2172 | } | |
2173 | ||
2174 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2175 | for this location's address. */ | |
2176 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2177 | { | |
2178 | loc = (*loc2p); | |
2179 | if (loc->cond | |
2180 | && is_breakpoint (loc->owner) | |
2181 | && loc->pspace->num == bl->pspace->num | |
2182 | && loc->owner->enable_state == bp_enabled | |
2183 | && loc->enabled) | |
2184 | /* Add the condition to the vector. This will be used later to send the | |
2185 | conditions to the target. */ | |
2186 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2187 | loc->cond_bytecode); | |
2188 | } | |
2189 | ||
2190 | return; | |
2191 | } | |
2192 | ||
d3ce09f5 SS |
2193 | /* Parses a command described by string CMD into an agent expression |
2194 | bytecode suitable for evaluation by the bytecode interpreter. | |
2195 | Return NULL if there was any error during parsing. */ | |
2196 | ||
2197 | static struct agent_expr * | |
2198 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2199 | { | |
2200 | struct cleanup *old_cleanups = 0; | |
2201 | struct expression *expr, **argvec; | |
2202 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2203 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2204 | const char *cmdrest; |
2205 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2206 | struct format_piece *fpieces; |
2207 | int nargs; | |
2208 | struct gdbarch *gdbarch = get_current_arch (); | |
2209 | ||
2210 | if (!cmd) | |
2211 | return NULL; | |
2212 | ||
2213 | cmdrest = cmd; | |
2214 | ||
2215 | if (*cmdrest == ',') | |
2216 | ++cmdrest; | |
bbc13ae3 | 2217 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2218 | |
2219 | if (*cmdrest++ != '"') | |
2220 | error (_("No format string following the location")); | |
2221 | ||
2222 | format_start = cmdrest; | |
2223 | ||
2224 | fpieces = parse_format_string (&cmdrest); | |
2225 | ||
2226 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2227 | ||
2228 | format_end = cmdrest; | |
2229 | ||
2230 | if (*cmdrest++ != '"') | |
2231 | error (_("Bad format string, non-terminated '\"'.")); | |
2232 | ||
bbc13ae3 | 2233 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2234 | |
2235 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2236 | error (_("Invalid argument syntax")); | |
2237 | ||
2238 | if (*cmdrest == ',') | |
2239 | cmdrest++; | |
bbc13ae3 | 2240 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2241 | |
2242 | /* For each argument, make an expression. */ | |
2243 | ||
2244 | argvec = (struct expression **) alloca (strlen (cmd) | |
2245 | * sizeof (struct expression *)); | |
2246 | ||
2247 | nargs = 0; | |
2248 | while (*cmdrest != '\0') | |
2249 | { | |
bbc13ae3 | 2250 | const char *cmd1; |
d3ce09f5 SS |
2251 | |
2252 | cmd1 = cmdrest; | |
2253 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2254 | argvec[nargs++] = expr; | |
2255 | cmdrest = cmd1; | |
2256 | if (*cmdrest == ',') | |
2257 | ++cmdrest; | |
2258 | } | |
2259 | ||
2260 | /* We don't want to stop processing, so catch any errors | |
2261 | that may show up. */ | |
2262 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2263 | { | |
2264 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2265 | format_start, format_end - format_start, | |
2266 | fpieces, nargs, argvec); | |
2267 | } | |
2268 | ||
2269 | if (ex.reason < 0) | |
2270 | { | |
2271 | /* If we got here, it means the command could not be parsed to a valid | |
2272 | bytecode expression and thus can't be evaluated on the target's side. | |
2273 | It's no use iterating through the other commands. */ | |
2274 | return NULL; | |
2275 | } | |
2276 | ||
2277 | do_cleanups (old_cleanups); | |
2278 | ||
2279 | /* We have a valid agent expression, return it. */ | |
2280 | return aexpr; | |
2281 | } | |
2282 | ||
2283 | /* Based on location BL, create a list of breakpoint commands to be | |
2284 | passed on to the target. If we have duplicated locations with | |
2285 | different commands, we will add any such to the list. */ | |
2286 | ||
2287 | static void | |
2288 | build_target_command_list (struct bp_location *bl) | |
2289 | { | |
2290 | struct bp_location **locp = NULL, **loc2p; | |
2291 | int null_command_or_parse_error = 0; | |
2292 | int modified = bl->needs_update; | |
2293 | struct bp_location *loc; | |
2294 | ||
2295 | /* For now, limit to agent-style dprintf breakpoints. */ | |
2296 | if (bl->owner->type != bp_dprintf | |
2297 | || strcmp (dprintf_style, dprintf_style_agent) != 0) | |
2298 | return; | |
2299 | ||
2300 | if (!target_can_run_breakpoint_commands ()) | |
2301 | return; | |
2302 | ||
2303 | /* Do a first pass to check for locations with no assigned | |
2304 | conditions or conditions that fail to parse to a valid agent expression | |
2305 | bytecode. If any of these happen, then it's no use to send conditions | |
2306 | to the target since this location will always trigger and generate a | |
2307 | response back to GDB. */ | |
2308 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2309 | { | |
2310 | loc = (*loc2p); | |
2311 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2312 | { | |
2313 | if (modified) | |
2314 | { | |
2315 | struct agent_expr *aexpr; | |
2316 | ||
2317 | /* Re-parse the commands since something changed. In that | |
2318 | case we already freed the command bytecodes (see | |
2319 | force_breakpoint_reinsertion). We just | |
2320 | need to parse the command to bytecodes again. */ | |
2321 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2322 | loc->owner->extra_string); | |
2323 | loc->cmd_bytecode = aexpr; | |
2324 | ||
2325 | if (!aexpr) | |
2326 | continue; | |
2327 | } | |
2328 | ||
2329 | /* If we have a NULL bytecode expression, it means something | |
2330 | went wrong or we have a null command expression. */ | |
2331 | if (!loc->cmd_bytecode) | |
2332 | { | |
2333 | null_command_or_parse_error = 1; | |
2334 | break; | |
2335 | } | |
2336 | } | |
2337 | } | |
2338 | ||
2339 | /* If anything failed, then we're not doing target-side commands, | |
2340 | and so clean up. */ | |
2341 | if (null_command_or_parse_error) | |
2342 | { | |
2343 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2344 | { | |
2345 | loc = (*loc2p); | |
2346 | if (is_breakpoint (loc->owner) | |
2347 | && loc->pspace->num == bl->pspace->num) | |
2348 | { | |
2349 | /* Only go as far as the first NULL bytecode is | |
2350 | located. */ | |
2351 | if (!loc->cond_bytecode) | |
2352 | return; | |
2353 | ||
2354 | free_agent_expr (loc->cond_bytecode); | |
2355 | loc->cond_bytecode = NULL; | |
2356 | } | |
2357 | } | |
2358 | } | |
2359 | ||
2360 | /* No NULL commands or failed bytecode generation. Build a command list | |
2361 | for this location's address. */ | |
2362 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2363 | { | |
2364 | loc = (*loc2p); | |
2365 | if (loc->owner->extra_string | |
2366 | && is_breakpoint (loc->owner) | |
2367 | && loc->pspace->num == bl->pspace->num | |
2368 | && loc->owner->enable_state == bp_enabled | |
2369 | && loc->enabled) | |
2370 | /* Add the command to the vector. This will be used later | |
2371 | to send the commands to the target. */ | |
2372 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2373 | loc->cmd_bytecode); | |
2374 | } | |
2375 | ||
2376 | bl->target_info.persist = 0; | |
2377 | /* Maybe flag this location as persistent. */ | |
2378 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2379 | bl->target_info.persist = 1; | |
2380 | } | |
2381 | ||
35df4500 TJB |
2382 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2383 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2384 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2385 | Returns 0 for success, 1 if the bp_location type is not supported or |
2386 | -1 for failure. | |
879bfdc2 | 2387 | |
4a64f543 MS |
2388 | NOTE drow/2003-09-09: This routine could be broken down to an |
2389 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2390 | static int |
35df4500 | 2391 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2392 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2393 | int *disabled_breaks, |
dd61ec5c MW |
2394 | int *hw_breakpoint_error, |
2395 | int *hw_bp_error_explained_already) | |
879bfdc2 DJ |
2396 | { |
2397 | int val = 0; | |
dd61ec5c MW |
2398 | char *hw_bp_err_string = NULL; |
2399 | struct gdb_exception e; | |
879bfdc2 | 2400 | |
b775012e | 2401 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2402 | return 0; |
2403 | ||
35c63cd8 JB |
2404 | /* Note we don't initialize bl->target_info, as that wipes out |
2405 | the breakpoint location's shadow_contents if the breakpoint | |
2406 | is still inserted at that location. This in turn breaks | |
2407 | target_read_memory which depends on these buffers when | |
2408 | a memory read is requested at the breakpoint location: | |
2409 | Once the target_info has been wiped, we fail to see that | |
2410 | we have a breakpoint inserted at that address and thus | |
2411 | read the breakpoint instead of returning the data saved in | |
2412 | the breakpoint location's shadow contents. */ | |
35df4500 TJB |
2413 | bl->target_info.placed_address = bl->address; |
2414 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2415 | bl->target_info.length = bl->length; |
8181d85f | 2416 | |
b775012e LM |
2417 | /* When working with target-side conditions, we must pass all the conditions |
2418 | for the same breakpoint address down to the target since GDB will not | |
2419 | insert those locations. With a list of breakpoint conditions, the target | |
2420 | can decide when to stop and notify GDB. */ | |
2421 | ||
2422 | if (is_breakpoint (bl->owner)) | |
2423 | { | |
2424 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2425 | build_target_command_list (bl); |
2426 | /* Reset the modification marker. */ | |
b775012e LM |
2427 | bl->needs_update = 0; |
2428 | } | |
2429 | ||
35df4500 TJB |
2430 | if (bl->loc_type == bp_loc_software_breakpoint |
2431 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2432 | { |
35df4500 | 2433 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2434 | { |
2435 | /* If the explicitly specified breakpoint type | |
2436 | is not hardware breakpoint, check the memory map to see | |
2437 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2438 | |
765dc015 VP |
2439 | Two important cases are: |
2440 | - location type is not hardware breakpoint, memory | |
2441 | is readonly. We change the type of the location to | |
2442 | hardware breakpoint. | |
4a64f543 MS |
2443 | - location type is hardware breakpoint, memory is |
2444 | read-write. This means we've previously made the | |
2445 | location hardware one, but then the memory map changed, | |
2446 | so we undo. | |
765dc015 | 2447 | |
4a64f543 MS |
2448 | When breakpoints are removed, remove_breakpoints will use |
2449 | location types we've just set here, the only possible | |
2450 | problem is that memory map has changed during running | |
2451 | program, but it's not going to work anyway with current | |
2452 | gdb. */ | |
765dc015 | 2453 | struct mem_region *mr |
35df4500 | 2454 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2455 | |
2456 | if (mr) | |
2457 | { | |
2458 | if (automatic_hardware_breakpoints) | |
2459 | { | |
765dc015 VP |
2460 | enum bp_loc_type new_type; |
2461 | ||
2462 | if (mr->attrib.mode != MEM_RW) | |
2463 | new_type = bp_loc_hardware_breakpoint; | |
2464 | else | |
2465 | new_type = bp_loc_software_breakpoint; | |
2466 | ||
35df4500 | 2467 | if (new_type != bl->loc_type) |
765dc015 VP |
2468 | { |
2469 | static int said = 0; | |
cc59ec59 | 2470 | |
35df4500 | 2471 | bl->loc_type = new_type; |
765dc015 VP |
2472 | if (!said) |
2473 | { | |
3e43a32a MS |
2474 | fprintf_filtered (gdb_stdout, |
2475 | _("Note: automatically using " | |
2476 | "hardware breakpoints for " | |
2477 | "read-only addresses.\n")); | |
765dc015 VP |
2478 | said = 1; |
2479 | } | |
2480 | } | |
2481 | } | |
35df4500 | 2482 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2483 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2484 | warning (_("cannot set software breakpoint " |
2485 | "at readonly address %s"), | |
35df4500 | 2486 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2487 | } |
2488 | } | |
2489 | ||
879bfdc2 DJ |
2490 | /* First check to see if we have to handle an overlay. */ |
2491 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2492 | || bl->section == NULL |
2493 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2494 | { |
2495 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2496 | TRY_CATCH (e, RETURN_MASK_ALL) |
2497 | { | |
2498 | val = bl->owner->ops->insert_location (bl); | |
2499 | } | |
2500 | if (e.reason < 0) | |
2501 | { | |
2502 | val = 1; | |
2503 | hw_bp_err_string = (char *) e.message; | |
2504 | } | |
879bfdc2 DJ |
2505 | } |
2506 | else | |
2507 | { | |
4a64f543 | 2508 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2509 | Shall we set a breakpoint at the LMA? */ |
2510 | if (!overlay_events_enabled) | |
2511 | { | |
2512 | /* Yes -- overlay event support is not active, | |
2513 | so we must try to set a breakpoint at the LMA. | |
2514 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2515 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2516 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2517 | bl->owner->number); |
879bfdc2 DJ |
2518 | else |
2519 | { | |
35df4500 TJB |
2520 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2521 | bl->section); | |
879bfdc2 | 2522 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2523 | bl->overlay_target_info = bl->target_info; |
2524 | bl->overlay_target_info.placed_address = addr; | |
2525 | val = target_insert_breakpoint (bl->gdbarch, | |
2526 | &bl->overlay_target_info); | |
879bfdc2 | 2527 | if (val != 0) |
99361f52 | 2528 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2529 | "Overlay breakpoint %d " |
2530 | "failed: in ROM?\n", | |
35df4500 | 2531 | bl->owner->number); |
879bfdc2 DJ |
2532 | } |
2533 | } | |
2534 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2535 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2536 | { |
2537 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2538 | TRY_CATCH (e, RETURN_MASK_ALL) |
2539 | { | |
2540 | val = bl->owner->ops->insert_location (bl); | |
2541 | } | |
2542 | if (e.reason < 0) | |
2543 | { | |
2544 | val = 1; | |
2545 | hw_bp_err_string = (char *) e.message; | |
2546 | } | |
879bfdc2 DJ |
2547 | } |
2548 | else | |
2549 | { | |
2550 | /* No. This breakpoint will not be inserted. | |
2551 | No error, but do not mark the bp as 'inserted'. */ | |
2552 | return 0; | |
2553 | } | |
2554 | } | |
2555 | ||
2556 | if (val) | |
2557 | { | |
2558 | /* Can't set the breakpoint. */ | |
35df4500 | 2559 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 2560 | { |
4a64f543 | 2561 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 2562 | val = 0; |
35df4500 | 2563 | bl->shlib_disabled = 1; |
8d3788bd | 2564 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2565 | if (!*disabled_breaks) |
2566 | { | |
2567 | fprintf_unfiltered (tmp_error_stream, | |
2568 | "Cannot insert breakpoint %d.\n", | |
2569 | bl->owner->number); | |
2570 | fprintf_unfiltered (tmp_error_stream, | |
2571 | "Temporarily disabling shared " | |
2572 | "library breakpoints:\n"); | |
2573 | } | |
2574 | *disabled_breaks = 1; | |
879bfdc2 | 2575 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2576 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
2577 | } |
2578 | else | |
879bfdc2 | 2579 | { |
35df4500 | 2580 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2581 | { |
dd61ec5c MW |
2582 | *hw_breakpoint_error = 1; |
2583 | *hw_bp_error_explained_already = hw_bp_err_string != NULL; | |
2584 | fprintf_unfiltered (tmp_error_stream, | |
2585 | "Cannot insert hardware breakpoint %d%s", | |
2586 | bl->owner->number, hw_bp_err_string ? ":" : ".\n"); | |
2587 | if (hw_bp_err_string) | |
2588 | fprintf_unfiltered (tmp_error_stream, "%s.\n", hw_bp_err_string); | |
879bfdc2 DJ |
2589 | } |
2590 | else | |
2591 | { | |
2592 | fprintf_unfiltered (tmp_error_stream, | |
2593 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 2594 | bl->owner->number); |
879bfdc2 DJ |
2595 | fprintf_filtered (tmp_error_stream, |
2596 | "Error accessing memory address "); | |
35df4500 | 2597 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 2598 | tmp_error_stream); |
879bfdc2 DJ |
2599 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
2600 | safe_strerror (val)); | |
2601 | } | |
2602 | ||
2603 | } | |
2604 | } | |
2605 | else | |
35df4500 | 2606 | bl->inserted = 1; |
879bfdc2 DJ |
2607 | |
2608 | return val; | |
2609 | } | |
2610 | ||
35df4500 | 2611 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2612 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2613 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2614 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2615 | { |
77b06cd7 TJB |
2616 | gdb_assert (bl->owner->ops != NULL |
2617 | && bl->owner->ops->insert_location != NULL); | |
2618 | ||
2619 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2620 | |
2621 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2622 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2623 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2624 | { |
2625 | struct bp_location *loc, **loc_temp; | |
2626 | ||
2627 | /* But don't try to insert it, if there's already another | |
2628 | hw_access location that would be considered a duplicate | |
2629 | of this one. */ | |
2630 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2631 | if (loc != bl |
85d721b8 | 2632 | && loc->watchpoint_type == hw_access |
35df4500 | 2633 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2634 | { |
35df4500 TJB |
2635 | bl->duplicate = 1; |
2636 | bl->inserted = 1; | |
2637 | bl->target_info = loc->target_info; | |
2638 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2639 | val = 0; |
2640 | break; | |
2641 | } | |
2642 | ||
2643 | if (val == 1) | |
2644 | { | |
77b06cd7 TJB |
2645 | bl->watchpoint_type = hw_access; |
2646 | val = bl->owner->ops->insert_location (bl); | |
2647 | ||
2648 | if (val) | |
2649 | /* Back to the original value. */ | |
2650 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2651 | } |
2652 | } | |
2653 | ||
35df4500 | 2654 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2655 | } |
2656 | ||
35df4500 | 2657 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2658 | { |
77b06cd7 TJB |
2659 | gdb_assert (bl->owner->ops != NULL |
2660 | && bl->owner->ops->insert_location != NULL); | |
2661 | ||
2662 | val = bl->owner->ops->insert_location (bl); | |
2663 | if (val) | |
2664 | { | |
2665 | bl->owner->enable_state = bp_disabled; | |
2666 | ||
2667 | if (val == 1) | |
2668 | warning (_("\ | |
2669 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2670 | of catchpoint."), bl->owner->number); | |
2671 | else | |
2672 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2673 | } | |
2674 | ||
2675 | bl->inserted = (val == 0); | |
1640b821 DJ |
2676 | |
2677 | /* We've already printed an error message if there was a problem | |
2678 | inserting this catchpoint, and we've disabled the catchpoint, | |
2679 | so just return success. */ | |
2680 | return 0; | |
879bfdc2 DJ |
2681 | } |
2682 | ||
2683 | return 0; | |
2684 | } | |
2685 | ||
6c95b8df PA |
2686 | /* This function is called when program space PSPACE is about to be |
2687 | deleted. It takes care of updating breakpoints to not reference | |
2688 | PSPACE anymore. */ | |
2689 | ||
2690 | void | |
2691 | breakpoint_program_space_exit (struct program_space *pspace) | |
2692 | { | |
2693 | struct breakpoint *b, *b_temp; | |
876fa593 | 2694 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2695 | |
2696 | /* Remove any breakpoint that was set through this program space. */ | |
2697 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2698 | { | |
2699 | if (b->pspace == pspace) | |
2700 | delete_breakpoint (b); | |
2701 | } | |
2702 | ||
2703 | /* Breakpoints set through other program spaces could have locations | |
2704 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2705 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2706 | { |
2707 | struct bp_location *tmp; | |
2708 | ||
2709 | if (loc->pspace == pspace) | |
2710 | { | |
2bdf28a0 | 2711 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2712 | if (loc->owner->loc == loc) |
2713 | loc->owner->loc = loc->next; | |
2714 | else | |
2715 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2716 | if (tmp->next == loc) | |
2717 | { | |
2718 | tmp->next = loc->next; | |
2719 | break; | |
2720 | } | |
2721 | } | |
2722 | } | |
2723 | ||
2724 | /* Now update the global location list to permanently delete the | |
2725 | removed locations above. */ | |
2726 | update_global_location_list (0); | |
2727 | } | |
2728 | ||
74960c60 VP |
2729 | /* Make sure all breakpoints are inserted in inferior. |
2730 | Throws exception on any error. | |
2731 | A breakpoint that is already inserted won't be inserted | |
2732 | again, so calling this function twice is safe. */ | |
2733 | void | |
2734 | insert_breakpoints (void) | |
2735 | { | |
2736 | struct breakpoint *bpt; | |
2737 | ||
2738 | ALL_BREAKPOINTS (bpt) | |
2739 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2740 | { |
2741 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2742 | ||
2743 | update_watchpoint (w, 0 /* don't reparse. */); | |
2744 | } | |
74960c60 | 2745 | |
b60e7edf | 2746 | update_global_location_list (1); |
74960c60 | 2747 | |
c35b1492 PA |
2748 | /* update_global_location_list does not insert breakpoints when |
2749 | always_inserted_mode is not enabled. Explicitly insert them | |
2750 | now. */ | |
2751 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2752 | insert_breakpoint_locations (); |
2753 | } | |
2754 | ||
20388dd6 YQ |
2755 | /* Invoke CALLBACK for each of bp_location. */ |
2756 | ||
2757 | void | |
2758 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2759 | { | |
2760 | struct bp_location *loc, **loc_tmp; | |
2761 | ||
2762 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2763 | { | |
2764 | callback (loc, NULL); | |
2765 | } | |
2766 | } | |
2767 | ||
b775012e LM |
2768 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2769 | target. It is the case with deleting and disabling of breakpoints when using | |
2770 | always-inserted mode. */ | |
2771 | ||
2772 | static void | |
2773 | update_inserted_breakpoint_locations (void) | |
2774 | { | |
2775 | struct bp_location *bl, **blp_tmp; | |
2776 | int error_flag = 0; | |
2777 | int val = 0; | |
2778 | int disabled_breaks = 0; | |
2779 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2780 | int hw_bp_details_reported = 0; |
b775012e LM |
2781 | |
2782 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2783 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2784 | ||
2785 | /* Explicitly mark the warning -- this will only be printed if | |
2786 | there was an error. */ | |
2787 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2788 | ||
2789 | save_current_space_and_thread (); | |
2790 | ||
2791 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2792 | { | |
2793 | /* We only want to update software breakpoints and hardware | |
2794 | breakpoints. */ | |
2795 | if (!is_breakpoint (bl->owner)) | |
2796 | continue; | |
2797 | ||
2798 | /* We only want to update locations that are already inserted | |
2799 | and need updating. This is to avoid unwanted insertion during | |
2800 | deletion of breakpoints. */ | |
2801 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2802 | continue; | |
2803 | ||
2804 | switch_to_program_space_and_thread (bl->pspace); | |
2805 | ||
2806 | /* For targets that support global breakpoints, there's no need | |
2807 | to select an inferior to insert breakpoint to. In fact, even | |
2808 | if we aren't attached to any process yet, we should still | |
2809 | insert breakpoints. */ | |
f5656ead | 2810 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2811 | && ptid_equal (inferior_ptid, null_ptid)) |
2812 | continue; | |
2813 | ||
2814 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 2815 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2816 | if (val) |
2817 | error_flag = val; | |
2818 | } | |
2819 | ||
2820 | if (error_flag) | |
2821 | { | |
2822 | target_terminal_ours_for_output (); | |
2823 | error_stream (tmp_error_stream); | |
2824 | } | |
2825 | ||
2826 | do_cleanups (cleanups); | |
2827 | } | |
2828 | ||
c30eee59 | 2829 | /* Used when starting or continuing the program. */ |
c906108c | 2830 | |
74960c60 VP |
2831 | static void |
2832 | insert_breakpoint_locations (void) | |
c906108c | 2833 | { |
a5606eee | 2834 | struct breakpoint *bpt; |
35df4500 | 2835 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2836 | int error_flag = 0; |
c906108c | 2837 | int val = 0; |
3fbb6ffa | 2838 | int disabled_breaks = 0; |
81d0cc19 | 2839 | int hw_breakpoint_error = 0; |
dd61ec5c | 2840 | int hw_bp_error_explained_already = 0; |
c906108c | 2841 | |
81d0cc19 | 2842 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2843 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2844 | |
81d0cc19 GS |
2845 | /* Explicitly mark the warning -- this will only be printed if |
2846 | there was an error. */ | |
2847 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2848 | |
2849 | save_current_space_and_thread (); | |
2850 | ||
35df4500 | 2851 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2852 | { |
b775012e | 2853 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2854 | continue; |
2855 | ||
4a64f543 MS |
2856 | /* There is no point inserting thread-specific breakpoints if |
2857 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2858 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2859 | if (bl->owner->thread != -1 |
2860 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2861 | continue; |
2862 | ||
35df4500 | 2863 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2864 | |
2865 | /* For targets that support global breakpoints, there's no need | |
2866 | to select an inferior to insert breakpoint to. In fact, even | |
2867 | if we aren't attached to any process yet, we should still | |
2868 | insert breakpoints. */ | |
f5656ead | 2869 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
2870 | && ptid_equal (inferior_ptid, null_ptid)) |
2871 | continue; | |
2872 | ||
3fbb6ffa | 2873 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2874 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2875 | if (val) |
eacd795a | 2876 | error_flag = val; |
879bfdc2 | 2877 | } |
c906108c | 2878 | |
4a64f543 MS |
2879 | /* If we failed to insert all locations of a watchpoint, remove |
2880 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2881 | ALL_BREAKPOINTS (bpt) |
2882 | { | |
2883 | int some_failed = 0; | |
2884 | struct bp_location *loc; | |
2885 | ||
2886 | if (!is_hardware_watchpoint (bpt)) | |
2887 | continue; | |
2888 | ||
d6b74ac4 | 2889 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2890 | continue; |
74960c60 VP |
2891 | |
2892 | if (bpt->disposition == disp_del_at_next_stop) | |
2893 | continue; | |
a5606eee VP |
2894 | |
2895 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2896 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2897 | { |
2898 | some_failed = 1; | |
2899 | break; | |
2900 | } | |
2901 | if (some_failed) | |
2902 | { | |
2903 | for (loc = bpt->loc; loc; loc = loc->next) | |
2904 | if (loc->inserted) | |
2905 | remove_breakpoint (loc, mark_uninserted); | |
2906 | ||
2907 | hw_breakpoint_error = 1; | |
2908 | fprintf_unfiltered (tmp_error_stream, | |
2909 | "Could not insert hardware watchpoint %d.\n", | |
2910 | bpt->number); | |
eacd795a | 2911 | error_flag = -1; |
a5606eee VP |
2912 | } |
2913 | } | |
2914 | ||
eacd795a | 2915 | if (error_flag) |
81d0cc19 GS |
2916 | { |
2917 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2918 | message about possibly exhausted resources. */ | |
dd61ec5c | 2919 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2920 | { |
c6510018 MS |
2921 | fprintf_unfiltered (tmp_error_stream, |
2922 | "Could not insert hardware breakpoints:\n\ | |
2923 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2924 | } |
81d0cc19 GS |
2925 | target_terminal_ours_for_output (); |
2926 | error_stream (tmp_error_stream); | |
2927 | } | |
f7545552 TT |
2928 | |
2929 | do_cleanups (cleanups); | |
c906108c SS |
2930 | } |
2931 | ||
c30eee59 TJB |
2932 | /* Used when the program stops. |
2933 | Returns zero if successful, or non-zero if there was a problem | |
2934 | removing a breakpoint location. */ | |
2935 | ||
c906108c | 2936 | int |
fba45db2 | 2937 | remove_breakpoints (void) |
c906108c | 2938 | { |
35df4500 | 2939 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2940 | int val = 0; |
c906108c | 2941 | |
35df4500 | 2942 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2943 | { |
1e4d1764 | 2944 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2945 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2946 | } |
3a1bae8e | 2947 | return val; |
c906108c SS |
2948 | } |
2949 | ||
6c95b8df PA |
2950 | /* Remove breakpoints of process PID. */ |
2951 | ||
2952 | int | |
2953 | remove_breakpoints_pid (int pid) | |
2954 | { | |
35df4500 | 2955 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2956 | int val; |
2957 | struct inferior *inf = find_inferior_pid (pid); | |
2958 | ||
35df4500 | 2959 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2960 | { |
35df4500 | 2961 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2962 | continue; |
2963 | ||
d3ce09f5 SS |
2964 | if (bl->owner->type == bp_dprintf) |
2965 | continue; | |
2966 | ||
35df4500 | 2967 | if (bl->inserted) |
6c95b8df | 2968 | { |
35df4500 | 2969 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2970 | if (val != 0) |
2971 | return val; | |
2972 | } | |
2973 | } | |
2974 | return 0; | |
2975 | } | |
2976 | ||
c906108c | 2977 | int |
fba45db2 | 2978 | reattach_breakpoints (int pid) |
c906108c | 2979 | { |
6c95b8df | 2980 | struct cleanup *old_chain; |
35df4500 | 2981 | struct bp_location *bl, **blp_tmp; |
c906108c | 2982 | int val; |
86b887df | 2983 | struct ui_file *tmp_error_stream; |
dd61ec5c | 2984 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
2985 | struct inferior *inf; |
2986 | struct thread_info *tp; | |
2987 | ||
2988 | tp = any_live_thread_of_process (pid); | |
2989 | if (tp == NULL) | |
2990 | return 1; | |
2991 | ||
2992 | inf = find_inferior_pid (pid); | |
2993 | old_chain = save_inferior_ptid (); | |
2994 | ||
2995 | inferior_ptid = tp->ptid; | |
a4954f26 | 2996 | |
86b887df | 2997 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2998 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2999 | |
35df4500 | 3000 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3001 | { |
35df4500 | 3002 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3003 | continue; |
3004 | ||
35df4500 | 3005 | if (bl->inserted) |
c5aa993b | 3006 | { |
35df4500 | 3007 | bl->inserted = 0; |
dd61ec5c | 3008 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3009 | if (val != 0) |
3010 | { | |
ce696e05 | 3011 | do_cleanups (old_chain); |
c5aa993b JM |
3012 | return val; |
3013 | } | |
3014 | } | |
3015 | } | |
ce696e05 | 3016 | do_cleanups (old_chain); |
c906108c SS |
3017 | return 0; |
3018 | } | |
3019 | ||
e58b0e63 PA |
3020 | static int internal_breakpoint_number = -1; |
3021 | ||
84f4c1fe PM |
3022 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3023 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3024 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3025 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3026 | breakpoint_count and that value incremented. Internal breakpoints |
3027 | do not set the internal var bpnum. */ | |
3028 | static void | |
3029 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3030 | { | |
3031 | if (internal) | |
3032 | b->number = internal_breakpoint_number--; | |
3033 | else | |
3034 | { | |
3035 | set_breakpoint_count (breakpoint_count + 1); | |
3036 | b->number = breakpoint_count; | |
3037 | } | |
3038 | } | |
3039 | ||
e62c965a | 3040 | static struct breakpoint * |
a6d9a66e | 3041 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3042 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3043 | const struct breakpoint_ops *ops) |
e62c965a | 3044 | { |
e62c965a PP |
3045 | struct symtab_and_line sal; |
3046 | struct breakpoint *b; | |
3047 | ||
4a64f543 | 3048 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3049 | |
3050 | sal.pc = address; | |
3051 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3052 | sal.pspace = current_program_space; |
e62c965a | 3053 | |
06edf0c0 | 3054 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3055 | b->number = internal_breakpoint_number--; |
3056 | b->disposition = disp_donttouch; | |
3057 | ||
3058 | return b; | |
3059 | } | |
3060 | ||
17450429 PP |
3061 | static const char *const longjmp_names[] = |
3062 | { | |
3063 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3064 | }; | |
3065 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3066 | ||
3067 | /* Per-objfile data private to breakpoint.c. */ | |
3068 | struct breakpoint_objfile_data | |
3069 | { | |
3070 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3071 | struct minimal_symbol *overlay_msym; | |
3072 | ||
3073 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3074 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
3075 | ||
28106bc2 SDJ |
3076 | /* True if we have looked for longjmp probes. */ |
3077 | int longjmp_searched; | |
3078 | ||
3079 | /* SystemTap probe points for longjmp (if any). */ | |
3080 | VEC (probe_p) *longjmp_probes; | |
3081 | ||
17450429 PP |
3082 | /* Minimal symbol for "std::terminate()" (if any). */ |
3083 | struct minimal_symbol *terminate_msym; | |
3084 | ||
3085 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3086 | struct minimal_symbol *exception_msym; | |
28106bc2 SDJ |
3087 | |
3088 | /* True if we have looked for exception probes. */ | |
3089 | int exception_searched; | |
3090 | ||
3091 | /* SystemTap probe points for unwinding (if any). */ | |
3092 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3093 | }; |
3094 | ||
3095 | static const struct objfile_data *breakpoint_objfile_key; | |
3096 | ||
3097 | /* Minimal symbol not found sentinel. */ | |
3098 | static struct minimal_symbol msym_not_found; | |
3099 | ||
3100 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3101 | ||
3102 | static int | |
3103 | msym_not_found_p (const struct minimal_symbol *msym) | |
3104 | { | |
3105 | return msym == &msym_not_found; | |
3106 | } | |
3107 | ||
3108 | /* Return per-objfile data needed by breakpoint.c. | |
3109 | Allocate the data if necessary. */ | |
3110 | ||
3111 | static struct breakpoint_objfile_data * | |
3112 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3113 | { | |
3114 | struct breakpoint_objfile_data *bp_objfile_data; | |
3115 | ||
3116 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3117 | if (bp_objfile_data == NULL) | |
3118 | { | |
3119 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3120 | sizeof (*bp_objfile_data)); | |
3121 | ||
3122 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3123 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3124 | } | |
3125 | return bp_objfile_data; | |
3126 | } | |
3127 | ||
28106bc2 SDJ |
3128 | static void |
3129 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3130 | { | |
3131 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3132 | ||
3133 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3134 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3135 | } | |
3136 | ||
e62c965a | 3137 | static void |
af02033e | 3138 | create_overlay_event_breakpoint (void) |
e62c965a | 3139 | { |
69de3c6a | 3140 | struct objfile *objfile; |
af02033e | 3141 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3142 | |
69de3c6a PP |
3143 | ALL_OBJFILES (objfile) |
3144 | { | |
3145 | struct breakpoint *b; | |
17450429 PP |
3146 | struct breakpoint_objfile_data *bp_objfile_data; |
3147 | CORE_ADDR addr; | |
69de3c6a | 3148 | |
17450429 PP |
3149 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3150 | ||
3151 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
3152 | continue; | |
3153 | ||
3154 | if (bp_objfile_data->overlay_msym == NULL) | |
3155 | { | |
3156 | struct minimal_symbol *m; | |
3157 | ||
3158 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3159 | if (m == NULL) | |
3160 | { | |
3161 | /* Avoid future lookups in this objfile. */ | |
3162 | bp_objfile_data->overlay_msym = &msym_not_found; | |
3163 | continue; | |
3164 | } | |
3165 | bp_objfile_data->overlay_msym = m; | |
3166 | } | |
e62c965a | 3167 | |
17450429 PP |
3168 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
3169 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
3170 | bp_overlay_event, |
3171 | &internal_breakpoint_ops); | |
69de3c6a | 3172 | b->addr_string = xstrdup (func_name); |
e62c965a | 3173 | |
69de3c6a PP |
3174 | if (overlay_debugging == ovly_auto) |
3175 | { | |
3176 | b->enable_state = bp_enabled; | |
3177 | overlay_events_enabled = 1; | |
3178 | } | |
3179 | else | |
3180 | { | |
3181 | b->enable_state = bp_disabled; | |
3182 | overlay_events_enabled = 0; | |
3183 | } | |
e62c965a PP |
3184 | } |
3185 | update_global_location_list (1); | |
3186 | } | |
3187 | ||
0fd8e87f | 3188 | static void |
af02033e | 3189 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3190 | { |
6c95b8df | 3191 | struct program_space *pspace; |
6c95b8df PA |
3192 | struct cleanup *old_chain; |
3193 | ||
3194 | old_chain = save_current_program_space (); | |
0fd8e87f | 3195 | |
6c95b8df | 3196 | ALL_PSPACES (pspace) |
af02033e PP |
3197 | { |
3198 | struct objfile *objfile; | |
3199 | ||
3200 | set_current_program_space (pspace); | |
3201 | ||
3202 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3203 | { |
af02033e PP |
3204 | int i; |
3205 | struct gdbarch *gdbarch; | |
17450429 | 3206 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3207 | |
af02033e PP |
3208 | gdbarch = get_objfile_arch (objfile); |
3209 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
3210 | continue; |
3211 | ||
17450429 PP |
3212 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3213 | ||
28106bc2 SDJ |
3214 | if (!bp_objfile_data->longjmp_searched) |
3215 | { | |
3216 | bp_objfile_data->longjmp_probes | |
3217 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3218 | bp_objfile_data->longjmp_searched = 1; | |
3219 | } | |
3220 | ||
3221 | if (bp_objfile_data->longjmp_probes != NULL) | |
3222 | { | |
3223 | int i; | |
3224 | struct probe *probe; | |
3225 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3226 | ||
3227 | for (i = 0; | |
3228 | VEC_iterate (probe_p, | |
3229 | bp_objfile_data->longjmp_probes, | |
3230 | i, probe); | |
3231 | ++i) | |
3232 | { | |
3233 | struct breakpoint *b; | |
3234 | ||
3235 | b = create_internal_breakpoint (gdbarch, probe->address, | |
3236 | bp_longjmp_master, | |
3237 | &internal_breakpoint_ops); | |
3238 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3239 | b->enable_state = bp_disabled; | |
3240 | } | |
3241 | ||
3242 | continue; | |
3243 | } | |
3244 | ||
17450429 | 3245 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3246 | { |
3247 | struct breakpoint *b; | |
af02033e | 3248 | const char *func_name; |
17450429 | 3249 | CORE_ADDR addr; |
6c95b8df | 3250 | |
17450429 | 3251 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 3252 | continue; |
0fd8e87f | 3253 | |
17450429 PP |
3254 | func_name = longjmp_names[i]; |
3255 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
3256 | { | |
3257 | struct minimal_symbol *m; | |
3258 | ||
3259 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3260 | if (m == NULL) | |
3261 | { | |
3262 | /* Prevent future lookups in this objfile. */ | |
3263 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
3264 | continue; | |
3265 | } | |
3266 | bp_objfile_data->longjmp_msym[i] = m; | |
3267 | } | |
3268 | ||
3269 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
3270 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3271 | &internal_breakpoint_ops); | |
af02033e PP |
3272 | b->addr_string = xstrdup (func_name); |
3273 | b->enable_state = bp_disabled; | |
3274 | } | |
0fd8e87f | 3275 | } |
af02033e | 3276 | } |
0fd8e87f | 3277 | update_global_location_list (1); |
6c95b8df PA |
3278 | |
3279 | do_cleanups (old_chain); | |
0fd8e87f UW |
3280 | } |
3281 | ||
af02033e | 3282 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3283 | static void |
af02033e | 3284 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3285 | { |
3286 | struct program_space *pspace; | |
aa7d318d | 3287 | struct cleanup *old_chain; |
af02033e | 3288 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3289 | |
3290 | old_chain = save_current_program_space (); | |
3291 | ||
3292 | ALL_PSPACES (pspace) | |
17450429 PP |
3293 | { |
3294 | struct objfile *objfile; | |
3295 | CORE_ADDR addr; | |
3296 | ||
3297 | set_current_program_space (pspace); | |
3298 | ||
aa7d318d TT |
3299 | ALL_OBJFILES (objfile) |
3300 | { | |
3301 | struct breakpoint *b; | |
17450429 | 3302 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3303 | |
17450429 | 3304 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3305 | |
17450429 PP |
3306 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
3307 | continue; | |
3308 | ||
3309 | if (bp_objfile_data->terminate_msym == NULL) | |
3310 | { | |
3311 | struct minimal_symbol *m; | |
3312 | ||
3313 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3314 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
3315 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
3316 | { | |
3317 | /* Prevent future lookups in this objfile. */ | |
3318 | bp_objfile_data->terminate_msym = &msym_not_found; | |
3319 | continue; | |
3320 | } | |
3321 | bp_objfile_data->terminate_msym = m; | |
3322 | } | |
aa7d318d | 3323 | |
17450429 PP |
3324 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3325 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
3326 | bp_std_terminate_master, |
3327 | &internal_breakpoint_ops); | |
aa7d318d TT |
3328 | b->addr_string = xstrdup (func_name); |
3329 | b->enable_state = bp_disabled; | |
3330 | } | |
17450429 PP |
3331 | } |
3332 | ||
aa7d318d TT |
3333 | update_global_location_list (1); |
3334 | ||
3335 | do_cleanups (old_chain); | |
3336 | } | |
3337 | ||
186c406b TT |
3338 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3339 | ||
70221824 | 3340 | static void |
186c406b TT |
3341 | create_exception_master_breakpoint (void) |
3342 | { | |
3343 | struct objfile *objfile; | |
17450429 | 3344 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3345 | |
3346 | ALL_OBJFILES (objfile) | |
3347 | { | |
17450429 PP |
3348 | struct breakpoint *b; |
3349 | struct gdbarch *gdbarch; | |
3350 | struct breakpoint_objfile_data *bp_objfile_data; | |
3351 | CORE_ADDR addr; | |
3352 | ||
3353 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3354 | ||
28106bc2 SDJ |
3355 | /* We prefer the SystemTap probe point if it exists. */ |
3356 | if (!bp_objfile_data->exception_searched) | |
3357 | { | |
3358 | bp_objfile_data->exception_probes | |
3359 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3360 | bp_objfile_data->exception_searched = 1; | |
3361 | } | |
3362 | ||
3363 | if (bp_objfile_data->exception_probes != NULL) | |
3364 | { | |
3365 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3366 | int i; | |
3367 | struct probe *probe; | |
3368 | ||
3369 | for (i = 0; | |
3370 | VEC_iterate (probe_p, | |
3371 | bp_objfile_data->exception_probes, | |
3372 | i, probe); | |
3373 | ++i) | |
3374 | { | |
3375 | struct breakpoint *b; | |
3376 | ||
3377 | b = create_internal_breakpoint (gdbarch, probe->address, | |
3378 | bp_exception_master, | |
3379 | &internal_breakpoint_ops); | |
3380 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3381 | b->enable_state = bp_disabled; | |
3382 | } | |
3383 | ||
3384 | continue; | |
3385 | } | |
3386 | ||
3387 | /* Otherwise, try the hook function. */ | |
3388 | ||
17450429 PP |
3389 | if (msym_not_found_p (bp_objfile_data->exception_msym)) |
3390 | continue; | |
3391 | ||
3392 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3393 | |
17450429 | 3394 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 3395 | { |
17450429 | 3396 | struct minimal_symbol *debug_hook; |
186c406b | 3397 | |
17450429 PP |
3398 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3399 | if (debug_hook == NULL) | |
3400 | { | |
3401 | bp_objfile_data->exception_msym = &msym_not_found; | |
3402 | continue; | |
3403 | } | |
3404 | ||
3405 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3406 | } |
17450429 PP |
3407 | |
3408 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
3409 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
3410 | ¤t_target); | |
06edf0c0 PA |
3411 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3412 | &internal_breakpoint_ops); | |
17450429 PP |
3413 | b->addr_string = xstrdup (func_name); |
3414 | b->enable_state = bp_disabled; | |
186c406b TT |
3415 | } |
3416 | ||
3417 | update_global_location_list (1); | |
3418 | } | |
3419 | ||
c906108c | 3420 | void |
fba45db2 | 3421 | update_breakpoints_after_exec (void) |
c906108c | 3422 | { |
35df4500 | 3423 | struct breakpoint *b, *b_tmp; |
876fa593 | 3424 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3425 | |
25b22b0a PA |
3426 | /* We're about to delete breakpoints from GDB's lists. If the |
3427 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3428 | writing the breakpoints' "shadow contents" back into memory. The | |
3429 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3430 | do that. Instead, the target is responsible from marking | |
3431 | breakpoints out as soon as it detects an exec. We don't do that | |
3432 | here instead, because there may be other attempts to delete | |
3433 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3434 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3435 | if (bploc->pspace == current_program_space) |
3436 | gdb_assert (!bploc->inserted); | |
c906108c | 3437 | |
35df4500 | 3438 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3439 | { |
6c95b8df PA |
3440 | if (b->pspace != current_program_space) |
3441 | continue; | |
3442 | ||
4a64f543 | 3443 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3444 | if (b->type == bp_shlib_event) |
3445 | { | |
3446 | delete_breakpoint (b); | |
3447 | continue; | |
3448 | } | |
c906108c | 3449 | |
4a64f543 | 3450 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3451 | if (b->type == bp_jit_event) |
3452 | { | |
3453 | delete_breakpoint (b); | |
3454 | continue; | |
3455 | } | |
3456 | ||
1900040c | 3457 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3458 | as must overlay event and longjmp master breakpoints. */ |
3459 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3460 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3461 | || b->type == bp_exception_master) | |
c4093a6a JM |
3462 | { |
3463 | delete_breakpoint (b); | |
3464 | continue; | |
3465 | } | |
3466 | ||
4a64f543 | 3467 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3468 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3469 | { |
3470 | delete_breakpoint (b); | |
3471 | continue; | |
3472 | } | |
3473 | ||
611c83ae PA |
3474 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3475 | after an exec. */ | |
186c406b | 3476 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3477 | || b->type == bp_longjmp_call_dummy |
186c406b | 3478 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3479 | { |
3480 | delete_breakpoint (b); | |
3481 | continue; | |
3482 | } | |
3483 | ||
ce78b96d JB |
3484 | if (b->type == bp_catchpoint) |
3485 | { | |
3486 | /* For now, none of the bp_catchpoint breakpoints need to | |
3487 | do anything at this point. In the future, if some of | |
3488 | the catchpoints need to something, we will need to add | |
3489 | a new method, and call this method from here. */ | |
3490 | continue; | |
3491 | } | |
3492 | ||
c5aa993b JM |
3493 | /* bp_finish is a special case. The only way we ought to be able |
3494 | to see one of these when an exec() has happened, is if the user | |
3495 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3496 | carries them to the call-site of the current callee, by setting | |
3497 | a temporary bp there and resuming. But in this case, the finish | |
3498 | will carry them entirely through the vfork & exec. | |
3499 | ||
3500 | We don't want to allow a bp_finish to remain inserted now. But | |
3501 | we can't safely delete it, 'cause finish_command has a handle to | |
3502 | the bp on a bpstat, and will later want to delete it. There's a | |
3503 | chance (and I've seen it happen) that if we delete the bp_finish | |
3504 | here, that its storage will get reused by the time finish_command | |
3505 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3506 | We really must allow finish_command to delete a bp_finish. | |
3507 | ||
e5dd4106 | 3508 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3509 | it's safe to delete something others may have handles to?" |
3510 | problem, what we'll do here is just uninsert the bp_finish, and | |
3511 | let finish_command delete it. | |
3512 | ||
3513 | (We know the bp_finish is "doomed" in the sense that it's | |
3514 | momentary, and will be deleted as soon as finish_command sees | |
3515 | the inferior stopped. So it doesn't matter that the bp's | |
3516 | address is probably bogus in the new a.out, unlike e.g., the | |
3517 | solib breakpoints.) */ | |
c5aa993b | 3518 | |
c5aa993b JM |
3519 | if (b->type == bp_finish) |
3520 | { | |
3521 | continue; | |
3522 | } | |
3523 | ||
3524 | /* Without a symbolic address, we have little hope of the | |
3525 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3526 | a.out. */ |
c5aa993b JM |
3527 | if (b->addr_string == NULL) |
3528 | { | |
3529 | delete_breakpoint (b); | |
3530 | continue; | |
3531 | } | |
c5aa993b | 3532 | } |
1900040c | 3533 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3534 | create_overlay_event_breakpoint (); |
3535 | create_longjmp_master_breakpoint (); | |
3536 | create_std_terminate_master_breakpoint (); | |
186c406b | 3537 | create_exception_master_breakpoint (); |
c906108c SS |
3538 | } |
3539 | ||
3540 | int | |
d80ee84f | 3541 | detach_breakpoints (ptid_t ptid) |
c906108c | 3542 | { |
35df4500 | 3543 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3544 | int val = 0; |
ce696e05 | 3545 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3546 | struct inferior *inf = current_inferior (); |
c5aa993b | 3547 | |
d80ee84f | 3548 | if (PIDGET (ptid) == PIDGET (inferior_ptid)) |
8a3fe4f8 | 3549 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3550 | |
6c95b8df | 3551 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3552 | inferior_ptid = ptid; |
35df4500 | 3553 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3554 | { |
35df4500 | 3555 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3556 | continue; |
3557 | ||
35df4500 TJB |
3558 | if (bl->inserted) |
3559 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3560 | } |
d03285ec UW |
3561 | |
3562 | /* Detach single-step breakpoints as well. */ | |
3563 | detach_single_step_breakpoints (); | |
3564 | ||
ce696e05 | 3565 | do_cleanups (old_chain); |
3a1bae8e | 3566 | return val; |
c906108c SS |
3567 | } |
3568 | ||
35df4500 | 3569 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3570 | Note that this is used to detach breakpoints from a child fork. |
3571 | When we get here, the child isn't in the inferior list, and neither | |
3572 | do we have objects to represent its address space --- we should | |
35df4500 | 3573 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3574 | |
c906108c | 3575 | static int |
35df4500 | 3576 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3577 | { |
3578 | int val; | |
c5aa993b | 3579 | |
35df4500 TJB |
3580 | /* BL is never in moribund_locations by our callers. */ |
3581 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3582 | |
35df4500 | 3583 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3584 | /* Permanent breakpoints cannot be inserted or removed. */ |
3585 | return 0; | |
3586 | ||
74960c60 VP |
3587 | /* The type of none suggests that owner is actually deleted. |
3588 | This should not ever happen. */ | |
35df4500 | 3589 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3590 | |
35df4500 TJB |
3591 | if (bl->loc_type == bp_loc_software_breakpoint |
3592 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3593 | { |
c02f5703 MS |
3594 | /* "Normal" instruction breakpoint: either the standard |
3595 | trap-instruction bp (bp_breakpoint), or a | |
3596 | bp_hardware_breakpoint. */ | |
3597 | ||
3598 | /* First check to see if we have to handle an overlay. */ | |
3599 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3600 | || bl->section == NULL |
3601 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3602 | { |
3603 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3604 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3605 | } |
c906108c SS |
3606 | else |
3607 | { | |
4a64f543 | 3608 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3609 | Did we set a breakpoint at the LMA? */ |
3610 | if (!overlay_events_enabled) | |
3611 | { | |
3612 | /* Yes -- overlay event support is not active, so we | |
3613 | should have set a breakpoint at the LMA. Remove it. | |
3614 | */ | |
c02f5703 MS |
3615 | /* Ignore any failures: if the LMA is in ROM, we will |
3616 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3617 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3618 | target_remove_hw_breakpoint (bl->gdbarch, | |
3619 | &bl->overlay_target_info); | |
c02f5703 | 3620 | else |
35df4500 TJB |
3621 | target_remove_breakpoint (bl->gdbarch, |
3622 | &bl->overlay_target_info); | |
c02f5703 MS |
3623 | } |
3624 | /* Did we set a breakpoint at the VMA? | |
3625 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3626 | if (bl->inserted) |
c906108c | 3627 | { |
c02f5703 MS |
3628 | /* Yes -- remove it. Previously we did not bother to |
3629 | remove the breakpoint if the section had been | |
3630 | unmapped, but let's not rely on that being safe. We | |
3631 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3632 | |
3633 | /* However, we should remove *software* breakpoints only | |
3634 | if the section is still mapped, or else we overwrite | |
3635 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3636 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3637 | || section_is_mapped (bl->section)) | |
3638 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3639 | else |
3640 | val = 0; | |
c906108c | 3641 | } |
c02f5703 MS |
3642 | else |
3643 | { | |
3644 | /* No -- not inserted, so no need to remove. No error. */ | |
3645 | val = 0; | |
3646 | } | |
c906108c | 3647 | } |
879d1e6b UW |
3648 | |
3649 | /* In some cases, we might not be able to remove a breakpoint | |
3650 | in a shared library that has already been removed, but we | |
3651 | have not yet processed the shlib unload event. */ | |
35df4500 | 3652 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
3653 | val = 0; |
3654 | ||
c906108c SS |
3655 | if (val) |
3656 | return val; | |
35df4500 | 3657 | bl->inserted = (is == mark_inserted); |
c906108c | 3658 | } |
35df4500 | 3659 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3660 | { |
77b06cd7 TJB |
3661 | gdb_assert (bl->owner->ops != NULL |
3662 | && bl->owner->ops->remove_location != NULL); | |
3663 | ||
35df4500 | 3664 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3665 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3666 | |
c906108c | 3667 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3668 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3669 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3670 | bl->owner->number); |
c906108c | 3671 | } |
35df4500 TJB |
3672 | else if (bl->owner->type == bp_catchpoint |
3673 | && breakpoint_enabled (bl->owner) | |
3674 | && !bl->duplicate) | |
ce78b96d | 3675 | { |
77b06cd7 TJB |
3676 | gdb_assert (bl->owner->ops != NULL |
3677 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3678 | |
77b06cd7 | 3679 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3680 | if (val) |
3681 | return val; | |
77b06cd7 | 3682 | |
35df4500 | 3683 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3684 | } |
c906108c SS |
3685 | |
3686 | return 0; | |
3687 | } | |
3688 | ||
6c95b8df | 3689 | static int |
35df4500 | 3690 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3691 | { |
3692 | int ret; | |
3693 | struct cleanup *old_chain; | |
3694 | ||
35df4500 TJB |
3695 | /* BL is never in moribund_locations by our callers. */ |
3696 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3697 | |
35df4500 | 3698 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3699 | /* Permanent breakpoints cannot be inserted or removed. */ |
3700 | return 0; | |
3701 | ||
3702 | /* The type of none suggests that owner is actually deleted. | |
3703 | This should not ever happen. */ | |
35df4500 | 3704 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3705 | |
3706 | old_chain = save_current_space_and_thread (); | |
3707 | ||
35df4500 | 3708 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3709 | |
35df4500 | 3710 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3711 | |
3712 | do_cleanups (old_chain); | |
3713 | return ret; | |
3714 | } | |
3715 | ||
c906108c SS |
3716 | /* Clear the "inserted" flag in all breakpoints. */ |
3717 | ||
25b22b0a | 3718 | void |
fba45db2 | 3719 | mark_breakpoints_out (void) |
c906108c | 3720 | { |
35df4500 | 3721 | struct bp_location *bl, **blp_tmp; |
c906108c | 3722 | |
35df4500 TJB |
3723 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3724 | if (bl->pspace == current_program_space) | |
3725 | bl->inserted = 0; | |
c906108c SS |
3726 | } |
3727 | ||
53a5351d JM |
3728 | /* Clear the "inserted" flag in all breakpoints and delete any |
3729 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3730 | |
3731 | Plus other such housekeeping that has to be done for breakpoints | |
3732 | between runs. | |
3733 | ||
53a5351d JM |
3734 | Note: this function gets called at the end of a run (by |
3735 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3736 | init_wait_for_inferior). */ |
c906108c SS |
3737 | |
3738 | ||
3739 | ||
3740 | void | |
fba45db2 | 3741 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3742 | { |
35df4500 TJB |
3743 | struct breakpoint *b, *b_tmp; |
3744 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3745 | int ix; |
6c95b8df | 3746 | struct program_space *pspace = current_program_space; |
c906108c | 3747 | |
50c71eaf PA |
3748 | /* If breakpoint locations are shared across processes, then there's |
3749 | nothing to do. */ | |
f5656ead | 3750 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3751 | return; |
3752 | ||
35df4500 | 3753 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3754 | { |
35df4500 TJB |
3755 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3756 | if (bl->pspace == pspace | |
3757 | && bl->owner->enable_state != bp_permanent) | |
3758 | bl->inserted = 0; | |
6c95b8df | 3759 | } |
075f6582 | 3760 | |
35df4500 | 3761 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3762 | { |
6c95b8df PA |
3763 | if (b->loc && b->loc->pspace != pspace) |
3764 | continue; | |
3765 | ||
c5aa993b JM |
3766 | switch (b->type) |
3767 | { | |
3768 | case bp_call_dummy: | |
e2e4d78b | 3769 | case bp_longjmp_call_dummy: |
c906108c | 3770 | |
c5aa993b | 3771 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3772 | cause problems when the inferior is rerun, so we better get |
3773 | rid of it. */ | |
3774 | ||
3775 | case bp_watchpoint_scope: | |
3776 | ||
3777 | /* Also get rid of scope breakpoints. */ | |
3778 | ||
3779 | case bp_shlib_event: | |
3780 | ||
3781 | /* Also remove solib event breakpoints. Their addresses may | |
3782 | have changed since the last time we ran the program. | |
3783 | Actually we may now be debugging against different target; | |
3784 | and so the solib backend that installed this breakpoint may | |
3785 | not be used in by the target. E.g., | |
3786 | ||
3787 | (gdb) file prog-linux | |
3788 | (gdb) run # native linux target | |
3789 | ... | |
3790 | (gdb) kill | |
3791 | (gdb) file prog-win.exe | |
3792 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3793 | */ | |
c906108c | 3794 | |
f59f708a PA |
3795 | case bp_step_resume: |
3796 | ||
3797 | /* Also remove step-resume breakpoints. */ | |
3798 | ||
c5aa993b JM |
3799 | delete_breakpoint (b); |
3800 | break; | |
c906108c | 3801 | |
c5aa993b JM |
3802 | case bp_watchpoint: |
3803 | case bp_hardware_watchpoint: | |
3804 | case bp_read_watchpoint: | |
3805 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3806 | { |
3807 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3808 | |
3a5c3e22 PA |
3809 | /* Likewise for watchpoints on local expressions. */ |
3810 | if (w->exp_valid_block != NULL) | |
3811 | delete_breakpoint (b); | |
3812 | else if (context == inf_starting) | |
3813 | { | |
3814 | /* Reset val field to force reread of starting value in | |
3815 | insert_breakpoints. */ | |
3816 | if (w->val) | |
3817 | value_free (w->val); | |
3818 | w->val = NULL; | |
3819 | w->val_valid = 0; | |
c860120c | 3820 | } |
3a5c3e22 | 3821 | } |
c5aa993b JM |
3822 | break; |
3823 | default: | |
c5aa993b JM |
3824 | break; |
3825 | } | |
3826 | } | |
1c5cfe86 PA |
3827 | |
3828 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3829 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3830 | decref_bp_location (&bl); | |
1c5cfe86 | 3831 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3832 | } |
3833 | ||
6c95b8df PA |
3834 | /* These functions concern about actual breakpoints inserted in the |
3835 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3836 | we need to hop over the bkpt --- so we check for address space | |
3837 | match, not program space. */ | |
3838 | ||
c2c6d25f JM |
3839 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3840 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3841 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3842 | permanent breakpoint. | |
3843 | - When continuing from a location with an ordinary breakpoint, we | |
3844 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3845 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3846 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3847 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3848 | |
c2c6d25f | 3849 | enum breakpoint_here |
6c95b8df | 3850 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 3851 | { |
35df4500 | 3852 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3853 | int any_breakpoint_here = 0; |
c906108c | 3854 | |
35df4500 | 3855 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3856 | { |
35df4500 TJB |
3857 | if (bl->loc_type != bp_loc_software_breakpoint |
3858 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3859 | continue; |
3860 | ||
f1310107 | 3861 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
3862 | if ((breakpoint_enabled (bl->owner) |
3863 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 3864 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3865 | { |
3866 | if (overlay_debugging | |
35df4500 TJB |
3867 | && section_is_overlay (bl->section) |
3868 | && !section_is_mapped (bl->section)) | |
075f6582 | 3869 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 3870 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
3871 | return permanent_breakpoint_here; |
3872 | else | |
3873 | any_breakpoint_here = 1; | |
3874 | } | |
3875 | } | |
c906108c | 3876 | |
c2c6d25f | 3877 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
3878 | } |
3879 | ||
1c5cfe86 PA |
3880 | /* Return true if there's a moribund breakpoint at PC. */ |
3881 | ||
3882 | int | |
6c95b8df | 3883 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
3884 | { |
3885 | struct bp_location *loc; | |
3886 | int ix; | |
3887 | ||
3888 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 3889 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
3890 | return 1; |
3891 | ||
3892 | return 0; | |
3893 | } | |
c2c6d25f | 3894 | |
c36b740a | 3895 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
3896 | inserted using regular breakpoint_chain / bp_location array |
3897 | mechanism. This does not check for single-step breakpoints, which | |
3898 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
3899 | |
3900 | int | |
4a64f543 MS |
3901 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
3902 | CORE_ADDR pc) | |
c906108c | 3903 | { |
35df4500 | 3904 | struct bp_location *bl, **blp_tmp; |
c906108c | 3905 | |
35df4500 | 3906 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3907 | { |
35df4500 TJB |
3908 | if (bl->loc_type != bp_loc_software_breakpoint |
3909 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3910 | continue; |
3911 | ||
35df4500 | 3912 | if (bl->inserted |
f1310107 | 3913 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3914 | { |
3915 | if (overlay_debugging | |
35df4500 TJB |
3916 | && section_is_overlay (bl->section) |
3917 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
3918 | continue; /* unmapped overlay -- can't be a match */ |
3919 | else | |
3920 | return 1; | |
3921 | } | |
c5aa993b | 3922 | } |
c36b740a VP |
3923 | return 0; |
3924 | } | |
3925 | ||
3926 | /* Returns non-zero iff there's either regular breakpoint | |
3927 | or a single step breakpoint inserted at PC. */ | |
3928 | ||
3929 | int | |
6c95b8df | 3930 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 3931 | { |
6c95b8df | 3932 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 3933 | return 1; |
c906108c | 3934 | |
6c95b8df | 3935 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3936 | return 1; |
3937 | ||
c906108c SS |
3938 | return 0; |
3939 | } | |
3940 | ||
4fa8626c DJ |
3941 | /* This function returns non-zero iff there is a software breakpoint |
3942 | inserted at PC. */ | |
3943 | ||
3944 | int | |
3e43a32a MS |
3945 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
3946 | CORE_ADDR pc) | |
4fa8626c | 3947 | { |
35df4500 | 3948 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 3949 | |
35df4500 | 3950 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 3951 | { |
35df4500 | 3952 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
3953 | continue; |
3954 | ||
35df4500 TJB |
3955 | if (bl->inserted |
3956 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 3957 | aspace, pc)) |
4fa8626c DJ |
3958 | { |
3959 | if (overlay_debugging | |
35df4500 TJB |
3960 | && section_is_overlay (bl->section) |
3961 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
3962 | continue; /* unmapped overlay -- can't be a match */ |
3963 | else | |
3964 | return 1; | |
3965 | } | |
3966 | } | |
3967 | ||
1aafd4da | 3968 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 3969 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3970 | return 1; |
3971 | ||
4fa8626c DJ |
3972 | return 0; |
3973 | } | |
3974 | ||
9093389c PA |
3975 | int |
3976 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
3977 | CORE_ADDR addr, ULONGEST len) | |
3978 | { | |
3979 | struct breakpoint *bpt; | |
3980 | ||
3981 | ALL_BREAKPOINTS (bpt) | |
3982 | { | |
3983 | struct bp_location *loc; | |
3984 | ||
3985 | if (bpt->type != bp_hardware_watchpoint | |
3986 | && bpt->type != bp_access_watchpoint) | |
3987 | continue; | |
3988 | ||
3989 | if (!breakpoint_enabled (bpt)) | |
3990 | continue; | |
3991 | ||
3992 | for (loc = bpt->loc; loc; loc = loc->next) | |
3993 | if (loc->pspace->aspace == aspace && loc->inserted) | |
3994 | { | |
3995 | CORE_ADDR l, h; | |
3996 | ||
3997 | /* Check for intersection. */ | |
3998 | l = max (loc->address, addr); | |
3999 | h = min (loc->address + loc->length, addr + len); | |
4000 | if (l < h) | |
4001 | return 1; | |
4002 | } | |
4003 | } | |
4004 | return 0; | |
4005 | } | |
4006 | ||
075f6582 DJ |
4007 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
4008 | PC is valid for process/thread PTID. */ | |
c906108c SS |
4009 | |
4010 | int | |
6c95b8df PA |
4011 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
4012 | ptid_t ptid) | |
c906108c | 4013 | { |
35df4500 | 4014 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 4015 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 4016 | int thread = -1; |
4a306c9a | 4017 | int task = 0; |
a6f1cd96 | 4018 | |
35df4500 | 4019 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4020 | { |
35df4500 TJB |
4021 | if (bl->loc_type != bp_loc_software_breakpoint |
4022 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4023 | continue; |
4024 | ||
35df4500 TJB |
4025 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
4026 | if (!breakpoint_enabled (bl->owner) | |
4027 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
4028 | continue; |
4029 | ||
f1310107 | 4030 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
4031 | continue; |
4032 | ||
35df4500 | 4033 | if (bl->owner->thread != -1) |
075f6582 | 4034 | { |
a6f1cd96 JB |
4035 | /* This is a thread-specific breakpoint. Check that ptid |
4036 | matches that thread. If thread hasn't been computed yet, | |
4037 | it is now time to do so. */ | |
4038 | if (thread == -1) | |
4039 | thread = pid_to_thread_id (ptid); | |
35df4500 | 4040 | if (bl->owner->thread != thread) |
a6f1cd96 | 4041 | continue; |
075f6582 | 4042 | } |
a6f1cd96 | 4043 | |
35df4500 | 4044 | if (bl->owner->task != 0) |
4a306c9a JB |
4045 | { |
4046 | /* This is a task-specific breakpoint. Check that ptid | |
4047 | matches that task. If task hasn't been computed yet, | |
4048 | it is now time to do so. */ | |
4049 | if (task == 0) | |
4050 | task = ada_get_task_number (ptid); | |
35df4500 | 4051 | if (bl->owner->task != task) |
4a306c9a JB |
4052 | continue; |
4053 | } | |
4054 | ||
a6f1cd96 | 4055 | if (overlay_debugging |
35df4500 TJB |
4056 | && section_is_overlay (bl->section) |
4057 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
4058 | continue; /* unmapped overlay -- can't be a match */ |
4059 | ||
4060 | return 1; | |
c5aa993b | 4061 | } |
c906108c SS |
4062 | |
4063 | return 0; | |
4064 | } | |
c906108c | 4065 | \f |
c5aa993b | 4066 | |
c906108c SS |
4067 | /* bpstat stuff. External routines' interfaces are documented |
4068 | in breakpoint.h. */ | |
4069 | ||
4070 | int | |
c326b90e | 4071 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4072 | { |
533be4dd | 4073 | return (ep->type == bp_catchpoint); |
c906108c SS |
4074 | } |
4075 | ||
f431efe5 PA |
4076 | /* Frees any storage that is part of a bpstat. Does not walk the |
4077 | 'next' chain. */ | |
4078 | ||
4079 | static void | |
198757a8 VP |
4080 | bpstat_free (bpstat bs) |
4081 | { | |
4082 | if (bs->old_val != NULL) | |
4083 | value_free (bs->old_val); | |
9add0f1b | 4084 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4085 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4086 | xfree (bs); |
4087 | } | |
4088 | ||
c906108c SS |
4089 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4090 | Also free any storage that is part of a bpstat. */ | |
4091 | ||
4092 | void | |
fba45db2 | 4093 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4094 | { |
4095 | bpstat p; | |
4096 | bpstat q; | |
4097 | ||
4098 | if (bsp == 0) | |
4099 | return; | |
4100 | p = *bsp; | |
4101 | while (p != NULL) | |
4102 | { | |
4103 | q = p->next; | |
198757a8 | 4104 | bpstat_free (p); |
c906108c SS |
4105 | p = q; |
4106 | } | |
4107 | *bsp = NULL; | |
4108 | } | |
4109 | ||
4110 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4111 | is part of the bpstat is copied as well. */ | |
4112 | ||
4113 | bpstat | |
fba45db2 | 4114 | bpstat_copy (bpstat bs) |
c906108c SS |
4115 | { |
4116 | bpstat p = NULL; | |
4117 | bpstat tmp; | |
4118 | bpstat retval = NULL; | |
4119 | ||
4120 | if (bs == NULL) | |
4121 | return bs; | |
4122 | ||
4123 | for (; bs != NULL; bs = bs->next) | |
4124 | { | |
4125 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4126 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4127 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4128 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4129 | if (bs->old_val != NULL) |
3c3185ac JK |
4130 | { |
4131 | tmp->old_val = value_copy (bs->old_val); | |
4132 | release_value (tmp->old_val); | |
4133 | } | |
31cc81e9 | 4134 | |
c906108c SS |
4135 | if (p == NULL) |
4136 | /* This is the first thing in the chain. */ | |
4137 | retval = tmp; | |
4138 | else | |
4139 | p->next = tmp; | |
4140 | p = tmp; | |
4141 | } | |
4142 | p->next = NULL; | |
4143 | return retval; | |
4144 | } | |
4145 | ||
4a64f543 | 4146 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4147 | |
4148 | bpstat | |
fba45db2 | 4149 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4150 | { |
c5aa993b JM |
4151 | if (bsp == NULL) |
4152 | return NULL; | |
c906108c | 4153 | |
c5aa993b JM |
4154 | for (; bsp != NULL; bsp = bsp->next) |
4155 | { | |
f431efe5 | 4156 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4157 | return bsp; |
4158 | } | |
c906108c SS |
4159 | return NULL; |
4160 | } | |
4161 | ||
ab04a2af TT |
4162 | /* See breakpoint.h. */ |
4163 | ||
4164 | enum bpstat_signal_value | |
4165 | bpstat_explains_signal (bpstat bsp) | |
4166 | { | |
4167 | enum bpstat_signal_value result = BPSTAT_SIGNAL_NO; | |
4168 | ||
4169 | for (; bsp != NULL; bsp = bsp->next) | |
4170 | { | |
4171 | /* Ensure that, if we ever entered this loop, then we at least | |
4172 | return BPSTAT_SIGNAL_HIDE. */ | |
4173 | enum bpstat_signal_value newval = BPSTAT_SIGNAL_HIDE; | |
4174 | ||
4175 | if (bsp->breakpoint_at != NULL) | |
4176 | newval = bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at); | |
4177 | ||
4178 | if (newval > result) | |
4179 | result = newval; | |
4180 | } | |
4181 | ||
4182 | return result; | |
4183 | } | |
4184 | ||
4a64f543 MS |
4185 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4186 | stopped at. *BSP upon return is a bpstat which points to the | |
4187 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4188 | good for anything but further calls to bpstat_num). | |
4189 | ||
8671a17b PA |
4190 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4191 | Return -1 if stopped at a breakpoint that has been deleted since | |
4192 | we set it. | |
4193 | Return 1 otherwise. */ | |
c906108c SS |
4194 | |
4195 | int | |
8671a17b | 4196 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4197 | { |
4198 | struct breakpoint *b; | |
4199 | ||
4200 | if ((*bsp) == NULL) | |
4201 | return 0; /* No more breakpoint values */ | |
8671a17b | 4202 | |
4a64f543 MS |
4203 | /* We assume we'll never have several bpstats that correspond to a |
4204 | single breakpoint -- otherwise, this function might return the | |
4205 | same number more than once and this will look ugly. */ | |
f431efe5 | 4206 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4207 | *bsp = (*bsp)->next; |
4208 | if (b == NULL) | |
4209 | return -1; /* breakpoint that's been deleted since */ | |
4210 | ||
4211 | *num = b->number; /* We have its number */ | |
4212 | return 1; | |
c906108c SS |
4213 | } |
4214 | ||
e93ca019 | 4215 | /* See breakpoint.h. */ |
c906108c SS |
4216 | |
4217 | void | |
e93ca019 | 4218 | bpstat_clear_actions (void) |
c906108c | 4219 | { |
e93ca019 JK |
4220 | struct thread_info *tp; |
4221 | bpstat bs; | |
4222 | ||
4223 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4224 | return; | |
4225 | ||
4226 | tp = find_thread_ptid (inferior_ptid); | |
4227 | if (tp == NULL) | |
4228 | return; | |
4229 | ||
4230 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4231 | { |
9add0f1b | 4232 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4233 | |
c906108c SS |
4234 | if (bs->old_val != NULL) |
4235 | { | |
4236 | value_free (bs->old_val); | |
4237 | bs->old_val = NULL; | |
4238 | } | |
4239 | } | |
4240 | } | |
4241 | ||
f3b1572e PA |
4242 | /* Called when a command is about to proceed the inferior. */ |
4243 | ||
4244 | static void | |
4245 | breakpoint_about_to_proceed (void) | |
4246 | { | |
4247 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4248 | { | |
4249 | struct thread_info *tp = inferior_thread (); | |
4250 | ||
4251 | /* Allow inferior function calls in breakpoint commands to not | |
4252 | interrupt the command list. When the call finishes | |
4253 | successfully, the inferior will be standing at the same | |
4254 | breakpoint as if nothing happened. */ | |
16c381f0 | 4255 | if (tp->control.in_infcall) |
f3b1572e PA |
4256 | return; |
4257 | } | |
4258 | ||
4259 | breakpoint_proceeded = 1; | |
4260 | } | |
4261 | ||
4a64f543 MS |
4262 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4263 | command. */ | |
c906108c | 4264 | static void |
4efb68b1 | 4265 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4266 | { |
4267 | executing_breakpoint_commands = 0; | |
4268 | } | |
4269 | ||
abf85f46 JK |
4270 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4271 | or its equivalent. */ | |
4272 | ||
4273 | static int | |
4274 | command_line_is_silent (struct command_line *cmd) | |
4275 | { | |
4276 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4277 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4278 | } | |
4279 | ||
4a64f543 MS |
4280 | /* Execute all the commands associated with all the breakpoints at |
4281 | this location. Any of these commands could cause the process to | |
4282 | proceed beyond this point, etc. We look out for such changes by | |
4283 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4284 | |
347bddb7 PA |
4285 | Returns true if a breakpoint command resumed the inferior. In that |
4286 | case, it is the caller's responsibility to recall it again with the | |
4287 | bpstat of the current thread. */ | |
4288 | ||
4289 | static int | |
4290 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4291 | { |
4292 | bpstat bs; | |
4293 | struct cleanup *old_chain; | |
347bddb7 | 4294 | int again = 0; |
c906108c SS |
4295 | |
4296 | /* Avoid endless recursion if a `source' command is contained | |
4297 | in bs->commands. */ | |
4298 | if (executing_breakpoint_commands) | |
347bddb7 | 4299 | return 0; |
c906108c SS |
4300 | |
4301 | executing_breakpoint_commands = 1; | |
4302 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4303 | ||
cf6c5ffb TT |
4304 | prevent_dont_repeat (); |
4305 | ||
4a64f543 | 4306 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4307 | bs = *bsp; |
4308 | ||
4309 | breakpoint_proceeded = 0; | |
4310 | for (; bs != NULL; bs = bs->next) | |
4311 | { | |
9add0f1b | 4312 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4313 | struct command_line *cmd; |
4314 | struct cleanup *this_cmd_tree_chain; | |
4315 | ||
4316 | /* Take ownership of the BSP's command tree, if it has one. | |
4317 | ||
4318 | The command tree could legitimately contain commands like | |
4319 | 'step' and 'next', which call clear_proceed_status, which | |
4320 | frees stop_bpstat's command tree. To make sure this doesn't | |
4321 | free the tree we're executing out from under us, we need to | |
4322 | take ownership of the tree ourselves. Since a given bpstat's | |
4323 | commands are only executed once, we don't need to copy it; we | |
4324 | can clear the pointer in the bpstat, and make sure we free | |
4325 | the tree when we're done. */ | |
9add0f1b TT |
4326 | ccmd = bs->commands; |
4327 | bs->commands = NULL; | |
abf85f46 JK |
4328 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4329 | cmd = ccmd ? ccmd->commands : NULL; | |
4330 | if (command_line_is_silent (cmd)) | |
4331 | { | |
4332 | /* The action has been already done by bpstat_stop_status. */ | |
4333 | cmd = cmd->next; | |
4334 | } | |
6c50ab1c | 4335 | |
c906108c SS |
4336 | while (cmd != NULL) |
4337 | { | |
4338 | execute_control_command (cmd); | |
4339 | ||
4340 | if (breakpoint_proceeded) | |
4341 | break; | |
4342 | else | |
4343 | cmd = cmd->next; | |
4344 | } | |
6c50ab1c JB |
4345 | |
4346 | /* We can free this command tree now. */ | |
4347 | do_cleanups (this_cmd_tree_chain); | |
4348 | ||
c906108c | 4349 | if (breakpoint_proceeded) |
32c1e744 VP |
4350 | { |
4351 | if (target_can_async_p ()) | |
347bddb7 PA |
4352 | /* If we are in async mode, then the target might be still |
4353 | running, not stopped at any breakpoint, so nothing for | |
4354 | us to do here -- just return to the event loop. */ | |
4355 | ; | |
32c1e744 VP |
4356 | else |
4357 | /* In sync mode, when execute_control_command returns | |
4358 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4359 | Breakpoint commands for that stop were not run, since |
4360 | execute_command does not run breakpoint commands -- | |
4361 | only command_line_handler does, but that one is not | |
4362 | involved in execution of breakpoint commands. So, we | |
4363 | can now execute breakpoint commands. It should be | |
4364 | noted that making execute_command do bpstat actions is | |
4365 | not an option -- in this case we'll have recursive | |
4366 | invocation of bpstat for each breakpoint with a | |
4367 | command, and can easily blow up GDB stack. Instead, we | |
4368 | return true, which will trigger the caller to recall us | |
4369 | with the new stop_bpstat. */ | |
4370 | again = 1; | |
4371 | break; | |
32c1e744 | 4372 | } |
c906108c | 4373 | } |
c2b8ed2c | 4374 | do_cleanups (old_chain); |
347bddb7 PA |
4375 | return again; |
4376 | } | |
4377 | ||
4378 | void | |
4379 | bpstat_do_actions (void) | |
4380 | { | |
353d1d73 JK |
4381 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4382 | ||
347bddb7 PA |
4383 | /* Do any commands attached to breakpoint we are stopped at. */ |
4384 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4385 | && target_has_execution | |
4386 | && !is_exited (inferior_ptid) | |
4387 | && !is_executing (inferior_ptid)) | |
4388 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4389 | and only return when it is stopped at the next breakpoint, we | |
4390 | keep doing breakpoint actions until it returns false to | |
4391 | indicate the inferior was not resumed. */ | |
16c381f0 | 4392 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4393 | break; |
353d1d73 JK |
4394 | |
4395 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4396 | } |
4397 | ||
fa4727a6 DJ |
4398 | /* Print out the (old or new) value associated with a watchpoint. */ |
4399 | ||
4400 | static void | |
4401 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4402 | { | |
4403 | if (val == NULL) | |
4404 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4405 | else | |
79a45b7d TT |
4406 | { |
4407 | struct value_print_options opts; | |
4408 | get_user_print_options (&opts); | |
4409 | value_print (val, stream, &opts); | |
4410 | } | |
fa4727a6 DJ |
4411 | } |
4412 | ||
e514a9d6 | 4413 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4414 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4415 | 'print_it' in the bpstat structure. Under some circumstances we |
4416 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4417 | normal_stop(). */ |
e514a9d6 JM |
4418 | |
4419 | static enum print_stop_action | |
4420 | print_bp_stop_message (bpstat bs) | |
4421 | { | |
4422 | switch (bs->print_it) | |
4423 | { | |
4424 | case print_it_noop: | |
4a64f543 | 4425 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4426 | return PRINT_UNKNOWN; |
4427 | break; | |
4428 | ||
4429 | case print_it_done: | |
4430 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4431 | relevant messages. */ |
e514a9d6 JM |
4432 | return PRINT_SRC_AND_LOC; |
4433 | break; | |
4434 | ||
4435 | case print_it_normal: | |
4f8d1dc6 | 4436 | { |
f431efe5 PA |
4437 | struct breakpoint *b = bs->breakpoint_at; |
4438 | ||
1a6a67de TJB |
4439 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4440 | which has since been deleted. */ | |
4441 | if (b == NULL) | |
4442 | return PRINT_UNKNOWN; | |
4443 | ||
348d480f PA |
4444 | /* Normal case. Call the breakpoint's print_it method. */ |
4445 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4446 | } |
348d480f | 4447 | break; |
3086aeae | 4448 | |
e514a9d6 | 4449 | default: |
8e65ff28 | 4450 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4451 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4452 | break; |
c906108c | 4453 | } |
c906108c SS |
4454 | } |
4455 | ||
edcc5120 TT |
4456 | /* A helper function that prints a shared library stopped event. */ |
4457 | ||
4458 | static void | |
4459 | print_solib_event (int is_catchpoint) | |
4460 | { | |
4461 | int any_deleted | |
4462 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4463 | int any_added | |
4464 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4465 | ||
4466 | if (!is_catchpoint) | |
4467 | { | |
4468 | if (any_added || any_deleted) | |
4469 | ui_out_text (current_uiout, | |
4470 | _("Stopped due to shared library event:\n")); | |
4471 | else | |
4472 | ui_out_text (current_uiout, | |
4473 | _("Stopped due to shared library event (no " | |
4474 | "libraries added or removed)\n")); | |
4475 | } | |
4476 | ||
4477 | if (ui_out_is_mi_like_p (current_uiout)) | |
4478 | ui_out_field_string (current_uiout, "reason", | |
4479 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4480 | ||
4481 | if (any_deleted) | |
4482 | { | |
4483 | struct cleanup *cleanup; | |
4484 | char *name; | |
4485 | int ix; | |
4486 | ||
4487 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4488 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4489 | "removed"); | |
4490 | for (ix = 0; | |
4491 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4492 | ix, name); | |
4493 | ++ix) | |
4494 | { | |
4495 | if (ix > 0) | |
4496 | ui_out_text (current_uiout, " "); | |
4497 | ui_out_field_string (current_uiout, "library", name); | |
4498 | ui_out_text (current_uiout, "\n"); | |
4499 | } | |
4500 | ||
4501 | do_cleanups (cleanup); | |
4502 | } | |
4503 | ||
4504 | if (any_added) | |
4505 | { | |
4506 | struct so_list *iter; | |
4507 | int ix; | |
4508 | struct cleanup *cleanup; | |
4509 | ||
4510 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4511 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4512 | "added"); | |
4513 | for (ix = 0; | |
4514 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4515 | ix, iter); | |
4516 | ++ix) | |
4517 | { | |
4518 | if (ix > 0) | |
4519 | ui_out_text (current_uiout, " "); | |
4520 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4521 | ui_out_text (current_uiout, "\n"); | |
4522 | } | |
4523 | ||
4524 | do_cleanups (cleanup); | |
4525 | } | |
4526 | } | |
4527 | ||
e514a9d6 JM |
4528 | /* Print a message indicating what happened. This is called from |
4529 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4530 | list - a list of the eventpoints that caused this stop. KIND is |
4531 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4532 | routine calls the generic print routine for printing a message |
4533 | about reasons for stopping. This will print (for example) the | |
4534 | "Breakpoint n," part of the output. The return value of this | |
4535 | routine is one of: | |
c906108c | 4536 | |
4a64f543 | 4537 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4538 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4539 | code to print the location. An example is |
c5aa993b JM |
4540 | "Breakpoint 1, " which should be followed by |
4541 | the location. | |
917317f4 | 4542 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4543 | to also print the location part of the message. |
4544 | An example is the catch/throw messages, which | |
4a64f543 | 4545 | don't require a location appended to the end. |
917317f4 | 4546 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4547 | further info to be printed. */ |
c906108c | 4548 | |
917317f4 | 4549 | enum print_stop_action |
36dfb11c | 4550 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4551 | { |
4552 | int val; | |
c5aa993b | 4553 | |
c906108c | 4554 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4555 | (Currently all watchpoints go on the bpstat whether hit or not. |
4556 | That probably could (should) be changed, provided care is taken | |
c906108c | 4557 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4558 | for (; bs; bs = bs->next) |
4559 | { | |
4560 | val = print_bp_stop_message (bs); | |
4561 | if (val == PRINT_SRC_ONLY | |
4562 | || val == PRINT_SRC_AND_LOC | |
4563 | || val == PRINT_NOTHING) | |
4564 | return val; | |
4565 | } | |
c906108c | 4566 | |
36dfb11c TT |
4567 | /* If we had hit a shared library event breakpoint, |
4568 | print_bp_stop_message would print out this message. If we hit an | |
4569 | OS-level shared library event, do the same thing. */ | |
4570 | if (kind == TARGET_WAITKIND_LOADED) | |
4571 | { | |
edcc5120 | 4572 | print_solib_event (0); |
36dfb11c TT |
4573 | return PRINT_NOTHING; |
4574 | } | |
4575 | ||
e514a9d6 | 4576 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4577 | with and nothing was printed. */ |
917317f4 | 4578 | return PRINT_UNKNOWN; |
c906108c SS |
4579 | } |
4580 | ||
4a64f543 MS |
4581 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
4582 | used inside a catch_errors to evaluate the breakpoint condition. | |
4583 | The argument is a "struct expression *" that has been cast to a | |
4584 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
4585 | |
4586 | static int | |
4efb68b1 | 4587 | breakpoint_cond_eval (void *exp) |
c906108c | 4588 | { |
278cd55f | 4589 | struct value *mark = value_mark (); |
c5aa993b | 4590 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4591 | |
c906108c SS |
4592 | value_free_to_mark (mark); |
4593 | return i; | |
4594 | } | |
4595 | ||
5760d0ab | 4596 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4597 | |
4598 | static bpstat | |
5760d0ab | 4599 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4600 | { |
4601 | bpstat bs; | |
4602 | ||
4603 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4604 | bs->next = NULL; |
4605 | **bs_link_pointer = bs; | |
4606 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4607 | bs->breakpoint_at = bl->owner; |
4608 | bs->bp_location_at = bl; | |
4609 | incref_bp_location (bl); | |
c906108c SS |
4610 | /* If the condition is false, etc., don't do the commands. */ |
4611 | bs->commands = NULL; | |
4612 | bs->old_val = NULL; | |
4613 | bs->print_it = print_it_normal; | |
4614 | return bs; | |
4615 | } | |
4616 | \f | |
d983da9c DJ |
4617 | /* The target has stopped with waitstatus WS. Check if any hardware |
4618 | watchpoints have triggered, according to the target. */ | |
4619 | ||
4620 | int | |
4621 | watchpoints_triggered (struct target_waitstatus *ws) | |
4622 | { | |
d92524f1 | 4623 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4624 | CORE_ADDR addr; |
4625 | struct breakpoint *b; | |
4626 | ||
4627 | if (!stopped_by_watchpoint) | |
4628 | { | |
4629 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4630 | as not triggered. */ | |
4631 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4632 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4633 | { |
4634 | struct watchpoint *w = (struct watchpoint *) b; | |
4635 | ||
4636 | w->watchpoint_triggered = watch_triggered_no; | |
4637 | } | |
d983da9c DJ |
4638 | |
4639 | return 0; | |
4640 | } | |
4641 | ||
4642 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4643 | { | |
4644 | /* We were stopped by a watchpoint, but we don't know where. | |
4645 | Mark all watchpoints as unknown. */ | |
4646 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4647 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4648 | { |
4649 | struct watchpoint *w = (struct watchpoint *) b; | |
4650 | ||
4651 | w->watchpoint_triggered = watch_triggered_unknown; | |
4652 | } | |
d983da9c DJ |
4653 | |
4654 | return stopped_by_watchpoint; | |
4655 | } | |
4656 | ||
4657 | /* The target could report the data address. Mark watchpoints | |
4658 | affected by this data address as triggered, and all others as not | |
4659 | triggered. */ | |
4660 | ||
4661 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4662 | if (is_hardware_watchpoint (b)) |
d983da9c | 4663 | { |
3a5c3e22 | 4664 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4665 | struct bp_location *loc; |
d983da9c | 4666 | |
3a5c3e22 | 4667 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4668 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4669 | { |
3a5c3e22 | 4670 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4671 | { |
3a5c3e22 PA |
4672 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4673 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4674 | |
4675 | if (newaddr == start) | |
4676 | { | |
3a5c3e22 | 4677 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4678 | break; |
4679 | } | |
4680 | } | |
4681 | /* Exact match not required. Within range is sufficient. */ | |
4682 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4683 | addr, loc->address, | |
4684 | loc->length)) | |
4685 | { | |
3a5c3e22 | 4686 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4687 | break; |
4688 | } | |
4689 | } | |
d983da9c DJ |
4690 | } |
4691 | ||
4692 | return 1; | |
4693 | } | |
4694 | ||
c906108c SS |
4695 | /* Possible return values for watchpoint_check (this can't be an enum |
4696 | because of check_errors). */ | |
4697 | /* The watchpoint has been deleted. */ | |
4698 | #define WP_DELETED 1 | |
4699 | /* The value has changed. */ | |
4700 | #define WP_VALUE_CHANGED 2 | |
4701 | /* The value has not changed. */ | |
4702 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4703 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4704 | #define WP_IGNORE 4 | |
c906108c SS |
4705 | |
4706 | #define BP_TEMPFLAG 1 | |
4707 | #define BP_HARDWAREFLAG 2 | |
4708 | ||
4a64f543 MS |
4709 | /* Evaluate watchpoint condition expression and check if its value |
4710 | changed. | |
553e4c11 JB |
4711 | |
4712 | P should be a pointer to struct bpstat, but is defined as a void * | |
4713 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4714 | |
4715 | static int | |
4efb68b1 | 4716 | watchpoint_check (void *p) |
c906108c SS |
4717 | { |
4718 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4719 | struct watchpoint *b; |
c906108c SS |
4720 | struct frame_info *fr; |
4721 | int within_current_scope; | |
4722 | ||
f431efe5 | 4723 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4724 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4725 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4726 | |
f6bc2008 PA |
4727 | /* If this is a local watchpoint, we only want to check if the |
4728 | watchpoint frame is in scope if the current thread is the thread | |
4729 | that was used to create the watchpoint. */ | |
4730 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4731 | return WP_IGNORE; |
f6bc2008 | 4732 | |
c906108c SS |
4733 | if (b->exp_valid_block == NULL) |
4734 | within_current_scope = 1; | |
4735 | else | |
4736 | { | |
edb3359d DJ |
4737 | struct frame_info *frame = get_current_frame (); |
4738 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4739 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4740 | ||
4a64f543 MS |
4741 | /* in_function_epilogue_p() returns a non-zero value if we're |
4742 | still in the function but the stack frame has already been | |
4743 | invalidated. Since we can't rely on the values of local | |
4744 | variables after the stack has been destroyed, we are treating | |
4745 | the watchpoint in that state as `not changed' without further | |
4746 | checking. Don't mark watchpoints as changed if the current | |
4747 | frame is in an epilogue - even if they are in some other | |
4748 | frame, our view of the stack is likely to be wrong and | |
4749 | frame_find_by_id could error out. */ | |
a0f49112 | 4750 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4751 | return WP_IGNORE; |
a0f49112 | 4752 | |
101dcfbe | 4753 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4754 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4755 | |
4756 | /* If we've gotten confused in the unwinder, we might have | |
4757 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4758 | if (within_current_scope) |
4759 | { | |
4760 | struct symbol *function; | |
4761 | ||
4762 | function = get_frame_function (fr); | |
4763 | if (function == NULL | |
4764 | || !contained_in (b->exp_valid_block, | |
4765 | SYMBOL_BLOCK_VALUE (function))) | |
4766 | within_current_scope = 0; | |
4767 | } | |
69fbadd5 | 4768 | |
edb3359d | 4769 | if (within_current_scope) |
c906108c SS |
4770 | /* If we end up stopping, the current frame will get selected |
4771 | in normal_stop. So this call to select_frame won't affect | |
4772 | the user. */ | |
0f7d239c | 4773 | select_frame (fr); |
c906108c | 4774 | } |
c5aa993b | 4775 | |
c906108c SS |
4776 | if (within_current_scope) |
4777 | { | |
4a64f543 MS |
4778 | /* We use value_{,free_to_}mark because it could be a *long* |
4779 | time before we return to the command level and call | |
4780 | free_all_values. We can't call free_all_values because we | |
4781 | might be in the middle of evaluating a function call. */ | |
c906108c | 4782 | |
0cf6dd15 | 4783 | int pc = 0; |
9c06b0b4 | 4784 | struct value *mark; |
fa4727a6 DJ |
4785 | struct value *new_val; |
4786 | ||
3a5c3e22 | 4787 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4788 | /* Since we don't know the exact trigger address (from |
4789 | stopped_data_address), just tell the user we've triggered | |
4790 | a mask watchpoint. */ | |
4791 | return WP_VALUE_CHANGED; | |
4792 | ||
4793 | mark = value_mark (); | |
0cf6dd15 | 4794 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 4795 | |
4a64f543 MS |
4796 | /* We use value_equal_contents instead of value_equal because |
4797 | the latter coerces an array to a pointer, thus comparing just | |
4798 | the address of the array instead of its contents. This is | |
4799 | not what we want. */ | |
fa4727a6 | 4800 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4801 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4802 | { |
fa4727a6 DJ |
4803 | if (new_val != NULL) |
4804 | { | |
4805 | release_value (new_val); | |
4806 | value_free_to_mark (mark); | |
4807 | } | |
c906108c SS |
4808 | bs->old_val = b->val; |
4809 | b->val = new_val; | |
fa4727a6 | 4810 | b->val_valid = 1; |
c906108c SS |
4811 | return WP_VALUE_CHANGED; |
4812 | } | |
4813 | else | |
4814 | { | |
60e1c644 | 4815 | /* Nothing changed. */ |
c906108c | 4816 | value_free_to_mark (mark); |
c906108c SS |
4817 | return WP_VALUE_NOT_CHANGED; |
4818 | } | |
4819 | } | |
4820 | else | |
4821 | { | |
79a45e25 PA |
4822 | struct ui_out *uiout = current_uiout; |
4823 | ||
c906108c | 4824 | /* This seems like the only logical thing to do because |
c5aa993b JM |
4825 | if we temporarily ignored the watchpoint, then when |
4826 | we reenter the block in which it is valid it contains | |
4827 | garbage (in the case of a function, it may have two | |
4828 | garbage values, one before and one after the prologue). | |
4829 | So we can't even detect the first assignment to it and | |
4830 | watch after that (since the garbage may or may not equal | |
4831 | the first value assigned). */ | |
348d480f PA |
4832 | /* We print all the stop information in |
4833 | breakpoint_ops->print_it, but in this case, by the time we | |
4834 | call breakpoint_ops->print_it this bp will be deleted | |
4835 | already. So we have no choice but print the information | |
4836 | here. */ | |
9dc5e2a9 | 4837 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4838 | ui_out_field_string |
4839 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 4840 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 4841 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
4842 | ui_out_text (uiout, |
4843 | " deleted because the program has left the block in\n\ | |
8b93c638 | 4844 | which its expression is valid.\n"); |
4ce44c66 | 4845 | |
cdac0397 | 4846 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 4847 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 4848 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4849 | |
4850 | return WP_DELETED; | |
4851 | } | |
4852 | } | |
4853 | ||
18a18393 | 4854 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4855 | breakpoint location BL. This function does not check if we should |
4856 | stop, only if BL explains the stop. */ | |
4857 | ||
18a18393 | 4858 | static int |
6c95b8df | 4859 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
4860 | struct address_space *aspace, CORE_ADDR bp_addr, |
4861 | const struct target_waitstatus *ws) | |
18a18393 VP |
4862 | { |
4863 | struct breakpoint *b = bl->owner; | |
4864 | ||
348d480f | 4865 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4866 | gdb_assert (b != NULL); |
4867 | ||
09ac7c10 | 4868 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4869 | } |
4870 | ||
3a5c3e22 PA |
4871 | /* Determine if the watched values have actually changed, and we |
4872 | should stop. If not, set BS->stop to 0. */ | |
4873 | ||
18a18393 VP |
4874 | static void |
4875 | bpstat_check_watchpoint (bpstat bs) | |
4876 | { | |
2bdf28a0 | 4877 | const struct bp_location *bl; |
3a5c3e22 | 4878 | struct watchpoint *b; |
2bdf28a0 JK |
4879 | |
4880 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4881 | bl = bs->bp_location_at; |
2bdf28a0 | 4882 | gdb_assert (bl != NULL); |
3a5c3e22 | 4883 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4884 | gdb_assert (b != NULL); |
18a18393 | 4885 | |
18a18393 | 4886 | { |
18a18393 VP |
4887 | int must_check_value = 0; |
4888 | ||
3a5c3e22 | 4889 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
4890 | /* For a software watchpoint, we must always check the |
4891 | watched value. */ | |
4892 | must_check_value = 1; | |
4893 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4894 | /* We have a hardware watchpoint (read, write, or access) | |
4895 | and the target earlier reported an address watched by | |
4896 | this watchpoint. */ | |
4897 | must_check_value = 1; | |
4898 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 4899 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
4900 | /* We were stopped by a hardware watchpoint, but the target could |
4901 | not report the data address. We must check the watchpoint's | |
4902 | value. Access and read watchpoints are out of luck; without | |
4903 | a data address, we can't figure it out. */ | |
4904 | must_check_value = 1; | |
3a5c3e22 | 4905 | |
18a18393 VP |
4906 | if (must_check_value) |
4907 | { | |
3e43a32a MS |
4908 | char *message |
4909 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 4910 | b->base.number); |
18a18393 VP |
4911 | struct cleanup *cleanups = make_cleanup (xfree, message); |
4912 | int e = catch_errors (watchpoint_check, bs, message, | |
4913 | RETURN_MASK_ALL); | |
4914 | do_cleanups (cleanups); | |
4915 | switch (e) | |
4916 | { | |
4917 | case WP_DELETED: | |
4918 | /* We've already printed what needs to be printed. */ | |
4919 | bs->print_it = print_it_done; | |
4920 | /* Stop. */ | |
4921 | break; | |
60e1c644 PA |
4922 | case WP_IGNORE: |
4923 | bs->print_it = print_it_noop; | |
4924 | bs->stop = 0; | |
4925 | break; | |
18a18393 | 4926 | case WP_VALUE_CHANGED: |
3a5c3e22 | 4927 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 4928 | { |
85d721b8 PA |
4929 | /* There are two cases to consider here: |
4930 | ||
4a64f543 | 4931 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
4932 | In that case, trust the target, and always report |
4933 | the watchpoint hit to the user. Even though | |
4934 | reads don't cause value changes, the value may | |
4935 | have changed since the last time it was read, and | |
4936 | since we're not trapping writes, we will not see | |
4937 | those, and as such we should ignore our notion of | |
4938 | old value. | |
4939 | ||
4a64f543 | 4940 | 2. We're watching the triggered memory for both |
85d721b8 PA |
4941 | reads and writes. There are two ways this may |
4942 | happen: | |
4943 | ||
4a64f543 | 4944 | 2.1. This is a target that can't break on data |
85d721b8 PA |
4945 | reads only, but can break on accesses (reads or |
4946 | writes), such as e.g., x86. We detect this case | |
4947 | at the time we try to insert read watchpoints. | |
4948 | ||
4a64f543 | 4949 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
4950 | watchpoints, but, the user set an access or write |
4951 | watchpoint watching the same memory as this read | |
4952 | watchpoint. | |
4953 | ||
4954 | If we're watching memory writes as well as reads, | |
4955 | ignore watchpoint hits when we find that the | |
4956 | value hasn't changed, as reads don't cause | |
4957 | changes. This still gives false positives when | |
4958 | the program writes the same value to memory as | |
4959 | what there was already in memory (we will confuse | |
4960 | it for a read), but it's much better than | |
4961 | nothing. */ | |
4962 | ||
4963 | int other_write_watchpoint = 0; | |
4964 | ||
4965 | if (bl->watchpoint_type == hw_read) | |
4966 | { | |
4967 | struct breakpoint *other_b; | |
4968 | ||
4969 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
4970 | if (other_b->type == bp_hardware_watchpoint |
4971 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 4972 | { |
3a5c3e22 PA |
4973 | struct watchpoint *other_w = |
4974 | (struct watchpoint *) other_b; | |
4975 | ||
4976 | if (other_w->watchpoint_triggered | |
4977 | == watch_triggered_yes) | |
4978 | { | |
4979 | other_write_watchpoint = 1; | |
4980 | break; | |
4981 | } | |
85d721b8 PA |
4982 | } |
4983 | } | |
4984 | ||
4985 | if (other_write_watchpoint | |
4986 | || bl->watchpoint_type == hw_access) | |
4987 | { | |
4988 | /* We're watching the same memory for writes, | |
4989 | and the value changed since the last time we | |
4990 | updated it, so this trap must be for a write. | |
4991 | Ignore it. */ | |
4992 | bs->print_it = print_it_noop; | |
4993 | bs->stop = 0; | |
4994 | } | |
18a18393 VP |
4995 | } |
4996 | break; | |
4997 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
4998 | if (b->base.type == bp_hardware_watchpoint |
4999 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5000 | { |
5001 | /* Don't stop: write watchpoints shouldn't fire if | |
5002 | the value hasn't changed. */ | |
5003 | bs->print_it = print_it_noop; | |
5004 | bs->stop = 0; | |
5005 | } | |
5006 | /* Stop. */ | |
5007 | break; | |
5008 | default: | |
5009 | /* Can't happen. */ | |
5010 | case 0: | |
5011 | /* Error from catch_errors. */ | |
3a5c3e22 | 5012 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5013 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5014 | /* We've already printed what needs to be printed. */ |
5015 | bs->print_it = print_it_done; | |
5016 | break; | |
5017 | } | |
5018 | } | |
5019 | else /* must_check_value == 0 */ | |
5020 | { | |
5021 | /* This is a case where some watchpoint(s) triggered, but | |
5022 | not at the address of this watchpoint, or else no | |
5023 | watchpoint triggered after all. So don't print | |
5024 | anything for this watchpoint. */ | |
5025 | bs->print_it = print_it_noop; | |
5026 | bs->stop = 0; | |
5027 | } | |
5028 | } | |
5029 | } | |
5030 | ||
5031 | ||
5032 | /* Check conditions (condition proper, frame, thread and ignore count) | |
5033 | of breakpoint referred to by BS. If we should not stop for this | |
5034 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5035 | |
18a18393 VP |
5036 | static void |
5037 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5038 | { | |
5039 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
5040 | const struct bp_location *bl; |
5041 | struct breakpoint *b; | |
5042 | ||
5043 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5044 | bl = bs->bp_location_at; |
2bdf28a0 | 5045 | gdb_assert (bl != NULL); |
f431efe5 | 5046 | b = bs->breakpoint_at; |
2bdf28a0 | 5047 | gdb_assert (b != NULL); |
18a18393 | 5048 | |
b775012e LM |
5049 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5050 | need to do so again since GDB does not know if we stopped due to a | |
5051 | breakpoint or a single step breakpoint. */ | |
5052 | ||
18a18393 | 5053 | if (frame_id_p (b->frame_id) |
edb3359d | 5054 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
5055 | bs->stop = 0; |
5056 | else if (bs->stop) | |
5057 | { | |
5058 | int value_is_zero = 0; | |
60e1c644 PA |
5059 | struct expression *cond; |
5060 | ||
7371cf6d PM |
5061 | /* Evaluate Python breakpoints that have a "stop" |
5062 | method implemented. */ | |
5063 | if (b->py_bp_object) | |
5064 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
5065 | ||
60e1c644 | 5066 | if (is_watchpoint (b)) |
3a5c3e22 PA |
5067 | { |
5068 | struct watchpoint *w = (struct watchpoint *) b; | |
5069 | ||
5070 | cond = w->cond_exp; | |
5071 | } | |
60e1c644 PA |
5072 | else |
5073 | cond = bl->cond; | |
5074 | ||
f431efe5 | 5075 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 5076 | { |
60e1c644 | 5077 | int within_current_scope = 1; |
3a5c3e22 | 5078 | struct watchpoint * w; |
60e1c644 | 5079 | |
c5bc3a77 DJ |
5080 | /* We use value_mark and value_free_to_mark because it could |
5081 | be a long time before we return to the command level and | |
5082 | call free_all_values. We can't call free_all_values | |
5083 | because we might be in the middle of evaluating a | |
5084 | function call. */ | |
5085 | struct value *mark = value_mark (); | |
5086 | ||
3a5c3e22 PA |
5087 | if (is_watchpoint (b)) |
5088 | w = (struct watchpoint *) b; | |
5089 | else | |
5090 | w = NULL; | |
5091 | ||
edb3359d DJ |
5092 | /* Need to select the frame, with all that implies so that |
5093 | the conditions will have the right context. Because we | |
5094 | use the frame, we will not see an inlined function's | |
5095 | variables when we arrive at a breakpoint at the start | |
5096 | of the inlined function; the current frame will be the | |
5097 | call site. */ | |
3a5c3e22 | 5098 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
5099 | select_frame (get_current_frame ()); |
5100 | else | |
5101 | { | |
5102 | struct frame_info *frame; | |
5103 | ||
5104 | /* For local watchpoint expressions, which particular | |
5105 | instance of a local is being watched matters, so we | |
5106 | keep track of the frame to evaluate the expression | |
5107 | in. To evaluate the condition however, it doesn't | |
5108 | really matter which instantiation of the function | |
5109 | where the condition makes sense triggers the | |
5110 | watchpoint. This allows an expression like "watch | |
5111 | global if q > 10" set in `func', catch writes to | |
5112 | global on all threads that call `func', or catch | |
5113 | writes on all recursive calls of `func' by a single | |
5114 | thread. We simply always evaluate the condition in | |
5115 | the innermost frame that's executing where it makes | |
5116 | sense to evaluate the condition. It seems | |
5117 | intuitive. */ | |
3a5c3e22 | 5118 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
5119 | if (frame != NULL) |
5120 | select_frame (frame); | |
5121 | else | |
5122 | within_current_scope = 0; | |
5123 | } | |
5124 | if (within_current_scope) | |
5125 | value_is_zero | |
5126 | = catch_errors (breakpoint_cond_eval, cond, | |
5127 | "Error in testing breakpoint condition:\n", | |
5128 | RETURN_MASK_ALL); | |
5129 | else | |
5130 | { | |
5131 | warning (_("Watchpoint condition cannot be tested " | |
5132 | "in the current scope")); | |
5133 | /* If we failed to set the right context for this | |
5134 | watchpoint, unconditionally report it. */ | |
5135 | value_is_zero = 0; | |
5136 | } | |
4a64f543 | 5137 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 5138 | value_free_to_mark (mark); |
18a18393 | 5139 | } |
60e1c644 PA |
5140 | |
5141 | if (cond && value_is_zero) | |
18a18393 VP |
5142 | { |
5143 | bs->stop = 0; | |
5144 | } | |
5145 | else if (b->thread != -1 && b->thread != thread_id) | |
5146 | { | |
5147 | bs->stop = 0; | |
5148 | } | |
5149 | else if (b->ignore_count > 0) | |
5150 | { | |
5151 | b->ignore_count--; | |
18a18393 | 5152 | bs->stop = 0; |
4a64f543 | 5153 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 5154 | ++(b->hit_count); |
8d3788bd | 5155 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
5156 | } |
5157 | } | |
5158 | } | |
5159 | ||
5160 | ||
9709f61c | 5161 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5162 | BP_ADDR in thread PTID. |
c906108c | 5163 | |
d983da9c | 5164 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5165 | don't understand this stop. Result is a chain of bpstat's such |
5166 | that: | |
c906108c | 5167 | |
c5aa993b | 5168 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5169 | |
c5aa993b | 5170 | if we understand why we stopped, the result is not null. |
c906108c | 5171 | |
c5aa993b JM |
5172 | Each element of the chain refers to a particular breakpoint or |
5173 | watchpoint at which we have stopped. (We may have stopped for | |
5174 | several reasons concurrently.) | |
c906108c | 5175 | |
c5aa993b JM |
5176 | Each element of the chain has valid next, breakpoint_at, |
5177 | commands, FIXME??? fields. */ | |
c906108c SS |
5178 | |
5179 | bpstat | |
6c95b8df | 5180 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5181 | CORE_ADDR bp_addr, ptid_t ptid, |
5182 | const struct target_waitstatus *ws) | |
c906108c | 5183 | { |
0d381245 | 5184 | struct breakpoint *b = NULL; |
afe38095 | 5185 | struct bp_location *bl; |
20874c92 | 5186 | struct bp_location *loc; |
5760d0ab JK |
5187 | /* First item of allocated bpstat's. */ |
5188 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5189 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5190 | bpstat bs; |
20874c92 | 5191 | int ix; |
429374b8 | 5192 | int need_remove_insert; |
f431efe5 | 5193 | int removed_any; |
c906108c | 5194 | |
f431efe5 PA |
5195 | /* First, build the bpstat chain with locations that explain a |
5196 | target stop, while being careful to not set the target running, | |
5197 | as that may invalidate locations (in particular watchpoint | |
5198 | locations are recreated). Resuming will happen here with | |
5199 | breakpoint conditions or watchpoint expressions that include | |
5200 | inferior function calls. */ | |
c5aa993b | 5201 | |
429374b8 JK |
5202 | ALL_BREAKPOINTS (b) |
5203 | { | |
5204 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
5205 | continue; | |
a5606eee | 5206 | |
429374b8 JK |
5207 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5208 | { | |
4a64f543 MS |
5209 | /* For hardware watchpoints, we look only at the first |
5210 | location. The watchpoint_check function will work on the | |
5211 | entire expression, not the individual locations. For | |
5212 | read watchpoints, the watchpoints_triggered function has | |
5213 | checked all locations already. */ | |
429374b8 JK |
5214 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5215 | break; | |
18a18393 | 5216 | |
f6592439 | 5217 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5218 | continue; |
c5aa993b | 5219 | |
09ac7c10 | 5220 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5221 | continue; |
c5aa993b | 5222 | |
4a64f543 MS |
5223 | /* Come here if it's a watchpoint, or if the break address |
5224 | matches. */ | |
c5aa993b | 5225 | |
4a64f543 MS |
5226 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5227 | explain stop. */ | |
c5aa993b | 5228 | |
f431efe5 PA |
5229 | /* Assume we stop. Should we find a watchpoint that is not |
5230 | actually triggered, or if the condition of the breakpoint | |
5231 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5232 | bs->stop = 1; |
5233 | bs->print = 1; | |
d983da9c | 5234 | |
f431efe5 PA |
5235 | /* If this is a scope breakpoint, mark the associated |
5236 | watchpoint as triggered so that we will handle the | |
5237 | out-of-scope event. We'll get to the watchpoint next | |
5238 | iteration. */ | |
d0fb5eae | 5239 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5240 | { |
5241 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5242 | ||
5243 | w->watchpoint_triggered = watch_triggered_yes; | |
5244 | } | |
f431efe5 PA |
5245 | } |
5246 | } | |
5247 | ||
5248 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
5249 | { | |
f1310107 | 5250 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5251 | { |
5760d0ab | 5252 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5253 | /* For hits of moribund locations, we should just proceed. */ |
5254 | bs->stop = 0; | |
5255 | bs->print = 0; | |
5256 | bs->print_it = print_it_noop; | |
5257 | } | |
5258 | } | |
5259 | ||
edcc5120 TT |
5260 | /* A bit of special processing for shlib breakpoints. We need to |
5261 | process solib loading here, so that the lists of loaded and | |
5262 | unloaded libraries are correct before we handle "catch load" and | |
5263 | "catch unload". */ | |
5264 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5265 | { | |
5d268276 | 5266 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5267 | { |
5268 | handle_solib_event (); | |
5269 | break; | |
5270 | } | |
5271 | } | |
5272 | ||
f431efe5 PA |
5273 | /* Now go through the locations that caused the target to stop, and |
5274 | check whether we're interested in reporting this stop to higher | |
5275 | layers, or whether we should resume the target transparently. */ | |
5276 | ||
5277 | removed_any = 0; | |
5278 | ||
5760d0ab | 5279 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5280 | { |
5281 | if (!bs->stop) | |
5282 | continue; | |
5283 | ||
f431efe5 | 5284 | b = bs->breakpoint_at; |
348d480f PA |
5285 | b->ops->check_status (bs); |
5286 | if (bs->stop) | |
28010a5d | 5287 | { |
348d480f | 5288 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5289 | |
429374b8 JK |
5290 | if (bs->stop) |
5291 | { | |
5292 | ++(b->hit_count); | |
8d3788bd | 5293 | observer_notify_breakpoint_modified (b); |
c906108c | 5294 | |
4a64f543 | 5295 | /* We will stop here. */ |
429374b8 JK |
5296 | if (b->disposition == disp_disable) |
5297 | { | |
816338b5 SS |
5298 | --(b->enable_count); |
5299 | if (b->enable_count <= 0 | |
5300 | && b->enable_state != bp_permanent) | |
429374b8 | 5301 | b->enable_state = bp_disabled; |
f431efe5 | 5302 | removed_any = 1; |
429374b8 JK |
5303 | } |
5304 | if (b->silent) | |
5305 | bs->print = 0; | |
5306 | bs->commands = b->commands; | |
9add0f1b | 5307 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5308 | if (command_line_is_silent (bs->commands |
5309 | ? bs->commands->commands : NULL)) | |
5310 | bs->print = 0; | |
429374b8 JK |
5311 | } |
5312 | ||
348d480f | 5313 | } |
a9b3a50f PA |
5314 | |
5315 | /* Print nothing for this entry if we don't stop or don't | |
5316 | print. */ | |
5317 | if (!bs->stop || !bs->print) | |
5318 | bs->print_it = print_it_noop; | |
429374b8 | 5319 | } |
876fa593 | 5320 | |
d983da9c DJ |
5321 | /* If we aren't stopping, the value of some hardware watchpoint may |
5322 | not have changed, but the intermediate memory locations we are | |
5323 | watching may have. Don't bother if we're stopping; this will get | |
5324 | done later. */ | |
d832cb68 | 5325 | need_remove_insert = 0; |
5760d0ab JK |
5326 | if (! bpstat_causes_stop (bs_head)) |
5327 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5328 | if (!bs->stop |
f431efe5 PA |
5329 | && bs->breakpoint_at |
5330 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5331 | { |
3a5c3e22 PA |
5332 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5333 | ||
5334 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5335 | need_remove_insert = 1; |
d983da9c DJ |
5336 | } |
5337 | ||
d832cb68 | 5338 | if (need_remove_insert) |
2d134ed3 | 5339 | update_global_location_list (1); |
f431efe5 PA |
5340 | else if (removed_any) |
5341 | update_global_location_list (0); | |
d832cb68 | 5342 | |
5760d0ab | 5343 | return bs_head; |
c906108c | 5344 | } |
628fe4e4 JK |
5345 | |
5346 | static void | |
5347 | handle_jit_event (void) | |
5348 | { | |
5349 | struct frame_info *frame; | |
5350 | struct gdbarch *gdbarch; | |
5351 | ||
5352 | /* Switch terminal for any messages produced by | |
5353 | breakpoint_re_set. */ | |
5354 | target_terminal_ours_for_output (); | |
5355 | ||
5356 | frame = get_current_frame (); | |
5357 | gdbarch = get_frame_arch (frame); | |
5358 | ||
5359 | jit_event_handler (gdbarch); | |
5360 | ||
5361 | target_terminal_inferior (); | |
5362 | } | |
5363 | ||
edcc5120 TT |
5364 | /* Handle an solib event by calling solib_add. */ |
5365 | ||
5366 | void | |
5367 | handle_solib_event (void) | |
5368 | { | |
5369 | clear_program_space_solib_cache (current_inferior ()->pspace); | |
5370 | ||
5371 | /* Check for any newly added shared libraries if we're supposed to | |
5372 | be adding them automatically. Switch terminal for any messages | |
5373 | produced by breakpoint_re_set. */ | |
5374 | target_terminal_ours_for_output (); | |
5375 | #ifdef SOLIB_ADD | |
5376 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
5377 | #else | |
5378 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
5379 | #endif | |
5380 | target_terminal_inferior (); | |
5381 | } | |
5382 | ||
628fe4e4 JK |
5383 | /* Prepare WHAT final decision for infrun. */ |
5384 | ||
5385 | /* Decide what infrun needs to do with this bpstat. */ | |
5386 | ||
c906108c | 5387 | struct bpstat_what |
0e30163f | 5388 | bpstat_what (bpstat bs_head) |
c906108c | 5389 | { |
c906108c | 5390 | struct bpstat_what retval; |
628fe4e4 | 5391 | int jit_event = 0; |
0e30163f | 5392 | bpstat bs; |
c906108c | 5393 | |
628fe4e4 | 5394 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5395 | retval.call_dummy = STOP_NONE; |
186c406b | 5396 | retval.is_longjmp = 0; |
628fe4e4 | 5397 | |
0e30163f | 5398 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5399 | { |
628fe4e4 JK |
5400 | /* Extract this BS's action. After processing each BS, we check |
5401 | if its action overrides all we've seem so far. */ | |
5402 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5403 | enum bptype bptype; | |
5404 | ||
c906108c | 5405 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5406 | { |
5407 | /* I suspect this can happen if it was a momentary | |
5408 | breakpoint which has since been deleted. */ | |
5409 | bptype = bp_none; | |
5410 | } | |
20874c92 | 5411 | else |
f431efe5 | 5412 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5413 | |
5414 | switch (bptype) | |
c906108c SS |
5415 | { |
5416 | case bp_none: | |
628fe4e4 | 5417 | break; |
c906108c SS |
5418 | case bp_breakpoint: |
5419 | case bp_hardware_breakpoint: | |
5420 | case bp_until: | |
5421 | case bp_finish: | |
a9b3a50f | 5422 | case bp_shlib_event: |
c906108c SS |
5423 | if (bs->stop) |
5424 | { | |
5425 | if (bs->print) | |
628fe4e4 | 5426 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5427 | else |
628fe4e4 | 5428 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5429 | } |
5430 | else | |
628fe4e4 | 5431 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5432 | break; |
5433 | case bp_watchpoint: | |
5434 | case bp_hardware_watchpoint: | |
5435 | case bp_read_watchpoint: | |
5436 | case bp_access_watchpoint: | |
5437 | if (bs->stop) | |
5438 | { | |
5439 | if (bs->print) | |
628fe4e4 | 5440 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5441 | else |
628fe4e4 | 5442 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5443 | } |
5444 | else | |
628fe4e4 JK |
5445 | { |
5446 | /* There was a watchpoint, but we're not stopping. | |
5447 | This requires no further action. */ | |
5448 | } | |
c906108c SS |
5449 | break; |
5450 | case bp_longjmp: | |
e2e4d78b | 5451 | case bp_longjmp_call_dummy: |
186c406b | 5452 | case bp_exception: |
628fe4e4 | 5453 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5454 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5455 | break; |
5456 | case bp_longjmp_resume: | |
186c406b | 5457 | case bp_exception_resume: |
628fe4e4 | 5458 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5459 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5460 | break; |
5461 | case bp_step_resume: | |
5462 | if (bs->stop) | |
628fe4e4 JK |
5463 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5464 | else | |
c906108c | 5465 | { |
628fe4e4 JK |
5466 | /* It is for the wrong frame. */ |
5467 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5468 | } |
c906108c | 5469 | break; |
2c03e5be PA |
5470 | case bp_hp_step_resume: |
5471 | if (bs->stop) | |
5472 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5473 | else | |
5474 | { | |
5475 | /* It is for the wrong frame. */ | |
5476 | this_action = BPSTAT_WHAT_SINGLE; | |
5477 | } | |
5478 | break; | |
c906108c | 5479 | case bp_watchpoint_scope: |
c4093a6a | 5480 | case bp_thread_event: |
1900040c | 5481 | case bp_overlay_event: |
0fd8e87f | 5482 | case bp_longjmp_master: |
aa7d318d | 5483 | case bp_std_terminate_master: |
186c406b | 5484 | case bp_exception_master: |
628fe4e4 | 5485 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5486 | break; |
ce78b96d | 5487 | case bp_catchpoint: |
c5aa993b JM |
5488 | if (bs->stop) |
5489 | { | |
5490 | if (bs->print) | |
628fe4e4 | 5491 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5492 | else |
628fe4e4 | 5493 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5494 | } |
5495 | else | |
628fe4e4 JK |
5496 | { |
5497 | /* There was a catchpoint, but we're not stopping. | |
5498 | This requires no further action. */ | |
5499 | } | |
5500 | break; | |
628fe4e4 JK |
5501 | case bp_jit_event: |
5502 | jit_event = 1; | |
5503 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5504 | break; |
c906108c | 5505 | case bp_call_dummy: |
53a5351d JM |
5506 | /* Make sure the action is stop (silent or noisy), |
5507 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5508 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5509 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5510 | break; |
5511 | case bp_std_terminate: | |
5512 | /* Make sure the action is stop (silent or noisy), | |
5513 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5514 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5515 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5516 | break; |
1042e4c0 | 5517 | case bp_tracepoint: |
7a697b8d | 5518 | case bp_fast_tracepoint: |
0fb4aa4b | 5519 | case bp_static_tracepoint: |
1042e4c0 SS |
5520 | /* Tracepoint hits should not be reported back to GDB, and |
5521 | if one got through somehow, it should have been filtered | |
5522 | out already. */ | |
5523 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5524 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5525 | break; |
5526 | case bp_gnu_ifunc_resolver: | |
5527 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5528 | this_action = BPSTAT_WHAT_SINGLE; | |
5529 | break; | |
5530 | case bp_gnu_ifunc_resolver_return: | |
5531 | /* The breakpoint will be removed, execution will restart from the | |
5532 | PC of the former breakpoint. */ | |
5533 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5534 | break; | |
e7e0cddf SS |
5535 | |
5536 | case bp_dprintf: | |
5537 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5538 | break; | |
5539 | ||
628fe4e4 JK |
5540 | default: |
5541 | internal_error (__FILE__, __LINE__, | |
5542 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5543 | } |
628fe4e4 JK |
5544 | |
5545 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5546 | } |
628fe4e4 | 5547 | |
0e30163f JK |
5548 | /* These operations may affect the bs->breakpoint_at state so they are |
5549 | delayed after MAIN_ACTION is decided above. */ | |
5550 | ||
628fe4e4 JK |
5551 | if (jit_event) |
5552 | { | |
5553 | if (debug_infrun) | |
5554 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5555 | ||
5556 | handle_jit_event (); | |
5557 | } | |
5558 | ||
0e30163f JK |
5559 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5560 | { | |
5561 | struct breakpoint *b = bs->breakpoint_at; | |
5562 | ||
5563 | if (b == NULL) | |
5564 | continue; | |
5565 | switch (b->type) | |
5566 | { | |
5567 | case bp_gnu_ifunc_resolver: | |
5568 | gnu_ifunc_resolver_stop (b); | |
5569 | break; | |
5570 | case bp_gnu_ifunc_resolver_return: | |
5571 | gnu_ifunc_resolver_return_stop (b); | |
5572 | break; | |
5573 | } | |
5574 | } | |
5575 | ||
c906108c SS |
5576 | return retval; |
5577 | } | |
5578 | ||
5579 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5580 | without hardware support). This isn't related to a specific bpstat, | |
5581 | just to things like whether watchpoints are set. */ | |
5582 | ||
c5aa993b | 5583 | int |
fba45db2 | 5584 | bpstat_should_step (void) |
c906108c SS |
5585 | { |
5586 | struct breakpoint *b; | |
cc59ec59 | 5587 | |
c906108c | 5588 | ALL_BREAKPOINTS (b) |
717a8278 | 5589 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5590 | return 1; |
c906108c SS |
5591 | return 0; |
5592 | } | |
5593 | ||
67822962 PA |
5594 | int |
5595 | bpstat_causes_stop (bpstat bs) | |
5596 | { | |
5597 | for (; bs != NULL; bs = bs->next) | |
5598 | if (bs->stop) | |
5599 | return 1; | |
5600 | ||
5601 | return 0; | |
5602 | } | |
5603 | ||
c906108c | 5604 | \f |
c5aa993b | 5605 | |
170b53b2 UW |
5606 | /* Compute a string of spaces suitable to indent the next line |
5607 | so it starts at the position corresponding to the table column | |
5608 | named COL_NAME in the currently active table of UIOUT. */ | |
5609 | ||
5610 | static char * | |
5611 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5612 | { | |
5613 | static char wrap_indent[80]; | |
5614 | int i, total_width, width, align; | |
5615 | char *text; | |
5616 | ||
5617 | total_width = 0; | |
5618 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5619 | { | |
5620 | if (strcmp (text, col_name) == 0) | |
5621 | { | |
5622 | gdb_assert (total_width < sizeof wrap_indent); | |
5623 | memset (wrap_indent, ' ', total_width); | |
5624 | wrap_indent[total_width] = 0; | |
5625 | ||
5626 | return wrap_indent; | |
5627 | } | |
5628 | ||
5629 | total_width += width + 1; | |
5630 | } | |
5631 | ||
5632 | return NULL; | |
5633 | } | |
5634 | ||
b775012e LM |
5635 | /* Determine if the locations of this breakpoint will have their conditions |
5636 | evaluated by the target, host or a mix of both. Returns the following: | |
5637 | ||
5638 | "host": Host evals condition. | |
5639 | "host or target": Host or Target evals condition. | |
5640 | "target": Target evals condition. | |
5641 | */ | |
5642 | ||
5643 | static const char * | |
5644 | bp_condition_evaluator (struct breakpoint *b) | |
5645 | { | |
5646 | struct bp_location *bl; | |
5647 | char host_evals = 0; | |
5648 | char target_evals = 0; | |
5649 | ||
5650 | if (!b) | |
5651 | return NULL; | |
5652 | ||
5653 | if (!is_breakpoint (b)) | |
5654 | return NULL; | |
5655 | ||
5656 | if (gdb_evaluates_breakpoint_condition_p () | |
5657 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5658 | return condition_evaluation_host; | |
5659 | ||
5660 | for (bl = b->loc; bl; bl = bl->next) | |
5661 | { | |
5662 | if (bl->cond_bytecode) | |
5663 | target_evals++; | |
5664 | else | |
5665 | host_evals++; | |
5666 | } | |
5667 | ||
5668 | if (host_evals && target_evals) | |
5669 | return condition_evaluation_both; | |
5670 | else if (target_evals) | |
5671 | return condition_evaluation_target; | |
5672 | else | |
5673 | return condition_evaluation_host; | |
5674 | } | |
5675 | ||
5676 | /* Determine the breakpoint location's condition evaluator. This is | |
5677 | similar to bp_condition_evaluator, but for locations. */ | |
5678 | ||
5679 | static const char * | |
5680 | bp_location_condition_evaluator (struct bp_location *bl) | |
5681 | { | |
5682 | if (bl && !is_breakpoint (bl->owner)) | |
5683 | return NULL; | |
5684 | ||
5685 | if (gdb_evaluates_breakpoint_condition_p () | |
5686 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5687 | return condition_evaluation_host; | |
5688 | ||
5689 | if (bl && bl->cond_bytecode) | |
5690 | return condition_evaluation_target; | |
5691 | else | |
5692 | return condition_evaluation_host; | |
5693 | } | |
5694 | ||
859825b8 JK |
5695 | /* Print the LOC location out of the list of B->LOC locations. */ |
5696 | ||
170b53b2 UW |
5697 | static void |
5698 | print_breakpoint_location (struct breakpoint *b, | |
5699 | struct bp_location *loc) | |
0d381245 | 5700 | { |
79a45e25 | 5701 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5702 | struct cleanup *old_chain = save_current_program_space (); |
5703 | ||
859825b8 JK |
5704 | if (loc != NULL && loc->shlib_disabled) |
5705 | loc = NULL; | |
5706 | ||
6c95b8df PA |
5707 | if (loc != NULL) |
5708 | set_current_program_space (loc->pspace); | |
5709 | ||
56435ebe TT |
5710 | if (b->display_canonical) |
5711 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5712 | else if (loc && loc->symtab) |
0d381245 VP |
5713 | { |
5714 | struct symbol *sym | |
5715 | = find_pc_sect_function (loc->address, loc->section); | |
5716 | if (sym) | |
5717 | { | |
5718 | ui_out_text (uiout, "in "); | |
5719 | ui_out_field_string (uiout, "func", | |
5720 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5721 | ui_out_text (uiout, " "); |
5722 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5723 | ui_out_text (uiout, "at "); | |
0d381245 | 5724 | } |
05cba821 JK |
5725 | ui_out_field_string (uiout, "file", |
5726 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 5727 | ui_out_text (uiout, ":"); |
05cba821 | 5728 | |
0d381245 | 5729 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
5730 | ui_out_field_string (uiout, "fullname", |
5731 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 5732 | |
f8eba3c6 | 5733 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5734 | } |
859825b8 | 5735 | else if (loc) |
0d381245 | 5736 | { |
f99d8bf4 PA |
5737 | struct ui_file *stb = mem_fileopen (); |
5738 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5739 | |
f99d8bf4 | 5740 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5741 | demangle, ""); |
0d381245 | 5742 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5743 | |
5744 | do_cleanups (stb_chain); | |
0d381245 | 5745 | } |
859825b8 JK |
5746 | else |
5747 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5748 | |
b775012e LM |
5749 | if (loc && is_breakpoint (b) |
5750 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5751 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5752 | { | |
5753 | ui_out_text (uiout, " ("); | |
5754 | ui_out_field_string (uiout, "evaluated-by", | |
5755 | bp_location_condition_evaluator (loc)); | |
5756 | ui_out_text (uiout, ")"); | |
5757 | } | |
5758 | ||
6c95b8df | 5759 | do_cleanups (old_chain); |
0d381245 VP |
5760 | } |
5761 | ||
269b11a2 PA |
5762 | static const char * |
5763 | bptype_string (enum bptype type) | |
c906108c | 5764 | { |
c4093a6a JM |
5765 | struct ep_type_description |
5766 | { | |
5767 | enum bptype type; | |
5768 | char *description; | |
5769 | }; | |
5770 | static struct ep_type_description bptypes[] = | |
c906108c | 5771 | { |
c5aa993b JM |
5772 | {bp_none, "?deleted?"}, |
5773 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5774 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5775 | {bp_until, "until"}, |
5776 | {bp_finish, "finish"}, | |
5777 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5778 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5779 | {bp_read_watchpoint, "read watchpoint"}, |
5780 | {bp_access_watchpoint, "acc watchpoint"}, | |
5781 | {bp_longjmp, "longjmp"}, | |
5782 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5783 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5784 | {bp_exception, "exception"}, |
5785 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5786 | {bp_step_resume, "step resume"}, |
2c03e5be | 5787 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5788 | {bp_watchpoint_scope, "watchpoint scope"}, |
5789 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5790 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5791 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5792 | {bp_thread_event, "thread events"}, |
1900040c | 5793 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5794 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5795 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5796 | {bp_exception_master, "exception master"}, |
ce78b96d | 5797 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5798 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5799 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5800 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5801 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5802 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5803 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5804 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5805 | }; |
269b11a2 PA |
5806 | |
5807 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5808 | || ((int) type != bptypes[(int) type].type)) | |
5809 | internal_error (__FILE__, __LINE__, | |
5810 | _("bptypes table does not describe type #%d."), | |
5811 | (int) type); | |
5812 | ||
5813 | return bptypes[(int) type].description; | |
5814 | } | |
5815 | ||
998580f1 MK |
5816 | DEF_VEC_I(int); |
5817 | ||
5818 | /* For MI, output a field named 'thread-groups' with a list as the value. | |
5819 | For CLI, prefix the list with the string 'inf'. */ | |
5820 | ||
5821 | static void | |
5822 | output_thread_groups (struct ui_out *uiout, | |
5823 | const char *field_name, | |
5824 | VEC(int) *inf_num, | |
5825 | int mi_only) | |
5826 | { | |
5827 | struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (uiout, | |
5828 | field_name); | |
5829 | int is_mi = ui_out_is_mi_like_p (uiout); | |
5830 | int inf; | |
5831 | int i; | |
5832 | ||
5833 | /* For backward compatibility, don't display inferiors in CLI unless | |
5834 | there are several. Always display them for MI. */ | |
5835 | if (!is_mi && mi_only) | |
5836 | return; | |
5837 | ||
5838 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) | |
5839 | { | |
5840 | if (is_mi) | |
5841 | { | |
5842 | char mi_group[10]; | |
5843 | ||
5844 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
5845 | ui_out_field_string (uiout, NULL, mi_group); | |
5846 | } | |
5847 | else | |
5848 | { | |
5849 | if (i == 0) | |
5850 | ui_out_text (uiout, " inf "); | |
5851 | else | |
5852 | ui_out_text (uiout, ", "); | |
5853 | ||
5854 | ui_out_text (uiout, plongest (inf)); | |
5855 | } | |
5856 | } | |
5857 | ||
5858 | do_cleanups (back_to); | |
5859 | } | |
5860 | ||
269b11a2 PA |
5861 | /* Print B to gdb_stdout. */ |
5862 | ||
5863 | static void | |
5864 | print_one_breakpoint_location (struct breakpoint *b, | |
5865 | struct bp_location *loc, | |
5866 | int loc_number, | |
5867 | struct bp_location **last_loc, | |
269b11a2 PA |
5868 | int allflag) |
5869 | { | |
5870 | struct command_line *l; | |
c2c6d25f | 5871 | static char bpenables[] = "nynny"; |
c906108c | 5872 | |
79a45e25 | 5873 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5874 | int header_of_multiple = 0; |
5875 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5876 | struct value_print_options opts; |
5877 | ||
5878 | get_user_print_options (&opts); | |
0d381245 VP |
5879 | |
5880 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5881 | /* See comment in print_one_breakpoint concerning treatment of |
5882 | breakpoints with single disabled location. */ | |
0d381245 VP |
5883 | if (loc == NULL |
5884 | && (b->loc != NULL | |
5885 | && (b->loc->next != NULL || !b->loc->enabled))) | |
5886 | header_of_multiple = 1; | |
5887 | if (loc == NULL) | |
5888 | loc = b->loc; | |
5889 | ||
c4093a6a JM |
5890 | annotate_record (); |
5891 | ||
5892 | /* 1 */ | |
5893 | annotate_field (0); | |
0d381245 VP |
5894 | if (part_of_multiple) |
5895 | { | |
5896 | char *formatted; | |
0c6773c1 | 5897 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
5898 | ui_out_field_string (uiout, "number", formatted); |
5899 | xfree (formatted); | |
5900 | } | |
5901 | else | |
5902 | { | |
5903 | ui_out_field_int (uiout, "number", b->number); | |
5904 | } | |
c4093a6a JM |
5905 | |
5906 | /* 2 */ | |
5907 | annotate_field (1); | |
0d381245 VP |
5908 | if (part_of_multiple) |
5909 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
5910 | else |
5911 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
5912 | |
5913 | /* 3 */ | |
5914 | annotate_field (2); | |
0d381245 VP |
5915 | if (part_of_multiple) |
5916 | ui_out_field_skip (uiout, "disp"); | |
5917 | else | |
2cec12e5 | 5918 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 5919 | |
c4093a6a JM |
5920 | |
5921 | /* 4 */ | |
5922 | annotate_field (3); | |
0d381245 | 5923 | if (part_of_multiple) |
54e52265 | 5924 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 5925 | else |
4a64f543 MS |
5926 | ui_out_field_fmt (uiout, "enabled", "%c", |
5927 | bpenables[(int) b->enable_state]); | |
54e52265 | 5928 | ui_out_spaces (uiout, 2); |
0d381245 | 5929 | |
c4093a6a JM |
5930 | |
5931 | /* 5 and 6 */ | |
3086aeae | 5932 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 5933 | { |
4a64f543 MS |
5934 | /* Although the print_one can possibly print all locations, |
5935 | calling it here is not likely to get any nice result. So, | |
5936 | make sure there's just one location. */ | |
0d381245 | 5937 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 5938 | b->ops->print_one (b, last_loc); |
0d381245 | 5939 | } |
3086aeae DJ |
5940 | else |
5941 | switch (b->type) | |
5942 | { | |
5943 | case bp_none: | |
5944 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 5945 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 5946 | break; |
c906108c | 5947 | |
3086aeae DJ |
5948 | case bp_watchpoint: |
5949 | case bp_hardware_watchpoint: | |
5950 | case bp_read_watchpoint: | |
5951 | case bp_access_watchpoint: | |
3a5c3e22 PA |
5952 | { |
5953 | struct watchpoint *w = (struct watchpoint *) b; | |
5954 | ||
5955 | /* Field 4, the address, is omitted (which makes the columns | |
5956 | not line up too nicely with the headers, but the effect | |
5957 | is relatively readable). */ | |
5958 | if (opts.addressprint) | |
5959 | ui_out_field_skip (uiout, "addr"); | |
5960 | annotate_field (5); | |
5961 | ui_out_field_string (uiout, "what", w->exp_string); | |
5962 | } | |
3086aeae DJ |
5963 | break; |
5964 | ||
3086aeae DJ |
5965 | case bp_breakpoint: |
5966 | case bp_hardware_breakpoint: | |
5967 | case bp_until: | |
5968 | case bp_finish: | |
5969 | case bp_longjmp: | |
5970 | case bp_longjmp_resume: | |
e2e4d78b | 5971 | case bp_longjmp_call_dummy: |
186c406b TT |
5972 | case bp_exception: |
5973 | case bp_exception_resume: | |
3086aeae | 5974 | case bp_step_resume: |
2c03e5be | 5975 | case bp_hp_step_resume: |
3086aeae DJ |
5976 | case bp_watchpoint_scope: |
5977 | case bp_call_dummy: | |
aa7d318d | 5978 | case bp_std_terminate: |
3086aeae DJ |
5979 | case bp_shlib_event: |
5980 | case bp_thread_event: | |
5981 | case bp_overlay_event: | |
0fd8e87f | 5982 | case bp_longjmp_master: |
aa7d318d | 5983 | case bp_std_terminate_master: |
186c406b | 5984 | case bp_exception_master: |
1042e4c0 | 5985 | case bp_tracepoint: |
7a697b8d | 5986 | case bp_fast_tracepoint: |
0fb4aa4b | 5987 | case bp_static_tracepoint: |
e7e0cddf | 5988 | case bp_dprintf: |
4efc6507 | 5989 | case bp_jit_event: |
0e30163f JK |
5990 | case bp_gnu_ifunc_resolver: |
5991 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 5992 | if (opts.addressprint) |
3086aeae DJ |
5993 | { |
5994 | annotate_field (4); | |
54e52265 | 5995 | if (header_of_multiple) |
0d381245 | 5996 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 5997 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 5998 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 5999 | else |
5af949e3 UW |
6000 | ui_out_field_core_addr (uiout, "addr", |
6001 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6002 | } |
6003 | annotate_field (5); | |
0d381245 | 6004 | if (!header_of_multiple) |
170b53b2 | 6005 | print_breakpoint_location (b, loc); |
0d381245 | 6006 | if (b->loc) |
a6d9a66e | 6007 | *last_loc = b->loc; |
3086aeae DJ |
6008 | break; |
6009 | } | |
c906108c | 6010 | |
6c95b8df | 6011 | |
998580f1 | 6012 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6013 | { |
6014 | struct inferior *inf; | |
998580f1 MK |
6015 | VEC(int) *inf_num = NULL; |
6016 | int mi_only = 1; | |
6c95b8df | 6017 | |
998580f1 | 6018 | ALL_INFERIORS (inf) |
6c95b8df PA |
6019 | { |
6020 | if (inf->pspace == loc->pspace) | |
998580f1 | 6021 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6022 | } |
998580f1 MK |
6023 | |
6024 | /* For backward compatibility, don't display inferiors in CLI unless | |
6025 | there are several. Always display for MI. */ | |
6026 | if (allflag | |
6027 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6028 | && (number_of_program_spaces () > 1 | |
6029 | || number_of_inferiors () > 1) | |
6030 | /* LOC is for existing B, it cannot be in | |
6031 | moribund_locations and thus having NULL OWNER. */ | |
6032 | && loc->owner->type != bp_catchpoint)) | |
6033 | mi_only = 0; | |
6034 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6035 | VEC_free (int, inf_num); | |
6c95b8df PA |
6036 | } |
6037 | ||
4a306c9a | 6038 | if (!part_of_multiple) |
c4093a6a | 6039 | { |
4a306c9a JB |
6040 | if (b->thread != -1) |
6041 | { | |
6042 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6043 | "stop only in" line a little further down. */ |
4a306c9a JB |
6044 | ui_out_text (uiout, " thread "); |
6045 | ui_out_field_int (uiout, "thread", b->thread); | |
6046 | } | |
6047 | else if (b->task != 0) | |
6048 | { | |
6049 | ui_out_text (uiout, " task "); | |
6050 | ui_out_field_int (uiout, "task", b->task); | |
6051 | } | |
c4093a6a | 6052 | } |
f1310107 | 6053 | |
8b93c638 | 6054 | ui_out_text (uiout, "\n"); |
f1310107 | 6055 | |
348d480f | 6056 | if (!part_of_multiple) |
f1310107 TJB |
6057 | b->ops->print_one_detail (b, uiout); |
6058 | ||
0d381245 | 6059 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6060 | { |
6061 | annotate_field (6); | |
8b93c638 | 6062 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6063 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6064 | the frame ID. */ |
5af949e3 UW |
6065 | ui_out_field_core_addr (uiout, "frame", |
6066 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6067 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6068 | } |
6069 | ||
28010a5d | 6070 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6071 | { |
6072 | annotate_field (7); | |
d77f58be | 6073 | if (is_tracepoint (b)) |
1042e4c0 SS |
6074 | ui_out_text (uiout, "\ttrace only if "); |
6075 | else | |
6076 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6077 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6078 | |
6079 | /* Print whether the target is doing the breakpoint's condition | |
6080 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6081 | if (is_breakpoint (b) | |
6082 | && breakpoint_condition_evaluation_mode () | |
6083 | == condition_evaluation_target) | |
6084 | { | |
6085 | ui_out_text (uiout, " ("); | |
6086 | ui_out_field_string (uiout, "evaluated-by", | |
6087 | bp_condition_evaluator (b)); | |
6088 | ui_out_text (uiout, " evals)"); | |
6089 | } | |
0101ce28 JJ |
6090 | ui_out_text (uiout, "\n"); |
6091 | } | |
6092 | ||
0d381245 | 6093 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6094 | { |
4a64f543 | 6095 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6096 | ui_out_text (uiout, "\tstop only in thread "); |
6097 | ui_out_field_int (uiout, "thread", b->thread); | |
6098 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6099 | } |
6100 | ||
556ec64d YQ |
6101 | if (!part_of_multiple) |
6102 | { | |
6103 | if (b->hit_count) | |
31f56a27 YQ |
6104 | { |
6105 | /* FIXME should make an annotation for this. */ | |
6106 | if (is_catchpoint (b)) | |
6107 | ui_out_text (uiout, "\tcatchpoint"); | |
6108 | else if (is_tracepoint (b)) | |
6109 | ui_out_text (uiout, "\ttracepoint"); | |
6110 | else | |
6111 | ui_out_text (uiout, "\tbreakpoint"); | |
6112 | ui_out_text (uiout, " already hit "); | |
6113 | ui_out_field_int (uiout, "times", b->hit_count); | |
6114 | if (b->hit_count == 1) | |
6115 | ui_out_text (uiout, " time\n"); | |
6116 | else | |
6117 | ui_out_text (uiout, " times\n"); | |
6118 | } | |
556ec64d YQ |
6119 | else |
6120 | { | |
31f56a27 YQ |
6121 | /* Output the count also if it is zero, but only if this is mi. */ |
6122 | if (ui_out_is_mi_like_p (uiout)) | |
6123 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6124 | } |
6125 | } | |
8b93c638 | 6126 | |
0d381245 | 6127 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6128 | { |
6129 | annotate_field (8); | |
8b93c638 JM |
6130 | ui_out_text (uiout, "\tignore next "); |
6131 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6132 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6133 | } |
059fb39f | 6134 | |
816338b5 SS |
6135 | /* Note that an enable count of 1 corresponds to "enable once" |
6136 | behavior, which is reported by the combination of enablement and | |
6137 | disposition, so we don't need to mention it here. */ | |
6138 | if (!part_of_multiple && b->enable_count > 1) | |
6139 | { | |
6140 | annotate_field (8); | |
6141 | ui_out_text (uiout, "\tdisable after "); | |
6142 | /* Tweak the wording to clarify that ignore and enable counts | |
6143 | are distinct, and have additive effect. */ | |
6144 | if (b->ignore_count) | |
6145 | ui_out_text (uiout, "additional "); | |
6146 | else | |
6147 | ui_out_text (uiout, "next "); | |
6148 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6149 | ui_out_text (uiout, " hits\n"); | |
6150 | } | |
6151 | ||
f196051f SS |
6152 | if (!part_of_multiple && is_tracepoint (b)) |
6153 | { | |
6154 | struct tracepoint *tp = (struct tracepoint *) b; | |
6155 | ||
6156 | if (tp->traceframe_usage) | |
6157 | { | |
6158 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6159 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6160 | ui_out_text (uiout, " bytes\n"); | |
6161 | } | |
6162 | } | |
d3ce09f5 | 6163 | |
9add0f1b | 6164 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6165 | if (!part_of_multiple && l) |
c4093a6a | 6166 | { |
3b31d625 EZ |
6167 | struct cleanup *script_chain; |
6168 | ||
c4093a6a | 6169 | annotate_field (9); |
3b31d625 | 6170 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6171 | print_command_lines (uiout, l, 4); |
3b31d625 | 6172 | do_cleanups (script_chain); |
c4093a6a | 6173 | } |
d24317b4 | 6174 | |
d9b3f62e | 6175 | if (is_tracepoint (b)) |
1042e4c0 | 6176 | { |
d9b3f62e PA |
6177 | struct tracepoint *t = (struct tracepoint *) b; |
6178 | ||
6179 | if (!part_of_multiple && t->pass_count) | |
6180 | { | |
6181 | annotate_field (10); | |
6182 | ui_out_text (uiout, "\tpass count "); | |
6183 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6184 | ui_out_text (uiout, " \n"); | |
6185 | } | |
f2a8bc8a YQ |
6186 | |
6187 | /* Don't display it when tracepoint or tracepoint location is | |
6188 | pending. */ | |
6189 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6190 | { | |
6191 | annotate_field (11); | |
6192 | ||
6193 | if (ui_out_is_mi_like_p (uiout)) | |
6194 | ui_out_field_string (uiout, "installed", | |
6195 | loc->inserted ? "y" : "n"); | |
6196 | else | |
6197 | { | |
6198 | if (loc->inserted) | |
6199 | ui_out_text (uiout, "\t"); | |
6200 | else | |
6201 | ui_out_text (uiout, "\tnot "); | |
6202 | ui_out_text (uiout, "installed on target\n"); | |
6203 | } | |
6204 | } | |
1042e4c0 SS |
6205 | } |
6206 | ||
d24317b4 VP |
6207 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6208 | { | |
3a5c3e22 PA |
6209 | if (is_watchpoint (b)) |
6210 | { | |
6211 | struct watchpoint *w = (struct watchpoint *) b; | |
6212 | ||
6213 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6214 | } | |
6215 | else if (b->addr_string) | |
d24317b4 | 6216 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6217 | } |
c4093a6a | 6218 | } |
c5aa993b | 6219 | |
0d381245 VP |
6220 | static void |
6221 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6222 | struct bp_location **last_loc, |
6c95b8df | 6223 | int allflag) |
0d381245 | 6224 | { |
8d3788bd | 6225 | struct cleanup *bkpt_chain; |
79a45e25 | 6226 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6227 | |
6228 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6229 | ||
12c5a436 | 6230 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6231 | do_cleanups (bkpt_chain); |
0d381245 VP |
6232 | |
6233 | /* If this breakpoint has custom print function, | |
6234 | it's already printed. Otherwise, print individual | |
6235 | locations, if any. */ | |
6236 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6237 | { | |
4a64f543 MS |
6238 | /* If breakpoint has a single location that is disabled, we |
6239 | print it as if it had several locations, since otherwise it's | |
6240 | hard to represent "breakpoint enabled, location disabled" | |
6241 | situation. | |
6242 | ||
6243 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6244 | internally, that's not a property exposed to user. */ |
0d381245 | 6245 | if (b->loc |
a5606eee | 6246 | && !is_hardware_watchpoint (b) |
8d3788bd | 6247 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6248 | { |
6249 | struct bp_location *loc; | |
6250 | int n = 1; | |
8d3788bd | 6251 | |
0d381245 | 6252 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6253 | { |
6254 | struct cleanup *inner2 = | |
6255 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6256 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6257 | do_cleanups (inner2); | |
6258 | } | |
0d381245 VP |
6259 | } |
6260 | } | |
6261 | } | |
6262 | ||
a6d9a66e UW |
6263 | static int |
6264 | breakpoint_address_bits (struct breakpoint *b) | |
6265 | { | |
6266 | int print_address_bits = 0; | |
6267 | struct bp_location *loc; | |
6268 | ||
6269 | for (loc = b->loc; loc; loc = loc->next) | |
6270 | { | |
c7437ca6 PA |
6271 | int addr_bit; |
6272 | ||
6273 | /* Software watchpoints that aren't watching memory don't have | |
6274 | an address to print. */ | |
6275 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6276 | continue; | |
6277 | ||
6278 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6279 | if (addr_bit > print_address_bits) |
6280 | print_address_bits = addr_bit; | |
6281 | } | |
6282 | ||
6283 | return print_address_bits; | |
6284 | } | |
0d381245 | 6285 | |
c4093a6a JM |
6286 | struct captured_breakpoint_query_args |
6287 | { | |
6288 | int bnum; | |
6289 | }; | |
c5aa993b | 6290 | |
c4093a6a | 6291 | static int |
2b65245e | 6292 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6293 | { |
6294 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6295 | struct breakpoint *b; |
a6d9a66e | 6296 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6297 | |
c4093a6a JM |
6298 | ALL_BREAKPOINTS (b) |
6299 | { | |
6300 | if (args->bnum == b->number) | |
c5aa993b | 6301 | { |
12c5a436 | 6302 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6303 | return GDB_RC_OK; |
c5aa993b | 6304 | } |
c4093a6a JM |
6305 | } |
6306 | return GDB_RC_NONE; | |
6307 | } | |
c5aa993b | 6308 | |
c4093a6a | 6309 | enum gdb_rc |
4a64f543 MS |
6310 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6311 | char **error_message) | |
c4093a6a JM |
6312 | { |
6313 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6314 | |
c4093a6a JM |
6315 | args.bnum = bnum; |
6316 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6317 | an error. */ |
b0b13bb4 DJ |
6318 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6319 | error_message, RETURN_MASK_ALL) < 0) | |
6320 | return GDB_RC_FAIL; | |
6321 | else | |
6322 | return GDB_RC_OK; | |
c4093a6a | 6323 | } |
c5aa993b | 6324 | |
09d682a4 TT |
6325 | /* Return true if this breakpoint was set by the user, false if it is |
6326 | internal or momentary. */ | |
6327 | ||
6328 | int | |
6329 | user_breakpoint_p (struct breakpoint *b) | |
6330 | { | |
46c6471b | 6331 | return b->number > 0; |
09d682a4 TT |
6332 | } |
6333 | ||
7f3b0473 | 6334 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6335 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6336 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6337 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6338 | ones for which it returns non-zero. Return the total number of | |
6339 | breakpoints listed. */ | |
c906108c | 6340 | |
d77f58be | 6341 | static int |
e5a67952 | 6342 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6343 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6344 | { |
52f0bd74 | 6345 | struct breakpoint *b; |
a6d9a66e | 6346 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6347 | int nr_printable_breakpoints; |
3b31d625 | 6348 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6349 | struct value_print_options opts; |
a6d9a66e | 6350 | int print_address_bits = 0; |
269b11a2 | 6351 | int print_type_col_width = 14; |
79a45e25 | 6352 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6353 | |
79a45b7d TT |
6354 | get_user_print_options (&opts); |
6355 | ||
4a64f543 MS |
6356 | /* Compute the number of rows in the table, as well as the size |
6357 | required for address fields. */ | |
7f3b0473 AC |
6358 | nr_printable_breakpoints = 0; |
6359 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6360 | { |
6361 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6362 | if (filter && !filter (b)) | |
6363 | continue; | |
6364 | ||
6365 | /* If we have an "args" string, it is a list of breakpoints to | |
6366 | accept. Skip the others. */ | |
6367 | if (args != NULL && *args != '\0') | |
6368 | { | |
6369 | if (allflag && parse_and_eval_long (args) != b->number) | |
6370 | continue; | |
6371 | if (!allflag && !number_is_in_list (args, b->number)) | |
6372 | continue; | |
6373 | } | |
269b11a2 | 6374 | |
e5a67952 MS |
6375 | if (allflag || user_breakpoint_p (b)) |
6376 | { | |
6377 | int addr_bit, type_len; | |
a6d9a66e | 6378 | |
e5a67952 MS |
6379 | addr_bit = breakpoint_address_bits (b); |
6380 | if (addr_bit > print_address_bits) | |
6381 | print_address_bits = addr_bit; | |
269b11a2 | 6382 | |
e5a67952 MS |
6383 | type_len = strlen (bptype_string (b->type)); |
6384 | if (type_len > print_type_col_width) | |
6385 | print_type_col_width = type_len; | |
6386 | ||
6387 | nr_printable_breakpoints++; | |
6388 | } | |
6389 | } | |
7f3b0473 | 6390 | |
79a45b7d | 6391 | if (opts.addressprint) |
3b31d625 | 6392 | bkpttbl_chain |
3e43a32a MS |
6393 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6394 | nr_printable_breakpoints, | |
3b31d625 | 6395 | "BreakpointTable"); |
8b93c638 | 6396 | else |
3b31d625 | 6397 | bkpttbl_chain |
3e43a32a MS |
6398 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6399 | nr_printable_breakpoints, | |
3b31d625 | 6400 | "BreakpointTable"); |
8b93c638 | 6401 | |
7f3b0473 | 6402 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6403 | annotate_breakpoints_headers (); |
6404 | if (nr_printable_breakpoints > 0) | |
6405 | annotate_field (0); | |
4a64f543 | 6406 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6407 | if (nr_printable_breakpoints > 0) |
6408 | annotate_field (1); | |
269b11a2 | 6409 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6410 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6411 | if (nr_printable_breakpoints > 0) |
6412 | annotate_field (2); | |
4a64f543 | 6413 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6414 | if (nr_printable_breakpoints > 0) |
6415 | annotate_field (3); | |
54e52265 | 6416 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6417 | if (opts.addressprint) |
e5a67952 MS |
6418 | { |
6419 | if (nr_printable_breakpoints > 0) | |
6420 | annotate_field (4); | |
6421 | if (print_address_bits <= 32) | |
6422 | ui_out_table_header (uiout, 10, ui_left, | |
6423 | "addr", "Address"); /* 5 */ | |
6424 | else | |
6425 | ui_out_table_header (uiout, 18, ui_left, | |
6426 | "addr", "Address"); /* 5 */ | |
6427 | } | |
d7faa9e7 AC |
6428 | if (nr_printable_breakpoints > 0) |
6429 | annotate_field (5); | |
6430 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6431 | ui_out_table_body (uiout); | |
6432 | if (nr_printable_breakpoints > 0) | |
6433 | annotate_breakpoints_table (); | |
7f3b0473 | 6434 | |
c4093a6a | 6435 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6436 | { |
6437 | QUIT; | |
6438 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6439 | if (filter && !filter (b)) | |
6440 | continue; | |
6441 | ||
6442 | /* If we have an "args" string, it is a list of breakpoints to | |
6443 | accept. Skip the others. */ | |
6444 | ||
6445 | if (args != NULL && *args != '\0') | |
6446 | { | |
6447 | if (allflag) /* maintenance info breakpoint */ | |
6448 | { | |
6449 | if (parse_and_eval_long (args) != b->number) | |
6450 | continue; | |
6451 | } | |
6452 | else /* all others */ | |
6453 | { | |
6454 | if (!number_is_in_list (args, b->number)) | |
6455 | continue; | |
6456 | } | |
6457 | } | |
6458 | /* We only print out user settable breakpoints unless the | |
6459 | allflag is set. */ | |
6460 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6461 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6462 | } |
6463 | ||
3b31d625 | 6464 | do_cleanups (bkpttbl_chain); |
698384cd | 6465 | |
7f3b0473 | 6466 | if (nr_printable_breakpoints == 0) |
c906108c | 6467 | { |
4a64f543 MS |
6468 | /* If there's a filter, let the caller decide how to report |
6469 | empty list. */ | |
d77f58be SS |
6470 | if (!filter) |
6471 | { | |
e5a67952 | 6472 | if (args == NULL || *args == '\0') |
d77f58be SS |
6473 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6474 | else | |
4a64f543 | 6475 | ui_out_message (uiout, 0, |
e5a67952 MS |
6476 | "No breakpoint or watchpoint matching '%s'.\n", |
6477 | args); | |
d77f58be | 6478 | } |
c906108c SS |
6479 | } |
6480 | else | |
c4093a6a | 6481 | { |
a6d9a66e UW |
6482 | if (last_loc && !server_command) |
6483 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6484 | } |
c906108c | 6485 | |
4a64f543 | 6486 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6487 | there have been breakpoints? */ |
c906108c | 6488 | annotate_breakpoints_table_end (); |
d77f58be SS |
6489 | |
6490 | return nr_printable_breakpoints; | |
c906108c SS |
6491 | } |
6492 | ||
ad443146 SS |
6493 | /* Display the value of default-collect in a way that is generally |
6494 | compatible with the breakpoint list. */ | |
6495 | ||
6496 | static void | |
6497 | default_collect_info (void) | |
6498 | { | |
79a45e25 PA |
6499 | struct ui_out *uiout = current_uiout; |
6500 | ||
ad443146 SS |
6501 | /* If it has no value (which is frequently the case), say nothing; a |
6502 | message like "No default-collect." gets in user's face when it's | |
6503 | not wanted. */ | |
6504 | if (!*default_collect) | |
6505 | return; | |
6506 | ||
6507 | /* The following phrase lines up nicely with per-tracepoint collect | |
6508 | actions. */ | |
6509 | ui_out_text (uiout, "default collect "); | |
6510 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6511 | ui_out_text (uiout, " \n"); | |
6512 | } | |
6513 | ||
c906108c | 6514 | static void |
e5a67952 | 6515 | breakpoints_info (char *args, int from_tty) |
c906108c | 6516 | { |
e5a67952 | 6517 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6518 | |
6519 | default_collect_info (); | |
d77f58be SS |
6520 | } |
6521 | ||
6522 | static void | |
e5a67952 | 6523 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6524 | { |
e5a67952 | 6525 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6526 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6527 | |
6528 | if (num_printed == 0) | |
6529 | { | |
e5a67952 | 6530 | if (args == NULL || *args == '\0') |
d77f58be SS |
6531 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6532 | else | |
e5a67952 | 6533 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6534 | } |
c906108c SS |
6535 | } |
6536 | ||
7a292a7a | 6537 | static void |
e5a67952 | 6538 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6539 | { |
e5a67952 | 6540 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6541 | |
6542 | default_collect_info (); | |
c906108c SS |
6543 | } |
6544 | ||
0d381245 | 6545 | static int |
714835d5 | 6546 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6547 | struct program_space *pspace, |
714835d5 | 6548 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6549 | { |
6550 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6551 | |
0d381245 VP |
6552 | for (; bl; bl = bl->next) |
6553 | { | |
6c95b8df PA |
6554 | if (bl->pspace == pspace |
6555 | && bl->address == pc | |
0d381245 VP |
6556 | && (!overlay_debugging || bl->section == section)) |
6557 | return 1; | |
6558 | } | |
6559 | return 0; | |
6560 | } | |
6561 | ||
672f9b60 | 6562 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6563 | concerns with logical breakpoints, so we match program spaces, not |
6564 | address spaces. */ | |
c906108c SS |
6565 | |
6566 | static void | |
6c95b8df PA |
6567 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6568 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6569 | struct obj_section *section, int thread) |
c906108c | 6570 | { |
52f0bd74 AC |
6571 | int others = 0; |
6572 | struct breakpoint *b; | |
c906108c SS |
6573 | |
6574 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6575 | others += (user_breakpoint_p (b) |
6576 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6577 | if (others > 0) |
6578 | { | |
a3f17187 AC |
6579 | if (others == 1) |
6580 | printf_filtered (_("Note: breakpoint ")); | |
6581 | else /* if (others == ???) */ | |
6582 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6583 | ALL_BREAKPOINTS (b) |
672f9b60 | 6584 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6585 | { |
6586 | others--; | |
6587 | printf_filtered ("%d", b->number); | |
6588 | if (b->thread == -1 && thread != -1) | |
6589 | printf_filtered (" (all threads)"); | |
6590 | else if (b->thread != -1) | |
6591 | printf_filtered (" (thread %d)", b->thread); | |
6592 | printf_filtered ("%s%s ", | |
059fb39f | 6593 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6594 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6595 | ? " (disabled)" |
6596 | : b->enable_state == bp_permanent | |
6597 | ? " (permanent)" | |
6598 | : ""), | |
6599 | (others > 1) ? "," | |
6600 | : ((others == 1) ? " and" : "")); | |
6601 | } | |
a3f17187 | 6602 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6603 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6604 | printf_filtered (".\n"); |
6605 | } | |
6606 | } | |
6607 | \f | |
c906108c | 6608 | |
e4f237da KB |
6609 | /* Return true iff it is meaningful to use the address member of |
6610 | BPT. For some breakpoint types, the address member is irrelevant | |
6611 | and it makes no sense to attempt to compare it to other addresses | |
6612 | (or use it for any other purpose either). | |
6613 | ||
4a64f543 MS |
6614 | More specifically, each of the following breakpoint types will |
6615 | always have a zero valued address and we don't want to mark | |
6616 | breakpoints of any of these types to be a duplicate of an actual | |
6617 | breakpoint at address zero: | |
e4f237da KB |
6618 | |
6619 | bp_watchpoint | |
2d134ed3 PA |
6620 | bp_catchpoint |
6621 | ||
6622 | */ | |
e4f237da KB |
6623 | |
6624 | static int | |
6625 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6626 | { | |
6627 | enum bptype type = bpt->type; | |
6628 | ||
2d134ed3 PA |
6629 | return (type != bp_watchpoint && type != bp_catchpoint); |
6630 | } | |
6631 | ||
6632 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6633 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6634 | ||
6635 | static int | |
4a64f543 MS |
6636 | watchpoint_locations_match (struct bp_location *loc1, |
6637 | struct bp_location *loc2) | |
2d134ed3 | 6638 | { |
3a5c3e22 PA |
6639 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6640 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6641 | ||
6642 | /* Both of them must exist. */ | |
6643 | gdb_assert (w1 != NULL); | |
6644 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6645 | |
4a64f543 MS |
6646 | /* If the target can evaluate the condition expression in hardware, |
6647 | then we we need to insert both watchpoints even if they are at | |
6648 | the same place. Otherwise the watchpoint will only trigger when | |
6649 | the condition of whichever watchpoint was inserted evaluates to | |
6650 | true, not giving a chance for GDB to check the condition of the | |
6651 | other watchpoint. */ | |
3a5c3e22 | 6652 | if ((w1->cond_exp |
4a64f543 MS |
6653 | && target_can_accel_watchpoint_condition (loc1->address, |
6654 | loc1->length, | |
0cf6dd15 | 6655 | loc1->watchpoint_type, |
3a5c3e22 PA |
6656 | w1->cond_exp)) |
6657 | || (w2->cond_exp | |
4a64f543 MS |
6658 | && target_can_accel_watchpoint_condition (loc2->address, |
6659 | loc2->length, | |
0cf6dd15 | 6660 | loc2->watchpoint_type, |
3a5c3e22 | 6661 | w2->cond_exp))) |
0cf6dd15 TJB |
6662 | return 0; |
6663 | ||
85d721b8 PA |
6664 | /* Note that this checks the owner's type, not the location's. In |
6665 | case the target does not support read watchpoints, but does | |
6666 | support access watchpoints, we'll have bp_read_watchpoint | |
6667 | watchpoints with hw_access locations. Those should be considered | |
6668 | duplicates of hw_read locations. The hw_read locations will | |
6669 | become hw_access locations later. */ | |
2d134ed3 PA |
6670 | return (loc1->owner->type == loc2->owner->type |
6671 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6672 | && loc1->address == loc2->address | |
6673 | && loc1->length == loc2->length); | |
e4f237da KB |
6674 | } |
6675 | ||
6c95b8df PA |
6676 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
6677 | same breakpoint location. In most targets, this can only be true | |
6678 | if ASPACE1 matches ASPACE2. On targets that have global | |
6679 | breakpoints, the address space doesn't really matter. */ | |
6680 | ||
6681 | static int | |
6682 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
6683 | struct address_space *aspace2, CORE_ADDR addr2) | |
6684 | { | |
f5656ead | 6685 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6686 | || aspace1 == aspace2) |
6687 | && addr1 == addr2); | |
6688 | } | |
6689 | ||
f1310107 TJB |
6690 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6691 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6692 | matches ASPACE2. On targets that have global breakpoints, the address | |
6693 | space doesn't really matter. */ | |
6694 | ||
6695 | static int | |
6696 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6697 | int len1, struct address_space *aspace2, | |
6698 | CORE_ADDR addr2) | |
6699 | { | |
f5656ead | 6700 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6701 | || aspace1 == aspace2) |
6702 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6703 | } | |
6704 | ||
6705 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6706 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6707 | matches the breakpoint's address space. On targets that have global | |
6708 | breakpoints, the address space doesn't really matter. */ | |
6709 | ||
6710 | static int | |
6711 | breakpoint_location_address_match (struct bp_location *bl, | |
6712 | struct address_space *aspace, | |
6713 | CORE_ADDR addr) | |
6714 | { | |
6715 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6716 | aspace, addr) | |
6717 | || (bl->length | |
6718 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6719 | bl->address, bl->length, | |
6720 | aspace, addr))); | |
6721 | } | |
6722 | ||
1e4d1764 YQ |
6723 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6724 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6725 | true, otherwise returns false. */ | |
6726 | ||
6727 | static int | |
6728 | tracepoint_locations_match (struct bp_location *loc1, | |
6729 | struct bp_location *loc2) | |
6730 | { | |
6731 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6732 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6733 | locations at the same address of different tracepoints are regarded as | |
6734 | different locations. */ | |
6735 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6736 | else | |
6737 | return 0; | |
6738 | } | |
6739 | ||
2d134ed3 PA |
6740 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6741 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6742 | represent the same location. */ | |
6743 | ||
6744 | static int | |
4a64f543 MS |
6745 | breakpoint_locations_match (struct bp_location *loc1, |
6746 | struct bp_location *loc2) | |
2d134ed3 | 6747 | { |
2bdf28a0 JK |
6748 | int hw_point1, hw_point2; |
6749 | ||
6750 | /* Both of them must not be in moribund_locations. */ | |
6751 | gdb_assert (loc1->owner != NULL); | |
6752 | gdb_assert (loc2->owner != NULL); | |
6753 | ||
6754 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6755 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6756 | |
6757 | if (hw_point1 != hw_point2) | |
6758 | return 0; | |
6759 | else if (hw_point1) | |
6760 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6761 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6762 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6763 | else |
f1310107 TJB |
6764 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6765 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6766 | loc2->pspace->aspace, loc2->address) | |
6767 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6768 | } |
6769 | ||
76897487 KB |
6770 | static void |
6771 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6772 | int bnum, int have_bnum) | |
6773 | { | |
f63fbe86 MS |
6774 | /* The longest string possibly returned by hex_string_custom |
6775 | is 50 chars. These must be at least that big for safety. */ | |
6776 | char astr1[64]; | |
6777 | char astr2[64]; | |
76897487 | 6778 | |
bb599908 PH |
6779 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6780 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6781 | if (have_bnum) |
8a3fe4f8 | 6782 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6783 | bnum, astr1, astr2); |
6784 | else | |
8a3fe4f8 | 6785 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6786 | } |
6787 | ||
4a64f543 MS |
6788 | /* Adjust a breakpoint's address to account for architectural |
6789 | constraints on breakpoint placement. Return the adjusted address. | |
6790 | Note: Very few targets require this kind of adjustment. For most | |
6791 | targets, this function is simply the identity function. */ | |
76897487 KB |
6792 | |
6793 | static CORE_ADDR | |
a6d9a66e UW |
6794 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6795 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6796 | { |
a6d9a66e | 6797 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6798 | { |
6799 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6800 | return bpaddr; | |
6801 | } | |
88f7da05 KB |
6802 | else if (bptype == bp_watchpoint |
6803 | || bptype == bp_hardware_watchpoint | |
6804 | || bptype == bp_read_watchpoint | |
6805 | || bptype == bp_access_watchpoint | |
fe798b75 | 6806 | || bptype == bp_catchpoint) |
88f7da05 KB |
6807 | { |
6808 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6809 | have their addresses modified. */ | |
6810 | return bpaddr; | |
6811 | } | |
76897487 KB |
6812 | else |
6813 | { | |
6814 | CORE_ADDR adjusted_bpaddr; | |
6815 | ||
6816 | /* Some targets have architectural constraints on the placement | |
6817 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6818 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6819 | |
6820 | /* An adjusted breakpoint address can significantly alter | |
6821 | a user's expectations. Print a warning if an adjustment | |
6822 | is required. */ | |
6823 | if (adjusted_bpaddr != bpaddr) | |
6824 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6825 | ||
6826 | return adjusted_bpaddr; | |
6827 | } | |
6828 | } | |
6829 | ||
28010a5d PA |
6830 | void |
6831 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
6832 | struct breakpoint *owner) | |
7cc221ef | 6833 | { |
7cc221ef DJ |
6834 | memset (loc, 0, sizeof (*loc)); |
6835 | ||
348d480f PA |
6836 | gdb_assert (ops != NULL); |
6837 | ||
28010a5d PA |
6838 | loc->ops = ops; |
6839 | loc->owner = owner; | |
511a6cd4 | 6840 | loc->cond = NULL; |
b775012e | 6841 | loc->cond_bytecode = NULL; |
0d381245 VP |
6842 | loc->shlib_disabled = 0; |
6843 | loc->enabled = 1; | |
e049a4b5 | 6844 | |
28010a5d | 6845 | switch (owner->type) |
e049a4b5 DJ |
6846 | { |
6847 | case bp_breakpoint: | |
6848 | case bp_until: | |
6849 | case bp_finish: | |
6850 | case bp_longjmp: | |
6851 | case bp_longjmp_resume: | |
e2e4d78b | 6852 | case bp_longjmp_call_dummy: |
186c406b TT |
6853 | case bp_exception: |
6854 | case bp_exception_resume: | |
e049a4b5 | 6855 | case bp_step_resume: |
2c03e5be | 6856 | case bp_hp_step_resume: |
e049a4b5 DJ |
6857 | case bp_watchpoint_scope: |
6858 | case bp_call_dummy: | |
aa7d318d | 6859 | case bp_std_terminate: |
e049a4b5 DJ |
6860 | case bp_shlib_event: |
6861 | case bp_thread_event: | |
6862 | case bp_overlay_event: | |
4efc6507 | 6863 | case bp_jit_event: |
0fd8e87f | 6864 | case bp_longjmp_master: |
aa7d318d | 6865 | case bp_std_terminate_master: |
186c406b | 6866 | case bp_exception_master: |
0e30163f JK |
6867 | case bp_gnu_ifunc_resolver: |
6868 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6869 | case bp_dprintf: |
e049a4b5 | 6870 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6871 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6872 | break; |
6873 | case bp_hardware_breakpoint: | |
6874 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6875 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6876 | break; |
6877 | case bp_hardware_watchpoint: | |
6878 | case bp_read_watchpoint: | |
6879 | case bp_access_watchpoint: | |
6880 | loc->loc_type = bp_loc_hardware_watchpoint; | |
6881 | break; | |
6882 | case bp_watchpoint: | |
ce78b96d | 6883 | case bp_catchpoint: |
15c3d785 PA |
6884 | case bp_tracepoint: |
6885 | case bp_fast_tracepoint: | |
0fb4aa4b | 6886 | case bp_static_tracepoint: |
e049a4b5 DJ |
6887 | loc->loc_type = bp_loc_other; |
6888 | break; | |
6889 | default: | |
e2e0b3e5 | 6890 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
6891 | } |
6892 | ||
f431efe5 | 6893 | loc->refc = 1; |
28010a5d PA |
6894 | } |
6895 | ||
6896 | /* Allocate a struct bp_location. */ | |
6897 | ||
6898 | static struct bp_location * | |
6899 | allocate_bp_location (struct breakpoint *bpt) | |
6900 | { | |
348d480f PA |
6901 | return bpt->ops->allocate_location (bpt); |
6902 | } | |
7cc221ef | 6903 | |
f431efe5 PA |
6904 | static void |
6905 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6906 | { |
348d480f | 6907 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
6908 | xfree (loc); |
6909 | } | |
6910 | ||
f431efe5 PA |
6911 | /* Increment reference count. */ |
6912 | ||
6913 | static void | |
6914 | incref_bp_location (struct bp_location *bl) | |
6915 | { | |
6916 | ++bl->refc; | |
6917 | } | |
6918 | ||
6919 | /* Decrement reference count. If the reference count reaches 0, | |
6920 | destroy the bp_location. Sets *BLP to NULL. */ | |
6921 | ||
6922 | static void | |
6923 | decref_bp_location (struct bp_location **blp) | |
6924 | { | |
0807b50c PA |
6925 | gdb_assert ((*blp)->refc > 0); |
6926 | ||
f431efe5 PA |
6927 | if (--(*blp)->refc == 0) |
6928 | free_bp_location (*blp); | |
6929 | *blp = NULL; | |
6930 | } | |
6931 | ||
346774a9 | 6932 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 6933 | |
346774a9 PA |
6934 | static void |
6935 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 6936 | { |
346774a9 | 6937 | struct breakpoint *b1; |
c906108c | 6938 | |
346774a9 PA |
6939 | /* Add this breakpoint to the end of the chain so that a list of |
6940 | breakpoints will come out in order of increasing numbers. */ | |
6941 | ||
6942 | b1 = breakpoint_chain; | |
6943 | if (b1 == 0) | |
6944 | breakpoint_chain = b; | |
6945 | else | |
6946 | { | |
6947 | while (b1->next) | |
6948 | b1 = b1->next; | |
6949 | b1->next = b; | |
6950 | } | |
6951 | } | |
6952 | ||
6953 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
6954 | ||
6955 | static void | |
6956 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
6957 | struct gdbarch *gdbarch, | |
28010a5d | 6958 | enum bptype bptype, |
c0a91b2b | 6959 | const struct breakpoint_ops *ops) |
346774a9 | 6960 | { |
c906108c | 6961 | memset (b, 0, sizeof (*b)); |
2219d63c | 6962 | |
348d480f PA |
6963 | gdb_assert (ops != NULL); |
6964 | ||
28010a5d | 6965 | b->ops = ops; |
4d28f7a8 | 6966 | b->type = bptype; |
a6d9a66e | 6967 | b->gdbarch = gdbarch; |
c906108c SS |
6968 | b->language = current_language->la_language; |
6969 | b->input_radix = input_radix; | |
6970 | b->thread = -1; | |
b5de0fa7 | 6971 | b->enable_state = bp_enabled; |
c906108c SS |
6972 | b->next = 0; |
6973 | b->silent = 0; | |
6974 | b->ignore_count = 0; | |
6975 | b->commands = NULL; | |
818dd999 | 6976 | b->frame_id = null_frame_id; |
0d381245 | 6977 | b->condition_not_parsed = 0; |
84f4c1fe | 6978 | b->py_bp_object = NULL; |
d0fb5eae | 6979 | b->related_breakpoint = b; |
346774a9 PA |
6980 | } |
6981 | ||
6982 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
6983 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
6984 | |
6985 | static struct breakpoint * | |
6986 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 6987 | enum bptype bptype, |
c0a91b2b | 6988 | const struct breakpoint_ops *ops) |
346774a9 PA |
6989 | { |
6990 | struct breakpoint *b = XNEW (struct breakpoint); | |
6991 | ||
348d480f | 6992 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 6993 | add_to_breakpoint_chain (b); |
0d381245 VP |
6994 | return b; |
6995 | } | |
6996 | ||
0e30163f JK |
6997 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
6998 | resolutions should be made as the user specified the location explicitly | |
6999 | enough. */ | |
7000 | ||
0d381245 | 7001 | static void |
0e30163f | 7002 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7003 | { |
2bdf28a0 JK |
7004 | gdb_assert (loc->owner != NULL); |
7005 | ||
0d381245 | 7006 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7007 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7008 | || is_tracepoint (loc->owner)) |
0d381245 | 7009 | { |
0e30163f | 7010 | int is_gnu_ifunc; |
2c02bd72 | 7011 | const char *function_name; |
6a3a010b | 7012 | CORE_ADDR func_addr; |
0e30163f | 7013 | |
2c02bd72 | 7014 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7015 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7016 | |
7017 | if (is_gnu_ifunc && !explicit_loc) | |
7018 | { | |
7019 | struct breakpoint *b = loc->owner; | |
7020 | ||
7021 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7022 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7023 | &loc->requested_address)) |
7024 | { | |
7025 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7026 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7027 | loc->requested_address, | |
7028 | b->type); | |
7029 | } | |
7030 | else if (b->type == bp_breakpoint && b->loc == loc | |
7031 | && loc->next == NULL && b->related_breakpoint == b) | |
7032 | { | |
7033 | /* Create only the whole new breakpoint of this type but do not | |
7034 | mess more complicated breakpoints with multiple locations. */ | |
7035 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7036 | /* Remember the resolver's address for use by the return |
7037 | breakpoint. */ | |
7038 | loc->related_address = func_addr; | |
0e30163f JK |
7039 | } |
7040 | } | |
7041 | ||
2c02bd72 DE |
7042 | if (function_name) |
7043 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7044 | } |
7045 | } | |
7046 | ||
a6d9a66e | 7047 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7048 | struct gdbarch * |
a6d9a66e UW |
7049 | get_sal_arch (struct symtab_and_line sal) |
7050 | { | |
7051 | if (sal.section) | |
7052 | return get_objfile_arch (sal.section->objfile); | |
7053 | if (sal.symtab) | |
7054 | return get_objfile_arch (sal.symtab->objfile); | |
7055 | ||
7056 | return NULL; | |
7057 | } | |
7058 | ||
346774a9 PA |
7059 | /* Low level routine for partially initializing a breakpoint of type |
7060 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7061 | file name, and line number are provided by SAL. |
0d381245 VP |
7062 | |
7063 | It is expected that the caller will complete the initialization of | |
7064 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7065 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7066 | |
346774a9 PA |
7067 | static void |
7068 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7069 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7070 | const struct breakpoint_ops *ops) |
0d381245 | 7071 | { |
28010a5d | 7072 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7073 | |
3742cc8b | 7074 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7075 | |
6c95b8df PA |
7076 | if (bptype != bp_catchpoint) |
7077 | gdb_assert (sal.pspace != NULL); | |
7078 | ||
f8eba3c6 TT |
7079 | /* Store the program space that was used to set the breakpoint, |
7080 | except for ordinary breakpoints, which are independent of the | |
7081 | program space. */ | |
7082 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7083 | b->pspace = sal.pspace; | |
346774a9 | 7084 | } |
c906108c | 7085 | |
346774a9 PA |
7086 | /* set_raw_breakpoint is a low level routine for allocating and |
7087 | partially initializing a breakpoint of type BPTYPE. The newly | |
7088 | created breakpoint's address, section, source file name, and line | |
7089 | number are provided by SAL. The newly created and partially | |
7090 | initialized breakpoint is added to the breakpoint chain and | |
7091 | is also returned as the value of this function. | |
7092 | ||
7093 | It is expected that the caller will complete the initialization of | |
7094 | the newly created breakpoint struct as well as output any status | |
7095 | information regarding the creation of a new breakpoint. In | |
7096 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7097 | number! Care should be taken to not allow an error to occur | |
7098 | prior to completing the initialization of the breakpoint. If this | |
7099 | should happen, a bogus breakpoint will be left on the chain. */ | |
7100 | ||
7101 | struct breakpoint * | |
7102 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7103 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7104 | const struct breakpoint_ops *ops) |
346774a9 PA |
7105 | { |
7106 | struct breakpoint *b = XNEW (struct breakpoint); | |
7107 | ||
348d480f | 7108 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7109 | add_to_breakpoint_chain (b); |
c906108c SS |
7110 | return b; |
7111 | } | |
7112 | ||
c2c6d25f JM |
7113 | |
7114 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7115 | instruction, hard-wired into the inferior's code. */ | |
7116 | void | |
7117 | make_breakpoint_permanent (struct breakpoint *b) | |
7118 | { | |
0d381245 | 7119 | struct bp_location *bl; |
cc59ec59 | 7120 | |
b5de0fa7 | 7121 | b->enable_state = bp_permanent; |
c2c6d25f | 7122 | |
4a64f543 MS |
7123 | /* By definition, permanent breakpoints are already present in the |
7124 | code. Mark all locations as inserted. For now, | |
7125 | make_breakpoint_permanent is called in just one place, so it's | |
7126 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7127 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
7128 | for (bl = b->loc; bl; bl = bl->next) |
7129 | bl->inserted = 1; | |
c2c6d25f JM |
7130 | } |
7131 | ||
53a5351d | 7132 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7133 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7134 | initiated the operation. */ | |
c906108c SS |
7135 | |
7136 | void | |
186c406b | 7137 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7138 | { |
35df4500 | 7139 | struct breakpoint *b, *b_tmp; |
186c406b | 7140 | int thread = tp->num; |
0fd8e87f UW |
7141 | |
7142 | /* To avoid having to rescan all objfile symbols at every step, | |
7143 | we maintain a list of continually-inserted but always disabled | |
7144 | longjmp "master" breakpoints. Here, we simply create momentary | |
7145 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7146 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7147 | if (b->pspace == current_program_space |
186c406b TT |
7148 | && (b->type == bp_longjmp_master |
7149 | || b->type == bp_exception_master)) | |
0fd8e87f | 7150 | { |
06edf0c0 PA |
7151 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7152 | struct breakpoint *clone; | |
cc59ec59 | 7153 | |
e2e4d78b JK |
7154 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7155 | after their removal. */ | |
06edf0c0 | 7156 | clone = momentary_breakpoint_from_master (b, type, |
e2e4d78b | 7157 | &longjmp_breakpoint_ops); |
0fd8e87f UW |
7158 | clone->thread = thread; |
7159 | } | |
186c406b TT |
7160 | |
7161 | tp->initiating_frame = frame; | |
c906108c SS |
7162 | } |
7163 | ||
611c83ae | 7164 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7165 | void |
611c83ae | 7166 | delete_longjmp_breakpoint (int thread) |
c906108c | 7167 | { |
35df4500 | 7168 | struct breakpoint *b, *b_tmp; |
c906108c | 7169 | |
35df4500 | 7170 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7171 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7172 | { |
7173 | if (b->thread == thread) | |
7174 | delete_breakpoint (b); | |
7175 | } | |
c906108c SS |
7176 | } |
7177 | ||
f59f708a PA |
7178 | void |
7179 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7180 | { | |
7181 | struct breakpoint *b, *b_tmp; | |
7182 | ||
7183 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7184 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7185 | { | |
7186 | if (b->thread == thread) | |
7187 | b->disposition = disp_del_at_next_stop; | |
7188 | } | |
7189 | } | |
7190 | ||
e2e4d78b JK |
7191 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7192 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7193 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7194 | breakpoints. */ | |
7195 | ||
7196 | struct breakpoint * | |
7197 | set_longjmp_breakpoint_for_call_dummy (void) | |
7198 | { | |
7199 | struct breakpoint *b, *retval = NULL; | |
7200 | ||
7201 | ALL_BREAKPOINTS (b) | |
7202 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7203 | { | |
7204 | struct breakpoint *new_b; | |
7205 | ||
7206 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
7207 | &momentary_breakpoint_ops); | |
7208 | new_b->thread = pid_to_thread_id (inferior_ptid); | |
7209 | ||
7210 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7211 | ||
7212 | gdb_assert (new_b->related_breakpoint == new_b); | |
7213 | if (retval == NULL) | |
7214 | retval = new_b; | |
7215 | new_b->related_breakpoint = retval; | |
7216 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7217 | retval = retval->related_breakpoint; | |
7218 | retval->related_breakpoint = new_b; | |
7219 | } | |
7220 | ||
7221 | return retval; | |
7222 | } | |
7223 | ||
7224 | /* Verify all existing dummy frames and their associated breakpoints for | |
7225 | THREAD. Remove those which can no longer be found in the current frame | |
7226 | stack. | |
7227 | ||
7228 | You should call this function only at places where it is safe to currently | |
7229 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7230 | frames. */ | |
7231 | ||
7232 | void | |
7233 | check_longjmp_breakpoint_for_call_dummy (int thread) | |
7234 | { | |
7235 | struct breakpoint *b, *b_tmp; | |
7236 | ||
7237 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7238 | if (b->type == bp_longjmp_call_dummy && b->thread == thread) | |
7239 | { | |
7240 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7241 | ||
7242 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7243 | dummy_b = dummy_b->related_breakpoint; | |
7244 | if (dummy_b->type != bp_call_dummy | |
7245 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7246 | continue; | |
7247 | ||
7248 | dummy_frame_discard (dummy_b->frame_id); | |
7249 | ||
7250 | while (b->related_breakpoint != b) | |
7251 | { | |
7252 | if (b_tmp == b->related_breakpoint) | |
7253 | b_tmp = b->related_breakpoint->next; | |
7254 | delete_breakpoint (b->related_breakpoint); | |
7255 | } | |
7256 | delete_breakpoint (b); | |
7257 | } | |
7258 | } | |
7259 | ||
1900040c MS |
7260 | void |
7261 | enable_overlay_breakpoints (void) | |
7262 | { | |
52f0bd74 | 7263 | struct breakpoint *b; |
1900040c MS |
7264 | |
7265 | ALL_BREAKPOINTS (b) | |
7266 | if (b->type == bp_overlay_event) | |
7267 | { | |
7268 | b->enable_state = bp_enabled; | |
b60e7edf | 7269 | update_global_location_list (1); |
c02f5703 | 7270 | overlay_events_enabled = 1; |
1900040c MS |
7271 | } |
7272 | } | |
7273 | ||
7274 | void | |
7275 | disable_overlay_breakpoints (void) | |
7276 | { | |
52f0bd74 | 7277 | struct breakpoint *b; |
1900040c MS |
7278 | |
7279 | ALL_BREAKPOINTS (b) | |
7280 | if (b->type == bp_overlay_event) | |
7281 | { | |
7282 | b->enable_state = bp_disabled; | |
b60e7edf | 7283 | update_global_location_list (0); |
c02f5703 | 7284 | overlay_events_enabled = 0; |
1900040c MS |
7285 | } |
7286 | } | |
7287 | ||
aa7d318d TT |
7288 | /* Set an active std::terminate breakpoint for each std::terminate |
7289 | master breakpoint. */ | |
7290 | void | |
7291 | set_std_terminate_breakpoint (void) | |
7292 | { | |
35df4500 | 7293 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7294 | |
35df4500 | 7295 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7296 | if (b->pspace == current_program_space |
7297 | && b->type == bp_std_terminate_master) | |
7298 | { | |
06edf0c0 PA |
7299 | momentary_breakpoint_from_master (b, bp_std_terminate, |
7300 | &momentary_breakpoint_ops); | |
aa7d318d TT |
7301 | } |
7302 | } | |
7303 | ||
7304 | /* Delete all the std::terminate breakpoints. */ | |
7305 | void | |
7306 | delete_std_terminate_breakpoint (void) | |
7307 | { | |
35df4500 | 7308 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7309 | |
35df4500 | 7310 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7311 | if (b->type == bp_std_terminate) |
7312 | delete_breakpoint (b); | |
7313 | } | |
7314 | ||
c4093a6a | 7315 | struct breakpoint * |
a6d9a66e | 7316 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7317 | { |
7318 | struct breakpoint *b; | |
c4093a6a | 7319 | |
06edf0c0 PA |
7320 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7321 | &internal_breakpoint_ops); | |
7322 | ||
b5de0fa7 | 7323 | b->enable_state = bp_enabled; |
c4093a6a | 7324 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7325 | b->addr_string |
7326 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7327 | |
b60e7edf | 7328 | update_global_location_list_nothrow (1); |
74960c60 | 7329 | |
c4093a6a JM |
7330 | return b; |
7331 | } | |
7332 | ||
7333 | void | |
7334 | remove_thread_event_breakpoints (void) | |
7335 | { | |
35df4500 | 7336 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7337 | |
35df4500 | 7338 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7339 | if (b->type == bp_thread_event |
7340 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7341 | delete_breakpoint (b); |
7342 | } | |
7343 | ||
0101ce28 JJ |
7344 | struct lang_and_radix |
7345 | { | |
7346 | enum language lang; | |
7347 | int radix; | |
7348 | }; | |
7349 | ||
4efc6507 DE |
7350 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7351 | ||
7352 | struct breakpoint * | |
7353 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7354 | { | |
7355 | struct breakpoint *b; | |
7356 | ||
06edf0c0 PA |
7357 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7358 | &internal_breakpoint_ops); | |
4efc6507 DE |
7359 | update_global_location_list_nothrow (1); |
7360 | return b; | |
7361 | } | |
0101ce28 | 7362 | |
03673fc7 PP |
7363 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7364 | ||
7365 | void | |
7366 | remove_jit_event_breakpoints (void) | |
7367 | { | |
7368 | struct breakpoint *b, *b_tmp; | |
7369 | ||
7370 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7371 | if (b->type == bp_jit_event | |
7372 | && b->loc->pspace == current_program_space) | |
7373 | delete_breakpoint (b); | |
7374 | } | |
7375 | ||
cae688ec JJ |
7376 | void |
7377 | remove_solib_event_breakpoints (void) | |
7378 | { | |
35df4500 | 7379 | struct breakpoint *b, *b_tmp; |
cae688ec | 7380 | |
35df4500 | 7381 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7382 | if (b->type == bp_shlib_event |
7383 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7384 | delete_breakpoint (b); |
7385 | } | |
7386 | ||
7387 | struct breakpoint * | |
a6d9a66e | 7388 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
7389 | { |
7390 | struct breakpoint *b; | |
7391 | ||
06edf0c0 PA |
7392 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7393 | &internal_breakpoint_ops); | |
b60e7edf | 7394 | update_global_location_list_nothrow (1); |
cae688ec JJ |
7395 | return b; |
7396 | } | |
7397 | ||
7398 | /* Disable any breakpoints that are on code in shared libraries. Only | |
7399 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7400 | ||
7401 | void | |
cb851954 | 7402 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7403 | { |
876fa593 | 7404 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7405 | |
876fa593 | 7406 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7407 | { |
2bdf28a0 | 7408 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7409 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7410 | |
4a64f543 MS |
7411 | /* We apply the check to all breakpoints, including disabled for |
7412 | those with loc->duplicate set. This is so that when breakpoint | |
7413 | becomes enabled, or the duplicate is removed, gdb will try to | |
7414 | insert all breakpoints. If we don't set shlib_disabled here, | |
7415 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7416 | if (((b->type == bp_breakpoint) |
508ccb1f | 7417 | || (b->type == bp_jit_event) |
1042e4c0 | 7418 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7419 | || (is_tracepoint (b))) |
6c95b8df | 7420 | && loc->pspace == current_program_space |
0d381245 | 7421 | && !loc->shlib_disabled |
a77053c2 | 7422 | #ifdef PC_SOLIB |
0d381245 | 7423 | && PC_SOLIB (loc->address) |
a77053c2 | 7424 | #else |
6c95b8df | 7425 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
7426 | #endif |
7427 | ) | |
0d381245 VP |
7428 | { |
7429 | loc->shlib_disabled = 1; | |
7430 | } | |
cae688ec JJ |
7431 | } |
7432 | } | |
7433 | ||
1e4d1764 YQ |
7434 | /* Disable any breakpoints and tracepoints that are in an unloaded shared |
7435 | library. Only apply to enabled breakpoints, disabled ones can just stay | |
4a64f543 | 7436 | disabled. */ |
84acb35a | 7437 | |
75149521 | 7438 | static void |
84acb35a JJ |
7439 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7440 | { | |
876fa593 | 7441 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7442 | int disabled_shlib_breaks = 0; |
7443 | ||
c86cf029 VP |
7444 | /* SunOS a.out shared libraries are always mapped, so do not |
7445 | disable breakpoints; they will only be reported as unloaded | |
7446 | through clear_solib when GDB discards its shared library | |
7447 | list. See clear_solib for more information. */ | |
7448 | if (exec_bfd != NULL | |
7449 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7450 | return; | |
7451 | ||
876fa593 | 7452 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7453 | { |
2bdf28a0 | 7454 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7455 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7456 | |
1e4d1764 | 7457 | if (solib->pspace == loc->pspace |
e2dd7057 | 7458 | && !loc->shlib_disabled |
1e4d1764 YQ |
7459 | && (((b->type == bp_breakpoint |
7460 | || b->type == bp_jit_event | |
7461 | || b->type == bp_hardware_breakpoint) | |
7462 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7463 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7464 | || is_tracepoint (b)) | |
e2dd7057 | 7465 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7466 | { |
e2dd7057 PP |
7467 | loc->shlib_disabled = 1; |
7468 | /* At this point, we cannot rely on remove_breakpoint | |
7469 | succeeding so we must mark the breakpoint as not inserted | |
7470 | to prevent future errors occurring in remove_breakpoints. */ | |
7471 | loc->inserted = 0; | |
8d3788bd VP |
7472 | |
7473 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7474 | observer_notify_breakpoint_modified (b); | |
7475 | ||
e2dd7057 PP |
7476 | if (!disabled_shlib_breaks) |
7477 | { | |
7478 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7479 | warning (_("Temporarily disabling breakpoints " |
7480 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7481 | solib->so_name); |
84acb35a | 7482 | } |
e2dd7057 | 7483 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7484 | } |
7485 | } | |
84acb35a JJ |
7486 | } |
7487 | ||
ce78b96d JB |
7488 | /* FORK & VFORK catchpoints. */ |
7489 | ||
e29a4733 PA |
7490 | /* An instance of this type is used to represent a fork or vfork |
7491 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7492 | class; users downcast to "struct breakpoint *" when needed. A | |
7493 | breakpoint is really of this type iff its ops pointer points to | |
7494 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7495 | ||
7496 | struct fork_catchpoint | |
7497 | { | |
7498 | /* The base class. */ | |
7499 | struct breakpoint base; | |
7500 | ||
7501 | /* Process id of a child process whose forking triggered this | |
7502 | catchpoint. This field is only valid immediately after this | |
7503 | catchpoint has triggered. */ | |
7504 | ptid_t forked_inferior_pid; | |
7505 | }; | |
7506 | ||
4a64f543 MS |
7507 | /* Implement the "insert" breakpoint_ops method for fork |
7508 | catchpoints. */ | |
ce78b96d | 7509 | |
77b06cd7 TJB |
7510 | static int |
7511 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7512 | { |
77b06cd7 | 7513 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
7514 | } |
7515 | ||
4a64f543 MS |
7516 | /* Implement the "remove" breakpoint_ops method for fork |
7517 | catchpoints. */ | |
ce78b96d JB |
7518 | |
7519 | static int | |
77b06cd7 | 7520 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
7521 | { |
7522 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
7523 | } | |
7524 | ||
7525 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7526 | catchpoints. */ | |
7527 | ||
7528 | static int | |
f1310107 | 7529 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7530 | struct address_space *aspace, CORE_ADDR bp_addr, |
7531 | const struct target_waitstatus *ws) | |
ce78b96d | 7532 | { |
e29a4733 PA |
7533 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7534 | ||
f90263c1 TT |
7535 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7536 | return 0; | |
7537 | ||
7538 | c->forked_inferior_pid = ws->value.related_pid; | |
7539 | return 1; | |
ce78b96d JB |
7540 | } |
7541 | ||
4a64f543 MS |
7542 | /* Implement the "print_it" breakpoint_ops method for fork |
7543 | catchpoints. */ | |
ce78b96d JB |
7544 | |
7545 | static enum print_stop_action | |
348d480f | 7546 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7547 | { |
36dfb11c | 7548 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7549 | struct breakpoint *b = bs->breakpoint_at; |
7550 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7551 | |
ce78b96d | 7552 | annotate_catchpoint (b->number); |
36dfb11c TT |
7553 | if (b->disposition == disp_del) |
7554 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7555 | else | |
7556 | ui_out_text (uiout, "\nCatchpoint "); | |
7557 | if (ui_out_is_mi_like_p (uiout)) | |
7558 | { | |
7559 | ui_out_field_string (uiout, "reason", | |
7560 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7561 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7562 | } | |
7563 | ui_out_field_int (uiout, "bkptno", b->number); | |
7564 | ui_out_text (uiout, " (forked process "); | |
7565 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7566 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7567 | return PRINT_SRC_AND_LOC; |
7568 | } | |
7569 | ||
4a64f543 MS |
7570 | /* Implement the "print_one" breakpoint_ops method for fork |
7571 | catchpoints. */ | |
ce78b96d JB |
7572 | |
7573 | static void | |
a6d9a66e | 7574 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7575 | { |
e29a4733 | 7576 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7577 | struct value_print_options opts; |
79a45e25 | 7578 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7579 | |
7580 | get_user_print_options (&opts); | |
7581 | ||
4a64f543 MS |
7582 | /* Field 4, the address, is omitted (which makes the columns not |
7583 | line up too nicely with the headers, but the effect is relatively | |
7584 | readable). */ | |
79a45b7d | 7585 | if (opts.addressprint) |
ce78b96d JB |
7586 | ui_out_field_skip (uiout, "addr"); |
7587 | annotate_field (5); | |
7588 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7589 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7590 | { |
7591 | ui_out_text (uiout, ", process "); | |
7592 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7593 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7594 | ui_out_spaces (uiout, 1); |
7595 | } | |
8ac3646f TT |
7596 | |
7597 | if (ui_out_is_mi_like_p (uiout)) | |
7598 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
7599 | } |
7600 | ||
7601 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7602 | catchpoints. */ | |
7603 | ||
7604 | static void | |
7605 | print_mention_catch_fork (struct breakpoint *b) | |
7606 | { | |
7607 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7608 | } | |
7609 | ||
6149aea9 PA |
7610 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7611 | catchpoints. */ | |
7612 | ||
7613 | static void | |
7614 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7615 | { | |
7616 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7617 | print_recreate_thread (b, fp); |
6149aea9 PA |
7618 | } |
7619 | ||
ce78b96d JB |
7620 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7621 | ||
2060206e | 7622 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7623 | |
4a64f543 MS |
7624 | /* Implement the "insert" breakpoint_ops method for vfork |
7625 | catchpoints. */ | |
ce78b96d | 7626 | |
77b06cd7 TJB |
7627 | static int |
7628 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7629 | { |
77b06cd7 | 7630 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
7631 | } |
7632 | ||
4a64f543 MS |
7633 | /* Implement the "remove" breakpoint_ops method for vfork |
7634 | catchpoints. */ | |
ce78b96d JB |
7635 | |
7636 | static int | |
77b06cd7 | 7637 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
7638 | { |
7639 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
7640 | } | |
7641 | ||
7642 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7643 | catchpoints. */ | |
7644 | ||
7645 | static int | |
f1310107 | 7646 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7647 | struct address_space *aspace, CORE_ADDR bp_addr, |
7648 | const struct target_waitstatus *ws) | |
ce78b96d | 7649 | { |
e29a4733 PA |
7650 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7651 | ||
f90263c1 TT |
7652 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7653 | return 0; | |
7654 | ||
7655 | c->forked_inferior_pid = ws->value.related_pid; | |
7656 | return 1; | |
ce78b96d JB |
7657 | } |
7658 | ||
4a64f543 MS |
7659 | /* Implement the "print_it" breakpoint_ops method for vfork |
7660 | catchpoints. */ | |
ce78b96d JB |
7661 | |
7662 | static enum print_stop_action | |
348d480f | 7663 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7664 | { |
36dfb11c | 7665 | struct ui_out *uiout = current_uiout; |
348d480f | 7666 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7667 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7668 | ||
ce78b96d | 7669 | annotate_catchpoint (b->number); |
36dfb11c TT |
7670 | if (b->disposition == disp_del) |
7671 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7672 | else | |
7673 | ui_out_text (uiout, "\nCatchpoint "); | |
7674 | if (ui_out_is_mi_like_p (uiout)) | |
7675 | { | |
7676 | ui_out_field_string (uiout, "reason", | |
7677 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7678 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7679 | } | |
7680 | ui_out_field_int (uiout, "bkptno", b->number); | |
7681 | ui_out_text (uiout, " (vforked process "); | |
7682 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7683 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7684 | return PRINT_SRC_AND_LOC; |
7685 | } | |
7686 | ||
4a64f543 MS |
7687 | /* Implement the "print_one" breakpoint_ops method for vfork |
7688 | catchpoints. */ | |
ce78b96d JB |
7689 | |
7690 | static void | |
a6d9a66e | 7691 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7692 | { |
e29a4733 | 7693 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7694 | struct value_print_options opts; |
79a45e25 | 7695 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7696 | |
7697 | get_user_print_options (&opts); | |
4a64f543 MS |
7698 | /* Field 4, the address, is omitted (which makes the columns not |
7699 | line up too nicely with the headers, but the effect is relatively | |
7700 | readable). */ | |
79a45b7d | 7701 | if (opts.addressprint) |
ce78b96d JB |
7702 | ui_out_field_skip (uiout, "addr"); |
7703 | annotate_field (5); | |
7704 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7705 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7706 | { |
7707 | ui_out_text (uiout, ", process "); | |
7708 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7709 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7710 | ui_out_spaces (uiout, 1); |
7711 | } | |
8ac3646f TT |
7712 | |
7713 | if (ui_out_is_mi_like_p (uiout)) | |
7714 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
7715 | } |
7716 | ||
7717 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7718 | catchpoints. */ | |
7719 | ||
7720 | static void | |
7721 | print_mention_catch_vfork (struct breakpoint *b) | |
7722 | { | |
7723 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7724 | } | |
7725 | ||
6149aea9 PA |
7726 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7727 | catchpoints. */ | |
7728 | ||
7729 | static void | |
7730 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7731 | { | |
7732 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7733 | print_recreate_thread (b, fp); |
6149aea9 PA |
7734 | } |
7735 | ||
ce78b96d JB |
7736 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7737 | ||
2060206e | 7738 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7739 | |
edcc5120 TT |
7740 | /* An instance of this type is used to represent an solib catchpoint. |
7741 | It includes a "struct breakpoint" as a kind of base class; users | |
7742 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7743 | really of this type iff its ops pointer points to | |
7744 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7745 | ||
7746 | struct solib_catchpoint | |
7747 | { | |
7748 | /* The base class. */ | |
7749 | struct breakpoint base; | |
7750 | ||
7751 | /* True for "catch load", false for "catch unload". */ | |
7752 | unsigned char is_load; | |
7753 | ||
7754 | /* Regular expression to match, if any. COMPILED is only valid when | |
7755 | REGEX is non-NULL. */ | |
7756 | char *regex; | |
7757 | regex_t compiled; | |
7758 | }; | |
7759 | ||
7760 | static void | |
7761 | dtor_catch_solib (struct breakpoint *b) | |
7762 | { | |
7763 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7764 | ||
7765 | if (self->regex) | |
7766 | regfree (&self->compiled); | |
7767 | xfree (self->regex); | |
7768 | ||
7769 | base_breakpoint_ops.dtor (b); | |
7770 | } | |
7771 | ||
7772 | static int | |
7773 | insert_catch_solib (struct bp_location *ignore) | |
7774 | { | |
7775 | return 0; | |
7776 | } | |
7777 | ||
7778 | static int | |
7779 | remove_catch_solib (struct bp_location *ignore) | |
7780 | { | |
7781 | return 0; | |
7782 | } | |
7783 | ||
7784 | static int | |
7785 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
7786 | struct address_space *aspace, | |
7787 | CORE_ADDR bp_addr, | |
7788 | const struct target_waitstatus *ws) | |
7789 | { | |
7790 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7791 | struct breakpoint *other; | |
7792 | ||
7793 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7794 | return 1; | |
7795 | ||
7796 | ALL_BREAKPOINTS (other) | |
7797 | { | |
7798 | struct bp_location *other_bl; | |
7799 | ||
7800 | if (other == bl->owner) | |
7801 | continue; | |
7802 | ||
7803 | if (other->type != bp_shlib_event) | |
7804 | continue; | |
7805 | ||
7806 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
7807 | continue; | |
7808 | ||
7809 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7810 | { | |
7811 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7812 | return 1; | |
7813 | } | |
7814 | } | |
7815 | ||
7816 | return 0; | |
7817 | } | |
7818 | ||
7819 | static void | |
7820 | check_status_catch_solib (struct bpstats *bs) | |
7821 | { | |
7822 | struct solib_catchpoint *self | |
7823 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
7824 | int ix; | |
7825 | ||
7826 | if (self->is_load) | |
7827 | { | |
7828 | struct so_list *iter; | |
7829 | ||
7830 | for (ix = 0; | |
7831 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
7832 | ix, iter); | |
7833 | ++ix) | |
7834 | { | |
7835 | if (!self->regex | |
7836 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
7837 | return; | |
7838 | } | |
7839 | } | |
7840 | else | |
7841 | { | |
7842 | char *iter; | |
7843 | ||
7844 | for (ix = 0; | |
7845 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
7846 | ix, iter); | |
7847 | ++ix) | |
7848 | { | |
7849 | if (!self->regex | |
7850 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
7851 | return; | |
7852 | } | |
7853 | } | |
7854 | ||
7855 | bs->stop = 0; | |
7856 | bs->print_it = print_it_noop; | |
7857 | } | |
7858 | ||
7859 | static enum print_stop_action | |
7860 | print_it_catch_solib (bpstat bs) | |
7861 | { | |
7862 | struct breakpoint *b = bs->breakpoint_at; | |
7863 | struct ui_out *uiout = current_uiout; | |
7864 | ||
7865 | annotate_catchpoint (b->number); | |
7866 | if (b->disposition == disp_del) | |
7867 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7868 | else | |
7869 | ui_out_text (uiout, "\nCatchpoint "); | |
7870 | ui_out_field_int (uiout, "bkptno", b->number); | |
7871 | ui_out_text (uiout, "\n"); | |
7872 | if (ui_out_is_mi_like_p (uiout)) | |
7873 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7874 | print_solib_event (1); | |
7875 | return PRINT_SRC_AND_LOC; | |
7876 | } | |
7877 | ||
7878 | static void | |
7879 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7880 | { | |
7881 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7882 | struct value_print_options opts; | |
7883 | struct ui_out *uiout = current_uiout; | |
7884 | char *msg; | |
7885 | ||
7886 | get_user_print_options (&opts); | |
7887 | /* Field 4, the address, is omitted (which makes the columns not | |
7888 | line up too nicely with the headers, but the effect is relatively | |
7889 | readable). */ | |
7890 | if (opts.addressprint) | |
7891 | { | |
7892 | annotate_field (4); | |
7893 | ui_out_field_skip (uiout, "addr"); | |
7894 | } | |
7895 | ||
7896 | annotate_field (5); | |
7897 | if (self->is_load) | |
7898 | { | |
7899 | if (self->regex) | |
7900 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
7901 | else | |
7902 | msg = xstrdup (_("load of library")); | |
7903 | } | |
7904 | else | |
7905 | { | |
7906 | if (self->regex) | |
7907 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
7908 | else | |
7909 | msg = xstrdup (_("unload of library")); | |
7910 | } | |
7911 | ui_out_field_string (uiout, "what", msg); | |
7912 | xfree (msg); | |
8ac3646f TT |
7913 | |
7914 | if (ui_out_is_mi_like_p (uiout)) | |
7915 | ui_out_field_string (uiout, "catch-type", | |
7916 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
7917 | } |
7918 | ||
7919 | static void | |
7920 | print_mention_catch_solib (struct breakpoint *b) | |
7921 | { | |
7922 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7923 | ||
7924 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
7925 | self->is_load ? "load" : "unload"); | |
7926 | } | |
7927 | ||
7928 | static void | |
7929 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
7930 | { | |
7931 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7932 | ||
7933 | fprintf_unfiltered (fp, "%s %s", | |
7934 | b->disposition == disp_del ? "tcatch" : "catch", | |
7935 | self->is_load ? "load" : "unload"); | |
7936 | if (self->regex) | |
7937 | fprintf_unfiltered (fp, " %s", self->regex); | |
7938 | fprintf_unfiltered (fp, "\n"); | |
7939 | } | |
7940 | ||
7941 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
7942 | ||
91985142 MG |
7943 | /* Shared helper function (MI and CLI) for creating and installing |
7944 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
7945 | the events to be caught are load events, otherwise they are | |
7946 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
7947 | temporary one. If ENABLED is non-zero the catchpoint is | |
7948 | created in an enabled state. */ | |
edcc5120 | 7949 | |
91985142 MG |
7950 | void |
7951 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
7952 | { |
7953 | struct solib_catchpoint *c; | |
7954 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
7955 | struct cleanup *cleanup; |
7956 | ||
edcc5120 TT |
7957 | if (!arg) |
7958 | arg = ""; | |
7959 | arg = skip_spaces (arg); | |
7960 | ||
7961 | c = XCNEW (struct solib_catchpoint); | |
7962 | cleanup = make_cleanup (xfree, c); | |
7963 | ||
7964 | if (*arg != '\0') | |
7965 | { | |
7966 | int errcode; | |
7967 | ||
7968 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
7969 | if (errcode != 0) | |
7970 | { | |
7971 | char *err = get_regcomp_error (errcode, &c->compiled); | |
7972 | ||
7973 | make_cleanup (xfree, err); | |
7974 | error (_("Invalid regexp (%s): %s"), err, arg); | |
7975 | } | |
7976 | c->regex = xstrdup (arg); | |
7977 | } | |
7978 | ||
7979 | c->is_load = is_load; | |
91985142 | 7980 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
7981 | &catch_solib_breakpoint_ops); |
7982 | ||
91985142 MG |
7983 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
7984 | ||
edcc5120 TT |
7985 | discard_cleanups (cleanup); |
7986 | install_breakpoint (0, &c->base, 1); | |
7987 | } | |
7988 | ||
91985142 MG |
7989 | /* A helper function that does all the work for "catch load" and |
7990 | "catch unload". */ | |
7991 | ||
7992 | static void | |
7993 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
7994 | struct cmd_list_element *command) | |
7995 | { | |
7996 | int tempflag; | |
7997 | const int enabled = 1; | |
7998 | ||
7999 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8000 | ||
8001 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8002 | } | |
8003 | ||
edcc5120 TT |
8004 | static void |
8005 | catch_load_command_1 (char *arg, int from_tty, | |
8006 | struct cmd_list_element *command) | |
8007 | { | |
8008 | catch_load_or_unload (arg, from_tty, 1, command); | |
8009 | } | |
8010 | ||
8011 | static void | |
8012 | catch_unload_command_1 (char *arg, int from_tty, | |
8013 | struct cmd_list_element *command) | |
8014 | { | |
8015 | catch_load_or_unload (arg, from_tty, 0, command); | |
8016 | } | |
8017 | ||
be5c67c1 PA |
8018 | /* An instance of this type is used to represent a syscall catchpoint. |
8019 | It includes a "struct breakpoint" as a kind of base class; users | |
8020 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8021 | really of this type iff its ops pointer points to | |
8022 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8023 | ||
8024 | struct syscall_catchpoint | |
8025 | { | |
8026 | /* The base class. */ | |
8027 | struct breakpoint base; | |
8028 | ||
8029 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8030 | syscall has been specified for filtering, its value is NULL. | |
8031 | Otherwise, it holds a list of all syscalls to be caught. The | |
8032 | list elements are allocated with xmalloc. */ | |
8033 | VEC(int) *syscalls_to_be_caught; | |
8034 | }; | |
8035 | ||
8036 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8037 | catchpoints. */ | |
8038 | ||
8039 | static void | |
8040 | dtor_catch_syscall (struct breakpoint *b) | |
8041 | { | |
8042 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8043 | ||
8044 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8045 | |
2060206e | 8046 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8047 | } |
8048 | ||
fa3064dd YQ |
8049 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8050 | ||
8051 | struct catch_syscall_inferior_data | |
8052 | { | |
8053 | /* We keep a count of the number of times the user has requested a | |
8054 | particular syscall to be tracked, and pass this information to the | |
8055 | target. This lets capable targets implement filtering directly. */ | |
8056 | ||
8057 | /* Number of times that "any" syscall is requested. */ | |
8058 | int any_syscall_count; | |
8059 | ||
8060 | /* Count of each system call. */ | |
8061 | VEC(int) *syscalls_counts; | |
8062 | ||
8063 | /* This counts all syscall catch requests, so we can readily determine | |
8064 | if any catching is necessary. */ | |
8065 | int total_syscalls_count; | |
8066 | }; | |
8067 | ||
8068 | static struct catch_syscall_inferior_data* | |
8069 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8070 | { | |
8071 | struct catch_syscall_inferior_data *inf_data; | |
8072 | ||
8073 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8074 | if (inf_data == NULL) | |
8075 | { | |
8076 | inf_data = XZALLOC (struct catch_syscall_inferior_data); | |
8077 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); | |
8078 | } | |
8079 | ||
8080 | return inf_data; | |
8081 | } | |
8082 | ||
8083 | static void | |
8084 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8085 | { | |
8086 | xfree (arg); | |
8087 | } | |
8088 | ||
8089 | ||
a96d9b2e SDJ |
8090 | /* Implement the "insert" breakpoint_ops method for syscall |
8091 | catchpoints. */ | |
8092 | ||
77b06cd7 TJB |
8093 | static int |
8094 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8095 | { |
be5c67c1 | 8096 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8097 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8098 | struct catch_syscall_inferior_data *inf_data |
8099 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8100 | |
fa3064dd | 8101 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8102 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8103 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8104 | else |
8105 | { | |
8106 | int i, iter; | |
cc59ec59 | 8107 | |
a96d9b2e | 8108 | for (i = 0; |
be5c67c1 | 8109 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8110 | i++) |
8111 | { | |
8112 | int elem; | |
cc59ec59 | 8113 | |
fa3064dd | 8114 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8115 | { |
fa3064dd | 8116 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8117 | uintptr_t vec_addr_offset |
8118 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8119 | uintptr_t vec_addr; |
fa3064dd YQ |
8120 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8121 | vec_addr = ((uintptr_t) VEC_address (int, | |
8122 | inf_data->syscalls_counts) | |
8123 | + vec_addr_offset); | |
a96d9b2e SDJ |
8124 | memset ((void *) vec_addr, 0, |
8125 | (iter + 1 - old_size) * sizeof (int)); | |
8126 | } | |
fa3064dd YQ |
8127 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8128 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8129 | } |
8130 | } | |
8131 | ||
77b06cd7 | 8132 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
fa3064dd YQ |
8133 | inf_data->total_syscalls_count != 0, |
8134 | inf_data->any_syscall_count, | |
8135 | VEC_length (int, | |
8136 | inf_data->syscalls_counts), | |
8137 | VEC_address (int, | |
8138 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8139 | } |
8140 | ||
8141 | /* Implement the "remove" breakpoint_ops method for syscall | |
8142 | catchpoints. */ | |
8143 | ||
8144 | static int | |
77b06cd7 | 8145 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8146 | { |
be5c67c1 | 8147 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8148 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8149 | struct catch_syscall_inferior_data *inf_data |
8150 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8151 | |
fa3064dd | 8152 | --inf_data->total_syscalls_count; |
be5c67c1 | 8153 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8154 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8155 | else |
8156 | { | |
8157 | int i, iter; | |
cc59ec59 | 8158 | |
a96d9b2e | 8159 | for (i = 0; |
be5c67c1 | 8160 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8161 | i++) |
8162 | { | |
8163 | int elem; | |
fa3064dd | 8164 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8165 | /* Shouldn't happen. */ |
8166 | continue; | |
fa3064dd YQ |
8167 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8168 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8169 | } |
8170 | } | |
8171 | ||
8172 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
fa3064dd YQ |
8173 | inf_data->total_syscalls_count != 0, |
8174 | inf_data->any_syscall_count, | |
8175 | VEC_length (int, | |
8176 | inf_data->syscalls_counts), | |
3e43a32a | 8177 | VEC_address (int, |
fa3064dd | 8178 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8179 | } |
8180 | ||
8181 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8182 | catchpoints. */ | |
8183 | ||
8184 | static int | |
f1310107 | 8185 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8186 | struct address_space *aspace, CORE_ADDR bp_addr, |
8187 | const struct target_waitstatus *ws) | |
a96d9b2e | 8188 | { |
4a64f543 MS |
8189 | /* We must check if we are catching specific syscalls in this |
8190 | breakpoint. If we are, then we must guarantee that the called | |
8191 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8192 | int syscall_number = 0; |
be5c67c1 PA |
8193 | const struct syscall_catchpoint *c |
8194 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8195 | |
f90263c1 TT |
8196 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8197 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8198 | return 0; |
8199 | ||
f90263c1 TT |
8200 | syscall_number = ws->value.syscall_number; |
8201 | ||
a96d9b2e | 8202 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8203 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8204 | { |
8205 | int i, iter; | |
cc59ec59 | 8206 | |
a96d9b2e | 8207 | for (i = 0; |
be5c67c1 | 8208 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8209 | i++) |
8210 | if (syscall_number == iter) | |
8211 | break; | |
8212 | /* Not the same. */ | |
8213 | if (!iter) | |
8214 | return 0; | |
8215 | } | |
8216 | ||
8217 | return 1; | |
8218 | } | |
8219 | ||
8220 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8221 | catchpoints. */ | |
8222 | ||
8223 | static enum print_stop_action | |
348d480f | 8224 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8225 | { |
36dfb11c | 8226 | struct ui_out *uiout = current_uiout; |
348d480f | 8227 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8228 | /* These are needed because we want to know in which state a |
8229 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8230 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8231 | must print "called syscall" or "returned from syscall". */ | |
8232 | ptid_t ptid; | |
8233 | struct target_waitstatus last; | |
8234 | struct syscall s; | |
a96d9b2e SDJ |
8235 | |
8236 | get_last_target_status (&ptid, &last); | |
8237 | ||
8238 | get_syscall_by_number (last.value.syscall_number, &s); | |
8239 | ||
8240 | annotate_catchpoint (b->number); | |
8241 | ||
36dfb11c TT |
8242 | if (b->disposition == disp_del) |
8243 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8244 | else |
36dfb11c TT |
8245 | ui_out_text (uiout, "\nCatchpoint "); |
8246 | if (ui_out_is_mi_like_p (uiout)) | |
8247 | { | |
8248 | ui_out_field_string (uiout, "reason", | |
8249 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8250 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8251 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8252 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8253 | } | |
8254 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8255 | |
8256 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8257 | ui_out_text (uiout, " (call to syscall "); |
8258 | else | |
8259 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8260 | |
36dfb11c TT |
8261 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8262 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8263 | if (s.name != NULL) | |
8264 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8265 | ||
8266 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8267 | |
8268 | return PRINT_SRC_AND_LOC; | |
8269 | } | |
8270 | ||
8271 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8272 | catchpoints. */ | |
8273 | ||
8274 | static void | |
8275 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8276 | struct bp_location **last_loc) |
a96d9b2e | 8277 | { |
be5c67c1 | 8278 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8279 | struct value_print_options opts; |
79a45e25 | 8280 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
8281 | |
8282 | get_user_print_options (&opts); | |
4a64f543 MS |
8283 | /* Field 4, the address, is omitted (which makes the columns not |
8284 | line up too nicely with the headers, but the effect is relatively | |
8285 | readable). */ | |
a96d9b2e SDJ |
8286 | if (opts.addressprint) |
8287 | ui_out_field_skip (uiout, "addr"); | |
8288 | annotate_field (5); | |
8289 | ||
be5c67c1 PA |
8290 | if (c->syscalls_to_be_caught |
8291 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8292 | ui_out_text (uiout, "syscalls \""); |
8293 | else | |
8294 | ui_out_text (uiout, "syscall \""); | |
8295 | ||
be5c67c1 | 8296 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8297 | { |
8298 | int i, iter; | |
8299 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8300 | |
a96d9b2e | 8301 | for (i = 0; |
be5c67c1 | 8302 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8303 | i++) |
8304 | { | |
8305 | char *x = text; | |
8306 | struct syscall s; | |
8307 | get_syscall_by_number (iter, &s); | |
8308 | ||
8309 | if (s.name != NULL) | |
8310 | text = xstrprintf ("%s%s, ", text, s.name); | |
8311 | else | |
8312 | text = xstrprintf ("%s%d, ", text, iter); | |
8313 | ||
8314 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8315 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8316 | on every call. */ |
8317 | xfree (x); | |
8318 | } | |
8319 | /* Remove the last comma. */ | |
8320 | text[strlen (text) - 2] = '\0'; | |
8321 | ui_out_field_string (uiout, "what", text); | |
8322 | } | |
8323 | else | |
8324 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8325 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8326 | |
8327 | if (ui_out_is_mi_like_p (uiout)) | |
8328 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8329 | } |
8330 | ||
8331 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8332 | catchpoints. */ | |
8333 | ||
8334 | static void | |
8335 | print_mention_catch_syscall (struct breakpoint *b) | |
8336 | { | |
be5c67c1 PA |
8337 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8338 | ||
8339 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8340 | { |
8341 | int i, iter; | |
8342 | ||
be5c67c1 | 8343 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8344 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8345 | else | |
8346 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8347 | ||
8348 | for (i = 0; | |
be5c67c1 | 8349 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8350 | i++) |
8351 | { | |
8352 | struct syscall s; | |
8353 | get_syscall_by_number (iter, &s); | |
8354 | ||
8355 | if (s.name) | |
8356 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8357 | else | |
8358 | printf_filtered (" %d", s.number); | |
8359 | } | |
8360 | printf_filtered (")"); | |
8361 | } | |
8362 | else | |
8363 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8364 | b->number); | |
8365 | } | |
8366 | ||
6149aea9 PA |
8367 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8368 | catchpoints. */ | |
8369 | ||
8370 | static void | |
8371 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8372 | { | |
be5c67c1 PA |
8373 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8374 | ||
6149aea9 PA |
8375 | fprintf_unfiltered (fp, "catch syscall"); |
8376 | ||
be5c67c1 | 8377 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8378 | { |
8379 | int i, iter; | |
8380 | ||
8381 | for (i = 0; | |
be5c67c1 | 8382 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8383 | i++) |
8384 | { | |
8385 | struct syscall s; | |
8386 | ||
8387 | get_syscall_by_number (iter, &s); | |
8388 | if (s.name) | |
8389 | fprintf_unfiltered (fp, " %s", s.name); | |
8390 | else | |
8391 | fprintf_unfiltered (fp, " %d", s.number); | |
8392 | } | |
8393 | } | |
d9b3f62e | 8394 | print_recreate_thread (b, fp); |
6149aea9 PA |
8395 | } |
8396 | ||
a96d9b2e SDJ |
8397 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8398 | ||
2060206e | 8399 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8400 | |
8401 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8402 | ||
8403 | static int | |
8404 | syscall_catchpoint_p (struct breakpoint *b) | |
8405 | { | |
8406 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8407 | } | |
8408 | ||
346774a9 PA |
8409 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8410 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8411 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8412 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8413 | |
ab04a2af | 8414 | void |
346774a9 PA |
8415 | init_catchpoint (struct breakpoint *b, |
8416 | struct gdbarch *gdbarch, int tempflag, | |
8417 | char *cond_string, | |
c0a91b2b | 8418 | const struct breakpoint_ops *ops) |
c906108c | 8419 | { |
c5aa993b | 8420 | struct symtab_and_line sal; |
346774a9 | 8421 | |
fe39c653 | 8422 | init_sal (&sal); |
6c95b8df | 8423 | sal.pspace = current_program_space; |
c5aa993b | 8424 | |
28010a5d | 8425 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8426 | |
1b36a34b | 8427 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8428 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8429 | } |
8430 | ||
28010a5d | 8431 | void |
3ea46bff | 8432 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8433 | { |
8434 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8435 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8436 | if (is_tracepoint (b)) |
8437 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8438 | if (!internal) |
8439 | mention (b); | |
c56053d2 | 8440 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8441 | |
8442 | if (update_gll) | |
8443 | update_global_location_list (1); | |
c56053d2 PA |
8444 | } |
8445 | ||
9b70b993 | 8446 | static void |
a6d9a66e UW |
8447 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8448 | int tempflag, char *cond_string, | |
c0a91b2b | 8449 | const struct breakpoint_ops *ops) |
c906108c | 8450 | { |
e29a4733 | 8451 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8452 | |
e29a4733 PA |
8453 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8454 | ||
8455 | c->forked_inferior_pid = null_ptid; | |
8456 | ||
3ea46bff | 8457 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8458 | } |
8459 | ||
fe798b75 JB |
8460 | /* Exec catchpoints. */ |
8461 | ||
b4d90040 PA |
8462 | /* An instance of this type is used to represent an exec catchpoint. |
8463 | It includes a "struct breakpoint" as a kind of base class; users | |
8464 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8465 | really of this type iff its ops pointer points to | |
8466 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8467 | ||
8468 | struct exec_catchpoint | |
8469 | { | |
8470 | /* The base class. */ | |
8471 | struct breakpoint base; | |
8472 | ||
8473 | /* Filename of a program whose exec triggered this catchpoint. | |
8474 | This field is only valid immediately after this catchpoint has | |
8475 | triggered. */ | |
8476 | char *exec_pathname; | |
8477 | }; | |
8478 | ||
8479 | /* Implement the "dtor" breakpoint_ops method for exec | |
8480 | catchpoints. */ | |
8481 | ||
8482 | static void | |
8483 | dtor_catch_exec (struct breakpoint *b) | |
8484 | { | |
8485 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8486 | ||
8487 | xfree (c->exec_pathname); | |
348d480f | 8488 | |
2060206e | 8489 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8490 | } |
8491 | ||
77b06cd7 TJB |
8492 | static int |
8493 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8494 | { |
77b06cd7 | 8495 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 8496 | } |
c906108c | 8497 | |
fe798b75 | 8498 | static int |
77b06cd7 | 8499 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
8500 | { |
8501 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
8502 | } | |
c906108c | 8503 | |
fe798b75 | 8504 | static int |
f1310107 | 8505 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8506 | struct address_space *aspace, CORE_ADDR bp_addr, |
8507 | const struct target_waitstatus *ws) | |
fe798b75 | 8508 | { |
b4d90040 PA |
8509 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8510 | ||
f90263c1 TT |
8511 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8512 | return 0; | |
8513 | ||
8514 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8515 | return 1; | |
fe798b75 | 8516 | } |
c906108c | 8517 | |
fe798b75 | 8518 | static enum print_stop_action |
348d480f | 8519 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8520 | { |
36dfb11c | 8521 | struct ui_out *uiout = current_uiout; |
348d480f | 8522 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8523 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8524 | ||
fe798b75 | 8525 | annotate_catchpoint (b->number); |
36dfb11c TT |
8526 | if (b->disposition == disp_del) |
8527 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8528 | else | |
8529 | ui_out_text (uiout, "\nCatchpoint "); | |
8530 | if (ui_out_is_mi_like_p (uiout)) | |
8531 | { | |
8532 | ui_out_field_string (uiout, "reason", | |
8533 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8534 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8535 | } | |
8536 | ui_out_field_int (uiout, "bkptno", b->number); | |
8537 | ui_out_text (uiout, " (exec'd "); | |
8538 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8539 | ui_out_text (uiout, "), "); | |
8540 | ||
fe798b75 | 8541 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8542 | } |
8543 | ||
fe798b75 | 8544 | static void |
a6d9a66e | 8545 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8546 | { |
b4d90040 | 8547 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8548 | struct value_print_options opts; |
79a45e25 | 8549 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8550 | |
8551 | get_user_print_options (&opts); | |
8552 | ||
8553 | /* Field 4, the address, is omitted (which makes the columns | |
8554 | not line up too nicely with the headers, but the effect | |
8555 | is relatively readable). */ | |
8556 | if (opts.addressprint) | |
8557 | ui_out_field_skip (uiout, "addr"); | |
8558 | annotate_field (5); | |
8559 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8560 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8561 | { |
8562 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8563 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8564 | ui_out_text (uiout, "\" "); |
8565 | } | |
8ac3646f TT |
8566 | |
8567 | if (ui_out_is_mi_like_p (uiout)) | |
8568 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8569 | } |
8570 | ||
8571 | static void | |
8572 | print_mention_catch_exec (struct breakpoint *b) | |
8573 | { | |
8574 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8575 | } | |
8576 | ||
6149aea9 PA |
8577 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8578 | catchpoints. */ | |
8579 | ||
8580 | static void | |
8581 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8582 | { | |
8583 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8584 | print_recreate_thread (b, fp); |
6149aea9 PA |
8585 | } |
8586 | ||
2060206e | 8587 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8588 | |
a96d9b2e SDJ |
8589 | static void |
8590 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 8591 | const struct breakpoint_ops *ops) |
a96d9b2e | 8592 | { |
be5c67c1 | 8593 | struct syscall_catchpoint *c; |
a96d9b2e | 8594 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 8595 | |
be5c67c1 PA |
8596 | c = XNEW (struct syscall_catchpoint); |
8597 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
8598 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 8599 | |
3ea46bff | 8600 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
8601 | } |
8602 | ||
c906108c | 8603 | static int |
fba45db2 | 8604 | hw_breakpoint_used_count (void) |
c906108c | 8605 | { |
c906108c | 8606 | int i = 0; |
f1310107 TJB |
8607 | struct breakpoint *b; |
8608 | struct bp_location *bl; | |
c906108c SS |
8609 | |
8610 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8611 | { |
d6b74ac4 | 8612 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8613 | for (bl = b->loc; bl; bl = bl->next) |
8614 | { | |
8615 | /* Special types of hardware breakpoints may use more than | |
8616 | one register. */ | |
348d480f | 8617 | i += b->ops->resources_needed (bl); |
f1310107 | 8618 | } |
c5aa993b | 8619 | } |
c906108c SS |
8620 | |
8621 | return i; | |
8622 | } | |
8623 | ||
a1398e0c PA |
8624 | /* Returns the resources B would use if it were a hardware |
8625 | watchpoint. */ | |
8626 | ||
c906108c | 8627 | static int |
a1398e0c | 8628 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8629 | { |
c906108c | 8630 | int i = 0; |
e09342b5 | 8631 | struct bp_location *bl; |
c906108c | 8632 | |
a1398e0c PA |
8633 | if (!breakpoint_enabled (b)) |
8634 | return 0; | |
8635 | ||
8636 | for (bl = b->loc; bl; bl = bl->next) | |
8637 | { | |
8638 | /* Special types of hardware watchpoints may use more than | |
8639 | one register. */ | |
8640 | i += b->ops->resources_needed (bl); | |
8641 | } | |
8642 | ||
8643 | return i; | |
8644 | } | |
8645 | ||
8646 | /* Returns the sum the used resources of all hardware watchpoints of | |
8647 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8648 | the sum of the used resources of all hardware watchpoints of other | |
8649 | types _not_ TYPE. */ | |
8650 | ||
8651 | static int | |
8652 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8653 | enum bptype type, int *other_type_used) | |
8654 | { | |
8655 | int i = 0; | |
8656 | struct breakpoint *b; | |
8657 | ||
c906108c SS |
8658 | *other_type_used = 0; |
8659 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8660 | { |
a1398e0c PA |
8661 | if (b == except) |
8662 | continue; | |
e09342b5 TJB |
8663 | if (!breakpoint_enabled (b)) |
8664 | continue; | |
8665 | ||
a1398e0c PA |
8666 | if (b->type == type) |
8667 | i += hw_watchpoint_use_count (b); | |
8668 | else if (is_hardware_watchpoint (b)) | |
8669 | *other_type_used = 1; | |
e09342b5 TJB |
8670 | } |
8671 | ||
c906108c SS |
8672 | return i; |
8673 | } | |
8674 | ||
c906108c | 8675 | void |
fba45db2 | 8676 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8677 | { |
c5aa993b | 8678 | struct breakpoint *b; |
c906108c SS |
8679 | |
8680 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8681 | { |
cc60f2e3 | 8682 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8683 | { |
b5de0fa7 | 8684 | b->enable_state = bp_call_disabled; |
b60e7edf | 8685 | update_global_location_list (0); |
c5aa993b JM |
8686 | } |
8687 | } | |
c906108c SS |
8688 | } |
8689 | ||
8690 | void | |
fba45db2 | 8691 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8692 | { |
c5aa993b | 8693 | struct breakpoint *b; |
c906108c SS |
8694 | |
8695 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8696 | { |
cc60f2e3 | 8697 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8698 | { |
b5de0fa7 | 8699 | b->enable_state = bp_enabled; |
b60e7edf | 8700 | update_global_location_list (1); |
c5aa993b JM |
8701 | } |
8702 | } | |
c906108c SS |
8703 | } |
8704 | ||
8bea4e01 UW |
8705 | void |
8706 | disable_breakpoints_before_startup (void) | |
8707 | { | |
6c95b8df | 8708 | current_program_space->executing_startup = 1; |
f8eba3c6 | 8709 | update_global_location_list (0); |
8bea4e01 UW |
8710 | } |
8711 | ||
8712 | void | |
8713 | enable_breakpoints_after_startup (void) | |
8714 | { | |
6c95b8df | 8715 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8716 | breakpoint_re_set (); |
8bea4e01 UW |
8717 | } |
8718 | ||
c906108c SS |
8719 | |
8720 | /* Set a breakpoint that will evaporate an end of command | |
8721 | at address specified by SAL. | |
8722 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8723 | ||
8724 | struct breakpoint * | |
a6d9a66e UW |
8725 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8726 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8727 | { |
52f0bd74 | 8728 | struct breakpoint *b; |
edb3359d | 8729 | |
193facb3 JK |
8730 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8731 | tail-called one. */ | |
8732 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8733 | |
06edf0c0 | 8734 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8735 | b->enable_state = bp_enabled; |
8736 | b->disposition = disp_donttouch; | |
818dd999 | 8737 | b->frame_id = frame_id; |
c906108c | 8738 | |
4a64f543 MS |
8739 | /* If we're debugging a multi-threaded program, then we want |
8740 | momentary breakpoints to be active in only a single thread of | |
8741 | control. */ | |
39f77062 KB |
8742 | if (in_thread_list (inferior_ptid)) |
8743 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8744 | |
b60e7edf | 8745 | update_global_location_list_nothrow (1); |
74960c60 | 8746 | |
c906108c SS |
8747 | return b; |
8748 | } | |
611c83ae | 8749 | |
06edf0c0 PA |
8750 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8751 | The new breakpoint will have type TYPE, and use OPS as it | |
8752 | breakpoint_ops. */ | |
e58b0e63 | 8753 | |
06edf0c0 PA |
8754 | static struct breakpoint * |
8755 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8756 | enum bptype type, | |
c0a91b2b | 8757 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8758 | { |
8759 | struct breakpoint *copy; | |
8760 | ||
06edf0c0 | 8761 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8762 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8763 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8764 | |
a6d9a66e | 8765 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8766 | copy->loc->requested_address = orig->loc->requested_address; |
8767 | copy->loc->address = orig->loc->address; | |
8768 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8769 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8770 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8771 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8772 | copy->loc->symtab = orig->loc->symtab; |
e58b0e63 PA |
8773 | copy->frame_id = orig->frame_id; |
8774 | copy->thread = orig->thread; | |
6c95b8df | 8775 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8776 | |
8777 | copy->enable_state = bp_enabled; | |
8778 | copy->disposition = disp_donttouch; | |
8779 | copy->number = internal_breakpoint_number--; | |
8780 | ||
8781 | update_global_location_list_nothrow (0); | |
8782 | return copy; | |
8783 | } | |
8784 | ||
06edf0c0 PA |
8785 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8786 | ORIG is NULL. */ | |
8787 | ||
8788 | struct breakpoint * | |
8789 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8790 | { | |
8791 | /* If there's nothing to clone, then return nothing. */ | |
8792 | if (orig == NULL) | |
8793 | return NULL; | |
8794 | ||
8795 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
8796 | } | |
8797 | ||
611c83ae | 8798 | struct breakpoint * |
a6d9a66e UW |
8799 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8800 | enum bptype type) | |
611c83ae PA |
8801 | { |
8802 | struct symtab_and_line sal; | |
8803 | ||
8804 | sal = find_pc_line (pc, 0); | |
8805 | sal.pc = pc; | |
8806 | sal.section = find_pc_overlay (pc); | |
8807 | sal.explicit_pc = 1; | |
8808 | ||
a6d9a66e | 8809 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8810 | } |
c906108c | 8811 | \f |
c5aa993b | 8812 | |
c906108c SS |
8813 | /* Tell the user we have just set a breakpoint B. */ |
8814 | ||
8815 | static void | |
fba45db2 | 8816 | mention (struct breakpoint *b) |
c906108c | 8817 | { |
348d480f | 8818 | b->ops->print_mention (b); |
79a45e25 | 8819 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8820 | return; |
c906108c SS |
8821 | printf_filtered ("\n"); |
8822 | } | |
c906108c | 8823 | \f |
c5aa993b | 8824 | |
0d381245 | 8825 | static struct bp_location * |
39d61571 | 8826 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8827 | const struct symtab_and_line *sal) |
8828 | { | |
8829 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8830 | CORE_ADDR adjusted_address; |
8831 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8832 | ||
8833 | if (loc_gdbarch == NULL) | |
8834 | loc_gdbarch = b->gdbarch; | |
8835 | ||
8836 | /* Adjust the breakpoint's address prior to allocating a location. | |
8837 | Once we call allocate_bp_location(), that mostly uninitialized | |
8838 | location will be placed on the location chain. Adjustment of the | |
8839 | breakpoint may cause target_read_memory() to be called and we do | |
8840 | not want its scan of the location chain to find a breakpoint and | |
8841 | location that's only been partially initialized. */ | |
8842 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8843 | sal->pc, b->type); | |
0d381245 | 8844 | |
d30113d4 | 8845 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8846 | loc = allocate_bp_location (b); |
d30113d4 JK |
8847 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8848 | tmp = &((*tmp)->next)) | |
0d381245 | 8849 | ; |
d30113d4 | 8850 | loc->next = *tmp; |
0d381245 | 8851 | *tmp = loc; |
3742cc8b | 8852 | |
0d381245 | 8853 | loc->requested_address = sal->pc; |
3742cc8b | 8854 | loc->address = adjusted_address; |
6c95b8df | 8855 | loc->pspace = sal->pspace; |
55aa24fb | 8856 | loc->probe = sal->probe; |
6c95b8df | 8857 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8858 | loc->section = sal->section; |
3742cc8b | 8859 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8860 | loc->line_number = sal->line; |
2f202fde | 8861 | loc->symtab = sal->symtab; |
f8eba3c6 | 8862 | |
0e30163f JK |
8863 | set_breakpoint_location_function (loc, |
8864 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
8865 | return loc; |
8866 | } | |
514f746b AR |
8867 | \f |
8868 | ||
8869 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8870 | return 0 otherwise. */ | |
8871 | ||
8872 | static int | |
8873 | bp_loc_is_permanent (struct bp_location *loc) | |
8874 | { | |
8875 | int len; | |
8876 | CORE_ADDR addr; | |
1afeeb75 | 8877 | const gdb_byte *bpoint; |
514f746b | 8878 | gdb_byte *target_mem; |
939c61fa JK |
8879 | struct cleanup *cleanup; |
8880 | int retval = 0; | |
514f746b AR |
8881 | |
8882 | gdb_assert (loc != NULL); | |
8883 | ||
8884 | addr = loc->address; | |
1afeeb75 | 8885 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 8886 | |
939c61fa | 8887 | /* Software breakpoints unsupported? */ |
1afeeb75 | 8888 | if (bpoint == NULL) |
939c61fa JK |
8889 | return 0; |
8890 | ||
514f746b AR |
8891 | target_mem = alloca (len); |
8892 | ||
939c61fa JK |
8893 | /* Enable the automatic memory restoration from breakpoints while |
8894 | we read the memory. Otherwise we could say about our temporary | |
8895 | breakpoints they are permanent. */ | |
6c95b8df PA |
8896 | cleanup = save_current_space_and_thread (); |
8897 | ||
8898 | switch_to_program_space_and_thread (loc->pspace); | |
8899 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 8900 | |
514f746b | 8901 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 8902 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 8903 | retval = 1; |
514f746b | 8904 | |
939c61fa JK |
8905 | do_cleanups (cleanup); |
8906 | ||
8907 | return retval; | |
514f746b AR |
8908 | } |
8909 | ||
e7e0cddf SS |
8910 | /* Build a command list for the dprintf corresponding to the current |
8911 | settings of the dprintf style options. */ | |
8912 | ||
8913 | static void | |
8914 | update_dprintf_command_list (struct breakpoint *b) | |
8915 | { | |
8916 | char *dprintf_args = b->extra_string; | |
8917 | char *printf_line = NULL; | |
8918 | ||
8919 | if (!dprintf_args) | |
8920 | return; | |
8921 | ||
8922 | dprintf_args = skip_spaces (dprintf_args); | |
8923 | ||
8924 | /* Allow a comma, as it may have terminated a location, but don't | |
8925 | insist on it. */ | |
8926 | if (*dprintf_args == ',') | |
8927 | ++dprintf_args; | |
8928 | dprintf_args = skip_spaces (dprintf_args); | |
8929 | ||
8930 | if (*dprintf_args != '"') | |
8931 | error (_("Bad format string, missing '\"'.")); | |
8932 | ||
d3ce09f5 | 8933 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8934 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8935 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8936 | { |
8937 | if (!dprintf_function) | |
8938 | error (_("No function supplied for dprintf call")); | |
8939 | ||
8940 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8941 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8942 | dprintf_function, | |
8943 | dprintf_channel, | |
8944 | dprintf_args); | |
8945 | else | |
8946 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8947 | dprintf_function, | |
8948 | dprintf_args); | |
8949 | } | |
d3ce09f5 SS |
8950 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8951 | { | |
8952 | if (target_can_run_breakpoint_commands ()) | |
8953 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8954 | else | |
8955 | { | |
8956 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8957 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8958 | } | |
8959 | } | |
e7e0cddf SS |
8960 | else |
8961 | internal_error (__FILE__, __LINE__, | |
8962 | _("Invalid dprintf style.")); | |
8963 | ||
f28045c2 | 8964 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8965 | /* Manufacture a printf/continue sequence. */ |
f28045c2 YQ |
8966 | { |
8967 | struct command_line *printf_cmd_line, *cont_cmd_line = NULL; | |
e7e0cddf | 8968 | |
f28045c2 YQ |
8969 | if (strcmp (dprintf_style, dprintf_style_agent) != 0) |
8970 | { | |
8971 | cont_cmd_line = xmalloc (sizeof (struct command_line)); | |
8972 | cont_cmd_line->control_type = simple_control; | |
8973 | cont_cmd_line->body_count = 0; | |
8974 | cont_cmd_line->body_list = NULL; | |
8975 | cont_cmd_line->next = NULL; | |
8976 | cont_cmd_line->line = xstrdup ("continue"); | |
8977 | } | |
e7e0cddf | 8978 | |
f28045c2 YQ |
8979 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
8980 | printf_cmd_line->control_type = simple_control; | |
8981 | printf_cmd_line->body_count = 0; | |
8982 | printf_cmd_line->body_list = NULL; | |
8983 | printf_cmd_line->next = cont_cmd_line; | |
8984 | printf_cmd_line->line = printf_line; | |
e7e0cddf | 8985 | |
f28045c2 YQ |
8986 | breakpoint_set_commands (b, printf_cmd_line); |
8987 | } | |
e7e0cddf SS |
8988 | } |
8989 | ||
8990 | /* Update all dprintf commands, making their command lists reflect | |
8991 | current style settings. */ | |
8992 | ||
8993 | static void | |
8994 | update_dprintf_commands (char *args, int from_tty, | |
8995 | struct cmd_list_element *c) | |
8996 | { | |
8997 | struct breakpoint *b; | |
8998 | ||
8999 | ALL_BREAKPOINTS (b) | |
9000 | { | |
9001 | if (b->type == bp_dprintf) | |
9002 | update_dprintf_command_list (b); | |
9003 | } | |
9004 | } | |
c3f6f71d | 9005 | |
018d34a4 VP |
9006 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9007 | as textual description of the location, and COND_STRING | |
db107f19 | 9008 | as condition expression. */ |
018d34a4 VP |
9009 | |
9010 | static void | |
d9b3f62e PA |
9011 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9012 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9013 | char *filter, char *cond_string, |
e7e0cddf | 9014 | char *extra_string, |
d9b3f62e PA |
9015 | enum bptype type, enum bpdisp disposition, |
9016 | int thread, int task, int ignore_count, | |
c0a91b2b | 9017 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9018 | int enabled, int internal, unsigned flags, |
9019 | int display_canonical) | |
018d34a4 | 9020 | { |
0d381245 | 9021 | int i; |
018d34a4 VP |
9022 | |
9023 | if (type == bp_hardware_breakpoint) | |
9024 | { | |
fbbd034e AS |
9025 | int target_resources_ok; |
9026 | ||
9027 | i = hw_breakpoint_used_count (); | |
9028 | target_resources_ok = | |
9029 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9030 | i + 1, 0); |
9031 | if (target_resources_ok == 0) | |
9032 | error (_("No hardware breakpoint support in the target.")); | |
9033 | else if (target_resources_ok < 0) | |
9034 | error (_("Hardware breakpoints used exceeds limit.")); | |
9035 | } | |
9036 | ||
6c95b8df PA |
9037 | gdb_assert (sals.nelts > 0); |
9038 | ||
0d381245 VP |
9039 | for (i = 0; i < sals.nelts; ++i) |
9040 | { | |
9041 | struct symtab_and_line sal = sals.sals[i]; | |
9042 | struct bp_location *loc; | |
9043 | ||
9044 | if (from_tty) | |
5af949e3 UW |
9045 | { |
9046 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9047 | if (!loc_gdbarch) | |
9048 | loc_gdbarch = gdbarch; | |
9049 | ||
9050 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9051 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9052 | } |
0d381245 VP |
9053 | |
9054 | if (i == 0) | |
9055 | { | |
d9b3f62e | 9056 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9057 | b->thread = thread; |
4a306c9a | 9058 | b->task = task; |
855a6e68 | 9059 | |
0d381245 | 9060 | b->cond_string = cond_string; |
e7e0cddf | 9061 | b->extra_string = extra_string; |
0d381245 | 9062 | b->ignore_count = ignore_count; |
41447f92 | 9063 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9064 | b->disposition = disposition; |
6c95b8df | 9065 | |
44f238bb PA |
9066 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9067 | b->loc->inserted = 1; | |
9068 | ||
0fb4aa4b PA |
9069 | if (type == bp_static_tracepoint) |
9070 | { | |
d9b3f62e | 9071 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9072 | struct static_tracepoint_marker marker; |
9073 | ||
983af33b | 9074 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9075 | { |
9076 | /* We already know the marker exists, otherwise, we | |
9077 | wouldn't see a sal for it. */ | |
9078 | char *p = &addr_string[3]; | |
9079 | char *endp; | |
9080 | char *marker_str; | |
0fb4aa4b | 9081 | |
e9cafbcc | 9082 | p = skip_spaces (p); |
0fb4aa4b | 9083 | |
e9cafbcc | 9084 | endp = skip_to_space (p); |
0fb4aa4b PA |
9085 | |
9086 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9087 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9088 | |
3e43a32a MS |
9089 | printf_filtered (_("Probed static tracepoint " |
9090 | "marker \"%s\"\n"), | |
d9b3f62e | 9091 | t->static_trace_marker_id); |
0fb4aa4b PA |
9092 | } |
9093 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9094 | { | |
d9b3f62e | 9095 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9096 | release_static_tracepoint_marker (&marker); |
9097 | ||
3e43a32a MS |
9098 | printf_filtered (_("Probed static tracepoint " |
9099 | "marker \"%s\"\n"), | |
d9b3f62e | 9100 | t->static_trace_marker_id); |
0fb4aa4b PA |
9101 | } |
9102 | else | |
3e43a32a MS |
9103 | warning (_("Couldn't determine the static " |
9104 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9105 | } |
9106 | ||
0d381245 VP |
9107 | loc = b->loc; |
9108 | } | |
9109 | else | |
018d34a4 | 9110 | { |
39d61571 | 9111 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9112 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9113 | loc->inserted = 1; | |
0d381245 VP |
9114 | } |
9115 | ||
514f746b AR |
9116 | if (bp_loc_is_permanent (loc)) |
9117 | make_breakpoint_permanent (b); | |
9118 | ||
0d381245 VP |
9119 | if (b->cond_string) |
9120 | { | |
bbc13ae3 KS |
9121 | const char *arg = b->cond_string; |
9122 | ||
1bb9788d TT |
9123 | loc->cond = parse_exp_1 (&arg, loc->address, |
9124 | block_for_pc (loc->address), 0); | |
0d381245 | 9125 | if (*arg) |
588ae58c | 9126 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9127 | } |
e7e0cddf SS |
9128 | |
9129 | /* Dynamic printf requires and uses additional arguments on the | |
9130 | command line, otherwise it's an error. */ | |
9131 | if (type == bp_dprintf) | |
9132 | { | |
9133 | if (b->extra_string) | |
9134 | update_dprintf_command_list (b); | |
9135 | else | |
9136 | error (_("Format string required")); | |
9137 | } | |
9138 | else if (b->extra_string) | |
588ae58c | 9139 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9140 | } |
018d34a4 | 9141 | |
56435ebe | 9142 | b->display_canonical = display_canonical; |
018d34a4 VP |
9143 | if (addr_string) |
9144 | b->addr_string = addr_string; | |
9145 | else | |
9146 | /* addr_string has to be used or breakpoint_re_set will delete | |
9147 | me. */ | |
5af949e3 UW |
9148 | b->addr_string |
9149 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9150 | b->filter = filter; |
d9b3f62e | 9151 | } |
018d34a4 | 9152 | |
d9b3f62e PA |
9153 | static void |
9154 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9155 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9156 | char *filter, char *cond_string, |
e7e0cddf | 9157 | char *extra_string, |
d9b3f62e PA |
9158 | enum bptype type, enum bpdisp disposition, |
9159 | int thread, int task, int ignore_count, | |
c0a91b2b | 9160 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9161 | int enabled, int internal, unsigned flags, |
9162 | int display_canonical) | |
d9b3f62e PA |
9163 | { |
9164 | struct breakpoint *b; | |
9165 | struct cleanup *old_chain; | |
9166 | ||
9167 | if (is_tracepoint_type (type)) | |
9168 | { | |
9169 | struct tracepoint *t; | |
9170 | ||
9171 | t = XCNEW (struct tracepoint); | |
9172 | b = &t->base; | |
9173 | } | |
9174 | else | |
9175 | b = XNEW (struct breakpoint); | |
9176 | ||
9177 | old_chain = make_cleanup (xfree, b); | |
9178 | ||
9179 | init_breakpoint_sal (b, gdbarch, | |
9180 | sals, addr_string, | |
e7e0cddf | 9181 | filter, cond_string, extra_string, |
d9b3f62e PA |
9182 | type, disposition, |
9183 | thread, task, ignore_count, | |
9184 | ops, from_tty, | |
44f238bb PA |
9185 | enabled, internal, flags, |
9186 | display_canonical); | |
d9b3f62e PA |
9187 | discard_cleanups (old_chain); |
9188 | ||
3ea46bff | 9189 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9190 | } |
9191 | ||
9192 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9193 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9194 | value. COND_STRING, if not NULL, specified the condition to be | |
9195 | used for all breakpoints. Essentially the only case where | |
9196 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9197 | function. In that case, it's still not possible to specify | |
9198 | separate conditions for different overloaded functions, so | |
9199 | we take just a single condition string. | |
9200 | ||
c3f6f71d | 9201 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9202 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9203 | array contents). If the function fails (error() is called), the |
9204 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9205 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9206 | |
9207 | static void | |
8cdf0e15 | 9208 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9209 | struct linespec_result *canonical, |
e7e0cddf | 9210 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9211 | enum bptype type, enum bpdisp disposition, |
9212 | int thread, int task, int ignore_count, | |
c0a91b2b | 9213 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9214 | int enabled, int internal, unsigned flags) |
c906108c | 9215 | { |
018d34a4 | 9216 | int i; |
f8eba3c6 | 9217 | struct linespec_sals *lsal; |
cc59ec59 | 9218 | |
f8eba3c6 TT |
9219 | if (canonical->pre_expanded) |
9220 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9221 | ||
9222 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9223 | { |
f8eba3c6 TT |
9224 | /* Note that 'addr_string' can be NULL in the case of a plain |
9225 | 'break', without arguments. */ | |
9226 | char *addr_string = (canonical->addr_string | |
9227 | ? xstrdup (canonical->addr_string) | |
9228 | : NULL); | |
9229 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9230 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9231 | |
f8eba3c6 TT |
9232 | make_cleanup (xfree, filter_string); |
9233 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9234 | addr_string, | |
9235 | filter_string, | |
e7e0cddf SS |
9236 | cond_string, extra_string, |
9237 | type, disposition, | |
84f4c1fe | 9238 | thread, task, ignore_count, ops, |
44f238bb | 9239 | from_tty, enabled, internal, flags, |
56435ebe | 9240 | canonical->special_display); |
f8eba3c6 | 9241 | discard_cleanups (inner); |
c3f6f71d | 9242 | } |
c3f6f71d | 9243 | } |
c906108c | 9244 | |
9998af43 | 9245 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9246 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9247 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9248 | address strings. ADDRESS points to the end of the SAL. |
9249 | ||
9250 | The array and the line spec strings are allocated on the heap, it is | |
9251 | the caller's responsibility to free them. */ | |
c906108c | 9252 | |
b9362cc7 | 9253 | static void |
c3f6f71d | 9254 | parse_breakpoint_sals (char **address, |
58438ac1 | 9255 | struct linespec_result *canonical) |
c3f6f71d | 9256 | { |
c3f6f71d | 9257 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9258 | breakpoint. */ |
c3f6f71d JM |
9259 | if ((*address) == NULL |
9260 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9261 | { |
1bfeeb0f JL |
9262 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9263 | address. */ | |
9264 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9265 | { |
f8eba3c6 | 9266 | struct linespec_sals lsal; |
c3f6f71d | 9267 | struct symtab_and_line sal; |
1c8cdcb1 | 9268 | CORE_ADDR pc; |
cc59ec59 | 9269 | |
4a64f543 | 9270 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9271 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9272 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9273 | |
9274 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9275 | corresponding to the last call to print_frame_info. |
9276 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9277 | as the breakpoint line number is inappropriate otherwise. | |
9278 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9279 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9280 | pc = sal.pc; |
9281 | sal = find_pc_line (pc, 0); | |
00903456 | 9282 | |
4a64f543 | 9283 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9284 | where PC is the last displayed codepoint's address. So |
9285 | make sure to set sal.explicit_pc to prevent GDB from | |
9286 | trying to expand the list of sals to include all other | |
9287 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9288 | sal.pc = pc; |
00903456 JK |
9289 | sal.explicit_pc = 1; |
9290 | ||
f8eba3c6 TT |
9291 | lsal.sals.sals[0] = sal; |
9292 | lsal.sals.nelts = 1; | |
9293 | lsal.canonical = NULL; | |
9294 | ||
9295 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9296 | } |
9297 | else | |
8a3fe4f8 | 9298 | error (_("No default breakpoint address now.")); |
c906108c SS |
9299 | } |
9300 | else | |
9301 | { | |
cc80f267 JK |
9302 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9303 | ||
c906108c | 9304 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9305 | current_source_symtab (which is decode_line_1's default). |
9306 | This should produce the results we want almost all of the | |
cc80f267 JK |
9307 | time while leaving default_breakpoint_* alone. |
9308 | ||
9309 | ObjC: However, don't match an Objective-C method name which | |
9310 | may have a '+' or '-' succeeded by a '['. */ | |
9311 | if (last_displayed_sal_is_valid () | |
9312 | && (!cursal.symtab | |
9313 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9314 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9315 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9316 | get_last_displayed_symtab (), | |
9317 | get_last_displayed_line (), | |
9318 | canonical, NULL, NULL); | |
c906108c | 9319 | else |
f8eba3c6 | 9320 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9321 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9322 | } |
c3f6f71d | 9323 | } |
c906108c | 9324 | |
c906108c | 9325 | |
c3f6f71d | 9326 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9327 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9328 | |
b9362cc7 | 9329 | static void |
23e7acfb | 9330 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9331 | { |
9332 | int i; | |
cc59ec59 | 9333 | |
c3f6f71d | 9334 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9335 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9336 | } |
9337 | ||
7a697b8d SS |
9338 | /* Fast tracepoints may have restrictions on valid locations. For |
9339 | instance, a fast tracepoint using a jump instead of a trap will | |
9340 | likely have to overwrite more bytes than a trap would, and so can | |
9341 | only be placed where the instruction is longer than the jump, or a | |
9342 | multi-instruction sequence does not have a jump into the middle of | |
9343 | it, etc. */ | |
9344 | ||
9345 | static void | |
9346 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9347 | struct symtabs_and_lines *sals) | |
9348 | { | |
9349 | int i, rslt; | |
9350 | struct symtab_and_line *sal; | |
9351 | char *msg; | |
9352 | struct cleanup *old_chain; | |
9353 | ||
9354 | for (i = 0; i < sals->nelts; i++) | |
9355 | { | |
f8eba3c6 TT |
9356 | struct gdbarch *sarch; |
9357 | ||
7a697b8d SS |
9358 | sal = &sals->sals[i]; |
9359 | ||
f8eba3c6 TT |
9360 | sarch = get_sal_arch (*sal); |
9361 | /* We fall back to GDBARCH if there is no architecture | |
9362 | associated with SAL. */ | |
9363 | if (sarch == NULL) | |
9364 | sarch = gdbarch; | |
9365 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9366 | NULL, &msg); |
9367 | old_chain = make_cleanup (xfree, msg); | |
9368 | ||
9369 | if (!rslt) | |
9370 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9371 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9372 | |
9373 | do_cleanups (old_chain); | |
9374 | } | |
9375 | } | |
9376 | ||
af4908ba KS |
9377 | /* Issue an invalid thread ID error. */ |
9378 | ||
9379 | static void ATTRIBUTE_NORETURN | |
9380 | invalid_thread_id_error (int id) | |
9381 | { | |
9382 | error (_("Unknown thread %d."), id); | |
9383 | } | |
9384 | ||
018d34a4 VP |
9385 | /* Given TOK, a string specification of condition and thread, as |
9386 | accepted by the 'break' command, extract the condition | |
9387 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9388 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9389 | If no condition is found, *COND_STRING is set to NULL. |
9390 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9391 | |
9392 | static void | |
bbc13ae3 | 9393 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9394 | char **cond_string, int *thread, int *task, |
9395 | char **rest) | |
018d34a4 VP |
9396 | { |
9397 | *cond_string = NULL; | |
9398 | *thread = -1; | |
ed1d1739 KS |
9399 | *task = 0; |
9400 | *rest = NULL; | |
9401 | ||
018d34a4 VP |
9402 | while (tok && *tok) |
9403 | { | |
bbc13ae3 | 9404 | const char *end_tok; |
018d34a4 | 9405 | int toklen; |
bbc13ae3 KS |
9406 | const char *cond_start = NULL; |
9407 | const char *cond_end = NULL; | |
cc59ec59 | 9408 | |
bbc13ae3 | 9409 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9410 | |
9411 | if ((*tok == '"' || *tok == ',') && rest) | |
9412 | { | |
9413 | *rest = savestring (tok, strlen (tok)); | |
9414 | return; | |
9415 | } | |
9416 | ||
bbc13ae3 | 9417 | end_tok = skip_to_space_const (tok); |
d634f2de | 9418 | |
018d34a4 | 9419 | toklen = end_tok - tok; |
d634f2de | 9420 | |
018d34a4 VP |
9421 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9422 | { | |
f7545552 TT |
9423 | struct expression *expr; |
9424 | ||
018d34a4 | 9425 | tok = cond_start = end_tok + 1; |
1bb9788d | 9426 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9427 | xfree (expr); |
018d34a4 | 9428 | cond_end = tok; |
d634f2de | 9429 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9430 | } |
9431 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9432 | { | |
9433 | char *tmptok; | |
d634f2de | 9434 | |
018d34a4 | 9435 | tok = end_tok + 1; |
bbc13ae3 | 9436 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9437 | if (tok == tmptok) |
9438 | error (_("Junk after thread keyword.")); | |
9439 | if (!valid_thread_id (*thread)) | |
af4908ba | 9440 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9441 | tok = tmptok; |
018d34a4 | 9442 | } |
4a306c9a JB |
9443 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9444 | { | |
9445 | char *tmptok; | |
9446 | ||
9447 | tok = end_tok + 1; | |
bbc13ae3 | 9448 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9449 | if (tok == tmptok) |
9450 | error (_("Junk after task keyword.")); | |
9451 | if (!valid_task_id (*task)) | |
b6199126 | 9452 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9453 | tok = tmptok; |
4a306c9a | 9454 | } |
e7e0cddf SS |
9455 | else if (rest) |
9456 | { | |
9457 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9458 | return; |
e7e0cddf | 9459 | } |
018d34a4 VP |
9460 | else |
9461 | error (_("Junk at end of arguments.")); | |
9462 | } | |
9463 | } | |
9464 | ||
0fb4aa4b PA |
9465 | /* Decode a static tracepoint marker spec. */ |
9466 | ||
9467 | static struct symtabs_and_lines | |
9468 | decode_static_tracepoint_spec (char **arg_p) | |
9469 | { | |
9470 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9471 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9472 | struct cleanup *old_chain; |
9473 | char *p = &(*arg_p)[3]; | |
9474 | char *endp; | |
9475 | char *marker_str; | |
9476 | int i; | |
9477 | ||
e9cafbcc | 9478 | p = skip_spaces (p); |
0fb4aa4b | 9479 | |
e9cafbcc | 9480 | endp = skip_to_space (p); |
0fb4aa4b PA |
9481 | |
9482 | marker_str = savestring (p, endp - p); | |
9483 | old_chain = make_cleanup (xfree, marker_str); | |
9484 | ||
9485 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9486 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9487 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9488 | ||
9489 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9490 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9491 | ||
9492 | for (i = 0; i < sals.nelts; i++) | |
9493 | { | |
9494 | struct static_tracepoint_marker *marker; | |
9495 | ||
9496 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9497 | ||
9498 | init_sal (&sals.sals[i]); | |
9499 | ||
9500 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9501 | sals.sals[i].pc = marker->address; | |
9502 | ||
9503 | release_static_tracepoint_marker (marker); | |
9504 | } | |
9505 | ||
9506 | do_cleanups (old_chain); | |
9507 | ||
9508 | *arg_p = endp; | |
9509 | return sals; | |
9510 | } | |
9511 | ||
fd9b8c24 PA |
9512 | /* Set a breakpoint. This function is shared between CLI and MI |
9513 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9514 | modes of operations, selected by the PARSE_ARG parameter. If |
9515 | non-zero, the function will parse ARG, extracting location, | |
9516 | condition, thread and extra string. Otherwise, ARG is just the | |
9517 | breakpoint's location, with condition, thread, and extra string | |
9518 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9519 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9520 | from the internal breakpoint count. Returns true if any breakpoint | |
9521 | was created; false otherwise. */ | |
0101ce28 | 9522 | |
8cdf0e15 VP |
9523 | int |
9524 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9525 | char *arg, char *cond_string, |
9526 | int thread, char *extra_string, | |
f6de8ec2 | 9527 | int parse_arg, |
0fb4aa4b | 9528 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9529 | int ignore_count, |
9530 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9531 | const struct breakpoint_ops *ops, |
44f238bb PA |
9532 | int from_tty, int enabled, int internal, |
9533 | unsigned flags) | |
c3f6f71d | 9534 | { |
b78a6381 | 9535 | volatile struct gdb_exception e; |
f8eba3c6 | 9536 | char *copy_arg = NULL; |
c3f6f71d | 9537 | char *addr_start = arg; |
7efd8fc2 | 9538 | struct linespec_result canonical; |
c3f6f71d | 9539 | struct cleanup *old_chain; |
80c99de1 | 9540 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9541 | int pending = 0; |
4a306c9a | 9542 | int task = 0; |
86b17b60 | 9543 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9544 | |
348d480f PA |
9545 | gdb_assert (ops != NULL); |
9546 | ||
7efd8fc2 | 9547 | init_linespec_result (&canonical); |
c3f6f71d | 9548 | |
b78a6381 TT |
9549 | TRY_CATCH (e, RETURN_MASK_ALL) |
9550 | { | |
983af33b SDJ |
9551 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9552 | addr_start, ©_arg); | |
b78a6381 | 9553 | } |
0101ce28 JJ |
9554 | |
9555 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 9556 | switch (e.reason) |
0101ce28 | 9557 | { |
983af33b SDJ |
9558 | case GDB_NO_ERROR: |
9559 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9560 | return 0; | |
9561 | break; | |
05ff989b AC |
9562 | case RETURN_ERROR: |
9563 | switch (e.error) | |
0101ce28 | 9564 | { |
05ff989b | 9565 | case NOT_FOUND_ERROR: |
0101ce28 | 9566 | |
05ff989b AC |
9567 | /* If pending breakpoint support is turned off, throw |
9568 | error. */ | |
fa8d40ab JJ |
9569 | |
9570 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9571 | throw_exception (e); |
9572 | ||
9573 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9574 | |
05ff989b AC |
9575 | /* If pending breakpoint support is auto query and the user |
9576 | selects no, then simply return the error code. */ | |
059fb39f | 9577 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9578 | && !nquery (_("Make %s pending on future shared library load? "), |
9579 | bptype_string (type_wanted))) | |
fd9b8c24 | 9580 | return 0; |
fa8d40ab | 9581 | |
05ff989b AC |
9582 | /* At this point, either the user was queried about setting |
9583 | a pending breakpoint and selected yes, or pending | |
9584 | breakpoint behavior is on and thus a pending breakpoint | |
9585 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9586 | { |
9587 | struct linespec_sals lsal; | |
9588 | ||
9589 | copy_arg = xstrdup (addr_start); | |
9590 | lsal.canonical = xstrdup (copy_arg); | |
9591 | lsal.sals.nelts = 1; | |
9592 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9593 | init_sal (&lsal.sals.sals[0]); | |
9594 | pending = 1; | |
9595 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9596 | } | |
05ff989b AC |
9597 | break; |
9598 | default: | |
98deb0da | 9599 | throw_exception (e); |
0101ce28 | 9600 | } |
2abae994 | 9601 | break; |
05ff989b | 9602 | default: |
983af33b | 9603 | throw_exception (e); |
0101ce28 | 9604 | } |
c3f6f71d | 9605 | |
4a64f543 | 9606 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9607 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9608 | |
c3f6f71d JM |
9609 | /* ----------------------------- SNIP ----------------------------- |
9610 | Anything added to the cleanup chain beyond this point is assumed | |
9611 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9612 | then the memory is not reclaimed. */ |
9613 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9614 | |
c3f6f71d JM |
9615 | /* Resolve all line numbers to PC's and verify that the addresses |
9616 | are ok for the target. */ | |
0101ce28 | 9617 | if (!pending) |
f8eba3c6 TT |
9618 | { |
9619 | int ix; | |
9620 | struct linespec_sals *iter; | |
9621 | ||
9622 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9623 | breakpoint_sals_to_pc (&iter->sals); | |
9624 | } | |
c3f6f71d | 9625 | |
7a697b8d | 9626 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9627 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9628 | { |
9629 | int ix; | |
9630 | struct linespec_sals *iter; | |
9631 | ||
9632 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9633 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9634 | } | |
7a697b8d | 9635 | |
c3f6f71d JM |
9636 | /* Verify that condition can be parsed, before setting any |
9637 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9638 | breakpoint. */ |
0101ce28 | 9639 | if (!pending) |
c3f6f71d | 9640 | { |
f8eba3c6 TT |
9641 | struct linespec_sals *lsal; |
9642 | ||
9643 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9644 | ||
f6de8ec2 | 9645 | if (parse_arg) |
72b2ff0e | 9646 | { |
e7e0cddf | 9647 | char *rest; |
72b2ff0e VP |
9648 | /* Here we only parse 'arg' to separate condition |
9649 | from thread number, so parsing in context of first | |
9650 | sal is OK. When setting the breakpoint we'll | |
9651 | re-parse it in context of each sal. */ | |
ed1d1739 | 9652 | |
f8eba3c6 | 9653 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, |
e7e0cddf | 9654 | &thread, &task, &rest); |
72b2ff0e VP |
9655 | if (cond_string) |
9656 | make_cleanup (xfree, cond_string); | |
e7e0cddf SS |
9657 | if (rest) |
9658 | make_cleanup (xfree, rest); | |
9659 | if (rest) | |
9660 | extra_string = rest; | |
72b2ff0e | 9661 | } |
2f069f6f | 9662 | else |
72b2ff0e | 9663 | { |
f6de8ec2 PA |
9664 | if (*arg != '\0') |
9665 | error (_("Garbage '%s' at end of location"), arg); | |
9666 | ||
72b2ff0e VP |
9667 | /* Create a private copy of condition string. */ |
9668 | if (cond_string) | |
9669 | { | |
9670 | cond_string = xstrdup (cond_string); | |
9671 | make_cleanup (xfree, cond_string); | |
9672 | } | |
e7e0cddf SS |
9673 | /* Create a private copy of any extra string. */ |
9674 | if (extra_string) | |
9675 | { | |
9676 | extra_string = xstrdup (extra_string); | |
9677 | make_cleanup (xfree, extra_string); | |
9678 | } | |
72b2ff0e | 9679 | } |
0fb4aa4b | 9680 | |
983af33b | 9681 | ops->create_breakpoints_sal (gdbarch, &canonical, lsal, |
e7e0cddf | 9682 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9683 | tempflag ? disp_del : disp_donttouch, |
9684 | thread, task, ignore_count, ops, | |
44f238bb | 9685 | from_tty, enabled, internal, flags); |
c906108c | 9686 | } |
0101ce28 JJ |
9687 | else |
9688 | { | |
0101ce28 JJ |
9689 | struct breakpoint *b; |
9690 | ||
0101ce28 JJ |
9691 | make_cleanup (xfree, copy_arg); |
9692 | ||
bfccc43c YQ |
9693 | if (is_tracepoint_type (type_wanted)) |
9694 | { | |
9695 | struct tracepoint *t; | |
9696 | ||
9697 | t = XCNEW (struct tracepoint); | |
9698 | b = &t->base; | |
9699 | } | |
9700 | else | |
9701 | b = XNEW (struct breakpoint); | |
9702 | ||
9703 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
9704 | ||
f8eba3c6 | 9705 | b->addr_string = copy_arg; |
f6de8ec2 | 9706 | if (parse_arg) |
e12c7713 MK |
9707 | b->cond_string = NULL; |
9708 | else | |
9709 | { | |
9710 | /* Create a private copy of condition string. */ | |
9711 | if (cond_string) | |
9712 | { | |
9713 | cond_string = xstrdup (cond_string); | |
9714 | make_cleanup (xfree, cond_string); | |
9715 | } | |
9716 | b->cond_string = cond_string; | |
9717 | } | |
e7e0cddf | 9718 | b->extra_string = NULL; |
0101ce28 | 9719 | b->ignore_count = ignore_count; |
0101ce28 | 9720 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9721 | b->condition_not_parsed = 1; |
41447f92 | 9722 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9723 | if ((type_wanted != bp_breakpoint |
9724 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9725 | b->pspace = current_program_space; |
8bea4e01 | 9726 | |
bfccc43c | 9727 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9728 | } |
9729 | ||
f8eba3c6 | 9730 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9731 | { |
3e43a32a MS |
9732 | warning (_("Multiple breakpoints were set.\nUse the " |
9733 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9734 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9735 | } |
9736 | ||
80c99de1 PA |
9737 | /* That's it. Discard the cleanups for data inserted into the |
9738 | breakpoint. */ | |
9739 | discard_cleanups (bkpt_chain); | |
9740 | /* But cleanup everything else. */ | |
c3f6f71d | 9741 | do_cleanups (old_chain); |
217dc9e2 | 9742 | |
80c99de1 | 9743 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 9744 | update_global_location_list (1); |
fd9b8c24 PA |
9745 | |
9746 | return 1; | |
c3f6f71d | 9747 | } |
c906108c | 9748 | |
348d480f | 9749 | /* Set a breakpoint. |
72b2ff0e VP |
9750 | ARG is a string describing breakpoint address, |
9751 | condition, and thread. | |
9752 | FLAG specifies if a breakpoint is hardware on, | |
9753 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9754 | and BP_TEMPFLAG. */ | |
348d480f | 9755 | |
98deb0da | 9756 | static void |
72b2ff0e | 9757 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9758 | { |
72b2ff0e | 9759 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9760 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9761 | ? bp_hardware_breakpoint | |
9762 | : bp_breakpoint); | |
55aa24fb SDJ |
9763 | struct breakpoint_ops *ops; |
9764 | const char *arg_cp = arg; | |
9765 | ||
9766 | /* Matching breakpoints on probes. */ | |
9767 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
9768 | ops = &bkpt_probe_breakpoint_ops; | |
9769 | else | |
9770 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9771 | |
8cdf0e15 VP |
9772 | create_breakpoint (get_current_arch (), |
9773 | arg, | |
e7e0cddf | 9774 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 9775 | tempflag, type_wanted, |
8cdf0e15 VP |
9776 | 0 /* Ignore count */, |
9777 | pending_break_support, | |
55aa24fb | 9778 | ops, |
8cdf0e15 | 9779 | from_tty, |
84f4c1fe | 9780 | 1 /* enabled */, |
44f238bb PA |
9781 | 0 /* internal */, |
9782 | 0); | |
c906108c SS |
9783 | } |
9784 | ||
c906108c SS |
9785 | /* Helper function for break_command_1 and disassemble_command. */ |
9786 | ||
9787 | void | |
fba45db2 | 9788 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9789 | { |
9790 | CORE_ADDR pc; | |
9791 | ||
9792 | if (sal->pc == 0 && sal->symtab != NULL) | |
9793 | { | |
9794 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9795 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9796 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9797 | sal->pc = pc; |
6a048695 | 9798 | |
4a64f543 MS |
9799 | /* If this SAL corresponds to a breakpoint inserted using a line |
9800 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9801 | if (sal->explicit_line) |
059acae7 | 9802 | skip_prologue_sal (sal); |
c906108c SS |
9803 | } |
9804 | ||
9805 | if (sal->section == 0 && sal->symtab != NULL) | |
9806 | { | |
9807 | struct blockvector *bv; | |
c5aa993b JM |
9808 | struct block *b; |
9809 | struct symbol *sym; | |
c906108c | 9810 | |
801e3a5b | 9811 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
9812 | if (bv != NULL) |
9813 | { | |
7f0df278 | 9814 | sym = block_linkage_function (b); |
c906108c SS |
9815 | if (sym != NULL) |
9816 | { | |
9817 | fixup_symbol_section (sym, sal->symtab->objfile); | |
e27d198c | 9818 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
c906108c SS |
9819 | } |
9820 | else | |
9821 | { | |
4a64f543 MS |
9822 | /* It really is worthwhile to have the section, so we'll |
9823 | just have to look harder. This case can be executed | |
9824 | if we have line numbers but no functions (as can | |
9825 | happen in assembly source). */ | |
c906108c | 9826 | |
7cbd4a93 | 9827 | struct bound_minimal_symbol msym; |
6c95b8df PA |
9828 | struct cleanup *old_chain = save_current_space_and_thread (); |
9829 | ||
9830 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9831 | |
9832 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 9833 | if (msym.minsym) |
e27d198c | 9834 | sal->section = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
9835 | |
9836 | do_cleanups (old_chain); | |
c906108c SS |
9837 | } |
9838 | } | |
9839 | } | |
9840 | } | |
9841 | ||
9842 | void | |
fba45db2 | 9843 | break_command (char *arg, int from_tty) |
c906108c | 9844 | { |
db107f19 | 9845 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9846 | } |
9847 | ||
c906108c | 9848 | void |
fba45db2 | 9849 | tbreak_command (char *arg, int from_tty) |
c906108c | 9850 | { |
db107f19 | 9851 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9852 | } |
9853 | ||
c906108c | 9854 | static void |
fba45db2 | 9855 | hbreak_command (char *arg, int from_tty) |
c906108c | 9856 | { |
db107f19 | 9857 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9858 | } |
9859 | ||
9860 | static void | |
fba45db2 | 9861 | thbreak_command (char *arg, int from_tty) |
c906108c | 9862 | { |
db107f19 | 9863 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9864 | } |
9865 | ||
9866 | static void | |
fba45db2 | 9867 | stop_command (char *arg, int from_tty) |
c906108c | 9868 | { |
a3f17187 | 9869 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9870 | Usage: stop in <function | address>\n\ |
a3f17187 | 9871 | stop at <line>\n")); |
c906108c SS |
9872 | } |
9873 | ||
9874 | static void | |
fba45db2 | 9875 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9876 | { |
9877 | int badInput = 0; | |
9878 | ||
c5aa993b | 9879 | if (arg == (char *) NULL) |
c906108c SS |
9880 | badInput = 1; |
9881 | else if (*arg != '*') | |
9882 | { | |
9883 | char *argptr = arg; | |
9884 | int hasColon = 0; | |
9885 | ||
4a64f543 | 9886 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9887 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9888 | function/method name. */ |
c906108c | 9889 | while (*argptr && !hasColon) |
c5aa993b JM |
9890 | { |
9891 | hasColon = (*argptr == ':'); | |
9892 | argptr++; | |
9893 | } | |
c906108c SS |
9894 | |
9895 | if (hasColon) | |
c5aa993b | 9896 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9897 | else |
c5aa993b | 9898 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9899 | } |
9900 | ||
9901 | if (badInput) | |
a3f17187 | 9902 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9903 | else |
db107f19 | 9904 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9905 | } |
9906 | ||
9907 | static void | |
fba45db2 | 9908 | stopat_command (char *arg, int from_tty) |
c906108c SS |
9909 | { |
9910 | int badInput = 0; | |
9911 | ||
c5aa993b | 9912 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9913 | badInput = 1; |
9914 | else | |
9915 | { | |
9916 | char *argptr = arg; | |
9917 | int hasColon = 0; | |
9918 | ||
4a64f543 MS |
9919 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9920 | it is probably a line number. */ | |
c906108c | 9921 | while (*argptr && !hasColon) |
c5aa993b JM |
9922 | { |
9923 | hasColon = (*argptr == ':'); | |
9924 | argptr++; | |
9925 | } | |
c906108c SS |
9926 | |
9927 | if (hasColon) | |
c5aa993b | 9928 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9929 | else |
c5aa993b | 9930 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9931 | } |
9932 | ||
9933 | if (badInput) | |
a3f17187 | 9934 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9935 | else |
db107f19 | 9936 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9937 | } |
9938 | ||
e7e0cddf SS |
9939 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9940 | with a prewired command list consisting of a single output command, | |
9941 | built from extra arguments supplied on the dprintf command | |
9942 | line. */ | |
9943 | ||
da821c7b | 9944 | static void |
e7e0cddf SS |
9945 | dprintf_command (char *arg, int from_tty) |
9946 | { | |
9947 | create_breakpoint (get_current_arch (), | |
9948 | arg, | |
9949 | NULL, 0, NULL, 1 /* parse arg */, | |
9950 | 0, bp_dprintf, | |
9951 | 0 /* Ignore count */, | |
9952 | pending_break_support, | |
9953 | &dprintf_breakpoint_ops, | |
9954 | from_tty, | |
9955 | 1 /* enabled */, | |
9956 | 0 /* internal */, | |
9957 | 0); | |
9958 | } | |
9959 | ||
d3ce09f5 SS |
9960 | static void |
9961 | agent_printf_command (char *arg, int from_tty) | |
9962 | { | |
9963 | error (_("May only run agent-printf on the target")); | |
9964 | } | |
9965 | ||
f1310107 TJB |
9966 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9967 | ranged breakpoints. */ | |
9968 | ||
9969 | static int | |
9970 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
9971 | struct address_space *aspace, | |
09ac7c10 TT |
9972 | CORE_ADDR bp_addr, |
9973 | const struct target_waitstatus *ws) | |
f1310107 | 9974 | { |
09ac7c10 | 9975 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9976 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9977 | return 0; |
9978 | ||
f1310107 TJB |
9979 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9980 | bl->length, aspace, bp_addr); | |
9981 | } | |
9982 | ||
9983 | /* Implement the "resources_needed" breakpoint_ops method for | |
9984 | ranged breakpoints. */ | |
9985 | ||
9986 | static int | |
9987 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9988 | { | |
9989 | return target_ranged_break_num_registers (); | |
9990 | } | |
9991 | ||
9992 | /* Implement the "print_it" breakpoint_ops method for | |
9993 | ranged breakpoints. */ | |
9994 | ||
9995 | static enum print_stop_action | |
348d480f | 9996 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9997 | { |
348d480f | 9998 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9999 | struct bp_location *bl = b->loc; |
79a45e25 | 10000 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10001 | |
10002 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10003 | ||
10004 | /* Ranged breakpoints have only one location. */ | |
10005 | gdb_assert (bl && bl->next == NULL); | |
10006 | ||
10007 | annotate_breakpoint (b->number); | |
10008 | if (b->disposition == disp_del) | |
10009 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10010 | else | |
10011 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10012 | if (ui_out_is_mi_like_p (uiout)) | |
10013 | { | |
10014 | ui_out_field_string (uiout, "reason", | |
10015 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10016 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10017 | } | |
10018 | ui_out_field_int (uiout, "bkptno", b->number); | |
10019 | ui_out_text (uiout, ", "); | |
10020 | ||
10021 | return PRINT_SRC_AND_LOC; | |
10022 | } | |
10023 | ||
10024 | /* Implement the "print_one" breakpoint_ops method for | |
10025 | ranged breakpoints. */ | |
10026 | ||
10027 | static void | |
10028 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10029 | struct bp_location **last_loc) | |
10030 | { | |
10031 | struct bp_location *bl = b->loc; | |
10032 | struct value_print_options opts; | |
79a45e25 | 10033 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10034 | |
10035 | /* Ranged breakpoints have only one location. */ | |
10036 | gdb_assert (bl && bl->next == NULL); | |
10037 | ||
10038 | get_user_print_options (&opts); | |
10039 | ||
10040 | if (opts.addressprint) | |
10041 | /* We don't print the address range here, it will be printed later | |
10042 | by print_one_detail_ranged_breakpoint. */ | |
10043 | ui_out_field_skip (uiout, "addr"); | |
10044 | annotate_field (5); | |
10045 | print_breakpoint_location (b, bl); | |
10046 | *last_loc = bl; | |
10047 | } | |
10048 | ||
10049 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10050 | ranged breakpoints. */ | |
10051 | ||
10052 | static void | |
10053 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10054 | struct ui_out *uiout) | |
10055 | { | |
10056 | CORE_ADDR address_start, address_end; | |
10057 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10058 | struct ui_file *stb = mem_fileopen (); |
10059 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10060 | |
10061 | gdb_assert (bl); | |
10062 | ||
10063 | address_start = bl->address; | |
10064 | address_end = address_start + bl->length - 1; | |
10065 | ||
10066 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10067 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10068 | print_core_address (bl->gdbarch, address_start), |
10069 | print_core_address (bl->gdbarch, address_end)); | |
10070 | ui_out_field_stream (uiout, "addr", stb); | |
10071 | ui_out_text (uiout, "\n"); | |
10072 | ||
10073 | do_cleanups (cleanup); | |
10074 | } | |
10075 | ||
10076 | /* Implement the "print_mention" breakpoint_ops method for | |
10077 | ranged breakpoints. */ | |
10078 | ||
10079 | static void | |
10080 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10081 | { | |
10082 | struct bp_location *bl = b->loc; | |
79a45e25 | 10083 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10084 | |
10085 | gdb_assert (bl); | |
10086 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10087 | ||
10088 | if (ui_out_is_mi_like_p (uiout)) | |
10089 | return; | |
10090 | ||
10091 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10092 | b->number, paddress (bl->gdbarch, bl->address), | |
10093 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10094 | } | |
10095 | ||
10096 | /* Implement the "print_recreate" breakpoint_ops method for | |
10097 | ranged breakpoints. */ | |
10098 | ||
10099 | static void | |
10100 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10101 | { | |
10102 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10103 | b->addr_string_range_end); | |
d9b3f62e | 10104 | print_recreate_thread (b, fp); |
f1310107 TJB |
10105 | } |
10106 | ||
10107 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10108 | ||
2060206e | 10109 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10110 | |
10111 | /* Find the address where the end of the breakpoint range should be | |
10112 | placed, given the SAL of the end of the range. This is so that if | |
10113 | the user provides a line number, the end of the range is set to the | |
10114 | last instruction of the given line. */ | |
10115 | ||
10116 | static CORE_ADDR | |
10117 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10118 | { | |
10119 | CORE_ADDR end; | |
10120 | ||
10121 | /* If the user provided a PC value, use it. Otherwise, | |
10122 | find the address of the end of the given location. */ | |
10123 | if (sal.explicit_pc) | |
10124 | end = sal.pc; | |
10125 | else | |
10126 | { | |
10127 | int ret; | |
10128 | CORE_ADDR start; | |
10129 | ||
10130 | ret = find_line_pc_range (sal, &start, &end); | |
10131 | if (!ret) | |
10132 | error (_("Could not find location of the end of the range.")); | |
10133 | ||
10134 | /* find_line_pc_range returns the start of the next line. */ | |
10135 | end--; | |
10136 | } | |
10137 | ||
10138 | return end; | |
10139 | } | |
10140 | ||
10141 | /* Implement the "break-range" CLI command. */ | |
10142 | ||
10143 | static void | |
10144 | break_range_command (char *arg, int from_tty) | |
10145 | { | |
10146 | char *arg_start, *addr_string_start, *addr_string_end; | |
10147 | struct linespec_result canonical_start, canonical_end; | |
10148 | int bp_count, can_use_bp, length; | |
10149 | CORE_ADDR end; | |
10150 | struct breakpoint *b; | |
10151 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10152 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10153 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10154 | |
10155 | /* We don't support software ranged breakpoints. */ | |
10156 | if (target_ranged_break_num_registers () < 0) | |
10157 | error (_("This target does not support hardware ranged breakpoints.")); | |
10158 | ||
10159 | bp_count = hw_breakpoint_used_count (); | |
10160 | bp_count += target_ranged_break_num_registers (); | |
10161 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10162 | bp_count, 0); | |
10163 | if (can_use_bp < 0) | |
10164 | error (_("Hardware breakpoints used exceeds limit.")); | |
10165 | ||
f8eba3c6 | 10166 | arg = skip_spaces (arg); |
f1310107 TJB |
10167 | if (arg == NULL || arg[0] == '\0') |
10168 | error(_("No address range specified.")); | |
10169 | ||
f1310107 TJB |
10170 | init_linespec_result (&canonical_start); |
10171 | ||
f8eba3c6 TT |
10172 | arg_start = arg; |
10173 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10174 | |
f8eba3c6 | 10175 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10176 | |
10177 | if (arg[0] != ',') | |
10178 | error (_("Too few arguments.")); | |
f8eba3c6 | 10179 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10180 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10181 | |
10182 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10183 | ||
10184 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10185 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10186 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10187 | ||
f8eba3c6 TT |
10188 | sal_start = lsal_start->sals.sals[0]; |
10189 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10190 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10191 | |
10192 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10193 | arg = skip_spaces (arg); |
f1310107 TJB |
10194 | |
10195 | /* Parse the end location. */ | |
10196 | ||
f1310107 TJB |
10197 | init_linespec_result (&canonical_end); |
10198 | arg_start = arg; | |
10199 | ||
f8eba3c6 | 10200 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10201 | parse_breakpoint_sals because we need to specify the start location's |
10202 | symtab and line as the default symtab and line for the end of the | |
10203 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10204 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10205 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10206 | sal_start.symtab, sal_start.line, | |
10207 | &canonical_end, NULL, NULL); | |
10208 | ||
10209 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10210 | |
f8eba3c6 | 10211 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10212 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10213 | |
10214 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10215 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10216 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10217 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10218 | ||
f8eba3c6 TT |
10219 | sal_end = lsal_end->sals.sals[0]; |
10220 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10221 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10222 | |
10223 | end = find_breakpoint_range_end (sal_end); | |
10224 | if (sal_start.pc > end) | |
177b42fe | 10225 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10226 | |
10227 | length = end - sal_start.pc + 1; | |
10228 | if (length < 0) | |
10229 | /* Length overflowed. */ | |
10230 | error (_("Address range too large.")); | |
10231 | else if (length == 1) | |
10232 | { | |
10233 | /* This range is simple enough to be handled by | |
10234 | the `hbreak' command. */ | |
10235 | hbreak_command (addr_string_start, 1); | |
10236 | ||
10237 | do_cleanups (cleanup_bkpt); | |
10238 | ||
10239 | return; | |
10240 | } | |
10241 | ||
10242 | /* Now set up the breakpoint. */ | |
10243 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10244 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10245 | set_breakpoint_count (breakpoint_count + 1); |
10246 | b->number = breakpoint_count; | |
10247 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10248 | b->addr_string = xstrdup (addr_string_start); |
10249 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10250 | b->loc->length = length; |
10251 | ||
f8eba3c6 | 10252 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10253 | |
10254 | mention (b); | |
8d3788bd | 10255 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
10256 | update_global_location_list (1); |
10257 | } | |
10258 | ||
4a64f543 MS |
10259 | /* Return non-zero if EXP is verified as constant. Returned zero |
10260 | means EXP is variable. Also the constant detection may fail for | |
10261 | some constant expressions and in such case still falsely return | |
10262 | zero. */ | |
2e6e3d9c | 10263 | |
65d79d4b SDJ |
10264 | static int |
10265 | watchpoint_exp_is_const (const struct expression *exp) | |
10266 | { | |
10267 | int i = exp->nelts; | |
10268 | ||
10269 | while (i > 0) | |
10270 | { | |
10271 | int oplenp, argsp; | |
10272 | ||
10273 | /* We are only interested in the descriptor of each element. */ | |
10274 | operator_length (exp, i, &oplenp, &argsp); | |
10275 | i -= oplenp; | |
10276 | ||
10277 | switch (exp->elts[i].opcode) | |
10278 | { | |
10279 | case BINOP_ADD: | |
10280 | case BINOP_SUB: | |
10281 | case BINOP_MUL: | |
10282 | case BINOP_DIV: | |
10283 | case BINOP_REM: | |
10284 | case BINOP_MOD: | |
10285 | case BINOP_LSH: | |
10286 | case BINOP_RSH: | |
10287 | case BINOP_LOGICAL_AND: | |
10288 | case BINOP_LOGICAL_OR: | |
10289 | case BINOP_BITWISE_AND: | |
10290 | case BINOP_BITWISE_IOR: | |
10291 | case BINOP_BITWISE_XOR: | |
10292 | case BINOP_EQUAL: | |
10293 | case BINOP_NOTEQUAL: | |
10294 | case BINOP_LESS: | |
10295 | case BINOP_GTR: | |
10296 | case BINOP_LEQ: | |
10297 | case BINOP_GEQ: | |
10298 | case BINOP_REPEAT: | |
10299 | case BINOP_COMMA: | |
10300 | case BINOP_EXP: | |
10301 | case BINOP_MIN: | |
10302 | case BINOP_MAX: | |
10303 | case BINOP_INTDIV: | |
10304 | case BINOP_CONCAT: | |
10305 | case BINOP_IN: | |
10306 | case BINOP_RANGE: | |
10307 | case TERNOP_COND: | |
10308 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10309 | |
10310 | case OP_LONG: | |
10311 | case OP_DOUBLE: | |
10312 | case OP_DECFLOAT: | |
10313 | case OP_LAST: | |
10314 | case OP_COMPLEX: | |
10315 | case OP_STRING: | |
65d79d4b SDJ |
10316 | case OP_ARRAY: |
10317 | case OP_TYPE: | |
608b4967 TT |
10318 | case OP_TYPEOF: |
10319 | case OP_DECLTYPE: | |
65d79d4b SDJ |
10320 | case OP_NAME: |
10321 | case OP_OBJC_NSSTRING: | |
10322 | ||
10323 | case UNOP_NEG: | |
10324 | case UNOP_LOGICAL_NOT: | |
10325 | case UNOP_COMPLEMENT: | |
10326 | case UNOP_ADDR: | |
10327 | case UNOP_HIGH: | |
aeaa2474 | 10328 | case UNOP_CAST: |
9eaf6705 TT |
10329 | |
10330 | case UNOP_CAST_TYPE: | |
10331 | case UNOP_REINTERPRET_CAST: | |
10332 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10333 | /* Unary, binary and ternary operators: We have to check |
10334 | their operands. If they are constant, then so is the | |
10335 | result of that operation. For instance, if A and B are | |
10336 | determined to be constants, then so is "A + B". | |
10337 | ||
10338 | UNOP_IND is one exception to the rule above, because the | |
10339 | value of *ADDR is not necessarily a constant, even when | |
10340 | ADDR is. */ | |
65d79d4b SDJ |
10341 | break; |
10342 | ||
10343 | case OP_VAR_VALUE: | |
10344 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10345 | |
65d79d4b | 10346 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10347 | possible that a buggy compiler could mark a variable as |
10348 | constant even when it is not, and TYPE_CONST would return | |
10349 | true in this case, while SYMBOL_CLASS wouldn't. | |
10350 | ||
10351 | We also have to check for function symbols because they | |
10352 | are always constant. */ | |
65d79d4b SDJ |
10353 | { |
10354 | struct symbol *s = exp->elts[i + 2].symbol; | |
10355 | ||
10356 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10357 | && SYMBOL_CLASS (s) != LOC_CONST | |
10358 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10359 | return 0; | |
10360 | break; | |
10361 | } | |
10362 | ||
10363 | /* The default action is to return 0 because we are using | |
10364 | the optimistic approach here: If we don't know something, | |
10365 | then it is not a constant. */ | |
10366 | default: | |
10367 | return 0; | |
10368 | } | |
10369 | } | |
10370 | ||
10371 | return 1; | |
10372 | } | |
10373 | ||
3a5c3e22 PA |
10374 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10375 | ||
10376 | static void | |
10377 | dtor_watchpoint (struct breakpoint *self) | |
10378 | { | |
10379 | struct watchpoint *w = (struct watchpoint *) self; | |
10380 | ||
10381 | xfree (w->cond_exp); | |
10382 | xfree (w->exp); | |
10383 | xfree (w->exp_string); | |
10384 | xfree (w->exp_string_reparse); | |
10385 | value_free (w->val); | |
10386 | ||
10387 | base_breakpoint_ops.dtor (self); | |
10388 | } | |
10389 | ||
348d480f PA |
10390 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10391 | ||
10392 | static void | |
10393 | re_set_watchpoint (struct breakpoint *b) | |
10394 | { | |
3a5c3e22 PA |
10395 | struct watchpoint *w = (struct watchpoint *) b; |
10396 | ||
348d480f PA |
10397 | /* Watchpoint can be either on expression using entirely global |
10398 | variables, or it can be on local variables. | |
10399 | ||
10400 | Watchpoints of the first kind are never auto-deleted, and even | |
10401 | persist across program restarts. Since they can use variables | |
10402 | from shared libraries, we need to reparse expression as libraries | |
10403 | are loaded and unloaded. | |
10404 | ||
10405 | Watchpoints on local variables can also change meaning as result | |
10406 | of solib event. For example, if a watchpoint uses both a local | |
10407 | and a global variables in expression, it's a local watchpoint, | |
10408 | but unloading of a shared library will make the expression | |
10409 | invalid. This is not a very common use case, but we still | |
10410 | re-evaluate expression, to avoid surprises to the user. | |
10411 | ||
10412 | Note that for local watchpoints, we re-evaluate it only if | |
10413 | watchpoints frame id is still valid. If it's not, it means the | |
10414 | watchpoint is out of scope and will be deleted soon. In fact, | |
10415 | I'm not sure we'll ever be called in this case. | |
10416 | ||
10417 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10418 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10419 | |
3a5c3e22 PA |
10420 | Don't do anything about disabled watchpoints, since they will be |
10421 | reevaluated again when enabled. */ | |
10422 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10423 | } |
10424 | ||
77b06cd7 TJB |
10425 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10426 | ||
10427 | static int | |
10428 | insert_watchpoint (struct bp_location *bl) | |
10429 | { | |
3a5c3e22 PA |
10430 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10431 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10432 | |
10433 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10434 | w->cond_exp); |
77b06cd7 TJB |
10435 | } |
10436 | ||
10437 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10438 | ||
10439 | static int | |
10440 | remove_watchpoint (struct bp_location *bl) | |
10441 | { | |
3a5c3e22 PA |
10442 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10443 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10444 | |
10445 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10446 | w->cond_exp); |
e09342b5 TJB |
10447 | } |
10448 | ||
e09342b5 | 10449 | static int |
348d480f | 10450 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10451 | struct address_space *aspace, CORE_ADDR bp_addr, |
10452 | const struct target_waitstatus *ws) | |
e09342b5 | 10453 | { |
348d480f | 10454 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10455 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10456 | |
348d480f PA |
10457 | /* Continuable hardware watchpoints are treated as non-existent if the |
10458 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10459 | some data address). Otherwise gdb won't stop on a break instruction | |
10460 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10461 | been defined. Also skip watchpoints which we know did not trigger | |
10462 | (did not match the data address). */ | |
10463 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10464 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10465 | return 0; |
9c06b0b4 | 10466 | |
348d480f | 10467 | return 1; |
9c06b0b4 TJB |
10468 | } |
10469 | ||
348d480f PA |
10470 | static void |
10471 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10472 | { |
348d480f | 10473 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10474 | |
348d480f | 10475 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10476 | } |
10477 | ||
10478 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10479 | hardware watchpoints. */ |
9c06b0b4 TJB |
10480 | |
10481 | static int | |
348d480f | 10482 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10483 | { |
3a5c3e22 PA |
10484 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10485 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10486 | |
10487 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10488 | } |
10489 | ||
10490 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10491 | hardware watchpoints. */ |
9c06b0b4 TJB |
10492 | |
10493 | static int | |
348d480f | 10494 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10495 | { |
efa80663 PA |
10496 | /* Read and access watchpoints only work with hardware support. */ |
10497 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10498 | } |
10499 | ||
9c06b0b4 | 10500 | static enum print_stop_action |
348d480f | 10501 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10502 | { |
348d480f PA |
10503 | struct cleanup *old_chain; |
10504 | struct breakpoint *b; | |
f99d8bf4 | 10505 | struct ui_file *stb; |
348d480f | 10506 | enum print_stop_action result; |
3a5c3e22 | 10507 | struct watchpoint *w; |
79a45e25 | 10508 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10509 | |
10510 | gdb_assert (bs->bp_location_at != NULL); | |
10511 | ||
348d480f | 10512 | b = bs->breakpoint_at; |
3a5c3e22 | 10513 | w = (struct watchpoint *) b; |
348d480f | 10514 | |
f99d8bf4 PA |
10515 | stb = mem_fileopen (); |
10516 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10517 | |
10518 | switch (b->type) | |
10519 | { | |
348d480f | 10520 | case bp_watchpoint: |
9c06b0b4 TJB |
10521 | case bp_hardware_watchpoint: |
10522 | annotate_watchpoint (b->number); | |
10523 | if (ui_out_is_mi_like_p (uiout)) | |
10524 | ui_out_field_string | |
10525 | (uiout, "reason", | |
10526 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10527 | mention (b); |
10528 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10529 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10530 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10531 | ui_out_field_stream (uiout, "old", stb); |
10532 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10533 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10534 | ui_out_field_stream (uiout, "new", stb); |
10535 | ui_out_text (uiout, "\n"); | |
10536 | /* More than one watchpoint may have been triggered. */ | |
10537 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10538 | break; |
10539 | ||
10540 | case bp_read_watchpoint: | |
10541 | if (ui_out_is_mi_like_p (uiout)) | |
10542 | ui_out_field_string | |
10543 | (uiout, "reason", | |
10544 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10545 | mention (b); |
10546 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10547 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10548 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10549 | ui_out_field_stream (uiout, "value", stb); |
10550 | ui_out_text (uiout, "\n"); | |
10551 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10552 | break; |
10553 | ||
10554 | case bp_access_watchpoint: | |
348d480f PA |
10555 | if (bs->old_val != NULL) |
10556 | { | |
10557 | annotate_watchpoint (b->number); | |
10558 | if (ui_out_is_mi_like_p (uiout)) | |
10559 | ui_out_field_string | |
10560 | (uiout, "reason", | |
10561 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10562 | mention (b); | |
10563 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10564 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10565 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10566 | ui_out_field_stream (uiout, "old", stb); |
10567 | ui_out_text (uiout, "\nNew value = "); | |
10568 | } | |
10569 | else | |
10570 | { | |
10571 | mention (b); | |
10572 | if (ui_out_is_mi_like_p (uiout)) | |
10573 | ui_out_field_string | |
10574 | (uiout, "reason", | |
10575 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10576 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10577 | ui_out_text (uiout, "\nValue = "); | |
10578 | } | |
f99d8bf4 | 10579 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10580 | ui_out_field_stream (uiout, "new", stb); |
10581 | ui_out_text (uiout, "\n"); | |
10582 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10583 | break; |
10584 | default: | |
348d480f | 10585 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10586 | } |
10587 | ||
348d480f PA |
10588 | do_cleanups (old_chain); |
10589 | return result; | |
10590 | } | |
10591 | ||
10592 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10593 | watchpoints. */ | |
10594 | ||
10595 | static void | |
10596 | print_mention_watchpoint (struct breakpoint *b) | |
10597 | { | |
10598 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10599 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10600 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10601 | |
10602 | switch (b->type) | |
10603 | { | |
10604 | case bp_watchpoint: | |
10605 | ui_out_text (uiout, "Watchpoint "); | |
10606 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10607 | break; | |
10608 | case bp_hardware_watchpoint: | |
10609 | ui_out_text (uiout, "Hardware watchpoint "); | |
10610 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10611 | break; | |
10612 | case bp_read_watchpoint: | |
10613 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10614 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10615 | break; | |
10616 | case bp_access_watchpoint: | |
10617 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10618 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10619 | break; | |
10620 | default: | |
10621 | internal_error (__FILE__, __LINE__, | |
10622 | _("Invalid hardware watchpoint type.")); | |
10623 | } | |
10624 | ||
10625 | ui_out_field_int (uiout, "number", b->number); | |
10626 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10627 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10628 | do_cleanups (ui_out_chain); |
10629 | } | |
10630 | ||
10631 | /* Implement the "print_recreate" breakpoint_ops method for | |
10632 | watchpoints. */ | |
10633 | ||
10634 | static void | |
10635 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10636 | { | |
3a5c3e22 PA |
10637 | struct watchpoint *w = (struct watchpoint *) b; |
10638 | ||
348d480f PA |
10639 | switch (b->type) |
10640 | { | |
10641 | case bp_watchpoint: | |
10642 | case bp_hardware_watchpoint: | |
10643 | fprintf_unfiltered (fp, "watch"); | |
10644 | break; | |
10645 | case bp_read_watchpoint: | |
10646 | fprintf_unfiltered (fp, "rwatch"); | |
10647 | break; | |
10648 | case bp_access_watchpoint: | |
10649 | fprintf_unfiltered (fp, "awatch"); | |
10650 | break; | |
10651 | default: | |
10652 | internal_error (__FILE__, __LINE__, | |
10653 | _("Invalid watchpoint type.")); | |
10654 | } | |
10655 | ||
3a5c3e22 | 10656 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10657 | print_recreate_thread (b, fp); |
348d480f PA |
10658 | } |
10659 | ||
10660 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
10661 | ||
2060206e | 10662 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10663 | |
10664 | /* Implement the "insert" breakpoint_ops method for | |
10665 | masked hardware watchpoints. */ | |
10666 | ||
10667 | static int | |
10668 | insert_masked_watchpoint (struct bp_location *bl) | |
10669 | { | |
3a5c3e22 PA |
10670 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10671 | ||
10672 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10673 | bl->watchpoint_type); |
10674 | } | |
10675 | ||
10676 | /* Implement the "remove" breakpoint_ops method for | |
10677 | masked hardware watchpoints. */ | |
10678 | ||
10679 | static int | |
10680 | remove_masked_watchpoint (struct bp_location *bl) | |
10681 | { | |
3a5c3e22 PA |
10682 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10683 | ||
10684 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10685 | bl->watchpoint_type); |
10686 | } | |
10687 | ||
10688 | /* Implement the "resources_needed" breakpoint_ops method for | |
10689 | masked hardware watchpoints. */ | |
10690 | ||
10691 | static int | |
10692 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10693 | { | |
3a5c3e22 PA |
10694 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10695 | ||
10696 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10697 | } |
10698 | ||
10699 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10700 | masked hardware watchpoints. */ | |
10701 | ||
10702 | static int | |
10703 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10704 | { | |
10705 | return 0; | |
10706 | } | |
10707 | ||
10708 | /* Implement the "print_it" breakpoint_ops method for | |
10709 | masked hardware watchpoints. */ | |
10710 | ||
10711 | static enum print_stop_action | |
10712 | print_it_masked_watchpoint (bpstat bs) | |
10713 | { | |
10714 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10715 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10716 | |
10717 | /* Masked watchpoints have only one location. */ | |
10718 | gdb_assert (b->loc && b->loc->next == NULL); | |
10719 | ||
10720 | switch (b->type) | |
10721 | { | |
10722 | case bp_hardware_watchpoint: | |
10723 | annotate_watchpoint (b->number); | |
10724 | if (ui_out_is_mi_like_p (uiout)) | |
10725 | ui_out_field_string | |
10726 | (uiout, "reason", | |
10727 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10728 | break; | |
10729 | ||
10730 | case bp_read_watchpoint: | |
10731 | if (ui_out_is_mi_like_p (uiout)) | |
10732 | ui_out_field_string | |
10733 | (uiout, "reason", | |
10734 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10735 | break; | |
10736 | ||
10737 | case bp_access_watchpoint: | |
10738 | if (ui_out_is_mi_like_p (uiout)) | |
10739 | ui_out_field_string | |
10740 | (uiout, "reason", | |
10741 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10742 | break; | |
10743 | default: | |
10744 | internal_error (__FILE__, __LINE__, | |
10745 | _("Invalid hardware watchpoint type.")); | |
10746 | } | |
10747 | ||
10748 | mention (b); | |
9c06b0b4 TJB |
10749 | ui_out_text (uiout, _("\n\ |
10750 | Check the underlying instruction at PC for the memory\n\ | |
10751 | address and value which triggered this watchpoint.\n")); | |
10752 | ui_out_text (uiout, "\n"); | |
10753 | ||
10754 | /* More than one watchpoint may have been triggered. */ | |
10755 | return PRINT_UNKNOWN; | |
10756 | } | |
10757 | ||
10758 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10759 | masked hardware watchpoints. */ | |
10760 | ||
10761 | static void | |
10762 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10763 | struct ui_out *uiout) | |
10764 | { | |
3a5c3e22 PA |
10765 | struct watchpoint *w = (struct watchpoint *) b; |
10766 | ||
9c06b0b4 TJB |
10767 | /* Masked watchpoints have only one location. */ |
10768 | gdb_assert (b->loc && b->loc->next == NULL); | |
10769 | ||
10770 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 10771 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
10772 | ui_out_text (uiout, "\n"); |
10773 | } | |
10774 | ||
10775 | /* Implement the "print_mention" breakpoint_ops method for | |
10776 | masked hardware watchpoints. */ | |
10777 | ||
10778 | static void | |
10779 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10780 | { | |
3a5c3e22 | 10781 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10782 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10783 | struct cleanup *ui_out_chain; |
10784 | ||
10785 | switch (b->type) | |
10786 | { | |
10787 | case bp_hardware_watchpoint: | |
10788 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
10789 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10790 | break; | |
10791 | case bp_read_watchpoint: | |
10792 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
10793 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10794 | break; | |
10795 | case bp_access_watchpoint: | |
10796 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
10797 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10798 | break; | |
10799 | default: | |
10800 | internal_error (__FILE__, __LINE__, | |
10801 | _("Invalid hardware watchpoint type.")); | |
10802 | } | |
10803 | ||
10804 | ui_out_field_int (uiout, "number", b->number); | |
10805 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10806 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
10807 | do_cleanups (ui_out_chain); |
10808 | } | |
10809 | ||
10810 | /* Implement the "print_recreate" breakpoint_ops method for | |
10811 | masked hardware watchpoints. */ | |
10812 | ||
10813 | static void | |
10814 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10815 | { | |
3a5c3e22 | 10816 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10817 | char tmp[40]; |
10818 | ||
10819 | switch (b->type) | |
10820 | { | |
10821 | case bp_hardware_watchpoint: | |
10822 | fprintf_unfiltered (fp, "watch"); | |
10823 | break; | |
10824 | case bp_read_watchpoint: | |
10825 | fprintf_unfiltered (fp, "rwatch"); | |
10826 | break; | |
10827 | case bp_access_watchpoint: | |
10828 | fprintf_unfiltered (fp, "awatch"); | |
10829 | break; | |
10830 | default: | |
10831 | internal_error (__FILE__, __LINE__, | |
10832 | _("Invalid hardware watchpoint type.")); | |
10833 | } | |
10834 | ||
3a5c3e22 PA |
10835 | sprintf_vma (tmp, w->hw_wp_mask); |
10836 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10837 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10838 | } |
10839 | ||
10840 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10841 | ||
2060206e | 10842 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10843 | |
10844 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10845 | ||
10846 | static int | |
10847 | is_masked_watchpoint (const struct breakpoint *b) | |
10848 | { | |
10849 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10850 | } | |
10851 | ||
53a5351d JM |
10852 | /* accessflag: hw_write: watch write, |
10853 | hw_read: watch read, | |
10854 | hw_access: watch access (read or write) */ | |
c906108c | 10855 | static void |
bbc13ae3 | 10856 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10857 | int just_location, int internal) |
c906108c | 10858 | { |
a9634178 | 10859 | volatile struct gdb_exception e; |
d983da9c | 10860 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 10861 | struct expression *exp; |
270140bd | 10862 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10863 | struct value *val, *mark, *result; |
c906108c | 10864 | struct frame_info *frame; |
bbc13ae3 KS |
10865 | const char *exp_start = NULL; |
10866 | const char *exp_end = NULL; | |
10867 | const char *tok, *end_tok; | |
9c06b0b4 | 10868 | int toklen = -1; |
bbc13ae3 KS |
10869 | const char *cond_start = NULL; |
10870 | const char *cond_end = NULL; | |
c906108c | 10871 | enum bptype bp_type; |
37e4754d | 10872 | int thread = -1; |
0cf6dd15 | 10873 | int pc = 0; |
9c06b0b4 TJB |
10874 | /* Flag to indicate whether we are going to use masks for |
10875 | the hardware watchpoint. */ | |
10876 | int use_mask = 0; | |
10877 | CORE_ADDR mask = 0; | |
3a5c3e22 | 10878 | struct watchpoint *w; |
bbc13ae3 KS |
10879 | char *expression; |
10880 | struct cleanup *back_to; | |
c906108c | 10881 | |
37e4754d LM |
10882 | /* Make sure that we actually have parameters to parse. */ |
10883 | if (arg != NULL && arg[0] != '\0') | |
10884 | { | |
bbc13ae3 KS |
10885 | const char *value_start; |
10886 | ||
10887 | exp_end = arg + strlen (arg); | |
37e4754d | 10888 | |
9c06b0b4 TJB |
10889 | /* Look for "parameter value" pairs at the end |
10890 | of the arguments string. */ | |
bbc13ae3 | 10891 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10892 | { |
10893 | /* Skip whitespace at the end of the argument list. */ | |
10894 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10895 | tok--; | |
10896 | ||
10897 | /* Find the beginning of the last token. | |
10898 | This is the value of the parameter. */ | |
10899 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10900 | tok--; | |
10901 | value_start = tok + 1; | |
10902 | ||
10903 | /* Skip whitespace. */ | |
10904 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10905 | tok--; | |
10906 | ||
10907 | end_tok = tok; | |
10908 | ||
10909 | /* Find the beginning of the second to last token. | |
10910 | This is the parameter itself. */ | |
10911 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10912 | tok--; | |
10913 | tok++; | |
10914 | toklen = end_tok - tok + 1; | |
10915 | ||
10916 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
10917 | { | |
10918 | /* At this point we've found a "thread" token, which means | |
10919 | the user is trying to set a watchpoint that triggers | |
10920 | only in a specific thread. */ | |
10921 | char *endp; | |
37e4754d | 10922 | |
9c06b0b4 TJB |
10923 | if (thread != -1) |
10924 | error(_("You can specify only one thread.")); | |
37e4754d | 10925 | |
9c06b0b4 TJB |
10926 | /* Extract the thread ID from the next token. */ |
10927 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 10928 | |
9c06b0b4 TJB |
10929 | /* Check if the user provided a valid numeric value for the |
10930 | thread ID. */ | |
10931 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
10932 | error (_("Invalid thread ID specification %s."), value_start); | |
10933 | ||
10934 | /* Check if the thread actually exists. */ | |
10935 | if (!valid_thread_id (thread)) | |
af4908ba | 10936 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
10937 | } |
10938 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
10939 | { | |
10940 | /* We've found a "mask" token, which means the user wants to | |
10941 | create a hardware watchpoint that is going to have the mask | |
10942 | facility. */ | |
10943 | struct value *mask_value, *mark; | |
37e4754d | 10944 | |
9c06b0b4 TJB |
10945 | if (use_mask) |
10946 | error(_("You can specify only one mask.")); | |
37e4754d | 10947 | |
9c06b0b4 | 10948 | use_mask = just_location = 1; |
37e4754d | 10949 | |
9c06b0b4 TJB |
10950 | mark = value_mark (); |
10951 | mask_value = parse_to_comma_and_eval (&value_start); | |
10952 | mask = value_as_address (mask_value); | |
10953 | value_free_to_mark (mark); | |
10954 | } | |
10955 | else | |
10956 | /* We didn't recognize what we found. We should stop here. */ | |
10957 | break; | |
37e4754d | 10958 | |
9c06b0b4 TJB |
10959 | /* Truncate the string and get rid of the "parameter value" pair before |
10960 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10961 | exp_end = tok; |
9c06b0b4 | 10962 | } |
37e4754d | 10963 | } |
bbc13ae3 KS |
10964 | else |
10965 | exp_end = arg; | |
37e4754d | 10966 | |
bbc13ae3 KS |
10967 | /* Parse the rest of the arguments. From here on out, everything |
10968 | is in terms of a newly allocated string instead of the original | |
10969 | ARG. */ | |
c906108c | 10970 | innermost_block = NULL; |
bbc13ae3 KS |
10971 | expression = savestring (arg, exp_end - arg); |
10972 | back_to = make_cleanup (xfree, expression); | |
10973 | exp_start = arg = expression; | |
1bb9788d | 10974 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 10975 | exp_end = arg; |
fa8a61dc TT |
10976 | /* Remove trailing whitespace from the expression before saving it. |
10977 | This makes the eventual display of the expression string a bit | |
10978 | prettier. */ | |
10979 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10980 | --exp_end; | |
10981 | ||
65d79d4b SDJ |
10982 | /* Checking if the expression is not constant. */ |
10983 | if (watchpoint_exp_is_const (exp)) | |
10984 | { | |
10985 | int len; | |
10986 | ||
10987 | len = exp_end - exp_start; | |
10988 | while (len > 0 && isspace (exp_start[len - 1])) | |
10989 | len--; | |
10990 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10991 | } | |
10992 | ||
c906108c SS |
10993 | exp_valid_block = innermost_block; |
10994 | mark = value_mark (); | |
a1442452 | 10995 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
10996 | |
10997 | if (just_location) | |
10998 | { | |
9c06b0b4 TJB |
10999 | int ret; |
11000 | ||
06a64a0b | 11001 | exp_valid_block = NULL; |
a1442452 | 11002 | val = value_addr (result); |
06a64a0b TT |
11003 | release_value (val); |
11004 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11005 | |
11006 | if (use_mask) | |
11007 | { | |
11008 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11009 | mask); | |
11010 | if (ret == -1) | |
11011 | error (_("This target does not support masked watchpoints.")); | |
11012 | else if (ret == -2) | |
11013 | error (_("Invalid mask or memory region.")); | |
11014 | } | |
06a64a0b TT |
11015 | } |
11016 | else if (val != NULL) | |
fa4727a6 | 11017 | release_value (val); |
c906108c | 11018 | |
bbc13ae3 KS |
11019 | tok = skip_spaces_const (arg); |
11020 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11021 | |
11022 | toklen = end_tok - tok; | |
11023 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11024 | { | |
2d134ed3 PA |
11025 | struct expression *cond; |
11026 | ||
60e1c644 | 11027 | innermost_block = NULL; |
c906108c | 11028 | tok = cond_start = end_tok + 1; |
1bb9788d | 11029 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11030 | |
11031 | /* The watchpoint expression may not be local, but the condition | |
11032 | may still be. E.g.: `watch global if local > 0'. */ | |
11033 | cond_exp_valid_block = innermost_block; | |
11034 | ||
2d134ed3 | 11035 | xfree (cond); |
c906108c SS |
11036 | cond_end = tok; |
11037 | } | |
11038 | if (*tok) | |
8a3fe4f8 | 11039 | error (_("Junk at end of command.")); |
c906108c | 11040 | |
53a5351d | 11041 | if (accessflag == hw_read) |
c5aa993b | 11042 | bp_type = bp_read_watchpoint; |
53a5351d | 11043 | else if (accessflag == hw_access) |
c5aa993b JM |
11044 | bp_type = bp_access_watchpoint; |
11045 | else | |
11046 | bp_type = bp_hardware_watchpoint; | |
c906108c | 11047 | |
d983da9c | 11048 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11049 | |
11050 | /* If the expression is "local", then set up a "watchpoint scope" | |
11051 | breakpoint at the point where we've left the scope of the watchpoint | |
11052 | expression. Create the scope breakpoint before the watchpoint, so | |
11053 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11054 | if (exp_valid_block && frame) |
d983da9c | 11055 | { |
edb3359d DJ |
11056 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11057 | { | |
11058 | scope_breakpoint | |
a6d9a66e UW |
11059 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11060 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11061 | bp_watchpoint_scope, |
11062 | &momentary_breakpoint_ops); | |
d983da9c | 11063 | |
edb3359d | 11064 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11065 | |
edb3359d DJ |
11066 | /* Automatically delete the breakpoint when it hits. */ |
11067 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11068 | |
edb3359d DJ |
11069 | /* Only break in the proper frame (help with recursion). */ |
11070 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11071 | |
edb3359d | 11072 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11073 | scope_breakpoint->loc->gdbarch |
11074 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11075 | scope_breakpoint->loc->requested_address |
11076 | = frame_unwind_caller_pc (frame); | |
11077 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11078 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11079 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11080 | scope_breakpoint->type); |
11081 | } | |
d983da9c DJ |
11082 | } |
11083 | ||
c906108c | 11084 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
11085 | |
11086 | w = XCNEW (struct watchpoint); | |
11087 | b = &w->base; | |
348d480f | 11088 | if (use_mask) |
3a5c3e22 PA |
11089 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11090 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11091 | else |
3a5c3e22 PA |
11092 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11093 | &watchpoint_breakpoint_ops); | |
37e4754d | 11094 | b->thread = thread; |
b5de0fa7 | 11095 | b->disposition = disp_donttouch; |
348d480f | 11096 | b->pspace = current_program_space; |
3a5c3e22 PA |
11097 | w->exp = exp; |
11098 | w->exp_valid_block = exp_valid_block; | |
11099 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11100 | if (just_location) |
11101 | { | |
11102 | struct type *t = value_type (val); | |
11103 | CORE_ADDR addr = value_as_address (val); | |
11104 | char *name; | |
11105 | ||
11106 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11107 | name = type_to_string (t); | |
11108 | ||
3a5c3e22 | 11109 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11110 | core_addr_to_string (addr)); |
06a64a0b TT |
11111 | xfree (name); |
11112 | ||
3a5c3e22 | 11113 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11114 | (int) (exp_end - exp_start), exp_start); |
11115 | ||
06a64a0b TT |
11116 | /* The above expression is in C. */ |
11117 | b->language = language_c; | |
11118 | } | |
11119 | else | |
3a5c3e22 | 11120 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11121 | |
11122 | if (use_mask) | |
11123 | { | |
3a5c3e22 | 11124 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11125 | } |
11126 | else | |
11127 | { | |
3a5c3e22 PA |
11128 | w->val = val; |
11129 | w->val_valid = 1; | |
9c06b0b4 | 11130 | } |
77b06cd7 | 11131 | |
c906108c SS |
11132 | if (cond_start) |
11133 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11134 | else | |
11135 | b->cond_string = 0; | |
c5aa993b | 11136 | |
c906108c | 11137 | if (frame) |
f6bc2008 | 11138 | { |
3a5c3e22 PA |
11139 | w->watchpoint_frame = get_frame_id (frame); |
11140 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11141 | } |
c906108c | 11142 | else |
f6bc2008 | 11143 | { |
3a5c3e22 PA |
11144 | w->watchpoint_frame = null_frame_id; |
11145 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11146 | } |
c906108c | 11147 | |
d983da9c | 11148 | if (scope_breakpoint != NULL) |
c906108c | 11149 | { |
d983da9c DJ |
11150 | /* The scope breakpoint is related to the watchpoint. We will |
11151 | need to act on them together. */ | |
11152 | b->related_breakpoint = scope_breakpoint; | |
11153 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11154 | } |
d983da9c | 11155 | |
06a64a0b TT |
11156 | if (!just_location) |
11157 | value_free_to_mark (mark); | |
2d134ed3 | 11158 | |
a9634178 TJB |
11159 | TRY_CATCH (e, RETURN_MASK_ALL) |
11160 | { | |
11161 | /* Finally update the new watchpoint. This creates the locations | |
11162 | that should be inserted. */ | |
3a5c3e22 | 11163 | update_watchpoint (w, 1); |
a9634178 TJB |
11164 | } |
11165 | if (e.reason < 0) | |
11166 | { | |
11167 | delete_breakpoint (b); | |
11168 | throw_exception (e); | |
11169 | } | |
11170 | ||
3ea46bff | 11171 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11172 | do_cleanups (back_to); |
c906108c SS |
11173 | } |
11174 | ||
e09342b5 | 11175 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11176 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11177 | |
c906108c | 11178 | static int |
a9634178 | 11179 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11180 | { |
11181 | int found_memory_cnt = 0; | |
2e70b7b9 | 11182 | struct value *head = v; |
c906108c SS |
11183 | |
11184 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11185 | if (!can_use_hw_watchpoints) |
c906108c | 11186 | return 0; |
c5aa993b | 11187 | |
5c44784c JM |
11188 | /* Make sure that the value of the expression depends only upon |
11189 | memory contents, and values computed from them within GDB. If we | |
11190 | find any register references or function calls, we can't use a | |
11191 | hardware watchpoint. | |
11192 | ||
11193 | The idea here is that evaluating an expression generates a series | |
11194 | of values, one holding the value of every subexpression. (The | |
11195 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11196 | a*b+c.) GDB's values hold almost enough information to establish | |
11197 | the criteria given above --- they identify memory lvalues, | |
11198 | register lvalues, computed values, etcetera. So we can evaluate | |
11199 | the expression, and then scan the chain of values that leaves | |
11200 | behind to decide whether we can detect any possible change to the | |
11201 | expression's final value using only hardware watchpoints. | |
11202 | ||
11203 | However, I don't think that the values returned by inferior | |
11204 | function calls are special in any way. So this function may not | |
11205 | notice that an expression involving an inferior function call | |
11206 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11207 | for (; v; v = value_next (v)) |
c906108c | 11208 | { |
5c44784c | 11209 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11210 | { |
8464be76 DJ |
11211 | if (v != head && value_lazy (v)) |
11212 | /* A lazy memory lvalue in the chain is one that GDB never | |
11213 | needed to fetch; we either just used its address (e.g., | |
11214 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11215 | in `a,b'). This doesn't apply to HEAD; if that is | |
11216 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11217 | ; |
53a5351d | 11218 | else |
5c44784c JM |
11219 | { |
11220 | /* Ahh, memory we actually used! Check if we can cover | |
11221 | it with hardware watchpoints. */ | |
df407dfe | 11222 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11223 | |
11224 | /* We only watch structs and arrays if user asked for it | |
11225 | explicitly, never if they just happen to appear in a | |
11226 | middle of some value chain. */ | |
11227 | if (v == head | |
11228 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11229 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11230 | { | |
42ae5230 | 11231 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11232 | int len; |
11233 | int num_regs; | |
11234 | ||
a9634178 | 11235 | len = (target_exact_watchpoints |
e09342b5 TJB |
11236 | && is_scalar_type_recursive (vtype))? |
11237 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11238 | |
e09342b5 TJB |
11239 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11240 | if (!num_regs) | |
2e70b7b9 MS |
11241 | return 0; |
11242 | else | |
e09342b5 | 11243 | found_memory_cnt += num_regs; |
2e70b7b9 | 11244 | } |
5c44784c | 11245 | } |
c5aa993b | 11246 | } |
5086187c AC |
11247 | else if (VALUE_LVAL (v) != not_lval |
11248 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11249 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11250 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11251 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11252 | } |
11253 | ||
11254 | /* The expression itself looks suitable for using a hardware | |
11255 | watchpoint, but give the target machine a chance to reject it. */ | |
11256 | return found_memory_cnt; | |
11257 | } | |
11258 | ||
8b93c638 | 11259 | void |
84f4c1fe | 11260 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11261 | { |
84f4c1fe | 11262 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11263 | } |
11264 | ||
06a64a0b TT |
11265 | /* A helper function that looks for the "-location" argument and then |
11266 | calls watch_command_1. */ | |
11267 | ||
11268 | static void | |
11269 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11270 | { | |
11271 | int just_location = 0; | |
11272 | ||
11273 | if (arg | |
11274 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11275 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11276 | { | |
e9cafbcc | 11277 | arg = skip_spaces (arg); |
06a64a0b TT |
11278 | just_location = 1; |
11279 | } | |
11280 | ||
84f4c1fe | 11281 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11282 | } |
8926118c | 11283 | |
c5aa993b | 11284 | static void |
fba45db2 | 11285 | watch_command (char *arg, int from_tty) |
c906108c | 11286 | { |
06a64a0b | 11287 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11288 | } |
11289 | ||
8b93c638 | 11290 | void |
84f4c1fe | 11291 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11292 | { |
84f4c1fe | 11293 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11294 | } |
8926118c | 11295 | |
c5aa993b | 11296 | static void |
fba45db2 | 11297 | rwatch_command (char *arg, int from_tty) |
c906108c | 11298 | { |
06a64a0b | 11299 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11300 | } |
11301 | ||
8b93c638 | 11302 | void |
84f4c1fe | 11303 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11304 | { |
84f4c1fe | 11305 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11306 | } |
8926118c | 11307 | |
c5aa993b | 11308 | static void |
fba45db2 | 11309 | awatch_command (char *arg, int from_tty) |
c906108c | 11310 | { |
06a64a0b | 11311 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11312 | } |
c906108c | 11313 | \f |
c5aa993b | 11314 | |
43ff13b4 | 11315 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11316 | because it uses the mechanisms of breakpoints. */ |
11317 | ||
bfec99b2 PA |
11318 | struct until_break_command_continuation_args |
11319 | { | |
11320 | struct breakpoint *breakpoint; | |
11321 | struct breakpoint *breakpoint2; | |
186c406b | 11322 | int thread_num; |
bfec99b2 PA |
11323 | }; |
11324 | ||
43ff13b4 | 11325 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11326 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11327 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11328 | command. */ |
c2c6d25f | 11329 | static void |
fa4cd53f | 11330 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11331 | { |
bfec99b2 PA |
11332 | struct until_break_command_continuation_args *a = arg; |
11333 | ||
11334 | delete_breakpoint (a->breakpoint); | |
11335 | if (a->breakpoint2) | |
11336 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11337 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11338 | } |
11339 | ||
c906108c | 11340 | void |
ae66c1fc | 11341 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11342 | { |
11343 | struct symtabs_and_lines sals; | |
11344 | struct symtab_and_line sal; | |
8556afb4 PA |
11345 | struct frame_info *frame; |
11346 | struct gdbarch *frame_gdbarch; | |
11347 | struct frame_id stack_frame_id; | |
11348 | struct frame_id caller_frame_id; | |
c906108c | 11349 | struct breakpoint *breakpoint; |
f107f563 | 11350 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11351 | struct cleanup *old_chain; |
186c406b TT |
11352 | int thread; |
11353 | struct thread_info *tp; | |
c906108c SS |
11354 | |
11355 | clear_proceed_status (); | |
11356 | ||
11357 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11358 | this function. */ |
c5aa993b | 11359 | |
1bfeeb0f | 11360 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11361 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11362 | get_last_displayed_symtab (), |
f8eba3c6 | 11363 | get_last_displayed_line ()); |
c906108c | 11364 | else |
f8eba3c6 TT |
11365 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11366 | (struct symtab *) NULL, 0); | |
c5aa993b | 11367 | |
c906108c | 11368 | if (sals.nelts != 1) |
8a3fe4f8 | 11369 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11370 | |
c906108c | 11371 | sal = sals.sals[0]; |
4a64f543 | 11372 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11373 | |
c906108c | 11374 | if (*arg) |
8a3fe4f8 | 11375 | error (_("Junk at end of arguments.")); |
c5aa993b | 11376 | |
c906108c | 11377 | resolve_sal_pc (&sal); |
c5aa993b | 11378 | |
186c406b TT |
11379 | tp = inferior_thread (); |
11380 | thread = tp->num; | |
11381 | ||
883bc8d1 PA |
11382 | old_chain = make_cleanup (null_cleanup, NULL); |
11383 | ||
8556afb4 PA |
11384 | /* Note linespec handling above invalidates the frame chain. |
11385 | Installing a breakpoint also invalidates the frame chain (as it | |
11386 | may need to switch threads), so do any frame handling before | |
11387 | that. */ | |
11388 | ||
11389 | frame = get_selected_frame (NULL); | |
11390 | frame_gdbarch = get_frame_arch (frame); | |
11391 | stack_frame_id = get_stack_frame_id (frame); | |
11392 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11393 | |
ae66c1fc EZ |
11394 | /* Keep within the current frame, or in frames called by the current |
11395 | one. */ | |
edb3359d | 11396 | |
883bc8d1 | 11397 | if (frame_id_p (caller_frame_id)) |
c906108c | 11398 | { |
883bc8d1 PA |
11399 | struct symtab_and_line sal2; |
11400 | ||
11401 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11402 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11403 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11404 | sal2, |
11405 | caller_frame_id, | |
f107f563 VP |
11406 | bp_until); |
11407 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11408 | |
883bc8d1 | 11409 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11410 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11411 | } |
c5aa993b | 11412 | |
c70a6932 JK |
11413 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11414 | frame = NULL; | |
11415 | ||
883bc8d1 PA |
11416 | if (anywhere) |
11417 | /* If the user told us to continue until a specified location, | |
11418 | we don't specify a frame at which we need to stop. */ | |
11419 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11420 | null_frame_id, bp_until); | |
11421 | else | |
11422 | /* Otherwise, specify the selected frame, because we want to stop | |
11423 | only at the very same frame. */ | |
11424 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11425 | stack_frame_id, bp_until); | |
11426 | make_cleanup_delete_breakpoint (breakpoint); | |
11427 | ||
a493e3e2 | 11428 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11429 | |
4a64f543 MS |
11430 | /* If we are running asynchronously, and proceed call above has |
11431 | actually managed to start the target, arrange for breakpoints to | |
11432 | be deleted when the target stops. Otherwise, we're already | |
11433 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11434 | |
8ea051c5 | 11435 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11436 | { |
bfec99b2 PA |
11437 | struct until_break_command_continuation_args *args; |
11438 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11439 | |
bfec99b2 PA |
11440 | args->breakpoint = breakpoint; |
11441 | args->breakpoint2 = breakpoint2; | |
186c406b | 11442 | args->thread_num = thread; |
f107f563 VP |
11443 | |
11444 | discard_cleanups (old_chain); | |
95e54da7 PA |
11445 | add_continuation (inferior_thread (), |
11446 | until_break_command_continuation, args, | |
604ead4a | 11447 | xfree); |
f107f563 VP |
11448 | } |
11449 | else | |
c5aa993b | 11450 | do_cleanups (old_chain); |
c906108c | 11451 | } |
ae66c1fc | 11452 | |
c906108c SS |
11453 | /* This function attempts to parse an optional "if <cond>" clause |
11454 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11455 | |
c906108c SS |
11456 | Else, it returns a pointer to the condition string. (It does not |
11457 | attempt to evaluate the string against a particular block.) And, | |
11458 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11459 | if clause in the arg string. */ |
53a5351d | 11460 | |
c906108c | 11461 | static char * |
fba45db2 | 11462 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11463 | { |
c5aa993b JM |
11464 | char *cond_string; |
11465 | ||
11466 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11467 | return NULL; |
c5aa993b | 11468 | |
4a64f543 | 11469 | /* Skip the "if" keyword. */ |
c906108c | 11470 | (*arg) += 2; |
c5aa993b | 11471 | |
c906108c | 11472 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11473 | condition string. */ |
e9cafbcc | 11474 | *arg = skip_spaces (*arg); |
c906108c | 11475 | cond_string = *arg; |
c5aa993b | 11476 | |
4a64f543 MS |
11477 | /* Assume that the condition occupies the remainder of the arg |
11478 | string. */ | |
c906108c | 11479 | (*arg) += strlen (cond_string); |
c5aa993b | 11480 | |
c906108c SS |
11481 | return cond_string; |
11482 | } | |
c5aa993b | 11483 | |
c906108c SS |
11484 | /* Commands to deal with catching events, such as signals, exceptions, |
11485 | process start/exit, etc. */ | |
c5aa993b JM |
11486 | |
11487 | typedef enum | |
11488 | { | |
44feb3ce TT |
11489 | catch_fork_temporary, catch_vfork_temporary, |
11490 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11491 | } |
11492 | catch_fork_kind; | |
11493 | ||
c906108c | 11494 | static void |
cc59ec59 MS |
11495 | catch_fork_command_1 (char *arg, int from_tty, |
11496 | struct cmd_list_element *command) | |
c906108c | 11497 | { |
a6d9a66e | 11498 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11499 | char *cond_string = NULL; |
44feb3ce TT |
11500 | catch_fork_kind fork_kind; |
11501 | int tempflag; | |
11502 | ||
11503 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11504 | tempflag = (fork_kind == catch_fork_temporary | |
11505 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11506 | |
44feb3ce TT |
11507 | if (!arg) |
11508 | arg = ""; | |
e9cafbcc | 11509 | arg = skip_spaces (arg); |
c5aa993b | 11510 | |
c906108c | 11511 | /* The allowed syntax is: |
c5aa993b JM |
11512 | catch [v]fork |
11513 | catch [v]fork if <cond> | |
11514 | ||
4a64f543 | 11515 | First, check if there's an if clause. */ |
c906108c | 11516 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11517 | |
c906108c | 11518 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11519 | error (_("Junk at end of arguments.")); |
c5aa993b | 11520 | |
c906108c | 11521 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11522 | and enable reporting of such events. */ |
c5aa993b JM |
11523 | switch (fork_kind) |
11524 | { | |
44feb3ce TT |
11525 | case catch_fork_temporary: |
11526 | case catch_fork_permanent: | |
a6d9a66e | 11527 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11528 | &catch_fork_breakpoint_ops); |
c906108c | 11529 | break; |
44feb3ce TT |
11530 | case catch_vfork_temporary: |
11531 | case catch_vfork_permanent: | |
a6d9a66e | 11532 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11533 | &catch_vfork_breakpoint_ops); |
c906108c | 11534 | break; |
c5aa993b | 11535 | default: |
8a3fe4f8 | 11536 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11537 | break; |
c5aa993b | 11538 | } |
c906108c SS |
11539 | } |
11540 | ||
11541 | static void | |
cc59ec59 MS |
11542 | catch_exec_command_1 (char *arg, int from_tty, |
11543 | struct cmd_list_element *command) | |
c906108c | 11544 | { |
b4d90040 | 11545 | struct exec_catchpoint *c; |
a6d9a66e | 11546 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11547 | int tempflag; |
c5aa993b | 11548 | char *cond_string = NULL; |
c906108c | 11549 | |
44feb3ce TT |
11550 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11551 | ||
11552 | if (!arg) | |
11553 | arg = ""; | |
e9cafbcc | 11554 | arg = skip_spaces (arg); |
c906108c SS |
11555 | |
11556 | /* The allowed syntax is: | |
c5aa993b JM |
11557 | catch exec |
11558 | catch exec if <cond> | |
c906108c | 11559 | |
4a64f543 | 11560 | First, check if there's an if clause. */ |
c906108c SS |
11561 | cond_string = ep_parse_optional_if_clause (&arg); |
11562 | ||
11563 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11564 | error (_("Junk at end of arguments.")); |
c906108c | 11565 | |
b4d90040 PA |
11566 | c = XNEW (struct exec_catchpoint); |
11567 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11568 | &catch_exec_breakpoint_ops); | |
11569 | c->exec_pathname = NULL; | |
11570 | ||
3ea46bff | 11571 | install_breakpoint (0, &c->base, 1); |
c906108c | 11572 | } |
c5aa993b | 11573 | |
591f19e8 TT |
11574 | /* A helper function that returns a value indicating the kind of the |
11575 | exception catchpoint B. */ | |
11576 | ||
11577 | static enum exception_event_kind | |
11578 | classify_exception_breakpoint (struct breakpoint *b) | |
11579 | { | |
11580 | if (strstr (b->addr_string, "catch") != NULL) | |
11581 | return EX_EVENT_CATCH; | |
11582 | else if (strstr (b->addr_string, "rethrow") != NULL) | |
11583 | return EX_EVENT_RETHROW; | |
11584 | else | |
11585 | return EX_EVENT_THROW; | |
11586 | } | |
11587 | ||
3086aeae | 11588 | static enum print_stop_action |
348d480f | 11589 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 11590 | { |
79a45e25 | 11591 | struct ui_out *uiout = current_uiout; |
348d480f | 11592 | struct breakpoint *b = bs->breakpoint_at; |
591f19e8 TT |
11593 | int bp_temp; |
11594 | enum exception_event_kind kind = classify_exception_breakpoint (b); | |
3086aeae | 11595 | |
ade92717 | 11596 | annotate_catchpoint (b->number); |
3086aeae | 11597 | |
ade92717 AR |
11598 | if (b->loc->address != b->loc->requested_address) |
11599 | breakpoint_adjustment_warning (b->loc->requested_address, | |
11600 | b->loc->address, | |
11601 | b->number, 1); | |
df2b6d2d | 11602 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
11603 | ui_out_text (uiout, |
11604 | bp_temp ? "Temporary catchpoint " | |
11605 | : "Catchpoint "); | |
11606 | if (!ui_out_is_mi_like_p (uiout)) | |
11607 | ui_out_field_int (uiout, "bkptno", b->number); | |
11608 | ui_out_text (uiout, | |
591f19e8 TT |
11609 | (kind == EX_EVENT_THROW ? " (exception thrown), " |
11610 | : (kind == EX_EVENT_CATCH ? " (exception caught), " | |
11611 | : " (exception rethrown), "))); | |
ade92717 AR |
11612 | if (ui_out_is_mi_like_p (uiout)) |
11613 | { | |
11614 | ui_out_field_string (uiout, "reason", | |
11615 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
11616 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
11617 | ui_out_field_int (uiout, "bkptno", b->number); | |
11618 | } | |
3086aeae DJ |
11619 | return PRINT_SRC_AND_LOC; |
11620 | } | |
11621 | ||
11622 | static void | |
cc59ec59 MS |
11623 | print_one_exception_catchpoint (struct breakpoint *b, |
11624 | struct bp_location **last_loc) | |
3086aeae | 11625 | { |
79a45b7d | 11626 | struct value_print_options opts; |
79a45e25 | 11627 | struct ui_out *uiout = current_uiout; |
591f19e8 | 11628 | enum exception_event_kind kind = classify_exception_breakpoint (b); |
cc59ec59 | 11629 | |
79a45b7d TT |
11630 | get_user_print_options (&opts); |
11631 | if (opts.addressprint) | |
3086aeae DJ |
11632 | { |
11633 | annotate_field (4); | |
604133b5 AR |
11634 | if (b->loc == NULL || b->loc->shlib_disabled) |
11635 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
11636 | else | |
5af949e3 UW |
11637 | ui_out_field_core_addr (uiout, "addr", |
11638 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
11639 | } |
11640 | annotate_field (5); | |
604133b5 | 11641 | if (b->loc) |
a6d9a66e | 11642 | *last_loc = b->loc; |
591f19e8 TT |
11643 | |
11644 | switch (kind) | |
8ac3646f | 11645 | { |
591f19e8 | 11646 | case EX_EVENT_THROW: |
8ac3646f TT |
11647 | ui_out_field_string (uiout, "what", "exception throw"); |
11648 | if (ui_out_is_mi_like_p (uiout)) | |
11649 | ui_out_field_string (uiout, "catch-type", "throw"); | |
591f19e8 TT |
11650 | break; |
11651 | ||
11652 | case EX_EVENT_RETHROW: | |
11653 | ui_out_field_string (uiout, "what", "exception rethrow"); | |
11654 | if (ui_out_is_mi_like_p (uiout)) | |
11655 | ui_out_field_string (uiout, "catch-type", "rethrow"); | |
11656 | break; | |
11657 | ||
11658 | case EX_EVENT_CATCH: | |
8ac3646f TT |
11659 | ui_out_field_string (uiout, "what", "exception catch"); |
11660 | if (ui_out_is_mi_like_p (uiout)) | |
11661 | ui_out_field_string (uiout, "catch-type", "catch"); | |
591f19e8 | 11662 | break; |
8ac3646f | 11663 | } |
3086aeae DJ |
11664 | } |
11665 | ||
11666 | static void | |
11667 | print_mention_exception_catchpoint (struct breakpoint *b) | |
11668 | { | |
79a45e25 | 11669 | struct ui_out *uiout = current_uiout; |
ade92717 | 11670 | int bp_temp; |
591f19e8 | 11671 | enum exception_event_kind kind = classify_exception_breakpoint (b); |
ade92717 | 11672 | |
df2b6d2d | 11673 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
11674 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") |
11675 | : _("Catchpoint ")); | |
11676 | ui_out_field_int (uiout, "bkptno", b->number); | |
591f19e8 TT |
11677 | ui_out_text (uiout, (kind == EX_EVENT_THROW ? _(" (throw)") |
11678 | : (kind == EX_EVENT_CATCH ? _(" (catch)") | |
11679 | : _(" (rethrow)")))); | |
3086aeae DJ |
11680 | } |
11681 | ||
6149aea9 PA |
11682 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
11683 | catch catchpoints. */ | |
11684 | ||
11685 | static void | |
4a64f543 MS |
11686 | print_recreate_exception_catchpoint (struct breakpoint *b, |
11687 | struct ui_file *fp) | |
6149aea9 PA |
11688 | { |
11689 | int bp_temp; | |
591f19e8 | 11690 | enum exception_event_kind kind = classify_exception_breakpoint (b); |
6149aea9 PA |
11691 | |
11692 | bp_temp = b->disposition == disp_del; | |
6149aea9 | 11693 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); |
591f19e8 TT |
11694 | switch (kind) |
11695 | { | |
11696 | case EX_EVENT_THROW: | |
11697 | fprintf_unfiltered (fp, "throw"); | |
11698 | break; | |
11699 | case EX_EVENT_CATCH: | |
11700 | fprintf_unfiltered (fp, "catch"); | |
11701 | break; | |
11702 | case EX_EVENT_RETHROW: | |
11703 | fprintf_unfiltered (fp, "rethrow"); | |
11704 | break; | |
11705 | } | |
d9b3f62e | 11706 | print_recreate_thread (b, fp); |
6149aea9 PA |
11707 | } |
11708 | ||
2060206e | 11709 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
11710 | |
11711 | static int | |
11712 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
11713 | enum exception_event_kind ex_event, int from_tty) | |
11714 | { | |
604133b5 AR |
11715 | char *trigger_func_name; |
11716 | ||
3086aeae | 11717 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 11718 | trigger_func_name = "__cxa_begin_catch"; |
591f19e8 TT |
11719 | else if (ex_event == EX_EVENT_RETHROW) |
11720 | trigger_func_name = "__cxa_rethrow"; | |
3086aeae | 11721 | else |
591f19e8 TT |
11722 | { |
11723 | gdb_assert (ex_event == EX_EVENT_THROW); | |
11724 | trigger_func_name = "__cxa_throw"; | |
11725 | } | |
3086aeae | 11726 | |
8cdf0e15 | 11727 | create_breakpoint (get_current_arch (), |
e7e0cddf | 11728 | trigger_func_name, cond_string, -1, NULL, |
8cdf0e15 | 11729 | 0 /* condition and thread are valid. */, |
0fb4aa4b | 11730 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
11731 | 0, |
11732 | AUTO_BOOLEAN_TRUE /* pending */, | |
11733 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe | 11734 | 1 /* enabled */, |
44f238bb PA |
11735 | 0 /* internal */, |
11736 | 0); | |
3086aeae | 11737 | |
3086aeae DJ |
11738 | return 1; |
11739 | } | |
11740 | ||
4a64f543 | 11741 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
11742 | |
11743 | static void | |
fba45db2 KB |
11744 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
11745 | int tempflag, int from_tty) | |
c906108c | 11746 | { |
c5aa993b | 11747 | char *cond_string = NULL; |
c5aa993b | 11748 | |
44feb3ce TT |
11749 | if (!arg) |
11750 | arg = ""; | |
e9cafbcc | 11751 | arg = skip_spaces (arg); |
c5aa993b | 11752 | |
c906108c SS |
11753 | cond_string = ep_parse_optional_if_clause (&arg); |
11754 | ||
11755 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11756 | error (_("Junk at end of arguments.")); |
c906108c | 11757 | |
059fb39f | 11758 | if (ex_event != EX_EVENT_THROW |
591f19e8 TT |
11759 | && ex_event != EX_EVENT_CATCH |
11760 | && ex_event != EX_EVENT_RETHROW) | |
8a3fe4f8 | 11761 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 11762 | |
3086aeae DJ |
11763 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
11764 | return; | |
11765 | ||
8a3fe4f8 | 11766 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
11767 | } |
11768 | ||
44feb3ce TT |
11769 | /* Implementation of "catch catch" command. */ |
11770 | ||
11771 | static void | |
11772 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
11773 | { | |
11774 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 11775 | |
44feb3ce TT |
11776 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
11777 | } | |
11778 | ||
11779 | /* Implementation of "catch throw" command. */ | |
11780 | ||
11781 | static void | |
11782 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
11783 | { | |
11784 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 11785 | |
44feb3ce TT |
11786 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
11787 | } | |
11788 | ||
591f19e8 TT |
11789 | /* Implementation of "catch rethrow" command. */ |
11790 | ||
11791 | static void | |
11792 | catch_rethrow_command (char *arg, int from_tty, | |
11793 | struct cmd_list_element *command) | |
11794 | { | |
11795 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
11796 | ||
11797 | catch_exception_command_1 (EX_EVENT_RETHROW, arg, tempflag, from_tty); | |
11798 | } | |
11799 | ||
9ac4176b | 11800 | void |
28010a5d PA |
11801 | init_ada_exception_breakpoint (struct breakpoint *b, |
11802 | struct gdbarch *gdbarch, | |
11803 | struct symtab_and_line sal, | |
11804 | char *addr_string, | |
c0a91b2b | 11805 | const struct breakpoint_ops *ops, |
28010a5d PA |
11806 | int tempflag, |
11807 | int from_tty) | |
f7f9143b | 11808 | { |
f7f9143b JB |
11809 | if (from_tty) |
11810 | { | |
5af949e3 UW |
11811 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11812 | if (!loc_gdbarch) | |
11813 | loc_gdbarch = gdbarch; | |
11814 | ||
6c95b8df PA |
11815 | describe_other_breakpoints (loc_gdbarch, |
11816 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11817 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11818 | version for exception catchpoints, because two catchpoints | |
11819 | used for different exception names will use the same address. | |
11820 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11821 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11822 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11823 | the user what type of catchpoint it is. The above is good |
11824 | enough for now, though. */ | |
11825 | } | |
11826 | ||
28010a5d | 11827 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
11828 | |
11829 | b->enable_state = bp_enabled; | |
11830 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
11831 | b->addr_string = addr_string; |
11832 | b->language = language_ada; | |
f7f9143b JB |
11833 | } |
11834 | ||
a96d9b2e SDJ |
11835 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
11836 | filter list, or NULL if no filtering is required. */ | |
11837 | static VEC(int) * | |
11838 | catch_syscall_split_args (char *arg) | |
11839 | { | |
11840 | VEC(int) *result = NULL; | |
29d0bb3d | 11841 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
11842 | |
11843 | while (*arg != '\0') | |
11844 | { | |
11845 | int i, syscall_number; | |
11846 | char *endptr; | |
11847 | char cur_name[128]; | |
11848 | struct syscall s; | |
11849 | ||
11850 | /* Skip whitespace. */ | |
529480d0 | 11851 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11852 | |
11853 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
11854 | cur_name[i] = arg[i]; | |
11855 | cur_name[i] = '\0'; | |
11856 | arg += i; | |
11857 | ||
11858 | /* Check if the user provided a syscall name or a number. */ | |
11859 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
11860 | if (*endptr == '\0') | |
bccd0dd2 | 11861 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
11862 | else |
11863 | { | |
11864 | /* We have a name. Let's check if it's valid and convert it | |
11865 | to a number. */ | |
11866 | get_syscall_by_name (cur_name, &s); | |
11867 | ||
11868 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
11869 | /* Here we have to issue an error instead of a warning, |
11870 | because GDB cannot do anything useful if there's no | |
11871 | syscall number to be caught. */ | |
a96d9b2e SDJ |
11872 | error (_("Unknown syscall name '%s'."), cur_name); |
11873 | } | |
11874 | ||
11875 | /* Ok, it's valid. */ | |
11876 | VEC_safe_push (int, result, s.number); | |
11877 | } | |
11878 | ||
11879 | discard_cleanups (cleanup); | |
11880 | return result; | |
11881 | } | |
11882 | ||
11883 | /* Implement the "catch syscall" command. */ | |
11884 | ||
11885 | static void | |
cc59ec59 MS |
11886 | catch_syscall_command_1 (char *arg, int from_tty, |
11887 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
11888 | { |
11889 | int tempflag; | |
11890 | VEC(int) *filter; | |
11891 | struct syscall s; | |
11892 | struct gdbarch *gdbarch = get_current_arch (); | |
11893 | ||
11894 | /* Checking if the feature if supported. */ | |
11895 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
11896 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 11897 | this architecture yet.")); |
a96d9b2e SDJ |
11898 | |
11899 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
11900 | ||
e9cafbcc | 11901 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11902 | |
11903 | /* We need to do this first "dummy" translation in order | |
11904 | to get the syscall XML file loaded or, most important, | |
11905 | to display a warning to the user if there's no XML file | |
11906 | for his/her architecture. */ | |
11907 | get_syscall_by_number (0, &s); | |
11908 | ||
11909 | /* The allowed syntax is: | |
11910 | catch syscall | |
11911 | catch syscall <name | number> [<name | number> ... <name | number>] | |
11912 | ||
11913 | Let's check if there's a syscall name. */ | |
11914 | ||
11915 | if (arg != NULL) | |
11916 | filter = catch_syscall_split_args (arg); | |
11917 | else | |
11918 | filter = NULL; | |
11919 | ||
11920 | create_syscall_event_catchpoint (tempflag, filter, | |
11921 | &catch_syscall_breakpoint_ops); | |
11922 | } | |
11923 | ||
c906108c | 11924 | static void |
fba45db2 | 11925 | catch_command (char *arg, int from_tty) |
c906108c | 11926 | { |
44feb3ce | 11927 | error (_("Catch requires an event name.")); |
c906108c SS |
11928 | } |
11929 | \f | |
11930 | ||
11931 | static void | |
fba45db2 | 11932 | tcatch_command (char *arg, int from_tty) |
c906108c | 11933 | { |
44feb3ce | 11934 | error (_("Catch requires an event name.")); |
c906108c SS |
11935 | } |
11936 | ||
8a2c437b TT |
11937 | /* A qsort comparison function that sorts breakpoints in order. */ |
11938 | ||
11939 | static int | |
11940 | compare_breakpoints (const void *a, const void *b) | |
11941 | { | |
11942 | const breakpoint_p *ba = a; | |
11943 | uintptr_t ua = (uintptr_t) *ba; | |
11944 | const breakpoint_p *bb = b; | |
11945 | uintptr_t ub = (uintptr_t) *bb; | |
11946 | ||
11947 | if ((*ba)->number < (*bb)->number) | |
11948 | return -1; | |
11949 | else if ((*ba)->number > (*bb)->number) | |
11950 | return 1; | |
11951 | ||
11952 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11953 | the number 0. */ | |
11954 | if (ua < ub) | |
11955 | return -1; | |
94b0e70d | 11956 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11957 | } |
11958 | ||
80f8a6eb | 11959 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11960 | |
11961 | static void | |
fba45db2 | 11962 | clear_command (char *arg, int from_tty) |
c906108c | 11963 | { |
8a2c437b | 11964 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11965 | VEC(breakpoint_p) *found = 0; |
11966 | int ix; | |
c906108c SS |
11967 | int default_match; |
11968 | struct symtabs_and_lines sals; | |
11969 | struct symtab_and_line sal; | |
c906108c | 11970 | int i; |
8a2c437b | 11971 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11972 | |
11973 | if (arg) | |
11974 | { | |
39cf75f7 DE |
11975 | sals = decode_line_with_current_source (arg, |
11976 | (DECODE_LINE_FUNFIRSTLINE | |
11977 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11978 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11979 | default_match = 0; |
11980 | } | |
11981 | else | |
11982 | { | |
c5aa993b | 11983 | sals.sals = (struct symtab_and_line *) |
c906108c | 11984 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11985 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11986 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11987 | |
11988 | /* Set sal's line, symtab, pc, and pspace to the values | |
11989 | corresponding to the last call to print_frame_info. If the | |
11990 | codepoint is not valid, this will set all the fields to 0. */ | |
11991 | get_last_displayed_sal (&sal); | |
c906108c | 11992 | if (sal.symtab == 0) |
8a3fe4f8 | 11993 | error (_("No source file specified.")); |
c906108c SS |
11994 | |
11995 | sals.sals[0] = sal; | |
11996 | sals.nelts = 1; | |
11997 | ||
11998 | default_match = 1; | |
11999 | } | |
12000 | ||
4a64f543 MS |
12001 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12002 | seems, because all existing breakpoints typically have both | |
12003 | file/line and pc set. So, if clear is given file/line, we can | |
12004 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12005 | |
12006 | We only support clearing given the address explicitly | |
12007 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12008 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12009 | due to optimization, all in one block. |
4a64f543 MS |
12010 | |
12011 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12012 | PC corresponding to the same file:line, the breakpoint won't |
12013 | be cleared. We probably can still clear the breakpoint, but | |
12014 | since the other PC value is never presented to user, user | |
12015 | can only find it by guessing, and it does not seem important | |
12016 | to support that. */ | |
12017 | ||
4a64f543 MS |
12018 | /* For each line spec given, delete bps which correspond to it. Do |
12019 | it in two passes, solely to preserve the current behavior that | |
12020 | from_tty is forced true if we delete more than one | |
12021 | breakpoint. */ | |
c906108c | 12022 | |
80f8a6eb | 12023 | found = NULL; |
8a2c437b | 12024 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12025 | for (i = 0; i < sals.nelts; i++) |
12026 | { | |
05cba821 JK |
12027 | const char *sal_fullname; |
12028 | ||
c906108c | 12029 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12030 | If line given (pc == 0), clear all bpts on specified line. |
12031 | If defaulting, clear all bpts on default line | |
c906108c | 12032 | or at default pc. |
c5aa993b JM |
12033 | |
12034 | defaulting sal.pc != 0 tests to do | |
12035 | ||
12036 | 0 1 pc | |
12037 | 1 1 pc _and_ line | |
12038 | 0 0 line | |
12039 | 1 0 <can't happen> */ | |
c906108c SS |
12040 | |
12041 | sal = sals.sals[i]; | |
05cba821 JK |
12042 | sal_fullname = (sal.symtab == NULL |
12043 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12044 | |
4a64f543 | 12045 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12046 | ALL_BREAKPOINTS (b) |
c5aa993b | 12047 | { |
0d381245 | 12048 | int match = 0; |
4a64f543 | 12049 | /* Are we going to delete b? */ |
cc60f2e3 | 12050 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12051 | { |
12052 | struct bp_location *loc = b->loc; | |
12053 | for (; loc; loc = loc->next) | |
12054 | { | |
f8eba3c6 TT |
12055 | /* If the user specified file:line, don't allow a PC |
12056 | match. This matches historical gdb behavior. */ | |
12057 | int pc_match = (!sal.explicit_line | |
12058 | && sal.pc | |
12059 | && (loc->pspace == sal.pspace) | |
12060 | && (loc->address == sal.pc) | |
12061 | && (!section_is_overlay (loc->section) | |
12062 | || loc->section == sal.section)); | |
4aac40c8 TT |
12063 | int line_match = 0; |
12064 | ||
12065 | if ((default_match || sal.explicit_line) | |
2f202fde | 12066 | && loc->symtab != NULL |
05cba821 | 12067 | && sal_fullname != NULL |
4aac40c8 | 12068 | && sal.pspace == loc->pspace |
05cba821 JK |
12069 | && loc->line_number == sal.line |
12070 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12071 | sal_fullname) == 0) | |
12072 | line_match = 1; | |
4aac40c8 | 12073 | |
0d381245 VP |
12074 | if (pc_match || line_match) |
12075 | { | |
12076 | match = 1; | |
12077 | break; | |
12078 | } | |
12079 | } | |
12080 | } | |
12081 | ||
12082 | if (match) | |
d6e956e5 | 12083 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12084 | } |
80f8a6eb | 12085 | } |
8a2c437b | 12086 | |
80f8a6eb | 12087 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12088 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12089 | { |
12090 | if (arg) | |
8a3fe4f8 | 12091 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12092 | else |
8a3fe4f8 | 12093 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12094 | } |
c906108c | 12095 | |
8a2c437b TT |
12096 | /* Remove duplicates from the vec. */ |
12097 | qsort (VEC_address (breakpoint_p, found), | |
12098 | VEC_length (breakpoint_p, found), | |
12099 | sizeof (breakpoint_p), | |
12100 | compare_breakpoints); | |
12101 | prev = VEC_index (breakpoint_p, found, 0); | |
12102 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12103 | { | |
12104 | if (b == prev) | |
12105 | { | |
12106 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12107 | --ix; | |
12108 | } | |
12109 | } | |
12110 | ||
d6e956e5 | 12111 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12112 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12113 | if (from_tty) |
a3f17187 | 12114 | { |
d6e956e5 | 12115 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12116 | printf_unfiltered (_("Deleted breakpoint ")); |
12117 | else | |
12118 | printf_unfiltered (_("Deleted breakpoints ")); | |
12119 | } | |
d6e956e5 VP |
12120 | |
12121 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12122 | { |
c5aa993b | 12123 | if (from_tty) |
d6e956e5 VP |
12124 | printf_unfiltered ("%d ", b->number); |
12125 | delete_breakpoint (b); | |
c906108c | 12126 | } |
80f8a6eb MS |
12127 | if (from_tty) |
12128 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12129 | |
12130 | do_cleanups (cleanups); | |
c906108c SS |
12131 | } |
12132 | \f | |
12133 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12134 | all breakpoints that are marked for deletion, whether hit or not. | |
12135 | This is called after any breakpoint is hit, or after errors. */ | |
12136 | ||
12137 | void | |
fba45db2 | 12138 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12139 | { |
35df4500 | 12140 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12141 | |
12142 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12143 | if (bs->breakpoint_at |
12144 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12145 | && bs->stop) |
f431efe5 | 12146 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12147 | |
35df4500 | 12148 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12149 | { |
b5de0fa7 | 12150 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12151 | delete_breakpoint (b); |
12152 | } | |
c906108c SS |
12153 | } |
12154 | ||
4a64f543 MS |
12155 | /* A comparison function for bp_location AP and BP being interfaced to |
12156 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12157 | does breakpoint_address_is_meaningful say for its OWNER), | |
12158 | secondarily by ordering first bp_permanent OWNERed elements and | |
12159 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 12160 | qsort being an unstable algorithm. */ |
876fa593 JK |
12161 | |
12162 | static int | |
494cfb0f | 12163 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12164 | { |
494cfb0f JK |
12165 | struct bp_location *a = *(void **) ap; |
12166 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 12167 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
12168 | int a_perm = a->owner->enable_state == bp_permanent; |
12169 | int b_perm = b->owner->enable_state == bp_permanent; | |
12170 | ||
12171 | if (a->address != b->address) | |
12172 | return (a->address > b->address) - (a->address < b->address); | |
12173 | ||
dea2aa5f LM |
12174 | /* Sort locations at the same address by their pspace number, keeping |
12175 | locations of the same inferior (in a multi-inferior environment) | |
12176 | grouped. */ | |
12177 | ||
12178 | if (a->pspace->num != b->pspace->num) | |
12179 | return ((a->pspace->num > b->pspace->num) | |
12180 | - (a->pspace->num < b->pspace->num)); | |
12181 | ||
876fa593 JK |
12182 | /* Sort permanent breakpoints first. */ |
12183 | if (a_perm != b_perm) | |
12184 | return (a_perm < b_perm) - (a_perm > b_perm); | |
12185 | ||
c56a97f9 JK |
12186 | /* Make the internal GDB representation stable across GDB runs |
12187 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12188 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12189 | |
12190 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12191 | return ((a->owner->number > b->owner->number) |
12192 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12193 | |
12194 | return (a > b) - (a < b); | |
12195 | } | |
12196 | ||
876fa593 | 12197 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12198 | bp_location_shadow_len_after_address_max according to the current |
12199 | content of the bp_location array. */ | |
f7545552 TT |
12200 | |
12201 | static void | |
876fa593 | 12202 | bp_location_target_extensions_update (void) |
f7545552 | 12203 | { |
876fa593 JK |
12204 | struct bp_location *bl, **blp_tmp; |
12205 | ||
12206 | bp_location_placed_address_before_address_max = 0; | |
12207 | bp_location_shadow_len_after_address_max = 0; | |
12208 | ||
12209 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12210 | { | |
12211 | CORE_ADDR start, end, addr; | |
12212 | ||
12213 | if (!bp_location_has_shadow (bl)) | |
12214 | continue; | |
12215 | ||
12216 | start = bl->target_info.placed_address; | |
12217 | end = start + bl->target_info.shadow_len; | |
12218 | ||
12219 | gdb_assert (bl->address >= start); | |
12220 | addr = bl->address - start; | |
12221 | if (addr > bp_location_placed_address_before_address_max) | |
12222 | bp_location_placed_address_before_address_max = addr; | |
12223 | ||
12224 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12225 | ||
12226 | gdb_assert (bl->address < end); | |
12227 | addr = end - bl->address; | |
12228 | if (addr > bp_location_shadow_len_after_address_max) | |
12229 | bp_location_shadow_len_after_address_max = addr; | |
12230 | } | |
f7545552 TT |
12231 | } |
12232 | ||
1e4d1764 YQ |
12233 | /* Download tracepoint locations if they haven't been. */ |
12234 | ||
12235 | static void | |
12236 | download_tracepoint_locations (void) | |
12237 | { | |
7ed2c994 | 12238 | struct breakpoint *b; |
1e4d1764 YQ |
12239 | struct cleanup *old_chain; |
12240 | ||
12241 | if (!target_can_download_tracepoint ()) | |
12242 | return; | |
12243 | ||
12244 | old_chain = save_current_space_and_thread (); | |
12245 | ||
7ed2c994 | 12246 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12247 | { |
7ed2c994 | 12248 | struct bp_location *bl; |
1e4d1764 | 12249 | struct tracepoint *t; |
f2a8bc8a | 12250 | int bp_location_downloaded = 0; |
1e4d1764 | 12251 | |
7ed2c994 | 12252 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12253 | ? !may_insert_fast_tracepoints |
12254 | : !may_insert_tracepoints)) | |
12255 | continue; | |
12256 | ||
7ed2c994 YQ |
12257 | for (bl = b->loc; bl; bl = bl->next) |
12258 | { | |
12259 | /* In tracepoint, locations are _never_ duplicated, so | |
12260 | should_be_inserted is equivalent to | |
12261 | unduplicated_should_be_inserted. */ | |
12262 | if (!should_be_inserted (bl) || bl->inserted) | |
12263 | continue; | |
1e4d1764 | 12264 | |
7ed2c994 | 12265 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12266 | |
7ed2c994 | 12267 | target_download_tracepoint (bl); |
1e4d1764 | 12268 | |
7ed2c994 | 12269 | bl->inserted = 1; |
f2a8bc8a | 12270 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12271 | } |
12272 | t = (struct tracepoint *) b; | |
12273 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12274 | if (bp_location_downloaded) |
12275 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12276 | } |
12277 | ||
12278 | do_cleanups (old_chain); | |
12279 | } | |
12280 | ||
934709f0 PW |
12281 | /* Swap the insertion/duplication state between two locations. */ |
12282 | ||
12283 | static void | |
12284 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12285 | { | |
12286 | const int left_inserted = left->inserted; | |
12287 | const int left_duplicate = left->duplicate; | |
b775012e | 12288 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12289 | const struct bp_target_info left_target_info = left->target_info; |
12290 | ||
1e4d1764 YQ |
12291 | /* Locations of tracepoints can never be duplicated. */ |
12292 | if (is_tracepoint (left->owner)) | |
12293 | gdb_assert (!left->duplicate); | |
12294 | if (is_tracepoint (right->owner)) | |
12295 | gdb_assert (!right->duplicate); | |
12296 | ||
934709f0 PW |
12297 | left->inserted = right->inserted; |
12298 | left->duplicate = right->duplicate; | |
b775012e | 12299 | left->needs_update = right->needs_update; |
934709f0 PW |
12300 | left->target_info = right->target_info; |
12301 | right->inserted = left_inserted; | |
12302 | right->duplicate = left_duplicate; | |
b775012e | 12303 | right->needs_update = left_needs_update; |
934709f0 PW |
12304 | right->target_info = left_target_info; |
12305 | } | |
12306 | ||
b775012e LM |
12307 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12308 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12309 | conditions on the target's side. Such conditions need to be updated on | |
12310 | the target. */ | |
12311 | ||
12312 | static void | |
12313 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12314 | { | |
12315 | struct bp_location **locp = NULL, **loc2p; | |
12316 | struct bp_location *loc; | |
12317 | CORE_ADDR address = 0; | |
12318 | int pspace_num; | |
12319 | ||
12320 | address = bl->address; | |
12321 | pspace_num = bl->pspace->num; | |
12322 | ||
12323 | /* This is only meaningful if the target is | |
12324 | evaluating conditions and if the user has | |
12325 | opted for condition evaluation on the target's | |
12326 | side. */ | |
12327 | if (gdb_evaluates_breakpoint_condition_p () | |
12328 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12329 | return; | |
12330 | ||
12331 | /* Flag all breakpoint locations with this address and | |
12332 | the same program space as the location | |
12333 | as "its condition has changed". We need to | |
12334 | update the conditions on the target's side. */ | |
12335 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12336 | { | |
12337 | loc = *loc2p; | |
12338 | ||
12339 | if (!is_breakpoint (loc->owner) | |
12340 | || pspace_num != loc->pspace->num) | |
12341 | continue; | |
12342 | ||
12343 | /* Flag the location appropriately. We use a different state to | |
12344 | let everyone know that we already updated the set of locations | |
12345 | with addr bl->address and program space bl->pspace. This is so | |
12346 | we don't have to keep calling these functions just to mark locations | |
12347 | that have already been marked. */ | |
12348 | loc->condition_changed = condition_updated; | |
12349 | ||
12350 | /* Free the agent expression bytecode as well. We will compute | |
12351 | it later on. */ | |
12352 | if (loc->cond_bytecode) | |
12353 | { | |
12354 | free_agent_expr (loc->cond_bytecode); | |
12355 | loc->cond_bytecode = NULL; | |
12356 | } | |
12357 | } | |
12358 | } | |
12359 | ||
4cd9bd08 | 12360 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
12361 | into the inferior, only remove already-inserted locations that no |
12362 | longer should be inserted. Functions that delete a breakpoint or | |
12363 | breakpoints should pass false, so that deleting a breakpoint | |
12364 | doesn't have the side effect of inserting the locations of other | |
12365 | breakpoints that are marked not-inserted, but should_be_inserted | |
12366 | returns true on them. | |
12367 | ||
12368 | This behaviour is useful is situations close to tear-down -- e.g., | |
12369 | after an exec, while the target still has execution, but breakpoint | |
12370 | shadows of the previous executable image should *NOT* be restored | |
12371 | to the new image; or before detaching, where the target still has | |
12372 | execution and wants to delete breakpoints from GDB's lists, and all | |
12373 | breakpoints had already been removed from the inferior. */ | |
12374 | ||
0d381245 | 12375 | static void |
b60e7edf | 12376 | update_global_location_list (int should_insert) |
0d381245 | 12377 | { |
74960c60 | 12378 | struct breakpoint *b; |
876fa593 | 12379 | struct bp_location **locp, *loc; |
f7545552 | 12380 | struct cleanup *cleanups; |
b775012e LM |
12381 | /* Last breakpoint location address that was marked for update. */ |
12382 | CORE_ADDR last_addr = 0; | |
12383 | /* Last breakpoint location program space that was marked for update. */ | |
12384 | int last_pspace_num = -1; | |
f7545552 | 12385 | |
2d134ed3 PA |
12386 | /* Used in the duplicates detection below. When iterating over all |
12387 | bp_locations, points to the first bp_location of a given address. | |
12388 | Breakpoints and watchpoints of different types are never | |
12389 | duplicates of each other. Keep one pointer for each type of | |
12390 | breakpoint/watchpoint, so we only need to loop over all locations | |
12391 | once. */ | |
12392 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12393 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12394 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12395 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12396 | |
4a64f543 MS |
12397 | /* Saved former bp_location array which we compare against the newly |
12398 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12399 | struct bp_location **old_location, **old_locp; |
12400 | unsigned old_location_count; | |
12401 | ||
12402 | old_location = bp_location; | |
12403 | old_location_count = bp_location_count; | |
12404 | bp_location = NULL; | |
12405 | bp_location_count = 0; | |
12406 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12407 | |
74960c60 | 12408 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12409 | for (loc = b->loc; loc; loc = loc->next) |
12410 | bp_location_count++; | |
12411 | ||
12412 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12413 | locp = bp_location; | |
12414 | ALL_BREAKPOINTS (b) | |
12415 | for (loc = b->loc; loc; loc = loc->next) | |
12416 | *locp++ = loc; | |
12417 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12418 | bp_location_compare); |
876fa593 JK |
12419 | |
12420 | bp_location_target_extensions_update (); | |
74960c60 | 12421 | |
4a64f543 MS |
12422 | /* Identify bp_location instances that are no longer present in the |
12423 | new list, and therefore should be freed. Note that it's not | |
12424 | necessary that those locations should be removed from inferior -- | |
12425 | if there's another location at the same address (previously | |
12426 | marked as duplicate), we don't need to remove/insert the | |
12427 | location. | |
876fa593 | 12428 | |
4a64f543 MS |
12429 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12430 | and former bp_location array state respectively. */ | |
876fa593 JK |
12431 | |
12432 | locp = bp_location; | |
12433 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12434 | old_locp++) | |
74960c60 | 12435 | { |
876fa593 | 12436 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12437 | struct bp_location **loc2p; |
876fa593 | 12438 | |
e5dd4106 | 12439 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12440 | not, we have to free it. */ |
c7d46a38 | 12441 | int found_object = 0; |
20874c92 VP |
12442 | /* Tells if the location should remain inserted in the target. */ |
12443 | int keep_in_target = 0; | |
12444 | int removed = 0; | |
876fa593 | 12445 | |
4a64f543 MS |
12446 | /* Skip LOCP entries which will definitely never be needed. |
12447 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12448 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12449 | && (*locp)->address < old_loc->address) |
876fa593 | 12450 | locp++; |
c7d46a38 PA |
12451 | |
12452 | for (loc2p = locp; | |
12453 | (loc2p < bp_location + bp_location_count | |
12454 | && (*loc2p)->address == old_loc->address); | |
12455 | loc2p++) | |
12456 | { | |
b775012e LM |
12457 | /* Check if this is a new/duplicated location or a duplicated |
12458 | location that had its condition modified. If so, we want to send | |
12459 | its condition to the target if evaluation of conditions is taking | |
12460 | place there. */ | |
12461 | if ((*loc2p)->condition_changed == condition_modified | |
12462 | && (last_addr != old_loc->address | |
12463 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12464 | { |
b775012e LM |
12465 | force_breakpoint_reinsertion (*loc2p); |
12466 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12467 | } |
b775012e LM |
12468 | |
12469 | if (*loc2p == old_loc) | |
12470 | found_object = 1; | |
c7d46a38 | 12471 | } |
74960c60 | 12472 | |
b775012e LM |
12473 | /* We have already handled this address, update it so that we don't |
12474 | have to go through updates again. */ | |
12475 | last_addr = old_loc->address; | |
12476 | ||
12477 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12478 | if (!found_object) | |
12479 | force_breakpoint_reinsertion (old_loc); | |
12480 | ||
4a64f543 MS |
12481 | /* If this location is no longer present, and inserted, look if |
12482 | there's maybe a new location at the same address. If so, | |
12483 | mark that one inserted, and don't remove this one. This is | |
12484 | needed so that we don't have a time window where a breakpoint | |
12485 | at certain location is not inserted. */ | |
74960c60 | 12486 | |
876fa593 | 12487 | if (old_loc->inserted) |
0d381245 | 12488 | { |
4a64f543 MS |
12489 | /* If the location is inserted now, we might have to remove |
12490 | it. */ | |
74960c60 | 12491 | |
876fa593 | 12492 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12493 | { |
4a64f543 MS |
12494 | /* The location is still present in the location list, |
12495 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12496 | keep_in_target = 1; |
74960c60 VP |
12497 | } |
12498 | else | |
12499 | { | |
b775012e LM |
12500 | /* This location still exists, but it won't be kept in the |
12501 | target since it may have been disabled. We proceed to | |
12502 | remove its target-side condition. */ | |
12503 | ||
4a64f543 MS |
12504 | /* The location is either no longer present, or got |
12505 | disabled. See if there's another location at the | |
12506 | same address, in which case we don't need to remove | |
12507 | this one from the target. */ | |
876fa593 | 12508 | |
2bdf28a0 | 12509 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12510 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12511 | { | |
876fa593 | 12512 | for (loc2p = locp; |
c7d46a38 PA |
12513 | (loc2p < bp_location + bp_location_count |
12514 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12515 | loc2p++) |
12516 | { | |
12517 | struct bp_location *loc2 = *loc2p; | |
12518 | ||
2d134ed3 | 12519 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12520 | { |
85d721b8 PA |
12521 | /* Read watchpoint locations are switched to |
12522 | access watchpoints, if the former are not | |
12523 | supported, but the latter are. */ | |
12524 | if (is_hardware_watchpoint (old_loc->owner)) | |
12525 | { | |
12526 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12527 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12528 | } | |
12529 | ||
934709f0 PW |
12530 | /* loc2 is a duplicated location. We need to check |
12531 | if it should be inserted in case it will be | |
12532 | unduplicated. */ | |
12533 | if (loc2 != old_loc | |
12534 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12535 | { |
934709f0 | 12536 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12537 | keep_in_target = 1; |
12538 | break; | |
12539 | } | |
876fa593 JK |
12540 | } |
12541 | } | |
12542 | } | |
74960c60 VP |
12543 | } |
12544 | ||
20874c92 VP |
12545 | if (!keep_in_target) |
12546 | { | |
876fa593 | 12547 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12548 | { |
4a64f543 MS |
12549 | /* This is just about all we can do. We could keep |
12550 | this location on the global list, and try to | |
12551 | remove it next time, but there's no particular | |
12552 | reason why we will succeed next time. | |
20874c92 | 12553 | |
4a64f543 MS |
12554 | Note that at this point, old_loc->owner is still |
12555 | valid, as delete_breakpoint frees the breakpoint | |
12556 | only after calling us. */ | |
3e43a32a MS |
12557 | printf_filtered (_("warning: Error removing " |
12558 | "breakpoint %d\n"), | |
876fa593 | 12559 | old_loc->owner->number); |
20874c92 VP |
12560 | } |
12561 | removed = 1; | |
12562 | } | |
0d381245 | 12563 | } |
74960c60 VP |
12564 | |
12565 | if (!found_object) | |
1c5cfe86 | 12566 | { |
db82e815 PA |
12567 | if (removed && non_stop |
12568 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12569 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12570 | { |
db82e815 PA |
12571 | /* This location was removed from the target. In |
12572 | non-stop mode, a race condition is possible where | |
12573 | we've removed a breakpoint, but stop events for that | |
12574 | breakpoint are already queued and will arrive later. | |
12575 | We apply an heuristic to be able to distinguish such | |
12576 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12577 | breakpoint location for a bit, and will retire it | |
12578 | after we see some number of events. The theory here | |
12579 | is that reporting of events should, "on the average", | |
12580 | be fair, so after a while we'll see events from all | |
12581 | threads that have anything of interest, and no longer | |
12582 | need to keep this breakpoint location around. We | |
12583 | don't hold locations forever so to reduce chances of | |
12584 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12585 | SIGTRAP. | |
12586 | ||
12587 | The heuristic failing can be disastrous on | |
12588 | decr_pc_after_break targets. | |
12589 | ||
12590 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12591 | if we fail to recognize a late breakpoint SIGTRAP, | |
12592 | because events_till_retirement has reached 0 too | |
12593 | soon, we'll fail to do the PC adjustment, and report | |
12594 | a random SIGTRAP to the user. When the user resumes | |
12595 | the inferior, it will most likely immediately crash | |
2dec564e | 12596 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12597 | corrupted, because of being resumed e.g., in the |
12598 | middle of a multi-byte instruction, or skipped a | |
12599 | one-byte instruction. This was actually seen happen | |
12600 | on native x86-linux, and should be less rare on | |
12601 | targets that do not support new thread events, like | |
12602 | remote, due to the heuristic depending on | |
12603 | thread_count. | |
12604 | ||
12605 | Mistaking a random SIGTRAP for a breakpoint trap | |
12606 | causes similar symptoms (PC adjustment applied when | |
12607 | it shouldn't), but then again, playing with SIGTRAPs | |
12608 | behind the debugger's back is asking for trouble. | |
12609 | ||
12610 | Since hardware watchpoint traps are always | |
12611 | distinguishable from other traps, so we don't need to | |
12612 | apply keep hardware watchpoint moribund locations | |
12613 | around. We simply always ignore hardware watchpoint | |
12614 | traps we can no longer explain. */ | |
12615 | ||
876fa593 JK |
12616 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12617 | old_loc->owner = NULL; | |
20874c92 | 12618 | |
876fa593 | 12619 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12620 | } |
12621 | else | |
f431efe5 PA |
12622 | { |
12623 | old_loc->owner = NULL; | |
12624 | decref_bp_location (&old_loc); | |
12625 | } | |
20874c92 | 12626 | } |
74960c60 | 12627 | } |
1c5cfe86 | 12628 | |
348d480f PA |
12629 | /* Rescan breakpoints at the same address and section, marking the |
12630 | first one as "first" and any others as "duplicates". This is so | |
12631 | that the bpt instruction is only inserted once. If we have a | |
12632 | permanent breakpoint at the same place as BPT, make that one the | |
12633 | official one, and the rest as duplicates. Permanent breakpoints | |
12634 | are sorted first for the same address. | |
12635 | ||
12636 | Do the same for hardware watchpoints, but also considering the | |
12637 | watchpoint's type (regular/access/read) and length. */ | |
12638 | ||
12639 | bp_loc_first = NULL; | |
12640 | wp_loc_first = NULL; | |
12641 | awp_loc_first = NULL; | |
12642 | rwp_loc_first = NULL; | |
12643 | ALL_BP_LOCATIONS (loc, locp) | |
12644 | { | |
12645 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12646 | non-NULL. */ | |
348d480f | 12647 | struct bp_location **loc_first_p; |
d3fbdd86 | 12648 | b = loc->owner; |
348d480f | 12649 | |
6f380991 | 12650 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12651 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12652 | /* Don't detect duplicate for tracepoint locations because they are |
12653 | never duplicated. See the comments in field `duplicate' of | |
12654 | `struct bp_location'. */ | |
348d480f | 12655 | || is_tracepoint (b)) |
b775012e LM |
12656 | { |
12657 | /* Clear the condition modification flag. */ | |
12658 | loc->condition_changed = condition_unchanged; | |
12659 | continue; | |
12660 | } | |
348d480f PA |
12661 | |
12662 | /* Permanent breakpoint should always be inserted. */ | |
12663 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
12664 | internal_error (__FILE__, __LINE__, | |
12665 | _("allegedly permanent breakpoint is not " | |
12666 | "actually inserted")); | |
12667 | ||
12668 | if (b->type == bp_hardware_watchpoint) | |
12669 | loc_first_p = &wp_loc_first; | |
12670 | else if (b->type == bp_read_watchpoint) | |
12671 | loc_first_p = &rwp_loc_first; | |
12672 | else if (b->type == bp_access_watchpoint) | |
12673 | loc_first_p = &awp_loc_first; | |
12674 | else | |
12675 | loc_first_p = &bp_loc_first; | |
12676 | ||
12677 | if (*loc_first_p == NULL | |
12678 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12679 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12680 | { | |
12681 | *loc_first_p = loc; | |
12682 | loc->duplicate = 0; | |
b775012e LM |
12683 | |
12684 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12685 | { | |
12686 | loc->needs_update = 1; | |
12687 | /* Clear the condition modification flag. */ | |
12688 | loc->condition_changed = condition_unchanged; | |
12689 | } | |
348d480f PA |
12690 | continue; |
12691 | } | |
12692 | ||
934709f0 PW |
12693 | |
12694 | /* This and the above ensure the invariant that the first location | |
12695 | is not duplicated, and is the inserted one. | |
12696 | All following are marked as duplicated, and are not inserted. */ | |
12697 | if (loc->inserted) | |
12698 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12699 | loc->duplicate = 1; |
12700 | ||
b775012e LM |
12701 | /* Clear the condition modification flag. */ |
12702 | loc->condition_changed = condition_unchanged; | |
12703 | ||
348d480f PA |
12704 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
12705 | && b->enable_state != bp_permanent) | |
12706 | internal_error (__FILE__, __LINE__, | |
12707 | _("another breakpoint was inserted on top of " | |
12708 | "a permanent breakpoint")); | |
12709 | } | |
12710 | ||
b775012e | 12711 | if (breakpoints_always_inserted_mode () |
348d480f | 12712 | && (have_live_inferiors () |
f5656ead | 12713 | || (gdbarch_has_global_breakpoints (target_gdbarch ())))) |
b775012e LM |
12714 | { |
12715 | if (should_insert) | |
12716 | insert_breakpoint_locations (); | |
12717 | else | |
12718 | { | |
12719 | /* Though should_insert is false, we may need to update conditions | |
12720 | on the target's side if it is evaluating such conditions. We | |
12721 | only update conditions for locations that are marked | |
12722 | "needs_update". */ | |
12723 | update_inserted_breakpoint_locations (); | |
12724 | } | |
12725 | } | |
348d480f | 12726 | |
1e4d1764 YQ |
12727 | if (should_insert) |
12728 | download_tracepoint_locations (); | |
12729 | ||
348d480f PA |
12730 | do_cleanups (cleanups); |
12731 | } | |
12732 | ||
12733 | void | |
12734 | breakpoint_retire_moribund (void) | |
12735 | { | |
12736 | struct bp_location *loc; | |
12737 | int ix; | |
12738 | ||
12739 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12740 | if (--(loc->events_till_retirement) == 0) | |
12741 | { | |
12742 | decref_bp_location (&loc); | |
12743 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12744 | --ix; | |
12745 | } | |
12746 | } | |
12747 | ||
12748 | static void | |
12749 | update_global_location_list_nothrow (int inserting) | |
12750 | { | |
bfd189b1 | 12751 | volatile struct gdb_exception e; |
348d480f PA |
12752 | |
12753 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12754 | update_global_location_list (inserting); | |
12755 | } | |
12756 | ||
12757 | /* Clear BKP from a BPS. */ | |
12758 | ||
12759 | static void | |
12760 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12761 | { | |
12762 | bpstat bs; | |
12763 | ||
12764 | for (bs = bps; bs; bs = bs->next) | |
12765 | if (bs->breakpoint_at == bpt) | |
12766 | { | |
12767 | bs->breakpoint_at = NULL; | |
12768 | bs->old_val = NULL; | |
12769 | /* bs->commands will be freed later. */ | |
12770 | } | |
12771 | } | |
12772 | ||
12773 | /* Callback for iterate_over_threads. */ | |
12774 | static int | |
12775 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12776 | { | |
12777 | struct breakpoint *bpt = data; | |
12778 | ||
12779 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12780 | return 0; | |
12781 | } | |
12782 | ||
12783 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12784 | callbacks. */ | |
12785 | ||
12786 | static void | |
12787 | say_where (struct breakpoint *b) | |
12788 | { | |
12789 | struct value_print_options opts; | |
12790 | ||
12791 | get_user_print_options (&opts); | |
12792 | ||
12793 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12794 | single string. */ | |
12795 | if (b->loc == NULL) | |
12796 | { | |
12797 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12798 | } | |
12799 | else | |
12800 | { | |
2f202fde | 12801 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12802 | { |
12803 | printf_filtered (" at "); | |
12804 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12805 | gdb_stdout); | |
12806 | } | |
2f202fde | 12807 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12808 | { |
12809 | /* If there is a single location, we can print the location | |
12810 | more nicely. */ | |
12811 | if (b->loc->next == NULL) | |
12812 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12813 | symtab_to_filename_for_display (b->loc->symtab), |
12814 | b->loc->line_number); | |
f8eba3c6 TT |
12815 | else |
12816 | /* This is not ideal, but each location may have a | |
12817 | different file name, and this at least reflects the | |
12818 | real situation somewhat. */ | |
12819 | printf_filtered (": %s.", b->addr_string); | |
12820 | } | |
348d480f PA |
12821 | |
12822 | if (b->loc->next) | |
12823 | { | |
12824 | struct bp_location *loc = b->loc; | |
12825 | int n = 0; | |
12826 | for (; loc; loc = loc->next) | |
12827 | ++n; | |
12828 | printf_filtered (" (%d locations)", n); | |
12829 | } | |
12830 | } | |
12831 | } | |
12832 | ||
348d480f PA |
12833 | /* Default bp_location_ops methods. */ |
12834 | ||
12835 | static void | |
12836 | bp_location_dtor (struct bp_location *self) | |
12837 | { | |
12838 | xfree (self->cond); | |
b775012e LM |
12839 | if (self->cond_bytecode) |
12840 | free_agent_expr (self->cond_bytecode); | |
348d480f PA |
12841 | xfree (self->function_name); |
12842 | } | |
12843 | ||
12844 | static const struct bp_location_ops bp_location_ops = | |
12845 | { | |
12846 | bp_location_dtor | |
12847 | }; | |
12848 | ||
2060206e PA |
12849 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12850 | inherit from. */ | |
348d480f | 12851 | |
2060206e PA |
12852 | static void |
12853 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12854 | { |
12855 | decref_counted_command_line (&self->commands); | |
12856 | xfree (self->cond_string); | |
fb81d016 | 12857 | xfree (self->extra_string); |
348d480f | 12858 | xfree (self->addr_string); |
f8eba3c6 | 12859 | xfree (self->filter); |
348d480f | 12860 | xfree (self->addr_string_range_end); |
348d480f PA |
12861 | } |
12862 | ||
2060206e PA |
12863 | static struct bp_location * |
12864 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12865 | { |
12866 | struct bp_location *loc; | |
12867 | ||
12868 | loc = XNEW (struct bp_location); | |
12869 | init_bp_location (loc, &bp_location_ops, self); | |
12870 | return loc; | |
12871 | } | |
12872 | ||
2060206e PA |
12873 | static void |
12874 | base_breakpoint_re_set (struct breakpoint *b) | |
12875 | { | |
12876 | /* Nothing to re-set. */ | |
12877 | } | |
12878 | ||
12879 | #define internal_error_pure_virtual_called() \ | |
12880 | gdb_assert_not_reached ("pure virtual function called") | |
12881 | ||
12882 | static int | |
12883 | base_breakpoint_insert_location (struct bp_location *bl) | |
12884 | { | |
12885 | internal_error_pure_virtual_called (); | |
12886 | } | |
12887 | ||
12888 | static int | |
12889 | base_breakpoint_remove_location (struct bp_location *bl) | |
12890 | { | |
12891 | internal_error_pure_virtual_called (); | |
12892 | } | |
12893 | ||
12894 | static int | |
12895 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12896 | struct address_space *aspace, | |
09ac7c10 TT |
12897 | CORE_ADDR bp_addr, |
12898 | const struct target_waitstatus *ws) | |
2060206e PA |
12899 | { |
12900 | internal_error_pure_virtual_called (); | |
12901 | } | |
12902 | ||
12903 | static void | |
12904 | base_breakpoint_check_status (bpstat bs) | |
12905 | { | |
12906 | /* Always stop. */ | |
12907 | } | |
12908 | ||
12909 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12910 | errors. */ | |
12911 | ||
12912 | static int | |
12913 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12914 | { | |
12915 | internal_error_pure_virtual_called (); | |
12916 | } | |
12917 | ||
12918 | /* A "resources_needed" breakpoint_ops method that just internal | |
12919 | errors. */ | |
12920 | ||
12921 | static int | |
12922 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12923 | { | |
12924 | internal_error_pure_virtual_called (); | |
12925 | } | |
12926 | ||
12927 | static enum print_stop_action | |
12928 | base_breakpoint_print_it (bpstat bs) | |
12929 | { | |
12930 | internal_error_pure_virtual_called (); | |
12931 | } | |
12932 | ||
12933 | static void | |
12934 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12935 | struct ui_out *uiout) | |
12936 | { | |
12937 | /* nothing */ | |
12938 | } | |
12939 | ||
12940 | static void | |
12941 | base_breakpoint_print_mention (struct breakpoint *b) | |
12942 | { | |
12943 | internal_error_pure_virtual_called (); | |
12944 | } | |
12945 | ||
12946 | static void | |
12947 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12948 | { | |
12949 | internal_error_pure_virtual_called (); | |
12950 | } | |
12951 | ||
983af33b SDJ |
12952 | static void |
12953 | base_breakpoint_create_sals_from_address (char **arg, | |
12954 | struct linespec_result *canonical, | |
12955 | enum bptype type_wanted, | |
12956 | char *addr_start, | |
12957 | char **copy_arg) | |
12958 | { | |
12959 | internal_error_pure_virtual_called (); | |
12960 | } | |
12961 | ||
12962 | static void | |
12963 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12964 | struct linespec_result *c, | |
12965 | struct linespec_sals *lsal, | |
12966 | char *cond_string, | |
e7e0cddf | 12967 | char *extra_string, |
983af33b SDJ |
12968 | enum bptype type_wanted, |
12969 | enum bpdisp disposition, | |
12970 | int thread, | |
12971 | int task, int ignore_count, | |
12972 | const struct breakpoint_ops *o, | |
12973 | int from_tty, int enabled, | |
44f238bb | 12974 | int internal, unsigned flags) |
983af33b SDJ |
12975 | { |
12976 | internal_error_pure_virtual_called (); | |
12977 | } | |
12978 | ||
12979 | static void | |
12980 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12981 | struct symtabs_and_lines *sals) | |
12982 | { | |
12983 | internal_error_pure_virtual_called (); | |
12984 | } | |
12985 | ||
ab04a2af TT |
12986 | /* The default 'explains_signal' method. */ |
12987 | ||
12988 | static enum bpstat_signal_value | |
12989 | base_breakpoint_explains_signal (struct breakpoint *b) | |
12990 | { | |
12991 | return BPSTAT_SIGNAL_HIDE; | |
12992 | } | |
12993 | ||
12994 | struct breakpoint_ops base_breakpoint_ops = | |
2060206e PA |
12995 | { |
12996 | base_breakpoint_dtor, | |
12997 | base_breakpoint_allocate_location, | |
12998 | base_breakpoint_re_set, | |
12999 | base_breakpoint_insert_location, | |
13000 | base_breakpoint_remove_location, | |
13001 | base_breakpoint_breakpoint_hit, | |
13002 | base_breakpoint_check_status, | |
13003 | base_breakpoint_resources_needed, | |
13004 | base_breakpoint_works_in_software_mode, | |
13005 | base_breakpoint_print_it, | |
13006 | NULL, | |
13007 | base_breakpoint_print_one_detail, | |
13008 | base_breakpoint_print_mention, | |
983af33b SDJ |
13009 | base_breakpoint_print_recreate, |
13010 | base_breakpoint_create_sals_from_address, | |
13011 | base_breakpoint_create_breakpoints_sal, | |
13012 | base_breakpoint_decode_linespec, | |
ab04a2af | 13013 | base_breakpoint_explains_signal |
2060206e PA |
13014 | }; |
13015 | ||
13016 | /* Default breakpoint_ops methods. */ | |
13017 | ||
13018 | static void | |
348d480f PA |
13019 | bkpt_re_set (struct breakpoint *b) |
13020 | { | |
06edf0c0 PA |
13021 | /* FIXME: is this still reachable? */ |
13022 | if (b->addr_string == NULL) | |
13023 | { | |
13024 | /* Anything without a string can't be re-set. */ | |
348d480f | 13025 | delete_breakpoint (b); |
06edf0c0 | 13026 | return; |
348d480f | 13027 | } |
06edf0c0 PA |
13028 | |
13029 | breakpoint_re_set_default (b); | |
348d480f PA |
13030 | } |
13031 | ||
2060206e | 13032 | static int |
348d480f PA |
13033 | bkpt_insert_location (struct bp_location *bl) |
13034 | { | |
13035 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13036 | return target_insert_hw_breakpoint (bl->gdbarch, | |
13037 | &bl->target_info); | |
13038 | else | |
13039 | return target_insert_breakpoint (bl->gdbarch, | |
13040 | &bl->target_info); | |
13041 | } | |
13042 | ||
2060206e | 13043 | static int |
348d480f PA |
13044 | bkpt_remove_location (struct bp_location *bl) |
13045 | { | |
13046 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13047 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13048 | else | |
13049 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
13050 | } | |
13051 | ||
2060206e | 13052 | static int |
348d480f | 13053 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13054 | struct address_space *aspace, CORE_ADDR bp_addr, |
13055 | const struct target_waitstatus *ws) | |
348d480f | 13056 | { |
09ac7c10 | 13057 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13058 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13059 | return 0; |
13060 | ||
348d480f PA |
13061 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13062 | aspace, bp_addr)) | |
13063 | return 0; | |
13064 | ||
13065 | if (overlay_debugging /* unmapped overlay section */ | |
13066 | && section_is_overlay (bl->section) | |
13067 | && !section_is_mapped (bl->section)) | |
13068 | return 0; | |
13069 | ||
13070 | return 1; | |
13071 | } | |
13072 | ||
2060206e | 13073 | static int |
348d480f PA |
13074 | bkpt_resources_needed (const struct bp_location *bl) |
13075 | { | |
13076 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13077 | ||
13078 | return 1; | |
13079 | } | |
13080 | ||
2060206e | 13081 | static enum print_stop_action |
348d480f PA |
13082 | bkpt_print_it (bpstat bs) |
13083 | { | |
348d480f PA |
13084 | struct breakpoint *b; |
13085 | const struct bp_location *bl; | |
001c8c33 | 13086 | int bp_temp; |
79a45e25 | 13087 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13088 | |
13089 | gdb_assert (bs->bp_location_at != NULL); | |
13090 | ||
13091 | bl = bs->bp_location_at; | |
13092 | b = bs->breakpoint_at; | |
13093 | ||
001c8c33 PA |
13094 | bp_temp = b->disposition == disp_del; |
13095 | if (bl->address != bl->requested_address) | |
13096 | breakpoint_adjustment_warning (bl->requested_address, | |
13097 | bl->address, | |
13098 | b->number, 1); | |
13099 | annotate_breakpoint (b->number); | |
13100 | if (bp_temp) | |
13101 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13102 | else | |
13103 | ui_out_text (uiout, "\nBreakpoint "); | |
13104 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13105 | { |
001c8c33 PA |
13106 | ui_out_field_string (uiout, "reason", |
13107 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13108 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13109 | } |
001c8c33 PA |
13110 | ui_out_field_int (uiout, "bkptno", b->number); |
13111 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13112 | |
001c8c33 | 13113 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13114 | } |
13115 | ||
2060206e | 13116 | static void |
06edf0c0 PA |
13117 | bkpt_print_mention (struct breakpoint *b) |
13118 | { | |
79a45e25 | 13119 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13120 | return; |
13121 | ||
13122 | switch (b->type) | |
13123 | { | |
13124 | case bp_breakpoint: | |
13125 | case bp_gnu_ifunc_resolver: | |
13126 | if (b->disposition == disp_del) | |
13127 | printf_filtered (_("Temporary breakpoint")); | |
13128 | else | |
13129 | printf_filtered (_("Breakpoint")); | |
13130 | printf_filtered (_(" %d"), b->number); | |
13131 | if (b->type == bp_gnu_ifunc_resolver) | |
13132 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13133 | break; | |
13134 | case bp_hardware_breakpoint: | |
13135 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13136 | break; | |
e7e0cddf SS |
13137 | case bp_dprintf: |
13138 | printf_filtered (_("Dprintf %d"), b->number); | |
13139 | break; | |
06edf0c0 PA |
13140 | } |
13141 | ||
13142 | say_where (b); | |
13143 | } | |
13144 | ||
2060206e | 13145 | static void |
06edf0c0 PA |
13146 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13147 | { | |
13148 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13149 | fprintf_unfiltered (fp, "tbreak"); | |
13150 | else if (tp->type == bp_breakpoint) | |
13151 | fprintf_unfiltered (fp, "break"); | |
13152 | else if (tp->type == bp_hardware_breakpoint | |
13153 | && tp->disposition == disp_del) | |
13154 | fprintf_unfiltered (fp, "thbreak"); | |
13155 | else if (tp->type == bp_hardware_breakpoint) | |
13156 | fprintf_unfiltered (fp, "hbreak"); | |
13157 | else | |
13158 | internal_error (__FILE__, __LINE__, | |
13159 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13160 | ||
2060206e | 13161 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13162 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13163 | } |
13164 | ||
983af33b SDJ |
13165 | static void |
13166 | bkpt_create_sals_from_address (char **arg, | |
13167 | struct linespec_result *canonical, | |
13168 | enum bptype type_wanted, | |
13169 | char *addr_start, char **copy_arg) | |
13170 | { | |
13171 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13172 | addr_start, copy_arg); | |
13173 | } | |
13174 | ||
13175 | static void | |
13176 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13177 | struct linespec_result *canonical, | |
13178 | struct linespec_sals *lsal, | |
13179 | char *cond_string, | |
e7e0cddf | 13180 | char *extra_string, |
983af33b SDJ |
13181 | enum bptype type_wanted, |
13182 | enum bpdisp disposition, | |
13183 | int thread, | |
13184 | int task, int ignore_count, | |
13185 | const struct breakpoint_ops *ops, | |
13186 | int from_tty, int enabled, | |
44f238bb | 13187 | int internal, unsigned flags) |
983af33b SDJ |
13188 | { |
13189 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
e7e0cddf SS |
13190 | cond_string, extra_string, |
13191 | type_wanted, | |
983af33b SDJ |
13192 | disposition, thread, task, |
13193 | ignore_count, ops, from_tty, | |
44f238bb | 13194 | enabled, internal, flags); |
983af33b SDJ |
13195 | } |
13196 | ||
13197 | static void | |
13198 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13199 | struct symtabs_and_lines *sals) | |
13200 | { | |
13201 | decode_linespec_default (b, s, sals); | |
13202 | } | |
13203 | ||
06edf0c0 PA |
13204 | /* Virtual table for internal breakpoints. */ |
13205 | ||
13206 | static void | |
13207 | internal_bkpt_re_set (struct breakpoint *b) | |
13208 | { | |
13209 | switch (b->type) | |
13210 | { | |
13211 | /* Delete overlay event and longjmp master breakpoints; they | |
13212 | will be reset later by breakpoint_re_set. */ | |
13213 | case bp_overlay_event: | |
13214 | case bp_longjmp_master: | |
13215 | case bp_std_terminate_master: | |
13216 | case bp_exception_master: | |
13217 | delete_breakpoint (b); | |
13218 | break; | |
13219 | ||
13220 | /* This breakpoint is special, it's set up when the inferior | |
13221 | starts and we really don't want to touch it. */ | |
13222 | case bp_shlib_event: | |
13223 | ||
13224 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13225 | it is set up, we do not want to touch it. */ | |
13226 | case bp_thread_event: | |
13227 | break; | |
13228 | } | |
13229 | } | |
13230 | ||
13231 | static void | |
13232 | internal_bkpt_check_status (bpstat bs) | |
13233 | { | |
a9b3a50f PA |
13234 | if (bs->breakpoint_at->type == bp_shlib_event) |
13235 | { | |
13236 | /* If requested, stop when the dynamic linker notifies GDB of | |
13237 | events. This allows the user to get control and place | |
13238 | breakpoints in initializer routines for dynamically loaded | |
13239 | objects (among other things). */ | |
13240 | bs->stop = stop_on_solib_events; | |
13241 | bs->print = stop_on_solib_events; | |
13242 | } | |
13243 | else | |
13244 | bs->stop = 0; | |
06edf0c0 PA |
13245 | } |
13246 | ||
13247 | static enum print_stop_action | |
13248 | internal_bkpt_print_it (bpstat bs) | |
13249 | { | |
06edf0c0 | 13250 | struct breakpoint *b; |
06edf0c0 | 13251 | |
06edf0c0 PA |
13252 | b = bs->breakpoint_at; |
13253 | ||
06edf0c0 PA |
13254 | switch (b->type) |
13255 | { | |
348d480f PA |
13256 | case bp_shlib_event: |
13257 | /* Did we stop because the user set the stop_on_solib_events | |
13258 | variable? (If so, we report this as a generic, "Stopped due | |
13259 | to shlib event" message.) */ | |
edcc5120 | 13260 | print_solib_event (0); |
348d480f PA |
13261 | break; |
13262 | ||
13263 | case bp_thread_event: | |
13264 | /* Not sure how we will get here. | |
13265 | GDB should not stop for these breakpoints. */ | |
13266 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13267 | break; |
13268 | ||
13269 | case bp_overlay_event: | |
13270 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13271 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13272 | break; |
13273 | ||
13274 | case bp_longjmp_master: | |
13275 | /* These should never be enabled. */ | |
13276 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13277 | break; |
13278 | ||
13279 | case bp_std_terminate_master: | |
13280 | /* These should never be enabled. */ | |
13281 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13282 | "gdb should not stop!\n")); | |
348d480f PA |
13283 | break; |
13284 | ||
13285 | case bp_exception_master: | |
13286 | /* These should never be enabled. */ | |
13287 | printf_filtered (_("Exception Master Breakpoint: " | |
13288 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13289 | break; |
13290 | } | |
13291 | ||
001c8c33 | 13292 | return PRINT_NOTHING; |
06edf0c0 PA |
13293 | } |
13294 | ||
13295 | static void | |
13296 | internal_bkpt_print_mention (struct breakpoint *b) | |
13297 | { | |
13298 | /* Nothing to mention. These breakpoints are internal. */ | |
13299 | } | |
13300 | ||
06edf0c0 PA |
13301 | /* Virtual table for momentary breakpoints */ |
13302 | ||
13303 | static void | |
13304 | momentary_bkpt_re_set (struct breakpoint *b) | |
13305 | { | |
13306 | /* Keep temporary breakpoints, which can be encountered when we step | |
13307 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
13308 | Otherwise these should have been blown away via the cleanup chain | |
13309 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13310 | } | |
13311 | ||
13312 | static void | |
13313 | momentary_bkpt_check_status (bpstat bs) | |
13314 | { | |
13315 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13316 | } | |
13317 | ||
13318 | static enum print_stop_action | |
13319 | momentary_bkpt_print_it (bpstat bs) | |
13320 | { | |
79a45e25 PA |
13321 | struct ui_out *uiout = current_uiout; |
13322 | ||
001c8c33 | 13323 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13324 | { |
001c8c33 | 13325 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13326 | |
001c8c33 PA |
13327 | switch (b->type) |
13328 | { | |
13329 | case bp_finish: | |
13330 | ui_out_field_string | |
13331 | (uiout, "reason", | |
13332 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13333 | break; | |
348d480f | 13334 | |
001c8c33 PA |
13335 | case bp_until: |
13336 | ui_out_field_string | |
13337 | (uiout, "reason", | |
13338 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13339 | break; | |
13340 | } | |
348d480f PA |
13341 | } |
13342 | ||
001c8c33 | 13343 | return PRINT_UNKNOWN; |
348d480f PA |
13344 | } |
13345 | ||
06edf0c0 PA |
13346 | static void |
13347 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13348 | { |
06edf0c0 | 13349 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13350 | } |
13351 | ||
e2e4d78b JK |
13352 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13353 | ||
13354 | It gets cleared already on the removal of the first one of such placed | |
13355 | breakpoints. This is OK as they get all removed altogether. */ | |
13356 | ||
13357 | static void | |
13358 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13359 | { | |
13360 | struct thread_info *tp = find_thread_id (self->thread); | |
13361 | ||
13362 | if (tp) | |
13363 | tp->initiating_frame = null_frame_id; | |
13364 | ||
13365 | momentary_breakpoint_ops.dtor (self); | |
13366 | } | |
13367 | ||
55aa24fb SDJ |
13368 | /* Specific methods for probe breakpoints. */ |
13369 | ||
13370 | static int | |
13371 | bkpt_probe_insert_location (struct bp_location *bl) | |
13372 | { | |
13373 | int v = bkpt_insert_location (bl); | |
13374 | ||
13375 | if (v == 0) | |
13376 | { | |
13377 | /* The insertion was successful, now let's set the probe's semaphore | |
13378 | if needed. */ | |
13379 | bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch); | |
13380 | } | |
13381 | ||
13382 | return v; | |
13383 | } | |
13384 | ||
13385 | static int | |
13386 | bkpt_probe_remove_location (struct bp_location *bl) | |
13387 | { | |
13388 | /* Let's clear the semaphore before removing the location. */ | |
13389 | bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch); | |
13390 | ||
13391 | return bkpt_remove_location (bl); | |
13392 | } | |
13393 | ||
13394 | static void | |
13395 | bkpt_probe_create_sals_from_address (char **arg, | |
13396 | struct linespec_result *canonical, | |
13397 | enum bptype type_wanted, | |
13398 | char *addr_start, char **copy_arg) | |
13399 | { | |
13400 | struct linespec_sals lsal; | |
13401 | ||
13402 | lsal.sals = parse_probes (arg, canonical); | |
13403 | ||
13404 | *copy_arg = xstrdup (canonical->addr_string); | |
13405 | lsal.canonical = xstrdup (*copy_arg); | |
13406 | ||
13407 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13408 | } | |
13409 | ||
13410 | static void | |
13411 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13412 | struct symtabs_and_lines *sals) | |
13413 | { | |
13414 | *sals = parse_probes (s, NULL); | |
13415 | if (!sals->sals) | |
13416 | error (_("probe not found")); | |
13417 | } | |
13418 | ||
348d480f | 13419 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13420 | |
348d480f PA |
13421 | static void |
13422 | tracepoint_re_set (struct breakpoint *b) | |
13423 | { | |
13424 | breakpoint_re_set_default (b); | |
13425 | } | |
876fa593 | 13426 | |
348d480f PA |
13427 | static int |
13428 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13429 | struct address_space *aspace, CORE_ADDR bp_addr, |
13430 | const struct target_waitstatus *ws) | |
348d480f PA |
13431 | { |
13432 | /* By definition, the inferior does not report stops at | |
13433 | tracepoints. */ | |
13434 | return 0; | |
74960c60 VP |
13435 | } |
13436 | ||
13437 | static void | |
348d480f PA |
13438 | tracepoint_print_one_detail (const struct breakpoint *self, |
13439 | struct ui_out *uiout) | |
74960c60 | 13440 | { |
d9b3f62e PA |
13441 | struct tracepoint *tp = (struct tracepoint *) self; |
13442 | if (tp->static_trace_marker_id) | |
348d480f PA |
13443 | { |
13444 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13445 | |
348d480f PA |
13446 | ui_out_text (uiout, "\tmarker id is "); |
13447 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13448 | tp->static_trace_marker_id); |
348d480f PA |
13449 | ui_out_text (uiout, "\n"); |
13450 | } | |
0d381245 VP |
13451 | } |
13452 | ||
a474d7c2 | 13453 | static void |
348d480f | 13454 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13455 | { |
79a45e25 | 13456 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13457 | return; |
cc59ec59 | 13458 | |
348d480f PA |
13459 | switch (b->type) |
13460 | { | |
13461 | case bp_tracepoint: | |
13462 | printf_filtered (_("Tracepoint")); | |
13463 | printf_filtered (_(" %d"), b->number); | |
13464 | break; | |
13465 | case bp_fast_tracepoint: | |
13466 | printf_filtered (_("Fast tracepoint")); | |
13467 | printf_filtered (_(" %d"), b->number); | |
13468 | break; | |
13469 | case bp_static_tracepoint: | |
13470 | printf_filtered (_("Static tracepoint")); | |
13471 | printf_filtered (_(" %d"), b->number); | |
13472 | break; | |
13473 | default: | |
13474 | internal_error (__FILE__, __LINE__, | |
13475 | _("unhandled tracepoint type %d"), (int) b->type); | |
13476 | } | |
13477 | ||
13478 | say_where (b); | |
a474d7c2 PA |
13479 | } |
13480 | ||
348d480f | 13481 | static void |
d9b3f62e | 13482 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13483 | { |
d9b3f62e PA |
13484 | struct tracepoint *tp = (struct tracepoint *) self; |
13485 | ||
13486 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13487 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13488 | if (self->type == bp_static_tracepoint) |
348d480f | 13489 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13490 | else if (self->type == bp_tracepoint) |
348d480f PA |
13491 | fprintf_unfiltered (fp, "trace"); |
13492 | else | |
13493 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13494 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13495 | |
d9b3f62e PA |
13496 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13497 | print_recreate_thread (self, fp); | |
13498 | ||
13499 | if (tp->pass_count) | |
13500 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13501 | } |
13502 | ||
983af33b SDJ |
13503 | static void |
13504 | tracepoint_create_sals_from_address (char **arg, | |
13505 | struct linespec_result *canonical, | |
13506 | enum bptype type_wanted, | |
13507 | char *addr_start, char **copy_arg) | |
13508 | { | |
13509 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13510 | addr_start, copy_arg); | |
13511 | } | |
13512 | ||
13513 | static void | |
13514 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13515 | struct linespec_result *canonical, | |
13516 | struct linespec_sals *lsal, | |
13517 | char *cond_string, | |
e7e0cddf | 13518 | char *extra_string, |
983af33b SDJ |
13519 | enum bptype type_wanted, |
13520 | enum bpdisp disposition, | |
13521 | int thread, | |
13522 | int task, int ignore_count, | |
13523 | const struct breakpoint_ops *ops, | |
13524 | int from_tty, int enabled, | |
44f238bb | 13525 | int internal, unsigned flags) |
983af33b SDJ |
13526 | { |
13527 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
e7e0cddf SS |
13528 | cond_string, extra_string, |
13529 | type_wanted, | |
983af33b SDJ |
13530 | disposition, thread, task, |
13531 | ignore_count, ops, from_tty, | |
44f238bb | 13532 | enabled, internal, flags); |
983af33b SDJ |
13533 | } |
13534 | ||
13535 | static void | |
13536 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13537 | struct symtabs_and_lines *sals) | |
13538 | { | |
13539 | decode_linespec_default (b, s, sals); | |
13540 | } | |
13541 | ||
2060206e | 13542 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13543 | |
55aa24fb SDJ |
13544 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13545 | static probe. */ | |
13546 | ||
13547 | static void | |
13548 | tracepoint_probe_create_sals_from_address (char **arg, | |
13549 | struct linespec_result *canonical, | |
13550 | enum bptype type_wanted, | |
13551 | char *addr_start, char **copy_arg) | |
13552 | { | |
13553 | /* We use the same method for breakpoint on probes. */ | |
13554 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13555 | addr_start, copy_arg); | |
13556 | } | |
13557 | ||
13558 | static void | |
13559 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13560 | struct symtabs_and_lines *sals) | |
13561 | { | |
13562 | /* We use the same method for breakpoint on probes. */ | |
13563 | bkpt_probe_decode_linespec (b, s, sals); | |
13564 | } | |
13565 | ||
13566 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13567 | ||
5c2b4418 HZ |
13568 | /* Dprintf breakpoint_ops methods. */ |
13569 | ||
13570 | static void | |
13571 | dprintf_re_set (struct breakpoint *b) | |
13572 | { | |
13573 | breakpoint_re_set_default (b); | |
13574 | ||
13575 | /* This breakpoint could have been pending, and be resolved now, and | |
13576 | if so, we should now have the extra string. If we don't, the | |
13577 | dprintf was malformed when created, but we couldn't tell because | |
13578 | we can't extract the extra string until the location is | |
13579 | resolved. */ | |
13580 | if (b->loc != NULL && b->extra_string == NULL) | |
13581 | error (_("Format string required")); | |
13582 | ||
13583 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13584 | 2 - create a dprintf, which resolves fine. | |
13585 | 3 - disconnect from target 1 | |
13586 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13587 | ||
13588 | After steps #3/#4, you'll want the dprintf command list to | |
13589 | be updated, because target 1 and 2 may well return different | |
13590 | answers for target_can_run_breakpoint_commands(). | |
13591 | Given absence of finer grained resetting, we get to do | |
13592 | it all the time. */ | |
13593 | if (b->extra_string != NULL) | |
13594 | update_dprintf_command_list (b); | |
13595 | } | |
13596 | ||
983af33b SDJ |
13597 | /* The breakpoint_ops structure to be used on static tracepoints with |
13598 | markers (`-m'). */ | |
13599 | ||
13600 | static void | |
13601 | strace_marker_create_sals_from_address (char **arg, | |
13602 | struct linespec_result *canonical, | |
13603 | enum bptype type_wanted, | |
13604 | char *addr_start, char **copy_arg) | |
13605 | { | |
13606 | struct linespec_sals lsal; | |
13607 | ||
13608 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13609 | ||
13610 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13611 | ||
13612 | canonical->addr_string = xstrdup (*copy_arg); | |
13613 | lsal.canonical = xstrdup (*copy_arg); | |
13614 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13615 | } | |
13616 | ||
13617 | static void | |
13618 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13619 | struct linespec_result *canonical, | |
13620 | struct linespec_sals *lsal, | |
13621 | char *cond_string, | |
e7e0cddf | 13622 | char *extra_string, |
983af33b SDJ |
13623 | enum bptype type_wanted, |
13624 | enum bpdisp disposition, | |
13625 | int thread, | |
13626 | int task, int ignore_count, | |
13627 | const struct breakpoint_ops *ops, | |
13628 | int from_tty, int enabled, | |
44f238bb | 13629 | int internal, unsigned flags) |
983af33b SDJ |
13630 | { |
13631 | int i; | |
13632 | ||
13633 | /* If the user is creating a static tracepoint by marker id | |
13634 | (strace -m MARKER_ID), then store the sals index, so that | |
13635 | breakpoint_re_set can try to match up which of the newly | |
13636 | found markers corresponds to this one, and, don't try to | |
13637 | expand multiple locations for each sal, given than SALS | |
13638 | already should contain all sals for MARKER_ID. */ | |
13639 | ||
13640 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13641 | { | |
13642 | struct symtabs_and_lines expanded; | |
13643 | struct tracepoint *tp; | |
13644 | struct cleanup *old_chain; | |
13645 | char *addr_string; | |
13646 | ||
13647 | expanded.nelts = 1; | |
13648 | expanded.sals = &lsal->sals.sals[i]; | |
13649 | ||
13650 | addr_string = xstrdup (canonical->addr_string); | |
13651 | old_chain = make_cleanup (xfree, addr_string); | |
13652 | ||
13653 | tp = XCNEW (struct tracepoint); | |
13654 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13655 | addr_string, NULL, | |
e7e0cddf SS |
13656 | cond_string, extra_string, |
13657 | type_wanted, disposition, | |
983af33b | 13658 | thread, task, ignore_count, ops, |
44f238bb | 13659 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13660 | canonical->special_display); |
13661 | /* Given that its possible to have multiple markers with | |
13662 | the same string id, if the user is creating a static | |
13663 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13664 | store the sals index, so that breakpoint_re_set can | |
13665 | try to match up which of the newly found markers | |
13666 | corresponds to this one */ | |
13667 | tp->static_trace_marker_id_idx = i; | |
13668 | ||
13669 | install_breakpoint (internal, &tp->base, 0); | |
13670 | ||
13671 | discard_cleanups (old_chain); | |
13672 | } | |
13673 | } | |
13674 | ||
13675 | static void | |
13676 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13677 | struct symtabs_and_lines *sals) | |
13678 | { | |
13679 | struct tracepoint *tp = (struct tracepoint *) b; | |
13680 | ||
13681 | *sals = decode_static_tracepoint_spec (s); | |
13682 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13683 | { | |
13684 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13685 | sals->nelts = 1; | |
13686 | } | |
13687 | else | |
13688 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13689 | } | |
13690 | ||
13691 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13692 | ||
13693 | static int | |
13694 | strace_marker_p (struct breakpoint *b) | |
13695 | { | |
13696 | return b->ops == &strace_marker_breakpoint_ops; | |
13697 | } | |
13698 | ||
53a5351d | 13699 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13700 | structures. */ |
c906108c SS |
13701 | |
13702 | void | |
fba45db2 | 13703 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13704 | { |
52f0bd74 | 13705 | struct breakpoint *b; |
c906108c | 13706 | |
8a3fe4f8 | 13707 | gdb_assert (bpt != NULL); |
c906108c | 13708 | |
4a64f543 MS |
13709 | /* Has this bp already been deleted? This can happen because |
13710 | multiple lists can hold pointers to bp's. bpstat lists are | |
13711 | especial culprits. | |
13712 | ||
13713 | One example of this happening is a watchpoint's scope bp. When | |
13714 | the scope bp triggers, we notice that the watchpoint is out of | |
13715 | scope, and delete it. We also delete its scope bp. But the | |
13716 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13717 | That bpstat is then checked for auto-deleting bp's, which are | |
13718 | deleted. | |
13719 | ||
13720 | A real solution to this problem might involve reference counts in | |
13721 | bp's, and/or giving them pointers back to their referencing | |
13722 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13723 | storage when no more references were extent. A cheaper bandaid | |
13724 | was chosen. */ | |
c906108c SS |
13725 | if (bpt->type == bp_none) |
13726 | return; | |
13727 | ||
4a64f543 MS |
13728 | /* At least avoid this stale reference until the reference counting |
13729 | of breakpoints gets resolved. */ | |
d0fb5eae | 13730 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13731 | { |
d0fb5eae | 13732 | struct breakpoint *related; |
3a5c3e22 | 13733 | struct watchpoint *w; |
d0fb5eae JK |
13734 | |
13735 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13736 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13737 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13738 | w = (struct watchpoint *) bpt; |
13739 | else | |
13740 | w = NULL; | |
13741 | if (w != NULL) | |
13742 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13743 | |
13744 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13745 | for (related = bpt; related->related_breakpoint != bpt; | |
13746 | related = related->related_breakpoint); | |
13747 | related->related_breakpoint = bpt->related_breakpoint; | |
13748 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13749 | } |
13750 | ||
a9634178 TJB |
13751 | /* watch_command_1 creates a watchpoint but only sets its number if |
13752 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13753 | a problem in that process, we'll be asked to delete the half-created | |
13754 | watchpoint. In that case, don't announce the deletion. */ | |
13755 | if (bpt->number) | |
13756 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13757 | |
c906108c SS |
13758 | if (breakpoint_chain == bpt) |
13759 | breakpoint_chain = bpt->next; | |
13760 | ||
c906108c SS |
13761 | ALL_BREAKPOINTS (b) |
13762 | if (b->next == bpt) | |
c5aa993b JM |
13763 | { |
13764 | b->next = bpt->next; | |
13765 | break; | |
13766 | } | |
c906108c | 13767 | |
f431efe5 PA |
13768 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13769 | been freed. */ | |
13770 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13771 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13772 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13773 | commands are associated with the bpstat; if we remove it here, | |
13774 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13775 | event-top.c won't do anything, and temporary breakpoints with | |
13776 | commands won't work. */ | |
13777 | ||
13778 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13779 | ||
4a64f543 MS |
13780 | /* Now that breakpoint is removed from breakpoint list, update the |
13781 | global location list. This will remove locations that used to | |
13782 | belong to this breakpoint. Do this before freeing the breakpoint | |
13783 | itself, since remove_breakpoint looks at location's owner. It | |
13784 | might be better design to have location completely | |
13785 | self-contained, but it's not the case now. */ | |
b60e7edf | 13786 | update_global_location_list (0); |
74960c60 | 13787 | |
348d480f | 13788 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13789 | /* On the chance that someone will soon try again to delete this |
13790 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13791 | bpt->type = bp_none; |
b8c9b27d | 13792 | xfree (bpt); |
c906108c SS |
13793 | } |
13794 | ||
4d6140d9 AC |
13795 | static void |
13796 | do_delete_breakpoint_cleanup (void *b) | |
13797 | { | |
13798 | delete_breakpoint (b); | |
13799 | } | |
13800 | ||
13801 | struct cleanup * | |
13802 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13803 | { | |
13804 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13805 | } | |
13806 | ||
51be5b68 PA |
13807 | /* Iterator function to call a user-provided callback function once |
13808 | for each of B and its related breakpoints. */ | |
13809 | ||
13810 | static void | |
13811 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13812 | void (*function) (struct breakpoint *, | |
13813 | void *), | |
13814 | void *data) | |
13815 | { | |
13816 | struct breakpoint *related; | |
13817 | ||
13818 | related = b; | |
13819 | do | |
13820 | { | |
13821 | struct breakpoint *next; | |
13822 | ||
13823 | /* FUNCTION may delete RELATED. */ | |
13824 | next = related->related_breakpoint; | |
13825 | ||
13826 | if (next == related) | |
13827 | { | |
13828 | /* RELATED is the last ring entry. */ | |
13829 | function (related, data); | |
13830 | ||
13831 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13832 | B. There's nothing left to do anyway, so just break | |
13833 | out. */ | |
13834 | break; | |
13835 | } | |
13836 | else | |
13837 | function (related, data); | |
13838 | ||
13839 | related = next; | |
13840 | } | |
13841 | while (related != b); | |
13842 | } | |
95a42b64 TT |
13843 | |
13844 | static void | |
13845 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13846 | { | |
13847 | delete_breakpoint (b); | |
13848 | } | |
13849 | ||
51be5b68 PA |
13850 | /* A callback for map_breakpoint_numbers that calls |
13851 | delete_breakpoint. */ | |
13852 | ||
13853 | static void | |
13854 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13855 | { | |
13856 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13857 | } | |
13858 | ||
c906108c | 13859 | void |
fba45db2 | 13860 | delete_command (char *arg, int from_tty) |
c906108c | 13861 | { |
35df4500 | 13862 | struct breakpoint *b, *b_tmp; |
c906108c | 13863 | |
ea9365bb TT |
13864 | dont_repeat (); |
13865 | ||
c906108c SS |
13866 | if (arg == 0) |
13867 | { | |
13868 | int breaks_to_delete = 0; | |
13869 | ||
46c6471b PA |
13870 | /* Delete all breakpoints if no argument. Do not delete |
13871 | internal breakpoints, these have to be deleted with an | |
13872 | explicit breakpoint number argument. */ | |
c5aa993b | 13873 | ALL_BREAKPOINTS (b) |
46c6471b | 13874 | if (user_breakpoint_p (b)) |
973d738b DJ |
13875 | { |
13876 | breaks_to_delete = 1; | |
13877 | break; | |
13878 | } | |
c906108c SS |
13879 | |
13880 | /* Ask user only if there are some breakpoints to delete. */ | |
13881 | if (!from_tty | |
e2e0b3e5 | 13882 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13883 | { |
35df4500 | 13884 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13885 | if (user_breakpoint_p (b)) |
c5aa993b | 13886 | delete_breakpoint (b); |
c906108c SS |
13887 | } |
13888 | } | |
13889 | else | |
51be5b68 | 13890 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13891 | } |
13892 | ||
0d381245 VP |
13893 | static int |
13894 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13895 | { |
0d381245 | 13896 | for (; loc; loc = loc->next) |
8645ff69 UW |
13897 | if (!loc->shlib_disabled |
13898 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13899 | return 0; |
13900 | return 1; | |
fe3f5fa8 VP |
13901 | } |
13902 | ||
776592bf DE |
13903 | /* Subroutine of update_breakpoint_locations to simplify it. |
13904 | Return non-zero if multiple fns in list LOC have the same name. | |
13905 | Null names are ignored. */ | |
13906 | ||
13907 | static int | |
13908 | ambiguous_names_p (struct bp_location *loc) | |
13909 | { | |
13910 | struct bp_location *l; | |
13911 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13912 | (int (*) (const void *, |
13913 | const void *)) streq, | |
776592bf DE |
13914 | NULL, xcalloc, xfree); |
13915 | ||
13916 | for (l = loc; l != NULL; l = l->next) | |
13917 | { | |
13918 | const char **slot; | |
13919 | const char *name = l->function_name; | |
13920 | ||
13921 | /* Allow for some names to be NULL, ignore them. */ | |
13922 | if (name == NULL) | |
13923 | continue; | |
13924 | ||
13925 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13926 | INSERT); | |
4a64f543 MS |
13927 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13928 | returns NULL. */ | |
776592bf DE |
13929 | if (*slot != NULL) |
13930 | { | |
13931 | htab_delete (htab); | |
13932 | return 1; | |
13933 | } | |
13934 | *slot = name; | |
13935 | } | |
13936 | ||
13937 | htab_delete (htab); | |
13938 | return 0; | |
13939 | } | |
13940 | ||
0fb4aa4b PA |
13941 | /* When symbols change, it probably means the sources changed as well, |
13942 | and it might mean the static tracepoint markers are no longer at | |
13943 | the same address or line numbers they used to be at last we | |
13944 | checked. Losing your static tracepoints whenever you rebuild is | |
13945 | undesirable. This function tries to resync/rematch gdb static | |
13946 | tracepoints with the markers on the target, for static tracepoints | |
13947 | that have not been set by marker id. Static tracepoint that have | |
13948 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13949 | The heuristic is: | |
13950 | ||
13951 | 1) For a tracepoint set at a specific address, look for a marker at | |
13952 | the old PC. If one is found there, assume to be the same marker. | |
13953 | If the name / string id of the marker found is different from the | |
13954 | previous known name, assume that means the user renamed the marker | |
13955 | in the sources, and output a warning. | |
13956 | ||
13957 | 2) For a tracepoint set at a given line number, look for a marker | |
13958 | at the new address of the old line number. If one is found there, | |
13959 | assume to be the same marker. If the name / string id of the | |
13960 | marker found is different from the previous known name, assume that | |
13961 | means the user renamed the marker in the sources, and output a | |
13962 | warning. | |
13963 | ||
13964 | 3) If a marker is no longer found at the same address or line, it | |
13965 | may mean the marker no longer exists. But it may also just mean | |
13966 | the code changed a bit. Maybe the user added a few lines of code | |
13967 | that made the marker move up or down (in line number terms). Ask | |
13968 | the target for info about the marker with the string id as we knew | |
13969 | it. If found, update line number and address in the matching | |
13970 | static tracepoint. This will get confused if there's more than one | |
13971 | marker with the same ID (possible in UST, although unadvised | |
13972 | precisely because it confuses tools). */ | |
13973 | ||
13974 | static struct symtab_and_line | |
13975 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13976 | { | |
d9b3f62e | 13977 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13978 | struct static_tracepoint_marker marker; |
13979 | CORE_ADDR pc; | |
0fb4aa4b PA |
13980 | |
13981 | pc = sal.pc; | |
13982 | if (sal.line) | |
13983 | find_line_pc (sal.symtab, sal.line, &pc); | |
13984 | ||
13985 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13986 | { | |
d9b3f62e | 13987 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13988 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13989 | b->number, | |
d9b3f62e | 13990 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13991 | |
d9b3f62e PA |
13992 | xfree (tp->static_trace_marker_id); |
13993 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13994 | release_static_tracepoint_marker (&marker); |
13995 | ||
13996 | return sal; | |
13997 | } | |
13998 | ||
13999 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14000 | by string ID. */ | |
14001 | if (!sal.explicit_pc | |
14002 | && sal.line != 0 | |
14003 | && sal.symtab != NULL | |
d9b3f62e | 14004 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14005 | { |
14006 | VEC(static_tracepoint_marker_p) *markers; | |
14007 | ||
14008 | markers | |
d9b3f62e | 14009 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14010 | |
14011 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14012 | { | |
80e1d417 | 14013 | struct symtab_and_line sal2; |
0fb4aa4b | 14014 | struct symbol *sym; |
80e1d417 | 14015 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14016 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 14017 | |
80e1d417 | 14018 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14019 | |
d9b3f62e | 14020 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14021 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14022 | |
14023 | warning (_("marker for static tracepoint %d (%s) not " | |
14024 | "found at previous line number"), | |
d9b3f62e | 14025 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14026 | |
80e1d417 | 14027 | init_sal (&sal2); |
0fb4aa4b | 14028 | |
80e1d417 | 14029 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14030 | |
80e1d417 AS |
14031 | sal2 = find_pc_line (tpmarker->address, 0); |
14032 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14033 | ui_out_text (uiout, "Now in "); |
14034 | if (sym) | |
14035 | { | |
14036 | ui_out_field_string (uiout, "func", | |
14037 | SYMBOL_PRINT_NAME (sym)); | |
14038 | ui_out_text (uiout, " at "); | |
14039 | } | |
05cba821 JK |
14040 | ui_out_field_string (uiout, "file", |
14041 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14042 | ui_out_text (uiout, ":"); |
14043 | ||
14044 | if (ui_out_is_mi_like_p (uiout)) | |
14045 | { | |
0b0865da | 14046 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14047 | |
f35a17b5 | 14048 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14049 | } |
14050 | ||
80e1d417 | 14051 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14052 | ui_out_text (uiout, "\n"); |
14053 | ||
80e1d417 | 14054 | b->loc->line_number = sal2.line; |
2f202fde | 14055 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14056 | |
14057 | xfree (b->addr_string); | |
14058 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14059 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14060 | b->loc->line_number); |
0fb4aa4b PA |
14061 | |
14062 | /* Might be nice to check if function changed, and warn if | |
14063 | so. */ | |
14064 | ||
80e1d417 | 14065 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14066 | } |
14067 | } | |
14068 | return sal; | |
14069 | } | |
14070 | ||
8d3788bd VP |
14071 | /* Returns 1 iff locations A and B are sufficiently same that |
14072 | we don't need to report breakpoint as changed. */ | |
14073 | ||
14074 | static int | |
14075 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14076 | { | |
14077 | while (a && b) | |
14078 | { | |
14079 | if (a->address != b->address) | |
14080 | return 0; | |
14081 | ||
14082 | if (a->shlib_disabled != b->shlib_disabled) | |
14083 | return 0; | |
14084 | ||
14085 | if (a->enabled != b->enabled) | |
14086 | return 0; | |
14087 | ||
14088 | a = a->next; | |
14089 | b = b->next; | |
14090 | } | |
14091 | ||
14092 | if ((a == NULL) != (b == NULL)) | |
14093 | return 0; | |
14094 | ||
14095 | return 1; | |
14096 | } | |
14097 | ||
f1310107 TJB |
14098 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14099 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14100 | a ranged breakpoint. */ | |
14101 | ||
0e30163f | 14102 | void |
0d381245 | 14103 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14104 | struct symtabs_and_lines sals, |
14105 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14106 | { |
14107 | int i; | |
0d381245 VP |
14108 | struct bp_location *existing_locations = b->loc; |
14109 | ||
f8eba3c6 TT |
14110 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14111 | { | |
14112 | /* Ranged breakpoints have only one start location and one end | |
14113 | location. */ | |
14114 | b->enable_state = bp_disabled; | |
14115 | update_global_location_list (1); | |
14116 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
14117 | "multiple locations found\n"), | |
14118 | b->number); | |
14119 | return; | |
14120 | } | |
f1310107 | 14121 | |
4a64f543 MS |
14122 | /* If there's no new locations, and all existing locations are |
14123 | pending, don't do anything. This optimizes the common case where | |
14124 | all locations are in the same shared library, that was unloaded. | |
14125 | We'd like to retain the location, so that when the library is | |
14126 | loaded again, we don't loose the enabled/disabled status of the | |
14127 | individual locations. */ | |
0d381245 | 14128 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14129 | return; |
14130 | ||
fe3f5fa8 VP |
14131 | b->loc = NULL; |
14132 | ||
0d381245 | 14133 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14134 | { |
f8eba3c6 TT |
14135 | struct bp_location *new_loc; |
14136 | ||
14137 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14138 | ||
14139 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14140 | |
0d381245 VP |
14141 | /* Reparse conditions, they might contain references to the |
14142 | old symtab. */ | |
14143 | if (b->cond_string != NULL) | |
14144 | { | |
bbc13ae3 | 14145 | const char *s; |
bfd189b1 | 14146 | volatile struct gdb_exception e; |
fe3f5fa8 | 14147 | |
0d381245 VP |
14148 | s = b->cond_string; |
14149 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14150 | { | |
1bb9788d TT |
14151 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14152 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14153 | 0); |
14154 | } | |
14155 | if (e.reason < 0) | |
14156 | { | |
3e43a32a MS |
14157 | warning (_("failed to reevaluate condition " |
14158 | "for breakpoint %d: %s"), | |
0d381245 VP |
14159 | b->number, e.message); |
14160 | new_loc->enabled = 0; | |
14161 | } | |
14162 | } | |
fe3f5fa8 | 14163 | |
f1310107 TJB |
14164 | if (sals_end.nelts) |
14165 | { | |
14166 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14167 | ||
14168 | new_loc->length = end - sals.sals[0].pc + 1; | |
14169 | } | |
0d381245 | 14170 | } |
fe3f5fa8 | 14171 | |
514f746b AR |
14172 | /* Update locations of permanent breakpoints. */ |
14173 | if (b->enable_state == bp_permanent) | |
14174 | make_breakpoint_permanent (b); | |
14175 | ||
4a64f543 MS |
14176 | /* If possible, carry over 'disable' status from existing |
14177 | breakpoints. */ | |
0d381245 VP |
14178 | { |
14179 | struct bp_location *e = existing_locations; | |
776592bf DE |
14180 | /* If there are multiple breakpoints with the same function name, |
14181 | e.g. for inline functions, comparing function names won't work. | |
14182 | Instead compare pc addresses; this is just a heuristic as things | |
14183 | may have moved, but in practice it gives the correct answer | |
14184 | often enough until a better solution is found. */ | |
14185 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14186 | ||
0d381245 VP |
14187 | for (; e; e = e->next) |
14188 | { | |
14189 | if (!e->enabled && e->function_name) | |
14190 | { | |
14191 | struct bp_location *l = b->loc; | |
776592bf DE |
14192 | if (have_ambiguous_names) |
14193 | { | |
14194 | for (; l; l = l->next) | |
f1310107 | 14195 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14196 | { |
14197 | l->enabled = 0; | |
14198 | break; | |
14199 | } | |
14200 | } | |
14201 | else | |
14202 | { | |
14203 | for (; l; l = l->next) | |
14204 | if (l->function_name | |
14205 | && strcmp (e->function_name, l->function_name) == 0) | |
14206 | { | |
14207 | l->enabled = 0; | |
14208 | break; | |
14209 | } | |
14210 | } | |
0d381245 VP |
14211 | } |
14212 | } | |
14213 | } | |
fe3f5fa8 | 14214 | |
8d3788bd VP |
14215 | if (!locations_are_equal (existing_locations, b->loc)) |
14216 | observer_notify_breakpoint_modified (b); | |
14217 | ||
b60e7edf | 14218 | update_global_location_list (1); |
fe3f5fa8 VP |
14219 | } |
14220 | ||
ef23e705 TJB |
14221 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14222 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14223 | ||
14224 | static struct symtabs_and_lines | |
14225 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14226 | { | |
14227 | char *s; | |
02d20e4a | 14228 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14229 | volatile struct gdb_exception e; |
ef23e705 | 14230 | |
983af33b | 14231 | gdb_assert (b->ops != NULL); |
ef23e705 | 14232 | s = addr_string; |
ef23e705 TJB |
14233 | |
14234 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14235 | { | |
983af33b | 14236 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14237 | } |
14238 | if (e.reason < 0) | |
14239 | { | |
14240 | int not_found_and_ok = 0; | |
14241 | /* For pending breakpoints, it's expected that parsing will | |
14242 | fail until the right shared library is loaded. User has | |
14243 | already told to create pending breakpoints and don't need | |
14244 | extra messages. If breakpoint is in bp_shlib_disabled | |
14245 | state, then user already saw the message about that | |
14246 | breakpoint being disabled, and don't want to see more | |
14247 | errors. */ | |
58438ac1 | 14248 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14249 | && (b->condition_not_parsed |
14250 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14251 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14252 | || b->enable_state == bp_disabled)) |
14253 | not_found_and_ok = 1; | |
14254 | ||
14255 | if (!not_found_and_ok) | |
14256 | { | |
14257 | /* We surely don't want to warn about the same breakpoint | |
14258 | 10 times. One solution, implemented here, is disable | |
14259 | the breakpoint on error. Another solution would be to | |
14260 | have separate 'warning emitted' flag. Since this | |
14261 | happens only when a binary has changed, I don't know | |
14262 | which approach is better. */ | |
14263 | b->enable_state = bp_disabled; | |
14264 | throw_exception (e); | |
14265 | } | |
14266 | } | |
14267 | ||
58438ac1 | 14268 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14269 | { |
f8eba3c6 | 14270 | int i; |
ef23e705 | 14271 | |
f8eba3c6 TT |
14272 | for (i = 0; i < sals.nelts; ++i) |
14273 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14274 | if (b->condition_not_parsed && s && s[0]) |
14275 | { | |
ed1d1739 KS |
14276 | char *cond_string, *extra_string; |
14277 | int thread, task; | |
ef23e705 TJB |
14278 | |
14279 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14280 | &cond_string, &thread, &task, |
14281 | &extra_string); | |
ef23e705 TJB |
14282 | if (cond_string) |
14283 | b->cond_string = cond_string; | |
14284 | b->thread = thread; | |
14285 | b->task = task; | |
e7e0cddf SS |
14286 | if (extra_string) |
14287 | b->extra_string = extra_string; | |
ef23e705 TJB |
14288 | b->condition_not_parsed = 0; |
14289 | } | |
14290 | ||
983af33b | 14291 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14292 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14293 | |
58438ac1 TT |
14294 | *found = 1; |
14295 | } | |
14296 | else | |
14297 | *found = 0; | |
ef23e705 TJB |
14298 | |
14299 | return sals; | |
14300 | } | |
14301 | ||
348d480f PA |
14302 | /* The default re_set method, for typical hardware or software |
14303 | breakpoints. Reevaluate the breakpoint and recreate its | |
14304 | locations. */ | |
14305 | ||
14306 | static void | |
28010a5d | 14307 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14308 | { |
14309 | int found; | |
f1310107 | 14310 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14311 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14312 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14313 | |
14314 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14315 | if (found) | |
14316 | { | |
14317 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14318 | expanded = sals; |
ef23e705 TJB |
14319 | } |
14320 | ||
f1310107 TJB |
14321 | if (b->addr_string_range_end) |
14322 | { | |
14323 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14324 | if (found) | |
14325 | { | |
14326 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14327 | expanded_end = sals_end; |
f1310107 TJB |
14328 | } |
14329 | } | |
14330 | ||
14331 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14332 | } |
14333 | ||
983af33b SDJ |
14334 | /* Default method for creating SALs from an address string. It basically |
14335 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14336 | ||
14337 | static void | |
14338 | create_sals_from_address_default (char **arg, | |
14339 | struct linespec_result *canonical, | |
14340 | enum bptype type_wanted, | |
14341 | char *addr_start, char **copy_arg) | |
14342 | { | |
14343 | parse_breakpoint_sals (arg, canonical); | |
14344 | } | |
14345 | ||
14346 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14347 | function for the `create_breakpoints_sal' method of | |
14348 | breakpoint_ops. */ | |
14349 | ||
14350 | static void | |
14351 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14352 | struct linespec_result *canonical, | |
14353 | struct linespec_sals *lsal, | |
14354 | char *cond_string, | |
e7e0cddf | 14355 | char *extra_string, |
983af33b SDJ |
14356 | enum bptype type_wanted, |
14357 | enum bpdisp disposition, | |
14358 | int thread, | |
14359 | int task, int ignore_count, | |
14360 | const struct breakpoint_ops *ops, | |
14361 | int from_tty, int enabled, | |
44f238bb | 14362 | int internal, unsigned flags) |
983af33b SDJ |
14363 | { |
14364 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14365 | extra_string, |
983af33b SDJ |
14366 | type_wanted, disposition, |
14367 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14368 | enabled, internal, flags); |
983af33b SDJ |
14369 | } |
14370 | ||
14371 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14372 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14373 | ||
14374 | static void | |
14375 | decode_linespec_default (struct breakpoint *b, char **s, | |
14376 | struct symtabs_and_lines *sals) | |
14377 | { | |
14378 | struct linespec_result canonical; | |
14379 | ||
14380 | init_linespec_result (&canonical); | |
14381 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14382 | (struct symtab *) NULL, 0, | |
14383 | &canonical, multiple_symbols_all, | |
14384 | b->filter); | |
14385 | ||
14386 | /* We should get 0 or 1 resulting SALs. */ | |
14387 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14388 | ||
14389 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14390 | { | |
14391 | struct linespec_sals *lsal; | |
14392 | ||
14393 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14394 | *sals = lsal->sals; | |
14395 | /* Arrange it so the destructor does not free the | |
14396 | contents. */ | |
14397 | lsal->sals.sals = NULL; | |
14398 | } | |
14399 | ||
14400 | destroy_linespec_result (&canonical); | |
14401 | } | |
14402 | ||
28010a5d PA |
14403 | /* Prepare the global context for a re-set of breakpoint B. */ |
14404 | ||
14405 | static struct cleanup * | |
14406 | prepare_re_set_context (struct breakpoint *b) | |
14407 | { | |
14408 | struct cleanup *cleanups; | |
14409 | ||
14410 | input_radix = b->input_radix; | |
14411 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14412 | if (b->pspace != NULL) |
14413 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14414 | set_language (b->language); |
14415 | ||
14416 | return cleanups; | |
ef23e705 TJB |
14417 | } |
14418 | ||
c906108c SS |
14419 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14420 | The value we return ends up being the return value from catch_errors. | |
14421 | Unused in this case. */ | |
14422 | ||
14423 | static int | |
4efb68b1 | 14424 | breakpoint_re_set_one (void *bint) |
c906108c | 14425 | { |
4a64f543 | 14426 | /* Get past catch_errs. */ |
53a5351d | 14427 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14428 | struct cleanup *cleanups; |
c906108c | 14429 | |
348d480f PA |
14430 | cleanups = prepare_re_set_context (b); |
14431 | b->ops->re_set (b); | |
14432 | do_cleanups (cleanups); | |
c906108c SS |
14433 | return 0; |
14434 | } | |
14435 | ||
69de3c6a | 14436 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14437 | void |
69de3c6a | 14438 | breakpoint_re_set (void) |
c906108c | 14439 | { |
35df4500 | 14440 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14441 | enum language save_language; |
14442 | int save_input_radix; | |
6c95b8df | 14443 | struct cleanup *old_chain; |
c5aa993b | 14444 | |
c906108c SS |
14445 | save_language = current_language->la_language; |
14446 | save_input_radix = input_radix; | |
6c95b8df PA |
14447 | old_chain = save_current_program_space (); |
14448 | ||
35df4500 | 14449 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14450 | { |
4a64f543 | 14451 | /* Format possible error msg. */ |
fe3f5fa8 | 14452 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14453 | b->number); |
14454 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14455 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14456 | do_cleanups (cleanups); |
c5aa993b | 14457 | } |
c906108c SS |
14458 | set_language (save_language); |
14459 | input_radix = save_input_radix; | |
e62c965a | 14460 | |
0756c555 | 14461 | jit_breakpoint_re_set (); |
4efc6507 | 14462 | |
6c95b8df PA |
14463 | do_cleanups (old_chain); |
14464 | ||
af02033e PP |
14465 | create_overlay_event_breakpoint (); |
14466 | create_longjmp_master_breakpoint (); | |
14467 | create_std_terminate_master_breakpoint (); | |
186c406b | 14468 | create_exception_master_breakpoint (); |
c906108c SS |
14469 | } |
14470 | \f | |
c906108c SS |
14471 | /* Reset the thread number of this breakpoint: |
14472 | ||
14473 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14474 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14475 | void |
fba45db2 | 14476 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14477 | { |
14478 | if (b->thread != -1) | |
14479 | { | |
39f77062 KB |
14480 | if (in_thread_list (inferior_ptid)) |
14481 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14482 | |
14483 | /* We're being called after following a fork. The new fork is | |
14484 | selected as current, and unless this was a vfork will have a | |
14485 | different program space from the original thread. Reset that | |
14486 | as well. */ | |
14487 | b->loc->pspace = current_program_space; | |
c906108c SS |
14488 | } |
14489 | } | |
14490 | ||
03ac34d5 MS |
14491 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14492 | If from_tty is nonzero, it prints a message to that effect, | |
14493 | which ends with a period (no newline). */ | |
14494 | ||
c906108c | 14495 | void |
fba45db2 | 14496 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14497 | { |
52f0bd74 | 14498 | struct breakpoint *b; |
c906108c SS |
14499 | |
14500 | if (count < 0) | |
14501 | count = 0; | |
14502 | ||
14503 | ALL_BREAKPOINTS (b) | |
14504 | if (b->number == bptnum) | |
c5aa993b | 14505 | { |
d77f58be SS |
14506 | if (is_tracepoint (b)) |
14507 | { | |
14508 | if (from_tty && count != 0) | |
14509 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14510 | bptnum); | |
14511 | return; | |
14512 | } | |
14513 | ||
c5aa993b | 14514 | b->ignore_count = count; |
221ea385 KS |
14515 | if (from_tty) |
14516 | { | |
14517 | if (count == 0) | |
3e43a32a MS |
14518 | printf_filtered (_("Will stop next time " |
14519 | "breakpoint %d is reached."), | |
221ea385 KS |
14520 | bptnum); |
14521 | else if (count == 1) | |
a3f17187 | 14522 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14523 | bptnum); |
14524 | else | |
3e43a32a MS |
14525 | printf_filtered (_("Will ignore next %d " |
14526 | "crossings of breakpoint %d."), | |
221ea385 KS |
14527 | count, bptnum); |
14528 | } | |
8d3788bd | 14529 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14530 | return; |
14531 | } | |
c906108c | 14532 | |
8a3fe4f8 | 14533 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14534 | } |
14535 | ||
c906108c SS |
14536 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14537 | ||
14538 | static void | |
fba45db2 | 14539 | ignore_command (char *args, int from_tty) |
c906108c SS |
14540 | { |
14541 | char *p = args; | |
52f0bd74 | 14542 | int num; |
c906108c SS |
14543 | |
14544 | if (p == 0) | |
e2e0b3e5 | 14545 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14546 | |
c906108c | 14547 | num = get_number (&p); |
5c44784c | 14548 | if (num == 0) |
8a3fe4f8 | 14549 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14550 | if (*p == 0) |
8a3fe4f8 | 14551 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14552 | |
14553 | set_ignore_count (num, | |
14554 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14555 | from_tty); | |
221ea385 KS |
14556 | if (from_tty) |
14557 | printf_filtered ("\n"); | |
c906108c SS |
14558 | } |
14559 | \f | |
14560 | /* Call FUNCTION on each of the breakpoints | |
14561 | whose numbers are given in ARGS. */ | |
14562 | ||
14563 | static void | |
95a42b64 TT |
14564 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14565 | void *), | |
14566 | void *data) | |
c906108c | 14567 | { |
52f0bd74 AC |
14568 | int num; |
14569 | struct breakpoint *b, *tmp; | |
11cf8741 | 14570 | int match; |
197f0a60 | 14571 | struct get_number_or_range_state state; |
c906108c | 14572 | |
197f0a60 | 14573 | if (args == 0) |
e2e0b3e5 | 14574 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14575 | |
197f0a60 TT |
14576 | init_number_or_range (&state, args); |
14577 | ||
14578 | while (!state.finished) | |
c906108c | 14579 | { |
197f0a60 TT |
14580 | char *p = state.string; |
14581 | ||
11cf8741 | 14582 | match = 0; |
c5aa993b | 14583 | |
197f0a60 | 14584 | num = get_number_or_range (&state); |
5c44784c | 14585 | if (num == 0) |
c5aa993b | 14586 | { |
8a3fe4f8 | 14587 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14588 | } |
14589 | else | |
14590 | { | |
14591 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14592 | if (b->number == num) | |
14593 | { | |
11cf8741 | 14594 | match = 1; |
cdac0397 | 14595 | function (b, data); |
11cf8741 | 14596 | break; |
5c44784c | 14597 | } |
11cf8741 | 14598 | if (match == 0) |
a3f17187 | 14599 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14600 | } |
c906108c SS |
14601 | } |
14602 | } | |
14603 | ||
0d381245 VP |
14604 | static struct bp_location * |
14605 | find_location_by_number (char *number) | |
14606 | { | |
14607 | char *dot = strchr (number, '.'); | |
14608 | char *p1; | |
14609 | int bp_num; | |
14610 | int loc_num; | |
14611 | struct breakpoint *b; | |
14612 | struct bp_location *loc; | |
14613 | ||
14614 | *dot = '\0'; | |
14615 | ||
14616 | p1 = number; | |
197f0a60 | 14617 | bp_num = get_number (&p1); |
0d381245 VP |
14618 | if (bp_num == 0) |
14619 | error (_("Bad breakpoint number '%s'"), number); | |
14620 | ||
14621 | ALL_BREAKPOINTS (b) | |
14622 | if (b->number == bp_num) | |
14623 | { | |
14624 | break; | |
14625 | } | |
14626 | ||
14627 | if (!b || b->number != bp_num) | |
14628 | error (_("Bad breakpoint number '%s'"), number); | |
14629 | ||
14630 | p1 = dot+1; | |
197f0a60 | 14631 | loc_num = get_number (&p1); |
0d381245 VP |
14632 | if (loc_num == 0) |
14633 | error (_("Bad breakpoint location number '%s'"), number); | |
14634 | ||
14635 | --loc_num; | |
14636 | loc = b->loc; | |
14637 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14638 | ; | |
14639 | if (!loc) | |
14640 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14641 | ||
14642 | return loc; | |
14643 | } | |
14644 | ||
14645 | ||
1900040c MS |
14646 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14647 | If from_tty is nonzero, it prints a message to that effect, | |
14648 | which ends with a period (no newline). */ | |
14649 | ||
c906108c | 14650 | void |
fba45db2 | 14651 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14652 | { |
14653 | /* Never disable a watchpoint scope breakpoint; we want to | |
14654 | hit them when we leave scope so we can delete both the | |
14655 | watchpoint and its scope breakpoint at that time. */ | |
14656 | if (bpt->type == bp_watchpoint_scope) | |
14657 | return; | |
14658 | ||
c2c6d25f | 14659 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 14660 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
14661 | return; |
14662 | ||
b5de0fa7 | 14663 | bpt->enable_state = bp_disabled; |
c906108c | 14664 | |
b775012e LM |
14665 | /* Mark breakpoint locations modified. */ |
14666 | mark_breakpoint_modified (bpt); | |
14667 | ||
d248b706 KY |
14668 | if (target_supports_enable_disable_tracepoint () |
14669 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14670 | { | |
14671 | struct bp_location *location; | |
14672 | ||
14673 | for (location = bpt->loc; location; location = location->next) | |
14674 | target_disable_tracepoint (location); | |
14675 | } | |
14676 | ||
b60e7edf | 14677 | update_global_location_list (0); |
c906108c | 14678 | |
8d3788bd | 14679 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14680 | } |
14681 | ||
51be5b68 PA |
14682 | /* A callback for iterate_over_related_breakpoints. */ |
14683 | ||
14684 | static void | |
14685 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14686 | { | |
14687 | disable_breakpoint (b); | |
14688 | } | |
14689 | ||
95a42b64 TT |
14690 | /* A callback for map_breakpoint_numbers that calls |
14691 | disable_breakpoint. */ | |
14692 | ||
14693 | static void | |
14694 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14695 | { | |
51be5b68 | 14696 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14697 | } |
14698 | ||
c906108c | 14699 | static void |
fba45db2 | 14700 | disable_command (char *args, int from_tty) |
c906108c | 14701 | { |
c906108c | 14702 | if (args == 0) |
46c6471b PA |
14703 | { |
14704 | struct breakpoint *bpt; | |
14705 | ||
14706 | ALL_BREAKPOINTS (bpt) | |
14707 | if (user_breakpoint_p (bpt)) | |
14708 | disable_breakpoint (bpt); | |
14709 | } | |
0d381245 VP |
14710 | else if (strchr (args, '.')) |
14711 | { | |
14712 | struct bp_location *loc = find_location_by_number (args); | |
14713 | if (loc) | |
d248b706 | 14714 | { |
b775012e LM |
14715 | if (loc->enabled) |
14716 | { | |
14717 | loc->enabled = 0; | |
14718 | mark_breakpoint_location_modified (loc); | |
14719 | } | |
d248b706 KY |
14720 | if (target_supports_enable_disable_tracepoint () |
14721 | && current_trace_status ()->running && loc->owner | |
14722 | && is_tracepoint (loc->owner)) | |
14723 | target_disable_tracepoint (loc); | |
14724 | } | |
b60e7edf | 14725 | update_global_location_list (0); |
0d381245 | 14726 | } |
c906108c | 14727 | else |
95a42b64 | 14728 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
14729 | } |
14730 | ||
14731 | static void | |
816338b5 SS |
14732 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14733 | int count) | |
c906108c | 14734 | { |
afe38095 | 14735 | int target_resources_ok; |
c906108c SS |
14736 | |
14737 | if (bpt->type == bp_hardware_breakpoint) | |
14738 | { | |
14739 | int i; | |
c5aa993b | 14740 | i = hw_breakpoint_used_count (); |
53a5351d | 14741 | target_resources_ok = |
d92524f1 | 14742 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14743 | i + 1, 0); |
c906108c | 14744 | if (target_resources_ok == 0) |
8a3fe4f8 | 14745 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14746 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14747 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14748 | } |
14749 | ||
cc60f2e3 | 14750 | if (is_watchpoint (bpt)) |
c906108c | 14751 | { |
d07205c2 JK |
14752 | /* Initialize it just to avoid a GCC false warning. */ |
14753 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 14754 | volatile struct gdb_exception e; |
dde02812 ES |
14755 | |
14756 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 14757 | { |
3a5c3e22 PA |
14758 | struct watchpoint *w = (struct watchpoint *) bpt; |
14759 | ||
1e718ff1 TJB |
14760 | orig_enable_state = bpt->enable_state; |
14761 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14762 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14763 | } |
dde02812 | 14764 | if (e.reason < 0) |
c5aa993b | 14765 | { |
1e718ff1 | 14766 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14767 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14768 | bpt->number); | |
14769 | return; | |
c5aa993b | 14770 | } |
c906108c | 14771 | } |
0101ce28 | 14772 | |
b4c291bb KH |
14773 | if (bpt->enable_state != bp_permanent) |
14774 | bpt->enable_state = bp_enabled; | |
d248b706 | 14775 | |
b775012e LM |
14776 | bpt->enable_state = bp_enabled; |
14777 | ||
14778 | /* Mark breakpoint locations modified. */ | |
14779 | mark_breakpoint_modified (bpt); | |
14780 | ||
d248b706 KY |
14781 | if (target_supports_enable_disable_tracepoint () |
14782 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14783 | { | |
14784 | struct bp_location *location; | |
14785 | ||
14786 | for (location = bpt->loc; location; location = location->next) | |
14787 | target_enable_tracepoint (location); | |
14788 | } | |
14789 | ||
b4c291bb | 14790 | bpt->disposition = disposition; |
816338b5 | 14791 | bpt->enable_count = count; |
b60e7edf | 14792 | update_global_location_list (1); |
9c97429f | 14793 | |
8d3788bd | 14794 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14795 | } |
14796 | ||
fe3f5fa8 | 14797 | |
c906108c | 14798 | void |
fba45db2 | 14799 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14800 | { |
816338b5 | 14801 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14802 | } |
14803 | ||
14804 | static void | |
14805 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14806 | { | |
14807 | enable_breakpoint (bpt); | |
c906108c SS |
14808 | } |
14809 | ||
95a42b64 TT |
14810 | /* A callback for map_breakpoint_numbers that calls |
14811 | enable_breakpoint. */ | |
14812 | ||
14813 | static void | |
14814 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14815 | { | |
51be5b68 | 14816 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14817 | } |
14818 | ||
c906108c SS |
14819 | /* The enable command enables the specified breakpoints (or all defined |
14820 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14821 | in stopping the inferior. */ |
c906108c | 14822 | |
c906108c | 14823 | static void |
fba45db2 | 14824 | enable_command (char *args, int from_tty) |
c906108c | 14825 | { |
c906108c | 14826 | if (args == 0) |
46c6471b PA |
14827 | { |
14828 | struct breakpoint *bpt; | |
14829 | ||
14830 | ALL_BREAKPOINTS (bpt) | |
14831 | if (user_breakpoint_p (bpt)) | |
14832 | enable_breakpoint (bpt); | |
14833 | } | |
0d381245 VP |
14834 | else if (strchr (args, '.')) |
14835 | { | |
14836 | struct bp_location *loc = find_location_by_number (args); | |
14837 | if (loc) | |
d248b706 | 14838 | { |
b775012e LM |
14839 | if (!loc->enabled) |
14840 | { | |
14841 | loc->enabled = 1; | |
14842 | mark_breakpoint_location_modified (loc); | |
14843 | } | |
d248b706 KY |
14844 | if (target_supports_enable_disable_tracepoint () |
14845 | && current_trace_status ()->running && loc->owner | |
14846 | && is_tracepoint (loc->owner)) | |
14847 | target_enable_tracepoint (loc); | |
14848 | } | |
b60e7edf | 14849 | update_global_location_list (1); |
0d381245 | 14850 | } |
c906108c | 14851 | else |
95a42b64 | 14852 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
14853 | } |
14854 | ||
816338b5 SS |
14855 | /* This struct packages up disposition data for application to multiple |
14856 | breakpoints. */ | |
14857 | ||
14858 | struct disp_data | |
14859 | { | |
14860 | enum bpdisp disp; | |
14861 | int count; | |
14862 | }; | |
14863 | ||
c906108c | 14864 | static void |
51be5b68 PA |
14865 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14866 | { | |
816338b5 | 14867 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14868 | |
816338b5 | 14869 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14870 | } |
14871 | ||
14872 | static void | |
14873 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14874 | { |
816338b5 | 14875 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14876 | |
14877 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14878 | } |
14879 | ||
c906108c | 14880 | static void |
fba45db2 | 14881 | enable_once_command (char *args, int from_tty) |
c906108c | 14882 | { |
51be5b68 | 14883 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14884 | } |
14885 | ||
816338b5 SS |
14886 | static void |
14887 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14888 | { | |
14889 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14890 | ||
14891 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14892 | } | |
14893 | ||
14894 | static void | |
14895 | enable_count_command (char *args, int from_tty) | |
14896 | { | |
14897 | int count = get_number (&args); | |
14898 | ||
14899 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14900 | } | |
14901 | ||
c906108c | 14902 | static void |
51be5b68 | 14903 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14904 | { |
816338b5 | 14905 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14906 | |
14907 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14908 | } |
14909 | ||
c906108c | 14910 | static void |
fba45db2 | 14911 | enable_delete_command (char *args, int from_tty) |
c906108c | 14912 | { |
51be5b68 | 14913 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14914 | } |
14915 | \f | |
fa8d40ab JJ |
14916 | static void |
14917 | set_breakpoint_cmd (char *args, int from_tty) | |
14918 | { | |
14919 | } | |
14920 | ||
14921 | static void | |
14922 | show_breakpoint_cmd (char *args, int from_tty) | |
14923 | { | |
14924 | } | |
14925 | ||
1f3b5d1b PP |
14926 | /* Invalidate last known value of any hardware watchpoint if |
14927 | the memory which that value represents has been written to by | |
14928 | GDB itself. */ | |
14929 | ||
14930 | static void | |
8de0566d YQ |
14931 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14932 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14933 | const bfd_byte *data) |
14934 | { | |
14935 | struct breakpoint *bp; | |
14936 | ||
14937 | ALL_BREAKPOINTS (bp) | |
14938 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14939 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14940 | { |
3a5c3e22 | 14941 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14942 | |
3a5c3e22 PA |
14943 | if (wp->val_valid && wp->val) |
14944 | { | |
14945 | struct bp_location *loc; | |
14946 | ||
14947 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14948 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14949 | && loc->address + loc->length > addr | |
14950 | && addr + len > loc->address) | |
14951 | { | |
14952 | value_free (wp->val); | |
14953 | wp->val = NULL; | |
14954 | wp->val_valid = 0; | |
14955 | } | |
14956 | } | |
1f3b5d1b PP |
14957 | } |
14958 | } | |
14959 | ||
8181d85f DJ |
14960 | /* Create and insert a raw software breakpoint at PC. Return an |
14961 | identifier, which should be used to remove the breakpoint later. | |
14962 | In general, places which call this should be using something on the | |
14963 | breakpoint chain instead; this function should be eliminated | |
14964 | someday. */ | |
14965 | ||
14966 | void * | |
6c95b8df PA |
14967 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
14968 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
14969 | { |
14970 | struct bp_target_info *bp_tgt; | |
14971 | ||
6c95b8df | 14972 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 14973 | |
6c95b8df | 14974 | bp_tgt->placed_address_space = aspace; |
8181d85f | 14975 | bp_tgt->placed_address = pc; |
6c95b8df | 14976 | |
a6d9a66e | 14977 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
14978 | { |
14979 | /* Could not insert the breakpoint. */ | |
14980 | xfree (bp_tgt); | |
14981 | return NULL; | |
14982 | } | |
14983 | ||
14984 | return bp_tgt; | |
14985 | } | |
14986 | ||
4a64f543 MS |
14987 | /* Remove a breakpoint BP inserted by |
14988 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
14989 | |
14990 | int | |
a6d9a66e | 14991 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
14992 | { |
14993 | struct bp_target_info *bp_tgt = bp; | |
14994 | int ret; | |
14995 | ||
a6d9a66e | 14996 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
14997 | xfree (bp_tgt); |
14998 | ||
14999 | return ret; | |
15000 | } | |
15001 | ||
4a64f543 MS |
15002 | /* One (or perhaps two) breakpoints used for software single |
15003 | stepping. */ | |
8181d85f DJ |
15004 | |
15005 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 15006 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
15007 | |
15008 | /* Create and insert a breakpoint for software single step. */ | |
15009 | ||
15010 | void | |
6c95b8df | 15011 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15012 | struct address_space *aspace, |
15013 | CORE_ADDR next_pc) | |
8181d85f DJ |
15014 | { |
15015 | void **bpt_p; | |
15016 | ||
15017 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
15018 | { |
15019 | bpt_p = &single_step_breakpoints[0]; | |
15020 | single_step_gdbarch[0] = gdbarch; | |
15021 | } | |
8181d85f DJ |
15022 | else |
15023 | { | |
15024 | gdb_assert (single_step_breakpoints[1] == NULL); | |
15025 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 15026 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
15027 | } |
15028 | ||
4a64f543 MS |
15029 | /* NOTE drow/2006-04-11: A future improvement to this function would |
15030 | be to only create the breakpoints once, and actually put them on | |
15031 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
15032 | We could adjust the addresses each time they were needed. Doing | |
15033 | this requires corresponding changes elsewhere where single step | |
15034 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 15035 | |
6c95b8df | 15036 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 15037 | if (*bpt_p == NULL) |
5af949e3 UW |
15038 | error (_("Could not insert single-step breakpoint at %s"), |
15039 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
15040 | } |
15041 | ||
f02253f1 HZ |
15042 | /* Check if the breakpoints used for software single stepping |
15043 | were inserted or not. */ | |
15044 | ||
15045 | int | |
15046 | single_step_breakpoints_inserted (void) | |
15047 | { | |
15048 | return (single_step_breakpoints[0] != NULL | |
15049 | || single_step_breakpoints[1] != NULL); | |
15050 | } | |
15051 | ||
8181d85f DJ |
15052 | /* Remove and delete any breakpoints used for software single step. */ |
15053 | ||
15054 | void | |
15055 | remove_single_step_breakpoints (void) | |
15056 | { | |
15057 | gdb_assert (single_step_breakpoints[0] != NULL); | |
15058 | ||
15059 | /* See insert_single_step_breakpoint for more about this deprecated | |
15060 | call. */ | |
a6d9a66e UW |
15061 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
15062 | single_step_breakpoints[0]); | |
15063 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
15064 | single_step_breakpoints[0] = NULL; |
15065 | ||
15066 | if (single_step_breakpoints[1] != NULL) | |
15067 | { | |
a6d9a66e UW |
15068 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
15069 | single_step_breakpoints[1]); | |
15070 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
15071 | single_step_breakpoints[1] = NULL; |
15072 | } | |
15073 | } | |
15074 | ||
d03285ec UW |
15075 | /* Delete software single step breakpoints without removing them from |
15076 | the inferior. This is intended to be used if the inferior's address | |
15077 | space where they were inserted is already gone, e.g. after exit or | |
15078 | exec. */ | |
15079 | ||
15080 | void | |
15081 | cancel_single_step_breakpoints (void) | |
15082 | { | |
15083 | int i; | |
15084 | ||
15085 | for (i = 0; i < 2; i++) | |
15086 | if (single_step_breakpoints[i]) | |
15087 | { | |
15088 | xfree (single_step_breakpoints[i]); | |
15089 | single_step_breakpoints[i] = NULL; | |
15090 | single_step_gdbarch[i] = NULL; | |
15091 | } | |
15092 | } | |
15093 | ||
15094 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
15095 | removing them. */ | |
15096 | ||
15097 | static void | |
15098 | detach_single_step_breakpoints (void) | |
15099 | { | |
15100 | int i; | |
15101 | ||
15102 | for (i = 0; i < 2; i++) | |
15103 | if (single_step_breakpoints[i]) | |
15104 | target_remove_breakpoint (single_step_gdbarch[i], | |
15105 | single_step_breakpoints[i]); | |
15106 | } | |
15107 | ||
4a64f543 MS |
15108 | /* Check whether a software single-step breakpoint is inserted at |
15109 | PC. */ | |
1aafd4da UW |
15110 | |
15111 | static int | |
cc59ec59 MS |
15112 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
15113 | CORE_ADDR pc) | |
1aafd4da UW |
15114 | { |
15115 | int i; | |
15116 | ||
15117 | for (i = 0; i < 2; i++) | |
15118 | { | |
15119 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
15120 | if (bp_tgt |
15121 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
15122 | bp_tgt->placed_address, | |
15123 | aspace, pc)) | |
1aafd4da UW |
15124 | return 1; |
15125 | } | |
15126 | ||
15127 | return 0; | |
15128 | } | |
15129 | ||
a96d9b2e SDJ |
15130 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15131 | non-zero otherwise. */ | |
15132 | static int | |
15133 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15134 | { | |
15135 | if (syscall_catchpoint_p (bp) | |
15136 | && bp->enable_state != bp_disabled | |
15137 | && bp->enable_state != bp_call_disabled) | |
15138 | return 1; | |
15139 | else | |
15140 | return 0; | |
15141 | } | |
15142 | ||
15143 | int | |
15144 | catch_syscall_enabled (void) | |
15145 | { | |
fa3064dd YQ |
15146 | struct catch_syscall_inferior_data *inf_data |
15147 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15148 | |
fa3064dd | 15149 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15150 | } |
15151 | ||
15152 | int | |
15153 | catching_syscall_number (int syscall_number) | |
15154 | { | |
15155 | struct breakpoint *bp; | |
15156 | ||
15157 | ALL_BREAKPOINTS (bp) | |
15158 | if (is_syscall_catchpoint_enabled (bp)) | |
15159 | { | |
be5c67c1 PA |
15160 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15161 | ||
15162 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15163 | { |
15164 | int i, iter; | |
15165 | for (i = 0; | |
be5c67c1 | 15166 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15167 | i++) |
15168 | if (syscall_number == iter) | |
15169 | return 1; | |
15170 | } | |
15171 | else | |
15172 | return 1; | |
15173 | } | |
15174 | ||
15175 | return 0; | |
15176 | } | |
15177 | ||
15178 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15179 | static VEC (char_ptr) * |
a96d9b2e | 15180 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15181 | const char *text, const char *word) |
a96d9b2e SDJ |
15182 | { |
15183 | const char **list = get_syscall_names (); | |
49c4e619 | 15184 | VEC (char_ptr) *retlist |
b45627a0 | 15185 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15186 | |
c38eea1a MS |
15187 | xfree (list); |
15188 | return retlist; | |
a96d9b2e SDJ |
15189 | } |
15190 | ||
1042e4c0 SS |
15191 | /* Tracepoint-specific operations. */ |
15192 | ||
15193 | /* Set tracepoint count to NUM. */ | |
15194 | static void | |
15195 | set_tracepoint_count (int num) | |
15196 | { | |
15197 | tracepoint_count = num; | |
4fa62494 | 15198 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15199 | } |
15200 | ||
70221824 | 15201 | static void |
1042e4c0 SS |
15202 | trace_command (char *arg, int from_tty) |
15203 | { | |
55aa24fb SDJ |
15204 | struct breakpoint_ops *ops; |
15205 | const char *arg_cp = arg; | |
15206 | ||
15207 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15208 | ops = &tracepoint_probe_breakpoint_ops; | |
15209 | else | |
15210 | ops = &tracepoint_breakpoint_ops; | |
15211 | ||
558a9d82 YQ |
15212 | create_breakpoint (get_current_arch (), |
15213 | arg, | |
15214 | NULL, 0, NULL, 1 /* parse arg */, | |
15215 | 0 /* tempflag */, | |
15216 | bp_tracepoint /* type_wanted */, | |
15217 | 0 /* Ignore count */, | |
15218 | pending_break_support, | |
15219 | ops, | |
15220 | from_tty, | |
15221 | 1 /* enabled */, | |
15222 | 0 /* internal */, 0); | |
1042e4c0 SS |
15223 | } |
15224 | ||
70221824 | 15225 | static void |
7a697b8d SS |
15226 | ftrace_command (char *arg, int from_tty) |
15227 | { | |
558a9d82 YQ |
15228 | create_breakpoint (get_current_arch (), |
15229 | arg, | |
15230 | NULL, 0, NULL, 1 /* parse arg */, | |
15231 | 0 /* tempflag */, | |
15232 | bp_fast_tracepoint /* type_wanted */, | |
15233 | 0 /* Ignore count */, | |
15234 | pending_break_support, | |
15235 | &tracepoint_breakpoint_ops, | |
15236 | from_tty, | |
15237 | 1 /* enabled */, | |
15238 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15239 | } |
15240 | ||
15241 | /* strace command implementation. Creates a static tracepoint. */ | |
15242 | ||
70221824 | 15243 | static void |
0fb4aa4b PA |
15244 | strace_command (char *arg, int from_tty) |
15245 | { | |
983af33b SDJ |
15246 | struct breakpoint_ops *ops; |
15247 | ||
15248 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15249 | or with a normal static tracepoint. */ | |
15250 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15251 | ops = &strace_marker_breakpoint_ops; | |
15252 | else | |
15253 | ops = &tracepoint_breakpoint_ops; | |
15254 | ||
558a9d82 YQ |
15255 | create_breakpoint (get_current_arch (), |
15256 | arg, | |
15257 | NULL, 0, NULL, 1 /* parse arg */, | |
15258 | 0 /* tempflag */, | |
15259 | bp_static_tracepoint /* type_wanted */, | |
15260 | 0 /* Ignore count */, | |
15261 | pending_break_support, | |
15262 | ops, | |
15263 | from_tty, | |
15264 | 1 /* enabled */, | |
15265 | 0 /* internal */, 0); | |
7a697b8d SS |
15266 | } |
15267 | ||
409873ef SS |
15268 | /* Set up a fake reader function that gets command lines from a linked |
15269 | list that was acquired during tracepoint uploading. */ | |
15270 | ||
15271 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15272 | static int next_cmd; |
409873ef SS |
15273 | |
15274 | static char * | |
15275 | read_uploaded_action (void) | |
15276 | { | |
15277 | char *rslt; | |
15278 | ||
3149d8c1 | 15279 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15280 | |
3149d8c1 | 15281 | next_cmd++; |
409873ef SS |
15282 | |
15283 | return rslt; | |
15284 | } | |
15285 | ||
00bf0b85 SS |
15286 | /* Given information about a tracepoint as recorded on a target (which |
15287 | can be either a live system or a trace file), attempt to create an | |
15288 | equivalent GDB tracepoint. This is not a reliable process, since | |
15289 | the target does not necessarily have all the information used when | |
15290 | the tracepoint was originally defined. */ | |
15291 | ||
d9b3f62e | 15292 | struct tracepoint * |
00bf0b85 | 15293 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15294 | { |
409873ef | 15295 | char *addr_str, small_buf[100]; |
d9b3f62e | 15296 | struct tracepoint *tp; |
fd9b8c24 | 15297 | |
409873ef SS |
15298 | if (utp->at_string) |
15299 | addr_str = utp->at_string; | |
15300 | else | |
15301 | { | |
15302 | /* In the absence of a source location, fall back to raw | |
15303 | address. Since there is no way to confirm that the address | |
15304 | means the same thing as when the trace was started, warn the | |
15305 | user. */ | |
3e43a32a MS |
15306 | warning (_("Uploaded tracepoint %d has no " |
15307 | "source location, using raw address"), | |
409873ef | 15308 | utp->number); |
8c042590 | 15309 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15310 | addr_str = small_buf; |
15311 | } | |
15312 | ||
15313 | /* There's not much we can do with a sequence of bytecodes. */ | |
15314 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15315 | warning (_("Uploaded tracepoint %d condition " |
15316 | "has no source form, ignoring it"), | |
409873ef | 15317 | utp->number); |
d5551862 | 15318 | |
8cdf0e15 | 15319 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15320 | addr_str, |
e7e0cddf SS |
15321 | utp->cond_string, -1, NULL, |
15322 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15323 | 0 /* tempflag */, |
0fb4aa4b | 15324 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15325 | 0 /* Ignore count */, |
15326 | pending_break_support, | |
348d480f | 15327 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15328 | 0 /* from_tty */, |
84f4c1fe | 15329 | utp->enabled /* enabled */, |
44f238bb PA |
15330 | 0 /* internal */, |
15331 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15332 | return NULL; |
15333 | ||
409873ef | 15334 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15335 | tp = get_tracepoint (tracepoint_count); |
15336 | gdb_assert (tp != NULL); | |
d5551862 | 15337 | |
00bf0b85 SS |
15338 | if (utp->pass > 0) |
15339 | { | |
8c042590 PM |
15340 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15341 | tp->base.number); | |
00bf0b85 | 15342 | |
409873ef | 15343 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15344 | } |
15345 | ||
409873ef SS |
15346 | /* If we have uploaded versions of the original commands, set up a |
15347 | special-purpose "reader" function and call the usual command line | |
15348 | reader, then pass the result to the breakpoint command-setting | |
15349 | function. */ | |
3149d8c1 | 15350 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15351 | { |
409873ef | 15352 | struct command_line *cmd_list; |
00bf0b85 | 15353 | |
409873ef | 15354 | this_utp = utp; |
3149d8c1 | 15355 | next_cmd = 0; |
d5551862 | 15356 | |
409873ef SS |
15357 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15358 | ||
d9b3f62e | 15359 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15360 | } |
3149d8c1 SS |
15361 | else if (!VEC_empty (char_ptr, utp->actions) |
15362 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15363 | warning (_("Uploaded tracepoint %d actions " |
15364 | "have no source form, ignoring them"), | |
409873ef | 15365 | utp->number); |
00bf0b85 | 15366 | |
f196051f SS |
15367 | /* Copy any status information that might be available. */ |
15368 | tp->base.hit_count = utp->hit_count; | |
15369 | tp->traceframe_usage = utp->traceframe_usage; | |
15370 | ||
00bf0b85 | 15371 | return tp; |
d9b3f62e | 15372 | } |
00bf0b85 | 15373 | |
1042e4c0 SS |
15374 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15375 | omitted. */ | |
15376 | ||
15377 | static void | |
e5a67952 | 15378 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15379 | { |
79a45e25 | 15380 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15381 | int num_printed; |
1042e4c0 | 15382 | |
e5a67952 | 15383 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15384 | |
15385 | if (num_printed == 0) | |
1042e4c0 | 15386 | { |
e5a67952 | 15387 | if (args == NULL || *args == '\0') |
d77f58be SS |
15388 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15389 | else | |
e5a67952 | 15390 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15391 | } |
ad443146 SS |
15392 | |
15393 | default_collect_info (); | |
1042e4c0 SS |
15394 | } |
15395 | ||
4a64f543 | 15396 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15397 | Not supported by all targets. */ |
15398 | static void | |
15399 | enable_trace_command (char *args, int from_tty) | |
15400 | { | |
15401 | enable_command (args, from_tty); | |
15402 | } | |
15403 | ||
4a64f543 | 15404 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15405 | Not supported by all targets. */ |
15406 | static void | |
15407 | disable_trace_command (char *args, int from_tty) | |
15408 | { | |
15409 | disable_command (args, from_tty); | |
15410 | } | |
15411 | ||
4a64f543 | 15412 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15413 | static void |
15414 | delete_trace_command (char *arg, int from_tty) | |
15415 | { | |
35df4500 | 15416 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15417 | |
15418 | dont_repeat (); | |
15419 | ||
15420 | if (arg == 0) | |
15421 | { | |
15422 | int breaks_to_delete = 0; | |
15423 | ||
15424 | /* Delete all breakpoints if no argument. | |
15425 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15426 | have to be deleted with an explicit breakpoint number |
15427 | argument. */ | |
1042e4c0 | 15428 | ALL_TRACEPOINTS (b) |
46c6471b | 15429 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15430 | { |
15431 | breaks_to_delete = 1; | |
15432 | break; | |
15433 | } | |
1042e4c0 SS |
15434 | |
15435 | /* Ask user only if there are some breakpoints to delete. */ | |
15436 | if (!from_tty | |
15437 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15438 | { | |
35df4500 | 15439 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15440 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15441 | delete_breakpoint (b); |
1042e4c0 SS |
15442 | } |
15443 | } | |
15444 | else | |
51be5b68 | 15445 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15446 | } |
15447 | ||
197f0a60 TT |
15448 | /* Helper function for trace_pass_command. */ |
15449 | ||
15450 | static void | |
d9b3f62e | 15451 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15452 | { |
d9b3f62e | 15453 | tp->pass_count = count; |
6f6484cd | 15454 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15455 | if (from_tty) |
15456 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15457 | tp->base.number, count); |
197f0a60 TT |
15458 | } |
15459 | ||
1042e4c0 SS |
15460 | /* Set passcount for tracepoint. |
15461 | ||
15462 | First command argument is passcount, second is tracepoint number. | |
15463 | If tracepoint number omitted, apply to most recently defined. | |
15464 | Also accepts special argument "all". */ | |
15465 | ||
15466 | static void | |
15467 | trace_pass_command (char *args, int from_tty) | |
15468 | { | |
d9b3f62e | 15469 | struct tracepoint *t1; |
1042e4c0 | 15470 | unsigned int count; |
1042e4c0 SS |
15471 | |
15472 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15473 | error (_("passcount command requires an " |
15474 | "argument (count + optional TP num)")); | |
1042e4c0 | 15475 | |
4a64f543 | 15476 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15477 | |
529480d0 | 15478 | args = skip_spaces (args); |
1042e4c0 SS |
15479 | if (*args && strncasecmp (args, "all", 3) == 0) |
15480 | { | |
d9b3f62e PA |
15481 | struct breakpoint *b; |
15482 | ||
1042e4c0 | 15483 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15484 | if (*args) |
15485 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15486 | |
d9b3f62e | 15487 | ALL_TRACEPOINTS (b) |
197f0a60 | 15488 | { |
d9b3f62e | 15489 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15490 | trace_pass_set_count (t1, count, from_tty); |
15491 | } | |
15492 | } | |
15493 | else if (*args == '\0') | |
1042e4c0 | 15494 | { |
197f0a60 | 15495 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 15496 | if (t1) |
197f0a60 TT |
15497 | trace_pass_set_count (t1, count, from_tty); |
15498 | } | |
15499 | else | |
15500 | { | |
15501 | struct get_number_or_range_state state; | |
15502 | ||
15503 | init_number_or_range (&state, args); | |
15504 | while (!state.finished) | |
1042e4c0 | 15505 | { |
197f0a60 TT |
15506 | t1 = get_tracepoint_by_number (&args, &state, 1); |
15507 | if (t1) | |
15508 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15509 | } |
15510 | } | |
1042e4c0 SS |
15511 | } |
15512 | ||
d9b3f62e | 15513 | struct tracepoint * |
1042e4c0 SS |
15514 | get_tracepoint (int num) |
15515 | { | |
15516 | struct breakpoint *t; | |
15517 | ||
15518 | ALL_TRACEPOINTS (t) | |
15519 | if (t->number == num) | |
d9b3f62e | 15520 | return (struct tracepoint *) t; |
1042e4c0 SS |
15521 | |
15522 | return NULL; | |
15523 | } | |
15524 | ||
d5551862 SS |
15525 | /* Find the tracepoint with the given target-side number (which may be |
15526 | different from the tracepoint number after disconnecting and | |
15527 | reconnecting). */ | |
15528 | ||
d9b3f62e | 15529 | struct tracepoint * |
d5551862 SS |
15530 | get_tracepoint_by_number_on_target (int num) |
15531 | { | |
d9b3f62e | 15532 | struct breakpoint *b; |
d5551862 | 15533 | |
d9b3f62e PA |
15534 | ALL_TRACEPOINTS (b) |
15535 | { | |
15536 | struct tracepoint *t = (struct tracepoint *) b; | |
15537 | ||
15538 | if (t->number_on_target == num) | |
15539 | return t; | |
15540 | } | |
d5551862 SS |
15541 | |
15542 | return NULL; | |
15543 | } | |
15544 | ||
1042e4c0 | 15545 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
15546 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
15547 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 15548 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 15549 | struct tracepoint * |
197f0a60 TT |
15550 | get_tracepoint_by_number (char **arg, |
15551 | struct get_number_or_range_state *state, | |
15552 | int optional_p) | |
1042e4c0 | 15553 | { |
1042e4c0 SS |
15554 | struct breakpoint *t; |
15555 | int tpnum; | |
15556 | char *instring = arg == NULL ? NULL : *arg; | |
15557 | ||
197f0a60 TT |
15558 | if (state) |
15559 | { | |
15560 | gdb_assert (!state->finished); | |
15561 | tpnum = get_number_or_range (state); | |
15562 | } | |
15563 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
15564 | { |
15565 | if (optional_p) | |
15566 | tpnum = tracepoint_count; | |
15567 | else | |
15568 | error_no_arg (_("tracepoint number")); | |
15569 | } | |
15570 | else | |
197f0a60 | 15571 | tpnum = get_number (arg); |
1042e4c0 SS |
15572 | |
15573 | if (tpnum <= 0) | |
15574 | { | |
15575 | if (instring && *instring) | |
15576 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15577 | instring); | |
15578 | else | |
3e43a32a MS |
15579 | printf_filtered (_("Tracepoint argument missing " |
15580 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
15581 | return NULL; |
15582 | } | |
15583 | ||
15584 | ALL_TRACEPOINTS (t) | |
15585 | if (t->number == tpnum) | |
15586 | { | |
d9b3f62e | 15587 | return (struct tracepoint *) t; |
1042e4c0 SS |
15588 | } |
15589 | ||
1042e4c0 SS |
15590 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15591 | return NULL; | |
15592 | } | |
15593 | ||
d9b3f62e PA |
15594 | void |
15595 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15596 | { | |
15597 | if (b->thread != -1) | |
15598 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15599 | ||
15600 | if (b->task != 0) | |
15601 | fprintf_unfiltered (fp, " task %d", b->task); | |
15602 | ||
15603 | fprintf_unfiltered (fp, "\n"); | |
15604 | } | |
15605 | ||
6149aea9 PA |
15606 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15607 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15608 | on each breakpoint and only include the ones for which it returns | |
15609 | non-zero. */ | |
15610 | ||
1042e4c0 | 15611 | static void |
6149aea9 PA |
15612 | save_breakpoints (char *filename, int from_tty, |
15613 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15614 | { |
15615 | struct breakpoint *tp; | |
6149aea9 | 15616 | int any = 0; |
a7bdde9e | 15617 | char *pathname; |
1042e4c0 | 15618 | struct cleanup *cleanup; |
a7bdde9e | 15619 | struct ui_file *fp; |
6149aea9 | 15620 | int extra_trace_bits = 0; |
1042e4c0 | 15621 | |
6149aea9 PA |
15622 | if (filename == 0 || *filename == 0) |
15623 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15624 | |
15625 | /* See if we have anything to save. */ | |
6149aea9 | 15626 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15627 | { |
6149aea9 | 15628 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15629 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15630 | continue; |
15631 | ||
15632 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15633 | if (filter && !filter (tp)) | |
15634 | continue; | |
15635 | ||
15636 | any = 1; | |
15637 | ||
15638 | if (is_tracepoint (tp)) | |
15639 | { | |
15640 | extra_trace_bits = 1; | |
15641 | ||
15642 | /* We can stop searching. */ | |
15643 | break; | |
15644 | } | |
1042e4c0 | 15645 | } |
6149aea9 PA |
15646 | |
15647 | if (!any) | |
1042e4c0 | 15648 | { |
6149aea9 | 15649 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15650 | return; |
15651 | } | |
15652 | ||
6149aea9 | 15653 | pathname = tilde_expand (filename); |
1042e4c0 | 15654 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 15655 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 15656 | if (!fp) |
6149aea9 PA |
15657 | error (_("Unable to open file '%s' for saving (%s)"), |
15658 | filename, safe_strerror (errno)); | |
a7bdde9e | 15659 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15660 | |
6149aea9 PA |
15661 | if (extra_trace_bits) |
15662 | save_trace_state_variables (fp); | |
8bf6485c | 15663 | |
6149aea9 | 15664 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15665 | { |
6149aea9 | 15666 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15667 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15668 | continue; |
8bf6485c | 15669 | |
6149aea9 PA |
15670 | /* If we have a filter, only save the breakpoints it accepts. */ |
15671 | if (filter && !filter (tp)) | |
15672 | continue; | |
15673 | ||
348d480f | 15674 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15675 | |
6149aea9 PA |
15676 | /* Note, we can't rely on tp->number for anything, as we can't |
15677 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15678 | instead. */ | |
15679 | ||
15680 | if (tp->cond_string) | |
15681 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15682 | ||
15683 | if (tp->ignore_count) | |
15684 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15685 | ||
a7bdde9e | 15686 | if (tp->commands) |
1042e4c0 | 15687 | { |
a7bdde9e VP |
15688 | volatile struct gdb_exception ex; |
15689 | ||
6149aea9 | 15690 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15691 | |
79a45e25 | 15692 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15693 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15694 | { |
79a45e25 | 15695 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15696 | } |
79a45e25 | 15697 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15698 | |
a7bdde9e VP |
15699 | if (ex.reason < 0) |
15700 | throw_exception (ex); | |
1042e4c0 | 15701 | |
a7bdde9e | 15702 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15703 | } |
6149aea9 PA |
15704 | |
15705 | if (tp->enable_state == bp_disabled) | |
15706 | fprintf_unfiltered (fp, "disable\n"); | |
15707 | ||
15708 | /* If this is a multi-location breakpoint, check if the locations | |
15709 | should be individually disabled. Watchpoint locations are | |
15710 | special, and not user visible. */ | |
15711 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15712 | { | |
15713 | struct bp_location *loc; | |
15714 | int n = 1; | |
15715 | ||
15716 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15717 | if (!loc->enabled) | |
15718 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15719 | } | |
1042e4c0 | 15720 | } |
8bf6485c | 15721 | |
6149aea9 | 15722 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15723 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15724 | ||
1042e4c0 SS |
15725 | do_cleanups (cleanup); |
15726 | if (from_tty) | |
6149aea9 PA |
15727 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
15728 | } | |
15729 | ||
15730 | /* The `save breakpoints' command. */ | |
15731 | ||
15732 | static void | |
15733 | save_breakpoints_command (char *args, int from_tty) | |
15734 | { | |
15735 | save_breakpoints (args, from_tty, NULL); | |
15736 | } | |
15737 | ||
15738 | /* The `save tracepoints' command. */ | |
15739 | ||
15740 | static void | |
15741 | save_tracepoints_command (char *args, int from_tty) | |
15742 | { | |
15743 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15744 | } |
15745 | ||
15746 | /* Create a vector of all tracepoints. */ | |
15747 | ||
15748 | VEC(breakpoint_p) * | |
eeae04df | 15749 | all_tracepoints (void) |
1042e4c0 SS |
15750 | { |
15751 | VEC(breakpoint_p) *tp_vec = 0; | |
15752 | struct breakpoint *tp; | |
15753 | ||
15754 | ALL_TRACEPOINTS (tp) | |
15755 | { | |
15756 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15757 | } | |
15758 | ||
15759 | return tp_vec; | |
15760 | } | |
15761 | ||
c906108c | 15762 | \f |
4a64f543 MS |
15763 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15764 | commands. It is defined as a macro to prevent duplication. | |
15765 | COMMAND should be a string constant containing the name of the | |
15766 | command. */ | |
31e2b00f | 15767 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15768 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15769 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15770 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
15771 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
15772 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15773 | If a line number is specified, break at start of code for that line.\n\ | |
15774 | If a function is specified, break at start of code for that function.\n\ | |
15775 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15776 | With no LOCATION, uses current execution address of the selected\n\ |
15777 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15778 | \n\ |
15779 | THREADNUM is the number from \"info threads\".\n\ | |
15780 | CONDITION is a boolean expression.\n\ | |
15781 | \n\ | |
d41c0fc8 PA |
15782 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15783 | conditions are different.\n\ | |
31e2b00f AS |
15784 | \n\ |
15785 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15786 | ||
44feb3ce TT |
15787 | /* List of subcommands for "catch". */ |
15788 | static struct cmd_list_element *catch_cmdlist; | |
15789 | ||
15790 | /* List of subcommands for "tcatch". */ | |
15791 | static struct cmd_list_element *tcatch_cmdlist; | |
15792 | ||
9ac4176b | 15793 | void |
44feb3ce TT |
15794 | add_catch_command (char *name, char *docstring, |
15795 | void (*sfunc) (char *args, int from_tty, | |
15796 | struct cmd_list_element *command), | |
625e8578 | 15797 | completer_ftype *completer, |
44feb3ce TT |
15798 | void *user_data_catch, |
15799 | void *user_data_tcatch) | |
15800 | { | |
15801 | struct cmd_list_element *command; | |
15802 | ||
15803 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15804 | &catch_cmdlist); | |
15805 | set_cmd_sfunc (command, sfunc); | |
15806 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15807 | set_cmd_completer (command, completer); |
44feb3ce TT |
15808 | |
15809 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15810 | &tcatch_cmdlist); | |
15811 | set_cmd_sfunc (command, sfunc); | |
15812 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15813 | set_cmd_completer (command, completer); |
44feb3ce TT |
15814 | } |
15815 | ||
6c95b8df | 15816 | static void |
a79b8f6e | 15817 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 15818 | { |
fa3064dd YQ |
15819 | struct catch_syscall_inferior_data *inf_data |
15820 | = get_catch_syscall_inferior_data (inf); | |
15821 | ||
15822 | inf_data->total_syscalls_count = 0; | |
15823 | inf_data->any_syscall_count = 0; | |
15824 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
15825 | } |
15826 | ||
6149aea9 PA |
15827 | static void |
15828 | save_command (char *arg, int from_tty) | |
15829 | { | |
3e43a32a MS |
15830 | printf_unfiltered (_("\"save\" must be followed by " |
15831 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
15832 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
15833 | } | |
15834 | ||
84f4c1fe PM |
15835 | struct breakpoint * |
15836 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15837 | void *data) | |
15838 | { | |
35df4500 | 15839 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15840 | |
35df4500 | 15841 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15842 | { |
15843 | if ((*callback) (b, data)) | |
15844 | return b; | |
15845 | } | |
15846 | ||
15847 | return NULL; | |
15848 | } | |
15849 | ||
0574c78f GB |
15850 | /* Zero if any of the breakpoint's locations could be a location where |
15851 | functions have been inlined, nonzero otherwise. */ | |
15852 | ||
15853 | static int | |
15854 | is_non_inline_function (struct breakpoint *b) | |
15855 | { | |
15856 | /* The shared library event breakpoint is set on the address of a | |
15857 | non-inline function. */ | |
15858 | if (b->type == bp_shlib_event) | |
15859 | return 1; | |
15860 | ||
15861 | return 0; | |
15862 | } | |
15863 | ||
15864 | /* Nonzero if the specified PC cannot be a location where functions | |
15865 | have been inlined. */ | |
15866 | ||
15867 | int | |
09ac7c10 TT |
15868 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15869 | const struct target_waitstatus *ws) | |
0574c78f GB |
15870 | { |
15871 | struct breakpoint *b; | |
15872 | struct bp_location *bl; | |
15873 | ||
15874 | ALL_BREAKPOINTS (b) | |
15875 | { | |
15876 | if (!is_non_inline_function (b)) | |
15877 | continue; | |
15878 | ||
15879 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15880 | { | |
15881 | if (!bl->shlib_disabled | |
09ac7c10 | 15882 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15883 | return 1; |
15884 | } | |
15885 | } | |
15886 | ||
15887 | return 0; | |
15888 | } | |
15889 | ||
2f202fde JK |
15890 | /* Remove any references to OBJFILE which is going to be freed. */ |
15891 | ||
15892 | void | |
15893 | breakpoint_free_objfile (struct objfile *objfile) | |
15894 | { | |
15895 | struct bp_location **locp, *loc; | |
15896 | ||
15897 | ALL_BP_LOCATIONS (loc, locp) | |
15898 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) | |
15899 | loc->symtab = NULL; | |
15900 | } | |
15901 | ||
2060206e PA |
15902 | void |
15903 | initialize_breakpoint_ops (void) | |
15904 | { | |
15905 | static int initialized = 0; | |
15906 | ||
15907 | struct breakpoint_ops *ops; | |
15908 | ||
15909 | if (initialized) | |
15910 | return; | |
15911 | initialized = 1; | |
15912 | ||
15913 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15914 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15915 | internal and momentary breakpoints, etc.). */ | |
15916 | ops = &bkpt_base_breakpoint_ops; | |
15917 | *ops = base_breakpoint_ops; | |
15918 | ops->re_set = bkpt_re_set; | |
15919 | ops->insert_location = bkpt_insert_location; | |
15920 | ops->remove_location = bkpt_remove_location; | |
15921 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
15922 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
15923 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
15924 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
15925 | |
15926 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15927 | ops = &bkpt_breakpoint_ops; | |
15928 | *ops = bkpt_base_breakpoint_ops; | |
15929 | ops->re_set = bkpt_re_set; | |
15930 | ops->resources_needed = bkpt_resources_needed; | |
15931 | ops->print_it = bkpt_print_it; | |
15932 | ops->print_mention = bkpt_print_mention; | |
15933 | ops->print_recreate = bkpt_print_recreate; | |
15934 | ||
15935 | /* Ranged breakpoints. */ | |
15936 | ops = &ranged_breakpoint_ops; | |
15937 | *ops = bkpt_breakpoint_ops; | |
15938 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15939 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15940 | ops->print_it = print_it_ranged_breakpoint; | |
15941 | ops->print_one = print_one_ranged_breakpoint; | |
15942 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15943 | ops->print_mention = print_mention_ranged_breakpoint; | |
15944 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15945 | ||
15946 | /* Internal breakpoints. */ | |
15947 | ops = &internal_breakpoint_ops; | |
15948 | *ops = bkpt_base_breakpoint_ops; | |
15949 | ops->re_set = internal_bkpt_re_set; | |
15950 | ops->check_status = internal_bkpt_check_status; | |
15951 | ops->print_it = internal_bkpt_print_it; | |
15952 | ops->print_mention = internal_bkpt_print_mention; | |
15953 | ||
15954 | /* Momentary breakpoints. */ | |
15955 | ops = &momentary_breakpoint_ops; | |
15956 | *ops = bkpt_base_breakpoint_ops; | |
15957 | ops->re_set = momentary_bkpt_re_set; | |
15958 | ops->check_status = momentary_bkpt_check_status; | |
15959 | ops->print_it = momentary_bkpt_print_it; | |
15960 | ops->print_mention = momentary_bkpt_print_mention; | |
15961 | ||
e2e4d78b JK |
15962 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15963 | ops = &longjmp_breakpoint_ops; | |
15964 | *ops = momentary_breakpoint_ops; | |
15965 | ops->dtor = longjmp_bkpt_dtor; | |
15966 | ||
55aa24fb SDJ |
15967 | /* Probe breakpoints. */ |
15968 | ops = &bkpt_probe_breakpoint_ops; | |
15969 | *ops = bkpt_breakpoint_ops; | |
15970 | ops->insert_location = bkpt_probe_insert_location; | |
15971 | ops->remove_location = bkpt_probe_remove_location; | |
15972 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
15973 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
15974 | ||
2060206e PA |
15975 | /* GNU v3 exception catchpoints. */ |
15976 | ops = &gnu_v3_exception_catchpoint_ops; | |
15977 | *ops = bkpt_breakpoint_ops; | |
15978 | ops->print_it = print_it_exception_catchpoint; | |
15979 | ops->print_one = print_one_exception_catchpoint; | |
15980 | ops->print_mention = print_mention_exception_catchpoint; | |
15981 | ops->print_recreate = print_recreate_exception_catchpoint; | |
15982 | ||
15983 | /* Watchpoints. */ | |
15984 | ops = &watchpoint_breakpoint_ops; | |
15985 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15986 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15987 | ops->re_set = re_set_watchpoint; |
15988 | ops->insert_location = insert_watchpoint; | |
15989 | ops->remove_location = remove_watchpoint; | |
15990 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15991 | ops->check_status = check_status_watchpoint; | |
15992 | ops->resources_needed = resources_needed_watchpoint; | |
15993 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15994 | ops->print_it = print_it_watchpoint; | |
15995 | ops->print_mention = print_mention_watchpoint; | |
15996 | ops->print_recreate = print_recreate_watchpoint; | |
15997 | ||
15998 | /* Masked watchpoints. */ | |
15999 | ops = &masked_watchpoint_breakpoint_ops; | |
16000 | *ops = watchpoint_breakpoint_ops; | |
16001 | ops->insert_location = insert_masked_watchpoint; | |
16002 | ops->remove_location = remove_masked_watchpoint; | |
16003 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16004 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16005 | ops->print_it = print_it_masked_watchpoint; | |
16006 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16007 | ops->print_mention = print_mention_masked_watchpoint; | |
16008 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16009 | ||
16010 | /* Tracepoints. */ | |
16011 | ops = &tracepoint_breakpoint_ops; | |
16012 | *ops = base_breakpoint_ops; | |
16013 | ops->re_set = tracepoint_re_set; | |
16014 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16015 | ops->print_one_detail = tracepoint_print_one_detail; | |
16016 | ops->print_mention = tracepoint_print_mention; | |
16017 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
16018 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
16019 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
16020 | ops->decode_linespec = tracepoint_decode_linespec; | |
16021 | ||
55aa24fb SDJ |
16022 | /* Probe tracepoints. */ |
16023 | ops = &tracepoint_probe_breakpoint_ops; | |
16024 | *ops = tracepoint_breakpoint_ops; | |
16025 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
16026 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
16027 | ||
983af33b SDJ |
16028 | /* Static tracepoints with marker (`-m'). */ |
16029 | ops = &strace_marker_breakpoint_ops; | |
16030 | *ops = tracepoint_breakpoint_ops; | |
16031 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
16032 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
16033 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
16034 | |
16035 | /* Fork catchpoints. */ | |
16036 | ops = &catch_fork_breakpoint_ops; | |
16037 | *ops = base_breakpoint_ops; | |
16038 | ops->insert_location = insert_catch_fork; | |
16039 | ops->remove_location = remove_catch_fork; | |
16040 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16041 | ops->print_it = print_it_catch_fork; | |
16042 | ops->print_one = print_one_catch_fork; | |
16043 | ops->print_mention = print_mention_catch_fork; | |
16044 | ops->print_recreate = print_recreate_catch_fork; | |
16045 | ||
16046 | /* Vfork catchpoints. */ | |
16047 | ops = &catch_vfork_breakpoint_ops; | |
16048 | *ops = base_breakpoint_ops; | |
16049 | ops->insert_location = insert_catch_vfork; | |
16050 | ops->remove_location = remove_catch_vfork; | |
16051 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16052 | ops->print_it = print_it_catch_vfork; | |
16053 | ops->print_one = print_one_catch_vfork; | |
16054 | ops->print_mention = print_mention_catch_vfork; | |
16055 | ops->print_recreate = print_recreate_catch_vfork; | |
16056 | ||
16057 | /* Exec catchpoints. */ | |
16058 | ops = &catch_exec_breakpoint_ops; | |
16059 | *ops = base_breakpoint_ops; | |
16060 | ops->dtor = dtor_catch_exec; | |
16061 | ops->insert_location = insert_catch_exec; | |
16062 | ops->remove_location = remove_catch_exec; | |
16063 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16064 | ops->print_it = print_it_catch_exec; | |
16065 | ops->print_one = print_one_catch_exec; | |
16066 | ops->print_mention = print_mention_catch_exec; | |
16067 | ops->print_recreate = print_recreate_catch_exec; | |
16068 | ||
16069 | /* Syscall catchpoints. */ | |
16070 | ops = &catch_syscall_breakpoint_ops; | |
16071 | *ops = base_breakpoint_ops; | |
16072 | ops->dtor = dtor_catch_syscall; | |
16073 | ops->insert_location = insert_catch_syscall; | |
16074 | ops->remove_location = remove_catch_syscall; | |
16075 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16076 | ops->print_it = print_it_catch_syscall; | |
16077 | ops->print_one = print_one_catch_syscall; | |
16078 | ops->print_mention = print_mention_catch_syscall; | |
16079 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16080 | |
16081 | /* Solib-related catchpoints. */ | |
16082 | ops = &catch_solib_breakpoint_ops; | |
16083 | *ops = base_breakpoint_ops; | |
16084 | ops->dtor = dtor_catch_solib; | |
16085 | ops->insert_location = insert_catch_solib; | |
16086 | ops->remove_location = remove_catch_solib; | |
16087 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16088 | ops->check_status = check_status_catch_solib; | |
16089 | ops->print_it = print_it_catch_solib; | |
16090 | ops->print_one = print_one_catch_solib; | |
16091 | ops->print_mention = print_mention_catch_solib; | |
16092 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16093 | |
16094 | ops = &dprintf_breakpoint_ops; | |
16095 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16096 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16097 | ops->resources_needed = bkpt_resources_needed; |
16098 | ops->print_it = bkpt_print_it; | |
16099 | ops->print_mention = bkpt_print_mention; | |
16100 | ops->print_recreate = bkpt_print_recreate; | |
2060206e PA |
16101 | } |
16102 | ||
8bfd80db YQ |
16103 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16104 | ||
16105 | static struct cmd_list_element *enablebreaklist = NULL; | |
16106 | ||
c906108c | 16107 | void |
fba45db2 | 16108 | _initialize_breakpoint (void) |
c906108c SS |
16109 | { |
16110 | struct cmd_list_element *c; | |
16111 | ||
2060206e PA |
16112 | initialize_breakpoint_ops (); |
16113 | ||
84acb35a | 16114 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 16115 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16116 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16117 | |
55aa24fb SDJ |
16118 | breakpoint_objfile_key |
16119 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16120 | |
fa3064dd | 16121 | catch_syscall_inferior_data |
8e260fc0 TT |
16122 | = register_inferior_data_with_cleanup (NULL, |
16123 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16124 | |
c906108c SS |
16125 | breakpoint_chain = 0; |
16126 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16127 | before a breakpoint is set. */ | |
16128 | breakpoint_count = 0; | |
16129 | ||
1042e4c0 SS |
16130 | tracepoint_count = 0; |
16131 | ||
1bedd215 AC |
16132 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16133 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16134 | Usage is `ignore N COUNT'.")); | |
c906108c | 16135 | if (xdb_commands) |
c5aa993b | 16136 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16137 | |
1bedd215 AC |
16138 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16139 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16140 | Give breakpoint number as argument after \"commands\".\n\ |
16141 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16142 | The commands themselves follow starting on the next line.\n\ | |
16143 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16144 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16145 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16146 | |
d55637df | 16147 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16148 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16149 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16150 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16151 | set_cmd_completer (c, condition_completer); |
c906108c | 16152 | |
1bedd215 | 16153 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16154 | Set a temporary breakpoint.\n\ |
c906108c SS |
16155 | Like \"break\" except the breakpoint is only temporary,\n\ |
16156 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16157 | by using \"enable delete\" on the breakpoint number.\n\ |
16158 | \n" | |
16159 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16160 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16161 | |
1bedd215 | 16162 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16163 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16164 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16165 | some target hardware may not have this support.\n\ |
16166 | \n" | |
16167 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16168 | set_cmd_completer (c, location_completer); |
c906108c | 16169 | |
1bedd215 | 16170 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16171 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16172 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16173 | so it will be deleted when hit.\n\ |
16174 | \n" | |
16175 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16176 | set_cmd_completer (c, location_completer); |
c906108c | 16177 | |
1bedd215 AC |
16178 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16179 | Enable some breakpoints.\n\ | |
c906108c SS |
16180 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16181 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16182 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16183 | With a subcommand you can enable temporarily."), |
c906108c SS |
16184 | &enablelist, "enable ", 1, &cmdlist); |
16185 | if (xdb_commands) | |
1bedd215 AC |
16186 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16187 | Enable some breakpoints.\n\ | |
c906108c SS |
16188 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16189 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16190 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16191 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16192 | |
16193 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16194 | ||
84951ab5 | 16195 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16196 | Enable some breakpoints.\n\ |
c906108c SS |
16197 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16198 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16199 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16200 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16201 | |
1a966eab AC |
16202 | add_cmd ("once", no_class, enable_once_command, _("\ |
16203 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16204 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16205 | &enablebreaklist); |
16206 | ||
1a966eab AC |
16207 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16208 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16209 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16210 | &enablebreaklist); |
16211 | ||
816338b5 SS |
16212 | add_cmd ("count", no_class, enable_count_command, _("\ |
16213 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16214 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16215 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16216 | &enablebreaklist); | |
16217 | ||
1a966eab AC |
16218 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16219 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16220 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16221 | &enablelist); |
16222 | ||
1a966eab AC |
16223 | add_cmd ("once", no_class, enable_once_command, _("\ |
16224 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16225 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16226 | &enablelist); |
16227 | ||
16228 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16229 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16230 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16231 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16232 | &enablelist); |
16233 | ||
1bedd215 AC |
16234 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16235 | Disable some breakpoints.\n\ | |
c906108c SS |
16236 | Arguments are breakpoint numbers with spaces in between.\n\ |
16237 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16238 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16239 | &disablelist, "disable ", 1, &cmdlist); |
16240 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16241 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16242 | if (xdb_commands) | |
1bedd215 AC |
16243 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16244 | Disable some breakpoints.\n\ | |
c906108c SS |
16245 | Arguments are breakpoint numbers with spaces in between.\n\ |
16246 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16247 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16248 | |
1a966eab AC |
16249 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16250 | Disable some breakpoints.\n\ | |
c906108c SS |
16251 | Arguments are breakpoint numbers with spaces in between.\n\ |
16252 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16253 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16254 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16255 | &disablelist); |
16256 | ||
1bedd215 AC |
16257 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16258 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16259 | Arguments are breakpoint numbers with spaces in between.\n\ |
16260 | To delete all breakpoints, give no argument.\n\ | |
16261 | \n\ | |
16262 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16263 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16264 | &deletelist, "delete ", 1, &cmdlist); |
16265 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16266 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16267 | if (xdb_commands) |
1bedd215 AC |
16268 | add_com ("db", class_breakpoint, delete_command, _("\ |
16269 | Delete some breakpoints.\n\ | |
c906108c | 16270 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16271 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16272 | |
1a966eab AC |
16273 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16274 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16275 | Arguments are breakpoint numbers with spaces in between.\n\ |
16276 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16277 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16278 | &deletelist); |
16279 | ||
1bedd215 AC |
16280 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16281 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16282 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16283 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16284 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16285 | If an address is specified, breakpoints at that address are cleared.\n\ |
16286 | \n\ | |
16287 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16288 | is executing in.\n\ |
16289 | \n\ | |
1bedd215 | 16290 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16291 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16292 | |
1bedd215 | 16293 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16294 | Set breakpoint at specified line or function.\n" |
16295 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16296 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16297 | |
c906108c SS |
16298 | add_com_alias ("b", "break", class_run, 1); |
16299 | add_com_alias ("br", "break", class_run, 1); | |
16300 | add_com_alias ("bre", "break", class_run, 1); | |
16301 | add_com_alias ("brea", "break", class_run, 1); | |
16302 | ||
7681d515 PM |
16303 | if (xdb_commands) |
16304 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16305 | |
16306 | if (dbx_commands) | |
16307 | { | |
1bedd215 AC |
16308 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16309 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16310 | &stoplist, "stop ", 1, &cmdlist); |
16311 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16312 | _("Break in function or address."), &stoplist); |
c5aa993b | 16313 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16314 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16315 | add_com ("status", class_info, breakpoints_info, _("\ |
16316 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16317 | The \"Type\" column indicates one of:\n\ |
16318 | \tbreakpoint - normal breakpoint\n\ | |
16319 | \twatchpoint - watchpoint\n\ | |
16320 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16321 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16322 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16323 | address and file/line number respectively.\n\ |
16324 | \n\ | |
16325 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16326 | are set to the address of the last breakpoint listed unless the command\n\ |
16327 | is prefixed with \"server \".\n\n\ | |
c906108c | 16328 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16329 | breakpoint set.")); |
c906108c SS |
16330 | } |
16331 | ||
1bedd215 | 16332 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16333 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16334 | The \"Type\" column indicates one of:\n\ |
16335 | \tbreakpoint - normal breakpoint\n\ | |
16336 | \twatchpoint - watchpoint\n\ | |
16337 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16338 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16339 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16340 | address and file/line number respectively.\n\ |
16341 | \n\ | |
16342 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16343 | are set to the address of the last breakpoint listed unless the command\n\ |
16344 | is prefixed with \"server \".\n\n\ | |
c906108c | 16345 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16346 | breakpoint set.")); |
c906108c | 16347 | |
6b04bdb7 MS |
16348 | add_info_alias ("b", "breakpoints", 1); |
16349 | ||
c906108c | 16350 | if (xdb_commands) |
1bedd215 AC |
16351 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16352 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16353 | The \"Type\" column indicates one of:\n\ |
16354 | \tbreakpoint - normal breakpoint\n\ | |
16355 | \twatchpoint - watchpoint\n\ | |
16356 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16357 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16358 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16359 | address and file/line number respectively.\n\ |
16360 | \n\ | |
16361 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16362 | are set to the address of the last breakpoint listed unless the command\n\ |
16363 | is prefixed with \"server \".\n\n\ | |
c906108c | 16364 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16365 | breakpoint set.")); |
c906108c | 16366 | |
1a966eab AC |
16367 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16368 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16369 | The \"Type\" column indicates one of:\n\ |
16370 | \tbreakpoint - normal breakpoint\n\ | |
16371 | \twatchpoint - watchpoint\n\ | |
16372 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16373 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16374 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16375 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16376 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16377 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16378 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16379 | address and file/line number respectively.\n\ |
16380 | \n\ | |
16381 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16382 | are set to the address of the last breakpoint listed unless the command\n\ |
16383 | is prefixed with \"server \".\n\n\ | |
c906108c | 16384 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16385 | breakpoint set."), |
c906108c SS |
16386 | &maintenanceinfolist); |
16387 | ||
44feb3ce TT |
16388 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16389 | Set catchpoints to catch events."), | |
16390 | &catch_cmdlist, "catch ", | |
16391 | 0/*allow-unknown*/, &cmdlist); | |
16392 | ||
16393 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16394 | Set temporary catchpoints to catch events."), | |
16395 | &tcatch_cmdlist, "tcatch ", | |
16396 | 0/*allow-unknown*/, &cmdlist); | |
16397 | ||
16398 | /* Add catch and tcatch sub-commands. */ | |
16399 | add_catch_command ("catch", _("\ | |
88e7d25d | 16400 | Catch an exception, when caught."), |
44feb3ce | 16401 | catch_catch_command, |
a96d9b2e | 16402 | NULL, |
44feb3ce TT |
16403 | CATCH_PERMANENT, |
16404 | CATCH_TEMPORARY); | |
16405 | add_catch_command ("throw", _("\ | |
88e7d25d | 16406 | Catch an exception, when thrown."), |
44feb3ce | 16407 | catch_throw_command, |
a96d9b2e | 16408 | NULL, |
44feb3ce TT |
16409 | CATCH_PERMANENT, |
16410 | CATCH_TEMPORARY); | |
591f19e8 TT |
16411 | add_catch_command ("rethrow", _("\ |
16412 | Catch an exception, when rethrown."), | |
16413 | catch_rethrow_command, | |
16414 | NULL, | |
16415 | CATCH_PERMANENT, | |
16416 | CATCH_TEMPORARY); | |
44feb3ce TT |
16417 | add_catch_command ("fork", _("Catch calls to fork."), |
16418 | catch_fork_command_1, | |
a96d9b2e | 16419 | NULL, |
44feb3ce TT |
16420 | (void *) (uintptr_t) catch_fork_permanent, |
16421 | (void *) (uintptr_t) catch_fork_temporary); | |
16422 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16423 | catch_fork_command_1, | |
a96d9b2e | 16424 | NULL, |
44feb3ce TT |
16425 | (void *) (uintptr_t) catch_vfork_permanent, |
16426 | (void *) (uintptr_t) catch_vfork_temporary); | |
16427 | add_catch_command ("exec", _("Catch calls to exec."), | |
16428 | catch_exec_command_1, | |
a96d9b2e SDJ |
16429 | NULL, |
16430 | CATCH_PERMANENT, | |
16431 | CATCH_TEMPORARY); | |
edcc5120 TT |
16432 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16433 | Usage: catch load [REGEX]\n\ | |
16434 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16435 | catch_load_command_1, | |
16436 | NULL, | |
16437 | CATCH_PERMANENT, | |
16438 | CATCH_TEMPORARY); | |
16439 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16440 | Usage: catch unload [REGEX]\n\ | |
16441 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16442 | catch_unload_command_1, | |
16443 | NULL, | |
16444 | CATCH_PERMANENT, | |
16445 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16446 | add_catch_command ("syscall", _("\ |
16447 | Catch system calls by their names and/or numbers.\n\ | |
16448 | Arguments say which system calls to catch. If no arguments\n\ | |
16449 | are given, every system call will be caught.\n\ | |
16450 | Arguments, if given, should be one or more system call names\n\ | |
16451 | (if your system supports that), or system call numbers."), | |
16452 | catch_syscall_command_1, | |
16453 | catch_syscall_completer, | |
44feb3ce TT |
16454 | CATCH_PERMANENT, |
16455 | CATCH_TEMPORARY); | |
c5aa993b | 16456 | |
1bedd215 AC |
16457 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16458 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16459 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16460 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16461 | an expression changes.\n\ |
16462 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16463 | the memory to which it refers.")); | |
65d12d83 | 16464 | set_cmd_completer (c, expression_completer); |
c906108c | 16465 | |
1bedd215 AC |
16466 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16467 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16468 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16469 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16470 | an expression is read.\n\ |
16471 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16472 | the memory to which it refers.")); | |
65d12d83 | 16473 | set_cmd_completer (c, expression_completer); |
c906108c | 16474 | |
1bedd215 AC |
16475 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16476 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16477 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16478 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16479 | an expression is either read or written.\n\ |
16480 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16481 | the memory to which it refers.")); | |
65d12d83 | 16482 | set_cmd_completer (c, expression_completer); |
c906108c | 16483 | |
d77f58be | 16484 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16485 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16486 | |
920d2a44 AC |
16487 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16488 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16489 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16490 | &can_use_hw_watchpoints, _("\ | |
16491 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16492 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16493 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16494 | such is available. (However, any hardware watchpoints that were\n\ | |
16495 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16496 | hardware.)"), |
16497 | NULL, | |
920d2a44 | 16498 | show_can_use_hw_watchpoints, |
85c07804 | 16499 | &setlist, &showlist); |
c906108c SS |
16500 | |
16501 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16502 | |
1042e4c0 SS |
16503 | /* Tracepoint manipulation commands. */ |
16504 | ||
16505 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16506 | Set a tracepoint at specified line or function.\n\ | |
16507 | \n" | |
16508 | BREAK_ARGS_HELP ("trace") "\n\ | |
16509 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16510 | set_cmd_completer (c, location_completer); | |
16511 | ||
16512 | add_com_alias ("tp", "trace", class_alias, 0); | |
16513 | add_com_alias ("tr", "trace", class_alias, 1); | |
16514 | add_com_alias ("tra", "trace", class_alias, 1); | |
16515 | add_com_alias ("trac", "trace", class_alias, 1); | |
16516 | ||
7a697b8d SS |
16517 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16518 | Set a fast tracepoint at specified line or function.\n\ | |
16519 | \n" | |
16520 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16521 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16522 | set_cmd_completer (c, location_completer); | |
16523 | ||
0fb4aa4b PA |
16524 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16525 | Set a static tracepoint at specified line, function or marker.\n\ | |
16526 | \n\ | |
16527 | strace [LOCATION] [if CONDITION]\n\ | |
16528 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16529 | or -m MARKER_ID.\n\ | |
16530 | If a line number is specified, probe the marker at start of code\n\ | |
16531 | for that line. If a function is specified, probe the marker at start\n\ | |
16532 | of code for that function. If an address is specified, probe the marker\n\ | |
16533 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16534 | with that name. With no LOCATION, uses current execution address of\n\ | |
16535 | the selected stack frame.\n\ | |
16536 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16537 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16538 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16539 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16540 | \n\ | |
16541 | CONDITION is a boolean expression.\n\ | |
16542 | \n\ | |
d41c0fc8 PA |
16543 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16544 | conditions are different.\n\ | |
0fb4aa4b PA |
16545 | \n\ |
16546 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16547 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16548 | set_cmd_completer (c, location_completer); | |
16549 | ||
1042e4c0 | 16550 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16551 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16552 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16553 | last tracepoint set.")); | |
16554 | ||
16555 | add_info_alias ("tp", "tracepoints", 1); | |
16556 | ||
16557 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16558 | Delete specified tracepoints.\n\ | |
16559 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16560 | No argument means delete all tracepoints."), | |
16561 | &deletelist); | |
7e20dfcd | 16562 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16563 | |
16564 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16565 | Disable specified tracepoints.\n\ | |
16566 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16567 | No argument means disable all tracepoints."), | |
16568 | &disablelist); | |
16569 | deprecate_cmd (c, "disable"); | |
16570 | ||
16571 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16572 | Enable specified tracepoints.\n\ | |
16573 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16574 | No argument means enable all tracepoints."), | |
16575 | &enablelist); | |
16576 | deprecate_cmd (c, "enable"); | |
16577 | ||
16578 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16579 | Set the passcount for a tracepoint.\n\ | |
16580 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16581 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16582 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16583 | ||
6149aea9 PA |
16584 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16585 | _("Save breakpoint definitions as a script."), | |
16586 | &save_cmdlist, "save ", | |
16587 | 0/*allow-unknown*/, &cmdlist); | |
16588 | ||
16589 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16590 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16591 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16592 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16593 | session to restore them."), | |
16594 | &save_cmdlist); | |
16595 | set_cmd_completer (c, filename_completer); | |
16596 | ||
16597 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16598 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16599 | Use the 'source' command in another debug session to restore them."), |
16600 | &save_cmdlist); | |
1042e4c0 SS |
16601 | set_cmd_completer (c, filename_completer); |
16602 | ||
6149aea9 PA |
16603 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16604 | deprecate_cmd (c, "save tracepoints"); | |
16605 | ||
1bedd215 | 16606 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16607 | Breakpoint specific settings\n\ |
16608 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16609 | pending breakpoint behavior"), |
fa8d40ab JJ |
16610 | &breakpoint_set_cmdlist, "set breakpoint ", |
16611 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16612 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16613 | Breakpoint specific settings\n\ |
16614 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16615 | pending breakpoint behavior"), |
fa8d40ab JJ |
16616 | &breakpoint_show_cmdlist, "show breakpoint ", |
16617 | 0/*allow-unknown*/, &showlist); | |
16618 | ||
7915a72c AC |
16619 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16620 | &pending_break_support, _("\ | |
16621 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16622 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16623 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16624 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16625 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16626 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16627 | NULL, |
920d2a44 | 16628 | show_pending_break_support, |
6e1d7d6c AC |
16629 | &breakpoint_set_cmdlist, |
16630 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16631 | |
16632 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16633 | |
16634 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16635 | &automatic_hardware_breakpoints, _("\ | |
16636 | Set automatic usage of hardware breakpoints."), _("\ | |
16637 | Show automatic usage of hardware breakpoints."), _("\ | |
16638 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16639 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16640 | a warning will be emitted for such breakpoints."), | |
16641 | NULL, | |
16642 | show_automatic_hardware_breakpoints, | |
16643 | &breakpoint_set_cmdlist, | |
16644 | &breakpoint_show_cmdlist); | |
74960c60 | 16645 | |
72d0e2c5 YQ |
16646 | add_setshow_auto_boolean_cmd ("always-inserted", class_support, |
16647 | &always_inserted_mode, _("\ | |
74960c60 VP |
16648 | Set mode for inserting breakpoints."), _("\ |
16649 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
16650 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
16651 | resumed, and removed when execution stops. When this mode is on,\n\ | |
16652 | breakpoints are inserted immediately and removed only when the user\n\ | |
16653 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
16654 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
16655 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
16656 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
16657 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
72d0e2c5 YQ |
16658 | NULL, |
16659 | &show_always_inserted_mode, | |
16660 | &breakpoint_set_cmdlist, | |
16661 | &breakpoint_show_cmdlist); | |
f1310107 | 16662 | |
b775012e LM |
16663 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16664 | condition_evaluation_enums, | |
16665 | &condition_evaluation_mode_1, _("\ | |
16666 | Set mode of breakpoint condition evaluation."), _("\ | |
16667 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16668 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16669 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16670 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16671 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16672 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16673 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16674 | be set to \"gdb\""), | |
16675 | &set_condition_evaluation_mode, | |
16676 | &show_condition_evaluation_mode, | |
16677 | &breakpoint_set_cmdlist, | |
16678 | &breakpoint_show_cmdlist); | |
16679 | ||
f1310107 TJB |
16680 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16681 | Set a breakpoint for an address range.\n\ | |
16682 | break-range START-LOCATION, END-LOCATION\n\ | |
16683 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16684 | LINENUM, for that line in the current file,\n\ | |
16685 | FILE:LINENUM, for that line in that file,\n\ | |
16686 | +OFFSET, for that number of lines after the current line\n\ | |
16687 | or the start of the range\n\ | |
16688 | FUNCTION, for the first line in that function,\n\ | |
16689 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16690 | *ADDRESS, for the instruction at that address.\n\ | |
16691 | \n\ | |
16692 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16693 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16694 | range (including START-LOCATION and END-LOCATION).")); | |
16695 | ||
e7e0cddf SS |
16696 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16697 | Set a dynamic printf at specified line or function.\n\ | |
16698 | dprintf location,format string,arg1,arg2,...\n\ | |
16699 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16700 | If a line number is specified, break at start of code for that line.\n\ | |
16701 | If a function is specified, break at start of code for that function.\n\ | |
16702 | ")); | |
16703 | set_cmd_completer (c, location_completer); | |
16704 | ||
16705 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16706 | dprintf_style_enums, &dprintf_style, _("\ | |
16707 | Set the style of usage for dynamic printf."), _("\ | |
16708 | Show the style of usage for dynamic printf."), _("\ | |
16709 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16710 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16711 | console, as with the \"printf\" command.\n\ | |
16712 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16713 | program; by default printf(), but you can choose a different function or\n\ | |
16714 | output stream by setting dprintf-function and dprintf-channel."), | |
16715 | update_dprintf_commands, NULL, | |
16716 | &setlist, &showlist); | |
16717 | ||
16718 | dprintf_function = xstrdup ("printf"); | |
16719 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16720 | &dprintf_function, _("\ | |
16721 | Set the function to use for dynamic printf"), _("\ | |
16722 | Show the function to use for dynamic printf"), NULL, | |
16723 | update_dprintf_commands, NULL, | |
16724 | &setlist, &showlist); | |
16725 | ||
16726 | dprintf_channel = xstrdup (""); | |
16727 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16728 | &dprintf_channel, _("\ | |
16729 | Set the channel to use for dynamic printf"), _("\ | |
16730 | Show the channel to use for dynamic printf"), NULL, | |
16731 | update_dprintf_commands, NULL, | |
16732 | &setlist, &showlist); | |
16733 | ||
d3ce09f5 SS |
16734 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16735 | &disconnected_dprintf, _("\ | |
16736 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16737 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16738 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16739 | even if GDB disconnects or detaches from the target."), | |
16740 | NULL, | |
16741 | NULL, | |
16742 | &setlist, &showlist); | |
16743 | ||
16744 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16745 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16746 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16747 | ||
765dc015 | 16748 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16749 | |
16750 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 16751 | } |