Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
61baf725 | 3 | Copyright (C) 1986-2017 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" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.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" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
765dc015 | 54 | #include "memattr.h" |
f7f9143b | 55 | #include "ada-lang.h" |
d1aa2f50 | 56 | #include "top.h" |
79a45b7d | 57 | #include "valprint.h" |
4efc6507 | 58 | #include "jit.h" |
65d79d4b | 59 | #include "parser-defs.h" |
55aa24fb SDJ |
60 | #include "gdb_regex.h" |
61 | #include "probe.h" | |
e9cafbcc | 62 | #include "cli/cli-utils.h" |
be34f849 | 63 | #include "continuations.h" |
1bfeeb0f JL |
64 | #include "stack.h" |
65 | #include "skip.h" | |
b775012e | 66 | #include "ax-gdb.h" |
e2e4d78b | 67 | #include "dummy-frame.h" |
5589af0e | 68 | #include "interps.h" |
d3ce09f5 | 69 | #include "format.h" |
cfc31633 | 70 | #include "thread-fsm.h" |
5d5658a1 | 71 | #include "tid-parse.h" |
d3ce09f5 | 72 | |
1042e4c0 SS |
73 | /* readline include files */ |
74 | #include "readline/readline.h" | |
75 | #include "readline/history.h" | |
76 | ||
77 | /* readline defines this. */ | |
78 | #undef savestring | |
79 | ||
034dad6f | 80 | #include "mi/mi-common.h" |
6dddc817 | 81 | #include "extension.h" |
325fac50 | 82 | #include <algorithm> |
104c1213 | 83 | |
e7e8980f YQ |
84 | /* Enums for exception-handling support. */ |
85 | enum exception_event_kind | |
86 | { | |
87 | EX_EVENT_THROW, | |
591f19e8 | 88 | EX_EVENT_RETHROW, |
e7e8980f YQ |
89 | EX_EVENT_CATCH |
90 | }; | |
91 | ||
4a64f543 | 92 | /* Prototypes for local functions. */ |
c906108c | 93 | |
a14ed312 | 94 | static void enable_delete_command (char *, int); |
c906108c | 95 | |
a14ed312 | 96 | static void enable_once_command (char *, int); |
c906108c | 97 | |
816338b5 SS |
98 | static void enable_count_command (char *, int); |
99 | ||
a14ed312 | 100 | static void disable_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void enable_command (char *, int); |
c906108c | 103 | |
896b6bda PA |
104 | static void map_breakpoint_numbers (const char *, |
105 | void (*) (struct breakpoint *, | |
106 | void *), | |
95a42b64 | 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 | ||
f00aae0f KS |
115 | static void |
116 | create_sals_from_location_default (const struct event_location *location, | |
117 | struct linespec_result *canonical, | |
118 | enum bptype type_wanted); | |
983af33b SDJ |
119 | |
120 | static void create_breakpoints_sal_default (struct gdbarch *, | |
121 | struct linespec_result *, | |
e7e0cddf | 122 | char *, char *, enum bptype, |
983af33b SDJ |
123 | enum bpdisp, int, int, |
124 | int, | |
125 | const struct breakpoint_ops *, | |
44f238bb | 126 | int, int, int, unsigned); |
983af33b | 127 | |
f00aae0f KS |
128 | static void decode_location_default (struct breakpoint *b, |
129 | const struct event_location *location, | |
c2f4122d | 130 | struct program_space *search_pspace, |
f00aae0f | 131 | struct symtabs_and_lines *sals); |
983af33b | 132 | |
a14ed312 | 133 | static void clear_command (char *, int); |
c906108c | 134 | |
a14ed312 | 135 | static void catch_command (char *, int); |
c906108c | 136 | |
a9634178 | 137 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 138 | |
98deb0da | 139 | static void break_command_1 (char *, int, int); |
c906108c | 140 | |
a14ed312 | 141 | static void mention (struct breakpoint *); |
c906108c | 142 | |
348d480f PA |
143 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
144 | enum bptype, | |
c0a91b2b | 145 | const struct breakpoint_ops *); |
3742cc8b YQ |
146 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
147 | const struct symtab_and_line *); | |
148 | ||
4a64f543 MS |
149 | /* This function is used in gdbtk sources and thus can not be made |
150 | static. */ | |
63c252f8 | 151 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 152 | struct symtab_and_line, |
c0a91b2b TT |
153 | enum bptype, |
154 | const struct breakpoint_ops *); | |
c906108c | 155 | |
06edf0c0 PA |
156 | static struct breakpoint * |
157 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
158 | enum bptype type, | |
a1aa2221 LM |
159 | const struct breakpoint_ops *ops, |
160 | int loc_enabled); | |
06edf0c0 | 161 | |
76897487 KB |
162 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
163 | ||
a6d9a66e UW |
164 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
165 | CORE_ADDR bpaddr, | |
88f7da05 | 166 | enum bptype bptype); |
76897487 | 167 | |
6c95b8df PA |
168 | static void describe_other_breakpoints (struct gdbarch *, |
169 | struct program_space *, CORE_ADDR, | |
5af949e3 | 170 | struct obj_section *, int); |
c906108c | 171 | |
85d721b8 PA |
172 | static int watchpoint_locations_match (struct bp_location *loc1, |
173 | struct bp_location *loc2); | |
174 | ||
f1310107 TJB |
175 | static int breakpoint_location_address_match (struct bp_location *bl, |
176 | struct address_space *aspace, | |
177 | CORE_ADDR addr); | |
178 | ||
d35ae833 PA |
179 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
180 | struct address_space *, | |
181 | CORE_ADDR, int); | |
182 | ||
a14ed312 | 183 | static void breakpoints_info (char *, int); |
c906108c | 184 | |
d77f58be SS |
185 | static void watchpoints_info (char *, int); |
186 | ||
e5a67952 MS |
187 | static int breakpoint_1 (char *, int, |
188 | int (*) (const struct breakpoint *)); | |
c906108c | 189 | |
4efb68b1 | 190 | static int breakpoint_cond_eval (void *); |
c906108c | 191 | |
4efb68b1 | 192 | static void cleanup_executing_breakpoints (void *); |
c906108c | 193 | |
a14ed312 | 194 | static void commands_command (char *, int); |
c906108c | 195 | |
a14ed312 | 196 | static void condition_command (char *, int); |
c906108c | 197 | |
834c0d03 | 198 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 199 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 200 | |
e514a9d6 | 201 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 202 | |
4efb68b1 | 203 | static int watchpoint_check (void *); |
c906108c | 204 | |
a14ed312 | 205 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 206 | |
a14ed312 | 207 | static int hw_breakpoint_used_count (void); |
c906108c | 208 | |
a1398e0c PA |
209 | static int hw_watchpoint_use_count (struct breakpoint *); |
210 | ||
211 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
212 | enum bptype type, | |
213 | int *other_type_used); | |
c906108c | 214 | |
a14ed312 | 215 | static void hbreak_command (char *, int); |
c906108c | 216 | |
a14ed312 | 217 | static void thbreak_command (char *, int); |
c906108c | 218 | |
816338b5 SS |
219 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
220 | int count); | |
c906108c | 221 | |
a14ed312 | 222 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 223 | |
a14ed312 | 224 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 225 | |
a14ed312 | 226 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 227 | |
a14ed312 | 228 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 229 | |
fe3f5fa8 | 230 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
231 | static void incref_bp_location (struct bp_location *loc); |
232 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 233 | |
39d61571 | 234 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 235 | |
44702360 PA |
236 | /* update_global_location_list's modes of operation wrt to whether to |
237 | insert locations now. */ | |
238 | enum ugll_insert_mode | |
239 | { | |
240 | /* Don't insert any breakpoint locations into the inferior, only | |
241 | remove already-inserted locations that no longer should be | |
242 | inserted. Functions that delete a breakpoint or breakpoints | |
243 | should specify this mode, so that deleting a breakpoint doesn't | |
244 | have the side effect of inserting the locations of other | |
245 | breakpoints that are marked not-inserted, but should_be_inserted | |
246 | returns true on them. | |
247 | ||
248 | This behavior is useful is situations close to tear-down -- e.g., | |
249 | after an exec, while the target still has execution, but | |
250 | breakpoint shadows of the previous executable image should *NOT* | |
251 | be restored to the new image; or before detaching, where the | |
252 | target still has execution and wants to delete breakpoints from | |
253 | GDB's lists, and all breakpoints had already been removed from | |
254 | the inferior. */ | |
255 | UGLL_DONT_INSERT, | |
256 | ||
a25a5a45 PA |
257 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
258 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
259 | UGLL_MAY_INSERT, |
260 | ||
a25a5a45 PA |
261 | /* Insert locations now, irrespective of |
262 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
263 | stopped right now, and the user did "continue". We need to | |
264 | insert breakpoints _before_ resuming the target, but | |
265 | UGLL_MAY_INSERT wouldn't insert them, because | |
266 | breakpoints_should_be_inserted_now returns false at that point, | |
267 | as no thread is running yet. */ | |
04086b45 | 268 | UGLL_INSERT |
44702360 PA |
269 | }; |
270 | ||
271 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 272 | |
44702360 | 273 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 274 | |
d77f58be | 275 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
276 | |
277 | static void insert_breakpoint_locations (void); | |
a5606eee | 278 | |
1042e4c0 SS |
279 | static void tracepoints_info (char *, int); |
280 | ||
281 | static void delete_trace_command (char *, int); | |
282 | ||
283 | static void enable_trace_command (char *, int); | |
284 | ||
285 | static void disable_trace_command (char *, int); | |
286 | ||
287 | static void trace_pass_command (char *, int); | |
288 | ||
558a9d82 YQ |
289 | static void set_tracepoint_count (int num); |
290 | ||
9c06b0b4 TJB |
291 | static int is_masked_watchpoint (const struct breakpoint *b); |
292 | ||
b775012e LM |
293 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
294 | ||
983af33b SDJ |
295 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
296 | otherwise. */ | |
297 | ||
298 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 299 | |
2060206e PA |
300 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
301 | that are implemented on top of software or hardware breakpoints | |
302 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
303 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
304 | ||
305 | /* Internal breakpoints class type. */ | |
06edf0c0 | 306 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
307 | |
308 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
309 | static struct breakpoint_ops momentary_breakpoint_ops; |
310 | ||
e2e4d78b JK |
311 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
312 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
313 | ||
2060206e PA |
314 | /* The breakpoint_ops structure to be used in regular user created |
315 | breakpoints. */ | |
316 | struct breakpoint_ops bkpt_breakpoint_ops; | |
317 | ||
55aa24fb SDJ |
318 | /* Breakpoints set on probes. */ |
319 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
320 | ||
e7e0cddf | 321 | /* Dynamic printf class type. */ |
c5867ab6 | 322 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 323 | |
d3ce09f5 SS |
324 | /* The style in which to perform a dynamic printf. This is a user |
325 | option because different output options have different tradeoffs; | |
326 | if GDB does the printing, there is better error handling if there | |
327 | is a problem with any of the arguments, but using an inferior | |
328 | function lets you have special-purpose printers and sending of | |
329 | output to the same place as compiled-in print functions. */ | |
330 | ||
331 | static const char dprintf_style_gdb[] = "gdb"; | |
332 | static const char dprintf_style_call[] = "call"; | |
333 | static const char dprintf_style_agent[] = "agent"; | |
334 | static const char *const dprintf_style_enums[] = { | |
335 | dprintf_style_gdb, | |
336 | dprintf_style_call, | |
337 | dprintf_style_agent, | |
338 | NULL | |
339 | }; | |
340 | static const char *dprintf_style = dprintf_style_gdb; | |
341 | ||
342 | /* The function to use for dynamic printf if the preferred style is to | |
343 | call into the inferior. The value is simply a string that is | |
344 | copied into the command, so it can be anything that GDB can | |
345 | evaluate to a callable address, not necessarily a function name. */ | |
346 | ||
bde6261a | 347 | static char *dprintf_function; |
d3ce09f5 SS |
348 | |
349 | /* The channel to use for dynamic printf if the preferred style is to | |
350 | call into the inferior; if a nonempty string, it will be passed to | |
351 | the call as the first argument, with the format string as the | |
352 | second. As with the dprintf function, this can be anything that | |
353 | GDB knows how to evaluate, so in addition to common choices like | |
354 | "stderr", this could be an app-specific expression like | |
355 | "mystreams[curlogger]". */ | |
356 | ||
bde6261a | 357 | static char *dprintf_channel; |
d3ce09f5 SS |
358 | |
359 | /* True if dprintf commands should continue to operate even if GDB | |
360 | has disconnected. */ | |
361 | static int disconnected_dprintf = 1; | |
362 | ||
5cea2a26 PA |
363 | /* A reference-counted struct command_line. This lets multiple |
364 | breakpoints share a single command list. */ | |
365 | struct counted_command_line | |
366 | { | |
367 | /* The reference count. */ | |
368 | int refc; | |
369 | ||
370 | /* The command list. */ | |
371 | struct command_line *commands; | |
372 | }; | |
373 | ||
374 | struct command_line * | |
375 | breakpoint_commands (struct breakpoint *b) | |
376 | { | |
377 | return b->commands ? b->commands->commands : NULL; | |
378 | } | |
3daf8fe5 | 379 | |
f3b1572e PA |
380 | /* Flag indicating that a command has proceeded the inferior past the |
381 | current breakpoint. */ | |
382 | ||
383 | static int breakpoint_proceeded; | |
384 | ||
956a9fb9 | 385 | const char * |
2cec12e5 AR |
386 | bpdisp_text (enum bpdisp disp) |
387 | { | |
4a64f543 MS |
388 | /* NOTE: the following values are a part of MI protocol and |
389 | represent values of 'disp' field returned when inferior stops at | |
390 | a breakpoint. */ | |
bc043ef3 | 391 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 392 | |
2cec12e5 AR |
393 | return bpdisps[(int) disp]; |
394 | } | |
c906108c | 395 | |
4a64f543 | 396 | /* Prototypes for exported functions. */ |
c906108c | 397 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 398 | if such is available. */ |
c906108c SS |
399 | static int can_use_hw_watchpoints; |
400 | ||
920d2a44 AC |
401 | static void |
402 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
403 | struct cmd_list_element *c, | |
404 | const char *value) | |
405 | { | |
3e43a32a MS |
406 | fprintf_filtered (file, |
407 | _("Debugger's willingness to use " | |
408 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
409 | value); |
410 | } | |
411 | ||
fa8d40ab JJ |
412 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
413 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 414 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
415 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
416 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
417 | static void |
418 | show_pending_break_support (struct ui_file *file, int from_tty, | |
419 | struct cmd_list_element *c, | |
420 | const char *value) | |
421 | { | |
3e43a32a MS |
422 | fprintf_filtered (file, |
423 | _("Debugger's behavior regarding " | |
424 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
425 | value); |
426 | } | |
fa8d40ab | 427 | |
765dc015 | 428 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 429 | set with "break" but falling in read-only memory. |
765dc015 VP |
430 | If 0, gdb will warn about such breakpoints, but won't automatically |
431 | use hardware breakpoints. */ | |
432 | static int automatic_hardware_breakpoints; | |
433 | static void | |
434 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
435 | struct cmd_list_element *c, | |
436 | const char *value) | |
437 | { | |
3e43a32a MS |
438 | fprintf_filtered (file, |
439 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
440 | value); |
441 | } | |
442 | ||
a25a5a45 PA |
443 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
444 | stopped, and immediately inserts any new breakpoints as soon as | |
445 | they're created. If off (default), GDB keeps breakpoints off of | |
446 | the target as long as possible. That is, it delays inserting | |
447 | breakpoints until the next resume, and removes them again when the | |
448 | target fully stops. This is a bit safer in case GDB crashes while | |
449 | processing user input. */ | |
450 | static int always_inserted_mode = 0; | |
72d0e2c5 | 451 | |
33e5cbd6 | 452 | static void |
74960c60 | 453 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 454 | struct cmd_list_element *c, const char *value) |
74960c60 | 455 | { |
a25a5a45 PA |
456 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
457 | value); | |
74960c60 VP |
458 | } |
459 | ||
b57bacec PA |
460 | /* See breakpoint.h. */ |
461 | ||
33e5cbd6 | 462 | int |
a25a5a45 | 463 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 464 | { |
a25a5a45 PA |
465 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
466 | { | |
467 | /* If breakpoints are global, they should be inserted even if no | |
468 | thread under gdb's control is running, or even if there are | |
469 | no threads under GDB's control yet. */ | |
470 | return 1; | |
471 | } | |
472 | else if (target_has_execution) | |
473 | { | |
372316f1 PA |
474 | struct thread_info *tp; |
475 | ||
a25a5a45 PA |
476 | if (always_inserted_mode) |
477 | { | |
478 | /* The user wants breakpoints inserted even if all threads | |
479 | are stopped. */ | |
480 | return 1; | |
481 | } | |
482 | ||
b57bacec PA |
483 | if (threads_are_executing ()) |
484 | return 1; | |
372316f1 PA |
485 | |
486 | /* Don't remove breakpoints yet if, even though all threads are | |
487 | stopped, we still have events to process. */ | |
488 | ALL_NON_EXITED_THREADS (tp) | |
489 | if (tp->resumed | |
490 | && tp->suspend.waitstatus_pending_p) | |
491 | return 1; | |
a25a5a45 PA |
492 | } |
493 | return 0; | |
33e5cbd6 | 494 | } |
765dc015 | 495 | |
b775012e LM |
496 | static const char condition_evaluation_both[] = "host or target"; |
497 | ||
498 | /* Modes for breakpoint condition evaluation. */ | |
499 | static const char condition_evaluation_auto[] = "auto"; | |
500 | static const char condition_evaluation_host[] = "host"; | |
501 | static const char condition_evaluation_target[] = "target"; | |
502 | static const char *const condition_evaluation_enums[] = { | |
503 | condition_evaluation_auto, | |
504 | condition_evaluation_host, | |
505 | condition_evaluation_target, | |
506 | NULL | |
507 | }; | |
508 | ||
509 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
510 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
511 | ||
512 | /* Global that we use to display information to the user (gets its value from | |
513 | condition_evaluation_mode_1. */ | |
514 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
515 | ||
516 | /* Translate a condition evaluation mode MODE into either "host" | |
517 | or "target". This is used mostly to translate from "auto" to the | |
518 | real setting that is being used. It returns the translated | |
519 | evaluation mode. */ | |
520 | ||
521 | static const char * | |
522 | translate_condition_evaluation_mode (const char *mode) | |
523 | { | |
524 | if (mode == condition_evaluation_auto) | |
525 | { | |
526 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
527 | return condition_evaluation_target; | |
528 | else | |
529 | return condition_evaluation_host; | |
530 | } | |
531 | else | |
532 | return mode; | |
533 | } | |
534 | ||
535 | /* Discovers what condition_evaluation_auto translates to. */ | |
536 | ||
537 | static const char * | |
538 | breakpoint_condition_evaluation_mode (void) | |
539 | { | |
540 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
541 | } | |
542 | ||
543 | /* Return true if GDB should evaluate breakpoint conditions or false | |
544 | otherwise. */ | |
545 | ||
546 | static int | |
547 | gdb_evaluates_breakpoint_condition_p (void) | |
548 | { | |
549 | const char *mode = breakpoint_condition_evaluation_mode (); | |
550 | ||
551 | return (mode == condition_evaluation_host); | |
552 | } | |
553 | ||
a14ed312 | 554 | void _initialize_breakpoint (void); |
c906108c | 555 | |
c906108c SS |
556 | /* Are we executing breakpoint commands? */ |
557 | static int executing_breakpoint_commands; | |
558 | ||
c02f5703 MS |
559 | /* Are overlay event breakpoints enabled? */ |
560 | static int overlay_events_enabled; | |
561 | ||
e09342b5 TJB |
562 | /* See description in breakpoint.h. */ |
563 | int target_exact_watchpoints = 0; | |
564 | ||
c906108c | 565 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 566 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 567 | current breakpoint. */ |
c906108c | 568 | |
5c44784c | 569 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 570 | |
5c44784c JM |
571 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
572 | for (B = breakpoint_chain; \ | |
573 | B ? (TMP=B->next, 1): 0; \ | |
574 | B = TMP) | |
c906108c | 575 | |
4a64f543 MS |
576 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
577 | not provided so update_global_location_list must not be called | |
578 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 579 | |
876fa593 | 580 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
581 | for (BP_TMP = bp_locations; \ |
582 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 583 | BP_TMP++) |
7cc221ef | 584 | |
b775012e LM |
585 | /* Iterates through locations with address ADDRESS for the currently selected |
586 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
587 | to where the loop should start from. | |
588 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
589 | appropriate location to start with. */ | |
590 | ||
591 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
592 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
593 | BP_LOCP_TMP = BP_LOCP_START; \ | |
594 | BP_LOCP_START \ | |
f5336ca5 | 595 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
596 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
597 | BP_LOCP_TMP++) | |
598 | ||
1042e4c0 SS |
599 | /* Iterator for tracepoints only. */ |
600 | ||
601 | #define ALL_TRACEPOINTS(B) \ | |
602 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 603 | if (is_tracepoint (B)) |
1042e4c0 | 604 | |
7cc221ef | 605 | /* Chains of all breakpoints defined. */ |
c906108c SS |
606 | |
607 | struct breakpoint *breakpoint_chain; | |
608 | ||
f5336ca5 | 609 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
876fa593 | 610 | |
f5336ca5 | 611 | static struct bp_location **bp_locations; |
876fa593 | 612 | |
f5336ca5 | 613 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 614 | |
f5336ca5 | 615 | static unsigned bp_locations_count; |
876fa593 | 616 | |
4a64f543 | 617 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 618 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 619 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 620 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 621 | an address you need to read. */ |
876fa593 | 622 | |
f5336ca5 | 623 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 624 | |
4a64f543 MS |
625 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
626 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
627 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
628 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 629 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 630 | |
f5336ca5 | 631 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 632 | |
4a64f543 | 633 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
634 | from the bp_locations array, but for which a hit may still be |
635 | reported by a target. */ | |
20874c92 VP |
636 | VEC(bp_location_p) *moribund_locations = NULL; |
637 | ||
c906108c SS |
638 | /* Number of last breakpoint made. */ |
639 | ||
95a42b64 TT |
640 | static int breakpoint_count; |
641 | ||
86b17b60 PA |
642 | /* The value of `breakpoint_count' before the last command that |
643 | created breakpoints. If the last (break-like) command created more | |
644 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
645 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
646 | static int prev_breakpoint_count; | |
c906108c | 647 | |
1042e4c0 SS |
648 | /* Number of last tracepoint made. */ |
649 | ||
95a42b64 | 650 | static int tracepoint_count; |
1042e4c0 | 651 | |
6149aea9 PA |
652 | static struct cmd_list_element *breakpoint_set_cmdlist; |
653 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 654 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 655 | |
badd37ce SDJ |
656 | /* See declaration at breakpoint.h. */ |
657 | ||
658 | struct breakpoint * | |
659 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
660 | void *user_data) | |
661 | { | |
662 | struct breakpoint *b = NULL; | |
663 | ||
664 | ALL_BREAKPOINTS (b) | |
665 | { | |
666 | if (func (b, user_data) != 0) | |
667 | break; | |
668 | } | |
669 | ||
670 | return b; | |
671 | } | |
672 | ||
468d015d JJ |
673 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
674 | static int | |
675 | breakpoint_enabled (struct breakpoint *b) | |
676 | { | |
0d381245 | 677 | return (b->enable_state == bp_enabled); |
468d015d JJ |
678 | } |
679 | ||
c906108c SS |
680 | /* Set breakpoint count to NUM. */ |
681 | ||
95a42b64 | 682 | static void |
fba45db2 | 683 | set_breakpoint_count (int num) |
c906108c | 684 | { |
86b17b60 | 685 | prev_breakpoint_count = breakpoint_count; |
c906108c | 686 | breakpoint_count = num; |
4fa62494 | 687 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
688 | } |
689 | ||
86b17b60 PA |
690 | /* Used by `start_rbreak_breakpoints' below, to record the current |
691 | breakpoint count before "rbreak" creates any breakpoint. */ | |
692 | static int rbreak_start_breakpoint_count; | |
693 | ||
95a42b64 TT |
694 | /* Called at the start an "rbreak" command to record the first |
695 | breakpoint made. */ | |
86b17b60 | 696 | |
95a42b64 TT |
697 | void |
698 | start_rbreak_breakpoints (void) | |
699 | { | |
86b17b60 | 700 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
701 | } |
702 | ||
703 | /* Called at the end of an "rbreak" command to record the last | |
704 | breakpoint made. */ | |
86b17b60 | 705 | |
95a42b64 TT |
706 | void |
707 | end_rbreak_breakpoints (void) | |
708 | { | |
86b17b60 | 709 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
710 | } |
711 | ||
4a64f543 | 712 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
713 | |
714 | void | |
fba45db2 | 715 | clear_breakpoint_hit_counts (void) |
c906108c SS |
716 | { |
717 | struct breakpoint *b; | |
718 | ||
719 | ALL_BREAKPOINTS (b) | |
720 | b->hit_count = 0; | |
721 | } | |
722 | ||
9add0f1b TT |
723 | /* Allocate a new counted_command_line with reference count of 1. |
724 | The new structure owns COMMANDS. */ | |
725 | ||
726 | static struct counted_command_line * | |
727 | alloc_counted_command_line (struct command_line *commands) | |
728 | { | |
8d749320 | 729 | struct counted_command_line *result = XNEW (struct counted_command_line); |
cc59ec59 | 730 | |
9add0f1b TT |
731 | result->refc = 1; |
732 | result->commands = commands; | |
8d749320 | 733 | |
9add0f1b TT |
734 | return result; |
735 | } | |
736 | ||
737 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
738 | ||
739 | static void | |
740 | incref_counted_command_line (struct counted_command_line *cmd) | |
741 | { | |
742 | if (cmd) | |
743 | ++cmd->refc; | |
744 | } | |
745 | ||
746 | /* Decrement reference count. If the reference count reaches 0, | |
747 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
748 | nothing if *CMDP is NULL. */ | |
749 | ||
750 | static void | |
751 | decref_counted_command_line (struct counted_command_line **cmdp) | |
752 | { | |
753 | if (*cmdp) | |
754 | { | |
755 | if (--(*cmdp)->refc == 0) | |
756 | { | |
757 | free_command_lines (&(*cmdp)->commands); | |
758 | xfree (*cmdp); | |
759 | } | |
760 | *cmdp = NULL; | |
761 | } | |
762 | } | |
763 | ||
764 | /* A cleanup function that calls decref_counted_command_line. */ | |
765 | ||
766 | static void | |
767 | do_cleanup_counted_command_line (void *arg) | |
768 | { | |
9a3c8263 | 769 | decref_counted_command_line ((struct counted_command_line **) arg); |
9add0f1b TT |
770 | } |
771 | ||
772 | /* Create a cleanup that calls decref_counted_command_line on the | |
773 | argument. */ | |
774 | ||
775 | static struct cleanup * | |
776 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
777 | { | |
778 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
779 | } | |
780 | ||
c906108c | 781 | \f |
48cb2d85 VP |
782 | /* Return the breakpoint with the specified number, or NULL |
783 | if the number does not refer to an existing breakpoint. */ | |
784 | ||
785 | struct breakpoint * | |
786 | get_breakpoint (int num) | |
787 | { | |
788 | struct breakpoint *b; | |
789 | ||
790 | ALL_BREAKPOINTS (b) | |
791 | if (b->number == num) | |
792 | return b; | |
793 | ||
794 | return NULL; | |
795 | } | |
5c44784c | 796 | |
c906108c | 797 | \f |
adc36818 | 798 | |
b775012e LM |
799 | /* Mark locations as "conditions have changed" in case the target supports |
800 | evaluating conditions on its side. */ | |
801 | ||
802 | static void | |
803 | mark_breakpoint_modified (struct breakpoint *b) | |
804 | { | |
805 | struct bp_location *loc; | |
806 | ||
807 | /* This is only meaningful if the target is | |
808 | evaluating conditions and if the user has | |
809 | opted for condition evaluation on the target's | |
810 | side. */ | |
811 | if (gdb_evaluates_breakpoint_condition_p () | |
812 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
813 | return; | |
814 | ||
815 | if (!is_breakpoint (b)) | |
816 | return; | |
817 | ||
818 | for (loc = b->loc; loc; loc = loc->next) | |
819 | loc->condition_changed = condition_modified; | |
820 | } | |
821 | ||
822 | /* Mark location as "conditions have changed" in case the target supports | |
823 | evaluating conditions on its side. */ | |
824 | ||
825 | static void | |
826 | mark_breakpoint_location_modified (struct bp_location *loc) | |
827 | { | |
828 | /* This is only meaningful if the target is | |
829 | evaluating conditions and if the user has | |
830 | opted for condition evaluation on the target's | |
831 | side. */ | |
832 | if (gdb_evaluates_breakpoint_condition_p () | |
833 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
834 | ||
835 | return; | |
836 | ||
837 | if (!is_breakpoint (loc->owner)) | |
838 | return; | |
839 | ||
840 | loc->condition_changed = condition_modified; | |
841 | } | |
842 | ||
843 | /* Sets the condition-evaluation mode using the static global | |
844 | condition_evaluation_mode. */ | |
845 | ||
846 | static void | |
847 | set_condition_evaluation_mode (char *args, int from_tty, | |
848 | struct cmd_list_element *c) | |
849 | { | |
b775012e LM |
850 | const char *old_mode, *new_mode; |
851 | ||
852 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
853 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
854 | { | |
855 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
856 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
857 | "Using host evaluation mode instead.")); | |
858 | return; | |
859 | } | |
860 | ||
861 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
862 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
863 | ||
abf1152a JK |
864 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
865 | settings was "auto". */ | |
866 | condition_evaluation_mode = condition_evaluation_mode_1; | |
867 | ||
b775012e LM |
868 | /* Only update the mode if the user picked a different one. */ |
869 | if (new_mode != old_mode) | |
870 | { | |
871 | struct bp_location *loc, **loc_tmp; | |
872 | /* If the user switched to a different evaluation mode, we | |
873 | need to synch the changes with the target as follows: | |
874 | ||
875 | "host" -> "target": Send all (valid) conditions to the target. | |
876 | "target" -> "host": Remove all the conditions from the target. | |
877 | */ | |
878 | ||
b775012e LM |
879 | if (new_mode == condition_evaluation_target) |
880 | { | |
881 | /* Mark everything modified and synch conditions with the | |
882 | target. */ | |
883 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
884 | mark_breakpoint_location_modified (loc); | |
885 | } | |
886 | else | |
887 | { | |
888 | /* Manually mark non-duplicate locations to synch conditions | |
889 | with the target. We do this to remove all the conditions the | |
890 | target knows about. */ | |
891 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
892 | if (is_breakpoint (loc->owner) && loc->inserted) | |
893 | loc->needs_update = 1; | |
894 | } | |
895 | ||
896 | /* Do the update. */ | |
44702360 | 897 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
898 | } |
899 | ||
900 | return; | |
901 | } | |
902 | ||
903 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
904 | what "auto" is translating to. */ | |
905 | ||
906 | static void | |
907 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
908 | struct cmd_list_element *c, const char *value) | |
909 | { | |
910 | if (condition_evaluation_mode == condition_evaluation_auto) | |
911 | fprintf_filtered (file, | |
912 | _("Breakpoint condition evaluation " | |
913 | "mode is %s (currently %s).\n"), | |
914 | value, | |
915 | breakpoint_condition_evaluation_mode ()); | |
916 | else | |
917 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
918 | value); | |
919 | } | |
920 | ||
921 | /* A comparison function for bp_location AP and BP that is used by | |
922 | bsearch. This comparison function only cares about addresses, unlike | |
f5336ca5 | 923 | the more general bp_locations_compare function. */ |
b775012e LM |
924 | |
925 | static int | |
f5336ca5 | 926 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 927 | { |
9a3c8263 SM |
928 | const struct bp_location *a = *(const struct bp_location **) ap; |
929 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
930 | |
931 | if (a->address == b->address) | |
932 | return 0; | |
933 | else | |
934 | return ((a->address > b->address) - (a->address < b->address)); | |
935 | } | |
936 | ||
937 | /* Helper function to skip all bp_locations with addresses | |
938 | less than ADDRESS. It returns the first bp_location that | |
939 | is greater than or equal to ADDRESS. If none is found, just | |
940 | return NULL. */ | |
941 | ||
942 | static struct bp_location ** | |
943 | get_first_locp_gte_addr (CORE_ADDR address) | |
944 | { | |
945 | struct bp_location dummy_loc; | |
946 | struct bp_location *dummy_locp = &dummy_loc; | |
947 | struct bp_location **locp_found = NULL; | |
948 | ||
949 | /* Initialize the dummy location's address field. */ | |
950 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
951 | dummy_loc.address = address; | |
952 | ||
953 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 954 | locp_found = ((struct bp_location **) |
f5336ca5 | 955 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 956 | sizeof (struct bp_location **), |
f5336ca5 | 957 | bp_locations_compare_addrs)); |
b775012e LM |
958 | |
959 | /* Nothing was found, nothing left to do. */ | |
960 | if (locp_found == NULL) | |
961 | return NULL; | |
962 | ||
963 | /* We may have found a location that is at ADDRESS but is not the first in the | |
964 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 965 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
966 | && (*(locp_found - 1))->address == address) |
967 | locp_found--; | |
968 | ||
969 | return locp_found; | |
970 | } | |
971 | ||
adc36818 | 972 | void |
7a26bd4d | 973 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
974 | int from_tty) |
975 | { | |
3a5c3e22 PA |
976 | xfree (b->cond_string); |
977 | b->cond_string = NULL; | |
adc36818 | 978 | |
3a5c3e22 | 979 | if (is_watchpoint (b)) |
adc36818 | 980 | { |
3a5c3e22 PA |
981 | struct watchpoint *w = (struct watchpoint *) b; |
982 | ||
4d01a485 | 983 | w->cond_exp.reset (); |
3a5c3e22 PA |
984 | } |
985 | else | |
986 | { | |
987 | struct bp_location *loc; | |
988 | ||
989 | for (loc = b->loc; loc; loc = loc->next) | |
990 | { | |
4d01a485 | 991 | loc->cond.reset (); |
b775012e LM |
992 | |
993 | /* No need to free the condition agent expression | |
994 | bytecode (if we have one). We will handle this | |
995 | when we go through update_global_location_list. */ | |
3a5c3e22 | 996 | } |
adc36818 | 997 | } |
adc36818 PM |
998 | |
999 | if (*exp == 0) | |
1000 | { | |
1001 | if (from_tty) | |
1002 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1003 | } | |
1004 | else | |
1005 | { | |
bbc13ae3 | 1006 | const char *arg = exp; |
cc59ec59 | 1007 | |
adc36818 PM |
1008 | /* I don't know if it matters whether this is the string the user |
1009 | typed in or the decompiled expression. */ | |
1010 | b->cond_string = xstrdup (arg); | |
1011 | b->condition_not_parsed = 0; | |
1012 | ||
1013 | if (is_watchpoint (b)) | |
1014 | { | |
3a5c3e22 PA |
1015 | struct watchpoint *w = (struct watchpoint *) b; |
1016 | ||
adc36818 PM |
1017 | innermost_block = NULL; |
1018 | arg = exp; | |
1bb9788d | 1019 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1020 | if (*arg) |
1021 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1022 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1023 | } |
1024 | else | |
1025 | { | |
3a5c3e22 PA |
1026 | struct bp_location *loc; |
1027 | ||
adc36818 PM |
1028 | for (loc = b->loc; loc; loc = loc->next) |
1029 | { | |
1030 | arg = exp; | |
1031 | loc->cond = | |
1bb9788d TT |
1032 | parse_exp_1 (&arg, loc->address, |
1033 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1034 | if (*arg) |
1035 | error (_("Junk at end of expression")); | |
1036 | } | |
1037 | } | |
1038 | } | |
b775012e LM |
1039 | mark_breakpoint_modified (b); |
1040 | ||
8d3788bd | 1041 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1042 | } |
1043 | ||
d55637df TT |
1044 | /* Completion for the "condition" command. */ |
1045 | ||
1046 | static VEC (char_ptr) * | |
6f937416 PA |
1047 | condition_completer (struct cmd_list_element *cmd, |
1048 | const char *text, const char *word) | |
d55637df | 1049 | { |
6f937416 | 1050 | const char *space; |
d55637df | 1051 | |
6f937416 PA |
1052 | text = skip_spaces_const (text); |
1053 | space = skip_to_space_const (text); | |
d55637df TT |
1054 | if (*space == '\0') |
1055 | { | |
1056 | int len; | |
1057 | struct breakpoint *b; | |
1058 | VEC (char_ptr) *result = NULL; | |
1059 | ||
1060 | if (text[0] == '$') | |
1061 | { | |
1062 | /* We don't support completion of history indices. */ | |
1063 | if (isdigit (text[1])) | |
1064 | return NULL; | |
1065 | return complete_internalvar (&text[1]); | |
1066 | } | |
1067 | ||
1068 | /* We're completing the breakpoint number. */ | |
1069 | len = strlen (text); | |
1070 | ||
1071 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1072 | { |
1073 | char number[50]; | |
1074 | ||
1075 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1076 | ||
1077 | if (strncmp (number, text, len) == 0) | |
1078 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1079 | } | |
d55637df TT |
1080 | |
1081 | return result; | |
1082 | } | |
1083 | ||
1084 | /* We're completing the expression part. */ | |
6f937416 | 1085 | text = skip_spaces_const (space); |
d55637df TT |
1086 | return expression_completer (cmd, text, word); |
1087 | } | |
1088 | ||
c906108c SS |
1089 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1090 | ||
1091 | static void | |
fba45db2 | 1092 | condition_command (char *arg, int from_tty) |
c906108c | 1093 | { |
52f0bd74 | 1094 | struct breakpoint *b; |
c906108c | 1095 | char *p; |
52f0bd74 | 1096 | int bnum; |
c906108c SS |
1097 | |
1098 | if (arg == 0) | |
e2e0b3e5 | 1099 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1100 | |
1101 | p = arg; | |
1102 | bnum = get_number (&p); | |
5c44784c | 1103 | if (bnum == 0) |
8a3fe4f8 | 1104 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1105 | |
1106 | ALL_BREAKPOINTS (b) | |
1107 | if (b->number == bnum) | |
2f069f6f | 1108 | { |
6dddc817 DE |
1109 | /* Check if this breakpoint has a "stop" method implemented in an |
1110 | extension language. This method and conditions entered into GDB | |
1111 | from the CLI are mutually exclusive. */ | |
1112 | const struct extension_language_defn *extlang | |
1113 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1114 | ||
1115 | if (extlang != NULL) | |
1116 | { | |
1117 | error (_("Only one stop condition allowed. There is currently" | |
1118 | " a %s stop condition defined for this breakpoint."), | |
1119 | ext_lang_capitalized_name (extlang)); | |
1120 | } | |
2566ad2d | 1121 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1122 | |
1123 | if (is_breakpoint (b)) | |
44702360 | 1124 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1125 | |
2f069f6f JB |
1126 | return; |
1127 | } | |
c906108c | 1128 | |
8a3fe4f8 | 1129 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1130 | } |
1131 | ||
a7bdde9e VP |
1132 | /* Check that COMMAND do not contain commands that are suitable |
1133 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1134 | Throw if any such commands is found. */ |
1135 | ||
a7bdde9e VP |
1136 | static void |
1137 | check_no_tracepoint_commands (struct command_line *commands) | |
1138 | { | |
1139 | struct command_line *c; | |
cc59ec59 | 1140 | |
a7bdde9e VP |
1141 | for (c = commands; c; c = c->next) |
1142 | { | |
1143 | int i; | |
1144 | ||
1145 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1146 | error (_("The 'while-stepping' command can " |
1147 | "only be used for tracepoints")); | |
a7bdde9e VP |
1148 | |
1149 | for (i = 0; i < c->body_count; ++i) | |
1150 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1151 | ||
1152 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1153 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1154 | command directly. */ |
1155 | if (strstr (c->line, "collect ") == c->line) | |
1156 | error (_("The 'collect' command can only be used for tracepoints")); | |
1157 | ||
51661e93 VP |
1158 | if (strstr (c->line, "teval ") == c->line) |
1159 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1160 | } |
1161 | } | |
1162 | ||
d77f58be SS |
1163 | /* Encapsulate tests for different types of tracepoints. */ |
1164 | ||
d9b3f62e PA |
1165 | static int |
1166 | is_tracepoint_type (enum bptype type) | |
1167 | { | |
1168 | return (type == bp_tracepoint | |
1169 | || type == bp_fast_tracepoint | |
1170 | || type == bp_static_tracepoint); | |
1171 | } | |
1172 | ||
a7bdde9e | 1173 | int |
d77f58be | 1174 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1175 | { |
d9b3f62e | 1176 | return is_tracepoint_type (b->type); |
a7bdde9e | 1177 | } |
d9b3f62e | 1178 | |
e5dd4106 | 1179 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1180 | breakpoint. This function will throw an exception if a problem is |
1181 | found. */ | |
48cb2d85 | 1182 | |
95a42b64 TT |
1183 | static void |
1184 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1185 | struct command_line *commands) | |
48cb2d85 | 1186 | { |
d77f58be | 1187 | if (is_tracepoint (b)) |
a7bdde9e | 1188 | { |
c9a6ce02 | 1189 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1190 | struct command_line *c; |
1191 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1192 | |
1193 | /* Reset the while-stepping step count. The previous commands | |
1194 | might have included a while-stepping action, while the new | |
1195 | ones might not. */ | |
1196 | t->step_count = 0; | |
1197 | ||
1198 | /* We need to verify that each top-level element of commands is | |
1199 | valid for tracepoints, that there's at most one | |
1200 | while-stepping element, and that the while-stepping's body | |
1201 | has valid tracing commands excluding nested while-stepping. | |
1202 | We also need to validate the tracepoint action line in the | |
1203 | context of the tracepoint --- validate_actionline actually | |
1204 | has side effects, like setting the tracepoint's | |
1205 | while-stepping STEP_COUNT, in addition to checking if the | |
1206 | collect/teval actions parse and make sense in the | |
1207 | tracepoint's context. */ | |
a7bdde9e VP |
1208 | for (c = commands; c; c = c->next) |
1209 | { | |
a7bdde9e VP |
1210 | if (c->control_type == while_stepping_control) |
1211 | { | |
1212 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1213 | error (_("The 'while-stepping' command " |
1214 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1215 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1216 | error (_("The 'while-stepping' command " |
1217 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1218 | |
1219 | if (while_stepping) | |
3e43a32a MS |
1220 | error (_("The 'while-stepping' command " |
1221 | "can be used only once")); | |
a7bdde9e VP |
1222 | else |
1223 | while_stepping = c; | |
1224 | } | |
c9a6ce02 PA |
1225 | |
1226 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1227 | } |
1228 | if (while_stepping) | |
1229 | { | |
1230 | struct command_line *c2; | |
1231 | ||
1232 | gdb_assert (while_stepping->body_count == 1); | |
1233 | c2 = while_stepping->body_list[0]; | |
1234 | for (; c2; c2 = c2->next) | |
1235 | { | |
a7bdde9e VP |
1236 | if (c2->control_type == while_stepping_control) |
1237 | error (_("The 'while-stepping' command cannot be nested")); | |
1238 | } | |
1239 | } | |
1240 | } | |
1241 | else | |
1242 | { | |
1243 | check_no_tracepoint_commands (commands); | |
1244 | } | |
95a42b64 TT |
1245 | } |
1246 | ||
0fb4aa4b PA |
1247 | /* Return a vector of all the static tracepoints set at ADDR. The |
1248 | caller is responsible for releasing the vector. */ | |
1249 | ||
1250 | VEC(breakpoint_p) * | |
1251 | static_tracepoints_here (CORE_ADDR addr) | |
1252 | { | |
1253 | struct breakpoint *b; | |
1254 | VEC(breakpoint_p) *found = 0; | |
1255 | struct bp_location *loc; | |
1256 | ||
1257 | ALL_BREAKPOINTS (b) | |
1258 | if (b->type == bp_static_tracepoint) | |
1259 | { | |
1260 | for (loc = b->loc; loc; loc = loc->next) | |
1261 | if (loc->address == addr) | |
1262 | VEC_safe_push(breakpoint_p, found, b); | |
1263 | } | |
1264 | ||
1265 | return found; | |
1266 | } | |
1267 | ||
95a42b64 | 1268 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1269 | validate that only allowed commands are included. */ |
95a42b64 TT |
1270 | |
1271 | void | |
4a64f543 | 1272 | breakpoint_set_commands (struct breakpoint *b, |
93921405 | 1273 | command_line_up &&commands) |
95a42b64 | 1274 | { |
93921405 | 1275 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1276 | |
9add0f1b | 1277 | decref_counted_command_line (&b->commands); |
93921405 | 1278 | b->commands = alloc_counted_command_line (commands.release ()); |
8d3788bd | 1279 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1280 | } |
1281 | ||
45a43567 TT |
1282 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1283 | is not the same as the "silent" that may appear in the breakpoint's | |
1284 | commands. */ | |
1285 | ||
1286 | void | |
1287 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1288 | { | |
1289 | int old_silent = b->silent; | |
1290 | ||
1291 | b->silent = silent; | |
1292 | if (old_silent != silent) | |
8d3788bd | 1293 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1294 | } |
1295 | ||
1296 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1297 | breakpoint work for any thread. */ | |
1298 | ||
1299 | void | |
1300 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1301 | { | |
1302 | int old_thread = b->thread; | |
1303 | ||
1304 | b->thread = thread; | |
1305 | if (old_thread != thread) | |
8d3788bd | 1306 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1307 | } |
1308 | ||
1309 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1310 | breakpoint work for any task. */ | |
1311 | ||
1312 | void | |
1313 | breakpoint_set_task (struct breakpoint *b, int task) | |
1314 | { | |
1315 | int old_task = b->task; | |
1316 | ||
1317 | b->task = task; | |
1318 | if (old_task != task) | |
8d3788bd | 1319 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1320 | } |
1321 | ||
95a42b64 TT |
1322 | void |
1323 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1324 | { |
9a3c8263 | 1325 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1326 | |
6f937416 | 1327 | validate_actionline (line, b); |
a7bdde9e VP |
1328 | } |
1329 | ||
95a42b64 TT |
1330 | /* A structure used to pass information through |
1331 | map_breakpoint_numbers. */ | |
1332 | ||
1333 | struct commands_info | |
1334 | { | |
1335 | /* True if the command was typed at a tty. */ | |
1336 | int from_tty; | |
86b17b60 PA |
1337 | |
1338 | /* The breakpoint range spec. */ | |
896b6bda | 1339 | const char *arg; |
86b17b60 | 1340 | |
95a42b64 TT |
1341 | /* Non-NULL if the body of the commands are being read from this |
1342 | already-parsed command. */ | |
1343 | struct command_line *control; | |
86b17b60 | 1344 | |
95a42b64 TT |
1345 | /* The command lines read from the user, or NULL if they have not |
1346 | yet been read. */ | |
1347 | struct counted_command_line *cmd; | |
1348 | }; | |
1349 | ||
1350 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1351 | commands_command. */ | |
1352 | ||
c906108c | 1353 | static void |
95a42b64 | 1354 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1355 | { |
9a3c8263 | 1356 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1357 | |
95a42b64 TT |
1358 | if (info->cmd == NULL) |
1359 | { | |
93921405 | 1360 | command_line_up l; |
5c44784c | 1361 | |
95a42b64 TT |
1362 | if (info->control != NULL) |
1363 | l = copy_command_lines (info->control->body_list[0]); | |
1364 | else | |
86b17b60 PA |
1365 | { |
1366 | struct cleanup *old_chain; | |
1367 | char *str; | |
c5aa993b | 1368 | |
3e43a32a MS |
1369 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1370 | "%s, one per line."), | |
86b17b60 PA |
1371 | info->arg); |
1372 | ||
1373 | old_chain = make_cleanup (xfree, str); | |
1374 | ||
1375 | l = read_command_lines (str, | |
1376 | info->from_tty, 1, | |
d77f58be | 1377 | (is_tracepoint (b) |
86b17b60 PA |
1378 | ? check_tracepoint_command : 0), |
1379 | b); | |
1380 | ||
1381 | do_cleanups (old_chain); | |
1382 | } | |
a7bdde9e | 1383 | |
93921405 | 1384 | info->cmd = alloc_counted_command_line (l.release ()); |
95a42b64 TT |
1385 | } |
1386 | ||
1387 | /* If a breakpoint was on the list more than once, we don't need to | |
1388 | do anything. */ | |
1389 | if (b->commands != info->cmd) | |
1390 | { | |
1391 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1392 | incref_counted_command_line (info->cmd); | |
1393 | decref_counted_command_line (&b->commands); | |
1394 | b->commands = info->cmd; | |
8d3788bd | 1395 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1396 | } |
95a42b64 TT |
1397 | } |
1398 | ||
1399 | static void | |
896b6bda | 1400 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1401 | struct command_line *control) |
95a42b64 TT |
1402 | { |
1403 | struct cleanup *cleanups; | |
1404 | struct commands_info info; | |
1405 | ||
1406 | info.from_tty = from_tty; | |
1407 | info.control = control; | |
1408 | info.cmd = NULL; | |
1409 | /* If we read command lines from the user, then `info' will hold an | |
1410 | extra reference to the commands that we must clean up. */ | |
1411 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1412 | ||
896b6bda PA |
1413 | std::string new_arg; |
1414 | ||
95a42b64 TT |
1415 | if (arg == NULL || !*arg) |
1416 | { | |
86b17b60 | 1417 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1418 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1419 | breakpoint_count); | |
95a42b64 | 1420 | else if (breakpoint_count > 0) |
896b6bda | 1421 | new_arg = string_printf ("%d", breakpoint_count); |
95a42b64 | 1422 | } |
9766ced4 | 1423 | else |
896b6bda | 1424 | new_arg = arg; |
86b17b60 | 1425 | |
896b6bda | 1426 | info.arg = new_arg.c_str (); |
95a42b64 | 1427 | |
896b6bda | 1428 | map_breakpoint_numbers (info.arg, do_map_commands_command, &info); |
95a42b64 TT |
1429 | |
1430 | if (info.cmd == NULL) | |
1431 | error (_("No breakpoints specified.")); | |
1432 | ||
1433 | do_cleanups (cleanups); | |
1434 | } | |
1435 | ||
1436 | static void | |
1437 | commands_command (char *arg, int from_tty) | |
1438 | { | |
1439 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1440 | } |
40c03ae8 EZ |
1441 | |
1442 | /* Like commands_command, but instead of reading the commands from | |
1443 | input stream, takes them from an already parsed command structure. | |
1444 | ||
1445 | This is used by cli-script.c to DTRT with breakpoint commands | |
1446 | that are part of if and while bodies. */ | |
1447 | enum command_control_type | |
896b6bda | 1448 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1449 | { |
95a42b64 TT |
1450 | commands_command_1 (arg, 0, cmd); |
1451 | return simple_control; | |
40c03ae8 | 1452 | } |
876fa593 JK |
1453 | |
1454 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1455 | ||
1456 | static int | |
1457 | bp_location_has_shadow (struct bp_location *bl) | |
1458 | { | |
1459 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1460 | return 0; | |
1461 | if (!bl->inserted) | |
1462 | return 0; | |
1463 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1464 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1465 | return 0; |
1466 | return 1; | |
1467 | } | |
1468 | ||
9d497a19 PA |
1469 | /* Update BUF, which is LEN bytes read from the target address |
1470 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1471 | contents. | |
1472 | ||
1473 | If READBUF is not NULL, this buffer must not overlap with the of | |
1474 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1475 | failed assertion internal error will be raised. */ | |
1476 | ||
1477 | static void | |
1478 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1479 | const gdb_byte *writebuf_org, | |
1480 | ULONGEST memaddr, LONGEST len, | |
1481 | struct bp_target_info *target_info, | |
1482 | struct gdbarch *gdbarch) | |
1483 | { | |
1484 | /* Now do full processing of the found relevant range of elements. */ | |
1485 | CORE_ADDR bp_addr = 0; | |
1486 | int bp_size = 0; | |
1487 | int bptoffset = 0; | |
1488 | ||
1489 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1490 | current_program_space->aspace, 0)) | |
1491 | { | |
1492 | /* The breakpoint is inserted in a different address space. */ | |
1493 | return; | |
1494 | } | |
1495 | ||
1496 | /* Addresses and length of the part of the breakpoint that | |
1497 | we need to copy. */ | |
1498 | bp_addr = target_info->placed_address; | |
1499 | bp_size = target_info->shadow_len; | |
1500 | ||
1501 | if (bp_addr + bp_size <= memaddr) | |
1502 | { | |
1503 | /* The breakpoint is entirely before the chunk of memory we are | |
1504 | reading. */ | |
1505 | return; | |
1506 | } | |
1507 | ||
1508 | if (bp_addr >= memaddr + len) | |
1509 | { | |
1510 | /* The breakpoint is entirely after the chunk of memory we are | |
1511 | reading. */ | |
1512 | return; | |
1513 | } | |
1514 | ||
1515 | /* Offset within shadow_contents. */ | |
1516 | if (bp_addr < memaddr) | |
1517 | { | |
1518 | /* Only copy the second part of the breakpoint. */ | |
1519 | bp_size -= memaddr - bp_addr; | |
1520 | bptoffset = memaddr - bp_addr; | |
1521 | bp_addr = memaddr; | |
1522 | } | |
1523 | ||
1524 | if (bp_addr + bp_size > memaddr + len) | |
1525 | { | |
1526 | /* Only copy the first part of the breakpoint. */ | |
1527 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1528 | } | |
1529 | ||
1530 | if (readbuf != NULL) | |
1531 | { | |
1532 | /* Verify that the readbuf buffer does not overlap with the | |
1533 | shadow_contents buffer. */ | |
1534 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1535 | || readbuf >= (target_info->shadow_contents | |
1536 | + target_info->shadow_len)); | |
1537 | ||
1538 | /* Update the read buffer with this inserted breakpoint's | |
1539 | shadow. */ | |
1540 | memcpy (readbuf + bp_addr - memaddr, | |
1541 | target_info->shadow_contents + bptoffset, bp_size); | |
1542 | } | |
1543 | else | |
1544 | { | |
1545 | const unsigned char *bp; | |
0d5ed153 MR |
1546 | CORE_ADDR addr = target_info->reqstd_address; |
1547 | int placed_size; | |
9d497a19 PA |
1548 | |
1549 | /* Update the shadow with what we want to write to memory. */ | |
1550 | memcpy (target_info->shadow_contents + bptoffset, | |
1551 | writebuf_org + bp_addr - memaddr, bp_size); | |
1552 | ||
1553 | /* Determine appropriate breakpoint contents and size for this | |
1554 | address. */ | |
0d5ed153 | 1555 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1556 | |
1557 | /* Update the final write buffer with this inserted | |
1558 | breakpoint's INSN. */ | |
1559 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1560 | } | |
1561 | } | |
1562 | ||
8defab1a | 1563 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1564 | by replacing any memory breakpoints with their shadowed contents. |
1565 | ||
35c63cd8 JB |
1566 | If READBUF is not NULL, this buffer must not overlap with any of |
1567 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1568 | a failed assertion internal error will be raised. | |
1569 | ||
876fa593 | 1570 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1571 | bl->address - bp_locations_placed_address_before_address_max |
1572 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1573 | The range we were requested to resolve shadows for is: |
1574 | memaddr ... memaddr + len | |
1575 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1576 | memaddr + len <= (bl->address |
f5336ca5 | 1577 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1578 | and: |
f5336ca5 | 1579 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1580 | |
8defab1a | 1581 | void |
f0ba3972 PA |
1582 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1583 | const gdb_byte *writebuf_org, | |
1584 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1585 | { |
4a64f543 MS |
1586 | /* Left boundary, right boundary and median element of our binary |
1587 | search. */ | |
876fa593 JK |
1588 | unsigned bc_l, bc_r, bc; |
1589 | ||
4a64f543 MS |
1590 | /* Find BC_L which is a leftmost element which may affect BUF |
1591 | content. It is safe to report lower value but a failure to | |
1592 | report higher one. */ | |
876fa593 JK |
1593 | |
1594 | bc_l = 0; | |
f5336ca5 | 1595 | bc_r = bp_locations_count; |
876fa593 JK |
1596 | while (bc_l + 1 < bc_r) |
1597 | { | |
35df4500 | 1598 | struct bp_location *bl; |
876fa593 JK |
1599 | |
1600 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1601 | bl = bp_locations[bc]; |
876fa593 | 1602 | |
4a64f543 MS |
1603 | /* Check first BL->ADDRESS will not overflow due to the added |
1604 | constant. Then advance the left boundary only if we are sure | |
1605 | the BC element can in no way affect the BUF content (MEMADDR | |
1606 | to MEMADDR + LEN range). | |
876fa593 | 1607 | |
f5336ca5 | 1608 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1609 | offset so that we cannot miss a breakpoint with its shadow |
1610 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1611 | |
f5336ca5 | 1612 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1613 | >= bl->address) |
f5336ca5 | 1614 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1615 | <= memaddr)) |
876fa593 JK |
1616 | bc_l = bc; |
1617 | else | |
1618 | bc_r = bc; | |
1619 | } | |
1620 | ||
128070bb PA |
1621 | /* Due to the binary search above, we need to make sure we pick the |
1622 | first location that's at BC_L's address. E.g., if there are | |
1623 | multiple locations at the same address, BC_L may end up pointing | |
1624 | at a duplicate location, and miss the "master"/"inserted" | |
1625 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1626 | B: | |
1627 | ||
1628 | L1@A, L2@A, L3@B, ... | |
1629 | ||
1630 | BC_L could end up pointing at location L2, while the "master" | |
1631 | location could be L1. Since the `loc->inserted' flag is only set | |
1632 | on "master" locations, we'd forget to restore the shadow of L1 | |
1633 | and L2. */ | |
1634 | while (bc_l > 0 | |
f5336ca5 | 1635 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1636 | bc_l--; |
1637 | ||
876fa593 JK |
1638 | /* Now do full processing of the found relevant range of elements. */ |
1639 | ||
f5336ca5 | 1640 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1641 | { |
f5336ca5 | 1642 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1643 | |
35df4500 TJB |
1644 | /* bp_location array has BL->OWNER always non-NULL. */ |
1645 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1646 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1647 | bl->owner->number); |
ffce0d52 | 1648 | |
e5dd4106 | 1649 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1650 | content. */ |
1651 | ||
f5336ca5 PA |
1652 | if (bl->address >= bp_locations_placed_address_before_address_max |
1653 | && memaddr + len <= (bl->address | |
1654 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1655 | break; |
1656 | ||
35df4500 | 1657 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1658 | continue; |
6c95b8df | 1659 | |
9d497a19 PA |
1660 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1661 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1662 | } | |
c906108c | 1663 | } |
9d497a19 | 1664 | |
c906108c | 1665 | \f |
c5aa993b | 1666 | |
b775012e LM |
1667 | /* Return true if BPT is either a software breakpoint or a hardware |
1668 | breakpoint. */ | |
1669 | ||
1670 | int | |
1671 | is_breakpoint (const struct breakpoint *bpt) | |
1672 | { | |
1673 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1674 | || bpt->type == bp_hardware_breakpoint |
1675 | || bpt->type == bp_dprintf); | |
b775012e LM |
1676 | } |
1677 | ||
60e1c644 PA |
1678 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1679 | ||
a5606eee | 1680 | static int |
d77f58be | 1681 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1682 | { |
1683 | return (bpt->type == bp_hardware_watchpoint | |
1684 | || bpt->type == bp_read_watchpoint | |
1685 | || bpt->type == bp_access_watchpoint); | |
1686 | } | |
7270d8f2 | 1687 | |
60e1c644 PA |
1688 | /* Return true if BPT is of any watchpoint kind, hardware or |
1689 | software. */ | |
1690 | ||
3a5c3e22 | 1691 | int |
d77f58be | 1692 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1693 | { |
1694 | return (is_hardware_watchpoint (bpt) | |
1695 | || bpt->type == bp_watchpoint); | |
1696 | } | |
1697 | ||
3a5c3e22 PA |
1698 | /* Returns true if the current thread and its running state are safe |
1699 | to evaluate or update watchpoint B. Watchpoints on local | |
1700 | expressions need to be evaluated in the context of the thread that | |
1701 | was current when the watchpoint was created, and, that thread needs | |
1702 | to be stopped to be able to select the correct frame context. | |
1703 | Watchpoints on global expressions can be evaluated on any thread, | |
1704 | and in any state. It is presently left to the target allowing | |
1705 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1706 | |
1707 | static int | |
3a5c3e22 | 1708 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1709 | { |
d0d8b0c6 JK |
1710 | return (b->base.pspace == current_program_space |
1711 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1712 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1713 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1714 | } |
1715 | ||
d0fb5eae JK |
1716 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1717 | associated bp_watchpoint_scope breakpoint. */ | |
1718 | ||
1719 | static void | |
3a5c3e22 | 1720 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1721 | { |
3a5c3e22 | 1722 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1723 | |
1724 | if (b->related_breakpoint != b) | |
1725 | { | |
1726 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1727 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1728 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1729 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1730 | b->related_breakpoint = b; | |
1731 | } | |
1732 | b->disposition = disp_del_at_next_stop; | |
1733 | } | |
1734 | ||
bb9d5f81 PP |
1735 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1736 | watchpoint W. */ | |
1737 | ||
1738 | static struct value * | |
1739 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1740 | { | |
1741 | struct value *bit_val; | |
1742 | ||
1743 | if (val == NULL) | |
1744 | return NULL; | |
1745 | ||
1746 | bit_val = allocate_value (value_type (val)); | |
1747 | ||
1748 | unpack_value_bitfield (bit_val, | |
1749 | w->val_bitpos, | |
1750 | w->val_bitsize, | |
1751 | value_contents_for_printing (val), | |
1752 | value_offset (val), | |
1753 | val); | |
1754 | ||
1755 | return bit_val; | |
1756 | } | |
1757 | ||
c6d81124 PA |
1758 | /* Allocate a dummy location and add it to B, which must be a software |
1759 | watchpoint. This is required because even if a software watchpoint | |
1760 | is not watching any memory, bpstat_stop_status requires a location | |
1761 | to be able to report stops. */ | |
1762 | ||
1763 | static void | |
1764 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1765 | struct program_space *pspace) | |
1766 | { | |
1767 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1768 | ||
1769 | b->loc = allocate_bp_location (b); | |
1770 | b->loc->pspace = pspace; | |
1771 | b->loc->address = -1; | |
1772 | b->loc->length = -1; | |
1773 | } | |
1774 | ||
1775 | /* Returns true if B is a software watchpoint that is not watching any | |
1776 | memory (e.g., "watch $pc"). */ | |
1777 | ||
1778 | static int | |
1779 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1780 | { | |
1781 | return (b->type == bp_watchpoint | |
1782 | && b->loc != NULL | |
1783 | && b->loc->next == NULL | |
1784 | && b->loc->address == -1 | |
1785 | && b->loc->length == -1); | |
1786 | } | |
1787 | ||
567e1b4e JB |
1788 | /* Assuming that B is a watchpoint: |
1789 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1790 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1791 | - Evaluate the condition if there is one, and store the result |
1792 | in b->loc->cond. | |
a5606eee VP |
1793 | - Update the list of values that must be watched in B->loc. |
1794 | ||
4a64f543 MS |
1795 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1796 | nothing. If this is local watchpoint that is out of scope, delete | |
1797 | it. | |
1798 | ||
1799 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1800 | removed + inserted on each stop here. Normal breakpoints must | |
1801 | never be removed because they might be missed by a running thread | |
1802 | when debugging in non-stop mode. On the other hand, hardware | |
1803 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1804 | to each LWP since they are stored in each LWP's hardware debug | |
1805 | registers. Therefore, such LWP must be stopped first in order to | |
1806 | be able to modify its hardware watchpoints. | |
1807 | ||
1808 | Hardware watchpoints must be reset exactly once after being | |
1809 | presented to the user. It cannot be done sooner, because it would | |
1810 | reset the data used to present the watchpoint hit to the user. And | |
1811 | it must not be done later because it could display the same single | |
1812 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1813 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1814 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1815 | not user-visible - its hit is suppressed if the memory content has | |
1816 | not changed. | |
1817 | ||
1818 | The following constraints influence the location where we can reset | |
1819 | hardware watchpoints: | |
1820 | ||
1821 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1822 | called several times when GDB stops. | |
1823 | ||
1824 | [linux] | |
1825 | * Multiple hardware watchpoints can be hit at the same time, | |
1826 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1827 | hit at a time as the reason for stopping, and all the other hits | |
1828 | are presented later, one after the other, each time the user | |
1829 | requests the execution to be resumed. Execution is not resumed | |
1830 | for the threads still having pending hit event stored in | |
1831 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1832 | the inferior on the first stop the thread hit event is kept being | |
1833 | reported from its cached value by linux_nat_stopped_data_address | |
1834 | until the real thread resume happens after the watchpoint gets | |
1835 | presented and thus its LWP_INFO->STATUS gets reset. | |
1836 | ||
1837 | Therefore the hardware watchpoint hit can get safely reset on the | |
1838 | watchpoint removal from inferior. */ | |
a79d3c27 | 1839 | |
b40ce68a | 1840 | static void |
3a5c3e22 | 1841 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1842 | { |
a5606eee | 1843 | int within_current_scope; |
a5606eee | 1844 | struct frame_id saved_frame_id; |
66076460 | 1845 | int frame_saved; |
a5606eee | 1846 | |
f6bc2008 PA |
1847 | /* If this is a local watchpoint, we only want to check if the |
1848 | watchpoint frame is in scope if the current thread is the thread | |
1849 | that was used to create the watchpoint. */ | |
1850 | if (!watchpoint_in_thread_scope (b)) | |
1851 | return; | |
1852 | ||
3a5c3e22 | 1853 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1854 | return; |
1855 | ||
66076460 | 1856 | frame_saved = 0; |
a5606eee VP |
1857 | |
1858 | /* Determine if the watchpoint is within scope. */ | |
1859 | if (b->exp_valid_block == NULL) | |
1860 | within_current_scope = 1; | |
1861 | else | |
1862 | { | |
b5db5dfc UW |
1863 | struct frame_info *fi = get_current_frame (); |
1864 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1865 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1866 | ||
c9cf6e20 MG |
1867 | /* If we're at a point where the stack has been destroyed |
1868 | (e.g. in a function epilogue), unwinding may not work | |
1869 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1870 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1871 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1872 | return; |
66076460 DJ |
1873 | |
1874 | /* Save the current frame's ID so we can restore it after | |
1875 | evaluating the watchpoint expression on its own frame. */ | |
1876 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1877 | took a frame parameter, so that we didn't have to change the | |
1878 | selected frame. */ | |
1879 | frame_saved = 1; | |
1880 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1881 | ||
a5606eee VP |
1882 | fi = frame_find_by_id (b->watchpoint_frame); |
1883 | within_current_scope = (fi != NULL); | |
1884 | if (within_current_scope) | |
1885 | select_frame (fi); | |
1886 | } | |
1887 | ||
b5db5dfc UW |
1888 | /* We don't free locations. They are stored in the bp_location array |
1889 | and update_global_location_list will eventually delete them and | |
1890 | remove breakpoints if needed. */ | |
3a5c3e22 | 1891 | b->base.loc = NULL; |
b5db5dfc | 1892 | |
a5606eee VP |
1893 | if (within_current_scope && reparse) |
1894 | { | |
bbc13ae3 | 1895 | const char *s; |
d63d0675 | 1896 | |
4d01a485 | 1897 | b->exp.reset (); |
d63d0675 | 1898 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1899 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1900 | /* If the meaning of expression itself changed, the old value is |
1901 | no longer relevant. We don't want to report a watchpoint hit | |
1902 | to the user when the old value and the new value may actually | |
1903 | be completely different objects. */ | |
1904 | value_free (b->val); | |
fa4727a6 DJ |
1905 | b->val = NULL; |
1906 | b->val_valid = 0; | |
60e1c644 PA |
1907 | |
1908 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1909 | expression is stored in the breakpoint object, not in the | |
1910 | locations (re)created below. */ | |
3a5c3e22 | 1911 | if (b->base.cond_string != NULL) |
60e1c644 | 1912 | { |
4d01a485 | 1913 | b->cond_exp.reset (); |
60e1c644 | 1914 | |
3a5c3e22 | 1915 | s = b->base.cond_string; |
1bb9788d | 1916 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1917 | } |
a5606eee | 1918 | } |
a5606eee VP |
1919 | |
1920 | /* If we failed to parse the expression, for example because | |
1921 | it refers to a global variable in a not-yet-loaded shared library, | |
1922 | don't try to insert watchpoint. We don't automatically delete | |
1923 | such watchpoint, though, since failure to parse expression | |
1924 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1925 | if (!target_has_execution) |
2d134ed3 PA |
1926 | { |
1927 | /* Without execution, memory can't change. No use to try and | |
1928 | set watchpoint locations. The watchpoint will be reset when | |
1929 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1930 | if (!can_use_hw_watchpoints) |
1931 | { | |
1932 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1933 | b->base.type = bp_watchpoint; | |
1934 | else | |
638aa5a1 AB |
1935 | error (_("Can't set read/access watchpoint when " |
1936 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1937 | } |
2d134ed3 PA |
1938 | } |
1939 | else if (within_current_scope && b->exp) | |
a5606eee | 1940 | { |
0cf6dd15 | 1941 | int pc = 0; |
fa4727a6 | 1942 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1943 | struct program_space *frame_pspace; |
a5606eee | 1944 | |
4d01a485 | 1945 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1946 | |
a5606eee VP |
1947 | /* Avoid setting b->val if it's already set. The meaning of |
1948 | b->val is 'the last value' user saw, and we should update | |
1949 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1950 | happens, the code that reports it updates b->val directly. |
1951 | We don't keep track of the memory value for masked | |
1952 | watchpoints. */ | |
3a5c3e22 | 1953 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1954 | { |
bb9d5f81 PP |
1955 | if (b->val_bitsize != 0) |
1956 | { | |
1957 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1958 | if (v != NULL) | |
1959 | release_value (v); | |
1960 | } | |
fa4727a6 DJ |
1961 | b->val = v; |
1962 | b->val_valid = 1; | |
1963 | } | |
a5606eee | 1964 | |
2d134ed3 PA |
1965 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1966 | ||
a5606eee | 1967 | /* Look at each value on the value chain. */ |
9fa40276 | 1968 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1969 | { |
1970 | /* If it's a memory location, and GDB actually needed | |
1971 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1972 | must watch it. If the first value returned is |
1973 | still lazy, that means an error occurred reading it; | |
1974 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1975 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1976 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1977 | { |
1978 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1979 | |
a5606eee VP |
1980 | /* We only watch structs and arrays if user asked |
1981 | for it explicitly, never if they just happen to | |
1982 | appear in the middle of some value chain. */ | |
fa4727a6 | 1983 | if (v == result |
a5606eee VP |
1984 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1985 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1986 | { | |
1987 | CORE_ADDR addr; | |
f486487f | 1988 | enum target_hw_bp_type type; |
a5606eee | 1989 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1990 | int bitpos = 0, bitsize = 0; |
1991 | ||
1992 | if (value_bitsize (v) != 0) | |
1993 | { | |
1994 | /* Extract the bit parameters out from the bitfield | |
1995 | sub-expression. */ | |
1996 | bitpos = value_bitpos (v); | |
1997 | bitsize = value_bitsize (v); | |
1998 | } | |
1999 | else if (v == result && b->val_bitsize != 0) | |
2000 | { | |
2001 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2002 | lvalue whose bit parameters are saved in the fields | |
2003 | VAL_BITPOS and VAL_BITSIZE. */ | |
2004 | bitpos = b->val_bitpos; | |
2005 | bitsize = b->val_bitsize; | |
2006 | } | |
a5606eee | 2007 | |
42ae5230 | 2008 | addr = value_address (v); |
bb9d5f81 PP |
2009 | if (bitsize != 0) |
2010 | { | |
2011 | /* Skip the bytes that don't contain the bitfield. */ | |
2012 | addr += bitpos / 8; | |
2013 | } | |
2014 | ||
a5606eee | 2015 | type = hw_write; |
3a5c3e22 | 2016 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2017 | type = hw_read; |
3a5c3e22 | 2018 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2019 | type = hw_access; |
3a5c3e22 PA |
2020 | |
2021 | loc = allocate_bp_location (&b->base); | |
2022 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2023 | ; |
2024 | *tmp = loc; | |
a6d9a66e | 2025 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2026 | |
2027 | loc->pspace = frame_pspace; | |
a5606eee | 2028 | loc->address = addr; |
bb9d5f81 PP |
2029 | |
2030 | if (bitsize != 0) | |
2031 | { | |
2032 | /* Just cover the bytes that make up the bitfield. */ | |
2033 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2034 | } | |
2035 | else | |
2036 | loc->length = TYPE_LENGTH (value_type (v)); | |
2037 | ||
a5606eee VP |
2038 | loc->watchpoint_type = type; |
2039 | } | |
2040 | } | |
9fa40276 TJB |
2041 | } |
2042 | ||
2043 | /* Change the type of breakpoint between hardware assisted or | |
2044 | an ordinary watchpoint depending on the hardware support | |
2045 | and free hardware slots. REPARSE is set when the inferior | |
2046 | is started. */ | |
a9634178 | 2047 | if (reparse) |
9fa40276 | 2048 | { |
e09342b5 | 2049 | int reg_cnt; |
9fa40276 TJB |
2050 | enum bp_loc_type loc_type; |
2051 | struct bp_location *bl; | |
a5606eee | 2052 | |
a9634178 | 2053 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2054 | |
2055 | if (reg_cnt) | |
9fa40276 TJB |
2056 | { |
2057 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2058 | enum bptype type; |
9fa40276 | 2059 | |
a9634178 TJB |
2060 | /* Use an exact watchpoint when there's only one memory region to be |
2061 | watched, and only one debug register is needed to watch it. */ | |
2062 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2063 | ||
9fa40276 | 2064 | /* We need to determine how many resources are already |
e09342b5 TJB |
2065 | used for all other hardware watchpoints plus this one |
2066 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2067 | this watchpoint in as well. */ |
2068 | ||
2069 | /* If this is a software watchpoint, we try to turn it | |
2070 | to a hardware one -- count resources as if B was of | |
2071 | hardware watchpoint type. */ | |
2072 | type = b->base.type; | |
2073 | if (type == bp_watchpoint) | |
2074 | type = bp_hardware_watchpoint; | |
2075 | ||
2076 | /* This watchpoint may or may not have been placed on | |
2077 | the list yet at this point (it won't be in the list | |
2078 | if we're trying to create it for the first time, | |
2079 | through watch_command), so always account for it | |
2080 | manually. */ | |
2081 | ||
2082 | /* Count resources used by all watchpoints except B. */ | |
2083 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2084 | ||
2085 | /* Add in the resources needed for B. */ | |
2086 | i += hw_watchpoint_use_count (&b->base); | |
2087 | ||
2088 | target_resources_ok | |
2089 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2090 | if (target_resources_ok <= 0) |
a9634178 | 2091 | { |
3a5c3e22 | 2092 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2093 | |
2094 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2095 | error (_("Target does not support this type of " |
2096 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2097 | else if (target_resources_ok < 0 && !sw_mode) |
2098 | error (_("There are not enough available hardware " | |
2099 | "resources for this watchpoint.")); | |
a1398e0c PA |
2100 | |
2101 | /* Downgrade to software watchpoint. */ | |
2102 | b->base.type = bp_watchpoint; | |
2103 | } | |
2104 | else | |
2105 | { | |
2106 | /* If this was a software watchpoint, we've just | |
2107 | found we have enough resources to turn it to a | |
2108 | hardware watchpoint. Otherwise, this is a | |
2109 | nop. */ | |
2110 | b->base.type = type; | |
a9634178 | 2111 | } |
9fa40276 | 2112 | } |
3a5c3e22 | 2113 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2114 | { |
2115 | if (!can_use_hw_watchpoints) | |
2116 | error (_("Can't set read/access watchpoint when " | |
2117 | "hardware watchpoints are disabled.")); | |
2118 | else | |
2119 | error (_("Expression cannot be implemented with " | |
2120 | "read/access watchpoint.")); | |
2121 | } | |
9fa40276 | 2122 | else |
3a5c3e22 | 2123 | b->base.type = bp_watchpoint; |
9fa40276 | 2124 | |
3a5c3e22 | 2125 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2126 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2127 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2128 | bl->loc_type = loc_type; |
2129 | } | |
2130 | ||
2131 | for (v = val_chain; v; v = next) | |
2132 | { | |
a5606eee VP |
2133 | next = value_next (v); |
2134 | if (v != b->val) | |
2135 | value_free (v); | |
2136 | } | |
2137 | ||
c7437ca6 PA |
2138 | /* If a software watchpoint is not watching any memory, then the |
2139 | above left it without any location set up. But, | |
2140 | bpstat_stop_status requires a location to be able to report | |
2141 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2142 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c6d81124 | 2143 | software_watchpoint_add_no_memory_location (&b->base, frame_pspace); |
a5606eee VP |
2144 | } |
2145 | else if (!within_current_scope) | |
7270d8f2 | 2146 | { |
ac74f770 MS |
2147 | printf_filtered (_("\ |
2148 | Watchpoint %d deleted because the program has left the block\n\ | |
2149 | in which its expression is valid.\n"), | |
3a5c3e22 | 2150 | b->base.number); |
d0fb5eae | 2151 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2152 | } |
a5606eee VP |
2153 | |
2154 | /* Restore the selected frame. */ | |
66076460 DJ |
2155 | if (frame_saved) |
2156 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2157 | } |
2158 | ||
a5606eee | 2159 | |
74960c60 | 2160 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2161 | inserted in the inferior. We don't differentiate the type of BL's owner |
2162 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2163 | breakpoint_ops is not defined, because in insert_bp_location, | |
2164 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2165 | static int |
35df4500 | 2166 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2167 | { |
35df4500 | 2168 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2169 | return 0; |
2170 | ||
35df4500 | 2171 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2172 | return 0; |
2173 | ||
35df4500 | 2174 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2175 | return 0; |
2176 | ||
f8eba3c6 TT |
2177 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2178 | return 0; | |
2179 | ||
56710373 PA |
2180 | /* This is set for example, when we're attached to the parent of a |
2181 | vfork, and have detached from the child. The child is running | |
2182 | free, and we expect it to do an exec or exit, at which point the | |
2183 | OS makes the parent schedulable again (and the target reports | |
2184 | that the vfork is done). Until the child is done with the shared | |
2185 | memory region, do not insert breakpoints in the parent, otherwise | |
2186 | the child could still trip on the parent's breakpoints. Since | |
2187 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2188 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2189 | return 0; |
2190 | ||
31e77af2 | 2191 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2192 | location, except if the breakpoint is a single-step breakpoint, |
2193 | and the breakpoint's thread is the thread which is stepping past | |
2194 | a breakpoint. */ | |
31e77af2 PA |
2195 | if ((bl->loc_type == bp_loc_software_breakpoint |
2196 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2197 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2198 | bl->address) |
2199 | /* The single-step breakpoint may be inserted at the location | |
2200 | we're trying to step if the instruction branches to itself. | |
2201 | However, the instruction won't be executed at all and it may | |
2202 | break the semantics of the instruction, for example, the | |
2203 | instruction is a conditional branch or updates some flags. | |
2204 | We can't fix it unless GDB is able to emulate the instruction | |
2205 | or switch to displaced stepping. */ | |
2206 | && !(bl->owner->type == bp_single_step | |
2207 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2208 | { |
2209 | if (debug_infrun) | |
2210 | { | |
2211 | fprintf_unfiltered (gdb_stdlog, | |
2212 | "infrun: skipping breakpoint: " | |
2213 | "stepping past insn at: %s\n", | |
2214 | paddress (bl->gdbarch, bl->address)); | |
2215 | } | |
2216 | return 0; | |
2217 | } | |
31e77af2 | 2218 | |
963f9c80 PA |
2219 | /* Don't insert watchpoints if we're trying to step past the |
2220 | instruction that triggered one. */ | |
2221 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2222 | && stepping_past_nonsteppable_watchpoint ()) | |
2223 | { | |
2224 | if (debug_infrun) | |
2225 | { | |
2226 | fprintf_unfiltered (gdb_stdlog, | |
2227 | "infrun: stepping past non-steppable watchpoint. " | |
2228 | "skipping watchpoint at %s:%d\n", | |
2229 | paddress (bl->gdbarch, bl->address), | |
2230 | bl->length); | |
2231 | } | |
2232 | return 0; | |
2233 | } | |
2234 | ||
74960c60 VP |
2235 | return 1; |
2236 | } | |
2237 | ||
934709f0 PW |
2238 | /* Same as should_be_inserted but does the check assuming |
2239 | that the location is not duplicated. */ | |
2240 | ||
2241 | static int | |
2242 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2243 | { | |
2244 | int result; | |
2245 | const int save_duplicate = bl->duplicate; | |
2246 | ||
2247 | bl->duplicate = 0; | |
2248 | result = should_be_inserted (bl); | |
2249 | bl->duplicate = save_duplicate; | |
2250 | return result; | |
2251 | } | |
2252 | ||
b775012e LM |
2253 | /* Parses a conditional described by an expression COND into an |
2254 | agent expression bytecode suitable for evaluation | |
2255 | by the bytecode interpreter. Return NULL if there was | |
2256 | any error during parsing. */ | |
2257 | ||
833177a4 | 2258 | static agent_expr_up |
b775012e LM |
2259 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2260 | { | |
833177a4 | 2261 | if (cond == NULL) |
b775012e LM |
2262 | return NULL; |
2263 | ||
833177a4 PA |
2264 | agent_expr_up aexpr; |
2265 | ||
b775012e LM |
2266 | /* We don't want to stop processing, so catch any errors |
2267 | that may show up. */ | |
492d29ea | 2268 | TRY |
b775012e | 2269 | { |
036e657b | 2270 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2271 | } |
2272 | ||
492d29ea | 2273 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2274 | { |
2275 | /* If we got here, it means the condition could not be parsed to a valid | |
2276 | bytecode expression and thus can't be evaluated on the target's side. | |
2277 | It's no use iterating through the conditions. */ | |
b775012e | 2278 | } |
492d29ea | 2279 | END_CATCH |
b775012e LM |
2280 | |
2281 | /* We have a valid agent expression. */ | |
2282 | return aexpr; | |
2283 | } | |
2284 | ||
2285 | /* Based on location BL, create a list of breakpoint conditions to be | |
2286 | passed on to the target. If we have duplicated locations with different | |
2287 | conditions, we will add such conditions to the list. The idea is that the | |
2288 | target will evaluate the list of conditions and will only notify GDB when | |
2289 | one of them is true. */ | |
2290 | ||
2291 | static void | |
2292 | build_target_condition_list (struct bp_location *bl) | |
2293 | { | |
2294 | struct bp_location **locp = NULL, **loc2p; | |
2295 | int null_condition_or_parse_error = 0; | |
2296 | int modified = bl->needs_update; | |
2297 | struct bp_location *loc; | |
2298 | ||
8b4f3082 | 2299 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2300 | bl->target_info.conditions.clear (); |
8b4f3082 | 2301 | |
b775012e LM |
2302 | /* This is only meaningful if the target is |
2303 | evaluating conditions and if the user has | |
2304 | opted for condition evaluation on the target's | |
2305 | side. */ | |
2306 | if (gdb_evaluates_breakpoint_condition_p () | |
2307 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2308 | return; | |
2309 | ||
2310 | /* Do a first pass to check for locations with no assigned | |
2311 | conditions or conditions that fail to parse to a valid agent expression | |
2312 | bytecode. If any of these happen, then it's no use to send conditions | |
2313 | to the target since this location will always trigger and generate a | |
2314 | response back to GDB. */ | |
2315 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2316 | { | |
2317 | loc = (*loc2p); | |
2318 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2319 | { | |
2320 | if (modified) | |
2321 | { | |
b775012e LM |
2322 | /* Re-parse the conditions since something changed. In that |
2323 | case we already freed the condition bytecodes (see | |
2324 | force_breakpoint_reinsertion). We just | |
2325 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2326 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2327 | loc->cond.get ()); | |
b775012e LM |
2328 | } |
2329 | ||
2330 | /* If we have a NULL bytecode expression, it means something | |
2331 | went wrong or we have a null condition expression. */ | |
2332 | if (!loc->cond_bytecode) | |
2333 | { | |
2334 | null_condition_or_parse_error = 1; | |
2335 | break; | |
2336 | } | |
2337 | } | |
2338 | } | |
2339 | ||
2340 | /* If any of these happened, it means we will have to evaluate the conditions | |
2341 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2342 | for all the other duplicate locations, thus we free all of them here. | |
2343 | ||
2344 | This is so we have a finer control over which locations' conditions are | |
2345 | being evaluated by GDB or the remote stub. */ | |
2346 | if (null_condition_or_parse_error) | |
2347 | { | |
2348 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2349 | { | |
2350 | loc = (*loc2p); | |
2351 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2352 | { | |
2353 | /* Only go as far as the first NULL bytecode is | |
2354 | located. */ | |
2355 | if (!loc->cond_bytecode) | |
2356 | return; | |
2357 | ||
833177a4 | 2358 | loc->cond_bytecode.reset (); |
b775012e LM |
2359 | } |
2360 | } | |
2361 | } | |
2362 | ||
2363 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2364 | for this location's address. */ | |
2365 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2366 | { | |
2367 | loc = (*loc2p); | |
2368 | if (loc->cond | |
2369 | && is_breakpoint (loc->owner) | |
2370 | && loc->pspace->num == bl->pspace->num | |
2371 | && loc->owner->enable_state == bp_enabled | |
2372 | && loc->enabled) | |
3cde5c42 PA |
2373 | { |
2374 | /* Add the condition to the vector. This will be used later | |
2375 | to send the conditions to the target. */ | |
2376 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2377 | } | |
b775012e LM |
2378 | } |
2379 | ||
2380 | return; | |
2381 | } | |
2382 | ||
d3ce09f5 SS |
2383 | /* Parses a command described by string CMD into an agent expression |
2384 | bytecode suitable for evaluation by the bytecode interpreter. | |
2385 | Return NULL if there was any error during parsing. */ | |
2386 | ||
833177a4 | 2387 | static agent_expr_up |
d3ce09f5 SS |
2388 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2389 | { | |
2390 | struct cleanup *old_cleanups = 0; | |
4d01a485 | 2391 | struct expression **argvec; |
bbc13ae3 KS |
2392 | const char *cmdrest; |
2393 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2394 | struct format_piece *fpieces; |
2395 | int nargs; | |
2396 | struct gdbarch *gdbarch = get_current_arch (); | |
2397 | ||
833177a4 | 2398 | if (cmd == NULL) |
d3ce09f5 SS |
2399 | return NULL; |
2400 | ||
2401 | cmdrest = cmd; | |
2402 | ||
2403 | if (*cmdrest == ',') | |
2404 | ++cmdrest; | |
bbc13ae3 | 2405 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2406 | |
2407 | if (*cmdrest++ != '"') | |
2408 | error (_("No format string following the location")); | |
2409 | ||
2410 | format_start = cmdrest; | |
2411 | ||
2412 | fpieces = parse_format_string (&cmdrest); | |
2413 | ||
2414 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2415 | ||
2416 | format_end = cmdrest; | |
2417 | ||
2418 | if (*cmdrest++ != '"') | |
2419 | error (_("Bad format string, non-terminated '\"'.")); | |
2420 | ||
bbc13ae3 | 2421 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2422 | |
2423 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2424 | error (_("Invalid argument syntax")); | |
2425 | ||
2426 | if (*cmdrest == ',') | |
2427 | cmdrest++; | |
bbc13ae3 | 2428 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2429 | |
2430 | /* For each argument, make an expression. */ | |
2431 | ||
2432 | argvec = (struct expression **) alloca (strlen (cmd) | |
2433 | * sizeof (struct expression *)); | |
2434 | ||
2435 | nargs = 0; | |
2436 | while (*cmdrest != '\0') | |
2437 | { | |
bbc13ae3 | 2438 | const char *cmd1; |
d3ce09f5 SS |
2439 | |
2440 | cmd1 = cmdrest; | |
4d01a485 PA |
2441 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
2442 | argvec[nargs++] = expr.release (); | |
d3ce09f5 SS |
2443 | cmdrest = cmd1; |
2444 | if (*cmdrest == ',') | |
2445 | ++cmdrest; | |
2446 | } | |
2447 | ||
833177a4 PA |
2448 | agent_expr_up aexpr; |
2449 | ||
d3ce09f5 SS |
2450 | /* We don't want to stop processing, so catch any errors |
2451 | that may show up. */ | |
492d29ea | 2452 | TRY |
d3ce09f5 | 2453 | { |
036e657b JB |
2454 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2455 | format_start, format_end - format_start, | |
2456 | fpieces, nargs, argvec); | |
d3ce09f5 | 2457 | } |
492d29ea | 2458 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2459 | { |
2460 | /* If we got here, it means the command could not be parsed to a valid | |
2461 | bytecode expression and thus can't be evaluated on the target's side. | |
2462 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2463 | } |
492d29ea PA |
2464 | END_CATCH |
2465 | ||
2466 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2467 | |
d3ce09f5 SS |
2468 | /* We have a valid agent expression, return it. */ |
2469 | return aexpr; | |
2470 | } | |
2471 | ||
2472 | /* Based on location BL, create a list of breakpoint commands to be | |
2473 | passed on to the target. If we have duplicated locations with | |
2474 | different commands, we will add any such to the list. */ | |
2475 | ||
2476 | static void | |
2477 | build_target_command_list (struct bp_location *bl) | |
2478 | { | |
2479 | struct bp_location **locp = NULL, **loc2p; | |
2480 | int null_command_or_parse_error = 0; | |
2481 | int modified = bl->needs_update; | |
2482 | struct bp_location *loc; | |
2483 | ||
3cde5c42 PA |
2484 | /* Clear commands left over from a previous insert. */ |
2485 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2486 | |
41fac0cf | 2487 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2488 | return; |
2489 | ||
41fac0cf PA |
2490 | /* For now, limit to agent-style dprintf breakpoints. */ |
2491 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2492 | return; |
2493 | ||
41fac0cf PA |
2494 | /* For now, if we have any duplicate location that isn't a dprintf, |
2495 | don't install the target-side commands, as that would make the | |
2496 | breakpoint not be reported to the core, and we'd lose | |
2497 | control. */ | |
2498 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2499 | { | |
2500 | loc = (*loc2p); | |
2501 | if (is_breakpoint (loc->owner) | |
2502 | && loc->pspace->num == bl->pspace->num | |
2503 | && loc->owner->type != bp_dprintf) | |
2504 | return; | |
2505 | } | |
2506 | ||
d3ce09f5 SS |
2507 | /* Do a first pass to check for locations with no assigned |
2508 | conditions or conditions that fail to parse to a valid agent expression | |
2509 | bytecode. If any of these happen, then it's no use to send conditions | |
2510 | to the target since this location will always trigger and generate a | |
2511 | response back to GDB. */ | |
2512 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2513 | { | |
2514 | loc = (*loc2p); | |
2515 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2516 | { | |
2517 | if (modified) | |
2518 | { | |
d3ce09f5 SS |
2519 | /* Re-parse the commands since something changed. In that |
2520 | case we already freed the command bytecodes (see | |
2521 | force_breakpoint_reinsertion). We just | |
2522 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2523 | loc->cmd_bytecode |
2524 | = parse_cmd_to_aexpr (bl->address, | |
2525 | loc->owner->extra_string); | |
d3ce09f5 SS |
2526 | } |
2527 | ||
2528 | /* If we have a NULL bytecode expression, it means something | |
2529 | went wrong or we have a null command expression. */ | |
2530 | if (!loc->cmd_bytecode) | |
2531 | { | |
2532 | null_command_or_parse_error = 1; | |
2533 | break; | |
2534 | } | |
2535 | } | |
2536 | } | |
2537 | ||
2538 | /* If anything failed, then we're not doing target-side commands, | |
2539 | and so clean up. */ | |
2540 | if (null_command_or_parse_error) | |
2541 | { | |
2542 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2543 | { | |
2544 | loc = (*loc2p); | |
2545 | if (is_breakpoint (loc->owner) | |
2546 | && loc->pspace->num == bl->pspace->num) | |
2547 | { | |
2548 | /* Only go as far as the first NULL bytecode is | |
2549 | located. */ | |
40fb6c5e | 2550 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2551 | return; |
2552 | ||
833177a4 | 2553 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2554 | } |
2555 | } | |
2556 | } | |
2557 | ||
2558 | /* No NULL commands or failed bytecode generation. Build a command list | |
2559 | for this location's address. */ | |
2560 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2561 | { | |
2562 | loc = (*loc2p); | |
2563 | if (loc->owner->extra_string | |
2564 | && is_breakpoint (loc->owner) | |
2565 | && loc->pspace->num == bl->pspace->num | |
2566 | && loc->owner->enable_state == bp_enabled | |
2567 | && loc->enabled) | |
3cde5c42 PA |
2568 | { |
2569 | /* Add the command to the vector. This will be used later | |
2570 | to send the commands to the target. */ | |
2571 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2572 | } | |
d3ce09f5 SS |
2573 | } |
2574 | ||
2575 | bl->target_info.persist = 0; | |
2576 | /* Maybe flag this location as persistent. */ | |
2577 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2578 | bl->target_info.persist = 1; | |
2579 | } | |
2580 | ||
833b7ab5 YQ |
2581 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2582 | of breakpoint according to ADDR except single-step breakpoint. | |
2583 | Get the kind of single-step breakpoint according to the current | |
2584 | registers state. */ | |
cd6c3b4f YQ |
2585 | |
2586 | static int | |
2587 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2588 | { | |
833b7ab5 YQ |
2589 | if (bl->owner->type == bp_single_step) |
2590 | { | |
2591 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2592 | struct regcache *regcache; | |
2593 | ||
2594 | regcache = get_thread_regcache (thr->ptid); | |
2595 | ||
2596 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2597 | regcache, addr); | |
2598 | } | |
2599 | else | |
2600 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2601 | } |
2602 | ||
35df4500 TJB |
2603 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2604 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2605 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2606 | Returns 0 for success, 1 if the bp_location type is not supported or |
2607 | -1 for failure. | |
879bfdc2 | 2608 | |
4a64f543 MS |
2609 | NOTE drow/2003-09-09: This routine could be broken down to an |
2610 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2611 | static int |
35df4500 | 2612 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2613 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2614 | int *disabled_breaks, |
dd61ec5c MW |
2615 | int *hw_breakpoint_error, |
2616 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2617 | { |
0000e5cc PA |
2618 | enum errors bp_err = GDB_NO_ERROR; |
2619 | const char *bp_err_message = NULL; | |
879bfdc2 | 2620 | |
b775012e | 2621 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2622 | return 0; |
2623 | ||
35c63cd8 JB |
2624 | /* Note we don't initialize bl->target_info, as that wipes out |
2625 | the breakpoint location's shadow_contents if the breakpoint | |
2626 | is still inserted at that location. This in turn breaks | |
2627 | target_read_memory which depends on these buffers when | |
2628 | a memory read is requested at the breakpoint location: | |
2629 | Once the target_info has been wiped, we fail to see that | |
2630 | we have a breakpoint inserted at that address and thus | |
2631 | read the breakpoint instead of returning the data saved in | |
2632 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2633 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2634 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2635 | bl->target_info.length = bl->length; |
8181d85f | 2636 | |
b775012e LM |
2637 | /* When working with target-side conditions, we must pass all the conditions |
2638 | for the same breakpoint address down to the target since GDB will not | |
2639 | insert those locations. With a list of breakpoint conditions, the target | |
2640 | can decide when to stop and notify GDB. */ | |
2641 | ||
2642 | if (is_breakpoint (bl->owner)) | |
2643 | { | |
2644 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2645 | build_target_command_list (bl); |
2646 | /* Reset the modification marker. */ | |
b775012e LM |
2647 | bl->needs_update = 0; |
2648 | } | |
2649 | ||
35df4500 TJB |
2650 | if (bl->loc_type == bp_loc_software_breakpoint |
2651 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2652 | { |
35df4500 | 2653 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2654 | { |
2655 | /* If the explicitly specified breakpoint type | |
2656 | is not hardware breakpoint, check the memory map to see | |
2657 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2658 | |
765dc015 VP |
2659 | Two important cases are: |
2660 | - location type is not hardware breakpoint, memory | |
2661 | is readonly. We change the type of the location to | |
2662 | hardware breakpoint. | |
4a64f543 MS |
2663 | - location type is hardware breakpoint, memory is |
2664 | read-write. This means we've previously made the | |
2665 | location hardware one, but then the memory map changed, | |
2666 | so we undo. | |
765dc015 | 2667 | |
4a64f543 MS |
2668 | When breakpoints are removed, remove_breakpoints will use |
2669 | location types we've just set here, the only possible | |
2670 | problem is that memory map has changed during running | |
2671 | program, but it's not going to work anyway with current | |
2672 | gdb. */ | |
765dc015 | 2673 | struct mem_region *mr |
0d5ed153 | 2674 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2675 | |
2676 | if (mr) | |
2677 | { | |
2678 | if (automatic_hardware_breakpoints) | |
2679 | { | |
765dc015 VP |
2680 | enum bp_loc_type new_type; |
2681 | ||
2682 | if (mr->attrib.mode != MEM_RW) | |
2683 | new_type = bp_loc_hardware_breakpoint; | |
2684 | else | |
2685 | new_type = bp_loc_software_breakpoint; | |
2686 | ||
35df4500 | 2687 | if (new_type != bl->loc_type) |
765dc015 VP |
2688 | { |
2689 | static int said = 0; | |
cc59ec59 | 2690 | |
35df4500 | 2691 | bl->loc_type = new_type; |
765dc015 VP |
2692 | if (!said) |
2693 | { | |
3e43a32a MS |
2694 | fprintf_filtered (gdb_stdout, |
2695 | _("Note: automatically using " | |
2696 | "hardware breakpoints for " | |
2697 | "read-only addresses.\n")); | |
765dc015 VP |
2698 | said = 1; |
2699 | } | |
2700 | } | |
2701 | } | |
35df4500 | 2702 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2703 | && mr->attrib.mode != MEM_RW) |
2704 | { | |
2705 | fprintf_unfiltered (tmp_error_stream, | |
2706 | _("Cannot insert breakpoint %d.\n" | |
2707 | "Cannot set software breakpoint " | |
2708 | "at read-only address %s\n"), | |
2709 | bl->owner->number, | |
2710 | paddress (bl->gdbarch, bl->address)); | |
2711 | return 1; | |
2712 | } | |
765dc015 VP |
2713 | } |
2714 | } | |
2715 | ||
879bfdc2 DJ |
2716 | /* First check to see if we have to handle an overlay. */ |
2717 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2718 | || bl->section == NULL |
2719 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2720 | { |
2721 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2722 | TRY |
dd61ec5c | 2723 | { |
0000e5cc PA |
2724 | int val; |
2725 | ||
dd61ec5c | 2726 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2727 | if (val) |
2728 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2729 | } |
492d29ea | 2730 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2731 | { |
0000e5cc PA |
2732 | bp_err = e.error; |
2733 | bp_err_message = e.message; | |
dd61ec5c | 2734 | } |
492d29ea | 2735 | END_CATCH |
879bfdc2 DJ |
2736 | } |
2737 | else | |
2738 | { | |
4a64f543 | 2739 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2740 | Shall we set a breakpoint at the LMA? */ |
2741 | if (!overlay_events_enabled) | |
2742 | { | |
2743 | /* Yes -- overlay event support is not active, | |
2744 | so we must try to set a breakpoint at the LMA. | |
2745 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2746 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2747 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2748 | bl->owner->number); |
879bfdc2 DJ |
2749 | else |
2750 | { | |
35df4500 TJB |
2751 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2752 | bl->section); | |
879bfdc2 | 2753 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2754 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2755 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2756 | |
2757 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2758 | TRY |
0000e5cc PA |
2759 | { |
2760 | int val; | |
2761 | ||
579c6ad9 | 2762 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2763 | = breakpoint_kind (bl, &addr); |
2764 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2765 | val = target_insert_breakpoint (bl->gdbarch, |
2766 | &bl->overlay_target_info); | |
2767 | if (val) | |
2768 | bp_err = GENERIC_ERROR; | |
2769 | } | |
492d29ea | 2770 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2771 | { |
2772 | bp_err = e.error; | |
2773 | bp_err_message = e.message; | |
2774 | } | |
492d29ea | 2775 | END_CATCH |
0000e5cc PA |
2776 | |
2777 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2778 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2779 | "Overlay breakpoint %d " |
2780 | "failed: in ROM?\n", | |
35df4500 | 2781 | bl->owner->number); |
879bfdc2 DJ |
2782 | } |
2783 | } | |
2784 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2785 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2786 | { |
2787 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2788 | TRY |
dd61ec5c | 2789 | { |
0000e5cc PA |
2790 | int val; |
2791 | ||
dd61ec5c | 2792 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2793 | if (val) |
2794 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2795 | } |
492d29ea | 2796 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2797 | { |
0000e5cc PA |
2798 | bp_err = e.error; |
2799 | bp_err_message = e.message; | |
dd61ec5c | 2800 | } |
492d29ea | 2801 | END_CATCH |
879bfdc2 DJ |
2802 | } |
2803 | else | |
2804 | { | |
2805 | /* No. This breakpoint will not be inserted. | |
2806 | No error, but do not mark the bp as 'inserted'. */ | |
2807 | return 0; | |
2808 | } | |
2809 | } | |
2810 | ||
0000e5cc | 2811 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2812 | { |
2813 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2814 | |
2815 | /* In some cases, we might not be able to insert a | |
2816 | breakpoint in a shared library that has already been | |
2817 | removed, but we have not yet processed the shlib unload | |
2818 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2819 | breakpoint insertion themselves can't tell why the |
2820 | breakpoint insertion failed (e.g., the remote target | |
2821 | doesn't define error codes), so we must treat generic | |
2822 | errors as memory errors. */ | |
0000e5cc | 2823 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2824 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2825 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2826 | || shared_objfile_contains_address_p (bl->pspace, |
2827 | bl->address))) | |
879bfdc2 | 2828 | { |
4a64f543 | 2829 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2830 | bl->shlib_disabled = 1; |
8d3788bd | 2831 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2832 | if (!*disabled_breaks) |
2833 | { | |
2834 | fprintf_unfiltered (tmp_error_stream, | |
2835 | "Cannot insert breakpoint %d.\n", | |
2836 | bl->owner->number); | |
2837 | fprintf_unfiltered (tmp_error_stream, | |
2838 | "Temporarily disabling shared " | |
2839 | "library breakpoints:\n"); | |
2840 | } | |
2841 | *disabled_breaks = 1; | |
879bfdc2 | 2842 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2843 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2844 | return 0; |
879bfdc2 DJ |
2845 | } |
2846 | else | |
879bfdc2 | 2847 | { |
35df4500 | 2848 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2849 | { |
0000e5cc PA |
2850 | *hw_breakpoint_error = 1; |
2851 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2852 | fprintf_unfiltered (tmp_error_stream, |
2853 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2854 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2855 | if (bp_err_message != NULL) | |
2856 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2857 | } |
2858 | else | |
2859 | { | |
0000e5cc PA |
2860 | if (bp_err_message == NULL) |
2861 | { | |
2862 | char *message | |
2863 | = memory_error_message (TARGET_XFER_E_IO, | |
2864 | bl->gdbarch, bl->address); | |
2865 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2866 | ||
2867 | fprintf_unfiltered (tmp_error_stream, | |
2868 | "Cannot insert breakpoint %d.\n" | |
2869 | "%s\n", | |
2870 | bl->owner->number, message); | |
2871 | do_cleanups (old_chain); | |
2872 | } | |
2873 | else | |
2874 | { | |
2875 | fprintf_unfiltered (tmp_error_stream, | |
2876 | "Cannot insert breakpoint %d: %s\n", | |
2877 | bl->owner->number, | |
2878 | bp_err_message); | |
2879 | } | |
879bfdc2 | 2880 | } |
0000e5cc | 2881 | return 1; |
879bfdc2 DJ |
2882 | |
2883 | } | |
2884 | } | |
2885 | else | |
35df4500 | 2886 | bl->inserted = 1; |
879bfdc2 | 2887 | |
0000e5cc | 2888 | return 0; |
879bfdc2 DJ |
2889 | } |
2890 | ||
35df4500 | 2891 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2892 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2893 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2894 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2895 | { |
0000e5cc PA |
2896 | int val; |
2897 | ||
77b06cd7 TJB |
2898 | gdb_assert (bl->owner->ops != NULL |
2899 | && bl->owner->ops->insert_location != NULL); | |
2900 | ||
2901 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2902 | |
2903 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2904 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2905 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2906 | { |
2907 | struct bp_location *loc, **loc_temp; | |
2908 | ||
2909 | /* But don't try to insert it, if there's already another | |
2910 | hw_access location that would be considered a duplicate | |
2911 | of this one. */ | |
2912 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2913 | if (loc != bl |
85d721b8 | 2914 | && loc->watchpoint_type == hw_access |
35df4500 | 2915 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2916 | { |
35df4500 TJB |
2917 | bl->duplicate = 1; |
2918 | bl->inserted = 1; | |
2919 | bl->target_info = loc->target_info; | |
2920 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2921 | val = 0; |
2922 | break; | |
2923 | } | |
2924 | ||
2925 | if (val == 1) | |
2926 | { | |
77b06cd7 TJB |
2927 | bl->watchpoint_type = hw_access; |
2928 | val = bl->owner->ops->insert_location (bl); | |
2929 | ||
2930 | if (val) | |
2931 | /* Back to the original value. */ | |
2932 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2933 | } |
2934 | } | |
2935 | ||
35df4500 | 2936 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2937 | } |
2938 | ||
35df4500 | 2939 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2940 | { |
0000e5cc PA |
2941 | int val; |
2942 | ||
77b06cd7 TJB |
2943 | gdb_assert (bl->owner->ops != NULL |
2944 | && bl->owner->ops->insert_location != NULL); | |
2945 | ||
2946 | val = bl->owner->ops->insert_location (bl); | |
2947 | if (val) | |
2948 | { | |
2949 | bl->owner->enable_state = bp_disabled; | |
2950 | ||
2951 | if (val == 1) | |
2952 | warning (_("\ | |
2953 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2954 | of catchpoint."), bl->owner->number); | |
2955 | else | |
2956 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2957 | } | |
2958 | ||
2959 | bl->inserted = (val == 0); | |
1640b821 DJ |
2960 | |
2961 | /* We've already printed an error message if there was a problem | |
2962 | inserting this catchpoint, and we've disabled the catchpoint, | |
2963 | so just return success. */ | |
2964 | return 0; | |
879bfdc2 DJ |
2965 | } |
2966 | ||
2967 | return 0; | |
2968 | } | |
2969 | ||
6c95b8df PA |
2970 | /* This function is called when program space PSPACE is about to be |
2971 | deleted. It takes care of updating breakpoints to not reference | |
2972 | PSPACE anymore. */ | |
2973 | ||
2974 | void | |
2975 | breakpoint_program_space_exit (struct program_space *pspace) | |
2976 | { | |
2977 | struct breakpoint *b, *b_temp; | |
876fa593 | 2978 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2979 | |
2980 | /* Remove any breakpoint that was set through this program space. */ | |
2981 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2982 | { | |
2983 | if (b->pspace == pspace) | |
2984 | delete_breakpoint (b); | |
2985 | } | |
2986 | ||
2987 | /* Breakpoints set through other program spaces could have locations | |
2988 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2989 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2990 | { |
2991 | struct bp_location *tmp; | |
2992 | ||
2993 | if (loc->pspace == pspace) | |
2994 | { | |
2bdf28a0 | 2995 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2996 | if (loc->owner->loc == loc) |
2997 | loc->owner->loc = loc->next; | |
2998 | else | |
2999 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3000 | if (tmp->next == loc) | |
3001 | { | |
3002 | tmp->next = loc->next; | |
3003 | break; | |
3004 | } | |
3005 | } | |
3006 | } | |
3007 | ||
3008 | /* Now update the global location list to permanently delete the | |
3009 | removed locations above. */ | |
44702360 | 3010 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3011 | } |
3012 | ||
74960c60 VP |
3013 | /* Make sure all breakpoints are inserted in inferior. |
3014 | Throws exception on any error. | |
3015 | A breakpoint that is already inserted won't be inserted | |
3016 | again, so calling this function twice is safe. */ | |
3017 | void | |
3018 | insert_breakpoints (void) | |
3019 | { | |
3020 | struct breakpoint *bpt; | |
3021 | ||
3022 | ALL_BREAKPOINTS (bpt) | |
3023 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3024 | { |
3025 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3026 | ||
3027 | update_watchpoint (w, 0 /* don't reparse. */); | |
3028 | } | |
74960c60 | 3029 | |
04086b45 PA |
3030 | /* Updating watchpoints creates new locations, so update the global |
3031 | location list. Explicitly tell ugll to insert locations and | |
3032 | ignore breakpoints_always_inserted_mode. */ | |
3033 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3034 | } |
3035 | ||
20388dd6 YQ |
3036 | /* Invoke CALLBACK for each of bp_location. */ |
3037 | ||
3038 | void | |
3039 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3040 | { | |
3041 | struct bp_location *loc, **loc_tmp; | |
3042 | ||
3043 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3044 | { | |
3045 | callback (loc, NULL); | |
3046 | } | |
3047 | } | |
3048 | ||
b775012e LM |
3049 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3050 | target. It is the case with deleting and disabling of breakpoints when using | |
3051 | always-inserted mode. */ | |
3052 | ||
3053 | static void | |
3054 | update_inserted_breakpoint_locations (void) | |
3055 | { | |
3056 | struct bp_location *bl, **blp_tmp; | |
3057 | int error_flag = 0; | |
3058 | int val = 0; | |
3059 | int disabled_breaks = 0; | |
3060 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3061 | int hw_bp_details_reported = 0; |
b775012e | 3062 | |
d7e74731 | 3063 | string_file tmp_error_stream; |
b775012e LM |
3064 | |
3065 | /* Explicitly mark the warning -- this will only be printed if | |
3066 | there was an error. */ | |
d7e74731 | 3067 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 3068 | |
d7e74731 | 3069 | struct cleanup *cleanups = save_current_space_and_thread (); |
b775012e LM |
3070 | |
3071 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3072 | { | |
3073 | /* We only want to update software breakpoints and hardware | |
3074 | breakpoints. */ | |
3075 | if (!is_breakpoint (bl->owner)) | |
3076 | continue; | |
3077 | ||
3078 | /* We only want to update locations that are already inserted | |
3079 | and need updating. This is to avoid unwanted insertion during | |
3080 | deletion of breakpoints. */ | |
3081 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3082 | continue; | |
3083 | ||
3084 | switch_to_program_space_and_thread (bl->pspace); | |
3085 | ||
3086 | /* For targets that support global breakpoints, there's no need | |
3087 | to select an inferior to insert breakpoint to. In fact, even | |
3088 | if we aren't attached to any process yet, we should still | |
3089 | insert breakpoints. */ | |
f5656ead | 3090 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3091 | && ptid_equal (inferior_ptid, null_ptid)) |
3092 | continue; | |
3093 | ||
d7e74731 | 3094 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3095 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3096 | if (val) |
3097 | error_flag = val; | |
3098 | } | |
3099 | ||
3100 | if (error_flag) | |
3101 | { | |
3102 | target_terminal_ours_for_output (); | |
3103 | error_stream (tmp_error_stream); | |
3104 | } | |
3105 | ||
3106 | do_cleanups (cleanups); | |
3107 | } | |
3108 | ||
c30eee59 | 3109 | /* Used when starting or continuing the program. */ |
c906108c | 3110 | |
74960c60 VP |
3111 | static void |
3112 | insert_breakpoint_locations (void) | |
c906108c | 3113 | { |
a5606eee | 3114 | struct breakpoint *bpt; |
35df4500 | 3115 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3116 | int error_flag = 0; |
c906108c | 3117 | int val = 0; |
3fbb6ffa | 3118 | int disabled_breaks = 0; |
81d0cc19 | 3119 | int hw_breakpoint_error = 0; |
dd61ec5c | 3120 | int hw_bp_error_explained_already = 0; |
c906108c | 3121 | |
d7e74731 PA |
3122 | string_file tmp_error_stream; |
3123 | ||
81d0cc19 GS |
3124 | /* Explicitly mark the warning -- this will only be printed if |
3125 | there was an error. */ | |
d7e74731 | 3126 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3127 | |
d7e74731 | 3128 | struct cleanup *cleanups = save_current_space_and_thread (); |
6c95b8df | 3129 | |
35df4500 | 3130 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3131 | { |
b775012e | 3132 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3133 | continue; |
3134 | ||
4a64f543 MS |
3135 | /* There is no point inserting thread-specific breakpoints if |
3136 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3137 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3138 | if (bl->owner->thread != -1 |
5d5658a1 | 3139 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3140 | continue; |
3141 | ||
35df4500 | 3142 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3143 | |
3144 | /* For targets that support global breakpoints, there's no need | |
3145 | to select an inferior to insert breakpoint to. In fact, even | |
3146 | if we aren't attached to any process yet, we should still | |
3147 | insert breakpoints. */ | |
f5656ead | 3148 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3149 | && ptid_equal (inferior_ptid, null_ptid)) |
3150 | continue; | |
3151 | ||
d7e74731 | 3152 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3153 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3154 | if (val) |
eacd795a | 3155 | error_flag = val; |
879bfdc2 | 3156 | } |
c906108c | 3157 | |
4a64f543 MS |
3158 | /* If we failed to insert all locations of a watchpoint, remove |
3159 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3160 | ALL_BREAKPOINTS (bpt) |
3161 | { | |
3162 | int some_failed = 0; | |
3163 | struct bp_location *loc; | |
3164 | ||
3165 | if (!is_hardware_watchpoint (bpt)) | |
3166 | continue; | |
3167 | ||
d6b74ac4 | 3168 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3169 | continue; |
74960c60 VP |
3170 | |
3171 | if (bpt->disposition == disp_del_at_next_stop) | |
3172 | continue; | |
a5606eee VP |
3173 | |
3174 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3175 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3176 | { |
3177 | some_failed = 1; | |
3178 | break; | |
3179 | } | |
3180 | if (some_failed) | |
3181 | { | |
3182 | for (loc = bpt->loc; loc; loc = loc->next) | |
3183 | if (loc->inserted) | |
834c0d03 | 3184 | remove_breakpoint (loc); |
a5606eee VP |
3185 | |
3186 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3187 | tmp_error_stream.printf ("Could not insert " |
3188 | "hardware watchpoint %d.\n", | |
3189 | bpt->number); | |
eacd795a | 3190 | error_flag = -1; |
a5606eee VP |
3191 | } |
3192 | } | |
3193 | ||
eacd795a | 3194 | if (error_flag) |
81d0cc19 GS |
3195 | { |
3196 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3197 | message about possibly exhausted resources. */ | |
dd61ec5c | 3198 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3199 | { |
d7e74731 | 3200 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3201 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3202 | } |
81d0cc19 GS |
3203 | target_terminal_ours_for_output (); |
3204 | error_stream (tmp_error_stream); | |
3205 | } | |
f7545552 TT |
3206 | |
3207 | do_cleanups (cleanups); | |
c906108c SS |
3208 | } |
3209 | ||
c30eee59 TJB |
3210 | /* Used when the program stops. |
3211 | Returns zero if successful, or non-zero if there was a problem | |
3212 | removing a breakpoint location. */ | |
3213 | ||
c906108c | 3214 | int |
fba45db2 | 3215 | remove_breakpoints (void) |
c906108c | 3216 | { |
35df4500 | 3217 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3218 | int val = 0; |
c906108c | 3219 | |
35df4500 | 3220 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3221 | { |
1e4d1764 | 3222 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3223 | val |= remove_breakpoint (bl); |
c5aa993b | 3224 | } |
3a1bae8e | 3225 | return val; |
c906108c SS |
3226 | } |
3227 | ||
49fa26b0 PA |
3228 | /* When a thread exits, remove breakpoints that are related to |
3229 | that thread. */ | |
3230 | ||
3231 | static void | |
3232 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3233 | { | |
3234 | struct breakpoint *b, *b_tmp; | |
3235 | ||
3236 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3237 | { | |
5d5658a1 | 3238 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3239 | { |
3240 | b->disposition = disp_del_at_next_stop; | |
3241 | ||
3242 | printf_filtered (_("\ | |
43792cf0 PA |
3243 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3244 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3245 | |
3246 | /* Hide it from the user. */ | |
3247 | b->number = 0; | |
3248 | } | |
3249 | } | |
3250 | } | |
3251 | ||
6c95b8df PA |
3252 | /* Remove breakpoints of process PID. */ |
3253 | ||
3254 | int | |
3255 | remove_breakpoints_pid (int pid) | |
3256 | { | |
35df4500 | 3257 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3258 | int val; |
3259 | struct inferior *inf = find_inferior_pid (pid); | |
3260 | ||
35df4500 | 3261 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3262 | { |
35df4500 | 3263 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3264 | continue; |
3265 | ||
fc126975 | 3266 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3267 | { |
834c0d03 | 3268 | val = remove_breakpoint (bl); |
6c95b8df PA |
3269 | if (val != 0) |
3270 | return val; | |
3271 | } | |
3272 | } | |
3273 | return 0; | |
3274 | } | |
3275 | ||
c906108c | 3276 | int |
fba45db2 | 3277 | reattach_breakpoints (int pid) |
c906108c | 3278 | { |
6c95b8df | 3279 | struct cleanup *old_chain; |
35df4500 | 3280 | struct bp_location *bl, **blp_tmp; |
c906108c | 3281 | int val; |
dd61ec5c | 3282 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3283 | struct inferior *inf; |
3284 | struct thread_info *tp; | |
3285 | ||
3286 | tp = any_live_thread_of_process (pid); | |
3287 | if (tp == NULL) | |
3288 | return 1; | |
3289 | ||
3290 | inf = find_inferior_pid (pid); | |
3291 | old_chain = save_inferior_ptid (); | |
3292 | ||
3293 | inferior_ptid = tp->ptid; | |
a4954f26 | 3294 | |
d7e74731 | 3295 | string_file tmp_error_stream; |
c906108c | 3296 | |
35df4500 | 3297 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3298 | { |
35df4500 | 3299 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3300 | continue; |
3301 | ||
35df4500 | 3302 | if (bl->inserted) |
c5aa993b | 3303 | { |
35df4500 | 3304 | bl->inserted = 0; |
d7e74731 | 3305 | val = insert_bp_location (bl, &tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3306 | if (val != 0) |
3307 | { | |
ce696e05 | 3308 | do_cleanups (old_chain); |
c5aa993b JM |
3309 | return val; |
3310 | } | |
3311 | } | |
3312 | } | |
ce696e05 | 3313 | do_cleanups (old_chain); |
c906108c SS |
3314 | return 0; |
3315 | } | |
3316 | ||
e58b0e63 PA |
3317 | static int internal_breakpoint_number = -1; |
3318 | ||
84f4c1fe PM |
3319 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3320 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3321 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3322 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3323 | breakpoint_count and that value incremented. Internal breakpoints |
3324 | do not set the internal var bpnum. */ | |
3325 | static void | |
3326 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3327 | { | |
3328 | if (internal) | |
3329 | b->number = internal_breakpoint_number--; | |
3330 | else | |
3331 | { | |
3332 | set_breakpoint_count (breakpoint_count + 1); | |
3333 | b->number = breakpoint_count; | |
3334 | } | |
3335 | } | |
3336 | ||
e62c965a | 3337 | static struct breakpoint * |
a6d9a66e | 3338 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3339 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3340 | const struct breakpoint_ops *ops) |
e62c965a | 3341 | { |
e62c965a PP |
3342 | struct symtab_and_line sal; |
3343 | struct breakpoint *b; | |
3344 | ||
4a64f543 | 3345 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3346 | |
3347 | sal.pc = address; | |
3348 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3349 | sal.pspace = current_program_space; |
e62c965a | 3350 | |
06edf0c0 | 3351 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3352 | b->number = internal_breakpoint_number--; |
3353 | b->disposition = disp_donttouch; | |
3354 | ||
3355 | return b; | |
3356 | } | |
3357 | ||
17450429 PP |
3358 | static const char *const longjmp_names[] = |
3359 | { | |
3360 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3361 | }; | |
3362 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3363 | ||
3364 | /* Per-objfile data private to breakpoint.c. */ | |
3365 | struct breakpoint_objfile_data | |
3366 | { | |
3367 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3368 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3369 | |
3370 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3371 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3372 | |
28106bc2 SDJ |
3373 | /* True if we have looked for longjmp probes. */ |
3374 | int longjmp_searched; | |
3375 | ||
3376 | /* SystemTap probe points for longjmp (if any). */ | |
3377 | VEC (probe_p) *longjmp_probes; | |
3378 | ||
17450429 | 3379 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3380 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3381 | |
3382 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3383 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3384 | |
3385 | /* True if we have looked for exception probes. */ | |
3386 | int exception_searched; | |
3387 | ||
3388 | /* SystemTap probe points for unwinding (if any). */ | |
3389 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3390 | }; |
3391 | ||
3392 | static const struct objfile_data *breakpoint_objfile_key; | |
3393 | ||
3394 | /* Minimal symbol not found sentinel. */ | |
3395 | static struct minimal_symbol msym_not_found; | |
3396 | ||
3397 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3398 | ||
3399 | static int | |
3400 | msym_not_found_p (const struct minimal_symbol *msym) | |
3401 | { | |
3402 | return msym == &msym_not_found; | |
3403 | } | |
3404 | ||
3405 | /* Return per-objfile data needed by breakpoint.c. | |
3406 | Allocate the data if necessary. */ | |
3407 | ||
3408 | static struct breakpoint_objfile_data * | |
3409 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3410 | { | |
3411 | struct breakpoint_objfile_data *bp_objfile_data; | |
3412 | ||
9a3c8263 SM |
3413 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3414 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3415 | if (bp_objfile_data == NULL) |
3416 | { | |
8d749320 SM |
3417 | bp_objfile_data = |
3418 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3419 | |
3420 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3421 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3422 | } | |
3423 | return bp_objfile_data; | |
3424 | } | |
3425 | ||
28106bc2 SDJ |
3426 | static void |
3427 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3428 | { | |
9a3c8263 SM |
3429 | struct breakpoint_objfile_data *bp_objfile_data |
3430 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3431 | |
3432 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3433 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3434 | } | |
3435 | ||
e62c965a | 3436 | static void |
af02033e | 3437 | create_overlay_event_breakpoint (void) |
e62c965a | 3438 | { |
69de3c6a | 3439 | struct objfile *objfile; |
af02033e | 3440 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3441 | |
69de3c6a PP |
3442 | ALL_OBJFILES (objfile) |
3443 | { | |
3444 | struct breakpoint *b; | |
17450429 PP |
3445 | struct breakpoint_objfile_data *bp_objfile_data; |
3446 | CORE_ADDR addr; | |
67994074 | 3447 | struct explicit_location explicit_loc; |
69de3c6a | 3448 | |
17450429 PP |
3449 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3450 | ||
3b7344d5 | 3451 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3452 | continue; |
3453 | ||
3b7344d5 | 3454 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3455 | { |
3b7344d5 | 3456 | struct bound_minimal_symbol m; |
17450429 PP |
3457 | |
3458 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3459 | if (m.minsym == NULL) |
17450429 PP |
3460 | { |
3461 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3462 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3463 | continue; |
3464 | } | |
3465 | bp_objfile_data->overlay_msym = m; | |
3466 | } | |
e62c965a | 3467 | |
77e371c0 | 3468 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3469 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3470 | bp_overlay_event, |
3471 | &internal_breakpoint_ops); | |
67994074 KS |
3472 | initialize_explicit_location (&explicit_loc); |
3473 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3474 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3475 | |
69de3c6a PP |
3476 | if (overlay_debugging == ovly_auto) |
3477 | { | |
3478 | b->enable_state = bp_enabled; | |
3479 | overlay_events_enabled = 1; | |
3480 | } | |
3481 | else | |
3482 | { | |
3483 | b->enable_state = bp_disabled; | |
3484 | overlay_events_enabled = 0; | |
3485 | } | |
e62c965a | 3486 | } |
e62c965a PP |
3487 | } |
3488 | ||
0fd8e87f | 3489 | static void |
af02033e | 3490 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3491 | { |
6c95b8df | 3492 | struct program_space *pspace; |
6c95b8df PA |
3493 | struct cleanup *old_chain; |
3494 | ||
3495 | old_chain = save_current_program_space (); | |
0fd8e87f | 3496 | |
6c95b8df | 3497 | ALL_PSPACES (pspace) |
af02033e PP |
3498 | { |
3499 | struct objfile *objfile; | |
3500 | ||
3501 | set_current_program_space (pspace); | |
3502 | ||
3503 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3504 | { |
af02033e PP |
3505 | int i; |
3506 | struct gdbarch *gdbarch; | |
17450429 | 3507 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3508 | |
af02033e | 3509 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3510 | |
17450429 PP |
3511 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3512 | ||
28106bc2 SDJ |
3513 | if (!bp_objfile_data->longjmp_searched) |
3514 | { | |
25f9533e SDJ |
3515 | VEC (probe_p) *ret; |
3516 | ||
3517 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3518 | if (ret != NULL) | |
3519 | { | |
3520 | /* We are only interested in checking one element. */ | |
3521 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3522 | ||
3523 | if (!can_evaluate_probe_arguments (p)) | |
3524 | { | |
3525 | /* We cannot use the probe interface here, because it does | |
3526 | not know how to evaluate arguments. */ | |
3527 | VEC_free (probe_p, ret); | |
3528 | ret = NULL; | |
3529 | } | |
3530 | } | |
3531 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3532 | bp_objfile_data->longjmp_searched = 1; |
3533 | } | |
3534 | ||
3535 | if (bp_objfile_data->longjmp_probes != NULL) | |
3536 | { | |
3537 | int i; | |
3538 | struct probe *probe; | |
3539 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3540 | ||
3541 | for (i = 0; | |
3542 | VEC_iterate (probe_p, | |
3543 | bp_objfile_data->longjmp_probes, | |
3544 | i, probe); | |
3545 | ++i) | |
3546 | { | |
3547 | struct breakpoint *b; | |
3548 | ||
729662a5 TT |
3549 | b = create_internal_breakpoint (gdbarch, |
3550 | get_probe_address (probe, | |
3551 | objfile), | |
28106bc2 SDJ |
3552 | bp_longjmp_master, |
3553 | &internal_breakpoint_ops); | |
d28cd78a | 3554 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
28106bc2 SDJ |
3555 | b->enable_state = bp_disabled; |
3556 | } | |
3557 | ||
3558 | continue; | |
3559 | } | |
3560 | ||
0569175e TSD |
3561 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3562 | continue; | |
3563 | ||
17450429 | 3564 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3565 | { |
3566 | struct breakpoint *b; | |
af02033e | 3567 | const char *func_name; |
17450429 | 3568 | CORE_ADDR addr; |
67994074 | 3569 | struct explicit_location explicit_loc; |
6c95b8df | 3570 | |
3b7344d5 | 3571 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3572 | continue; |
0fd8e87f | 3573 | |
17450429 | 3574 | func_name = longjmp_names[i]; |
3b7344d5 | 3575 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3576 | { |
3b7344d5 | 3577 | struct bound_minimal_symbol m; |
17450429 PP |
3578 | |
3579 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3580 | if (m.minsym == NULL) |
17450429 PP |
3581 | { |
3582 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3583 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3584 | continue; |
3585 | } | |
3586 | bp_objfile_data->longjmp_msym[i] = m; | |
3587 | } | |
3588 | ||
77e371c0 | 3589 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3590 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3591 | &internal_breakpoint_ops); | |
67994074 KS |
3592 | initialize_explicit_location (&explicit_loc); |
3593 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3594 | b->location = new_explicit_location (&explicit_loc); |
af02033e PP |
3595 | b->enable_state = bp_disabled; |
3596 | } | |
0fd8e87f | 3597 | } |
af02033e | 3598 | } |
6c95b8df PA |
3599 | |
3600 | do_cleanups (old_chain); | |
0fd8e87f UW |
3601 | } |
3602 | ||
af02033e | 3603 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3604 | static void |
af02033e | 3605 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3606 | { |
3607 | struct program_space *pspace; | |
aa7d318d | 3608 | struct cleanup *old_chain; |
af02033e | 3609 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3610 | |
3611 | old_chain = save_current_program_space (); | |
3612 | ||
3613 | ALL_PSPACES (pspace) | |
17450429 PP |
3614 | { |
3615 | struct objfile *objfile; | |
3616 | CORE_ADDR addr; | |
3617 | ||
3618 | set_current_program_space (pspace); | |
3619 | ||
aa7d318d TT |
3620 | ALL_OBJFILES (objfile) |
3621 | { | |
3622 | struct breakpoint *b; | |
17450429 | 3623 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3624 | struct explicit_location explicit_loc; |
aa7d318d | 3625 | |
17450429 | 3626 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3627 | |
3b7344d5 | 3628 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3629 | continue; |
3630 | ||
3b7344d5 | 3631 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3632 | { |
3b7344d5 | 3633 | struct bound_minimal_symbol m; |
17450429 PP |
3634 | |
3635 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3636 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3637 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3638 | { |
3639 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3640 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3641 | continue; |
3642 | } | |
3643 | bp_objfile_data->terminate_msym = m; | |
3644 | } | |
aa7d318d | 3645 | |
77e371c0 | 3646 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3647 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3648 | bp_std_terminate_master, |
3649 | &internal_breakpoint_ops); | |
67994074 KS |
3650 | initialize_explicit_location (&explicit_loc); |
3651 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3652 | b->location = new_explicit_location (&explicit_loc); |
aa7d318d TT |
3653 | b->enable_state = bp_disabled; |
3654 | } | |
17450429 PP |
3655 | } |
3656 | ||
aa7d318d TT |
3657 | do_cleanups (old_chain); |
3658 | } | |
3659 | ||
186c406b TT |
3660 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3661 | ||
70221824 | 3662 | static void |
186c406b TT |
3663 | create_exception_master_breakpoint (void) |
3664 | { | |
3665 | struct objfile *objfile; | |
17450429 | 3666 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3667 | |
3668 | ALL_OBJFILES (objfile) | |
3669 | { | |
17450429 PP |
3670 | struct breakpoint *b; |
3671 | struct gdbarch *gdbarch; | |
3672 | struct breakpoint_objfile_data *bp_objfile_data; | |
3673 | CORE_ADDR addr; | |
67994074 | 3674 | struct explicit_location explicit_loc; |
17450429 PP |
3675 | |
3676 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3677 | ||
28106bc2 SDJ |
3678 | /* We prefer the SystemTap probe point if it exists. */ |
3679 | if (!bp_objfile_data->exception_searched) | |
3680 | { | |
25f9533e SDJ |
3681 | VEC (probe_p) *ret; |
3682 | ||
3683 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3684 | ||
3685 | if (ret != NULL) | |
3686 | { | |
3687 | /* We are only interested in checking one element. */ | |
3688 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3689 | ||
3690 | if (!can_evaluate_probe_arguments (p)) | |
3691 | { | |
3692 | /* We cannot use the probe interface here, because it does | |
3693 | not know how to evaluate arguments. */ | |
3694 | VEC_free (probe_p, ret); | |
3695 | ret = NULL; | |
3696 | } | |
3697 | } | |
3698 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3699 | bp_objfile_data->exception_searched = 1; |
3700 | } | |
3701 | ||
3702 | if (bp_objfile_data->exception_probes != NULL) | |
3703 | { | |
3704 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3705 | int i; | |
3706 | struct probe *probe; | |
3707 | ||
3708 | for (i = 0; | |
3709 | VEC_iterate (probe_p, | |
3710 | bp_objfile_data->exception_probes, | |
3711 | i, probe); | |
3712 | ++i) | |
3713 | { | |
3714 | struct breakpoint *b; | |
3715 | ||
729662a5 TT |
3716 | b = create_internal_breakpoint (gdbarch, |
3717 | get_probe_address (probe, | |
3718 | objfile), | |
28106bc2 SDJ |
3719 | bp_exception_master, |
3720 | &internal_breakpoint_ops); | |
d28cd78a | 3721 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3722 | b->enable_state = bp_disabled; |
3723 | } | |
3724 | ||
3725 | continue; | |
3726 | } | |
3727 | ||
3728 | /* Otherwise, try the hook function. */ | |
3729 | ||
3b7344d5 | 3730 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3731 | continue; |
3732 | ||
3733 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3734 | |
3b7344d5 | 3735 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3736 | { |
3b7344d5 | 3737 | struct bound_minimal_symbol debug_hook; |
186c406b | 3738 | |
17450429 | 3739 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3740 | if (debug_hook.minsym == NULL) |
17450429 | 3741 | { |
3b7344d5 | 3742 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3743 | continue; |
3744 | } | |
3745 | ||
3746 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3747 | } |
17450429 | 3748 | |
77e371c0 | 3749 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3750 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3751 | ¤t_target); | |
06edf0c0 PA |
3752 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3753 | &internal_breakpoint_ops); | |
67994074 KS |
3754 | initialize_explicit_location (&explicit_loc); |
3755 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3756 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3757 | b->enable_state = bp_disabled; |
186c406b | 3758 | } |
186c406b TT |
3759 | } |
3760 | ||
9ef9e6a6 KS |
3761 | /* Does B have a location spec? */ |
3762 | ||
3763 | static int | |
3764 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3765 | { | |
d28cd78a | 3766 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3767 | } |
3768 | ||
c906108c | 3769 | void |
fba45db2 | 3770 | update_breakpoints_after_exec (void) |
c906108c | 3771 | { |
35df4500 | 3772 | struct breakpoint *b, *b_tmp; |
876fa593 | 3773 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3774 | |
25b22b0a PA |
3775 | /* We're about to delete breakpoints from GDB's lists. If the |
3776 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3777 | writing the breakpoints' "shadow contents" back into memory. The | |
3778 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3779 | do that. Instead, the target is responsible from marking | |
3780 | breakpoints out as soon as it detects an exec. We don't do that | |
3781 | here instead, because there may be other attempts to delete | |
3782 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3783 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3784 | if (bploc->pspace == current_program_space) |
3785 | gdb_assert (!bploc->inserted); | |
c906108c | 3786 | |
35df4500 | 3787 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3788 | { |
6c95b8df PA |
3789 | if (b->pspace != current_program_space) |
3790 | continue; | |
3791 | ||
4a64f543 | 3792 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3793 | if (b->type == bp_shlib_event) |
3794 | { | |
3795 | delete_breakpoint (b); | |
3796 | continue; | |
3797 | } | |
c906108c | 3798 | |
4a64f543 | 3799 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3800 | if (b->type == bp_jit_event) |
3801 | { | |
3802 | delete_breakpoint (b); | |
3803 | continue; | |
3804 | } | |
3805 | ||
1900040c | 3806 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3807 | as must overlay event and longjmp master breakpoints. */ |
3808 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3809 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3810 | || b->type == bp_exception_master) | |
c4093a6a JM |
3811 | { |
3812 | delete_breakpoint (b); | |
3813 | continue; | |
3814 | } | |
3815 | ||
4a64f543 | 3816 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3817 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3818 | { |
3819 | delete_breakpoint (b); | |
3820 | continue; | |
3821 | } | |
3822 | ||
7c16b83e PA |
3823 | /* Just like single-step breakpoints. */ |
3824 | if (b->type == bp_single_step) | |
3825 | { | |
3826 | delete_breakpoint (b); | |
3827 | continue; | |
3828 | } | |
3829 | ||
611c83ae PA |
3830 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3831 | after an exec. */ | |
186c406b | 3832 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3833 | || b->type == bp_longjmp_call_dummy |
186c406b | 3834 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3835 | { |
3836 | delete_breakpoint (b); | |
3837 | continue; | |
3838 | } | |
3839 | ||
ce78b96d JB |
3840 | if (b->type == bp_catchpoint) |
3841 | { | |
3842 | /* For now, none of the bp_catchpoint breakpoints need to | |
3843 | do anything at this point. In the future, if some of | |
3844 | the catchpoints need to something, we will need to add | |
3845 | a new method, and call this method from here. */ | |
3846 | continue; | |
3847 | } | |
3848 | ||
c5aa993b JM |
3849 | /* bp_finish is a special case. The only way we ought to be able |
3850 | to see one of these when an exec() has happened, is if the user | |
3851 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3852 | carries them to the call-site of the current callee, by setting | |
3853 | a temporary bp there and resuming. But in this case, the finish | |
3854 | will carry them entirely through the vfork & exec. | |
3855 | ||
3856 | We don't want to allow a bp_finish to remain inserted now. But | |
3857 | we can't safely delete it, 'cause finish_command has a handle to | |
3858 | the bp on a bpstat, and will later want to delete it. There's a | |
3859 | chance (and I've seen it happen) that if we delete the bp_finish | |
3860 | here, that its storage will get reused by the time finish_command | |
3861 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3862 | We really must allow finish_command to delete a bp_finish. | |
3863 | ||
e5dd4106 | 3864 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3865 | it's safe to delete something others may have handles to?" |
3866 | problem, what we'll do here is just uninsert the bp_finish, and | |
3867 | let finish_command delete it. | |
3868 | ||
3869 | (We know the bp_finish is "doomed" in the sense that it's | |
3870 | momentary, and will be deleted as soon as finish_command sees | |
3871 | the inferior stopped. So it doesn't matter that the bp's | |
3872 | address is probably bogus in the new a.out, unlike e.g., the | |
3873 | solib breakpoints.) */ | |
c5aa993b | 3874 | |
c5aa993b JM |
3875 | if (b->type == bp_finish) |
3876 | { | |
3877 | continue; | |
3878 | } | |
3879 | ||
3880 | /* Without a symbolic address, we have little hope of the | |
3881 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3882 | a.out. */ |
9ef9e6a6 | 3883 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3884 | { |
3885 | delete_breakpoint (b); | |
3886 | continue; | |
3887 | } | |
c5aa993b | 3888 | } |
c906108c SS |
3889 | } |
3890 | ||
3891 | int | |
d80ee84f | 3892 | detach_breakpoints (ptid_t ptid) |
c906108c | 3893 | { |
35df4500 | 3894 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3895 | int val = 0; |
ce696e05 | 3896 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3897 | struct inferior *inf = current_inferior (); |
c5aa993b | 3898 | |
dfd4cc63 | 3899 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3900 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3901 | |
6c95b8df | 3902 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3903 | inferior_ptid = ptid; |
35df4500 | 3904 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3905 | { |
35df4500 | 3906 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3907 | continue; |
3908 | ||
bd9673a4 PW |
3909 | /* This function must physically remove breakpoints locations |
3910 | from the specified ptid, without modifying the breakpoint | |
3911 | package's state. Locations of type bp_loc_other are only | |
3912 | maintained at GDB side. So, there is no need to remove | |
3913 | these bp_loc_other locations. Moreover, removing these | |
3914 | would modify the breakpoint package's state. */ | |
3915 | if (bl->loc_type == bp_loc_other) | |
3916 | continue; | |
3917 | ||
35df4500 | 3918 | if (bl->inserted) |
b2b6a7da | 3919 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3920 | } |
d03285ec | 3921 | |
ce696e05 | 3922 | do_cleanups (old_chain); |
3a1bae8e | 3923 | return val; |
c906108c SS |
3924 | } |
3925 | ||
35df4500 | 3926 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3927 | Note that this is used to detach breakpoints from a child fork. |
3928 | When we get here, the child isn't in the inferior list, and neither | |
3929 | do we have objects to represent its address space --- we should | |
35df4500 | 3930 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3931 | |
c906108c | 3932 | static int |
b2b6a7da | 3933 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3934 | { |
3935 | int val; | |
c5aa993b | 3936 | |
35df4500 TJB |
3937 | /* BL is never in moribund_locations by our callers. */ |
3938 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3939 | |
74960c60 VP |
3940 | /* The type of none suggests that owner is actually deleted. |
3941 | This should not ever happen. */ | |
35df4500 | 3942 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3943 | |
35df4500 TJB |
3944 | if (bl->loc_type == bp_loc_software_breakpoint |
3945 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3946 | { |
c02f5703 MS |
3947 | /* "Normal" instruction breakpoint: either the standard |
3948 | trap-instruction bp (bp_breakpoint), or a | |
3949 | bp_hardware_breakpoint. */ | |
3950 | ||
3951 | /* First check to see if we have to handle an overlay. */ | |
3952 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3953 | || bl->section == NULL |
3954 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3955 | { |
3956 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3957 | |
3958 | /* If we're trying to uninsert a memory breakpoint that we | |
3959 | know is set in a dynamic object that is marked | |
3960 | shlib_disabled, then either the dynamic object was | |
3961 | removed with "remove-symbol-file" or with | |
3962 | "nosharedlibrary". In the former case, we don't know | |
3963 | whether another dynamic object might have loaded over the | |
3964 | breakpoint's address -- the user might well let us know | |
3965 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3966 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3967 | list of dynamically loaded objects). If we have the |
3968 | breakpoint's shadow memory, that is, this is a software | |
3969 | breakpoint managed by GDB, check whether the breakpoint | |
3970 | is still inserted in memory, to avoid overwriting wrong | |
3971 | code with stale saved shadow contents. Note that HW | |
3972 | breakpoints don't have shadow memory, as they're | |
3973 | implemented using a mechanism that is not dependent on | |
3974 | being able to modify the target's memory, and as such | |
3975 | they should always be removed. */ | |
3976 | if (bl->shlib_disabled | |
3977 | && bl->target_info.shadow_len != 0 | |
3978 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3979 | val = 0; | |
3980 | else | |
73971819 | 3981 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3982 | } |
c906108c SS |
3983 | else |
3984 | { | |
4a64f543 | 3985 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3986 | Did we set a breakpoint at the LMA? */ |
3987 | if (!overlay_events_enabled) | |
3988 | { | |
3989 | /* Yes -- overlay event support is not active, so we | |
3990 | should have set a breakpoint at the LMA. Remove it. | |
3991 | */ | |
c02f5703 MS |
3992 | /* Ignore any failures: if the LMA is in ROM, we will |
3993 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3994 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3995 | target_remove_hw_breakpoint (bl->gdbarch, | |
3996 | &bl->overlay_target_info); | |
c02f5703 | 3997 | else |
35df4500 | 3998 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3999 | &bl->overlay_target_info, |
4000 | reason); | |
c02f5703 MS |
4001 | } |
4002 | /* Did we set a breakpoint at the VMA? | |
4003 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4004 | if (bl->inserted) |
c906108c | 4005 | { |
c02f5703 MS |
4006 | /* Yes -- remove it. Previously we did not bother to |
4007 | remove the breakpoint if the section had been | |
4008 | unmapped, but let's not rely on that being safe. We | |
4009 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4010 | |
4011 | /* However, we should remove *software* breakpoints only | |
4012 | if the section is still mapped, or else we overwrite | |
4013 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4014 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4015 | || section_is_mapped (bl->section)) | |
73971819 | 4016 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
4017 | else |
4018 | val = 0; | |
c906108c | 4019 | } |
c02f5703 MS |
4020 | else |
4021 | { | |
4022 | /* No -- not inserted, so no need to remove. No error. */ | |
4023 | val = 0; | |
4024 | } | |
c906108c | 4025 | } |
879d1e6b | 4026 | |
08351840 PA |
4027 | /* In some cases, we might not be able to remove a breakpoint in |
4028 | a shared library that has already been removed, but we have | |
4029 | not yet processed the shlib unload event. Similarly for an | |
4030 | unloaded add-symbol-file object - the user might not yet have | |
4031 | had the chance to remove-symbol-file it. shlib_disabled will | |
4032 | be set if the library/object has already been removed, but | |
4033 | the breakpoint hasn't been uninserted yet, e.g., after | |
4034 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4035 | always-inserted mode. */ | |
076855f9 | 4036 | if (val |
08351840 PA |
4037 | && (bl->loc_type == bp_loc_software_breakpoint |
4038 | && (bl->shlib_disabled | |
4039 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4040 | || shared_objfile_contains_address_p (bl->pspace, |
4041 | bl->address)))) | |
879d1e6b UW |
4042 | val = 0; |
4043 | ||
c906108c SS |
4044 | if (val) |
4045 | return val; | |
b2b6a7da | 4046 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 4047 | } |
35df4500 | 4048 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4049 | { |
77b06cd7 TJB |
4050 | gdb_assert (bl->owner->ops != NULL |
4051 | && bl->owner->ops->remove_location != NULL); | |
4052 | ||
b2b6a7da | 4053 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 4054 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 4055 | |
c906108c | 4056 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 4057 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 4058 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4059 | bl->owner->number); |
c906108c | 4060 | } |
35df4500 TJB |
4061 | else if (bl->owner->type == bp_catchpoint |
4062 | && breakpoint_enabled (bl->owner) | |
4063 | && !bl->duplicate) | |
ce78b96d | 4064 | { |
77b06cd7 TJB |
4065 | gdb_assert (bl->owner->ops != NULL |
4066 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4067 | |
73971819 | 4068 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
4069 | if (val) |
4070 | return val; | |
77b06cd7 | 4071 | |
b2b6a7da | 4072 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 4073 | } |
c906108c SS |
4074 | |
4075 | return 0; | |
4076 | } | |
4077 | ||
6c95b8df | 4078 | static int |
834c0d03 | 4079 | remove_breakpoint (struct bp_location *bl) |
6c95b8df PA |
4080 | { |
4081 | int ret; | |
4082 | struct cleanup *old_chain; | |
4083 | ||
35df4500 TJB |
4084 | /* BL is never in moribund_locations by our callers. */ |
4085 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4086 | |
6c95b8df PA |
4087 | /* The type of none suggests that owner is actually deleted. |
4088 | This should not ever happen. */ | |
35df4500 | 4089 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4090 | |
4091 | old_chain = save_current_space_and_thread (); | |
4092 | ||
35df4500 | 4093 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4094 | |
b2b6a7da | 4095 | ret = remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4096 | |
4097 | do_cleanups (old_chain); | |
4098 | return ret; | |
4099 | } | |
4100 | ||
c906108c SS |
4101 | /* Clear the "inserted" flag in all breakpoints. */ |
4102 | ||
25b22b0a | 4103 | void |
fba45db2 | 4104 | mark_breakpoints_out (void) |
c906108c | 4105 | { |
35df4500 | 4106 | struct bp_location *bl, **blp_tmp; |
c906108c | 4107 | |
35df4500 | 4108 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4109 | if (bl->pspace == current_program_space) |
35df4500 | 4110 | bl->inserted = 0; |
c906108c SS |
4111 | } |
4112 | ||
53a5351d JM |
4113 | /* Clear the "inserted" flag in all breakpoints and delete any |
4114 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4115 | |
4116 | Plus other such housekeeping that has to be done for breakpoints | |
4117 | between runs. | |
4118 | ||
53a5351d JM |
4119 | Note: this function gets called at the end of a run (by |
4120 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4121 | init_wait_for_inferior). */ |
c906108c SS |
4122 | |
4123 | ||
4124 | ||
4125 | void | |
fba45db2 | 4126 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4127 | { |
35df4500 | 4128 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4129 | struct bp_location *bl; |
1c5cfe86 | 4130 | int ix; |
6c95b8df | 4131 | struct program_space *pspace = current_program_space; |
c906108c | 4132 | |
50c71eaf PA |
4133 | /* If breakpoint locations are shared across processes, then there's |
4134 | nothing to do. */ | |
f5656ead | 4135 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4136 | return; |
4137 | ||
1a853c52 | 4138 | mark_breakpoints_out (); |
075f6582 | 4139 | |
35df4500 | 4140 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4141 | { |
6c95b8df PA |
4142 | if (b->loc && b->loc->pspace != pspace) |
4143 | continue; | |
4144 | ||
c5aa993b JM |
4145 | switch (b->type) |
4146 | { | |
4147 | case bp_call_dummy: | |
e2e4d78b | 4148 | case bp_longjmp_call_dummy: |
c906108c | 4149 | |
c5aa993b | 4150 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4151 | cause problems when the inferior is rerun, so we better get |
4152 | rid of it. */ | |
4153 | ||
4154 | case bp_watchpoint_scope: | |
4155 | ||
4156 | /* Also get rid of scope breakpoints. */ | |
4157 | ||
4158 | case bp_shlib_event: | |
4159 | ||
4160 | /* Also remove solib event breakpoints. Their addresses may | |
4161 | have changed since the last time we ran the program. | |
4162 | Actually we may now be debugging against different target; | |
4163 | and so the solib backend that installed this breakpoint may | |
4164 | not be used in by the target. E.g., | |
4165 | ||
4166 | (gdb) file prog-linux | |
4167 | (gdb) run # native linux target | |
4168 | ... | |
4169 | (gdb) kill | |
4170 | (gdb) file prog-win.exe | |
4171 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4172 | */ | |
c906108c | 4173 | |
f59f708a PA |
4174 | case bp_step_resume: |
4175 | ||
4176 | /* Also remove step-resume breakpoints. */ | |
4177 | ||
7c16b83e PA |
4178 | case bp_single_step: |
4179 | ||
4180 | /* Also remove single-step breakpoints. */ | |
4181 | ||
c5aa993b JM |
4182 | delete_breakpoint (b); |
4183 | break; | |
c906108c | 4184 | |
c5aa993b JM |
4185 | case bp_watchpoint: |
4186 | case bp_hardware_watchpoint: | |
4187 | case bp_read_watchpoint: | |
4188 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4189 | { |
4190 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4191 | |
3a5c3e22 PA |
4192 | /* Likewise for watchpoints on local expressions. */ |
4193 | if (w->exp_valid_block != NULL) | |
4194 | delete_breakpoint (b); | |
63000888 | 4195 | else |
3a5c3e22 | 4196 | { |
63000888 PA |
4197 | /* Get rid of existing locations, which are no longer |
4198 | valid. New ones will be created in | |
4199 | update_watchpoint, when the inferior is restarted. | |
4200 | The next update_global_location_list call will | |
4201 | garbage collect them. */ | |
4202 | b->loc = NULL; | |
4203 | ||
4204 | if (context == inf_starting) | |
4205 | { | |
4206 | /* Reset val field to force reread of starting value in | |
4207 | insert_breakpoints. */ | |
4208 | if (w->val) | |
4209 | value_free (w->val); | |
4210 | w->val = NULL; | |
4211 | w->val_valid = 0; | |
4212 | } | |
4213 | } | |
3a5c3e22 | 4214 | } |
c5aa993b JM |
4215 | break; |
4216 | default: | |
c5aa993b JM |
4217 | break; |
4218 | } | |
4219 | } | |
1c5cfe86 PA |
4220 | |
4221 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4222 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4223 | decref_bp_location (&bl); | |
1c5cfe86 | 4224 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4225 | } |
4226 | ||
6c95b8df PA |
4227 | /* These functions concern about actual breakpoints inserted in the |
4228 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4229 | we need to hop over the bkpt --- so we check for address space | |
4230 | match, not program space. */ | |
4231 | ||
c2c6d25f JM |
4232 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4233 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4234 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4235 | permanent breakpoint. | |
4236 | - When continuing from a location with an ordinary breakpoint, we | |
4237 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4238 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4239 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4240 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4241 | |
c2c6d25f | 4242 | enum breakpoint_here |
6c95b8df | 4243 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4244 | { |
35df4500 | 4245 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4246 | int any_breakpoint_here = 0; |
c906108c | 4247 | |
35df4500 | 4248 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4249 | { |
35df4500 TJB |
4250 | if (bl->loc_type != bp_loc_software_breakpoint |
4251 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4252 | continue; |
4253 | ||
f1310107 | 4254 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4255 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4256 | || bl->permanent) |
f1310107 | 4257 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4258 | { |
4259 | if (overlay_debugging | |
35df4500 TJB |
4260 | && section_is_overlay (bl->section) |
4261 | && !section_is_mapped (bl->section)) | |
075f6582 | 4262 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4263 | else if (bl->permanent) |
075f6582 DJ |
4264 | return permanent_breakpoint_here; |
4265 | else | |
4266 | any_breakpoint_here = 1; | |
4267 | } | |
4268 | } | |
c906108c | 4269 | |
f486487f | 4270 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4271 | } |
4272 | ||
d35ae833 PA |
4273 | /* See breakpoint.h. */ |
4274 | ||
4275 | int | |
4276 | breakpoint_in_range_p (struct address_space *aspace, | |
4277 | CORE_ADDR addr, ULONGEST len) | |
4278 | { | |
4279 | struct bp_location *bl, **blp_tmp; | |
4280 | ||
4281 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4282 | { | |
4283 | if (bl->loc_type != bp_loc_software_breakpoint | |
4284 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4285 | continue; | |
4286 | ||
4287 | if ((breakpoint_enabled (bl->owner) | |
4288 | || bl->permanent) | |
4289 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4290 | addr, len)) | |
4291 | { | |
4292 | if (overlay_debugging | |
4293 | && section_is_overlay (bl->section) | |
4294 | && !section_is_mapped (bl->section)) | |
4295 | { | |
4296 | /* Unmapped overlay -- can't be a match. */ | |
4297 | continue; | |
4298 | } | |
4299 | ||
4300 | return 1; | |
4301 | } | |
4302 | } | |
4303 | ||
4304 | return 0; | |
4305 | } | |
4306 | ||
1c5cfe86 PA |
4307 | /* Return true if there's a moribund breakpoint at PC. */ |
4308 | ||
4309 | int | |
6c95b8df | 4310 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4311 | { |
4312 | struct bp_location *loc; | |
4313 | int ix; | |
4314 | ||
4315 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4316 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4317 | return 1; |
4318 | ||
4319 | return 0; | |
4320 | } | |
c2c6d25f | 4321 | |
f7ce857f PA |
4322 | /* Returns non-zero iff BL is inserted at PC, in address space |
4323 | ASPACE. */ | |
4324 | ||
4325 | static int | |
4326 | bp_location_inserted_here_p (struct bp_location *bl, | |
4327 | struct address_space *aspace, CORE_ADDR pc) | |
4328 | { | |
4329 | if (bl->inserted | |
4330 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4331 | aspace, pc)) | |
4332 | { | |
4333 | if (overlay_debugging | |
4334 | && section_is_overlay (bl->section) | |
4335 | && !section_is_mapped (bl->section)) | |
4336 | return 0; /* unmapped overlay -- can't be a match */ | |
4337 | else | |
4338 | return 1; | |
4339 | } | |
4340 | return 0; | |
4341 | } | |
4342 | ||
a1fd2fa5 | 4343 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4344 | |
4345 | int | |
a1fd2fa5 | 4346 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4347 | { |
f7ce857f | 4348 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4349 | |
f7ce857f | 4350 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4351 | { |
f7ce857f PA |
4352 | struct bp_location *bl = *blp; |
4353 | ||
35df4500 TJB |
4354 | if (bl->loc_type != bp_loc_software_breakpoint |
4355 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4356 | continue; |
4357 | ||
f7ce857f PA |
4358 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4359 | return 1; | |
c5aa993b | 4360 | } |
c36b740a VP |
4361 | return 0; |
4362 | } | |
4363 | ||
a1fd2fa5 PA |
4364 | /* This function returns non-zero iff there is a software breakpoint |
4365 | inserted at PC. */ | |
c36b740a VP |
4366 | |
4367 | int | |
a1fd2fa5 PA |
4368 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4369 | CORE_ADDR pc) | |
4fa8626c | 4370 | { |
f7ce857f | 4371 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4372 | |
f7ce857f | 4373 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4374 | { |
f7ce857f PA |
4375 | struct bp_location *bl = *blp; |
4376 | ||
35df4500 | 4377 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4378 | continue; |
4379 | ||
f7ce857f PA |
4380 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4381 | return 1; | |
4fa8626c DJ |
4382 | } |
4383 | ||
4384 | return 0; | |
9c02b525 PA |
4385 | } |
4386 | ||
4387 | /* See breakpoint.h. */ | |
4388 | ||
4389 | int | |
4390 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4391 | CORE_ADDR pc) | |
4392 | { | |
4393 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4394 | |
4395 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4396 | { | |
4397 | struct bp_location *bl = *blp; | |
4398 | ||
4399 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4400 | continue; | |
4401 | ||
4402 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4403 | return 1; | |
4404 | } | |
4405 | ||
4406 | return 0; | |
4fa8626c DJ |
4407 | } |
4408 | ||
9093389c PA |
4409 | int |
4410 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4411 | CORE_ADDR addr, ULONGEST len) | |
4412 | { | |
4413 | struct breakpoint *bpt; | |
4414 | ||
4415 | ALL_BREAKPOINTS (bpt) | |
4416 | { | |
4417 | struct bp_location *loc; | |
4418 | ||
4419 | if (bpt->type != bp_hardware_watchpoint | |
4420 | && bpt->type != bp_access_watchpoint) | |
4421 | continue; | |
4422 | ||
4423 | if (!breakpoint_enabled (bpt)) | |
4424 | continue; | |
4425 | ||
4426 | for (loc = bpt->loc; loc; loc = loc->next) | |
4427 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4428 | { | |
4429 | CORE_ADDR l, h; | |
4430 | ||
4431 | /* Check for intersection. */ | |
768adc05 PA |
4432 | l = std::max<CORE_ADDR> (loc->address, addr); |
4433 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4434 | if (l < h) |
4435 | return 1; | |
4436 | } | |
4437 | } | |
4438 | return 0; | |
4439 | } | |
c906108c | 4440 | \f |
c5aa993b | 4441 | |
c906108c SS |
4442 | /* bpstat stuff. External routines' interfaces are documented |
4443 | in breakpoint.h. */ | |
4444 | ||
4445 | int | |
c326b90e | 4446 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4447 | { |
533be4dd | 4448 | return (ep->type == bp_catchpoint); |
c906108c SS |
4449 | } |
4450 | ||
f431efe5 PA |
4451 | /* Frees any storage that is part of a bpstat. Does not walk the |
4452 | 'next' chain. */ | |
4453 | ||
4454 | static void | |
198757a8 VP |
4455 | bpstat_free (bpstat bs) |
4456 | { | |
4457 | if (bs->old_val != NULL) | |
4458 | value_free (bs->old_val); | |
9add0f1b | 4459 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4460 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4461 | xfree (bs); |
4462 | } | |
4463 | ||
c906108c SS |
4464 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4465 | Also free any storage that is part of a bpstat. */ | |
4466 | ||
4467 | void | |
fba45db2 | 4468 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4469 | { |
4470 | bpstat p; | |
4471 | bpstat q; | |
4472 | ||
4473 | if (bsp == 0) | |
4474 | return; | |
4475 | p = *bsp; | |
4476 | while (p != NULL) | |
4477 | { | |
4478 | q = p->next; | |
198757a8 | 4479 | bpstat_free (p); |
c906108c SS |
4480 | p = q; |
4481 | } | |
4482 | *bsp = NULL; | |
4483 | } | |
4484 | ||
4485 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4486 | is part of the bpstat is copied as well. */ | |
4487 | ||
4488 | bpstat | |
fba45db2 | 4489 | bpstat_copy (bpstat bs) |
c906108c SS |
4490 | { |
4491 | bpstat p = NULL; | |
4492 | bpstat tmp; | |
4493 | bpstat retval = NULL; | |
4494 | ||
4495 | if (bs == NULL) | |
4496 | return bs; | |
4497 | ||
4498 | for (; bs != NULL; bs = bs->next) | |
4499 | { | |
4500 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4501 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4502 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4503 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4504 | if (bs->old_val != NULL) |
3c3185ac JK |
4505 | { |
4506 | tmp->old_val = value_copy (bs->old_val); | |
4507 | release_value (tmp->old_val); | |
4508 | } | |
31cc81e9 | 4509 | |
c906108c SS |
4510 | if (p == NULL) |
4511 | /* This is the first thing in the chain. */ | |
4512 | retval = tmp; | |
4513 | else | |
4514 | p->next = tmp; | |
4515 | p = tmp; | |
4516 | } | |
4517 | p->next = NULL; | |
4518 | return retval; | |
4519 | } | |
4520 | ||
4a64f543 | 4521 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4522 | |
4523 | bpstat | |
fba45db2 | 4524 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4525 | { |
c5aa993b JM |
4526 | if (bsp == NULL) |
4527 | return NULL; | |
c906108c | 4528 | |
c5aa993b JM |
4529 | for (; bsp != NULL; bsp = bsp->next) |
4530 | { | |
f431efe5 | 4531 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4532 | return bsp; |
4533 | } | |
c906108c SS |
4534 | return NULL; |
4535 | } | |
4536 | ||
ab04a2af TT |
4537 | /* See breakpoint.h. */ |
4538 | ||
47591c29 | 4539 | int |
427cd150 | 4540 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4541 | { |
ab04a2af TT |
4542 | for (; bsp != NULL; bsp = bsp->next) |
4543 | { | |
427cd150 TT |
4544 | if (bsp->breakpoint_at == NULL) |
4545 | { | |
4546 | /* A moribund location can never explain a signal other than | |
4547 | GDB_SIGNAL_TRAP. */ | |
4548 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4549 | return 1; |
427cd150 TT |
4550 | } |
4551 | else | |
47591c29 PA |
4552 | { |
4553 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4554 | sig)) | |
4555 | return 1; | |
4556 | } | |
ab04a2af TT |
4557 | } |
4558 | ||
47591c29 | 4559 | return 0; |
ab04a2af TT |
4560 | } |
4561 | ||
4a64f543 MS |
4562 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4563 | stopped at. *BSP upon return is a bpstat which points to the | |
4564 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4565 | good for anything but further calls to bpstat_num). | |
4566 | ||
8671a17b PA |
4567 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4568 | Return -1 if stopped at a breakpoint that has been deleted since | |
4569 | we set it. | |
4570 | Return 1 otherwise. */ | |
c906108c SS |
4571 | |
4572 | int | |
8671a17b | 4573 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4574 | { |
4575 | struct breakpoint *b; | |
4576 | ||
4577 | if ((*bsp) == NULL) | |
4578 | return 0; /* No more breakpoint values */ | |
8671a17b | 4579 | |
4a64f543 MS |
4580 | /* We assume we'll never have several bpstats that correspond to a |
4581 | single breakpoint -- otherwise, this function might return the | |
4582 | same number more than once and this will look ugly. */ | |
f431efe5 | 4583 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4584 | *bsp = (*bsp)->next; |
4585 | if (b == NULL) | |
4586 | return -1; /* breakpoint that's been deleted since */ | |
4587 | ||
4588 | *num = b->number; /* We have its number */ | |
4589 | return 1; | |
c906108c SS |
4590 | } |
4591 | ||
e93ca019 | 4592 | /* See breakpoint.h. */ |
c906108c SS |
4593 | |
4594 | void | |
e93ca019 | 4595 | bpstat_clear_actions (void) |
c906108c | 4596 | { |
e93ca019 JK |
4597 | struct thread_info *tp; |
4598 | bpstat bs; | |
4599 | ||
4600 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4601 | return; | |
4602 | ||
4603 | tp = find_thread_ptid (inferior_ptid); | |
4604 | if (tp == NULL) | |
4605 | return; | |
4606 | ||
4607 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4608 | { |
9add0f1b | 4609 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4610 | |
c906108c SS |
4611 | if (bs->old_val != NULL) |
4612 | { | |
4613 | value_free (bs->old_val); | |
4614 | bs->old_val = NULL; | |
4615 | } | |
4616 | } | |
4617 | } | |
4618 | ||
f3b1572e PA |
4619 | /* Called when a command is about to proceed the inferior. */ |
4620 | ||
4621 | static void | |
4622 | breakpoint_about_to_proceed (void) | |
4623 | { | |
4624 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4625 | { | |
4626 | struct thread_info *tp = inferior_thread (); | |
4627 | ||
4628 | /* Allow inferior function calls in breakpoint commands to not | |
4629 | interrupt the command list. When the call finishes | |
4630 | successfully, the inferior will be standing at the same | |
4631 | breakpoint as if nothing happened. */ | |
16c381f0 | 4632 | if (tp->control.in_infcall) |
f3b1572e PA |
4633 | return; |
4634 | } | |
4635 | ||
4636 | breakpoint_proceeded = 1; | |
4637 | } | |
4638 | ||
4a64f543 MS |
4639 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4640 | command. */ | |
c906108c | 4641 | static void |
4efb68b1 | 4642 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4643 | { |
4644 | executing_breakpoint_commands = 0; | |
4645 | } | |
4646 | ||
abf85f46 JK |
4647 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4648 | or its equivalent. */ | |
4649 | ||
4650 | static int | |
4651 | command_line_is_silent (struct command_line *cmd) | |
4652 | { | |
4f45d445 | 4653 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4654 | } |
4655 | ||
4a64f543 MS |
4656 | /* Execute all the commands associated with all the breakpoints at |
4657 | this location. Any of these commands could cause the process to | |
4658 | proceed beyond this point, etc. We look out for such changes by | |
4659 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4660 | |
347bddb7 PA |
4661 | Returns true if a breakpoint command resumed the inferior. In that |
4662 | case, it is the caller's responsibility to recall it again with the | |
4663 | bpstat of the current thread. */ | |
4664 | ||
4665 | static int | |
4666 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4667 | { |
4668 | bpstat bs; | |
4669 | struct cleanup *old_chain; | |
347bddb7 | 4670 | int again = 0; |
c906108c SS |
4671 | |
4672 | /* Avoid endless recursion if a `source' command is contained | |
4673 | in bs->commands. */ | |
4674 | if (executing_breakpoint_commands) | |
347bddb7 | 4675 | return 0; |
c906108c SS |
4676 | |
4677 | executing_breakpoint_commands = 1; | |
4678 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4679 | ||
1ac32117 | 4680 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4681 | |
4a64f543 | 4682 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4683 | bs = *bsp; |
4684 | ||
4685 | breakpoint_proceeded = 0; | |
4686 | for (; bs != NULL; bs = bs->next) | |
4687 | { | |
9add0f1b | 4688 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4689 | struct command_line *cmd; |
4690 | struct cleanup *this_cmd_tree_chain; | |
4691 | ||
4692 | /* Take ownership of the BSP's command tree, if it has one. | |
4693 | ||
4694 | The command tree could legitimately contain commands like | |
4695 | 'step' and 'next', which call clear_proceed_status, which | |
4696 | frees stop_bpstat's command tree. To make sure this doesn't | |
4697 | free the tree we're executing out from under us, we need to | |
4698 | take ownership of the tree ourselves. Since a given bpstat's | |
4699 | commands are only executed once, we don't need to copy it; we | |
4700 | can clear the pointer in the bpstat, and make sure we free | |
4701 | the tree when we're done. */ | |
9add0f1b TT |
4702 | ccmd = bs->commands; |
4703 | bs->commands = NULL; | |
abf85f46 JK |
4704 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4705 | cmd = ccmd ? ccmd->commands : NULL; | |
4706 | if (command_line_is_silent (cmd)) | |
4707 | { | |
4708 | /* The action has been already done by bpstat_stop_status. */ | |
4709 | cmd = cmd->next; | |
4710 | } | |
6c50ab1c | 4711 | |
c906108c SS |
4712 | while (cmd != NULL) |
4713 | { | |
4714 | execute_control_command (cmd); | |
4715 | ||
4716 | if (breakpoint_proceeded) | |
4717 | break; | |
4718 | else | |
4719 | cmd = cmd->next; | |
4720 | } | |
6c50ab1c JB |
4721 | |
4722 | /* We can free this command tree now. */ | |
4723 | do_cleanups (this_cmd_tree_chain); | |
4724 | ||
c906108c | 4725 | if (breakpoint_proceeded) |
32c1e744 | 4726 | { |
cb814510 | 4727 | if (current_ui->async) |
347bddb7 PA |
4728 | /* If we are in async mode, then the target might be still |
4729 | running, not stopped at any breakpoint, so nothing for | |
4730 | us to do here -- just return to the event loop. */ | |
4731 | ; | |
32c1e744 VP |
4732 | else |
4733 | /* In sync mode, when execute_control_command returns | |
4734 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4735 | Breakpoint commands for that stop were not run, since |
4736 | execute_command does not run breakpoint commands -- | |
4737 | only command_line_handler does, but that one is not | |
4738 | involved in execution of breakpoint commands. So, we | |
4739 | can now execute breakpoint commands. It should be | |
4740 | noted that making execute_command do bpstat actions is | |
4741 | not an option -- in this case we'll have recursive | |
4742 | invocation of bpstat for each breakpoint with a | |
4743 | command, and can easily blow up GDB stack. Instead, we | |
4744 | return true, which will trigger the caller to recall us | |
4745 | with the new stop_bpstat. */ | |
4746 | again = 1; | |
4747 | break; | |
32c1e744 | 4748 | } |
c906108c | 4749 | } |
c2b8ed2c | 4750 | do_cleanups (old_chain); |
347bddb7 PA |
4751 | return again; |
4752 | } | |
4753 | ||
4754 | void | |
4755 | bpstat_do_actions (void) | |
4756 | { | |
353d1d73 JK |
4757 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4758 | ||
347bddb7 PA |
4759 | /* Do any commands attached to breakpoint we are stopped at. */ |
4760 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4761 | && target_has_execution | |
4762 | && !is_exited (inferior_ptid) | |
4763 | && !is_executing (inferior_ptid)) | |
4764 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4765 | and only return when it is stopped at the next breakpoint, we | |
4766 | keep doing breakpoint actions until it returns false to | |
4767 | indicate the inferior was not resumed. */ | |
16c381f0 | 4768 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4769 | break; |
353d1d73 JK |
4770 | |
4771 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4772 | } |
4773 | ||
fa4727a6 DJ |
4774 | /* Print out the (old or new) value associated with a watchpoint. */ |
4775 | ||
4776 | static void | |
4777 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4778 | { | |
4779 | if (val == NULL) | |
4780 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4781 | else | |
79a45b7d TT |
4782 | { |
4783 | struct value_print_options opts; | |
4784 | get_user_print_options (&opts); | |
4785 | value_print (val, stream, &opts); | |
4786 | } | |
fa4727a6 DJ |
4787 | } |
4788 | ||
f303dbd6 PA |
4789 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4790 | debugging multiple threads. */ | |
4791 | ||
4792 | void | |
4793 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4794 | { | |
112e8700 | 4795 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4796 | return; |
4797 | ||
112e8700 | 4798 | uiout->text ("\n"); |
f303dbd6 PA |
4799 | |
4800 | if (show_thread_that_caused_stop ()) | |
4801 | { | |
4802 | const char *name; | |
4803 | struct thread_info *thr = inferior_thread (); | |
4804 | ||
112e8700 SM |
4805 | uiout->text ("Thread "); |
4806 | uiout->field_fmt ("thread-id", "%s", print_thread_id (thr)); | |
f303dbd6 PA |
4807 | |
4808 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4809 | if (name != NULL) | |
4810 | { | |
112e8700 SM |
4811 | uiout->text (" \""); |
4812 | uiout->field_fmt ("name", "%s", name); | |
4813 | uiout->text ("\""); | |
f303dbd6 PA |
4814 | } |
4815 | ||
112e8700 | 4816 | uiout->text (" hit "); |
f303dbd6 PA |
4817 | } |
4818 | } | |
4819 | ||
e514a9d6 | 4820 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4821 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4822 | 'print_it' in the bpstat structure. Under some circumstances we |
4823 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4824 | normal_stop(). */ |
e514a9d6 JM |
4825 | |
4826 | static enum print_stop_action | |
4827 | print_bp_stop_message (bpstat bs) | |
4828 | { | |
4829 | switch (bs->print_it) | |
4830 | { | |
4831 | case print_it_noop: | |
4a64f543 | 4832 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4833 | return PRINT_UNKNOWN; |
4834 | break; | |
4835 | ||
4836 | case print_it_done: | |
4837 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4838 | relevant messages. */ |
e514a9d6 JM |
4839 | return PRINT_SRC_AND_LOC; |
4840 | break; | |
4841 | ||
4842 | case print_it_normal: | |
4f8d1dc6 | 4843 | { |
f431efe5 PA |
4844 | struct breakpoint *b = bs->breakpoint_at; |
4845 | ||
1a6a67de TJB |
4846 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4847 | which has since been deleted. */ | |
4848 | if (b == NULL) | |
4849 | return PRINT_UNKNOWN; | |
4850 | ||
348d480f PA |
4851 | /* Normal case. Call the breakpoint's print_it method. */ |
4852 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4853 | } |
348d480f | 4854 | break; |
3086aeae | 4855 | |
e514a9d6 | 4856 | default: |
8e65ff28 | 4857 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4858 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4859 | break; |
c906108c | 4860 | } |
c906108c SS |
4861 | } |
4862 | ||
edcc5120 TT |
4863 | /* A helper function that prints a shared library stopped event. */ |
4864 | ||
4865 | static void | |
4866 | print_solib_event (int is_catchpoint) | |
4867 | { | |
4868 | int any_deleted | |
4869 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4870 | int any_added | |
4871 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4872 | ||
4873 | if (!is_catchpoint) | |
4874 | { | |
4875 | if (any_added || any_deleted) | |
112e8700 | 4876 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4877 | else |
112e8700 SM |
4878 | current_uiout->text (_("Stopped due to shared library event (no " |
4879 | "libraries added or removed)\n")); | |
edcc5120 TT |
4880 | } |
4881 | ||
112e8700 SM |
4882 | if (current_uiout->is_mi_like_p ()) |
4883 | current_uiout->field_string ("reason", | |
4884 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4885 | |
4886 | if (any_deleted) | |
4887 | { | |
4888 | struct cleanup *cleanup; | |
4889 | char *name; | |
4890 | int ix; | |
4891 | ||
112e8700 | 4892 | current_uiout->text (_(" Inferior unloaded ")); |
edcc5120 TT |
4893 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, |
4894 | "removed"); | |
4895 | for (ix = 0; | |
4896 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4897 | ix, name); | |
4898 | ++ix) | |
4899 | { | |
4900 | if (ix > 0) | |
112e8700 SM |
4901 | current_uiout->text (" "); |
4902 | current_uiout->field_string ("library", name); | |
4903 | current_uiout->text ("\n"); | |
edcc5120 TT |
4904 | } |
4905 | ||
4906 | do_cleanups (cleanup); | |
4907 | } | |
4908 | ||
4909 | if (any_added) | |
4910 | { | |
4911 | struct so_list *iter; | |
4912 | int ix; | |
4913 | struct cleanup *cleanup; | |
4914 | ||
112e8700 | 4915 | current_uiout->text (_(" Inferior loaded ")); |
edcc5120 TT |
4916 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, |
4917 | "added"); | |
4918 | for (ix = 0; | |
4919 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4920 | ix, iter); | |
4921 | ++ix) | |
4922 | { | |
4923 | if (ix > 0) | |
112e8700 SM |
4924 | current_uiout->text (" "); |
4925 | current_uiout->field_string ("library", iter->so_name); | |
4926 | current_uiout->text ("\n"); | |
edcc5120 TT |
4927 | } |
4928 | ||
4929 | do_cleanups (cleanup); | |
4930 | } | |
4931 | } | |
4932 | ||
e514a9d6 JM |
4933 | /* Print a message indicating what happened. This is called from |
4934 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4935 | list - a list of the eventpoints that caused this stop. KIND is |
4936 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4937 | routine calls the generic print routine for printing a message |
4938 | about reasons for stopping. This will print (for example) the | |
4939 | "Breakpoint n," part of the output. The return value of this | |
4940 | routine is one of: | |
c906108c | 4941 | |
4a64f543 | 4942 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4943 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4944 | code to print the location. An example is |
c5aa993b JM |
4945 | "Breakpoint 1, " which should be followed by |
4946 | the location. | |
917317f4 | 4947 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4948 | to also print the location part of the message. |
4949 | An example is the catch/throw messages, which | |
4a64f543 | 4950 | don't require a location appended to the end. |
917317f4 | 4951 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4952 | further info to be printed. */ |
c906108c | 4953 | |
917317f4 | 4954 | enum print_stop_action |
36dfb11c | 4955 | bpstat_print (bpstat bs, int kind) |
c906108c | 4956 | { |
f486487f | 4957 | enum print_stop_action val; |
c5aa993b | 4958 | |
c906108c | 4959 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4960 | (Currently all watchpoints go on the bpstat whether hit or not. |
4961 | That probably could (should) be changed, provided care is taken | |
c906108c | 4962 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4963 | for (; bs; bs = bs->next) |
4964 | { | |
4965 | val = print_bp_stop_message (bs); | |
4966 | if (val == PRINT_SRC_ONLY | |
4967 | || val == PRINT_SRC_AND_LOC | |
4968 | || val == PRINT_NOTHING) | |
4969 | return val; | |
4970 | } | |
c906108c | 4971 | |
36dfb11c TT |
4972 | /* If we had hit a shared library event breakpoint, |
4973 | print_bp_stop_message would print out this message. If we hit an | |
4974 | OS-level shared library event, do the same thing. */ | |
4975 | if (kind == TARGET_WAITKIND_LOADED) | |
4976 | { | |
edcc5120 | 4977 | print_solib_event (0); |
36dfb11c TT |
4978 | return PRINT_NOTHING; |
4979 | } | |
4980 | ||
e514a9d6 | 4981 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4982 | with and nothing was printed. */ |
917317f4 | 4983 | return PRINT_UNKNOWN; |
c906108c SS |
4984 | } |
4985 | ||
c42bd95a DE |
4986 | /* Evaluate the expression EXP and return 1 if value is zero. |
4987 | This returns the inverse of the condition because it is called | |
4988 | from catch_errors which returns 0 if an exception happened, and if an | |
4989 | exception happens we want execution to stop. | |
4a64f543 | 4990 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4991 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4992 | |
4993 | static int | |
4efb68b1 | 4994 | breakpoint_cond_eval (void *exp) |
c906108c | 4995 | { |
278cd55f | 4996 | struct value *mark = value_mark (); |
c5aa993b | 4997 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4998 | |
c906108c SS |
4999 | value_free_to_mark (mark); |
5000 | return i; | |
5001 | } | |
5002 | ||
5760d0ab | 5003 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5004 | |
5005 | static bpstat | |
5760d0ab | 5006 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5007 | { |
5008 | bpstat bs; | |
5009 | ||
5010 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5011 | bs->next = NULL; |
5012 | **bs_link_pointer = bs; | |
5013 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5014 | bs->breakpoint_at = bl->owner; |
5015 | bs->bp_location_at = bl; | |
5016 | incref_bp_location (bl); | |
c906108c SS |
5017 | /* If the condition is false, etc., don't do the commands. */ |
5018 | bs->commands = NULL; | |
5019 | bs->old_val = NULL; | |
5020 | bs->print_it = print_it_normal; | |
5021 | return bs; | |
5022 | } | |
5023 | \f | |
d983da9c DJ |
5024 | /* The target has stopped with waitstatus WS. Check if any hardware |
5025 | watchpoints have triggered, according to the target. */ | |
5026 | ||
5027 | int | |
5028 | watchpoints_triggered (struct target_waitstatus *ws) | |
5029 | { | |
d92524f1 | 5030 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5031 | CORE_ADDR addr; |
5032 | struct breakpoint *b; | |
5033 | ||
5034 | if (!stopped_by_watchpoint) | |
5035 | { | |
5036 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5037 | as not triggered. */ | |
5038 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5039 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5040 | { |
5041 | struct watchpoint *w = (struct watchpoint *) b; | |
5042 | ||
5043 | w->watchpoint_triggered = watch_triggered_no; | |
5044 | } | |
d983da9c DJ |
5045 | |
5046 | return 0; | |
5047 | } | |
5048 | ||
5049 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5050 | { | |
5051 | /* We were stopped by a watchpoint, but we don't know where. | |
5052 | Mark all watchpoints as unknown. */ | |
5053 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5054 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5055 | { |
5056 | struct watchpoint *w = (struct watchpoint *) b; | |
5057 | ||
5058 | w->watchpoint_triggered = watch_triggered_unknown; | |
5059 | } | |
d983da9c | 5060 | |
3c4797ba | 5061 | return 1; |
d983da9c DJ |
5062 | } |
5063 | ||
5064 | /* The target could report the data address. Mark watchpoints | |
5065 | affected by this data address as triggered, and all others as not | |
5066 | triggered. */ | |
5067 | ||
5068 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5069 | if (is_hardware_watchpoint (b)) |
d983da9c | 5070 | { |
3a5c3e22 | 5071 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5072 | struct bp_location *loc; |
d983da9c | 5073 | |
3a5c3e22 | 5074 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5075 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5076 | { |
3a5c3e22 | 5077 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5078 | { |
3a5c3e22 PA |
5079 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5080 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5081 | |
5082 | if (newaddr == start) | |
5083 | { | |
3a5c3e22 | 5084 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5085 | break; |
5086 | } | |
5087 | } | |
5088 | /* Exact match not required. Within range is sufficient. */ | |
5089 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5090 | addr, loc->address, | |
5091 | loc->length)) | |
5092 | { | |
3a5c3e22 | 5093 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5094 | break; |
5095 | } | |
5096 | } | |
d983da9c DJ |
5097 | } |
5098 | ||
5099 | return 1; | |
5100 | } | |
5101 | ||
c906108c SS |
5102 | /* Possible return values for watchpoint_check (this can't be an enum |
5103 | because of check_errors). */ | |
5104 | /* The watchpoint has been deleted. */ | |
5105 | #define WP_DELETED 1 | |
5106 | /* The value has changed. */ | |
5107 | #define WP_VALUE_CHANGED 2 | |
5108 | /* The value has not changed. */ | |
5109 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5110 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5111 | #define WP_IGNORE 4 | |
c906108c SS |
5112 | |
5113 | #define BP_TEMPFLAG 1 | |
5114 | #define BP_HARDWAREFLAG 2 | |
5115 | ||
4a64f543 MS |
5116 | /* Evaluate watchpoint condition expression and check if its value |
5117 | changed. | |
553e4c11 JB |
5118 | |
5119 | P should be a pointer to struct bpstat, but is defined as a void * | |
5120 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5121 | |
5122 | static int | |
4efb68b1 | 5123 | watchpoint_check (void *p) |
c906108c SS |
5124 | { |
5125 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5126 | struct watchpoint *b; |
c906108c SS |
5127 | struct frame_info *fr; |
5128 | int within_current_scope; | |
5129 | ||
f431efe5 | 5130 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5131 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5132 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5133 | |
f6bc2008 PA |
5134 | /* If this is a local watchpoint, we only want to check if the |
5135 | watchpoint frame is in scope if the current thread is the thread | |
5136 | that was used to create the watchpoint. */ | |
5137 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5138 | return WP_IGNORE; |
f6bc2008 | 5139 | |
c906108c SS |
5140 | if (b->exp_valid_block == NULL) |
5141 | within_current_scope = 1; | |
5142 | else | |
5143 | { | |
edb3359d DJ |
5144 | struct frame_info *frame = get_current_frame (); |
5145 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5146 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5147 | ||
c9cf6e20 | 5148 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5149 | still in the function but the stack frame has already been |
5150 | invalidated. Since we can't rely on the values of local | |
5151 | variables after the stack has been destroyed, we are treating | |
5152 | the watchpoint in that state as `not changed' without further | |
5153 | checking. Don't mark watchpoints as changed if the current | |
5154 | frame is in an epilogue - even if they are in some other | |
5155 | frame, our view of the stack is likely to be wrong and | |
5156 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5157 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5158 | return WP_IGNORE; |
a0f49112 | 5159 | |
101dcfbe | 5160 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5161 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5162 | |
5163 | /* If we've gotten confused in the unwinder, we might have | |
5164 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5165 | if (within_current_scope) |
5166 | { | |
5167 | struct symbol *function; | |
5168 | ||
5169 | function = get_frame_function (fr); | |
5170 | if (function == NULL | |
5171 | || !contained_in (b->exp_valid_block, | |
5172 | SYMBOL_BLOCK_VALUE (function))) | |
5173 | within_current_scope = 0; | |
5174 | } | |
69fbadd5 | 5175 | |
edb3359d | 5176 | if (within_current_scope) |
c906108c SS |
5177 | /* If we end up stopping, the current frame will get selected |
5178 | in normal_stop. So this call to select_frame won't affect | |
5179 | the user. */ | |
0f7d239c | 5180 | select_frame (fr); |
c906108c | 5181 | } |
c5aa993b | 5182 | |
c906108c SS |
5183 | if (within_current_scope) |
5184 | { | |
4a64f543 MS |
5185 | /* We use value_{,free_to_}mark because it could be a *long* |
5186 | time before we return to the command level and call | |
5187 | free_all_values. We can't call free_all_values because we | |
5188 | might be in the middle of evaluating a function call. */ | |
c906108c | 5189 | |
0cf6dd15 | 5190 | int pc = 0; |
9c06b0b4 | 5191 | struct value *mark; |
fa4727a6 DJ |
5192 | struct value *new_val; |
5193 | ||
3a5c3e22 | 5194 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5195 | /* Since we don't know the exact trigger address (from |
5196 | stopped_data_address), just tell the user we've triggered | |
5197 | a mask watchpoint. */ | |
5198 | return WP_VALUE_CHANGED; | |
5199 | ||
5200 | mark = value_mark (); | |
4d01a485 | 5201 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5202 | |
bb9d5f81 PP |
5203 | if (b->val_bitsize != 0) |
5204 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5205 | ||
4a64f543 MS |
5206 | /* We use value_equal_contents instead of value_equal because |
5207 | the latter coerces an array to a pointer, thus comparing just | |
5208 | the address of the array instead of its contents. This is | |
5209 | not what we want. */ | |
fa4727a6 | 5210 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5211 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5212 | { |
fa4727a6 DJ |
5213 | if (new_val != NULL) |
5214 | { | |
5215 | release_value (new_val); | |
5216 | value_free_to_mark (mark); | |
5217 | } | |
c906108c SS |
5218 | bs->old_val = b->val; |
5219 | b->val = new_val; | |
fa4727a6 | 5220 | b->val_valid = 1; |
c906108c SS |
5221 | return WP_VALUE_CHANGED; |
5222 | } | |
5223 | else | |
5224 | { | |
60e1c644 | 5225 | /* Nothing changed. */ |
c906108c | 5226 | value_free_to_mark (mark); |
c906108c SS |
5227 | return WP_VALUE_NOT_CHANGED; |
5228 | } | |
5229 | } | |
5230 | else | |
5231 | { | |
5232 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5233 | if we temporarily ignored the watchpoint, then when |
5234 | we reenter the block in which it is valid it contains | |
5235 | garbage (in the case of a function, it may have two | |
5236 | garbage values, one before and one after the prologue). | |
5237 | So we can't even detect the first assignment to it and | |
5238 | watch after that (since the garbage may or may not equal | |
5239 | the first value assigned). */ | |
348d480f PA |
5240 | /* We print all the stop information in |
5241 | breakpoint_ops->print_it, but in this case, by the time we | |
5242 | call breakpoint_ops->print_it this bp will be deleted | |
5243 | already. So we have no choice but print the information | |
5244 | here. */ | |
468afe6c | 5245 | |
0e454242 | 5246 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5247 | { |
5248 | struct ui_out *uiout = current_uiout; | |
5249 | ||
112e8700 SM |
5250 | if (uiout->is_mi_like_p ()) |
5251 | uiout->field_string | |
5252 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5253 | uiout->text ("\nWatchpoint "); | |
5254 | uiout->field_int ("wpnum", b->base.number); | |
5255 | uiout->text (" deleted because the program has left the block in\n" | |
468afe6c PA |
5256 | "which its expression is valid.\n"); |
5257 | } | |
4ce44c66 | 5258 | |
cdac0397 | 5259 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5260 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5261 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5262 | |
5263 | return WP_DELETED; | |
5264 | } | |
5265 | } | |
5266 | ||
18a18393 | 5267 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5268 | breakpoint location BL. This function does not check if we should |
5269 | stop, only if BL explains the stop. */ | |
5270 | ||
18a18393 | 5271 | static int |
6c95b8df | 5272 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5273 | struct address_space *aspace, CORE_ADDR bp_addr, |
5274 | const struct target_waitstatus *ws) | |
18a18393 VP |
5275 | { |
5276 | struct breakpoint *b = bl->owner; | |
5277 | ||
348d480f | 5278 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5279 | gdb_assert (b != NULL); |
5280 | ||
09ac7c10 | 5281 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5282 | } |
5283 | ||
3a5c3e22 PA |
5284 | /* Determine if the watched values have actually changed, and we |
5285 | should stop. If not, set BS->stop to 0. */ | |
5286 | ||
18a18393 VP |
5287 | static void |
5288 | bpstat_check_watchpoint (bpstat bs) | |
5289 | { | |
2bdf28a0 | 5290 | const struct bp_location *bl; |
3a5c3e22 | 5291 | struct watchpoint *b; |
2bdf28a0 JK |
5292 | |
5293 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5294 | bl = bs->bp_location_at; |
2bdf28a0 | 5295 | gdb_assert (bl != NULL); |
3a5c3e22 | 5296 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5297 | gdb_assert (b != NULL); |
18a18393 | 5298 | |
18a18393 | 5299 | { |
18a18393 VP |
5300 | int must_check_value = 0; |
5301 | ||
3a5c3e22 | 5302 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5303 | /* For a software watchpoint, we must always check the |
5304 | watched value. */ | |
5305 | must_check_value = 1; | |
5306 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5307 | /* We have a hardware watchpoint (read, write, or access) | |
5308 | and the target earlier reported an address watched by | |
5309 | this watchpoint. */ | |
5310 | must_check_value = 1; | |
5311 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5312 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5313 | /* We were stopped by a hardware watchpoint, but the target could |
5314 | not report the data address. We must check the watchpoint's | |
5315 | value. Access and read watchpoints are out of luck; without | |
5316 | a data address, we can't figure it out. */ | |
5317 | must_check_value = 1; | |
3a5c3e22 | 5318 | |
18a18393 VP |
5319 | if (must_check_value) |
5320 | { | |
3e43a32a MS |
5321 | char *message |
5322 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5323 | b->base.number); |
18a18393 VP |
5324 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5325 | int e = catch_errors (watchpoint_check, bs, message, | |
5326 | RETURN_MASK_ALL); | |
5327 | do_cleanups (cleanups); | |
5328 | switch (e) | |
5329 | { | |
5330 | case WP_DELETED: | |
5331 | /* We've already printed what needs to be printed. */ | |
5332 | bs->print_it = print_it_done; | |
5333 | /* Stop. */ | |
5334 | break; | |
60e1c644 PA |
5335 | case WP_IGNORE: |
5336 | bs->print_it = print_it_noop; | |
5337 | bs->stop = 0; | |
5338 | break; | |
18a18393 | 5339 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5340 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5341 | { |
85d721b8 PA |
5342 | /* There are two cases to consider here: |
5343 | ||
4a64f543 | 5344 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5345 | In that case, trust the target, and always report |
5346 | the watchpoint hit to the user. Even though | |
5347 | reads don't cause value changes, the value may | |
5348 | have changed since the last time it was read, and | |
5349 | since we're not trapping writes, we will not see | |
5350 | those, and as such we should ignore our notion of | |
5351 | old value. | |
5352 | ||
4a64f543 | 5353 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5354 | reads and writes. There are two ways this may |
5355 | happen: | |
5356 | ||
4a64f543 | 5357 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5358 | reads only, but can break on accesses (reads or |
5359 | writes), such as e.g., x86. We detect this case | |
5360 | at the time we try to insert read watchpoints. | |
5361 | ||
4a64f543 | 5362 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5363 | watchpoints, but, the user set an access or write |
5364 | watchpoint watching the same memory as this read | |
5365 | watchpoint. | |
5366 | ||
5367 | If we're watching memory writes as well as reads, | |
5368 | ignore watchpoint hits when we find that the | |
5369 | value hasn't changed, as reads don't cause | |
5370 | changes. This still gives false positives when | |
5371 | the program writes the same value to memory as | |
5372 | what there was already in memory (we will confuse | |
5373 | it for a read), but it's much better than | |
5374 | nothing. */ | |
5375 | ||
5376 | int other_write_watchpoint = 0; | |
5377 | ||
5378 | if (bl->watchpoint_type == hw_read) | |
5379 | { | |
5380 | struct breakpoint *other_b; | |
5381 | ||
5382 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5383 | if (other_b->type == bp_hardware_watchpoint |
5384 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5385 | { |
3a5c3e22 PA |
5386 | struct watchpoint *other_w = |
5387 | (struct watchpoint *) other_b; | |
5388 | ||
5389 | if (other_w->watchpoint_triggered | |
5390 | == watch_triggered_yes) | |
5391 | { | |
5392 | other_write_watchpoint = 1; | |
5393 | break; | |
5394 | } | |
85d721b8 PA |
5395 | } |
5396 | } | |
5397 | ||
5398 | if (other_write_watchpoint | |
5399 | || bl->watchpoint_type == hw_access) | |
5400 | { | |
5401 | /* We're watching the same memory for writes, | |
5402 | and the value changed since the last time we | |
5403 | updated it, so this trap must be for a write. | |
5404 | Ignore it. */ | |
5405 | bs->print_it = print_it_noop; | |
5406 | bs->stop = 0; | |
5407 | } | |
18a18393 VP |
5408 | } |
5409 | break; | |
5410 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5411 | if (b->base.type == bp_hardware_watchpoint |
5412 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5413 | { |
5414 | /* Don't stop: write watchpoints shouldn't fire if | |
5415 | the value hasn't changed. */ | |
5416 | bs->print_it = print_it_noop; | |
5417 | bs->stop = 0; | |
5418 | } | |
5419 | /* Stop. */ | |
5420 | break; | |
5421 | default: | |
5422 | /* Can't happen. */ | |
5423 | case 0: | |
5424 | /* Error from catch_errors. */ | |
468afe6c | 5425 | { |
0e454242 | 5426 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5427 | { |
5428 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5429 | b->base.number); | |
5430 | } | |
5431 | watchpoint_del_at_next_stop (b); | |
5432 | /* We've already printed what needs to be printed. */ | |
5433 | bs->print_it = print_it_done; | |
5434 | } | |
18a18393 VP |
5435 | break; |
5436 | } | |
5437 | } | |
5438 | else /* must_check_value == 0 */ | |
5439 | { | |
5440 | /* This is a case where some watchpoint(s) triggered, but | |
5441 | not at the address of this watchpoint, or else no | |
5442 | watchpoint triggered after all. So don't print | |
5443 | anything for this watchpoint. */ | |
5444 | bs->print_it = print_it_noop; | |
5445 | bs->stop = 0; | |
5446 | } | |
5447 | } | |
5448 | } | |
5449 | ||
7d4df6a4 DE |
5450 | /* For breakpoints that are currently marked as telling gdb to stop, |
5451 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5452 | of breakpoint referred to by BS. If we should not stop for this |
5453 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5454 | |
18a18393 VP |
5455 | static void |
5456 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5457 | { | |
2bdf28a0 JK |
5458 | const struct bp_location *bl; |
5459 | struct breakpoint *b; | |
7d4df6a4 DE |
5460 | int value_is_zero = 0; |
5461 | struct expression *cond; | |
5462 | ||
5463 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5464 | |
5465 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5466 | bl = bs->bp_location_at; |
2bdf28a0 | 5467 | gdb_assert (bl != NULL); |
f431efe5 | 5468 | b = bs->breakpoint_at; |
2bdf28a0 | 5469 | gdb_assert (b != NULL); |
18a18393 | 5470 | |
b775012e LM |
5471 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5472 | need to do so again since GDB does not know if we stopped due to a | |
5473 | breakpoint or a single step breakpoint. */ | |
5474 | ||
18a18393 | 5475 | if (frame_id_p (b->frame_id) |
edb3359d | 5476 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5477 | { |
7d4df6a4 DE |
5478 | bs->stop = 0; |
5479 | return; | |
5480 | } | |
60e1c644 | 5481 | |
12ab52e9 PA |
5482 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5483 | evaluating the condition if this isn't the specified | |
5484 | thread/task. */ | |
5d5658a1 | 5485 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5486 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5487 | ||
6c1b0f7b DE |
5488 | { |
5489 | bs->stop = 0; | |
5490 | return; | |
5491 | } | |
5492 | ||
6dddc817 DE |
5493 | /* Evaluate extension language breakpoints that have a "stop" method |
5494 | implemented. */ | |
5495 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5496 | |
7d4df6a4 DE |
5497 | if (is_watchpoint (b)) |
5498 | { | |
5499 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5500 | |
4d01a485 | 5501 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5502 | } |
5503 | else | |
4d01a485 | 5504 | cond = bl->cond.get (); |
60e1c644 | 5505 | |
7d4df6a4 DE |
5506 | if (cond && b->disposition != disp_del_at_next_stop) |
5507 | { | |
5508 | int within_current_scope = 1; | |
5509 | struct watchpoint * w; | |
60e1c644 | 5510 | |
7d4df6a4 DE |
5511 | /* We use value_mark and value_free_to_mark because it could |
5512 | be a long time before we return to the command level and | |
5513 | call free_all_values. We can't call free_all_values | |
5514 | because we might be in the middle of evaluating a | |
5515 | function call. */ | |
5516 | struct value *mark = value_mark (); | |
5517 | ||
5518 | if (is_watchpoint (b)) | |
5519 | w = (struct watchpoint *) b; | |
5520 | else | |
5521 | w = NULL; | |
5522 | ||
5523 | /* Need to select the frame, with all that implies so that | |
5524 | the conditions will have the right context. Because we | |
5525 | use the frame, we will not see an inlined function's | |
5526 | variables when we arrive at a breakpoint at the start | |
5527 | of the inlined function; the current frame will be the | |
5528 | call site. */ | |
5529 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5530 | select_frame (get_current_frame ()); | |
5531 | else | |
18a18393 | 5532 | { |
7d4df6a4 DE |
5533 | struct frame_info *frame; |
5534 | ||
5535 | /* For local watchpoint expressions, which particular | |
5536 | instance of a local is being watched matters, so we | |
5537 | keep track of the frame to evaluate the expression | |
5538 | in. To evaluate the condition however, it doesn't | |
5539 | really matter which instantiation of the function | |
5540 | where the condition makes sense triggers the | |
5541 | watchpoint. This allows an expression like "watch | |
5542 | global if q > 10" set in `func', catch writes to | |
5543 | global on all threads that call `func', or catch | |
5544 | writes on all recursive calls of `func' by a single | |
5545 | thread. We simply always evaluate the condition in | |
5546 | the innermost frame that's executing where it makes | |
5547 | sense to evaluate the condition. It seems | |
5548 | intuitive. */ | |
5549 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5550 | if (frame != NULL) | |
5551 | select_frame (frame); | |
5552 | else | |
5553 | within_current_scope = 0; | |
18a18393 | 5554 | } |
7d4df6a4 DE |
5555 | if (within_current_scope) |
5556 | value_is_zero | |
5557 | = catch_errors (breakpoint_cond_eval, cond, | |
5558 | "Error in testing breakpoint condition:\n", | |
5559 | RETURN_MASK_ALL); | |
5560 | else | |
18a18393 | 5561 | { |
7d4df6a4 DE |
5562 | warning (_("Watchpoint condition cannot be tested " |
5563 | "in the current scope")); | |
5564 | /* If we failed to set the right context for this | |
5565 | watchpoint, unconditionally report it. */ | |
5566 | value_is_zero = 0; | |
18a18393 | 5567 | } |
7d4df6a4 DE |
5568 | /* FIXME-someday, should give breakpoint #. */ |
5569 | value_free_to_mark (mark); | |
18a18393 | 5570 | } |
7d4df6a4 DE |
5571 | |
5572 | if (cond && value_is_zero) | |
5573 | { | |
5574 | bs->stop = 0; | |
5575 | } | |
7d4df6a4 DE |
5576 | else if (b->ignore_count > 0) |
5577 | { | |
5578 | b->ignore_count--; | |
5579 | bs->stop = 0; | |
5580 | /* Increase the hit count even though we don't stop. */ | |
5581 | ++(b->hit_count); | |
5582 | observer_notify_breakpoint_modified (b); | |
5583 | } | |
18a18393 VP |
5584 | } |
5585 | ||
1cf4d951 PA |
5586 | /* Returns true if we need to track moribund locations of LOC's type |
5587 | on the current target. */ | |
5588 | ||
5589 | static int | |
5590 | need_moribund_for_location_type (struct bp_location *loc) | |
5591 | { | |
5592 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5593 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5594 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5595 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5596 | } | |
5597 | ||
18a18393 | 5598 | |
9709f61c | 5599 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5600 | BP_ADDR in thread PTID. |
c906108c | 5601 | |
d983da9c | 5602 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5603 | don't understand this stop. Result is a chain of bpstat's such |
5604 | that: | |
c906108c | 5605 | |
c5aa993b | 5606 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5607 | |
c5aa993b | 5608 | if we understand why we stopped, the result is not null. |
c906108c | 5609 | |
c5aa993b JM |
5610 | Each element of the chain refers to a particular breakpoint or |
5611 | watchpoint at which we have stopped. (We may have stopped for | |
5612 | several reasons concurrently.) | |
c906108c | 5613 | |
c5aa993b JM |
5614 | Each element of the chain has valid next, breakpoint_at, |
5615 | commands, FIXME??? fields. */ | |
c906108c SS |
5616 | |
5617 | bpstat | |
6c95b8df | 5618 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5619 | CORE_ADDR bp_addr, ptid_t ptid, |
5620 | const struct target_waitstatus *ws) | |
c906108c | 5621 | { |
0d381245 | 5622 | struct breakpoint *b = NULL; |
afe38095 | 5623 | struct bp_location *bl; |
20874c92 | 5624 | struct bp_location *loc; |
5760d0ab JK |
5625 | /* First item of allocated bpstat's. */ |
5626 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5627 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5628 | bpstat bs; |
20874c92 | 5629 | int ix; |
429374b8 | 5630 | int need_remove_insert; |
f431efe5 | 5631 | int removed_any; |
c906108c | 5632 | |
f431efe5 PA |
5633 | /* First, build the bpstat chain with locations that explain a |
5634 | target stop, while being careful to not set the target running, | |
5635 | as that may invalidate locations (in particular watchpoint | |
5636 | locations are recreated). Resuming will happen here with | |
5637 | breakpoint conditions or watchpoint expressions that include | |
5638 | inferior function calls. */ | |
c5aa993b | 5639 | |
429374b8 JK |
5640 | ALL_BREAKPOINTS (b) |
5641 | { | |
1a853c52 | 5642 | if (!breakpoint_enabled (b)) |
429374b8 | 5643 | continue; |
a5606eee | 5644 | |
429374b8 JK |
5645 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5646 | { | |
4a64f543 MS |
5647 | /* For hardware watchpoints, we look only at the first |
5648 | location. The watchpoint_check function will work on the | |
5649 | entire expression, not the individual locations. For | |
5650 | read watchpoints, the watchpoints_triggered function has | |
5651 | checked all locations already. */ | |
429374b8 JK |
5652 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5653 | break; | |
18a18393 | 5654 | |
f6592439 | 5655 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5656 | continue; |
c5aa993b | 5657 | |
09ac7c10 | 5658 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5659 | continue; |
c5aa993b | 5660 | |
4a64f543 MS |
5661 | /* Come here if it's a watchpoint, or if the break address |
5662 | matches. */ | |
c5aa993b | 5663 | |
4a64f543 MS |
5664 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5665 | explain stop. */ | |
c5aa993b | 5666 | |
f431efe5 PA |
5667 | /* Assume we stop. Should we find a watchpoint that is not |
5668 | actually triggered, or if the condition of the breakpoint | |
5669 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5670 | bs->stop = 1; |
5671 | bs->print = 1; | |
d983da9c | 5672 | |
f431efe5 PA |
5673 | /* If this is a scope breakpoint, mark the associated |
5674 | watchpoint as triggered so that we will handle the | |
5675 | out-of-scope event. We'll get to the watchpoint next | |
5676 | iteration. */ | |
d0fb5eae | 5677 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5678 | { |
5679 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5680 | ||
5681 | w->watchpoint_triggered = watch_triggered_yes; | |
5682 | } | |
f431efe5 PA |
5683 | } |
5684 | } | |
5685 | ||
7c16b83e | 5686 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5687 | if (!target_supports_stopped_by_sw_breakpoint () |
5688 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5689 | { |
1cf4d951 | 5690 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5691 | { |
1cf4d951 PA |
5692 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5693 | && need_moribund_for_location_type (loc)) | |
5694 | { | |
5695 | bs = bpstat_alloc (loc, &bs_link); | |
5696 | /* For hits of moribund locations, we should just proceed. */ | |
5697 | bs->stop = 0; | |
5698 | bs->print = 0; | |
5699 | bs->print_it = print_it_noop; | |
5700 | } | |
f431efe5 PA |
5701 | } |
5702 | } | |
5703 | ||
edcc5120 TT |
5704 | /* A bit of special processing for shlib breakpoints. We need to |
5705 | process solib loading here, so that the lists of loaded and | |
5706 | unloaded libraries are correct before we handle "catch load" and | |
5707 | "catch unload". */ | |
5708 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5709 | { | |
5d268276 | 5710 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5711 | { |
5712 | handle_solib_event (); | |
5713 | break; | |
5714 | } | |
5715 | } | |
5716 | ||
f431efe5 PA |
5717 | /* Now go through the locations that caused the target to stop, and |
5718 | check whether we're interested in reporting this stop to higher | |
5719 | layers, or whether we should resume the target transparently. */ | |
5720 | ||
5721 | removed_any = 0; | |
5722 | ||
5760d0ab | 5723 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5724 | { |
5725 | if (!bs->stop) | |
5726 | continue; | |
5727 | ||
f431efe5 | 5728 | b = bs->breakpoint_at; |
348d480f PA |
5729 | b->ops->check_status (bs); |
5730 | if (bs->stop) | |
28010a5d | 5731 | { |
348d480f | 5732 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5733 | |
429374b8 JK |
5734 | if (bs->stop) |
5735 | { | |
5736 | ++(b->hit_count); | |
8d3788bd | 5737 | observer_notify_breakpoint_modified (b); |
c906108c | 5738 | |
4a64f543 | 5739 | /* We will stop here. */ |
429374b8 JK |
5740 | if (b->disposition == disp_disable) |
5741 | { | |
816338b5 | 5742 | --(b->enable_count); |
1a853c52 | 5743 | if (b->enable_count <= 0) |
429374b8 | 5744 | b->enable_state = bp_disabled; |
f431efe5 | 5745 | removed_any = 1; |
429374b8 JK |
5746 | } |
5747 | if (b->silent) | |
5748 | bs->print = 0; | |
5749 | bs->commands = b->commands; | |
9add0f1b | 5750 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5751 | if (command_line_is_silent (bs->commands |
5752 | ? bs->commands->commands : NULL)) | |
5753 | bs->print = 0; | |
9d6e6e84 HZ |
5754 | |
5755 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5756 | } |
5757 | ||
348d480f | 5758 | } |
a9b3a50f PA |
5759 | |
5760 | /* Print nothing for this entry if we don't stop or don't | |
5761 | print. */ | |
5762 | if (!bs->stop || !bs->print) | |
5763 | bs->print_it = print_it_noop; | |
429374b8 | 5764 | } |
876fa593 | 5765 | |
d983da9c DJ |
5766 | /* If we aren't stopping, the value of some hardware watchpoint may |
5767 | not have changed, but the intermediate memory locations we are | |
5768 | watching may have. Don't bother if we're stopping; this will get | |
5769 | done later. */ | |
d832cb68 | 5770 | need_remove_insert = 0; |
5760d0ab JK |
5771 | if (! bpstat_causes_stop (bs_head)) |
5772 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5773 | if (!bs->stop |
f431efe5 PA |
5774 | && bs->breakpoint_at |
5775 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5776 | { |
3a5c3e22 PA |
5777 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5778 | ||
5779 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5780 | need_remove_insert = 1; |
d983da9c DJ |
5781 | } |
5782 | ||
d832cb68 | 5783 | if (need_remove_insert) |
44702360 | 5784 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5785 | else if (removed_any) |
44702360 | 5786 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5787 | |
5760d0ab | 5788 | return bs_head; |
c906108c | 5789 | } |
628fe4e4 JK |
5790 | |
5791 | static void | |
5792 | handle_jit_event (void) | |
5793 | { | |
5794 | struct frame_info *frame; | |
5795 | struct gdbarch *gdbarch; | |
5796 | ||
243a9253 PA |
5797 | if (debug_infrun) |
5798 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5799 | ||
628fe4e4 JK |
5800 | /* Switch terminal for any messages produced by |
5801 | breakpoint_re_set. */ | |
5802 | target_terminal_ours_for_output (); | |
5803 | ||
5804 | frame = get_current_frame (); | |
5805 | gdbarch = get_frame_arch (frame); | |
5806 | ||
5807 | jit_event_handler (gdbarch); | |
5808 | ||
5809 | target_terminal_inferior (); | |
5810 | } | |
5811 | ||
5812 | /* Prepare WHAT final decision for infrun. */ | |
5813 | ||
5814 | /* Decide what infrun needs to do with this bpstat. */ | |
5815 | ||
c906108c | 5816 | struct bpstat_what |
0e30163f | 5817 | bpstat_what (bpstat bs_head) |
c906108c | 5818 | { |
c906108c | 5819 | struct bpstat_what retval; |
0e30163f | 5820 | bpstat bs; |
c906108c | 5821 | |
628fe4e4 | 5822 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5823 | retval.call_dummy = STOP_NONE; |
186c406b | 5824 | retval.is_longjmp = 0; |
628fe4e4 | 5825 | |
0e30163f | 5826 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5827 | { |
628fe4e4 JK |
5828 | /* Extract this BS's action. After processing each BS, we check |
5829 | if its action overrides all we've seem so far. */ | |
5830 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5831 | enum bptype bptype; | |
5832 | ||
c906108c | 5833 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5834 | { |
5835 | /* I suspect this can happen if it was a momentary | |
5836 | breakpoint which has since been deleted. */ | |
5837 | bptype = bp_none; | |
5838 | } | |
20874c92 | 5839 | else |
f431efe5 | 5840 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5841 | |
5842 | switch (bptype) | |
c906108c SS |
5843 | { |
5844 | case bp_none: | |
628fe4e4 | 5845 | break; |
c906108c SS |
5846 | case bp_breakpoint: |
5847 | case bp_hardware_breakpoint: | |
7c16b83e | 5848 | case bp_single_step: |
c906108c SS |
5849 | case bp_until: |
5850 | case bp_finish: | |
a9b3a50f | 5851 | case bp_shlib_event: |
c906108c SS |
5852 | if (bs->stop) |
5853 | { | |
5854 | if (bs->print) | |
628fe4e4 | 5855 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5856 | else |
628fe4e4 | 5857 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5858 | } |
5859 | else | |
628fe4e4 | 5860 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5861 | break; |
5862 | case bp_watchpoint: | |
5863 | case bp_hardware_watchpoint: | |
5864 | case bp_read_watchpoint: | |
5865 | case bp_access_watchpoint: | |
5866 | if (bs->stop) | |
5867 | { | |
5868 | if (bs->print) | |
628fe4e4 | 5869 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5870 | else |
628fe4e4 | 5871 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5872 | } |
5873 | else | |
628fe4e4 JK |
5874 | { |
5875 | /* There was a watchpoint, but we're not stopping. | |
5876 | This requires no further action. */ | |
5877 | } | |
c906108c SS |
5878 | break; |
5879 | case bp_longjmp: | |
e2e4d78b | 5880 | case bp_longjmp_call_dummy: |
186c406b | 5881 | case bp_exception: |
0a39bb32 PA |
5882 | if (bs->stop) |
5883 | { | |
5884 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5885 | retval.is_longjmp = bptype != bp_exception; | |
5886 | } | |
5887 | else | |
5888 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5889 | break; |
5890 | case bp_longjmp_resume: | |
186c406b | 5891 | case bp_exception_resume: |
0a39bb32 PA |
5892 | if (bs->stop) |
5893 | { | |
5894 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5895 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5896 | } | |
5897 | else | |
5898 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5899 | break; |
5900 | case bp_step_resume: | |
5901 | if (bs->stop) | |
628fe4e4 JK |
5902 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5903 | else | |
c906108c | 5904 | { |
628fe4e4 JK |
5905 | /* It is for the wrong frame. */ |
5906 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5907 | } |
c906108c | 5908 | break; |
2c03e5be PA |
5909 | case bp_hp_step_resume: |
5910 | if (bs->stop) | |
5911 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5912 | else | |
5913 | { | |
5914 | /* It is for the wrong frame. */ | |
5915 | this_action = BPSTAT_WHAT_SINGLE; | |
5916 | } | |
5917 | break; | |
c906108c | 5918 | case bp_watchpoint_scope: |
c4093a6a | 5919 | case bp_thread_event: |
1900040c | 5920 | case bp_overlay_event: |
0fd8e87f | 5921 | case bp_longjmp_master: |
aa7d318d | 5922 | case bp_std_terminate_master: |
186c406b | 5923 | case bp_exception_master: |
628fe4e4 | 5924 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5925 | break; |
ce78b96d | 5926 | case bp_catchpoint: |
c5aa993b JM |
5927 | if (bs->stop) |
5928 | { | |
5929 | if (bs->print) | |
628fe4e4 | 5930 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5931 | else |
628fe4e4 | 5932 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5933 | } |
5934 | else | |
628fe4e4 JK |
5935 | { |
5936 | /* There was a catchpoint, but we're not stopping. | |
5937 | This requires no further action. */ | |
5938 | } | |
5939 | break; | |
628fe4e4 | 5940 | case bp_jit_event: |
628fe4e4 | 5941 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5942 | break; |
c906108c | 5943 | case bp_call_dummy: |
53a5351d JM |
5944 | /* Make sure the action is stop (silent or noisy), |
5945 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5946 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5947 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5948 | break; |
5949 | case bp_std_terminate: | |
5950 | /* Make sure the action is stop (silent or noisy), | |
5951 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5952 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5953 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5954 | break; |
1042e4c0 | 5955 | case bp_tracepoint: |
7a697b8d | 5956 | case bp_fast_tracepoint: |
0fb4aa4b | 5957 | case bp_static_tracepoint: |
1042e4c0 SS |
5958 | /* Tracepoint hits should not be reported back to GDB, and |
5959 | if one got through somehow, it should have been filtered | |
5960 | out already. */ | |
5961 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5962 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5963 | break; |
5964 | case bp_gnu_ifunc_resolver: | |
5965 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5966 | this_action = BPSTAT_WHAT_SINGLE; | |
5967 | break; | |
5968 | case bp_gnu_ifunc_resolver_return: | |
5969 | /* The breakpoint will be removed, execution will restart from the | |
5970 | PC of the former breakpoint. */ | |
5971 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5972 | break; | |
e7e0cddf SS |
5973 | |
5974 | case bp_dprintf: | |
a11cfd87 HZ |
5975 | if (bs->stop) |
5976 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5977 | else | |
5978 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5979 | break; |
5980 | ||
628fe4e4 JK |
5981 | default: |
5982 | internal_error (__FILE__, __LINE__, | |
5983 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5984 | } |
628fe4e4 | 5985 | |
325fac50 | 5986 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5987 | } |
628fe4e4 | 5988 | |
243a9253 PA |
5989 | return retval; |
5990 | } | |
628fe4e4 | 5991 | |
243a9253 PA |
5992 | void |
5993 | bpstat_run_callbacks (bpstat bs_head) | |
5994 | { | |
5995 | bpstat bs; | |
628fe4e4 | 5996 | |
0e30163f JK |
5997 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5998 | { | |
5999 | struct breakpoint *b = bs->breakpoint_at; | |
6000 | ||
6001 | if (b == NULL) | |
6002 | continue; | |
6003 | switch (b->type) | |
6004 | { | |
243a9253 PA |
6005 | case bp_jit_event: |
6006 | handle_jit_event (); | |
6007 | break; | |
0e30163f JK |
6008 | case bp_gnu_ifunc_resolver: |
6009 | gnu_ifunc_resolver_stop (b); | |
6010 | break; | |
6011 | case bp_gnu_ifunc_resolver_return: | |
6012 | gnu_ifunc_resolver_return_stop (b); | |
6013 | break; | |
6014 | } | |
6015 | } | |
c906108c SS |
6016 | } |
6017 | ||
6018 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6019 | without hardware support). This isn't related to a specific bpstat, | |
6020 | just to things like whether watchpoints are set. */ | |
6021 | ||
c5aa993b | 6022 | int |
fba45db2 | 6023 | bpstat_should_step (void) |
c906108c SS |
6024 | { |
6025 | struct breakpoint *b; | |
cc59ec59 | 6026 | |
c906108c | 6027 | ALL_BREAKPOINTS (b) |
717a8278 | 6028 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6029 | return 1; |
c906108c SS |
6030 | return 0; |
6031 | } | |
6032 | ||
67822962 PA |
6033 | int |
6034 | bpstat_causes_stop (bpstat bs) | |
6035 | { | |
6036 | for (; bs != NULL; bs = bs->next) | |
6037 | if (bs->stop) | |
6038 | return 1; | |
6039 | ||
6040 | return 0; | |
6041 | } | |
6042 | ||
c906108c | 6043 | \f |
c5aa993b | 6044 | |
170b53b2 UW |
6045 | /* Compute a string of spaces suitable to indent the next line |
6046 | so it starts at the position corresponding to the table column | |
6047 | named COL_NAME in the currently active table of UIOUT. */ | |
6048 | ||
6049 | static char * | |
6050 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6051 | { | |
6052 | static char wrap_indent[80]; | |
6053 | int i, total_width, width, align; | |
c5209615 | 6054 | const char *text; |
170b53b2 UW |
6055 | |
6056 | total_width = 0; | |
112e8700 | 6057 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
6058 | { |
6059 | if (strcmp (text, col_name) == 0) | |
6060 | { | |
6061 | gdb_assert (total_width < sizeof wrap_indent); | |
6062 | memset (wrap_indent, ' ', total_width); | |
6063 | wrap_indent[total_width] = 0; | |
6064 | ||
6065 | return wrap_indent; | |
6066 | } | |
6067 | ||
6068 | total_width += width + 1; | |
6069 | } | |
6070 | ||
6071 | return NULL; | |
6072 | } | |
6073 | ||
b775012e LM |
6074 | /* Determine if the locations of this breakpoint will have their conditions |
6075 | evaluated by the target, host or a mix of both. Returns the following: | |
6076 | ||
6077 | "host": Host evals condition. | |
6078 | "host or target": Host or Target evals condition. | |
6079 | "target": Target evals condition. | |
6080 | */ | |
6081 | ||
6082 | static const char * | |
6083 | bp_condition_evaluator (struct breakpoint *b) | |
6084 | { | |
6085 | struct bp_location *bl; | |
6086 | char host_evals = 0; | |
6087 | char target_evals = 0; | |
6088 | ||
6089 | if (!b) | |
6090 | return NULL; | |
6091 | ||
6092 | if (!is_breakpoint (b)) | |
6093 | return NULL; | |
6094 | ||
6095 | if (gdb_evaluates_breakpoint_condition_p () | |
6096 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6097 | return condition_evaluation_host; | |
6098 | ||
6099 | for (bl = b->loc; bl; bl = bl->next) | |
6100 | { | |
6101 | if (bl->cond_bytecode) | |
6102 | target_evals++; | |
6103 | else | |
6104 | host_evals++; | |
6105 | } | |
6106 | ||
6107 | if (host_evals && target_evals) | |
6108 | return condition_evaluation_both; | |
6109 | else if (target_evals) | |
6110 | return condition_evaluation_target; | |
6111 | else | |
6112 | return condition_evaluation_host; | |
6113 | } | |
6114 | ||
6115 | /* Determine the breakpoint location's condition evaluator. This is | |
6116 | similar to bp_condition_evaluator, but for locations. */ | |
6117 | ||
6118 | static const char * | |
6119 | bp_location_condition_evaluator (struct bp_location *bl) | |
6120 | { | |
6121 | if (bl && !is_breakpoint (bl->owner)) | |
6122 | return NULL; | |
6123 | ||
6124 | if (gdb_evaluates_breakpoint_condition_p () | |
6125 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6126 | return condition_evaluation_host; | |
6127 | ||
6128 | if (bl && bl->cond_bytecode) | |
6129 | return condition_evaluation_target; | |
6130 | else | |
6131 | return condition_evaluation_host; | |
6132 | } | |
6133 | ||
859825b8 JK |
6134 | /* Print the LOC location out of the list of B->LOC locations. */ |
6135 | ||
170b53b2 UW |
6136 | static void |
6137 | print_breakpoint_location (struct breakpoint *b, | |
6138 | struct bp_location *loc) | |
0d381245 | 6139 | { |
79a45e25 | 6140 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6141 | struct cleanup *old_chain = save_current_program_space (); |
6142 | ||
859825b8 JK |
6143 | if (loc != NULL && loc->shlib_disabled) |
6144 | loc = NULL; | |
6145 | ||
6c95b8df PA |
6146 | if (loc != NULL) |
6147 | set_current_program_space (loc->pspace); | |
6148 | ||
56435ebe | 6149 | if (b->display_canonical) |
d28cd78a | 6150 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 6151 | else if (loc && loc->symtab) |
0d381245 VP |
6152 | { |
6153 | struct symbol *sym | |
6154 | = find_pc_sect_function (loc->address, loc->section); | |
6155 | if (sym) | |
6156 | { | |
112e8700 SM |
6157 | uiout->text ("in "); |
6158 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); | |
6159 | uiout->text (" "); | |
6160 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
6161 | uiout->text ("at "); | |
0d381245 | 6162 | } |
112e8700 | 6163 | uiout->field_string ("file", |
05cba821 | 6164 | symtab_to_filename_for_display (loc->symtab)); |
112e8700 | 6165 | uiout->text (":"); |
05cba821 | 6166 | |
112e8700 SM |
6167 | if (uiout->is_mi_like_p ()) |
6168 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 6169 | |
112e8700 | 6170 | uiout->field_int ("line", loc->line_number); |
0d381245 | 6171 | } |
859825b8 | 6172 | else if (loc) |
0d381245 | 6173 | { |
d7e74731 | 6174 | string_file stb; |
170b53b2 | 6175 | |
d7e74731 | 6176 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 6177 | demangle, ""); |
112e8700 | 6178 | uiout->field_stream ("at", stb); |
0d381245 | 6179 | } |
859825b8 | 6180 | else |
f00aae0f | 6181 | { |
d28cd78a TT |
6182 | uiout->field_string ("pending", |
6183 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
6184 | /* If extra_string is available, it could be holding a condition |
6185 | or dprintf arguments. In either case, make sure it is printed, | |
6186 | too, but only for non-MI streams. */ | |
112e8700 | 6187 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
6188 | { |
6189 | if (b->type == bp_dprintf) | |
112e8700 | 6190 | uiout->text (","); |
f00aae0f | 6191 | else |
112e8700 SM |
6192 | uiout->text (" "); |
6193 | uiout->text (b->extra_string); | |
f00aae0f KS |
6194 | } |
6195 | } | |
6c95b8df | 6196 | |
b775012e LM |
6197 | if (loc && is_breakpoint (b) |
6198 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6199 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6200 | { | |
112e8700 SM |
6201 | uiout->text (" ("); |
6202 | uiout->field_string ("evaluated-by", | |
b775012e | 6203 | bp_location_condition_evaluator (loc)); |
112e8700 | 6204 | uiout->text (")"); |
b775012e LM |
6205 | } |
6206 | ||
6c95b8df | 6207 | do_cleanups (old_chain); |
0d381245 VP |
6208 | } |
6209 | ||
269b11a2 PA |
6210 | static const char * |
6211 | bptype_string (enum bptype type) | |
c906108c | 6212 | { |
c4093a6a JM |
6213 | struct ep_type_description |
6214 | { | |
6215 | enum bptype type; | |
a121b7c1 | 6216 | const char *description; |
c4093a6a JM |
6217 | }; |
6218 | static struct ep_type_description bptypes[] = | |
c906108c | 6219 | { |
c5aa993b JM |
6220 | {bp_none, "?deleted?"}, |
6221 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6222 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6223 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6224 | {bp_until, "until"}, |
6225 | {bp_finish, "finish"}, | |
6226 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6227 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6228 | {bp_read_watchpoint, "read watchpoint"}, |
6229 | {bp_access_watchpoint, "acc watchpoint"}, | |
6230 | {bp_longjmp, "longjmp"}, | |
6231 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6232 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6233 | {bp_exception, "exception"}, |
6234 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6235 | {bp_step_resume, "step resume"}, |
2c03e5be | 6236 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6237 | {bp_watchpoint_scope, "watchpoint scope"}, |
6238 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6239 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6240 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6241 | {bp_thread_event, "thread events"}, |
1900040c | 6242 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6243 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6244 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6245 | {bp_exception_master, "exception master"}, |
ce78b96d | 6246 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6247 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6248 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6249 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6250 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6251 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6252 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6253 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6254 | }; |
269b11a2 PA |
6255 | |
6256 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6257 | || ((int) type != bptypes[(int) type].type)) | |
6258 | internal_error (__FILE__, __LINE__, | |
6259 | _("bptypes table does not describe type #%d."), | |
6260 | (int) type); | |
6261 | ||
6262 | return bptypes[(int) type].description; | |
6263 | } | |
6264 | ||
998580f1 MK |
6265 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6266 | For CLI, prefix the list with the string 'inf'. */ | |
6267 | ||
6268 | static void | |
6269 | output_thread_groups (struct ui_out *uiout, | |
6270 | const char *field_name, | |
6271 | VEC(int) *inf_num, | |
6272 | int mi_only) | |
6273 | { | |
752eb8b4 | 6274 | struct cleanup *back_to; |
112e8700 | 6275 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6276 | int inf; |
6277 | int i; | |
6278 | ||
6279 | /* For backward compatibility, don't display inferiors in CLI unless | |
6280 | there are several. Always display them for MI. */ | |
6281 | if (!is_mi && mi_only) | |
6282 | return; | |
6283 | ||
752eb8b4 TT |
6284 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6285 | ||
998580f1 MK |
6286 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6287 | { | |
6288 | if (is_mi) | |
6289 | { | |
6290 | char mi_group[10]; | |
6291 | ||
6292 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
112e8700 | 6293 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6294 | } |
6295 | else | |
6296 | { | |
6297 | if (i == 0) | |
112e8700 | 6298 | uiout->text (" inf "); |
998580f1 | 6299 | else |
112e8700 | 6300 | uiout->text (", "); |
998580f1 | 6301 | |
112e8700 | 6302 | uiout->text (plongest (inf)); |
998580f1 MK |
6303 | } |
6304 | } | |
6305 | ||
6306 | do_cleanups (back_to); | |
6307 | } | |
6308 | ||
269b11a2 PA |
6309 | /* Print B to gdb_stdout. */ |
6310 | ||
6311 | static void | |
6312 | print_one_breakpoint_location (struct breakpoint *b, | |
6313 | struct bp_location *loc, | |
6314 | int loc_number, | |
6315 | struct bp_location **last_loc, | |
269b11a2 PA |
6316 | int allflag) |
6317 | { | |
6318 | struct command_line *l; | |
c2c6d25f | 6319 | static char bpenables[] = "nynny"; |
c906108c | 6320 | |
79a45e25 | 6321 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6322 | int header_of_multiple = 0; |
6323 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6324 | struct value_print_options opts; |
6325 | ||
6326 | get_user_print_options (&opts); | |
0d381245 VP |
6327 | |
6328 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6329 | /* See comment in print_one_breakpoint concerning treatment of |
6330 | breakpoints with single disabled location. */ | |
0d381245 VP |
6331 | if (loc == NULL |
6332 | && (b->loc != NULL | |
6333 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6334 | header_of_multiple = 1; | |
6335 | if (loc == NULL) | |
6336 | loc = b->loc; | |
6337 | ||
c4093a6a JM |
6338 | annotate_record (); |
6339 | ||
6340 | /* 1 */ | |
6341 | annotate_field (0); | |
0d381245 VP |
6342 | if (part_of_multiple) |
6343 | { | |
6344 | char *formatted; | |
0c6773c1 | 6345 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
112e8700 | 6346 | uiout->field_string ("number", formatted); |
0d381245 VP |
6347 | xfree (formatted); |
6348 | } | |
6349 | else | |
6350 | { | |
112e8700 | 6351 | uiout->field_int ("number", b->number); |
0d381245 | 6352 | } |
c4093a6a JM |
6353 | |
6354 | /* 2 */ | |
6355 | annotate_field (1); | |
0d381245 | 6356 | if (part_of_multiple) |
112e8700 | 6357 | uiout->field_skip ("type"); |
269b11a2 | 6358 | else |
112e8700 | 6359 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6360 | |
6361 | /* 3 */ | |
6362 | annotate_field (2); | |
0d381245 | 6363 | if (part_of_multiple) |
112e8700 | 6364 | uiout->field_skip ("disp"); |
0d381245 | 6365 | else |
112e8700 | 6366 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6367 | |
c4093a6a JM |
6368 | |
6369 | /* 4 */ | |
6370 | annotate_field (3); | |
0d381245 | 6371 | if (part_of_multiple) |
112e8700 | 6372 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6373 | else |
112e8700 SM |
6374 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
6375 | uiout->spaces (2); | |
0d381245 | 6376 | |
c4093a6a JM |
6377 | |
6378 | /* 5 and 6 */ | |
3086aeae | 6379 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6380 | { |
4a64f543 MS |
6381 | /* Although the print_one can possibly print all locations, |
6382 | calling it here is not likely to get any nice result. So, | |
6383 | make sure there's just one location. */ | |
0d381245 | 6384 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6385 | b->ops->print_one (b, last_loc); |
0d381245 | 6386 | } |
3086aeae DJ |
6387 | else |
6388 | switch (b->type) | |
6389 | { | |
6390 | case bp_none: | |
6391 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6392 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6393 | break; |
c906108c | 6394 | |
3086aeae DJ |
6395 | case bp_watchpoint: |
6396 | case bp_hardware_watchpoint: | |
6397 | case bp_read_watchpoint: | |
6398 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6399 | { |
6400 | struct watchpoint *w = (struct watchpoint *) b; | |
6401 | ||
6402 | /* Field 4, the address, is omitted (which makes the columns | |
6403 | not line up too nicely with the headers, but the effect | |
6404 | is relatively readable). */ | |
6405 | if (opts.addressprint) | |
112e8700 | 6406 | uiout->field_skip ("addr"); |
3a5c3e22 | 6407 | annotate_field (5); |
112e8700 | 6408 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6409 | } |
3086aeae DJ |
6410 | break; |
6411 | ||
3086aeae DJ |
6412 | case bp_breakpoint: |
6413 | case bp_hardware_breakpoint: | |
7c16b83e | 6414 | case bp_single_step: |
3086aeae DJ |
6415 | case bp_until: |
6416 | case bp_finish: | |
6417 | case bp_longjmp: | |
6418 | case bp_longjmp_resume: | |
e2e4d78b | 6419 | case bp_longjmp_call_dummy: |
186c406b TT |
6420 | case bp_exception: |
6421 | case bp_exception_resume: | |
3086aeae | 6422 | case bp_step_resume: |
2c03e5be | 6423 | case bp_hp_step_resume: |
3086aeae DJ |
6424 | case bp_watchpoint_scope: |
6425 | case bp_call_dummy: | |
aa7d318d | 6426 | case bp_std_terminate: |
3086aeae DJ |
6427 | case bp_shlib_event: |
6428 | case bp_thread_event: | |
6429 | case bp_overlay_event: | |
0fd8e87f | 6430 | case bp_longjmp_master: |
aa7d318d | 6431 | case bp_std_terminate_master: |
186c406b | 6432 | case bp_exception_master: |
1042e4c0 | 6433 | case bp_tracepoint: |
7a697b8d | 6434 | case bp_fast_tracepoint: |
0fb4aa4b | 6435 | case bp_static_tracepoint: |
e7e0cddf | 6436 | case bp_dprintf: |
4efc6507 | 6437 | case bp_jit_event: |
0e30163f JK |
6438 | case bp_gnu_ifunc_resolver: |
6439 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6440 | if (opts.addressprint) |
3086aeae DJ |
6441 | { |
6442 | annotate_field (4); | |
54e52265 | 6443 | if (header_of_multiple) |
112e8700 | 6444 | uiout->field_string ("addr", "<MULTIPLE>"); |
e9bbd7c5 | 6445 | else if (b->loc == NULL || loc->shlib_disabled) |
112e8700 | 6446 | uiout->field_string ("addr", "<PENDING>"); |
0101ce28 | 6447 | else |
112e8700 | 6448 | uiout->field_core_addr ("addr", |
5af949e3 | 6449 | loc->gdbarch, loc->address); |
3086aeae DJ |
6450 | } |
6451 | annotate_field (5); | |
0d381245 | 6452 | if (!header_of_multiple) |
170b53b2 | 6453 | print_breakpoint_location (b, loc); |
0d381245 | 6454 | if (b->loc) |
a6d9a66e | 6455 | *last_loc = b->loc; |
3086aeae DJ |
6456 | break; |
6457 | } | |
c906108c | 6458 | |
6c95b8df | 6459 | |
998580f1 | 6460 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6461 | { |
6462 | struct inferior *inf; | |
998580f1 MK |
6463 | VEC(int) *inf_num = NULL; |
6464 | int mi_only = 1; | |
6c95b8df | 6465 | |
998580f1 | 6466 | ALL_INFERIORS (inf) |
6c95b8df PA |
6467 | { |
6468 | if (inf->pspace == loc->pspace) | |
998580f1 | 6469 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6470 | } |
998580f1 MK |
6471 | |
6472 | /* For backward compatibility, don't display inferiors in CLI unless | |
6473 | there are several. Always display for MI. */ | |
6474 | if (allflag | |
6475 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6476 | && (number_of_program_spaces () > 1 | |
6477 | || number_of_inferiors () > 1) | |
6478 | /* LOC is for existing B, it cannot be in | |
6479 | moribund_locations and thus having NULL OWNER. */ | |
6480 | && loc->owner->type != bp_catchpoint)) | |
6481 | mi_only = 0; | |
6482 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6483 | VEC_free (int, inf_num); | |
6c95b8df PA |
6484 | } |
6485 | ||
4a306c9a | 6486 | if (!part_of_multiple) |
c4093a6a | 6487 | { |
4a306c9a JB |
6488 | if (b->thread != -1) |
6489 | { | |
6490 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6491 | "stop only in" line a little further down. */ |
112e8700 SM |
6492 | uiout->text (" thread "); |
6493 | uiout->field_int ("thread", b->thread); | |
4a306c9a JB |
6494 | } |
6495 | else if (b->task != 0) | |
6496 | { | |
112e8700 SM |
6497 | uiout->text (" task "); |
6498 | uiout->field_int ("task", b->task); | |
4a306c9a | 6499 | } |
c4093a6a | 6500 | } |
f1310107 | 6501 | |
112e8700 | 6502 | uiout->text ("\n"); |
f1310107 | 6503 | |
348d480f | 6504 | if (!part_of_multiple) |
f1310107 TJB |
6505 | b->ops->print_one_detail (b, uiout); |
6506 | ||
0d381245 | 6507 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6508 | { |
6509 | annotate_field (6); | |
112e8700 | 6510 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6511 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6512 | the frame ID. */ |
112e8700 | 6513 | uiout->field_core_addr ("frame", |
5af949e3 | 6514 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6515 | uiout->text ("\n"); |
c4093a6a JM |
6516 | } |
6517 | ||
28010a5d | 6518 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6519 | { |
6520 | annotate_field (7); | |
d77f58be | 6521 | if (is_tracepoint (b)) |
112e8700 | 6522 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6523 | else |
112e8700 SM |
6524 | uiout->text ("\tstop only if "); |
6525 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6526 | |
6527 | /* Print whether the target is doing the breakpoint's condition | |
6528 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6529 | if (is_breakpoint (b) | |
6530 | && breakpoint_condition_evaluation_mode () | |
6531 | == condition_evaluation_target) | |
6532 | { | |
112e8700 SM |
6533 | uiout->text (" ("); |
6534 | uiout->field_string ("evaluated-by", | |
b775012e | 6535 | bp_condition_evaluator (b)); |
112e8700 | 6536 | uiout->text (" evals)"); |
b775012e | 6537 | } |
112e8700 | 6538 | uiout->text ("\n"); |
0101ce28 JJ |
6539 | } |
6540 | ||
0d381245 | 6541 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6542 | { |
4a64f543 | 6543 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6544 | uiout->text ("\tstop only in thread "); |
6545 | if (uiout->is_mi_like_p ()) | |
6546 | uiout->field_int ("thread", b->thread); | |
5d5658a1 PA |
6547 | else |
6548 | { | |
6549 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6550 | ||
112e8700 | 6551 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6552 | } |
112e8700 | 6553 | uiout->text ("\n"); |
c4093a6a JM |
6554 | } |
6555 | ||
556ec64d YQ |
6556 | if (!part_of_multiple) |
6557 | { | |
6558 | if (b->hit_count) | |
31f56a27 YQ |
6559 | { |
6560 | /* FIXME should make an annotation for this. */ | |
6561 | if (is_catchpoint (b)) | |
112e8700 | 6562 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6563 | else if (is_tracepoint (b)) |
112e8700 | 6564 | uiout->text ("\ttracepoint"); |
31f56a27 | 6565 | else |
112e8700 SM |
6566 | uiout->text ("\tbreakpoint"); |
6567 | uiout->text (" already hit "); | |
6568 | uiout->field_int ("times", b->hit_count); | |
31f56a27 | 6569 | if (b->hit_count == 1) |
112e8700 | 6570 | uiout->text (" time\n"); |
31f56a27 | 6571 | else |
112e8700 | 6572 | uiout->text (" times\n"); |
31f56a27 | 6573 | } |
556ec64d YQ |
6574 | else |
6575 | { | |
31f56a27 | 6576 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 SM |
6577 | if (uiout->is_mi_like_p ()) |
6578 | uiout->field_int ("times", b->hit_count); | |
556ec64d YQ |
6579 | } |
6580 | } | |
8b93c638 | 6581 | |
0d381245 | 6582 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6583 | { |
6584 | annotate_field (8); | |
112e8700 SM |
6585 | uiout->text ("\tignore next "); |
6586 | uiout->field_int ("ignore", b->ignore_count); | |
6587 | uiout->text (" hits\n"); | |
c4093a6a | 6588 | } |
059fb39f | 6589 | |
816338b5 SS |
6590 | /* Note that an enable count of 1 corresponds to "enable once" |
6591 | behavior, which is reported by the combination of enablement and | |
6592 | disposition, so we don't need to mention it here. */ | |
6593 | if (!part_of_multiple && b->enable_count > 1) | |
6594 | { | |
6595 | annotate_field (8); | |
112e8700 | 6596 | uiout->text ("\tdisable after "); |
816338b5 SS |
6597 | /* Tweak the wording to clarify that ignore and enable counts |
6598 | are distinct, and have additive effect. */ | |
6599 | if (b->ignore_count) | |
112e8700 | 6600 | uiout->text ("additional "); |
816338b5 | 6601 | else |
112e8700 SM |
6602 | uiout->text ("next "); |
6603 | uiout->field_int ("enable", b->enable_count); | |
6604 | uiout->text (" hits\n"); | |
816338b5 SS |
6605 | } |
6606 | ||
f196051f SS |
6607 | if (!part_of_multiple && is_tracepoint (b)) |
6608 | { | |
6609 | struct tracepoint *tp = (struct tracepoint *) b; | |
6610 | ||
6611 | if (tp->traceframe_usage) | |
6612 | { | |
112e8700 SM |
6613 | uiout->text ("\ttrace buffer usage "); |
6614 | uiout->field_int ("traceframe-usage", tp->traceframe_usage); | |
6615 | uiout->text (" bytes\n"); | |
f196051f SS |
6616 | } |
6617 | } | |
d3ce09f5 | 6618 | |
9add0f1b | 6619 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6620 | if (!part_of_multiple && l) |
c4093a6a JM |
6621 | { |
6622 | annotate_field (9); | |
2e783024 | 6623 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6624 | print_command_lines (uiout, l, 4); |
c4093a6a | 6625 | } |
d24317b4 | 6626 | |
d9b3f62e | 6627 | if (is_tracepoint (b)) |
1042e4c0 | 6628 | { |
d9b3f62e PA |
6629 | struct tracepoint *t = (struct tracepoint *) b; |
6630 | ||
6631 | if (!part_of_multiple && t->pass_count) | |
6632 | { | |
6633 | annotate_field (10); | |
112e8700 SM |
6634 | uiout->text ("\tpass count "); |
6635 | uiout->field_int ("pass", t->pass_count); | |
6636 | uiout->text (" \n"); | |
d9b3f62e | 6637 | } |
f2a8bc8a YQ |
6638 | |
6639 | /* Don't display it when tracepoint or tracepoint location is | |
6640 | pending. */ | |
6641 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6642 | { | |
6643 | annotate_field (11); | |
6644 | ||
112e8700 SM |
6645 | if (uiout->is_mi_like_p ()) |
6646 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6647 | loc->inserted ? "y" : "n"); |
6648 | else | |
6649 | { | |
6650 | if (loc->inserted) | |
112e8700 | 6651 | uiout->text ("\t"); |
f2a8bc8a | 6652 | else |
112e8700 SM |
6653 | uiout->text ("\tnot "); |
6654 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6655 | } |
6656 | } | |
1042e4c0 SS |
6657 | } |
6658 | ||
112e8700 | 6659 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6660 | { |
3a5c3e22 PA |
6661 | if (is_watchpoint (b)) |
6662 | { | |
6663 | struct watchpoint *w = (struct watchpoint *) b; | |
6664 | ||
112e8700 | 6665 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6666 | } |
f00aae0f | 6667 | else if (b->location != NULL |
d28cd78a | 6668 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6669 | uiout->field_string ("original-location", |
d28cd78a | 6670 | event_location_to_string (b->location.get ())); |
d24317b4 | 6671 | } |
c4093a6a | 6672 | } |
c5aa993b | 6673 | |
0d381245 VP |
6674 | static void |
6675 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6676 | struct bp_location **last_loc, |
6c95b8df | 6677 | int allflag) |
0d381245 | 6678 | { |
79a45e25 | 6679 | struct ui_out *uiout = current_uiout; |
8d3788bd | 6680 | |
2e783024 TT |
6681 | { |
6682 | ui_out_emit_tuple tuple_emitter (uiout, "bkpt"); | |
8d3788bd | 6683 | |
2e783024 TT |
6684 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
6685 | } | |
0d381245 VP |
6686 | |
6687 | /* If this breakpoint has custom print function, | |
6688 | it's already printed. Otherwise, print individual | |
6689 | locations, if any. */ | |
6690 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6691 | { | |
4a64f543 MS |
6692 | /* If breakpoint has a single location that is disabled, we |
6693 | print it as if it had several locations, since otherwise it's | |
6694 | hard to represent "breakpoint enabled, location disabled" | |
6695 | situation. | |
6696 | ||
6697 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6698 | internally, that's not a property exposed to user. */ |
0d381245 | 6699 | if (b->loc |
a5606eee | 6700 | && !is_hardware_watchpoint (b) |
8d3788bd | 6701 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6702 | { |
6703 | struct bp_location *loc; | |
6704 | int n = 1; | |
8d3788bd | 6705 | |
0d381245 | 6706 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd | 6707 | { |
2e783024 | 6708 | ui_out_emit_tuple tuple_emitter (uiout, NULL); |
8d3788bd | 6709 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
8d3788bd | 6710 | } |
0d381245 VP |
6711 | } |
6712 | } | |
6713 | } | |
6714 | ||
a6d9a66e UW |
6715 | static int |
6716 | breakpoint_address_bits (struct breakpoint *b) | |
6717 | { | |
6718 | int print_address_bits = 0; | |
6719 | struct bp_location *loc; | |
6720 | ||
c6d81124 PA |
6721 | /* Software watchpoints that aren't watching memory don't have an |
6722 | address to print. */ | |
6723 | if (is_no_memory_software_watchpoint (b)) | |
6724 | return 0; | |
6725 | ||
a6d9a66e UW |
6726 | for (loc = b->loc; loc; loc = loc->next) |
6727 | { | |
c7437ca6 PA |
6728 | int addr_bit; |
6729 | ||
c7437ca6 | 6730 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6731 | if (addr_bit > print_address_bits) |
6732 | print_address_bits = addr_bit; | |
6733 | } | |
6734 | ||
6735 | return print_address_bits; | |
6736 | } | |
0d381245 | 6737 | |
c4093a6a JM |
6738 | struct captured_breakpoint_query_args |
6739 | { | |
6740 | int bnum; | |
6741 | }; | |
c5aa993b | 6742 | |
c4093a6a | 6743 | static int |
2b65245e | 6744 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6745 | { |
9a3c8263 SM |
6746 | struct captured_breakpoint_query_args *args |
6747 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6748 | struct breakpoint *b; |
a6d9a66e | 6749 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6750 | |
c4093a6a JM |
6751 | ALL_BREAKPOINTS (b) |
6752 | { | |
6753 | if (args->bnum == b->number) | |
c5aa993b | 6754 | { |
12c5a436 | 6755 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6756 | return GDB_RC_OK; |
c5aa993b | 6757 | } |
c4093a6a JM |
6758 | } |
6759 | return GDB_RC_NONE; | |
6760 | } | |
c5aa993b | 6761 | |
c4093a6a | 6762 | enum gdb_rc |
4a64f543 MS |
6763 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6764 | char **error_message) | |
c4093a6a JM |
6765 | { |
6766 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6767 | |
c4093a6a JM |
6768 | args.bnum = bnum; |
6769 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6770 | an error. */ |
b0b13bb4 DJ |
6771 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6772 | error_message, RETURN_MASK_ALL) < 0) | |
6773 | return GDB_RC_FAIL; | |
6774 | else | |
6775 | return GDB_RC_OK; | |
c4093a6a | 6776 | } |
c5aa993b | 6777 | |
09d682a4 TT |
6778 | /* Return true if this breakpoint was set by the user, false if it is |
6779 | internal or momentary. */ | |
6780 | ||
6781 | int | |
6782 | user_breakpoint_p (struct breakpoint *b) | |
6783 | { | |
46c6471b | 6784 | return b->number > 0; |
09d682a4 TT |
6785 | } |
6786 | ||
93daf339 TT |
6787 | /* See breakpoint.h. */ |
6788 | ||
6789 | int | |
6790 | pending_breakpoint_p (struct breakpoint *b) | |
6791 | { | |
6792 | return b->loc == NULL; | |
6793 | } | |
6794 | ||
7f3b0473 | 6795 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6796 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6797 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6798 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6799 | ones for which it returns non-zero. Return the total number of | |
6800 | breakpoints listed. */ | |
c906108c | 6801 | |
d77f58be | 6802 | static int |
e5a67952 | 6803 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6804 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6805 | { |
52f0bd74 | 6806 | struct breakpoint *b; |
a6d9a66e | 6807 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6808 | int nr_printable_breakpoints; |
3b31d625 | 6809 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6810 | struct value_print_options opts; |
a6d9a66e | 6811 | int print_address_bits = 0; |
269b11a2 | 6812 | int print_type_col_width = 14; |
79a45e25 | 6813 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6814 | |
79a45b7d TT |
6815 | get_user_print_options (&opts); |
6816 | ||
4a64f543 MS |
6817 | /* Compute the number of rows in the table, as well as the size |
6818 | required for address fields. */ | |
7f3b0473 AC |
6819 | nr_printable_breakpoints = 0; |
6820 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6821 | { |
6822 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6823 | if (filter && !filter (b)) | |
6824 | continue; | |
6825 | ||
6826 | /* If we have an "args" string, it is a list of breakpoints to | |
6827 | accept. Skip the others. */ | |
6828 | if (args != NULL && *args != '\0') | |
6829 | { | |
6830 | if (allflag && parse_and_eval_long (args) != b->number) | |
6831 | continue; | |
6832 | if (!allflag && !number_is_in_list (args, b->number)) | |
6833 | continue; | |
6834 | } | |
269b11a2 | 6835 | |
e5a67952 MS |
6836 | if (allflag || user_breakpoint_p (b)) |
6837 | { | |
6838 | int addr_bit, type_len; | |
a6d9a66e | 6839 | |
e5a67952 MS |
6840 | addr_bit = breakpoint_address_bits (b); |
6841 | if (addr_bit > print_address_bits) | |
6842 | print_address_bits = addr_bit; | |
269b11a2 | 6843 | |
e5a67952 MS |
6844 | type_len = strlen (bptype_string (b->type)); |
6845 | if (type_len > print_type_col_width) | |
6846 | print_type_col_width = type_len; | |
6847 | ||
6848 | nr_printable_breakpoints++; | |
6849 | } | |
6850 | } | |
7f3b0473 | 6851 | |
79a45b7d | 6852 | if (opts.addressprint) |
3b31d625 | 6853 | bkpttbl_chain |
3e43a32a MS |
6854 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6855 | nr_printable_breakpoints, | |
3b31d625 | 6856 | "BreakpointTable"); |
8b93c638 | 6857 | else |
3b31d625 | 6858 | bkpttbl_chain |
3e43a32a MS |
6859 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6860 | nr_printable_breakpoints, | |
3b31d625 | 6861 | "BreakpointTable"); |
8b93c638 | 6862 | |
7f3b0473 | 6863 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6864 | annotate_breakpoints_headers (); |
6865 | if (nr_printable_breakpoints > 0) | |
6866 | annotate_field (0); | |
112e8700 | 6867 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6868 | if (nr_printable_breakpoints > 0) |
6869 | annotate_field (1); | |
112e8700 | 6870 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6871 | if (nr_printable_breakpoints > 0) |
6872 | annotate_field (2); | |
112e8700 | 6873 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6874 | if (nr_printable_breakpoints > 0) |
6875 | annotate_field (3); | |
112e8700 | 6876 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6877 | if (opts.addressprint) |
e5a67952 MS |
6878 | { |
6879 | if (nr_printable_breakpoints > 0) | |
6880 | annotate_field (4); | |
6881 | if (print_address_bits <= 32) | |
112e8700 | 6882 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ |
e5a67952 | 6883 | else |
112e8700 | 6884 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ |
e5a67952 | 6885 | } |
d7faa9e7 AC |
6886 | if (nr_printable_breakpoints > 0) |
6887 | annotate_field (5); | |
112e8700 SM |
6888 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ |
6889 | uiout->table_body (); | |
d7faa9e7 AC |
6890 | if (nr_printable_breakpoints > 0) |
6891 | annotate_breakpoints_table (); | |
7f3b0473 | 6892 | |
c4093a6a | 6893 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6894 | { |
6895 | QUIT; | |
6896 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6897 | if (filter && !filter (b)) | |
6898 | continue; | |
6899 | ||
6900 | /* If we have an "args" string, it is a list of breakpoints to | |
6901 | accept. Skip the others. */ | |
6902 | ||
6903 | if (args != NULL && *args != '\0') | |
6904 | { | |
6905 | if (allflag) /* maintenance info breakpoint */ | |
6906 | { | |
6907 | if (parse_and_eval_long (args) != b->number) | |
6908 | continue; | |
6909 | } | |
6910 | else /* all others */ | |
6911 | { | |
6912 | if (!number_is_in_list (args, b->number)) | |
6913 | continue; | |
6914 | } | |
6915 | } | |
6916 | /* We only print out user settable breakpoints unless the | |
6917 | allflag is set. */ | |
6918 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6919 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6920 | } |
6921 | ||
3b31d625 | 6922 | do_cleanups (bkpttbl_chain); |
698384cd | 6923 | |
7f3b0473 | 6924 | if (nr_printable_breakpoints == 0) |
c906108c | 6925 | { |
4a64f543 MS |
6926 | /* If there's a filter, let the caller decide how to report |
6927 | empty list. */ | |
d77f58be SS |
6928 | if (!filter) |
6929 | { | |
e5a67952 | 6930 | if (args == NULL || *args == '\0') |
112e8700 | 6931 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6932 | else |
112e8700 | 6933 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
e5a67952 | 6934 | args); |
d77f58be | 6935 | } |
c906108c SS |
6936 | } |
6937 | else | |
c4093a6a | 6938 | { |
a6d9a66e UW |
6939 | if (last_loc && !server_command) |
6940 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6941 | } |
c906108c | 6942 | |
4a64f543 | 6943 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6944 | there have been breakpoints? */ |
c906108c | 6945 | annotate_breakpoints_table_end (); |
d77f58be SS |
6946 | |
6947 | return nr_printable_breakpoints; | |
c906108c SS |
6948 | } |
6949 | ||
ad443146 SS |
6950 | /* Display the value of default-collect in a way that is generally |
6951 | compatible with the breakpoint list. */ | |
6952 | ||
6953 | static void | |
6954 | default_collect_info (void) | |
6955 | { | |
79a45e25 PA |
6956 | struct ui_out *uiout = current_uiout; |
6957 | ||
ad443146 SS |
6958 | /* If it has no value (which is frequently the case), say nothing; a |
6959 | message like "No default-collect." gets in user's face when it's | |
6960 | not wanted. */ | |
6961 | if (!*default_collect) | |
6962 | return; | |
6963 | ||
6964 | /* The following phrase lines up nicely with per-tracepoint collect | |
6965 | actions. */ | |
112e8700 SM |
6966 | uiout->text ("default collect "); |
6967 | uiout->field_string ("default-collect", default_collect); | |
6968 | uiout->text (" \n"); | |
ad443146 SS |
6969 | } |
6970 | ||
c906108c | 6971 | static void |
e5a67952 | 6972 | breakpoints_info (char *args, int from_tty) |
c906108c | 6973 | { |
e5a67952 | 6974 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6975 | |
6976 | default_collect_info (); | |
d77f58be SS |
6977 | } |
6978 | ||
6979 | static void | |
e5a67952 | 6980 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6981 | { |
e5a67952 | 6982 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6983 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6984 | |
6985 | if (num_printed == 0) | |
6986 | { | |
e5a67952 | 6987 | if (args == NULL || *args == '\0') |
112e8700 | 6988 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6989 | else |
112e8700 | 6990 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6991 | } |
c906108c SS |
6992 | } |
6993 | ||
7a292a7a | 6994 | static void |
e5a67952 | 6995 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6996 | { |
e5a67952 | 6997 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6998 | |
6999 | default_collect_info (); | |
c906108c SS |
7000 | } |
7001 | ||
0d381245 | 7002 | static int |
714835d5 | 7003 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7004 | struct program_space *pspace, |
714835d5 | 7005 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7006 | { |
7007 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7008 | |
0d381245 VP |
7009 | for (; bl; bl = bl->next) |
7010 | { | |
6c95b8df PA |
7011 | if (bl->pspace == pspace |
7012 | && bl->address == pc | |
0d381245 VP |
7013 | && (!overlay_debugging || bl->section == section)) |
7014 | return 1; | |
7015 | } | |
7016 | return 0; | |
7017 | } | |
7018 | ||
672f9b60 | 7019 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7020 | concerns with logical breakpoints, so we match program spaces, not |
7021 | address spaces. */ | |
c906108c SS |
7022 | |
7023 | static void | |
6c95b8df PA |
7024 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7025 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7026 | struct obj_section *section, int thread) |
c906108c | 7027 | { |
52f0bd74 AC |
7028 | int others = 0; |
7029 | struct breakpoint *b; | |
c906108c SS |
7030 | |
7031 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7032 | others += (user_breakpoint_p (b) |
7033 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7034 | if (others > 0) |
7035 | { | |
a3f17187 AC |
7036 | if (others == 1) |
7037 | printf_filtered (_("Note: breakpoint ")); | |
7038 | else /* if (others == ???) */ | |
7039 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7040 | ALL_BREAKPOINTS (b) |
672f9b60 | 7041 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7042 | { |
7043 | others--; | |
7044 | printf_filtered ("%d", b->number); | |
7045 | if (b->thread == -1 && thread != -1) | |
7046 | printf_filtered (" (all threads)"); | |
7047 | else if (b->thread != -1) | |
7048 | printf_filtered (" (thread %d)", b->thread); | |
7049 | printf_filtered ("%s%s ", | |
059fb39f | 7050 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7051 | || b->enable_state == bp_call_disabled) |
0d381245 | 7052 | ? " (disabled)" |
0d381245 VP |
7053 | : ""), |
7054 | (others > 1) ? "," | |
7055 | : ((others == 1) ? " and" : "")); | |
7056 | } | |
a3f17187 | 7057 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7058 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7059 | printf_filtered (".\n"); |
7060 | } | |
7061 | } | |
7062 | \f | |
c906108c | 7063 | |
e4f237da | 7064 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7065 | BPT locations. For some breakpoint types, the locations' address members |
7066 | are irrelevant and it makes no sense to attempt to compare them to other | |
7067 | addresses (or use them for any other purpose either). | |
e4f237da | 7068 | |
4a64f543 | 7069 | More specifically, each of the following breakpoint types will |
244558af | 7070 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7071 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7072 | breakpoint location at address zero: |
e4f237da KB |
7073 | |
7074 | bp_watchpoint | |
2d134ed3 PA |
7075 | bp_catchpoint |
7076 | ||
7077 | */ | |
e4f237da KB |
7078 | |
7079 | static int | |
7080 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7081 | { | |
7082 | enum bptype type = bpt->type; | |
7083 | ||
2d134ed3 PA |
7084 | return (type != bp_watchpoint && type != bp_catchpoint); |
7085 | } | |
7086 | ||
7087 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7088 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7089 | ||
7090 | static int | |
4a64f543 MS |
7091 | watchpoint_locations_match (struct bp_location *loc1, |
7092 | struct bp_location *loc2) | |
2d134ed3 | 7093 | { |
3a5c3e22 PA |
7094 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7095 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7096 | ||
7097 | /* Both of them must exist. */ | |
7098 | gdb_assert (w1 != NULL); | |
7099 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7100 | |
4a64f543 MS |
7101 | /* If the target can evaluate the condition expression in hardware, |
7102 | then we we need to insert both watchpoints even if they are at | |
7103 | the same place. Otherwise the watchpoint will only trigger when | |
7104 | the condition of whichever watchpoint was inserted evaluates to | |
7105 | true, not giving a chance for GDB to check the condition of the | |
7106 | other watchpoint. */ | |
3a5c3e22 | 7107 | if ((w1->cond_exp |
4a64f543 MS |
7108 | && target_can_accel_watchpoint_condition (loc1->address, |
7109 | loc1->length, | |
0cf6dd15 | 7110 | loc1->watchpoint_type, |
4d01a485 | 7111 | w1->cond_exp.get ())) |
3a5c3e22 | 7112 | || (w2->cond_exp |
4a64f543 MS |
7113 | && target_can_accel_watchpoint_condition (loc2->address, |
7114 | loc2->length, | |
0cf6dd15 | 7115 | loc2->watchpoint_type, |
4d01a485 | 7116 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
7117 | return 0; |
7118 | ||
85d721b8 PA |
7119 | /* Note that this checks the owner's type, not the location's. In |
7120 | case the target does not support read watchpoints, but does | |
7121 | support access watchpoints, we'll have bp_read_watchpoint | |
7122 | watchpoints with hw_access locations. Those should be considered | |
7123 | duplicates of hw_read locations. The hw_read locations will | |
7124 | become hw_access locations later. */ | |
2d134ed3 PA |
7125 | return (loc1->owner->type == loc2->owner->type |
7126 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7127 | && loc1->address == loc2->address | |
7128 | && loc1->length == loc2->length); | |
e4f237da KB |
7129 | } |
7130 | ||
31e77af2 | 7131 | /* See breakpoint.h. */ |
6c95b8df | 7132 | |
31e77af2 | 7133 | int |
6c95b8df PA |
7134 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7135 | struct address_space *aspace2, CORE_ADDR addr2) | |
7136 | { | |
f5656ead | 7137 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7138 | || aspace1 == aspace2) |
7139 | && addr1 == addr2); | |
7140 | } | |
7141 | ||
f1310107 TJB |
7142 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7143 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7144 | matches ASPACE2. On targets that have global breakpoints, the address | |
7145 | space doesn't really matter. */ | |
7146 | ||
7147 | static int | |
7148 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7149 | int len1, struct address_space *aspace2, | |
7150 | CORE_ADDR addr2) | |
7151 | { | |
f5656ead | 7152 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7153 | || aspace1 == aspace2) |
7154 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7155 | } | |
7156 | ||
7157 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7158 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7159 | matches the breakpoint's address space. On targets that have global | |
7160 | breakpoints, the address space doesn't really matter. */ | |
7161 | ||
7162 | static int | |
7163 | breakpoint_location_address_match (struct bp_location *bl, | |
7164 | struct address_space *aspace, | |
7165 | CORE_ADDR addr) | |
7166 | { | |
7167 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7168 | aspace, addr) | |
7169 | || (bl->length | |
7170 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7171 | bl->address, bl->length, | |
7172 | aspace, addr))); | |
7173 | } | |
7174 | ||
d35ae833 PA |
7175 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7176 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7177 | match happens only if ASPACE matches the breakpoint's address | |
7178 | space. On targets that have global breakpoints, the address space | |
7179 | doesn't really matter. */ | |
7180 | ||
7181 | static int | |
7182 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7183 | struct address_space *aspace, | |
7184 | CORE_ADDR addr, int len) | |
7185 | { | |
7186 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7187 | || bl->pspace->aspace == aspace) | |
7188 | { | |
7189 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7190 | ||
7191 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7192 | return 1; | |
7193 | } | |
7194 | return 0; | |
7195 | } | |
7196 | ||
1e4d1764 YQ |
7197 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7198 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7199 | true, otherwise returns false. */ | |
7200 | ||
7201 | static int | |
7202 | tracepoint_locations_match (struct bp_location *loc1, | |
7203 | struct bp_location *loc2) | |
7204 | { | |
7205 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7206 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7207 | locations at the same address of different tracepoints are regarded as | |
7208 | different locations. */ | |
7209 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7210 | else | |
7211 | return 0; | |
7212 | } | |
7213 | ||
2d134ed3 PA |
7214 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7215 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7216 | represent the same location. */ | |
7217 | ||
7218 | static int | |
4a64f543 MS |
7219 | breakpoint_locations_match (struct bp_location *loc1, |
7220 | struct bp_location *loc2) | |
2d134ed3 | 7221 | { |
2bdf28a0 JK |
7222 | int hw_point1, hw_point2; |
7223 | ||
7224 | /* Both of them must not be in moribund_locations. */ | |
7225 | gdb_assert (loc1->owner != NULL); | |
7226 | gdb_assert (loc2->owner != NULL); | |
7227 | ||
7228 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7229 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7230 | |
7231 | if (hw_point1 != hw_point2) | |
7232 | return 0; | |
7233 | else if (hw_point1) | |
7234 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7235 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7236 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7237 | else |
f1310107 TJB |
7238 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7239 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7240 | loc2->pspace->aspace, loc2->address) | |
7241 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7242 | } |
7243 | ||
76897487 KB |
7244 | static void |
7245 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7246 | int bnum, int have_bnum) | |
7247 | { | |
f63fbe86 MS |
7248 | /* The longest string possibly returned by hex_string_custom |
7249 | is 50 chars. These must be at least that big for safety. */ | |
7250 | char astr1[64]; | |
7251 | char astr2[64]; | |
76897487 | 7252 | |
bb599908 PH |
7253 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7254 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7255 | if (have_bnum) |
8a3fe4f8 | 7256 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7257 | bnum, astr1, astr2); |
7258 | else | |
8a3fe4f8 | 7259 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7260 | } |
7261 | ||
4a64f543 MS |
7262 | /* Adjust a breakpoint's address to account for architectural |
7263 | constraints on breakpoint placement. Return the adjusted address. | |
7264 | Note: Very few targets require this kind of adjustment. For most | |
7265 | targets, this function is simply the identity function. */ | |
76897487 KB |
7266 | |
7267 | static CORE_ADDR | |
a6d9a66e UW |
7268 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7269 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7270 | { |
a6d9a66e | 7271 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7272 | { |
7273 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7274 | return bpaddr; | |
7275 | } | |
88f7da05 KB |
7276 | else if (bptype == bp_watchpoint |
7277 | || bptype == bp_hardware_watchpoint | |
7278 | || bptype == bp_read_watchpoint | |
7279 | || bptype == bp_access_watchpoint | |
fe798b75 | 7280 | || bptype == bp_catchpoint) |
88f7da05 KB |
7281 | { |
7282 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7283 | have their addresses modified. */ | |
7284 | return bpaddr; | |
7285 | } | |
7c16b83e PA |
7286 | else if (bptype == bp_single_step) |
7287 | { | |
7288 | /* Single-step breakpoints should not have their addresses | |
7289 | modified. If there's any architectural constrain that | |
7290 | applies to this address, then it should have already been | |
7291 | taken into account when the breakpoint was created in the | |
7292 | first place. If we didn't do this, stepping through e.g., | |
7293 | Thumb-2 IT blocks would break. */ | |
7294 | return bpaddr; | |
7295 | } | |
76897487 KB |
7296 | else |
7297 | { | |
7298 | CORE_ADDR adjusted_bpaddr; | |
7299 | ||
7300 | /* Some targets have architectural constraints on the placement | |
7301 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7302 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7303 | |
7304 | /* An adjusted breakpoint address can significantly alter | |
7305 | a user's expectations. Print a warning if an adjustment | |
7306 | is required. */ | |
7307 | if (adjusted_bpaddr != bpaddr) | |
7308 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7309 | ||
7310 | return adjusted_bpaddr; | |
7311 | } | |
7312 | } | |
7313 | ||
28010a5d PA |
7314 | void |
7315 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7316 | struct breakpoint *owner) | |
7cc221ef | 7317 | { |
7cc221ef DJ |
7318 | memset (loc, 0, sizeof (*loc)); |
7319 | ||
348d480f PA |
7320 | gdb_assert (ops != NULL); |
7321 | ||
28010a5d PA |
7322 | loc->ops = ops; |
7323 | loc->owner = owner; | |
b775012e | 7324 | loc->cond_bytecode = NULL; |
0d381245 VP |
7325 | loc->shlib_disabled = 0; |
7326 | loc->enabled = 1; | |
e049a4b5 | 7327 | |
28010a5d | 7328 | switch (owner->type) |
e049a4b5 DJ |
7329 | { |
7330 | case bp_breakpoint: | |
7c16b83e | 7331 | case bp_single_step: |
e049a4b5 DJ |
7332 | case bp_until: |
7333 | case bp_finish: | |
7334 | case bp_longjmp: | |
7335 | case bp_longjmp_resume: | |
e2e4d78b | 7336 | case bp_longjmp_call_dummy: |
186c406b TT |
7337 | case bp_exception: |
7338 | case bp_exception_resume: | |
e049a4b5 | 7339 | case bp_step_resume: |
2c03e5be | 7340 | case bp_hp_step_resume: |
e049a4b5 DJ |
7341 | case bp_watchpoint_scope: |
7342 | case bp_call_dummy: | |
aa7d318d | 7343 | case bp_std_terminate: |
e049a4b5 DJ |
7344 | case bp_shlib_event: |
7345 | case bp_thread_event: | |
7346 | case bp_overlay_event: | |
4efc6507 | 7347 | case bp_jit_event: |
0fd8e87f | 7348 | case bp_longjmp_master: |
aa7d318d | 7349 | case bp_std_terminate_master: |
186c406b | 7350 | case bp_exception_master: |
0e30163f JK |
7351 | case bp_gnu_ifunc_resolver: |
7352 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7353 | case bp_dprintf: |
e049a4b5 | 7354 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7355 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7356 | break; |
7357 | case bp_hardware_breakpoint: | |
7358 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7359 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7360 | break; |
7361 | case bp_hardware_watchpoint: | |
7362 | case bp_read_watchpoint: | |
7363 | case bp_access_watchpoint: | |
7364 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7365 | break; | |
7366 | case bp_watchpoint: | |
ce78b96d | 7367 | case bp_catchpoint: |
15c3d785 PA |
7368 | case bp_tracepoint: |
7369 | case bp_fast_tracepoint: | |
0fb4aa4b | 7370 | case bp_static_tracepoint: |
e049a4b5 DJ |
7371 | loc->loc_type = bp_loc_other; |
7372 | break; | |
7373 | default: | |
e2e0b3e5 | 7374 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7375 | } |
7376 | ||
f431efe5 | 7377 | loc->refc = 1; |
28010a5d PA |
7378 | } |
7379 | ||
7380 | /* Allocate a struct bp_location. */ | |
7381 | ||
7382 | static struct bp_location * | |
7383 | allocate_bp_location (struct breakpoint *bpt) | |
7384 | { | |
348d480f PA |
7385 | return bpt->ops->allocate_location (bpt); |
7386 | } | |
7cc221ef | 7387 | |
f431efe5 PA |
7388 | static void |
7389 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7390 | { |
348d480f | 7391 | loc->ops->dtor (loc); |
4d01a485 | 7392 | delete loc; |
fe3f5fa8 VP |
7393 | } |
7394 | ||
f431efe5 PA |
7395 | /* Increment reference count. */ |
7396 | ||
7397 | static void | |
7398 | incref_bp_location (struct bp_location *bl) | |
7399 | { | |
7400 | ++bl->refc; | |
7401 | } | |
7402 | ||
7403 | /* Decrement reference count. If the reference count reaches 0, | |
7404 | destroy the bp_location. Sets *BLP to NULL. */ | |
7405 | ||
7406 | static void | |
7407 | decref_bp_location (struct bp_location **blp) | |
7408 | { | |
0807b50c PA |
7409 | gdb_assert ((*blp)->refc > 0); |
7410 | ||
f431efe5 PA |
7411 | if (--(*blp)->refc == 0) |
7412 | free_bp_location (*blp); | |
7413 | *blp = NULL; | |
7414 | } | |
7415 | ||
346774a9 | 7416 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7417 | |
346774a9 PA |
7418 | static void |
7419 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7420 | { |
346774a9 | 7421 | struct breakpoint *b1; |
c906108c | 7422 | |
346774a9 PA |
7423 | /* Add this breakpoint to the end of the chain so that a list of |
7424 | breakpoints will come out in order of increasing numbers. */ | |
7425 | ||
7426 | b1 = breakpoint_chain; | |
7427 | if (b1 == 0) | |
7428 | breakpoint_chain = b; | |
7429 | else | |
7430 | { | |
7431 | while (b1->next) | |
7432 | b1 = b1->next; | |
7433 | b1->next = b; | |
7434 | } | |
7435 | } | |
7436 | ||
7437 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7438 | ||
7439 | static void | |
7440 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7441 | struct gdbarch *gdbarch, | |
28010a5d | 7442 | enum bptype bptype, |
c0a91b2b | 7443 | const struct breakpoint_ops *ops) |
346774a9 | 7444 | { |
c906108c | 7445 | memset (b, 0, sizeof (*b)); |
2219d63c | 7446 | |
348d480f PA |
7447 | gdb_assert (ops != NULL); |
7448 | ||
28010a5d | 7449 | b->ops = ops; |
4d28f7a8 | 7450 | b->type = bptype; |
a6d9a66e | 7451 | b->gdbarch = gdbarch; |
c906108c SS |
7452 | b->language = current_language->la_language; |
7453 | b->input_radix = input_radix; | |
7454 | b->thread = -1; | |
b5de0fa7 | 7455 | b->enable_state = bp_enabled; |
c906108c SS |
7456 | b->next = 0; |
7457 | b->silent = 0; | |
7458 | b->ignore_count = 0; | |
7459 | b->commands = NULL; | |
818dd999 | 7460 | b->frame_id = null_frame_id; |
0d381245 | 7461 | b->condition_not_parsed = 0; |
84f4c1fe | 7462 | b->py_bp_object = NULL; |
d0fb5eae | 7463 | b->related_breakpoint = b; |
f00aae0f | 7464 | b->location = NULL; |
346774a9 PA |
7465 | } |
7466 | ||
7467 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7468 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7469 | |
7470 | static struct breakpoint * | |
7471 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7472 | enum bptype bptype, |
c0a91b2b | 7473 | const struct breakpoint_ops *ops) |
346774a9 | 7474 | { |
4d01a485 | 7475 | struct breakpoint *b = new breakpoint (); |
346774a9 | 7476 | |
348d480f | 7477 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7478 | add_to_breakpoint_chain (b); |
0d381245 VP |
7479 | return b; |
7480 | } | |
7481 | ||
0e30163f JK |
7482 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7483 | resolutions should be made as the user specified the location explicitly | |
7484 | enough. */ | |
7485 | ||
0d381245 | 7486 | static void |
0e30163f | 7487 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7488 | { |
2bdf28a0 JK |
7489 | gdb_assert (loc->owner != NULL); |
7490 | ||
0d381245 | 7491 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7492 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7493 | || is_tracepoint (loc->owner)) |
0d381245 | 7494 | { |
0e30163f | 7495 | int is_gnu_ifunc; |
2c02bd72 | 7496 | const char *function_name; |
6a3a010b | 7497 | CORE_ADDR func_addr; |
0e30163f | 7498 | |
2c02bd72 | 7499 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7500 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7501 | |
7502 | if (is_gnu_ifunc && !explicit_loc) | |
7503 | { | |
7504 | struct breakpoint *b = loc->owner; | |
7505 | ||
7506 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7507 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7508 | &loc->requested_address)) |
7509 | { | |
7510 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7511 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7512 | loc->requested_address, | |
7513 | b->type); | |
7514 | } | |
7515 | else if (b->type == bp_breakpoint && b->loc == loc | |
7516 | && loc->next == NULL && b->related_breakpoint == b) | |
7517 | { | |
7518 | /* Create only the whole new breakpoint of this type but do not | |
7519 | mess more complicated breakpoints with multiple locations. */ | |
7520 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7521 | /* Remember the resolver's address for use by the return |
7522 | breakpoint. */ | |
7523 | loc->related_address = func_addr; | |
0e30163f JK |
7524 | } |
7525 | } | |
7526 | ||
2c02bd72 DE |
7527 | if (function_name) |
7528 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7529 | } |
7530 | } | |
7531 | ||
a6d9a66e | 7532 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7533 | struct gdbarch * |
a6d9a66e UW |
7534 | get_sal_arch (struct symtab_and_line sal) |
7535 | { | |
7536 | if (sal.section) | |
7537 | return get_objfile_arch (sal.section->objfile); | |
7538 | if (sal.symtab) | |
eb822aa6 | 7539 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7540 | |
7541 | return NULL; | |
7542 | } | |
7543 | ||
346774a9 PA |
7544 | /* Low level routine for partially initializing a breakpoint of type |
7545 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7546 | file name, and line number are provided by SAL. |
0d381245 VP |
7547 | |
7548 | It is expected that the caller will complete the initialization of | |
7549 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7550 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7551 | |
346774a9 PA |
7552 | static void |
7553 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7554 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7555 | const struct breakpoint_ops *ops) |
0d381245 | 7556 | { |
28010a5d | 7557 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7558 | |
3742cc8b | 7559 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7560 | |
6c95b8df PA |
7561 | if (bptype != bp_catchpoint) |
7562 | gdb_assert (sal.pspace != NULL); | |
7563 | ||
f8eba3c6 TT |
7564 | /* Store the program space that was used to set the breakpoint, |
7565 | except for ordinary breakpoints, which are independent of the | |
7566 | program space. */ | |
7567 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7568 | b->pspace = sal.pspace; | |
346774a9 | 7569 | } |
c906108c | 7570 | |
346774a9 PA |
7571 | /* set_raw_breakpoint is a low level routine for allocating and |
7572 | partially initializing a breakpoint of type BPTYPE. The newly | |
7573 | created breakpoint's address, section, source file name, and line | |
7574 | number are provided by SAL. The newly created and partially | |
7575 | initialized breakpoint is added to the breakpoint chain and | |
7576 | is also returned as the value of this function. | |
7577 | ||
7578 | It is expected that the caller will complete the initialization of | |
7579 | the newly created breakpoint struct as well as output any status | |
7580 | information regarding the creation of a new breakpoint. In | |
7581 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7582 | number! Care should be taken to not allow an error to occur | |
7583 | prior to completing the initialization of the breakpoint. If this | |
7584 | should happen, a bogus breakpoint will be left on the chain. */ | |
7585 | ||
7586 | struct breakpoint * | |
7587 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7588 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7589 | const struct breakpoint_ops *ops) |
346774a9 | 7590 | { |
4d01a485 | 7591 | struct breakpoint *b = new breakpoint (); |
346774a9 | 7592 | |
348d480f | 7593 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7594 | add_to_breakpoint_chain (b); |
c906108c SS |
7595 | return b; |
7596 | } | |
7597 | ||
53a5351d | 7598 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7599 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7600 | initiated the operation. */ | |
c906108c SS |
7601 | |
7602 | void | |
186c406b | 7603 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7604 | { |
35df4500 | 7605 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7606 | int thread = tp->global_num; |
0fd8e87f UW |
7607 | |
7608 | /* To avoid having to rescan all objfile symbols at every step, | |
7609 | we maintain a list of continually-inserted but always disabled | |
7610 | longjmp "master" breakpoints. Here, we simply create momentary | |
7611 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7612 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7613 | if (b->pspace == current_program_space |
186c406b TT |
7614 | && (b->type == bp_longjmp_master |
7615 | || b->type == bp_exception_master)) | |
0fd8e87f | 7616 | { |
06edf0c0 PA |
7617 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7618 | struct breakpoint *clone; | |
cc59ec59 | 7619 | |
e2e4d78b JK |
7620 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7621 | after their removal. */ | |
06edf0c0 | 7622 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7623 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7624 | clone->thread = thread; |
7625 | } | |
186c406b TT |
7626 | |
7627 | tp->initiating_frame = frame; | |
c906108c SS |
7628 | } |
7629 | ||
611c83ae | 7630 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7631 | void |
611c83ae | 7632 | delete_longjmp_breakpoint (int thread) |
c906108c | 7633 | { |
35df4500 | 7634 | struct breakpoint *b, *b_tmp; |
c906108c | 7635 | |
35df4500 | 7636 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7637 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7638 | { |
7639 | if (b->thread == thread) | |
7640 | delete_breakpoint (b); | |
7641 | } | |
c906108c SS |
7642 | } |
7643 | ||
f59f708a PA |
7644 | void |
7645 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7646 | { | |
7647 | struct breakpoint *b, *b_tmp; | |
7648 | ||
7649 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7650 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7651 | { | |
7652 | if (b->thread == thread) | |
7653 | b->disposition = disp_del_at_next_stop; | |
7654 | } | |
7655 | } | |
7656 | ||
e2e4d78b JK |
7657 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7658 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7659 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7660 | breakpoints. */ | |
7661 | ||
7662 | struct breakpoint * | |
7663 | set_longjmp_breakpoint_for_call_dummy (void) | |
7664 | { | |
7665 | struct breakpoint *b, *retval = NULL; | |
7666 | ||
7667 | ALL_BREAKPOINTS (b) | |
7668 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7669 | { | |
7670 | struct breakpoint *new_b; | |
7671 | ||
7672 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7673 | &momentary_breakpoint_ops, |
7674 | 1); | |
5d5658a1 | 7675 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7676 | |
7677 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7678 | ||
7679 | gdb_assert (new_b->related_breakpoint == new_b); | |
7680 | if (retval == NULL) | |
7681 | retval = new_b; | |
7682 | new_b->related_breakpoint = retval; | |
7683 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7684 | retval = retval->related_breakpoint; | |
7685 | retval->related_breakpoint = new_b; | |
7686 | } | |
7687 | ||
7688 | return retval; | |
7689 | } | |
7690 | ||
7691 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7692 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7693 | stack. |
7694 | ||
7695 | You should call this function only at places where it is safe to currently | |
7696 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7697 | frames. */ | |
7698 | ||
7699 | void | |
b67a2c6f | 7700 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7701 | { |
7702 | struct breakpoint *b, *b_tmp; | |
7703 | ||
7704 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7705 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7706 | { |
7707 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7708 | ||
7709 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7710 | dummy_b = dummy_b->related_breakpoint; | |
7711 | if (dummy_b->type != bp_call_dummy | |
7712 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7713 | continue; | |
7714 | ||
b67a2c6f | 7715 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7716 | |
7717 | while (b->related_breakpoint != b) | |
7718 | { | |
7719 | if (b_tmp == b->related_breakpoint) | |
7720 | b_tmp = b->related_breakpoint->next; | |
7721 | delete_breakpoint (b->related_breakpoint); | |
7722 | } | |
7723 | delete_breakpoint (b); | |
7724 | } | |
7725 | } | |
7726 | ||
1900040c MS |
7727 | void |
7728 | enable_overlay_breakpoints (void) | |
7729 | { | |
52f0bd74 | 7730 | struct breakpoint *b; |
1900040c MS |
7731 | |
7732 | ALL_BREAKPOINTS (b) | |
7733 | if (b->type == bp_overlay_event) | |
7734 | { | |
7735 | b->enable_state = bp_enabled; | |
44702360 | 7736 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7737 | overlay_events_enabled = 1; |
1900040c MS |
7738 | } |
7739 | } | |
7740 | ||
7741 | void | |
7742 | disable_overlay_breakpoints (void) | |
7743 | { | |
52f0bd74 | 7744 | struct breakpoint *b; |
1900040c MS |
7745 | |
7746 | ALL_BREAKPOINTS (b) | |
7747 | if (b->type == bp_overlay_event) | |
7748 | { | |
7749 | b->enable_state = bp_disabled; | |
44702360 | 7750 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7751 | overlay_events_enabled = 0; |
1900040c MS |
7752 | } |
7753 | } | |
7754 | ||
aa7d318d TT |
7755 | /* Set an active std::terminate breakpoint for each std::terminate |
7756 | master breakpoint. */ | |
7757 | void | |
7758 | set_std_terminate_breakpoint (void) | |
7759 | { | |
35df4500 | 7760 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7761 | |
35df4500 | 7762 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7763 | if (b->pspace == current_program_space |
7764 | && b->type == bp_std_terminate_master) | |
7765 | { | |
06edf0c0 | 7766 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7767 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7768 | } |
7769 | } | |
7770 | ||
7771 | /* Delete all the std::terminate breakpoints. */ | |
7772 | void | |
7773 | delete_std_terminate_breakpoint (void) | |
7774 | { | |
35df4500 | 7775 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7776 | |
35df4500 | 7777 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7778 | if (b->type == bp_std_terminate) |
7779 | delete_breakpoint (b); | |
7780 | } | |
7781 | ||
c4093a6a | 7782 | struct breakpoint * |
a6d9a66e | 7783 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7784 | { |
7785 | struct breakpoint *b; | |
c4093a6a | 7786 | |
06edf0c0 PA |
7787 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7788 | &internal_breakpoint_ops); | |
7789 | ||
b5de0fa7 | 7790 | b->enable_state = bp_enabled; |
f00aae0f | 7791 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7792 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7793 | |
44702360 | 7794 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7795 | |
c4093a6a JM |
7796 | return b; |
7797 | } | |
7798 | ||
0101ce28 JJ |
7799 | struct lang_and_radix |
7800 | { | |
7801 | enum language lang; | |
7802 | int radix; | |
7803 | }; | |
7804 | ||
4efc6507 DE |
7805 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7806 | ||
7807 | struct breakpoint * | |
7808 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7809 | { | |
2a7f3dff PA |
7810 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7811 | &internal_breakpoint_ops); | |
4efc6507 | 7812 | } |
0101ce28 | 7813 | |
03673fc7 PP |
7814 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7815 | ||
7816 | void | |
7817 | remove_jit_event_breakpoints (void) | |
7818 | { | |
7819 | struct breakpoint *b, *b_tmp; | |
7820 | ||
7821 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7822 | if (b->type == bp_jit_event | |
7823 | && b->loc->pspace == current_program_space) | |
7824 | delete_breakpoint (b); | |
7825 | } | |
7826 | ||
cae688ec JJ |
7827 | void |
7828 | remove_solib_event_breakpoints (void) | |
7829 | { | |
35df4500 | 7830 | struct breakpoint *b, *b_tmp; |
cae688ec | 7831 | |
35df4500 | 7832 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7833 | if (b->type == bp_shlib_event |
7834 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7835 | delete_breakpoint (b); |
7836 | } | |
7837 | ||
f37f681c PA |
7838 | /* See breakpoint.h. */ |
7839 | ||
7840 | void | |
7841 | remove_solib_event_breakpoints_at_next_stop (void) | |
7842 | { | |
7843 | struct breakpoint *b, *b_tmp; | |
7844 | ||
7845 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7846 | if (b->type == bp_shlib_event | |
7847 | && b->loc->pspace == current_program_space) | |
7848 | b->disposition = disp_del_at_next_stop; | |
7849 | } | |
7850 | ||
04086b45 PA |
7851 | /* Helper for create_solib_event_breakpoint / |
7852 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7853 | INSERT_MODE to pass through to update_global_location_list. */ | |
7854 | ||
7855 | static struct breakpoint * | |
7856 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7857 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7858 | { |
7859 | struct breakpoint *b; | |
7860 | ||
06edf0c0 PA |
7861 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7862 | &internal_breakpoint_ops); | |
04086b45 | 7863 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7864 | return b; |
7865 | } | |
7866 | ||
04086b45 PA |
7867 | struct breakpoint * |
7868 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7869 | { | |
7870 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7871 | } | |
7872 | ||
f37f681c PA |
7873 | /* See breakpoint.h. */ |
7874 | ||
7875 | struct breakpoint * | |
7876 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7877 | { | |
7878 | struct breakpoint *b; | |
7879 | ||
04086b45 PA |
7880 | /* Explicitly tell update_global_location_list to insert |
7881 | locations. */ | |
7882 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7883 | if (!b->loc->inserted) |
7884 | { | |
7885 | delete_breakpoint (b); | |
7886 | return NULL; | |
7887 | } | |
7888 | return b; | |
7889 | } | |
7890 | ||
cae688ec JJ |
7891 | /* Disable any breakpoints that are on code in shared libraries. Only |
7892 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7893 | ||
7894 | void | |
cb851954 | 7895 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7896 | { |
876fa593 | 7897 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7898 | |
876fa593 | 7899 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7900 | { |
2bdf28a0 | 7901 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7902 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7903 | |
4a64f543 MS |
7904 | /* We apply the check to all breakpoints, including disabled for |
7905 | those with loc->duplicate set. This is so that when breakpoint | |
7906 | becomes enabled, or the duplicate is removed, gdb will try to | |
7907 | insert all breakpoints. If we don't set shlib_disabled here, | |
7908 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7909 | if (((b->type == bp_breakpoint) |
508ccb1f | 7910 | || (b->type == bp_jit_event) |
1042e4c0 | 7911 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7912 | || (is_tracepoint (b))) |
6c95b8df | 7913 | && loc->pspace == current_program_space |
0d381245 | 7914 | && !loc->shlib_disabled |
6c95b8df | 7915 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7916 | ) |
0d381245 VP |
7917 | { |
7918 | loc->shlib_disabled = 1; | |
7919 | } | |
cae688ec JJ |
7920 | } |
7921 | } | |
7922 | ||
63644780 NB |
7923 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7924 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7925 | disabled ones can just stay disabled. */ | |
84acb35a | 7926 | |
75149521 | 7927 | static void |
84acb35a JJ |
7928 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7929 | { | |
876fa593 | 7930 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7931 | int disabled_shlib_breaks = 0; |
7932 | ||
876fa593 | 7933 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7934 | { |
2bdf28a0 | 7935 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7936 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7937 | |
1e4d1764 | 7938 | if (solib->pspace == loc->pspace |
e2dd7057 | 7939 | && !loc->shlib_disabled |
1e4d1764 YQ |
7940 | && (((b->type == bp_breakpoint |
7941 | || b->type == bp_jit_event | |
7942 | || b->type == bp_hardware_breakpoint) | |
7943 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7944 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7945 | || is_tracepoint (b)) | |
e2dd7057 | 7946 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7947 | { |
e2dd7057 PP |
7948 | loc->shlib_disabled = 1; |
7949 | /* At this point, we cannot rely on remove_breakpoint | |
7950 | succeeding so we must mark the breakpoint as not inserted | |
7951 | to prevent future errors occurring in remove_breakpoints. */ | |
7952 | loc->inserted = 0; | |
8d3788bd VP |
7953 | |
7954 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7955 | observer_notify_breakpoint_modified (b); | |
7956 | ||
e2dd7057 PP |
7957 | if (!disabled_shlib_breaks) |
7958 | { | |
7959 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7960 | warning (_("Temporarily disabling breakpoints " |
7961 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7962 | solib->so_name); |
84acb35a | 7963 | } |
e2dd7057 | 7964 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7965 | } |
7966 | } | |
84acb35a JJ |
7967 | } |
7968 | ||
63644780 NB |
7969 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7970 | notification of free_objfile. Only apply to enabled breakpoints, | |
7971 | disabled ones can just stay disabled. */ | |
7972 | ||
7973 | static void | |
7974 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7975 | { | |
7976 | struct breakpoint *b; | |
7977 | ||
7978 | if (objfile == NULL) | |
7979 | return; | |
7980 | ||
d03de421 PA |
7981 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7982 | managed by the user with add-symbol-file/remove-symbol-file. | |
7983 | Similarly to how breakpoints in shared libraries are handled in | |
7984 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7985 | shlib_disabled so they end up uninserted on the next global |
7986 | location list update. Shared libraries not loaded by the user | |
7987 | aren't handled here -- they're already handled in | |
7988 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7989 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7990 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7991 | main objfile). */ | |
7992 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7993 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7994 | return; |
7995 | ||
7996 | ALL_BREAKPOINTS (b) | |
7997 | { | |
7998 | struct bp_location *loc; | |
7999 | int bp_modified = 0; | |
8000 | ||
8001 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
8002 | continue; | |
8003 | ||
8004 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
8005 | { | |
8006 | CORE_ADDR loc_addr = loc->address; | |
8007 | ||
8008 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8009 | && loc->loc_type != bp_loc_software_breakpoint) | |
8010 | continue; | |
8011 | ||
8012 | if (loc->shlib_disabled != 0) | |
8013 | continue; | |
8014 | ||
8015 | if (objfile->pspace != loc->pspace) | |
8016 | continue; | |
8017 | ||
8018 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8019 | && loc->loc_type != bp_loc_software_breakpoint) | |
8020 | continue; | |
8021 | ||
8022 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8023 | { | |
8024 | loc->shlib_disabled = 1; | |
08351840 PA |
8025 | /* At this point, we don't know whether the object was |
8026 | unmapped from the inferior or not, so leave the | |
8027 | inserted flag alone. We'll handle failure to | |
8028 | uninsert quietly, in case the object was indeed | |
8029 | unmapped. */ | |
63644780 NB |
8030 | |
8031 | mark_breakpoint_location_modified (loc); | |
8032 | ||
8033 | bp_modified = 1; | |
8034 | } | |
8035 | } | |
8036 | ||
8037 | if (bp_modified) | |
8038 | observer_notify_breakpoint_modified (b); | |
8039 | } | |
8040 | } | |
8041 | ||
ce78b96d JB |
8042 | /* FORK & VFORK catchpoints. */ |
8043 | ||
e29a4733 PA |
8044 | /* An instance of this type is used to represent a fork or vfork |
8045 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8046 | class; users downcast to "struct breakpoint *" when needed. A | |
8047 | breakpoint is really of this type iff its ops pointer points to | |
8048 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8049 | ||
8050 | struct fork_catchpoint | |
8051 | { | |
8052 | /* The base class. */ | |
8053 | struct breakpoint base; | |
8054 | ||
8055 | /* Process id of a child process whose forking triggered this | |
8056 | catchpoint. This field is only valid immediately after this | |
8057 | catchpoint has triggered. */ | |
8058 | ptid_t forked_inferior_pid; | |
8059 | }; | |
8060 | ||
4a64f543 MS |
8061 | /* Implement the "insert" breakpoint_ops method for fork |
8062 | catchpoints. */ | |
ce78b96d | 8063 | |
77b06cd7 TJB |
8064 | static int |
8065 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8066 | { |
dfd4cc63 | 8067 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8068 | } |
8069 | ||
4a64f543 MS |
8070 | /* Implement the "remove" breakpoint_ops method for fork |
8071 | catchpoints. */ | |
ce78b96d JB |
8072 | |
8073 | static int | |
73971819 | 8074 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8075 | { |
dfd4cc63 | 8076 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8077 | } |
8078 | ||
8079 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8080 | catchpoints. */ | |
8081 | ||
8082 | static int | |
f1310107 | 8083 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8084 | struct address_space *aspace, CORE_ADDR bp_addr, |
8085 | const struct target_waitstatus *ws) | |
ce78b96d | 8086 | { |
e29a4733 PA |
8087 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8088 | ||
f90263c1 TT |
8089 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8090 | return 0; | |
8091 | ||
8092 | c->forked_inferior_pid = ws->value.related_pid; | |
8093 | return 1; | |
ce78b96d JB |
8094 | } |
8095 | ||
4a64f543 MS |
8096 | /* Implement the "print_it" breakpoint_ops method for fork |
8097 | catchpoints. */ | |
ce78b96d JB |
8098 | |
8099 | static enum print_stop_action | |
348d480f | 8100 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8101 | { |
36dfb11c | 8102 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8103 | struct breakpoint *b = bs->breakpoint_at; |
8104 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8105 | |
ce78b96d | 8106 | annotate_catchpoint (b->number); |
f303dbd6 | 8107 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8108 | if (b->disposition == disp_del) |
112e8700 | 8109 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8110 | else |
112e8700 SM |
8111 | uiout->text ("Catchpoint "); |
8112 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8113 | { |
112e8700 SM |
8114 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
8115 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8116 | } |
112e8700 SM |
8117 | uiout->field_int ("bkptno", b->number); |
8118 | uiout->text (" (forked process "); | |
8119 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8120 | uiout->text ("), "); | |
ce78b96d JB |
8121 | return PRINT_SRC_AND_LOC; |
8122 | } | |
8123 | ||
4a64f543 MS |
8124 | /* Implement the "print_one" breakpoint_ops method for fork |
8125 | catchpoints. */ | |
ce78b96d JB |
8126 | |
8127 | static void | |
a6d9a66e | 8128 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8129 | { |
e29a4733 | 8130 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8131 | struct value_print_options opts; |
79a45e25 | 8132 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8133 | |
8134 | get_user_print_options (&opts); | |
8135 | ||
4a64f543 MS |
8136 | /* Field 4, the address, is omitted (which makes the columns not |
8137 | line up too nicely with the headers, but the effect is relatively | |
8138 | readable). */ | |
79a45b7d | 8139 | if (opts.addressprint) |
112e8700 | 8140 | uiout->field_skip ("addr"); |
ce78b96d | 8141 | annotate_field (5); |
112e8700 | 8142 | uiout->text ("fork"); |
e29a4733 | 8143 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8144 | { |
112e8700 SM |
8145 | uiout->text (", process "); |
8146 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8147 | uiout->spaces (1); | |
ce78b96d | 8148 | } |
8ac3646f | 8149 | |
112e8700 SM |
8150 | if (uiout->is_mi_like_p ()) |
8151 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
8152 | } |
8153 | ||
8154 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8155 | catchpoints. */ | |
8156 | ||
8157 | static void | |
8158 | print_mention_catch_fork (struct breakpoint *b) | |
8159 | { | |
8160 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8161 | } | |
8162 | ||
6149aea9 PA |
8163 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8164 | catchpoints. */ | |
8165 | ||
8166 | static void | |
8167 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8168 | { | |
8169 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8170 | print_recreate_thread (b, fp); |
6149aea9 PA |
8171 | } |
8172 | ||
ce78b96d JB |
8173 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8174 | ||
2060206e | 8175 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8176 | |
4a64f543 MS |
8177 | /* Implement the "insert" breakpoint_ops method for vfork |
8178 | catchpoints. */ | |
ce78b96d | 8179 | |
77b06cd7 TJB |
8180 | static int |
8181 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8182 | { |
dfd4cc63 | 8183 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8184 | } |
8185 | ||
4a64f543 MS |
8186 | /* Implement the "remove" breakpoint_ops method for vfork |
8187 | catchpoints. */ | |
ce78b96d JB |
8188 | |
8189 | static int | |
73971819 | 8190 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8191 | { |
dfd4cc63 | 8192 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8193 | } |
8194 | ||
8195 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8196 | catchpoints. */ | |
8197 | ||
8198 | static int | |
f1310107 | 8199 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8200 | struct address_space *aspace, CORE_ADDR bp_addr, |
8201 | const struct target_waitstatus *ws) | |
ce78b96d | 8202 | { |
e29a4733 PA |
8203 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8204 | ||
f90263c1 TT |
8205 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8206 | return 0; | |
8207 | ||
8208 | c->forked_inferior_pid = ws->value.related_pid; | |
8209 | return 1; | |
ce78b96d JB |
8210 | } |
8211 | ||
4a64f543 MS |
8212 | /* Implement the "print_it" breakpoint_ops method for vfork |
8213 | catchpoints. */ | |
ce78b96d JB |
8214 | |
8215 | static enum print_stop_action | |
348d480f | 8216 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8217 | { |
36dfb11c | 8218 | struct ui_out *uiout = current_uiout; |
348d480f | 8219 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8220 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8221 | ||
ce78b96d | 8222 | annotate_catchpoint (b->number); |
f303dbd6 | 8223 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8224 | if (b->disposition == disp_del) |
112e8700 | 8225 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8226 | else |
112e8700 SM |
8227 | uiout->text ("Catchpoint "); |
8228 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8229 | { |
112e8700 SM |
8230 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
8231 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8232 | } |
112e8700 SM |
8233 | uiout->field_int ("bkptno", b->number); |
8234 | uiout->text (" (vforked process "); | |
8235 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8236 | uiout->text ("), "); | |
ce78b96d JB |
8237 | return PRINT_SRC_AND_LOC; |
8238 | } | |
8239 | ||
4a64f543 MS |
8240 | /* Implement the "print_one" breakpoint_ops method for vfork |
8241 | catchpoints. */ | |
ce78b96d JB |
8242 | |
8243 | static void | |
a6d9a66e | 8244 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8245 | { |
e29a4733 | 8246 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8247 | struct value_print_options opts; |
79a45e25 | 8248 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8249 | |
8250 | get_user_print_options (&opts); | |
4a64f543 MS |
8251 | /* Field 4, the address, is omitted (which makes the columns not |
8252 | line up too nicely with the headers, but the effect is relatively | |
8253 | readable). */ | |
79a45b7d | 8254 | if (opts.addressprint) |
112e8700 | 8255 | uiout->field_skip ("addr"); |
ce78b96d | 8256 | annotate_field (5); |
112e8700 | 8257 | uiout->text ("vfork"); |
e29a4733 | 8258 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8259 | { |
112e8700 SM |
8260 | uiout->text (", process "); |
8261 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8262 | uiout->spaces (1); | |
ce78b96d | 8263 | } |
8ac3646f | 8264 | |
112e8700 SM |
8265 | if (uiout->is_mi_like_p ()) |
8266 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
8267 | } |
8268 | ||
8269 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8270 | catchpoints. */ | |
8271 | ||
8272 | static void | |
8273 | print_mention_catch_vfork (struct breakpoint *b) | |
8274 | { | |
8275 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8276 | } | |
8277 | ||
6149aea9 PA |
8278 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8279 | catchpoints. */ | |
8280 | ||
8281 | static void | |
8282 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8283 | { | |
8284 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8285 | print_recreate_thread (b, fp); |
6149aea9 PA |
8286 | } |
8287 | ||
ce78b96d JB |
8288 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8289 | ||
2060206e | 8290 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8291 | |
edcc5120 TT |
8292 | /* An instance of this type is used to represent an solib catchpoint. |
8293 | It includes a "struct breakpoint" as a kind of base class; users | |
8294 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8295 | really of this type iff its ops pointer points to | |
8296 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8297 | ||
8298 | struct solib_catchpoint | |
8299 | { | |
8300 | /* The base class. */ | |
8301 | struct breakpoint base; | |
8302 | ||
8303 | /* True for "catch load", false for "catch unload". */ | |
8304 | unsigned char is_load; | |
8305 | ||
8306 | /* Regular expression to match, if any. COMPILED is only valid when | |
8307 | REGEX is non-NULL. */ | |
8308 | char *regex; | |
8309 | regex_t compiled; | |
8310 | }; | |
8311 | ||
8312 | static void | |
8313 | dtor_catch_solib (struct breakpoint *b) | |
8314 | { | |
8315 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8316 | ||
8317 | if (self->regex) | |
8318 | regfree (&self->compiled); | |
8319 | xfree (self->regex); | |
8320 | ||
8321 | base_breakpoint_ops.dtor (b); | |
8322 | } | |
8323 | ||
8324 | static int | |
8325 | insert_catch_solib (struct bp_location *ignore) | |
8326 | { | |
8327 | return 0; | |
8328 | } | |
8329 | ||
8330 | static int | |
73971819 | 8331 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8332 | { |
8333 | return 0; | |
8334 | } | |
8335 | ||
8336 | static int | |
8337 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8338 | struct address_space *aspace, | |
8339 | CORE_ADDR bp_addr, | |
8340 | const struct target_waitstatus *ws) | |
8341 | { | |
8342 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8343 | struct breakpoint *other; | |
8344 | ||
8345 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8346 | return 1; | |
8347 | ||
8348 | ALL_BREAKPOINTS (other) | |
8349 | { | |
8350 | struct bp_location *other_bl; | |
8351 | ||
8352 | if (other == bl->owner) | |
8353 | continue; | |
8354 | ||
8355 | if (other->type != bp_shlib_event) | |
8356 | continue; | |
8357 | ||
8358 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8359 | continue; | |
8360 | ||
8361 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8362 | { | |
8363 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8364 | return 1; | |
8365 | } | |
8366 | } | |
8367 | ||
8368 | return 0; | |
8369 | } | |
8370 | ||
8371 | static void | |
8372 | check_status_catch_solib (struct bpstats *bs) | |
8373 | { | |
8374 | struct solib_catchpoint *self | |
8375 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8376 | int ix; | |
8377 | ||
8378 | if (self->is_load) | |
8379 | { | |
8380 | struct so_list *iter; | |
8381 | ||
8382 | for (ix = 0; | |
8383 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8384 | ix, iter); | |
8385 | ++ix) | |
8386 | { | |
8387 | if (!self->regex | |
8388 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8389 | return; | |
8390 | } | |
8391 | } | |
8392 | else | |
8393 | { | |
8394 | char *iter; | |
8395 | ||
8396 | for (ix = 0; | |
8397 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8398 | ix, iter); | |
8399 | ++ix) | |
8400 | { | |
8401 | if (!self->regex | |
8402 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8403 | return; | |
8404 | } | |
8405 | } | |
8406 | ||
8407 | bs->stop = 0; | |
8408 | bs->print_it = print_it_noop; | |
8409 | } | |
8410 | ||
8411 | static enum print_stop_action | |
8412 | print_it_catch_solib (bpstat bs) | |
8413 | { | |
8414 | struct breakpoint *b = bs->breakpoint_at; | |
8415 | struct ui_out *uiout = current_uiout; | |
8416 | ||
8417 | annotate_catchpoint (b->number); | |
f303dbd6 | 8418 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8419 | if (b->disposition == disp_del) |
112e8700 | 8420 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8421 | else |
112e8700 SM |
8422 | uiout->text ("Catchpoint "); |
8423 | uiout->field_int ("bkptno", b->number); | |
8424 | uiout->text ("\n"); | |
8425 | if (uiout->is_mi_like_p ()) | |
8426 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8427 | print_solib_event (1); |
8428 | return PRINT_SRC_AND_LOC; | |
8429 | } | |
8430 | ||
8431 | static void | |
8432 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8433 | { | |
8434 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8435 | struct value_print_options opts; | |
8436 | struct ui_out *uiout = current_uiout; | |
8437 | char *msg; | |
8438 | ||
8439 | get_user_print_options (&opts); | |
8440 | /* Field 4, the address, is omitted (which makes the columns not | |
8441 | line up too nicely with the headers, but the effect is relatively | |
8442 | readable). */ | |
8443 | if (opts.addressprint) | |
8444 | { | |
8445 | annotate_field (4); | |
112e8700 | 8446 | uiout->field_skip ("addr"); |
edcc5120 TT |
8447 | } |
8448 | ||
8449 | annotate_field (5); | |
8450 | if (self->is_load) | |
8451 | { | |
8452 | if (self->regex) | |
8453 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8454 | else | |
8455 | msg = xstrdup (_("load of library")); | |
8456 | } | |
8457 | else | |
8458 | { | |
8459 | if (self->regex) | |
8460 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8461 | else | |
8462 | msg = xstrdup (_("unload of library")); | |
8463 | } | |
112e8700 | 8464 | uiout->field_string ("what", msg); |
edcc5120 | 8465 | xfree (msg); |
8ac3646f | 8466 | |
112e8700 SM |
8467 | if (uiout->is_mi_like_p ()) |
8468 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8469 | } |
8470 | ||
8471 | static void | |
8472 | print_mention_catch_solib (struct breakpoint *b) | |
8473 | { | |
8474 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8475 | ||
8476 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8477 | self->is_load ? "load" : "unload"); | |
8478 | } | |
8479 | ||
8480 | static void | |
8481 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8482 | { | |
8483 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8484 | ||
8485 | fprintf_unfiltered (fp, "%s %s", | |
8486 | b->disposition == disp_del ? "tcatch" : "catch", | |
8487 | self->is_load ? "load" : "unload"); | |
8488 | if (self->regex) | |
8489 | fprintf_unfiltered (fp, " %s", self->regex); | |
8490 | fprintf_unfiltered (fp, "\n"); | |
8491 | } | |
8492 | ||
8493 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8494 | ||
91985142 MG |
8495 | /* Shared helper function (MI and CLI) for creating and installing |
8496 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8497 | the events to be caught are load events, otherwise they are | |
8498 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8499 | temporary one. If ENABLED is non-zero the catchpoint is | |
8500 | created in an enabled state. */ | |
edcc5120 | 8501 | |
91985142 | 8502 | void |
a121b7c1 | 8503 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 TT |
8504 | { |
8505 | struct solib_catchpoint *c; | |
8506 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8507 | struct cleanup *cleanup; |
8508 | ||
edcc5120 TT |
8509 | if (!arg) |
8510 | arg = ""; | |
a121b7c1 | 8511 | arg = skip_spaces_const (arg); |
edcc5120 | 8512 | |
4d01a485 | 8513 | c = new solib_catchpoint (); |
edcc5120 TT |
8514 | cleanup = make_cleanup (xfree, c); |
8515 | ||
8516 | if (*arg != '\0') | |
8517 | { | |
8518 | int errcode; | |
8519 | ||
8520 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8521 | if (errcode != 0) | |
8522 | { | |
8523 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8524 | ||
8525 | make_cleanup (xfree, err); | |
8526 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8527 | } | |
8528 | c->regex = xstrdup (arg); | |
8529 | } | |
8530 | ||
8531 | c->is_load = is_load; | |
91985142 | 8532 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8533 | &catch_solib_breakpoint_ops); |
8534 | ||
91985142 MG |
8535 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8536 | ||
edcc5120 TT |
8537 | discard_cleanups (cleanup); |
8538 | install_breakpoint (0, &c->base, 1); | |
8539 | } | |
8540 | ||
91985142 MG |
8541 | /* A helper function that does all the work for "catch load" and |
8542 | "catch unload". */ | |
8543 | ||
8544 | static void | |
8545 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8546 | struct cmd_list_element *command) | |
8547 | { | |
8548 | int tempflag; | |
8549 | const int enabled = 1; | |
8550 | ||
8551 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8552 | ||
8553 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8554 | } | |
8555 | ||
edcc5120 TT |
8556 | static void |
8557 | catch_load_command_1 (char *arg, int from_tty, | |
8558 | struct cmd_list_element *command) | |
8559 | { | |
8560 | catch_load_or_unload (arg, from_tty, 1, command); | |
8561 | } | |
8562 | ||
8563 | static void | |
8564 | catch_unload_command_1 (char *arg, int from_tty, | |
8565 | struct cmd_list_element *command) | |
8566 | { | |
8567 | catch_load_or_unload (arg, from_tty, 0, command); | |
8568 | } | |
8569 | ||
346774a9 PA |
8570 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8571 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8572 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8573 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8574 | |
ab04a2af | 8575 | void |
346774a9 PA |
8576 | init_catchpoint (struct breakpoint *b, |
8577 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8578 | const char *cond_string, |
c0a91b2b | 8579 | const struct breakpoint_ops *ops) |
c906108c | 8580 | { |
c5aa993b | 8581 | struct symtab_and_line sal; |
346774a9 | 8582 | |
fe39c653 | 8583 | init_sal (&sal); |
6c95b8df | 8584 | sal.pspace = current_program_space; |
c5aa993b | 8585 | |
28010a5d | 8586 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8587 | |
1b36a34b | 8588 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8589 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8590 | } |
8591 | ||
28010a5d | 8592 | void |
3ea46bff | 8593 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8594 | { |
8595 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8596 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8597 | if (is_tracepoint (b)) |
8598 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8599 | if (!internal) |
8600 | mention (b); | |
c56053d2 | 8601 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8602 | |
8603 | if (update_gll) | |
44702360 | 8604 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8605 | } |
8606 | ||
9b70b993 | 8607 | static void |
a6d9a66e | 8608 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8609 | int tempflag, const char *cond_string, |
c0a91b2b | 8610 | const struct breakpoint_ops *ops) |
c906108c | 8611 | { |
4d01a485 | 8612 | struct fork_catchpoint *c = new fork_catchpoint (); |
ce78b96d | 8613 | |
e29a4733 PA |
8614 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8615 | ||
8616 | c->forked_inferior_pid = null_ptid; | |
8617 | ||
3ea46bff | 8618 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8619 | } |
8620 | ||
fe798b75 JB |
8621 | /* Exec catchpoints. */ |
8622 | ||
b4d90040 PA |
8623 | /* An instance of this type is used to represent an exec catchpoint. |
8624 | It includes a "struct breakpoint" as a kind of base class; users | |
8625 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8626 | really of this type iff its ops pointer points to | |
8627 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8628 | ||
8629 | struct exec_catchpoint | |
8630 | { | |
8631 | /* The base class. */ | |
8632 | struct breakpoint base; | |
8633 | ||
8634 | /* Filename of a program whose exec triggered this catchpoint. | |
8635 | This field is only valid immediately after this catchpoint has | |
8636 | triggered. */ | |
8637 | char *exec_pathname; | |
8638 | }; | |
8639 | ||
8640 | /* Implement the "dtor" breakpoint_ops method for exec | |
8641 | catchpoints. */ | |
8642 | ||
8643 | static void | |
8644 | dtor_catch_exec (struct breakpoint *b) | |
8645 | { | |
8646 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8647 | ||
8648 | xfree (c->exec_pathname); | |
348d480f | 8649 | |
2060206e | 8650 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8651 | } |
8652 | ||
77b06cd7 TJB |
8653 | static int |
8654 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8655 | { |
dfd4cc63 | 8656 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8657 | } |
c906108c | 8658 | |
fe798b75 | 8659 | static int |
73971819 | 8660 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8661 | { |
dfd4cc63 | 8662 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8663 | } |
c906108c | 8664 | |
fe798b75 | 8665 | static int |
f1310107 | 8666 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8667 | struct address_space *aspace, CORE_ADDR bp_addr, |
8668 | const struct target_waitstatus *ws) | |
fe798b75 | 8669 | { |
b4d90040 PA |
8670 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8671 | ||
f90263c1 TT |
8672 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8673 | return 0; | |
8674 | ||
8675 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8676 | return 1; | |
fe798b75 | 8677 | } |
c906108c | 8678 | |
fe798b75 | 8679 | static enum print_stop_action |
348d480f | 8680 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8681 | { |
36dfb11c | 8682 | struct ui_out *uiout = current_uiout; |
348d480f | 8683 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8684 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8685 | ||
fe798b75 | 8686 | annotate_catchpoint (b->number); |
f303dbd6 | 8687 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8688 | if (b->disposition == disp_del) |
112e8700 | 8689 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8690 | else |
112e8700 SM |
8691 | uiout->text ("Catchpoint "); |
8692 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8693 | { |
112e8700 SM |
8694 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8695 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8696 | } |
112e8700 SM |
8697 | uiout->field_int ("bkptno", b->number); |
8698 | uiout->text (" (exec'd "); | |
8699 | uiout->field_string ("new-exec", c->exec_pathname); | |
8700 | uiout->text ("), "); | |
36dfb11c | 8701 | |
fe798b75 | 8702 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8703 | } |
8704 | ||
fe798b75 | 8705 | static void |
a6d9a66e | 8706 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8707 | { |
b4d90040 | 8708 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8709 | struct value_print_options opts; |
79a45e25 | 8710 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8711 | |
8712 | get_user_print_options (&opts); | |
8713 | ||
8714 | /* Field 4, the address, is omitted (which makes the columns | |
8715 | not line up too nicely with the headers, but the effect | |
8716 | is relatively readable). */ | |
8717 | if (opts.addressprint) | |
112e8700 | 8718 | uiout->field_skip ("addr"); |
fe798b75 | 8719 | annotate_field (5); |
112e8700 | 8720 | uiout->text ("exec"); |
b4d90040 | 8721 | if (c->exec_pathname != NULL) |
fe798b75 | 8722 | { |
112e8700 SM |
8723 | uiout->text (", program \""); |
8724 | uiout->field_string ("what", c->exec_pathname); | |
8725 | uiout->text ("\" "); | |
fe798b75 | 8726 | } |
8ac3646f | 8727 | |
112e8700 SM |
8728 | if (uiout->is_mi_like_p ()) |
8729 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8730 | } |
8731 | ||
8732 | static void | |
8733 | print_mention_catch_exec (struct breakpoint *b) | |
8734 | { | |
8735 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8736 | } | |
8737 | ||
6149aea9 PA |
8738 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8739 | catchpoints. */ | |
8740 | ||
8741 | static void | |
8742 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8743 | { | |
8744 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8745 | print_recreate_thread (b, fp); |
6149aea9 PA |
8746 | } |
8747 | ||
2060206e | 8748 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8749 | |
c906108c | 8750 | static int |
fba45db2 | 8751 | hw_breakpoint_used_count (void) |
c906108c | 8752 | { |
c906108c | 8753 | int i = 0; |
f1310107 TJB |
8754 | struct breakpoint *b; |
8755 | struct bp_location *bl; | |
c906108c SS |
8756 | |
8757 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8758 | { |
d6b74ac4 | 8759 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8760 | for (bl = b->loc; bl; bl = bl->next) |
8761 | { | |
8762 | /* Special types of hardware breakpoints may use more than | |
8763 | one register. */ | |
348d480f | 8764 | i += b->ops->resources_needed (bl); |
f1310107 | 8765 | } |
c5aa993b | 8766 | } |
c906108c SS |
8767 | |
8768 | return i; | |
8769 | } | |
8770 | ||
a1398e0c PA |
8771 | /* Returns the resources B would use if it were a hardware |
8772 | watchpoint. */ | |
8773 | ||
c906108c | 8774 | static int |
a1398e0c | 8775 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8776 | { |
c906108c | 8777 | int i = 0; |
e09342b5 | 8778 | struct bp_location *bl; |
c906108c | 8779 | |
a1398e0c PA |
8780 | if (!breakpoint_enabled (b)) |
8781 | return 0; | |
8782 | ||
8783 | for (bl = b->loc; bl; bl = bl->next) | |
8784 | { | |
8785 | /* Special types of hardware watchpoints may use more than | |
8786 | one register. */ | |
8787 | i += b->ops->resources_needed (bl); | |
8788 | } | |
8789 | ||
8790 | return i; | |
8791 | } | |
8792 | ||
8793 | /* Returns the sum the used resources of all hardware watchpoints of | |
8794 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8795 | the sum of the used resources of all hardware watchpoints of other | |
8796 | types _not_ TYPE. */ | |
8797 | ||
8798 | static int | |
8799 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8800 | enum bptype type, int *other_type_used) | |
8801 | { | |
8802 | int i = 0; | |
8803 | struct breakpoint *b; | |
8804 | ||
c906108c SS |
8805 | *other_type_used = 0; |
8806 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8807 | { |
a1398e0c PA |
8808 | if (b == except) |
8809 | continue; | |
e09342b5 TJB |
8810 | if (!breakpoint_enabled (b)) |
8811 | continue; | |
8812 | ||
a1398e0c PA |
8813 | if (b->type == type) |
8814 | i += hw_watchpoint_use_count (b); | |
8815 | else if (is_hardware_watchpoint (b)) | |
8816 | *other_type_used = 1; | |
e09342b5 TJB |
8817 | } |
8818 | ||
c906108c SS |
8819 | return i; |
8820 | } | |
8821 | ||
c906108c | 8822 | void |
fba45db2 | 8823 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8824 | { |
c5aa993b | 8825 | struct breakpoint *b; |
c906108c SS |
8826 | |
8827 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8828 | { |
cc60f2e3 | 8829 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8830 | { |
b5de0fa7 | 8831 | b->enable_state = bp_call_disabled; |
44702360 | 8832 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8833 | } |
8834 | } | |
c906108c SS |
8835 | } |
8836 | ||
8837 | void | |
fba45db2 | 8838 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8839 | { |
c5aa993b | 8840 | struct breakpoint *b; |
c906108c SS |
8841 | |
8842 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8843 | { |
cc60f2e3 | 8844 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8845 | { |
b5de0fa7 | 8846 | b->enable_state = bp_enabled; |
44702360 | 8847 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8848 | } |
8849 | } | |
c906108c SS |
8850 | } |
8851 | ||
8bea4e01 UW |
8852 | void |
8853 | disable_breakpoints_before_startup (void) | |
8854 | { | |
6c95b8df | 8855 | current_program_space->executing_startup = 1; |
44702360 | 8856 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8857 | } |
8858 | ||
8859 | void | |
8860 | enable_breakpoints_after_startup (void) | |
8861 | { | |
6c95b8df | 8862 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8863 | breakpoint_re_set (); |
8bea4e01 UW |
8864 | } |
8865 | ||
7c16b83e PA |
8866 | /* Create a new single-step breakpoint for thread THREAD, with no |
8867 | locations. */ | |
c906108c | 8868 | |
7c16b83e PA |
8869 | static struct breakpoint * |
8870 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8871 | { | |
4d01a485 | 8872 | struct breakpoint *b = new breakpoint (); |
7c16b83e PA |
8873 | |
8874 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8875 | &momentary_breakpoint_ops); | |
8876 | ||
8877 | b->disposition = disp_donttouch; | |
8878 | b->frame_id = null_frame_id; | |
8879 | ||
8880 | b->thread = thread; | |
8881 | gdb_assert (b->thread != 0); | |
8882 | ||
8883 | add_to_breakpoint_chain (b); | |
8884 | ||
8885 | return b; | |
8886 | } | |
8887 | ||
8888 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8889 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8890 | frame. */ | |
c906108c SS |
8891 | |
8892 | struct breakpoint * | |
a6d9a66e UW |
8893 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8894 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8895 | { |
52f0bd74 | 8896 | struct breakpoint *b; |
edb3359d | 8897 | |
193facb3 JK |
8898 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8899 | tail-called one. */ | |
8900 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8901 | |
06edf0c0 | 8902 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8903 | b->enable_state = bp_enabled; |
8904 | b->disposition = disp_donttouch; | |
818dd999 | 8905 | b->frame_id = frame_id; |
c906108c | 8906 | |
4a64f543 MS |
8907 | /* If we're debugging a multi-threaded program, then we want |
8908 | momentary breakpoints to be active in only a single thread of | |
8909 | control. */ | |
39f77062 | 8910 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8911 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8912 | |
44702360 | 8913 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8914 | |
c906108c SS |
8915 | return b; |
8916 | } | |
611c83ae | 8917 | |
06edf0c0 | 8918 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8919 | The new breakpoint will have type TYPE, use OPS as its |
8920 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8921 | |
06edf0c0 PA |
8922 | static struct breakpoint * |
8923 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8924 | enum bptype type, | |
a1aa2221 LM |
8925 | const struct breakpoint_ops *ops, |
8926 | int loc_enabled) | |
e58b0e63 PA |
8927 | { |
8928 | struct breakpoint *copy; | |
8929 | ||
06edf0c0 | 8930 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8931 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8932 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8933 | |
a6d9a66e | 8934 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8935 | copy->loc->requested_address = orig->loc->requested_address; |
8936 | copy->loc->address = orig->loc->address; | |
8937 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8938 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8939 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8940 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8941 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8942 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8943 | copy->frame_id = orig->frame_id; |
8944 | copy->thread = orig->thread; | |
6c95b8df | 8945 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8946 | |
8947 | copy->enable_state = bp_enabled; | |
8948 | copy->disposition = disp_donttouch; | |
8949 | copy->number = internal_breakpoint_number--; | |
8950 | ||
44702360 | 8951 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8952 | return copy; |
8953 | } | |
8954 | ||
06edf0c0 PA |
8955 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8956 | ORIG is NULL. */ | |
8957 | ||
8958 | struct breakpoint * | |
8959 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8960 | { | |
8961 | /* If there's nothing to clone, then return nothing. */ | |
8962 | if (orig == NULL) | |
8963 | return NULL; | |
8964 | ||
a1aa2221 | 8965 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8966 | } |
8967 | ||
611c83ae | 8968 | struct breakpoint * |
a6d9a66e UW |
8969 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8970 | enum bptype type) | |
611c83ae PA |
8971 | { |
8972 | struct symtab_and_line sal; | |
8973 | ||
8974 | sal = find_pc_line (pc, 0); | |
8975 | sal.pc = pc; | |
8976 | sal.section = find_pc_overlay (pc); | |
8977 | sal.explicit_pc = 1; | |
8978 | ||
a6d9a66e | 8979 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8980 | } |
c906108c | 8981 | \f |
c5aa993b | 8982 | |
c906108c SS |
8983 | /* Tell the user we have just set a breakpoint B. */ |
8984 | ||
8985 | static void | |
fba45db2 | 8986 | mention (struct breakpoint *b) |
c906108c | 8987 | { |
348d480f | 8988 | b->ops->print_mention (b); |
112e8700 | 8989 | if (current_uiout->is_mi_like_p ()) |
fb40c209 | 8990 | return; |
c906108c SS |
8991 | printf_filtered ("\n"); |
8992 | } | |
c906108c | 8993 | \f |
c5aa993b | 8994 | |
1a853c52 PA |
8995 | static int bp_loc_is_permanent (struct bp_location *loc); |
8996 | ||
0d381245 | 8997 | static struct bp_location * |
39d61571 | 8998 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8999 | const struct symtab_and_line *sal) |
9000 | { | |
9001 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9002 | CORE_ADDR adjusted_address; |
9003 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9004 | ||
9005 | if (loc_gdbarch == NULL) | |
9006 | loc_gdbarch = b->gdbarch; | |
9007 | ||
9008 | /* Adjust the breakpoint's address prior to allocating a location. | |
9009 | Once we call allocate_bp_location(), that mostly uninitialized | |
9010 | location will be placed on the location chain. Adjustment of the | |
9011 | breakpoint may cause target_read_memory() to be called and we do | |
9012 | not want its scan of the location chain to find a breakpoint and | |
9013 | location that's only been partially initialized. */ | |
9014 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9015 | sal->pc, b->type); | |
0d381245 | 9016 | |
d30113d4 | 9017 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9018 | loc = allocate_bp_location (b); |
d30113d4 JK |
9019 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9020 | tmp = &((*tmp)->next)) | |
0d381245 | 9021 | ; |
d30113d4 | 9022 | loc->next = *tmp; |
0d381245 | 9023 | *tmp = loc; |
3742cc8b | 9024 | |
0d381245 | 9025 | loc->requested_address = sal->pc; |
3742cc8b | 9026 | loc->address = adjusted_address; |
6c95b8df | 9027 | loc->pspace = sal->pspace; |
729662a5 TT |
9028 | loc->probe.probe = sal->probe; |
9029 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9030 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9031 | loc->section = sal->section; |
3742cc8b | 9032 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9033 | loc->line_number = sal->line; |
2f202fde | 9034 | loc->symtab = sal->symtab; |
f8eba3c6 | 9035 | |
0e30163f JK |
9036 | set_breakpoint_location_function (loc, |
9037 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9038 | |
6ae88661 LM |
9039 | /* While by definition, permanent breakpoints are already present in the |
9040 | code, we don't mark the location as inserted. Normally one would expect | |
9041 | that GDB could rely on that breakpoint instruction to stop the program, | |
9042 | thus removing the need to insert its own breakpoint, except that executing | |
9043 | the breakpoint instruction can kill the target instead of reporting a | |
9044 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9045 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9046 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9047 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9048 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9049 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9050 | it manually increments the PC, thus avoiding executing the breakpoint | |
9051 | instruction.) */ | |
1a853c52 | 9052 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9053 | loc->permanent = 1; |
1a853c52 | 9054 | |
0d381245 VP |
9055 | return loc; |
9056 | } | |
514f746b AR |
9057 | \f |
9058 | ||
1cf4d951 | 9059 | /* See breakpoint.h. */ |
514f746b | 9060 | |
1cf4d951 PA |
9061 | int |
9062 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9063 | { |
9064 | int len; | |
9065 | CORE_ADDR addr; | |
1afeeb75 | 9066 | const gdb_byte *bpoint; |
514f746b | 9067 | gdb_byte *target_mem; |
939c61fa JK |
9068 | struct cleanup *cleanup; |
9069 | int retval = 0; | |
514f746b | 9070 | |
1cf4d951 PA |
9071 | addr = address; |
9072 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9073 | ||
9074 | /* Software breakpoints unsupported? */ | |
9075 | if (bpoint == NULL) | |
9076 | return 0; | |
9077 | ||
224c3ddb | 9078 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9079 | |
9080 | /* Enable the automatic memory restoration from breakpoints while | |
9081 | we read the memory. Otherwise we could say about our temporary | |
9082 | breakpoints they are permanent. */ | |
9083 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9084 | ||
9085 | if (target_read_memory (address, target_mem, len) == 0 | |
9086 | && memcmp (target_mem, bpoint, len) == 0) | |
9087 | retval = 1; | |
9088 | ||
9089 | do_cleanups (cleanup); | |
9090 | ||
9091 | return retval; | |
9092 | } | |
9093 | ||
9094 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9095 | return 0 otherwise. */ | |
9096 | ||
9097 | static int | |
9098 | bp_loc_is_permanent (struct bp_location *loc) | |
9099 | { | |
9100 | struct cleanup *cleanup; | |
9101 | int retval; | |
9102 | ||
514f746b AR |
9103 | gdb_assert (loc != NULL); |
9104 | ||
244558af LM |
9105 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9106 | attempt to read from the addresses the locations of these breakpoint types | |
9107 | point to. program_breakpoint_here_p, below, will attempt to read | |
9108 | memory. */ | |
9109 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9110 | return 0; | |
9111 | ||
6c95b8df | 9112 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9113 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9114 | |
1cf4d951 | 9115 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9116 | |
939c61fa JK |
9117 | do_cleanups (cleanup); |
9118 | ||
9119 | return retval; | |
514f746b AR |
9120 | } |
9121 | ||
e7e0cddf SS |
9122 | /* Build a command list for the dprintf corresponding to the current |
9123 | settings of the dprintf style options. */ | |
9124 | ||
9125 | static void | |
9126 | update_dprintf_command_list (struct breakpoint *b) | |
9127 | { | |
9128 | char *dprintf_args = b->extra_string; | |
9129 | char *printf_line = NULL; | |
9130 | ||
9131 | if (!dprintf_args) | |
9132 | return; | |
9133 | ||
9134 | dprintf_args = skip_spaces (dprintf_args); | |
9135 | ||
9136 | /* Allow a comma, as it may have terminated a location, but don't | |
9137 | insist on it. */ | |
9138 | if (*dprintf_args == ',') | |
9139 | ++dprintf_args; | |
9140 | dprintf_args = skip_spaces (dprintf_args); | |
9141 | ||
9142 | if (*dprintf_args != '"') | |
9143 | error (_("Bad format string, missing '\"'.")); | |
9144 | ||
d3ce09f5 | 9145 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9146 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9147 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9148 | { |
9149 | if (!dprintf_function) | |
9150 | error (_("No function supplied for dprintf call")); | |
9151 | ||
9152 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9153 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9154 | dprintf_function, | |
9155 | dprintf_channel, | |
9156 | dprintf_args); | |
9157 | else | |
9158 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9159 | dprintf_function, | |
9160 | dprintf_args); | |
9161 | } | |
d3ce09f5 SS |
9162 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9163 | { | |
9164 | if (target_can_run_breakpoint_commands ()) | |
9165 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9166 | else | |
9167 | { | |
9168 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9169 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9170 | } | |
9171 | } | |
e7e0cddf SS |
9172 | else |
9173 | internal_error (__FILE__, __LINE__, | |
9174 | _("Invalid dprintf style.")); | |
9175 | ||
f28045c2 | 9176 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9177 | /* Manufacture a printf sequence. */ |
f28045c2 | 9178 | { |
8d749320 | 9179 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9180 | |
f28045c2 YQ |
9181 | printf_cmd_line->control_type = simple_control; |
9182 | printf_cmd_line->body_count = 0; | |
9183 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9184 | printf_cmd_line->next = NULL; |
f28045c2 | 9185 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9186 | |
93921405 | 9187 | breakpoint_set_commands (b, command_line_up (printf_cmd_line)); |
f28045c2 | 9188 | } |
e7e0cddf SS |
9189 | } |
9190 | ||
9191 | /* Update all dprintf commands, making their command lists reflect | |
9192 | current style settings. */ | |
9193 | ||
9194 | static void | |
9195 | update_dprintf_commands (char *args, int from_tty, | |
9196 | struct cmd_list_element *c) | |
9197 | { | |
9198 | struct breakpoint *b; | |
9199 | ||
9200 | ALL_BREAKPOINTS (b) | |
9201 | { | |
9202 | if (b->type == bp_dprintf) | |
9203 | update_dprintf_command_list (b); | |
9204 | } | |
9205 | } | |
c3f6f71d | 9206 | |
f00aae0f KS |
9207 | /* Create a breakpoint with SAL as location. Use LOCATION |
9208 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9209 | as condition expression. If LOCATION is NULL then create an |
9210 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9211 | |
9212 | static void | |
d9b3f62e | 9213 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f | 9214 | struct symtabs_and_lines sals, |
ffc2605c | 9215 | event_location_up &&location, |
f8eba3c6 | 9216 | char *filter, char *cond_string, |
e7e0cddf | 9217 | char *extra_string, |
d9b3f62e PA |
9218 | enum bptype type, enum bpdisp disposition, |
9219 | int thread, int task, int ignore_count, | |
c0a91b2b | 9220 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9221 | int enabled, int internal, unsigned flags, |
9222 | int display_canonical) | |
018d34a4 | 9223 | { |
0d381245 | 9224 | int i; |
018d34a4 VP |
9225 | |
9226 | if (type == bp_hardware_breakpoint) | |
9227 | { | |
fbbd034e AS |
9228 | int target_resources_ok; |
9229 | ||
9230 | i = hw_breakpoint_used_count (); | |
9231 | target_resources_ok = | |
9232 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9233 | i + 1, 0); |
9234 | if (target_resources_ok == 0) | |
9235 | error (_("No hardware breakpoint support in the target.")); | |
9236 | else if (target_resources_ok < 0) | |
9237 | error (_("Hardware breakpoints used exceeds limit.")); | |
9238 | } | |
9239 | ||
6c95b8df PA |
9240 | gdb_assert (sals.nelts > 0); |
9241 | ||
0d381245 VP |
9242 | for (i = 0; i < sals.nelts; ++i) |
9243 | { | |
9244 | struct symtab_and_line sal = sals.sals[i]; | |
9245 | struct bp_location *loc; | |
9246 | ||
9247 | if (from_tty) | |
5af949e3 UW |
9248 | { |
9249 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9250 | if (!loc_gdbarch) | |
9251 | loc_gdbarch = gdbarch; | |
9252 | ||
9253 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9254 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9255 | } |
0d381245 VP |
9256 | |
9257 | if (i == 0) | |
9258 | { | |
d9b3f62e | 9259 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9260 | b->thread = thread; |
4a306c9a | 9261 | b->task = task; |
855a6e68 | 9262 | |
0d381245 | 9263 | b->cond_string = cond_string; |
e7e0cddf | 9264 | b->extra_string = extra_string; |
0d381245 | 9265 | b->ignore_count = ignore_count; |
41447f92 | 9266 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9267 | b->disposition = disposition; |
6c95b8df | 9268 | |
44f238bb PA |
9269 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9270 | b->loc->inserted = 1; | |
9271 | ||
0fb4aa4b PA |
9272 | if (type == bp_static_tracepoint) |
9273 | { | |
d9b3f62e | 9274 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9275 | struct static_tracepoint_marker marker; |
9276 | ||
983af33b | 9277 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9278 | { |
9279 | /* We already know the marker exists, otherwise, we | |
9280 | wouldn't see a sal for it. */ | |
d28cd78a TT |
9281 | const char *p |
9282 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 9283 | const char *endp; |
0fb4aa4b | 9284 | char *marker_str; |
0fb4aa4b | 9285 | |
f00aae0f | 9286 | p = skip_spaces_const (p); |
0fb4aa4b | 9287 | |
f00aae0f | 9288 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9289 | |
9290 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9291 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9292 | |
3e43a32a MS |
9293 | printf_filtered (_("Probed static tracepoint " |
9294 | "marker \"%s\"\n"), | |
d9b3f62e | 9295 | t->static_trace_marker_id); |
0fb4aa4b PA |
9296 | } |
9297 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9298 | { | |
d9b3f62e | 9299 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9300 | release_static_tracepoint_marker (&marker); |
9301 | ||
3e43a32a MS |
9302 | printf_filtered (_("Probed static tracepoint " |
9303 | "marker \"%s\"\n"), | |
d9b3f62e | 9304 | t->static_trace_marker_id); |
0fb4aa4b PA |
9305 | } |
9306 | else | |
3e43a32a MS |
9307 | warning (_("Couldn't determine the static " |
9308 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9309 | } |
9310 | ||
0d381245 VP |
9311 | loc = b->loc; |
9312 | } | |
9313 | else | |
018d34a4 | 9314 | { |
39d61571 | 9315 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9316 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9317 | loc->inserted = 1; | |
0d381245 VP |
9318 | } |
9319 | ||
9320 | if (b->cond_string) | |
9321 | { | |
bbc13ae3 KS |
9322 | const char *arg = b->cond_string; |
9323 | ||
1bb9788d TT |
9324 | loc->cond = parse_exp_1 (&arg, loc->address, |
9325 | block_for_pc (loc->address), 0); | |
0d381245 | 9326 | if (*arg) |
588ae58c | 9327 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9328 | } |
e7e0cddf SS |
9329 | |
9330 | /* Dynamic printf requires and uses additional arguments on the | |
9331 | command line, otherwise it's an error. */ | |
9332 | if (type == bp_dprintf) | |
9333 | { | |
9334 | if (b->extra_string) | |
9335 | update_dprintf_command_list (b); | |
9336 | else | |
9337 | error (_("Format string required")); | |
9338 | } | |
9339 | else if (b->extra_string) | |
588ae58c | 9340 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9341 | } |
018d34a4 | 9342 | |
56435ebe | 9343 | b->display_canonical = display_canonical; |
f00aae0f | 9344 | if (location != NULL) |
d28cd78a | 9345 | b->location = std::move (location); |
018d34a4 | 9346 | else |
d28cd78a | 9347 | b->location = new_address_location (b->loc->address, NULL, 0); |
f8eba3c6 | 9348 | b->filter = filter; |
d9b3f62e | 9349 | } |
018d34a4 | 9350 | |
d9b3f62e PA |
9351 | static void |
9352 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f | 9353 | struct symtabs_and_lines sals, |
ffc2605c | 9354 | event_location_up &&location, |
f8eba3c6 | 9355 | char *filter, char *cond_string, |
e7e0cddf | 9356 | char *extra_string, |
d9b3f62e PA |
9357 | enum bptype type, enum bpdisp disposition, |
9358 | int thread, int task, int ignore_count, | |
c0a91b2b | 9359 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9360 | int enabled, int internal, unsigned flags, |
9361 | int display_canonical) | |
d9b3f62e PA |
9362 | { |
9363 | struct breakpoint *b; | |
9364 | struct cleanup *old_chain; | |
9365 | ||
9366 | if (is_tracepoint_type (type)) | |
9367 | { | |
9368 | struct tracepoint *t; | |
9369 | ||
4d01a485 | 9370 | t = new tracepoint (); |
d9b3f62e PA |
9371 | b = &t->base; |
9372 | } | |
9373 | else | |
4d01a485 | 9374 | b = new breakpoint (); |
d9b3f62e PA |
9375 | |
9376 | old_chain = make_cleanup (xfree, b); | |
9377 | ||
9378 | init_breakpoint_sal (b, gdbarch, | |
ffc2605c | 9379 | sals, std::move (location), |
e7e0cddf | 9380 | filter, cond_string, extra_string, |
d9b3f62e PA |
9381 | type, disposition, |
9382 | thread, task, ignore_count, | |
9383 | ops, from_tty, | |
44f238bb PA |
9384 | enabled, internal, flags, |
9385 | display_canonical); | |
d9b3f62e PA |
9386 | discard_cleanups (old_chain); |
9387 | ||
3ea46bff | 9388 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9389 | } |
9390 | ||
9391 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9392 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9393 | value. COND_STRING, if not NULL, specified the condition to be | |
9394 | used for all breakpoints. Essentially the only case where | |
9395 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9396 | function. In that case, it's still not possible to specify | |
9397 | separate conditions for different overloaded functions, so | |
9398 | we take just a single condition string. | |
9399 | ||
c3f6f71d | 9400 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9401 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9402 | array contents). If the function fails (error() is called), the |
9403 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9404 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9405 | |
9406 | static void | |
8cdf0e15 | 9407 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9408 | struct linespec_result *canonical, |
e7e0cddf | 9409 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9410 | enum bptype type, enum bpdisp disposition, |
9411 | int thread, int task, int ignore_count, | |
c0a91b2b | 9412 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9413 | int enabled, int internal, unsigned flags) |
c906108c | 9414 | { |
018d34a4 | 9415 | int i; |
f8eba3c6 | 9416 | struct linespec_sals *lsal; |
cc59ec59 | 9417 | |
f8eba3c6 TT |
9418 | if (canonical->pre_expanded) |
9419 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9420 | ||
9421 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9422 | { |
f00aae0f | 9423 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9424 | 'break', without arguments. */ |
ffc2605c | 9425 | event_location_up location |
f00aae0f | 9426 | = (canonical->location != NULL |
8e9e35b1 | 9427 | ? copy_event_location (canonical->location.get ()) : NULL); |
f8eba3c6 | 9428 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
0d381245 | 9429 | |
f8eba3c6 TT |
9430 | make_cleanup (xfree, filter_string); |
9431 | create_breakpoint_sal (gdbarch, lsal->sals, | |
ffc2605c | 9432 | std::move (location), |
f8eba3c6 | 9433 | filter_string, |
e7e0cddf SS |
9434 | cond_string, extra_string, |
9435 | type, disposition, | |
84f4c1fe | 9436 | thread, task, ignore_count, ops, |
44f238bb | 9437 | from_tty, enabled, internal, flags, |
56435ebe | 9438 | canonical->special_display); |
c3f6f71d | 9439 | } |
c3f6f71d | 9440 | } |
c906108c | 9441 | |
f00aae0f | 9442 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9443 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9444 | addresses found. LOCATION points to the end of the SAL (for |
9445 | linespec locations). | |
9998af43 TJB |
9446 | |
9447 | The array and the line spec strings are allocated on the heap, it is | |
9448 | the caller's responsibility to free them. */ | |
c906108c | 9449 | |
b9362cc7 | 9450 | static void |
f00aae0f | 9451 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9452 | struct linespec_result *canonical) |
c3f6f71d | 9453 | { |
f00aae0f KS |
9454 | struct symtab_and_line cursal; |
9455 | ||
9456 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9457 | { | |
9458 | const char *address = get_linespec_location (location); | |
9459 | ||
9460 | if (address == NULL) | |
9461 | { | |
9462 | /* The last displayed codepoint, if it's valid, is our default | |
9463 | breakpoint address. */ | |
9464 | if (last_displayed_sal_is_valid ()) | |
9465 | { | |
9466 | struct linespec_sals lsal; | |
9467 | struct symtab_and_line sal; | |
9468 | CORE_ADDR pc; | |
9469 | ||
9470 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9471 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9472 | |
9473 | /* Set sal's pspace, pc, symtab, and line to the values | |
9474 | corresponding to the last call to print_frame_info. | |
9475 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9476 | as the breakpoint line number is inappropriate otherwise. | |
9477 | find_pc_line would adjust PC, re-set it back. */ | |
9478 | get_last_displayed_sal (&sal); | |
9479 | pc = sal.pc; | |
9480 | sal = find_pc_line (pc, 0); | |
9481 | ||
9482 | /* "break" without arguments is equivalent to "break *PC" | |
9483 | where PC is the last displayed codepoint's address. So | |
9484 | make sure to set sal.explicit_pc to prevent GDB from | |
9485 | trying to expand the list of sals to include all other | |
9486 | instances with the same symtab and line. */ | |
9487 | sal.pc = pc; | |
9488 | sal.explicit_pc = 1; | |
9489 | ||
9490 | lsal.sals.sals[0] = sal; | |
9491 | lsal.sals.nelts = 1; | |
9492 | lsal.canonical = NULL; | |
9493 | ||
9494 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9495 | return; | |
9496 | } | |
9497 | else | |
9498 | error (_("No default breakpoint address now.")); | |
c906108c | 9499 | } |
c906108c | 9500 | } |
f00aae0f KS |
9501 | |
9502 | /* Force almost all breakpoints to be in terms of the | |
9503 | current_source_symtab (which is decode_line_1's default). | |
9504 | This should produce the results we want almost all of the | |
9505 | time while leaving default_breakpoint_* alone. | |
9506 | ||
9507 | ObjC: However, don't match an Objective-C method name which | |
9508 | may have a '+' or '-' succeeded by a '['. */ | |
9509 | cursal = get_current_source_symtab_and_line (); | |
9510 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9511 | { |
f00aae0f | 9512 | const char *address = NULL; |
cc80f267 | 9513 | |
f00aae0f KS |
9514 | if (event_location_type (location) == LINESPEC_LOCATION) |
9515 | address = get_linespec_location (location); | |
cc80f267 | 9516 | |
f00aae0f KS |
9517 | if (!cursal.symtab |
9518 | || (address != NULL | |
9519 | && strchr ("+-", address[0]) != NULL | |
9520 | && address[1] != '[')) | |
9521 | { | |
c2f4122d | 9522 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9523 | get_last_displayed_symtab (), |
9524 | get_last_displayed_line (), | |
9525 | canonical, NULL, NULL); | |
9526 | return; | |
9527 | } | |
c906108c | 9528 | } |
f00aae0f | 9529 | |
c2f4122d | 9530 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9531 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9532 | } |
c906108c | 9533 | |
c906108c | 9534 | |
c3f6f71d | 9535 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9536 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9537 | |
b9362cc7 | 9538 | static void |
23e7acfb | 9539 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9540 | { |
9541 | int i; | |
cc59ec59 | 9542 | |
c3f6f71d | 9543 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9544 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9545 | } |
9546 | ||
7a697b8d SS |
9547 | /* Fast tracepoints may have restrictions on valid locations. For |
9548 | instance, a fast tracepoint using a jump instead of a trap will | |
9549 | likely have to overwrite more bytes than a trap would, and so can | |
9550 | only be placed where the instruction is longer than the jump, or a | |
9551 | multi-instruction sequence does not have a jump into the middle of | |
9552 | it, etc. */ | |
9553 | ||
9554 | static void | |
9555 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9556 | struct symtabs_and_lines *sals) | |
9557 | { | |
9558 | int i, rslt; | |
9559 | struct symtab_and_line *sal; | |
9560 | char *msg; | |
9561 | struct cleanup *old_chain; | |
9562 | ||
9563 | for (i = 0; i < sals->nelts; i++) | |
9564 | { | |
f8eba3c6 TT |
9565 | struct gdbarch *sarch; |
9566 | ||
7a697b8d SS |
9567 | sal = &sals->sals[i]; |
9568 | ||
f8eba3c6 TT |
9569 | sarch = get_sal_arch (*sal); |
9570 | /* We fall back to GDBARCH if there is no architecture | |
9571 | associated with SAL. */ | |
9572 | if (sarch == NULL) | |
9573 | sarch = gdbarch; | |
6b940e6a | 9574 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9575 | old_chain = make_cleanup (xfree, msg); |
9576 | ||
9577 | if (!rslt) | |
53c3572a | 9578 | error (_("May not have a fast tracepoint at %s%s"), |
f8eba3c6 | 9579 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9580 | |
9581 | do_cleanups (old_chain); | |
9582 | } | |
9583 | } | |
9584 | ||
018d34a4 VP |
9585 | /* Given TOK, a string specification of condition and thread, as |
9586 | accepted by the 'break' command, extract the condition | |
9587 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9588 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9589 | If no condition is found, *COND_STRING is set to NULL. |
9590 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9591 | |
9592 | static void | |
bbc13ae3 | 9593 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9594 | char **cond_string, int *thread, int *task, |
9595 | char **rest) | |
018d34a4 VP |
9596 | { |
9597 | *cond_string = NULL; | |
9598 | *thread = -1; | |
ed1d1739 KS |
9599 | *task = 0; |
9600 | *rest = NULL; | |
9601 | ||
018d34a4 VP |
9602 | while (tok && *tok) |
9603 | { | |
bbc13ae3 | 9604 | const char *end_tok; |
018d34a4 | 9605 | int toklen; |
bbc13ae3 KS |
9606 | const char *cond_start = NULL; |
9607 | const char *cond_end = NULL; | |
cc59ec59 | 9608 | |
bbc13ae3 | 9609 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9610 | |
9611 | if ((*tok == '"' || *tok == ',') && rest) | |
9612 | { | |
9613 | *rest = savestring (tok, strlen (tok)); | |
9614 | return; | |
9615 | } | |
9616 | ||
bbc13ae3 | 9617 | end_tok = skip_to_space_const (tok); |
d634f2de | 9618 | |
018d34a4 | 9619 | toklen = end_tok - tok; |
d634f2de | 9620 | |
018d34a4 VP |
9621 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9622 | { | |
9623 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9624 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9625 | cond_end = tok; |
d634f2de | 9626 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9627 | } |
9628 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9629 | { | |
5d5658a1 PA |
9630 | const char *tmptok; |
9631 | struct thread_info *thr; | |
d634f2de | 9632 | |
018d34a4 | 9633 | tok = end_tok + 1; |
5d5658a1 | 9634 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9635 | if (tok == tmptok) |
9636 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9637 | *thread = thr->global_num; |
bbc13ae3 | 9638 | tok = tmptok; |
018d34a4 | 9639 | } |
4a306c9a JB |
9640 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9641 | { | |
9642 | char *tmptok; | |
9643 | ||
9644 | tok = end_tok + 1; | |
bbc13ae3 | 9645 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9646 | if (tok == tmptok) |
9647 | error (_("Junk after task keyword.")); | |
9648 | if (!valid_task_id (*task)) | |
b6199126 | 9649 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9650 | tok = tmptok; |
4a306c9a | 9651 | } |
e7e0cddf SS |
9652 | else if (rest) |
9653 | { | |
9654 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9655 | return; |
e7e0cddf | 9656 | } |
018d34a4 VP |
9657 | else |
9658 | error (_("Junk at end of arguments.")); | |
9659 | } | |
9660 | } | |
9661 | ||
0fb4aa4b PA |
9662 | /* Decode a static tracepoint marker spec. */ |
9663 | ||
9664 | static struct symtabs_and_lines | |
f00aae0f | 9665 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9666 | { |
9667 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9668 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9669 | struct cleanup *old_chain; |
f00aae0f KS |
9670 | const char *p = &(*arg_p)[3]; |
9671 | const char *endp; | |
0fb4aa4b PA |
9672 | char *marker_str; |
9673 | int i; | |
9674 | ||
f00aae0f | 9675 | p = skip_spaces_const (p); |
0fb4aa4b | 9676 | |
f00aae0f | 9677 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9678 | |
9679 | marker_str = savestring (p, endp - p); | |
9680 | old_chain = make_cleanup (xfree, marker_str); | |
9681 | ||
9682 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9683 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9684 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9685 | ||
9686 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9687 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9688 | |
9689 | for (i = 0; i < sals.nelts; i++) | |
9690 | { | |
9691 | struct static_tracepoint_marker *marker; | |
9692 | ||
9693 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9694 | ||
9695 | init_sal (&sals.sals[i]); | |
9696 | ||
9697 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9698 | sals.sals[i].pc = marker->address; | |
9699 | ||
9700 | release_static_tracepoint_marker (marker); | |
9701 | } | |
9702 | ||
9703 | do_cleanups (old_chain); | |
9704 | ||
9705 | *arg_p = endp; | |
9706 | return sals; | |
9707 | } | |
9708 | ||
f00aae0f | 9709 | /* See breakpoint.h. */ |
0101ce28 | 9710 | |
8cdf0e15 VP |
9711 | int |
9712 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9713 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9714 | int thread, char *extra_string, |
f00aae0f | 9715 | int parse_extra, |
0fb4aa4b | 9716 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9717 | int ignore_count, |
9718 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9719 | const struct breakpoint_ops *ops, |
44f238bb PA |
9720 | int from_tty, int enabled, int internal, |
9721 | unsigned flags) | |
c3f6f71d | 9722 | { |
7efd8fc2 | 9723 | struct linespec_result canonical; |
80c99de1 | 9724 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9725 | int pending = 0; |
4a306c9a | 9726 | int task = 0; |
86b17b60 | 9727 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9728 | |
348d480f PA |
9729 | gdb_assert (ops != NULL); |
9730 | ||
f00aae0f KS |
9731 | /* If extra_string isn't useful, set it to NULL. */ |
9732 | if (extra_string != NULL && *extra_string == '\0') | |
9733 | extra_string = NULL; | |
9734 | ||
492d29ea | 9735 | TRY |
b78a6381 | 9736 | { |
f00aae0f | 9737 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9738 | } |
492d29ea | 9739 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9740 | { |
492d29ea PA |
9741 | /* If caller is interested in rc value from parse, set |
9742 | value. */ | |
9743 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9744 | { |
05ff989b AC |
9745 | /* If pending breakpoint support is turned off, throw |
9746 | error. */ | |
fa8d40ab JJ |
9747 | |
9748 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9749 | throw_exception (e); |
9750 | ||
9751 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9752 | |
05ff989b AC |
9753 | /* If pending breakpoint support is auto query and the user |
9754 | selects no, then simply return the error code. */ | |
059fb39f | 9755 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9756 | && !nquery (_("Make %s pending on future shared library load? "), |
9757 | bptype_string (type_wanted))) | |
fd9b8c24 | 9758 | return 0; |
fa8d40ab | 9759 | |
05ff989b AC |
9760 | /* At this point, either the user was queried about setting |
9761 | a pending breakpoint and selected yes, or pending | |
9762 | breakpoint behavior is on and thus a pending breakpoint | |
9763 | is defaulted on behalf of the user. */ | |
f00aae0f | 9764 | pending = 1; |
0101ce28 | 9765 | } |
492d29ea PA |
9766 | else |
9767 | throw_exception (e); | |
0101ce28 | 9768 | } |
492d29ea PA |
9769 | END_CATCH |
9770 | ||
f00aae0f | 9771 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9772 | return 0; |
c3f6f71d | 9773 | |
c3f6f71d JM |
9774 | /* ----------------------------- SNIP ----------------------------- |
9775 | Anything added to the cleanup chain beyond this point is assumed | |
9776 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9777 | then the memory is not reclaimed. */ |
9778 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9779 | |
c3f6f71d JM |
9780 | /* Resolve all line numbers to PC's and verify that the addresses |
9781 | are ok for the target. */ | |
0101ce28 | 9782 | if (!pending) |
f8eba3c6 TT |
9783 | { |
9784 | int ix; | |
9785 | struct linespec_sals *iter; | |
9786 | ||
9787 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9788 | breakpoint_sals_to_pc (&iter->sals); | |
9789 | } | |
c3f6f71d | 9790 | |
7a697b8d | 9791 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9792 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9793 | { |
9794 | int ix; | |
9795 | struct linespec_sals *iter; | |
9796 | ||
9797 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9798 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9799 | } | |
7a697b8d | 9800 | |
c3f6f71d JM |
9801 | /* Verify that condition can be parsed, before setting any |
9802 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9803 | breakpoint. */ |
0101ce28 | 9804 | if (!pending) |
c3f6f71d | 9805 | { |
f00aae0f | 9806 | if (parse_extra) |
72b2ff0e | 9807 | { |
0878d0fa | 9808 | char *rest; |
52d361e1 YQ |
9809 | struct linespec_sals *lsal; |
9810 | ||
9811 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9812 | ||
0878d0fa YQ |
9813 | /* Here we only parse 'arg' to separate condition |
9814 | from thread number, so parsing in context of first | |
9815 | sal is OK. When setting the breakpoint we'll | |
9816 | re-parse it in context of each sal. */ | |
9817 | ||
f00aae0f KS |
9818 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9819 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9820 | if (cond_string) |
9821 | make_cleanup (xfree, cond_string); | |
9822 | if (rest) | |
9823 | make_cleanup (xfree, rest); | |
9824 | if (rest) | |
9825 | extra_string = rest; | |
f00aae0f KS |
9826 | else |
9827 | extra_string = NULL; | |
72b2ff0e | 9828 | } |
2f069f6f | 9829 | else |
72b2ff0e | 9830 | { |
f00aae0f KS |
9831 | if (type_wanted != bp_dprintf |
9832 | && extra_string != NULL && *extra_string != '\0') | |
9833 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9834 | |
9835 | /* Create a private copy of condition string. */ | |
9836 | if (cond_string) | |
9837 | { | |
9838 | cond_string = xstrdup (cond_string); | |
9839 | make_cleanup (xfree, cond_string); | |
9840 | } | |
9841 | /* Create a private copy of any extra string. */ | |
9842 | if (extra_string) | |
9843 | { | |
9844 | extra_string = xstrdup (extra_string); | |
9845 | make_cleanup (xfree, extra_string); | |
9846 | } | |
72b2ff0e | 9847 | } |
0fb4aa4b | 9848 | |
52d361e1 | 9849 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9850 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9851 | tempflag ? disp_del : disp_donttouch, |
9852 | thread, task, ignore_count, ops, | |
44f238bb | 9853 | from_tty, enabled, internal, flags); |
c906108c | 9854 | } |
0101ce28 JJ |
9855 | else |
9856 | { | |
0101ce28 JJ |
9857 | struct breakpoint *b; |
9858 | ||
bfccc43c YQ |
9859 | if (is_tracepoint_type (type_wanted)) |
9860 | { | |
9861 | struct tracepoint *t; | |
9862 | ||
4d01a485 | 9863 | t = new tracepoint (); |
bfccc43c YQ |
9864 | b = &t->base; |
9865 | } | |
9866 | else | |
4d01a485 | 9867 | b = new breakpoint (); |
bfccc43c YQ |
9868 | |
9869 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
d28cd78a | 9870 | b->location = copy_event_location (location); |
bfccc43c | 9871 | |
f00aae0f KS |
9872 | if (parse_extra) |
9873 | b->cond_string = NULL; | |
e12c7713 MK |
9874 | else |
9875 | { | |
9876 | /* Create a private copy of condition string. */ | |
9877 | if (cond_string) | |
9878 | { | |
9879 | cond_string = xstrdup (cond_string); | |
9880 | make_cleanup (xfree, cond_string); | |
9881 | } | |
9882 | b->cond_string = cond_string; | |
15630549 | 9883 | b->thread = thread; |
e12c7713 | 9884 | } |
f00aae0f KS |
9885 | |
9886 | /* Create a private copy of any extra string. */ | |
9887 | if (extra_string != NULL) | |
9888 | { | |
9889 | extra_string = xstrdup (extra_string); | |
9890 | make_cleanup (xfree, extra_string); | |
9891 | } | |
9892 | b->extra_string = extra_string; | |
0101ce28 | 9893 | b->ignore_count = ignore_count; |
0101ce28 | 9894 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9895 | b->condition_not_parsed = 1; |
41447f92 | 9896 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9897 | if ((type_wanted != bp_breakpoint |
9898 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9899 | b->pspace = current_program_space; |
8bea4e01 | 9900 | |
bfccc43c | 9901 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9902 | } |
9903 | ||
f8eba3c6 | 9904 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9905 | { |
3e43a32a MS |
9906 | warning (_("Multiple breakpoints were set.\nUse the " |
9907 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9908 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9909 | } |
9910 | ||
80c99de1 PA |
9911 | /* That's it. Discard the cleanups for data inserted into the |
9912 | breakpoint. */ | |
9913 | discard_cleanups (bkpt_chain); | |
217dc9e2 | 9914 | |
80c99de1 | 9915 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9916 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9917 | |
9918 | return 1; | |
c3f6f71d | 9919 | } |
c906108c | 9920 | |
348d480f | 9921 | /* Set a breakpoint. |
72b2ff0e VP |
9922 | ARG is a string describing breakpoint address, |
9923 | condition, and thread. | |
9924 | FLAG specifies if a breakpoint is hardware on, | |
9925 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9926 | and BP_TEMPFLAG. */ | |
348d480f | 9927 | |
98deb0da | 9928 | static void |
72b2ff0e | 9929 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9930 | { |
72b2ff0e | 9931 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9932 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9933 | ? bp_hardware_breakpoint | |
9934 | : bp_breakpoint); | |
55aa24fb | 9935 | struct breakpoint_ops *ops; |
f00aae0f | 9936 | |
ffc2605c | 9937 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9938 | |
9939 | /* Matching breakpoints on probes. */ | |
5b56227b | 9940 | if (location != NULL |
ffc2605c | 9941 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9942 | ops = &bkpt_probe_breakpoint_ops; |
9943 | else | |
9944 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9945 | |
8cdf0e15 | 9946 | create_breakpoint (get_current_arch (), |
ffc2605c | 9947 | location.get (), |
f00aae0f | 9948 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9949 | tempflag, type_wanted, |
8cdf0e15 VP |
9950 | 0 /* Ignore count */, |
9951 | pending_break_support, | |
55aa24fb | 9952 | ops, |
8cdf0e15 | 9953 | from_tty, |
84f4c1fe | 9954 | 1 /* enabled */, |
44f238bb PA |
9955 | 0 /* internal */, |
9956 | 0); | |
c906108c SS |
9957 | } |
9958 | ||
c906108c SS |
9959 | /* Helper function for break_command_1 and disassemble_command. */ |
9960 | ||
9961 | void | |
fba45db2 | 9962 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9963 | { |
9964 | CORE_ADDR pc; | |
9965 | ||
9966 | if (sal->pc == 0 && sal->symtab != NULL) | |
9967 | { | |
9968 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9969 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9970 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9971 | sal->pc = pc; |
6a048695 | 9972 | |
4a64f543 MS |
9973 | /* If this SAL corresponds to a breakpoint inserted using a line |
9974 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9975 | if (sal->explicit_line) |
059acae7 | 9976 | skip_prologue_sal (sal); |
c906108c SS |
9977 | } |
9978 | ||
9979 | if (sal->section == 0 && sal->symtab != NULL) | |
9980 | { | |
346d1dfe | 9981 | const struct blockvector *bv; |
3977b71f | 9982 | const struct block *b; |
c5aa993b | 9983 | struct symbol *sym; |
c906108c | 9984 | |
43f3e411 DE |
9985 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9986 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9987 | if (bv != NULL) |
9988 | { | |
7f0df278 | 9989 | sym = block_linkage_function (b); |
c906108c SS |
9990 | if (sym != NULL) |
9991 | { | |
eb822aa6 DE |
9992 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9993 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9994 | sym); | |
c906108c SS |
9995 | } |
9996 | else | |
9997 | { | |
4a64f543 MS |
9998 | /* It really is worthwhile to have the section, so we'll |
9999 | just have to look harder. This case can be executed | |
10000 | if we have line numbers but no functions (as can | |
10001 | happen in assembly source). */ | |
c906108c | 10002 | |
7cbd4a93 | 10003 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10004 | struct cleanup *old_chain = save_current_space_and_thread (); |
10005 | ||
10006 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10007 | |
10008 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10009 | if (msym.minsym) |
efd66ac6 | 10010 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10011 | |
10012 | do_cleanups (old_chain); | |
c906108c SS |
10013 | } |
10014 | } | |
10015 | } | |
10016 | } | |
10017 | ||
10018 | void | |
fba45db2 | 10019 | break_command (char *arg, int from_tty) |
c906108c | 10020 | { |
db107f19 | 10021 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10022 | } |
10023 | ||
c906108c | 10024 | void |
fba45db2 | 10025 | tbreak_command (char *arg, int from_tty) |
c906108c | 10026 | { |
db107f19 | 10027 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10028 | } |
10029 | ||
c906108c | 10030 | static void |
fba45db2 | 10031 | hbreak_command (char *arg, int from_tty) |
c906108c | 10032 | { |
db107f19 | 10033 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10034 | } |
10035 | ||
10036 | static void | |
fba45db2 | 10037 | thbreak_command (char *arg, int from_tty) |
c906108c | 10038 | { |
db107f19 | 10039 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10040 | } |
10041 | ||
10042 | static void | |
fba45db2 | 10043 | stop_command (char *arg, int from_tty) |
c906108c | 10044 | { |
a3f17187 | 10045 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10046 | Usage: stop in <function | address>\n\ |
a3f17187 | 10047 | stop at <line>\n")); |
c906108c SS |
10048 | } |
10049 | ||
10050 | static void | |
fba45db2 | 10051 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10052 | { |
10053 | int badInput = 0; | |
10054 | ||
c5aa993b | 10055 | if (arg == (char *) NULL) |
c906108c SS |
10056 | badInput = 1; |
10057 | else if (*arg != '*') | |
10058 | { | |
10059 | char *argptr = arg; | |
10060 | int hasColon = 0; | |
10061 | ||
4a64f543 | 10062 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10063 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10064 | function/method name. */ |
c906108c | 10065 | while (*argptr && !hasColon) |
c5aa993b JM |
10066 | { |
10067 | hasColon = (*argptr == ':'); | |
10068 | argptr++; | |
10069 | } | |
c906108c SS |
10070 | |
10071 | if (hasColon) | |
c5aa993b | 10072 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10073 | else |
c5aa993b | 10074 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10075 | } |
10076 | ||
10077 | if (badInput) | |
a3f17187 | 10078 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10079 | else |
db107f19 | 10080 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10081 | } |
10082 | ||
10083 | static void | |
fba45db2 | 10084 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10085 | { |
10086 | int badInput = 0; | |
10087 | ||
c5aa993b | 10088 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10089 | badInput = 1; |
10090 | else | |
10091 | { | |
10092 | char *argptr = arg; | |
10093 | int hasColon = 0; | |
10094 | ||
4a64f543 MS |
10095 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10096 | it is probably a line number. */ | |
c906108c | 10097 | while (*argptr && !hasColon) |
c5aa993b JM |
10098 | { |
10099 | hasColon = (*argptr == ':'); | |
10100 | argptr++; | |
10101 | } | |
c906108c SS |
10102 | |
10103 | if (hasColon) | |
c5aa993b | 10104 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10105 | else |
c5aa993b | 10106 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10107 | } |
10108 | ||
10109 | if (badInput) | |
a3f17187 | 10110 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10111 | else |
db107f19 | 10112 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10113 | } |
10114 | ||
e7e0cddf SS |
10115 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10116 | with a prewired command list consisting of a single output command, | |
10117 | built from extra arguments supplied on the dprintf command | |
10118 | line. */ | |
10119 | ||
da821c7b | 10120 | static void |
e7e0cddf SS |
10121 | dprintf_command (char *arg, int from_tty) |
10122 | { | |
ffc2605c | 10123 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
10124 | |
10125 | /* If non-NULL, ARG should have been advanced past the location; | |
10126 | the next character must be ','. */ | |
10127 | if (arg != NULL) | |
10128 | { | |
10129 | if (arg[0] != ',' || arg[1] == '\0') | |
10130 | error (_("Format string required")); | |
10131 | else | |
10132 | { | |
10133 | /* Skip the comma. */ | |
10134 | ++arg; | |
10135 | } | |
10136 | } | |
10137 | ||
e7e0cddf | 10138 | create_breakpoint (get_current_arch (), |
ffc2605c | 10139 | location.get (), |
f00aae0f | 10140 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
10141 | 0, bp_dprintf, |
10142 | 0 /* Ignore count */, | |
10143 | pending_break_support, | |
10144 | &dprintf_breakpoint_ops, | |
10145 | from_tty, | |
10146 | 1 /* enabled */, | |
10147 | 0 /* internal */, | |
10148 | 0); | |
10149 | } | |
10150 | ||
d3ce09f5 SS |
10151 | static void |
10152 | agent_printf_command (char *arg, int from_tty) | |
10153 | { | |
10154 | error (_("May only run agent-printf on the target")); | |
10155 | } | |
10156 | ||
f1310107 TJB |
10157 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10158 | ranged breakpoints. */ | |
10159 | ||
10160 | static int | |
10161 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10162 | struct address_space *aspace, | |
09ac7c10 TT |
10163 | CORE_ADDR bp_addr, |
10164 | const struct target_waitstatus *ws) | |
f1310107 | 10165 | { |
09ac7c10 | 10166 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10167 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10168 | return 0; |
10169 | ||
f1310107 TJB |
10170 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10171 | bl->length, aspace, bp_addr); | |
10172 | } | |
10173 | ||
10174 | /* Implement the "resources_needed" breakpoint_ops method for | |
10175 | ranged breakpoints. */ | |
10176 | ||
10177 | static int | |
10178 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10179 | { | |
10180 | return target_ranged_break_num_registers (); | |
10181 | } | |
10182 | ||
10183 | /* Implement the "print_it" breakpoint_ops method for | |
10184 | ranged breakpoints. */ | |
10185 | ||
10186 | static enum print_stop_action | |
348d480f | 10187 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10188 | { |
348d480f | 10189 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10190 | struct bp_location *bl = b->loc; |
79a45e25 | 10191 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10192 | |
10193 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10194 | ||
10195 | /* Ranged breakpoints have only one location. */ | |
10196 | gdb_assert (bl && bl->next == NULL); | |
10197 | ||
10198 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10199 | |
10200 | maybe_print_thread_hit_breakpoint (uiout); | |
10201 | ||
f1310107 | 10202 | if (b->disposition == disp_del) |
112e8700 | 10203 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 10204 | else |
112e8700 SM |
10205 | uiout->text ("Ranged breakpoint "); |
10206 | if (uiout->is_mi_like_p ()) | |
f1310107 | 10207 | { |
112e8700 | 10208 | uiout->field_string ("reason", |
f1310107 | 10209 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 10210 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 10211 | } |
112e8700 SM |
10212 | uiout->field_int ("bkptno", b->number); |
10213 | uiout->text (", "); | |
f1310107 TJB |
10214 | |
10215 | return PRINT_SRC_AND_LOC; | |
10216 | } | |
10217 | ||
10218 | /* Implement the "print_one" breakpoint_ops method for | |
10219 | ranged breakpoints. */ | |
10220 | ||
10221 | static void | |
10222 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10223 | struct bp_location **last_loc) | |
10224 | { | |
10225 | struct bp_location *bl = b->loc; | |
10226 | struct value_print_options opts; | |
79a45e25 | 10227 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10228 | |
10229 | /* Ranged breakpoints have only one location. */ | |
10230 | gdb_assert (bl && bl->next == NULL); | |
10231 | ||
10232 | get_user_print_options (&opts); | |
10233 | ||
10234 | if (opts.addressprint) | |
10235 | /* We don't print the address range here, it will be printed later | |
10236 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 10237 | uiout->field_skip ("addr"); |
f1310107 TJB |
10238 | annotate_field (5); |
10239 | print_breakpoint_location (b, bl); | |
10240 | *last_loc = bl; | |
10241 | } | |
10242 | ||
10243 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10244 | ranged breakpoints. */ | |
10245 | ||
10246 | static void | |
10247 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10248 | struct ui_out *uiout) | |
10249 | { | |
10250 | CORE_ADDR address_start, address_end; | |
10251 | struct bp_location *bl = b->loc; | |
d7e74731 | 10252 | string_file stb; |
f1310107 TJB |
10253 | |
10254 | gdb_assert (bl); | |
10255 | ||
10256 | address_start = bl->address; | |
10257 | address_end = address_start + bl->length - 1; | |
10258 | ||
112e8700 | 10259 | uiout->text ("\taddress range: "); |
d7e74731 PA |
10260 | stb.printf ("[%s, %s]", |
10261 | print_core_address (bl->gdbarch, address_start), | |
10262 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
10263 | uiout->field_stream ("addr", stb); |
10264 | uiout->text ("\n"); | |
f1310107 TJB |
10265 | } |
10266 | ||
10267 | /* Implement the "print_mention" breakpoint_ops method for | |
10268 | ranged breakpoints. */ | |
10269 | ||
10270 | static void | |
10271 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10272 | { | |
10273 | struct bp_location *bl = b->loc; | |
79a45e25 | 10274 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10275 | |
10276 | gdb_assert (bl); | |
10277 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10278 | ||
112e8700 | 10279 | if (uiout->is_mi_like_p ()) |
f1310107 TJB |
10280 | return; |
10281 | ||
10282 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10283 | b->number, paddress (bl->gdbarch, bl->address), | |
10284 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10285 | } | |
10286 | ||
10287 | /* Implement the "print_recreate" breakpoint_ops method for | |
10288 | ranged breakpoints. */ | |
10289 | ||
10290 | static void | |
10291 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10292 | { | |
f00aae0f | 10293 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
10294 | event_location_to_string (b->location.get ()), |
10295 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 10296 | print_recreate_thread (b, fp); |
f1310107 TJB |
10297 | } |
10298 | ||
10299 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10300 | ||
2060206e | 10301 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10302 | |
10303 | /* Find the address where the end of the breakpoint range should be | |
10304 | placed, given the SAL of the end of the range. This is so that if | |
10305 | the user provides a line number, the end of the range is set to the | |
10306 | last instruction of the given line. */ | |
10307 | ||
10308 | static CORE_ADDR | |
10309 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10310 | { | |
10311 | CORE_ADDR end; | |
10312 | ||
10313 | /* If the user provided a PC value, use it. Otherwise, | |
10314 | find the address of the end of the given location. */ | |
10315 | if (sal.explicit_pc) | |
10316 | end = sal.pc; | |
10317 | else | |
10318 | { | |
10319 | int ret; | |
10320 | CORE_ADDR start; | |
10321 | ||
10322 | ret = find_line_pc_range (sal, &start, &end); | |
10323 | if (!ret) | |
10324 | error (_("Could not find location of the end of the range.")); | |
10325 | ||
10326 | /* find_line_pc_range returns the start of the next line. */ | |
10327 | end--; | |
10328 | } | |
10329 | ||
10330 | return end; | |
10331 | } | |
10332 | ||
10333 | /* Implement the "break-range" CLI command. */ | |
10334 | ||
10335 | static void | |
10336 | break_range_command (char *arg, int from_tty) | |
10337 | { | |
870f88f7 | 10338 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10339 | struct linespec_result canonical_start, canonical_end; |
10340 | int bp_count, can_use_bp, length; | |
10341 | CORE_ADDR end; | |
10342 | struct breakpoint *b; | |
10343 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10344 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10345 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10346 | |
10347 | /* We don't support software ranged breakpoints. */ | |
10348 | if (target_ranged_break_num_registers () < 0) | |
10349 | error (_("This target does not support hardware ranged breakpoints.")); | |
10350 | ||
10351 | bp_count = hw_breakpoint_used_count (); | |
10352 | bp_count += target_ranged_break_num_registers (); | |
10353 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10354 | bp_count, 0); | |
10355 | if (can_use_bp < 0) | |
10356 | error (_("Hardware breakpoints used exceeds limit.")); | |
10357 | ||
f8eba3c6 | 10358 | arg = skip_spaces (arg); |
f1310107 TJB |
10359 | if (arg == NULL || arg[0] == '\0') |
10360 | error(_("No address range specified.")); | |
10361 | ||
f8eba3c6 | 10362 | arg_start = arg; |
ffc2605c TT |
10363 | event_location_up start_location = string_to_event_location (&arg, |
10364 | current_language); | |
10365 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
10366 | |
10367 | if (arg[0] != ',') | |
10368 | error (_("Too few arguments.")); | |
f8eba3c6 | 10369 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10370 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10371 | |
10372 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10373 | ||
10374 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10375 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10376 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10377 | ||
f8eba3c6 TT |
10378 | sal_start = lsal_start->sals.sals[0]; |
10379 | addr_string_start = savestring (arg_start, arg - arg_start); | |
16e802b9 | 10380 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); |
f1310107 TJB |
10381 | |
10382 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10383 | arg = skip_spaces (arg); |
f1310107 TJB |
10384 | |
10385 | /* Parse the end location. */ | |
10386 | ||
f1310107 TJB |
10387 | arg_start = arg; |
10388 | ||
f8eba3c6 | 10389 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10390 | parse_breakpoint_sals because we need to specify the start location's |
10391 | symtab and line as the default symtab and line for the end of the | |
10392 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10393 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
10394 | event_location_up end_location = string_to_event_location (&arg, |
10395 | current_language); | |
10396 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
10397 | sal_start.symtab, sal_start.line, |
10398 | &canonical_end, NULL, NULL); | |
10399 | ||
f8eba3c6 | 10400 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10401 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10402 | |
10403 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10404 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10405 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10406 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10407 | ||
f8eba3c6 | 10408 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10409 | |
10410 | end = find_breakpoint_range_end (sal_end); | |
10411 | if (sal_start.pc > end) | |
177b42fe | 10412 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10413 | |
10414 | length = end - sal_start.pc + 1; | |
10415 | if (length < 0) | |
10416 | /* Length overflowed. */ | |
10417 | error (_("Address range too large.")); | |
10418 | else if (length == 1) | |
10419 | { | |
10420 | /* This range is simple enough to be handled by | |
10421 | the `hbreak' command. */ | |
10422 | hbreak_command (addr_string_start, 1); | |
10423 | ||
10424 | do_cleanups (cleanup_bkpt); | |
10425 | ||
10426 | return; | |
10427 | } | |
10428 | ||
10429 | /* Now set up the breakpoint. */ | |
10430 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10431 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10432 | set_breakpoint_count (breakpoint_count + 1); |
10433 | b->number = breakpoint_count; | |
10434 | b->disposition = disp_donttouch; | |
d28cd78a TT |
10435 | b->location = std::move (start_location); |
10436 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
10437 | b->loc->length = length; |
10438 | ||
f8eba3c6 | 10439 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10440 | |
10441 | mention (b); | |
8d3788bd | 10442 | observer_notify_breakpoint_created (b); |
44702360 | 10443 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10444 | } |
10445 | ||
4a64f543 MS |
10446 | /* Return non-zero if EXP is verified as constant. Returned zero |
10447 | means EXP is variable. Also the constant detection may fail for | |
10448 | some constant expressions and in such case still falsely return | |
10449 | zero. */ | |
2e6e3d9c | 10450 | |
65d79d4b SDJ |
10451 | static int |
10452 | watchpoint_exp_is_const (const struct expression *exp) | |
10453 | { | |
10454 | int i = exp->nelts; | |
10455 | ||
10456 | while (i > 0) | |
10457 | { | |
10458 | int oplenp, argsp; | |
10459 | ||
10460 | /* We are only interested in the descriptor of each element. */ | |
10461 | operator_length (exp, i, &oplenp, &argsp); | |
10462 | i -= oplenp; | |
10463 | ||
10464 | switch (exp->elts[i].opcode) | |
10465 | { | |
10466 | case BINOP_ADD: | |
10467 | case BINOP_SUB: | |
10468 | case BINOP_MUL: | |
10469 | case BINOP_DIV: | |
10470 | case BINOP_REM: | |
10471 | case BINOP_MOD: | |
10472 | case BINOP_LSH: | |
10473 | case BINOP_RSH: | |
10474 | case BINOP_LOGICAL_AND: | |
10475 | case BINOP_LOGICAL_OR: | |
10476 | case BINOP_BITWISE_AND: | |
10477 | case BINOP_BITWISE_IOR: | |
10478 | case BINOP_BITWISE_XOR: | |
10479 | case BINOP_EQUAL: | |
10480 | case BINOP_NOTEQUAL: | |
10481 | case BINOP_LESS: | |
10482 | case BINOP_GTR: | |
10483 | case BINOP_LEQ: | |
10484 | case BINOP_GEQ: | |
10485 | case BINOP_REPEAT: | |
10486 | case BINOP_COMMA: | |
10487 | case BINOP_EXP: | |
10488 | case BINOP_MIN: | |
10489 | case BINOP_MAX: | |
10490 | case BINOP_INTDIV: | |
10491 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10492 | case TERNOP_COND: |
10493 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10494 | |
10495 | case OP_LONG: | |
10496 | case OP_DOUBLE: | |
10497 | case OP_DECFLOAT: | |
10498 | case OP_LAST: | |
10499 | case OP_COMPLEX: | |
10500 | case OP_STRING: | |
65d79d4b SDJ |
10501 | case OP_ARRAY: |
10502 | case OP_TYPE: | |
608b4967 TT |
10503 | case OP_TYPEOF: |
10504 | case OP_DECLTYPE: | |
6e72ca20 | 10505 | case OP_TYPEID: |
65d79d4b SDJ |
10506 | case OP_NAME: |
10507 | case OP_OBJC_NSSTRING: | |
10508 | ||
10509 | case UNOP_NEG: | |
10510 | case UNOP_LOGICAL_NOT: | |
10511 | case UNOP_COMPLEMENT: | |
10512 | case UNOP_ADDR: | |
10513 | case UNOP_HIGH: | |
aeaa2474 | 10514 | case UNOP_CAST: |
9eaf6705 TT |
10515 | |
10516 | case UNOP_CAST_TYPE: | |
10517 | case UNOP_REINTERPRET_CAST: | |
10518 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10519 | /* Unary, binary and ternary operators: We have to check |
10520 | their operands. If they are constant, then so is the | |
10521 | result of that operation. For instance, if A and B are | |
10522 | determined to be constants, then so is "A + B". | |
10523 | ||
10524 | UNOP_IND is one exception to the rule above, because the | |
10525 | value of *ADDR is not necessarily a constant, even when | |
10526 | ADDR is. */ | |
65d79d4b SDJ |
10527 | break; |
10528 | ||
10529 | case OP_VAR_VALUE: | |
10530 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10531 | |
65d79d4b | 10532 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10533 | possible that a buggy compiler could mark a variable as |
10534 | constant even when it is not, and TYPE_CONST would return | |
10535 | true in this case, while SYMBOL_CLASS wouldn't. | |
10536 | ||
10537 | We also have to check for function symbols because they | |
10538 | are always constant. */ | |
65d79d4b SDJ |
10539 | { |
10540 | struct symbol *s = exp->elts[i + 2].symbol; | |
10541 | ||
10542 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10543 | && SYMBOL_CLASS (s) != LOC_CONST | |
10544 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10545 | return 0; | |
10546 | break; | |
10547 | } | |
10548 | ||
10549 | /* The default action is to return 0 because we are using | |
10550 | the optimistic approach here: If we don't know something, | |
10551 | then it is not a constant. */ | |
10552 | default: | |
10553 | return 0; | |
10554 | } | |
10555 | } | |
10556 | ||
10557 | return 1; | |
10558 | } | |
10559 | ||
3a5c3e22 PA |
10560 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10561 | ||
10562 | static void | |
10563 | dtor_watchpoint (struct breakpoint *self) | |
10564 | { | |
10565 | struct watchpoint *w = (struct watchpoint *) self; | |
10566 | ||
3a5c3e22 PA |
10567 | xfree (w->exp_string); |
10568 | xfree (w->exp_string_reparse); | |
10569 | value_free (w->val); | |
10570 | ||
10571 | base_breakpoint_ops.dtor (self); | |
10572 | } | |
10573 | ||
348d480f PA |
10574 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10575 | ||
10576 | static void | |
10577 | re_set_watchpoint (struct breakpoint *b) | |
10578 | { | |
3a5c3e22 PA |
10579 | struct watchpoint *w = (struct watchpoint *) b; |
10580 | ||
348d480f PA |
10581 | /* Watchpoint can be either on expression using entirely global |
10582 | variables, or it can be on local variables. | |
10583 | ||
10584 | Watchpoints of the first kind are never auto-deleted, and even | |
10585 | persist across program restarts. Since they can use variables | |
10586 | from shared libraries, we need to reparse expression as libraries | |
10587 | are loaded and unloaded. | |
10588 | ||
10589 | Watchpoints on local variables can also change meaning as result | |
10590 | of solib event. For example, if a watchpoint uses both a local | |
10591 | and a global variables in expression, it's a local watchpoint, | |
10592 | but unloading of a shared library will make the expression | |
10593 | invalid. This is not a very common use case, but we still | |
10594 | re-evaluate expression, to avoid surprises to the user. | |
10595 | ||
10596 | Note that for local watchpoints, we re-evaluate it only if | |
10597 | watchpoints frame id is still valid. If it's not, it means the | |
10598 | watchpoint is out of scope and will be deleted soon. In fact, | |
10599 | I'm not sure we'll ever be called in this case. | |
10600 | ||
10601 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10602 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10603 | |
3a5c3e22 PA |
10604 | Don't do anything about disabled watchpoints, since they will be |
10605 | reevaluated again when enabled. */ | |
10606 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10607 | } |
10608 | ||
77b06cd7 TJB |
10609 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10610 | ||
10611 | static int | |
10612 | insert_watchpoint (struct bp_location *bl) | |
10613 | { | |
3a5c3e22 PA |
10614 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10615 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10616 | |
10617 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10618 | w->cond_exp.get ()); |
77b06cd7 TJB |
10619 | } |
10620 | ||
10621 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10622 | ||
10623 | static int | |
73971819 | 10624 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10625 | { |
3a5c3e22 PA |
10626 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10627 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10628 | |
10629 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10630 | w->cond_exp.get ()); |
e09342b5 TJB |
10631 | } |
10632 | ||
e09342b5 | 10633 | static int |
348d480f | 10634 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10635 | struct address_space *aspace, CORE_ADDR bp_addr, |
10636 | const struct target_waitstatus *ws) | |
e09342b5 | 10637 | { |
348d480f | 10638 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10639 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10640 | |
348d480f PA |
10641 | /* Continuable hardware watchpoints are treated as non-existent if the |
10642 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10643 | some data address). Otherwise gdb won't stop on a break instruction | |
10644 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10645 | been defined. Also skip watchpoints which we know did not trigger | |
10646 | (did not match the data address). */ | |
10647 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10648 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10649 | return 0; |
9c06b0b4 | 10650 | |
348d480f | 10651 | return 1; |
9c06b0b4 TJB |
10652 | } |
10653 | ||
348d480f PA |
10654 | static void |
10655 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10656 | { |
348d480f | 10657 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10658 | |
348d480f | 10659 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10660 | } |
10661 | ||
10662 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10663 | hardware watchpoints. */ |
9c06b0b4 TJB |
10664 | |
10665 | static int | |
348d480f | 10666 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10667 | { |
3a5c3e22 PA |
10668 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10669 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10670 | |
10671 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10672 | } |
10673 | ||
10674 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10675 | hardware watchpoints. */ |
9c06b0b4 TJB |
10676 | |
10677 | static int | |
348d480f | 10678 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10679 | { |
efa80663 PA |
10680 | /* Read and access watchpoints only work with hardware support. */ |
10681 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10682 | } |
10683 | ||
9c06b0b4 | 10684 | static enum print_stop_action |
348d480f | 10685 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10686 | { |
348d480f PA |
10687 | struct cleanup *old_chain; |
10688 | struct breakpoint *b; | |
348d480f | 10689 | enum print_stop_action result; |
3a5c3e22 | 10690 | struct watchpoint *w; |
79a45e25 | 10691 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10692 | |
10693 | gdb_assert (bs->bp_location_at != NULL); | |
10694 | ||
348d480f | 10695 | b = bs->breakpoint_at; |
3a5c3e22 | 10696 | w = (struct watchpoint *) b; |
348d480f | 10697 | |
d7e74731 | 10698 | old_chain = make_cleanup (null_cleanup, NULL); |
9c06b0b4 | 10699 | |
f303dbd6 PA |
10700 | annotate_watchpoint (b->number); |
10701 | maybe_print_thread_hit_breakpoint (uiout); | |
10702 | ||
d7e74731 PA |
10703 | string_file stb; |
10704 | ||
9c06b0b4 TJB |
10705 | switch (b->type) |
10706 | { | |
348d480f | 10707 | case bp_watchpoint: |
9c06b0b4 | 10708 | case bp_hardware_watchpoint: |
112e8700 SM |
10709 | if (uiout->is_mi_like_p ()) |
10710 | uiout->field_string | |
10711 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10712 | mention (b); |
10713 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10714 | uiout->text ("\nOld value = "); |
d7e74731 | 10715 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10716 | uiout->field_stream ("old", stb); |
10717 | uiout->text ("\nNew value = "); | |
d7e74731 | 10718 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10719 | uiout->field_stream ("new", stb); |
10720 | uiout->text ("\n"); | |
348d480f PA |
10721 | /* More than one watchpoint may have been triggered. */ |
10722 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10723 | break; |
10724 | ||
10725 | case bp_read_watchpoint: | |
112e8700 SM |
10726 | if (uiout->is_mi_like_p ()) |
10727 | uiout->field_string | |
10728 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10729 | mention (b); |
10730 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10731 | uiout->text ("\nValue = "); |
d7e74731 | 10732 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10733 | uiout->field_stream ("value", stb); |
10734 | uiout->text ("\n"); | |
348d480f | 10735 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10736 | break; |
10737 | ||
10738 | case bp_access_watchpoint: | |
348d480f PA |
10739 | if (bs->old_val != NULL) |
10740 | { | |
112e8700 SM |
10741 | if (uiout->is_mi_like_p ()) |
10742 | uiout->field_string | |
10743 | ("reason", | |
348d480f PA |
10744 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10745 | mention (b); | |
10746 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10747 | uiout->text ("\nOld value = "); |
d7e74731 | 10748 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10749 | uiout->field_stream ("old", stb); |
10750 | uiout->text ("\nNew value = "); | |
348d480f PA |
10751 | } |
10752 | else | |
10753 | { | |
10754 | mention (b); | |
112e8700 SM |
10755 | if (uiout->is_mi_like_p ()) |
10756 | uiout->field_string | |
10757 | ("reason", | |
348d480f PA |
10758 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10759 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10760 | uiout->text ("\nValue = "); |
348d480f | 10761 | } |
d7e74731 | 10762 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10763 | uiout->field_stream ("new", stb); |
10764 | uiout->text ("\n"); | |
348d480f | 10765 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10766 | break; |
10767 | default: | |
348d480f | 10768 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10769 | } |
10770 | ||
348d480f PA |
10771 | do_cleanups (old_chain); |
10772 | return result; | |
10773 | } | |
10774 | ||
10775 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10776 | watchpoints. */ | |
10777 | ||
10778 | static void | |
10779 | print_mention_watchpoint (struct breakpoint *b) | |
10780 | { | |
10781 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10782 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10783 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10784 | |
10785 | switch (b->type) | |
10786 | { | |
10787 | case bp_watchpoint: | |
112e8700 | 10788 | uiout->text ("Watchpoint "); |
348d480f PA |
10789 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
10790 | break; | |
10791 | case bp_hardware_watchpoint: | |
112e8700 | 10792 | uiout->text ("Hardware watchpoint "); |
348d480f PA |
10793 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
10794 | break; | |
10795 | case bp_read_watchpoint: | |
112e8700 | 10796 | uiout->text ("Hardware read watchpoint "); |
348d480f PA |
10797 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
10798 | break; | |
10799 | case bp_access_watchpoint: | |
112e8700 | 10800 | uiout->text ("Hardware access (read/write) watchpoint "); |
348d480f PA |
10801 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
10802 | break; | |
10803 | default: | |
10804 | internal_error (__FILE__, __LINE__, | |
10805 | _("Invalid hardware watchpoint type.")); | |
10806 | } | |
10807 | ||
112e8700 SM |
10808 | uiout->field_int ("number", b->number); |
10809 | uiout->text (": "); | |
10810 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10811 | do_cleanups (ui_out_chain); |
10812 | } | |
10813 | ||
10814 | /* Implement the "print_recreate" breakpoint_ops method for | |
10815 | watchpoints. */ | |
10816 | ||
10817 | static void | |
10818 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10819 | { | |
3a5c3e22 PA |
10820 | struct watchpoint *w = (struct watchpoint *) b; |
10821 | ||
348d480f PA |
10822 | switch (b->type) |
10823 | { | |
10824 | case bp_watchpoint: | |
10825 | case bp_hardware_watchpoint: | |
10826 | fprintf_unfiltered (fp, "watch"); | |
10827 | break; | |
10828 | case bp_read_watchpoint: | |
10829 | fprintf_unfiltered (fp, "rwatch"); | |
10830 | break; | |
10831 | case bp_access_watchpoint: | |
10832 | fprintf_unfiltered (fp, "awatch"); | |
10833 | break; | |
10834 | default: | |
10835 | internal_error (__FILE__, __LINE__, | |
10836 | _("Invalid watchpoint type.")); | |
10837 | } | |
10838 | ||
3a5c3e22 | 10839 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10840 | print_recreate_thread (b, fp); |
348d480f PA |
10841 | } |
10842 | ||
427cd150 TT |
10843 | /* Implement the "explains_signal" breakpoint_ops method for |
10844 | watchpoints. */ | |
10845 | ||
47591c29 | 10846 | static int |
427cd150 TT |
10847 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10848 | { | |
10849 | /* A software watchpoint cannot cause a signal other than | |
10850 | GDB_SIGNAL_TRAP. */ | |
10851 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10852 | return 0; |
427cd150 | 10853 | |
47591c29 | 10854 | return 1; |
427cd150 TT |
10855 | } |
10856 | ||
348d480f PA |
10857 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10858 | ||
2060206e | 10859 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10860 | |
10861 | /* Implement the "insert" breakpoint_ops method for | |
10862 | masked hardware watchpoints. */ | |
10863 | ||
10864 | static int | |
10865 | insert_masked_watchpoint (struct bp_location *bl) | |
10866 | { | |
3a5c3e22 PA |
10867 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10868 | ||
10869 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10870 | bl->watchpoint_type); |
10871 | } | |
10872 | ||
10873 | /* Implement the "remove" breakpoint_ops method for | |
10874 | masked hardware watchpoints. */ | |
10875 | ||
10876 | static int | |
73971819 | 10877 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10878 | { |
3a5c3e22 PA |
10879 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10880 | ||
10881 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10882 | bl->watchpoint_type); |
10883 | } | |
10884 | ||
10885 | /* Implement the "resources_needed" breakpoint_ops method for | |
10886 | masked hardware watchpoints. */ | |
10887 | ||
10888 | static int | |
10889 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10890 | { | |
3a5c3e22 PA |
10891 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10892 | ||
10893 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10894 | } |
10895 | ||
10896 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10897 | masked hardware watchpoints. */ | |
10898 | ||
10899 | static int | |
10900 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10901 | { | |
10902 | return 0; | |
10903 | } | |
10904 | ||
10905 | /* Implement the "print_it" breakpoint_ops method for | |
10906 | masked hardware watchpoints. */ | |
10907 | ||
10908 | static enum print_stop_action | |
10909 | print_it_masked_watchpoint (bpstat bs) | |
10910 | { | |
10911 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10912 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10913 | |
10914 | /* Masked watchpoints have only one location. */ | |
10915 | gdb_assert (b->loc && b->loc->next == NULL); | |
10916 | ||
f303dbd6 PA |
10917 | annotate_watchpoint (b->number); |
10918 | maybe_print_thread_hit_breakpoint (uiout); | |
10919 | ||
348d480f PA |
10920 | switch (b->type) |
10921 | { | |
10922 | case bp_hardware_watchpoint: | |
112e8700 SM |
10923 | if (uiout->is_mi_like_p ()) |
10924 | uiout->field_string | |
10925 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10926 | break; |
10927 | ||
10928 | case bp_read_watchpoint: | |
112e8700 SM |
10929 | if (uiout->is_mi_like_p ()) |
10930 | uiout->field_string | |
10931 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10932 | break; |
10933 | ||
10934 | case bp_access_watchpoint: | |
112e8700 SM |
10935 | if (uiout->is_mi_like_p ()) |
10936 | uiout->field_string | |
10937 | ("reason", | |
348d480f PA |
10938 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10939 | break; | |
10940 | default: | |
10941 | internal_error (__FILE__, __LINE__, | |
10942 | _("Invalid hardware watchpoint type.")); | |
10943 | } | |
10944 | ||
10945 | mention (b); | |
112e8700 | 10946 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10947 | Check the underlying instruction at PC for the memory\n\ |
10948 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10949 | uiout->text ("\n"); |
9c06b0b4 TJB |
10950 | |
10951 | /* More than one watchpoint may have been triggered. */ | |
10952 | return PRINT_UNKNOWN; | |
10953 | } | |
10954 | ||
10955 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10956 | masked hardware watchpoints. */ | |
10957 | ||
10958 | static void | |
10959 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10960 | struct ui_out *uiout) | |
10961 | { | |
3a5c3e22 PA |
10962 | struct watchpoint *w = (struct watchpoint *) b; |
10963 | ||
9c06b0b4 TJB |
10964 | /* Masked watchpoints have only one location. */ |
10965 | gdb_assert (b->loc && b->loc->next == NULL); | |
10966 | ||
112e8700 SM |
10967 | uiout->text ("\tmask "); |
10968 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10969 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10970 | } |
10971 | ||
10972 | /* Implement the "print_mention" breakpoint_ops method for | |
10973 | masked hardware watchpoints. */ | |
10974 | ||
10975 | static void | |
10976 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10977 | { | |
3a5c3e22 | 10978 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10979 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10980 | struct cleanup *ui_out_chain; |
10981 | ||
10982 | switch (b->type) | |
10983 | { | |
10984 | case bp_hardware_watchpoint: | |
112e8700 | 10985 | uiout->text ("Masked hardware watchpoint "); |
9c06b0b4 TJB |
10986 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
10987 | break; | |
10988 | case bp_read_watchpoint: | |
112e8700 | 10989 | uiout->text ("Masked hardware read watchpoint "); |
9c06b0b4 TJB |
10990 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
10991 | break; | |
10992 | case bp_access_watchpoint: | |
112e8700 | 10993 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
9c06b0b4 TJB |
10994 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
10995 | break; | |
10996 | default: | |
10997 | internal_error (__FILE__, __LINE__, | |
10998 | _("Invalid hardware watchpoint type.")); | |
10999 | } | |
11000 | ||
112e8700 SM |
11001 | uiout->field_int ("number", b->number); |
11002 | uiout->text (": "); | |
11003 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
11004 | do_cleanups (ui_out_chain); |
11005 | } | |
11006 | ||
11007 | /* Implement the "print_recreate" breakpoint_ops method for | |
11008 | masked hardware watchpoints. */ | |
11009 | ||
11010 | static void | |
11011 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11012 | { | |
3a5c3e22 | 11013 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11014 | char tmp[40]; |
11015 | ||
11016 | switch (b->type) | |
11017 | { | |
11018 | case bp_hardware_watchpoint: | |
11019 | fprintf_unfiltered (fp, "watch"); | |
11020 | break; | |
11021 | case bp_read_watchpoint: | |
11022 | fprintf_unfiltered (fp, "rwatch"); | |
11023 | break; | |
11024 | case bp_access_watchpoint: | |
11025 | fprintf_unfiltered (fp, "awatch"); | |
11026 | break; | |
11027 | default: | |
11028 | internal_error (__FILE__, __LINE__, | |
11029 | _("Invalid hardware watchpoint type.")); | |
11030 | } | |
11031 | ||
3a5c3e22 PA |
11032 | sprintf_vma (tmp, w->hw_wp_mask); |
11033 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11034 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11035 | } |
11036 | ||
11037 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11038 | ||
2060206e | 11039 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11040 | |
11041 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11042 | ||
11043 | static int | |
11044 | is_masked_watchpoint (const struct breakpoint *b) | |
11045 | { | |
11046 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11047 | } | |
11048 | ||
53a5351d JM |
11049 | /* accessflag: hw_write: watch write, |
11050 | hw_read: watch read, | |
11051 | hw_access: watch access (read or write) */ | |
c906108c | 11052 | static void |
bbc13ae3 | 11053 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11054 | int just_location, int internal) |
c906108c | 11055 | { |
d983da9c | 11056 | struct breakpoint *b, *scope_breakpoint = NULL; |
270140bd | 11057 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11058 | struct value *val, *mark, *result; |
bb9d5f81 | 11059 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
11060 | const char *exp_start = NULL; |
11061 | const char *exp_end = NULL; | |
11062 | const char *tok, *end_tok; | |
9c06b0b4 | 11063 | int toklen = -1; |
bbc13ae3 KS |
11064 | const char *cond_start = NULL; |
11065 | const char *cond_end = NULL; | |
c906108c | 11066 | enum bptype bp_type; |
37e4754d | 11067 | int thread = -1; |
0cf6dd15 | 11068 | int pc = 0; |
9c06b0b4 TJB |
11069 | /* Flag to indicate whether we are going to use masks for |
11070 | the hardware watchpoint. */ | |
11071 | int use_mask = 0; | |
11072 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11073 | struct watchpoint *w; |
bbc13ae3 KS |
11074 | char *expression; |
11075 | struct cleanup *back_to; | |
c906108c | 11076 | |
37e4754d LM |
11077 | /* Make sure that we actually have parameters to parse. */ |
11078 | if (arg != NULL && arg[0] != '\0') | |
11079 | { | |
bbc13ae3 KS |
11080 | const char *value_start; |
11081 | ||
11082 | exp_end = arg + strlen (arg); | |
37e4754d | 11083 | |
9c06b0b4 TJB |
11084 | /* Look for "parameter value" pairs at the end |
11085 | of the arguments string. */ | |
bbc13ae3 | 11086 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11087 | { |
11088 | /* Skip whitespace at the end of the argument list. */ | |
11089 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11090 | tok--; | |
11091 | ||
11092 | /* Find the beginning of the last token. | |
11093 | This is the value of the parameter. */ | |
11094 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11095 | tok--; | |
11096 | value_start = tok + 1; | |
11097 | ||
11098 | /* Skip whitespace. */ | |
11099 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11100 | tok--; | |
11101 | ||
11102 | end_tok = tok; | |
11103 | ||
11104 | /* Find the beginning of the second to last token. | |
11105 | This is the parameter itself. */ | |
11106 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11107 | tok--; | |
11108 | tok++; | |
11109 | toklen = end_tok - tok + 1; | |
11110 | ||
61012eef | 11111 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11112 | { |
5d5658a1 | 11113 | struct thread_info *thr; |
9c06b0b4 TJB |
11114 | /* At this point we've found a "thread" token, which means |
11115 | the user is trying to set a watchpoint that triggers | |
11116 | only in a specific thread. */ | |
5d5658a1 | 11117 | const char *endp; |
37e4754d | 11118 | |
9c06b0b4 TJB |
11119 | if (thread != -1) |
11120 | error(_("You can specify only one thread.")); | |
37e4754d | 11121 | |
9c06b0b4 | 11122 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11123 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11124 | |
5d5658a1 | 11125 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11126 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11127 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11128 | |
5d5658a1 | 11129 | thread = thr->global_num; |
9c06b0b4 | 11130 | } |
61012eef | 11131 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11132 | { |
11133 | /* We've found a "mask" token, which means the user wants to | |
11134 | create a hardware watchpoint that is going to have the mask | |
11135 | facility. */ | |
11136 | struct value *mask_value, *mark; | |
37e4754d | 11137 | |
9c06b0b4 TJB |
11138 | if (use_mask) |
11139 | error(_("You can specify only one mask.")); | |
37e4754d | 11140 | |
9c06b0b4 | 11141 | use_mask = just_location = 1; |
37e4754d | 11142 | |
9c06b0b4 TJB |
11143 | mark = value_mark (); |
11144 | mask_value = parse_to_comma_and_eval (&value_start); | |
11145 | mask = value_as_address (mask_value); | |
11146 | value_free_to_mark (mark); | |
11147 | } | |
11148 | else | |
11149 | /* We didn't recognize what we found. We should stop here. */ | |
11150 | break; | |
37e4754d | 11151 | |
9c06b0b4 TJB |
11152 | /* Truncate the string and get rid of the "parameter value" pair before |
11153 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11154 | exp_end = tok; |
9c06b0b4 | 11155 | } |
37e4754d | 11156 | } |
bbc13ae3 KS |
11157 | else |
11158 | exp_end = arg; | |
37e4754d | 11159 | |
bbc13ae3 KS |
11160 | /* Parse the rest of the arguments. From here on out, everything |
11161 | is in terms of a newly allocated string instead of the original | |
11162 | ARG. */ | |
c906108c | 11163 | innermost_block = NULL; |
bbc13ae3 KS |
11164 | expression = savestring (arg, exp_end - arg); |
11165 | back_to = make_cleanup (xfree, expression); | |
11166 | exp_start = arg = expression; | |
4d01a485 | 11167 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11168 | exp_end = arg; |
fa8a61dc TT |
11169 | /* Remove trailing whitespace from the expression before saving it. |
11170 | This makes the eventual display of the expression string a bit | |
11171 | prettier. */ | |
11172 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11173 | --exp_end; | |
11174 | ||
65d79d4b | 11175 | /* Checking if the expression is not constant. */ |
4d01a485 | 11176 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
11177 | { |
11178 | int len; | |
11179 | ||
11180 | len = exp_end - exp_start; | |
11181 | while (len > 0 && isspace (exp_start[len - 1])) | |
11182 | len--; | |
11183 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11184 | } | |
11185 | ||
c906108c SS |
11186 | exp_valid_block = innermost_block; |
11187 | mark = value_mark (); | |
4d01a485 | 11188 | fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location); |
06a64a0b | 11189 | |
bb9d5f81 PP |
11190 | if (val != NULL && just_location) |
11191 | { | |
11192 | saved_bitpos = value_bitpos (val); | |
11193 | saved_bitsize = value_bitsize (val); | |
11194 | } | |
11195 | ||
06a64a0b TT |
11196 | if (just_location) |
11197 | { | |
9c06b0b4 TJB |
11198 | int ret; |
11199 | ||
06a64a0b | 11200 | exp_valid_block = NULL; |
a1442452 | 11201 | val = value_addr (result); |
06a64a0b TT |
11202 | release_value (val); |
11203 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11204 | |
11205 | if (use_mask) | |
11206 | { | |
11207 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11208 | mask); | |
11209 | if (ret == -1) | |
11210 | error (_("This target does not support masked watchpoints.")); | |
11211 | else if (ret == -2) | |
11212 | error (_("Invalid mask or memory region.")); | |
11213 | } | |
06a64a0b TT |
11214 | } |
11215 | else if (val != NULL) | |
fa4727a6 | 11216 | release_value (val); |
c906108c | 11217 | |
bbc13ae3 KS |
11218 | tok = skip_spaces_const (arg); |
11219 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11220 | |
11221 | toklen = end_tok - tok; | |
11222 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11223 | { | |
60e1c644 | 11224 | innermost_block = NULL; |
c906108c | 11225 | tok = cond_start = end_tok + 1; |
4d01a485 | 11226 | parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11227 | |
11228 | /* The watchpoint expression may not be local, but the condition | |
11229 | may still be. E.g.: `watch global if local > 0'. */ | |
11230 | cond_exp_valid_block = innermost_block; | |
11231 | ||
c906108c SS |
11232 | cond_end = tok; |
11233 | } | |
11234 | if (*tok) | |
8a3fe4f8 | 11235 | error (_("Junk at end of command.")); |
c906108c | 11236 | |
441d7c93 PA |
11237 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
11238 | ||
11239 | /* Save this because create_internal_breakpoint below invalidates | |
11240 | 'wp_frame'. */ | |
11241 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
11242 | |
11243 | /* If the expression is "local", then set up a "watchpoint scope" | |
11244 | breakpoint at the point where we've left the scope of the watchpoint | |
11245 | expression. Create the scope breakpoint before the watchpoint, so | |
11246 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 11247 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 11248 | { |
441d7c93 PA |
11249 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
11250 | ||
11251 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 11252 | { |
441d7c93 PA |
11253 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
11254 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
11255 | ||
edb3359d | 11256 | scope_breakpoint |
441d7c93 | 11257 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
11258 | bp_watchpoint_scope, |
11259 | &momentary_breakpoint_ops); | |
d983da9c | 11260 | |
441d7c93 PA |
11261 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
11262 | wp_frame = NULL; | |
11263 | ||
edb3359d | 11264 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11265 | |
edb3359d DJ |
11266 | /* Automatically delete the breakpoint when it hits. */ |
11267 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11268 | |
edb3359d | 11269 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 11270 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 11271 | |
edb3359d | 11272 | /* Set the address at which we will stop. */ |
441d7c93 PA |
11273 | scope_breakpoint->loc->gdbarch = caller_arch; |
11274 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 11275 | scope_breakpoint->loc->address |
a6d9a66e UW |
11276 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11277 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11278 | scope_breakpoint->type); |
11279 | } | |
d983da9c DJ |
11280 | } |
11281 | ||
e8369a73 AB |
11282 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11283 | watchpoints here even if hardware watchpoints are turned off, a call | |
11284 | to update_watchpoint later in this function will cause the type to | |
11285 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11286 | ||
11287 | if (accessflag == hw_read) | |
11288 | bp_type = bp_read_watchpoint; | |
11289 | else if (accessflag == hw_access) | |
11290 | bp_type = bp_access_watchpoint; | |
11291 | else | |
11292 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 11293 | |
4d01a485 | 11294 | w = new watchpoint (); |
3a5c3e22 | 11295 | b = &w->base; |
348d480f | 11296 | if (use_mask) |
3a5c3e22 PA |
11297 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11298 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11299 | else |
3a5c3e22 PA |
11300 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11301 | &watchpoint_breakpoint_ops); | |
37e4754d | 11302 | b->thread = thread; |
b5de0fa7 | 11303 | b->disposition = disp_donttouch; |
348d480f | 11304 | b->pspace = current_program_space; |
b22e99fd | 11305 | w->exp = std::move (exp); |
3a5c3e22 PA |
11306 | w->exp_valid_block = exp_valid_block; |
11307 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11308 | if (just_location) |
11309 | { | |
11310 | struct type *t = value_type (val); | |
11311 | CORE_ADDR addr = value_as_address (val); | |
06a64a0b TT |
11312 | |
11313 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
06a64a0b | 11314 | |
2f408ecb PA |
11315 | std::string name = type_to_string (t); |
11316 | ||
11317 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name.c_str (), | |
d63d0675 | 11318 | core_addr_to_string (addr)); |
06a64a0b | 11319 | |
3a5c3e22 | 11320 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11321 | (int) (exp_end - exp_start), exp_start); |
11322 | ||
06a64a0b TT |
11323 | /* The above expression is in C. */ |
11324 | b->language = language_c; | |
11325 | } | |
11326 | else | |
3a5c3e22 | 11327 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11328 | |
11329 | if (use_mask) | |
11330 | { | |
3a5c3e22 | 11331 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11332 | } |
11333 | else | |
11334 | { | |
3a5c3e22 | 11335 | w->val = val; |
bb9d5f81 PP |
11336 | w->val_bitpos = saved_bitpos; |
11337 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11338 | w->val_valid = 1; |
9c06b0b4 | 11339 | } |
77b06cd7 | 11340 | |
c906108c SS |
11341 | if (cond_start) |
11342 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11343 | else | |
11344 | b->cond_string = 0; | |
c5aa993b | 11345 | |
441d7c93 | 11346 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 11347 | { |
441d7c93 | 11348 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 11349 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 11350 | } |
c906108c | 11351 | else |
f6bc2008 | 11352 | { |
3a5c3e22 PA |
11353 | w->watchpoint_frame = null_frame_id; |
11354 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11355 | } |
c906108c | 11356 | |
d983da9c | 11357 | if (scope_breakpoint != NULL) |
c906108c | 11358 | { |
d983da9c DJ |
11359 | /* The scope breakpoint is related to the watchpoint. We will |
11360 | need to act on them together. */ | |
11361 | b->related_breakpoint = scope_breakpoint; | |
11362 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11363 | } |
d983da9c | 11364 | |
06a64a0b TT |
11365 | if (!just_location) |
11366 | value_free_to_mark (mark); | |
2d134ed3 | 11367 | |
492d29ea | 11368 | TRY |
a9634178 TJB |
11369 | { |
11370 | /* Finally update the new watchpoint. This creates the locations | |
11371 | that should be inserted. */ | |
3a5c3e22 | 11372 | update_watchpoint (w, 1); |
a9634178 | 11373 | } |
492d29ea | 11374 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11375 | { |
11376 | delete_breakpoint (b); | |
11377 | throw_exception (e); | |
11378 | } | |
492d29ea | 11379 | END_CATCH |
a9634178 | 11380 | |
3ea46bff | 11381 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11382 | do_cleanups (back_to); |
c906108c SS |
11383 | } |
11384 | ||
e09342b5 | 11385 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11386 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11387 | |
c906108c | 11388 | static int |
a9634178 | 11389 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11390 | { |
11391 | int found_memory_cnt = 0; | |
2e70b7b9 | 11392 | struct value *head = v; |
c906108c SS |
11393 | |
11394 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11395 | if (!can_use_hw_watchpoints) |
c906108c | 11396 | return 0; |
c5aa993b | 11397 | |
5c44784c JM |
11398 | /* Make sure that the value of the expression depends only upon |
11399 | memory contents, and values computed from them within GDB. If we | |
11400 | find any register references or function calls, we can't use a | |
11401 | hardware watchpoint. | |
11402 | ||
11403 | The idea here is that evaluating an expression generates a series | |
11404 | of values, one holding the value of every subexpression. (The | |
11405 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11406 | a*b+c.) GDB's values hold almost enough information to establish | |
11407 | the criteria given above --- they identify memory lvalues, | |
11408 | register lvalues, computed values, etcetera. So we can evaluate | |
11409 | the expression, and then scan the chain of values that leaves | |
11410 | behind to decide whether we can detect any possible change to the | |
11411 | expression's final value using only hardware watchpoints. | |
11412 | ||
11413 | However, I don't think that the values returned by inferior | |
11414 | function calls are special in any way. So this function may not | |
11415 | notice that an expression involving an inferior function call | |
11416 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11417 | for (; v; v = value_next (v)) |
c906108c | 11418 | { |
5c44784c | 11419 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11420 | { |
8464be76 DJ |
11421 | if (v != head && value_lazy (v)) |
11422 | /* A lazy memory lvalue in the chain is one that GDB never | |
11423 | needed to fetch; we either just used its address (e.g., | |
11424 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11425 | in `a,b'). This doesn't apply to HEAD; if that is | |
11426 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11427 | ; |
53a5351d | 11428 | else |
5c44784c JM |
11429 | { |
11430 | /* Ahh, memory we actually used! Check if we can cover | |
11431 | it with hardware watchpoints. */ | |
df407dfe | 11432 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11433 | |
11434 | /* We only watch structs and arrays if user asked for it | |
11435 | explicitly, never if they just happen to appear in a | |
11436 | middle of some value chain. */ | |
11437 | if (v == head | |
11438 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11439 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11440 | { | |
42ae5230 | 11441 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11442 | int len; |
11443 | int num_regs; | |
11444 | ||
a9634178 | 11445 | len = (target_exact_watchpoints |
e09342b5 TJB |
11446 | && is_scalar_type_recursive (vtype))? |
11447 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11448 | |
e09342b5 TJB |
11449 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11450 | if (!num_regs) | |
2e70b7b9 MS |
11451 | return 0; |
11452 | else | |
e09342b5 | 11453 | found_memory_cnt += num_regs; |
2e70b7b9 | 11454 | } |
5c44784c | 11455 | } |
c5aa993b | 11456 | } |
5086187c AC |
11457 | else if (VALUE_LVAL (v) != not_lval |
11458 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11459 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11460 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11461 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11462 | } |
11463 | ||
11464 | /* The expression itself looks suitable for using a hardware | |
11465 | watchpoint, but give the target machine a chance to reject it. */ | |
11466 | return found_memory_cnt; | |
11467 | } | |
11468 | ||
8b93c638 | 11469 | void |
84f4c1fe | 11470 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11471 | { |
84f4c1fe | 11472 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11473 | } |
11474 | ||
06a64a0b TT |
11475 | /* A helper function that looks for the "-location" argument and then |
11476 | calls watch_command_1. */ | |
11477 | ||
11478 | static void | |
11479 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11480 | { | |
11481 | int just_location = 0; | |
11482 | ||
11483 | if (arg | |
11484 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11485 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11486 | { | |
e9cafbcc | 11487 | arg = skip_spaces (arg); |
06a64a0b TT |
11488 | just_location = 1; |
11489 | } | |
11490 | ||
84f4c1fe | 11491 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11492 | } |
8926118c | 11493 | |
c5aa993b | 11494 | static void |
fba45db2 | 11495 | watch_command (char *arg, int from_tty) |
c906108c | 11496 | { |
06a64a0b | 11497 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11498 | } |
11499 | ||
8b93c638 | 11500 | void |
84f4c1fe | 11501 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11502 | { |
84f4c1fe | 11503 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11504 | } |
8926118c | 11505 | |
c5aa993b | 11506 | static void |
fba45db2 | 11507 | rwatch_command (char *arg, int from_tty) |
c906108c | 11508 | { |
06a64a0b | 11509 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11510 | } |
11511 | ||
8b93c638 | 11512 | void |
84f4c1fe | 11513 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11514 | { |
84f4c1fe | 11515 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11516 | } |
8926118c | 11517 | |
c5aa993b | 11518 | static void |
fba45db2 | 11519 | awatch_command (char *arg, int from_tty) |
c906108c | 11520 | { |
06a64a0b | 11521 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11522 | } |
c906108c | 11523 | \f |
c5aa993b | 11524 | |
cfc31633 PA |
11525 | /* Data for the FSM that manages the until(location)/advance commands |
11526 | in infcmd.c. Here because it uses the mechanisms of | |
11527 | breakpoints. */ | |
c906108c | 11528 | |
cfc31633 | 11529 | struct until_break_fsm |
bfec99b2 | 11530 | { |
cfc31633 PA |
11531 | /* The base class. */ |
11532 | struct thread_fsm thread_fsm; | |
11533 | ||
11534 | /* The thread that as current when the command was executed. */ | |
11535 | int thread; | |
11536 | ||
11537 | /* The breakpoint set at the destination location. */ | |
11538 | struct breakpoint *location_breakpoint; | |
11539 | ||
11540 | /* Breakpoint set at the return address in the caller frame. May be | |
11541 | NULL. */ | |
11542 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11543 | }; |
11544 | ||
8980e177 PA |
11545 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11546 | struct thread_info *thread); | |
11547 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11548 | struct thread_info *thread); | |
cfc31633 PA |
11549 | static enum async_reply_reason |
11550 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11551 | ||
11552 | /* until_break_fsm's vtable. */ | |
11553 | ||
11554 | static struct thread_fsm_ops until_break_fsm_ops = | |
11555 | { | |
11556 | NULL, /* dtor */ | |
11557 | until_break_fsm_clean_up, | |
11558 | until_break_fsm_should_stop, | |
11559 | NULL, /* return_value */ | |
11560 | until_break_fsm_async_reply_reason, | |
11561 | }; | |
11562 | ||
11563 | /* Allocate a new until_break_command_fsm. */ | |
11564 | ||
11565 | static struct until_break_fsm * | |
8980e177 | 11566 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11567 | struct breakpoint *location_breakpoint, |
11568 | struct breakpoint *caller_breakpoint) | |
11569 | { | |
11570 | struct until_break_fsm *sm; | |
11571 | ||
11572 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11573 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11574 | |
11575 | sm->thread = thread; | |
11576 | sm->location_breakpoint = location_breakpoint; | |
11577 | sm->caller_breakpoint = caller_breakpoint; | |
11578 | ||
11579 | return sm; | |
11580 | } | |
11581 | ||
11582 | /* Implementation of the 'should_stop' FSM method for the | |
11583 | until(location)/advance commands. */ | |
11584 | ||
11585 | static int | |
8980e177 PA |
11586 | until_break_fsm_should_stop (struct thread_fsm *self, |
11587 | struct thread_info *tp) | |
cfc31633 PA |
11588 | { |
11589 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11590 | |
11591 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11592 | sm->location_breakpoint) != NULL | |
11593 | || (sm->caller_breakpoint != NULL | |
11594 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11595 | sm->caller_breakpoint) != NULL)) | |
11596 | thread_fsm_set_finished (self); | |
11597 | ||
11598 | return 1; | |
11599 | } | |
11600 | ||
11601 | /* Implementation of the 'clean_up' FSM method for the | |
11602 | until(location)/advance commands. */ | |
11603 | ||
c2c6d25f | 11604 | static void |
8980e177 PA |
11605 | until_break_fsm_clean_up (struct thread_fsm *self, |
11606 | struct thread_info *thread) | |
43ff13b4 | 11607 | { |
cfc31633 | 11608 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11609 | |
cfc31633 PA |
11610 | /* Clean up our temporary breakpoints. */ |
11611 | if (sm->location_breakpoint != NULL) | |
11612 | { | |
11613 | delete_breakpoint (sm->location_breakpoint); | |
11614 | sm->location_breakpoint = NULL; | |
11615 | } | |
11616 | if (sm->caller_breakpoint != NULL) | |
11617 | { | |
11618 | delete_breakpoint (sm->caller_breakpoint); | |
11619 | sm->caller_breakpoint = NULL; | |
11620 | } | |
11621 | delete_longjmp_breakpoint (sm->thread); | |
11622 | } | |
11623 | ||
11624 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11625 | until(location)/advance commands. */ | |
11626 | ||
11627 | static enum async_reply_reason | |
11628 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11629 | { | |
11630 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11631 | } |
11632 | ||
c906108c | 11633 | void |
ae66c1fc | 11634 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11635 | { |
11636 | struct symtabs_and_lines sals; | |
11637 | struct symtab_and_line sal; | |
8556afb4 PA |
11638 | struct frame_info *frame; |
11639 | struct gdbarch *frame_gdbarch; | |
11640 | struct frame_id stack_frame_id; | |
11641 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11642 | struct breakpoint *location_breakpoint; |
11643 | struct breakpoint *caller_breakpoint = NULL; | |
ffc2605c | 11644 | struct cleanup *old_chain; |
186c406b TT |
11645 | int thread; |
11646 | struct thread_info *tp; | |
cfc31633 | 11647 | struct until_break_fsm *sm; |
c906108c | 11648 | |
70509625 | 11649 | clear_proceed_status (0); |
c906108c SS |
11650 | |
11651 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11652 | this function. */ |
c5aa993b | 11653 | |
ffc2605c | 11654 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11655 | |
1bfeeb0f | 11656 | if (last_displayed_sal_is_valid ()) |
ffc2605c | 11657 | sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11658 | get_last_displayed_symtab (), |
f8eba3c6 | 11659 | get_last_displayed_line ()); |
c906108c | 11660 | else |
ffc2605c | 11661 | sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11662 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11663 | |
c906108c | 11664 | if (sals.nelts != 1) |
8a3fe4f8 | 11665 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11666 | |
c906108c | 11667 | sal = sals.sals[0]; |
4a64f543 | 11668 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11669 | |
c906108c | 11670 | if (*arg) |
8a3fe4f8 | 11671 | error (_("Junk at end of arguments.")); |
c5aa993b | 11672 | |
c906108c | 11673 | resolve_sal_pc (&sal); |
c5aa993b | 11674 | |
186c406b | 11675 | tp = inferior_thread (); |
5d5658a1 | 11676 | thread = tp->global_num; |
186c406b | 11677 | |
883bc8d1 PA |
11678 | old_chain = make_cleanup (null_cleanup, NULL); |
11679 | ||
8556afb4 PA |
11680 | /* Note linespec handling above invalidates the frame chain. |
11681 | Installing a breakpoint also invalidates the frame chain (as it | |
11682 | may need to switch threads), so do any frame handling before | |
11683 | that. */ | |
11684 | ||
11685 | frame = get_selected_frame (NULL); | |
11686 | frame_gdbarch = get_frame_arch (frame); | |
11687 | stack_frame_id = get_stack_frame_id (frame); | |
11688 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11689 | |
ae66c1fc EZ |
11690 | /* Keep within the current frame, or in frames called by the current |
11691 | one. */ | |
edb3359d | 11692 | |
883bc8d1 | 11693 | if (frame_id_p (caller_frame_id)) |
c906108c | 11694 | { |
883bc8d1 | 11695 | struct symtab_and_line sal2; |
cfc31633 | 11696 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11697 | |
11698 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11699 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11700 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11701 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11702 | sal2, | |
11703 | caller_frame_id, | |
11704 | bp_until); | |
11705 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11706 | |
883bc8d1 | 11707 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11708 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11709 | } |
c5aa993b | 11710 | |
c70a6932 JK |
11711 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11712 | frame = NULL; | |
11713 | ||
883bc8d1 PA |
11714 | if (anywhere) |
11715 | /* If the user told us to continue until a specified location, | |
11716 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11717 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11718 | null_frame_id, bp_until); | |
883bc8d1 PA |
11719 | else |
11720 | /* Otherwise, specify the selected frame, because we want to stop | |
11721 | only at the very same frame. */ | |
cfc31633 PA |
11722 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11723 | stack_frame_id, bp_until); | |
11724 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11725 | |
8980e177 | 11726 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11727 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11728 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11729 | |
cfc31633 | 11730 | discard_cleanups (old_chain); |
f107f563 | 11731 | |
cfc31633 | 11732 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11733 | } |
ae66c1fc | 11734 | |
c906108c SS |
11735 | /* This function attempts to parse an optional "if <cond>" clause |
11736 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11737 | |
c906108c SS |
11738 | Else, it returns a pointer to the condition string. (It does not |
11739 | attempt to evaluate the string against a particular block.) And, | |
11740 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11741 | if clause in the arg string. */ |
53a5351d | 11742 | |
63160a43 PA |
11743 | const char * |
11744 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11745 | { |
63160a43 | 11746 | const char *cond_string; |
c5aa993b JM |
11747 | |
11748 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11749 | return NULL; |
c5aa993b | 11750 | |
4a64f543 | 11751 | /* Skip the "if" keyword. */ |
c906108c | 11752 | (*arg) += 2; |
c5aa993b | 11753 | |
c906108c | 11754 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11755 | condition string. */ |
63160a43 | 11756 | *arg = skip_spaces_const (*arg); |
c906108c | 11757 | cond_string = *arg; |
c5aa993b | 11758 | |
4a64f543 MS |
11759 | /* Assume that the condition occupies the remainder of the arg |
11760 | string. */ | |
c906108c | 11761 | (*arg) += strlen (cond_string); |
c5aa993b | 11762 | |
c906108c SS |
11763 | return cond_string; |
11764 | } | |
c5aa993b | 11765 | |
c906108c SS |
11766 | /* Commands to deal with catching events, such as signals, exceptions, |
11767 | process start/exit, etc. */ | |
c5aa993b JM |
11768 | |
11769 | typedef enum | |
11770 | { | |
44feb3ce TT |
11771 | catch_fork_temporary, catch_vfork_temporary, |
11772 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11773 | } |
11774 | catch_fork_kind; | |
11775 | ||
c906108c | 11776 | static void |
63160a43 | 11777 | catch_fork_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11778 | struct cmd_list_element *command) |
c906108c | 11779 | { |
63160a43 | 11780 | const char *arg = arg_entry; |
a6d9a66e | 11781 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11782 | const char *cond_string = NULL; |
44feb3ce TT |
11783 | catch_fork_kind fork_kind; |
11784 | int tempflag; | |
11785 | ||
11786 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11787 | tempflag = (fork_kind == catch_fork_temporary | |
11788 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11789 | |
44feb3ce TT |
11790 | if (!arg) |
11791 | arg = ""; | |
63160a43 | 11792 | arg = skip_spaces_const (arg); |
c5aa993b | 11793 | |
c906108c | 11794 | /* The allowed syntax is: |
c5aa993b JM |
11795 | catch [v]fork |
11796 | catch [v]fork if <cond> | |
11797 | ||
4a64f543 | 11798 | First, check if there's an if clause. */ |
c906108c | 11799 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11800 | |
c906108c | 11801 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11802 | error (_("Junk at end of arguments.")); |
c5aa993b | 11803 | |
c906108c | 11804 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11805 | and enable reporting of such events. */ |
c5aa993b JM |
11806 | switch (fork_kind) |
11807 | { | |
44feb3ce TT |
11808 | case catch_fork_temporary: |
11809 | case catch_fork_permanent: | |
a6d9a66e | 11810 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11811 | &catch_fork_breakpoint_ops); |
c906108c | 11812 | break; |
44feb3ce TT |
11813 | case catch_vfork_temporary: |
11814 | case catch_vfork_permanent: | |
a6d9a66e | 11815 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11816 | &catch_vfork_breakpoint_ops); |
c906108c | 11817 | break; |
c5aa993b | 11818 | default: |
8a3fe4f8 | 11819 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11820 | break; |
c5aa993b | 11821 | } |
c906108c SS |
11822 | } |
11823 | ||
11824 | static void | |
63160a43 | 11825 | catch_exec_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11826 | struct cmd_list_element *command) |
c906108c | 11827 | { |
63160a43 | 11828 | const char *arg = arg_entry; |
b4d90040 | 11829 | struct exec_catchpoint *c; |
a6d9a66e | 11830 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11831 | int tempflag; |
63160a43 | 11832 | const char *cond_string = NULL; |
c906108c | 11833 | |
44feb3ce TT |
11834 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11835 | ||
11836 | if (!arg) | |
11837 | arg = ""; | |
63160a43 | 11838 | arg = skip_spaces_const (arg); |
c906108c SS |
11839 | |
11840 | /* The allowed syntax is: | |
c5aa993b JM |
11841 | catch exec |
11842 | catch exec if <cond> | |
c906108c | 11843 | |
4a64f543 | 11844 | First, check if there's an if clause. */ |
c906108c SS |
11845 | cond_string = ep_parse_optional_if_clause (&arg); |
11846 | ||
11847 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11848 | error (_("Junk at end of arguments.")); |
c906108c | 11849 | |
4d01a485 | 11850 | c = new exec_catchpoint (); |
b4d90040 PA |
11851 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, |
11852 | &catch_exec_breakpoint_ops); | |
11853 | c->exec_pathname = NULL; | |
11854 | ||
3ea46bff | 11855 | install_breakpoint (0, &c->base, 1); |
c906108c | 11856 | } |
c5aa993b | 11857 | |
9ac4176b | 11858 | void |
28010a5d PA |
11859 | init_ada_exception_breakpoint (struct breakpoint *b, |
11860 | struct gdbarch *gdbarch, | |
11861 | struct symtab_and_line sal, | |
11862 | char *addr_string, | |
c0a91b2b | 11863 | const struct breakpoint_ops *ops, |
28010a5d | 11864 | int tempflag, |
349774ef | 11865 | int enabled, |
28010a5d | 11866 | int from_tty) |
f7f9143b | 11867 | { |
f7f9143b JB |
11868 | if (from_tty) |
11869 | { | |
5af949e3 UW |
11870 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11871 | if (!loc_gdbarch) | |
11872 | loc_gdbarch = gdbarch; | |
11873 | ||
6c95b8df PA |
11874 | describe_other_breakpoints (loc_gdbarch, |
11875 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11876 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11877 | version for exception catchpoints, because two catchpoints | |
11878 | used for different exception names will use the same address. | |
11879 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11880 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11881 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11882 | the user what type of catchpoint it is. The above is good |
11883 | enough for now, though. */ | |
11884 | } | |
11885 | ||
28010a5d | 11886 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11887 | |
349774ef | 11888 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11889 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11890 | b->location = string_to_event_location (&addr_string, |
11891 | language_def (language_ada)); | |
f7f9143b | 11892 | b->language = language_ada; |
f7f9143b JB |
11893 | } |
11894 | ||
c906108c | 11895 | static void |
fba45db2 | 11896 | catch_command (char *arg, int from_tty) |
c906108c | 11897 | { |
44feb3ce | 11898 | error (_("Catch requires an event name.")); |
c906108c SS |
11899 | } |
11900 | \f | |
11901 | ||
11902 | static void | |
fba45db2 | 11903 | tcatch_command (char *arg, int from_tty) |
c906108c | 11904 | { |
44feb3ce | 11905 | error (_("Catch requires an event name.")); |
c906108c SS |
11906 | } |
11907 | ||
8a2c437b TT |
11908 | /* A qsort comparison function that sorts breakpoints in order. */ |
11909 | ||
11910 | static int | |
11911 | compare_breakpoints (const void *a, const void *b) | |
11912 | { | |
9a3c8263 | 11913 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11914 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11915 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11916 | uintptr_t ub = (uintptr_t) *bb; |
11917 | ||
11918 | if ((*ba)->number < (*bb)->number) | |
11919 | return -1; | |
11920 | else if ((*ba)->number > (*bb)->number) | |
11921 | return 1; | |
11922 | ||
11923 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11924 | the number 0. */ | |
11925 | if (ua < ub) | |
11926 | return -1; | |
94b0e70d | 11927 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11928 | } |
11929 | ||
80f8a6eb | 11930 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11931 | |
11932 | static void | |
fba45db2 | 11933 | clear_command (char *arg, int from_tty) |
c906108c | 11934 | { |
8a2c437b | 11935 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11936 | VEC(breakpoint_p) *found = 0; |
11937 | int ix; | |
c906108c SS |
11938 | int default_match; |
11939 | struct symtabs_and_lines sals; | |
11940 | struct symtab_and_line sal; | |
c906108c | 11941 | int i; |
8a2c437b | 11942 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11943 | |
11944 | if (arg) | |
11945 | { | |
39cf75f7 DE |
11946 | sals = decode_line_with_current_source (arg, |
11947 | (DECODE_LINE_FUNFIRSTLINE | |
11948 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11949 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11950 | default_match = 0; |
11951 | } | |
11952 | else | |
11953 | { | |
8d749320 | 11954 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 11955 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11956 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11957 | |
11958 | /* Set sal's line, symtab, pc, and pspace to the values | |
11959 | corresponding to the last call to print_frame_info. If the | |
11960 | codepoint is not valid, this will set all the fields to 0. */ | |
11961 | get_last_displayed_sal (&sal); | |
c906108c | 11962 | if (sal.symtab == 0) |
8a3fe4f8 | 11963 | error (_("No source file specified.")); |
c906108c SS |
11964 | |
11965 | sals.sals[0] = sal; | |
11966 | sals.nelts = 1; | |
11967 | ||
11968 | default_match = 1; | |
11969 | } | |
11970 | ||
4a64f543 MS |
11971 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11972 | seems, because all existing breakpoints typically have both | |
11973 | file/line and pc set. So, if clear is given file/line, we can | |
11974 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11975 | |
11976 | We only support clearing given the address explicitly | |
11977 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11978 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11979 | due to optimization, all in one block. |
4a64f543 MS |
11980 | |
11981 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11982 | PC corresponding to the same file:line, the breakpoint won't |
11983 | be cleared. We probably can still clear the breakpoint, but | |
11984 | since the other PC value is never presented to user, user | |
11985 | can only find it by guessing, and it does not seem important | |
11986 | to support that. */ | |
11987 | ||
4a64f543 MS |
11988 | /* For each line spec given, delete bps which correspond to it. Do |
11989 | it in two passes, solely to preserve the current behavior that | |
11990 | from_tty is forced true if we delete more than one | |
11991 | breakpoint. */ | |
c906108c | 11992 | |
80f8a6eb | 11993 | found = NULL; |
8a2c437b | 11994 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11995 | for (i = 0; i < sals.nelts; i++) |
11996 | { | |
05cba821 JK |
11997 | const char *sal_fullname; |
11998 | ||
c906108c | 11999 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12000 | If line given (pc == 0), clear all bpts on specified line. |
12001 | If defaulting, clear all bpts on default line | |
c906108c | 12002 | or at default pc. |
c5aa993b JM |
12003 | |
12004 | defaulting sal.pc != 0 tests to do | |
12005 | ||
12006 | 0 1 pc | |
12007 | 1 1 pc _and_ line | |
12008 | 0 0 line | |
12009 | 1 0 <can't happen> */ | |
c906108c SS |
12010 | |
12011 | sal = sals.sals[i]; | |
05cba821 JK |
12012 | sal_fullname = (sal.symtab == NULL |
12013 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12014 | |
4a64f543 | 12015 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12016 | ALL_BREAKPOINTS (b) |
c5aa993b | 12017 | { |
0d381245 | 12018 | int match = 0; |
4a64f543 | 12019 | /* Are we going to delete b? */ |
cc60f2e3 | 12020 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12021 | { |
12022 | struct bp_location *loc = b->loc; | |
12023 | for (; loc; loc = loc->next) | |
12024 | { | |
f8eba3c6 TT |
12025 | /* If the user specified file:line, don't allow a PC |
12026 | match. This matches historical gdb behavior. */ | |
12027 | int pc_match = (!sal.explicit_line | |
12028 | && sal.pc | |
12029 | && (loc->pspace == sal.pspace) | |
12030 | && (loc->address == sal.pc) | |
12031 | && (!section_is_overlay (loc->section) | |
12032 | || loc->section == sal.section)); | |
4aac40c8 TT |
12033 | int line_match = 0; |
12034 | ||
12035 | if ((default_match || sal.explicit_line) | |
2f202fde | 12036 | && loc->symtab != NULL |
05cba821 | 12037 | && sal_fullname != NULL |
4aac40c8 | 12038 | && sal.pspace == loc->pspace |
05cba821 JK |
12039 | && loc->line_number == sal.line |
12040 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12041 | sal_fullname) == 0) | |
12042 | line_match = 1; | |
4aac40c8 | 12043 | |
0d381245 VP |
12044 | if (pc_match || line_match) |
12045 | { | |
12046 | match = 1; | |
12047 | break; | |
12048 | } | |
12049 | } | |
12050 | } | |
12051 | ||
12052 | if (match) | |
d6e956e5 | 12053 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12054 | } |
80f8a6eb | 12055 | } |
8a2c437b | 12056 | |
80f8a6eb | 12057 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12058 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12059 | { |
12060 | if (arg) | |
8a3fe4f8 | 12061 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12062 | else |
8a3fe4f8 | 12063 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12064 | } |
c906108c | 12065 | |
8a2c437b TT |
12066 | /* Remove duplicates from the vec. */ |
12067 | qsort (VEC_address (breakpoint_p, found), | |
12068 | VEC_length (breakpoint_p, found), | |
12069 | sizeof (breakpoint_p), | |
12070 | compare_breakpoints); | |
12071 | prev = VEC_index (breakpoint_p, found, 0); | |
12072 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12073 | { | |
12074 | if (b == prev) | |
12075 | { | |
12076 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12077 | --ix; | |
12078 | } | |
12079 | } | |
12080 | ||
d6e956e5 | 12081 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12082 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12083 | if (from_tty) |
a3f17187 | 12084 | { |
d6e956e5 | 12085 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12086 | printf_unfiltered (_("Deleted breakpoint ")); |
12087 | else | |
12088 | printf_unfiltered (_("Deleted breakpoints ")); | |
12089 | } | |
d6e956e5 VP |
12090 | |
12091 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12092 | { |
c5aa993b | 12093 | if (from_tty) |
d6e956e5 VP |
12094 | printf_unfiltered ("%d ", b->number); |
12095 | delete_breakpoint (b); | |
c906108c | 12096 | } |
80f8a6eb MS |
12097 | if (from_tty) |
12098 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12099 | |
12100 | do_cleanups (cleanups); | |
c906108c SS |
12101 | } |
12102 | \f | |
12103 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12104 | all breakpoints that are marked for deletion, whether hit or not. | |
12105 | This is called after any breakpoint is hit, or after errors. */ | |
12106 | ||
12107 | void | |
fba45db2 | 12108 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12109 | { |
35df4500 | 12110 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12111 | |
12112 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12113 | if (bs->breakpoint_at |
12114 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12115 | && bs->stop) |
f431efe5 | 12116 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12117 | |
35df4500 | 12118 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12119 | { |
b5de0fa7 | 12120 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12121 | delete_breakpoint (b); |
12122 | } | |
c906108c SS |
12123 | } |
12124 | ||
4a64f543 MS |
12125 | /* A comparison function for bp_location AP and BP being interfaced to |
12126 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12127 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12128 | secondarily by ordering first permanent elements and |
4a64f543 | 12129 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12130 | qsort being an unstable algorithm. */ |
876fa593 JK |
12131 | |
12132 | static int | |
f5336ca5 | 12133 | bp_locations_compare (const void *ap, const void *bp) |
876fa593 | 12134 | { |
9a3c8263 SM |
12135 | const struct bp_location *a = *(const struct bp_location **) ap; |
12136 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12137 | |
12138 | if (a->address != b->address) | |
12139 | return (a->address > b->address) - (a->address < b->address); | |
12140 | ||
dea2aa5f LM |
12141 | /* Sort locations at the same address by their pspace number, keeping |
12142 | locations of the same inferior (in a multi-inferior environment) | |
12143 | grouped. */ | |
12144 | ||
12145 | if (a->pspace->num != b->pspace->num) | |
12146 | return ((a->pspace->num > b->pspace->num) | |
12147 | - (a->pspace->num < b->pspace->num)); | |
12148 | ||
876fa593 | 12149 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12150 | if (a->permanent != b->permanent) |
12151 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12152 | |
c56a97f9 JK |
12153 | /* Make the internal GDB representation stable across GDB runs |
12154 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12155 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12156 | |
12157 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12158 | return ((a->owner->number > b->owner->number) |
12159 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12160 | |
12161 | return (a > b) - (a < b); | |
12162 | } | |
12163 | ||
f5336ca5 PA |
12164 | /* Set bp_locations_placed_address_before_address_max and |
12165 | bp_locations_shadow_len_after_address_max according to the current | |
12166 | content of the bp_locations array. */ | |
f7545552 TT |
12167 | |
12168 | static void | |
f5336ca5 | 12169 | bp_locations_target_extensions_update (void) |
f7545552 | 12170 | { |
876fa593 JK |
12171 | struct bp_location *bl, **blp_tmp; |
12172 | ||
f5336ca5 PA |
12173 | bp_locations_placed_address_before_address_max = 0; |
12174 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
12175 | |
12176 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12177 | { | |
12178 | CORE_ADDR start, end, addr; | |
12179 | ||
12180 | if (!bp_location_has_shadow (bl)) | |
12181 | continue; | |
12182 | ||
12183 | start = bl->target_info.placed_address; | |
12184 | end = start + bl->target_info.shadow_len; | |
12185 | ||
12186 | gdb_assert (bl->address >= start); | |
12187 | addr = bl->address - start; | |
f5336ca5 PA |
12188 | if (addr > bp_locations_placed_address_before_address_max) |
12189 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
12190 | |
12191 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12192 | ||
12193 | gdb_assert (bl->address < end); | |
12194 | addr = end - bl->address; | |
f5336ca5 PA |
12195 | if (addr > bp_locations_shadow_len_after_address_max) |
12196 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 12197 | } |
f7545552 TT |
12198 | } |
12199 | ||
1e4d1764 YQ |
12200 | /* Download tracepoint locations if they haven't been. */ |
12201 | ||
12202 | static void | |
12203 | download_tracepoint_locations (void) | |
12204 | { | |
7ed2c994 | 12205 | struct breakpoint *b; |
1e4d1764 | 12206 | struct cleanup *old_chain; |
dd2e65cc | 12207 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12208 | |
12209 | old_chain = save_current_space_and_thread (); | |
12210 | ||
7ed2c994 | 12211 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12212 | { |
7ed2c994 | 12213 | struct bp_location *bl; |
1e4d1764 | 12214 | struct tracepoint *t; |
f2a8bc8a | 12215 | int bp_location_downloaded = 0; |
1e4d1764 | 12216 | |
7ed2c994 | 12217 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12218 | ? !may_insert_fast_tracepoints |
12219 | : !may_insert_tracepoints)) | |
12220 | continue; | |
12221 | ||
dd2e65cc YQ |
12222 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12223 | { | |
12224 | if (target_can_download_tracepoint ()) | |
12225 | can_download_tracepoint = TRIBOOL_TRUE; | |
12226 | else | |
12227 | can_download_tracepoint = TRIBOOL_FALSE; | |
12228 | } | |
12229 | ||
12230 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12231 | break; | |
12232 | ||
7ed2c994 YQ |
12233 | for (bl = b->loc; bl; bl = bl->next) |
12234 | { | |
12235 | /* In tracepoint, locations are _never_ duplicated, so | |
12236 | should_be_inserted is equivalent to | |
12237 | unduplicated_should_be_inserted. */ | |
12238 | if (!should_be_inserted (bl) || bl->inserted) | |
12239 | continue; | |
1e4d1764 | 12240 | |
7ed2c994 | 12241 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12242 | |
7ed2c994 | 12243 | target_download_tracepoint (bl); |
1e4d1764 | 12244 | |
7ed2c994 | 12245 | bl->inserted = 1; |
f2a8bc8a | 12246 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12247 | } |
12248 | t = (struct tracepoint *) b; | |
12249 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12250 | if (bp_location_downloaded) |
12251 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12252 | } |
12253 | ||
12254 | do_cleanups (old_chain); | |
12255 | } | |
12256 | ||
934709f0 PW |
12257 | /* Swap the insertion/duplication state between two locations. */ |
12258 | ||
12259 | static void | |
12260 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12261 | { | |
12262 | const int left_inserted = left->inserted; | |
12263 | const int left_duplicate = left->duplicate; | |
b775012e | 12264 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12265 | const struct bp_target_info left_target_info = left->target_info; |
12266 | ||
1e4d1764 YQ |
12267 | /* Locations of tracepoints can never be duplicated. */ |
12268 | if (is_tracepoint (left->owner)) | |
12269 | gdb_assert (!left->duplicate); | |
12270 | if (is_tracepoint (right->owner)) | |
12271 | gdb_assert (!right->duplicate); | |
12272 | ||
934709f0 PW |
12273 | left->inserted = right->inserted; |
12274 | left->duplicate = right->duplicate; | |
b775012e | 12275 | left->needs_update = right->needs_update; |
934709f0 PW |
12276 | left->target_info = right->target_info; |
12277 | right->inserted = left_inserted; | |
12278 | right->duplicate = left_duplicate; | |
b775012e | 12279 | right->needs_update = left_needs_update; |
934709f0 PW |
12280 | right->target_info = left_target_info; |
12281 | } | |
12282 | ||
b775012e LM |
12283 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12284 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12285 | conditions on the target's side. Such conditions need to be updated on | |
12286 | the target. */ | |
12287 | ||
12288 | static void | |
12289 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12290 | { | |
12291 | struct bp_location **locp = NULL, **loc2p; | |
12292 | struct bp_location *loc; | |
12293 | CORE_ADDR address = 0; | |
12294 | int pspace_num; | |
12295 | ||
12296 | address = bl->address; | |
12297 | pspace_num = bl->pspace->num; | |
12298 | ||
12299 | /* This is only meaningful if the target is | |
12300 | evaluating conditions and if the user has | |
12301 | opted for condition evaluation on the target's | |
12302 | side. */ | |
12303 | if (gdb_evaluates_breakpoint_condition_p () | |
12304 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12305 | return; | |
12306 | ||
12307 | /* Flag all breakpoint locations with this address and | |
12308 | the same program space as the location | |
12309 | as "its condition has changed". We need to | |
12310 | update the conditions on the target's side. */ | |
12311 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12312 | { | |
12313 | loc = *loc2p; | |
12314 | ||
12315 | if (!is_breakpoint (loc->owner) | |
12316 | || pspace_num != loc->pspace->num) | |
12317 | continue; | |
12318 | ||
12319 | /* Flag the location appropriately. We use a different state to | |
12320 | let everyone know that we already updated the set of locations | |
12321 | with addr bl->address and program space bl->pspace. This is so | |
12322 | we don't have to keep calling these functions just to mark locations | |
12323 | that have already been marked. */ | |
12324 | loc->condition_changed = condition_updated; | |
12325 | ||
12326 | /* Free the agent expression bytecode as well. We will compute | |
12327 | it later on. */ | |
833177a4 | 12328 | loc->cond_bytecode.reset (); |
b775012e LM |
12329 | } |
12330 | } | |
44702360 PA |
12331 | /* Called whether new breakpoints are created, or existing breakpoints |
12332 | deleted, to update the global location list and recompute which | |
12333 | locations are duplicate of which. | |
b775012e | 12334 | |
04086b45 PA |
12335 | The INSERT_MODE flag determines whether locations may not, may, or |
12336 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12337 | info. */ | |
b60e7edf | 12338 | |
0d381245 | 12339 | static void |
44702360 | 12340 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12341 | { |
74960c60 | 12342 | struct breakpoint *b; |
876fa593 | 12343 | struct bp_location **locp, *loc; |
f7545552 | 12344 | struct cleanup *cleanups; |
b775012e LM |
12345 | /* Last breakpoint location address that was marked for update. */ |
12346 | CORE_ADDR last_addr = 0; | |
12347 | /* Last breakpoint location program space that was marked for update. */ | |
12348 | int last_pspace_num = -1; | |
f7545552 | 12349 | |
2d134ed3 PA |
12350 | /* Used in the duplicates detection below. When iterating over all |
12351 | bp_locations, points to the first bp_location of a given address. | |
12352 | Breakpoints and watchpoints of different types are never | |
12353 | duplicates of each other. Keep one pointer for each type of | |
12354 | breakpoint/watchpoint, so we only need to loop over all locations | |
12355 | once. */ | |
12356 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12357 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12358 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12359 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12360 | |
f5336ca5 PA |
12361 | /* Saved former bp_locations array which we compare against the newly |
12362 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
12363 | struct bp_location **old_locations, **old_locp; | |
12364 | unsigned old_locations_count; | |
876fa593 | 12365 | |
f5336ca5 PA |
12366 | old_locations = bp_locations; |
12367 | old_locations_count = bp_locations_count; | |
12368 | bp_locations = NULL; | |
12369 | bp_locations_count = 0; | |
12370 | cleanups = make_cleanup (xfree, old_locations); | |
0d381245 | 12371 | |
74960c60 | 12372 | ALL_BREAKPOINTS (b) |
876fa593 | 12373 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 12374 | bp_locations_count++; |
876fa593 | 12375 | |
f5336ca5 PA |
12376 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
12377 | locp = bp_locations; | |
876fa593 JK |
12378 | ALL_BREAKPOINTS (b) |
12379 | for (loc = b->loc; loc; loc = loc->next) | |
12380 | *locp++ = loc; | |
f5336ca5 PA |
12381 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
12382 | bp_locations_compare); | |
876fa593 | 12383 | |
f5336ca5 | 12384 | bp_locations_target_extensions_update (); |
74960c60 | 12385 | |
4a64f543 MS |
12386 | /* Identify bp_location instances that are no longer present in the |
12387 | new list, and therefore should be freed. Note that it's not | |
12388 | necessary that those locations should be removed from inferior -- | |
12389 | if there's another location at the same address (previously | |
12390 | marked as duplicate), we don't need to remove/insert the | |
12391 | location. | |
876fa593 | 12392 | |
4a64f543 MS |
12393 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12394 | and former bp_location array state respectively. */ | |
876fa593 | 12395 | |
f5336ca5 PA |
12396 | locp = bp_locations; |
12397 | for (old_locp = old_locations; | |
12398 | old_locp < old_locations + old_locations_count; | |
876fa593 | 12399 | old_locp++) |
74960c60 | 12400 | { |
876fa593 | 12401 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12402 | struct bp_location **loc2p; |
876fa593 | 12403 | |
e5dd4106 | 12404 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12405 | not, we have to free it. */ |
c7d46a38 | 12406 | int found_object = 0; |
20874c92 VP |
12407 | /* Tells if the location should remain inserted in the target. */ |
12408 | int keep_in_target = 0; | |
12409 | int removed = 0; | |
876fa593 | 12410 | |
4a64f543 MS |
12411 | /* Skip LOCP entries which will definitely never be needed. |
12412 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 12413 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 12414 | && (*locp)->address < old_loc->address) |
876fa593 | 12415 | locp++; |
c7d46a38 PA |
12416 | |
12417 | for (loc2p = locp; | |
f5336ca5 | 12418 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
12419 | && (*loc2p)->address == old_loc->address); |
12420 | loc2p++) | |
12421 | { | |
b775012e LM |
12422 | /* Check if this is a new/duplicated location or a duplicated |
12423 | location that had its condition modified. If so, we want to send | |
12424 | its condition to the target if evaluation of conditions is taking | |
12425 | place there. */ | |
12426 | if ((*loc2p)->condition_changed == condition_modified | |
12427 | && (last_addr != old_loc->address | |
12428 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12429 | { |
b775012e LM |
12430 | force_breakpoint_reinsertion (*loc2p); |
12431 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12432 | } |
b775012e LM |
12433 | |
12434 | if (*loc2p == old_loc) | |
12435 | found_object = 1; | |
c7d46a38 | 12436 | } |
74960c60 | 12437 | |
b775012e LM |
12438 | /* We have already handled this address, update it so that we don't |
12439 | have to go through updates again. */ | |
12440 | last_addr = old_loc->address; | |
12441 | ||
12442 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12443 | if (!found_object) | |
12444 | force_breakpoint_reinsertion (old_loc); | |
12445 | ||
4a64f543 MS |
12446 | /* If this location is no longer present, and inserted, look if |
12447 | there's maybe a new location at the same address. If so, | |
12448 | mark that one inserted, and don't remove this one. This is | |
12449 | needed so that we don't have a time window where a breakpoint | |
12450 | at certain location is not inserted. */ | |
74960c60 | 12451 | |
876fa593 | 12452 | if (old_loc->inserted) |
0d381245 | 12453 | { |
4a64f543 MS |
12454 | /* If the location is inserted now, we might have to remove |
12455 | it. */ | |
74960c60 | 12456 | |
876fa593 | 12457 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12458 | { |
4a64f543 MS |
12459 | /* The location is still present in the location list, |
12460 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12461 | keep_in_target = 1; |
74960c60 VP |
12462 | } |
12463 | else | |
12464 | { | |
b775012e LM |
12465 | /* This location still exists, but it won't be kept in the |
12466 | target since it may have been disabled. We proceed to | |
12467 | remove its target-side condition. */ | |
12468 | ||
4a64f543 MS |
12469 | /* The location is either no longer present, or got |
12470 | disabled. See if there's another location at the | |
12471 | same address, in which case we don't need to remove | |
12472 | this one from the target. */ | |
876fa593 | 12473 | |
2bdf28a0 | 12474 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12475 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12476 | { | |
876fa593 | 12477 | for (loc2p = locp; |
f5336ca5 | 12478 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 12479 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
12480 | loc2p++) |
12481 | { | |
12482 | struct bp_location *loc2 = *loc2p; | |
12483 | ||
2d134ed3 | 12484 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12485 | { |
85d721b8 PA |
12486 | /* Read watchpoint locations are switched to |
12487 | access watchpoints, if the former are not | |
12488 | supported, but the latter are. */ | |
12489 | if (is_hardware_watchpoint (old_loc->owner)) | |
12490 | { | |
12491 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12492 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12493 | } | |
12494 | ||
934709f0 PW |
12495 | /* loc2 is a duplicated location. We need to check |
12496 | if it should be inserted in case it will be | |
12497 | unduplicated. */ | |
12498 | if (loc2 != old_loc | |
12499 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12500 | { |
934709f0 | 12501 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12502 | keep_in_target = 1; |
12503 | break; | |
12504 | } | |
876fa593 JK |
12505 | } |
12506 | } | |
12507 | } | |
74960c60 VP |
12508 | } |
12509 | ||
20874c92 VP |
12510 | if (!keep_in_target) |
12511 | { | |
834c0d03 | 12512 | if (remove_breakpoint (old_loc)) |
20874c92 | 12513 | { |
4a64f543 MS |
12514 | /* This is just about all we can do. We could keep |
12515 | this location on the global list, and try to | |
12516 | remove it next time, but there's no particular | |
12517 | reason why we will succeed next time. | |
20874c92 | 12518 | |
4a64f543 MS |
12519 | Note that at this point, old_loc->owner is still |
12520 | valid, as delete_breakpoint frees the breakpoint | |
12521 | only after calling us. */ | |
3e43a32a MS |
12522 | printf_filtered (_("warning: Error removing " |
12523 | "breakpoint %d\n"), | |
876fa593 | 12524 | old_loc->owner->number); |
20874c92 VP |
12525 | } |
12526 | removed = 1; | |
12527 | } | |
0d381245 | 12528 | } |
74960c60 VP |
12529 | |
12530 | if (!found_object) | |
1c5cfe86 | 12531 | { |
fbea99ea | 12532 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12533 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12534 | { |
db82e815 PA |
12535 | /* This location was removed from the target. In |
12536 | non-stop mode, a race condition is possible where | |
12537 | we've removed a breakpoint, but stop events for that | |
12538 | breakpoint are already queued and will arrive later. | |
12539 | We apply an heuristic to be able to distinguish such | |
12540 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12541 | breakpoint location for a bit, and will retire it | |
12542 | after we see some number of events. The theory here | |
12543 | is that reporting of events should, "on the average", | |
12544 | be fair, so after a while we'll see events from all | |
12545 | threads that have anything of interest, and no longer | |
12546 | need to keep this breakpoint location around. We | |
12547 | don't hold locations forever so to reduce chances of | |
12548 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12549 | SIGTRAP. | |
12550 | ||
12551 | The heuristic failing can be disastrous on | |
12552 | decr_pc_after_break targets. | |
12553 | ||
12554 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12555 | if we fail to recognize a late breakpoint SIGTRAP, | |
12556 | because events_till_retirement has reached 0 too | |
12557 | soon, we'll fail to do the PC adjustment, and report | |
12558 | a random SIGTRAP to the user. When the user resumes | |
12559 | the inferior, it will most likely immediately crash | |
2dec564e | 12560 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12561 | corrupted, because of being resumed e.g., in the |
12562 | middle of a multi-byte instruction, or skipped a | |
12563 | one-byte instruction. This was actually seen happen | |
12564 | on native x86-linux, and should be less rare on | |
12565 | targets that do not support new thread events, like | |
12566 | remote, due to the heuristic depending on | |
12567 | thread_count. | |
12568 | ||
12569 | Mistaking a random SIGTRAP for a breakpoint trap | |
12570 | causes similar symptoms (PC adjustment applied when | |
12571 | it shouldn't), but then again, playing with SIGTRAPs | |
12572 | behind the debugger's back is asking for trouble. | |
12573 | ||
12574 | Since hardware watchpoint traps are always | |
12575 | distinguishable from other traps, so we don't need to | |
12576 | apply keep hardware watchpoint moribund locations | |
12577 | around. We simply always ignore hardware watchpoint | |
12578 | traps we can no longer explain. */ | |
12579 | ||
876fa593 JK |
12580 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12581 | old_loc->owner = NULL; | |
20874c92 | 12582 | |
876fa593 | 12583 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12584 | } |
12585 | else | |
f431efe5 PA |
12586 | { |
12587 | old_loc->owner = NULL; | |
12588 | decref_bp_location (&old_loc); | |
12589 | } | |
20874c92 | 12590 | } |
74960c60 | 12591 | } |
1c5cfe86 | 12592 | |
348d480f PA |
12593 | /* Rescan breakpoints at the same address and section, marking the |
12594 | first one as "first" and any others as "duplicates". This is so | |
12595 | that the bpt instruction is only inserted once. If we have a | |
12596 | permanent breakpoint at the same place as BPT, make that one the | |
12597 | official one, and the rest as duplicates. Permanent breakpoints | |
12598 | are sorted first for the same address. | |
12599 | ||
12600 | Do the same for hardware watchpoints, but also considering the | |
12601 | watchpoint's type (regular/access/read) and length. */ | |
12602 | ||
12603 | bp_loc_first = NULL; | |
12604 | wp_loc_first = NULL; | |
12605 | awp_loc_first = NULL; | |
12606 | rwp_loc_first = NULL; | |
12607 | ALL_BP_LOCATIONS (loc, locp) | |
12608 | { | |
12609 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12610 | non-NULL. */ | |
348d480f | 12611 | struct bp_location **loc_first_p; |
d3fbdd86 | 12612 | b = loc->owner; |
348d480f | 12613 | |
6f380991 | 12614 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12615 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12616 | /* Don't detect duplicate for tracepoint locations because they are |
12617 | never duplicated. See the comments in field `duplicate' of | |
12618 | `struct bp_location'. */ | |
348d480f | 12619 | || is_tracepoint (b)) |
b775012e LM |
12620 | { |
12621 | /* Clear the condition modification flag. */ | |
12622 | loc->condition_changed = condition_unchanged; | |
12623 | continue; | |
12624 | } | |
348d480f | 12625 | |
348d480f PA |
12626 | if (b->type == bp_hardware_watchpoint) |
12627 | loc_first_p = &wp_loc_first; | |
12628 | else if (b->type == bp_read_watchpoint) | |
12629 | loc_first_p = &rwp_loc_first; | |
12630 | else if (b->type == bp_access_watchpoint) | |
12631 | loc_first_p = &awp_loc_first; | |
12632 | else | |
12633 | loc_first_p = &bp_loc_first; | |
12634 | ||
12635 | if (*loc_first_p == NULL | |
12636 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12637 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12638 | { | |
12639 | *loc_first_p = loc; | |
12640 | loc->duplicate = 0; | |
b775012e LM |
12641 | |
12642 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12643 | { | |
12644 | loc->needs_update = 1; | |
12645 | /* Clear the condition modification flag. */ | |
12646 | loc->condition_changed = condition_unchanged; | |
12647 | } | |
348d480f PA |
12648 | continue; |
12649 | } | |
12650 | ||
934709f0 PW |
12651 | |
12652 | /* This and the above ensure the invariant that the first location | |
12653 | is not duplicated, and is the inserted one. | |
12654 | All following are marked as duplicated, and are not inserted. */ | |
12655 | if (loc->inserted) | |
12656 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12657 | loc->duplicate = 1; |
12658 | ||
b775012e LM |
12659 | /* Clear the condition modification flag. */ |
12660 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12661 | } |
12662 | ||
a25a5a45 | 12663 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12664 | { |
04086b45 | 12665 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12666 | insert_breakpoint_locations (); |
12667 | else | |
12668 | { | |
44702360 PA |
12669 | /* Even though the caller told us to not insert new |
12670 | locations, we may still need to update conditions on the | |
12671 | target's side of breakpoints that were already inserted | |
12672 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12673 | only update conditions for locations that are marked |
12674 | "needs_update". */ | |
12675 | update_inserted_breakpoint_locations (); | |
12676 | } | |
12677 | } | |
348d480f | 12678 | |
04086b45 | 12679 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12680 | download_tracepoint_locations (); |
12681 | ||
348d480f PA |
12682 | do_cleanups (cleanups); |
12683 | } | |
12684 | ||
12685 | void | |
12686 | breakpoint_retire_moribund (void) | |
12687 | { | |
12688 | struct bp_location *loc; | |
12689 | int ix; | |
12690 | ||
12691 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12692 | if (--(loc->events_till_retirement) == 0) | |
12693 | { | |
12694 | decref_bp_location (&loc); | |
12695 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12696 | --ix; | |
12697 | } | |
12698 | } | |
12699 | ||
12700 | static void | |
44702360 | 12701 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12702 | { |
348d480f | 12703 | |
492d29ea PA |
12704 | TRY |
12705 | { | |
12706 | update_global_location_list (insert_mode); | |
12707 | } | |
12708 | CATCH (e, RETURN_MASK_ERROR) | |
12709 | { | |
12710 | } | |
12711 | END_CATCH | |
348d480f PA |
12712 | } |
12713 | ||
12714 | /* Clear BKP from a BPS. */ | |
12715 | ||
12716 | static void | |
12717 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12718 | { | |
12719 | bpstat bs; | |
12720 | ||
12721 | for (bs = bps; bs; bs = bs->next) | |
12722 | if (bs->breakpoint_at == bpt) | |
12723 | { | |
12724 | bs->breakpoint_at = NULL; | |
12725 | bs->old_val = NULL; | |
12726 | /* bs->commands will be freed later. */ | |
12727 | } | |
12728 | } | |
12729 | ||
12730 | /* Callback for iterate_over_threads. */ | |
12731 | static int | |
12732 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12733 | { | |
9a3c8263 | 12734 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12735 | |
12736 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12737 | return 0; | |
12738 | } | |
12739 | ||
12740 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12741 | callbacks. */ | |
12742 | ||
12743 | static void | |
12744 | say_where (struct breakpoint *b) | |
12745 | { | |
12746 | struct value_print_options opts; | |
12747 | ||
12748 | get_user_print_options (&opts); | |
12749 | ||
12750 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12751 | single string. */ | |
12752 | if (b->loc == NULL) | |
12753 | { | |
f00aae0f KS |
12754 | /* For pending locations, the output differs slightly based |
12755 | on b->extra_string. If this is non-NULL, it contains either | |
12756 | a condition or dprintf arguments. */ | |
12757 | if (b->extra_string == NULL) | |
12758 | { | |
12759 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12760 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12761 | } |
12762 | else if (b->type == bp_dprintf) | |
12763 | { | |
12764 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12765 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12766 | b->extra_string); |
12767 | } | |
12768 | else | |
12769 | { | |
12770 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12771 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12772 | b->extra_string); |
12773 | } | |
348d480f PA |
12774 | } |
12775 | else | |
12776 | { | |
2f202fde | 12777 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12778 | { |
12779 | printf_filtered (" at "); | |
12780 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12781 | gdb_stdout); | |
12782 | } | |
2f202fde | 12783 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12784 | { |
12785 | /* If there is a single location, we can print the location | |
12786 | more nicely. */ | |
12787 | if (b->loc->next == NULL) | |
12788 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12789 | symtab_to_filename_for_display (b->loc->symtab), |
12790 | b->loc->line_number); | |
f8eba3c6 TT |
12791 | else |
12792 | /* This is not ideal, but each location may have a | |
12793 | different file name, and this at least reflects the | |
12794 | real situation somewhat. */ | |
f00aae0f | 12795 | printf_filtered (": %s.", |
d28cd78a | 12796 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12797 | } |
348d480f PA |
12798 | |
12799 | if (b->loc->next) | |
12800 | { | |
12801 | struct bp_location *loc = b->loc; | |
12802 | int n = 0; | |
12803 | for (; loc; loc = loc->next) | |
12804 | ++n; | |
12805 | printf_filtered (" (%d locations)", n); | |
12806 | } | |
12807 | } | |
12808 | } | |
12809 | ||
348d480f PA |
12810 | /* Default bp_location_ops methods. */ |
12811 | ||
12812 | static void | |
12813 | bp_location_dtor (struct bp_location *self) | |
12814 | { | |
348d480f PA |
12815 | xfree (self->function_name); |
12816 | } | |
12817 | ||
12818 | static const struct bp_location_ops bp_location_ops = | |
12819 | { | |
12820 | bp_location_dtor | |
12821 | }; | |
12822 | ||
2060206e PA |
12823 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12824 | inherit from. */ | |
348d480f | 12825 | |
2060206e PA |
12826 | static void |
12827 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12828 | { |
12829 | decref_counted_command_line (&self->commands); | |
12830 | xfree (self->cond_string); | |
fb81d016 | 12831 | xfree (self->extra_string); |
f8eba3c6 | 12832 | xfree (self->filter); |
348d480f PA |
12833 | } |
12834 | ||
2060206e PA |
12835 | static struct bp_location * |
12836 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12837 | { |
12838 | struct bp_location *loc; | |
12839 | ||
4d01a485 | 12840 | loc = new struct bp_location (); |
348d480f PA |
12841 | init_bp_location (loc, &bp_location_ops, self); |
12842 | return loc; | |
12843 | } | |
12844 | ||
2060206e PA |
12845 | static void |
12846 | base_breakpoint_re_set (struct breakpoint *b) | |
12847 | { | |
12848 | /* Nothing to re-set. */ | |
12849 | } | |
12850 | ||
12851 | #define internal_error_pure_virtual_called() \ | |
12852 | gdb_assert_not_reached ("pure virtual function called") | |
12853 | ||
12854 | static int | |
12855 | base_breakpoint_insert_location (struct bp_location *bl) | |
12856 | { | |
12857 | internal_error_pure_virtual_called (); | |
12858 | } | |
12859 | ||
12860 | static int | |
73971819 PA |
12861 | base_breakpoint_remove_location (struct bp_location *bl, |
12862 | enum remove_bp_reason reason) | |
2060206e PA |
12863 | { |
12864 | internal_error_pure_virtual_called (); | |
12865 | } | |
12866 | ||
12867 | static int | |
12868 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12869 | struct address_space *aspace, | |
09ac7c10 TT |
12870 | CORE_ADDR bp_addr, |
12871 | const struct target_waitstatus *ws) | |
2060206e PA |
12872 | { |
12873 | internal_error_pure_virtual_called (); | |
12874 | } | |
12875 | ||
12876 | static void | |
12877 | base_breakpoint_check_status (bpstat bs) | |
12878 | { | |
12879 | /* Always stop. */ | |
12880 | } | |
12881 | ||
12882 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12883 | errors. */ | |
12884 | ||
12885 | static int | |
12886 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12887 | { | |
12888 | internal_error_pure_virtual_called (); | |
12889 | } | |
12890 | ||
12891 | /* A "resources_needed" breakpoint_ops method that just internal | |
12892 | errors. */ | |
12893 | ||
12894 | static int | |
12895 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12896 | { | |
12897 | internal_error_pure_virtual_called (); | |
12898 | } | |
12899 | ||
12900 | static enum print_stop_action | |
12901 | base_breakpoint_print_it (bpstat bs) | |
12902 | { | |
12903 | internal_error_pure_virtual_called (); | |
12904 | } | |
12905 | ||
12906 | static void | |
12907 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12908 | struct ui_out *uiout) | |
12909 | { | |
12910 | /* nothing */ | |
12911 | } | |
12912 | ||
12913 | static void | |
12914 | base_breakpoint_print_mention (struct breakpoint *b) | |
12915 | { | |
12916 | internal_error_pure_virtual_called (); | |
12917 | } | |
12918 | ||
12919 | static void | |
12920 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12921 | { | |
12922 | internal_error_pure_virtual_called (); | |
12923 | } | |
12924 | ||
983af33b | 12925 | static void |
f00aae0f KS |
12926 | base_breakpoint_create_sals_from_location |
12927 | (const struct event_location *location, | |
12928 | struct linespec_result *canonical, | |
12929 | enum bptype type_wanted) | |
983af33b SDJ |
12930 | { |
12931 | internal_error_pure_virtual_called (); | |
12932 | } | |
12933 | ||
12934 | static void | |
12935 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12936 | struct linespec_result *c, | |
983af33b | 12937 | char *cond_string, |
e7e0cddf | 12938 | char *extra_string, |
983af33b SDJ |
12939 | enum bptype type_wanted, |
12940 | enum bpdisp disposition, | |
12941 | int thread, | |
12942 | int task, int ignore_count, | |
12943 | const struct breakpoint_ops *o, | |
12944 | int from_tty, int enabled, | |
44f238bb | 12945 | int internal, unsigned flags) |
983af33b SDJ |
12946 | { |
12947 | internal_error_pure_virtual_called (); | |
12948 | } | |
12949 | ||
12950 | static void | |
f00aae0f KS |
12951 | base_breakpoint_decode_location (struct breakpoint *b, |
12952 | const struct event_location *location, | |
c2f4122d | 12953 | struct program_space *search_pspace, |
983af33b SDJ |
12954 | struct symtabs_and_lines *sals) |
12955 | { | |
12956 | internal_error_pure_virtual_called (); | |
12957 | } | |
12958 | ||
ab04a2af TT |
12959 | /* The default 'explains_signal' method. */ |
12960 | ||
47591c29 | 12961 | static int |
427cd150 | 12962 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12963 | { |
47591c29 | 12964 | return 1; |
ab04a2af TT |
12965 | } |
12966 | ||
9d6e6e84 HZ |
12967 | /* The default "after_condition_true" method. */ |
12968 | ||
12969 | static void | |
12970 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12971 | { | |
12972 | /* Nothing to do. */ | |
12973 | } | |
12974 | ||
ab04a2af | 12975 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12976 | { |
12977 | base_breakpoint_dtor, | |
12978 | base_breakpoint_allocate_location, | |
12979 | base_breakpoint_re_set, | |
12980 | base_breakpoint_insert_location, | |
12981 | base_breakpoint_remove_location, | |
12982 | base_breakpoint_breakpoint_hit, | |
12983 | base_breakpoint_check_status, | |
12984 | base_breakpoint_resources_needed, | |
12985 | base_breakpoint_works_in_software_mode, | |
12986 | base_breakpoint_print_it, | |
12987 | NULL, | |
12988 | base_breakpoint_print_one_detail, | |
12989 | base_breakpoint_print_mention, | |
983af33b | 12990 | base_breakpoint_print_recreate, |
5f700d83 | 12991 | base_breakpoint_create_sals_from_location, |
983af33b | 12992 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12993 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12994 | base_breakpoint_explains_signal, |
12995 | base_breakpoint_after_condition_true, | |
2060206e PA |
12996 | }; |
12997 | ||
12998 | /* Default breakpoint_ops methods. */ | |
12999 | ||
13000 | static void | |
348d480f PA |
13001 | bkpt_re_set (struct breakpoint *b) |
13002 | { | |
06edf0c0 | 13003 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 13004 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 13005 | { |
f00aae0f | 13006 | /* Anything without a location can't be re-set. */ |
348d480f | 13007 | delete_breakpoint (b); |
06edf0c0 | 13008 | return; |
348d480f | 13009 | } |
06edf0c0 PA |
13010 | |
13011 | breakpoint_re_set_default (b); | |
348d480f PA |
13012 | } |
13013 | ||
2060206e | 13014 | static int |
348d480f PA |
13015 | bkpt_insert_location (struct bp_location *bl) |
13016 | { | |
cd6c3b4f YQ |
13017 | CORE_ADDR addr = bl->target_info.reqstd_address; |
13018 | ||
579c6ad9 | 13019 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
13020 | bl->target_info.placed_address = addr; |
13021 | ||
348d480f | 13022 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 13023 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13024 | else |
7c16b83e | 13025 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13026 | } |
13027 | ||
2060206e | 13028 | static int |
73971819 | 13029 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
13030 | { |
13031 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13032 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13033 | else | |
73971819 | 13034 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
13035 | } |
13036 | ||
2060206e | 13037 | static int |
348d480f | 13038 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13039 | struct address_space *aspace, CORE_ADDR bp_addr, |
13040 | const struct target_waitstatus *ws) | |
348d480f | 13041 | { |
09ac7c10 | 13042 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13043 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13044 | return 0; |
13045 | ||
348d480f PA |
13046 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13047 | aspace, bp_addr)) | |
13048 | return 0; | |
13049 | ||
13050 | if (overlay_debugging /* unmapped overlay section */ | |
13051 | && section_is_overlay (bl->section) | |
13052 | && !section_is_mapped (bl->section)) | |
13053 | return 0; | |
13054 | ||
13055 | return 1; | |
13056 | } | |
13057 | ||
cd1608cc PA |
13058 | static int |
13059 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13060 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13061 | const struct target_waitstatus *ws) | |
13062 | { | |
13063 | if (dprintf_style == dprintf_style_agent | |
13064 | && target_can_run_breakpoint_commands ()) | |
13065 | { | |
13066 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13067 | for this address it must be for a breakpoint that happens to | |
13068 | be set at the same address. */ | |
13069 | return 0; | |
13070 | } | |
13071 | ||
13072 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13073 | } | |
13074 | ||
2060206e | 13075 | static int |
348d480f PA |
13076 | bkpt_resources_needed (const struct bp_location *bl) |
13077 | { | |
13078 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13079 | ||
13080 | return 1; | |
13081 | } | |
13082 | ||
2060206e | 13083 | static enum print_stop_action |
348d480f PA |
13084 | bkpt_print_it (bpstat bs) |
13085 | { | |
348d480f PA |
13086 | struct breakpoint *b; |
13087 | const struct bp_location *bl; | |
001c8c33 | 13088 | int bp_temp; |
79a45e25 | 13089 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13090 | |
13091 | gdb_assert (bs->bp_location_at != NULL); | |
13092 | ||
13093 | bl = bs->bp_location_at; | |
13094 | b = bs->breakpoint_at; | |
13095 | ||
001c8c33 PA |
13096 | bp_temp = b->disposition == disp_del; |
13097 | if (bl->address != bl->requested_address) | |
13098 | breakpoint_adjustment_warning (bl->requested_address, | |
13099 | bl->address, | |
13100 | b->number, 1); | |
13101 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
13102 | maybe_print_thread_hit_breakpoint (uiout); |
13103 | ||
001c8c33 | 13104 | if (bp_temp) |
112e8700 | 13105 | uiout->text ("Temporary breakpoint "); |
001c8c33 | 13106 | else |
112e8700 SM |
13107 | uiout->text ("Breakpoint "); |
13108 | if (uiout->is_mi_like_p ()) | |
348d480f | 13109 | { |
112e8700 | 13110 | uiout->field_string ("reason", |
001c8c33 | 13111 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 13112 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 13113 | } |
112e8700 SM |
13114 | uiout->field_int ("bkptno", b->number); |
13115 | uiout->text (", "); | |
06edf0c0 | 13116 | |
001c8c33 | 13117 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13118 | } |
13119 | ||
2060206e | 13120 | static void |
06edf0c0 PA |
13121 | bkpt_print_mention (struct breakpoint *b) |
13122 | { | |
112e8700 | 13123 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
13124 | return; |
13125 | ||
13126 | switch (b->type) | |
13127 | { | |
13128 | case bp_breakpoint: | |
13129 | case bp_gnu_ifunc_resolver: | |
13130 | if (b->disposition == disp_del) | |
13131 | printf_filtered (_("Temporary breakpoint")); | |
13132 | else | |
13133 | printf_filtered (_("Breakpoint")); | |
13134 | printf_filtered (_(" %d"), b->number); | |
13135 | if (b->type == bp_gnu_ifunc_resolver) | |
13136 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13137 | break; | |
13138 | case bp_hardware_breakpoint: | |
13139 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13140 | break; | |
e7e0cddf SS |
13141 | case bp_dprintf: |
13142 | printf_filtered (_("Dprintf %d"), b->number); | |
13143 | break; | |
06edf0c0 PA |
13144 | } |
13145 | ||
13146 | say_where (b); | |
13147 | } | |
13148 | ||
2060206e | 13149 | static void |
06edf0c0 PA |
13150 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13151 | { | |
13152 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13153 | fprintf_unfiltered (fp, "tbreak"); | |
13154 | else if (tp->type == bp_breakpoint) | |
13155 | fprintf_unfiltered (fp, "break"); | |
13156 | else if (tp->type == bp_hardware_breakpoint | |
13157 | && tp->disposition == disp_del) | |
13158 | fprintf_unfiltered (fp, "thbreak"); | |
13159 | else if (tp->type == bp_hardware_breakpoint) | |
13160 | fprintf_unfiltered (fp, "hbreak"); | |
13161 | else | |
13162 | internal_error (__FILE__, __LINE__, | |
13163 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13164 | ||
f00aae0f | 13165 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13166 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
13167 | |
13168 | /* Print out extra_string if this breakpoint is pending. It might | |
13169 | contain, for example, conditions that were set by the user. */ | |
13170 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13171 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13172 | ||
dd11a36c | 13173 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13174 | } |
13175 | ||
983af33b | 13176 | static void |
f00aae0f KS |
13177 | bkpt_create_sals_from_location (const struct event_location *location, |
13178 | struct linespec_result *canonical, | |
13179 | enum bptype type_wanted) | |
983af33b | 13180 | { |
f00aae0f | 13181 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13182 | } |
13183 | ||
13184 | static void | |
13185 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13186 | struct linespec_result *canonical, | |
983af33b | 13187 | char *cond_string, |
e7e0cddf | 13188 | char *extra_string, |
983af33b SDJ |
13189 | enum bptype type_wanted, |
13190 | enum bpdisp disposition, | |
13191 | int thread, | |
13192 | int task, int ignore_count, | |
13193 | const struct breakpoint_ops *ops, | |
13194 | int from_tty, int enabled, | |
44f238bb | 13195 | int internal, unsigned flags) |
983af33b | 13196 | { |
023fa29b | 13197 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13198 | cond_string, extra_string, |
13199 | type_wanted, | |
983af33b SDJ |
13200 | disposition, thread, task, |
13201 | ignore_count, ops, from_tty, | |
44f238bb | 13202 | enabled, internal, flags); |
983af33b SDJ |
13203 | } |
13204 | ||
13205 | static void | |
f00aae0f KS |
13206 | bkpt_decode_location (struct breakpoint *b, |
13207 | const struct event_location *location, | |
c2f4122d | 13208 | struct program_space *search_pspace, |
983af33b SDJ |
13209 | struct symtabs_and_lines *sals) |
13210 | { | |
c2f4122d | 13211 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13212 | } |
13213 | ||
06edf0c0 PA |
13214 | /* Virtual table for internal breakpoints. */ |
13215 | ||
13216 | static void | |
13217 | internal_bkpt_re_set (struct breakpoint *b) | |
13218 | { | |
13219 | switch (b->type) | |
13220 | { | |
13221 | /* Delete overlay event and longjmp master breakpoints; they | |
13222 | will be reset later by breakpoint_re_set. */ | |
13223 | case bp_overlay_event: | |
13224 | case bp_longjmp_master: | |
13225 | case bp_std_terminate_master: | |
13226 | case bp_exception_master: | |
13227 | delete_breakpoint (b); | |
13228 | break; | |
13229 | ||
13230 | /* This breakpoint is special, it's set up when the inferior | |
13231 | starts and we really don't want to touch it. */ | |
13232 | case bp_shlib_event: | |
13233 | ||
13234 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13235 | it is set up, we do not want to touch it. */ | |
13236 | case bp_thread_event: | |
13237 | break; | |
13238 | } | |
13239 | } | |
13240 | ||
13241 | static void | |
13242 | internal_bkpt_check_status (bpstat bs) | |
13243 | { | |
a9b3a50f PA |
13244 | if (bs->breakpoint_at->type == bp_shlib_event) |
13245 | { | |
13246 | /* If requested, stop when the dynamic linker notifies GDB of | |
13247 | events. This allows the user to get control and place | |
13248 | breakpoints in initializer routines for dynamically loaded | |
13249 | objects (among other things). */ | |
13250 | bs->stop = stop_on_solib_events; | |
13251 | bs->print = stop_on_solib_events; | |
13252 | } | |
13253 | else | |
13254 | bs->stop = 0; | |
06edf0c0 PA |
13255 | } |
13256 | ||
13257 | static enum print_stop_action | |
13258 | internal_bkpt_print_it (bpstat bs) | |
13259 | { | |
06edf0c0 | 13260 | struct breakpoint *b; |
06edf0c0 | 13261 | |
06edf0c0 PA |
13262 | b = bs->breakpoint_at; |
13263 | ||
06edf0c0 PA |
13264 | switch (b->type) |
13265 | { | |
348d480f PA |
13266 | case bp_shlib_event: |
13267 | /* Did we stop because the user set the stop_on_solib_events | |
13268 | variable? (If so, we report this as a generic, "Stopped due | |
13269 | to shlib event" message.) */ | |
edcc5120 | 13270 | print_solib_event (0); |
348d480f PA |
13271 | break; |
13272 | ||
13273 | case bp_thread_event: | |
13274 | /* Not sure how we will get here. | |
13275 | GDB should not stop for these breakpoints. */ | |
13276 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13277 | break; |
13278 | ||
13279 | case bp_overlay_event: | |
13280 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13281 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13282 | break; |
13283 | ||
13284 | case bp_longjmp_master: | |
13285 | /* These should never be enabled. */ | |
13286 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13287 | break; |
13288 | ||
13289 | case bp_std_terminate_master: | |
13290 | /* These should never be enabled. */ | |
13291 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13292 | "gdb should not stop!\n")); | |
348d480f PA |
13293 | break; |
13294 | ||
13295 | case bp_exception_master: | |
13296 | /* These should never be enabled. */ | |
13297 | printf_filtered (_("Exception Master Breakpoint: " | |
13298 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13299 | break; |
13300 | } | |
13301 | ||
001c8c33 | 13302 | return PRINT_NOTHING; |
06edf0c0 PA |
13303 | } |
13304 | ||
13305 | static void | |
13306 | internal_bkpt_print_mention (struct breakpoint *b) | |
13307 | { | |
13308 | /* Nothing to mention. These breakpoints are internal. */ | |
13309 | } | |
13310 | ||
06edf0c0 PA |
13311 | /* Virtual table for momentary breakpoints */ |
13312 | ||
13313 | static void | |
13314 | momentary_bkpt_re_set (struct breakpoint *b) | |
13315 | { | |
13316 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13317 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13318 | Otherwise these should have been blown away via the cleanup chain |
13319 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13320 | } | |
13321 | ||
13322 | static void | |
13323 | momentary_bkpt_check_status (bpstat bs) | |
13324 | { | |
13325 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13326 | } | |
13327 | ||
13328 | static enum print_stop_action | |
13329 | momentary_bkpt_print_it (bpstat bs) | |
13330 | { | |
001c8c33 | 13331 | return PRINT_UNKNOWN; |
348d480f PA |
13332 | } |
13333 | ||
06edf0c0 PA |
13334 | static void |
13335 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13336 | { |
06edf0c0 | 13337 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13338 | } |
13339 | ||
e2e4d78b JK |
13340 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13341 | ||
13342 | It gets cleared already on the removal of the first one of such placed | |
13343 | breakpoints. This is OK as they get all removed altogether. */ | |
13344 | ||
13345 | static void | |
13346 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13347 | { | |
5d5658a1 | 13348 | struct thread_info *tp = find_thread_global_id (self->thread); |
e2e4d78b JK |
13349 | |
13350 | if (tp) | |
13351 | tp->initiating_frame = null_frame_id; | |
13352 | ||
13353 | momentary_breakpoint_ops.dtor (self); | |
13354 | } | |
13355 | ||
55aa24fb SDJ |
13356 | /* Specific methods for probe breakpoints. */ |
13357 | ||
13358 | static int | |
13359 | bkpt_probe_insert_location (struct bp_location *bl) | |
13360 | { | |
13361 | int v = bkpt_insert_location (bl); | |
13362 | ||
13363 | if (v == 0) | |
13364 | { | |
13365 | /* The insertion was successful, now let's set the probe's semaphore | |
13366 | if needed. */ | |
0ea5cda8 SDJ |
13367 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13368 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13369 | bl->probe.objfile, | |
13370 | bl->gdbarch); | |
55aa24fb SDJ |
13371 | } |
13372 | ||
13373 | return v; | |
13374 | } | |
13375 | ||
13376 | static int | |
73971819 PA |
13377 | bkpt_probe_remove_location (struct bp_location *bl, |
13378 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13379 | { |
13380 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13381 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13382 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13383 | bl->probe.objfile, | |
13384 | bl->gdbarch); | |
55aa24fb | 13385 | |
73971819 | 13386 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13387 | } |
13388 | ||
13389 | static void | |
f00aae0f | 13390 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13391 | struct linespec_result *canonical, |
f00aae0f | 13392 | enum bptype type_wanted) |
55aa24fb SDJ |
13393 | { |
13394 | struct linespec_sals lsal; | |
13395 | ||
c2f4122d | 13396 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
13397 | lsal.canonical |
13398 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
55aa24fb SDJ |
13399 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13400 | } | |
13401 | ||
13402 | static void | |
f00aae0f KS |
13403 | bkpt_probe_decode_location (struct breakpoint *b, |
13404 | const struct event_location *location, | |
c2f4122d | 13405 | struct program_space *search_pspace, |
55aa24fb SDJ |
13406 | struct symtabs_and_lines *sals) |
13407 | { | |
c2f4122d | 13408 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13409 | if (!sals->sals) |
13410 | error (_("probe not found")); | |
13411 | } | |
13412 | ||
348d480f | 13413 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13414 | |
348d480f PA |
13415 | static void |
13416 | tracepoint_re_set (struct breakpoint *b) | |
13417 | { | |
13418 | breakpoint_re_set_default (b); | |
13419 | } | |
876fa593 | 13420 | |
348d480f PA |
13421 | static int |
13422 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13423 | struct address_space *aspace, CORE_ADDR bp_addr, |
13424 | const struct target_waitstatus *ws) | |
348d480f PA |
13425 | { |
13426 | /* By definition, the inferior does not report stops at | |
13427 | tracepoints. */ | |
13428 | return 0; | |
74960c60 VP |
13429 | } |
13430 | ||
13431 | static void | |
348d480f PA |
13432 | tracepoint_print_one_detail (const struct breakpoint *self, |
13433 | struct ui_out *uiout) | |
74960c60 | 13434 | { |
d9b3f62e PA |
13435 | struct tracepoint *tp = (struct tracepoint *) self; |
13436 | if (tp->static_trace_marker_id) | |
348d480f PA |
13437 | { |
13438 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13439 | |
112e8700 SM |
13440 | uiout->text ("\tmarker id is "); |
13441 | uiout->field_string ("static-tracepoint-marker-string-id", | |
d9b3f62e | 13442 | tp->static_trace_marker_id); |
112e8700 | 13443 | uiout->text ("\n"); |
348d480f | 13444 | } |
0d381245 VP |
13445 | } |
13446 | ||
a474d7c2 | 13447 | static void |
348d480f | 13448 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13449 | { |
112e8700 | 13450 | if (current_uiout->is_mi_like_p ()) |
348d480f | 13451 | return; |
cc59ec59 | 13452 | |
348d480f PA |
13453 | switch (b->type) |
13454 | { | |
13455 | case bp_tracepoint: | |
13456 | printf_filtered (_("Tracepoint")); | |
13457 | printf_filtered (_(" %d"), b->number); | |
13458 | break; | |
13459 | case bp_fast_tracepoint: | |
13460 | printf_filtered (_("Fast tracepoint")); | |
13461 | printf_filtered (_(" %d"), b->number); | |
13462 | break; | |
13463 | case bp_static_tracepoint: | |
13464 | printf_filtered (_("Static tracepoint")); | |
13465 | printf_filtered (_(" %d"), b->number); | |
13466 | break; | |
13467 | default: | |
13468 | internal_error (__FILE__, __LINE__, | |
13469 | _("unhandled tracepoint type %d"), (int) b->type); | |
13470 | } | |
13471 | ||
13472 | say_where (b); | |
a474d7c2 PA |
13473 | } |
13474 | ||
348d480f | 13475 | static void |
d9b3f62e | 13476 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13477 | { |
d9b3f62e PA |
13478 | struct tracepoint *tp = (struct tracepoint *) self; |
13479 | ||
13480 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13481 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13482 | else if (self->type == bp_static_tracepoint) |
348d480f | 13483 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13484 | else if (self->type == bp_tracepoint) |
348d480f PA |
13485 | fprintf_unfiltered (fp, "trace"); |
13486 | else | |
13487 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13488 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13489 | |
f00aae0f | 13490 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13491 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
13492 | print_recreate_thread (self, fp); |
13493 | ||
13494 | if (tp->pass_count) | |
13495 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13496 | } |
13497 | ||
983af33b | 13498 | static void |
f00aae0f KS |
13499 | tracepoint_create_sals_from_location (const struct event_location *location, |
13500 | struct linespec_result *canonical, | |
13501 | enum bptype type_wanted) | |
983af33b | 13502 | { |
f00aae0f | 13503 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13504 | } |
13505 | ||
13506 | static void | |
13507 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13508 | struct linespec_result *canonical, | |
983af33b | 13509 | char *cond_string, |
e7e0cddf | 13510 | char *extra_string, |
983af33b SDJ |
13511 | enum bptype type_wanted, |
13512 | enum bpdisp disposition, | |
13513 | int thread, | |
13514 | int task, int ignore_count, | |
13515 | const struct breakpoint_ops *ops, | |
13516 | int from_tty, int enabled, | |
44f238bb | 13517 | int internal, unsigned flags) |
983af33b | 13518 | { |
023fa29b | 13519 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13520 | cond_string, extra_string, |
13521 | type_wanted, | |
983af33b SDJ |
13522 | disposition, thread, task, |
13523 | ignore_count, ops, from_tty, | |
44f238bb | 13524 | enabled, internal, flags); |
983af33b SDJ |
13525 | } |
13526 | ||
13527 | static void | |
f00aae0f KS |
13528 | tracepoint_decode_location (struct breakpoint *b, |
13529 | const struct event_location *location, | |
c2f4122d | 13530 | struct program_space *search_pspace, |
983af33b SDJ |
13531 | struct symtabs_and_lines *sals) |
13532 | { | |
c2f4122d | 13533 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13534 | } |
13535 | ||
2060206e | 13536 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13537 | |
55aa24fb SDJ |
13538 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13539 | static probe. */ | |
13540 | ||
13541 | static void | |
f00aae0f KS |
13542 | tracepoint_probe_create_sals_from_location |
13543 | (const struct event_location *location, | |
13544 | struct linespec_result *canonical, | |
13545 | enum bptype type_wanted) | |
55aa24fb SDJ |
13546 | { |
13547 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13548 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13549 | } |
13550 | ||
13551 | static void | |
f00aae0f KS |
13552 | tracepoint_probe_decode_location (struct breakpoint *b, |
13553 | const struct event_location *location, | |
c2f4122d | 13554 | struct program_space *search_pspace, |
55aa24fb SDJ |
13555 | struct symtabs_and_lines *sals) |
13556 | { | |
13557 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13558 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13559 | } |
13560 | ||
13561 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13562 | ||
5c2b4418 HZ |
13563 | /* Dprintf breakpoint_ops methods. */ |
13564 | ||
13565 | static void | |
13566 | dprintf_re_set (struct breakpoint *b) | |
13567 | { | |
13568 | breakpoint_re_set_default (b); | |
13569 | ||
f00aae0f KS |
13570 | /* extra_string should never be non-NULL for dprintf. */ |
13571 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13572 | |
13573 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13574 | 2 - create a dprintf, which resolves fine. | |
13575 | 3 - disconnect from target 1 | |
13576 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13577 | ||
13578 | After steps #3/#4, you'll want the dprintf command list to | |
13579 | be updated, because target 1 and 2 may well return different | |
13580 | answers for target_can_run_breakpoint_commands(). | |
13581 | Given absence of finer grained resetting, we get to do | |
13582 | it all the time. */ | |
13583 | if (b->extra_string != NULL) | |
13584 | update_dprintf_command_list (b); | |
13585 | } | |
13586 | ||
2d9442cc HZ |
13587 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13588 | ||
13589 | static void | |
13590 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13591 | { | |
f00aae0f | 13592 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 13593 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
13594 | tp->extra_string); |
13595 | print_recreate_thread (tp, fp); | |
13596 | } | |
13597 | ||
9d6e6e84 HZ |
13598 | /* Implement the "after_condition_true" breakpoint_ops method for |
13599 | dprintf. | |
13600 | ||
13601 | dprintf's are implemented with regular commands in their command | |
13602 | list, but we run the commands here instead of before presenting the | |
13603 | stop to the user, as dprintf's don't actually cause a stop. This | |
13604 | also makes it so that the commands of multiple dprintfs at the same | |
13605 | address are all handled. */ | |
13606 | ||
13607 | static void | |
13608 | dprintf_after_condition_true (struct bpstats *bs) | |
13609 | { | |
13610 | struct cleanup *old_chain; | |
13611 | struct bpstats tmp_bs = { NULL }; | |
13612 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13613 | ||
13614 | /* dprintf's never cause a stop. This wasn't set in the | |
13615 | check_status hook instead because that would make the dprintf's | |
13616 | condition not be evaluated. */ | |
13617 | bs->stop = 0; | |
13618 | ||
13619 | /* Run the command list here. Take ownership of it instead of | |
13620 | copying. We never want these commands to run later in | |
13621 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13622 | be set at same address as this dprintf, or even if running the | |
13623 | commands here throws. */ | |
13624 | tmp_bs.commands = bs->commands; | |
13625 | bs->commands = NULL; | |
13626 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13627 | ||
13628 | bpstat_do_actions_1 (&tmp_bs_p); | |
13629 | ||
13630 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13631 | bpstat_do_actions_1 may return early without processing the whole | |
13632 | list. */ | |
13633 | do_cleanups (old_chain); | |
13634 | } | |
13635 | ||
983af33b SDJ |
13636 | /* The breakpoint_ops structure to be used on static tracepoints with |
13637 | markers (`-m'). */ | |
13638 | ||
13639 | static void | |
f00aae0f | 13640 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13641 | struct linespec_result *canonical, |
f00aae0f | 13642 | enum bptype type_wanted) |
983af33b SDJ |
13643 | { |
13644 | struct linespec_sals lsal; | |
f00aae0f KS |
13645 | const char *arg_start, *arg; |
13646 | char *str; | |
13647 | struct cleanup *cleanup; | |
983af33b | 13648 | |
f00aae0f KS |
13649 | arg = arg_start = get_linespec_location (location); |
13650 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13651 | |
f00aae0f KS |
13652 | str = savestring (arg_start, arg - arg_start); |
13653 | cleanup = make_cleanup (xfree, str); | |
8e9e35b1 | 13654 | canonical->location = new_linespec_location (&str); |
f00aae0f | 13655 | do_cleanups (cleanup); |
983af33b | 13656 | |
8e9e35b1 TT |
13657 | lsal.canonical |
13658 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
983af33b SDJ |
13659 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13660 | } | |
13661 | ||
13662 | static void | |
13663 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13664 | struct linespec_result *canonical, | |
983af33b | 13665 | char *cond_string, |
e7e0cddf | 13666 | char *extra_string, |
983af33b SDJ |
13667 | enum bptype type_wanted, |
13668 | enum bpdisp disposition, | |
13669 | int thread, | |
13670 | int task, int ignore_count, | |
13671 | const struct breakpoint_ops *ops, | |
13672 | int from_tty, int enabled, | |
44f238bb | 13673 | int internal, unsigned flags) |
983af33b SDJ |
13674 | { |
13675 | int i; | |
52d361e1 YQ |
13676 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13677 | canonical->sals, 0); | |
983af33b SDJ |
13678 | |
13679 | /* If the user is creating a static tracepoint by marker id | |
13680 | (strace -m MARKER_ID), then store the sals index, so that | |
13681 | breakpoint_re_set can try to match up which of the newly | |
13682 | found markers corresponds to this one, and, don't try to | |
13683 | expand multiple locations for each sal, given than SALS | |
13684 | already should contain all sals for MARKER_ID. */ | |
13685 | ||
13686 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13687 | { | |
13688 | struct symtabs_and_lines expanded; | |
13689 | struct tracepoint *tp; | |
ffc2605c | 13690 | event_location_up location; |
983af33b SDJ |
13691 | |
13692 | expanded.nelts = 1; | |
13693 | expanded.sals = &lsal->sals.sals[i]; | |
13694 | ||
8e9e35b1 | 13695 | location = copy_event_location (canonical->location.get ()); |
983af33b | 13696 | |
4d01a485 | 13697 | tp = new tracepoint (); |
983af33b | 13698 | init_breakpoint_sal (&tp->base, gdbarch, expanded, |
ffc2605c | 13699 | std::move (location), NULL, |
e7e0cddf SS |
13700 | cond_string, extra_string, |
13701 | type_wanted, disposition, | |
983af33b | 13702 | thread, task, ignore_count, ops, |
44f238bb | 13703 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13704 | canonical->special_display); |
13705 | /* Given that its possible to have multiple markers with | |
13706 | the same string id, if the user is creating a static | |
13707 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13708 | store the sals index, so that breakpoint_re_set can | |
13709 | try to match up which of the newly found markers | |
13710 | corresponds to this one */ | |
13711 | tp->static_trace_marker_id_idx = i; | |
13712 | ||
13713 | install_breakpoint (internal, &tp->base, 0); | |
983af33b SDJ |
13714 | } |
13715 | } | |
13716 | ||
13717 | static void | |
f00aae0f KS |
13718 | strace_marker_decode_location (struct breakpoint *b, |
13719 | const struct event_location *location, | |
c2f4122d | 13720 | struct program_space *search_pspace, |
983af33b SDJ |
13721 | struct symtabs_and_lines *sals) |
13722 | { | |
13723 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13724 | const char *s = get_linespec_location (location); |
983af33b | 13725 | |
f00aae0f | 13726 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13727 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13728 | { | |
13729 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13730 | sals->nelts = 1; | |
13731 | } | |
13732 | else | |
13733 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13734 | } | |
13735 | ||
13736 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13737 | ||
13738 | static int | |
13739 | strace_marker_p (struct breakpoint *b) | |
13740 | { | |
13741 | return b->ops == &strace_marker_breakpoint_ops; | |
13742 | } | |
13743 | ||
53a5351d | 13744 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13745 | structures. */ |
c906108c SS |
13746 | |
13747 | void | |
fba45db2 | 13748 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13749 | { |
52f0bd74 | 13750 | struct breakpoint *b; |
c906108c | 13751 | |
8a3fe4f8 | 13752 | gdb_assert (bpt != NULL); |
c906108c | 13753 | |
4a64f543 MS |
13754 | /* Has this bp already been deleted? This can happen because |
13755 | multiple lists can hold pointers to bp's. bpstat lists are | |
13756 | especial culprits. | |
13757 | ||
13758 | One example of this happening is a watchpoint's scope bp. When | |
13759 | the scope bp triggers, we notice that the watchpoint is out of | |
13760 | scope, and delete it. We also delete its scope bp. But the | |
13761 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13762 | That bpstat is then checked for auto-deleting bp's, which are | |
13763 | deleted. | |
13764 | ||
13765 | A real solution to this problem might involve reference counts in | |
13766 | bp's, and/or giving them pointers back to their referencing | |
13767 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13768 | storage when no more references were extent. A cheaper bandaid | |
13769 | was chosen. */ | |
c906108c SS |
13770 | if (bpt->type == bp_none) |
13771 | return; | |
13772 | ||
4a64f543 MS |
13773 | /* At least avoid this stale reference until the reference counting |
13774 | of breakpoints gets resolved. */ | |
d0fb5eae | 13775 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13776 | { |
d0fb5eae | 13777 | struct breakpoint *related; |
3a5c3e22 | 13778 | struct watchpoint *w; |
d0fb5eae JK |
13779 | |
13780 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13781 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13782 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13783 | w = (struct watchpoint *) bpt; |
13784 | else | |
13785 | w = NULL; | |
13786 | if (w != NULL) | |
13787 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13788 | |
13789 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13790 | for (related = bpt; related->related_breakpoint != bpt; | |
13791 | related = related->related_breakpoint); | |
13792 | related->related_breakpoint = bpt->related_breakpoint; | |
13793 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13794 | } |
13795 | ||
a9634178 TJB |
13796 | /* watch_command_1 creates a watchpoint but only sets its number if |
13797 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13798 | a problem in that process, we'll be asked to delete the half-created | |
13799 | watchpoint. In that case, don't announce the deletion. */ | |
13800 | if (bpt->number) | |
13801 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13802 | |
c906108c SS |
13803 | if (breakpoint_chain == bpt) |
13804 | breakpoint_chain = bpt->next; | |
13805 | ||
c906108c SS |
13806 | ALL_BREAKPOINTS (b) |
13807 | if (b->next == bpt) | |
c5aa993b JM |
13808 | { |
13809 | b->next = bpt->next; | |
13810 | break; | |
13811 | } | |
c906108c | 13812 | |
f431efe5 PA |
13813 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13814 | been freed. */ | |
13815 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13816 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13817 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13818 | commands are associated with the bpstat; if we remove it here, | |
13819 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13820 | event-top.c won't do anything, and temporary breakpoints with | |
13821 | commands won't work. */ | |
13822 | ||
13823 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13824 | ||
4a64f543 MS |
13825 | /* Now that breakpoint is removed from breakpoint list, update the |
13826 | global location list. This will remove locations that used to | |
13827 | belong to this breakpoint. Do this before freeing the breakpoint | |
13828 | itself, since remove_breakpoint looks at location's owner. It | |
13829 | might be better design to have location completely | |
13830 | self-contained, but it's not the case now. */ | |
44702360 | 13831 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13832 | |
348d480f | 13833 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13834 | /* On the chance that someone will soon try again to delete this |
13835 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13836 | bpt->type = bp_none; |
4d01a485 | 13837 | delete bpt; |
c906108c SS |
13838 | } |
13839 | ||
4d6140d9 AC |
13840 | static void |
13841 | do_delete_breakpoint_cleanup (void *b) | |
13842 | { | |
9a3c8263 | 13843 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13844 | } |
13845 | ||
13846 | struct cleanup * | |
13847 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13848 | { | |
13849 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13850 | } | |
13851 | ||
51be5b68 PA |
13852 | /* Iterator function to call a user-provided callback function once |
13853 | for each of B and its related breakpoints. */ | |
13854 | ||
13855 | static void | |
13856 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13857 | void (*function) (struct breakpoint *, | |
13858 | void *), | |
13859 | void *data) | |
13860 | { | |
13861 | struct breakpoint *related; | |
13862 | ||
13863 | related = b; | |
13864 | do | |
13865 | { | |
13866 | struct breakpoint *next; | |
13867 | ||
13868 | /* FUNCTION may delete RELATED. */ | |
13869 | next = related->related_breakpoint; | |
13870 | ||
13871 | if (next == related) | |
13872 | { | |
13873 | /* RELATED is the last ring entry. */ | |
13874 | function (related, data); | |
13875 | ||
13876 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13877 | B. There's nothing left to do anyway, so just break | |
13878 | out. */ | |
13879 | break; | |
13880 | } | |
13881 | else | |
13882 | function (related, data); | |
13883 | ||
13884 | related = next; | |
13885 | } | |
13886 | while (related != b); | |
13887 | } | |
95a42b64 TT |
13888 | |
13889 | static void | |
13890 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13891 | { | |
13892 | delete_breakpoint (b); | |
13893 | } | |
13894 | ||
51be5b68 PA |
13895 | /* A callback for map_breakpoint_numbers that calls |
13896 | delete_breakpoint. */ | |
13897 | ||
13898 | static void | |
13899 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13900 | { | |
13901 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13902 | } | |
13903 | ||
c906108c | 13904 | void |
fba45db2 | 13905 | delete_command (char *arg, int from_tty) |
c906108c | 13906 | { |
35df4500 | 13907 | struct breakpoint *b, *b_tmp; |
c906108c | 13908 | |
ea9365bb TT |
13909 | dont_repeat (); |
13910 | ||
c906108c SS |
13911 | if (arg == 0) |
13912 | { | |
13913 | int breaks_to_delete = 0; | |
13914 | ||
46c6471b PA |
13915 | /* Delete all breakpoints if no argument. Do not delete |
13916 | internal breakpoints, these have to be deleted with an | |
13917 | explicit breakpoint number argument. */ | |
c5aa993b | 13918 | ALL_BREAKPOINTS (b) |
46c6471b | 13919 | if (user_breakpoint_p (b)) |
973d738b DJ |
13920 | { |
13921 | breaks_to_delete = 1; | |
13922 | break; | |
13923 | } | |
c906108c SS |
13924 | |
13925 | /* Ask user only if there are some breakpoints to delete. */ | |
13926 | if (!from_tty | |
e2e0b3e5 | 13927 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13928 | { |
35df4500 | 13929 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13930 | if (user_breakpoint_p (b)) |
c5aa993b | 13931 | delete_breakpoint (b); |
c906108c SS |
13932 | } |
13933 | } | |
13934 | else | |
51be5b68 | 13935 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13936 | } |
13937 | ||
c2f4122d PA |
13938 | /* Return true if all locations of B bound to PSPACE are pending. If |
13939 | PSPACE is NULL, all locations of all program spaces are | |
13940 | considered. */ | |
13941 | ||
0d381245 | 13942 | static int |
c2f4122d | 13943 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13944 | { |
c2f4122d PA |
13945 | struct bp_location *loc; |
13946 | ||
13947 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13948 | if ((pspace == NULL | |
13949 | || loc->pspace == pspace) | |
13950 | && !loc->shlib_disabled | |
8645ff69 | 13951 | && !loc->pspace->executing_startup) |
0d381245 VP |
13952 | return 0; |
13953 | return 1; | |
fe3f5fa8 VP |
13954 | } |
13955 | ||
776592bf DE |
13956 | /* Subroutine of update_breakpoint_locations to simplify it. |
13957 | Return non-zero if multiple fns in list LOC have the same name. | |
13958 | Null names are ignored. */ | |
13959 | ||
13960 | static int | |
13961 | ambiguous_names_p (struct bp_location *loc) | |
13962 | { | |
13963 | struct bp_location *l; | |
13964 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13965 | (int (*) (const void *, |
13966 | const void *)) streq, | |
776592bf DE |
13967 | NULL, xcalloc, xfree); |
13968 | ||
13969 | for (l = loc; l != NULL; l = l->next) | |
13970 | { | |
13971 | const char **slot; | |
13972 | const char *name = l->function_name; | |
13973 | ||
13974 | /* Allow for some names to be NULL, ignore them. */ | |
13975 | if (name == NULL) | |
13976 | continue; | |
13977 | ||
13978 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13979 | INSERT); | |
4a64f543 MS |
13980 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13981 | returns NULL. */ | |
776592bf DE |
13982 | if (*slot != NULL) |
13983 | { | |
13984 | htab_delete (htab); | |
13985 | return 1; | |
13986 | } | |
13987 | *slot = name; | |
13988 | } | |
13989 | ||
13990 | htab_delete (htab); | |
13991 | return 0; | |
13992 | } | |
13993 | ||
0fb4aa4b PA |
13994 | /* When symbols change, it probably means the sources changed as well, |
13995 | and it might mean the static tracepoint markers are no longer at | |
13996 | the same address or line numbers they used to be at last we | |
13997 | checked. Losing your static tracepoints whenever you rebuild is | |
13998 | undesirable. This function tries to resync/rematch gdb static | |
13999 | tracepoints with the markers on the target, for static tracepoints | |
14000 | that have not been set by marker id. Static tracepoint that have | |
14001 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14002 | The heuristic is: | |
14003 | ||
14004 | 1) For a tracepoint set at a specific address, look for a marker at | |
14005 | the old PC. If one is found there, assume to be the same marker. | |
14006 | If the name / string id of the marker found is different from the | |
14007 | previous known name, assume that means the user renamed the marker | |
14008 | in the sources, and output a warning. | |
14009 | ||
14010 | 2) For a tracepoint set at a given line number, look for a marker | |
14011 | at the new address of the old line number. If one is found there, | |
14012 | assume to be the same marker. If the name / string id of the | |
14013 | marker found is different from the previous known name, assume that | |
14014 | means the user renamed the marker in the sources, and output a | |
14015 | warning. | |
14016 | ||
14017 | 3) If a marker is no longer found at the same address or line, it | |
14018 | may mean the marker no longer exists. But it may also just mean | |
14019 | the code changed a bit. Maybe the user added a few lines of code | |
14020 | that made the marker move up or down (in line number terms). Ask | |
14021 | the target for info about the marker with the string id as we knew | |
14022 | it. If found, update line number and address in the matching | |
14023 | static tracepoint. This will get confused if there's more than one | |
14024 | marker with the same ID (possible in UST, although unadvised | |
14025 | precisely because it confuses tools). */ | |
14026 | ||
14027 | static struct symtab_and_line | |
14028 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14029 | { | |
d9b3f62e | 14030 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14031 | struct static_tracepoint_marker marker; |
14032 | CORE_ADDR pc; | |
0fb4aa4b PA |
14033 | |
14034 | pc = sal.pc; | |
14035 | if (sal.line) | |
14036 | find_line_pc (sal.symtab, sal.line, &pc); | |
14037 | ||
14038 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14039 | { | |
d9b3f62e | 14040 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14041 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14042 | b->number, | |
d9b3f62e | 14043 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14044 | |
d9b3f62e PA |
14045 | xfree (tp->static_trace_marker_id); |
14046 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14047 | release_static_tracepoint_marker (&marker); |
14048 | ||
14049 | return sal; | |
14050 | } | |
14051 | ||
14052 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14053 | by string ID. */ | |
14054 | if (!sal.explicit_pc | |
14055 | && sal.line != 0 | |
14056 | && sal.symtab != NULL | |
d9b3f62e | 14057 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14058 | { |
14059 | VEC(static_tracepoint_marker_p) *markers; | |
14060 | ||
14061 | markers | |
d9b3f62e | 14062 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14063 | |
14064 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14065 | { | |
80e1d417 | 14066 | struct symtab_and_line sal2; |
0fb4aa4b | 14067 | struct symbol *sym; |
80e1d417 | 14068 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14069 | struct ui_out *uiout = current_uiout; |
67994074 | 14070 | struct explicit_location explicit_loc; |
0fb4aa4b | 14071 | |
80e1d417 | 14072 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14073 | |
d9b3f62e | 14074 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14075 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14076 | |
14077 | warning (_("marker for static tracepoint %d (%s) not " | |
14078 | "found at previous line number"), | |
d9b3f62e | 14079 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14080 | |
80e1d417 | 14081 | init_sal (&sal2); |
0fb4aa4b | 14082 | |
80e1d417 | 14083 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14084 | |
80e1d417 AS |
14085 | sal2 = find_pc_line (tpmarker->address, 0); |
14086 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
112e8700 | 14087 | uiout->text ("Now in "); |
0fb4aa4b PA |
14088 | if (sym) |
14089 | { | |
112e8700 SM |
14090 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); |
14091 | uiout->text (" at "); | |
0fb4aa4b | 14092 | } |
112e8700 | 14093 | uiout->field_string ("file", |
05cba821 | 14094 | symtab_to_filename_for_display (sal2.symtab)); |
112e8700 | 14095 | uiout->text (":"); |
0fb4aa4b | 14096 | |
112e8700 | 14097 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 14098 | { |
0b0865da | 14099 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14100 | |
112e8700 | 14101 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
14102 | } |
14103 | ||
112e8700 SM |
14104 | uiout->field_int ("line", sal2.line); |
14105 | uiout->text ("\n"); | |
0fb4aa4b | 14106 | |
80e1d417 | 14107 | b->loc->line_number = sal2.line; |
2f202fde | 14108 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14109 | |
d28cd78a | 14110 | b->location.reset (NULL); |
67994074 KS |
14111 | initialize_explicit_location (&explicit_loc); |
14112 | explicit_loc.source_filename | |
00e52e53 | 14113 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14114 | explicit_loc.line_offset.offset = b->loc->line_number; |
14115 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 14116 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
14117 | |
14118 | /* Might be nice to check if function changed, and warn if | |
14119 | so. */ | |
14120 | ||
80e1d417 | 14121 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14122 | } |
14123 | } | |
14124 | return sal; | |
14125 | } | |
14126 | ||
8d3788bd VP |
14127 | /* Returns 1 iff locations A and B are sufficiently same that |
14128 | we don't need to report breakpoint as changed. */ | |
14129 | ||
14130 | static int | |
14131 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14132 | { | |
14133 | while (a && b) | |
14134 | { | |
14135 | if (a->address != b->address) | |
14136 | return 0; | |
14137 | ||
14138 | if (a->shlib_disabled != b->shlib_disabled) | |
14139 | return 0; | |
14140 | ||
14141 | if (a->enabled != b->enabled) | |
14142 | return 0; | |
14143 | ||
14144 | a = a->next; | |
14145 | b = b->next; | |
14146 | } | |
14147 | ||
14148 | if ((a == NULL) != (b == NULL)) | |
14149 | return 0; | |
14150 | ||
14151 | return 1; | |
14152 | } | |
14153 | ||
c2f4122d PA |
14154 | /* Split all locations of B that are bound to PSPACE out of B's |
14155 | location list to a separate list and return that list's head. If | |
14156 | PSPACE is NULL, hoist out all locations of B. */ | |
14157 | ||
14158 | static struct bp_location * | |
14159 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14160 | { | |
14161 | struct bp_location head; | |
14162 | struct bp_location *i = b->loc; | |
14163 | struct bp_location **i_link = &b->loc; | |
14164 | struct bp_location *hoisted = &head; | |
14165 | ||
14166 | if (pspace == NULL) | |
14167 | { | |
14168 | i = b->loc; | |
14169 | b->loc = NULL; | |
14170 | return i; | |
14171 | } | |
14172 | ||
14173 | head.next = NULL; | |
14174 | ||
14175 | while (i != NULL) | |
14176 | { | |
14177 | if (i->pspace == pspace) | |
14178 | { | |
14179 | *i_link = i->next; | |
14180 | i->next = NULL; | |
14181 | hoisted->next = i; | |
14182 | hoisted = i; | |
14183 | } | |
14184 | else | |
14185 | i_link = &i->next; | |
14186 | i = *i_link; | |
14187 | } | |
14188 | ||
14189 | return head.next; | |
14190 | } | |
14191 | ||
14192 | /* Create new breakpoint locations for B (a hardware or software | |
14193 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14194 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14195 | FILTER_PSPACE. Locations of other program spaces are left | |
14196 | untouched. */ | |
f1310107 | 14197 | |
0e30163f | 14198 | void |
0d381245 | 14199 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14200 | struct program_space *filter_pspace, |
f1310107 TJB |
14201 | struct symtabs_and_lines sals, |
14202 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14203 | { |
14204 | int i; | |
c2f4122d | 14205 | struct bp_location *existing_locations; |
0d381245 | 14206 | |
f8eba3c6 TT |
14207 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14208 | { | |
14209 | /* Ranged breakpoints have only one start location and one end | |
14210 | location. */ | |
14211 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14212 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14213 | "multiple locations found\n"), | |
14214 | b->number); | |
14215 | return; | |
14216 | } | |
f1310107 | 14217 | |
4a64f543 MS |
14218 | /* If there's no new locations, and all existing locations are |
14219 | pending, don't do anything. This optimizes the common case where | |
14220 | all locations are in the same shared library, that was unloaded. | |
14221 | We'd like to retain the location, so that when the library is | |
14222 | loaded again, we don't loose the enabled/disabled status of the | |
14223 | individual locations. */ | |
c2f4122d | 14224 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14225 | return; |
14226 | ||
c2f4122d | 14227 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14228 | |
0d381245 | 14229 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14230 | { |
f8eba3c6 TT |
14231 | struct bp_location *new_loc; |
14232 | ||
14233 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14234 | ||
14235 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14236 | |
0d381245 VP |
14237 | /* Reparse conditions, they might contain references to the |
14238 | old symtab. */ | |
14239 | if (b->cond_string != NULL) | |
14240 | { | |
bbc13ae3 | 14241 | const char *s; |
fe3f5fa8 | 14242 | |
0d381245 | 14243 | s = b->cond_string; |
492d29ea | 14244 | TRY |
0d381245 | 14245 | { |
1bb9788d TT |
14246 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14247 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14248 | 0); |
14249 | } | |
492d29ea | 14250 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14251 | { |
3e43a32a MS |
14252 | warning (_("failed to reevaluate condition " |
14253 | "for breakpoint %d: %s"), | |
0d381245 VP |
14254 | b->number, e.message); |
14255 | new_loc->enabled = 0; | |
14256 | } | |
492d29ea | 14257 | END_CATCH |
0d381245 | 14258 | } |
fe3f5fa8 | 14259 | |
f1310107 TJB |
14260 | if (sals_end.nelts) |
14261 | { | |
14262 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14263 | ||
14264 | new_loc->length = end - sals.sals[0].pc + 1; | |
14265 | } | |
0d381245 | 14266 | } |
fe3f5fa8 | 14267 | |
4a64f543 MS |
14268 | /* If possible, carry over 'disable' status from existing |
14269 | breakpoints. */ | |
0d381245 VP |
14270 | { |
14271 | struct bp_location *e = existing_locations; | |
776592bf DE |
14272 | /* If there are multiple breakpoints with the same function name, |
14273 | e.g. for inline functions, comparing function names won't work. | |
14274 | Instead compare pc addresses; this is just a heuristic as things | |
14275 | may have moved, but in practice it gives the correct answer | |
14276 | often enough until a better solution is found. */ | |
14277 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14278 | ||
0d381245 VP |
14279 | for (; e; e = e->next) |
14280 | { | |
14281 | if (!e->enabled && e->function_name) | |
14282 | { | |
14283 | struct bp_location *l = b->loc; | |
776592bf DE |
14284 | if (have_ambiguous_names) |
14285 | { | |
14286 | for (; l; l = l->next) | |
f1310107 | 14287 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14288 | { |
14289 | l->enabled = 0; | |
14290 | break; | |
14291 | } | |
14292 | } | |
14293 | else | |
14294 | { | |
14295 | for (; l; l = l->next) | |
14296 | if (l->function_name | |
14297 | && strcmp (e->function_name, l->function_name) == 0) | |
14298 | { | |
14299 | l->enabled = 0; | |
14300 | break; | |
14301 | } | |
14302 | } | |
0d381245 VP |
14303 | } |
14304 | } | |
14305 | } | |
fe3f5fa8 | 14306 | |
8d3788bd VP |
14307 | if (!locations_are_equal (existing_locations, b->loc)) |
14308 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14309 | } |
14310 | ||
f00aae0f | 14311 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14312 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14313 | ||
14314 | static struct symtabs_and_lines | |
f00aae0f | 14315 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14316 | struct program_space *search_pspace, int *found) |
ef23e705 | 14317 | { |
02d20e4a | 14318 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14319 | struct gdb_exception exception = exception_none; |
ef23e705 | 14320 | |
983af33b | 14321 | gdb_assert (b->ops != NULL); |
ef23e705 | 14322 | |
492d29ea | 14323 | TRY |
ef23e705 | 14324 | { |
c2f4122d | 14325 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14326 | } |
492d29ea | 14327 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14328 | { |
14329 | int not_found_and_ok = 0; | |
492d29ea PA |
14330 | |
14331 | exception = e; | |
14332 | ||
ef23e705 TJB |
14333 | /* For pending breakpoints, it's expected that parsing will |
14334 | fail until the right shared library is loaded. User has | |
14335 | already told to create pending breakpoints and don't need | |
14336 | extra messages. If breakpoint is in bp_shlib_disabled | |
14337 | state, then user already saw the message about that | |
14338 | breakpoint being disabled, and don't want to see more | |
14339 | errors. */ | |
58438ac1 | 14340 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14341 | && (b->condition_not_parsed |
14342 | || (b->loc != NULL | |
14343 | && search_pspace != NULL | |
14344 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14345 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14346 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14347 | || b->enable_state == bp_disabled)) |
14348 | not_found_and_ok = 1; | |
14349 | ||
14350 | if (!not_found_and_ok) | |
14351 | { | |
14352 | /* We surely don't want to warn about the same breakpoint | |
14353 | 10 times. One solution, implemented here, is disable | |
14354 | the breakpoint on error. Another solution would be to | |
14355 | have separate 'warning emitted' flag. Since this | |
14356 | happens only when a binary has changed, I don't know | |
14357 | which approach is better. */ | |
14358 | b->enable_state = bp_disabled; | |
14359 | throw_exception (e); | |
14360 | } | |
14361 | } | |
492d29ea | 14362 | END_CATCH |
ef23e705 | 14363 | |
492d29ea | 14364 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14365 | { |
f8eba3c6 | 14366 | int i; |
ef23e705 | 14367 | |
f8eba3c6 TT |
14368 | for (i = 0; i < sals.nelts; ++i) |
14369 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14370 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14371 | { |
ed1d1739 KS |
14372 | char *cond_string, *extra_string; |
14373 | int thread, task; | |
ef23e705 | 14374 | |
f00aae0f | 14375 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14376 | &cond_string, &thread, &task, |
14377 | &extra_string); | |
f00aae0f | 14378 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14379 | if (cond_string) |
14380 | b->cond_string = cond_string; | |
14381 | b->thread = thread; | |
14382 | b->task = task; | |
e7e0cddf | 14383 | if (extra_string) |
f00aae0f KS |
14384 | { |
14385 | xfree (b->extra_string); | |
14386 | b->extra_string = extra_string; | |
14387 | } | |
ef23e705 TJB |
14388 | b->condition_not_parsed = 0; |
14389 | } | |
14390 | ||
983af33b | 14391 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14392 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14393 | |
58438ac1 TT |
14394 | *found = 1; |
14395 | } | |
14396 | else | |
14397 | *found = 0; | |
ef23e705 TJB |
14398 | |
14399 | return sals; | |
14400 | } | |
14401 | ||
348d480f PA |
14402 | /* The default re_set method, for typical hardware or software |
14403 | breakpoints. Reevaluate the breakpoint and recreate its | |
14404 | locations. */ | |
14405 | ||
14406 | static void | |
28010a5d | 14407 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14408 | { |
14409 | int found; | |
f1310107 | 14410 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14411 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14412 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14413 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14414 | |
d28cd78a | 14415 | sals = location_to_sals (b, b->location.get (), filter_pspace, &found); |
ef23e705 TJB |
14416 | if (found) |
14417 | { | |
14418 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14419 | expanded = sals; |
ef23e705 TJB |
14420 | } |
14421 | ||
f00aae0f | 14422 | if (b->location_range_end != NULL) |
f1310107 | 14423 | { |
d28cd78a | 14424 | sals_end = location_to_sals (b, b->location_range_end.get (), |
c2f4122d | 14425 | filter_pspace, &found); |
f1310107 TJB |
14426 | if (found) |
14427 | { | |
14428 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14429 | expanded_end = sals_end; |
f1310107 TJB |
14430 | } |
14431 | } | |
14432 | ||
c2f4122d | 14433 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14434 | } |
14435 | ||
983af33b SDJ |
14436 | /* Default method for creating SALs from an address string. It basically |
14437 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14438 | ||
14439 | static void | |
f00aae0f KS |
14440 | create_sals_from_location_default (const struct event_location *location, |
14441 | struct linespec_result *canonical, | |
14442 | enum bptype type_wanted) | |
983af33b | 14443 | { |
f00aae0f | 14444 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14445 | } |
14446 | ||
14447 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14448 | function for the `create_breakpoints_sal' method of | |
14449 | breakpoint_ops. */ | |
14450 | ||
14451 | static void | |
14452 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14453 | struct linespec_result *canonical, | |
983af33b | 14454 | char *cond_string, |
e7e0cddf | 14455 | char *extra_string, |
983af33b SDJ |
14456 | enum bptype type_wanted, |
14457 | enum bpdisp disposition, | |
14458 | int thread, | |
14459 | int task, int ignore_count, | |
14460 | const struct breakpoint_ops *ops, | |
14461 | int from_tty, int enabled, | |
44f238bb | 14462 | int internal, unsigned flags) |
983af33b SDJ |
14463 | { |
14464 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14465 | extra_string, |
983af33b SDJ |
14466 | type_wanted, disposition, |
14467 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14468 | enabled, internal, flags); |
983af33b SDJ |
14469 | } |
14470 | ||
14471 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14472 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14473 | |
14474 | static void | |
f00aae0f KS |
14475 | decode_location_default (struct breakpoint *b, |
14476 | const struct event_location *location, | |
c2f4122d | 14477 | struct program_space *search_pspace, |
983af33b SDJ |
14478 | struct symtabs_and_lines *sals) |
14479 | { | |
14480 | struct linespec_result canonical; | |
14481 | ||
c2f4122d | 14482 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14483 | (struct symtab *) NULL, 0, |
14484 | &canonical, multiple_symbols_all, | |
14485 | b->filter); | |
14486 | ||
14487 | /* We should get 0 or 1 resulting SALs. */ | |
14488 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14489 | ||
14490 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14491 | { | |
14492 | struct linespec_sals *lsal; | |
14493 | ||
14494 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14495 | *sals = lsal->sals; | |
14496 | /* Arrange it so the destructor does not free the | |
14497 | contents. */ | |
14498 | lsal->sals.sals = NULL; | |
14499 | } | |
983af33b SDJ |
14500 | } |
14501 | ||
28010a5d PA |
14502 | /* Prepare the global context for a re-set of breakpoint B. */ |
14503 | ||
14504 | static struct cleanup * | |
14505 | prepare_re_set_context (struct breakpoint *b) | |
14506 | { | |
28010a5d | 14507 | input_radix = b->input_radix; |
28010a5d PA |
14508 | set_language (b->language); |
14509 | ||
c2f4122d | 14510 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14511 | } |
14512 | ||
c906108c SS |
14513 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14514 | The value we return ends up being the return value from catch_errors. | |
14515 | Unused in this case. */ | |
14516 | ||
14517 | static int | |
4efb68b1 | 14518 | breakpoint_re_set_one (void *bint) |
c906108c | 14519 | { |
4a64f543 | 14520 | /* Get past catch_errs. */ |
53a5351d | 14521 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14522 | struct cleanup *cleanups; |
c906108c | 14523 | |
348d480f PA |
14524 | cleanups = prepare_re_set_context (b); |
14525 | b->ops->re_set (b); | |
14526 | do_cleanups (cleanups); | |
c906108c SS |
14527 | return 0; |
14528 | } | |
14529 | ||
c2f4122d PA |
14530 | /* Re-set breakpoint locations for the current program space. |
14531 | Locations bound to other program spaces are left untouched. */ | |
14532 | ||
c906108c | 14533 | void |
69de3c6a | 14534 | breakpoint_re_set (void) |
c906108c | 14535 | { |
35df4500 | 14536 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14537 | enum language save_language; |
14538 | int save_input_radix; | |
6c95b8df | 14539 | struct cleanup *old_chain; |
c5aa993b | 14540 | |
c906108c SS |
14541 | save_language = current_language->la_language; |
14542 | save_input_radix = input_radix; | |
c2f4122d | 14543 | old_chain = save_current_space_and_thread (); |
6c95b8df | 14544 | |
2a7f3dff PA |
14545 | /* Note: we must not try to insert locations until after all |
14546 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14547 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14548 | hadn't been re-set yet, and thus may have stale locations. */ | |
14549 | ||
35df4500 | 14550 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14551 | { |
4a64f543 | 14552 | /* Format possible error msg. */ |
fe3f5fa8 | 14553 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14554 | b->number); |
14555 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14556 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14557 | do_cleanups (cleanups); |
c5aa993b | 14558 | } |
c906108c SS |
14559 | set_language (save_language); |
14560 | input_radix = save_input_radix; | |
e62c965a | 14561 | |
0756c555 | 14562 | jit_breakpoint_re_set (); |
4efc6507 | 14563 | |
6c95b8df PA |
14564 | do_cleanups (old_chain); |
14565 | ||
af02033e PP |
14566 | create_overlay_event_breakpoint (); |
14567 | create_longjmp_master_breakpoint (); | |
14568 | create_std_terminate_master_breakpoint (); | |
186c406b | 14569 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14570 | |
14571 | /* Now we can insert. */ | |
14572 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14573 | } |
14574 | \f | |
c906108c SS |
14575 | /* Reset the thread number of this breakpoint: |
14576 | ||
14577 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14578 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14579 | void |
fba45db2 | 14580 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14581 | { |
14582 | if (b->thread != -1) | |
14583 | { | |
39f77062 | 14584 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14585 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14586 | |
14587 | /* We're being called after following a fork. The new fork is | |
14588 | selected as current, and unless this was a vfork will have a | |
14589 | different program space from the original thread. Reset that | |
14590 | as well. */ | |
14591 | b->loc->pspace = current_program_space; | |
c906108c SS |
14592 | } |
14593 | } | |
14594 | ||
03ac34d5 MS |
14595 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14596 | If from_tty is nonzero, it prints a message to that effect, | |
14597 | which ends with a period (no newline). */ | |
14598 | ||
c906108c | 14599 | void |
fba45db2 | 14600 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14601 | { |
52f0bd74 | 14602 | struct breakpoint *b; |
c906108c SS |
14603 | |
14604 | if (count < 0) | |
14605 | count = 0; | |
14606 | ||
14607 | ALL_BREAKPOINTS (b) | |
14608 | if (b->number == bptnum) | |
c5aa993b | 14609 | { |
d77f58be SS |
14610 | if (is_tracepoint (b)) |
14611 | { | |
14612 | if (from_tty && count != 0) | |
14613 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14614 | bptnum); | |
14615 | return; | |
14616 | } | |
14617 | ||
c5aa993b | 14618 | b->ignore_count = count; |
221ea385 KS |
14619 | if (from_tty) |
14620 | { | |
14621 | if (count == 0) | |
3e43a32a MS |
14622 | printf_filtered (_("Will stop next time " |
14623 | "breakpoint %d is reached."), | |
221ea385 KS |
14624 | bptnum); |
14625 | else if (count == 1) | |
a3f17187 | 14626 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14627 | bptnum); |
14628 | else | |
3e43a32a MS |
14629 | printf_filtered (_("Will ignore next %d " |
14630 | "crossings of breakpoint %d."), | |
221ea385 KS |
14631 | count, bptnum); |
14632 | } | |
8d3788bd | 14633 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14634 | return; |
14635 | } | |
c906108c | 14636 | |
8a3fe4f8 | 14637 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14638 | } |
14639 | ||
c906108c SS |
14640 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14641 | ||
14642 | static void | |
fba45db2 | 14643 | ignore_command (char *args, int from_tty) |
c906108c SS |
14644 | { |
14645 | char *p = args; | |
52f0bd74 | 14646 | int num; |
c906108c SS |
14647 | |
14648 | if (p == 0) | |
e2e0b3e5 | 14649 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14650 | |
c906108c | 14651 | num = get_number (&p); |
5c44784c | 14652 | if (num == 0) |
8a3fe4f8 | 14653 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14654 | if (*p == 0) |
8a3fe4f8 | 14655 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14656 | |
14657 | set_ignore_count (num, | |
14658 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14659 | from_tty); | |
221ea385 KS |
14660 | if (from_tty) |
14661 | printf_filtered ("\n"); | |
c906108c SS |
14662 | } |
14663 | \f | |
14664 | /* Call FUNCTION on each of the breakpoints | |
14665 | whose numbers are given in ARGS. */ | |
14666 | ||
14667 | static void | |
896b6bda PA |
14668 | map_breakpoint_numbers (const char *args, |
14669 | void (*function) (struct breakpoint *, | |
14670 | void *), | |
95a42b64 | 14671 | void *data) |
c906108c | 14672 | { |
52f0bd74 AC |
14673 | int num; |
14674 | struct breakpoint *b, *tmp; | |
c906108c | 14675 | |
b9d61307 | 14676 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14677 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14678 | |
bfd28288 | 14679 | number_or_range_parser parser (args); |
197f0a60 | 14680 | |
bfd28288 | 14681 | while (!parser.finished ()) |
c906108c | 14682 | { |
bfd28288 PA |
14683 | const char *p = parser.cur_tok (); |
14684 | bool match = false; | |
197f0a60 | 14685 | |
bfd28288 | 14686 | num = parser.get_number (); |
5c44784c | 14687 | if (num == 0) |
c5aa993b | 14688 | { |
8a3fe4f8 | 14689 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14690 | } |
14691 | else | |
14692 | { | |
14693 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14694 | if (b->number == num) | |
14695 | { | |
bfd28288 | 14696 | match = true; |
cdac0397 | 14697 | function (b, data); |
11cf8741 | 14698 | break; |
5c44784c | 14699 | } |
bfd28288 | 14700 | if (!match) |
a3f17187 | 14701 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14702 | } |
c906108c SS |
14703 | } |
14704 | } | |
14705 | ||
0d381245 VP |
14706 | static struct bp_location * |
14707 | find_location_by_number (char *number) | |
14708 | { | |
14709 | char *dot = strchr (number, '.'); | |
14710 | char *p1; | |
14711 | int bp_num; | |
14712 | int loc_num; | |
14713 | struct breakpoint *b; | |
14714 | struct bp_location *loc; | |
14715 | ||
14716 | *dot = '\0'; | |
14717 | ||
14718 | p1 = number; | |
197f0a60 | 14719 | bp_num = get_number (&p1); |
0d381245 VP |
14720 | if (bp_num == 0) |
14721 | error (_("Bad breakpoint number '%s'"), number); | |
14722 | ||
14723 | ALL_BREAKPOINTS (b) | |
14724 | if (b->number == bp_num) | |
14725 | { | |
14726 | break; | |
14727 | } | |
14728 | ||
14729 | if (!b || b->number != bp_num) | |
14730 | error (_("Bad breakpoint number '%s'"), number); | |
14731 | ||
14732 | p1 = dot+1; | |
197f0a60 | 14733 | loc_num = get_number (&p1); |
0d381245 VP |
14734 | if (loc_num == 0) |
14735 | error (_("Bad breakpoint location number '%s'"), number); | |
14736 | ||
14737 | --loc_num; | |
14738 | loc = b->loc; | |
14739 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14740 | ; | |
14741 | if (!loc) | |
14742 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14743 | ||
14744 | return loc; | |
14745 | } | |
14746 | ||
14747 | ||
1900040c MS |
14748 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14749 | If from_tty is nonzero, it prints a message to that effect, | |
14750 | which ends with a period (no newline). */ | |
14751 | ||
c906108c | 14752 | void |
fba45db2 | 14753 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14754 | { |
14755 | /* Never disable a watchpoint scope breakpoint; we want to | |
14756 | hit them when we leave scope so we can delete both the | |
14757 | watchpoint and its scope breakpoint at that time. */ | |
14758 | if (bpt->type == bp_watchpoint_scope) | |
14759 | return; | |
14760 | ||
b5de0fa7 | 14761 | bpt->enable_state = bp_disabled; |
c906108c | 14762 | |
b775012e LM |
14763 | /* Mark breakpoint locations modified. */ |
14764 | mark_breakpoint_modified (bpt); | |
14765 | ||
d248b706 KY |
14766 | if (target_supports_enable_disable_tracepoint () |
14767 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14768 | { | |
14769 | struct bp_location *location; | |
14770 | ||
14771 | for (location = bpt->loc; location; location = location->next) | |
14772 | target_disable_tracepoint (location); | |
14773 | } | |
14774 | ||
44702360 | 14775 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14776 | |
8d3788bd | 14777 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14778 | } |
14779 | ||
51be5b68 PA |
14780 | /* A callback for iterate_over_related_breakpoints. */ |
14781 | ||
14782 | static void | |
14783 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14784 | { | |
14785 | disable_breakpoint (b); | |
14786 | } | |
14787 | ||
95a42b64 TT |
14788 | /* A callback for map_breakpoint_numbers that calls |
14789 | disable_breakpoint. */ | |
14790 | ||
14791 | static void | |
14792 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14793 | { | |
51be5b68 | 14794 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14795 | } |
14796 | ||
c906108c | 14797 | static void |
fba45db2 | 14798 | disable_command (char *args, int from_tty) |
c906108c | 14799 | { |
c906108c | 14800 | if (args == 0) |
46c6471b PA |
14801 | { |
14802 | struct breakpoint *bpt; | |
14803 | ||
14804 | ALL_BREAKPOINTS (bpt) | |
14805 | if (user_breakpoint_p (bpt)) | |
14806 | disable_breakpoint (bpt); | |
14807 | } | |
9eaabc75 | 14808 | else |
0d381245 | 14809 | { |
9eaabc75 MW |
14810 | char *num = extract_arg (&args); |
14811 | ||
14812 | while (num) | |
d248b706 | 14813 | { |
9eaabc75 | 14814 | if (strchr (num, '.')) |
b775012e | 14815 | { |
9eaabc75 MW |
14816 | struct bp_location *loc = find_location_by_number (num); |
14817 | ||
14818 | if (loc) | |
14819 | { | |
14820 | if (loc->enabled) | |
14821 | { | |
14822 | loc->enabled = 0; | |
14823 | mark_breakpoint_location_modified (loc); | |
14824 | } | |
14825 | if (target_supports_enable_disable_tracepoint () | |
14826 | && current_trace_status ()->running && loc->owner | |
14827 | && is_tracepoint (loc->owner)) | |
14828 | target_disable_tracepoint (loc); | |
14829 | } | |
44702360 | 14830 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14831 | } |
9eaabc75 MW |
14832 | else |
14833 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14834 | num = extract_arg (&args); | |
d248b706 | 14835 | } |
0d381245 | 14836 | } |
c906108c SS |
14837 | } |
14838 | ||
14839 | static void | |
816338b5 SS |
14840 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14841 | int count) | |
c906108c | 14842 | { |
afe38095 | 14843 | int target_resources_ok; |
c906108c SS |
14844 | |
14845 | if (bpt->type == bp_hardware_breakpoint) | |
14846 | { | |
14847 | int i; | |
c5aa993b | 14848 | i = hw_breakpoint_used_count (); |
53a5351d | 14849 | target_resources_ok = |
d92524f1 | 14850 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14851 | i + 1, 0); |
c906108c | 14852 | if (target_resources_ok == 0) |
8a3fe4f8 | 14853 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14854 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14855 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14856 | } |
14857 | ||
cc60f2e3 | 14858 | if (is_watchpoint (bpt)) |
c906108c | 14859 | { |
d07205c2 | 14860 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14861 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14862 | |
492d29ea | 14863 | TRY |
c906108c | 14864 | { |
3a5c3e22 PA |
14865 | struct watchpoint *w = (struct watchpoint *) bpt; |
14866 | ||
1e718ff1 TJB |
14867 | orig_enable_state = bpt->enable_state; |
14868 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14869 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14870 | } |
492d29ea | 14871 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14872 | { |
1e718ff1 | 14873 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14874 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14875 | bpt->number); | |
14876 | return; | |
c5aa993b | 14877 | } |
492d29ea | 14878 | END_CATCH |
c906108c | 14879 | } |
0101ce28 | 14880 | |
b775012e LM |
14881 | bpt->enable_state = bp_enabled; |
14882 | ||
14883 | /* Mark breakpoint locations modified. */ | |
14884 | mark_breakpoint_modified (bpt); | |
14885 | ||
d248b706 KY |
14886 | if (target_supports_enable_disable_tracepoint () |
14887 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14888 | { | |
14889 | struct bp_location *location; | |
14890 | ||
14891 | for (location = bpt->loc; location; location = location->next) | |
14892 | target_enable_tracepoint (location); | |
14893 | } | |
14894 | ||
b4c291bb | 14895 | bpt->disposition = disposition; |
816338b5 | 14896 | bpt->enable_count = count; |
44702360 | 14897 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14898 | |
8d3788bd | 14899 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14900 | } |
14901 | ||
fe3f5fa8 | 14902 | |
c906108c | 14903 | void |
fba45db2 | 14904 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14905 | { |
816338b5 | 14906 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14907 | } |
14908 | ||
14909 | static void | |
14910 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14911 | { | |
14912 | enable_breakpoint (bpt); | |
c906108c SS |
14913 | } |
14914 | ||
95a42b64 TT |
14915 | /* A callback for map_breakpoint_numbers that calls |
14916 | enable_breakpoint. */ | |
14917 | ||
14918 | static void | |
14919 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14920 | { | |
51be5b68 | 14921 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14922 | } |
14923 | ||
c906108c SS |
14924 | /* The enable command enables the specified breakpoints (or all defined |
14925 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14926 | in stopping the inferior. */ |
c906108c | 14927 | |
c906108c | 14928 | static void |
fba45db2 | 14929 | enable_command (char *args, int from_tty) |
c906108c | 14930 | { |
c906108c | 14931 | if (args == 0) |
46c6471b PA |
14932 | { |
14933 | struct breakpoint *bpt; | |
14934 | ||
14935 | ALL_BREAKPOINTS (bpt) | |
14936 | if (user_breakpoint_p (bpt)) | |
14937 | enable_breakpoint (bpt); | |
14938 | } | |
9eaabc75 | 14939 | else |
0d381245 | 14940 | { |
9eaabc75 MW |
14941 | char *num = extract_arg (&args); |
14942 | ||
14943 | while (num) | |
d248b706 | 14944 | { |
9eaabc75 | 14945 | if (strchr (num, '.')) |
b775012e | 14946 | { |
9eaabc75 MW |
14947 | struct bp_location *loc = find_location_by_number (num); |
14948 | ||
14949 | if (loc) | |
14950 | { | |
14951 | if (!loc->enabled) | |
14952 | { | |
14953 | loc->enabled = 1; | |
14954 | mark_breakpoint_location_modified (loc); | |
14955 | } | |
14956 | if (target_supports_enable_disable_tracepoint () | |
14957 | && current_trace_status ()->running && loc->owner | |
14958 | && is_tracepoint (loc->owner)) | |
14959 | target_enable_tracepoint (loc); | |
14960 | } | |
44702360 | 14961 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14962 | } |
9eaabc75 MW |
14963 | else |
14964 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14965 | num = extract_arg (&args); | |
d248b706 | 14966 | } |
0d381245 | 14967 | } |
c906108c SS |
14968 | } |
14969 | ||
816338b5 SS |
14970 | /* This struct packages up disposition data for application to multiple |
14971 | breakpoints. */ | |
14972 | ||
14973 | struct disp_data | |
14974 | { | |
14975 | enum bpdisp disp; | |
14976 | int count; | |
14977 | }; | |
14978 | ||
c906108c | 14979 | static void |
51be5b68 PA |
14980 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14981 | { | |
816338b5 | 14982 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14983 | |
816338b5 | 14984 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14985 | } |
14986 | ||
14987 | static void | |
14988 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14989 | { |
816338b5 | 14990 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14991 | |
14992 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14993 | } |
14994 | ||
c906108c | 14995 | static void |
fba45db2 | 14996 | enable_once_command (char *args, int from_tty) |
c906108c | 14997 | { |
51be5b68 | 14998 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14999 | } |
15000 | ||
816338b5 SS |
15001 | static void |
15002 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15003 | { | |
15004 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15005 | ||
15006 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15007 | } | |
15008 | ||
15009 | static void | |
15010 | enable_count_command (char *args, int from_tty) | |
15011 | { | |
b9d61307 SM |
15012 | int count; |
15013 | ||
15014 | if (args == NULL) | |
15015 | error_no_arg (_("hit count")); | |
15016 | ||
15017 | count = get_number (&args); | |
816338b5 SS |
15018 | |
15019 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15020 | } | |
15021 | ||
c906108c | 15022 | static void |
51be5b68 | 15023 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15024 | { |
816338b5 | 15025 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15026 | |
15027 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15028 | } |
15029 | ||
c906108c | 15030 | static void |
fba45db2 | 15031 | enable_delete_command (char *args, int from_tty) |
c906108c | 15032 | { |
51be5b68 | 15033 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15034 | } |
15035 | \f | |
fa8d40ab JJ |
15036 | static void |
15037 | set_breakpoint_cmd (char *args, int from_tty) | |
15038 | { | |
15039 | } | |
15040 | ||
15041 | static void | |
15042 | show_breakpoint_cmd (char *args, int from_tty) | |
15043 | { | |
15044 | } | |
15045 | ||
1f3b5d1b PP |
15046 | /* Invalidate last known value of any hardware watchpoint if |
15047 | the memory which that value represents has been written to by | |
15048 | GDB itself. */ | |
15049 | ||
15050 | static void | |
8de0566d YQ |
15051 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15052 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15053 | const bfd_byte *data) |
15054 | { | |
15055 | struct breakpoint *bp; | |
15056 | ||
15057 | ALL_BREAKPOINTS (bp) | |
15058 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15059 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15060 | { |
3a5c3e22 | 15061 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15062 | |
3a5c3e22 PA |
15063 | if (wp->val_valid && wp->val) |
15064 | { | |
15065 | struct bp_location *loc; | |
15066 | ||
15067 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15068 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15069 | && loc->address + loc->length > addr | |
15070 | && addr + len > loc->address) | |
15071 | { | |
15072 | value_free (wp->val); | |
15073 | wp->val = NULL; | |
15074 | wp->val_valid = 0; | |
15075 | } | |
15076 | } | |
1f3b5d1b PP |
15077 | } |
15078 | } | |
15079 | ||
8181d85f DJ |
15080 | /* Create and insert a breakpoint for software single step. */ |
15081 | ||
15082 | void | |
6c95b8df | 15083 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15084 | struct address_space *aspace, |
15085 | CORE_ADDR next_pc) | |
8181d85f | 15086 | { |
7c16b83e PA |
15087 | struct thread_info *tp = inferior_thread (); |
15088 | struct symtab_and_line sal; | |
15089 | CORE_ADDR pc = next_pc; | |
8181d85f | 15090 | |
34b7e8a6 PA |
15091 | if (tp->control.single_step_breakpoints == NULL) |
15092 | { | |
15093 | tp->control.single_step_breakpoints | |
5d5658a1 | 15094 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 15095 | } |
8181d85f | 15096 | |
7c16b83e PA |
15097 | sal = find_pc_line (pc, 0); |
15098 | sal.pc = pc; | |
15099 | sal.section = find_pc_overlay (pc); | |
15100 | sal.explicit_pc = 1; | |
34b7e8a6 | 15101 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15102 | |
7c16b83e | 15103 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15104 | } |
15105 | ||
93f9a11f YQ |
15106 | /* Insert single step breakpoints according to the current state. */ |
15107 | ||
15108 | int | |
15109 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
15110 | { | |
f5ea389a | 15111 | struct regcache *regcache = get_current_regcache (); |
93f9a11f YQ |
15112 | VEC (CORE_ADDR) * next_pcs; |
15113 | ||
f5ea389a | 15114 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f YQ |
15115 | |
15116 | if (next_pcs != NULL) | |
15117 | { | |
15118 | int i; | |
15119 | CORE_ADDR pc; | |
f5ea389a | 15120 | struct frame_info *frame = get_current_frame (); |
93f9a11f YQ |
15121 | struct address_space *aspace = get_frame_address_space (frame); |
15122 | ||
15123 | for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); i++) | |
15124 | insert_single_step_breakpoint (gdbarch, aspace, pc); | |
15125 | ||
15126 | VEC_free (CORE_ADDR, next_pcs); | |
15127 | ||
15128 | return 1; | |
15129 | } | |
15130 | else | |
15131 | return 0; | |
15132 | } | |
15133 | ||
34b7e8a6 | 15134 | /* See breakpoint.h. */ |
f02253f1 HZ |
15135 | |
15136 | int | |
7c16b83e PA |
15137 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15138 | struct address_space *aspace, | |
15139 | CORE_ADDR pc) | |
1aafd4da | 15140 | { |
7c16b83e | 15141 | struct bp_location *loc; |
1aafd4da | 15142 | |
7c16b83e PA |
15143 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15144 | if (loc->inserted | |
15145 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15146 | return 1; | |
1aafd4da | 15147 | |
7c16b83e | 15148 | return 0; |
ef370185 JB |
15149 | } |
15150 | ||
15151 | /* Check whether a software single-step breakpoint is inserted at | |
15152 | PC. */ | |
15153 | ||
15154 | int | |
15155 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15156 | CORE_ADDR pc) | |
15157 | { | |
34b7e8a6 PA |
15158 | struct breakpoint *bpt; |
15159 | ||
15160 | ALL_BREAKPOINTS (bpt) | |
15161 | { | |
15162 | if (bpt->type == bp_single_step | |
15163 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15164 | return 1; | |
15165 | } | |
15166 | return 0; | |
1aafd4da UW |
15167 | } |
15168 | ||
1042e4c0 SS |
15169 | /* Tracepoint-specific operations. */ |
15170 | ||
15171 | /* Set tracepoint count to NUM. */ | |
15172 | static void | |
15173 | set_tracepoint_count (int num) | |
15174 | { | |
15175 | tracepoint_count = num; | |
4fa62494 | 15176 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15177 | } |
15178 | ||
70221824 | 15179 | static void |
1042e4c0 SS |
15180 | trace_command (char *arg, int from_tty) |
15181 | { | |
55aa24fb | 15182 | struct breakpoint_ops *ops; |
55aa24fb | 15183 | |
ffc2605c TT |
15184 | event_location_up location = string_to_event_location (&arg, |
15185 | current_language); | |
5b56227b | 15186 | if (location != NULL |
ffc2605c | 15187 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
15188 | ops = &tracepoint_probe_breakpoint_ops; |
15189 | else | |
15190 | ops = &tracepoint_breakpoint_ops; | |
15191 | ||
558a9d82 | 15192 | create_breakpoint (get_current_arch (), |
ffc2605c | 15193 | location.get (), |
f00aae0f | 15194 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15195 | 0 /* tempflag */, |
15196 | bp_tracepoint /* type_wanted */, | |
15197 | 0 /* Ignore count */, | |
15198 | pending_break_support, | |
15199 | ops, | |
15200 | from_tty, | |
15201 | 1 /* enabled */, | |
15202 | 0 /* internal */, 0); | |
1042e4c0 SS |
15203 | } |
15204 | ||
70221824 | 15205 | static void |
7a697b8d SS |
15206 | ftrace_command (char *arg, int from_tty) |
15207 | { | |
ffc2605c TT |
15208 | event_location_up location = string_to_event_location (&arg, |
15209 | current_language); | |
558a9d82 | 15210 | create_breakpoint (get_current_arch (), |
ffc2605c | 15211 | location.get (), |
f00aae0f | 15212 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15213 | 0 /* tempflag */, |
15214 | bp_fast_tracepoint /* type_wanted */, | |
15215 | 0 /* Ignore count */, | |
15216 | pending_break_support, | |
15217 | &tracepoint_breakpoint_ops, | |
15218 | from_tty, | |
15219 | 1 /* enabled */, | |
15220 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15221 | } |
15222 | ||
15223 | /* strace command implementation. Creates a static tracepoint. */ | |
15224 | ||
70221824 | 15225 | static void |
0fb4aa4b PA |
15226 | strace_command (char *arg, int from_tty) |
15227 | { | |
983af33b | 15228 | struct breakpoint_ops *ops; |
ffc2605c | 15229 | event_location_up location; |
f00aae0f | 15230 | struct cleanup *back_to; |
983af33b SDJ |
15231 | |
15232 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15233 | or with a normal static tracepoint. */ | |
61012eef | 15234 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15235 | { |
15236 | ops = &strace_marker_breakpoint_ops; | |
15237 | location = new_linespec_location (&arg); | |
15238 | } | |
983af33b | 15239 | else |
f00aae0f KS |
15240 | { |
15241 | ops = &tracepoint_breakpoint_ops; | |
15242 | location = string_to_event_location (&arg, current_language); | |
15243 | } | |
983af33b | 15244 | |
558a9d82 | 15245 | create_breakpoint (get_current_arch (), |
ffc2605c | 15246 | location.get (), |
f00aae0f | 15247 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15248 | 0 /* tempflag */, |
15249 | bp_static_tracepoint /* type_wanted */, | |
15250 | 0 /* Ignore count */, | |
15251 | pending_break_support, | |
15252 | ops, | |
15253 | from_tty, | |
15254 | 1 /* enabled */, | |
15255 | 0 /* internal */, 0); | |
7a697b8d SS |
15256 | } |
15257 | ||
409873ef SS |
15258 | /* Set up a fake reader function that gets command lines from a linked |
15259 | list that was acquired during tracepoint uploading. */ | |
15260 | ||
15261 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15262 | static int next_cmd; |
409873ef SS |
15263 | |
15264 | static char * | |
15265 | read_uploaded_action (void) | |
15266 | { | |
15267 | char *rslt; | |
15268 | ||
3149d8c1 | 15269 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15270 | |
3149d8c1 | 15271 | next_cmd++; |
409873ef SS |
15272 | |
15273 | return rslt; | |
15274 | } | |
15275 | ||
00bf0b85 SS |
15276 | /* Given information about a tracepoint as recorded on a target (which |
15277 | can be either a live system or a trace file), attempt to create an | |
15278 | equivalent GDB tracepoint. This is not a reliable process, since | |
15279 | the target does not necessarily have all the information used when | |
15280 | the tracepoint was originally defined. */ | |
15281 | ||
d9b3f62e | 15282 | struct tracepoint * |
00bf0b85 | 15283 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15284 | { |
409873ef | 15285 | char *addr_str, small_buf[100]; |
d9b3f62e | 15286 | struct tracepoint *tp; |
fd9b8c24 | 15287 | |
409873ef SS |
15288 | if (utp->at_string) |
15289 | addr_str = utp->at_string; | |
15290 | else | |
15291 | { | |
15292 | /* In the absence of a source location, fall back to raw | |
15293 | address. Since there is no way to confirm that the address | |
15294 | means the same thing as when the trace was started, warn the | |
15295 | user. */ | |
3e43a32a MS |
15296 | warning (_("Uploaded tracepoint %d has no " |
15297 | "source location, using raw address"), | |
409873ef | 15298 | utp->number); |
8c042590 | 15299 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15300 | addr_str = small_buf; |
15301 | } | |
15302 | ||
15303 | /* There's not much we can do with a sequence of bytecodes. */ | |
15304 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15305 | warning (_("Uploaded tracepoint %d condition " |
15306 | "has no source form, ignoring it"), | |
409873ef | 15307 | utp->number); |
d5551862 | 15308 | |
ffc2605c TT |
15309 | event_location_up location = string_to_event_location (&addr_str, |
15310 | current_language); | |
8cdf0e15 | 15311 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 15312 | location.get (), |
f00aae0f | 15313 | utp->cond_string, -1, addr_str, |
e7e0cddf | 15314 | 0 /* parse cond/thread */, |
8cdf0e15 | 15315 | 0 /* tempflag */, |
0fb4aa4b | 15316 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15317 | 0 /* Ignore count */, |
15318 | pending_break_support, | |
348d480f | 15319 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15320 | 0 /* from_tty */, |
84f4c1fe | 15321 | utp->enabled /* enabled */, |
44f238bb PA |
15322 | 0 /* internal */, |
15323 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 15324 | return NULL; |
fd9b8c24 | 15325 | |
409873ef | 15326 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15327 | tp = get_tracepoint (tracepoint_count); |
15328 | gdb_assert (tp != NULL); | |
d5551862 | 15329 | |
00bf0b85 SS |
15330 | if (utp->pass > 0) |
15331 | { | |
8c042590 PM |
15332 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15333 | tp->base.number); | |
00bf0b85 | 15334 | |
409873ef | 15335 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15336 | } |
15337 | ||
409873ef SS |
15338 | /* If we have uploaded versions of the original commands, set up a |
15339 | special-purpose "reader" function and call the usual command line | |
15340 | reader, then pass the result to the breakpoint command-setting | |
15341 | function. */ | |
3149d8c1 | 15342 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15343 | { |
93921405 | 15344 | command_line_up cmd_list; |
00bf0b85 | 15345 | |
409873ef | 15346 | this_utp = utp; |
3149d8c1 | 15347 | next_cmd = 0; |
d5551862 | 15348 | |
409873ef SS |
15349 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15350 | ||
93921405 | 15351 | breakpoint_set_commands (&tp->base, std::move (cmd_list)); |
00bf0b85 | 15352 | } |
3149d8c1 SS |
15353 | else if (!VEC_empty (char_ptr, utp->actions) |
15354 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15355 | warning (_("Uploaded tracepoint %d actions " |
15356 | "have no source form, ignoring them"), | |
409873ef | 15357 | utp->number); |
00bf0b85 | 15358 | |
f196051f SS |
15359 | /* Copy any status information that might be available. */ |
15360 | tp->base.hit_count = utp->hit_count; | |
15361 | tp->traceframe_usage = utp->traceframe_usage; | |
15362 | ||
00bf0b85 | 15363 | return tp; |
d9b3f62e | 15364 | } |
00bf0b85 | 15365 | |
1042e4c0 SS |
15366 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15367 | omitted. */ | |
15368 | ||
15369 | static void | |
e5a67952 | 15370 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15371 | { |
79a45e25 | 15372 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15373 | int num_printed; |
1042e4c0 | 15374 | |
e5a67952 | 15375 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15376 | |
15377 | if (num_printed == 0) | |
1042e4c0 | 15378 | { |
e5a67952 | 15379 | if (args == NULL || *args == '\0') |
112e8700 | 15380 | uiout->message ("No tracepoints.\n"); |
d77f58be | 15381 | else |
112e8700 | 15382 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15383 | } |
ad443146 SS |
15384 | |
15385 | default_collect_info (); | |
1042e4c0 SS |
15386 | } |
15387 | ||
4a64f543 | 15388 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15389 | Not supported by all targets. */ |
15390 | static void | |
15391 | enable_trace_command (char *args, int from_tty) | |
15392 | { | |
15393 | enable_command (args, from_tty); | |
15394 | } | |
15395 | ||
4a64f543 | 15396 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15397 | Not supported by all targets. */ |
15398 | static void | |
15399 | disable_trace_command (char *args, int from_tty) | |
15400 | { | |
15401 | disable_command (args, from_tty); | |
15402 | } | |
15403 | ||
4a64f543 | 15404 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15405 | static void |
15406 | delete_trace_command (char *arg, int from_tty) | |
15407 | { | |
35df4500 | 15408 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15409 | |
15410 | dont_repeat (); | |
15411 | ||
15412 | if (arg == 0) | |
15413 | { | |
15414 | int breaks_to_delete = 0; | |
15415 | ||
15416 | /* Delete all breakpoints if no argument. | |
15417 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15418 | have to be deleted with an explicit breakpoint number |
15419 | argument. */ | |
1042e4c0 | 15420 | ALL_TRACEPOINTS (b) |
46c6471b | 15421 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15422 | { |
15423 | breaks_to_delete = 1; | |
15424 | break; | |
15425 | } | |
1042e4c0 SS |
15426 | |
15427 | /* Ask user only if there are some breakpoints to delete. */ | |
15428 | if (!from_tty | |
15429 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15430 | { | |
35df4500 | 15431 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15432 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15433 | delete_breakpoint (b); |
1042e4c0 SS |
15434 | } |
15435 | } | |
15436 | else | |
51be5b68 | 15437 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15438 | } |
15439 | ||
197f0a60 TT |
15440 | /* Helper function for trace_pass_command. */ |
15441 | ||
15442 | static void | |
d9b3f62e | 15443 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15444 | { |
d9b3f62e | 15445 | tp->pass_count = count; |
6f6484cd | 15446 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15447 | if (from_tty) |
15448 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15449 | tp->base.number, count); |
197f0a60 TT |
15450 | } |
15451 | ||
1042e4c0 SS |
15452 | /* Set passcount for tracepoint. |
15453 | ||
15454 | First command argument is passcount, second is tracepoint number. | |
15455 | If tracepoint number omitted, apply to most recently defined. | |
15456 | Also accepts special argument "all". */ | |
15457 | ||
15458 | static void | |
15459 | trace_pass_command (char *args, int from_tty) | |
15460 | { | |
d9b3f62e | 15461 | struct tracepoint *t1; |
1042e4c0 | 15462 | unsigned int count; |
1042e4c0 SS |
15463 | |
15464 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15465 | error (_("passcount command requires an " |
15466 | "argument (count + optional TP num)")); | |
1042e4c0 | 15467 | |
4a64f543 | 15468 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15469 | |
529480d0 | 15470 | args = skip_spaces (args); |
1042e4c0 SS |
15471 | if (*args && strncasecmp (args, "all", 3) == 0) |
15472 | { | |
d9b3f62e PA |
15473 | struct breakpoint *b; |
15474 | ||
1042e4c0 | 15475 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15476 | if (*args) |
15477 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15478 | |
d9b3f62e | 15479 | ALL_TRACEPOINTS (b) |
197f0a60 | 15480 | { |
d9b3f62e | 15481 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15482 | trace_pass_set_count (t1, count, from_tty); |
15483 | } | |
15484 | } | |
15485 | else if (*args == '\0') | |
1042e4c0 | 15486 | { |
5fa1d40e | 15487 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15488 | if (t1) |
197f0a60 TT |
15489 | trace_pass_set_count (t1, count, from_tty); |
15490 | } | |
15491 | else | |
15492 | { | |
bfd28288 PA |
15493 | number_or_range_parser parser (args); |
15494 | while (!parser.finished ()) | |
1042e4c0 | 15495 | { |
bfd28288 | 15496 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15497 | if (t1) |
15498 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15499 | } |
15500 | } | |
1042e4c0 SS |
15501 | } |
15502 | ||
d9b3f62e | 15503 | struct tracepoint * |
1042e4c0 SS |
15504 | get_tracepoint (int num) |
15505 | { | |
15506 | struct breakpoint *t; | |
15507 | ||
15508 | ALL_TRACEPOINTS (t) | |
15509 | if (t->number == num) | |
d9b3f62e | 15510 | return (struct tracepoint *) t; |
1042e4c0 SS |
15511 | |
15512 | return NULL; | |
15513 | } | |
15514 | ||
d5551862 SS |
15515 | /* Find the tracepoint with the given target-side number (which may be |
15516 | different from the tracepoint number after disconnecting and | |
15517 | reconnecting). */ | |
15518 | ||
d9b3f62e | 15519 | struct tracepoint * |
d5551862 SS |
15520 | get_tracepoint_by_number_on_target (int num) |
15521 | { | |
d9b3f62e | 15522 | struct breakpoint *b; |
d5551862 | 15523 | |
d9b3f62e PA |
15524 | ALL_TRACEPOINTS (b) |
15525 | { | |
15526 | struct tracepoint *t = (struct tracepoint *) b; | |
15527 | ||
15528 | if (t->number_on_target == num) | |
15529 | return t; | |
15530 | } | |
d5551862 SS |
15531 | |
15532 | return NULL; | |
15533 | } | |
15534 | ||
1042e4c0 | 15535 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15536 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15537 | If the argument is missing, the most recent tracepoint |
15538 | (tracepoint_count) is returned. */ | |
15539 | ||
d9b3f62e | 15540 | struct tracepoint * |
197f0a60 | 15541 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15542 | number_or_range_parser *parser) |
1042e4c0 | 15543 | { |
1042e4c0 SS |
15544 | struct breakpoint *t; |
15545 | int tpnum; | |
15546 | char *instring = arg == NULL ? NULL : *arg; | |
15547 | ||
bfd28288 | 15548 | if (parser != NULL) |
197f0a60 | 15549 | { |
bfd28288 PA |
15550 | gdb_assert (!parser->finished ()); |
15551 | tpnum = parser->get_number (); | |
197f0a60 TT |
15552 | } |
15553 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15554 | tpnum = tracepoint_count; |
1042e4c0 | 15555 | else |
197f0a60 | 15556 | tpnum = get_number (arg); |
1042e4c0 SS |
15557 | |
15558 | if (tpnum <= 0) | |
15559 | { | |
15560 | if (instring && *instring) | |
15561 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15562 | instring); | |
15563 | else | |
5fa1d40e | 15564 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15565 | return NULL; |
15566 | } | |
15567 | ||
15568 | ALL_TRACEPOINTS (t) | |
15569 | if (t->number == tpnum) | |
15570 | { | |
d9b3f62e | 15571 | return (struct tracepoint *) t; |
1042e4c0 SS |
15572 | } |
15573 | ||
1042e4c0 SS |
15574 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15575 | return NULL; | |
15576 | } | |
15577 | ||
d9b3f62e PA |
15578 | void |
15579 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15580 | { | |
15581 | if (b->thread != -1) | |
15582 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15583 | ||
15584 | if (b->task != 0) | |
15585 | fprintf_unfiltered (fp, " task %d", b->task); | |
15586 | ||
15587 | fprintf_unfiltered (fp, "\n"); | |
15588 | } | |
15589 | ||
6149aea9 PA |
15590 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15591 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15592 | on each breakpoint and only include the ones for which it returns | |
15593 | non-zero. */ | |
15594 | ||
1042e4c0 | 15595 | static void |
6149aea9 PA |
15596 | save_breakpoints (char *filename, int from_tty, |
15597 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15598 | { |
15599 | struct breakpoint *tp; | |
6149aea9 | 15600 | int any = 0; |
1042e4c0 | 15601 | struct cleanup *cleanup; |
6149aea9 | 15602 | int extra_trace_bits = 0; |
1042e4c0 | 15603 | |
6149aea9 PA |
15604 | if (filename == 0 || *filename == 0) |
15605 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15606 | |
15607 | /* See if we have anything to save. */ | |
6149aea9 | 15608 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15609 | { |
6149aea9 | 15610 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15611 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15612 | continue; |
15613 | ||
15614 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15615 | if (filter && !filter (tp)) | |
15616 | continue; | |
15617 | ||
15618 | any = 1; | |
15619 | ||
15620 | if (is_tracepoint (tp)) | |
15621 | { | |
15622 | extra_trace_bits = 1; | |
15623 | ||
15624 | /* We can stop searching. */ | |
15625 | break; | |
15626 | } | |
1042e4c0 | 15627 | } |
6149aea9 PA |
15628 | |
15629 | if (!any) | |
1042e4c0 | 15630 | { |
6149aea9 | 15631 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15632 | return; |
15633 | } | |
15634 | ||
c718be47 PA |
15635 | filename = tilde_expand (filename); |
15636 | cleanup = make_cleanup (xfree, filename); | |
d7e74731 PA |
15637 | |
15638 | stdio_file fp; | |
15639 | ||
15640 | if (!fp.open (filename, "w")) | |
6149aea9 PA |
15641 | error (_("Unable to open file '%s' for saving (%s)"), |
15642 | filename, safe_strerror (errno)); | |
8bf6485c | 15643 | |
6149aea9 | 15644 | if (extra_trace_bits) |
d7e74731 | 15645 | save_trace_state_variables (&fp); |
8bf6485c | 15646 | |
6149aea9 | 15647 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15648 | { |
6149aea9 | 15649 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15650 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15651 | continue; |
8bf6485c | 15652 | |
6149aea9 PA |
15653 | /* If we have a filter, only save the breakpoints it accepts. */ |
15654 | if (filter && !filter (tp)) | |
15655 | continue; | |
15656 | ||
d7e74731 | 15657 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15658 | |
6149aea9 PA |
15659 | /* Note, we can't rely on tp->number for anything, as we can't |
15660 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15661 | instead. */ | |
15662 | ||
15663 | if (tp->cond_string) | |
d7e74731 | 15664 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15665 | |
15666 | if (tp->ignore_count) | |
d7e74731 | 15667 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15668 | |
2d9442cc | 15669 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15670 | { |
d7e74731 | 15671 | fp.puts (" commands\n"); |
a7bdde9e | 15672 | |
d7e74731 | 15673 | current_uiout->redirect (&fp); |
492d29ea | 15674 | TRY |
1042e4c0 | 15675 | { |
79a45e25 | 15676 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15677 | } |
492d29ea PA |
15678 | CATCH (ex, RETURN_MASK_ALL) |
15679 | { | |
112e8700 | 15680 | current_uiout->redirect (NULL); |
492d29ea PA |
15681 | throw_exception (ex); |
15682 | } | |
15683 | END_CATCH | |
1042e4c0 | 15684 | |
112e8700 | 15685 | current_uiout->redirect (NULL); |
d7e74731 | 15686 | fp.puts (" end\n"); |
1042e4c0 | 15687 | } |
6149aea9 PA |
15688 | |
15689 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15690 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15691 | |
15692 | /* If this is a multi-location breakpoint, check if the locations | |
15693 | should be individually disabled. Watchpoint locations are | |
15694 | special, and not user visible. */ | |
15695 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15696 | { | |
15697 | struct bp_location *loc; | |
15698 | int n = 1; | |
15699 | ||
15700 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15701 | if (!loc->enabled) | |
d7e74731 | 15702 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15703 | } |
1042e4c0 | 15704 | } |
8bf6485c | 15705 | |
6149aea9 | 15706 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15707 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15708 | |
1042e4c0 | 15709 | if (from_tty) |
6149aea9 | 15710 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15711 | do_cleanups (cleanup); |
6149aea9 PA |
15712 | } |
15713 | ||
15714 | /* The `save breakpoints' command. */ | |
15715 | ||
15716 | static void | |
15717 | save_breakpoints_command (char *args, int from_tty) | |
15718 | { | |
15719 | save_breakpoints (args, from_tty, NULL); | |
15720 | } | |
15721 | ||
15722 | /* The `save tracepoints' command. */ | |
15723 | ||
15724 | static void | |
15725 | save_tracepoints_command (char *args, int from_tty) | |
15726 | { | |
15727 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15728 | } |
15729 | ||
15730 | /* Create a vector of all tracepoints. */ | |
15731 | ||
15732 | VEC(breakpoint_p) * | |
eeae04df | 15733 | all_tracepoints (void) |
1042e4c0 SS |
15734 | { |
15735 | VEC(breakpoint_p) *tp_vec = 0; | |
15736 | struct breakpoint *tp; | |
15737 | ||
15738 | ALL_TRACEPOINTS (tp) | |
15739 | { | |
15740 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15741 | } | |
15742 | ||
15743 | return tp_vec; | |
15744 | } | |
15745 | ||
c906108c | 15746 | \f |
629500fa KS |
15747 | /* This help string is used to consolidate all the help string for specifying |
15748 | locations used by several commands. */ | |
15749 | ||
15750 | #define LOCATION_HELP_STRING \ | |
15751 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15752 | source filename, function name, label name, and line number.\n\ | |
15753 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15754 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15755 | \"factorial.c:fact:the_top\".\n\ | |
15756 | \n\ | |
15757 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15758 | program. Example: To specify the fourth byte past the start function\n\ | |
15759 | \"main\", use \"*main + 4\".\n\ | |
15760 | \n\ | |
15761 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15762 | syntax to specify location parameters.\n\ | |
15763 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15764 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15765 | -function fact -label the_top\".\n" | |
15766 | ||
4a64f543 MS |
15767 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15768 | commands. It is defined as a macro to prevent duplication. | |
15769 | COMMAND should be a string constant containing the name of the | |
15770 | command. */ | |
629500fa | 15771 | |
31e2b00f | 15772 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15773 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15774 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15775 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15776 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15777 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15778 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15779 | below.\n\ | |
15780 | \n\ | |
dc10affe PA |
15781 | With no LOCATION, uses current execution address of the selected\n\ |
15782 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15783 | \n\ |
15784 | THREADNUM is the number from \"info threads\".\n\ | |
15785 | CONDITION is a boolean expression.\n\ | |
629500fa | 15786 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15787 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15788 | conditions are different.\n\ | |
31e2b00f AS |
15789 | \n\ |
15790 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15791 | ||
44feb3ce TT |
15792 | /* List of subcommands for "catch". */ |
15793 | static struct cmd_list_element *catch_cmdlist; | |
15794 | ||
15795 | /* List of subcommands for "tcatch". */ | |
15796 | static struct cmd_list_element *tcatch_cmdlist; | |
15797 | ||
9ac4176b | 15798 | void |
a121b7c1 | 15799 | add_catch_command (const char *name, const char *docstring, |
82ae6c8d | 15800 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15801 | completer_ftype *completer, |
44feb3ce TT |
15802 | void *user_data_catch, |
15803 | void *user_data_tcatch) | |
15804 | { | |
15805 | struct cmd_list_element *command; | |
15806 | ||
15807 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15808 | &catch_cmdlist); | |
15809 | set_cmd_sfunc (command, sfunc); | |
15810 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15811 | set_cmd_completer (command, completer); |
44feb3ce TT |
15812 | |
15813 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15814 | &tcatch_cmdlist); | |
15815 | set_cmd_sfunc (command, sfunc); | |
15816 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15817 | set_cmd_completer (command, completer); |
44feb3ce TT |
15818 | } |
15819 | ||
6149aea9 PA |
15820 | static void |
15821 | save_command (char *arg, int from_tty) | |
15822 | { | |
3e43a32a MS |
15823 | printf_unfiltered (_("\"save\" must be followed by " |
15824 | "the name of a save subcommand.\n")); | |
635c7e8a | 15825 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15826 | } |
15827 | ||
84f4c1fe PM |
15828 | struct breakpoint * |
15829 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15830 | void *data) | |
15831 | { | |
35df4500 | 15832 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15833 | |
35df4500 | 15834 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15835 | { |
15836 | if ((*callback) (b, data)) | |
15837 | return b; | |
15838 | } | |
15839 | ||
15840 | return NULL; | |
15841 | } | |
15842 | ||
0574c78f GB |
15843 | /* Zero if any of the breakpoint's locations could be a location where |
15844 | functions have been inlined, nonzero otherwise. */ | |
15845 | ||
15846 | static int | |
15847 | is_non_inline_function (struct breakpoint *b) | |
15848 | { | |
15849 | /* The shared library event breakpoint is set on the address of a | |
15850 | non-inline function. */ | |
15851 | if (b->type == bp_shlib_event) | |
15852 | return 1; | |
15853 | ||
15854 | return 0; | |
15855 | } | |
15856 | ||
15857 | /* Nonzero if the specified PC cannot be a location where functions | |
15858 | have been inlined. */ | |
15859 | ||
15860 | int | |
09ac7c10 TT |
15861 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15862 | const struct target_waitstatus *ws) | |
0574c78f GB |
15863 | { |
15864 | struct breakpoint *b; | |
15865 | struct bp_location *bl; | |
15866 | ||
15867 | ALL_BREAKPOINTS (b) | |
15868 | { | |
15869 | if (!is_non_inline_function (b)) | |
15870 | continue; | |
15871 | ||
15872 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15873 | { | |
15874 | if (!bl->shlib_disabled | |
09ac7c10 | 15875 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15876 | return 1; |
15877 | } | |
15878 | } | |
15879 | ||
15880 | return 0; | |
15881 | } | |
15882 | ||
2f202fde JK |
15883 | /* Remove any references to OBJFILE which is going to be freed. */ |
15884 | ||
15885 | void | |
15886 | breakpoint_free_objfile (struct objfile *objfile) | |
15887 | { | |
15888 | struct bp_location **locp, *loc; | |
15889 | ||
15890 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15891 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15892 | loc->symtab = NULL; |
15893 | } | |
15894 | ||
2060206e PA |
15895 | void |
15896 | initialize_breakpoint_ops (void) | |
15897 | { | |
15898 | static int initialized = 0; | |
15899 | ||
15900 | struct breakpoint_ops *ops; | |
15901 | ||
15902 | if (initialized) | |
15903 | return; | |
15904 | initialized = 1; | |
15905 | ||
15906 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15907 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15908 | internal and momentary breakpoints, etc.). */ | |
15909 | ops = &bkpt_base_breakpoint_ops; | |
15910 | *ops = base_breakpoint_ops; | |
15911 | ops->re_set = bkpt_re_set; | |
15912 | ops->insert_location = bkpt_insert_location; | |
15913 | ops->remove_location = bkpt_remove_location; | |
15914 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15915 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15916 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15917 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15918 | |
15919 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15920 | ops = &bkpt_breakpoint_ops; | |
15921 | *ops = bkpt_base_breakpoint_ops; | |
15922 | ops->re_set = bkpt_re_set; | |
15923 | ops->resources_needed = bkpt_resources_needed; | |
15924 | ops->print_it = bkpt_print_it; | |
15925 | ops->print_mention = bkpt_print_mention; | |
15926 | ops->print_recreate = bkpt_print_recreate; | |
15927 | ||
15928 | /* Ranged breakpoints. */ | |
15929 | ops = &ranged_breakpoint_ops; | |
15930 | *ops = bkpt_breakpoint_ops; | |
15931 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15932 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15933 | ops->print_it = print_it_ranged_breakpoint; | |
15934 | ops->print_one = print_one_ranged_breakpoint; | |
15935 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15936 | ops->print_mention = print_mention_ranged_breakpoint; | |
15937 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15938 | ||
15939 | /* Internal breakpoints. */ | |
15940 | ops = &internal_breakpoint_ops; | |
15941 | *ops = bkpt_base_breakpoint_ops; | |
15942 | ops->re_set = internal_bkpt_re_set; | |
15943 | ops->check_status = internal_bkpt_check_status; | |
15944 | ops->print_it = internal_bkpt_print_it; | |
15945 | ops->print_mention = internal_bkpt_print_mention; | |
15946 | ||
15947 | /* Momentary breakpoints. */ | |
15948 | ops = &momentary_breakpoint_ops; | |
15949 | *ops = bkpt_base_breakpoint_ops; | |
15950 | ops->re_set = momentary_bkpt_re_set; | |
15951 | ops->check_status = momentary_bkpt_check_status; | |
15952 | ops->print_it = momentary_bkpt_print_it; | |
15953 | ops->print_mention = momentary_bkpt_print_mention; | |
15954 | ||
e2e4d78b JK |
15955 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15956 | ops = &longjmp_breakpoint_ops; | |
15957 | *ops = momentary_breakpoint_ops; | |
15958 | ops->dtor = longjmp_bkpt_dtor; | |
15959 | ||
55aa24fb SDJ |
15960 | /* Probe breakpoints. */ |
15961 | ops = &bkpt_probe_breakpoint_ops; | |
15962 | *ops = bkpt_breakpoint_ops; | |
15963 | ops->insert_location = bkpt_probe_insert_location; | |
15964 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15965 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15966 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15967 | |
2060206e PA |
15968 | /* Watchpoints. */ |
15969 | ops = &watchpoint_breakpoint_ops; | |
15970 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15971 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15972 | ops->re_set = re_set_watchpoint; |
15973 | ops->insert_location = insert_watchpoint; | |
15974 | ops->remove_location = remove_watchpoint; | |
15975 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15976 | ops->check_status = check_status_watchpoint; | |
15977 | ops->resources_needed = resources_needed_watchpoint; | |
15978 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15979 | ops->print_it = print_it_watchpoint; | |
15980 | ops->print_mention = print_mention_watchpoint; | |
15981 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15982 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15983 | |
15984 | /* Masked watchpoints. */ | |
15985 | ops = &masked_watchpoint_breakpoint_ops; | |
15986 | *ops = watchpoint_breakpoint_ops; | |
15987 | ops->insert_location = insert_masked_watchpoint; | |
15988 | ops->remove_location = remove_masked_watchpoint; | |
15989 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15990 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15991 | ops->print_it = print_it_masked_watchpoint; | |
15992 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15993 | ops->print_mention = print_mention_masked_watchpoint; | |
15994 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15995 | ||
15996 | /* Tracepoints. */ | |
15997 | ops = &tracepoint_breakpoint_ops; | |
15998 | *ops = base_breakpoint_ops; | |
15999 | ops->re_set = tracepoint_re_set; | |
16000 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16001 | ops->print_one_detail = tracepoint_print_one_detail; | |
16002 | ops->print_mention = tracepoint_print_mention; | |
16003 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 16004 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 16005 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 16006 | ops->decode_location = tracepoint_decode_location; |
983af33b | 16007 | |
55aa24fb SDJ |
16008 | /* Probe tracepoints. */ |
16009 | ops = &tracepoint_probe_breakpoint_ops; | |
16010 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
16011 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
16012 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 16013 | |
983af33b SDJ |
16014 | /* Static tracepoints with marker (`-m'). */ |
16015 | ops = &strace_marker_breakpoint_ops; | |
16016 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 16017 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 16018 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 16019 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
16020 | |
16021 | /* Fork catchpoints. */ | |
16022 | ops = &catch_fork_breakpoint_ops; | |
16023 | *ops = base_breakpoint_ops; | |
16024 | ops->insert_location = insert_catch_fork; | |
16025 | ops->remove_location = remove_catch_fork; | |
16026 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16027 | ops->print_it = print_it_catch_fork; | |
16028 | ops->print_one = print_one_catch_fork; | |
16029 | ops->print_mention = print_mention_catch_fork; | |
16030 | ops->print_recreate = print_recreate_catch_fork; | |
16031 | ||
16032 | /* Vfork catchpoints. */ | |
16033 | ops = &catch_vfork_breakpoint_ops; | |
16034 | *ops = base_breakpoint_ops; | |
16035 | ops->insert_location = insert_catch_vfork; | |
16036 | ops->remove_location = remove_catch_vfork; | |
16037 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16038 | ops->print_it = print_it_catch_vfork; | |
16039 | ops->print_one = print_one_catch_vfork; | |
16040 | ops->print_mention = print_mention_catch_vfork; | |
16041 | ops->print_recreate = print_recreate_catch_vfork; | |
16042 | ||
16043 | /* Exec catchpoints. */ | |
16044 | ops = &catch_exec_breakpoint_ops; | |
16045 | *ops = base_breakpoint_ops; | |
16046 | ops->dtor = dtor_catch_exec; | |
16047 | ops->insert_location = insert_catch_exec; | |
16048 | ops->remove_location = remove_catch_exec; | |
16049 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16050 | ops->print_it = print_it_catch_exec; | |
16051 | ops->print_one = print_one_catch_exec; | |
16052 | ops->print_mention = print_mention_catch_exec; | |
16053 | ops->print_recreate = print_recreate_catch_exec; | |
16054 | ||
edcc5120 TT |
16055 | /* Solib-related catchpoints. */ |
16056 | ops = &catch_solib_breakpoint_ops; | |
16057 | *ops = base_breakpoint_ops; | |
16058 | ops->dtor = dtor_catch_solib; | |
16059 | ops->insert_location = insert_catch_solib; | |
16060 | ops->remove_location = remove_catch_solib; | |
16061 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16062 | ops->check_status = check_status_catch_solib; | |
16063 | ops->print_it = print_it_catch_solib; | |
16064 | ops->print_one = print_one_catch_solib; | |
16065 | ops->print_mention = print_mention_catch_solib; | |
16066 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16067 | |
16068 | ops = &dprintf_breakpoint_ops; | |
16069 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16070 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16071 | ops->resources_needed = bkpt_resources_needed; |
16072 | ops->print_it = bkpt_print_it; | |
16073 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16074 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16075 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16076 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16077 | } |
16078 | ||
8bfd80db YQ |
16079 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16080 | ||
16081 | static struct cmd_list_element *enablebreaklist = NULL; | |
16082 | ||
c906108c | 16083 | void |
fba45db2 | 16084 | _initialize_breakpoint (void) |
c906108c SS |
16085 | { |
16086 | struct cmd_list_element *c; | |
16087 | ||
2060206e PA |
16088 | initialize_breakpoint_ops (); |
16089 | ||
84acb35a | 16090 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16091 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16092 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16093 | |
55aa24fb SDJ |
16094 | breakpoint_objfile_key |
16095 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16096 | |
c906108c SS |
16097 | breakpoint_chain = 0; |
16098 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16099 | before a breakpoint is set. */ | |
16100 | breakpoint_count = 0; | |
16101 | ||
1042e4c0 SS |
16102 | tracepoint_count = 0; |
16103 | ||
1bedd215 AC |
16104 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16105 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16106 | Usage is `ignore N COUNT'.")); | |
c906108c | 16107 | |
1bedd215 | 16108 | add_com ("commands", class_breakpoint, commands_command, _("\ |
18da0c51 MG |
16109 | Set commands to be executed when the given breakpoints are hit.\n\ |
16110 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
16111 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
16112 | (e.g. `5-7').\n\ | |
c906108c SS |
16113 | With no argument, the targeted breakpoint is the last one set.\n\ |
16114 | The commands themselves follow starting on the next line.\n\ | |
16115 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16116 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16117 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16118 | |
d55637df | 16119 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16120 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16121 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16122 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16123 | set_cmd_completer (c, condition_completer); |
c906108c | 16124 | |
1bedd215 | 16125 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16126 | Set a temporary breakpoint.\n\ |
c906108c SS |
16127 | Like \"break\" except the breakpoint is only temporary,\n\ |
16128 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16129 | by using \"enable delete\" on the breakpoint number.\n\ |
16130 | \n" | |
16131 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16132 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16133 | |
1bedd215 | 16134 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16135 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16136 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16137 | some target hardware may not have this support.\n\ |
16138 | \n" | |
16139 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16140 | set_cmd_completer (c, location_completer); |
c906108c | 16141 | |
1bedd215 | 16142 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16143 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16144 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16145 | so it will be deleted when hit.\n\ |
16146 | \n" | |
16147 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16148 | set_cmd_completer (c, location_completer); |
c906108c | 16149 | |
1bedd215 AC |
16150 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16151 | Enable some breakpoints.\n\ | |
c906108c SS |
16152 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16153 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16154 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16155 | With a subcommand you can enable temporarily."), |
c906108c | 16156 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16157 | |
16158 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16159 | ||
84951ab5 | 16160 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16161 | Enable some breakpoints.\n\ |
c906108c SS |
16162 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16163 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16164 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16165 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16166 | |
1a966eab AC |
16167 | add_cmd ("once", no_class, enable_once_command, _("\ |
16168 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16169 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16170 | &enablebreaklist); |
16171 | ||
1a966eab AC |
16172 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16173 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16174 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16175 | &enablebreaklist); |
16176 | ||
816338b5 SS |
16177 | add_cmd ("count", no_class, enable_count_command, _("\ |
16178 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16179 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16180 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16181 | &enablebreaklist); | |
16182 | ||
1a966eab AC |
16183 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16184 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16185 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16186 | &enablelist); |
16187 | ||
1a966eab AC |
16188 | add_cmd ("once", no_class, enable_once_command, _("\ |
16189 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16190 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16191 | &enablelist); |
16192 | ||
16193 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16194 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16195 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16196 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16197 | &enablelist); |
16198 | ||
1bedd215 AC |
16199 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16200 | Disable some breakpoints.\n\ | |
c906108c SS |
16201 | Arguments are breakpoint numbers with spaces in between.\n\ |
16202 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16203 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16204 | &disablelist, "disable ", 1, &cmdlist); |
16205 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16206 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16207 | |
1a966eab AC |
16208 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16209 | Disable some breakpoints.\n\ | |
c906108c SS |
16210 | Arguments are breakpoint numbers with spaces in between.\n\ |
16211 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16212 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16213 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16214 | &disablelist); |
16215 | ||
1bedd215 AC |
16216 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16217 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16218 | Arguments are breakpoint numbers with spaces in between.\n\ |
16219 | To delete all breakpoints, give no argument.\n\ | |
16220 | \n\ | |
16221 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16222 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16223 | &deletelist, "delete ", 1, &cmdlist); |
16224 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16225 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16226 | |
1a966eab AC |
16227 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16228 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16229 | Arguments are breakpoint numbers with spaces in between.\n\ |
16230 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16231 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16232 | &deletelist); |
16233 | ||
1bedd215 | 16234 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16235 | Clear breakpoint at specified location.\n\ |
16236 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16237 | \n\ |
16238 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16239 | is executing in.\n" |
16240 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16241 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16242 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16243 | |
1bedd215 | 16244 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16245 | Set breakpoint at specified location.\n" |
31e2b00f | 16246 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16247 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16248 | |
c906108c SS |
16249 | add_com_alias ("b", "break", class_run, 1); |
16250 | add_com_alias ("br", "break", class_run, 1); | |
16251 | add_com_alias ("bre", "break", class_run, 1); | |
16252 | add_com_alias ("brea", "break", class_run, 1); | |
16253 | ||
c906108c SS |
16254 | if (dbx_commands) |
16255 | { | |
1bedd215 AC |
16256 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16257 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16258 | &stoplist, "stop ", 1, &cmdlist); |
16259 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16260 | _("Break in function or address."), &stoplist); |
c5aa993b | 16261 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16262 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16263 | add_com ("status", class_info, breakpoints_info, _("\ |
16264 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16265 | The \"Type\" column indicates one of:\n\ |
16266 | \tbreakpoint - normal breakpoint\n\ | |
16267 | \twatchpoint - watchpoint\n\ | |
16268 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16269 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16270 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16271 | address and file/line number respectively.\n\ |
16272 | \n\ | |
16273 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16274 | are set to the address of the last breakpoint listed unless the command\n\ |
16275 | is prefixed with \"server \".\n\n\ | |
c906108c | 16276 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16277 | breakpoint set.")); |
c906108c SS |
16278 | } |
16279 | ||
1bedd215 | 16280 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16281 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16282 | The \"Type\" column indicates one of:\n\ |
16283 | \tbreakpoint - normal breakpoint\n\ | |
16284 | \twatchpoint - watchpoint\n\ | |
16285 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16286 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16287 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16288 | address and file/line number respectively.\n\ |
16289 | \n\ | |
16290 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16291 | are set to the address of the last breakpoint listed unless the command\n\ |
16292 | is prefixed with \"server \".\n\n\ | |
c906108c | 16293 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16294 | breakpoint set.")); |
c906108c | 16295 | |
6b04bdb7 MS |
16296 | add_info_alias ("b", "breakpoints", 1); |
16297 | ||
1a966eab AC |
16298 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16299 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16300 | The \"Type\" column indicates one of:\n\ |
16301 | \tbreakpoint - normal breakpoint\n\ | |
16302 | \twatchpoint - watchpoint\n\ | |
16303 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16304 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16305 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16306 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16307 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16308 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16309 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16310 | address and file/line number respectively.\n\ |
16311 | \n\ | |
16312 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16313 | are set to the address of the last breakpoint listed unless the command\n\ |
16314 | is prefixed with \"server \".\n\n\ | |
c906108c | 16315 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16316 | breakpoint set."), |
c906108c SS |
16317 | &maintenanceinfolist); |
16318 | ||
44feb3ce TT |
16319 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16320 | Set catchpoints to catch events."), | |
16321 | &catch_cmdlist, "catch ", | |
16322 | 0/*allow-unknown*/, &cmdlist); | |
16323 | ||
16324 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16325 | Set temporary catchpoints to catch events."), | |
16326 | &tcatch_cmdlist, "tcatch ", | |
16327 | 0/*allow-unknown*/, &cmdlist); | |
16328 | ||
44feb3ce TT |
16329 | add_catch_command ("fork", _("Catch calls to fork."), |
16330 | catch_fork_command_1, | |
a96d9b2e | 16331 | NULL, |
44feb3ce TT |
16332 | (void *) (uintptr_t) catch_fork_permanent, |
16333 | (void *) (uintptr_t) catch_fork_temporary); | |
16334 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16335 | catch_fork_command_1, | |
a96d9b2e | 16336 | NULL, |
44feb3ce TT |
16337 | (void *) (uintptr_t) catch_vfork_permanent, |
16338 | (void *) (uintptr_t) catch_vfork_temporary); | |
16339 | add_catch_command ("exec", _("Catch calls to exec."), | |
16340 | catch_exec_command_1, | |
a96d9b2e SDJ |
16341 | NULL, |
16342 | CATCH_PERMANENT, | |
16343 | CATCH_TEMPORARY); | |
edcc5120 TT |
16344 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16345 | Usage: catch load [REGEX]\n\ | |
16346 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16347 | catch_load_command_1, | |
16348 | NULL, | |
16349 | CATCH_PERMANENT, | |
16350 | CATCH_TEMPORARY); | |
16351 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16352 | Usage: catch unload [REGEX]\n\ | |
16353 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16354 | catch_unload_command_1, | |
16355 | NULL, | |
16356 | CATCH_PERMANENT, | |
16357 | CATCH_TEMPORARY); | |
c5aa993b | 16358 | |
1bedd215 AC |
16359 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16360 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16361 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16362 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16363 | an expression changes.\n\ |
16364 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16365 | the memory to which it refers.")); | |
65d12d83 | 16366 | set_cmd_completer (c, expression_completer); |
c906108c | 16367 | |
1bedd215 AC |
16368 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16369 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16370 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16371 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16372 | an expression is read.\n\ |
16373 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16374 | the memory to which it refers.")); | |
65d12d83 | 16375 | set_cmd_completer (c, expression_completer); |
c906108c | 16376 | |
1bedd215 AC |
16377 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16378 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16379 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16380 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16381 | an expression is either read or written.\n\ |
16382 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16383 | the memory to which it refers.")); | |
65d12d83 | 16384 | set_cmd_completer (c, expression_completer); |
c906108c | 16385 | |
d77f58be | 16386 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16387 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16388 | |
920d2a44 AC |
16389 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16390 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16391 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16392 | &can_use_hw_watchpoints, _("\ | |
16393 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16394 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16395 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16396 | such is available. (However, any hardware watchpoints that were\n\ | |
16397 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16398 | hardware.)"), |
16399 | NULL, | |
920d2a44 | 16400 | show_can_use_hw_watchpoints, |
85c07804 | 16401 | &setlist, &showlist); |
c906108c SS |
16402 | |
16403 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16404 | |
1042e4c0 SS |
16405 | /* Tracepoint manipulation commands. */ |
16406 | ||
16407 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16408 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16409 | \n" |
16410 | BREAK_ARGS_HELP ("trace") "\n\ | |
16411 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16412 | set_cmd_completer (c, location_completer); | |
16413 | ||
16414 | add_com_alias ("tp", "trace", class_alias, 0); | |
16415 | add_com_alias ("tr", "trace", class_alias, 1); | |
16416 | add_com_alias ("tra", "trace", class_alias, 1); | |
16417 | add_com_alias ("trac", "trace", class_alias, 1); | |
16418 | ||
7a697b8d | 16419 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16420 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16421 | \n" |
16422 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16423 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16424 | set_cmd_completer (c, location_completer); | |
16425 | ||
0fb4aa4b | 16426 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16427 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16428 | \n\ |
16429 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16430 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16431 | or -m MARKER_ID.\n\n\ | |
16432 | If a marker id is specified, probe the marker with that name. With\n\ | |
16433 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16434 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16435 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16436 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16437 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16438 | \n\ | |
16439 | CONDITION is a boolean expression.\n\ | |
629500fa | 16440 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16441 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16442 | conditions are different.\n\ | |
0fb4aa4b PA |
16443 | \n\ |
16444 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16445 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16446 | set_cmd_completer (c, location_completer); | |
16447 | ||
1042e4c0 | 16448 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16449 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16450 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16451 | last tracepoint set.")); | |
16452 | ||
16453 | add_info_alias ("tp", "tracepoints", 1); | |
16454 | ||
16455 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16456 | Delete specified tracepoints.\n\ | |
16457 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16458 | No argument means delete all tracepoints."), | |
16459 | &deletelist); | |
7e20dfcd | 16460 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16461 | |
16462 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16463 | Disable specified tracepoints.\n\ | |
16464 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16465 | No argument means disable all tracepoints."), | |
16466 | &disablelist); | |
16467 | deprecate_cmd (c, "disable"); | |
16468 | ||
16469 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16470 | Enable specified tracepoints.\n\ | |
16471 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16472 | No argument means enable all tracepoints."), | |
16473 | &enablelist); | |
16474 | deprecate_cmd (c, "enable"); | |
16475 | ||
16476 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16477 | Set the passcount for a tracepoint.\n\ | |
16478 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16479 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16480 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16481 | ||
6149aea9 PA |
16482 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16483 | _("Save breakpoint definitions as a script."), | |
16484 | &save_cmdlist, "save ", | |
16485 | 0/*allow-unknown*/, &cmdlist); | |
16486 | ||
16487 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16488 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16489 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16490 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16491 | session to restore them."), | |
16492 | &save_cmdlist); | |
16493 | set_cmd_completer (c, filename_completer); | |
16494 | ||
16495 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16496 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16497 | Use the 'source' command in another debug session to restore them."), |
16498 | &save_cmdlist); | |
1042e4c0 SS |
16499 | set_cmd_completer (c, filename_completer); |
16500 | ||
6149aea9 PA |
16501 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16502 | deprecate_cmd (c, "save tracepoints"); | |
16503 | ||
1bedd215 | 16504 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16505 | Breakpoint specific settings\n\ |
16506 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16507 | pending breakpoint behavior"), |
fa8d40ab JJ |
16508 | &breakpoint_set_cmdlist, "set breakpoint ", |
16509 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16510 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16511 | Breakpoint specific settings\n\ |
16512 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16513 | pending breakpoint behavior"), |
fa8d40ab JJ |
16514 | &breakpoint_show_cmdlist, "show breakpoint ", |
16515 | 0/*allow-unknown*/, &showlist); | |
16516 | ||
7915a72c AC |
16517 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16518 | &pending_break_support, _("\ | |
16519 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16520 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16521 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16522 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16523 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16524 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16525 | NULL, |
920d2a44 | 16526 | show_pending_break_support, |
6e1d7d6c AC |
16527 | &breakpoint_set_cmdlist, |
16528 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16529 | |
16530 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16531 | |
16532 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16533 | &automatic_hardware_breakpoints, _("\ | |
16534 | Set automatic usage of hardware breakpoints."), _("\ | |
16535 | Show automatic usage of hardware breakpoints."), _("\ | |
16536 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16537 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16538 | a warning will be emitted for such breakpoints."), | |
16539 | NULL, | |
16540 | show_automatic_hardware_breakpoints, | |
16541 | &breakpoint_set_cmdlist, | |
16542 | &breakpoint_show_cmdlist); | |
74960c60 | 16543 | |
a25a5a45 PA |
16544 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16545 | &always_inserted_mode, _("\ | |
74960c60 VP |
16546 | Set mode for inserting breakpoints."), _("\ |
16547 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16548 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16549 | they're created, kept inserted even when execution stops, and removed\n\ | |
16550 | only when the user deletes them. When this mode is off (the default),\n\ | |
16551 | breakpoints are inserted only when execution continues, and removed\n\ | |
16552 | when execution stops."), | |
72d0e2c5 YQ |
16553 | NULL, |
16554 | &show_always_inserted_mode, | |
16555 | &breakpoint_set_cmdlist, | |
16556 | &breakpoint_show_cmdlist); | |
f1310107 | 16557 | |
b775012e LM |
16558 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16559 | condition_evaluation_enums, | |
16560 | &condition_evaluation_mode_1, _("\ | |
16561 | Set mode of breakpoint condition evaluation."), _("\ | |
16562 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16563 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16564 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16565 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16566 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16567 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16568 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16569 | be set to \"gdb\""), | |
16570 | &set_condition_evaluation_mode, | |
16571 | &show_condition_evaluation_mode, | |
16572 | &breakpoint_set_cmdlist, | |
16573 | &breakpoint_show_cmdlist); | |
16574 | ||
f1310107 TJB |
16575 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16576 | Set a breakpoint for an address range.\n\ | |
16577 | break-range START-LOCATION, END-LOCATION\n\ | |
16578 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16579 | LINENUM, for that line in the current file,\n\ | |
16580 | FILE:LINENUM, for that line in that file,\n\ | |
16581 | +OFFSET, for that number of lines after the current line\n\ | |
16582 | or the start of the range\n\ | |
16583 | FUNCTION, for the first line in that function,\n\ | |
16584 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16585 | *ADDRESS, for the instruction at that address.\n\ | |
16586 | \n\ | |
16587 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16588 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16589 | range (including START-LOCATION and END-LOCATION).")); | |
16590 | ||
e7e0cddf | 16591 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16592 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16593 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16594 | location may be a linespec, explicit, or address location.\n" |
16595 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16596 | set_cmd_completer (c, location_completer); |
16597 | ||
16598 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16599 | dprintf_style_enums, &dprintf_style, _("\ | |
16600 | Set the style of usage for dynamic printf."), _("\ | |
16601 | Show the style of usage for dynamic printf."), _("\ | |
16602 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16603 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16604 | console, as with the \"printf\" command.\n\ | |
16605 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16606 | program; by default printf(), but you can choose a different function or\n\ | |
16607 | output stream by setting dprintf-function and dprintf-channel."), | |
16608 | update_dprintf_commands, NULL, | |
16609 | &setlist, &showlist); | |
16610 | ||
16611 | dprintf_function = xstrdup ("printf"); | |
16612 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16613 | &dprintf_function, _("\ | |
16614 | Set the function to use for dynamic printf"), _("\ | |
16615 | Show the function to use for dynamic printf"), NULL, | |
16616 | update_dprintf_commands, NULL, | |
16617 | &setlist, &showlist); | |
16618 | ||
16619 | dprintf_channel = xstrdup (""); | |
16620 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16621 | &dprintf_channel, _("\ | |
16622 | Set the channel to use for dynamic printf"), _("\ | |
16623 | Show the channel to use for dynamic printf"), NULL, | |
16624 | update_dprintf_commands, NULL, | |
16625 | &setlist, &showlist); | |
16626 | ||
d3ce09f5 SS |
16627 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16628 | &disconnected_dprintf, _("\ | |
16629 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16630 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16631 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16632 | even if GDB disconnects or detaches from the target."), | |
16633 | NULL, | |
16634 | NULL, | |
16635 | &setlist, &showlist); | |
16636 | ||
16637 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16638 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16639 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16640 | ||
765dc015 | 16641 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16642 | |
16643 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16644 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16645 | } |