Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
618f726f | 3 | Copyright (C) 1986-2016 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" |
f00aae0f | 70 | #include "location.h" |
cfc31633 | 71 | #include "thread-fsm.h" |
5d5658a1 | 72 | #include "tid-parse.h" |
d3ce09f5 | 73 | |
1042e4c0 SS |
74 | /* readline include files */ |
75 | #include "readline/readline.h" | |
76 | #include "readline/history.h" | |
77 | ||
78 | /* readline defines this. */ | |
79 | #undef savestring | |
80 | ||
034dad6f | 81 | #include "mi/mi-common.h" |
6dddc817 | 82 | #include "extension.h" |
325fac50 | 83 | #include <algorithm> |
104c1213 | 84 | |
e7e8980f YQ |
85 | /* Enums for exception-handling support. */ |
86 | enum exception_event_kind | |
87 | { | |
88 | EX_EVENT_THROW, | |
591f19e8 | 89 | EX_EVENT_RETHROW, |
e7e8980f YQ |
90 | EX_EVENT_CATCH |
91 | }; | |
92 | ||
4a64f543 | 93 | /* Prototypes for local functions. */ |
c906108c | 94 | |
a14ed312 | 95 | static void enable_delete_command (char *, int); |
c906108c | 96 | |
a14ed312 | 97 | static void enable_once_command (char *, int); |
c906108c | 98 | |
816338b5 SS |
99 | static void enable_count_command (char *, int); |
100 | ||
a14ed312 | 101 | static void disable_command (char *, int); |
c906108c | 102 | |
a14ed312 | 103 | static void enable_command (char *, int); |
c906108c | 104 | |
95a42b64 TT |
105 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
106 | void *), | |
107 | void *); | |
c906108c | 108 | |
a14ed312 | 109 | static void ignore_command (char *, int); |
c906108c | 110 | |
4efb68b1 | 111 | static int breakpoint_re_set_one (void *); |
c906108c | 112 | |
348d480f PA |
113 | static void breakpoint_re_set_default (struct breakpoint *); |
114 | ||
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 | ||
347 | static char *dprintf_function = ""; | |
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 | ||
357 | static char *dprintf_channel = ""; | |
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 JK |
580 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
581 | for (BP_TMP = bp_location; \ | |
582 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
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 \ | |
595 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
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 | ||
876fa593 JK |
609 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
610 | ||
611 | static struct bp_location **bp_location; | |
612 | ||
613 | /* Number of elements of BP_LOCATION. */ | |
614 | ||
615 | static unsigned bp_location_count; | |
616 | ||
4a64f543 MS |
617 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
618 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
619 | result from bp_location_has_shadow. You can use it for roughly | |
620 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
621 | an address you need to read. */ | |
876fa593 JK |
622 | |
623 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
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 | |
627 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
628 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
629 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
630 | |
631 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 632 | |
4a64f543 MS |
633 | /* The locations that no longer correspond to any breakpoint, unlinked |
634 | from bp_location array, but for which a hit may still be reported | |
635 | 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 | |
923 | the more general bp_location_compare function. */ | |
924 | ||
925 | static int | |
926 | bp_location_compare_addrs (const void *ap, const void *bp) | |
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 SM |
954 | locp_found = ((struct bp_location **) |
955 | bsearch (&dummy_locp, bp_location, bp_location_count, | |
956 | sizeof (struct bp_location **), | |
957 | bp_location_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. */ | |
965 | while ((locp_found - 1) >= bp_location | |
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 | ||
983 | xfree (w->cond_exp); | |
984 | w->cond_exp = NULL; | |
985 | } | |
986 | else | |
987 | { | |
988 | struct bp_location *loc; | |
989 | ||
990 | for (loc = b->loc; loc; loc = loc->next) | |
991 | { | |
992 | xfree (loc->cond); | |
993 | loc->cond = NULL; | |
b775012e LM |
994 | |
995 | /* No need to free the condition agent expression | |
996 | bytecode (if we have one). We will handle this | |
997 | when we go through update_global_location_list. */ | |
3a5c3e22 | 998 | } |
adc36818 | 999 | } |
adc36818 PM |
1000 | |
1001 | if (*exp == 0) | |
1002 | { | |
1003 | if (from_tty) | |
1004 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1005 | } | |
1006 | else | |
1007 | { | |
bbc13ae3 | 1008 | const char *arg = exp; |
cc59ec59 | 1009 | |
adc36818 PM |
1010 | /* I don't know if it matters whether this is the string the user |
1011 | typed in or the decompiled expression. */ | |
1012 | b->cond_string = xstrdup (arg); | |
1013 | b->condition_not_parsed = 0; | |
1014 | ||
1015 | if (is_watchpoint (b)) | |
1016 | { | |
3a5c3e22 PA |
1017 | struct watchpoint *w = (struct watchpoint *) b; |
1018 | ||
adc36818 PM |
1019 | innermost_block = NULL; |
1020 | arg = exp; | |
1bb9788d | 1021 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1022 | if (*arg) |
1023 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1024 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1025 | } |
1026 | else | |
1027 | { | |
3a5c3e22 PA |
1028 | struct bp_location *loc; |
1029 | ||
adc36818 PM |
1030 | for (loc = b->loc; loc; loc = loc->next) |
1031 | { | |
1032 | arg = exp; | |
1033 | loc->cond = | |
1bb9788d TT |
1034 | parse_exp_1 (&arg, loc->address, |
1035 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1036 | if (*arg) |
1037 | error (_("Junk at end of expression")); | |
1038 | } | |
1039 | } | |
1040 | } | |
b775012e LM |
1041 | mark_breakpoint_modified (b); |
1042 | ||
8d3788bd | 1043 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1044 | } |
1045 | ||
d55637df TT |
1046 | /* Completion for the "condition" command. */ |
1047 | ||
1048 | static VEC (char_ptr) * | |
6f937416 PA |
1049 | condition_completer (struct cmd_list_element *cmd, |
1050 | const char *text, const char *word) | |
d55637df | 1051 | { |
6f937416 | 1052 | const char *space; |
d55637df | 1053 | |
6f937416 PA |
1054 | text = skip_spaces_const (text); |
1055 | space = skip_to_space_const (text); | |
d55637df TT |
1056 | if (*space == '\0') |
1057 | { | |
1058 | int len; | |
1059 | struct breakpoint *b; | |
1060 | VEC (char_ptr) *result = NULL; | |
1061 | ||
1062 | if (text[0] == '$') | |
1063 | { | |
1064 | /* We don't support completion of history indices. */ | |
1065 | if (isdigit (text[1])) | |
1066 | return NULL; | |
1067 | return complete_internalvar (&text[1]); | |
1068 | } | |
1069 | ||
1070 | /* We're completing the breakpoint number. */ | |
1071 | len = strlen (text); | |
1072 | ||
1073 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1074 | { |
1075 | char number[50]; | |
1076 | ||
1077 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1078 | ||
1079 | if (strncmp (number, text, len) == 0) | |
1080 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1081 | } | |
d55637df TT |
1082 | |
1083 | return result; | |
1084 | } | |
1085 | ||
1086 | /* We're completing the expression part. */ | |
6f937416 | 1087 | text = skip_spaces_const (space); |
d55637df TT |
1088 | return expression_completer (cmd, text, word); |
1089 | } | |
1090 | ||
c906108c SS |
1091 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1092 | ||
1093 | static void | |
fba45db2 | 1094 | condition_command (char *arg, int from_tty) |
c906108c | 1095 | { |
52f0bd74 | 1096 | struct breakpoint *b; |
c906108c | 1097 | char *p; |
52f0bd74 | 1098 | int bnum; |
c906108c SS |
1099 | |
1100 | if (arg == 0) | |
e2e0b3e5 | 1101 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1102 | |
1103 | p = arg; | |
1104 | bnum = get_number (&p); | |
5c44784c | 1105 | if (bnum == 0) |
8a3fe4f8 | 1106 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1107 | |
1108 | ALL_BREAKPOINTS (b) | |
1109 | if (b->number == bnum) | |
2f069f6f | 1110 | { |
6dddc817 DE |
1111 | /* Check if this breakpoint has a "stop" method implemented in an |
1112 | extension language. This method and conditions entered into GDB | |
1113 | from the CLI are mutually exclusive. */ | |
1114 | const struct extension_language_defn *extlang | |
1115 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1116 | ||
1117 | if (extlang != NULL) | |
1118 | { | |
1119 | error (_("Only one stop condition allowed. There is currently" | |
1120 | " a %s stop condition defined for this breakpoint."), | |
1121 | ext_lang_capitalized_name (extlang)); | |
1122 | } | |
2566ad2d | 1123 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1124 | |
1125 | if (is_breakpoint (b)) | |
44702360 | 1126 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1127 | |
2f069f6f JB |
1128 | return; |
1129 | } | |
c906108c | 1130 | |
8a3fe4f8 | 1131 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1132 | } |
1133 | ||
a7bdde9e VP |
1134 | /* Check that COMMAND do not contain commands that are suitable |
1135 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1136 | Throw if any such commands is found. */ |
1137 | ||
a7bdde9e VP |
1138 | static void |
1139 | check_no_tracepoint_commands (struct command_line *commands) | |
1140 | { | |
1141 | struct command_line *c; | |
cc59ec59 | 1142 | |
a7bdde9e VP |
1143 | for (c = commands; c; c = c->next) |
1144 | { | |
1145 | int i; | |
1146 | ||
1147 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1148 | error (_("The 'while-stepping' command can " |
1149 | "only be used for tracepoints")); | |
a7bdde9e VP |
1150 | |
1151 | for (i = 0; i < c->body_count; ++i) | |
1152 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1153 | ||
1154 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1155 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1156 | command directly. */ |
1157 | if (strstr (c->line, "collect ") == c->line) | |
1158 | error (_("The 'collect' command can only be used for tracepoints")); | |
1159 | ||
51661e93 VP |
1160 | if (strstr (c->line, "teval ") == c->line) |
1161 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1162 | } |
1163 | } | |
1164 | ||
d77f58be SS |
1165 | /* Encapsulate tests for different types of tracepoints. */ |
1166 | ||
d9b3f62e PA |
1167 | static int |
1168 | is_tracepoint_type (enum bptype type) | |
1169 | { | |
1170 | return (type == bp_tracepoint | |
1171 | || type == bp_fast_tracepoint | |
1172 | || type == bp_static_tracepoint); | |
1173 | } | |
1174 | ||
a7bdde9e | 1175 | int |
d77f58be | 1176 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1177 | { |
d9b3f62e | 1178 | return is_tracepoint_type (b->type); |
a7bdde9e | 1179 | } |
d9b3f62e | 1180 | |
e5dd4106 | 1181 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1182 | breakpoint. This function will throw an exception if a problem is |
1183 | found. */ | |
48cb2d85 | 1184 | |
95a42b64 TT |
1185 | static void |
1186 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1187 | struct command_line *commands) | |
48cb2d85 | 1188 | { |
d77f58be | 1189 | if (is_tracepoint (b)) |
a7bdde9e | 1190 | { |
c9a6ce02 | 1191 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1192 | struct command_line *c; |
1193 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1194 | |
1195 | /* Reset the while-stepping step count. The previous commands | |
1196 | might have included a while-stepping action, while the new | |
1197 | ones might not. */ | |
1198 | t->step_count = 0; | |
1199 | ||
1200 | /* We need to verify that each top-level element of commands is | |
1201 | valid for tracepoints, that there's at most one | |
1202 | while-stepping element, and that the while-stepping's body | |
1203 | has valid tracing commands excluding nested while-stepping. | |
1204 | We also need to validate the tracepoint action line in the | |
1205 | context of the tracepoint --- validate_actionline actually | |
1206 | has side effects, like setting the tracepoint's | |
1207 | while-stepping STEP_COUNT, in addition to checking if the | |
1208 | collect/teval actions parse and make sense in the | |
1209 | tracepoint's context. */ | |
a7bdde9e VP |
1210 | for (c = commands; c; c = c->next) |
1211 | { | |
a7bdde9e VP |
1212 | if (c->control_type == while_stepping_control) |
1213 | { | |
1214 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1215 | error (_("The 'while-stepping' command " |
1216 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1217 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1218 | error (_("The 'while-stepping' command " |
1219 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1220 | |
1221 | if (while_stepping) | |
3e43a32a MS |
1222 | error (_("The 'while-stepping' command " |
1223 | "can be used only once")); | |
a7bdde9e VP |
1224 | else |
1225 | while_stepping = c; | |
1226 | } | |
c9a6ce02 PA |
1227 | |
1228 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1229 | } |
1230 | if (while_stepping) | |
1231 | { | |
1232 | struct command_line *c2; | |
1233 | ||
1234 | gdb_assert (while_stepping->body_count == 1); | |
1235 | c2 = while_stepping->body_list[0]; | |
1236 | for (; c2; c2 = c2->next) | |
1237 | { | |
a7bdde9e VP |
1238 | if (c2->control_type == while_stepping_control) |
1239 | error (_("The 'while-stepping' command cannot be nested")); | |
1240 | } | |
1241 | } | |
1242 | } | |
1243 | else | |
1244 | { | |
1245 | check_no_tracepoint_commands (commands); | |
1246 | } | |
95a42b64 TT |
1247 | } |
1248 | ||
0fb4aa4b PA |
1249 | /* Return a vector of all the static tracepoints set at ADDR. The |
1250 | caller is responsible for releasing the vector. */ | |
1251 | ||
1252 | VEC(breakpoint_p) * | |
1253 | static_tracepoints_here (CORE_ADDR addr) | |
1254 | { | |
1255 | struct breakpoint *b; | |
1256 | VEC(breakpoint_p) *found = 0; | |
1257 | struct bp_location *loc; | |
1258 | ||
1259 | ALL_BREAKPOINTS (b) | |
1260 | if (b->type == bp_static_tracepoint) | |
1261 | { | |
1262 | for (loc = b->loc; loc; loc = loc->next) | |
1263 | if (loc->address == addr) | |
1264 | VEC_safe_push(breakpoint_p, found, b); | |
1265 | } | |
1266 | ||
1267 | return found; | |
1268 | } | |
1269 | ||
95a42b64 | 1270 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1271 | validate that only allowed commands are included. */ |
95a42b64 TT |
1272 | |
1273 | void | |
4a64f543 MS |
1274 | breakpoint_set_commands (struct breakpoint *b, |
1275 | struct command_line *commands) | |
95a42b64 TT |
1276 | { |
1277 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1278 | |
9add0f1b TT |
1279 | decref_counted_command_line (&b->commands); |
1280 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1281 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1282 | } |
1283 | ||
45a43567 TT |
1284 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1285 | is not the same as the "silent" that may appear in the breakpoint's | |
1286 | commands. */ | |
1287 | ||
1288 | void | |
1289 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1290 | { | |
1291 | int old_silent = b->silent; | |
1292 | ||
1293 | b->silent = silent; | |
1294 | if (old_silent != silent) | |
8d3788bd | 1295 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1296 | } |
1297 | ||
1298 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1299 | breakpoint work for any thread. */ | |
1300 | ||
1301 | void | |
1302 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1303 | { | |
1304 | int old_thread = b->thread; | |
1305 | ||
1306 | b->thread = thread; | |
1307 | if (old_thread != thread) | |
8d3788bd | 1308 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1309 | } |
1310 | ||
1311 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1312 | breakpoint work for any task. */ | |
1313 | ||
1314 | void | |
1315 | breakpoint_set_task (struct breakpoint *b, int task) | |
1316 | { | |
1317 | int old_task = b->task; | |
1318 | ||
1319 | b->task = task; | |
1320 | if (old_task != task) | |
8d3788bd | 1321 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1322 | } |
1323 | ||
95a42b64 TT |
1324 | void |
1325 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1326 | { |
9a3c8263 | 1327 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1328 | |
6f937416 | 1329 | validate_actionline (line, b); |
a7bdde9e VP |
1330 | } |
1331 | ||
95a42b64 TT |
1332 | /* A structure used to pass information through |
1333 | map_breakpoint_numbers. */ | |
1334 | ||
1335 | struct commands_info | |
1336 | { | |
1337 | /* True if the command was typed at a tty. */ | |
1338 | int from_tty; | |
86b17b60 PA |
1339 | |
1340 | /* The breakpoint range spec. */ | |
1341 | char *arg; | |
1342 | ||
95a42b64 TT |
1343 | /* Non-NULL if the body of the commands are being read from this |
1344 | already-parsed command. */ | |
1345 | struct command_line *control; | |
86b17b60 | 1346 | |
95a42b64 TT |
1347 | /* The command lines read from the user, or NULL if they have not |
1348 | yet been read. */ | |
1349 | struct counted_command_line *cmd; | |
1350 | }; | |
1351 | ||
1352 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1353 | commands_command. */ | |
1354 | ||
c906108c | 1355 | static void |
95a42b64 | 1356 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1357 | { |
9a3c8263 | 1358 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1359 | |
95a42b64 TT |
1360 | if (info->cmd == NULL) |
1361 | { | |
1362 | struct command_line *l; | |
5c44784c | 1363 | |
95a42b64 TT |
1364 | if (info->control != NULL) |
1365 | l = copy_command_lines (info->control->body_list[0]); | |
1366 | else | |
86b17b60 PA |
1367 | { |
1368 | struct cleanup *old_chain; | |
1369 | char *str; | |
c5aa993b | 1370 | |
3e43a32a MS |
1371 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1372 | "%s, one per line."), | |
86b17b60 PA |
1373 | info->arg); |
1374 | ||
1375 | old_chain = make_cleanup (xfree, str); | |
1376 | ||
1377 | l = read_command_lines (str, | |
1378 | info->from_tty, 1, | |
d77f58be | 1379 | (is_tracepoint (b) |
86b17b60 PA |
1380 | ? check_tracepoint_command : 0), |
1381 | b); | |
1382 | ||
1383 | do_cleanups (old_chain); | |
1384 | } | |
a7bdde9e | 1385 | |
95a42b64 TT |
1386 | info->cmd = alloc_counted_command_line (l); |
1387 | } | |
1388 | ||
1389 | /* If a breakpoint was on the list more than once, we don't need to | |
1390 | do anything. */ | |
1391 | if (b->commands != info->cmd) | |
1392 | { | |
1393 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1394 | incref_counted_command_line (info->cmd); | |
1395 | decref_counted_command_line (&b->commands); | |
1396 | b->commands = info->cmd; | |
8d3788bd | 1397 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1398 | } |
95a42b64 TT |
1399 | } |
1400 | ||
1401 | static void | |
4a64f543 MS |
1402 | commands_command_1 (char *arg, int from_tty, |
1403 | struct command_line *control) | |
95a42b64 TT |
1404 | { |
1405 | struct cleanup *cleanups; | |
1406 | struct commands_info info; | |
1407 | ||
1408 | info.from_tty = from_tty; | |
1409 | info.control = control; | |
1410 | info.cmd = NULL; | |
1411 | /* If we read command lines from the user, then `info' will hold an | |
1412 | extra reference to the commands that we must clean up. */ | |
1413 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1414 | ||
1415 | if (arg == NULL || !*arg) | |
1416 | { | |
86b17b60 | 1417 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1418 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1419 | breakpoint_count); | |
95a42b64 TT |
1420 | else if (breakpoint_count > 0) |
1421 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1422 | else |
1423 | { | |
1424 | /* So that we don't try to free the incoming non-NULL | |
1425 | argument in the cleanup below. Mapping breakpoint | |
1426 | numbers will fail in this case. */ | |
1427 | arg = NULL; | |
1428 | } | |
95a42b64 | 1429 | } |
9766ced4 SS |
1430 | else |
1431 | /* The command loop has some static state, so we need to preserve | |
1432 | our argument. */ | |
1433 | arg = xstrdup (arg); | |
86b17b60 PA |
1434 | |
1435 | if (arg != NULL) | |
1436 | make_cleanup (xfree, arg); | |
1437 | ||
1438 | info.arg = arg; | |
95a42b64 TT |
1439 | |
1440 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1441 | ||
1442 | if (info.cmd == NULL) | |
1443 | error (_("No breakpoints specified.")); | |
1444 | ||
1445 | do_cleanups (cleanups); | |
1446 | } | |
1447 | ||
1448 | static void | |
1449 | commands_command (char *arg, int from_tty) | |
1450 | { | |
1451 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1452 | } |
40c03ae8 EZ |
1453 | |
1454 | /* Like commands_command, but instead of reading the commands from | |
1455 | input stream, takes them from an already parsed command structure. | |
1456 | ||
1457 | This is used by cli-script.c to DTRT with breakpoint commands | |
1458 | that are part of if and while bodies. */ | |
1459 | enum command_control_type | |
1460 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1461 | { | |
95a42b64 TT |
1462 | commands_command_1 (arg, 0, cmd); |
1463 | return simple_control; | |
40c03ae8 | 1464 | } |
876fa593 JK |
1465 | |
1466 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1467 | ||
1468 | static int | |
1469 | bp_location_has_shadow (struct bp_location *bl) | |
1470 | { | |
1471 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1472 | return 0; | |
1473 | if (!bl->inserted) | |
1474 | return 0; | |
1475 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1476 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1477 | return 0; |
1478 | return 1; | |
1479 | } | |
1480 | ||
9d497a19 PA |
1481 | /* Update BUF, which is LEN bytes read from the target address |
1482 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1483 | contents. | |
1484 | ||
1485 | If READBUF is not NULL, this buffer must not overlap with the of | |
1486 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1487 | failed assertion internal error will be raised. */ | |
1488 | ||
1489 | static void | |
1490 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1491 | const gdb_byte *writebuf_org, | |
1492 | ULONGEST memaddr, LONGEST len, | |
1493 | struct bp_target_info *target_info, | |
1494 | struct gdbarch *gdbarch) | |
1495 | { | |
1496 | /* Now do full processing of the found relevant range of elements. */ | |
1497 | CORE_ADDR bp_addr = 0; | |
1498 | int bp_size = 0; | |
1499 | int bptoffset = 0; | |
1500 | ||
1501 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1502 | current_program_space->aspace, 0)) | |
1503 | { | |
1504 | /* The breakpoint is inserted in a different address space. */ | |
1505 | return; | |
1506 | } | |
1507 | ||
1508 | /* Addresses and length of the part of the breakpoint that | |
1509 | we need to copy. */ | |
1510 | bp_addr = target_info->placed_address; | |
1511 | bp_size = target_info->shadow_len; | |
1512 | ||
1513 | if (bp_addr + bp_size <= memaddr) | |
1514 | { | |
1515 | /* The breakpoint is entirely before the chunk of memory we are | |
1516 | reading. */ | |
1517 | return; | |
1518 | } | |
1519 | ||
1520 | if (bp_addr >= memaddr + len) | |
1521 | { | |
1522 | /* The breakpoint is entirely after the chunk of memory we are | |
1523 | reading. */ | |
1524 | return; | |
1525 | } | |
1526 | ||
1527 | /* Offset within shadow_contents. */ | |
1528 | if (bp_addr < memaddr) | |
1529 | { | |
1530 | /* Only copy the second part of the breakpoint. */ | |
1531 | bp_size -= memaddr - bp_addr; | |
1532 | bptoffset = memaddr - bp_addr; | |
1533 | bp_addr = memaddr; | |
1534 | } | |
1535 | ||
1536 | if (bp_addr + bp_size > memaddr + len) | |
1537 | { | |
1538 | /* Only copy the first part of the breakpoint. */ | |
1539 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1540 | } | |
1541 | ||
1542 | if (readbuf != NULL) | |
1543 | { | |
1544 | /* Verify that the readbuf buffer does not overlap with the | |
1545 | shadow_contents buffer. */ | |
1546 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1547 | || readbuf >= (target_info->shadow_contents | |
1548 | + target_info->shadow_len)); | |
1549 | ||
1550 | /* Update the read buffer with this inserted breakpoint's | |
1551 | shadow. */ | |
1552 | memcpy (readbuf + bp_addr - memaddr, | |
1553 | target_info->shadow_contents + bptoffset, bp_size); | |
1554 | } | |
1555 | else | |
1556 | { | |
1557 | const unsigned char *bp; | |
0d5ed153 MR |
1558 | CORE_ADDR addr = target_info->reqstd_address; |
1559 | int placed_size; | |
9d497a19 PA |
1560 | |
1561 | /* Update the shadow with what we want to write to memory. */ | |
1562 | memcpy (target_info->shadow_contents + bptoffset, | |
1563 | writebuf_org + bp_addr - memaddr, bp_size); | |
1564 | ||
1565 | /* Determine appropriate breakpoint contents and size for this | |
1566 | address. */ | |
0d5ed153 | 1567 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1568 | |
1569 | /* Update the final write buffer with this inserted | |
1570 | breakpoint's INSN. */ | |
1571 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1572 | } | |
1573 | } | |
1574 | ||
8defab1a | 1575 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1576 | by replacing any memory breakpoints with their shadowed contents. |
1577 | ||
35c63cd8 JB |
1578 | If READBUF is not NULL, this buffer must not overlap with any of |
1579 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1580 | a failed assertion internal error will be raised. | |
1581 | ||
876fa593 | 1582 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1583 | bl->address - bp_location_placed_address_before_address_max |
1584 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1585 | The range we were requested to resolve shadows for is: |
1586 | memaddr ... memaddr + len | |
1587 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1588 | memaddr + len <= (bl->address |
1589 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1590 | and: |
35df4500 | 1591 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1592 | |
8defab1a | 1593 | void |
f0ba3972 PA |
1594 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1595 | const gdb_byte *writebuf_org, | |
1596 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1597 | { |
4a64f543 MS |
1598 | /* Left boundary, right boundary and median element of our binary |
1599 | search. */ | |
876fa593 JK |
1600 | unsigned bc_l, bc_r, bc; |
1601 | ||
4a64f543 MS |
1602 | /* Find BC_L which is a leftmost element which may affect BUF |
1603 | content. It is safe to report lower value but a failure to | |
1604 | report higher one. */ | |
876fa593 JK |
1605 | |
1606 | bc_l = 0; | |
1607 | bc_r = bp_location_count; | |
1608 | while (bc_l + 1 < bc_r) | |
1609 | { | |
35df4500 | 1610 | struct bp_location *bl; |
876fa593 JK |
1611 | |
1612 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1613 | bl = bp_location[bc]; |
876fa593 | 1614 | |
4a64f543 MS |
1615 | /* Check first BL->ADDRESS will not overflow due to the added |
1616 | constant. Then advance the left boundary only if we are sure | |
1617 | the BC element can in no way affect the BUF content (MEMADDR | |
1618 | to MEMADDR + LEN range). | |
876fa593 | 1619 | |
4a64f543 MS |
1620 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1621 | offset so that we cannot miss a breakpoint with its shadow | |
1622 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1623 | |
35df4500 TJB |
1624 | if ((bl->address + bp_location_shadow_len_after_address_max |
1625 | >= bl->address) | |
1626 | && (bl->address + bp_location_shadow_len_after_address_max | |
1627 | <= memaddr)) | |
876fa593 JK |
1628 | bc_l = bc; |
1629 | else | |
1630 | bc_r = bc; | |
1631 | } | |
1632 | ||
128070bb PA |
1633 | /* Due to the binary search above, we need to make sure we pick the |
1634 | first location that's at BC_L's address. E.g., if there are | |
1635 | multiple locations at the same address, BC_L may end up pointing | |
1636 | at a duplicate location, and miss the "master"/"inserted" | |
1637 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1638 | B: | |
1639 | ||
1640 | L1@A, L2@A, L3@B, ... | |
1641 | ||
1642 | BC_L could end up pointing at location L2, while the "master" | |
1643 | location could be L1. Since the `loc->inserted' flag is only set | |
1644 | on "master" locations, we'd forget to restore the shadow of L1 | |
1645 | and L2. */ | |
1646 | while (bc_l > 0 | |
1647 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1648 | bc_l--; | |
1649 | ||
876fa593 JK |
1650 | /* Now do full processing of the found relevant range of elements. */ |
1651 | ||
1652 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1653 | { |
35df4500 | 1654 | struct bp_location *bl = bp_location[bc]; |
876fa593 | 1655 | |
35df4500 TJB |
1656 | /* bp_location array has BL->OWNER always non-NULL. */ |
1657 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1658 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1659 | bl->owner->number); |
ffce0d52 | 1660 | |
e5dd4106 | 1661 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1662 | content. */ |
1663 | ||
35df4500 TJB |
1664 | if (bl->address >= bp_location_placed_address_before_address_max |
1665 | && memaddr + len <= (bl->address | |
1666 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1667 | break; |
1668 | ||
35df4500 | 1669 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1670 | continue; |
6c95b8df | 1671 | |
9d497a19 PA |
1672 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1673 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1674 | } | |
c906108c | 1675 | } |
9d497a19 | 1676 | |
c906108c | 1677 | \f |
c5aa993b | 1678 | |
b775012e LM |
1679 | /* Return true if BPT is either a software breakpoint or a hardware |
1680 | breakpoint. */ | |
1681 | ||
1682 | int | |
1683 | is_breakpoint (const struct breakpoint *bpt) | |
1684 | { | |
1685 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1686 | || bpt->type == bp_hardware_breakpoint |
1687 | || bpt->type == bp_dprintf); | |
b775012e LM |
1688 | } |
1689 | ||
60e1c644 PA |
1690 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1691 | ||
a5606eee | 1692 | static int |
d77f58be | 1693 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1694 | { |
1695 | return (bpt->type == bp_hardware_watchpoint | |
1696 | || bpt->type == bp_read_watchpoint | |
1697 | || bpt->type == bp_access_watchpoint); | |
1698 | } | |
7270d8f2 | 1699 | |
60e1c644 PA |
1700 | /* Return true if BPT is of any watchpoint kind, hardware or |
1701 | software. */ | |
1702 | ||
3a5c3e22 | 1703 | int |
d77f58be | 1704 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1705 | { |
1706 | return (is_hardware_watchpoint (bpt) | |
1707 | || bpt->type == bp_watchpoint); | |
1708 | } | |
1709 | ||
3a5c3e22 PA |
1710 | /* Returns true if the current thread and its running state are safe |
1711 | to evaluate or update watchpoint B. Watchpoints on local | |
1712 | expressions need to be evaluated in the context of the thread that | |
1713 | was current when the watchpoint was created, and, that thread needs | |
1714 | to be stopped to be able to select the correct frame context. | |
1715 | Watchpoints on global expressions can be evaluated on any thread, | |
1716 | and in any state. It is presently left to the target allowing | |
1717 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1718 | |
1719 | static int | |
3a5c3e22 | 1720 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1721 | { |
d0d8b0c6 JK |
1722 | return (b->base.pspace == current_program_space |
1723 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1724 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1725 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1726 | } |
1727 | ||
d0fb5eae JK |
1728 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1729 | associated bp_watchpoint_scope breakpoint. */ | |
1730 | ||
1731 | static void | |
3a5c3e22 | 1732 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1733 | { |
3a5c3e22 | 1734 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1735 | |
1736 | if (b->related_breakpoint != b) | |
1737 | { | |
1738 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1739 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1740 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1741 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1742 | b->related_breakpoint = b; | |
1743 | } | |
1744 | b->disposition = disp_del_at_next_stop; | |
1745 | } | |
1746 | ||
bb9d5f81 PP |
1747 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1748 | watchpoint W. */ | |
1749 | ||
1750 | static struct value * | |
1751 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1752 | { | |
1753 | struct value *bit_val; | |
1754 | ||
1755 | if (val == NULL) | |
1756 | return NULL; | |
1757 | ||
1758 | bit_val = allocate_value (value_type (val)); | |
1759 | ||
1760 | unpack_value_bitfield (bit_val, | |
1761 | w->val_bitpos, | |
1762 | w->val_bitsize, | |
1763 | value_contents_for_printing (val), | |
1764 | value_offset (val), | |
1765 | val); | |
1766 | ||
1767 | return bit_val; | |
1768 | } | |
1769 | ||
c6d81124 PA |
1770 | /* Allocate a dummy location and add it to B, which must be a software |
1771 | watchpoint. This is required because even if a software watchpoint | |
1772 | is not watching any memory, bpstat_stop_status requires a location | |
1773 | to be able to report stops. */ | |
1774 | ||
1775 | static void | |
1776 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1777 | struct program_space *pspace) | |
1778 | { | |
1779 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1780 | ||
1781 | b->loc = allocate_bp_location (b); | |
1782 | b->loc->pspace = pspace; | |
1783 | b->loc->address = -1; | |
1784 | b->loc->length = -1; | |
1785 | } | |
1786 | ||
1787 | /* Returns true if B is a software watchpoint that is not watching any | |
1788 | memory (e.g., "watch $pc"). */ | |
1789 | ||
1790 | static int | |
1791 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1792 | { | |
1793 | return (b->type == bp_watchpoint | |
1794 | && b->loc != NULL | |
1795 | && b->loc->next == NULL | |
1796 | && b->loc->address == -1 | |
1797 | && b->loc->length == -1); | |
1798 | } | |
1799 | ||
567e1b4e JB |
1800 | /* Assuming that B is a watchpoint: |
1801 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1802 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1803 | - Evaluate the condition if there is one, and store the result |
1804 | in b->loc->cond. | |
a5606eee VP |
1805 | - Update the list of values that must be watched in B->loc. |
1806 | ||
4a64f543 MS |
1807 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1808 | nothing. If this is local watchpoint that is out of scope, delete | |
1809 | it. | |
1810 | ||
1811 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1812 | removed + inserted on each stop here. Normal breakpoints must | |
1813 | never be removed because they might be missed by a running thread | |
1814 | when debugging in non-stop mode. On the other hand, hardware | |
1815 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1816 | to each LWP since they are stored in each LWP's hardware debug | |
1817 | registers. Therefore, such LWP must be stopped first in order to | |
1818 | be able to modify its hardware watchpoints. | |
1819 | ||
1820 | Hardware watchpoints must be reset exactly once after being | |
1821 | presented to the user. It cannot be done sooner, because it would | |
1822 | reset the data used to present the watchpoint hit to the user. And | |
1823 | it must not be done later because it could display the same single | |
1824 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1825 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1826 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1827 | not user-visible - its hit is suppressed if the memory content has | |
1828 | not changed. | |
1829 | ||
1830 | The following constraints influence the location where we can reset | |
1831 | hardware watchpoints: | |
1832 | ||
1833 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1834 | called several times when GDB stops. | |
1835 | ||
1836 | [linux] | |
1837 | * Multiple hardware watchpoints can be hit at the same time, | |
1838 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1839 | hit at a time as the reason for stopping, and all the other hits | |
1840 | are presented later, one after the other, each time the user | |
1841 | requests the execution to be resumed. Execution is not resumed | |
1842 | for the threads still having pending hit event stored in | |
1843 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1844 | the inferior on the first stop the thread hit event is kept being | |
1845 | reported from its cached value by linux_nat_stopped_data_address | |
1846 | until the real thread resume happens after the watchpoint gets | |
1847 | presented and thus its LWP_INFO->STATUS gets reset. | |
1848 | ||
1849 | Therefore the hardware watchpoint hit can get safely reset on the | |
1850 | watchpoint removal from inferior. */ | |
a79d3c27 | 1851 | |
b40ce68a | 1852 | static void |
3a5c3e22 | 1853 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1854 | { |
a5606eee | 1855 | int within_current_scope; |
a5606eee | 1856 | struct frame_id saved_frame_id; |
66076460 | 1857 | int frame_saved; |
a5606eee | 1858 | |
f6bc2008 PA |
1859 | /* If this is a local watchpoint, we only want to check if the |
1860 | watchpoint frame is in scope if the current thread is the thread | |
1861 | that was used to create the watchpoint. */ | |
1862 | if (!watchpoint_in_thread_scope (b)) | |
1863 | return; | |
1864 | ||
3a5c3e22 | 1865 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1866 | return; |
1867 | ||
66076460 | 1868 | frame_saved = 0; |
a5606eee VP |
1869 | |
1870 | /* Determine if the watchpoint is within scope. */ | |
1871 | if (b->exp_valid_block == NULL) | |
1872 | within_current_scope = 1; | |
1873 | else | |
1874 | { | |
b5db5dfc UW |
1875 | struct frame_info *fi = get_current_frame (); |
1876 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1877 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1878 | ||
c9cf6e20 MG |
1879 | /* If we're at a point where the stack has been destroyed |
1880 | (e.g. in a function epilogue), unwinding may not work | |
1881 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1882 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1883 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1884 | return; |
66076460 DJ |
1885 | |
1886 | /* Save the current frame's ID so we can restore it after | |
1887 | evaluating the watchpoint expression on its own frame. */ | |
1888 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1889 | took a frame parameter, so that we didn't have to change the | |
1890 | selected frame. */ | |
1891 | frame_saved = 1; | |
1892 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1893 | ||
a5606eee VP |
1894 | fi = frame_find_by_id (b->watchpoint_frame); |
1895 | within_current_scope = (fi != NULL); | |
1896 | if (within_current_scope) | |
1897 | select_frame (fi); | |
1898 | } | |
1899 | ||
b5db5dfc UW |
1900 | /* We don't free locations. They are stored in the bp_location array |
1901 | and update_global_location_list will eventually delete them and | |
1902 | remove breakpoints if needed. */ | |
3a5c3e22 | 1903 | b->base.loc = NULL; |
b5db5dfc | 1904 | |
a5606eee VP |
1905 | if (within_current_scope && reparse) |
1906 | { | |
bbc13ae3 | 1907 | const char *s; |
d63d0675 | 1908 | |
a5606eee VP |
1909 | if (b->exp) |
1910 | { | |
1911 | xfree (b->exp); | |
1912 | b->exp = NULL; | |
1913 | } | |
d63d0675 | 1914 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1915 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1916 | /* If the meaning of expression itself changed, the old value is |
1917 | no longer relevant. We don't want to report a watchpoint hit | |
1918 | to the user when the old value and the new value may actually | |
1919 | be completely different objects. */ | |
1920 | value_free (b->val); | |
fa4727a6 DJ |
1921 | b->val = NULL; |
1922 | b->val_valid = 0; | |
60e1c644 PA |
1923 | |
1924 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1925 | expression is stored in the breakpoint object, not in the | |
1926 | locations (re)created below. */ | |
3a5c3e22 | 1927 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1928 | { |
1929 | if (b->cond_exp != NULL) | |
1930 | { | |
1931 | xfree (b->cond_exp); | |
1932 | b->cond_exp = NULL; | |
1933 | } | |
1934 | ||
3a5c3e22 | 1935 | s = b->base.cond_string; |
1bb9788d | 1936 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1937 | } |
a5606eee | 1938 | } |
a5606eee VP |
1939 | |
1940 | /* If we failed to parse the expression, for example because | |
1941 | it refers to a global variable in a not-yet-loaded shared library, | |
1942 | don't try to insert watchpoint. We don't automatically delete | |
1943 | such watchpoint, though, since failure to parse expression | |
1944 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1945 | if (!target_has_execution) |
2d134ed3 PA |
1946 | { |
1947 | /* Without execution, memory can't change. No use to try and | |
1948 | set watchpoint locations. The watchpoint will be reset when | |
1949 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1950 | if (!can_use_hw_watchpoints) |
1951 | { | |
1952 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1953 | b->base.type = bp_watchpoint; | |
1954 | else | |
638aa5a1 AB |
1955 | error (_("Can't set read/access watchpoint when " |
1956 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1957 | } |
2d134ed3 PA |
1958 | } |
1959 | else if (within_current_scope && b->exp) | |
a5606eee | 1960 | { |
0cf6dd15 | 1961 | int pc = 0; |
fa4727a6 | 1962 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1963 | struct program_space *frame_pspace; |
a5606eee | 1964 | |
3a1115a0 | 1965 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1966 | |
a5606eee VP |
1967 | /* Avoid setting b->val if it's already set. The meaning of |
1968 | b->val is 'the last value' user saw, and we should update | |
1969 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1970 | happens, the code that reports it updates b->val directly. |
1971 | We don't keep track of the memory value for masked | |
1972 | watchpoints. */ | |
3a5c3e22 | 1973 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1974 | { |
bb9d5f81 PP |
1975 | if (b->val_bitsize != 0) |
1976 | { | |
1977 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1978 | if (v != NULL) | |
1979 | release_value (v); | |
1980 | } | |
fa4727a6 DJ |
1981 | b->val = v; |
1982 | b->val_valid = 1; | |
1983 | } | |
a5606eee | 1984 | |
2d134ed3 PA |
1985 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1986 | ||
a5606eee | 1987 | /* Look at each value on the value chain. */ |
9fa40276 | 1988 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1989 | { |
1990 | /* If it's a memory location, and GDB actually needed | |
1991 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1992 | must watch it. If the first value returned is |
1993 | still lazy, that means an error occurred reading it; | |
1994 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1995 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1996 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1997 | { |
1998 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1999 | |
a5606eee VP |
2000 | /* We only watch structs and arrays if user asked |
2001 | for it explicitly, never if they just happen to | |
2002 | appear in the middle of some value chain. */ | |
fa4727a6 | 2003 | if (v == result |
a5606eee VP |
2004 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
2005 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
2006 | { | |
2007 | CORE_ADDR addr; | |
f486487f | 2008 | enum target_hw_bp_type type; |
a5606eee | 2009 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
2010 | int bitpos = 0, bitsize = 0; |
2011 | ||
2012 | if (value_bitsize (v) != 0) | |
2013 | { | |
2014 | /* Extract the bit parameters out from the bitfield | |
2015 | sub-expression. */ | |
2016 | bitpos = value_bitpos (v); | |
2017 | bitsize = value_bitsize (v); | |
2018 | } | |
2019 | else if (v == result && b->val_bitsize != 0) | |
2020 | { | |
2021 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2022 | lvalue whose bit parameters are saved in the fields | |
2023 | VAL_BITPOS and VAL_BITSIZE. */ | |
2024 | bitpos = b->val_bitpos; | |
2025 | bitsize = b->val_bitsize; | |
2026 | } | |
a5606eee | 2027 | |
42ae5230 | 2028 | addr = value_address (v); |
bb9d5f81 PP |
2029 | if (bitsize != 0) |
2030 | { | |
2031 | /* Skip the bytes that don't contain the bitfield. */ | |
2032 | addr += bitpos / 8; | |
2033 | } | |
2034 | ||
a5606eee | 2035 | type = hw_write; |
3a5c3e22 | 2036 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2037 | type = hw_read; |
3a5c3e22 | 2038 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2039 | type = hw_access; |
3a5c3e22 PA |
2040 | |
2041 | loc = allocate_bp_location (&b->base); | |
2042 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2043 | ; |
2044 | *tmp = loc; | |
a6d9a66e | 2045 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2046 | |
2047 | loc->pspace = frame_pspace; | |
a5606eee | 2048 | loc->address = addr; |
bb9d5f81 PP |
2049 | |
2050 | if (bitsize != 0) | |
2051 | { | |
2052 | /* Just cover the bytes that make up the bitfield. */ | |
2053 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2054 | } | |
2055 | else | |
2056 | loc->length = TYPE_LENGTH (value_type (v)); | |
2057 | ||
a5606eee VP |
2058 | loc->watchpoint_type = type; |
2059 | } | |
2060 | } | |
9fa40276 TJB |
2061 | } |
2062 | ||
2063 | /* Change the type of breakpoint between hardware assisted or | |
2064 | an ordinary watchpoint depending on the hardware support | |
2065 | and free hardware slots. REPARSE is set when the inferior | |
2066 | is started. */ | |
a9634178 | 2067 | if (reparse) |
9fa40276 | 2068 | { |
e09342b5 | 2069 | int reg_cnt; |
9fa40276 TJB |
2070 | enum bp_loc_type loc_type; |
2071 | struct bp_location *bl; | |
a5606eee | 2072 | |
a9634178 | 2073 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2074 | |
2075 | if (reg_cnt) | |
9fa40276 TJB |
2076 | { |
2077 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2078 | enum bptype type; |
9fa40276 | 2079 | |
a9634178 TJB |
2080 | /* Use an exact watchpoint when there's only one memory region to be |
2081 | watched, and only one debug register is needed to watch it. */ | |
2082 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2083 | ||
9fa40276 | 2084 | /* We need to determine how many resources are already |
e09342b5 TJB |
2085 | used for all other hardware watchpoints plus this one |
2086 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2087 | this watchpoint in as well. */ |
2088 | ||
2089 | /* If this is a software watchpoint, we try to turn it | |
2090 | to a hardware one -- count resources as if B was of | |
2091 | hardware watchpoint type. */ | |
2092 | type = b->base.type; | |
2093 | if (type == bp_watchpoint) | |
2094 | type = bp_hardware_watchpoint; | |
2095 | ||
2096 | /* This watchpoint may or may not have been placed on | |
2097 | the list yet at this point (it won't be in the list | |
2098 | if we're trying to create it for the first time, | |
2099 | through watch_command), so always account for it | |
2100 | manually. */ | |
2101 | ||
2102 | /* Count resources used by all watchpoints except B. */ | |
2103 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2104 | ||
2105 | /* Add in the resources needed for B. */ | |
2106 | i += hw_watchpoint_use_count (&b->base); | |
2107 | ||
2108 | target_resources_ok | |
2109 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2110 | if (target_resources_ok <= 0) |
a9634178 | 2111 | { |
3a5c3e22 | 2112 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2113 | |
2114 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2115 | error (_("Target does not support this type of " |
2116 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2117 | else if (target_resources_ok < 0 && !sw_mode) |
2118 | error (_("There are not enough available hardware " | |
2119 | "resources for this watchpoint.")); | |
a1398e0c PA |
2120 | |
2121 | /* Downgrade to software watchpoint. */ | |
2122 | b->base.type = bp_watchpoint; | |
2123 | } | |
2124 | else | |
2125 | { | |
2126 | /* If this was a software watchpoint, we've just | |
2127 | found we have enough resources to turn it to a | |
2128 | hardware watchpoint. Otherwise, this is a | |
2129 | nop. */ | |
2130 | b->base.type = type; | |
a9634178 | 2131 | } |
9fa40276 | 2132 | } |
3a5c3e22 | 2133 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2134 | { |
2135 | if (!can_use_hw_watchpoints) | |
2136 | error (_("Can't set read/access watchpoint when " | |
2137 | "hardware watchpoints are disabled.")); | |
2138 | else | |
2139 | error (_("Expression cannot be implemented with " | |
2140 | "read/access watchpoint.")); | |
2141 | } | |
9fa40276 | 2142 | else |
3a5c3e22 | 2143 | b->base.type = bp_watchpoint; |
9fa40276 | 2144 | |
3a5c3e22 | 2145 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2146 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2147 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2148 | bl->loc_type = loc_type; |
2149 | } | |
2150 | ||
2151 | for (v = val_chain; v; v = next) | |
2152 | { | |
a5606eee VP |
2153 | next = value_next (v); |
2154 | if (v != b->val) | |
2155 | value_free (v); | |
2156 | } | |
2157 | ||
c7437ca6 PA |
2158 | /* If a software watchpoint is not watching any memory, then the |
2159 | above left it without any location set up. But, | |
2160 | bpstat_stop_status requires a location to be able to report | |
2161 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2162 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c6d81124 | 2163 | software_watchpoint_add_no_memory_location (&b->base, frame_pspace); |
a5606eee VP |
2164 | } |
2165 | else if (!within_current_scope) | |
7270d8f2 | 2166 | { |
ac74f770 MS |
2167 | printf_filtered (_("\ |
2168 | Watchpoint %d deleted because the program has left the block\n\ | |
2169 | in which its expression is valid.\n"), | |
3a5c3e22 | 2170 | b->base.number); |
d0fb5eae | 2171 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2172 | } |
a5606eee VP |
2173 | |
2174 | /* Restore the selected frame. */ | |
66076460 DJ |
2175 | if (frame_saved) |
2176 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2177 | } |
2178 | ||
a5606eee | 2179 | |
74960c60 | 2180 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2181 | inserted in the inferior. We don't differentiate the type of BL's owner |
2182 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2183 | breakpoint_ops is not defined, because in insert_bp_location, | |
2184 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2185 | static int |
35df4500 | 2186 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2187 | { |
35df4500 | 2188 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2189 | return 0; |
2190 | ||
35df4500 | 2191 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2192 | return 0; |
2193 | ||
35df4500 | 2194 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2195 | return 0; |
2196 | ||
f8eba3c6 TT |
2197 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2198 | return 0; | |
2199 | ||
56710373 PA |
2200 | /* This is set for example, when we're attached to the parent of a |
2201 | vfork, and have detached from the child. The child is running | |
2202 | free, and we expect it to do an exec or exit, at which point the | |
2203 | OS makes the parent schedulable again (and the target reports | |
2204 | that the vfork is done). Until the child is done with the shared | |
2205 | memory region, do not insert breakpoints in the parent, otherwise | |
2206 | the child could still trip on the parent's breakpoints. Since | |
2207 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2208 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2209 | return 0; |
2210 | ||
31e77af2 | 2211 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2212 | location, except if the breakpoint is a single-step breakpoint, |
2213 | and the breakpoint's thread is the thread which is stepping past | |
2214 | a breakpoint. */ | |
31e77af2 PA |
2215 | if ((bl->loc_type == bp_loc_software_breakpoint |
2216 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2217 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2218 | bl->address) |
2219 | /* The single-step breakpoint may be inserted at the location | |
2220 | we're trying to step if the instruction branches to itself. | |
2221 | However, the instruction won't be executed at all and it may | |
2222 | break the semantics of the instruction, for example, the | |
2223 | instruction is a conditional branch or updates some flags. | |
2224 | We can't fix it unless GDB is able to emulate the instruction | |
2225 | or switch to displaced stepping. */ | |
2226 | && !(bl->owner->type == bp_single_step | |
2227 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2228 | { |
2229 | if (debug_infrun) | |
2230 | { | |
2231 | fprintf_unfiltered (gdb_stdlog, | |
2232 | "infrun: skipping breakpoint: " | |
2233 | "stepping past insn at: %s\n", | |
2234 | paddress (bl->gdbarch, bl->address)); | |
2235 | } | |
2236 | return 0; | |
2237 | } | |
31e77af2 | 2238 | |
963f9c80 PA |
2239 | /* Don't insert watchpoints if we're trying to step past the |
2240 | instruction that triggered one. */ | |
2241 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2242 | && stepping_past_nonsteppable_watchpoint ()) | |
2243 | { | |
2244 | if (debug_infrun) | |
2245 | { | |
2246 | fprintf_unfiltered (gdb_stdlog, | |
2247 | "infrun: stepping past non-steppable watchpoint. " | |
2248 | "skipping watchpoint at %s:%d\n", | |
2249 | paddress (bl->gdbarch, bl->address), | |
2250 | bl->length); | |
2251 | } | |
2252 | return 0; | |
2253 | } | |
2254 | ||
74960c60 VP |
2255 | return 1; |
2256 | } | |
2257 | ||
934709f0 PW |
2258 | /* Same as should_be_inserted but does the check assuming |
2259 | that the location is not duplicated. */ | |
2260 | ||
2261 | static int | |
2262 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2263 | { | |
2264 | int result; | |
2265 | const int save_duplicate = bl->duplicate; | |
2266 | ||
2267 | bl->duplicate = 0; | |
2268 | result = should_be_inserted (bl); | |
2269 | bl->duplicate = save_duplicate; | |
2270 | return result; | |
2271 | } | |
2272 | ||
b775012e LM |
2273 | /* Parses a conditional described by an expression COND into an |
2274 | agent expression bytecode suitable for evaluation | |
2275 | by the bytecode interpreter. Return NULL if there was | |
2276 | any error during parsing. */ | |
2277 | ||
2278 | static struct agent_expr * | |
2279 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2280 | { | |
2281 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2282 | |
2283 | if (!cond) | |
2284 | return NULL; | |
2285 | ||
2286 | /* We don't want to stop processing, so catch any errors | |
2287 | that may show up. */ | |
492d29ea | 2288 | TRY |
b775012e LM |
2289 | { |
2290 | aexpr = gen_eval_for_expr (scope, cond); | |
2291 | } | |
2292 | ||
492d29ea | 2293 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2294 | { |
2295 | /* If we got here, it means the condition could not be parsed to a valid | |
2296 | bytecode expression and thus can't be evaluated on the target's side. | |
2297 | It's no use iterating through the conditions. */ | |
2298 | return NULL; | |
2299 | } | |
492d29ea | 2300 | END_CATCH |
b775012e LM |
2301 | |
2302 | /* We have a valid agent expression. */ | |
2303 | return aexpr; | |
2304 | } | |
2305 | ||
2306 | /* Based on location BL, create a list of breakpoint conditions to be | |
2307 | passed on to the target. If we have duplicated locations with different | |
2308 | conditions, we will add such conditions to the list. The idea is that the | |
2309 | target will evaluate the list of conditions and will only notify GDB when | |
2310 | one of them is true. */ | |
2311 | ||
2312 | static void | |
2313 | build_target_condition_list (struct bp_location *bl) | |
2314 | { | |
2315 | struct bp_location **locp = NULL, **loc2p; | |
2316 | int null_condition_or_parse_error = 0; | |
2317 | int modified = bl->needs_update; | |
2318 | struct bp_location *loc; | |
2319 | ||
8b4f3082 PA |
2320 | /* Release conditions left over from a previous insert. */ |
2321 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2322 | ||
b775012e LM |
2323 | /* This is only meaningful if the target is |
2324 | evaluating conditions and if the user has | |
2325 | opted for condition evaluation on the target's | |
2326 | side. */ | |
2327 | if (gdb_evaluates_breakpoint_condition_p () | |
2328 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2329 | return; | |
2330 | ||
2331 | /* Do a first pass to check for locations with no assigned | |
2332 | conditions or conditions that fail to parse to a valid agent expression | |
2333 | bytecode. If any of these happen, then it's no use to send conditions | |
2334 | to the target since this location will always trigger and generate a | |
2335 | response back to GDB. */ | |
2336 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2337 | { | |
2338 | loc = (*loc2p); | |
2339 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2340 | { | |
2341 | if (modified) | |
2342 | { | |
2343 | struct agent_expr *aexpr; | |
2344 | ||
2345 | /* Re-parse the conditions since something changed. In that | |
2346 | case we already freed the condition bytecodes (see | |
2347 | force_breakpoint_reinsertion). We just | |
2348 | need to parse the condition to bytecodes again. */ | |
2349 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2350 | loc->cond_bytecode = aexpr; | |
b775012e LM |
2351 | } |
2352 | ||
2353 | /* If we have a NULL bytecode expression, it means something | |
2354 | went wrong or we have a null condition expression. */ | |
2355 | if (!loc->cond_bytecode) | |
2356 | { | |
2357 | null_condition_or_parse_error = 1; | |
2358 | break; | |
2359 | } | |
2360 | } | |
2361 | } | |
2362 | ||
2363 | /* If any of these happened, it means we will have to evaluate the conditions | |
2364 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2365 | for all the other duplicate locations, thus we free all of them here. | |
2366 | ||
2367 | This is so we have a finer control over which locations' conditions are | |
2368 | being evaluated by GDB or the remote stub. */ | |
2369 | if (null_condition_or_parse_error) | |
2370 | { | |
2371 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2372 | { | |
2373 | loc = (*loc2p); | |
2374 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2375 | { | |
2376 | /* Only go as far as the first NULL bytecode is | |
2377 | located. */ | |
2378 | if (!loc->cond_bytecode) | |
2379 | return; | |
2380 | ||
2381 | free_agent_expr (loc->cond_bytecode); | |
2382 | loc->cond_bytecode = NULL; | |
2383 | } | |
2384 | } | |
2385 | } | |
2386 | ||
2387 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2388 | for this location's address. */ | |
2389 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2390 | { | |
2391 | loc = (*loc2p); | |
2392 | if (loc->cond | |
2393 | && is_breakpoint (loc->owner) | |
2394 | && loc->pspace->num == bl->pspace->num | |
2395 | && loc->owner->enable_state == bp_enabled | |
2396 | && loc->enabled) | |
2397 | /* Add the condition to the vector. This will be used later to send the | |
2398 | conditions to the target. */ | |
2399 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2400 | loc->cond_bytecode); | |
2401 | } | |
2402 | ||
2403 | return; | |
2404 | } | |
2405 | ||
d3ce09f5 SS |
2406 | /* Parses a command described by string CMD into an agent expression |
2407 | bytecode suitable for evaluation by the bytecode interpreter. | |
2408 | Return NULL if there was any error during parsing. */ | |
2409 | ||
2410 | static struct agent_expr * | |
2411 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2412 | { | |
2413 | struct cleanup *old_cleanups = 0; | |
2414 | struct expression *expr, **argvec; | |
2415 | struct agent_expr *aexpr = NULL; | |
bbc13ae3 KS |
2416 | const char *cmdrest; |
2417 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2418 | struct format_piece *fpieces; |
2419 | int nargs; | |
2420 | struct gdbarch *gdbarch = get_current_arch (); | |
2421 | ||
2422 | if (!cmd) | |
2423 | return NULL; | |
2424 | ||
2425 | cmdrest = cmd; | |
2426 | ||
2427 | if (*cmdrest == ',') | |
2428 | ++cmdrest; | |
bbc13ae3 | 2429 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2430 | |
2431 | if (*cmdrest++ != '"') | |
2432 | error (_("No format string following the location")); | |
2433 | ||
2434 | format_start = cmdrest; | |
2435 | ||
2436 | fpieces = parse_format_string (&cmdrest); | |
2437 | ||
2438 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2439 | ||
2440 | format_end = cmdrest; | |
2441 | ||
2442 | if (*cmdrest++ != '"') | |
2443 | error (_("Bad format string, non-terminated '\"'.")); | |
2444 | ||
bbc13ae3 | 2445 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2446 | |
2447 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2448 | error (_("Invalid argument syntax")); | |
2449 | ||
2450 | if (*cmdrest == ',') | |
2451 | cmdrest++; | |
bbc13ae3 | 2452 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2453 | |
2454 | /* For each argument, make an expression. */ | |
2455 | ||
2456 | argvec = (struct expression **) alloca (strlen (cmd) | |
2457 | * sizeof (struct expression *)); | |
2458 | ||
2459 | nargs = 0; | |
2460 | while (*cmdrest != '\0') | |
2461 | { | |
bbc13ae3 | 2462 | const char *cmd1; |
d3ce09f5 SS |
2463 | |
2464 | cmd1 = cmdrest; | |
2465 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2466 | argvec[nargs++] = expr; | |
2467 | cmdrest = cmd1; | |
2468 | if (*cmdrest == ',') | |
2469 | ++cmdrest; | |
2470 | } | |
2471 | ||
2472 | /* We don't want to stop processing, so catch any errors | |
2473 | that may show up. */ | |
492d29ea | 2474 | TRY |
d3ce09f5 SS |
2475 | { |
2476 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2477 | format_start, format_end - format_start, | |
2478 | fpieces, nargs, argvec); | |
2479 | } | |
492d29ea | 2480 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2481 | { |
2482 | /* If we got here, it means the command could not be parsed to a valid | |
2483 | bytecode expression and thus can't be evaluated on the target's side. | |
2484 | It's no use iterating through the other commands. */ | |
492d29ea | 2485 | aexpr = NULL; |
d3ce09f5 | 2486 | } |
492d29ea PA |
2487 | END_CATCH |
2488 | ||
2489 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2490 | |
d3ce09f5 SS |
2491 | /* We have a valid agent expression, return it. */ |
2492 | return aexpr; | |
2493 | } | |
2494 | ||
2495 | /* Based on location BL, create a list of breakpoint commands to be | |
2496 | passed on to the target. If we have duplicated locations with | |
2497 | different commands, we will add any such to the list. */ | |
2498 | ||
2499 | static void | |
2500 | build_target_command_list (struct bp_location *bl) | |
2501 | { | |
2502 | struct bp_location **locp = NULL, **loc2p; | |
2503 | int null_command_or_parse_error = 0; | |
2504 | int modified = bl->needs_update; | |
2505 | struct bp_location *loc; | |
2506 | ||
8b4f3082 PA |
2507 | /* Release commands left over from a previous insert. */ |
2508 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2509 | ||
41fac0cf | 2510 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2511 | return; |
2512 | ||
41fac0cf PA |
2513 | /* For now, limit to agent-style dprintf breakpoints. */ |
2514 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2515 | return; |
2516 | ||
41fac0cf PA |
2517 | /* For now, if we have any duplicate location that isn't a dprintf, |
2518 | don't install the target-side commands, as that would make the | |
2519 | breakpoint not be reported to the core, and we'd lose | |
2520 | control. */ | |
2521 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2522 | { | |
2523 | loc = (*loc2p); | |
2524 | if (is_breakpoint (loc->owner) | |
2525 | && loc->pspace->num == bl->pspace->num | |
2526 | && loc->owner->type != bp_dprintf) | |
2527 | return; | |
2528 | } | |
2529 | ||
d3ce09f5 SS |
2530 | /* Do a first pass to check for locations with no assigned |
2531 | conditions or conditions that fail to parse to a valid agent expression | |
2532 | bytecode. If any of these happen, then it's no use to send conditions | |
2533 | to the target since this location will always trigger and generate a | |
2534 | response back to GDB. */ | |
2535 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2536 | { | |
2537 | loc = (*loc2p); | |
2538 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2539 | { | |
2540 | if (modified) | |
2541 | { | |
2542 | struct agent_expr *aexpr; | |
2543 | ||
2544 | /* Re-parse the commands since something changed. In that | |
2545 | case we already freed the command bytecodes (see | |
2546 | force_breakpoint_reinsertion). We just | |
2547 | need to parse the command to bytecodes again. */ | |
2548 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2549 | loc->owner->extra_string); | |
2550 | loc->cmd_bytecode = aexpr; | |
d3ce09f5 SS |
2551 | } |
2552 | ||
2553 | /* If we have a NULL bytecode expression, it means something | |
2554 | went wrong or we have a null command expression. */ | |
2555 | if (!loc->cmd_bytecode) | |
2556 | { | |
2557 | null_command_or_parse_error = 1; | |
2558 | break; | |
2559 | } | |
2560 | } | |
2561 | } | |
2562 | ||
2563 | /* If anything failed, then we're not doing target-side commands, | |
2564 | and so clean up. */ | |
2565 | if (null_command_or_parse_error) | |
2566 | { | |
2567 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2568 | { | |
2569 | loc = (*loc2p); | |
2570 | if (is_breakpoint (loc->owner) | |
2571 | && loc->pspace->num == bl->pspace->num) | |
2572 | { | |
2573 | /* Only go as far as the first NULL bytecode is | |
2574 | located. */ | |
40fb6c5e | 2575 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2576 | return; |
2577 | ||
40fb6c5e HZ |
2578 | free_agent_expr (loc->cmd_bytecode); |
2579 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2580 | } |
2581 | } | |
2582 | } | |
2583 | ||
2584 | /* No NULL commands or failed bytecode generation. Build a command list | |
2585 | for this location's address. */ | |
2586 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2587 | { | |
2588 | loc = (*loc2p); | |
2589 | if (loc->owner->extra_string | |
2590 | && is_breakpoint (loc->owner) | |
2591 | && loc->pspace->num == bl->pspace->num | |
2592 | && loc->owner->enable_state == bp_enabled | |
2593 | && loc->enabled) | |
2594 | /* Add the command to the vector. This will be used later | |
2595 | to send the commands to the target. */ | |
2596 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2597 | loc->cmd_bytecode); | |
2598 | } | |
2599 | ||
2600 | bl->target_info.persist = 0; | |
2601 | /* Maybe flag this location as persistent. */ | |
2602 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2603 | bl->target_info.persist = 1; | |
2604 | } | |
2605 | ||
35df4500 TJB |
2606 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2607 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2608 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2609 | Returns 0 for success, 1 if the bp_location type is not supported or |
2610 | -1 for failure. | |
879bfdc2 | 2611 | |
4a64f543 MS |
2612 | NOTE drow/2003-09-09: This routine could be broken down to an |
2613 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2614 | static int |
35df4500 | 2615 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2616 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2617 | int *disabled_breaks, |
dd61ec5c MW |
2618 | int *hw_breakpoint_error, |
2619 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2620 | { |
0000e5cc PA |
2621 | enum errors bp_err = GDB_NO_ERROR; |
2622 | const char *bp_err_message = NULL; | |
879bfdc2 | 2623 | |
b775012e | 2624 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2625 | return 0; |
2626 | ||
35c63cd8 JB |
2627 | /* Note we don't initialize bl->target_info, as that wipes out |
2628 | the breakpoint location's shadow_contents if the breakpoint | |
2629 | is still inserted at that location. This in turn breaks | |
2630 | target_read_memory which depends on these buffers when | |
2631 | a memory read is requested at the breakpoint location: | |
2632 | Once the target_info has been wiped, we fail to see that | |
2633 | we have a breakpoint inserted at that address and thus | |
2634 | read the breakpoint instead of returning the data saved in | |
2635 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2636 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2637 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2638 | bl->target_info.length = bl->length; |
8181d85f | 2639 | |
b775012e LM |
2640 | /* When working with target-side conditions, we must pass all the conditions |
2641 | for the same breakpoint address down to the target since GDB will not | |
2642 | insert those locations. With a list of breakpoint conditions, the target | |
2643 | can decide when to stop and notify GDB. */ | |
2644 | ||
2645 | if (is_breakpoint (bl->owner)) | |
2646 | { | |
2647 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2648 | build_target_command_list (bl); |
2649 | /* Reset the modification marker. */ | |
b775012e LM |
2650 | bl->needs_update = 0; |
2651 | } | |
2652 | ||
35df4500 TJB |
2653 | if (bl->loc_type == bp_loc_software_breakpoint |
2654 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2655 | { |
35df4500 | 2656 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2657 | { |
2658 | /* If the explicitly specified breakpoint type | |
2659 | is not hardware breakpoint, check the memory map to see | |
2660 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2661 | |
765dc015 VP |
2662 | Two important cases are: |
2663 | - location type is not hardware breakpoint, memory | |
2664 | is readonly. We change the type of the location to | |
2665 | hardware breakpoint. | |
4a64f543 MS |
2666 | - location type is hardware breakpoint, memory is |
2667 | read-write. This means we've previously made the | |
2668 | location hardware one, but then the memory map changed, | |
2669 | so we undo. | |
765dc015 | 2670 | |
4a64f543 MS |
2671 | When breakpoints are removed, remove_breakpoints will use |
2672 | location types we've just set here, the only possible | |
2673 | problem is that memory map has changed during running | |
2674 | program, but it's not going to work anyway with current | |
2675 | gdb. */ | |
765dc015 | 2676 | struct mem_region *mr |
0d5ed153 | 2677 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2678 | |
2679 | if (mr) | |
2680 | { | |
2681 | if (automatic_hardware_breakpoints) | |
2682 | { | |
765dc015 VP |
2683 | enum bp_loc_type new_type; |
2684 | ||
2685 | if (mr->attrib.mode != MEM_RW) | |
2686 | new_type = bp_loc_hardware_breakpoint; | |
2687 | else | |
2688 | new_type = bp_loc_software_breakpoint; | |
2689 | ||
35df4500 | 2690 | if (new_type != bl->loc_type) |
765dc015 VP |
2691 | { |
2692 | static int said = 0; | |
cc59ec59 | 2693 | |
35df4500 | 2694 | bl->loc_type = new_type; |
765dc015 VP |
2695 | if (!said) |
2696 | { | |
3e43a32a MS |
2697 | fprintf_filtered (gdb_stdout, |
2698 | _("Note: automatically using " | |
2699 | "hardware breakpoints for " | |
2700 | "read-only addresses.\n")); | |
765dc015 VP |
2701 | said = 1; |
2702 | } | |
2703 | } | |
2704 | } | |
35df4500 | 2705 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2706 | && mr->attrib.mode != MEM_RW) |
2707 | { | |
2708 | fprintf_unfiltered (tmp_error_stream, | |
2709 | _("Cannot insert breakpoint %d.\n" | |
2710 | "Cannot set software breakpoint " | |
2711 | "at read-only address %s\n"), | |
2712 | bl->owner->number, | |
2713 | paddress (bl->gdbarch, bl->address)); | |
2714 | return 1; | |
2715 | } | |
765dc015 VP |
2716 | } |
2717 | } | |
2718 | ||
879bfdc2 DJ |
2719 | /* First check to see if we have to handle an overlay. */ |
2720 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2721 | || bl->section == NULL |
2722 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2723 | { |
2724 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2725 | TRY |
dd61ec5c | 2726 | { |
0000e5cc PA |
2727 | int val; |
2728 | ||
dd61ec5c | 2729 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2730 | if (val) |
2731 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2732 | } |
492d29ea | 2733 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2734 | { |
0000e5cc PA |
2735 | bp_err = e.error; |
2736 | bp_err_message = e.message; | |
dd61ec5c | 2737 | } |
492d29ea | 2738 | END_CATCH |
879bfdc2 DJ |
2739 | } |
2740 | else | |
2741 | { | |
4a64f543 | 2742 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2743 | Shall we set a breakpoint at the LMA? */ |
2744 | if (!overlay_events_enabled) | |
2745 | { | |
2746 | /* Yes -- overlay event support is not active, | |
2747 | so we must try to set a breakpoint at the LMA. | |
2748 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2749 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2750 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2751 | bl->owner->number); |
879bfdc2 DJ |
2752 | else |
2753 | { | |
35df4500 TJB |
2754 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2755 | bl->section); | |
879bfdc2 | 2756 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2757 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2758 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2759 | |
2760 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2761 | TRY |
0000e5cc PA |
2762 | { |
2763 | int val; | |
2764 | ||
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 LM |
3062 | |
3063 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3064 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3065 | ||
3066 | /* Explicitly mark the warning -- this will only be printed if | |
3067 | there was an error. */ | |
3068 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3069 | ||
3070 | save_current_space_and_thread (); | |
3071 | ||
3072 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3073 | { | |
3074 | /* We only want to update software breakpoints and hardware | |
3075 | breakpoints. */ | |
3076 | if (!is_breakpoint (bl->owner)) | |
3077 | continue; | |
3078 | ||
3079 | /* We only want to update locations that are already inserted | |
3080 | and need updating. This is to avoid unwanted insertion during | |
3081 | deletion of breakpoints. */ | |
3082 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3083 | continue; | |
3084 | ||
3085 | switch_to_program_space_and_thread (bl->pspace); | |
3086 | ||
3087 | /* For targets that support global breakpoints, there's no need | |
3088 | to select an inferior to insert breakpoint to. In fact, even | |
3089 | if we aren't attached to any process yet, we should still | |
3090 | insert breakpoints. */ | |
f5656ead | 3091 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3092 | && ptid_equal (inferior_ptid, null_ptid)) |
3093 | continue; | |
3094 | ||
3095 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3096 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3097 | if (val) |
3098 | error_flag = val; | |
3099 | } | |
3100 | ||
3101 | if (error_flag) | |
3102 | { | |
3103 | target_terminal_ours_for_output (); | |
3104 | error_stream (tmp_error_stream); | |
3105 | } | |
3106 | ||
3107 | do_cleanups (cleanups); | |
3108 | } | |
3109 | ||
c30eee59 | 3110 | /* Used when starting or continuing the program. */ |
c906108c | 3111 | |
74960c60 VP |
3112 | static void |
3113 | insert_breakpoint_locations (void) | |
c906108c | 3114 | { |
a5606eee | 3115 | struct breakpoint *bpt; |
35df4500 | 3116 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3117 | int error_flag = 0; |
c906108c | 3118 | int val = 0; |
3fbb6ffa | 3119 | int disabled_breaks = 0; |
81d0cc19 | 3120 | int hw_breakpoint_error = 0; |
dd61ec5c | 3121 | int hw_bp_error_explained_already = 0; |
c906108c | 3122 | |
81d0cc19 | 3123 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3124 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3125 | |
81d0cc19 GS |
3126 | /* Explicitly mark the warning -- this will only be printed if |
3127 | there was an error. */ | |
3128 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3129 | |
3130 | save_current_space_and_thread (); | |
3131 | ||
35df4500 | 3132 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3133 | { |
b775012e | 3134 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3135 | continue; |
3136 | ||
4a64f543 MS |
3137 | /* There is no point inserting thread-specific breakpoints if |
3138 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3139 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3140 | if (bl->owner->thread != -1 |
5d5658a1 | 3141 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3142 | continue; |
3143 | ||
35df4500 | 3144 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3145 | |
3146 | /* For targets that support global breakpoints, there's no need | |
3147 | to select an inferior to insert breakpoint to. In fact, even | |
3148 | if we aren't attached to any process yet, we should still | |
3149 | insert breakpoints. */ | |
f5656ead | 3150 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3151 | && ptid_equal (inferior_ptid, null_ptid)) |
3152 | continue; | |
3153 | ||
3fbb6ffa | 3154 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3155 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3156 | if (val) |
eacd795a | 3157 | error_flag = val; |
879bfdc2 | 3158 | } |
c906108c | 3159 | |
4a64f543 MS |
3160 | /* If we failed to insert all locations of a watchpoint, remove |
3161 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3162 | ALL_BREAKPOINTS (bpt) |
3163 | { | |
3164 | int some_failed = 0; | |
3165 | struct bp_location *loc; | |
3166 | ||
3167 | if (!is_hardware_watchpoint (bpt)) | |
3168 | continue; | |
3169 | ||
d6b74ac4 | 3170 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3171 | continue; |
74960c60 VP |
3172 | |
3173 | if (bpt->disposition == disp_del_at_next_stop) | |
3174 | continue; | |
a5606eee VP |
3175 | |
3176 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3177 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3178 | { |
3179 | some_failed = 1; | |
3180 | break; | |
3181 | } | |
3182 | if (some_failed) | |
3183 | { | |
3184 | for (loc = bpt->loc; loc; loc = loc->next) | |
3185 | if (loc->inserted) | |
834c0d03 | 3186 | remove_breakpoint (loc); |
a5606eee VP |
3187 | |
3188 | hw_breakpoint_error = 1; | |
3189 | fprintf_unfiltered (tmp_error_stream, | |
3190 | "Could not insert hardware watchpoint %d.\n", | |
3191 | bpt->number); | |
eacd795a | 3192 | error_flag = -1; |
a5606eee VP |
3193 | } |
3194 | } | |
3195 | ||
eacd795a | 3196 | if (error_flag) |
81d0cc19 GS |
3197 | { |
3198 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3199 | message about possibly exhausted resources. */ | |
dd61ec5c | 3200 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3201 | { |
c6510018 MS |
3202 | fprintf_unfiltered (tmp_error_stream, |
3203 | "Could not insert hardware breakpoints:\n\ | |
3204 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3205 | } |
81d0cc19 GS |
3206 | target_terminal_ours_for_output (); |
3207 | error_stream (tmp_error_stream); | |
3208 | } | |
f7545552 TT |
3209 | |
3210 | do_cleanups (cleanups); | |
c906108c SS |
3211 | } |
3212 | ||
c30eee59 TJB |
3213 | /* Used when the program stops. |
3214 | Returns zero if successful, or non-zero if there was a problem | |
3215 | removing a breakpoint location. */ | |
3216 | ||
c906108c | 3217 | int |
fba45db2 | 3218 | remove_breakpoints (void) |
c906108c | 3219 | { |
35df4500 | 3220 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3221 | int val = 0; |
c906108c | 3222 | |
35df4500 | 3223 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3224 | { |
1e4d1764 | 3225 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3226 | val |= remove_breakpoint (bl); |
c5aa993b | 3227 | } |
3a1bae8e | 3228 | return val; |
c906108c SS |
3229 | } |
3230 | ||
49fa26b0 PA |
3231 | /* When a thread exits, remove breakpoints that are related to |
3232 | that thread. */ | |
3233 | ||
3234 | static void | |
3235 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3236 | { | |
3237 | struct breakpoint *b, *b_tmp; | |
3238 | ||
3239 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3240 | { | |
5d5658a1 | 3241 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3242 | { |
3243 | b->disposition = disp_del_at_next_stop; | |
3244 | ||
3245 | printf_filtered (_("\ | |
43792cf0 PA |
3246 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3247 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3248 | |
3249 | /* Hide it from the user. */ | |
3250 | b->number = 0; | |
3251 | } | |
3252 | } | |
3253 | } | |
3254 | ||
6c95b8df PA |
3255 | /* Remove breakpoints of process PID. */ |
3256 | ||
3257 | int | |
3258 | remove_breakpoints_pid (int pid) | |
3259 | { | |
35df4500 | 3260 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3261 | int val; |
3262 | struct inferior *inf = find_inferior_pid (pid); | |
3263 | ||
35df4500 | 3264 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3265 | { |
35df4500 | 3266 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3267 | continue; |
3268 | ||
fc126975 | 3269 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3270 | { |
834c0d03 | 3271 | val = remove_breakpoint (bl); |
6c95b8df PA |
3272 | if (val != 0) |
3273 | return val; | |
3274 | } | |
3275 | } | |
3276 | return 0; | |
3277 | } | |
3278 | ||
c906108c | 3279 | int |
fba45db2 | 3280 | reattach_breakpoints (int pid) |
c906108c | 3281 | { |
6c95b8df | 3282 | struct cleanup *old_chain; |
35df4500 | 3283 | struct bp_location *bl, **blp_tmp; |
c906108c | 3284 | int val; |
86b887df | 3285 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3286 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3287 | struct inferior *inf; |
3288 | struct thread_info *tp; | |
3289 | ||
3290 | tp = any_live_thread_of_process (pid); | |
3291 | if (tp == NULL) | |
3292 | return 1; | |
3293 | ||
3294 | inf = find_inferior_pid (pid); | |
3295 | old_chain = save_inferior_ptid (); | |
3296 | ||
3297 | inferior_ptid = tp->ptid; | |
a4954f26 | 3298 | |
86b887df | 3299 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3300 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3301 | |
35df4500 | 3302 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3303 | { |
35df4500 | 3304 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3305 | continue; |
3306 | ||
35df4500 | 3307 | if (bl->inserted) |
c5aa993b | 3308 | { |
35df4500 | 3309 | bl->inserted = 0; |
dd61ec5c | 3310 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3311 | if (val != 0) |
3312 | { | |
ce696e05 | 3313 | do_cleanups (old_chain); |
c5aa993b JM |
3314 | return val; |
3315 | } | |
3316 | } | |
3317 | } | |
ce696e05 | 3318 | do_cleanups (old_chain); |
c906108c SS |
3319 | return 0; |
3320 | } | |
3321 | ||
e58b0e63 PA |
3322 | static int internal_breakpoint_number = -1; |
3323 | ||
84f4c1fe PM |
3324 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3325 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3326 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3327 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3328 | breakpoint_count and that value incremented. Internal breakpoints |
3329 | do not set the internal var bpnum. */ | |
3330 | static void | |
3331 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3332 | { | |
3333 | if (internal) | |
3334 | b->number = internal_breakpoint_number--; | |
3335 | else | |
3336 | { | |
3337 | set_breakpoint_count (breakpoint_count + 1); | |
3338 | b->number = breakpoint_count; | |
3339 | } | |
3340 | } | |
3341 | ||
e62c965a | 3342 | static struct breakpoint * |
a6d9a66e | 3343 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3344 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3345 | const struct breakpoint_ops *ops) |
e62c965a | 3346 | { |
e62c965a PP |
3347 | struct symtab_and_line sal; |
3348 | struct breakpoint *b; | |
3349 | ||
4a64f543 | 3350 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3351 | |
3352 | sal.pc = address; | |
3353 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3354 | sal.pspace = current_program_space; |
e62c965a | 3355 | |
06edf0c0 | 3356 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3357 | b->number = internal_breakpoint_number--; |
3358 | b->disposition = disp_donttouch; | |
3359 | ||
3360 | return b; | |
3361 | } | |
3362 | ||
17450429 PP |
3363 | static const char *const longjmp_names[] = |
3364 | { | |
3365 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3366 | }; | |
3367 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3368 | ||
3369 | /* Per-objfile data private to breakpoint.c. */ | |
3370 | struct breakpoint_objfile_data | |
3371 | { | |
3372 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3373 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3374 | |
3375 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3376 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3377 | |
28106bc2 SDJ |
3378 | /* True if we have looked for longjmp probes. */ |
3379 | int longjmp_searched; | |
3380 | ||
3381 | /* SystemTap probe points for longjmp (if any). */ | |
3382 | VEC (probe_p) *longjmp_probes; | |
3383 | ||
17450429 | 3384 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3385 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3386 | |
3387 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3388 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3389 | |
3390 | /* True if we have looked for exception probes. */ | |
3391 | int exception_searched; | |
3392 | ||
3393 | /* SystemTap probe points for unwinding (if any). */ | |
3394 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3395 | }; |
3396 | ||
3397 | static const struct objfile_data *breakpoint_objfile_key; | |
3398 | ||
3399 | /* Minimal symbol not found sentinel. */ | |
3400 | static struct minimal_symbol msym_not_found; | |
3401 | ||
3402 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3403 | ||
3404 | static int | |
3405 | msym_not_found_p (const struct minimal_symbol *msym) | |
3406 | { | |
3407 | return msym == &msym_not_found; | |
3408 | } | |
3409 | ||
3410 | /* Return per-objfile data needed by breakpoint.c. | |
3411 | Allocate the data if necessary. */ | |
3412 | ||
3413 | static struct breakpoint_objfile_data * | |
3414 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3415 | { | |
3416 | struct breakpoint_objfile_data *bp_objfile_data; | |
3417 | ||
9a3c8263 SM |
3418 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3419 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3420 | if (bp_objfile_data == NULL) |
3421 | { | |
8d749320 SM |
3422 | bp_objfile_data = |
3423 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3424 | |
3425 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3426 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3427 | } | |
3428 | return bp_objfile_data; | |
3429 | } | |
3430 | ||
28106bc2 SDJ |
3431 | static void |
3432 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3433 | { | |
9a3c8263 SM |
3434 | struct breakpoint_objfile_data *bp_objfile_data |
3435 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3436 | |
3437 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3438 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3439 | } | |
3440 | ||
e62c965a | 3441 | static void |
af02033e | 3442 | create_overlay_event_breakpoint (void) |
e62c965a | 3443 | { |
69de3c6a | 3444 | struct objfile *objfile; |
af02033e | 3445 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3446 | |
69de3c6a PP |
3447 | ALL_OBJFILES (objfile) |
3448 | { | |
3449 | struct breakpoint *b; | |
17450429 PP |
3450 | struct breakpoint_objfile_data *bp_objfile_data; |
3451 | CORE_ADDR addr; | |
67994074 | 3452 | struct explicit_location explicit_loc; |
69de3c6a | 3453 | |
17450429 PP |
3454 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3455 | ||
3b7344d5 | 3456 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3457 | continue; |
3458 | ||
3b7344d5 | 3459 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3460 | { |
3b7344d5 | 3461 | struct bound_minimal_symbol m; |
17450429 PP |
3462 | |
3463 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3464 | if (m.minsym == NULL) |
17450429 PP |
3465 | { |
3466 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3467 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3468 | continue; |
3469 | } | |
3470 | bp_objfile_data->overlay_msym = m; | |
3471 | } | |
e62c965a | 3472 | |
77e371c0 | 3473 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3474 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3475 | bp_overlay_event, |
3476 | &internal_breakpoint_ops); | |
67994074 KS |
3477 | initialize_explicit_location (&explicit_loc); |
3478 | explicit_loc.function_name = ASTRDUP (func_name); | |
3479 | b->location = new_explicit_location (&explicit_loc); | |
e62c965a | 3480 | |
69de3c6a PP |
3481 | if (overlay_debugging == ovly_auto) |
3482 | { | |
3483 | b->enable_state = bp_enabled; | |
3484 | overlay_events_enabled = 1; | |
3485 | } | |
3486 | else | |
3487 | { | |
3488 | b->enable_state = bp_disabled; | |
3489 | overlay_events_enabled = 0; | |
3490 | } | |
e62c965a | 3491 | } |
e62c965a PP |
3492 | } |
3493 | ||
0fd8e87f | 3494 | static void |
af02033e | 3495 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3496 | { |
6c95b8df | 3497 | struct program_space *pspace; |
6c95b8df PA |
3498 | struct cleanup *old_chain; |
3499 | ||
3500 | old_chain = save_current_program_space (); | |
0fd8e87f | 3501 | |
6c95b8df | 3502 | ALL_PSPACES (pspace) |
af02033e PP |
3503 | { |
3504 | struct objfile *objfile; | |
3505 | ||
3506 | set_current_program_space (pspace); | |
3507 | ||
3508 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3509 | { |
af02033e PP |
3510 | int i; |
3511 | struct gdbarch *gdbarch; | |
17450429 | 3512 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3513 | |
af02033e | 3514 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3515 | |
17450429 PP |
3516 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3517 | ||
28106bc2 SDJ |
3518 | if (!bp_objfile_data->longjmp_searched) |
3519 | { | |
25f9533e SDJ |
3520 | VEC (probe_p) *ret; |
3521 | ||
3522 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3523 | if (ret != NULL) | |
3524 | { | |
3525 | /* We are only interested in checking one element. */ | |
3526 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3527 | ||
3528 | if (!can_evaluate_probe_arguments (p)) | |
3529 | { | |
3530 | /* We cannot use the probe interface here, because it does | |
3531 | not know how to evaluate arguments. */ | |
3532 | VEC_free (probe_p, ret); | |
3533 | ret = NULL; | |
3534 | } | |
3535 | } | |
3536 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3537 | bp_objfile_data->longjmp_searched = 1; |
3538 | } | |
3539 | ||
3540 | if (bp_objfile_data->longjmp_probes != NULL) | |
3541 | { | |
3542 | int i; | |
3543 | struct probe *probe; | |
3544 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3545 | ||
3546 | for (i = 0; | |
3547 | VEC_iterate (probe_p, | |
3548 | bp_objfile_data->longjmp_probes, | |
3549 | i, probe); | |
3550 | ++i) | |
3551 | { | |
3552 | struct breakpoint *b; | |
3553 | ||
729662a5 TT |
3554 | b = create_internal_breakpoint (gdbarch, |
3555 | get_probe_address (probe, | |
3556 | objfile), | |
28106bc2 SDJ |
3557 | bp_longjmp_master, |
3558 | &internal_breakpoint_ops); | |
5b56227b KS |
3559 | b->location |
3560 | = new_probe_location ("-probe-stap libc:longjmp"); | |
28106bc2 SDJ |
3561 | b->enable_state = bp_disabled; |
3562 | } | |
3563 | ||
3564 | continue; | |
3565 | } | |
3566 | ||
0569175e TSD |
3567 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3568 | continue; | |
3569 | ||
17450429 | 3570 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3571 | { |
3572 | struct breakpoint *b; | |
af02033e | 3573 | const char *func_name; |
17450429 | 3574 | CORE_ADDR addr; |
67994074 | 3575 | struct explicit_location explicit_loc; |
6c95b8df | 3576 | |
3b7344d5 | 3577 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3578 | continue; |
0fd8e87f | 3579 | |
17450429 | 3580 | func_name = longjmp_names[i]; |
3b7344d5 | 3581 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3582 | { |
3b7344d5 | 3583 | struct bound_minimal_symbol m; |
17450429 PP |
3584 | |
3585 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3586 | if (m.minsym == NULL) |
17450429 PP |
3587 | { |
3588 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3589 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3590 | continue; |
3591 | } | |
3592 | bp_objfile_data->longjmp_msym[i] = m; | |
3593 | } | |
3594 | ||
77e371c0 | 3595 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3596 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3597 | &internal_breakpoint_ops); | |
67994074 KS |
3598 | initialize_explicit_location (&explicit_loc); |
3599 | explicit_loc.function_name = ASTRDUP (func_name); | |
3600 | b->location = new_explicit_location (&explicit_loc); | |
af02033e PP |
3601 | b->enable_state = bp_disabled; |
3602 | } | |
0fd8e87f | 3603 | } |
af02033e | 3604 | } |
6c95b8df PA |
3605 | |
3606 | do_cleanups (old_chain); | |
0fd8e87f UW |
3607 | } |
3608 | ||
af02033e | 3609 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3610 | static void |
af02033e | 3611 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3612 | { |
3613 | struct program_space *pspace; | |
aa7d318d | 3614 | struct cleanup *old_chain; |
af02033e | 3615 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3616 | |
3617 | old_chain = save_current_program_space (); | |
3618 | ||
3619 | ALL_PSPACES (pspace) | |
17450429 PP |
3620 | { |
3621 | struct objfile *objfile; | |
3622 | CORE_ADDR addr; | |
3623 | ||
3624 | set_current_program_space (pspace); | |
3625 | ||
aa7d318d TT |
3626 | ALL_OBJFILES (objfile) |
3627 | { | |
3628 | struct breakpoint *b; | |
17450429 | 3629 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3630 | struct explicit_location explicit_loc; |
aa7d318d | 3631 | |
17450429 | 3632 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3633 | |
3b7344d5 | 3634 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3635 | continue; |
3636 | ||
3b7344d5 | 3637 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3638 | { |
3b7344d5 | 3639 | struct bound_minimal_symbol m; |
17450429 PP |
3640 | |
3641 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3642 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3643 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3644 | { |
3645 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3646 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3647 | continue; |
3648 | } | |
3649 | bp_objfile_data->terminate_msym = m; | |
3650 | } | |
aa7d318d | 3651 | |
77e371c0 | 3652 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3653 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3654 | bp_std_terminate_master, |
3655 | &internal_breakpoint_ops); | |
67994074 KS |
3656 | initialize_explicit_location (&explicit_loc); |
3657 | explicit_loc.function_name = ASTRDUP (func_name); | |
3658 | b->location = new_explicit_location (&explicit_loc); | |
aa7d318d TT |
3659 | b->enable_state = bp_disabled; |
3660 | } | |
17450429 PP |
3661 | } |
3662 | ||
aa7d318d TT |
3663 | do_cleanups (old_chain); |
3664 | } | |
3665 | ||
186c406b TT |
3666 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3667 | ||
70221824 | 3668 | static void |
186c406b TT |
3669 | create_exception_master_breakpoint (void) |
3670 | { | |
3671 | struct objfile *objfile; | |
17450429 | 3672 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3673 | |
3674 | ALL_OBJFILES (objfile) | |
3675 | { | |
17450429 PP |
3676 | struct breakpoint *b; |
3677 | struct gdbarch *gdbarch; | |
3678 | struct breakpoint_objfile_data *bp_objfile_data; | |
3679 | CORE_ADDR addr; | |
67994074 | 3680 | struct explicit_location explicit_loc; |
17450429 PP |
3681 | |
3682 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3683 | ||
28106bc2 SDJ |
3684 | /* We prefer the SystemTap probe point if it exists. */ |
3685 | if (!bp_objfile_data->exception_searched) | |
3686 | { | |
25f9533e SDJ |
3687 | VEC (probe_p) *ret; |
3688 | ||
3689 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3690 | ||
3691 | if (ret != NULL) | |
3692 | { | |
3693 | /* We are only interested in checking one element. */ | |
3694 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3695 | ||
3696 | if (!can_evaluate_probe_arguments (p)) | |
3697 | { | |
3698 | /* We cannot use the probe interface here, because it does | |
3699 | not know how to evaluate arguments. */ | |
3700 | VEC_free (probe_p, ret); | |
3701 | ret = NULL; | |
3702 | } | |
3703 | } | |
3704 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3705 | bp_objfile_data->exception_searched = 1; |
3706 | } | |
3707 | ||
3708 | if (bp_objfile_data->exception_probes != NULL) | |
3709 | { | |
3710 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3711 | int i; | |
3712 | struct probe *probe; | |
3713 | ||
3714 | for (i = 0; | |
3715 | VEC_iterate (probe_p, | |
3716 | bp_objfile_data->exception_probes, | |
3717 | i, probe); | |
3718 | ++i) | |
3719 | { | |
3720 | struct breakpoint *b; | |
3721 | ||
729662a5 TT |
3722 | b = create_internal_breakpoint (gdbarch, |
3723 | get_probe_address (probe, | |
3724 | objfile), | |
28106bc2 SDJ |
3725 | bp_exception_master, |
3726 | &internal_breakpoint_ops); | |
5b56227b KS |
3727 | b->location |
3728 | = new_probe_location ("-probe-stap libgcc:unwind"); | |
28106bc2 SDJ |
3729 | b->enable_state = bp_disabled; |
3730 | } | |
3731 | ||
3732 | continue; | |
3733 | } | |
3734 | ||
3735 | /* Otherwise, try the hook function. */ | |
3736 | ||
3b7344d5 | 3737 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3738 | continue; |
3739 | ||
3740 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3741 | |
3b7344d5 | 3742 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3743 | { |
3b7344d5 | 3744 | struct bound_minimal_symbol debug_hook; |
186c406b | 3745 | |
17450429 | 3746 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3747 | if (debug_hook.minsym == NULL) |
17450429 | 3748 | { |
3b7344d5 | 3749 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3750 | continue; |
3751 | } | |
3752 | ||
3753 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3754 | } |
17450429 | 3755 | |
77e371c0 | 3756 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3757 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3758 | ¤t_target); | |
06edf0c0 PA |
3759 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3760 | &internal_breakpoint_ops); | |
67994074 KS |
3761 | initialize_explicit_location (&explicit_loc); |
3762 | explicit_loc.function_name = ASTRDUP (func_name); | |
3763 | b->location = new_explicit_location (&explicit_loc); | |
17450429 | 3764 | b->enable_state = bp_disabled; |
186c406b | 3765 | } |
186c406b TT |
3766 | } |
3767 | ||
9ef9e6a6 KS |
3768 | /* Does B have a location spec? */ |
3769 | ||
3770 | static int | |
3771 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3772 | { | |
3773 | return b->location != NULL && event_location_empty_p (b->location); | |
3774 | } | |
3775 | ||
c906108c | 3776 | void |
fba45db2 | 3777 | update_breakpoints_after_exec (void) |
c906108c | 3778 | { |
35df4500 | 3779 | struct breakpoint *b, *b_tmp; |
876fa593 | 3780 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3781 | |
25b22b0a PA |
3782 | /* We're about to delete breakpoints from GDB's lists. If the |
3783 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3784 | writing the breakpoints' "shadow contents" back into memory. The | |
3785 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3786 | do that. Instead, the target is responsible from marking | |
3787 | breakpoints out as soon as it detects an exec. We don't do that | |
3788 | here instead, because there may be other attempts to delete | |
3789 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3790 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3791 | if (bploc->pspace == current_program_space) |
3792 | gdb_assert (!bploc->inserted); | |
c906108c | 3793 | |
35df4500 | 3794 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3795 | { |
6c95b8df PA |
3796 | if (b->pspace != current_program_space) |
3797 | continue; | |
3798 | ||
4a64f543 | 3799 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3800 | if (b->type == bp_shlib_event) |
3801 | { | |
3802 | delete_breakpoint (b); | |
3803 | continue; | |
3804 | } | |
c906108c | 3805 | |
4a64f543 | 3806 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3807 | if (b->type == bp_jit_event) |
3808 | { | |
3809 | delete_breakpoint (b); | |
3810 | continue; | |
3811 | } | |
3812 | ||
1900040c | 3813 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3814 | as must overlay event and longjmp master breakpoints. */ |
3815 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3816 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3817 | || b->type == bp_exception_master) | |
c4093a6a JM |
3818 | { |
3819 | delete_breakpoint (b); | |
3820 | continue; | |
3821 | } | |
3822 | ||
4a64f543 | 3823 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3824 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3825 | { |
3826 | delete_breakpoint (b); | |
3827 | continue; | |
3828 | } | |
3829 | ||
7c16b83e PA |
3830 | /* Just like single-step breakpoints. */ |
3831 | if (b->type == bp_single_step) | |
3832 | { | |
3833 | delete_breakpoint (b); | |
3834 | continue; | |
3835 | } | |
3836 | ||
611c83ae PA |
3837 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3838 | after an exec. */ | |
186c406b | 3839 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3840 | || b->type == bp_longjmp_call_dummy |
186c406b | 3841 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3842 | { |
3843 | delete_breakpoint (b); | |
3844 | continue; | |
3845 | } | |
3846 | ||
ce78b96d JB |
3847 | if (b->type == bp_catchpoint) |
3848 | { | |
3849 | /* For now, none of the bp_catchpoint breakpoints need to | |
3850 | do anything at this point. In the future, if some of | |
3851 | the catchpoints need to something, we will need to add | |
3852 | a new method, and call this method from here. */ | |
3853 | continue; | |
3854 | } | |
3855 | ||
c5aa993b JM |
3856 | /* bp_finish is a special case. The only way we ought to be able |
3857 | to see one of these when an exec() has happened, is if the user | |
3858 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3859 | carries them to the call-site of the current callee, by setting | |
3860 | a temporary bp there and resuming. But in this case, the finish | |
3861 | will carry them entirely through the vfork & exec. | |
3862 | ||
3863 | We don't want to allow a bp_finish to remain inserted now. But | |
3864 | we can't safely delete it, 'cause finish_command has a handle to | |
3865 | the bp on a bpstat, and will later want to delete it. There's a | |
3866 | chance (and I've seen it happen) that if we delete the bp_finish | |
3867 | here, that its storage will get reused by the time finish_command | |
3868 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3869 | We really must allow finish_command to delete a bp_finish. | |
3870 | ||
e5dd4106 | 3871 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3872 | it's safe to delete something others may have handles to?" |
3873 | problem, what we'll do here is just uninsert the bp_finish, and | |
3874 | let finish_command delete it. | |
3875 | ||
3876 | (We know the bp_finish is "doomed" in the sense that it's | |
3877 | momentary, and will be deleted as soon as finish_command sees | |
3878 | the inferior stopped. So it doesn't matter that the bp's | |
3879 | address is probably bogus in the new a.out, unlike e.g., the | |
3880 | solib breakpoints.) */ | |
c5aa993b | 3881 | |
c5aa993b JM |
3882 | if (b->type == bp_finish) |
3883 | { | |
3884 | continue; | |
3885 | } | |
3886 | ||
3887 | /* Without a symbolic address, we have little hope of the | |
3888 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3889 | a.out. */ |
9ef9e6a6 | 3890 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3891 | { |
3892 | delete_breakpoint (b); | |
3893 | continue; | |
3894 | } | |
c5aa993b | 3895 | } |
c906108c SS |
3896 | } |
3897 | ||
3898 | int | |
d80ee84f | 3899 | detach_breakpoints (ptid_t ptid) |
c906108c | 3900 | { |
35df4500 | 3901 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3902 | int val = 0; |
ce696e05 | 3903 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3904 | struct inferior *inf = current_inferior (); |
c5aa993b | 3905 | |
dfd4cc63 | 3906 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3907 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3908 | |
6c95b8df | 3909 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3910 | inferior_ptid = ptid; |
35df4500 | 3911 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3912 | { |
35df4500 | 3913 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3914 | continue; |
3915 | ||
bd9673a4 PW |
3916 | /* This function must physically remove breakpoints locations |
3917 | from the specified ptid, without modifying the breakpoint | |
3918 | package's state. Locations of type bp_loc_other are only | |
3919 | maintained at GDB side. So, there is no need to remove | |
3920 | these bp_loc_other locations. Moreover, removing these | |
3921 | would modify the breakpoint package's state. */ | |
3922 | if (bl->loc_type == bp_loc_other) | |
3923 | continue; | |
3924 | ||
35df4500 | 3925 | if (bl->inserted) |
b2b6a7da | 3926 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3927 | } |
d03285ec | 3928 | |
ce696e05 | 3929 | do_cleanups (old_chain); |
3a1bae8e | 3930 | return val; |
c906108c SS |
3931 | } |
3932 | ||
35df4500 | 3933 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3934 | Note that this is used to detach breakpoints from a child fork. |
3935 | When we get here, the child isn't in the inferior list, and neither | |
3936 | do we have objects to represent its address space --- we should | |
35df4500 | 3937 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3938 | |
c906108c | 3939 | static int |
b2b6a7da | 3940 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3941 | { |
3942 | int val; | |
c5aa993b | 3943 | |
35df4500 TJB |
3944 | /* BL is never in moribund_locations by our callers. */ |
3945 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3946 | |
74960c60 VP |
3947 | /* The type of none suggests that owner is actually deleted. |
3948 | This should not ever happen. */ | |
35df4500 | 3949 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3950 | |
35df4500 TJB |
3951 | if (bl->loc_type == bp_loc_software_breakpoint |
3952 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3953 | { |
c02f5703 MS |
3954 | /* "Normal" instruction breakpoint: either the standard |
3955 | trap-instruction bp (bp_breakpoint), or a | |
3956 | bp_hardware_breakpoint. */ | |
3957 | ||
3958 | /* First check to see if we have to handle an overlay. */ | |
3959 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3960 | || bl->section == NULL |
3961 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3962 | { |
3963 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3964 | |
3965 | /* If we're trying to uninsert a memory breakpoint that we | |
3966 | know is set in a dynamic object that is marked | |
3967 | shlib_disabled, then either the dynamic object was | |
3968 | removed with "remove-symbol-file" or with | |
3969 | "nosharedlibrary". In the former case, we don't know | |
3970 | whether another dynamic object might have loaded over the | |
3971 | breakpoint's address -- the user might well let us know | |
3972 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3973 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3974 | list of dynamically loaded objects). If we have the |
3975 | breakpoint's shadow memory, that is, this is a software | |
3976 | breakpoint managed by GDB, check whether the breakpoint | |
3977 | is still inserted in memory, to avoid overwriting wrong | |
3978 | code with stale saved shadow contents. Note that HW | |
3979 | breakpoints don't have shadow memory, as they're | |
3980 | implemented using a mechanism that is not dependent on | |
3981 | being able to modify the target's memory, and as such | |
3982 | they should always be removed. */ | |
3983 | if (bl->shlib_disabled | |
3984 | && bl->target_info.shadow_len != 0 | |
3985 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3986 | val = 0; | |
3987 | else | |
73971819 | 3988 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3989 | } |
c906108c SS |
3990 | else |
3991 | { | |
4a64f543 | 3992 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3993 | Did we set a breakpoint at the LMA? */ |
3994 | if (!overlay_events_enabled) | |
3995 | { | |
3996 | /* Yes -- overlay event support is not active, so we | |
3997 | should have set a breakpoint at the LMA. Remove it. | |
3998 | */ | |
c02f5703 MS |
3999 | /* Ignore any failures: if the LMA is in ROM, we will |
4000 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
4001 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
4002 | target_remove_hw_breakpoint (bl->gdbarch, | |
4003 | &bl->overlay_target_info); | |
c02f5703 | 4004 | else |
35df4500 | 4005 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
4006 | &bl->overlay_target_info, |
4007 | reason); | |
c02f5703 MS |
4008 | } |
4009 | /* Did we set a breakpoint at the VMA? | |
4010 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4011 | if (bl->inserted) |
c906108c | 4012 | { |
c02f5703 MS |
4013 | /* Yes -- remove it. Previously we did not bother to |
4014 | remove the breakpoint if the section had been | |
4015 | unmapped, but let's not rely on that being safe. We | |
4016 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4017 | |
4018 | /* However, we should remove *software* breakpoints only | |
4019 | if the section is still mapped, or else we overwrite | |
4020 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4021 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4022 | || section_is_mapped (bl->section)) | |
73971819 | 4023 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
4024 | else |
4025 | val = 0; | |
c906108c | 4026 | } |
c02f5703 MS |
4027 | else |
4028 | { | |
4029 | /* No -- not inserted, so no need to remove. No error. */ | |
4030 | val = 0; | |
4031 | } | |
c906108c | 4032 | } |
879d1e6b | 4033 | |
08351840 PA |
4034 | /* In some cases, we might not be able to remove a breakpoint in |
4035 | a shared library that has already been removed, but we have | |
4036 | not yet processed the shlib unload event. Similarly for an | |
4037 | unloaded add-symbol-file object - the user might not yet have | |
4038 | had the chance to remove-symbol-file it. shlib_disabled will | |
4039 | be set if the library/object has already been removed, but | |
4040 | the breakpoint hasn't been uninserted yet, e.g., after | |
4041 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4042 | always-inserted mode. */ | |
076855f9 | 4043 | if (val |
08351840 PA |
4044 | && (bl->loc_type == bp_loc_software_breakpoint |
4045 | && (bl->shlib_disabled | |
4046 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4047 | || shared_objfile_contains_address_p (bl->pspace, |
4048 | bl->address)))) | |
879d1e6b UW |
4049 | val = 0; |
4050 | ||
c906108c SS |
4051 | if (val) |
4052 | return val; | |
b2b6a7da | 4053 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 4054 | } |
35df4500 | 4055 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4056 | { |
77b06cd7 TJB |
4057 | gdb_assert (bl->owner->ops != NULL |
4058 | && bl->owner->ops->remove_location != NULL); | |
4059 | ||
b2b6a7da | 4060 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 4061 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 4062 | |
c906108c | 4063 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 4064 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 4065 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4066 | bl->owner->number); |
c906108c | 4067 | } |
35df4500 TJB |
4068 | else if (bl->owner->type == bp_catchpoint |
4069 | && breakpoint_enabled (bl->owner) | |
4070 | && !bl->duplicate) | |
ce78b96d | 4071 | { |
77b06cd7 TJB |
4072 | gdb_assert (bl->owner->ops != NULL |
4073 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4074 | |
73971819 | 4075 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
4076 | if (val) |
4077 | return val; | |
77b06cd7 | 4078 | |
b2b6a7da | 4079 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 4080 | } |
c906108c SS |
4081 | |
4082 | return 0; | |
4083 | } | |
4084 | ||
6c95b8df | 4085 | static int |
834c0d03 | 4086 | remove_breakpoint (struct bp_location *bl) |
6c95b8df PA |
4087 | { |
4088 | int ret; | |
4089 | struct cleanup *old_chain; | |
4090 | ||
35df4500 TJB |
4091 | /* BL is never in moribund_locations by our callers. */ |
4092 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4093 | |
6c95b8df PA |
4094 | /* The type of none suggests that owner is actually deleted. |
4095 | This should not ever happen. */ | |
35df4500 | 4096 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4097 | |
4098 | old_chain = save_current_space_and_thread (); | |
4099 | ||
35df4500 | 4100 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4101 | |
b2b6a7da | 4102 | ret = remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4103 | |
4104 | do_cleanups (old_chain); | |
4105 | return ret; | |
4106 | } | |
4107 | ||
c906108c SS |
4108 | /* Clear the "inserted" flag in all breakpoints. */ |
4109 | ||
25b22b0a | 4110 | void |
fba45db2 | 4111 | mark_breakpoints_out (void) |
c906108c | 4112 | { |
35df4500 | 4113 | struct bp_location *bl, **blp_tmp; |
c906108c | 4114 | |
35df4500 | 4115 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4116 | if (bl->pspace == current_program_space) |
35df4500 | 4117 | bl->inserted = 0; |
c906108c SS |
4118 | } |
4119 | ||
53a5351d JM |
4120 | /* Clear the "inserted" flag in all breakpoints and delete any |
4121 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4122 | |
4123 | Plus other such housekeeping that has to be done for breakpoints | |
4124 | between runs. | |
4125 | ||
53a5351d JM |
4126 | Note: this function gets called at the end of a run (by |
4127 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4128 | init_wait_for_inferior). */ |
c906108c SS |
4129 | |
4130 | ||
4131 | ||
4132 | void | |
fba45db2 | 4133 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4134 | { |
35df4500 | 4135 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4136 | struct bp_location *bl; |
1c5cfe86 | 4137 | int ix; |
6c95b8df | 4138 | struct program_space *pspace = current_program_space; |
c906108c | 4139 | |
50c71eaf PA |
4140 | /* If breakpoint locations are shared across processes, then there's |
4141 | nothing to do. */ | |
f5656ead | 4142 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4143 | return; |
4144 | ||
1a853c52 | 4145 | mark_breakpoints_out (); |
075f6582 | 4146 | |
35df4500 | 4147 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4148 | { |
6c95b8df PA |
4149 | if (b->loc && b->loc->pspace != pspace) |
4150 | continue; | |
4151 | ||
c5aa993b JM |
4152 | switch (b->type) |
4153 | { | |
4154 | case bp_call_dummy: | |
e2e4d78b | 4155 | case bp_longjmp_call_dummy: |
c906108c | 4156 | |
c5aa993b | 4157 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4158 | cause problems when the inferior is rerun, so we better get |
4159 | rid of it. */ | |
4160 | ||
4161 | case bp_watchpoint_scope: | |
4162 | ||
4163 | /* Also get rid of scope breakpoints. */ | |
4164 | ||
4165 | case bp_shlib_event: | |
4166 | ||
4167 | /* Also remove solib event breakpoints. Their addresses may | |
4168 | have changed since the last time we ran the program. | |
4169 | Actually we may now be debugging against different target; | |
4170 | and so the solib backend that installed this breakpoint may | |
4171 | not be used in by the target. E.g., | |
4172 | ||
4173 | (gdb) file prog-linux | |
4174 | (gdb) run # native linux target | |
4175 | ... | |
4176 | (gdb) kill | |
4177 | (gdb) file prog-win.exe | |
4178 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4179 | */ | |
c906108c | 4180 | |
f59f708a PA |
4181 | case bp_step_resume: |
4182 | ||
4183 | /* Also remove step-resume breakpoints. */ | |
4184 | ||
7c16b83e PA |
4185 | case bp_single_step: |
4186 | ||
4187 | /* Also remove single-step breakpoints. */ | |
4188 | ||
c5aa993b JM |
4189 | delete_breakpoint (b); |
4190 | break; | |
c906108c | 4191 | |
c5aa993b JM |
4192 | case bp_watchpoint: |
4193 | case bp_hardware_watchpoint: | |
4194 | case bp_read_watchpoint: | |
4195 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4196 | { |
4197 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4198 | |
3a5c3e22 PA |
4199 | /* Likewise for watchpoints on local expressions. */ |
4200 | if (w->exp_valid_block != NULL) | |
4201 | delete_breakpoint (b); | |
63000888 | 4202 | else |
3a5c3e22 | 4203 | { |
63000888 PA |
4204 | /* Get rid of existing locations, which are no longer |
4205 | valid. New ones will be created in | |
4206 | update_watchpoint, when the inferior is restarted. | |
4207 | The next update_global_location_list call will | |
4208 | garbage collect them. */ | |
4209 | b->loc = NULL; | |
4210 | ||
4211 | if (context == inf_starting) | |
4212 | { | |
4213 | /* Reset val field to force reread of starting value in | |
4214 | insert_breakpoints. */ | |
4215 | if (w->val) | |
4216 | value_free (w->val); | |
4217 | w->val = NULL; | |
4218 | w->val_valid = 0; | |
4219 | } | |
4220 | } | |
3a5c3e22 | 4221 | } |
c5aa993b JM |
4222 | break; |
4223 | default: | |
c5aa993b JM |
4224 | break; |
4225 | } | |
4226 | } | |
1c5cfe86 PA |
4227 | |
4228 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4229 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4230 | decref_bp_location (&bl); | |
1c5cfe86 | 4231 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4232 | } |
4233 | ||
6c95b8df PA |
4234 | /* These functions concern about actual breakpoints inserted in the |
4235 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4236 | we need to hop over the bkpt --- so we check for address space | |
4237 | match, not program space. */ | |
4238 | ||
c2c6d25f JM |
4239 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4240 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4241 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4242 | permanent breakpoint. | |
4243 | - When continuing from a location with an ordinary breakpoint, we | |
4244 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4245 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4246 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4247 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4248 | |
c2c6d25f | 4249 | enum breakpoint_here |
6c95b8df | 4250 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4251 | { |
35df4500 | 4252 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4253 | int any_breakpoint_here = 0; |
c906108c | 4254 | |
35df4500 | 4255 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4256 | { |
35df4500 TJB |
4257 | if (bl->loc_type != bp_loc_software_breakpoint |
4258 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4259 | continue; |
4260 | ||
f1310107 | 4261 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4262 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4263 | || bl->permanent) |
f1310107 | 4264 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4265 | { |
4266 | if (overlay_debugging | |
35df4500 TJB |
4267 | && section_is_overlay (bl->section) |
4268 | && !section_is_mapped (bl->section)) | |
075f6582 | 4269 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4270 | else if (bl->permanent) |
075f6582 DJ |
4271 | return permanent_breakpoint_here; |
4272 | else | |
4273 | any_breakpoint_here = 1; | |
4274 | } | |
4275 | } | |
c906108c | 4276 | |
f486487f | 4277 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4278 | } |
4279 | ||
d35ae833 PA |
4280 | /* See breakpoint.h. */ |
4281 | ||
4282 | int | |
4283 | breakpoint_in_range_p (struct address_space *aspace, | |
4284 | CORE_ADDR addr, ULONGEST len) | |
4285 | { | |
4286 | struct bp_location *bl, **blp_tmp; | |
4287 | ||
4288 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4289 | { | |
4290 | if (bl->loc_type != bp_loc_software_breakpoint | |
4291 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4292 | continue; | |
4293 | ||
4294 | if ((breakpoint_enabled (bl->owner) | |
4295 | || bl->permanent) | |
4296 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4297 | addr, len)) | |
4298 | { | |
4299 | if (overlay_debugging | |
4300 | && section_is_overlay (bl->section) | |
4301 | && !section_is_mapped (bl->section)) | |
4302 | { | |
4303 | /* Unmapped overlay -- can't be a match. */ | |
4304 | continue; | |
4305 | } | |
4306 | ||
4307 | return 1; | |
4308 | } | |
4309 | } | |
4310 | ||
4311 | return 0; | |
4312 | } | |
4313 | ||
1c5cfe86 PA |
4314 | /* Return true if there's a moribund breakpoint at PC. */ |
4315 | ||
4316 | int | |
6c95b8df | 4317 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4318 | { |
4319 | struct bp_location *loc; | |
4320 | int ix; | |
4321 | ||
4322 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4323 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4324 | return 1; |
4325 | ||
4326 | return 0; | |
4327 | } | |
c2c6d25f | 4328 | |
f7ce857f PA |
4329 | /* Returns non-zero iff BL is inserted at PC, in address space |
4330 | ASPACE. */ | |
4331 | ||
4332 | static int | |
4333 | bp_location_inserted_here_p (struct bp_location *bl, | |
4334 | struct address_space *aspace, CORE_ADDR pc) | |
4335 | { | |
4336 | if (bl->inserted | |
4337 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4338 | aspace, pc)) | |
4339 | { | |
4340 | if (overlay_debugging | |
4341 | && section_is_overlay (bl->section) | |
4342 | && !section_is_mapped (bl->section)) | |
4343 | return 0; /* unmapped overlay -- can't be a match */ | |
4344 | else | |
4345 | return 1; | |
4346 | } | |
4347 | return 0; | |
4348 | } | |
4349 | ||
a1fd2fa5 | 4350 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4351 | |
4352 | int | |
a1fd2fa5 | 4353 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4354 | { |
f7ce857f | 4355 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4356 | |
f7ce857f | 4357 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4358 | { |
f7ce857f PA |
4359 | struct bp_location *bl = *blp; |
4360 | ||
35df4500 TJB |
4361 | if (bl->loc_type != bp_loc_software_breakpoint |
4362 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4363 | continue; |
4364 | ||
f7ce857f PA |
4365 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4366 | return 1; | |
c5aa993b | 4367 | } |
c36b740a VP |
4368 | return 0; |
4369 | } | |
4370 | ||
a1fd2fa5 PA |
4371 | /* This function returns non-zero iff there is a software breakpoint |
4372 | inserted at PC. */ | |
c36b740a VP |
4373 | |
4374 | int | |
a1fd2fa5 PA |
4375 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4376 | CORE_ADDR pc) | |
4fa8626c | 4377 | { |
f7ce857f | 4378 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4379 | |
f7ce857f | 4380 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4381 | { |
f7ce857f PA |
4382 | struct bp_location *bl = *blp; |
4383 | ||
35df4500 | 4384 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4385 | continue; |
4386 | ||
f7ce857f PA |
4387 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4388 | return 1; | |
4fa8626c DJ |
4389 | } |
4390 | ||
4391 | return 0; | |
9c02b525 PA |
4392 | } |
4393 | ||
4394 | /* See breakpoint.h. */ | |
4395 | ||
4396 | int | |
4397 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4398 | CORE_ADDR pc) | |
4399 | { | |
4400 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4401 | |
4402 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4403 | { | |
4404 | struct bp_location *bl = *blp; | |
4405 | ||
4406 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4407 | continue; | |
4408 | ||
4409 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4410 | return 1; | |
4411 | } | |
4412 | ||
4413 | return 0; | |
4fa8626c DJ |
4414 | } |
4415 | ||
9093389c PA |
4416 | int |
4417 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4418 | CORE_ADDR addr, ULONGEST len) | |
4419 | { | |
4420 | struct breakpoint *bpt; | |
4421 | ||
4422 | ALL_BREAKPOINTS (bpt) | |
4423 | { | |
4424 | struct bp_location *loc; | |
4425 | ||
4426 | if (bpt->type != bp_hardware_watchpoint | |
4427 | && bpt->type != bp_access_watchpoint) | |
4428 | continue; | |
4429 | ||
4430 | if (!breakpoint_enabled (bpt)) | |
4431 | continue; | |
4432 | ||
4433 | for (loc = bpt->loc; loc; loc = loc->next) | |
4434 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4435 | { | |
4436 | CORE_ADDR l, h; | |
4437 | ||
4438 | /* Check for intersection. */ | |
768adc05 PA |
4439 | l = std::max<CORE_ADDR> (loc->address, addr); |
4440 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4441 | if (l < h) |
4442 | return 1; | |
4443 | } | |
4444 | } | |
4445 | return 0; | |
4446 | } | |
c906108c | 4447 | \f |
c5aa993b | 4448 | |
c906108c SS |
4449 | /* bpstat stuff. External routines' interfaces are documented |
4450 | in breakpoint.h. */ | |
4451 | ||
4452 | int | |
c326b90e | 4453 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4454 | { |
533be4dd | 4455 | return (ep->type == bp_catchpoint); |
c906108c SS |
4456 | } |
4457 | ||
f431efe5 PA |
4458 | /* Frees any storage that is part of a bpstat. Does not walk the |
4459 | 'next' chain. */ | |
4460 | ||
4461 | static void | |
198757a8 VP |
4462 | bpstat_free (bpstat bs) |
4463 | { | |
4464 | if (bs->old_val != NULL) | |
4465 | value_free (bs->old_val); | |
9add0f1b | 4466 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4467 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4468 | xfree (bs); |
4469 | } | |
4470 | ||
c906108c SS |
4471 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4472 | Also free any storage that is part of a bpstat. */ | |
4473 | ||
4474 | void | |
fba45db2 | 4475 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4476 | { |
4477 | bpstat p; | |
4478 | bpstat q; | |
4479 | ||
4480 | if (bsp == 0) | |
4481 | return; | |
4482 | p = *bsp; | |
4483 | while (p != NULL) | |
4484 | { | |
4485 | q = p->next; | |
198757a8 | 4486 | bpstat_free (p); |
c906108c SS |
4487 | p = q; |
4488 | } | |
4489 | *bsp = NULL; | |
4490 | } | |
4491 | ||
4492 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4493 | is part of the bpstat is copied as well. */ | |
4494 | ||
4495 | bpstat | |
fba45db2 | 4496 | bpstat_copy (bpstat bs) |
c906108c SS |
4497 | { |
4498 | bpstat p = NULL; | |
4499 | bpstat tmp; | |
4500 | bpstat retval = NULL; | |
4501 | ||
4502 | if (bs == NULL) | |
4503 | return bs; | |
4504 | ||
4505 | for (; bs != NULL; bs = bs->next) | |
4506 | { | |
4507 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4508 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4509 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4510 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4511 | if (bs->old_val != NULL) |
3c3185ac JK |
4512 | { |
4513 | tmp->old_val = value_copy (bs->old_val); | |
4514 | release_value (tmp->old_val); | |
4515 | } | |
31cc81e9 | 4516 | |
c906108c SS |
4517 | if (p == NULL) |
4518 | /* This is the first thing in the chain. */ | |
4519 | retval = tmp; | |
4520 | else | |
4521 | p->next = tmp; | |
4522 | p = tmp; | |
4523 | } | |
4524 | p->next = NULL; | |
4525 | return retval; | |
4526 | } | |
4527 | ||
4a64f543 | 4528 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4529 | |
4530 | bpstat | |
fba45db2 | 4531 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4532 | { |
c5aa993b JM |
4533 | if (bsp == NULL) |
4534 | return NULL; | |
c906108c | 4535 | |
c5aa993b JM |
4536 | for (; bsp != NULL; bsp = bsp->next) |
4537 | { | |
f431efe5 | 4538 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4539 | return bsp; |
4540 | } | |
c906108c SS |
4541 | return NULL; |
4542 | } | |
4543 | ||
ab04a2af TT |
4544 | /* See breakpoint.h. */ |
4545 | ||
47591c29 | 4546 | int |
427cd150 | 4547 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4548 | { |
ab04a2af TT |
4549 | for (; bsp != NULL; bsp = bsp->next) |
4550 | { | |
427cd150 TT |
4551 | if (bsp->breakpoint_at == NULL) |
4552 | { | |
4553 | /* A moribund location can never explain a signal other than | |
4554 | GDB_SIGNAL_TRAP. */ | |
4555 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4556 | return 1; |
427cd150 TT |
4557 | } |
4558 | else | |
47591c29 PA |
4559 | { |
4560 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4561 | sig)) | |
4562 | return 1; | |
4563 | } | |
ab04a2af TT |
4564 | } |
4565 | ||
47591c29 | 4566 | return 0; |
ab04a2af TT |
4567 | } |
4568 | ||
4a64f543 MS |
4569 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4570 | stopped at. *BSP upon return is a bpstat which points to the | |
4571 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4572 | good for anything but further calls to bpstat_num). | |
4573 | ||
8671a17b PA |
4574 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4575 | Return -1 if stopped at a breakpoint that has been deleted since | |
4576 | we set it. | |
4577 | Return 1 otherwise. */ | |
c906108c SS |
4578 | |
4579 | int | |
8671a17b | 4580 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4581 | { |
4582 | struct breakpoint *b; | |
4583 | ||
4584 | if ((*bsp) == NULL) | |
4585 | return 0; /* No more breakpoint values */ | |
8671a17b | 4586 | |
4a64f543 MS |
4587 | /* We assume we'll never have several bpstats that correspond to a |
4588 | single breakpoint -- otherwise, this function might return the | |
4589 | same number more than once and this will look ugly. */ | |
f431efe5 | 4590 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4591 | *bsp = (*bsp)->next; |
4592 | if (b == NULL) | |
4593 | return -1; /* breakpoint that's been deleted since */ | |
4594 | ||
4595 | *num = b->number; /* We have its number */ | |
4596 | return 1; | |
c906108c SS |
4597 | } |
4598 | ||
e93ca019 | 4599 | /* See breakpoint.h. */ |
c906108c SS |
4600 | |
4601 | void | |
e93ca019 | 4602 | bpstat_clear_actions (void) |
c906108c | 4603 | { |
e93ca019 JK |
4604 | struct thread_info *tp; |
4605 | bpstat bs; | |
4606 | ||
4607 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4608 | return; | |
4609 | ||
4610 | tp = find_thread_ptid (inferior_ptid); | |
4611 | if (tp == NULL) | |
4612 | return; | |
4613 | ||
4614 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4615 | { |
9add0f1b | 4616 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4617 | |
c906108c SS |
4618 | if (bs->old_val != NULL) |
4619 | { | |
4620 | value_free (bs->old_val); | |
4621 | bs->old_val = NULL; | |
4622 | } | |
4623 | } | |
4624 | } | |
4625 | ||
f3b1572e PA |
4626 | /* Called when a command is about to proceed the inferior. */ |
4627 | ||
4628 | static void | |
4629 | breakpoint_about_to_proceed (void) | |
4630 | { | |
4631 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4632 | { | |
4633 | struct thread_info *tp = inferior_thread (); | |
4634 | ||
4635 | /* Allow inferior function calls in breakpoint commands to not | |
4636 | interrupt the command list. When the call finishes | |
4637 | successfully, the inferior will be standing at the same | |
4638 | breakpoint as if nothing happened. */ | |
16c381f0 | 4639 | if (tp->control.in_infcall) |
f3b1572e PA |
4640 | return; |
4641 | } | |
4642 | ||
4643 | breakpoint_proceeded = 1; | |
4644 | } | |
4645 | ||
4a64f543 MS |
4646 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4647 | command. */ | |
c906108c | 4648 | static void |
4efb68b1 | 4649 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4650 | { |
4651 | executing_breakpoint_commands = 0; | |
4652 | } | |
4653 | ||
abf85f46 JK |
4654 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4655 | or its equivalent. */ | |
4656 | ||
4657 | static int | |
4658 | command_line_is_silent (struct command_line *cmd) | |
4659 | { | |
4f45d445 | 4660 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4661 | } |
4662 | ||
4a64f543 MS |
4663 | /* Execute all the commands associated with all the breakpoints at |
4664 | this location. Any of these commands could cause the process to | |
4665 | proceed beyond this point, etc. We look out for such changes by | |
4666 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4667 | |
347bddb7 PA |
4668 | Returns true if a breakpoint command resumed the inferior. In that |
4669 | case, it is the caller's responsibility to recall it again with the | |
4670 | bpstat of the current thread. */ | |
4671 | ||
4672 | static int | |
4673 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4674 | { |
4675 | bpstat bs; | |
4676 | struct cleanup *old_chain; | |
347bddb7 | 4677 | int again = 0; |
c906108c SS |
4678 | |
4679 | /* Avoid endless recursion if a `source' command is contained | |
4680 | in bs->commands. */ | |
4681 | if (executing_breakpoint_commands) | |
347bddb7 | 4682 | return 0; |
c906108c SS |
4683 | |
4684 | executing_breakpoint_commands = 1; | |
4685 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4686 | ||
cf6c5ffb TT |
4687 | prevent_dont_repeat (); |
4688 | ||
4a64f543 | 4689 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4690 | bs = *bsp; |
4691 | ||
4692 | breakpoint_proceeded = 0; | |
4693 | for (; bs != NULL; bs = bs->next) | |
4694 | { | |
9add0f1b | 4695 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4696 | struct command_line *cmd; |
4697 | struct cleanup *this_cmd_tree_chain; | |
4698 | ||
4699 | /* Take ownership of the BSP's command tree, if it has one. | |
4700 | ||
4701 | The command tree could legitimately contain commands like | |
4702 | 'step' and 'next', which call clear_proceed_status, which | |
4703 | frees stop_bpstat's command tree. To make sure this doesn't | |
4704 | free the tree we're executing out from under us, we need to | |
4705 | take ownership of the tree ourselves. Since a given bpstat's | |
4706 | commands are only executed once, we don't need to copy it; we | |
4707 | can clear the pointer in the bpstat, and make sure we free | |
4708 | the tree when we're done. */ | |
9add0f1b TT |
4709 | ccmd = bs->commands; |
4710 | bs->commands = NULL; | |
abf85f46 JK |
4711 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4712 | cmd = ccmd ? ccmd->commands : NULL; | |
4713 | if (command_line_is_silent (cmd)) | |
4714 | { | |
4715 | /* The action has been already done by bpstat_stop_status. */ | |
4716 | cmd = cmd->next; | |
4717 | } | |
6c50ab1c | 4718 | |
c906108c SS |
4719 | while (cmd != NULL) |
4720 | { | |
4721 | execute_control_command (cmd); | |
4722 | ||
4723 | if (breakpoint_proceeded) | |
4724 | break; | |
4725 | else | |
4726 | cmd = cmd->next; | |
4727 | } | |
6c50ab1c JB |
4728 | |
4729 | /* We can free this command tree now. */ | |
4730 | do_cleanups (this_cmd_tree_chain); | |
4731 | ||
c906108c | 4732 | if (breakpoint_proceeded) |
32c1e744 | 4733 | { |
cb814510 | 4734 | if (current_ui->async) |
347bddb7 PA |
4735 | /* If we are in async mode, then the target might be still |
4736 | running, not stopped at any breakpoint, so nothing for | |
4737 | us to do here -- just return to the event loop. */ | |
4738 | ; | |
32c1e744 VP |
4739 | else |
4740 | /* In sync mode, when execute_control_command returns | |
4741 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4742 | Breakpoint commands for that stop were not run, since |
4743 | execute_command does not run breakpoint commands -- | |
4744 | only command_line_handler does, but that one is not | |
4745 | involved in execution of breakpoint commands. So, we | |
4746 | can now execute breakpoint commands. It should be | |
4747 | noted that making execute_command do bpstat actions is | |
4748 | not an option -- in this case we'll have recursive | |
4749 | invocation of bpstat for each breakpoint with a | |
4750 | command, and can easily blow up GDB stack. Instead, we | |
4751 | return true, which will trigger the caller to recall us | |
4752 | with the new stop_bpstat. */ | |
4753 | again = 1; | |
4754 | break; | |
32c1e744 | 4755 | } |
c906108c | 4756 | } |
c2b8ed2c | 4757 | do_cleanups (old_chain); |
347bddb7 PA |
4758 | return again; |
4759 | } | |
4760 | ||
4761 | void | |
4762 | bpstat_do_actions (void) | |
4763 | { | |
353d1d73 JK |
4764 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4765 | ||
347bddb7 PA |
4766 | /* Do any commands attached to breakpoint we are stopped at. */ |
4767 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4768 | && target_has_execution | |
4769 | && !is_exited (inferior_ptid) | |
4770 | && !is_executing (inferior_ptid)) | |
4771 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4772 | and only return when it is stopped at the next breakpoint, we | |
4773 | keep doing breakpoint actions until it returns false to | |
4774 | indicate the inferior was not resumed. */ | |
16c381f0 | 4775 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4776 | break; |
353d1d73 JK |
4777 | |
4778 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4779 | } |
4780 | ||
fa4727a6 DJ |
4781 | /* Print out the (old or new) value associated with a watchpoint. */ |
4782 | ||
4783 | static void | |
4784 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4785 | { | |
4786 | if (val == NULL) | |
4787 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4788 | else | |
79a45b7d TT |
4789 | { |
4790 | struct value_print_options opts; | |
4791 | get_user_print_options (&opts); | |
4792 | value_print (val, stream, &opts); | |
4793 | } | |
fa4727a6 DJ |
4794 | } |
4795 | ||
f303dbd6 PA |
4796 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4797 | debugging multiple threads. */ | |
4798 | ||
4799 | void | |
4800 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4801 | { | |
4802 | if (ui_out_is_mi_like_p (uiout)) | |
4803 | return; | |
4804 | ||
4805 | ui_out_text (uiout, "\n"); | |
4806 | ||
4807 | if (show_thread_that_caused_stop ()) | |
4808 | { | |
4809 | const char *name; | |
4810 | struct thread_info *thr = inferior_thread (); | |
4811 | ||
4812 | ui_out_text (uiout, "Thread "); | |
4813 | ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr)); | |
4814 | ||
4815 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4816 | if (name != NULL) | |
4817 | { | |
4818 | ui_out_text (uiout, " \""); | |
4819 | ui_out_field_fmt (uiout, "name", "%s", name); | |
4820 | ui_out_text (uiout, "\""); | |
4821 | } | |
4822 | ||
4823 | ui_out_text (uiout, " hit "); | |
4824 | } | |
4825 | } | |
4826 | ||
e514a9d6 | 4827 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4828 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4829 | 'print_it' in the bpstat structure. Under some circumstances we |
4830 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4831 | normal_stop(). */ |
e514a9d6 JM |
4832 | |
4833 | static enum print_stop_action | |
4834 | print_bp_stop_message (bpstat bs) | |
4835 | { | |
4836 | switch (bs->print_it) | |
4837 | { | |
4838 | case print_it_noop: | |
4a64f543 | 4839 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4840 | return PRINT_UNKNOWN; |
4841 | break; | |
4842 | ||
4843 | case print_it_done: | |
4844 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4845 | relevant messages. */ |
e514a9d6 JM |
4846 | return PRINT_SRC_AND_LOC; |
4847 | break; | |
4848 | ||
4849 | case print_it_normal: | |
4f8d1dc6 | 4850 | { |
f431efe5 PA |
4851 | struct breakpoint *b = bs->breakpoint_at; |
4852 | ||
1a6a67de TJB |
4853 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4854 | which has since been deleted. */ | |
4855 | if (b == NULL) | |
4856 | return PRINT_UNKNOWN; | |
4857 | ||
348d480f PA |
4858 | /* Normal case. Call the breakpoint's print_it method. */ |
4859 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4860 | } |
348d480f | 4861 | break; |
3086aeae | 4862 | |
e514a9d6 | 4863 | default: |
8e65ff28 | 4864 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4865 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4866 | break; |
c906108c | 4867 | } |
c906108c SS |
4868 | } |
4869 | ||
edcc5120 TT |
4870 | /* A helper function that prints a shared library stopped event. */ |
4871 | ||
4872 | static void | |
4873 | print_solib_event (int is_catchpoint) | |
4874 | { | |
4875 | int any_deleted | |
4876 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4877 | int any_added | |
4878 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4879 | ||
4880 | if (!is_catchpoint) | |
4881 | { | |
4882 | if (any_added || any_deleted) | |
4883 | ui_out_text (current_uiout, | |
4884 | _("Stopped due to shared library event:\n")); | |
4885 | else | |
4886 | ui_out_text (current_uiout, | |
4887 | _("Stopped due to shared library event (no " | |
4888 | "libraries added or removed)\n")); | |
4889 | } | |
4890 | ||
4891 | if (ui_out_is_mi_like_p (current_uiout)) | |
4892 | ui_out_field_string (current_uiout, "reason", | |
4893 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4894 | ||
4895 | if (any_deleted) | |
4896 | { | |
4897 | struct cleanup *cleanup; | |
4898 | char *name; | |
4899 | int ix; | |
4900 | ||
4901 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4902 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4903 | "removed"); | |
4904 | for (ix = 0; | |
4905 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4906 | ix, name); | |
4907 | ++ix) | |
4908 | { | |
4909 | if (ix > 0) | |
4910 | ui_out_text (current_uiout, " "); | |
4911 | ui_out_field_string (current_uiout, "library", name); | |
4912 | ui_out_text (current_uiout, "\n"); | |
4913 | } | |
4914 | ||
4915 | do_cleanups (cleanup); | |
4916 | } | |
4917 | ||
4918 | if (any_added) | |
4919 | { | |
4920 | struct so_list *iter; | |
4921 | int ix; | |
4922 | struct cleanup *cleanup; | |
4923 | ||
4924 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4925 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4926 | "added"); | |
4927 | for (ix = 0; | |
4928 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4929 | ix, iter); | |
4930 | ++ix) | |
4931 | { | |
4932 | if (ix > 0) | |
4933 | ui_out_text (current_uiout, " "); | |
4934 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4935 | ui_out_text (current_uiout, "\n"); | |
4936 | } | |
4937 | ||
4938 | do_cleanups (cleanup); | |
4939 | } | |
4940 | } | |
4941 | ||
e514a9d6 JM |
4942 | /* Print a message indicating what happened. This is called from |
4943 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4944 | list - a list of the eventpoints that caused this stop. KIND is |
4945 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4946 | routine calls the generic print routine for printing a message |
4947 | about reasons for stopping. This will print (for example) the | |
4948 | "Breakpoint n," part of the output. The return value of this | |
4949 | routine is one of: | |
c906108c | 4950 | |
4a64f543 | 4951 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4952 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4953 | code to print the location. An example is |
c5aa993b JM |
4954 | "Breakpoint 1, " which should be followed by |
4955 | the location. | |
917317f4 | 4956 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4957 | to also print the location part of the message. |
4958 | An example is the catch/throw messages, which | |
4a64f543 | 4959 | don't require a location appended to the end. |
917317f4 | 4960 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4961 | further info to be printed. */ |
c906108c | 4962 | |
917317f4 | 4963 | enum print_stop_action |
36dfb11c | 4964 | bpstat_print (bpstat bs, int kind) |
c906108c | 4965 | { |
f486487f | 4966 | enum print_stop_action val; |
c5aa993b | 4967 | |
c906108c | 4968 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4969 | (Currently all watchpoints go on the bpstat whether hit or not. |
4970 | That probably could (should) be changed, provided care is taken | |
c906108c | 4971 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4972 | for (; bs; bs = bs->next) |
4973 | { | |
4974 | val = print_bp_stop_message (bs); | |
4975 | if (val == PRINT_SRC_ONLY | |
4976 | || val == PRINT_SRC_AND_LOC | |
4977 | || val == PRINT_NOTHING) | |
4978 | return val; | |
4979 | } | |
c906108c | 4980 | |
36dfb11c TT |
4981 | /* If we had hit a shared library event breakpoint, |
4982 | print_bp_stop_message would print out this message. If we hit an | |
4983 | OS-level shared library event, do the same thing. */ | |
4984 | if (kind == TARGET_WAITKIND_LOADED) | |
4985 | { | |
edcc5120 | 4986 | print_solib_event (0); |
36dfb11c TT |
4987 | return PRINT_NOTHING; |
4988 | } | |
4989 | ||
e514a9d6 | 4990 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4991 | with and nothing was printed. */ |
917317f4 | 4992 | return PRINT_UNKNOWN; |
c906108c SS |
4993 | } |
4994 | ||
c42bd95a DE |
4995 | /* Evaluate the expression EXP and return 1 if value is zero. |
4996 | This returns the inverse of the condition because it is called | |
4997 | from catch_errors which returns 0 if an exception happened, and if an | |
4998 | exception happens we want execution to stop. | |
4a64f543 | 4999 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 5000 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
5001 | |
5002 | static int | |
4efb68b1 | 5003 | breakpoint_cond_eval (void *exp) |
c906108c | 5004 | { |
278cd55f | 5005 | struct value *mark = value_mark (); |
c5aa993b | 5006 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 5007 | |
c906108c SS |
5008 | value_free_to_mark (mark); |
5009 | return i; | |
5010 | } | |
5011 | ||
5760d0ab | 5012 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5013 | |
5014 | static bpstat | |
5760d0ab | 5015 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5016 | { |
5017 | bpstat bs; | |
5018 | ||
5019 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5020 | bs->next = NULL; |
5021 | **bs_link_pointer = bs; | |
5022 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5023 | bs->breakpoint_at = bl->owner; |
5024 | bs->bp_location_at = bl; | |
5025 | incref_bp_location (bl); | |
c906108c SS |
5026 | /* If the condition is false, etc., don't do the commands. */ |
5027 | bs->commands = NULL; | |
5028 | bs->old_val = NULL; | |
5029 | bs->print_it = print_it_normal; | |
5030 | return bs; | |
5031 | } | |
5032 | \f | |
d983da9c DJ |
5033 | /* The target has stopped with waitstatus WS. Check if any hardware |
5034 | watchpoints have triggered, according to the target. */ | |
5035 | ||
5036 | int | |
5037 | watchpoints_triggered (struct target_waitstatus *ws) | |
5038 | { | |
d92524f1 | 5039 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5040 | CORE_ADDR addr; |
5041 | struct breakpoint *b; | |
5042 | ||
5043 | if (!stopped_by_watchpoint) | |
5044 | { | |
5045 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5046 | as not triggered. */ | |
5047 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5048 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5049 | { |
5050 | struct watchpoint *w = (struct watchpoint *) b; | |
5051 | ||
5052 | w->watchpoint_triggered = watch_triggered_no; | |
5053 | } | |
d983da9c DJ |
5054 | |
5055 | return 0; | |
5056 | } | |
5057 | ||
5058 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5059 | { | |
5060 | /* We were stopped by a watchpoint, but we don't know where. | |
5061 | Mark all watchpoints as unknown. */ | |
5062 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5063 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5064 | { |
5065 | struct watchpoint *w = (struct watchpoint *) b; | |
5066 | ||
5067 | w->watchpoint_triggered = watch_triggered_unknown; | |
5068 | } | |
d983da9c | 5069 | |
3c4797ba | 5070 | return 1; |
d983da9c DJ |
5071 | } |
5072 | ||
5073 | /* The target could report the data address. Mark watchpoints | |
5074 | affected by this data address as triggered, and all others as not | |
5075 | triggered. */ | |
5076 | ||
5077 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5078 | if (is_hardware_watchpoint (b)) |
d983da9c | 5079 | { |
3a5c3e22 | 5080 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5081 | struct bp_location *loc; |
d983da9c | 5082 | |
3a5c3e22 | 5083 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5084 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5085 | { |
3a5c3e22 | 5086 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5087 | { |
3a5c3e22 PA |
5088 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5089 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5090 | |
5091 | if (newaddr == start) | |
5092 | { | |
3a5c3e22 | 5093 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5094 | break; |
5095 | } | |
5096 | } | |
5097 | /* Exact match not required. Within range is sufficient. */ | |
5098 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5099 | addr, loc->address, | |
5100 | loc->length)) | |
5101 | { | |
3a5c3e22 | 5102 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5103 | break; |
5104 | } | |
5105 | } | |
d983da9c DJ |
5106 | } |
5107 | ||
5108 | return 1; | |
5109 | } | |
5110 | ||
c906108c SS |
5111 | /* Possible return values for watchpoint_check (this can't be an enum |
5112 | because of check_errors). */ | |
5113 | /* The watchpoint has been deleted. */ | |
5114 | #define WP_DELETED 1 | |
5115 | /* The value has changed. */ | |
5116 | #define WP_VALUE_CHANGED 2 | |
5117 | /* The value has not changed. */ | |
5118 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5119 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5120 | #define WP_IGNORE 4 | |
c906108c SS |
5121 | |
5122 | #define BP_TEMPFLAG 1 | |
5123 | #define BP_HARDWAREFLAG 2 | |
5124 | ||
4a64f543 MS |
5125 | /* Evaluate watchpoint condition expression and check if its value |
5126 | changed. | |
553e4c11 JB |
5127 | |
5128 | P should be a pointer to struct bpstat, but is defined as a void * | |
5129 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5130 | |
5131 | static int | |
4efb68b1 | 5132 | watchpoint_check (void *p) |
c906108c SS |
5133 | { |
5134 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5135 | struct watchpoint *b; |
c906108c SS |
5136 | struct frame_info *fr; |
5137 | int within_current_scope; | |
5138 | ||
f431efe5 | 5139 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5140 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5141 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5142 | |
f6bc2008 PA |
5143 | /* If this is a local watchpoint, we only want to check if the |
5144 | watchpoint frame is in scope if the current thread is the thread | |
5145 | that was used to create the watchpoint. */ | |
5146 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5147 | return WP_IGNORE; |
f6bc2008 | 5148 | |
c906108c SS |
5149 | if (b->exp_valid_block == NULL) |
5150 | within_current_scope = 1; | |
5151 | else | |
5152 | { | |
edb3359d DJ |
5153 | struct frame_info *frame = get_current_frame (); |
5154 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5155 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5156 | ||
c9cf6e20 | 5157 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5158 | still in the function but the stack frame has already been |
5159 | invalidated. Since we can't rely on the values of local | |
5160 | variables after the stack has been destroyed, we are treating | |
5161 | the watchpoint in that state as `not changed' without further | |
5162 | checking. Don't mark watchpoints as changed if the current | |
5163 | frame is in an epilogue - even if they are in some other | |
5164 | frame, our view of the stack is likely to be wrong and | |
5165 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5166 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5167 | return WP_IGNORE; |
a0f49112 | 5168 | |
101dcfbe | 5169 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5170 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5171 | |
5172 | /* If we've gotten confused in the unwinder, we might have | |
5173 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5174 | if (within_current_scope) |
5175 | { | |
5176 | struct symbol *function; | |
5177 | ||
5178 | function = get_frame_function (fr); | |
5179 | if (function == NULL | |
5180 | || !contained_in (b->exp_valid_block, | |
5181 | SYMBOL_BLOCK_VALUE (function))) | |
5182 | within_current_scope = 0; | |
5183 | } | |
69fbadd5 | 5184 | |
edb3359d | 5185 | if (within_current_scope) |
c906108c SS |
5186 | /* If we end up stopping, the current frame will get selected |
5187 | in normal_stop. So this call to select_frame won't affect | |
5188 | the user. */ | |
0f7d239c | 5189 | select_frame (fr); |
c906108c | 5190 | } |
c5aa993b | 5191 | |
c906108c SS |
5192 | if (within_current_scope) |
5193 | { | |
4a64f543 MS |
5194 | /* We use value_{,free_to_}mark because it could be a *long* |
5195 | time before we return to the command level and call | |
5196 | free_all_values. We can't call free_all_values because we | |
5197 | might be in the middle of evaluating a function call. */ | |
c906108c | 5198 | |
0cf6dd15 | 5199 | int pc = 0; |
9c06b0b4 | 5200 | struct value *mark; |
fa4727a6 DJ |
5201 | struct value *new_val; |
5202 | ||
3a5c3e22 | 5203 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5204 | /* Since we don't know the exact trigger address (from |
5205 | stopped_data_address), just tell the user we've triggered | |
5206 | a mask watchpoint. */ | |
5207 | return WP_VALUE_CHANGED; | |
5208 | ||
5209 | mark = value_mark (); | |
3a1115a0 | 5210 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5211 | |
bb9d5f81 PP |
5212 | if (b->val_bitsize != 0) |
5213 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5214 | ||
4a64f543 MS |
5215 | /* We use value_equal_contents instead of value_equal because |
5216 | the latter coerces an array to a pointer, thus comparing just | |
5217 | the address of the array instead of its contents. This is | |
5218 | not what we want. */ | |
fa4727a6 | 5219 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5220 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5221 | { |
fa4727a6 DJ |
5222 | if (new_val != NULL) |
5223 | { | |
5224 | release_value (new_val); | |
5225 | value_free_to_mark (mark); | |
5226 | } | |
c906108c SS |
5227 | bs->old_val = b->val; |
5228 | b->val = new_val; | |
fa4727a6 | 5229 | b->val_valid = 1; |
c906108c SS |
5230 | return WP_VALUE_CHANGED; |
5231 | } | |
5232 | else | |
5233 | { | |
60e1c644 | 5234 | /* Nothing changed. */ |
c906108c | 5235 | value_free_to_mark (mark); |
c906108c SS |
5236 | return WP_VALUE_NOT_CHANGED; |
5237 | } | |
5238 | } | |
5239 | else | |
5240 | { | |
468afe6c | 5241 | struct switch_thru_all_uis state; |
79a45e25 | 5242 | |
c906108c | 5243 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5244 | if we temporarily ignored the watchpoint, then when |
5245 | we reenter the block in which it is valid it contains | |
5246 | garbage (in the case of a function, it may have two | |
5247 | garbage values, one before and one after the prologue). | |
5248 | So we can't even detect the first assignment to it and | |
5249 | watch after that (since the garbage may or may not equal | |
5250 | the first value assigned). */ | |
348d480f PA |
5251 | /* We print all the stop information in |
5252 | breakpoint_ops->print_it, but in this case, by the time we | |
5253 | call breakpoint_ops->print_it this bp will be deleted | |
5254 | already. So we have no choice but print the information | |
5255 | here. */ | |
468afe6c PA |
5256 | |
5257 | SWITCH_THRU_ALL_UIS (state) | |
5258 | { | |
5259 | struct ui_out *uiout = current_uiout; | |
5260 | ||
5261 | if (ui_out_is_mi_like_p (uiout)) | |
5262 | ui_out_field_string | |
5263 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5264 | ui_out_text (uiout, "\nWatchpoint "); | |
5265 | ui_out_field_int (uiout, "wpnum", b->base.number); | |
5266 | ui_out_text (uiout, | |
5267 | " deleted because the program has left the block in\n" | |
5268 | "which its expression is valid.\n"); | |
5269 | } | |
4ce44c66 | 5270 | |
cdac0397 | 5271 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5272 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5273 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5274 | |
5275 | return WP_DELETED; | |
5276 | } | |
5277 | } | |
5278 | ||
18a18393 | 5279 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5280 | breakpoint location BL. This function does not check if we should |
5281 | stop, only if BL explains the stop. */ | |
5282 | ||
18a18393 | 5283 | static int |
6c95b8df | 5284 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5285 | struct address_space *aspace, CORE_ADDR bp_addr, |
5286 | const struct target_waitstatus *ws) | |
18a18393 VP |
5287 | { |
5288 | struct breakpoint *b = bl->owner; | |
5289 | ||
348d480f | 5290 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5291 | gdb_assert (b != NULL); |
5292 | ||
09ac7c10 | 5293 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5294 | } |
5295 | ||
3a5c3e22 PA |
5296 | /* Determine if the watched values have actually changed, and we |
5297 | should stop. If not, set BS->stop to 0. */ | |
5298 | ||
18a18393 VP |
5299 | static void |
5300 | bpstat_check_watchpoint (bpstat bs) | |
5301 | { | |
2bdf28a0 | 5302 | const struct bp_location *bl; |
3a5c3e22 | 5303 | struct watchpoint *b; |
2bdf28a0 JK |
5304 | |
5305 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5306 | bl = bs->bp_location_at; |
2bdf28a0 | 5307 | gdb_assert (bl != NULL); |
3a5c3e22 | 5308 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5309 | gdb_assert (b != NULL); |
18a18393 | 5310 | |
18a18393 | 5311 | { |
18a18393 VP |
5312 | int must_check_value = 0; |
5313 | ||
3a5c3e22 | 5314 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5315 | /* For a software watchpoint, we must always check the |
5316 | watched value. */ | |
5317 | must_check_value = 1; | |
5318 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5319 | /* We have a hardware watchpoint (read, write, or access) | |
5320 | and the target earlier reported an address watched by | |
5321 | this watchpoint. */ | |
5322 | must_check_value = 1; | |
5323 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5324 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5325 | /* We were stopped by a hardware watchpoint, but the target could |
5326 | not report the data address. We must check the watchpoint's | |
5327 | value. Access and read watchpoints are out of luck; without | |
5328 | a data address, we can't figure it out. */ | |
5329 | must_check_value = 1; | |
3a5c3e22 | 5330 | |
18a18393 VP |
5331 | if (must_check_value) |
5332 | { | |
3e43a32a MS |
5333 | char *message |
5334 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5335 | b->base.number); |
18a18393 VP |
5336 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5337 | int e = catch_errors (watchpoint_check, bs, message, | |
5338 | RETURN_MASK_ALL); | |
5339 | do_cleanups (cleanups); | |
5340 | switch (e) | |
5341 | { | |
5342 | case WP_DELETED: | |
5343 | /* We've already printed what needs to be printed. */ | |
5344 | bs->print_it = print_it_done; | |
5345 | /* Stop. */ | |
5346 | break; | |
60e1c644 PA |
5347 | case WP_IGNORE: |
5348 | bs->print_it = print_it_noop; | |
5349 | bs->stop = 0; | |
5350 | break; | |
18a18393 | 5351 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5352 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5353 | { |
85d721b8 PA |
5354 | /* There are two cases to consider here: |
5355 | ||
4a64f543 | 5356 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5357 | In that case, trust the target, and always report |
5358 | the watchpoint hit to the user. Even though | |
5359 | reads don't cause value changes, the value may | |
5360 | have changed since the last time it was read, and | |
5361 | since we're not trapping writes, we will not see | |
5362 | those, and as such we should ignore our notion of | |
5363 | old value. | |
5364 | ||
4a64f543 | 5365 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5366 | reads and writes. There are two ways this may |
5367 | happen: | |
5368 | ||
4a64f543 | 5369 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5370 | reads only, but can break on accesses (reads or |
5371 | writes), such as e.g., x86. We detect this case | |
5372 | at the time we try to insert read watchpoints. | |
5373 | ||
4a64f543 | 5374 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5375 | watchpoints, but, the user set an access or write |
5376 | watchpoint watching the same memory as this read | |
5377 | watchpoint. | |
5378 | ||
5379 | If we're watching memory writes as well as reads, | |
5380 | ignore watchpoint hits when we find that the | |
5381 | value hasn't changed, as reads don't cause | |
5382 | changes. This still gives false positives when | |
5383 | the program writes the same value to memory as | |
5384 | what there was already in memory (we will confuse | |
5385 | it for a read), but it's much better than | |
5386 | nothing. */ | |
5387 | ||
5388 | int other_write_watchpoint = 0; | |
5389 | ||
5390 | if (bl->watchpoint_type == hw_read) | |
5391 | { | |
5392 | struct breakpoint *other_b; | |
5393 | ||
5394 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5395 | if (other_b->type == bp_hardware_watchpoint |
5396 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5397 | { |
3a5c3e22 PA |
5398 | struct watchpoint *other_w = |
5399 | (struct watchpoint *) other_b; | |
5400 | ||
5401 | if (other_w->watchpoint_triggered | |
5402 | == watch_triggered_yes) | |
5403 | { | |
5404 | other_write_watchpoint = 1; | |
5405 | break; | |
5406 | } | |
85d721b8 PA |
5407 | } |
5408 | } | |
5409 | ||
5410 | if (other_write_watchpoint | |
5411 | || bl->watchpoint_type == hw_access) | |
5412 | { | |
5413 | /* We're watching the same memory for writes, | |
5414 | and the value changed since the last time we | |
5415 | updated it, so this trap must be for a write. | |
5416 | Ignore it. */ | |
5417 | bs->print_it = print_it_noop; | |
5418 | bs->stop = 0; | |
5419 | } | |
18a18393 VP |
5420 | } |
5421 | break; | |
5422 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5423 | if (b->base.type == bp_hardware_watchpoint |
5424 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5425 | { |
5426 | /* Don't stop: write watchpoints shouldn't fire if | |
5427 | the value hasn't changed. */ | |
5428 | bs->print_it = print_it_noop; | |
5429 | bs->stop = 0; | |
5430 | } | |
5431 | /* Stop. */ | |
5432 | break; | |
5433 | default: | |
5434 | /* Can't happen. */ | |
5435 | case 0: | |
5436 | /* Error from catch_errors. */ | |
468afe6c PA |
5437 | { |
5438 | struct switch_thru_all_uis state; | |
5439 | ||
5440 | SWITCH_THRU_ALL_UIS (state) | |
5441 | { | |
5442 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5443 | b->base.number); | |
5444 | } | |
5445 | watchpoint_del_at_next_stop (b); | |
5446 | /* We've already printed what needs to be printed. */ | |
5447 | bs->print_it = print_it_done; | |
5448 | } | |
18a18393 VP |
5449 | break; |
5450 | } | |
5451 | } | |
5452 | else /* must_check_value == 0 */ | |
5453 | { | |
5454 | /* This is a case where some watchpoint(s) triggered, but | |
5455 | not at the address of this watchpoint, or else no | |
5456 | watchpoint triggered after all. So don't print | |
5457 | anything for this watchpoint. */ | |
5458 | bs->print_it = print_it_noop; | |
5459 | bs->stop = 0; | |
5460 | } | |
5461 | } | |
5462 | } | |
5463 | ||
7d4df6a4 DE |
5464 | /* For breakpoints that are currently marked as telling gdb to stop, |
5465 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5466 | of breakpoint referred to by BS. If we should not stop for this |
5467 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5468 | |
18a18393 VP |
5469 | static void |
5470 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5471 | { | |
2bdf28a0 JK |
5472 | const struct bp_location *bl; |
5473 | struct breakpoint *b; | |
7d4df6a4 DE |
5474 | int value_is_zero = 0; |
5475 | struct expression *cond; | |
5476 | ||
5477 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5478 | |
5479 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5480 | bl = bs->bp_location_at; |
2bdf28a0 | 5481 | gdb_assert (bl != NULL); |
f431efe5 | 5482 | b = bs->breakpoint_at; |
2bdf28a0 | 5483 | gdb_assert (b != NULL); |
18a18393 | 5484 | |
b775012e LM |
5485 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5486 | need to do so again since GDB does not know if we stopped due to a | |
5487 | breakpoint or a single step breakpoint. */ | |
5488 | ||
18a18393 | 5489 | if (frame_id_p (b->frame_id) |
edb3359d | 5490 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5491 | { |
7d4df6a4 DE |
5492 | bs->stop = 0; |
5493 | return; | |
5494 | } | |
60e1c644 | 5495 | |
12ab52e9 PA |
5496 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5497 | evaluating the condition if this isn't the specified | |
5498 | thread/task. */ | |
5d5658a1 | 5499 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5500 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5501 | ||
6c1b0f7b DE |
5502 | { |
5503 | bs->stop = 0; | |
5504 | return; | |
5505 | } | |
5506 | ||
6dddc817 DE |
5507 | /* Evaluate extension language breakpoints that have a "stop" method |
5508 | implemented. */ | |
5509 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5510 | |
7d4df6a4 DE |
5511 | if (is_watchpoint (b)) |
5512 | { | |
5513 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5514 | |
7d4df6a4 DE |
5515 | cond = w->cond_exp; |
5516 | } | |
5517 | else | |
5518 | cond = bl->cond; | |
60e1c644 | 5519 | |
7d4df6a4 DE |
5520 | if (cond && b->disposition != disp_del_at_next_stop) |
5521 | { | |
5522 | int within_current_scope = 1; | |
5523 | struct watchpoint * w; | |
60e1c644 | 5524 | |
7d4df6a4 DE |
5525 | /* We use value_mark and value_free_to_mark because it could |
5526 | be a long time before we return to the command level and | |
5527 | call free_all_values. We can't call free_all_values | |
5528 | because we might be in the middle of evaluating a | |
5529 | function call. */ | |
5530 | struct value *mark = value_mark (); | |
5531 | ||
5532 | if (is_watchpoint (b)) | |
5533 | w = (struct watchpoint *) b; | |
5534 | else | |
5535 | w = NULL; | |
5536 | ||
5537 | /* Need to select the frame, with all that implies so that | |
5538 | the conditions will have the right context. Because we | |
5539 | use the frame, we will not see an inlined function's | |
5540 | variables when we arrive at a breakpoint at the start | |
5541 | of the inlined function; the current frame will be the | |
5542 | call site. */ | |
5543 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5544 | select_frame (get_current_frame ()); | |
5545 | else | |
18a18393 | 5546 | { |
7d4df6a4 DE |
5547 | struct frame_info *frame; |
5548 | ||
5549 | /* For local watchpoint expressions, which particular | |
5550 | instance of a local is being watched matters, so we | |
5551 | keep track of the frame to evaluate the expression | |
5552 | in. To evaluate the condition however, it doesn't | |
5553 | really matter which instantiation of the function | |
5554 | where the condition makes sense triggers the | |
5555 | watchpoint. This allows an expression like "watch | |
5556 | global if q > 10" set in `func', catch writes to | |
5557 | global on all threads that call `func', or catch | |
5558 | writes on all recursive calls of `func' by a single | |
5559 | thread. We simply always evaluate the condition in | |
5560 | the innermost frame that's executing where it makes | |
5561 | sense to evaluate the condition. It seems | |
5562 | intuitive. */ | |
5563 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5564 | if (frame != NULL) | |
5565 | select_frame (frame); | |
5566 | else | |
5567 | within_current_scope = 0; | |
18a18393 | 5568 | } |
7d4df6a4 DE |
5569 | if (within_current_scope) |
5570 | value_is_zero | |
5571 | = catch_errors (breakpoint_cond_eval, cond, | |
5572 | "Error in testing breakpoint condition:\n", | |
5573 | RETURN_MASK_ALL); | |
5574 | else | |
18a18393 | 5575 | { |
7d4df6a4 DE |
5576 | warning (_("Watchpoint condition cannot be tested " |
5577 | "in the current scope")); | |
5578 | /* If we failed to set the right context for this | |
5579 | watchpoint, unconditionally report it. */ | |
5580 | value_is_zero = 0; | |
18a18393 | 5581 | } |
7d4df6a4 DE |
5582 | /* FIXME-someday, should give breakpoint #. */ |
5583 | value_free_to_mark (mark); | |
18a18393 | 5584 | } |
7d4df6a4 DE |
5585 | |
5586 | if (cond && value_is_zero) | |
5587 | { | |
5588 | bs->stop = 0; | |
5589 | } | |
7d4df6a4 DE |
5590 | else if (b->ignore_count > 0) |
5591 | { | |
5592 | b->ignore_count--; | |
5593 | bs->stop = 0; | |
5594 | /* Increase the hit count even though we don't stop. */ | |
5595 | ++(b->hit_count); | |
5596 | observer_notify_breakpoint_modified (b); | |
5597 | } | |
18a18393 VP |
5598 | } |
5599 | ||
1cf4d951 PA |
5600 | /* Returns true if we need to track moribund locations of LOC's type |
5601 | on the current target. */ | |
5602 | ||
5603 | static int | |
5604 | need_moribund_for_location_type (struct bp_location *loc) | |
5605 | { | |
5606 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5607 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5608 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5609 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5610 | } | |
5611 | ||
18a18393 | 5612 | |
9709f61c | 5613 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5614 | BP_ADDR in thread PTID. |
c906108c | 5615 | |
d983da9c | 5616 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5617 | don't understand this stop. Result is a chain of bpstat's such |
5618 | that: | |
c906108c | 5619 | |
c5aa993b | 5620 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5621 | |
c5aa993b | 5622 | if we understand why we stopped, the result is not null. |
c906108c | 5623 | |
c5aa993b JM |
5624 | Each element of the chain refers to a particular breakpoint or |
5625 | watchpoint at which we have stopped. (We may have stopped for | |
5626 | several reasons concurrently.) | |
c906108c | 5627 | |
c5aa993b JM |
5628 | Each element of the chain has valid next, breakpoint_at, |
5629 | commands, FIXME??? fields. */ | |
c906108c SS |
5630 | |
5631 | bpstat | |
6c95b8df | 5632 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5633 | CORE_ADDR bp_addr, ptid_t ptid, |
5634 | const struct target_waitstatus *ws) | |
c906108c | 5635 | { |
0d381245 | 5636 | struct breakpoint *b = NULL; |
afe38095 | 5637 | struct bp_location *bl; |
20874c92 | 5638 | struct bp_location *loc; |
5760d0ab JK |
5639 | /* First item of allocated bpstat's. */ |
5640 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5641 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5642 | bpstat bs; |
20874c92 | 5643 | int ix; |
429374b8 | 5644 | int need_remove_insert; |
f431efe5 | 5645 | int removed_any; |
c906108c | 5646 | |
f431efe5 PA |
5647 | /* First, build the bpstat chain with locations that explain a |
5648 | target stop, while being careful to not set the target running, | |
5649 | as that may invalidate locations (in particular watchpoint | |
5650 | locations are recreated). Resuming will happen here with | |
5651 | breakpoint conditions or watchpoint expressions that include | |
5652 | inferior function calls. */ | |
c5aa993b | 5653 | |
429374b8 JK |
5654 | ALL_BREAKPOINTS (b) |
5655 | { | |
1a853c52 | 5656 | if (!breakpoint_enabled (b)) |
429374b8 | 5657 | continue; |
a5606eee | 5658 | |
429374b8 JK |
5659 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5660 | { | |
4a64f543 MS |
5661 | /* For hardware watchpoints, we look only at the first |
5662 | location. The watchpoint_check function will work on the | |
5663 | entire expression, not the individual locations. For | |
5664 | read watchpoints, the watchpoints_triggered function has | |
5665 | checked all locations already. */ | |
429374b8 JK |
5666 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5667 | break; | |
18a18393 | 5668 | |
f6592439 | 5669 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5670 | continue; |
c5aa993b | 5671 | |
09ac7c10 | 5672 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5673 | continue; |
c5aa993b | 5674 | |
4a64f543 MS |
5675 | /* Come here if it's a watchpoint, or if the break address |
5676 | matches. */ | |
c5aa993b | 5677 | |
4a64f543 MS |
5678 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5679 | explain stop. */ | |
c5aa993b | 5680 | |
f431efe5 PA |
5681 | /* Assume we stop. Should we find a watchpoint that is not |
5682 | actually triggered, or if the condition of the breakpoint | |
5683 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5684 | bs->stop = 1; |
5685 | bs->print = 1; | |
d983da9c | 5686 | |
f431efe5 PA |
5687 | /* If this is a scope breakpoint, mark the associated |
5688 | watchpoint as triggered so that we will handle the | |
5689 | out-of-scope event. We'll get to the watchpoint next | |
5690 | iteration. */ | |
d0fb5eae | 5691 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5692 | { |
5693 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5694 | ||
5695 | w->watchpoint_triggered = watch_triggered_yes; | |
5696 | } | |
f431efe5 PA |
5697 | } |
5698 | } | |
5699 | ||
7c16b83e | 5700 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5701 | if (!target_supports_stopped_by_sw_breakpoint () |
5702 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5703 | { |
1cf4d951 | 5704 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5705 | { |
1cf4d951 PA |
5706 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5707 | && need_moribund_for_location_type (loc)) | |
5708 | { | |
5709 | bs = bpstat_alloc (loc, &bs_link); | |
5710 | /* For hits of moribund locations, we should just proceed. */ | |
5711 | bs->stop = 0; | |
5712 | bs->print = 0; | |
5713 | bs->print_it = print_it_noop; | |
5714 | } | |
f431efe5 PA |
5715 | } |
5716 | } | |
5717 | ||
edcc5120 TT |
5718 | /* A bit of special processing for shlib breakpoints. We need to |
5719 | process solib loading here, so that the lists of loaded and | |
5720 | unloaded libraries are correct before we handle "catch load" and | |
5721 | "catch unload". */ | |
5722 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5723 | { | |
5d268276 | 5724 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5725 | { |
5726 | handle_solib_event (); | |
5727 | break; | |
5728 | } | |
5729 | } | |
5730 | ||
f431efe5 PA |
5731 | /* Now go through the locations that caused the target to stop, and |
5732 | check whether we're interested in reporting this stop to higher | |
5733 | layers, or whether we should resume the target transparently. */ | |
5734 | ||
5735 | removed_any = 0; | |
5736 | ||
5760d0ab | 5737 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5738 | { |
5739 | if (!bs->stop) | |
5740 | continue; | |
5741 | ||
f431efe5 | 5742 | b = bs->breakpoint_at; |
348d480f PA |
5743 | b->ops->check_status (bs); |
5744 | if (bs->stop) | |
28010a5d | 5745 | { |
348d480f | 5746 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5747 | |
429374b8 JK |
5748 | if (bs->stop) |
5749 | { | |
5750 | ++(b->hit_count); | |
8d3788bd | 5751 | observer_notify_breakpoint_modified (b); |
c906108c | 5752 | |
4a64f543 | 5753 | /* We will stop here. */ |
429374b8 JK |
5754 | if (b->disposition == disp_disable) |
5755 | { | |
816338b5 | 5756 | --(b->enable_count); |
1a853c52 | 5757 | if (b->enable_count <= 0) |
429374b8 | 5758 | b->enable_state = bp_disabled; |
f431efe5 | 5759 | removed_any = 1; |
429374b8 JK |
5760 | } |
5761 | if (b->silent) | |
5762 | bs->print = 0; | |
5763 | bs->commands = b->commands; | |
9add0f1b | 5764 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5765 | if (command_line_is_silent (bs->commands |
5766 | ? bs->commands->commands : NULL)) | |
5767 | bs->print = 0; | |
9d6e6e84 HZ |
5768 | |
5769 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5770 | } |
5771 | ||
348d480f | 5772 | } |
a9b3a50f PA |
5773 | |
5774 | /* Print nothing for this entry if we don't stop or don't | |
5775 | print. */ | |
5776 | if (!bs->stop || !bs->print) | |
5777 | bs->print_it = print_it_noop; | |
429374b8 | 5778 | } |
876fa593 | 5779 | |
d983da9c DJ |
5780 | /* If we aren't stopping, the value of some hardware watchpoint may |
5781 | not have changed, but the intermediate memory locations we are | |
5782 | watching may have. Don't bother if we're stopping; this will get | |
5783 | done later. */ | |
d832cb68 | 5784 | need_remove_insert = 0; |
5760d0ab JK |
5785 | if (! bpstat_causes_stop (bs_head)) |
5786 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5787 | if (!bs->stop |
f431efe5 PA |
5788 | && bs->breakpoint_at |
5789 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5790 | { |
3a5c3e22 PA |
5791 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5792 | ||
5793 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5794 | need_remove_insert = 1; |
d983da9c DJ |
5795 | } |
5796 | ||
d832cb68 | 5797 | if (need_remove_insert) |
44702360 | 5798 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5799 | else if (removed_any) |
44702360 | 5800 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5801 | |
5760d0ab | 5802 | return bs_head; |
c906108c | 5803 | } |
628fe4e4 JK |
5804 | |
5805 | static void | |
5806 | handle_jit_event (void) | |
5807 | { | |
5808 | struct frame_info *frame; | |
5809 | struct gdbarch *gdbarch; | |
5810 | ||
243a9253 PA |
5811 | if (debug_infrun) |
5812 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5813 | ||
628fe4e4 JK |
5814 | /* Switch terminal for any messages produced by |
5815 | breakpoint_re_set. */ | |
5816 | target_terminal_ours_for_output (); | |
5817 | ||
5818 | frame = get_current_frame (); | |
5819 | gdbarch = get_frame_arch (frame); | |
5820 | ||
5821 | jit_event_handler (gdbarch); | |
5822 | ||
5823 | target_terminal_inferior (); | |
5824 | } | |
5825 | ||
5826 | /* Prepare WHAT final decision for infrun. */ | |
5827 | ||
5828 | /* Decide what infrun needs to do with this bpstat. */ | |
5829 | ||
c906108c | 5830 | struct bpstat_what |
0e30163f | 5831 | bpstat_what (bpstat bs_head) |
c906108c | 5832 | { |
c906108c | 5833 | struct bpstat_what retval; |
0e30163f | 5834 | bpstat bs; |
c906108c | 5835 | |
628fe4e4 | 5836 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5837 | retval.call_dummy = STOP_NONE; |
186c406b | 5838 | retval.is_longjmp = 0; |
628fe4e4 | 5839 | |
0e30163f | 5840 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5841 | { |
628fe4e4 JK |
5842 | /* Extract this BS's action. After processing each BS, we check |
5843 | if its action overrides all we've seem so far. */ | |
5844 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5845 | enum bptype bptype; | |
5846 | ||
c906108c | 5847 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5848 | { |
5849 | /* I suspect this can happen if it was a momentary | |
5850 | breakpoint which has since been deleted. */ | |
5851 | bptype = bp_none; | |
5852 | } | |
20874c92 | 5853 | else |
f431efe5 | 5854 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5855 | |
5856 | switch (bptype) | |
c906108c SS |
5857 | { |
5858 | case bp_none: | |
628fe4e4 | 5859 | break; |
c906108c SS |
5860 | case bp_breakpoint: |
5861 | case bp_hardware_breakpoint: | |
7c16b83e | 5862 | case bp_single_step: |
c906108c SS |
5863 | case bp_until: |
5864 | case bp_finish: | |
a9b3a50f | 5865 | case bp_shlib_event: |
c906108c SS |
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 | 5874 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5875 | break; |
5876 | case bp_watchpoint: | |
5877 | case bp_hardware_watchpoint: | |
5878 | case bp_read_watchpoint: | |
5879 | case bp_access_watchpoint: | |
5880 | if (bs->stop) | |
5881 | { | |
5882 | if (bs->print) | |
628fe4e4 | 5883 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5884 | else |
628fe4e4 | 5885 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5886 | } |
5887 | else | |
628fe4e4 JK |
5888 | { |
5889 | /* There was a watchpoint, but we're not stopping. | |
5890 | This requires no further action. */ | |
5891 | } | |
c906108c SS |
5892 | break; |
5893 | case bp_longjmp: | |
e2e4d78b | 5894 | case bp_longjmp_call_dummy: |
186c406b | 5895 | case bp_exception: |
0a39bb32 PA |
5896 | if (bs->stop) |
5897 | { | |
5898 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5899 | retval.is_longjmp = bptype != bp_exception; | |
5900 | } | |
5901 | else | |
5902 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5903 | break; |
5904 | case bp_longjmp_resume: | |
186c406b | 5905 | case bp_exception_resume: |
0a39bb32 PA |
5906 | if (bs->stop) |
5907 | { | |
5908 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5909 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5910 | } | |
5911 | else | |
5912 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5913 | break; |
5914 | case bp_step_resume: | |
5915 | if (bs->stop) | |
628fe4e4 JK |
5916 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5917 | else | |
c906108c | 5918 | { |
628fe4e4 JK |
5919 | /* It is for the wrong frame. */ |
5920 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5921 | } |
c906108c | 5922 | break; |
2c03e5be PA |
5923 | case bp_hp_step_resume: |
5924 | if (bs->stop) | |
5925 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5926 | else | |
5927 | { | |
5928 | /* It is for the wrong frame. */ | |
5929 | this_action = BPSTAT_WHAT_SINGLE; | |
5930 | } | |
5931 | break; | |
c906108c | 5932 | case bp_watchpoint_scope: |
c4093a6a | 5933 | case bp_thread_event: |
1900040c | 5934 | case bp_overlay_event: |
0fd8e87f | 5935 | case bp_longjmp_master: |
aa7d318d | 5936 | case bp_std_terminate_master: |
186c406b | 5937 | case bp_exception_master: |
628fe4e4 | 5938 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5939 | break; |
ce78b96d | 5940 | case bp_catchpoint: |
c5aa993b JM |
5941 | if (bs->stop) |
5942 | { | |
5943 | if (bs->print) | |
628fe4e4 | 5944 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5945 | else |
628fe4e4 | 5946 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5947 | } |
5948 | else | |
628fe4e4 JK |
5949 | { |
5950 | /* There was a catchpoint, but we're not stopping. | |
5951 | This requires no further action. */ | |
5952 | } | |
5953 | break; | |
628fe4e4 | 5954 | case bp_jit_event: |
628fe4e4 | 5955 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5956 | break; |
c906108c | 5957 | case bp_call_dummy: |
53a5351d JM |
5958 | /* Make sure the action is stop (silent or noisy), |
5959 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5960 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5961 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5962 | break; |
5963 | case bp_std_terminate: | |
5964 | /* Make sure the action is stop (silent or noisy), | |
5965 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5966 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5967 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5968 | break; |
1042e4c0 | 5969 | case bp_tracepoint: |
7a697b8d | 5970 | case bp_fast_tracepoint: |
0fb4aa4b | 5971 | case bp_static_tracepoint: |
1042e4c0 SS |
5972 | /* Tracepoint hits should not be reported back to GDB, and |
5973 | if one got through somehow, it should have been filtered | |
5974 | out already. */ | |
5975 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5976 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5977 | break; |
5978 | case bp_gnu_ifunc_resolver: | |
5979 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5980 | this_action = BPSTAT_WHAT_SINGLE; | |
5981 | break; | |
5982 | case bp_gnu_ifunc_resolver_return: | |
5983 | /* The breakpoint will be removed, execution will restart from the | |
5984 | PC of the former breakpoint. */ | |
5985 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5986 | break; | |
e7e0cddf SS |
5987 | |
5988 | case bp_dprintf: | |
a11cfd87 HZ |
5989 | if (bs->stop) |
5990 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5991 | else | |
5992 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5993 | break; |
5994 | ||
628fe4e4 JK |
5995 | default: |
5996 | internal_error (__FILE__, __LINE__, | |
5997 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5998 | } |
628fe4e4 | 5999 | |
325fac50 | 6000 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 6001 | } |
628fe4e4 | 6002 | |
243a9253 PA |
6003 | return retval; |
6004 | } | |
628fe4e4 | 6005 | |
243a9253 PA |
6006 | void |
6007 | bpstat_run_callbacks (bpstat bs_head) | |
6008 | { | |
6009 | bpstat bs; | |
628fe4e4 | 6010 | |
0e30163f JK |
6011 | for (bs = bs_head; bs != NULL; bs = bs->next) |
6012 | { | |
6013 | struct breakpoint *b = bs->breakpoint_at; | |
6014 | ||
6015 | if (b == NULL) | |
6016 | continue; | |
6017 | switch (b->type) | |
6018 | { | |
243a9253 PA |
6019 | case bp_jit_event: |
6020 | handle_jit_event (); | |
6021 | break; | |
0e30163f JK |
6022 | case bp_gnu_ifunc_resolver: |
6023 | gnu_ifunc_resolver_stop (b); | |
6024 | break; | |
6025 | case bp_gnu_ifunc_resolver_return: | |
6026 | gnu_ifunc_resolver_return_stop (b); | |
6027 | break; | |
6028 | } | |
6029 | } | |
c906108c SS |
6030 | } |
6031 | ||
6032 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6033 | without hardware support). This isn't related to a specific bpstat, | |
6034 | just to things like whether watchpoints are set. */ | |
6035 | ||
c5aa993b | 6036 | int |
fba45db2 | 6037 | bpstat_should_step (void) |
c906108c SS |
6038 | { |
6039 | struct breakpoint *b; | |
cc59ec59 | 6040 | |
c906108c | 6041 | ALL_BREAKPOINTS (b) |
717a8278 | 6042 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6043 | return 1; |
c906108c SS |
6044 | return 0; |
6045 | } | |
6046 | ||
67822962 PA |
6047 | int |
6048 | bpstat_causes_stop (bpstat bs) | |
6049 | { | |
6050 | for (; bs != NULL; bs = bs->next) | |
6051 | if (bs->stop) | |
6052 | return 1; | |
6053 | ||
6054 | return 0; | |
6055 | } | |
6056 | ||
c906108c | 6057 | \f |
c5aa993b | 6058 | |
170b53b2 UW |
6059 | /* Compute a string of spaces suitable to indent the next line |
6060 | so it starts at the position corresponding to the table column | |
6061 | named COL_NAME in the currently active table of UIOUT. */ | |
6062 | ||
6063 | static char * | |
6064 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6065 | { | |
6066 | static char wrap_indent[80]; | |
6067 | int i, total_width, width, align; | |
6068 | char *text; | |
6069 | ||
6070 | total_width = 0; | |
6071 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
6072 | { | |
6073 | if (strcmp (text, col_name) == 0) | |
6074 | { | |
6075 | gdb_assert (total_width < sizeof wrap_indent); | |
6076 | memset (wrap_indent, ' ', total_width); | |
6077 | wrap_indent[total_width] = 0; | |
6078 | ||
6079 | return wrap_indent; | |
6080 | } | |
6081 | ||
6082 | total_width += width + 1; | |
6083 | } | |
6084 | ||
6085 | return NULL; | |
6086 | } | |
6087 | ||
b775012e LM |
6088 | /* Determine if the locations of this breakpoint will have their conditions |
6089 | evaluated by the target, host or a mix of both. Returns the following: | |
6090 | ||
6091 | "host": Host evals condition. | |
6092 | "host or target": Host or Target evals condition. | |
6093 | "target": Target evals condition. | |
6094 | */ | |
6095 | ||
6096 | static const char * | |
6097 | bp_condition_evaluator (struct breakpoint *b) | |
6098 | { | |
6099 | struct bp_location *bl; | |
6100 | char host_evals = 0; | |
6101 | char target_evals = 0; | |
6102 | ||
6103 | if (!b) | |
6104 | return NULL; | |
6105 | ||
6106 | if (!is_breakpoint (b)) | |
6107 | return NULL; | |
6108 | ||
6109 | if (gdb_evaluates_breakpoint_condition_p () | |
6110 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6111 | return condition_evaluation_host; | |
6112 | ||
6113 | for (bl = b->loc; bl; bl = bl->next) | |
6114 | { | |
6115 | if (bl->cond_bytecode) | |
6116 | target_evals++; | |
6117 | else | |
6118 | host_evals++; | |
6119 | } | |
6120 | ||
6121 | if (host_evals && target_evals) | |
6122 | return condition_evaluation_both; | |
6123 | else if (target_evals) | |
6124 | return condition_evaluation_target; | |
6125 | else | |
6126 | return condition_evaluation_host; | |
6127 | } | |
6128 | ||
6129 | /* Determine the breakpoint location's condition evaluator. This is | |
6130 | similar to bp_condition_evaluator, but for locations. */ | |
6131 | ||
6132 | static const char * | |
6133 | bp_location_condition_evaluator (struct bp_location *bl) | |
6134 | { | |
6135 | if (bl && !is_breakpoint (bl->owner)) | |
6136 | return NULL; | |
6137 | ||
6138 | if (gdb_evaluates_breakpoint_condition_p () | |
6139 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6140 | return condition_evaluation_host; | |
6141 | ||
6142 | if (bl && bl->cond_bytecode) | |
6143 | return condition_evaluation_target; | |
6144 | else | |
6145 | return condition_evaluation_host; | |
6146 | } | |
6147 | ||
859825b8 JK |
6148 | /* Print the LOC location out of the list of B->LOC locations. */ |
6149 | ||
170b53b2 UW |
6150 | static void |
6151 | print_breakpoint_location (struct breakpoint *b, | |
6152 | struct bp_location *loc) | |
0d381245 | 6153 | { |
79a45e25 | 6154 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6155 | struct cleanup *old_chain = save_current_program_space (); |
6156 | ||
859825b8 JK |
6157 | if (loc != NULL && loc->shlib_disabled) |
6158 | loc = NULL; | |
6159 | ||
6c95b8df PA |
6160 | if (loc != NULL) |
6161 | set_current_program_space (loc->pspace); | |
6162 | ||
56435ebe | 6163 | if (b->display_canonical) |
f00aae0f KS |
6164 | ui_out_field_string (uiout, "what", |
6165 | event_location_to_string (b->location)); | |
2f202fde | 6166 | else if (loc && loc->symtab) |
0d381245 VP |
6167 | { |
6168 | struct symbol *sym | |
6169 | = find_pc_sect_function (loc->address, loc->section); | |
6170 | if (sym) | |
6171 | { | |
6172 | ui_out_text (uiout, "in "); | |
6173 | ui_out_field_string (uiout, "func", | |
6174 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6175 | ui_out_text (uiout, " "); |
6176 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6177 | ui_out_text (uiout, "at "); | |
0d381245 | 6178 | } |
05cba821 JK |
6179 | ui_out_field_string (uiout, "file", |
6180 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6181 | ui_out_text (uiout, ":"); |
05cba821 | 6182 | |
0d381245 | 6183 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6184 | ui_out_field_string (uiout, "fullname", |
6185 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6186 | |
f8eba3c6 | 6187 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6188 | } |
859825b8 | 6189 | else if (loc) |
0d381245 | 6190 | { |
f99d8bf4 PA |
6191 | struct ui_file *stb = mem_fileopen (); |
6192 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6193 | |
f99d8bf4 | 6194 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6195 | demangle, ""); |
0d381245 | 6196 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6197 | |
6198 | do_cleanups (stb_chain); | |
0d381245 | 6199 | } |
859825b8 | 6200 | else |
f00aae0f KS |
6201 | { |
6202 | ui_out_field_string (uiout, "pending", | |
6203 | event_location_to_string (b->location)); | |
6204 | /* If extra_string is available, it could be holding a condition | |
6205 | or dprintf arguments. In either case, make sure it is printed, | |
6206 | too, but only for non-MI streams. */ | |
6207 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) | |
6208 | { | |
6209 | if (b->type == bp_dprintf) | |
6210 | ui_out_text (uiout, ","); | |
6211 | else | |
6212 | ui_out_text (uiout, " "); | |
6213 | ui_out_text (uiout, b->extra_string); | |
6214 | } | |
6215 | } | |
6c95b8df | 6216 | |
b775012e LM |
6217 | if (loc && is_breakpoint (b) |
6218 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6219 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6220 | { | |
6221 | ui_out_text (uiout, " ("); | |
6222 | ui_out_field_string (uiout, "evaluated-by", | |
6223 | bp_location_condition_evaluator (loc)); | |
6224 | ui_out_text (uiout, ")"); | |
6225 | } | |
6226 | ||
6c95b8df | 6227 | do_cleanups (old_chain); |
0d381245 VP |
6228 | } |
6229 | ||
269b11a2 PA |
6230 | static const char * |
6231 | bptype_string (enum bptype type) | |
c906108c | 6232 | { |
c4093a6a JM |
6233 | struct ep_type_description |
6234 | { | |
6235 | enum bptype type; | |
6236 | char *description; | |
6237 | }; | |
6238 | static struct ep_type_description bptypes[] = | |
c906108c | 6239 | { |
c5aa993b JM |
6240 | {bp_none, "?deleted?"}, |
6241 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6242 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6243 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6244 | {bp_until, "until"}, |
6245 | {bp_finish, "finish"}, | |
6246 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6247 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6248 | {bp_read_watchpoint, "read watchpoint"}, |
6249 | {bp_access_watchpoint, "acc watchpoint"}, | |
6250 | {bp_longjmp, "longjmp"}, | |
6251 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6252 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6253 | {bp_exception, "exception"}, |
6254 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6255 | {bp_step_resume, "step resume"}, |
2c03e5be | 6256 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6257 | {bp_watchpoint_scope, "watchpoint scope"}, |
6258 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6259 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6260 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6261 | {bp_thread_event, "thread events"}, |
1900040c | 6262 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6263 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6264 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6265 | {bp_exception_master, "exception master"}, |
ce78b96d | 6266 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6267 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6268 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6269 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6270 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6271 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6272 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6273 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6274 | }; |
269b11a2 PA |
6275 | |
6276 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6277 | || ((int) type != bptypes[(int) type].type)) | |
6278 | internal_error (__FILE__, __LINE__, | |
6279 | _("bptypes table does not describe type #%d."), | |
6280 | (int) type); | |
6281 | ||
6282 | return bptypes[(int) type].description; | |
6283 | } | |
6284 | ||
998580f1 MK |
6285 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6286 | For CLI, prefix the list with the string 'inf'. */ | |
6287 | ||
6288 | static void | |
6289 | output_thread_groups (struct ui_out *uiout, | |
6290 | const char *field_name, | |
6291 | VEC(int) *inf_num, | |
6292 | int mi_only) | |
6293 | { | |
752eb8b4 | 6294 | struct cleanup *back_to; |
998580f1 MK |
6295 | int is_mi = ui_out_is_mi_like_p (uiout); |
6296 | int inf; | |
6297 | int i; | |
6298 | ||
6299 | /* For backward compatibility, don't display inferiors in CLI unless | |
6300 | there are several. Always display them for MI. */ | |
6301 | if (!is_mi && mi_only) | |
6302 | return; | |
6303 | ||
752eb8b4 TT |
6304 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6305 | ||
998580f1 MK |
6306 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6307 | { | |
6308 | if (is_mi) | |
6309 | { | |
6310 | char mi_group[10]; | |
6311 | ||
6312 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6313 | ui_out_field_string (uiout, NULL, mi_group); | |
6314 | } | |
6315 | else | |
6316 | { | |
6317 | if (i == 0) | |
6318 | ui_out_text (uiout, " inf "); | |
6319 | else | |
6320 | ui_out_text (uiout, ", "); | |
6321 | ||
6322 | ui_out_text (uiout, plongest (inf)); | |
6323 | } | |
6324 | } | |
6325 | ||
6326 | do_cleanups (back_to); | |
6327 | } | |
6328 | ||
269b11a2 PA |
6329 | /* Print B to gdb_stdout. */ |
6330 | ||
6331 | static void | |
6332 | print_one_breakpoint_location (struct breakpoint *b, | |
6333 | struct bp_location *loc, | |
6334 | int loc_number, | |
6335 | struct bp_location **last_loc, | |
269b11a2 PA |
6336 | int allflag) |
6337 | { | |
6338 | struct command_line *l; | |
c2c6d25f | 6339 | static char bpenables[] = "nynny"; |
c906108c | 6340 | |
79a45e25 | 6341 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6342 | int header_of_multiple = 0; |
6343 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6344 | struct value_print_options opts; |
6345 | ||
6346 | get_user_print_options (&opts); | |
0d381245 VP |
6347 | |
6348 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6349 | /* See comment in print_one_breakpoint concerning treatment of |
6350 | breakpoints with single disabled location. */ | |
0d381245 VP |
6351 | if (loc == NULL |
6352 | && (b->loc != NULL | |
6353 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6354 | header_of_multiple = 1; | |
6355 | if (loc == NULL) | |
6356 | loc = b->loc; | |
6357 | ||
c4093a6a JM |
6358 | annotate_record (); |
6359 | ||
6360 | /* 1 */ | |
6361 | annotate_field (0); | |
0d381245 VP |
6362 | if (part_of_multiple) |
6363 | { | |
6364 | char *formatted; | |
0c6773c1 | 6365 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6366 | ui_out_field_string (uiout, "number", formatted); |
6367 | xfree (formatted); | |
6368 | } | |
6369 | else | |
6370 | { | |
6371 | ui_out_field_int (uiout, "number", b->number); | |
6372 | } | |
c4093a6a JM |
6373 | |
6374 | /* 2 */ | |
6375 | annotate_field (1); | |
0d381245 VP |
6376 | if (part_of_multiple) |
6377 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6378 | else |
6379 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6380 | |
6381 | /* 3 */ | |
6382 | annotate_field (2); | |
0d381245 VP |
6383 | if (part_of_multiple) |
6384 | ui_out_field_skip (uiout, "disp"); | |
6385 | else | |
2cec12e5 | 6386 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6387 | |
c4093a6a JM |
6388 | |
6389 | /* 4 */ | |
6390 | annotate_field (3); | |
0d381245 | 6391 | if (part_of_multiple) |
54e52265 | 6392 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6393 | else |
4a64f543 MS |
6394 | ui_out_field_fmt (uiout, "enabled", "%c", |
6395 | bpenables[(int) b->enable_state]); | |
54e52265 | 6396 | ui_out_spaces (uiout, 2); |
0d381245 | 6397 | |
c4093a6a JM |
6398 | |
6399 | /* 5 and 6 */ | |
3086aeae | 6400 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6401 | { |
4a64f543 MS |
6402 | /* Although the print_one can possibly print all locations, |
6403 | calling it here is not likely to get any nice result. So, | |
6404 | make sure there's just one location. */ | |
0d381245 | 6405 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6406 | b->ops->print_one (b, last_loc); |
0d381245 | 6407 | } |
3086aeae DJ |
6408 | else |
6409 | switch (b->type) | |
6410 | { | |
6411 | case bp_none: | |
6412 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6413 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6414 | break; |
c906108c | 6415 | |
3086aeae DJ |
6416 | case bp_watchpoint: |
6417 | case bp_hardware_watchpoint: | |
6418 | case bp_read_watchpoint: | |
6419 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6420 | { |
6421 | struct watchpoint *w = (struct watchpoint *) b; | |
6422 | ||
6423 | /* Field 4, the address, is omitted (which makes the columns | |
6424 | not line up too nicely with the headers, but the effect | |
6425 | is relatively readable). */ | |
6426 | if (opts.addressprint) | |
6427 | ui_out_field_skip (uiout, "addr"); | |
6428 | annotate_field (5); | |
6429 | ui_out_field_string (uiout, "what", w->exp_string); | |
6430 | } | |
3086aeae DJ |
6431 | break; |
6432 | ||
3086aeae DJ |
6433 | case bp_breakpoint: |
6434 | case bp_hardware_breakpoint: | |
7c16b83e | 6435 | case bp_single_step: |
3086aeae DJ |
6436 | case bp_until: |
6437 | case bp_finish: | |
6438 | case bp_longjmp: | |
6439 | case bp_longjmp_resume: | |
e2e4d78b | 6440 | case bp_longjmp_call_dummy: |
186c406b TT |
6441 | case bp_exception: |
6442 | case bp_exception_resume: | |
3086aeae | 6443 | case bp_step_resume: |
2c03e5be | 6444 | case bp_hp_step_resume: |
3086aeae DJ |
6445 | case bp_watchpoint_scope: |
6446 | case bp_call_dummy: | |
aa7d318d | 6447 | case bp_std_terminate: |
3086aeae DJ |
6448 | case bp_shlib_event: |
6449 | case bp_thread_event: | |
6450 | case bp_overlay_event: | |
0fd8e87f | 6451 | case bp_longjmp_master: |
aa7d318d | 6452 | case bp_std_terminate_master: |
186c406b | 6453 | case bp_exception_master: |
1042e4c0 | 6454 | case bp_tracepoint: |
7a697b8d | 6455 | case bp_fast_tracepoint: |
0fb4aa4b | 6456 | case bp_static_tracepoint: |
e7e0cddf | 6457 | case bp_dprintf: |
4efc6507 | 6458 | case bp_jit_event: |
0e30163f JK |
6459 | case bp_gnu_ifunc_resolver: |
6460 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6461 | if (opts.addressprint) |
3086aeae DJ |
6462 | { |
6463 | annotate_field (4); | |
54e52265 | 6464 | if (header_of_multiple) |
0d381245 | 6465 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6466 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6467 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6468 | else |
5af949e3 UW |
6469 | ui_out_field_core_addr (uiout, "addr", |
6470 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6471 | } |
6472 | annotate_field (5); | |
0d381245 | 6473 | if (!header_of_multiple) |
170b53b2 | 6474 | print_breakpoint_location (b, loc); |
0d381245 | 6475 | if (b->loc) |
a6d9a66e | 6476 | *last_loc = b->loc; |
3086aeae DJ |
6477 | break; |
6478 | } | |
c906108c | 6479 | |
6c95b8df | 6480 | |
998580f1 | 6481 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6482 | { |
6483 | struct inferior *inf; | |
998580f1 MK |
6484 | VEC(int) *inf_num = NULL; |
6485 | int mi_only = 1; | |
6c95b8df | 6486 | |
998580f1 | 6487 | ALL_INFERIORS (inf) |
6c95b8df PA |
6488 | { |
6489 | if (inf->pspace == loc->pspace) | |
998580f1 | 6490 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6491 | } |
998580f1 MK |
6492 | |
6493 | /* For backward compatibility, don't display inferiors in CLI unless | |
6494 | there are several. Always display for MI. */ | |
6495 | if (allflag | |
6496 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6497 | && (number_of_program_spaces () > 1 | |
6498 | || number_of_inferiors () > 1) | |
6499 | /* LOC is for existing B, it cannot be in | |
6500 | moribund_locations and thus having NULL OWNER. */ | |
6501 | && loc->owner->type != bp_catchpoint)) | |
6502 | mi_only = 0; | |
6503 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6504 | VEC_free (int, inf_num); | |
6c95b8df PA |
6505 | } |
6506 | ||
4a306c9a | 6507 | if (!part_of_multiple) |
c4093a6a | 6508 | { |
4a306c9a JB |
6509 | if (b->thread != -1) |
6510 | { | |
6511 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6512 | "stop only in" line a little further down. */ |
4a306c9a JB |
6513 | ui_out_text (uiout, " thread "); |
6514 | ui_out_field_int (uiout, "thread", b->thread); | |
6515 | } | |
6516 | else if (b->task != 0) | |
6517 | { | |
6518 | ui_out_text (uiout, " task "); | |
6519 | ui_out_field_int (uiout, "task", b->task); | |
6520 | } | |
c4093a6a | 6521 | } |
f1310107 | 6522 | |
8b93c638 | 6523 | ui_out_text (uiout, "\n"); |
f1310107 | 6524 | |
348d480f | 6525 | if (!part_of_multiple) |
f1310107 TJB |
6526 | b->ops->print_one_detail (b, uiout); |
6527 | ||
0d381245 | 6528 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6529 | { |
6530 | annotate_field (6); | |
8b93c638 | 6531 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6532 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6533 | the frame ID. */ |
5af949e3 UW |
6534 | ui_out_field_core_addr (uiout, "frame", |
6535 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6536 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6537 | } |
6538 | ||
28010a5d | 6539 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6540 | { |
6541 | annotate_field (7); | |
d77f58be | 6542 | if (is_tracepoint (b)) |
1042e4c0 SS |
6543 | ui_out_text (uiout, "\ttrace only if "); |
6544 | else | |
6545 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6546 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6547 | |
6548 | /* Print whether the target is doing the breakpoint's condition | |
6549 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6550 | if (is_breakpoint (b) | |
6551 | && breakpoint_condition_evaluation_mode () | |
6552 | == condition_evaluation_target) | |
6553 | { | |
6554 | ui_out_text (uiout, " ("); | |
6555 | ui_out_field_string (uiout, "evaluated-by", | |
6556 | bp_condition_evaluator (b)); | |
6557 | ui_out_text (uiout, " evals)"); | |
6558 | } | |
0101ce28 JJ |
6559 | ui_out_text (uiout, "\n"); |
6560 | } | |
6561 | ||
0d381245 | 6562 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6563 | { |
4a64f543 | 6564 | /* FIXME should make an annotation for this. */ |
8b93c638 | 6565 | ui_out_text (uiout, "\tstop only in thread "); |
5d5658a1 PA |
6566 | if (ui_out_is_mi_like_p (uiout)) |
6567 | ui_out_field_int (uiout, "thread", b->thread); | |
6568 | else | |
6569 | { | |
6570 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6571 | ||
6572 | ui_out_field_string (uiout, "thread", print_thread_id (thr)); | |
6573 | } | |
8b93c638 | 6574 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6575 | } |
6576 | ||
556ec64d YQ |
6577 | if (!part_of_multiple) |
6578 | { | |
6579 | if (b->hit_count) | |
31f56a27 YQ |
6580 | { |
6581 | /* FIXME should make an annotation for this. */ | |
6582 | if (is_catchpoint (b)) | |
6583 | ui_out_text (uiout, "\tcatchpoint"); | |
6584 | else if (is_tracepoint (b)) | |
6585 | ui_out_text (uiout, "\ttracepoint"); | |
6586 | else | |
6587 | ui_out_text (uiout, "\tbreakpoint"); | |
6588 | ui_out_text (uiout, " already hit "); | |
6589 | ui_out_field_int (uiout, "times", b->hit_count); | |
6590 | if (b->hit_count == 1) | |
6591 | ui_out_text (uiout, " time\n"); | |
6592 | else | |
6593 | ui_out_text (uiout, " times\n"); | |
6594 | } | |
556ec64d YQ |
6595 | else |
6596 | { | |
31f56a27 YQ |
6597 | /* Output the count also if it is zero, but only if this is mi. */ |
6598 | if (ui_out_is_mi_like_p (uiout)) | |
6599 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6600 | } |
6601 | } | |
8b93c638 | 6602 | |
0d381245 | 6603 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6604 | { |
6605 | annotate_field (8); | |
8b93c638 JM |
6606 | ui_out_text (uiout, "\tignore next "); |
6607 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6608 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6609 | } |
059fb39f | 6610 | |
816338b5 SS |
6611 | /* Note that an enable count of 1 corresponds to "enable once" |
6612 | behavior, which is reported by the combination of enablement and | |
6613 | disposition, so we don't need to mention it here. */ | |
6614 | if (!part_of_multiple && b->enable_count > 1) | |
6615 | { | |
6616 | annotate_field (8); | |
6617 | ui_out_text (uiout, "\tdisable after "); | |
6618 | /* Tweak the wording to clarify that ignore and enable counts | |
6619 | are distinct, and have additive effect. */ | |
6620 | if (b->ignore_count) | |
6621 | ui_out_text (uiout, "additional "); | |
6622 | else | |
6623 | ui_out_text (uiout, "next "); | |
6624 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6625 | ui_out_text (uiout, " hits\n"); | |
6626 | } | |
6627 | ||
f196051f SS |
6628 | if (!part_of_multiple && is_tracepoint (b)) |
6629 | { | |
6630 | struct tracepoint *tp = (struct tracepoint *) b; | |
6631 | ||
6632 | if (tp->traceframe_usage) | |
6633 | { | |
6634 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6635 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6636 | ui_out_text (uiout, " bytes\n"); | |
6637 | } | |
6638 | } | |
d3ce09f5 | 6639 | |
9add0f1b | 6640 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6641 | if (!part_of_multiple && l) |
c4093a6a | 6642 | { |
3b31d625 EZ |
6643 | struct cleanup *script_chain; |
6644 | ||
c4093a6a | 6645 | annotate_field (9); |
3b31d625 | 6646 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6647 | print_command_lines (uiout, l, 4); |
3b31d625 | 6648 | do_cleanups (script_chain); |
c4093a6a | 6649 | } |
d24317b4 | 6650 | |
d9b3f62e | 6651 | if (is_tracepoint (b)) |
1042e4c0 | 6652 | { |
d9b3f62e PA |
6653 | struct tracepoint *t = (struct tracepoint *) b; |
6654 | ||
6655 | if (!part_of_multiple && t->pass_count) | |
6656 | { | |
6657 | annotate_field (10); | |
6658 | ui_out_text (uiout, "\tpass count "); | |
6659 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6660 | ui_out_text (uiout, " \n"); | |
6661 | } | |
f2a8bc8a YQ |
6662 | |
6663 | /* Don't display it when tracepoint or tracepoint location is | |
6664 | pending. */ | |
6665 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6666 | { | |
6667 | annotate_field (11); | |
6668 | ||
6669 | if (ui_out_is_mi_like_p (uiout)) | |
6670 | ui_out_field_string (uiout, "installed", | |
6671 | loc->inserted ? "y" : "n"); | |
6672 | else | |
6673 | { | |
6674 | if (loc->inserted) | |
6675 | ui_out_text (uiout, "\t"); | |
6676 | else | |
6677 | ui_out_text (uiout, "\tnot "); | |
6678 | ui_out_text (uiout, "installed on target\n"); | |
6679 | } | |
6680 | } | |
1042e4c0 SS |
6681 | } |
6682 | ||
d24317b4 VP |
6683 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6684 | { | |
3a5c3e22 PA |
6685 | if (is_watchpoint (b)) |
6686 | { | |
6687 | struct watchpoint *w = (struct watchpoint *) b; | |
6688 | ||
6689 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6690 | } | |
f00aae0f KS |
6691 | else if (b->location != NULL |
6692 | && event_location_to_string (b->location) != NULL) | |
6693 | ui_out_field_string (uiout, "original-location", | |
6694 | event_location_to_string (b->location)); | |
d24317b4 | 6695 | } |
c4093a6a | 6696 | } |
c5aa993b | 6697 | |
0d381245 VP |
6698 | static void |
6699 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6700 | struct bp_location **last_loc, |
6c95b8df | 6701 | int allflag) |
0d381245 | 6702 | { |
8d3788bd | 6703 | struct cleanup *bkpt_chain; |
79a45e25 | 6704 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6705 | |
6706 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6707 | ||
12c5a436 | 6708 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6709 | do_cleanups (bkpt_chain); |
0d381245 VP |
6710 | |
6711 | /* If this breakpoint has custom print function, | |
6712 | it's already printed. Otherwise, print individual | |
6713 | locations, if any. */ | |
6714 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6715 | { | |
4a64f543 MS |
6716 | /* If breakpoint has a single location that is disabled, we |
6717 | print it as if it had several locations, since otherwise it's | |
6718 | hard to represent "breakpoint enabled, location disabled" | |
6719 | situation. | |
6720 | ||
6721 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6722 | internally, that's not a property exposed to user. */ |
0d381245 | 6723 | if (b->loc |
a5606eee | 6724 | && !is_hardware_watchpoint (b) |
8d3788bd | 6725 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6726 | { |
6727 | struct bp_location *loc; | |
6728 | int n = 1; | |
8d3788bd | 6729 | |
0d381245 | 6730 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6731 | { |
6732 | struct cleanup *inner2 = | |
6733 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6734 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6735 | do_cleanups (inner2); | |
6736 | } | |
0d381245 VP |
6737 | } |
6738 | } | |
6739 | } | |
6740 | ||
a6d9a66e UW |
6741 | static int |
6742 | breakpoint_address_bits (struct breakpoint *b) | |
6743 | { | |
6744 | int print_address_bits = 0; | |
6745 | struct bp_location *loc; | |
6746 | ||
c6d81124 PA |
6747 | /* Software watchpoints that aren't watching memory don't have an |
6748 | address to print. */ | |
6749 | if (is_no_memory_software_watchpoint (b)) | |
6750 | return 0; | |
6751 | ||
a6d9a66e UW |
6752 | for (loc = b->loc; loc; loc = loc->next) |
6753 | { | |
c7437ca6 PA |
6754 | int addr_bit; |
6755 | ||
c7437ca6 | 6756 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6757 | if (addr_bit > print_address_bits) |
6758 | print_address_bits = addr_bit; | |
6759 | } | |
6760 | ||
6761 | return print_address_bits; | |
6762 | } | |
0d381245 | 6763 | |
c4093a6a JM |
6764 | struct captured_breakpoint_query_args |
6765 | { | |
6766 | int bnum; | |
6767 | }; | |
c5aa993b | 6768 | |
c4093a6a | 6769 | static int |
2b65245e | 6770 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6771 | { |
9a3c8263 SM |
6772 | struct captured_breakpoint_query_args *args |
6773 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6774 | struct breakpoint *b; |
a6d9a66e | 6775 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6776 | |
c4093a6a JM |
6777 | ALL_BREAKPOINTS (b) |
6778 | { | |
6779 | if (args->bnum == b->number) | |
c5aa993b | 6780 | { |
12c5a436 | 6781 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6782 | return GDB_RC_OK; |
c5aa993b | 6783 | } |
c4093a6a JM |
6784 | } |
6785 | return GDB_RC_NONE; | |
6786 | } | |
c5aa993b | 6787 | |
c4093a6a | 6788 | enum gdb_rc |
4a64f543 MS |
6789 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6790 | char **error_message) | |
c4093a6a JM |
6791 | { |
6792 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6793 | |
c4093a6a JM |
6794 | args.bnum = bnum; |
6795 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6796 | an error. */ |
b0b13bb4 DJ |
6797 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6798 | error_message, RETURN_MASK_ALL) < 0) | |
6799 | return GDB_RC_FAIL; | |
6800 | else | |
6801 | return GDB_RC_OK; | |
c4093a6a | 6802 | } |
c5aa993b | 6803 | |
09d682a4 TT |
6804 | /* Return true if this breakpoint was set by the user, false if it is |
6805 | internal or momentary. */ | |
6806 | ||
6807 | int | |
6808 | user_breakpoint_p (struct breakpoint *b) | |
6809 | { | |
46c6471b | 6810 | return b->number > 0; |
09d682a4 TT |
6811 | } |
6812 | ||
93daf339 TT |
6813 | /* See breakpoint.h. */ |
6814 | ||
6815 | int | |
6816 | pending_breakpoint_p (struct breakpoint *b) | |
6817 | { | |
6818 | return b->loc == NULL; | |
6819 | } | |
6820 | ||
7f3b0473 | 6821 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6822 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6823 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6824 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6825 | ones for which it returns non-zero. Return the total number of | |
6826 | breakpoints listed. */ | |
c906108c | 6827 | |
d77f58be | 6828 | static int |
e5a67952 | 6829 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6830 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6831 | { |
52f0bd74 | 6832 | struct breakpoint *b; |
a6d9a66e | 6833 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6834 | int nr_printable_breakpoints; |
3b31d625 | 6835 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6836 | struct value_print_options opts; |
a6d9a66e | 6837 | int print_address_bits = 0; |
269b11a2 | 6838 | int print_type_col_width = 14; |
79a45e25 | 6839 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6840 | |
79a45b7d TT |
6841 | get_user_print_options (&opts); |
6842 | ||
4a64f543 MS |
6843 | /* Compute the number of rows in the table, as well as the size |
6844 | required for address fields. */ | |
7f3b0473 AC |
6845 | nr_printable_breakpoints = 0; |
6846 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6847 | { |
6848 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6849 | if (filter && !filter (b)) | |
6850 | continue; | |
6851 | ||
6852 | /* If we have an "args" string, it is a list of breakpoints to | |
6853 | accept. Skip the others. */ | |
6854 | if (args != NULL && *args != '\0') | |
6855 | { | |
6856 | if (allflag && parse_and_eval_long (args) != b->number) | |
6857 | continue; | |
6858 | if (!allflag && !number_is_in_list (args, b->number)) | |
6859 | continue; | |
6860 | } | |
269b11a2 | 6861 | |
e5a67952 MS |
6862 | if (allflag || user_breakpoint_p (b)) |
6863 | { | |
6864 | int addr_bit, type_len; | |
a6d9a66e | 6865 | |
e5a67952 MS |
6866 | addr_bit = breakpoint_address_bits (b); |
6867 | if (addr_bit > print_address_bits) | |
6868 | print_address_bits = addr_bit; | |
269b11a2 | 6869 | |
e5a67952 MS |
6870 | type_len = strlen (bptype_string (b->type)); |
6871 | if (type_len > print_type_col_width) | |
6872 | print_type_col_width = type_len; | |
6873 | ||
6874 | nr_printable_breakpoints++; | |
6875 | } | |
6876 | } | |
7f3b0473 | 6877 | |
79a45b7d | 6878 | if (opts.addressprint) |
3b31d625 | 6879 | bkpttbl_chain |
3e43a32a MS |
6880 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6881 | nr_printable_breakpoints, | |
3b31d625 | 6882 | "BreakpointTable"); |
8b93c638 | 6883 | else |
3b31d625 | 6884 | bkpttbl_chain |
3e43a32a MS |
6885 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6886 | nr_printable_breakpoints, | |
3b31d625 | 6887 | "BreakpointTable"); |
8b93c638 | 6888 | |
7f3b0473 | 6889 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6890 | annotate_breakpoints_headers (); |
6891 | if (nr_printable_breakpoints > 0) | |
6892 | annotate_field (0); | |
4a64f543 | 6893 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6894 | if (nr_printable_breakpoints > 0) |
6895 | annotate_field (1); | |
269b11a2 | 6896 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6897 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6898 | if (nr_printable_breakpoints > 0) |
6899 | annotate_field (2); | |
4a64f543 | 6900 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6901 | if (nr_printable_breakpoints > 0) |
6902 | annotate_field (3); | |
54e52265 | 6903 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6904 | if (opts.addressprint) |
e5a67952 MS |
6905 | { |
6906 | if (nr_printable_breakpoints > 0) | |
6907 | annotate_field (4); | |
6908 | if (print_address_bits <= 32) | |
6909 | ui_out_table_header (uiout, 10, ui_left, | |
6910 | "addr", "Address"); /* 5 */ | |
6911 | else | |
6912 | ui_out_table_header (uiout, 18, ui_left, | |
6913 | "addr", "Address"); /* 5 */ | |
6914 | } | |
d7faa9e7 AC |
6915 | if (nr_printable_breakpoints > 0) |
6916 | annotate_field (5); | |
6917 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6918 | ui_out_table_body (uiout); | |
6919 | if (nr_printable_breakpoints > 0) | |
6920 | annotate_breakpoints_table (); | |
7f3b0473 | 6921 | |
c4093a6a | 6922 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6923 | { |
6924 | QUIT; | |
6925 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6926 | if (filter && !filter (b)) | |
6927 | continue; | |
6928 | ||
6929 | /* If we have an "args" string, it is a list of breakpoints to | |
6930 | accept. Skip the others. */ | |
6931 | ||
6932 | if (args != NULL && *args != '\0') | |
6933 | { | |
6934 | if (allflag) /* maintenance info breakpoint */ | |
6935 | { | |
6936 | if (parse_and_eval_long (args) != b->number) | |
6937 | continue; | |
6938 | } | |
6939 | else /* all others */ | |
6940 | { | |
6941 | if (!number_is_in_list (args, b->number)) | |
6942 | continue; | |
6943 | } | |
6944 | } | |
6945 | /* We only print out user settable breakpoints unless the | |
6946 | allflag is set. */ | |
6947 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6948 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6949 | } |
6950 | ||
3b31d625 | 6951 | do_cleanups (bkpttbl_chain); |
698384cd | 6952 | |
7f3b0473 | 6953 | if (nr_printable_breakpoints == 0) |
c906108c | 6954 | { |
4a64f543 MS |
6955 | /* If there's a filter, let the caller decide how to report |
6956 | empty list. */ | |
d77f58be SS |
6957 | if (!filter) |
6958 | { | |
e5a67952 | 6959 | if (args == NULL || *args == '\0') |
d77f58be SS |
6960 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6961 | else | |
4a64f543 | 6962 | ui_out_message (uiout, 0, |
e5a67952 MS |
6963 | "No breakpoint or watchpoint matching '%s'.\n", |
6964 | args); | |
d77f58be | 6965 | } |
c906108c SS |
6966 | } |
6967 | else | |
c4093a6a | 6968 | { |
a6d9a66e UW |
6969 | if (last_loc && !server_command) |
6970 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6971 | } |
c906108c | 6972 | |
4a64f543 | 6973 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6974 | there have been breakpoints? */ |
c906108c | 6975 | annotate_breakpoints_table_end (); |
d77f58be SS |
6976 | |
6977 | return nr_printable_breakpoints; | |
c906108c SS |
6978 | } |
6979 | ||
ad443146 SS |
6980 | /* Display the value of default-collect in a way that is generally |
6981 | compatible with the breakpoint list. */ | |
6982 | ||
6983 | static void | |
6984 | default_collect_info (void) | |
6985 | { | |
79a45e25 PA |
6986 | struct ui_out *uiout = current_uiout; |
6987 | ||
ad443146 SS |
6988 | /* If it has no value (which is frequently the case), say nothing; a |
6989 | message like "No default-collect." gets in user's face when it's | |
6990 | not wanted. */ | |
6991 | if (!*default_collect) | |
6992 | return; | |
6993 | ||
6994 | /* The following phrase lines up nicely with per-tracepoint collect | |
6995 | actions. */ | |
6996 | ui_out_text (uiout, "default collect "); | |
6997 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6998 | ui_out_text (uiout, " \n"); | |
6999 | } | |
7000 | ||
c906108c | 7001 | static void |
e5a67952 | 7002 | breakpoints_info (char *args, int from_tty) |
c906108c | 7003 | { |
e5a67952 | 7004 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
7005 | |
7006 | default_collect_info (); | |
d77f58be SS |
7007 | } |
7008 | ||
7009 | static void | |
e5a67952 | 7010 | watchpoints_info (char *args, int from_tty) |
d77f58be | 7011 | { |
e5a67952 | 7012 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 7013 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
7014 | |
7015 | if (num_printed == 0) | |
7016 | { | |
e5a67952 | 7017 | if (args == NULL || *args == '\0') |
d77f58be SS |
7018 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
7019 | else | |
e5a67952 | 7020 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 7021 | } |
c906108c SS |
7022 | } |
7023 | ||
7a292a7a | 7024 | static void |
e5a67952 | 7025 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 7026 | { |
e5a67952 | 7027 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
7028 | |
7029 | default_collect_info (); | |
c906108c SS |
7030 | } |
7031 | ||
0d381245 | 7032 | static int |
714835d5 | 7033 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7034 | struct program_space *pspace, |
714835d5 | 7035 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7036 | { |
7037 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7038 | |
0d381245 VP |
7039 | for (; bl; bl = bl->next) |
7040 | { | |
6c95b8df PA |
7041 | if (bl->pspace == pspace |
7042 | && bl->address == pc | |
0d381245 VP |
7043 | && (!overlay_debugging || bl->section == section)) |
7044 | return 1; | |
7045 | } | |
7046 | return 0; | |
7047 | } | |
7048 | ||
672f9b60 | 7049 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7050 | concerns with logical breakpoints, so we match program spaces, not |
7051 | address spaces. */ | |
c906108c SS |
7052 | |
7053 | static void | |
6c95b8df PA |
7054 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7055 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7056 | struct obj_section *section, int thread) |
c906108c | 7057 | { |
52f0bd74 AC |
7058 | int others = 0; |
7059 | struct breakpoint *b; | |
c906108c SS |
7060 | |
7061 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7062 | others += (user_breakpoint_p (b) |
7063 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7064 | if (others > 0) |
7065 | { | |
a3f17187 AC |
7066 | if (others == 1) |
7067 | printf_filtered (_("Note: breakpoint ")); | |
7068 | else /* if (others == ???) */ | |
7069 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7070 | ALL_BREAKPOINTS (b) |
672f9b60 | 7071 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7072 | { |
7073 | others--; | |
7074 | printf_filtered ("%d", b->number); | |
7075 | if (b->thread == -1 && thread != -1) | |
7076 | printf_filtered (" (all threads)"); | |
7077 | else if (b->thread != -1) | |
7078 | printf_filtered (" (thread %d)", b->thread); | |
7079 | printf_filtered ("%s%s ", | |
059fb39f | 7080 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7081 | || b->enable_state == bp_call_disabled) |
0d381245 | 7082 | ? " (disabled)" |
0d381245 VP |
7083 | : ""), |
7084 | (others > 1) ? "," | |
7085 | : ((others == 1) ? " and" : "")); | |
7086 | } | |
a3f17187 | 7087 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7088 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7089 | printf_filtered (".\n"); |
7090 | } | |
7091 | } | |
7092 | \f | |
c906108c | 7093 | |
e4f237da | 7094 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7095 | BPT locations. For some breakpoint types, the locations' address members |
7096 | are irrelevant and it makes no sense to attempt to compare them to other | |
7097 | addresses (or use them for any other purpose either). | |
e4f237da | 7098 | |
4a64f543 | 7099 | More specifically, each of the following breakpoint types will |
244558af | 7100 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7101 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7102 | breakpoint location at address zero: |
e4f237da KB |
7103 | |
7104 | bp_watchpoint | |
2d134ed3 PA |
7105 | bp_catchpoint |
7106 | ||
7107 | */ | |
e4f237da KB |
7108 | |
7109 | static int | |
7110 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7111 | { | |
7112 | enum bptype type = bpt->type; | |
7113 | ||
2d134ed3 PA |
7114 | return (type != bp_watchpoint && type != bp_catchpoint); |
7115 | } | |
7116 | ||
7117 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7118 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7119 | ||
7120 | static int | |
4a64f543 MS |
7121 | watchpoint_locations_match (struct bp_location *loc1, |
7122 | struct bp_location *loc2) | |
2d134ed3 | 7123 | { |
3a5c3e22 PA |
7124 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7125 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7126 | ||
7127 | /* Both of them must exist. */ | |
7128 | gdb_assert (w1 != NULL); | |
7129 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7130 | |
4a64f543 MS |
7131 | /* If the target can evaluate the condition expression in hardware, |
7132 | then we we need to insert both watchpoints even if they are at | |
7133 | the same place. Otherwise the watchpoint will only trigger when | |
7134 | the condition of whichever watchpoint was inserted evaluates to | |
7135 | true, not giving a chance for GDB to check the condition of the | |
7136 | other watchpoint. */ | |
3a5c3e22 | 7137 | if ((w1->cond_exp |
4a64f543 MS |
7138 | && target_can_accel_watchpoint_condition (loc1->address, |
7139 | loc1->length, | |
0cf6dd15 | 7140 | loc1->watchpoint_type, |
3a5c3e22 PA |
7141 | w1->cond_exp)) |
7142 | || (w2->cond_exp | |
4a64f543 MS |
7143 | && target_can_accel_watchpoint_condition (loc2->address, |
7144 | loc2->length, | |
0cf6dd15 | 7145 | loc2->watchpoint_type, |
3a5c3e22 | 7146 | w2->cond_exp))) |
0cf6dd15 TJB |
7147 | return 0; |
7148 | ||
85d721b8 PA |
7149 | /* Note that this checks the owner's type, not the location's. In |
7150 | case the target does not support read watchpoints, but does | |
7151 | support access watchpoints, we'll have bp_read_watchpoint | |
7152 | watchpoints with hw_access locations. Those should be considered | |
7153 | duplicates of hw_read locations. The hw_read locations will | |
7154 | become hw_access locations later. */ | |
2d134ed3 PA |
7155 | return (loc1->owner->type == loc2->owner->type |
7156 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7157 | && loc1->address == loc2->address | |
7158 | && loc1->length == loc2->length); | |
e4f237da KB |
7159 | } |
7160 | ||
31e77af2 | 7161 | /* See breakpoint.h. */ |
6c95b8df | 7162 | |
31e77af2 | 7163 | int |
6c95b8df PA |
7164 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7165 | struct address_space *aspace2, CORE_ADDR addr2) | |
7166 | { | |
f5656ead | 7167 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7168 | || aspace1 == aspace2) |
7169 | && addr1 == addr2); | |
7170 | } | |
7171 | ||
f1310107 TJB |
7172 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7173 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7174 | matches ASPACE2. On targets that have global breakpoints, the address | |
7175 | space doesn't really matter. */ | |
7176 | ||
7177 | static int | |
7178 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7179 | int len1, struct address_space *aspace2, | |
7180 | CORE_ADDR addr2) | |
7181 | { | |
f5656ead | 7182 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7183 | || aspace1 == aspace2) |
7184 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7185 | } | |
7186 | ||
7187 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7188 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7189 | matches the breakpoint's address space. On targets that have global | |
7190 | breakpoints, the address space doesn't really matter. */ | |
7191 | ||
7192 | static int | |
7193 | breakpoint_location_address_match (struct bp_location *bl, | |
7194 | struct address_space *aspace, | |
7195 | CORE_ADDR addr) | |
7196 | { | |
7197 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7198 | aspace, addr) | |
7199 | || (bl->length | |
7200 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7201 | bl->address, bl->length, | |
7202 | aspace, addr))); | |
7203 | } | |
7204 | ||
d35ae833 PA |
7205 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7206 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7207 | match happens only if ASPACE matches the breakpoint's address | |
7208 | space. On targets that have global breakpoints, the address space | |
7209 | doesn't really matter. */ | |
7210 | ||
7211 | static int | |
7212 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7213 | struct address_space *aspace, | |
7214 | CORE_ADDR addr, int len) | |
7215 | { | |
7216 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7217 | || bl->pspace->aspace == aspace) | |
7218 | { | |
7219 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7220 | ||
7221 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7222 | return 1; | |
7223 | } | |
7224 | return 0; | |
7225 | } | |
7226 | ||
1e4d1764 YQ |
7227 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7228 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7229 | true, otherwise returns false. */ | |
7230 | ||
7231 | static int | |
7232 | tracepoint_locations_match (struct bp_location *loc1, | |
7233 | struct bp_location *loc2) | |
7234 | { | |
7235 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7236 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7237 | locations at the same address of different tracepoints are regarded as | |
7238 | different locations. */ | |
7239 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7240 | else | |
7241 | return 0; | |
7242 | } | |
7243 | ||
2d134ed3 PA |
7244 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7245 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7246 | represent the same location. */ | |
7247 | ||
7248 | static int | |
4a64f543 MS |
7249 | breakpoint_locations_match (struct bp_location *loc1, |
7250 | struct bp_location *loc2) | |
2d134ed3 | 7251 | { |
2bdf28a0 JK |
7252 | int hw_point1, hw_point2; |
7253 | ||
7254 | /* Both of them must not be in moribund_locations. */ | |
7255 | gdb_assert (loc1->owner != NULL); | |
7256 | gdb_assert (loc2->owner != NULL); | |
7257 | ||
7258 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7259 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7260 | |
7261 | if (hw_point1 != hw_point2) | |
7262 | return 0; | |
7263 | else if (hw_point1) | |
7264 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7265 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7266 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7267 | else |
f1310107 TJB |
7268 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7269 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7270 | loc2->pspace->aspace, loc2->address) | |
7271 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7272 | } |
7273 | ||
76897487 KB |
7274 | static void |
7275 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7276 | int bnum, int have_bnum) | |
7277 | { | |
f63fbe86 MS |
7278 | /* The longest string possibly returned by hex_string_custom |
7279 | is 50 chars. These must be at least that big for safety. */ | |
7280 | char astr1[64]; | |
7281 | char astr2[64]; | |
76897487 | 7282 | |
bb599908 PH |
7283 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7284 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7285 | if (have_bnum) |
8a3fe4f8 | 7286 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7287 | bnum, astr1, astr2); |
7288 | else | |
8a3fe4f8 | 7289 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7290 | } |
7291 | ||
4a64f543 MS |
7292 | /* Adjust a breakpoint's address to account for architectural |
7293 | constraints on breakpoint placement. Return the adjusted address. | |
7294 | Note: Very few targets require this kind of adjustment. For most | |
7295 | targets, this function is simply the identity function. */ | |
76897487 KB |
7296 | |
7297 | static CORE_ADDR | |
a6d9a66e UW |
7298 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7299 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7300 | { |
a6d9a66e | 7301 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7302 | { |
7303 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7304 | return bpaddr; | |
7305 | } | |
88f7da05 KB |
7306 | else if (bptype == bp_watchpoint |
7307 | || bptype == bp_hardware_watchpoint | |
7308 | || bptype == bp_read_watchpoint | |
7309 | || bptype == bp_access_watchpoint | |
fe798b75 | 7310 | || bptype == bp_catchpoint) |
88f7da05 KB |
7311 | { |
7312 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7313 | have their addresses modified. */ | |
7314 | return bpaddr; | |
7315 | } | |
7c16b83e PA |
7316 | else if (bptype == bp_single_step) |
7317 | { | |
7318 | /* Single-step breakpoints should not have their addresses | |
7319 | modified. If there's any architectural constrain that | |
7320 | applies to this address, then it should have already been | |
7321 | taken into account when the breakpoint was created in the | |
7322 | first place. If we didn't do this, stepping through e.g., | |
7323 | Thumb-2 IT blocks would break. */ | |
7324 | return bpaddr; | |
7325 | } | |
76897487 KB |
7326 | else |
7327 | { | |
7328 | CORE_ADDR adjusted_bpaddr; | |
7329 | ||
7330 | /* Some targets have architectural constraints on the placement | |
7331 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7332 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7333 | |
7334 | /* An adjusted breakpoint address can significantly alter | |
7335 | a user's expectations. Print a warning if an adjustment | |
7336 | is required. */ | |
7337 | if (adjusted_bpaddr != bpaddr) | |
7338 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7339 | ||
7340 | return adjusted_bpaddr; | |
7341 | } | |
7342 | } | |
7343 | ||
28010a5d PA |
7344 | void |
7345 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7346 | struct breakpoint *owner) | |
7cc221ef | 7347 | { |
7cc221ef DJ |
7348 | memset (loc, 0, sizeof (*loc)); |
7349 | ||
348d480f PA |
7350 | gdb_assert (ops != NULL); |
7351 | ||
28010a5d PA |
7352 | loc->ops = ops; |
7353 | loc->owner = owner; | |
511a6cd4 | 7354 | loc->cond = NULL; |
b775012e | 7355 | loc->cond_bytecode = NULL; |
0d381245 VP |
7356 | loc->shlib_disabled = 0; |
7357 | loc->enabled = 1; | |
e049a4b5 | 7358 | |
28010a5d | 7359 | switch (owner->type) |
e049a4b5 DJ |
7360 | { |
7361 | case bp_breakpoint: | |
7c16b83e | 7362 | case bp_single_step: |
e049a4b5 DJ |
7363 | case bp_until: |
7364 | case bp_finish: | |
7365 | case bp_longjmp: | |
7366 | case bp_longjmp_resume: | |
e2e4d78b | 7367 | case bp_longjmp_call_dummy: |
186c406b TT |
7368 | case bp_exception: |
7369 | case bp_exception_resume: | |
e049a4b5 | 7370 | case bp_step_resume: |
2c03e5be | 7371 | case bp_hp_step_resume: |
e049a4b5 DJ |
7372 | case bp_watchpoint_scope: |
7373 | case bp_call_dummy: | |
aa7d318d | 7374 | case bp_std_terminate: |
e049a4b5 DJ |
7375 | case bp_shlib_event: |
7376 | case bp_thread_event: | |
7377 | case bp_overlay_event: | |
4efc6507 | 7378 | case bp_jit_event: |
0fd8e87f | 7379 | case bp_longjmp_master: |
aa7d318d | 7380 | case bp_std_terminate_master: |
186c406b | 7381 | case bp_exception_master: |
0e30163f JK |
7382 | case bp_gnu_ifunc_resolver: |
7383 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7384 | case bp_dprintf: |
e049a4b5 | 7385 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7386 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7387 | break; |
7388 | case bp_hardware_breakpoint: | |
7389 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7390 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7391 | break; |
7392 | case bp_hardware_watchpoint: | |
7393 | case bp_read_watchpoint: | |
7394 | case bp_access_watchpoint: | |
7395 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7396 | break; | |
7397 | case bp_watchpoint: | |
ce78b96d | 7398 | case bp_catchpoint: |
15c3d785 PA |
7399 | case bp_tracepoint: |
7400 | case bp_fast_tracepoint: | |
0fb4aa4b | 7401 | case bp_static_tracepoint: |
e049a4b5 DJ |
7402 | loc->loc_type = bp_loc_other; |
7403 | break; | |
7404 | default: | |
e2e0b3e5 | 7405 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7406 | } |
7407 | ||
f431efe5 | 7408 | loc->refc = 1; |
28010a5d PA |
7409 | } |
7410 | ||
7411 | /* Allocate a struct bp_location. */ | |
7412 | ||
7413 | static struct bp_location * | |
7414 | allocate_bp_location (struct breakpoint *bpt) | |
7415 | { | |
348d480f PA |
7416 | return bpt->ops->allocate_location (bpt); |
7417 | } | |
7cc221ef | 7418 | |
f431efe5 PA |
7419 | static void |
7420 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7421 | { |
348d480f | 7422 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7423 | xfree (loc); |
7424 | } | |
7425 | ||
f431efe5 PA |
7426 | /* Increment reference count. */ |
7427 | ||
7428 | static void | |
7429 | incref_bp_location (struct bp_location *bl) | |
7430 | { | |
7431 | ++bl->refc; | |
7432 | } | |
7433 | ||
7434 | /* Decrement reference count. If the reference count reaches 0, | |
7435 | destroy the bp_location. Sets *BLP to NULL. */ | |
7436 | ||
7437 | static void | |
7438 | decref_bp_location (struct bp_location **blp) | |
7439 | { | |
0807b50c PA |
7440 | gdb_assert ((*blp)->refc > 0); |
7441 | ||
f431efe5 PA |
7442 | if (--(*blp)->refc == 0) |
7443 | free_bp_location (*blp); | |
7444 | *blp = NULL; | |
7445 | } | |
7446 | ||
346774a9 | 7447 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7448 | |
346774a9 PA |
7449 | static void |
7450 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7451 | { |
346774a9 | 7452 | struct breakpoint *b1; |
c906108c | 7453 | |
346774a9 PA |
7454 | /* Add this breakpoint to the end of the chain so that a list of |
7455 | breakpoints will come out in order of increasing numbers. */ | |
7456 | ||
7457 | b1 = breakpoint_chain; | |
7458 | if (b1 == 0) | |
7459 | breakpoint_chain = b; | |
7460 | else | |
7461 | { | |
7462 | while (b1->next) | |
7463 | b1 = b1->next; | |
7464 | b1->next = b; | |
7465 | } | |
7466 | } | |
7467 | ||
7468 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7469 | ||
7470 | static void | |
7471 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7472 | struct gdbarch *gdbarch, | |
28010a5d | 7473 | enum bptype bptype, |
c0a91b2b | 7474 | const struct breakpoint_ops *ops) |
346774a9 | 7475 | { |
c906108c | 7476 | memset (b, 0, sizeof (*b)); |
2219d63c | 7477 | |
348d480f PA |
7478 | gdb_assert (ops != NULL); |
7479 | ||
28010a5d | 7480 | b->ops = ops; |
4d28f7a8 | 7481 | b->type = bptype; |
a6d9a66e | 7482 | b->gdbarch = gdbarch; |
c906108c SS |
7483 | b->language = current_language->la_language; |
7484 | b->input_radix = input_radix; | |
7485 | b->thread = -1; | |
b5de0fa7 | 7486 | b->enable_state = bp_enabled; |
c906108c SS |
7487 | b->next = 0; |
7488 | b->silent = 0; | |
7489 | b->ignore_count = 0; | |
7490 | b->commands = NULL; | |
818dd999 | 7491 | b->frame_id = null_frame_id; |
0d381245 | 7492 | b->condition_not_parsed = 0; |
84f4c1fe | 7493 | b->py_bp_object = NULL; |
d0fb5eae | 7494 | b->related_breakpoint = b; |
f00aae0f | 7495 | b->location = NULL; |
346774a9 PA |
7496 | } |
7497 | ||
7498 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7499 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7500 | |
7501 | static struct breakpoint * | |
7502 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7503 | enum bptype bptype, |
c0a91b2b | 7504 | const struct breakpoint_ops *ops) |
346774a9 PA |
7505 | { |
7506 | struct breakpoint *b = XNEW (struct breakpoint); | |
7507 | ||
348d480f | 7508 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7509 | add_to_breakpoint_chain (b); |
0d381245 VP |
7510 | return b; |
7511 | } | |
7512 | ||
0e30163f JK |
7513 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7514 | resolutions should be made as the user specified the location explicitly | |
7515 | enough. */ | |
7516 | ||
0d381245 | 7517 | static void |
0e30163f | 7518 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7519 | { |
2bdf28a0 JK |
7520 | gdb_assert (loc->owner != NULL); |
7521 | ||
0d381245 | 7522 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7523 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7524 | || is_tracepoint (loc->owner)) |
0d381245 | 7525 | { |
0e30163f | 7526 | int is_gnu_ifunc; |
2c02bd72 | 7527 | const char *function_name; |
6a3a010b | 7528 | CORE_ADDR func_addr; |
0e30163f | 7529 | |
2c02bd72 | 7530 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7531 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7532 | |
7533 | if (is_gnu_ifunc && !explicit_loc) | |
7534 | { | |
7535 | struct breakpoint *b = loc->owner; | |
7536 | ||
7537 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7538 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7539 | &loc->requested_address)) |
7540 | { | |
7541 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7542 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7543 | loc->requested_address, | |
7544 | b->type); | |
7545 | } | |
7546 | else if (b->type == bp_breakpoint && b->loc == loc | |
7547 | && loc->next == NULL && b->related_breakpoint == b) | |
7548 | { | |
7549 | /* Create only the whole new breakpoint of this type but do not | |
7550 | mess more complicated breakpoints with multiple locations. */ | |
7551 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7552 | /* Remember the resolver's address for use by the return |
7553 | breakpoint. */ | |
7554 | loc->related_address = func_addr; | |
0e30163f JK |
7555 | } |
7556 | } | |
7557 | ||
2c02bd72 DE |
7558 | if (function_name) |
7559 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7560 | } |
7561 | } | |
7562 | ||
a6d9a66e | 7563 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7564 | struct gdbarch * |
a6d9a66e UW |
7565 | get_sal_arch (struct symtab_and_line sal) |
7566 | { | |
7567 | if (sal.section) | |
7568 | return get_objfile_arch (sal.section->objfile); | |
7569 | if (sal.symtab) | |
eb822aa6 | 7570 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7571 | |
7572 | return NULL; | |
7573 | } | |
7574 | ||
346774a9 PA |
7575 | /* Low level routine for partially initializing a breakpoint of type |
7576 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7577 | file name, and line number are provided by SAL. |
0d381245 VP |
7578 | |
7579 | It is expected that the caller will complete the initialization of | |
7580 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7581 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7582 | |
346774a9 PA |
7583 | static void |
7584 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7585 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7586 | const struct breakpoint_ops *ops) |
0d381245 | 7587 | { |
28010a5d | 7588 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7589 | |
3742cc8b | 7590 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7591 | |
6c95b8df PA |
7592 | if (bptype != bp_catchpoint) |
7593 | gdb_assert (sal.pspace != NULL); | |
7594 | ||
f8eba3c6 TT |
7595 | /* Store the program space that was used to set the breakpoint, |
7596 | except for ordinary breakpoints, which are independent of the | |
7597 | program space. */ | |
7598 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7599 | b->pspace = sal.pspace; | |
346774a9 | 7600 | } |
c906108c | 7601 | |
346774a9 PA |
7602 | /* set_raw_breakpoint is a low level routine for allocating and |
7603 | partially initializing a breakpoint of type BPTYPE. The newly | |
7604 | created breakpoint's address, section, source file name, and line | |
7605 | number are provided by SAL. The newly created and partially | |
7606 | initialized breakpoint is added to the breakpoint chain and | |
7607 | is also returned as the value of this function. | |
7608 | ||
7609 | It is expected that the caller will complete the initialization of | |
7610 | the newly created breakpoint struct as well as output any status | |
7611 | information regarding the creation of a new breakpoint. In | |
7612 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7613 | number! Care should be taken to not allow an error to occur | |
7614 | prior to completing the initialization of the breakpoint. If this | |
7615 | should happen, a bogus breakpoint will be left on the chain. */ | |
7616 | ||
7617 | struct breakpoint * | |
7618 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7619 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7620 | const struct breakpoint_ops *ops) |
346774a9 PA |
7621 | { |
7622 | struct breakpoint *b = XNEW (struct breakpoint); | |
7623 | ||
348d480f | 7624 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7625 | add_to_breakpoint_chain (b); |
c906108c SS |
7626 | return b; |
7627 | } | |
7628 | ||
53a5351d | 7629 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7630 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7631 | initiated the operation. */ | |
c906108c SS |
7632 | |
7633 | void | |
186c406b | 7634 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7635 | { |
35df4500 | 7636 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7637 | int thread = tp->global_num; |
0fd8e87f UW |
7638 | |
7639 | /* To avoid having to rescan all objfile symbols at every step, | |
7640 | we maintain a list of continually-inserted but always disabled | |
7641 | longjmp "master" breakpoints. Here, we simply create momentary | |
7642 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7643 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7644 | if (b->pspace == current_program_space |
186c406b TT |
7645 | && (b->type == bp_longjmp_master |
7646 | || b->type == bp_exception_master)) | |
0fd8e87f | 7647 | { |
06edf0c0 PA |
7648 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7649 | struct breakpoint *clone; | |
cc59ec59 | 7650 | |
e2e4d78b JK |
7651 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7652 | after their removal. */ | |
06edf0c0 | 7653 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7654 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7655 | clone->thread = thread; |
7656 | } | |
186c406b TT |
7657 | |
7658 | tp->initiating_frame = frame; | |
c906108c SS |
7659 | } |
7660 | ||
611c83ae | 7661 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7662 | void |
611c83ae | 7663 | delete_longjmp_breakpoint (int thread) |
c906108c | 7664 | { |
35df4500 | 7665 | struct breakpoint *b, *b_tmp; |
c906108c | 7666 | |
35df4500 | 7667 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7668 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7669 | { |
7670 | if (b->thread == thread) | |
7671 | delete_breakpoint (b); | |
7672 | } | |
c906108c SS |
7673 | } |
7674 | ||
f59f708a PA |
7675 | void |
7676 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7677 | { | |
7678 | struct breakpoint *b, *b_tmp; | |
7679 | ||
7680 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7681 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7682 | { | |
7683 | if (b->thread == thread) | |
7684 | b->disposition = disp_del_at_next_stop; | |
7685 | } | |
7686 | } | |
7687 | ||
e2e4d78b JK |
7688 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7689 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7690 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7691 | breakpoints. */ | |
7692 | ||
7693 | struct breakpoint * | |
7694 | set_longjmp_breakpoint_for_call_dummy (void) | |
7695 | { | |
7696 | struct breakpoint *b, *retval = NULL; | |
7697 | ||
7698 | ALL_BREAKPOINTS (b) | |
7699 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7700 | { | |
7701 | struct breakpoint *new_b; | |
7702 | ||
7703 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7704 | &momentary_breakpoint_ops, |
7705 | 1); | |
5d5658a1 | 7706 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7707 | |
7708 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7709 | ||
7710 | gdb_assert (new_b->related_breakpoint == new_b); | |
7711 | if (retval == NULL) | |
7712 | retval = new_b; | |
7713 | new_b->related_breakpoint = retval; | |
7714 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7715 | retval = retval->related_breakpoint; | |
7716 | retval->related_breakpoint = new_b; | |
7717 | } | |
7718 | ||
7719 | return retval; | |
7720 | } | |
7721 | ||
7722 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7723 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7724 | stack. |
7725 | ||
7726 | You should call this function only at places where it is safe to currently | |
7727 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7728 | frames. */ | |
7729 | ||
7730 | void | |
b67a2c6f | 7731 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7732 | { |
7733 | struct breakpoint *b, *b_tmp; | |
7734 | ||
7735 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7736 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7737 | { |
7738 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7739 | ||
7740 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7741 | dummy_b = dummy_b->related_breakpoint; | |
7742 | if (dummy_b->type != bp_call_dummy | |
7743 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7744 | continue; | |
7745 | ||
b67a2c6f | 7746 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7747 | |
7748 | while (b->related_breakpoint != b) | |
7749 | { | |
7750 | if (b_tmp == b->related_breakpoint) | |
7751 | b_tmp = b->related_breakpoint->next; | |
7752 | delete_breakpoint (b->related_breakpoint); | |
7753 | } | |
7754 | delete_breakpoint (b); | |
7755 | } | |
7756 | } | |
7757 | ||
1900040c MS |
7758 | void |
7759 | enable_overlay_breakpoints (void) | |
7760 | { | |
52f0bd74 | 7761 | struct breakpoint *b; |
1900040c MS |
7762 | |
7763 | ALL_BREAKPOINTS (b) | |
7764 | if (b->type == bp_overlay_event) | |
7765 | { | |
7766 | b->enable_state = bp_enabled; | |
44702360 | 7767 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7768 | overlay_events_enabled = 1; |
1900040c MS |
7769 | } |
7770 | } | |
7771 | ||
7772 | void | |
7773 | disable_overlay_breakpoints (void) | |
7774 | { | |
52f0bd74 | 7775 | struct breakpoint *b; |
1900040c MS |
7776 | |
7777 | ALL_BREAKPOINTS (b) | |
7778 | if (b->type == bp_overlay_event) | |
7779 | { | |
7780 | b->enable_state = bp_disabled; | |
44702360 | 7781 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7782 | overlay_events_enabled = 0; |
1900040c MS |
7783 | } |
7784 | } | |
7785 | ||
aa7d318d TT |
7786 | /* Set an active std::terminate breakpoint for each std::terminate |
7787 | master breakpoint. */ | |
7788 | void | |
7789 | set_std_terminate_breakpoint (void) | |
7790 | { | |
35df4500 | 7791 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7792 | |
35df4500 | 7793 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7794 | if (b->pspace == current_program_space |
7795 | && b->type == bp_std_terminate_master) | |
7796 | { | |
06edf0c0 | 7797 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7798 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7799 | } |
7800 | } | |
7801 | ||
7802 | /* Delete all the std::terminate breakpoints. */ | |
7803 | void | |
7804 | delete_std_terminate_breakpoint (void) | |
7805 | { | |
35df4500 | 7806 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7807 | |
35df4500 | 7808 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7809 | if (b->type == bp_std_terminate) |
7810 | delete_breakpoint (b); | |
7811 | } | |
7812 | ||
c4093a6a | 7813 | struct breakpoint * |
a6d9a66e | 7814 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7815 | { |
7816 | struct breakpoint *b; | |
c4093a6a | 7817 | |
06edf0c0 PA |
7818 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7819 | &internal_breakpoint_ops); | |
7820 | ||
b5de0fa7 | 7821 | b->enable_state = bp_enabled; |
f00aae0f | 7822 | /* location has to be used or breakpoint_re_set will delete me. */ |
305e13e6 | 7823 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7824 | |
44702360 | 7825 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7826 | |
c4093a6a JM |
7827 | return b; |
7828 | } | |
7829 | ||
0101ce28 JJ |
7830 | struct lang_and_radix |
7831 | { | |
7832 | enum language lang; | |
7833 | int radix; | |
7834 | }; | |
7835 | ||
4efc6507 DE |
7836 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7837 | ||
7838 | struct breakpoint * | |
7839 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7840 | { | |
2a7f3dff PA |
7841 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7842 | &internal_breakpoint_ops); | |
4efc6507 | 7843 | } |
0101ce28 | 7844 | |
03673fc7 PP |
7845 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7846 | ||
7847 | void | |
7848 | remove_jit_event_breakpoints (void) | |
7849 | { | |
7850 | struct breakpoint *b, *b_tmp; | |
7851 | ||
7852 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7853 | if (b->type == bp_jit_event | |
7854 | && b->loc->pspace == current_program_space) | |
7855 | delete_breakpoint (b); | |
7856 | } | |
7857 | ||
cae688ec JJ |
7858 | void |
7859 | remove_solib_event_breakpoints (void) | |
7860 | { | |
35df4500 | 7861 | struct breakpoint *b, *b_tmp; |
cae688ec | 7862 | |
35df4500 | 7863 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7864 | if (b->type == bp_shlib_event |
7865 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7866 | delete_breakpoint (b); |
7867 | } | |
7868 | ||
f37f681c PA |
7869 | /* See breakpoint.h. */ |
7870 | ||
7871 | void | |
7872 | remove_solib_event_breakpoints_at_next_stop (void) | |
7873 | { | |
7874 | struct breakpoint *b, *b_tmp; | |
7875 | ||
7876 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7877 | if (b->type == bp_shlib_event | |
7878 | && b->loc->pspace == current_program_space) | |
7879 | b->disposition = disp_del_at_next_stop; | |
7880 | } | |
7881 | ||
04086b45 PA |
7882 | /* Helper for create_solib_event_breakpoint / |
7883 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7884 | INSERT_MODE to pass through to update_global_location_list. */ | |
7885 | ||
7886 | static struct breakpoint * | |
7887 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7888 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7889 | { |
7890 | struct breakpoint *b; | |
7891 | ||
06edf0c0 PA |
7892 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7893 | &internal_breakpoint_ops); | |
04086b45 | 7894 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7895 | return b; |
7896 | } | |
7897 | ||
04086b45 PA |
7898 | struct breakpoint * |
7899 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7900 | { | |
7901 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7902 | } | |
7903 | ||
f37f681c PA |
7904 | /* See breakpoint.h. */ |
7905 | ||
7906 | struct breakpoint * | |
7907 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7908 | { | |
7909 | struct breakpoint *b; | |
7910 | ||
04086b45 PA |
7911 | /* Explicitly tell update_global_location_list to insert |
7912 | locations. */ | |
7913 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7914 | if (!b->loc->inserted) |
7915 | { | |
7916 | delete_breakpoint (b); | |
7917 | return NULL; | |
7918 | } | |
7919 | return b; | |
7920 | } | |
7921 | ||
cae688ec JJ |
7922 | /* Disable any breakpoints that are on code in shared libraries. Only |
7923 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7924 | ||
7925 | void | |
cb851954 | 7926 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7927 | { |
876fa593 | 7928 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7929 | |
876fa593 | 7930 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7931 | { |
2bdf28a0 | 7932 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7933 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7934 | |
4a64f543 MS |
7935 | /* We apply the check to all breakpoints, including disabled for |
7936 | those with loc->duplicate set. This is so that when breakpoint | |
7937 | becomes enabled, or the duplicate is removed, gdb will try to | |
7938 | insert all breakpoints. If we don't set shlib_disabled here, | |
7939 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7940 | if (((b->type == bp_breakpoint) |
508ccb1f | 7941 | || (b->type == bp_jit_event) |
1042e4c0 | 7942 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7943 | || (is_tracepoint (b))) |
6c95b8df | 7944 | && loc->pspace == current_program_space |
0d381245 | 7945 | && !loc->shlib_disabled |
6c95b8df | 7946 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7947 | ) |
0d381245 VP |
7948 | { |
7949 | loc->shlib_disabled = 1; | |
7950 | } | |
cae688ec JJ |
7951 | } |
7952 | } | |
7953 | ||
63644780 NB |
7954 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7955 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7956 | disabled ones can just stay disabled. */ | |
84acb35a | 7957 | |
75149521 | 7958 | static void |
84acb35a JJ |
7959 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7960 | { | |
876fa593 | 7961 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7962 | int disabled_shlib_breaks = 0; |
7963 | ||
c86cf029 VP |
7964 | /* SunOS a.out shared libraries are always mapped, so do not |
7965 | disable breakpoints; they will only be reported as unloaded | |
7966 | through clear_solib when GDB discards its shared library | |
7967 | list. See clear_solib for more information. */ | |
7968 | if (exec_bfd != NULL | |
7969 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7970 | return; | |
7971 | ||
876fa593 | 7972 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7973 | { |
2bdf28a0 | 7974 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7975 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7976 | |
1e4d1764 | 7977 | if (solib->pspace == loc->pspace |
e2dd7057 | 7978 | && !loc->shlib_disabled |
1e4d1764 YQ |
7979 | && (((b->type == bp_breakpoint |
7980 | || b->type == bp_jit_event | |
7981 | || b->type == bp_hardware_breakpoint) | |
7982 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7983 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7984 | || is_tracepoint (b)) | |
e2dd7057 | 7985 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7986 | { |
e2dd7057 PP |
7987 | loc->shlib_disabled = 1; |
7988 | /* At this point, we cannot rely on remove_breakpoint | |
7989 | succeeding so we must mark the breakpoint as not inserted | |
7990 | to prevent future errors occurring in remove_breakpoints. */ | |
7991 | loc->inserted = 0; | |
8d3788bd VP |
7992 | |
7993 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7994 | observer_notify_breakpoint_modified (b); | |
7995 | ||
e2dd7057 PP |
7996 | if (!disabled_shlib_breaks) |
7997 | { | |
7998 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7999 | warning (_("Temporarily disabling breakpoints " |
8000 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 8001 | solib->so_name); |
84acb35a | 8002 | } |
e2dd7057 | 8003 | disabled_shlib_breaks = 1; |
84acb35a JJ |
8004 | } |
8005 | } | |
84acb35a JJ |
8006 | } |
8007 | ||
63644780 NB |
8008 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
8009 | notification of free_objfile. Only apply to enabled breakpoints, | |
8010 | disabled ones can just stay disabled. */ | |
8011 | ||
8012 | static void | |
8013 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
8014 | { | |
8015 | struct breakpoint *b; | |
8016 | ||
8017 | if (objfile == NULL) | |
8018 | return; | |
8019 | ||
d03de421 PA |
8020 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
8021 | managed by the user with add-symbol-file/remove-symbol-file. | |
8022 | Similarly to how breakpoints in shared libraries are handled in | |
8023 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
8024 | shlib_disabled so they end up uninserted on the next global |
8025 | location list update. Shared libraries not loaded by the user | |
8026 | aren't handled here -- they're already handled in | |
8027 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
8028 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
8029 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
8030 | main objfile). */ | |
8031 | if ((objfile->flags & OBJF_SHARED) == 0 | |
8032 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
8033 | return; |
8034 | ||
8035 | ALL_BREAKPOINTS (b) | |
8036 | { | |
8037 | struct bp_location *loc; | |
8038 | int bp_modified = 0; | |
8039 | ||
8040 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
8041 | continue; | |
8042 | ||
8043 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
8044 | { | |
8045 | CORE_ADDR loc_addr = loc->address; | |
8046 | ||
8047 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8048 | && loc->loc_type != bp_loc_software_breakpoint) | |
8049 | continue; | |
8050 | ||
8051 | if (loc->shlib_disabled != 0) | |
8052 | continue; | |
8053 | ||
8054 | if (objfile->pspace != loc->pspace) | |
8055 | continue; | |
8056 | ||
8057 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8058 | && loc->loc_type != bp_loc_software_breakpoint) | |
8059 | continue; | |
8060 | ||
8061 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8062 | { | |
8063 | loc->shlib_disabled = 1; | |
08351840 PA |
8064 | /* At this point, we don't know whether the object was |
8065 | unmapped from the inferior or not, so leave the | |
8066 | inserted flag alone. We'll handle failure to | |
8067 | uninsert quietly, in case the object was indeed | |
8068 | unmapped. */ | |
63644780 NB |
8069 | |
8070 | mark_breakpoint_location_modified (loc); | |
8071 | ||
8072 | bp_modified = 1; | |
8073 | } | |
8074 | } | |
8075 | ||
8076 | if (bp_modified) | |
8077 | observer_notify_breakpoint_modified (b); | |
8078 | } | |
8079 | } | |
8080 | ||
ce78b96d JB |
8081 | /* FORK & VFORK catchpoints. */ |
8082 | ||
e29a4733 PA |
8083 | /* An instance of this type is used to represent a fork or vfork |
8084 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8085 | class; users downcast to "struct breakpoint *" when needed. A | |
8086 | breakpoint is really of this type iff its ops pointer points to | |
8087 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8088 | ||
8089 | struct fork_catchpoint | |
8090 | { | |
8091 | /* The base class. */ | |
8092 | struct breakpoint base; | |
8093 | ||
8094 | /* Process id of a child process whose forking triggered this | |
8095 | catchpoint. This field is only valid immediately after this | |
8096 | catchpoint has triggered. */ | |
8097 | ptid_t forked_inferior_pid; | |
8098 | }; | |
8099 | ||
4a64f543 MS |
8100 | /* Implement the "insert" breakpoint_ops method for fork |
8101 | catchpoints. */ | |
ce78b96d | 8102 | |
77b06cd7 TJB |
8103 | static int |
8104 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8105 | { |
dfd4cc63 | 8106 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8107 | } |
8108 | ||
4a64f543 MS |
8109 | /* Implement the "remove" breakpoint_ops method for fork |
8110 | catchpoints. */ | |
ce78b96d JB |
8111 | |
8112 | static int | |
73971819 | 8113 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8114 | { |
dfd4cc63 | 8115 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8116 | } |
8117 | ||
8118 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8119 | catchpoints. */ | |
8120 | ||
8121 | static int | |
f1310107 | 8122 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8123 | struct address_space *aspace, CORE_ADDR bp_addr, |
8124 | const struct target_waitstatus *ws) | |
ce78b96d | 8125 | { |
e29a4733 PA |
8126 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8127 | ||
f90263c1 TT |
8128 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8129 | return 0; | |
8130 | ||
8131 | c->forked_inferior_pid = ws->value.related_pid; | |
8132 | return 1; | |
ce78b96d JB |
8133 | } |
8134 | ||
4a64f543 MS |
8135 | /* Implement the "print_it" breakpoint_ops method for fork |
8136 | catchpoints. */ | |
ce78b96d JB |
8137 | |
8138 | static enum print_stop_action | |
348d480f | 8139 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8140 | { |
36dfb11c | 8141 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8142 | struct breakpoint *b = bs->breakpoint_at; |
8143 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8144 | |
ce78b96d | 8145 | annotate_catchpoint (b->number); |
f303dbd6 | 8146 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8147 | if (b->disposition == disp_del) |
f303dbd6 | 8148 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8149 | else |
f303dbd6 | 8150 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8151 | if (ui_out_is_mi_like_p (uiout)) |
8152 | { | |
8153 | ui_out_field_string (uiout, "reason", | |
8154 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8155 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8156 | } | |
8157 | ui_out_field_int (uiout, "bkptno", b->number); | |
8158 | ui_out_text (uiout, " (forked process "); | |
8159 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8160 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8161 | return PRINT_SRC_AND_LOC; |
8162 | } | |
8163 | ||
4a64f543 MS |
8164 | /* Implement the "print_one" breakpoint_ops method for fork |
8165 | catchpoints. */ | |
ce78b96d JB |
8166 | |
8167 | static void | |
a6d9a66e | 8168 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8169 | { |
e29a4733 | 8170 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8171 | struct value_print_options opts; |
79a45e25 | 8172 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8173 | |
8174 | get_user_print_options (&opts); | |
8175 | ||
4a64f543 MS |
8176 | /* Field 4, the address, is omitted (which makes the columns not |
8177 | line up too nicely with the headers, but the effect is relatively | |
8178 | readable). */ | |
79a45b7d | 8179 | if (opts.addressprint) |
ce78b96d JB |
8180 | ui_out_field_skip (uiout, "addr"); |
8181 | annotate_field (5); | |
8182 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8183 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8184 | { |
8185 | ui_out_text (uiout, ", process "); | |
8186 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8187 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8188 | ui_out_spaces (uiout, 1); |
8189 | } | |
8ac3646f TT |
8190 | |
8191 | if (ui_out_is_mi_like_p (uiout)) | |
8192 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8193 | } |
8194 | ||
8195 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8196 | catchpoints. */ | |
8197 | ||
8198 | static void | |
8199 | print_mention_catch_fork (struct breakpoint *b) | |
8200 | { | |
8201 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8202 | } | |
8203 | ||
6149aea9 PA |
8204 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8205 | catchpoints. */ | |
8206 | ||
8207 | static void | |
8208 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8209 | { | |
8210 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8211 | print_recreate_thread (b, fp); |
6149aea9 PA |
8212 | } |
8213 | ||
ce78b96d JB |
8214 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8215 | ||
2060206e | 8216 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8217 | |
4a64f543 MS |
8218 | /* Implement the "insert" breakpoint_ops method for vfork |
8219 | catchpoints. */ | |
ce78b96d | 8220 | |
77b06cd7 TJB |
8221 | static int |
8222 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8223 | { |
dfd4cc63 | 8224 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8225 | } |
8226 | ||
4a64f543 MS |
8227 | /* Implement the "remove" breakpoint_ops method for vfork |
8228 | catchpoints. */ | |
ce78b96d JB |
8229 | |
8230 | static int | |
73971819 | 8231 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8232 | { |
dfd4cc63 | 8233 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8234 | } |
8235 | ||
8236 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8237 | catchpoints. */ | |
8238 | ||
8239 | static int | |
f1310107 | 8240 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8241 | struct address_space *aspace, CORE_ADDR bp_addr, |
8242 | const struct target_waitstatus *ws) | |
ce78b96d | 8243 | { |
e29a4733 PA |
8244 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8245 | ||
f90263c1 TT |
8246 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8247 | return 0; | |
8248 | ||
8249 | c->forked_inferior_pid = ws->value.related_pid; | |
8250 | return 1; | |
ce78b96d JB |
8251 | } |
8252 | ||
4a64f543 MS |
8253 | /* Implement the "print_it" breakpoint_ops method for vfork |
8254 | catchpoints. */ | |
ce78b96d JB |
8255 | |
8256 | static enum print_stop_action | |
348d480f | 8257 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8258 | { |
36dfb11c | 8259 | struct ui_out *uiout = current_uiout; |
348d480f | 8260 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8261 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8262 | ||
ce78b96d | 8263 | annotate_catchpoint (b->number); |
f303dbd6 | 8264 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8265 | if (b->disposition == disp_del) |
f303dbd6 | 8266 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8267 | else |
f303dbd6 | 8268 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8269 | if (ui_out_is_mi_like_p (uiout)) |
8270 | { | |
8271 | ui_out_field_string (uiout, "reason", | |
8272 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8273 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8274 | } | |
8275 | ui_out_field_int (uiout, "bkptno", b->number); | |
8276 | ui_out_text (uiout, " (vforked process "); | |
8277 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8278 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8279 | return PRINT_SRC_AND_LOC; |
8280 | } | |
8281 | ||
4a64f543 MS |
8282 | /* Implement the "print_one" breakpoint_ops method for vfork |
8283 | catchpoints. */ | |
ce78b96d JB |
8284 | |
8285 | static void | |
a6d9a66e | 8286 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8287 | { |
e29a4733 | 8288 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8289 | struct value_print_options opts; |
79a45e25 | 8290 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8291 | |
8292 | get_user_print_options (&opts); | |
4a64f543 MS |
8293 | /* Field 4, the address, is omitted (which makes the columns not |
8294 | line up too nicely with the headers, but the effect is relatively | |
8295 | readable). */ | |
79a45b7d | 8296 | if (opts.addressprint) |
ce78b96d JB |
8297 | ui_out_field_skip (uiout, "addr"); |
8298 | annotate_field (5); | |
8299 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8300 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8301 | { |
8302 | ui_out_text (uiout, ", process "); | |
8303 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8304 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8305 | ui_out_spaces (uiout, 1); |
8306 | } | |
8ac3646f TT |
8307 | |
8308 | if (ui_out_is_mi_like_p (uiout)) | |
8309 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8310 | } |
8311 | ||
8312 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8313 | catchpoints. */ | |
8314 | ||
8315 | static void | |
8316 | print_mention_catch_vfork (struct breakpoint *b) | |
8317 | { | |
8318 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8319 | } | |
8320 | ||
6149aea9 PA |
8321 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8322 | catchpoints. */ | |
8323 | ||
8324 | static void | |
8325 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8326 | { | |
8327 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8328 | print_recreate_thread (b, fp); |
6149aea9 PA |
8329 | } |
8330 | ||
ce78b96d JB |
8331 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8332 | ||
2060206e | 8333 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8334 | |
edcc5120 TT |
8335 | /* An instance of this type is used to represent an solib catchpoint. |
8336 | It includes a "struct breakpoint" as a kind of base class; users | |
8337 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8338 | really of this type iff its ops pointer points to | |
8339 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8340 | ||
8341 | struct solib_catchpoint | |
8342 | { | |
8343 | /* The base class. */ | |
8344 | struct breakpoint base; | |
8345 | ||
8346 | /* True for "catch load", false for "catch unload". */ | |
8347 | unsigned char is_load; | |
8348 | ||
8349 | /* Regular expression to match, if any. COMPILED is only valid when | |
8350 | REGEX is non-NULL. */ | |
8351 | char *regex; | |
8352 | regex_t compiled; | |
8353 | }; | |
8354 | ||
8355 | static void | |
8356 | dtor_catch_solib (struct breakpoint *b) | |
8357 | { | |
8358 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8359 | ||
8360 | if (self->regex) | |
8361 | regfree (&self->compiled); | |
8362 | xfree (self->regex); | |
8363 | ||
8364 | base_breakpoint_ops.dtor (b); | |
8365 | } | |
8366 | ||
8367 | static int | |
8368 | insert_catch_solib (struct bp_location *ignore) | |
8369 | { | |
8370 | return 0; | |
8371 | } | |
8372 | ||
8373 | static int | |
73971819 | 8374 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8375 | { |
8376 | return 0; | |
8377 | } | |
8378 | ||
8379 | static int | |
8380 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8381 | struct address_space *aspace, | |
8382 | CORE_ADDR bp_addr, | |
8383 | const struct target_waitstatus *ws) | |
8384 | { | |
8385 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8386 | struct breakpoint *other; | |
8387 | ||
8388 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8389 | return 1; | |
8390 | ||
8391 | ALL_BREAKPOINTS (other) | |
8392 | { | |
8393 | struct bp_location *other_bl; | |
8394 | ||
8395 | if (other == bl->owner) | |
8396 | continue; | |
8397 | ||
8398 | if (other->type != bp_shlib_event) | |
8399 | continue; | |
8400 | ||
8401 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8402 | continue; | |
8403 | ||
8404 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8405 | { | |
8406 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8407 | return 1; | |
8408 | } | |
8409 | } | |
8410 | ||
8411 | return 0; | |
8412 | } | |
8413 | ||
8414 | static void | |
8415 | check_status_catch_solib (struct bpstats *bs) | |
8416 | { | |
8417 | struct solib_catchpoint *self | |
8418 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8419 | int ix; | |
8420 | ||
8421 | if (self->is_load) | |
8422 | { | |
8423 | struct so_list *iter; | |
8424 | ||
8425 | for (ix = 0; | |
8426 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8427 | ix, iter); | |
8428 | ++ix) | |
8429 | { | |
8430 | if (!self->regex | |
8431 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8432 | return; | |
8433 | } | |
8434 | } | |
8435 | else | |
8436 | { | |
8437 | char *iter; | |
8438 | ||
8439 | for (ix = 0; | |
8440 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8441 | ix, iter); | |
8442 | ++ix) | |
8443 | { | |
8444 | if (!self->regex | |
8445 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8446 | return; | |
8447 | } | |
8448 | } | |
8449 | ||
8450 | bs->stop = 0; | |
8451 | bs->print_it = print_it_noop; | |
8452 | } | |
8453 | ||
8454 | static enum print_stop_action | |
8455 | print_it_catch_solib (bpstat bs) | |
8456 | { | |
8457 | struct breakpoint *b = bs->breakpoint_at; | |
8458 | struct ui_out *uiout = current_uiout; | |
8459 | ||
8460 | annotate_catchpoint (b->number); | |
f303dbd6 | 8461 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8462 | if (b->disposition == disp_del) |
f303dbd6 | 8463 | ui_out_text (uiout, "Temporary catchpoint "); |
edcc5120 | 8464 | else |
f303dbd6 | 8465 | ui_out_text (uiout, "Catchpoint "); |
edcc5120 TT |
8466 | ui_out_field_int (uiout, "bkptno", b->number); |
8467 | ui_out_text (uiout, "\n"); | |
8468 | if (ui_out_is_mi_like_p (uiout)) | |
8469 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8470 | print_solib_event (1); | |
8471 | return PRINT_SRC_AND_LOC; | |
8472 | } | |
8473 | ||
8474 | static void | |
8475 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8476 | { | |
8477 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8478 | struct value_print_options opts; | |
8479 | struct ui_out *uiout = current_uiout; | |
8480 | char *msg; | |
8481 | ||
8482 | get_user_print_options (&opts); | |
8483 | /* Field 4, the address, is omitted (which makes the columns not | |
8484 | line up too nicely with the headers, but the effect is relatively | |
8485 | readable). */ | |
8486 | if (opts.addressprint) | |
8487 | { | |
8488 | annotate_field (4); | |
8489 | ui_out_field_skip (uiout, "addr"); | |
8490 | } | |
8491 | ||
8492 | annotate_field (5); | |
8493 | if (self->is_load) | |
8494 | { | |
8495 | if (self->regex) | |
8496 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8497 | else | |
8498 | msg = xstrdup (_("load of library")); | |
8499 | } | |
8500 | else | |
8501 | { | |
8502 | if (self->regex) | |
8503 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8504 | else | |
8505 | msg = xstrdup (_("unload of library")); | |
8506 | } | |
8507 | ui_out_field_string (uiout, "what", msg); | |
8508 | xfree (msg); | |
8ac3646f TT |
8509 | |
8510 | if (ui_out_is_mi_like_p (uiout)) | |
8511 | ui_out_field_string (uiout, "catch-type", | |
8512 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8513 | } |
8514 | ||
8515 | static void | |
8516 | print_mention_catch_solib (struct breakpoint *b) | |
8517 | { | |
8518 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8519 | ||
8520 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8521 | self->is_load ? "load" : "unload"); | |
8522 | } | |
8523 | ||
8524 | static void | |
8525 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8526 | { | |
8527 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8528 | ||
8529 | fprintf_unfiltered (fp, "%s %s", | |
8530 | b->disposition == disp_del ? "tcatch" : "catch", | |
8531 | self->is_load ? "load" : "unload"); | |
8532 | if (self->regex) | |
8533 | fprintf_unfiltered (fp, " %s", self->regex); | |
8534 | fprintf_unfiltered (fp, "\n"); | |
8535 | } | |
8536 | ||
8537 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8538 | ||
91985142 MG |
8539 | /* Shared helper function (MI and CLI) for creating and installing |
8540 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8541 | the events to be caught are load events, otherwise they are | |
8542 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8543 | temporary one. If ENABLED is non-zero the catchpoint is | |
8544 | created in an enabled state. */ | |
edcc5120 | 8545 | |
91985142 MG |
8546 | void |
8547 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8548 | { |
8549 | struct solib_catchpoint *c; | |
8550 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8551 | struct cleanup *cleanup; |
8552 | ||
edcc5120 TT |
8553 | if (!arg) |
8554 | arg = ""; | |
8555 | arg = skip_spaces (arg); | |
8556 | ||
8557 | c = XCNEW (struct solib_catchpoint); | |
8558 | cleanup = make_cleanup (xfree, c); | |
8559 | ||
8560 | if (*arg != '\0') | |
8561 | { | |
8562 | int errcode; | |
8563 | ||
8564 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8565 | if (errcode != 0) | |
8566 | { | |
8567 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8568 | ||
8569 | make_cleanup (xfree, err); | |
8570 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8571 | } | |
8572 | c->regex = xstrdup (arg); | |
8573 | } | |
8574 | ||
8575 | c->is_load = is_load; | |
91985142 | 8576 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8577 | &catch_solib_breakpoint_ops); |
8578 | ||
91985142 MG |
8579 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8580 | ||
edcc5120 TT |
8581 | discard_cleanups (cleanup); |
8582 | install_breakpoint (0, &c->base, 1); | |
8583 | } | |
8584 | ||
91985142 MG |
8585 | /* A helper function that does all the work for "catch load" and |
8586 | "catch unload". */ | |
8587 | ||
8588 | static void | |
8589 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8590 | struct cmd_list_element *command) | |
8591 | { | |
8592 | int tempflag; | |
8593 | const int enabled = 1; | |
8594 | ||
8595 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8596 | ||
8597 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8598 | } | |
8599 | ||
edcc5120 TT |
8600 | static void |
8601 | catch_load_command_1 (char *arg, int from_tty, | |
8602 | struct cmd_list_element *command) | |
8603 | { | |
8604 | catch_load_or_unload (arg, from_tty, 1, command); | |
8605 | } | |
8606 | ||
8607 | static void | |
8608 | catch_unload_command_1 (char *arg, int from_tty, | |
8609 | struct cmd_list_element *command) | |
8610 | { | |
8611 | catch_load_or_unload (arg, from_tty, 0, command); | |
8612 | } | |
8613 | ||
346774a9 PA |
8614 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8615 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8616 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8617 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8618 | |
ab04a2af | 8619 | void |
346774a9 PA |
8620 | init_catchpoint (struct breakpoint *b, |
8621 | struct gdbarch *gdbarch, int tempflag, | |
8622 | char *cond_string, | |
c0a91b2b | 8623 | const struct breakpoint_ops *ops) |
c906108c | 8624 | { |
c5aa993b | 8625 | struct symtab_and_line sal; |
346774a9 | 8626 | |
fe39c653 | 8627 | init_sal (&sal); |
6c95b8df | 8628 | sal.pspace = current_program_space; |
c5aa993b | 8629 | |
28010a5d | 8630 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8631 | |
1b36a34b | 8632 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8633 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8634 | } |
8635 | ||
28010a5d | 8636 | void |
3ea46bff | 8637 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8638 | { |
8639 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8640 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8641 | if (is_tracepoint (b)) |
8642 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8643 | if (!internal) |
8644 | mention (b); | |
c56053d2 | 8645 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8646 | |
8647 | if (update_gll) | |
44702360 | 8648 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8649 | } |
8650 | ||
9b70b993 | 8651 | static void |
a6d9a66e UW |
8652 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8653 | int tempflag, char *cond_string, | |
c0a91b2b | 8654 | const struct breakpoint_ops *ops) |
c906108c | 8655 | { |
e29a4733 | 8656 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8657 | |
e29a4733 PA |
8658 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8659 | ||
8660 | c->forked_inferior_pid = null_ptid; | |
8661 | ||
3ea46bff | 8662 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8663 | } |
8664 | ||
fe798b75 JB |
8665 | /* Exec catchpoints. */ |
8666 | ||
b4d90040 PA |
8667 | /* An instance of this type is used to represent an exec catchpoint. |
8668 | It includes a "struct breakpoint" as a kind of base class; users | |
8669 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8670 | really of this type iff its ops pointer points to | |
8671 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8672 | ||
8673 | struct exec_catchpoint | |
8674 | { | |
8675 | /* The base class. */ | |
8676 | struct breakpoint base; | |
8677 | ||
8678 | /* Filename of a program whose exec triggered this catchpoint. | |
8679 | This field is only valid immediately after this catchpoint has | |
8680 | triggered. */ | |
8681 | char *exec_pathname; | |
8682 | }; | |
8683 | ||
8684 | /* Implement the "dtor" breakpoint_ops method for exec | |
8685 | catchpoints. */ | |
8686 | ||
8687 | static void | |
8688 | dtor_catch_exec (struct breakpoint *b) | |
8689 | { | |
8690 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8691 | ||
8692 | xfree (c->exec_pathname); | |
348d480f | 8693 | |
2060206e | 8694 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8695 | } |
8696 | ||
77b06cd7 TJB |
8697 | static int |
8698 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8699 | { |
dfd4cc63 | 8700 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8701 | } |
c906108c | 8702 | |
fe798b75 | 8703 | static int |
73971819 | 8704 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8705 | { |
dfd4cc63 | 8706 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8707 | } |
c906108c | 8708 | |
fe798b75 | 8709 | static int |
f1310107 | 8710 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8711 | struct address_space *aspace, CORE_ADDR bp_addr, |
8712 | const struct target_waitstatus *ws) | |
fe798b75 | 8713 | { |
b4d90040 PA |
8714 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8715 | ||
f90263c1 TT |
8716 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8717 | return 0; | |
8718 | ||
8719 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8720 | return 1; | |
fe798b75 | 8721 | } |
c906108c | 8722 | |
fe798b75 | 8723 | static enum print_stop_action |
348d480f | 8724 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8725 | { |
36dfb11c | 8726 | struct ui_out *uiout = current_uiout; |
348d480f | 8727 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8728 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8729 | ||
fe798b75 | 8730 | annotate_catchpoint (b->number); |
f303dbd6 | 8731 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8732 | if (b->disposition == disp_del) |
f303dbd6 | 8733 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8734 | else |
f303dbd6 | 8735 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8736 | if (ui_out_is_mi_like_p (uiout)) |
8737 | { | |
8738 | ui_out_field_string (uiout, "reason", | |
8739 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8740 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8741 | } | |
8742 | ui_out_field_int (uiout, "bkptno", b->number); | |
8743 | ui_out_text (uiout, " (exec'd "); | |
8744 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8745 | ui_out_text (uiout, "), "); | |
8746 | ||
fe798b75 | 8747 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8748 | } |
8749 | ||
fe798b75 | 8750 | static void |
a6d9a66e | 8751 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8752 | { |
b4d90040 | 8753 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8754 | struct value_print_options opts; |
79a45e25 | 8755 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8756 | |
8757 | get_user_print_options (&opts); | |
8758 | ||
8759 | /* Field 4, the address, is omitted (which makes the columns | |
8760 | not line up too nicely with the headers, but the effect | |
8761 | is relatively readable). */ | |
8762 | if (opts.addressprint) | |
8763 | ui_out_field_skip (uiout, "addr"); | |
8764 | annotate_field (5); | |
8765 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8766 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8767 | { |
8768 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8769 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8770 | ui_out_text (uiout, "\" "); |
8771 | } | |
8ac3646f TT |
8772 | |
8773 | if (ui_out_is_mi_like_p (uiout)) | |
8774 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8775 | } |
8776 | ||
8777 | static void | |
8778 | print_mention_catch_exec (struct breakpoint *b) | |
8779 | { | |
8780 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8781 | } | |
8782 | ||
6149aea9 PA |
8783 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8784 | catchpoints. */ | |
8785 | ||
8786 | static void | |
8787 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8788 | { | |
8789 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8790 | print_recreate_thread (b, fp); |
6149aea9 PA |
8791 | } |
8792 | ||
2060206e | 8793 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8794 | |
c906108c | 8795 | static int |
fba45db2 | 8796 | hw_breakpoint_used_count (void) |
c906108c | 8797 | { |
c906108c | 8798 | int i = 0; |
f1310107 TJB |
8799 | struct breakpoint *b; |
8800 | struct bp_location *bl; | |
c906108c SS |
8801 | |
8802 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8803 | { |
d6b74ac4 | 8804 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8805 | for (bl = b->loc; bl; bl = bl->next) |
8806 | { | |
8807 | /* Special types of hardware breakpoints may use more than | |
8808 | one register. */ | |
348d480f | 8809 | i += b->ops->resources_needed (bl); |
f1310107 | 8810 | } |
c5aa993b | 8811 | } |
c906108c SS |
8812 | |
8813 | return i; | |
8814 | } | |
8815 | ||
a1398e0c PA |
8816 | /* Returns the resources B would use if it were a hardware |
8817 | watchpoint. */ | |
8818 | ||
c906108c | 8819 | static int |
a1398e0c | 8820 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8821 | { |
c906108c | 8822 | int i = 0; |
e09342b5 | 8823 | struct bp_location *bl; |
c906108c | 8824 | |
a1398e0c PA |
8825 | if (!breakpoint_enabled (b)) |
8826 | return 0; | |
8827 | ||
8828 | for (bl = b->loc; bl; bl = bl->next) | |
8829 | { | |
8830 | /* Special types of hardware watchpoints may use more than | |
8831 | one register. */ | |
8832 | i += b->ops->resources_needed (bl); | |
8833 | } | |
8834 | ||
8835 | return i; | |
8836 | } | |
8837 | ||
8838 | /* Returns the sum the used resources of all hardware watchpoints of | |
8839 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8840 | the sum of the used resources of all hardware watchpoints of other | |
8841 | types _not_ TYPE. */ | |
8842 | ||
8843 | static int | |
8844 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8845 | enum bptype type, int *other_type_used) | |
8846 | { | |
8847 | int i = 0; | |
8848 | struct breakpoint *b; | |
8849 | ||
c906108c SS |
8850 | *other_type_used = 0; |
8851 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8852 | { |
a1398e0c PA |
8853 | if (b == except) |
8854 | continue; | |
e09342b5 TJB |
8855 | if (!breakpoint_enabled (b)) |
8856 | continue; | |
8857 | ||
a1398e0c PA |
8858 | if (b->type == type) |
8859 | i += hw_watchpoint_use_count (b); | |
8860 | else if (is_hardware_watchpoint (b)) | |
8861 | *other_type_used = 1; | |
e09342b5 TJB |
8862 | } |
8863 | ||
c906108c SS |
8864 | return i; |
8865 | } | |
8866 | ||
c906108c | 8867 | void |
fba45db2 | 8868 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8869 | { |
c5aa993b | 8870 | struct breakpoint *b; |
c906108c SS |
8871 | |
8872 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8873 | { |
cc60f2e3 | 8874 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8875 | { |
b5de0fa7 | 8876 | b->enable_state = bp_call_disabled; |
44702360 | 8877 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8878 | } |
8879 | } | |
c906108c SS |
8880 | } |
8881 | ||
8882 | void | |
fba45db2 | 8883 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8884 | { |
c5aa993b | 8885 | struct breakpoint *b; |
c906108c SS |
8886 | |
8887 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8888 | { |
cc60f2e3 | 8889 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8890 | { |
b5de0fa7 | 8891 | b->enable_state = bp_enabled; |
44702360 | 8892 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8893 | } |
8894 | } | |
c906108c SS |
8895 | } |
8896 | ||
8bea4e01 UW |
8897 | void |
8898 | disable_breakpoints_before_startup (void) | |
8899 | { | |
6c95b8df | 8900 | current_program_space->executing_startup = 1; |
44702360 | 8901 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8902 | } |
8903 | ||
8904 | void | |
8905 | enable_breakpoints_after_startup (void) | |
8906 | { | |
6c95b8df | 8907 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8908 | breakpoint_re_set (); |
8bea4e01 UW |
8909 | } |
8910 | ||
7c16b83e PA |
8911 | /* Create a new single-step breakpoint for thread THREAD, with no |
8912 | locations. */ | |
c906108c | 8913 | |
7c16b83e PA |
8914 | static struct breakpoint * |
8915 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8916 | { | |
8917 | struct breakpoint *b = XNEW (struct breakpoint); | |
8918 | ||
8919 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8920 | &momentary_breakpoint_ops); | |
8921 | ||
8922 | b->disposition = disp_donttouch; | |
8923 | b->frame_id = null_frame_id; | |
8924 | ||
8925 | b->thread = thread; | |
8926 | gdb_assert (b->thread != 0); | |
8927 | ||
8928 | add_to_breakpoint_chain (b); | |
8929 | ||
8930 | return b; | |
8931 | } | |
8932 | ||
8933 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8934 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8935 | frame. */ | |
c906108c SS |
8936 | |
8937 | struct breakpoint * | |
a6d9a66e UW |
8938 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8939 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8940 | { |
52f0bd74 | 8941 | struct breakpoint *b; |
edb3359d | 8942 | |
193facb3 JK |
8943 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8944 | tail-called one. */ | |
8945 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8946 | |
06edf0c0 | 8947 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8948 | b->enable_state = bp_enabled; |
8949 | b->disposition = disp_donttouch; | |
818dd999 | 8950 | b->frame_id = frame_id; |
c906108c | 8951 | |
4a64f543 MS |
8952 | /* If we're debugging a multi-threaded program, then we want |
8953 | momentary breakpoints to be active in only a single thread of | |
8954 | control. */ | |
39f77062 | 8955 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8956 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8957 | |
44702360 | 8958 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8959 | |
c906108c SS |
8960 | return b; |
8961 | } | |
611c83ae | 8962 | |
06edf0c0 | 8963 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8964 | The new breakpoint will have type TYPE, use OPS as its |
8965 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8966 | |
06edf0c0 PA |
8967 | static struct breakpoint * |
8968 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8969 | enum bptype type, | |
a1aa2221 LM |
8970 | const struct breakpoint_ops *ops, |
8971 | int loc_enabled) | |
e58b0e63 PA |
8972 | { |
8973 | struct breakpoint *copy; | |
8974 | ||
06edf0c0 | 8975 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8976 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8977 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8978 | |
a6d9a66e | 8979 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8980 | copy->loc->requested_address = orig->loc->requested_address; |
8981 | copy->loc->address = orig->loc->address; | |
8982 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8983 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8984 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8985 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8986 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8987 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8988 | copy->frame_id = orig->frame_id; |
8989 | copy->thread = orig->thread; | |
6c95b8df | 8990 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8991 | |
8992 | copy->enable_state = bp_enabled; | |
8993 | copy->disposition = disp_donttouch; | |
8994 | copy->number = internal_breakpoint_number--; | |
8995 | ||
44702360 | 8996 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8997 | return copy; |
8998 | } | |
8999 | ||
06edf0c0 PA |
9000 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9001 | ORIG is NULL. */ | |
9002 | ||
9003 | struct breakpoint * | |
9004 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9005 | { | |
9006 | /* If there's nothing to clone, then return nothing. */ | |
9007 | if (orig == NULL) | |
9008 | return NULL; | |
9009 | ||
a1aa2221 | 9010 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
9011 | } |
9012 | ||
611c83ae | 9013 | struct breakpoint * |
a6d9a66e UW |
9014 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9015 | enum bptype type) | |
611c83ae PA |
9016 | { |
9017 | struct symtab_and_line sal; | |
9018 | ||
9019 | sal = find_pc_line (pc, 0); | |
9020 | sal.pc = pc; | |
9021 | sal.section = find_pc_overlay (pc); | |
9022 | sal.explicit_pc = 1; | |
9023 | ||
a6d9a66e | 9024 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9025 | } |
c906108c | 9026 | \f |
c5aa993b | 9027 | |
c906108c SS |
9028 | /* Tell the user we have just set a breakpoint B. */ |
9029 | ||
9030 | static void | |
fba45db2 | 9031 | mention (struct breakpoint *b) |
c906108c | 9032 | { |
348d480f | 9033 | b->ops->print_mention (b); |
79a45e25 | 9034 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9035 | return; |
c906108c SS |
9036 | printf_filtered ("\n"); |
9037 | } | |
c906108c | 9038 | \f |
c5aa993b | 9039 | |
1a853c52 PA |
9040 | static int bp_loc_is_permanent (struct bp_location *loc); |
9041 | ||
0d381245 | 9042 | static struct bp_location * |
39d61571 | 9043 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9044 | const struct symtab_and_line *sal) |
9045 | { | |
9046 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9047 | CORE_ADDR adjusted_address; |
9048 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9049 | ||
9050 | if (loc_gdbarch == NULL) | |
9051 | loc_gdbarch = b->gdbarch; | |
9052 | ||
9053 | /* Adjust the breakpoint's address prior to allocating a location. | |
9054 | Once we call allocate_bp_location(), that mostly uninitialized | |
9055 | location will be placed on the location chain. Adjustment of the | |
9056 | breakpoint may cause target_read_memory() to be called and we do | |
9057 | not want its scan of the location chain to find a breakpoint and | |
9058 | location that's only been partially initialized. */ | |
9059 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9060 | sal->pc, b->type); | |
0d381245 | 9061 | |
d30113d4 | 9062 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9063 | loc = allocate_bp_location (b); |
d30113d4 JK |
9064 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9065 | tmp = &((*tmp)->next)) | |
0d381245 | 9066 | ; |
d30113d4 | 9067 | loc->next = *tmp; |
0d381245 | 9068 | *tmp = loc; |
3742cc8b | 9069 | |
0d381245 | 9070 | loc->requested_address = sal->pc; |
3742cc8b | 9071 | loc->address = adjusted_address; |
6c95b8df | 9072 | loc->pspace = sal->pspace; |
729662a5 TT |
9073 | loc->probe.probe = sal->probe; |
9074 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9075 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9076 | loc->section = sal->section; |
3742cc8b | 9077 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9078 | loc->line_number = sal->line; |
2f202fde | 9079 | loc->symtab = sal->symtab; |
f8eba3c6 | 9080 | |
0e30163f JK |
9081 | set_breakpoint_location_function (loc, |
9082 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9083 | |
6ae88661 LM |
9084 | /* While by definition, permanent breakpoints are already present in the |
9085 | code, we don't mark the location as inserted. Normally one would expect | |
9086 | that GDB could rely on that breakpoint instruction to stop the program, | |
9087 | thus removing the need to insert its own breakpoint, except that executing | |
9088 | the breakpoint instruction can kill the target instead of reporting a | |
9089 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9090 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9091 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9092 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9093 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9094 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9095 | it manually increments the PC, thus avoiding executing the breakpoint | |
9096 | instruction.) */ | |
1a853c52 | 9097 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9098 | loc->permanent = 1; |
1a853c52 | 9099 | |
0d381245 VP |
9100 | return loc; |
9101 | } | |
514f746b AR |
9102 | \f |
9103 | ||
1cf4d951 | 9104 | /* See breakpoint.h. */ |
514f746b | 9105 | |
1cf4d951 PA |
9106 | int |
9107 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9108 | { |
9109 | int len; | |
9110 | CORE_ADDR addr; | |
1afeeb75 | 9111 | const gdb_byte *bpoint; |
514f746b | 9112 | gdb_byte *target_mem; |
939c61fa JK |
9113 | struct cleanup *cleanup; |
9114 | int retval = 0; | |
514f746b | 9115 | |
1cf4d951 PA |
9116 | addr = address; |
9117 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9118 | ||
9119 | /* Software breakpoints unsupported? */ | |
9120 | if (bpoint == NULL) | |
9121 | return 0; | |
9122 | ||
224c3ddb | 9123 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9124 | |
9125 | /* Enable the automatic memory restoration from breakpoints while | |
9126 | we read the memory. Otherwise we could say about our temporary | |
9127 | breakpoints they are permanent. */ | |
9128 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9129 | ||
9130 | if (target_read_memory (address, target_mem, len) == 0 | |
9131 | && memcmp (target_mem, bpoint, len) == 0) | |
9132 | retval = 1; | |
9133 | ||
9134 | do_cleanups (cleanup); | |
9135 | ||
9136 | return retval; | |
9137 | } | |
9138 | ||
9139 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9140 | return 0 otherwise. */ | |
9141 | ||
9142 | static int | |
9143 | bp_loc_is_permanent (struct bp_location *loc) | |
9144 | { | |
9145 | struct cleanup *cleanup; | |
9146 | int retval; | |
9147 | ||
514f746b AR |
9148 | gdb_assert (loc != NULL); |
9149 | ||
244558af LM |
9150 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9151 | attempt to read from the addresses the locations of these breakpoint types | |
9152 | point to. program_breakpoint_here_p, below, will attempt to read | |
9153 | memory. */ | |
9154 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9155 | return 0; | |
9156 | ||
6c95b8df | 9157 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9158 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9159 | |
1cf4d951 | 9160 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9161 | |
939c61fa JK |
9162 | do_cleanups (cleanup); |
9163 | ||
9164 | return retval; | |
514f746b AR |
9165 | } |
9166 | ||
e7e0cddf SS |
9167 | /* Build a command list for the dprintf corresponding to the current |
9168 | settings of the dprintf style options. */ | |
9169 | ||
9170 | static void | |
9171 | update_dprintf_command_list (struct breakpoint *b) | |
9172 | { | |
9173 | char *dprintf_args = b->extra_string; | |
9174 | char *printf_line = NULL; | |
9175 | ||
9176 | if (!dprintf_args) | |
9177 | return; | |
9178 | ||
9179 | dprintf_args = skip_spaces (dprintf_args); | |
9180 | ||
9181 | /* Allow a comma, as it may have terminated a location, but don't | |
9182 | insist on it. */ | |
9183 | if (*dprintf_args == ',') | |
9184 | ++dprintf_args; | |
9185 | dprintf_args = skip_spaces (dprintf_args); | |
9186 | ||
9187 | if (*dprintf_args != '"') | |
9188 | error (_("Bad format string, missing '\"'.")); | |
9189 | ||
d3ce09f5 | 9190 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9191 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9192 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9193 | { |
9194 | if (!dprintf_function) | |
9195 | error (_("No function supplied for dprintf call")); | |
9196 | ||
9197 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9198 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9199 | dprintf_function, | |
9200 | dprintf_channel, | |
9201 | dprintf_args); | |
9202 | else | |
9203 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9204 | dprintf_function, | |
9205 | dprintf_args); | |
9206 | } | |
d3ce09f5 SS |
9207 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9208 | { | |
9209 | if (target_can_run_breakpoint_commands ()) | |
9210 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9211 | else | |
9212 | { | |
9213 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9214 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9215 | } | |
9216 | } | |
e7e0cddf SS |
9217 | else |
9218 | internal_error (__FILE__, __LINE__, | |
9219 | _("Invalid dprintf style.")); | |
9220 | ||
f28045c2 | 9221 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9222 | /* Manufacture a printf sequence. */ |
f28045c2 | 9223 | { |
8d749320 | 9224 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9225 | |
f28045c2 YQ |
9226 | printf_cmd_line->control_type = simple_control; |
9227 | printf_cmd_line->body_count = 0; | |
9228 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9229 | printf_cmd_line->next = NULL; |
f28045c2 | 9230 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9231 | |
f28045c2 YQ |
9232 | breakpoint_set_commands (b, printf_cmd_line); |
9233 | } | |
e7e0cddf SS |
9234 | } |
9235 | ||
9236 | /* Update all dprintf commands, making their command lists reflect | |
9237 | current style settings. */ | |
9238 | ||
9239 | static void | |
9240 | update_dprintf_commands (char *args, int from_tty, | |
9241 | struct cmd_list_element *c) | |
9242 | { | |
9243 | struct breakpoint *b; | |
9244 | ||
9245 | ALL_BREAKPOINTS (b) | |
9246 | { | |
9247 | if (b->type == bp_dprintf) | |
9248 | update_dprintf_command_list (b); | |
9249 | } | |
9250 | } | |
c3f6f71d | 9251 | |
f00aae0f KS |
9252 | /* Create a breakpoint with SAL as location. Use LOCATION |
9253 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9254 | as condition expression. If LOCATION is NULL then create an |
9255 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9256 | |
9257 | static void | |
d9b3f62e | 9258 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f KS |
9259 | struct symtabs_and_lines sals, |
9260 | struct event_location *location, | |
f8eba3c6 | 9261 | char *filter, char *cond_string, |
e7e0cddf | 9262 | char *extra_string, |
d9b3f62e PA |
9263 | enum bptype type, enum bpdisp disposition, |
9264 | int thread, int task, int ignore_count, | |
c0a91b2b | 9265 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9266 | int enabled, int internal, unsigned flags, |
9267 | int display_canonical) | |
018d34a4 | 9268 | { |
0d381245 | 9269 | int i; |
018d34a4 VP |
9270 | |
9271 | if (type == bp_hardware_breakpoint) | |
9272 | { | |
fbbd034e AS |
9273 | int target_resources_ok; |
9274 | ||
9275 | i = hw_breakpoint_used_count (); | |
9276 | target_resources_ok = | |
9277 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9278 | i + 1, 0); |
9279 | if (target_resources_ok == 0) | |
9280 | error (_("No hardware breakpoint support in the target.")); | |
9281 | else if (target_resources_ok < 0) | |
9282 | error (_("Hardware breakpoints used exceeds limit.")); | |
9283 | } | |
9284 | ||
6c95b8df PA |
9285 | gdb_assert (sals.nelts > 0); |
9286 | ||
0d381245 VP |
9287 | for (i = 0; i < sals.nelts; ++i) |
9288 | { | |
9289 | struct symtab_and_line sal = sals.sals[i]; | |
9290 | struct bp_location *loc; | |
9291 | ||
9292 | if (from_tty) | |
5af949e3 UW |
9293 | { |
9294 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9295 | if (!loc_gdbarch) | |
9296 | loc_gdbarch = gdbarch; | |
9297 | ||
9298 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9299 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9300 | } |
0d381245 VP |
9301 | |
9302 | if (i == 0) | |
9303 | { | |
d9b3f62e | 9304 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9305 | b->thread = thread; |
4a306c9a | 9306 | b->task = task; |
855a6e68 | 9307 | |
0d381245 | 9308 | b->cond_string = cond_string; |
e7e0cddf | 9309 | b->extra_string = extra_string; |
0d381245 | 9310 | b->ignore_count = ignore_count; |
41447f92 | 9311 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9312 | b->disposition = disposition; |
6c95b8df | 9313 | |
44f238bb PA |
9314 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9315 | b->loc->inserted = 1; | |
9316 | ||
0fb4aa4b PA |
9317 | if (type == bp_static_tracepoint) |
9318 | { | |
d9b3f62e | 9319 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9320 | struct static_tracepoint_marker marker; |
9321 | ||
983af33b | 9322 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9323 | { |
9324 | /* We already know the marker exists, otherwise, we | |
9325 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9326 | const char *p = &event_location_to_string (b->location)[3]; |
9327 | const char *endp; | |
0fb4aa4b | 9328 | char *marker_str; |
0fb4aa4b | 9329 | |
f00aae0f | 9330 | p = skip_spaces_const (p); |
0fb4aa4b | 9331 | |
f00aae0f | 9332 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9333 | |
9334 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9335 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9336 | |
3e43a32a MS |
9337 | printf_filtered (_("Probed static tracepoint " |
9338 | "marker \"%s\"\n"), | |
d9b3f62e | 9339 | t->static_trace_marker_id); |
0fb4aa4b PA |
9340 | } |
9341 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9342 | { | |
d9b3f62e | 9343 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9344 | release_static_tracepoint_marker (&marker); |
9345 | ||
3e43a32a MS |
9346 | printf_filtered (_("Probed static tracepoint " |
9347 | "marker \"%s\"\n"), | |
d9b3f62e | 9348 | t->static_trace_marker_id); |
0fb4aa4b PA |
9349 | } |
9350 | else | |
3e43a32a MS |
9351 | warning (_("Couldn't determine the static " |
9352 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9353 | } |
9354 | ||
0d381245 VP |
9355 | loc = b->loc; |
9356 | } | |
9357 | else | |
018d34a4 | 9358 | { |
39d61571 | 9359 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9360 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9361 | loc->inserted = 1; | |
0d381245 VP |
9362 | } |
9363 | ||
9364 | if (b->cond_string) | |
9365 | { | |
bbc13ae3 KS |
9366 | const char *arg = b->cond_string; |
9367 | ||
1bb9788d TT |
9368 | loc->cond = parse_exp_1 (&arg, loc->address, |
9369 | block_for_pc (loc->address), 0); | |
0d381245 | 9370 | if (*arg) |
588ae58c | 9371 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9372 | } |
e7e0cddf SS |
9373 | |
9374 | /* Dynamic printf requires and uses additional arguments on the | |
9375 | command line, otherwise it's an error. */ | |
9376 | if (type == bp_dprintf) | |
9377 | { | |
9378 | if (b->extra_string) | |
9379 | update_dprintf_command_list (b); | |
9380 | else | |
9381 | error (_("Format string required")); | |
9382 | } | |
9383 | else if (b->extra_string) | |
588ae58c | 9384 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9385 | } |
018d34a4 | 9386 | |
56435ebe | 9387 | b->display_canonical = display_canonical; |
f00aae0f KS |
9388 | if (location != NULL) |
9389 | b->location = location; | |
018d34a4 | 9390 | else |
305e13e6 JB |
9391 | { |
9392 | const char *addr_string = NULL; | |
9393 | int addr_string_len = 0; | |
9394 | ||
9395 | if (location != NULL) | |
9396 | addr_string = event_location_to_string (location); | |
9397 | if (addr_string != NULL) | |
9398 | addr_string_len = strlen (addr_string); | |
9399 | ||
9400 | b->location = new_address_location (b->loc->address, | |
9401 | addr_string, addr_string_len); | |
9402 | } | |
f8eba3c6 | 9403 | b->filter = filter; |
d9b3f62e | 9404 | } |
018d34a4 | 9405 | |
d9b3f62e PA |
9406 | static void |
9407 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f KS |
9408 | struct symtabs_and_lines sals, |
9409 | struct event_location *location, | |
f8eba3c6 | 9410 | char *filter, char *cond_string, |
e7e0cddf | 9411 | char *extra_string, |
d9b3f62e PA |
9412 | enum bptype type, enum bpdisp disposition, |
9413 | int thread, int task, int ignore_count, | |
c0a91b2b | 9414 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9415 | int enabled, int internal, unsigned flags, |
9416 | int display_canonical) | |
d9b3f62e PA |
9417 | { |
9418 | struct breakpoint *b; | |
9419 | struct cleanup *old_chain; | |
9420 | ||
9421 | if (is_tracepoint_type (type)) | |
9422 | { | |
9423 | struct tracepoint *t; | |
9424 | ||
9425 | t = XCNEW (struct tracepoint); | |
9426 | b = &t->base; | |
9427 | } | |
9428 | else | |
9429 | b = XNEW (struct breakpoint); | |
9430 | ||
9431 | old_chain = make_cleanup (xfree, b); | |
9432 | ||
9433 | init_breakpoint_sal (b, gdbarch, | |
f00aae0f | 9434 | sals, location, |
e7e0cddf | 9435 | filter, cond_string, extra_string, |
d9b3f62e PA |
9436 | type, disposition, |
9437 | thread, task, ignore_count, | |
9438 | ops, from_tty, | |
44f238bb PA |
9439 | enabled, internal, flags, |
9440 | display_canonical); | |
d9b3f62e PA |
9441 | discard_cleanups (old_chain); |
9442 | ||
3ea46bff | 9443 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9444 | } |
9445 | ||
9446 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9447 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9448 | value. COND_STRING, if not NULL, specified the condition to be | |
9449 | used for all breakpoints. Essentially the only case where | |
9450 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9451 | function. In that case, it's still not possible to specify | |
9452 | separate conditions for different overloaded functions, so | |
9453 | we take just a single condition string. | |
9454 | ||
c3f6f71d | 9455 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9456 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9457 | array contents). If the function fails (error() is called), the |
9458 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9459 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9460 | |
9461 | static void | |
8cdf0e15 | 9462 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9463 | struct linespec_result *canonical, |
e7e0cddf | 9464 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9465 | enum bptype type, enum bpdisp disposition, |
9466 | int thread, int task, int ignore_count, | |
c0a91b2b | 9467 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9468 | int enabled, int internal, unsigned flags) |
c906108c | 9469 | { |
018d34a4 | 9470 | int i; |
f8eba3c6 | 9471 | struct linespec_sals *lsal; |
cc59ec59 | 9472 | |
f8eba3c6 TT |
9473 | if (canonical->pre_expanded) |
9474 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9475 | ||
9476 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9477 | { |
f00aae0f | 9478 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9479 | 'break', without arguments. */ |
f00aae0f KS |
9480 | struct event_location *location |
9481 | = (canonical->location != NULL | |
9482 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9483 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
f00aae0f | 9484 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
0d381245 | 9485 | |
f8eba3c6 TT |
9486 | make_cleanup (xfree, filter_string); |
9487 | create_breakpoint_sal (gdbarch, lsal->sals, | |
f00aae0f | 9488 | location, |
f8eba3c6 | 9489 | filter_string, |
e7e0cddf SS |
9490 | cond_string, extra_string, |
9491 | type, disposition, | |
84f4c1fe | 9492 | thread, task, ignore_count, ops, |
44f238bb | 9493 | from_tty, enabled, internal, flags, |
56435ebe | 9494 | canonical->special_display); |
f8eba3c6 | 9495 | discard_cleanups (inner); |
c3f6f71d | 9496 | } |
c3f6f71d | 9497 | } |
c906108c | 9498 | |
f00aae0f | 9499 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9500 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9501 | addresses found. LOCATION points to the end of the SAL (for |
9502 | linespec locations). | |
9998af43 TJB |
9503 | |
9504 | The array and the line spec strings are allocated on the heap, it is | |
9505 | the caller's responsibility to free them. */ | |
c906108c | 9506 | |
b9362cc7 | 9507 | static void |
f00aae0f | 9508 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9509 | struct linespec_result *canonical) |
c3f6f71d | 9510 | { |
f00aae0f KS |
9511 | struct symtab_and_line cursal; |
9512 | ||
9513 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9514 | { | |
9515 | const char *address = get_linespec_location (location); | |
9516 | ||
9517 | if (address == NULL) | |
9518 | { | |
9519 | /* The last displayed codepoint, if it's valid, is our default | |
9520 | breakpoint address. */ | |
9521 | if (last_displayed_sal_is_valid ()) | |
9522 | { | |
9523 | struct linespec_sals lsal; | |
9524 | struct symtab_and_line sal; | |
9525 | CORE_ADDR pc; | |
9526 | ||
9527 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9528 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9529 | |
9530 | /* Set sal's pspace, pc, symtab, and line to the values | |
9531 | corresponding to the last call to print_frame_info. | |
9532 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9533 | as the breakpoint line number is inappropriate otherwise. | |
9534 | find_pc_line would adjust PC, re-set it back. */ | |
9535 | get_last_displayed_sal (&sal); | |
9536 | pc = sal.pc; | |
9537 | sal = find_pc_line (pc, 0); | |
9538 | ||
9539 | /* "break" without arguments is equivalent to "break *PC" | |
9540 | where PC is the last displayed codepoint's address. So | |
9541 | make sure to set sal.explicit_pc to prevent GDB from | |
9542 | trying to expand the list of sals to include all other | |
9543 | instances with the same symtab and line. */ | |
9544 | sal.pc = pc; | |
9545 | sal.explicit_pc = 1; | |
9546 | ||
9547 | lsal.sals.sals[0] = sal; | |
9548 | lsal.sals.nelts = 1; | |
9549 | lsal.canonical = NULL; | |
9550 | ||
9551 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9552 | return; | |
9553 | } | |
9554 | else | |
9555 | error (_("No default breakpoint address now.")); | |
c906108c | 9556 | } |
c906108c | 9557 | } |
f00aae0f KS |
9558 | |
9559 | /* Force almost all breakpoints to be in terms of the | |
9560 | current_source_symtab (which is decode_line_1's default). | |
9561 | This should produce the results we want almost all of the | |
9562 | time while leaving default_breakpoint_* alone. | |
9563 | ||
9564 | ObjC: However, don't match an Objective-C method name which | |
9565 | may have a '+' or '-' succeeded by a '['. */ | |
9566 | cursal = get_current_source_symtab_and_line (); | |
9567 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9568 | { |
f00aae0f | 9569 | const char *address = NULL; |
cc80f267 | 9570 | |
f00aae0f KS |
9571 | if (event_location_type (location) == LINESPEC_LOCATION) |
9572 | address = get_linespec_location (location); | |
cc80f267 | 9573 | |
f00aae0f KS |
9574 | if (!cursal.symtab |
9575 | || (address != NULL | |
9576 | && strchr ("+-", address[0]) != NULL | |
9577 | && address[1] != '[')) | |
9578 | { | |
c2f4122d | 9579 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9580 | get_last_displayed_symtab (), |
9581 | get_last_displayed_line (), | |
9582 | canonical, NULL, NULL); | |
9583 | return; | |
9584 | } | |
c906108c | 9585 | } |
f00aae0f | 9586 | |
c2f4122d | 9587 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9588 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9589 | } |
c906108c | 9590 | |
c906108c | 9591 | |
c3f6f71d | 9592 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9593 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9594 | |
b9362cc7 | 9595 | static void |
23e7acfb | 9596 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9597 | { |
9598 | int i; | |
cc59ec59 | 9599 | |
c3f6f71d | 9600 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9601 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9602 | } |
9603 | ||
7a697b8d SS |
9604 | /* Fast tracepoints may have restrictions on valid locations. For |
9605 | instance, a fast tracepoint using a jump instead of a trap will | |
9606 | likely have to overwrite more bytes than a trap would, and so can | |
9607 | only be placed where the instruction is longer than the jump, or a | |
9608 | multi-instruction sequence does not have a jump into the middle of | |
9609 | it, etc. */ | |
9610 | ||
9611 | static void | |
9612 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9613 | struct symtabs_and_lines *sals) | |
9614 | { | |
9615 | int i, rslt; | |
9616 | struct symtab_and_line *sal; | |
9617 | char *msg; | |
9618 | struct cleanup *old_chain; | |
9619 | ||
9620 | for (i = 0; i < sals->nelts; i++) | |
9621 | { | |
f8eba3c6 TT |
9622 | struct gdbarch *sarch; |
9623 | ||
7a697b8d SS |
9624 | sal = &sals->sals[i]; |
9625 | ||
f8eba3c6 TT |
9626 | sarch = get_sal_arch (*sal); |
9627 | /* We fall back to GDBARCH if there is no architecture | |
9628 | associated with SAL. */ | |
9629 | if (sarch == NULL) | |
9630 | sarch = gdbarch; | |
6b940e6a | 9631 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9632 | old_chain = make_cleanup (xfree, msg); |
9633 | ||
9634 | if (!rslt) | |
9635 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9636 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9637 | |
9638 | do_cleanups (old_chain); | |
9639 | } | |
9640 | } | |
9641 | ||
018d34a4 VP |
9642 | /* Given TOK, a string specification of condition and thread, as |
9643 | accepted by the 'break' command, extract the condition | |
9644 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9645 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9646 | If no condition is found, *COND_STRING is set to NULL. |
9647 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9648 | |
9649 | static void | |
bbc13ae3 | 9650 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9651 | char **cond_string, int *thread, int *task, |
9652 | char **rest) | |
018d34a4 VP |
9653 | { |
9654 | *cond_string = NULL; | |
9655 | *thread = -1; | |
ed1d1739 KS |
9656 | *task = 0; |
9657 | *rest = NULL; | |
9658 | ||
018d34a4 VP |
9659 | while (tok && *tok) |
9660 | { | |
bbc13ae3 | 9661 | const char *end_tok; |
018d34a4 | 9662 | int toklen; |
bbc13ae3 KS |
9663 | const char *cond_start = NULL; |
9664 | const char *cond_end = NULL; | |
cc59ec59 | 9665 | |
bbc13ae3 | 9666 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9667 | |
9668 | if ((*tok == '"' || *tok == ',') && rest) | |
9669 | { | |
9670 | *rest = savestring (tok, strlen (tok)); | |
9671 | return; | |
9672 | } | |
9673 | ||
bbc13ae3 | 9674 | end_tok = skip_to_space_const (tok); |
d634f2de | 9675 | |
018d34a4 | 9676 | toklen = end_tok - tok; |
d634f2de | 9677 | |
018d34a4 VP |
9678 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9679 | { | |
f7545552 TT |
9680 | struct expression *expr; |
9681 | ||
018d34a4 | 9682 | tok = cond_start = end_tok + 1; |
1bb9788d | 9683 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9684 | xfree (expr); |
018d34a4 | 9685 | cond_end = tok; |
d634f2de | 9686 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9687 | } |
9688 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9689 | { | |
5d5658a1 PA |
9690 | const char *tmptok; |
9691 | struct thread_info *thr; | |
d634f2de | 9692 | |
018d34a4 | 9693 | tok = end_tok + 1; |
5d5658a1 | 9694 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9695 | if (tok == tmptok) |
9696 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9697 | *thread = thr->global_num; |
bbc13ae3 | 9698 | tok = tmptok; |
018d34a4 | 9699 | } |
4a306c9a JB |
9700 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9701 | { | |
9702 | char *tmptok; | |
9703 | ||
9704 | tok = end_tok + 1; | |
bbc13ae3 | 9705 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9706 | if (tok == tmptok) |
9707 | error (_("Junk after task keyword.")); | |
9708 | if (!valid_task_id (*task)) | |
b6199126 | 9709 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9710 | tok = tmptok; |
4a306c9a | 9711 | } |
e7e0cddf SS |
9712 | else if (rest) |
9713 | { | |
9714 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9715 | return; |
e7e0cddf | 9716 | } |
018d34a4 VP |
9717 | else |
9718 | error (_("Junk at end of arguments.")); | |
9719 | } | |
9720 | } | |
9721 | ||
0fb4aa4b PA |
9722 | /* Decode a static tracepoint marker spec. */ |
9723 | ||
9724 | static struct symtabs_and_lines | |
f00aae0f | 9725 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9726 | { |
9727 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9728 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9729 | struct cleanup *old_chain; |
f00aae0f KS |
9730 | const char *p = &(*arg_p)[3]; |
9731 | const char *endp; | |
0fb4aa4b PA |
9732 | char *marker_str; |
9733 | int i; | |
9734 | ||
f00aae0f | 9735 | p = skip_spaces_const (p); |
0fb4aa4b | 9736 | |
f00aae0f | 9737 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9738 | |
9739 | marker_str = savestring (p, endp - p); | |
9740 | old_chain = make_cleanup (xfree, marker_str); | |
9741 | ||
9742 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9743 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9744 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9745 | ||
9746 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9747 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9748 | |
9749 | for (i = 0; i < sals.nelts; i++) | |
9750 | { | |
9751 | struct static_tracepoint_marker *marker; | |
9752 | ||
9753 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9754 | ||
9755 | init_sal (&sals.sals[i]); | |
9756 | ||
9757 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9758 | sals.sals[i].pc = marker->address; | |
9759 | ||
9760 | release_static_tracepoint_marker (marker); | |
9761 | } | |
9762 | ||
9763 | do_cleanups (old_chain); | |
9764 | ||
9765 | *arg_p = endp; | |
9766 | return sals; | |
9767 | } | |
9768 | ||
f00aae0f | 9769 | /* See breakpoint.h. */ |
0101ce28 | 9770 | |
8cdf0e15 VP |
9771 | int |
9772 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9773 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9774 | int thread, char *extra_string, |
f00aae0f | 9775 | int parse_extra, |
0fb4aa4b | 9776 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9777 | int ignore_count, |
9778 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9779 | const struct breakpoint_ops *ops, |
44f238bb PA |
9780 | int from_tty, int enabled, int internal, |
9781 | unsigned flags) | |
c3f6f71d | 9782 | { |
7efd8fc2 | 9783 | struct linespec_result canonical; |
c3f6f71d | 9784 | struct cleanup *old_chain; |
80c99de1 | 9785 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9786 | int pending = 0; |
4a306c9a | 9787 | int task = 0; |
86b17b60 | 9788 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9789 | |
348d480f PA |
9790 | gdb_assert (ops != NULL); |
9791 | ||
f00aae0f KS |
9792 | /* If extra_string isn't useful, set it to NULL. */ |
9793 | if (extra_string != NULL && *extra_string == '\0') | |
9794 | extra_string = NULL; | |
9795 | ||
7efd8fc2 | 9796 | init_linespec_result (&canonical); |
c3f6f71d | 9797 | |
492d29ea | 9798 | TRY |
b78a6381 | 9799 | { |
f00aae0f | 9800 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9801 | } |
492d29ea | 9802 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9803 | { |
492d29ea PA |
9804 | /* If caller is interested in rc value from parse, set |
9805 | value. */ | |
9806 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9807 | { |
05ff989b AC |
9808 | /* If pending breakpoint support is turned off, throw |
9809 | error. */ | |
fa8d40ab JJ |
9810 | |
9811 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9812 | throw_exception (e); |
9813 | ||
9814 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9815 | |
05ff989b AC |
9816 | /* If pending breakpoint support is auto query and the user |
9817 | selects no, then simply return the error code. */ | |
059fb39f | 9818 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9819 | && !nquery (_("Make %s pending on future shared library load? "), |
9820 | bptype_string (type_wanted))) | |
fd9b8c24 | 9821 | return 0; |
fa8d40ab | 9822 | |
05ff989b AC |
9823 | /* At this point, either the user was queried about setting |
9824 | a pending breakpoint and selected yes, or pending | |
9825 | breakpoint behavior is on and thus a pending breakpoint | |
9826 | is defaulted on behalf of the user. */ | |
f00aae0f | 9827 | pending = 1; |
0101ce28 | 9828 | } |
492d29ea PA |
9829 | else |
9830 | throw_exception (e); | |
0101ce28 | 9831 | } |
492d29ea PA |
9832 | END_CATCH |
9833 | ||
f00aae0f | 9834 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9835 | return 0; |
c3f6f71d | 9836 | |
4a64f543 | 9837 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9838 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9839 | |
c3f6f71d JM |
9840 | /* ----------------------------- SNIP ----------------------------- |
9841 | Anything added to the cleanup chain beyond this point is assumed | |
9842 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9843 | then the memory is not reclaimed. */ |
9844 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9845 | |
c3f6f71d JM |
9846 | /* Resolve all line numbers to PC's and verify that the addresses |
9847 | are ok for the target. */ | |
0101ce28 | 9848 | if (!pending) |
f8eba3c6 TT |
9849 | { |
9850 | int ix; | |
9851 | struct linespec_sals *iter; | |
9852 | ||
9853 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9854 | breakpoint_sals_to_pc (&iter->sals); | |
9855 | } | |
c3f6f71d | 9856 | |
7a697b8d | 9857 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9858 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9859 | { |
9860 | int ix; | |
9861 | struct linespec_sals *iter; | |
9862 | ||
9863 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9864 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9865 | } | |
7a697b8d | 9866 | |
c3f6f71d JM |
9867 | /* Verify that condition can be parsed, before setting any |
9868 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9869 | breakpoint. */ |
0101ce28 | 9870 | if (!pending) |
c3f6f71d | 9871 | { |
f00aae0f | 9872 | if (parse_extra) |
72b2ff0e | 9873 | { |
0878d0fa | 9874 | char *rest; |
52d361e1 YQ |
9875 | struct linespec_sals *lsal; |
9876 | ||
9877 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9878 | ||
0878d0fa YQ |
9879 | /* Here we only parse 'arg' to separate condition |
9880 | from thread number, so parsing in context of first | |
9881 | sal is OK. When setting the breakpoint we'll | |
9882 | re-parse it in context of each sal. */ | |
9883 | ||
f00aae0f KS |
9884 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9885 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9886 | if (cond_string) |
9887 | make_cleanup (xfree, cond_string); | |
9888 | if (rest) | |
9889 | make_cleanup (xfree, rest); | |
9890 | if (rest) | |
9891 | extra_string = rest; | |
f00aae0f KS |
9892 | else |
9893 | extra_string = NULL; | |
72b2ff0e | 9894 | } |
2f069f6f | 9895 | else |
72b2ff0e | 9896 | { |
f00aae0f KS |
9897 | if (type_wanted != bp_dprintf |
9898 | && extra_string != NULL && *extra_string != '\0') | |
9899 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9900 | |
9901 | /* Create a private copy of condition string. */ | |
9902 | if (cond_string) | |
9903 | { | |
9904 | cond_string = xstrdup (cond_string); | |
9905 | make_cleanup (xfree, cond_string); | |
9906 | } | |
9907 | /* Create a private copy of any extra string. */ | |
9908 | if (extra_string) | |
9909 | { | |
9910 | extra_string = xstrdup (extra_string); | |
9911 | make_cleanup (xfree, extra_string); | |
9912 | } | |
72b2ff0e | 9913 | } |
0fb4aa4b | 9914 | |
52d361e1 | 9915 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9916 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9917 | tempflag ? disp_del : disp_donttouch, |
9918 | thread, task, ignore_count, ops, | |
44f238bb | 9919 | from_tty, enabled, internal, flags); |
c906108c | 9920 | } |
0101ce28 JJ |
9921 | else |
9922 | { | |
0101ce28 JJ |
9923 | struct breakpoint *b; |
9924 | ||
bfccc43c YQ |
9925 | if (is_tracepoint_type (type_wanted)) |
9926 | { | |
9927 | struct tracepoint *t; | |
9928 | ||
9929 | t = XCNEW (struct tracepoint); | |
9930 | b = &t->base; | |
9931 | } | |
9932 | else | |
9933 | b = XNEW (struct breakpoint); | |
9934 | ||
9935 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
f00aae0f | 9936 | b->location = copy_event_location (location); |
bfccc43c | 9937 | |
f00aae0f KS |
9938 | if (parse_extra) |
9939 | b->cond_string = NULL; | |
e12c7713 MK |
9940 | else |
9941 | { | |
9942 | /* Create a private copy of condition string. */ | |
9943 | if (cond_string) | |
9944 | { | |
9945 | cond_string = xstrdup (cond_string); | |
9946 | make_cleanup (xfree, cond_string); | |
9947 | } | |
9948 | b->cond_string = cond_string; | |
15630549 | 9949 | b->thread = thread; |
e12c7713 | 9950 | } |
f00aae0f KS |
9951 | |
9952 | /* Create a private copy of any extra string. */ | |
9953 | if (extra_string != NULL) | |
9954 | { | |
9955 | extra_string = xstrdup (extra_string); | |
9956 | make_cleanup (xfree, extra_string); | |
9957 | } | |
9958 | b->extra_string = extra_string; | |
0101ce28 | 9959 | b->ignore_count = ignore_count; |
0101ce28 | 9960 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9961 | b->condition_not_parsed = 1; |
41447f92 | 9962 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9963 | if ((type_wanted != bp_breakpoint |
9964 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9965 | b->pspace = current_program_space; |
8bea4e01 | 9966 | |
bfccc43c | 9967 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9968 | } |
9969 | ||
f8eba3c6 | 9970 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9971 | { |
3e43a32a MS |
9972 | warning (_("Multiple breakpoints were set.\nUse the " |
9973 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9974 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9975 | } |
9976 | ||
80c99de1 PA |
9977 | /* That's it. Discard the cleanups for data inserted into the |
9978 | breakpoint. */ | |
9979 | discard_cleanups (bkpt_chain); | |
9980 | /* But cleanup everything else. */ | |
c3f6f71d | 9981 | do_cleanups (old_chain); |
217dc9e2 | 9982 | |
80c99de1 | 9983 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9984 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9985 | |
9986 | return 1; | |
c3f6f71d | 9987 | } |
c906108c | 9988 | |
348d480f | 9989 | /* Set a breakpoint. |
72b2ff0e VP |
9990 | ARG is a string describing breakpoint address, |
9991 | condition, and thread. | |
9992 | FLAG specifies if a breakpoint is hardware on, | |
9993 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9994 | and BP_TEMPFLAG. */ | |
348d480f | 9995 | |
98deb0da | 9996 | static void |
72b2ff0e | 9997 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9998 | { |
72b2ff0e | 9999 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
10000 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
10001 | ? bp_hardware_breakpoint | |
10002 | : bp_breakpoint); | |
55aa24fb | 10003 | struct breakpoint_ops *ops; |
f00aae0f KS |
10004 | struct event_location *location; |
10005 | struct cleanup *cleanup; | |
10006 | ||
10007 | location = string_to_event_location (&arg, current_language); | |
10008 | cleanup = make_cleanup_delete_event_location (location); | |
55aa24fb SDJ |
10009 | |
10010 | /* Matching breakpoints on probes. */ | |
5b56227b KS |
10011 | if (location != NULL |
10012 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
10013 | ops = &bkpt_probe_breakpoint_ops; |
10014 | else | |
10015 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 10016 | |
8cdf0e15 | 10017 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10018 | location, |
10019 | NULL, 0, arg, 1 /* parse arg */, | |
0fb4aa4b | 10020 | tempflag, type_wanted, |
8cdf0e15 VP |
10021 | 0 /* Ignore count */, |
10022 | pending_break_support, | |
55aa24fb | 10023 | ops, |
8cdf0e15 | 10024 | from_tty, |
84f4c1fe | 10025 | 1 /* enabled */, |
44f238bb PA |
10026 | 0 /* internal */, |
10027 | 0); | |
f00aae0f | 10028 | do_cleanups (cleanup); |
c906108c SS |
10029 | } |
10030 | ||
c906108c SS |
10031 | /* Helper function for break_command_1 and disassemble_command. */ |
10032 | ||
10033 | void | |
fba45db2 | 10034 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10035 | { |
10036 | CORE_ADDR pc; | |
10037 | ||
10038 | if (sal->pc == 0 && sal->symtab != NULL) | |
10039 | { | |
10040 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10041 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10042 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10043 | sal->pc = pc; |
6a048695 | 10044 | |
4a64f543 MS |
10045 | /* If this SAL corresponds to a breakpoint inserted using a line |
10046 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10047 | if (sal->explicit_line) |
059acae7 | 10048 | skip_prologue_sal (sal); |
c906108c SS |
10049 | } |
10050 | ||
10051 | if (sal->section == 0 && sal->symtab != NULL) | |
10052 | { | |
346d1dfe | 10053 | const struct blockvector *bv; |
3977b71f | 10054 | const struct block *b; |
c5aa993b | 10055 | struct symbol *sym; |
c906108c | 10056 | |
43f3e411 DE |
10057 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10058 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10059 | if (bv != NULL) |
10060 | { | |
7f0df278 | 10061 | sym = block_linkage_function (b); |
c906108c SS |
10062 | if (sym != NULL) |
10063 | { | |
eb822aa6 DE |
10064 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10065 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10066 | sym); | |
c906108c SS |
10067 | } |
10068 | else | |
10069 | { | |
4a64f543 MS |
10070 | /* It really is worthwhile to have the section, so we'll |
10071 | just have to look harder. This case can be executed | |
10072 | if we have line numbers but no functions (as can | |
10073 | happen in assembly source). */ | |
c906108c | 10074 | |
7cbd4a93 | 10075 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10076 | struct cleanup *old_chain = save_current_space_and_thread (); |
10077 | ||
10078 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10079 | |
10080 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10081 | if (msym.minsym) |
efd66ac6 | 10082 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10083 | |
10084 | do_cleanups (old_chain); | |
c906108c SS |
10085 | } |
10086 | } | |
10087 | } | |
10088 | } | |
10089 | ||
10090 | void | |
fba45db2 | 10091 | break_command (char *arg, int from_tty) |
c906108c | 10092 | { |
db107f19 | 10093 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10094 | } |
10095 | ||
c906108c | 10096 | void |
fba45db2 | 10097 | tbreak_command (char *arg, int from_tty) |
c906108c | 10098 | { |
db107f19 | 10099 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10100 | } |
10101 | ||
c906108c | 10102 | static void |
fba45db2 | 10103 | hbreak_command (char *arg, int from_tty) |
c906108c | 10104 | { |
db107f19 | 10105 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10106 | } |
10107 | ||
10108 | static void | |
fba45db2 | 10109 | thbreak_command (char *arg, int from_tty) |
c906108c | 10110 | { |
db107f19 | 10111 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10112 | } |
10113 | ||
10114 | static void | |
fba45db2 | 10115 | stop_command (char *arg, int from_tty) |
c906108c | 10116 | { |
a3f17187 | 10117 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10118 | Usage: stop in <function | address>\n\ |
a3f17187 | 10119 | stop at <line>\n")); |
c906108c SS |
10120 | } |
10121 | ||
10122 | static void | |
fba45db2 | 10123 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10124 | { |
10125 | int badInput = 0; | |
10126 | ||
c5aa993b | 10127 | if (arg == (char *) NULL) |
c906108c SS |
10128 | badInput = 1; |
10129 | else if (*arg != '*') | |
10130 | { | |
10131 | char *argptr = arg; | |
10132 | int hasColon = 0; | |
10133 | ||
4a64f543 | 10134 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10135 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10136 | function/method name. */ |
c906108c | 10137 | while (*argptr && !hasColon) |
c5aa993b JM |
10138 | { |
10139 | hasColon = (*argptr == ':'); | |
10140 | argptr++; | |
10141 | } | |
c906108c SS |
10142 | |
10143 | if (hasColon) | |
c5aa993b | 10144 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10145 | else |
c5aa993b | 10146 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10147 | } |
10148 | ||
10149 | if (badInput) | |
a3f17187 | 10150 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10151 | else |
db107f19 | 10152 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10153 | } |
10154 | ||
10155 | static void | |
fba45db2 | 10156 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10157 | { |
10158 | int badInput = 0; | |
10159 | ||
c5aa993b | 10160 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10161 | badInput = 1; |
10162 | else | |
10163 | { | |
10164 | char *argptr = arg; | |
10165 | int hasColon = 0; | |
10166 | ||
4a64f543 MS |
10167 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10168 | it is probably a line number. */ | |
c906108c | 10169 | while (*argptr && !hasColon) |
c5aa993b JM |
10170 | { |
10171 | hasColon = (*argptr == ':'); | |
10172 | argptr++; | |
10173 | } | |
c906108c SS |
10174 | |
10175 | if (hasColon) | |
c5aa993b | 10176 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10177 | else |
c5aa993b | 10178 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10179 | } |
10180 | ||
10181 | if (badInput) | |
a3f17187 | 10182 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10183 | else |
db107f19 | 10184 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10185 | } |
10186 | ||
e7e0cddf SS |
10187 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10188 | with a prewired command list consisting of a single output command, | |
10189 | built from extra arguments supplied on the dprintf command | |
10190 | line. */ | |
10191 | ||
da821c7b | 10192 | static void |
e7e0cddf SS |
10193 | dprintf_command (char *arg, int from_tty) |
10194 | { | |
f00aae0f KS |
10195 | struct event_location *location; |
10196 | struct cleanup *cleanup; | |
10197 | ||
10198 | location = string_to_event_location (&arg, current_language); | |
10199 | cleanup = make_cleanup_delete_event_location (location); | |
10200 | ||
10201 | /* If non-NULL, ARG should have been advanced past the location; | |
10202 | the next character must be ','. */ | |
10203 | if (arg != NULL) | |
10204 | { | |
10205 | if (arg[0] != ',' || arg[1] == '\0') | |
10206 | error (_("Format string required")); | |
10207 | else | |
10208 | { | |
10209 | /* Skip the comma. */ | |
10210 | ++arg; | |
10211 | } | |
10212 | } | |
10213 | ||
e7e0cddf | 10214 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10215 | location, |
10216 | NULL, 0, arg, 1 /* parse arg */, | |
e7e0cddf SS |
10217 | 0, bp_dprintf, |
10218 | 0 /* Ignore count */, | |
10219 | pending_break_support, | |
10220 | &dprintf_breakpoint_ops, | |
10221 | from_tty, | |
10222 | 1 /* enabled */, | |
10223 | 0 /* internal */, | |
10224 | 0); | |
f00aae0f | 10225 | do_cleanups (cleanup); |
e7e0cddf SS |
10226 | } |
10227 | ||
d3ce09f5 SS |
10228 | static void |
10229 | agent_printf_command (char *arg, int from_tty) | |
10230 | { | |
10231 | error (_("May only run agent-printf on the target")); | |
10232 | } | |
10233 | ||
f1310107 TJB |
10234 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10235 | ranged breakpoints. */ | |
10236 | ||
10237 | static int | |
10238 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10239 | struct address_space *aspace, | |
09ac7c10 TT |
10240 | CORE_ADDR bp_addr, |
10241 | const struct target_waitstatus *ws) | |
f1310107 | 10242 | { |
09ac7c10 | 10243 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10244 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10245 | return 0; |
10246 | ||
f1310107 TJB |
10247 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10248 | bl->length, aspace, bp_addr); | |
10249 | } | |
10250 | ||
10251 | /* Implement the "resources_needed" breakpoint_ops method for | |
10252 | ranged breakpoints. */ | |
10253 | ||
10254 | static int | |
10255 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10256 | { | |
10257 | return target_ranged_break_num_registers (); | |
10258 | } | |
10259 | ||
10260 | /* Implement the "print_it" breakpoint_ops method for | |
10261 | ranged breakpoints. */ | |
10262 | ||
10263 | static enum print_stop_action | |
348d480f | 10264 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10265 | { |
348d480f | 10266 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10267 | struct bp_location *bl = b->loc; |
79a45e25 | 10268 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10269 | |
10270 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10271 | ||
10272 | /* Ranged breakpoints have only one location. */ | |
10273 | gdb_assert (bl && bl->next == NULL); | |
10274 | ||
10275 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10276 | |
10277 | maybe_print_thread_hit_breakpoint (uiout); | |
10278 | ||
f1310107 | 10279 | if (b->disposition == disp_del) |
f303dbd6 | 10280 | ui_out_text (uiout, "Temporary ranged breakpoint "); |
f1310107 | 10281 | else |
f303dbd6 | 10282 | ui_out_text (uiout, "Ranged breakpoint "); |
f1310107 TJB |
10283 | if (ui_out_is_mi_like_p (uiout)) |
10284 | { | |
10285 | ui_out_field_string (uiout, "reason", | |
10286 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10287 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10288 | } | |
10289 | ui_out_field_int (uiout, "bkptno", b->number); | |
10290 | ui_out_text (uiout, ", "); | |
10291 | ||
10292 | return PRINT_SRC_AND_LOC; | |
10293 | } | |
10294 | ||
10295 | /* Implement the "print_one" breakpoint_ops method for | |
10296 | ranged breakpoints. */ | |
10297 | ||
10298 | static void | |
10299 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10300 | struct bp_location **last_loc) | |
10301 | { | |
10302 | struct bp_location *bl = b->loc; | |
10303 | struct value_print_options opts; | |
79a45e25 | 10304 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10305 | |
10306 | /* Ranged breakpoints have only one location. */ | |
10307 | gdb_assert (bl && bl->next == NULL); | |
10308 | ||
10309 | get_user_print_options (&opts); | |
10310 | ||
10311 | if (opts.addressprint) | |
10312 | /* We don't print the address range here, it will be printed later | |
10313 | by print_one_detail_ranged_breakpoint. */ | |
10314 | ui_out_field_skip (uiout, "addr"); | |
10315 | annotate_field (5); | |
10316 | print_breakpoint_location (b, bl); | |
10317 | *last_loc = bl; | |
10318 | } | |
10319 | ||
10320 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10321 | ranged breakpoints. */ | |
10322 | ||
10323 | static void | |
10324 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10325 | struct ui_out *uiout) | |
10326 | { | |
10327 | CORE_ADDR address_start, address_end; | |
10328 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10329 | struct ui_file *stb = mem_fileopen (); |
10330 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10331 | |
10332 | gdb_assert (bl); | |
10333 | ||
10334 | address_start = bl->address; | |
10335 | address_end = address_start + bl->length - 1; | |
10336 | ||
10337 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10338 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10339 | print_core_address (bl->gdbarch, address_start), |
10340 | print_core_address (bl->gdbarch, address_end)); | |
10341 | ui_out_field_stream (uiout, "addr", stb); | |
10342 | ui_out_text (uiout, "\n"); | |
10343 | ||
10344 | do_cleanups (cleanup); | |
10345 | } | |
10346 | ||
10347 | /* Implement the "print_mention" breakpoint_ops method for | |
10348 | ranged breakpoints. */ | |
10349 | ||
10350 | static void | |
10351 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10352 | { | |
10353 | struct bp_location *bl = b->loc; | |
79a45e25 | 10354 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10355 | |
10356 | gdb_assert (bl); | |
10357 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10358 | ||
10359 | if (ui_out_is_mi_like_p (uiout)) | |
10360 | return; | |
10361 | ||
10362 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10363 | b->number, paddress (bl->gdbarch, bl->address), | |
10364 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10365 | } | |
10366 | ||
10367 | /* Implement the "print_recreate" breakpoint_ops method for | |
10368 | ranged breakpoints. */ | |
10369 | ||
10370 | static void | |
10371 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10372 | { | |
f00aae0f KS |
10373 | fprintf_unfiltered (fp, "break-range %s, %s", |
10374 | event_location_to_string (b->location), | |
10375 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10376 | print_recreate_thread (b, fp); |
f1310107 TJB |
10377 | } |
10378 | ||
10379 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10380 | ||
2060206e | 10381 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10382 | |
10383 | /* Find the address where the end of the breakpoint range should be | |
10384 | placed, given the SAL of the end of the range. This is so that if | |
10385 | the user provides a line number, the end of the range is set to the | |
10386 | last instruction of the given line. */ | |
10387 | ||
10388 | static CORE_ADDR | |
10389 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10390 | { | |
10391 | CORE_ADDR end; | |
10392 | ||
10393 | /* If the user provided a PC value, use it. Otherwise, | |
10394 | find the address of the end of the given location. */ | |
10395 | if (sal.explicit_pc) | |
10396 | end = sal.pc; | |
10397 | else | |
10398 | { | |
10399 | int ret; | |
10400 | CORE_ADDR start; | |
10401 | ||
10402 | ret = find_line_pc_range (sal, &start, &end); | |
10403 | if (!ret) | |
10404 | error (_("Could not find location of the end of the range.")); | |
10405 | ||
10406 | /* find_line_pc_range returns the start of the next line. */ | |
10407 | end--; | |
10408 | } | |
10409 | ||
10410 | return end; | |
10411 | } | |
10412 | ||
10413 | /* Implement the "break-range" CLI command. */ | |
10414 | ||
10415 | static void | |
10416 | break_range_command (char *arg, int from_tty) | |
10417 | { | |
870f88f7 | 10418 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10419 | struct linespec_result canonical_start, canonical_end; |
10420 | int bp_count, can_use_bp, length; | |
10421 | CORE_ADDR end; | |
10422 | struct breakpoint *b; | |
10423 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10424 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10425 | struct linespec_sals *lsal_start, *lsal_end; |
f00aae0f | 10426 | struct event_location *start_location, *end_location; |
f1310107 TJB |
10427 | |
10428 | /* We don't support software ranged breakpoints. */ | |
10429 | if (target_ranged_break_num_registers () < 0) | |
10430 | error (_("This target does not support hardware ranged breakpoints.")); | |
10431 | ||
10432 | bp_count = hw_breakpoint_used_count (); | |
10433 | bp_count += target_ranged_break_num_registers (); | |
10434 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10435 | bp_count, 0); | |
10436 | if (can_use_bp < 0) | |
10437 | error (_("Hardware breakpoints used exceeds limit.")); | |
10438 | ||
f8eba3c6 | 10439 | arg = skip_spaces (arg); |
f1310107 TJB |
10440 | if (arg == NULL || arg[0] == '\0') |
10441 | error(_("No address range specified.")); | |
10442 | ||
f1310107 TJB |
10443 | init_linespec_result (&canonical_start); |
10444 | ||
f8eba3c6 | 10445 | arg_start = arg; |
f00aae0f KS |
10446 | start_location = string_to_event_location (&arg, current_language); |
10447 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); | |
10448 | parse_breakpoint_sals (start_location, &canonical_start); | |
10449 | make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10450 | |
10451 | if (arg[0] != ',') | |
10452 | error (_("Too few arguments.")); | |
f8eba3c6 | 10453 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10454 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10455 | |
10456 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10457 | ||
10458 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10459 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10460 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10461 | ||
f8eba3c6 TT |
10462 | sal_start = lsal_start->sals.sals[0]; |
10463 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10464 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10465 | |
10466 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10467 | arg = skip_spaces (arg); |
f1310107 TJB |
10468 | |
10469 | /* Parse the end location. */ | |
10470 | ||
f1310107 TJB |
10471 | init_linespec_result (&canonical_end); |
10472 | arg_start = arg; | |
10473 | ||
f8eba3c6 | 10474 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10475 | parse_breakpoint_sals because we need to specify the start location's |
10476 | symtab and line as the default symtab and line for the end of the | |
10477 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10478 | where +14 means 14 lines from the start location. */ | |
f00aae0f KS |
10479 | end_location = string_to_event_location (&arg, current_language); |
10480 | make_cleanup_delete_event_location (end_location); | |
c2f4122d | 10481 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f8eba3c6 TT |
10482 | sal_start.symtab, sal_start.line, |
10483 | &canonical_end, NULL, NULL); | |
10484 | ||
10485 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10486 | |
f8eba3c6 | 10487 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10488 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10489 | |
10490 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10491 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10492 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10493 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10494 | ||
f8eba3c6 | 10495 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10496 | |
10497 | end = find_breakpoint_range_end (sal_end); | |
10498 | if (sal_start.pc > end) | |
177b42fe | 10499 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10500 | |
10501 | length = end - sal_start.pc + 1; | |
10502 | if (length < 0) | |
10503 | /* Length overflowed. */ | |
10504 | error (_("Address range too large.")); | |
10505 | else if (length == 1) | |
10506 | { | |
10507 | /* This range is simple enough to be handled by | |
10508 | the `hbreak' command. */ | |
10509 | hbreak_command (addr_string_start, 1); | |
10510 | ||
10511 | do_cleanups (cleanup_bkpt); | |
10512 | ||
10513 | return; | |
10514 | } | |
10515 | ||
10516 | /* Now set up the breakpoint. */ | |
10517 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10518 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10519 | set_breakpoint_count (breakpoint_count + 1); |
10520 | b->number = breakpoint_count; | |
10521 | b->disposition = disp_donttouch; | |
f00aae0f KS |
10522 | b->location = copy_event_location (start_location); |
10523 | b->location_range_end = copy_event_location (end_location); | |
f1310107 TJB |
10524 | b->loc->length = length; |
10525 | ||
f8eba3c6 | 10526 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10527 | |
10528 | mention (b); | |
8d3788bd | 10529 | observer_notify_breakpoint_created (b); |
44702360 | 10530 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10531 | } |
10532 | ||
4a64f543 MS |
10533 | /* Return non-zero if EXP is verified as constant. Returned zero |
10534 | means EXP is variable. Also the constant detection may fail for | |
10535 | some constant expressions and in such case still falsely return | |
10536 | zero. */ | |
2e6e3d9c | 10537 | |
65d79d4b SDJ |
10538 | static int |
10539 | watchpoint_exp_is_const (const struct expression *exp) | |
10540 | { | |
10541 | int i = exp->nelts; | |
10542 | ||
10543 | while (i > 0) | |
10544 | { | |
10545 | int oplenp, argsp; | |
10546 | ||
10547 | /* We are only interested in the descriptor of each element. */ | |
10548 | operator_length (exp, i, &oplenp, &argsp); | |
10549 | i -= oplenp; | |
10550 | ||
10551 | switch (exp->elts[i].opcode) | |
10552 | { | |
10553 | case BINOP_ADD: | |
10554 | case BINOP_SUB: | |
10555 | case BINOP_MUL: | |
10556 | case BINOP_DIV: | |
10557 | case BINOP_REM: | |
10558 | case BINOP_MOD: | |
10559 | case BINOP_LSH: | |
10560 | case BINOP_RSH: | |
10561 | case BINOP_LOGICAL_AND: | |
10562 | case BINOP_LOGICAL_OR: | |
10563 | case BINOP_BITWISE_AND: | |
10564 | case BINOP_BITWISE_IOR: | |
10565 | case BINOP_BITWISE_XOR: | |
10566 | case BINOP_EQUAL: | |
10567 | case BINOP_NOTEQUAL: | |
10568 | case BINOP_LESS: | |
10569 | case BINOP_GTR: | |
10570 | case BINOP_LEQ: | |
10571 | case BINOP_GEQ: | |
10572 | case BINOP_REPEAT: | |
10573 | case BINOP_COMMA: | |
10574 | case BINOP_EXP: | |
10575 | case BINOP_MIN: | |
10576 | case BINOP_MAX: | |
10577 | case BINOP_INTDIV: | |
10578 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10579 | case TERNOP_COND: |
10580 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10581 | |
10582 | case OP_LONG: | |
10583 | case OP_DOUBLE: | |
10584 | case OP_DECFLOAT: | |
10585 | case OP_LAST: | |
10586 | case OP_COMPLEX: | |
10587 | case OP_STRING: | |
65d79d4b SDJ |
10588 | case OP_ARRAY: |
10589 | case OP_TYPE: | |
608b4967 TT |
10590 | case OP_TYPEOF: |
10591 | case OP_DECLTYPE: | |
6e72ca20 | 10592 | case OP_TYPEID: |
65d79d4b SDJ |
10593 | case OP_NAME: |
10594 | case OP_OBJC_NSSTRING: | |
10595 | ||
10596 | case UNOP_NEG: | |
10597 | case UNOP_LOGICAL_NOT: | |
10598 | case UNOP_COMPLEMENT: | |
10599 | case UNOP_ADDR: | |
10600 | case UNOP_HIGH: | |
aeaa2474 | 10601 | case UNOP_CAST: |
9eaf6705 TT |
10602 | |
10603 | case UNOP_CAST_TYPE: | |
10604 | case UNOP_REINTERPRET_CAST: | |
10605 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10606 | /* Unary, binary and ternary operators: We have to check |
10607 | their operands. If they are constant, then so is the | |
10608 | result of that operation. For instance, if A and B are | |
10609 | determined to be constants, then so is "A + B". | |
10610 | ||
10611 | UNOP_IND is one exception to the rule above, because the | |
10612 | value of *ADDR is not necessarily a constant, even when | |
10613 | ADDR is. */ | |
65d79d4b SDJ |
10614 | break; |
10615 | ||
10616 | case OP_VAR_VALUE: | |
10617 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10618 | |
65d79d4b | 10619 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10620 | possible that a buggy compiler could mark a variable as |
10621 | constant even when it is not, and TYPE_CONST would return | |
10622 | true in this case, while SYMBOL_CLASS wouldn't. | |
10623 | ||
10624 | We also have to check for function symbols because they | |
10625 | are always constant. */ | |
65d79d4b SDJ |
10626 | { |
10627 | struct symbol *s = exp->elts[i + 2].symbol; | |
10628 | ||
10629 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10630 | && SYMBOL_CLASS (s) != LOC_CONST | |
10631 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10632 | return 0; | |
10633 | break; | |
10634 | } | |
10635 | ||
10636 | /* The default action is to return 0 because we are using | |
10637 | the optimistic approach here: If we don't know something, | |
10638 | then it is not a constant. */ | |
10639 | default: | |
10640 | return 0; | |
10641 | } | |
10642 | } | |
10643 | ||
10644 | return 1; | |
10645 | } | |
10646 | ||
3a5c3e22 PA |
10647 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10648 | ||
10649 | static void | |
10650 | dtor_watchpoint (struct breakpoint *self) | |
10651 | { | |
10652 | struct watchpoint *w = (struct watchpoint *) self; | |
10653 | ||
10654 | xfree (w->cond_exp); | |
10655 | xfree (w->exp); | |
10656 | xfree (w->exp_string); | |
10657 | xfree (w->exp_string_reparse); | |
10658 | value_free (w->val); | |
10659 | ||
10660 | base_breakpoint_ops.dtor (self); | |
10661 | } | |
10662 | ||
348d480f PA |
10663 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10664 | ||
10665 | static void | |
10666 | re_set_watchpoint (struct breakpoint *b) | |
10667 | { | |
3a5c3e22 PA |
10668 | struct watchpoint *w = (struct watchpoint *) b; |
10669 | ||
348d480f PA |
10670 | /* Watchpoint can be either on expression using entirely global |
10671 | variables, or it can be on local variables. | |
10672 | ||
10673 | Watchpoints of the first kind are never auto-deleted, and even | |
10674 | persist across program restarts. Since they can use variables | |
10675 | from shared libraries, we need to reparse expression as libraries | |
10676 | are loaded and unloaded. | |
10677 | ||
10678 | Watchpoints on local variables can also change meaning as result | |
10679 | of solib event. For example, if a watchpoint uses both a local | |
10680 | and a global variables in expression, it's a local watchpoint, | |
10681 | but unloading of a shared library will make the expression | |
10682 | invalid. This is not a very common use case, but we still | |
10683 | re-evaluate expression, to avoid surprises to the user. | |
10684 | ||
10685 | Note that for local watchpoints, we re-evaluate it only if | |
10686 | watchpoints frame id is still valid. If it's not, it means the | |
10687 | watchpoint is out of scope and will be deleted soon. In fact, | |
10688 | I'm not sure we'll ever be called in this case. | |
10689 | ||
10690 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10691 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10692 | |
3a5c3e22 PA |
10693 | Don't do anything about disabled watchpoints, since they will be |
10694 | reevaluated again when enabled. */ | |
10695 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10696 | } |
10697 | ||
77b06cd7 TJB |
10698 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10699 | ||
10700 | static int | |
10701 | insert_watchpoint (struct bp_location *bl) | |
10702 | { | |
3a5c3e22 PA |
10703 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10704 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10705 | |
10706 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10707 | w->cond_exp); |
77b06cd7 TJB |
10708 | } |
10709 | ||
10710 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10711 | ||
10712 | static int | |
73971819 | 10713 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10714 | { |
3a5c3e22 PA |
10715 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10716 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10717 | |
10718 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10719 | w->cond_exp); |
e09342b5 TJB |
10720 | } |
10721 | ||
e09342b5 | 10722 | static int |
348d480f | 10723 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10724 | struct address_space *aspace, CORE_ADDR bp_addr, |
10725 | const struct target_waitstatus *ws) | |
e09342b5 | 10726 | { |
348d480f | 10727 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10728 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10729 | |
348d480f PA |
10730 | /* Continuable hardware watchpoints are treated as non-existent if the |
10731 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10732 | some data address). Otherwise gdb won't stop on a break instruction | |
10733 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10734 | been defined. Also skip watchpoints which we know did not trigger | |
10735 | (did not match the data address). */ | |
10736 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10737 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10738 | return 0; |
9c06b0b4 | 10739 | |
348d480f | 10740 | return 1; |
9c06b0b4 TJB |
10741 | } |
10742 | ||
348d480f PA |
10743 | static void |
10744 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10745 | { |
348d480f | 10746 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10747 | |
348d480f | 10748 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10749 | } |
10750 | ||
10751 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10752 | hardware watchpoints. */ |
9c06b0b4 TJB |
10753 | |
10754 | static int | |
348d480f | 10755 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10756 | { |
3a5c3e22 PA |
10757 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10758 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10759 | |
10760 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10761 | } |
10762 | ||
10763 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10764 | hardware watchpoints. */ |
9c06b0b4 TJB |
10765 | |
10766 | static int | |
348d480f | 10767 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10768 | { |
efa80663 PA |
10769 | /* Read and access watchpoints only work with hardware support. */ |
10770 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10771 | } |
10772 | ||
9c06b0b4 | 10773 | static enum print_stop_action |
348d480f | 10774 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10775 | { |
348d480f PA |
10776 | struct cleanup *old_chain; |
10777 | struct breakpoint *b; | |
f99d8bf4 | 10778 | struct ui_file *stb; |
348d480f | 10779 | enum print_stop_action result; |
3a5c3e22 | 10780 | struct watchpoint *w; |
79a45e25 | 10781 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10782 | |
10783 | gdb_assert (bs->bp_location_at != NULL); | |
10784 | ||
348d480f | 10785 | b = bs->breakpoint_at; |
3a5c3e22 | 10786 | w = (struct watchpoint *) b; |
348d480f | 10787 | |
f99d8bf4 PA |
10788 | stb = mem_fileopen (); |
10789 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 | 10790 | |
f303dbd6 PA |
10791 | annotate_watchpoint (b->number); |
10792 | maybe_print_thread_hit_breakpoint (uiout); | |
10793 | ||
9c06b0b4 TJB |
10794 | switch (b->type) |
10795 | { | |
348d480f | 10796 | case bp_watchpoint: |
9c06b0b4 | 10797 | case bp_hardware_watchpoint: |
9c06b0b4 TJB |
10798 | if (ui_out_is_mi_like_p (uiout)) |
10799 | ui_out_field_string | |
10800 | (uiout, "reason", | |
10801 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10802 | mention (b); |
10803 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10804 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10805 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10806 | ui_out_field_stream (uiout, "old", stb); |
10807 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10808 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10809 | ui_out_field_stream (uiout, "new", stb); |
10810 | ui_out_text (uiout, "\n"); | |
10811 | /* More than one watchpoint may have been triggered. */ | |
10812 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10813 | break; |
10814 | ||
10815 | case bp_read_watchpoint: | |
10816 | if (ui_out_is_mi_like_p (uiout)) | |
10817 | ui_out_field_string | |
10818 | (uiout, "reason", | |
10819 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10820 | mention (b); |
10821 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10822 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10823 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10824 | ui_out_field_stream (uiout, "value", stb); |
10825 | ui_out_text (uiout, "\n"); | |
10826 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10827 | break; |
10828 | ||
10829 | case bp_access_watchpoint: | |
348d480f PA |
10830 | if (bs->old_val != NULL) |
10831 | { | |
348d480f PA |
10832 | if (ui_out_is_mi_like_p (uiout)) |
10833 | ui_out_field_string | |
10834 | (uiout, "reason", | |
10835 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10836 | mention (b); | |
10837 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10838 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10839 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10840 | ui_out_field_stream (uiout, "old", stb); |
10841 | ui_out_text (uiout, "\nNew value = "); | |
10842 | } | |
10843 | else | |
10844 | { | |
10845 | mention (b); | |
10846 | if (ui_out_is_mi_like_p (uiout)) | |
10847 | ui_out_field_string | |
10848 | (uiout, "reason", | |
10849 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10850 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10851 | ui_out_text (uiout, "\nValue = "); | |
10852 | } | |
f99d8bf4 | 10853 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10854 | ui_out_field_stream (uiout, "new", stb); |
10855 | ui_out_text (uiout, "\n"); | |
10856 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10857 | break; |
10858 | default: | |
348d480f | 10859 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10860 | } |
10861 | ||
348d480f PA |
10862 | do_cleanups (old_chain); |
10863 | return result; | |
10864 | } | |
10865 | ||
10866 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10867 | watchpoints. */ | |
10868 | ||
10869 | static void | |
10870 | print_mention_watchpoint (struct breakpoint *b) | |
10871 | { | |
10872 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10873 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10874 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10875 | |
10876 | switch (b->type) | |
10877 | { | |
10878 | case bp_watchpoint: | |
10879 | ui_out_text (uiout, "Watchpoint "); | |
10880 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10881 | break; | |
10882 | case bp_hardware_watchpoint: | |
10883 | ui_out_text (uiout, "Hardware watchpoint "); | |
10884 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10885 | break; | |
10886 | case bp_read_watchpoint: | |
10887 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10888 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10889 | break; | |
10890 | case bp_access_watchpoint: | |
10891 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10892 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10893 | break; | |
10894 | default: | |
10895 | internal_error (__FILE__, __LINE__, | |
10896 | _("Invalid hardware watchpoint type.")); | |
10897 | } | |
10898 | ||
10899 | ui_out_field_int (uiout, "number", b->number); | |
10900 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10901 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10902 | do_cleanups (ui_out_chain); |
10903 | } | |
10904 | ||
10905 | /* Implement the "print_recreate" breakpoint_ops method for | |
10906 | watchpoints. */ | |
10907 | ||
10908 | static void | |
10909 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10910 | { | |
3a5c3e22 PA |
10911 | struct watchpoint *w = (struct watchpoint *) b; |
10912 | ||
348d480f PA |
10913 | switch (b->type) |
10914 | { | |
10915 | case bp_watchpoint: | |
10916 | case bp_hardware_watchpoint: | |
10917 | fprintf_unfiltered (fp, "watch"); | |
10918 | break; | |
10919 | case bp_read_watchpoint: | |
10920 | fprintf_unfiltered (fp, "rwatch"); | |
10921 | break; | |
10922 | case bp_access_watchpoint: | |
10923 | fprintf_unfiltered (fp, "awatch"); | |
10924 | break; | |
10925 | default: | |
10926 | internal_error (__FILE__, __LINE__, | |
10927 | _("Invalid watchpoint type.")); | |
10928 | } | |
10929 | ||
3a5c3e22 | 10930 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10931 | print_recreate_thread (b, fp); |
348d480f PA |
10932 | } |
10933 | ||
427cd150 TT |
10934 | /* Implement the "explains_signal" breakpoint_ops method for |
10935 | watchpoints. */ | |
10936 | ||
47591c29 | 10937 | static int |
427cd150 TT |
10938 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10939 | { | |
10940 | /* A software watchpoint cannot cause a signal other than | |
10941 | GDB_SIGNAL_TRAP. */ | |
10942 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10943 | return 0; |
427cd150 | 10944 | |
47591c29 | 10945 | return 1; |
427cd150 TT |
10946 | } |
10947 | ||
348d480f PA |
10948 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10949 | ||
2060206e | 10950 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10951 | |
10952 | /* Implement the "insert" breakpoint_ops method for | |
10953 | masked hardware watchpoints. */ | |
10954 | ||
10955 | static int | |
10956 | insert_masked_watchpoint (struct bp_location *bl) | |
10957 | { | |
3a5c3e22 PA |
10958 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10959 | ||
10960 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10961 | bl->watchpoint_type); |
10962 | } | |
10963 | ||
10964 | /* Implement the "remove" breakpoint_ops method for | |
10965 | masked hardware watchpoints. */ | |
10966 | ||
10967 | static int | |
73971819 | 10968 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10969 | { |
3a5c3e22 PA |
10970 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10971 | ||
10972 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10973 | bl->watchpoint_type); |
10974 | } | |
10975 | ||
10976 | /* Implement the "resources_needed" breakpoint_ops method for | |
10977 | masked hardware watchpoints. */ | |
10978 | ||
10979 | static int | |
10980 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10981 | { | |
3a5c3e22 PA |
10982 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10983 | ||
10984 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10985 | } |
10986 | ||
10987 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10988 | masked hardware watchpoints. */ | |
10989 | ||
10990 | static int | |
10991 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10992 | { | |
10993 | return 0; | |
10994 | } | |
10995 | ||
10996 | /* Implement the "print_it" breakpoint_ops method for | |
10997 | masked hardware watchpoints. */ | |
10998 | ||
10999 | static enum print_stop_action | |
11000 | print_it_masked_watchpoint (bpstat bs) | |
11001 | { | |
11002 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 11003 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11004 | |
11005 | /* Masked watchpoints have only one location. */ | |
11006 | gdb_assert (b->loc && b->loc->next == NULL); | |
11007 | ||
f303dbd6 PA |
11008 | annotate_watchpoint (b->number); |
11009 | maybe_print_thread_hit_breakpoint (uiout); | |
11010 | ||
348d480f PA |
11011 | switch (b->type) |
11012 | { | |
11013 | case bp_hardware_watchpoint: | |
348d480f PA |
11014 | if (ui_out_is_mi_like_p (uiout)) |
11015 | ui_out_field_string | |
11016 | (uiout, "reason", | |
11017 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11018 | break; | |
11019 | ||
11020 | case bp_read_watchpoint: | |
11021 | if (ui_out_is_mi_like_p (uiout)) | |
11022 | ui_out_field_string | |
11023 | (uiout, "reason", | |
11024 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11025 | break; | |
11026 | ||
11027 | case bp_access_watchpoint: | |
11028 | if (ui_out_is_mi_like_p (uiout)) | |
11029 | ui_out_field_string | |
11030 | (uiout, "reason", | |
11031 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11032 | break; | |
11033 | default: | |
11034 | internal_error (__FILE__, __LINE__, | |
11035 | _("Invalid hardware watchpoint type.")); | |
11036 | } | |
11037 | ||
11038 | mention (b); | |
9c06b0b4 TJB |
11039 | ui_out_text (uiout, _("\n\ |
11040 | Check the underlying instruction at PC for the memory\n\ | |
11041 | address and value which triggered this watchpoint.\n")); | |
11042 | ui_out_text (uiout, "\n"); | |
11043 | ||
11044 | /* More than one watchpoint may have been triggered. */ | |
11045 | return PRINT_UNKNOWN; | |
11046 | } | |
11047 | ||
11048 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11049 | masked hardware watchpoints. */ | |
11050 | ||
11051 | static void | |
11052 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11053 | struct ui_out *uiout) | |
11054 | { | |
3a5c3e22 PA |
11055 | struct watchpoint *w = (struct watchpoint *) b; |
11056 | ||
9c06b0b4 TJB |
11057 | /* Masked watchpoints have only one location. */ |
11058 | gdb_assert (b->loc && b->loc->next == NULL); | |
11059 | ||
11060 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11061 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11062 | ui_out_text (uiout, "\n"); |
11063 | } | |
11064 | ||
11065 | /* Implement the "print_mention" breakpoint_ops method for | |
11066 | masked hardware watchpoints. */ | |
11067 | ||
11068 | static void | |
11069 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11070 | { | |
3a5c3e22 | 11071 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11072 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11073 | struct cleanup *ui_out_chain; |
11074 | ||
11075 | switch (b->type) | |
11076 | { | |
11077 | case bp_hardware_watchpoint: | |
11078 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11079 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11080 | break; | |
11081 | case bp_read_watchpoint: | |
11082 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11083 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11084 | break; | |
11085 | case bp_access_watchpoint: | |
11086 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11087 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11088 | break; | |
11089 | default: | |
11090 | internal_error (__FILE__, __LINE__, | |
11091 | _("Invalid hardware watchpoint type.")); | |
11092 | } | |
11093 | ||
11094 | ui_out_field_int (uiout, "number", b->number); | |
11095 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11096 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11097 | do_cleanups (ui_out_chain); |
11098 | } | |
11099 | ||
11100 | /* Implement the "print_recreate" breakpoint_ops method for | |
11101 | masked hardware watchpoints. */ | |
11102 | ||
11103 | static void | |
11104 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11105 | { | |
3a5c3e22 | 11106 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11107 | char tmp[40]; |
11108 | ||
11109 | switch (b->type) | |
11110 | { | |
11111 | case bp_hardware_watchpoint: | |
11112 | fprintf_unfiltered (fp, "watch"); | |
11113 | break; | |
11114 | case bp_read_watchpoint: | |
11115 | fprintf_unfiltered (fp, "rwatch"); | |
11116 | break; | |
11117 | case bp_access_watchpoint: | |
11118 | fprintf_unfiltered (fp, "awatch"); | |
11119 | break; | |
11120 | default: | |
11121 | internal_error (__FILE__, __LINE__, | |
11122 | _("Invalid hardware watchpoint type.")); | |
11123 | } | |
11124 | ||
3a5c3e22 PA |
11125 | sprintf_vma (tmp, w->hw_wp_mask); |
11126 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11127 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11128 | } |
11129 | ||
11130 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11131 | ||
2060206e | 11132 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11133 | |
11134 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11135 | ||
11136 | static int | |
11137 | is_masked_watchpoint (const struct breakpoint *b) | |
11138 | { | |
11139 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11140 | } | |
11141 | ||
53a5351d JM |
11142 | /* accessflag: hw_write: watch write, |
11143 | hw_read: watch read, | |
11144 | hw_access: watch access (read or write) */ | |
c906108c | 11145 | static void |
bbc13ae3 | 11146 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11147 | int just_location, int internal) |
c906108c | 11148 | { |
d983da9c | 11149 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11150 | struct expression *exp; |
270140bd | 11151 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11152 | struct value *val, *mark, *result; |
bb9d5f81 | 11153 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11154 | struct frame_info *frame; |
bbc13ae3 KS |
11155 | const char *exp_start = NULL; |
11156 | const char *exp_end = NULL; | |
11157 | const char *tok, *end_tok; | |
9c06b0b4 | 11158 | int toklen = -1; |
bbc13ae3 KS |
11159 | const char *cond_start = NULL; |
11160 | const char *cond_end = NULL; | |
c906108c | 11161 | enum bptype bp_type; |
37e4754d | 11162 | int thread = -1; |
0cf6dd15 | 11163 | int pc = 0; |
9c06b0b4 TJB |
11164 | /* Flag to indicate whether we are going to use masks for |
11165 | the hardware watchpoint. */ | |
11166 | int use_mask = 0; | |
11167 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11168 | struct watchpoint *w; |
bbc13ae3 KS |
11169 | char *expression; |
11170 | struct cleanup *back_to; | |
c906108c | 11171 | |
37e4754d LM |
11172 | /* Make sure that we actually have parameters to parse. */ |
11173 | if (arg != NULL && arg[0] != '\0') | |
11174 | { | |
bbc13ae3 KS |
11175 | const char *value_start; |
11176 | ||
11177 | exp_end = arg + strlen (arg); | |
37e4754d | 11178 | |
9c06b0b4 TJB |
11179 | /* Look for "parameter value" pairs at the end |
11180 | of the arguments string. */ | |
bbc13ae3 | 11181 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11182 | { |
11183 | /* Skip whitespace at the end of the argument list. */ | |
11184 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11185 | tok--; | |
11186 | ||
11187 | /* Find the beginning of the last token. | |
11188 | This is the value of the parameter. */ | |
11189 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11190 | tok--; | |
11191 | value_start = tok + 1; | |
11192 | ||
11193 | /* Skip whitespace. */ | |
11194 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11195 | tok--; | |
11196 | ||
11197 | end_tok = tok; | |
11198 | ||
11199 | /* Find the beginning of the second to last token. | |
11200 | This is the parameter itself. */ | |
11201 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11202 | tok--; | |
11203 | tok++; | |
11204 | toklen = end_tok - tok + 1; | |
11205 | ||
61012eef | 11206 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11207 | { |
5d5658a1 | 11208 | struct thread_info *thr; |
9c06b0b4 TJB |
11209 | /* At this point we've found a "thread" token, which means |
11210 | the user is trying to set a watchpoint that triggers | |
11211 | only in a specific thread. */ | |
5d5658a1 | 11212 | const char *endp; |
37e4754d | 11213 | |
9c06b0b4 TJB |
11214 | if (thread != -1) |
11215 | error(_("You can specify only one thread.")); | |
37e4754d | 11216 | |
9c06b0b4 | 11217 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11218 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11219 | |
5d5658a1 | 11220 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11221 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11222 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11223 | |
5d5658a1 | 11224 | thread = thr->global_num; |
9c06b0b4 | 11225 | } |
61012eef | 11226 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11227 | { |
11228 | /* We've found a "mask" token, which means the user wants to | |
11229 | create a hardware watchpoint that is going to have the mask | |
11230 | facility. */ | |
11231 | struct value *mask_value, *mark; | |
37e4754d | 11232 | |
9c06b0b4 TJB |
11233 | if (use_mask) |
11234 | error(_("You can specify only one mask.")); | |
37e4754d | 11235 | |
9c06b0b4 | 11236 | use_mask = just_location = 1; |
37e4754d | 11237 | |
9c06b0b4 TJB |
11238 | mark = value_mark (); |
11239 | mask_value = parse_to_comma_and_eval (&value_start); | |
11240 | mask = value_as_address (mask_value); | |
11241 | value_free_to_mark (mark); | |
11242 | } | |
11243 | else | |
11244 | /* We didn't recognize what we found. We should stop here. */ | |
11245 | break; | |
37e4754d | 11246 | |
9c06b0b4 TJB |
11247 | /* Truncate the string and get rid of the "parameter value" pair before |
11248 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11249 | exp_end = tok; |
9c06b0b4 | 11250 | } |
37e4754d | 11251 | } |
bbc13ae3 KS |
11252 | else |
11253 | exp_end = arg; | |
37e4754d | 11254 | |
bbc13ae3 KS |
11255 | /* Parse the rest of the arguments. From here on out, everything |
11256 | is in terms of a newly allocated string instead of the original | |
11257 | ARG. */ | |
c906108c | 11258 | innermost_block = NULL; |
bbc13ae3 KS |
11259 | expression = savestring (arg, exp_end - arg); |
11260 | back_to = make_cleanup (xfree, expression); | |
11261 | exp_start = arg = expression; | |
1bb9788d | 11262 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11263 | exp_end = arg; |
fa8a61dc TT |
11264 | /* Remove trailing whitespace from the expression before saving it. |
11265 | This makes the eventual display of the expression string a bit | |
11266 | prettier. */ | |
11267 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11268 | --exp_end; | |
11269 | ||
65d79d4b SDJ |
11270 | /* Checking if the expression is not constant. */ |
11271 | if (watchpoint_exp_is_const (exp)) | |
11272 | { | |
11273 | int len; | |
11274 | ||
11275 | len = exp_end - exp_start; | |
11276 | while (len > 0 && isspace (exp_start[len - 1])) | |
11277 | len--; | |
11278 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11279 | } | |
11280 | ||
c906108c SS |
11281 | exp_valid_block = innermost_block; |
11282 | mark = value_mark (); | |
3a1115a0 | 11283 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11284 | |
bb9d5f81 PP |
11285 | if (val != NULL && just_location) |
11286 | { | |
11287 | saved_bitpos = value_bitpos (val); | |
11288 | saved_bitsize = value_bitsize (val); | |
11289 | } | |
11290 | ||
06a64a0b TT |
11291 | if (just_location) |
11292 | { | |
9c06b0b4 TJB |
11293 | int ret; |
11294 | ||
06a64a0b | 11295 | exp_valid_block = NULL; |
a1442452 | 11296 | val = value_addr (result); |
06a64a0b TT |
11297 | release_value (val); |
11298 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11299 | |
11300 | if (use_mask) | |
11301 | { | |
11302 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11303 | mask); | |
11304 | if (ret == -1) | |
11305 | error (_("This target does not support masked watchpoints.")); | |
11306 | else if (ret == -2) | |
11307 | error (_("Invalid mask or memory region.")); | |
11308 | } | |
06a64a0b TT |
11309 | } |
11310 | else if (val != NULL) | |
fa4727a6 | 11311 | release_value (val); |
c906108c | 11312 | |
bbc13ae3 KS |
11313 | tok = skip_spaces_const (arg); |
11314 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11315 | |
11316 | toklen = end_tok - tok; | |
11317 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11318 | { | |
2d134ed3 PA |
11319 | struct expression *cond; |
11320 | ||
60e1c644 | 11321 | innermost_block = NULL; |
c906108c | 11322 | tok = cond_start = end_tok + 1; |
1bb9788d | 11323 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11324 | |
11325 | /* The watchpoint expression may not be local, but the condition | |
11326 | may still be. E.g.: `watch global if local > 0'. */ | |
11327 | cond_exp_valid_block = innermost_block; | |
11328 | ||
2d134ed3 | 11329 | xfree (cond); |
c906108c SS |
11330 | cond_end = tok; |
11331 | } | |
11332 | if (*tok) | |
8a3fe4f8 | 11333 | error (_("Junk at end of command.")); |
c906108c | 11334 | |
d983da9c | 11335 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11336 | |
11337 | /* If the expression is "local", then set up a "watchpoint scope" | |
11338 | breakpoint at the point where we've left the scope of the watchpoint | |
11339 | expression. Create the scope breakpoint before the watchpoint, so | |
11340 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11341 | if (exp_valid_block && frame) |
d983da9c | 11342 | { |
edb3359d DJ |
11343 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11344 | { | |
11345 | scope_breakpoint | |
a6d9a66e UW |
11346 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11347 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11348 | bp_watchpoint_scope, |
11349 | &momentary_breakpoint_ops); | |
d983da9c | 11350 | |
edb3359d | 11351 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11352 | |
edb3359d DJ |
11353 | /* Automatically delete the breakpoint when it hits. */ |
11354 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11355 | |
edb3359d DJ |
11356 | /* Only break in the proper frame (help with recursion). */ |
11357 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11358 | |
edb3359d | 11359 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11360 | scope_breakpoint->loc->gdbarch |
11361 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11362 | scope_breakpoint->loc->requested_address |
11363 | = frame_unwind_caller_pc (frame); | |
11364 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11365 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11366 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11367 | scope_breakpoint->type); |
11368 | } | |
d983da9c DJ |
11369 | } |
11370 | ||
e8369a73 AB |
11371 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11372 | watchpoints here even if hardware watchpoints are turned off, a call | |
11373 | to update_watchpoint later in this function will cause the type to | |
11374 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11375 | ||
11376 | if (accessflag == hw_read) | |
11377 | bp_type = bp_read_watchpoint; | |
11378 | else if (accessflag == hw_access) | |
11379 | bp_type = bp_access_watchpoint; | |
11380 | else | |
11381 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11382 | |
11383 | w = XCNEW (struct watchpoint); | |
11384 | b = &w->base; | |
348d480f | 11385 | if (use_mask) |
3a5c3e22 PA |
11386 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11387 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11388 | else |
3a5c3e22 PA |
11389 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11390 | &watchpoint_breakpoint_ops); | |
37e4754d | 11391 | b->thread = thread; |
b5de0fa7 | 11392 | b->disposition = disp_donttouch; |
348d480f | 11393 | b->pspace = current_program_space; |
3a5c3e22 PA |
11394 | w->exp = exp; |
11395 | w->exp_valid_block = exp_valid_block; | |
11396 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11397 | if (just_location) |
11398 | { | |
11399 | struct type *t = value_type (val); | |
11400 | CORE_ADDR addr = value_as_address (val); | |
11401 | char *name; | |
11402 | ||
11403 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11404 | name = type_to_string (t); | |
11405 | ||
3a5c3e22 | 11406 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11407 | core_addr_to_string (addr)); |
06a64a0b TT |
11408 | xfree (name); |
11409 | ||
3a5c3e22 | 11410 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11411 | (int) (exp_end - exp_start), exp_start); |
11412 | ||
06a64a0b TT |
11413 | /* The above expression is in C. */ |
11414 | b->language = language_c; | |
11415 | } | |
11416 | else | |
3a5c3e22 | 11417 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11418 | |
11419 | if (use_mask) | |
11420 | { | |
3a5c3e22 | 11421 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11422 | } |
11423 | else | |
11424 | { | |
3a5c3e22 | 11425 | w->val = val; |
bb9d5f81 PP |
11426 | w->val_bitpos = saved_bitpos; |
11427 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11428 | w->val_valid = 1; |
9c06b0b4 | 11429 | } |
77b06cd7 | 11430 | |
c906108c SS |
11431 | if (cond_start) |
11432 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11433 | else | |
11434 | b->cond_string = 0; | |
c5aa993b | 11435 | |
c906108c | 11436 | if (frame) |
f6bc2008 | 11437 | { |
3a5c3e22 PA |
11438 | w->watchpoint_frame = get_frame_id (frame); |
11439 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11440 | } |
c906108c | 11441 | else |
f6bc2008 | 11442 | { |
3a5c3e22 PA |
11443 | w->watchpoint_frame = null_frame_id; |
11444 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11445 | } |
c906108c | 11446 | |
d983da9c | 11447 | if (scope_breakpoint != NULL) |
c906108c | 11448 | { |
d983da9c DJ |
11449 | /* The scope breakpoint is related to the watchpoint. We will |
11450 | need to act on them together. */ | |
11451 | b->related_breakpoint = scope_breakpoint; | |
11452 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11453 | } |
d983da9c | 11454 | |
06a64a0b TT |
11455 | if (!just_location) |
11456 | value_free_to_mark (mark); | |
2d134ed3 | 11457 | |
492d29ea | 11458 | TRY |
a9634178 TJB |
11459 | { |
11460 | /* Finally update the new watchpoint. This creates the locations | |
11461 | that should be inserted. */ | |
3a5c3e22 | 11462 | update_watchpoint (w, 1); |
a9634178 | 11463 | } |
492d29ea | 11464 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11465 | { |
11466 | delete_breakpoint (b); | |
11467 | throw_exception (e); | |
11468 | } | |
492d29ea | 11469 | END_CATCH |
a9634178 | 11470 | |
3ea46bff | 11471 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11472 | do_cleanups (back_to); |
c906108c SS |
11473 | } |
11474 | ||
e09342b5 | 11475 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11476 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11477 | |
c906108c | 11478 | static int |
a9634178 | 11479 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11480 | { |
11481 | int found_memory_cnt = 0; | |
2e70b7b9 | 11482 | struct value *head = v; |
c906108c SS |
11483 | |
11484 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11485 | if (!can_use_hw_watchpoints) |
c906108c | 11486 | return 0; |
c5aa993b | 11487 | |
5c44784c JM |
11488 | /* Make sure that the value of the expression depends only upon |
11489 | memory contents, and values computed from them within GDB. If we | |
11490 | find any register references or function calls, we can't use a | |
11491 | hardware watchpoint. | |
11492 | ||
11493 | The idea here is that evaluating an expression generates a series | |
11494 | of values, one holding the value of every subexpression. (The | |
11495 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11496 | a*b+c.) GDB's values hold almost enough information to establish | |
11497 | the criteria given above --- they identify memory lvalues, | |
11498 | register lvalues, computed values, etcetera. So we can evaluate | |
11499 | the expression, and then scan the chain of values that leaves | |
11500 | behind to decide whether we can detect any possible change to the | |
11501 | expression's final value using only hardware watchpoints. | |
11502 | ||
11503 | However, I don't think that the values returned by inferior | |
11504 | function calls are special in any way. So this function may not | |
11505 | notice that an expression involving an inferior function call | |
11506 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11507 | for (; v; v = value_next (v)) |
c906108c | 11508 | { |
5c44784c | 11509 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11510 | { |
8464be76 DJ |
11511 | if (v != head && value_lazy (v)) |
11512 | /* A lazy memory lvalue in the chain is one that GDB never | |
11513 | needed to fetch; we either just used its address (e.g., | |
11514 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11515 | in `a,b'). This doesn't apply to HEAD; if that is | |
11516 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11517 | ; |
53a5351d | 11518 | else |
5c44784c JM |
11519 | { |
11520 | /* Ahh, memory we actually used! Check if we can cover | |
11521 | it with hardware watchpoints. */ | |
df407dfe | 11522 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11523 | |
11524 | /* We only watch structs and arrays if user asked for it | |
11525 | explicitly, never if they just happen to appear in a | |
11526 | middle of some value chain. */ | |
11527 | if (v == head | |
11528 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11529 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11530 | { | |
42ae5230 | 11531 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11532 | int len; |
11533 | int num_regs; | |
11534 | ||
a9634178 | 11535 | len = (target_exact_watchpoints |
e09342b5 TJB |
11536 | && is_scalar_type_recursive (vtype))? |
11537 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11538 | |
e09342b5 TJB |
11539 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11540 | if (!num_regs) | |
2e70b7b9 MS |
11541 | return 0; |
11542 | else | |
e09342b5 | 11543 | found_memory_cnt += num_regs; |
2e70b7b9 | 11544 | } |
5c44784c | 11545 | } |
c5aa993b | 11546 | } |
5086187c AC |
11547 | else if (VALUE_LVAL (v) != not_lval |
11548 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11549 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11550 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11551 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11552 | } |
11553 | ||
11554 | /* The expression itself looks suitable for using a hardware | |
11555 | watchpoint, but give the target machine a chance to reject it. */ | |
11556 | return found_memory_cnt; | |
11557 | } | |
11558 | ||
8b93c638 | 11559 | void |
84f4c1fe | 11560 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11561 | { |
84f4c1fe | 11562 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11563 | } |
11564 | ||
06a64a0b TT |
11565 | /* A helper function that looks for the "-location" argument and then |
11566 | calls watch_command_1. */ | |
11567 | ||
11568 | static void | |
11569 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11570 | { | |
11571 | int just_location = 0; | |
11572 | ||
11573 | if (arg | |
11574 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11575 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11576 | { | |
e9cafbcc | 11577 | arg = skip_spaces (arg); |
06a64a0b TT |
11578 | just_location = 1; |
11579 | } | |
11580 | ||
84f4c1fe | 11581 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11582 | } |
8926118c | 11583 | |
c5aa993b | 11584 | static void |
fba45db2 | 11585 | watch_command (char *arg, int from_tty) |
c906108c | 11586 | { |
06a64a0b | 11587 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11588 | } |
11589 | ||
8b93c638 | 11590 | void |
84f4c1fe | 11591 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11592 | { |
84f4c1fe | 11593 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11594 | } |
8926118c | 11595 | |
c5aa993b | 11596 | static void |
fba45db2 | 11597 | rwatch_command (char *arg, int from_tty) |
c906108c | 11598 | { |
06a64a0b | 11599 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11600 | } |
11601 | ||
8b93c638 | 11602 | void |
84f4c1fe | 11603 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11604 | { |
84f4c1fe | 11605 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11606 | } |
8926118c | 11607 | |
c5aa993b | 11608 | static void |
fba45db2 | 11609 | awatch_command (char *arg, int from_tty) |
c906108c | 11610 | { |
06a64a0b | 11611 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11612 | } |
c906108c | 11613 | \f |
c5aa993b | 11614 | |
cfc31633 PA |
11615 | /* Data for the FSM that manages the until(location)/advance commands |
11616 | in infcmd.c. Here because it uses the mechanisms of | |
11617 | breakpoints. */ | |
c906108c | 11618 | |
cfc31633 | 11619 | struct until_break_fsm |
bfec99b2 | 11620 | { |
cfc31633 PA |
11621 | /* The base class. */ |
11622 | struct thread_fsm thread_fsm; | |
11623 | ||
11624 | /* The thread that as current when the command was executed. */ | |
11625 | int thread; | |
11626 | ||
11627 | /* The breakpoint set at the destination location. */ | |
11628 | struct breakpoint *location_breakpoint; | |
11629 | ||
11630 | /* Breakpoint set at the return address in the caller frame. May be | |
11631 | NULL. */ | |
11632 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11633 | }; |
11634 | ||
8980e177 PA |
11635 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11636 | struct thread_info *thread); | |
11637 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11638 | struct thread_info *thread); | |
cfc31633 PA |
11639 | static enum async_reply_reason |
11640 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11641 | ||
11642 | /* until_break_fsm's vtable. */ | |
11643 | ||
11644 | static struct thread_fsm_ops until_break_fsm_ops = | |
11645 | { | |
11646 | NULL, /* dtor */ | |
11647 | until_break_fsm_clean_up, | |
11648 | until_break_fsm_should_stop, | |
11649 | NULL, /* return_value */ | |
11650 | until_break_fsm_async_reply_reason, | |
11651 | }; | |
11652 | ||
11653 | /* Allocate a new until_break_command_fsm. */ | |
11654 | ||
11655 | static struct until_break_fsm * | |
8980e177 | 11656 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11657 | struct breakpoint *location_breakpoint, |
11658 | struct breakpoint *caller_breakpoint) | |
11659 | { | |
11660 | struct until_break_fsm *sm; | |
11661 | ||
11662 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11663 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11664 | |
11665 | sm->thread = thread; | |
11666 | sm->location_breakpoint = location_breakpoint; | |
11667 | sm->caller_breakpoint = caller_breakpoint; | |
11668 | ||
11669 | return sm; | |
11670 | } | |
11671 | ||
11672 | /* Implementation of the 'should_stop' FSM method for the | |
11673 | until(location)/advance commands. */ | |
11674 | ||
11675 | static int | |
8980e177 PA |
11676 | until_break_fsm_should_stop (struct thread_fsm *self, |
11677 | struct thread_info *tp) | |
cfc31633 PA |
11678 | { |
11679 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11680 | |
11681 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11682 | sm->location_breakpoint) != NULL | |
11683 | || (sm->caller_breakpoint != NULL | |
11684 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11685 | sm->caller_breakpoint) != NULL)) | |
11686 | thread_fsm_set_finished (self); | |
11687 | ||
11688 | return 1; | |
11689 | } | |
11690 | ||
11691 | /* Implementation of the 'clean_up' FSM method for the | |
11692 | until(location)/advance commands. */ | |
11693 | ||
c2c6d25f | 11694 | static void |
8980e177 PA |
11695 | until_break_fsm_clean_up (struct thread_fsm *self, |
11696 | struct thread_info *thread) | |
43ff13b4 | 11697 | { |
cfc31633 | 11698 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11699 | |
cfc31633 PA |
11700 | /* Clean up our temporary breakpoints. */ |
11701 | if (sm->location_breakpoint != NULL) | |
11702 | { | |
11703 | delete_breakpoint (sm->location_breakpoint); | |
11704 | sm->location_breakpoint = NULL; | |
11705 | } | |
11706 | if (sm->caller_breakpoint != NULL) | |
11707 | { | |
11708 | delete_breakpoint (sm->caller_breakpoint); | |
11709 | sm->caller_breakpoint = NULL; | |
11710 | } | |
11711 | delete_longjmp_breakpoint (sm->thread); | |
11712 | } | |
11713 | ||
11714 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11715 | until(location)/advance commands. */ | |
11716 | ||
11717 | static enum async_reply_reason | |
11718 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11719 | { | |
11720 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11721 | } |
11722 | ||
c906108c | 11723 | void |
ae66c1fc | 11724 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11725 | { |
11726 | struct symtabs_and_lines sals; | |
11727 | struct symtab_and_line sal; | |
8556afb4 PA |
11728 | struct frame_info *frame; |
11729 | struct gdbarch *frame_gdbarch; | |
11730 | struct frame_id stack_frame_id; | |
11731 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11732 | struct breakpoint *location_breakpoint; |
11733 | struct breakpoint *caller_breakpoint = NULL; | |
f00aae0f | 11734 | struct cleanup *old_chain, *cleanup; |
186c406b TT |
11735 | int thread; |
11736 | struct thread_info *tp; | |
f00aae0f | 11737 | struct event_location *location; |
cfc31633 | 11738 | struct until_break_fsm *sm; |
c906108c | 11739 | |
70509625 | 11740 | clear_proceed_status (0); |
c906108c SS |
11741 | |
11742 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11743 | this function. */ |
c5aa993b | 11744 | |
f00aae0f KS |
11745 | location = string_to_event_location (&arg, current_language); |
11746 | cleanup = make_cleanup_delete_event_location (location); | |
11747 | ||
1bfeeb0f | 11748 | if (last_displayed_sal_is_valid ()) |
c2f4122d | 11749 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11750 | get_last_displayed_symtab (), |
f8eba3c6 | 11751 | get_last_displayed_line ()); |
c906108c | 11752 | else |
f00aae0f | 11753 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11754 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11755 | |
c906108c | 11756 | if (sals.nelts != 1) |
8a3fe4f8 | 11757 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11758 | |
c906108c | 11759 | sal = sals.sals[0]; |
4a64f543 | 11760 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11761 | |
c906108c | 11762 | if (*arg) |
8a3fe4f8 | 11763 | error (_("Junk at end of arguments.")); |
c5aa993b | 11764 | |
c906108c | 11765 | resolve_sal_pc (&sal); |
c5aa993b | 11766 | |
186c406b | 11767 | tp = inferior_thread (); |
5d5658a1 | 11768 | thread = tp->global_num; |
186c406b | 11769 | |
883bc8d1 PA |
11770 | old_chain = make_cleanup (null_cleanup, NULL); |
11771 | ||
8556afb4 PA |
11772 | /* Note linespec handling above invalidates the frame chain. |
11773 | Installing a breakpoint also invalidates the frame chain (as it | |
11774 | may need to switch threads), so do any frame handling before | |
11775 | that. */ | |
11776 | ||
11777 | frame = get_selected_frame (NULL); | |
11778 | frame_gdbarch = get_frame_arch (frame); | |
11779 | stack_frame_id = get_stack_frame_id (frame); | |
11780 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11781 | |
ae66c1fc EZ |
11782 | /* Keep within the current frame, or in frames called by the current |
11783 | one. */ | |
edb3359d | 11784 | |
883bc8d1 | 11785 | if (frame_id_p (caller_frame_id)) |
c906108c | 11786 | { |
883bc8d1 | 11787 | struct symtab_and_line sal2; |
cfc31633 | 11788 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11789 | |
11790 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11791 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11792 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11793 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11794 | sal2, | |
11795 | caller_frame_id, | |
11796 | bp_until); | |
11797 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11798 | |
883bc8d1 | 11799 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11800 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11801 | } |
c5aa993b | 11802 | |
c70a6932 JK |
11803 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11804 | frame = NULL; | |
11805 | ||
883bc8d1 PA |
11806 | if (anywhere) |
11807 | /* If the user told us to continue until a specified location, | |
11808 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11809 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11810 | null_frame_id, bp_until); | |
883bc8d1 PA |
11811 | else |
11812 | /* Otherwise, specify the selected frame, because we want to stop | |
11813 | only at the very same frame. */ | |
cfc31633 PA |
11814 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11815 | stack_frame_id, bp_until); | |
11816 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11817 | |
8980e177 | 11818 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11819 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11820 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11821 | |
cfc31633 | 11822 | discard_cleanups (old_chain); |
f107f563 | 11823 | |
cfc31633 | 11824 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f00aae0f KS |
11825 | |
11826 | do_cleanups (cleanup); | |
c906108c | 11827 | } |
ae66c1fc | 11828 | |
c906108c SS |
11829 | /* This function attempts to parse an optional "if <cond>" clause |
11830 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11831 | |
c906108c SS |
11832 | Else, it returns a pointer to the condition string. (It does not |
11833 | attempt to evaluate the string against a particular block.) And, | |
11834 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11835 | if clause in the arg string. */ |
53a5351d | 11836 | |
916703c0 | 11837 | char * |
fba45db2 | 11838 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11839 | { |
c5aa993b JM |
11840 | char *cond_string; |
11841 | ||
11842 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11843 | return NULL; |
c5aa993b | 11844 | |
4a64f543 | 11845 | /* Skip the "if" keyword. */ |
c906108c | 11846 | (*arg) += 2; |
c5aa993b | 11847 | |
c906108c | 11848 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11849 | condition string. */ |
e9cafbcc | 11850 | *arg = skip_spaces (*arg); |
c906108c | 11851 | cond_string = *arg; |
c5aa993b | 11852 | |
4a64f543 MS |
11853 | /* Assume that the condition occupies the remainder of the arg |
11854 | string. */ | |
c906108c | 11855 | (*arg) += strlen (cond_string); |
c5aa993b | 11856 | |
c906108c SS |
11857 | return cond_string; |
11858 | } | |
c5aa993b | 11859 | |
c906108c SS |
11860 | /* Commands to deal with catching events, such as signals, exceptions, |
11861 | process start/exit, etc. */ | |
c5aa993b JM |
11862 | |
11863 | typedef enum | |
11864 | { | |
44feb3ce TT |
11865 | catch_fork_temporary, catch_vfork_temporary, |
11866 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11867 | } |
11868 | catch_fork_kind; | |
11869 | ||
c906108c | 11870 | static void |
cc59ec59 MS |
11871 | catch_fork_command_1 (char *arg, int from_tty, |
11872 | struct cmd_list_element *command) | |
c906108c | 11873 | { |
a6d9a66e | 11874 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11875 | char *cond_string = NULL; |
44feb3ce TT |
11876 | catch_fork_kind fork_kind; |
11877 | int tempflag; | |
11878 | ||
11879 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11880 | tempflag = (fork_kind == catch_fork_temporary | |
11881 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11882 | |
44feb3ce TT |
11883 | if (!arg) |
11884 | arg = ""; | |
e9cafbcc | 11885 | arg = skip_spaces (arg); |
c5aa993b | 11886 | |
c906108c | 11887 | /* The allowed syntax is: |
c5aa993b JM |
11888 | catch [v]fork |
11889 | catch [v]fork if <cond> | |
11890 | ||
4a64f543 | 11891 | First, check if there's an if clause. */ |
c906108c | 11892 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11893 | |
c906108c | 11894 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11895 | error (_("Junk at end of arguments.")); |
c5aa993b | 11896 | |
c906108c | 11897 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11898 | and enable reporting of such events. */ |
c5aa993b JM |
11899 | switch (fork_kind) |
11900 | { | |
44feb3ce TT |
11901 | case catch_fork_temporary: |
11902 | case catch_fork_permanent: | |
a6d9a66e | 11903 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11904 | &catch_fork_breakpoint_ops); |
c906108c | 11905 | break; |
44feb3ce TT |
11906 | case catch_vfork_temporary: |
11907 | case catch_vfork_permanent: | |
a6d9a66e | 11908 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11909 | &catch_vfork_breakpoint_ops); |
c906108c | 11910 | break; |
c5aa993b | 11911 | default: |
8a3fe4f8 | 11912 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11913 | break; |
c5aa993b | 11914 | } |
c906108c SS |
11915 | } |
11916 | ||
11917 | static void | |
cc59ec59 MS |
11918 | catch_exec_command_1 (char *arg, int from_tty, |
11919 | struct cmd_list_element *command) | |
c906108c | 11920 | { |
b4d90040 | 11921 | struct exec_catchpoint *c; |
a6d9a66e | 11922 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11923 | int tempflag; |
c5aa993b | 11924 | char *cond_string = NULL; |
c906108c | 11925 | |
44feb3ce TT |
11926 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11927 | ||
11928 | if (!arg) | |
11929 | arg = ""; | |
e9cafbcc | 11930 | arg = skip_spaces (arg); |
c906108c SS |
11931 | |
11932 | /* The allowed syntax is: | |
c5aa993b JM |
11933 | catch exec |
11934 | catch exec if <cond> | |
c906108c | 11935 | |
4a64f543 | 11936 | First, check if there's an if clause. */ |
c906108c SS |
11937 | cond_string = ep_parse_optional_if_clause (&arg); |
11938 | ||
11939 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11940 | error (_("Junk at end of arguments.")); |
c906108c | 11941 | |
b4d90040 PA |
11942 | c = XNEW (struct exec_catchpoint); |
11943 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11944 | &catch_exec_breakpoint_ops); | |
11945 | c->exec_pathname = NULL; | |
11946 | ||
3ea46bff | 11947 | install_breakpoint (0, &c->base, 1); |
c906108c | 11948 | } |
c5aa993b | 11949 | |
9ac4176b | 11950 | void |
28010a5d PA |
11951 | init_ada_exception_breakpoint (struct breakpoint *b, |
11952 | struct gdbarch *gdbarch, | |
11953 | struct symtab_and_line sal, | |
11954 | char *addr_string, | |
c0a91b2b | 11955 | const struct breakpoint_ops *ops, |
28010a5d | 11956 | int tempflag, |
349774ef | 11957 | int enabled, |
28010a5d | 11958 | int from_tty) |
f7f9143b | 11959 | { |
f7f9143b JB |
11960 | if (from_tty) |
11961 | { | |
5af949e3 UW |
11962 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11963 | if (!loc_gdbarch) | |
11964 | loc_gdbarch = gdbarch; | |
11965 | ||
6c95b8df PA |
11966 | describe_other_breakpoints (loc_gdbarch, |
11967 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11968 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11969 | version for exception catchpoints, because two catchpoints | |
11970 | used for different exception names will use the same address. | |
11971 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11972 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11973 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11974 | the user what type of catchpoint it is. The above is good |
11975 | enough for now, though. */ | |
11976 | } | |
11977 | ||
28010a5d | 11978 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11979 | |
349774ef | 11980 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11981 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f00aae0f KS |
11982 | b->location = string_to_event_location (&addr_string, |
11983 | language_def (language_ada)); | |
f7f9143b | 11984 | b->language = language_ada; |
f7f9143b JB |
11985 | } |
11986 | ||
c906108c | 11987 | static void |
fba45db2 | 11988 | catch_command (char *arg, int from_tty) |
c906108c | 11989 | { |
44feb3ce | 11990 | error (_("Catch requires an event name.")); |
c906108c SS |
11991 | } |
11992 | \f | |
11993 | ||
11994 | static void | |
fba45db2 | 11995 | tcatch_command (char *arg, int from_tty) |
c906108c | 11996 | { |
44feb3ce | 11997 | error (_("Catch requires an event name.")); |
c906108c SS |
11998 | } |
11999 | ||
8a2c437b TT |
12000 | /* A qsort comparison function that sorts breakpoints in order. */ |
12001 | ||
12002 | static int | |
12003 | compare_breakpoints (const void *a, const void *b) | |
12004 | { | |
9a3c8263 | 12005 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 12006 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 12007 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
12008 | uintptr_t ub = (uintptr_t) *bb; |
12009 | ||
12010 | if ((*ba)->number < (*bb)->number) | |
12011 | return -1; | |
12012 | else if ((*ba)->number > (*bb)->number) | |
12013 | return 1; | |
12014 | ||
12015 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
12016 | the number 0. */ | |
12017 | if (ua < ub) | |
12018 | return -1; | |
94b0e70d | 12019 | return ua > ub ? 1 : 0; |
8a2c437b TT |
12020 | } |
12021 | ||
80f8a6eb | 12022 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12023 | |
12024 | static void | |
fba45db2 | 12025 | clear_command (char *arg, int from_tty) |
c906108c | 12026 | { |
8a2c437b | 12027 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12028 | VEC(breakpoint_p) *found = 0; |
12029 | int ix; | |
c906108c SS |
12030 | int default_match; |
12031 | struct symtabs_and_lines sals; | |
12032 | struct symtab_and_line sal; | |
c906108c | 12033 | int i; |
8a2c437b | 12034 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12035 | |
12036 | if (arg) | |
12037 | { | |
39cf75f7 DE |
12038 | sals = decode_line_with_current_source (arg, |
12039 | (DECODE_LINE_FUNFIRSTLINE | |
12040 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12041 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12042 | default_match = 0; |
12043 | } | |
12044 | else | |
12045 | { | |
8d749320 | 12046 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 12047 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12048 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12049 | |
12050 | /* Set sal's line, symtab, pc, and pspace to the values | |
12051 | corresponding to the last call to print_frame_info. If the | |
12052 | codepoint is not valid, this will set all the fields to 0. */ | |
12053 | get_last_displayed_sal (&sal); | |
c906108c | 12054 | if (sal.symtab == 0) |
8a3fe4f8 | 12055 | error (_("No source file specified.")); |
c906108c SS |
12056 | |
12057 | sals.sals[0] = sal; | |
12058 | sals.nelts = 1; | |
12059 | ||
12060 | default_match = 1; | |
12061 | } | |
12062 | ||
4a64f543 MS |
12063 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12064 | seems, because all existing breakpoints typically have both | |
12065 | file/line and pc set. So, if clear is given file/line, we can | |
12066 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12067 | |
12068 | We only support clearing given the address explicitly | |
12069 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12070 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12071 | due to optimization, all in one block. |
4a64f543 MS |
12072 | |
12073 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12074 | PC corresponding to the same file:line, the breakpoint won't |
12075 | be cleared. We probably can still clear the breakpoint, but | |
12076 | since the other PC value is never presented to user, user | |
12077 | can only find it by guessing, and it does not seem important | |
12078 | to support that. */ | |
12079 | ||
4a64f543 MS |
12080 | /* For each line spec given, delete bps which correspond to it. Do |
12081 | it in two passes, solely to preserve the current behavior that | |
12082 | from_tty is forced true if we delete more than one | |
12083 | breakpoint. */ | |
c906108c | 12084 | |
80f8a6eb | 12085 | found = NULL; |
8a2c437b | 12086 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12087 | for (i = 0; i < sals.nelts; i++) |
12088 | { | |
05cba821 JK |
12089 | const char *sal_fullname; |
12090 | ||
c906108c | 12091 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12092 | If line given (pc == 0), clear all bpts on specified line. |
12093 | If defaulting, clear all bpts on default line | |
c906108c | 12094 | or at default pc. |
c5aa993b JM |
12095 | |
12096 | defaulting sal.pc != 0 tests to do | |
12097 | ||
12098 | 0 1 pc | |
12099 | 1 1 pc _and_ line | |
12100 | 0 0 line | |
12101 | 1 0 <can't happen> */ | |
c906108c SS |
12102 | |
12103 | sal = sals.sals[i]; | |
05cba821 JK |
12104 | sal_fullname = (sal.symtab == NULL |
12105 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12106 | |
4a64f543 | 12107 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12108 | ALL_BREAKPOINTS (b) |
c5aa993b | 12109 | { |
0d381245 | 12110 | int match = 0; |
4a64f543 | 12111 | /* Are we going to delete b? */ |
cc60f2e3 | 12112 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12113 | { |
12114 | struct bp_location *loc = b->loc; | |
12115 | for (; loc; loc = loc->next) | |
12116 | { | |
f8eba3c6 TT |
12117 | /* If the user specified file:line, don't allow a PC |
12118 | match. This matches historical gdb behavior. */ | |
12119 | int pc_match = (!sal.explicit_line | |
12120 | && sal.pc | |
12121 | && (loc->pspace == sal.pspace) | |
12122 | && (loc->address == sal.pc) | |
12123 | && (!section_is_overlay (loc->section) | |
12124 | || loc->section == sal.section)); | |
4aac40c8 TT |
12125 | int line_match = 0; |
12126 | ||
12127 | if ((default_match || sal.explicit_line) | |
2f202fde | 12128 | && loc->symtab != NULL |
05cba821 | 12129 | && sal_fullname != NULL |
4aac40c8 | 12130 | && sal.pspace == loc->pspace |
05cba821 JK |
12131 | && loc->line_number == sal.line |
12132 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12133 | sal_fullname) == 0) | |
12134 | line_match = 1; | |
4aac40c8 | 12135 | |
0d381245 VP |
12136 | if (pc_match || line_match) |
12137 | { | |
12138 | match = 1; | |
12139 | break; | |
12140 | } | |
12141 | } | |
12142 | } | |
12143 | ||
12144 | if (match) | |
d6e956e5 | 12145 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12146 | } |
80f8a6eb | 12147 | } |
8a2c437b | 12148 | |
80f8a6eb | 12149 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12150 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12151 | { |
12152 | if (arg) | |
8a3fe4f8 | 12153 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12154 | else |
8a3fe4f8 | 12155 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12156 | } |
c906108c | 12157 | |
8a2c437b TT |
12158 | /* Remove duplicates from the vec. */ |
12159 | qsort (VEC_address (breakpoint_p, found), | |
12160 | VEC_length (breakpoint_p, found), | |
12161 | sizeof (breakpoint_p), | |
12162 | compare_breakpoints); | |
12163 | prev = VEC_index (breakpoint_p, found, 0); | |
12164 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12165 | { | |
12166 | if (b == prev) | |
12167 | { | |
12168 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12169 | --ix; | |
12170 | } | |
12171 | } | |
12172 | ||
d6e956e5 | 12173 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12174 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12175 | if (from_tty) |
a3f17187 | 12176 | { |
d6e956e5 | 12177 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12178 | printf_unfiltered (_("Deleted breakpoint ")); |
12179 | else | |
12180 | printf_unfiltered (_("Deleted breakpoints ")); | |
12181 | } | |
d6e956e5 VP |
12182 | |
12183 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12184 | { |
c5aa993b | 12185 | if (from_tty) |
d6e956e5 VP |
12186 | printf_unfiltered ("%d ", b->number); |
12187 | delete_breakpoint (b); | |
c906108c | 12188 | } |
80f8a6eb MS |
12189 | if (from_tty) |
12190 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12191 | |
12192 | do_cleanups (cleanups); | |
c906108c SS |
12193 | } |
12194 | \f | |
12195 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12196 | all breakpoints that are marked for deletion, whether hit or not. | |
12197 | This is called after any breakpoint is hit, or after errors. */ | |
12198 | ||
12199 | void | |
fba45db2 | 12200 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12201 | { |
35df4500 | 12202 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12203 | |
12204 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12205 | if (bs->breakpoint_at |
12206 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12207 | && bs->stop) |
f431efe5 | 12208 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12209 | |
35df4500 | 12210 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12211 | { |
b5de0fa7 | 12212 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12213 | delete_breakpoint (b); |
12214 | } | |
c906108c SS |
12215 | } |
12216 | ||
4a64f543 MS |
12217 | /* A comparison function for bp_location AP and BP being interfaced to |
12218 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12219 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12220 | secondarily by ordering first permanent elements and |
4a64f543 | 12221 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12222 | qsort being an unstable algorithm. */ |
876fa593 JK |
12223 | |
12224 | static int | |
494cfb0f | 12225 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12226 | { |
9a3c8263 SM |
12227 | const struct bp_location *a = *(const struct bp_location **) ap; |
12228 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12229 | |
12230 | if (a->address != b->address) | |
12231 | return (a->address > b->address) - (a->address < b->address); | |
12232 | ||
dea2aa5f LM |
12233 | /* Sort locations at the same address by their pspace number, keeping |
12234 | locations of the same inferior (in a multi-inferior environment) | |
12235 | grouped. */ | |
12236 | ||
12237 | if (a->pspace->num != b->pspace->num) | |
12238 | return ((a->pspace->num > b->pspace->num) | |
12239 | - (a->pspace->num < b->pspace->num)); | |
12240 | ||
876fa593 | 12241 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12242 | if (a->permanent != b->permanent) |
12243 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12244 | |
c56a97f9 JK |
12245 | /* Make the internal GDB representation stable across GDB runs |
12246 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12247 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12248 | |
12249 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12250 | return ((a->owner->number > b->owner->number) |
12251 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12252 | |
12253 | return (a > b) - (a < b); | |
12254 | } | |
12255 | ||
876fa593 | 12256 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12257 | bp_location_shadow_len_after_address_max according to the current |
12258 | content of the bp_location array. */ | |
f7545552 TT |
12259 | |
12260 | static void | |
876fa593 | 12261 | bp_location_target_extensions_update (void) |
f7545552 | 12262 | { |
876fa593 JK |
12263 | struct bp_location *bl, **blp_tmp; |
12264 | ||
12265 | bp_location_placed_address_before_address_max = 0; | |
12266 | bp_location_shadow_len_after_address_max = 0; | |
12267 | ||
12268 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12269 | { | |
12270 | CORE_ADDR start, end, addr; | |
12271 | ||
12272 | if (!bp_location_has_shadow (bl)) | |
12273 | continue; | |
12274 | ||
12275 | start = bl->target_info.placed_address; | |
12276 | end = start + bl->target_info.shadow_len; | |
12277 | ||
12278 | gdb_assert (bl->address >= start); | |
12279 | addr = bl->address - start; | |
12280 | if (addr > bp_location_placed_address_before_address_max) | |
12281 | bp_location_placed_address_before_address_max = addr; | |
12282 | ||
12283 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12284 | ||
12285 | gdb_assert (bl->address < end); | |
12286 | addr = end - bl->address; | |
12287 | if (addr > bp_location_shadow_len_after_address_max) | |
12288 | bp_location_shadow_len_after_address_max = addr; | |
12289 | } | |
f7545552 TT |
12290 | } |
12291 | ||
1e4d1764 YQ |
12292 | /* Download tracepoint locations if they haven't been. */ |
12293 | ||
12294 | static void | |
12295 | download_tracepoint_locations (void) | |
12296 | { | |
7ed2c994 | 12297 | struct breakpoint *b; |
1e4d1764 | 12298 | struct cleanup *old_chain; |
dd2e65cc | 12299 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12300 | |
12301 | old_chain = save_current_space_and_thread (); | |
12302 | ||
7ed2c994 | 12303 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12304 | { |
7ed2c994 | 12305 | struct bp_location *bl; |
1e4d1764 | 12306 | struct tracepoint *t; |
f2a8bc8a | 12307 | int bp_location_downloaded = 0; |
1e4d1764 | 12308 | |
7ed2c994 | 12309 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12310 | ? !may_insert_fast_tracepoints |
12311 | : !may_insert_tracepoints)) | |
12312 | continue; | |
12313 | ||
dd2e65cc YQ |
12314 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12315 | { | |
12316 | if (target_can_download_tracepoint ()) | |
12317 | can_download_tracepoint = TRIBOOL_TRUE; | |
12318 | else | |
12319 | can_download_tracepoint = TRIBOOL_FALSE; | |
12320 | } | |
12321 | ||
12322 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12323 | break; | |
12324 | ||
7ed2c994 YQ |
12325 | for (bl = b->loc; bl; bl = bl->next) |
12326 | { | |
12327 | /* In tracepoint, locations are _never_ duplicated, so | |
12328 | should_be_inserted is equivalent to | |
12329 | unduplicated_should_be_inserted. */ | |
12330 | if (!should_be_inserted (bl) || bl->inserted) | |
12331 | continue; | |
1e4d1764 | 12332 | |
7ed2c994 | 12333 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12334 | |
7ed2c994 | 12335 | target_download_tracepoint (bl); |
1e4d1764 | 12336 | |
7ed2c994 | 12337 | bl->inserted = 1; |
f2a8bc8a | 12338 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12339 | } |
12340 | t = (struct tracepoint *) b; | |
12341 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12342 | if (bp_location_downloaded) |
12343 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12344 | } |
12345 | ||
12346 | do_cleanups (old_chain); | |
12347 | } | |
12348 | ||
934709f0 PW |
12349 | /* Swap the insertion/duplication state between two locations. */ |
12350 | ||
12351 | static void | |
12352 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12353 | { | |
12354 | const int left_inserted = left->inserted; | |
12355 | const int left_duplicate = left->duplicate; | |
b775012e | 12356 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12357 | const struct bp_target_info left_target_info = left->target_info; |
12358 | ||
1e4d1764 YQ |
12359 | /* Locations of tracepoints can never be duplicated. */ |
12360 | if (is_tracepoint (left->owner)) | |
12361 | gdb_assert (!left->duplicate); | |
12362 | if (is_tracepoint (right->owner)) | |
12363 | gdb_assert (!right->duplicate); | |
12364 | ||
934709f0 PW |
12365 | left->inserted = right->inserted; |
12366 | left->duplicate = right->duplicate; | |
b775012e | 12367 | left->needs_update = right->needs_update; |
934709f0 PW |
12368 | left->target_info = right->target_info; |
12369 | right->inserted = left_inserted; | |
12370 | right->duplicate = left_duplicate; | |
b775012e | 12371 | right->needs_update = left_needs_update; |
934709f0 PW |
12372 | right->target_info = left_target_info; |
12373 | } | |
12374 | ||
b775012e LM |
12375 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12376 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12377 | conditions on the target's side. Such conditions need to be updated on | |
12378 | the target. */ | |
12379 | ||
12380 | static void | |
12381 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12382 | { | |
12383 | struct bp_location **locp = NULL, **loc2p; | |
12384 | struct bp_location *loc; | |
12385 | CORE_ADDR address = 0; | |
12386 | int pspace_num; | |
12387 | ||
12388 | address = bl->address; | |
12389 | pspace_num = bl->pspace->num; | |
12390 | ||
12391 | /* This is only meaningful if the target is | |
12392 | evaluating conditions and if the user has | |
12393 | opted for condition evaluation on the target's | |
12394 | side. */ | |
12395 | if (gdb_evaluates_breakpoint_condition_p () | |
12396 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12397 | return; | |
12398 | ||
12399 | /* Flag all breakpoint locations with this address and | |
12400 | the same program space as the location | |
12401 | as "its condition has changed". We need to | |
12402 | update the conditions on the target's side. */ | |
12403 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12404 | { | |
12405 | loc = *loc2p; | |
12406 | ||
12407 | if (!is_breakpoint (loc->owner) | |
12408 | || pspace_num != loc->pspace->num) | |
12409 | continue; | |
12410 | ||
12411 | /* Flag the location appropriately. We use a different state to | |
12412 | let everyone know that we already updated the set of locations | |
12413 | with addr bl->address and program space bl->pspace. This is so | |
12414 | we don't have to keep calling these functions just to mark locations | |
12415 | that have already been marked. */ | |
12416 | loc->condition_changed = condition_updated; | |
12417 | ||
12418 | /* Free the agent expression bytecode as well. We will compute | |
12419 | it later on. */ | |
12420 | if (loc->cond_bytecode) | |
12421 | { | |
12422 | free_agent_expr (loc->cond_bytecode); | |
12423 | loc->cond_bytecode = NULL; | |
12424 | } | |
12425 | } | |
12426 | } | |
44702360 PA |
12427 | /* Called whether new breakpoints are created, or existing breakpoints |
12428 | deleted, to update the global location list and recompute which | |
12429 | locations are duplicate of which. | |
b775012e | 12430 | |
04086b45 PA |
12431 | The INSERT_MODE flag determines whether locations may not, may, or |
12432 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12433 | info. */ | |
b60e7edf | 12434 | |
0d381245 | 12435 | static void |
44702360 | 12436 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12437 | { |
74960c60 | 12438 | struct breakpoint *b; |
876fa593 | 12439 | struct bp_location **locp, *loc; |
f7545552 | 12440 | struct cleanup *cleanups; |
b775012e LM |
12441 | /* Last breakpoint location address that was marked for update. */ |
12442 | CORE_ADDR last_addr = 0; | |
12443 | /* Last breakpoint location program space that was marked for update. */ | |
12444 | int last_pspace_num = -1; | |
f7545552 | 12445 | |
2d134ed3 PA |
12446 | /* Used in the duplicates detection below. When iterating over all |
12447 | bp_locations, points to the first bp_location of a given address. | |
12448 | Breakpoints and watchpoints of different types are never | |
12449 | duplicates of each other. Keep one pointer for each type of | |
12450 | breakpoint/watchpoint, so we only need to loop over all locations | |
12451 | once. */ | |
12452 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12453 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12454 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12455 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12456 | |
4a64f543 MS |
12457 | /* Saved former bp_location array which we compare against the newly |
12458 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12459 | struct bp_location **old_location, **old_locp; |
12460 | unsigned old_location_count; | |
12461 | ||
12462 | old_location = bp_location; | |
12463 | old_location_count = bp_location_count; | |
12464 | bp_location = NULL; | |
12465 | bp_location_count = 0; | |
12466 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12467 | |
74960c60 | 12468 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12469 | for (loc = b->loc; loc; loc = loc->next) |
12470 | bp_location_count++; | |
12471 | ||
8d749320 | 12472 | bp_location = XNEWVEC (struct bp_location *, bp_location_count); |
876fa593 JK |
12473 | locp = bp_location; |
12474 | ALL_BREAKPOINTS (b) | |
12475 | for (loc = b->loc; loc; loc = loc->next) | |
12476 | *locp++ = loc; | |
12477 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12478 | bp_location_compare); |
876fa593 JK |
12479 | |
12480 | bp_location_target_extensions_update (); | |
74960c60 | 12481 | |
4a64f543 MS |
12482 | /* Identify bp_location instances that are no longer present in the |
12483 | new list, and therefore should be freed. Note that it's not | |
12484 | necessary that those locations should be removed from inferior -- | |
12485 | if there's another location at the same address (previously | |
12486 | marked as duplicate), we don't need to remove/insert the | |
12487 | location. | |
876fa593 | 12488 | |
4a64f543 MS |
12489 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12490 | and former bp_location array state respectively. */ | |
876fa593 JK |
12491 | |
12492 | locp = bp_location; | |
12493 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12494 | old_locp++) | |
74960c60 | 12495 | { |
876fa593 | 12496 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12497 | struct bp_location **loc2p; |
876fa593 | 12498 | |
e5dd4106 | 12499 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12500 | not, we have to free it. */ |
c7d46a38 | 12501 | int found_object = 0; |
20874c92 VP |
12502 | /* Tells if the location should remain inserted in the target. */ |
12503 | int keep_in_target = 0; | |
12504 | int removed = 0; | |
876fa593 | 12505 | |
4a64f543 MS |
12506 | /* Skip LOCP entries which will definitely never be needed. |
12507 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12508 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12509 | && (*locp)->address < old_loc->address) |
876fa593 | 12510 | locp++; |
c7d46a38 PA |
12511 | |
12512 | for (loc2p = locp; | |
12513 | (loc2p < bp_location + bp_location_count | |
12514 | && (*loc2p)->address == old_loc->address); | |
12515 | loc2p++) | |
12516 | { | |
b775012e LM |
12517 | /* Check if this is a new/duplicated location or a duplicated |
12518 | location that had its condition modified. If so, we want to send | |
12519 | its condition to the target if evaluation of conditions is taking | |
12520 | place there. */ | |
12521 | if ((*loc2p)->condition_changed == condition_modified | |
12522 | && (last_addr != old_loc->address | |
12523 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12524 | { |
b775012e LM |
12525 | force_breakpoint_reinsertion (*loc2p); |
12526 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12527 | } |
b775012e LM |
12528 | |
12529 | if (*loc2p == old_loc) | |
12530 | found_object = 1; | |
c7d46a38 | 12531 | } |
74960c60 | 12532 | |
b775012e LM |
12533 | /* We have already handled this address, update it so that we don't |
12534 | have to go through updates again. */ | |
12535 | last_addr = old_loc->address; | |
12536 | ||
12537 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12538 | if (!found_object) | |
12539 | force_breakpoint_reinsertion (old_loc); | |
12540 | ||
4a64f543 MS |
12541 | /* If this location is no longer present, and inserted, look if |
12542 | there's maybe a new location at the same address. If so, | |
12543 | mark that one inserted, and don't remove this one. This is | |
12544 | needed so that we don't have a time window where a breakpoint | |
12545 | at certain location is not inserted. */ | |
74960c60 | 12546 | |
876fa593 | 12547 | if (old_loc->inserted) |
0d381245 | 12548 | { |
4a64f543 MS |
12549 | /* If the location is inserted now, we might have to remove |
12550 | it. */ | |
74960c60 | 12551 | |
876fa593 | 12552 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12553 | { |
4a64f543 MS |
12554 | /* The location is still present in the location list, |
12555 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12556 | keep_in_target = 1; |
74960c60 VP |
12557 | } |
12558 | else | |
12559 | { | |
b775012e LM |
12560 | /* This location still exists, but it won't be kept in the |
12561 | target since it may have been disabled. We proceed to | |
12562 | remove its target-side condition. */ | |
12563 | ||
4a64f543 MS |
12564 | /* The location is either no longer present, or got |
12565 | disabled. See if there's another location at the | |
12566 | same address, in which case we don't need to remove | |
12567 | this one from the target. */ | |
876fa593 | 12568 | |
2bdf28a0 | 12569 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12570 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12571 | { | |
876fa593 | 12572 | for (loc2p = locp; |
c7d46a38 PA |
12573 | (loc2p < bp_location + bp_location_count |
12574 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12575 | loc2p++) |
12576 | { | |
12577 | struct bp_location *loc2 = *loc2p; | |
12578 | ||
2d134ed3 | 12579 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12580 | { |
85d721b8 PA |
12581 | /* Read watchpoint locations are switched to |
12582 | access watchpoints, if the former are not | |
12583 | supported, but the latter are. */ | |
12584 | if (is_hardware_watchpoint (old_loc->owner)) | |
12585 | { | |
12586 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12587 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12588 | } | |
12589 | ||
934709f0 PW |
12590 | /* loc2 is a duplicated location. We need to check |
12591 | if it should be inserted in case it will be | |
12592 | unduplicated. */ | |
12593 | if (loc2 != old_loc | |
12594 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12595 | { |
934709f0 | 12596 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12597 | keep_in_target = 1; |
12598 | break; | |
12599 | } | |
876fa593 JK |
12600 | } |
12601 | } | |
12602 | } | |
74960c60 VP |
12603 | } |
12604 | ||
20874c92 VP |
12605 | if (!keep_in_target) |
12606 | { | |
834c0d03 | 12607 | if (remove_breakpoint (old_loc)) |
20874c92 | 12608 | { |
4a64f543 MS |
12609 | /* This is just about all we can do. We could keep |
12610 | this location on the global list, and try to | |
12611 | remove it next time, but there's no particular | |
12612 | reason why we will succeed next time. | |
20874c92 | 12613 | |
4a64f543 MS |
12614 | Note that at this point, old_loc->owner is still |
12615 | valid, as delete_breakpoint frees the breakpoint | |
12616 | only after calling us. */ | |
3e43a32a MS |
12617 | printf_filtered (_("warning: Error removing " |
12618 | "breakpoint %d\n"), | |
876fa593 | 12619 | old_loc->owner->number); |
20874c92 VP |
12620 | } |
12621 | removed = 1; | |
12622 | } | |
0d381245 | 12623 | } |
74960c60 VP |
12624 | |
12625 | if (!found_object) | |
1c5cfe86 | 12626 | { |
fbea99ea | 12627 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12628 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12629 | { |
db82e815 PA |
12630 | /* This location was removed from the target. In |
12631 | non-stop mode, a race condition is possible where | |
12632 | we've removed a breakpoint, but stop events for that | |
12633 | breakpoint are already queued and will arrive later. | |
12634 | We apply an heuristic to be able to distinguish such | |
12635 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12636 | breakpoint location for a bit, and will retire it | |
12637 | after we see some number of events. The theory here | |
12638 | is that reporting of events should, "on the average", | |
12639 | be fair, so after a while we'll see events from all | |
12640 | threads that have anything of interest, and no longer | |
12641 | need to keep this breakpoint location around. We | |
12642 | don't hold locations forever so to reduce chances of | |
12643 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12644 | SIGTRAP. | |
12645 | ||
12646 | The heuristic failing can be disastrous on | |
12647 | decr_pc_after_break targets. | |
12648 | ||
12649 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12650 | if we fail to recognize a late breakpoint SIGTRAP, | |
12651 | because events_till_retirement has reached 0 too | |
12652 | soon, we'll fail to do the PC adjustment, and report | |
12653 | a random SIGTRAP to the user. When the user resumes | |
12654 | the inferior, it will most likely immediately crash | |
2dec564e | 12655 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12656 | corrupted, because of being resumed e.g., in the |
12657 | middle of a multi-byte instruction, or skipped a | |
12658 | one-byte instruction. This was actually seen happen | |
12659 | on native x86-linux, and should be less rare on | |
12660 | targets that do not support new thread events, like | |
12661 | remote, due to the heuristic depending on | |
12662 | thread_count. | |
12663 | ||
12664 | Mistaking a random SIGTRAP for a breakpoint trap | |
12665 | causes similar symptoms (PC adjustment applied when | |
12666 | it shouldn't), but then again, playing with SIGTRAPs | |
12667 | behind the debugger's back is asking for trouble. | |
12668 | ||
12669 | Since hardware watchpoint traps are always | |
12670 | distinguishable from other traps, so we don't need to | |
12671 | apply keep hardware watchpoint moribund locations | |
12672 | around. We simply always ignore hardware watchpoint | |
12673 | traps we can no longer explain. */ | |
12674 | ||
876fa593 JK |
12675 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12676 | old_loc->owner = NULL; | |
20874c92 | 12677 | |
876fa593 | 12678 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12679 | } |
12680 | else | |
f431efe5 PA |
12681 | { |
12682 | old_loc->owner = NULL; | |
12683 | decref_bp_location (&old_loc); | |
12684 | } | |
20874c92 | 12685 | } |
74960c60 | 12686 | } |
1c5cfe86 | 12687 | |
348d480f PA |
12688 | /* Rescan breakpoints at the same address and section, marking the |
12689 | first one as "first" and any others as "duplicates". This is so | |
12690 | that the bpt instruction is only inserted once. If we have a | |
12691 | permanent breakpoint at the same place as BPT, make that one the | |
12692 | official one, and the rest as duplicates. Permanent breakpoints | |
12693 | are sorted first for the same address. | |
12694 | ||
12695 | Do the same for hardware watchpoints, but also considering the | |
12696 | watchpoint's type (regular/access/read) and length. */ | |
12697 | ||
12698 | bp_loc_first = NULL; | |
12699 | wp_loc_first = NULL; | |
12700 | awp_loc_first = NULL; | |
12701 | rwp_loc_first = NULL; | |
12702 | ALL_BP_LOCATIONS (loc, locp) | |
12703 | { | |
12704 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12705 | non-NULL. */ | |
348d480f | 12706 | struct bp_location **loc_first_p; |
d3fbdd86 | 12707 | b = loc->owner; |
348d480f | 12708 | |
6f380991 | 12709 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12710 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12711 | /* Don't detect duplicate for tracepoint locations because they are |
12712 | never duplicated. See the comments in field `duplicate' of | |
12713 | `struct bp_location'. */ | |
348d480f | 12714 | || is_tracepoint (b)) |
b775012e LM |
12715 | { |
12716 | /* Clear the condition modification flag. */ | |
12717 | loc->condition_changed = condition_unchanged; | |
12718 | continue; | |
12719 | } | |
348d480f | 12720 | |
348d480f PA |
12721 | if (b->type == bp_hardware_watchpoint) |
12722 | loc_first_p = &wp_loc_first; | |
12723 | else if (b->type == bp_read_watchpoint) | |
12724 | loc_first_p = &rwp_loc_first; | |
12725 | else if (b->type == bp_access_watchpoint) | |
12726 | loc_first_p = &awp_loc_first; | |
12727 | else | |
12728 | loc_first_p = &bp_loc_first; | |
12729 | ||
12730 | if (*loc_first_p == NULL | |
12731 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12732 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12733 | { | |
12734 | *loc_first_p = loc; | |
12735 | loc->duplicate = 0; | |
b775012e LM |
12736 | |
12737 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12738 | { | |
12739 | loc->needs_update = 1; | |
12740 | /* Clear the condition modification flag. */ | |
12741 | loc->condition_changed = condition_unchanged; | |
12742 | } | |
348d480f PA |
12743 | continue; |
12744 | } | |
12745 | ||
934709f0 PW |
12746 | |
12747 | /* This and the above ensure the invariant that the first location | |
12748 | is not duplicated, and is the inserted one. | |
12749 | All following are marked as duplicated, and are not inserted. */ | |
12750 | if (loc->inserted) | |
12751 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12752 | loc->duplicate = 1; |
12753 | ||
b775012e LM |
12754 | /* Clear the condition modification flag. */ |
12755 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12756 | } |
12757 | ||
a25a5a45 | 12758 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12759 | { |
04086b45 | 12760 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12761 | insert_breakpoint_locations (); |
12762 | else | |
12763 | { | |
44702360 PA |
12764 | /* Even though the caller told us to not insert new |
12765 | locations, we may still need to update conditions on the | |
12766 | target's side of breakpoints that were already inserted | |
12767 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12768 | only update conditions for locations that are marked |
12769 | "needs_update". */ | |
12770 | update_inserted_breakpoint_locations (); | |
12771 | } | |
12772 | } | |
348d480f | 12773 | |
04086b45 | 12774 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12775 | download_tracepoint_locations (); |
12776 | ||
348d480f PA |
12777 | do_cleanups (cleanups); |
12778 | } | |
12779 | ||
12780 | void | |
12781 | breakpoint_retire_moribund (void) | |
12782 | { | |
12783 | struct bp_location *loc; | |
12784 | int ix; | |
12785 | ||
12786 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12787 | if (--(loc->events_till_retirement) == 0) | |
12788 | { | |
12789 | decref_bp_location (&loc); | |
12790 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12791 | --ix; | |
12792 | } | |
12793 | } | |
12794 | ||
12795 | static void | |
44702360 | 12796 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12797 | { |
348d480f | 12798 | |
492d29ea PA |
12799 | TRY |
12800 | { | |
12801 | update_global_location_list (insert_mode); | |
12802 | } | |
12803 | CATCH (e, RETURN_MASK_ERROR) | |
12804 | { | |
12805 | } | |
12806 | END_CATCH | |
348d480f PA |
12807 | } |
12808 | ||
12809 | /* Clear BKP from a BPS. */ | |
12810 | ||
12811 | static void | |
12812 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12813 | { | |
12814 | bpstat bs; | |
12815 | ||
12816 | for (bs = bps; bs; bs = bs->next) | |
12817 | if (bs->breakpoint_at == bpt) | |
12818 | { | |
12819 | bs->breakpoint_at = NULL; | |
12820 | bs->old_val = NULL; | |
12821 | /* bs->commands will be freed later. */ | |
12822 | } | |
12823 | } | |
12824 | ||
12825 | /* Callback for iterate_over_threads. */ | |
12826 | static int | |
12827 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12828 | { | |
9a3c8263 | 12829 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12830 | |
12831 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12832 | return 0; | |
12833 | } | |
12834 | ||
12835 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12836 | callbacks. */ | |
12837 | ||
12838 | static void | |
12839 | say_where (struct breakpoint *b) | |
12840 | { | |
12841 | struct value_print_options opts; | |
12842 | ||
12843 | get_user_print_options (&opts); | |
12844 | ||
12845 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12846 | single string. */ | |
12847 | if (b->loc == NULL) | |
12848 | { | |
f00aae0f KS |
12849 | /* For pending locations, the output differs slightly based |
12850 | on b->extra_string. If this is non-NULL, it contains either | |
12851 | a condition or dprintf arguments. */ | |
12852 | if (b->extra_string == NULL) | |
12853 | { | |
12854 | printf_filtered (_(" (%s) pending."), | |
12855 | event_location_to_string (b->location)); | |
12856 | } | |
12857 | else if (b->type == bp_dprintf) | |
12858 | { | |
12859 | printf_filtered (_(" (%s,%s) pending."), | |
12860 | event_location_to_string (b->location), | |
12861 | b->extra_string); | |
12862 | } | |
12863 | else | |
12864 | { | |
12865 | printf_filtered (_(" (%s %s) pending."), | |
12866 | event_location_to_string (b->location), | |
12867 | b->extra_string); | |
12868 | } | |
348d480f PA |
12869 | } |
12870 | else | |
12871 | { | |
2f202fde | 12872 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12873 | { |
12874 | printf_filtered (" at "); | |
12875 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12876 | gdb_stdout); | |
12877 | } | |
2f202fde | 12878 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12879 | { |
12880 | /* If there is a single location, we can print the location | |
12881 | more nicely. */ | |
12882 | if (b->loc->next == NULL) | |
12883 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12884 | symtab_to_filename_for_display (b->loc->symtab), |
12885 | b->loc->line_number); | |
f8eba3c6 TT |
12886 | else |
12887 | /* This is not ideal, but each location may have a | |
12888 | different file name, and this at least reflects the | |
12889 | real situation somewhat. */ | |
f00aae0f KS |
12890 | printf_filtered (": %s.", |
12891 | event_location_to_string (b->location)); | |
f8eba3c6 | 12892 | } |
348d480f PA |
12893 | |
12894 | if (b->loc->next) | |
12895 | { | |
12896 | struct bp_location *loc = b->loc; | |
12897 | int n = 0; | |
12898 | for (; loc; loc = loc->next) | |
12899 | ++n; | |
12900 | printf_filtered (" (%d locations)", n); | |
12901 | } | |
12902 | } | |
12903 | } | |
12904 | ||
348d480f PA |
12905 | /* Default bp_location_ops methods. */ |
12906 | ||
12907 | static void | |
12908 | bp_location_dtor (struct bp_location *self) | |
12909 | { | |
12910 | xfree (self->cond); | |
b775012e LM |
12911 | if (self->cond_bytecode) |
12912 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12913 | xfree (self->function_name); |
8b4f3082 PA |
12914 | |
12915 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12916 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12917 | } |
12918 | ||
12919 | static const struct bp_location_ops bp_location_ops = | |
12920 | { | |
12921 | bp_location_dtor | |
12922 | }; | |
12923 | ||
2060206e PA |
12924 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12925 | inherit from. */ | |
348d480f | 12926 | |
2060206e PA |
12927 | static void |
12928 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12929 | { |
12930 | decref_counted_command_line (&self->commands); | |
12931 | xfree (self->cond_string); | |
fb81d016 | 12932 | xfree (self->extra_string); |
f8eba3c6 | 12933 | xfree (self->filter); |
f00aae0f KS |
12934 | delete_event_location (self->location); |
12935 | delete_event_location (self->location_range_end); | |
348d480f PA |
12936 | } |
12937 | ||
2060206e PA |
12938 | static struct bp_location * |
12939 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12940 | { |
12941 | struct bp_location *loc; | |
12942 | ||
12943 | loc = XNEW (struct bp_location); | |
12944 | init_bp_location (loc, &bp_location_ops, self); | |
12945 | return loc; | |
12946 | } | |
12947 | ||
2060206e PA |
12948 | static void |
12949 | base_breakpoint_re_set (struct breakpoint *b) | |
12950 | { | |
12951 | /* Nothing to re-set. */ | |
12952 | } | |
12953 | ||
12954 | #define internal_error_pure_virtual_called() \ | |
12955 | gdb_assert_not_reached ("pure virtual function called") | |
12956 | ||
12957 | static int | |
12958 | base_breakpoint_insert_location (struct bp_location *bl) | |
12959 | { | |
12960 | internal_error_pure_virtual_called (); | |
12961 | } | |
12962 | ||
12963 | static int | |
73971819 PA |
12964 | base_breakpoint_remove_location (struct bp_location *bl, |
12965 | enum remove_bp_reason reason) | |
2060206e PA |
12966 | { |
12967 | internal_error_pure_virtual_called (); | |
12968 | } | |
12969 | ||
12970 | static int | |
12971 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12972 | struct address_space *aspace, | |
09ac7c10 TT |
12973 | CORE_ADDR bp_addr, |
12974 | const struct target_waitstatus *ws) | |
2060206e PA |
12975 | { |
12976 | internal_error_pure_virtual_called (); | |
12977 | } | |
12978 | ||
12979 | static void | |
12980 | base_breakpoint_check_status (bpstat bs) | |
12981 | { | |
12982 | /* Always stop. */ | |
12983 | } | |
12984 | ||
12985 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12986 | errors. */ | |
12987 | ||
12988 | static int | |
12989 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12990 | { | |
12991 | internal_error_pure_virtual_called (); | |
12992 | } | |
12993 | ||
12994 | /* A "resources_needed" breakpoint_ops method that just internal | |
12995 | errors. */ | |
12996 | ||
12997 | static int | |
12998 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12999 | { | |
13000 | internal_error_pure_virtual_called (); | |
13001 | } | |
13002 | ||
13003 | static enum print_stop_action | |
13004 | base_breakpoint_print_it (bpstat bs) | |
13005 | { | |
13006 | internal_error_pure_virtual_called (); | |
13007 | } | |
13008 | ||
13009 | static void | |
13010 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
13011 | struct ui_out *uiout) | |
13012 | { | |
13013 | /* nothing */ | |
13014 | } | |
13015 | ||
13016 | static void | |
13017 | base_breakpoint_print_mention (struct breakpoint *b) | |
13018 | { | |
13019 | internal_error_pure_virtual_called (); | |
13020 | } | |
13021 | ||
13022 | static void | |
13023 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13024 | { | |
13025 | internal_error_pure_virtual_called (); | |
13026 | } | |
13027 | ||
983af33b | 13028 | static void |
f00aae0f KS |
13029 | base_breakpoint_create_sals_from_location |
13030 | (const struct event_location *location, | |
13031 | struct linespec_result *canonical, | |
13032 | enum bptype type_wanted) | |
983af33b SDJ |
13033 | { |
13034 | internal_error_pure_virtual_called (); | |
13035 | } | |
13036 | ||
13037 | static void | |
13038 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13039 | struct linespec_result *c, | |
983af33b | 13040 | char *cond_string, |
e7e0cddf | 13041 | char *extra_string, |
983af33b SDJ |
13042 | enum bptype type_wanted, |
13043 | enum bpdisp disposition, | |
13044 | int thread, | |
13045 | int task, int ignore_count, | |
13046 | const struct breakpoint_ops *o, | |
13047 | int from_tty, int enabled, | |
44f238bb | 13048 | int internal, unsigned flags) |
983af33b SDJ |
13049 | { |
13050 | internal_error_pure_virtual_called (); | |
13051 | } | |
13052 | ||
13053 | static void | |
f00aae0f KS |
13054 | base_breakpoint_decode_location (struct breakpoint *b, |
13055 | const struct event_location *location, | |
c2f4122d | 13056 | struct program_space *search_pspace, |
983af33b SDJ |
13057 | struct symtabs_and_lines *sals) |
13058 | { | |
13059 | internal_error_pure_virtual_called (); | |
13060 | } | |
13061 | ||
ab04a2af TT |
13062 | /* The default 'explains_signal' method. */ |
13063 | ||
47591c29 | 13064 | static int |
427cd150 | 13065 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13066 | { |
47591c29 | 13067 | return 1; |
ab04a2af TT |
13068 | } |
13069 | ||
9d6e6e84 HZ |
13070 | /* The default "after_condition_true" method. */ |
13071 | ||
13072 | static void | |
13073 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13074 | { | |
13075 | /* Nothing to do. */ | |
13076 | } | |
13077 | ||
ab04a2af | 13078 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13079 | { |
13080 | base_breakpoint_dtor, | |
13081 | base_breakpoint_allocate_location, | |
13082 | base_breakpoint_re_set, | |
13083 | base_breakpoint_insert_location, | |
13084 | base_breakpoint_remove_location, | |
13085 | base_breakpoint_breakpoint_hit, | |
13086 | base_breakpoint_check_status, | |
13087 | base_breakpoint_resources_needed, | |
13088 | base_breakpoint_works_in_software_mode, | |
13089 | base_breakpoint_print_it, | |
13090 | NULL, | |
13091 | base_breakpoint_print_one_detail, | |
13092 | base_breakpoint_print_mention, | |
983af33b | 13093 | base_breakpoint_print_recreate, |
5f700d83 | 13094 | base_breakpoint_create_sals_from_location, |
983af33b | 13095 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 13096 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
13097 | base_breakpoint_explains_signal, |
13098 | base_breakpoint_after_condition_true, | |
2060206e PA |
13099 | }; |
13100 | ||
13101 | /* Default breakpoint_ops methods. */ | |
13102 | ||
13103 | static void | |
348d480f PA |
13104 | bkpt_re_set (struct breakpoint *b) |
13105 | { | |
06edf0c0 | 13106 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 13107 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 13108 | { |
f00aae0f | 13109 | /* Anything without a location can't be re-set. */ |
348d480f | 13110 | delete_breakpoint (b); |
06edf0c0 | 13111 | return; |
348d480f | 13112 | } |
06edf0c0 PA |
13113 | |
13114 | breakpoint_re_set_default (b); | |
348d480f PA |
13115 | } |
13116 | ||
2060206e | 13117 | static int |
348d480f PA |
13118 | bkpt_insert_location (struct bp_location *bl) |
13119 | { | |
13120 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 13121 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13122 | else |
7c16b83e | 13123 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13124 | } |
13125 | ||
2060206e | 13126 | static int |
73971819 | 13127 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
13128 | { |
13129 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13130 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13131 | else | |
73971819 | 13132 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
13133 | } |
13134 | ||
2060206e | 13135 | static int |
348d480f | 13136 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13137 | struct address_space *aspace, CORE_ADDR bp_addr, |
13138 | const struct target_waitstatus *ws) | |
348d480f | 13139 | { |
09ac7c10 | 13140 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13141 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13142 | return 0; |
13143 | ||
348d480f PA |
13144 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13145 | aspace, bp_addr)) | |
13146 | return 0; | |
13147 | ||
13148 | if (overlay_debugging /* unmapped overlay section */ | |
13149 | && section_is_overlay (bl->section) | |
13150 | && !section_is_mapped (bl->section)) | |
13151 | return 0; | |
13152 | ||
13153 | return 1; | |
13154 | } | |
13155 | ||
cd1608cc PA |
13156 | static int |
13157 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13158 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13159 | const struct target_waitstatus *ws) | |
13160 | { | |
13161 | if (dprintf_style == dprintf_style_agent | |
13162 | && target_can_run_breakpoint_commands ()) | |
13163 | { | |
13164 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13165 | for this address it must be for a breakpoint that happens to | |
13166 | be set at the same address. */ | |
13167 | return 0; | |
13168 | } | |
13169 | ||
13170 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13171 | } | |
13172 | ||
2060206e | 13173 | static int |
348d480f PA |
13174 | bkpt_resources_needed (const struct bp_location *bl) |
13175 | { | |
13176 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13177 | ||
13178 | return 1; | |
13179 | } | |
13180 | ||
2060206e | 13181 | static enum print_stop_action |
348d480f PA |
13182 | bkpt_print_it (bpstat bs) |
13183 | { | |
348d480f PA |
13184 | struct breakpoint *b; |
13185 | const struct bp_location *bl; | |
001c8c33 | 13186 | int bp_temp; |
79a45e25 | 13187 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13188 | |
13189 | gdb_assert (bs->bp_location_at != NULL); | |
13190 | ||
13191 | bl = bs->bp_location_at; | |
13192 | b = bs->breakpoint_at; | |
13193 | ||
001c8c33 PA |
13194 | bp_temp = b->disposition == disp_del; |
13195 | if (bl->address != bl->requested_address) | |
13196 | breakpoint_adjustment_warning (bl->requested_address, | |
13197 | bl->address, | |
13198 | b->number, 1); | |
13199 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
13200 | maybe_print_thread_hit_breakpoint (uiout); |
13201 | ||
001c8c33 | 13202 | if (bp_temp) |
f303dbd6 | 13203 | ui_out_text (uiout, "Temporary breakpoint "); |
001c8c33 | 13204 | else |
f303dbd6 | 13205 | ui_out_text (uiout, "Breakpoint "); |
001c8c33 | 13206 | if (ui_out_is_mi_like_p (uiout)) |
348d480f | 13207 | { |
001c8c33 PA |
13208 | ui_out_field_string (uiout, "reason", |
13209 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13210 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13211 | } |
001c8c33 PA |
13212 | ui_out_field_int (uiout, "bkptno", b->number); |
13213 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13214 | |
001c8c33 | 13215 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13216 | } |
13217 | ||
2060206e | 13218 | static void |
06edf0c0 PA |
13219 | bkpt_print_mention (struct breakpoint *b) |
13220 | { | |
79a45e25 | 13221 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13222 | return; |
13223 | ||
13224 | switch (b->type) | |
13225 | { | |
13226 | case bp_breakpoint: | |
13227 | case bp_gnu_ifunc_resolver: | |
13228 | if (b->disposition == disp_del) | |
13229 | printf_filtered (_("Temporary breakpoint")); | |
13230 | else | |
13231 | printf_filtered (_("Breakpoint")); | |
13232 | printf_filtered (_(" %d"), b->number); | |
13233 | if (b->type == bp_gnu_ifunc_resolver) | |
13234 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13235 | break; | |
13236 | case bp_hardware_breakpoint: | |
13237 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13238 | break; | |
e7e0cddf SS |
13239 | case bp_dprintf: |
13240 | printf_filtered (_("Dprintf %d"), b->number); | |
13241 | break; | |
06edf0c0 PA |
13242 | } |
13243 | ||
13244 | say_where (b); | |
13245 | } | |
13246 | ||
2060206e | 13247 | static void |
06edf0c0 PA |
13248 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13249 | { | |
13250 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13251 | fprintf_unfiltered (fp, "tbreak"); | |
13252 | else if (tp->type == bp_breakpoint) | |
13253 | fprintf_unfiltered (fp, "break"); | |
13254 | else if (tp->type == bp_hardware_breakpoint | |
13255 | && tp->disposition == disp_del) | |
13256 | fprintf_unfiltered (fp, "thbreak"); | |
13257 | else if (tp->type == bp_hardware_breakpoint) | |
13258 | fprintf_unfiltered (fp, "hbreak"); | |
13259 | else | |
13260 | internal_error (__FILE__, __LINE__, | |
13261 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13262 | ||
f00aae0f KS |
13263 | fprintf_unfiltered (fp, " %s", |
13264 | event_location_to_string (tp->location)); | |
13265 | ||
13266 | /* Print out extra_string if this breakpoint is pending. It might | |
13267 | contain, for example, conditions that were set by the user. */ | |
13268 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13269 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13270 | ||
dd11a36c | 13271 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13272 | } |
13273 | ||
983af33b | 13274 | static void |
f00aae0f KS |
13275 | bkpt_create_sals_from_location (const struct event_location *location, |
13276 | struct linespec_result *canonical, | |
13277 | enum bptype type_wanted) | |
983af33b | 13278 | { |
f00aae0f | 13279 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13280 | } |
13281 | ||
13282 | static void | |
13283 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13284 | struct linespec_result *canonical, | |
983af33b | 13285 | char *cond_string, |
e7e0cddf | 13286 | char *extra_string, |
983af33b SDJ |
13287 | enum bptype type_wanted, |
13288 | enum bpdisp disposition, | |
13289 | int thread, | |
13290 | int task, int ignore_count, | |
13291 | const struct breakpoint_ops *ops, | |
13292 | int from_tty, int enabled, | |
44f238bb | 13293 | int internal, unsigned flags) |
983af33b | 13294 | { |
023fa29b | 13295 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13296 | cond_string, extra_string, |
13297 | type_wanted, | |
983af33b SDJ |
13298 | disposition, thread, task, |
13299 | ignore_count, ops, from_tty, | |
44f238bb | 13300 | enabled, internal, flags); |
983af33b SDJ |
13301 | } |
13302 | ||
13303 | static void | |
f00aae0f KS |
13304 | bkpt_decode_location (struct breakpoint *b, |
13305 | const struct event_location *location, | |
c2f4122d | 13306 | struct program_space *search_pspace, |
983af33b SDJ |
13307 | struct symtabs_and_lines *sals) |
13308 | { | |
c2f4122d | 13309 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13310 | } |
13311 | ||
06edf0c0 PA |
13312 | /* Virtual table for internal breakpoints. */ |
13313 | ||
13314 | static void | |
13315 | internal_bkpt_re_set (struct breakpoint *b) | |
13316 | { | |
13317 | switch (b->type) | |
13318 | { | |
13319 | /* Delete overlay event and longjmp master breakpoints; they | |
13320 | will be reset later by breakpoint_re_set. */ | |
13321 | case bp_overlay_event: | |
13322 | case bp_longjmp_master: | |
13323 | case bp_std_terminate_master: | |
13324 | case bp_exception_master: | |
13325 | delete_breakpoint (b); | |
13326 | break; | |
13327 | ||
13328 | /* This breakpoint is special, it's set up when the inferior | |
13329 | starts and we really don't want to touch it. */ | |
13330 | case bp_shlib_event: | |
13331 | ||
13332 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13333 | it is set up, we do not want to touch it. */ | |
13334 | case bp_thread_event: | |
13335 | break; | |
13336 | } | |
13337 | } | |
13338 | ||
13339 | static void | |
13340 | internal_bkpt_check_status (bpstat bs) | |
13341 | { | |
a9b3a50f PA |
13342 | if (bs->breakpoint_at->type == bp_shlib_event) |
13343 | { | |
13344 | /* If requested, stop when the dynamic linker notifies GDB of | |
13345 | events. This allows the user to get control and place | |
13346 | breakpoints in initializer routines for dynamically loaded | |
13347 | objects (among other things). */ | |
13348 | bs->stop = stop_on_solib_events; | |
13349 | bs->print = stop_on_solib_events; | |
13350 | } | |
13351 | else | |
13352 | bs->stop = 0; | |
06edf0c0 PA |
13353 | } |
13354 | ||
13355 | static enum print_stop_action | |
13356 | internal_bkpt_print_it (bpstat bs) | |
13357 | { | |
06edf0c0 | 13358 | struct breakpoint *b; |
06edf0c0 | 13359 | |
06edf0c0 PA |
13360 | b = bs->breakpoint_at; |
13361 | ||
06edf0c0 PA |
13362 | switch (b->type) |
13363 | { | |
348d480f PA |
13364 | case bp_shlib_event: |
13365 | /* Did we stop because the user set the stop_on_solib_events | |
13366 | variable? (If so, we report this as a generic, "Stopped due | |
13367 | to shlib event" message.) */ | |
edcc5120 | 13368 | print_solib_event (0); |
348d480f PA |
13369 | break; |
13370 | ||
13371 | case bp_thread_event: | |
13372 | /* Not sure how we will get here. | |
13373 | GDB should not stop for these breakpoints. */ | |
13374 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13375 | break; |
13376 | ||
13377 | case bp_overlay_event: | |
13378 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13379 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13380 | break; |
13381 | ||
13382 | case bp_longjmp_master: | |
13383 | /* These should never be enabled. */ | |
13384 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13385 | break; |
13386 | ||
13387 | case bp_std_terminate_master: | |
13388 | /* These should never be enabled. */ | |
13389 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13390 | "gdb should not stop!\n")); | |
348d480f PA |
13391 | break; |
13392 | ||
13393 | case bp_exception_master: | |
13394 | /* These should never be enabled. */ | |
13395 | printf_filtered (_("Exception Master Breakpoint: " | |
13396 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13397 | break; |
13398 | } | |
13399 | ||
001c8c33 | 13400 | return PRINT_NOTHING; |
06edf0c0 PA |
13401 | } |
13402 | ||
13403 | static void | |
13404 | internal_bkpt_print_mention (struct breakpoint *b) | |
13405 | { | |
13406 | /* Nothing to mention. These breakpoints are internal. */ | |
13407 | } | |
13408 | ||
06edf0c0 PA |
13409 | /* Virtual table for momentary breakpoints */ |
13410 | ||
13411 | static void | |
13412 | momentary_bkpt_re_set (struct breakpoint *b) | |
13413 | { | |
13414 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13415 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13416 | Otherwise these should have been blown away via the cleanup chain |
13417 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13418 | } | |
13419 | ||
13420 | static void | |
13421 | momentary_bkpt_check_status (bpstat bs) | |
13422 | { | |
13423 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13424 | } | |
13425 | ||
13426 | static enum print_stop_action | |
13427 | momentary_bkpt_print_it (bpstat bs) | |
13428 | { | |
001c8c33 | 13429 | return PRINT_UNKNOWN; |
348d480f PA |
13430 | } |
13431 | ||
06edf0c0 PA |
13432 | static void |
13433 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13434 | { |
06edf0c0 | 13435 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13436 | } |
13437 | ||
e2e4d78b JK |
13438 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13439 | ||
13440 | It gets cleared already on the removal of the first one of such placed | |
13441 | breakpoints. This is OK as they get all removed altogether. */ | |
13442 | ||
13443 | static void | |
13444 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13445 | { | |
5d5658a1 | 13446 | struct thread_info *tp = find_thread_global_id (self->thread); |
e2e4d78b JK |
13447 | |
13448 | if (tp) | |
13449 | tp->initiating_frame = null_frame_id; | |
13450 | ||
13451 | momentary_breakpoint_ops.dtor (self); | |
13452 | } | |
13453 | ||
55aa24fb SDJ |
13454 | /* Specific methods for probe breakpoints. */ |
13455 | ||
13456 | static int | |
13457 | bkpt_probe_insert_location (struct bp_location *bl) | |
13458 | { | |
13459 | int v = bkpt_insert_location (bl); | |
13460 | ||
13461 | if (v == 0) | |
13462 | { | |
13463 | /* The insertion was successful, now let's set the probe's semaphore | |
13464 | if needed. */ | |
0ea5cda8 SDJ |
13465 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13466 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13467 | bl->probe.objfile, | |
13468 | bl->gdbarch); | |
55aa24fb SDJ |
13469 | } |
13470 | ||
13471 | return v; | |
13472 | } | |
13473 | ||
13474 | static int | |
73971819 PA |
13475 | bkpt_probe_remove_location (struct bp_location *bl, |
13476 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13477 | { |
13478 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13479 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13480 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13481 | bl->probe.objfile, | |
13482 | bl->gdbarch); | |
55aa24fb | 13483 | |
73971819 | 13484 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13485 | } |
13486 | ||
13487 | static void | |
f00aae0f | 13488 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13489 | struct linespec_result *canonical, |
f00aae0f | 13490 | enum bptype type_wanted) |
55aa24fb SDJ |
13491 | { |
13492 | struct linespec_sals lsal; | |
13493 | ||
c2f4122d | 13494 | lsal.sals = parse_probes (location, NULL, canonical); |
f00aae0f | 13495 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
55aa24fb SDJ |
13496 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13497 | } | |
13498 | ||
13499 | static void | |
f00aae0f KS |
13500 | bkpt_probe_decode_location (struct breakpoint *b, |
13501 | const struct event_location *location, | |
c2f4122d | 13502 | struct program_space *search_pspace, |
55aa24fb SDJ |
13503 | struct symtabs_and_lines *sals) |
13504 | { | |
c2f4122d | 13505 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13506 | if (!sals->sals) |
13507 | error (_("probe not found")); | |
13508 | } | |
13509 | ||
348d480f | 13510 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13511 | |
348d480f PA |
13512 | static void |
13513 | tracepoint_re_set (struct breakpoint *b) | |
13514 | { | |
13515 | breakpoint_re_set_default (b); | |
13516 | } | |
876fa593 | 13517 | |
348d480f PA |
13518 | static int |
13519 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13520 | struct address_space *aspace, CORE_ADDR bp_addr, |
13521 | const struct target_waitstatus *ws) | |
348d480f PA |
13522 | { |
13523 | /* By definition, the inferior does not report stops at | |
13524 | tracepoints. */ | |
13525 | return 0; | |
74960c60 VP |
13526 | } |
13527 | ||
13528 | static void | |
348d480f PA |
13529 | tracepoint_print_one_detail (const struct breakpoint *self, |
13530 | struct ui_out *uiout) | |
74960c60 | 13531 | { |
d9b3f62e PA |
13532 | struct tracepoint *tp = (struct tracepoint *) self; |
13533 | if (tp->static_trace_marker_id) | |
348d480f PA |
13534 | { |
13535 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13536 | |
348d480f PA |
13537 | ui_out_text (uiout, "\tmarker id is "); |
13538 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13539 | tp->static_trace_marker_id); |
348d480f PA |
13540 | ui_out_text (uiout, "\n"); |
13541 | } | |
0d381245 VP |
13542 | } |
13543 | ||
a474d7c2 | 13544 | static void |
348d480f | 13545 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13546 | { |
79a45e25 | 13547 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13548 | return; |
cc59ec59 | 13549 | |
348d480f PA |
13550 | switch (b->type) |
13551 | { | |
13552 | case bp_tracepoint: | |
13553 | printf_filtered (_("Tracepoint")); | |
13554 | printf_filtered (_(" %d"), b->number); | |
13555 | break; | |
13556 | case bp_fast_tracepoint: | |
13557 | printf_filtered (_("Fast tracepoint")); | |
13558 | printf_filtered (_(" %d"), b->number); | |
13559 | break; | |
13560 | case bp_static_tracepoint: | |
13561 | printf_filtered (_("Static tracepoint")); | |
13562 | printf_filtered (_(" %d"), b->number); | |
13563 | break; | |
13564 | default: | |
13565 | internal_error (__FILE__, __LINE__, | |
13566 | _("unhandled tracepoint type %d"), (int) b->type); | |
13567 | } | |
13568 | ||
13569 | say_where (b); | |
a474d7c2 PA |
13570 | } |
13571 | ||
348d480f | 13572 | static void |
d9b3f62e | 13573 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13574 | { |
d9b3f62e PA |
13575 | struct tracepoint *tp = (struct tracepoint *) self; |
13576 | ||
13577 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13578 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13579 | else if (self->type == bp_static_tracepoint) |
348d480f | 13580 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13581 | else if (self->type == bp_tracepoint) |
348d480f PA |
13582 | fprintf_unfiltered (fp, "trace"); |
13583 | else | |
13584 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13585 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13586 | |
f00aae0f KS |
13587 | fprintf_unfiltered (fp, " %s", |
13588 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13589 | print_recreate_thread (self, fp); |
13590 | ||
13591 | if (tp->pass_count) | |
13592 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13593 | } |
13594 | ||
983af33b | 13595 | static void |
f00aae0f KS |
13596 | tracepoint_create_sals_from_location (const struct event_location *location, |
13597 | struct linespec_result *canonical, | |
13598 | enum bptype type_wanted) | |
983af33b | 13599 | { |
f00aae0f | 13600 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13601 | } |
13602 | ||
13603 | static void | |
13604 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13605 | struct linespec_result *canonical, | |
983af33b | 13606 | char *cond_string, |
e7e0cddf | 13607 | char *extra_string, |
983af33b SDJ |
13608 | enum bptype type_wanted, |
13609 | enum bpdisp disposition, | |
13610 | int thread, | |
13611 | int task, int ignore_count, | |
13612 | const struct breakpoint_ops *ops, | |
13613 | int from_tty, int enabled, | |
44f238bb | 13614 | int internal, unsigned flags) |
983af33b | 13615 | { |
023fa29b | 13616 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13617 | cond_string, extra_string, |
13618 | type_wanted, | |
983af33b SDJ |
13619 | disposition, thread, task, |
13620 | ignore_count, ops, from_tty, | |
44f238bb | 13621 | enabled, internal, flags); |
983af33b SDJ |
13622 | } |
13623 | ||
13624 | static void | |
f00aae0f KS |
13625 | tracepoint_decode_location (struct breakpoint *b, |
13626 | const struct event_location *location, | |
c2f4122d | 13627 | struct program_space *search_pspace, |
983af33b SDJ |
13628 | struct symtabs_and_lines *sals) |
13629 | { | |
c2f4122d | 13630 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13631 | } |
13632 | ||
2060206e | 13633 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13634 | |
55aa24fb SDJ |
13635 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13636 | static probe. */ | |
13637 | ||
13638 | static void | |
f00aae0f KS |
13639 | tracepoint_probe_create_sals_from_location |
13640 | (const struct event_location *location, | |
13641 | struct linespec_result *canonical, | |
13642 | enum bptype type_wanted) | |
55aa24fb SDJ |
13643 | { |
13644 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13645 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13646 | } |
13647 | ||
13648 | static void | |
f00aae0f KS |
13649 | tracepoint_probe_decode_location (struct breakpoint *b, |
13650 | const struct event_location *location, | |
c2f4122d | 13651 | struct program_space *search_pspace, |
55aa24fb SDJ |
13652 | struct symtabs_and_lines *sals) |
13653 | { | |
13654 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13655 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13656 | } |
13657 | ||
13658 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13659 | ||
5c2b4418 HZ |
13660 | /* Dprintf breakpoint_ops methods. */ |
13661 | ||
13662 | static void | |
13663 | dprintf_re_set (struct breakpoint *b) | |
13664 | { | |
13665 | breakpoint_re_set_default (b); | |
13666 | ||
f00aae0f KS |
13667 | /* extra_string should never be non-NULL for dprintf. */ |
13668 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13669 | |
13670 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13671 | 2 - create a dprintf, which resolves fine. | |
13672 | 3 - disconnect from target 1 | |
13673 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13674 | ||
13675 | After steps #3/#4, you'll want the dprintf command list to | |
13676 | be updated, because target 1 and 2 may well return different | |
13677 | answers for target_can_run_breakpoint_commands(). | |
13678 | Given absence of finer grained resetting, we get to do | |
13679 | it all the time. */ | |
13680 | if (b->extra_string != NULL) | |
13681 | update_dprintf_command_list (b); | |
13682 | } | |
13683 | ||
2d9442cc HZ |
13684 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13685 | ||
13686 | static void | |
13687 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13688 | { | |
f00aae0f KS |
13689 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13690 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13691 | tp->extra_string); |
13692 | print_recreate_thread (tp, fp); | |
13693 | } | |
13694 | ||
9d6e6e84 HZ |
13695 | /* Implement the "after_condition_true" breakpoint_ops method for |
13696 | dprintf. | |
13697 | ||
13698 | dprintf's are implemented with regular commands in their command | |
13699 | list, but we run the commands here instead of before presenting the | |
13700 | stop to the user, as dprintf's don't actually cause a stop. This | |
13701 | also makes it so that the commands of multiple dprintfs at the same | |
13702 | address are all handled. */ | |
13703 | ||
13704 | static void | |
13705 | dprintf_after_condition_true (struct bpstats *bs) | |
13706 | { | |
13707 | struct cleanup *old_chain; | |
13708 | struct bpstats tmp_bs = { NULL }; | |
13709 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13710 | ||
13711 | /* dprintf's never cause a stop. This wasn't set in the | |
13712 | check_status hook instead because that would make the dprintf's | |
13713 | condition not be evaluated. */ | |
13714 | bs->stop = 0; | |
13715 | ||
13716 | /* Run the command list here. Take ownership of it instead of | |
13717 | copying. We never want these commands to run later in | |
13718 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13719 | be set at same address as this dprintf, or even if running the | |
13720 | commands here throws. */ | |
13721 | tmp_bs.commands = bs->commands; | |
13722 | bs->commands = NULL; | |
13723 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13724 | ||
13725 | bpstat_do_actions_1 (&tmp_bs_p); | |
13726 | ||
13727 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13728 | bpstat_do_actions_1 may return early without processing the whole | |
13729 | list. */ | |
13730 | do_cleanups (old_chain); | |
13731 | } | |
13732 | ||
983af33b SDJ |
13733 | /* The breakpoint_ops structure to be used on static tracepoints with |
13734 | markers (`-m'). */ | |
13735 | ||
13736 | static void | |
f00aae0f | 13737 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13738 | struct linespec_result *canonical, |
f00aae0f | 13739 | enum bptype type_wanted) |
983af33b SDJ |
13740 | { |
13741 | struct linespec_sals lsal; | |
f00aae0f KS |
13742 | const char *arg_start, *arg; |
13743 | char *str; | |
13744 | struct cleanup *cleanup; | |
983af33b | 13745 | |
f00aae0f KS |
13746 | arg = arg_start = get_linespec_location (location); |
13747 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13748 | |
f00aae0f KS |
13749 | str = savestring (arg_start, arg - arg_start); |
13750 | cleanup = make_cleanup (xfree, str); | |
13751 | canonical->location = new_linespec_location (&str); | |
13752 | do_cleanups (cleanup); | |
983af33b | 13753 | |
f00aae0f | 13754 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13755 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13756 | } | |
13757 | ||
13758 | static void | |
13759 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13760 | struct linespec_result *canonical, | |
983af33b | 13761 | char *cond_string, |
e7e0cddf | 13762 | char *extra_string, |
983af33b SDJ |
13763 | enum bptype type_wanted, |
13764 | enum bpdisp disposition, | |
13765 | int thread, | |
13766 | int task, int ignore_count, | |
13767 | const struct breakpoint_ops *ops, | |
13768 | int from_tty, int enabled, | |
44f238bb | 13769 | int internal, unsigned flags) |
983af33b SDJ |
13770 | { |
13771 | int i; | |
52d361e1 YQ |
13772 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13773 | canonical->sals, 0); | |
983af33b SDJ |
13774 | |
13775 | /* If the user is creating a static tracepoint by marker id | |
13776 | (strace -m MARKER_ID), then store the sals index, so that | |
13777 | breakpoint_re_set can try to match up which of the newly | |
13778 | found markers corresponds to this one, and, don't try to | |
13779 | expand multiple locations for each sal, given than SALS | |
13780 | already should contain all sals for MARKER_ID. */ | |
13781 | ||
13782 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13783 | { | |
13784 | struct symtabs_and_lines expanded; | |
13785 | struct tracepoint *tp; | |
13786 | struct cleanup *old_chain; | |
f00aae0f | 13787 | struct event_location *location; |
983af33b SDJ |
13788 | |
13789 | expanded.nelts = 1; | |
13790 | expanded.sals = &lsal->sals.sals[i]; | |
13791 | ||
f00aae0f KS |
13792 | location = copy_event_location (canonical->location); |
13793 | old_chain = make_cleanup_delete_event_location (location); | |
983af33b SDJ |
13794 | |
13795 | tp = XCNEW (struct tracepoint); | |
13796 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
f00aae0f | 13797 | location, NULL, |
e7e0cddf SS |
13798 | cond_string, extra_string, |
13799 | type_wanted, disposition, | |
983af33b | 13800 | thread, task, ignore_count, ops, |
44f238bb | 13801 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13802 | canonical->special_display); |
13803 | /* Given that its possible to have multiple markers with | |
13804 | the same string id, if the user is creating a static | |
13805 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13806 | store the sals index, so that breakpoint_re_set can | |
13807 | try to match up which of the newly found markers | |
13808 | corresponds to this one */ | |
13809 | tp->static_trace_marker_id_idx = i; | |
13810 | ||
13811 | install_breakpoint (internal, &tp->base, 0); | |
13812 | ||
13813 | discard_cleanups (old_chain); | |
13814 | } | |
13815 | } | |
13816 | ||
13817 | static void | |
f00aae0f KS |
13818 | strace_marker_decode_location (struct breakpoint *b, |
13819 | const struct event_location *location, | |
c2f4122d | 13820 | struct program_space *search_pspace, |
983af33b SDJ |
13821 | struct symtabs_and_lines *sals) |
13822 | { | |
13823 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13824 | const char *s = get_linespec_location (location); |
983af33b | 13825 | |
f00aae0f | 13826 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13827 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13828 | { | |
13829 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13830 | sals->nelts = 1; | |
13831 | } | |
13832 | else | |
13833 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13834 | } | |
13835 | ||
13836 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13837 | ||
13838 | static int | |
13839 | strace_marker_p (struct breakpoint *b) | |
13840 | { | |
13841 | return b->ops == &strace_marker_breakpoint_ops; | |
13842 | } | |
13843 | ||
53a5351d | 13844 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13845 | structures. */ |
c906108c SS |
13846 | |
13847 | void | |
fba45db2 | 13848 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13849 | { |
52f0bd74 | 13850 | struct breakpoint *b; |
c906108c | 13851 | |
8a3fe4f8 | 13852 | gdb_assert (bpt != NULL); |
c906108c | 13853 | |
4a64f543 MS |
13854 | /* Has this bp already been deleted? This can happen because |
13855 | multiple lists can hold pointers to bp's. bpstat lists are | |
13856 | especial culprits. | |
13857 | ||
13858 | One example of this happening is a watchpoint's scope bp. When | |
13859 | the scope bp triggers, we notice that the watchpoint is out of | |
13860 | scope, and delete it. We also delete its scope bp. But the | |
13861 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13862 | That bpstat is then checked for auto-deleting bp's, which are | |
13863 | deleted. | |
13864 | ||
13865 | A real solution to this problem might involve reference counts in | |
13866 | bp's, and/or giving them pointers back to their referencing | |
13867 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13868 | storage when no more references were extent. A cheaper bandaid | |
13869 | was chosen. */ | |
c906108c SS |
13870 | if (bpt->type == bp_none) |
13871 | return; | |
13872 | ||
4a64f543 MS |
13873 | /* At least avoid this stale reference until the reference counting |
13874 | of breakpoints gets resolved. */ | |
d0fb5eae | 13875 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13876 | { |
d0fb5eae | 13877 | struct breakpoint *related; |
3a5c3e22 | 13878 | struct watchpoint *w; |
d0fb5eae JK |
13879 | |
13880 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13881 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13882 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13883 | w = (struct watchpoint *) bpt; |
13884 | else | |
13885 | w = NULL; | |
13886 | if (w != NULL) | |
13887 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13888 | |
13889 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13890 | for (related = bpt; related->related_breakpoint != bpt; | |
13891 | related = related->related_breakpoint); | |
13892 | related->related_breakpoint = bpt->related_breakpoint; | |
13893 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13894 | } |
13895 | ||
a9634178 TJB |
13896 | /* watch_command_1 creates a watchpoint but only sets its number if |
13897 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13898 | a problem in that process, we'll be asked to delete the half-created | |
13899 | watchpoint. In that case, don't announce the deletion. */ | |
13900 | if (bpt->number) | |
13901 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13902 | |
c906108c SS |
13903 | if (breakpoint_chain == bpt) |
13904 | breakpoint_chain = bpt->next; | |
13905 | ||
c906108c SS |
13906 | ALL_BREAKPOINTS (b) |
13907 | if (b->next == bpt) | |
c5aa993b JM |
13908 | { |
13909 | b->next = bpt->next; | |
13910 | break; | |
13911 | } | |
c906108c | 13912 | |
f431efe5 PA |
13913 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13914 | been freed. */ | |
13915 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13916 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13917 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13918 | commands are associated with the bpstat; if we remove it here, | |
13919 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13920 | event-top.c won't do anything, and temporary breakpoints with | |
13921 | commands won't work. */ | |
13922 | ||
13923 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13924 | ||
4a64f543 MS |
13925 | /* Now that breakpoint is removed from breakpoint list, update the |
13926 | global location list. This will remove locations that used to | |
13927 | belong to this breakpoint. Do this before freeing the breakpoint | |
13928 | itself, since remove_breakpoint looks at location's owner. It | |
13929 | might be better design to have location completely | |
13930 | self-contained, but it's not the case now. */ | |
44702360 | 13931 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13932 | |
348d480f | 13933 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13934 | /* On the chance that someone will soon try again to delete this |
13935 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13936 | bpt->type = bp_none; |
b8c9b27d | 13937 | xfree (bpt); |
c906108c SS |
13938 | } |
13939 | ||
4d6140d9 AC |
13940 | static void |
13941 | do_delete_breakpoint_cleanup (void *b) | |
13942 | { | |
9a3c8263 | 13943 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13944 | } |
13945 | ||
13946 | struct cleanup * | |
13947 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13948 | { | |
13949 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13950 | } | |
13951 | ||
51be5b68 PA |
13952 | /* Iterator function to call a user-provided callback function once |
13953 | for each of B and its related breakpoints. */ | |
13954 | ||
13955 | static void | |
13956 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13957 | void (*function) (struct breakpoint *, | |
13958 | void *), | |
13959 | void *data) | |
13960 | { | |
13961 | struct breakpoint *related; | |
13962 | ||
13963 | related = b; | |
13964 | do | |
13965 | { | |
13966 | struct breakpoint *next; | |
13967 | ||
13968 | /* FUNCTION may delete RELATED. */ | |
13969 | next = related->related_breakpoint; | |
13970 | ||
13971 | if (next == related) | |
13972 | { | |
13973 | /* RELATED is the last ring entry. */ | |
13974 | function (related, data); | |
13975 | ||
13976 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13977 | B. There's nothing left to do anyway, so just break | |
13978 | out. */ | |
13979 | break; | |
13980 | } | |
13981 | else | |
13982 | function (related, data); | |
13983 | ||
13984 | related = next; | |
13985 | } | |
13986 | while (related != b); | |
13987 | } | |
95a42b64 TT |
13988 | |
13989 | static void | |
13990 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13991 | { | |
13992 | delete_breakpoint (b); | |
13993 | } | |
13994 | ||
51be5b68 PA |
13995 | /* A callback for map_breakpoint_numbers that calls |
13996 | delete_breakpoint. */ | |
13997 | ||
13998 | static void | |
13999 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14000 | { | |
14001 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
14002 | } | |
14003 | ||
c906108c | 14004 | void |
fba45db2 | 14005 | delete_command (char *arg, int from_tty) |
c906108c | 14006 | { |
35df4500 | 14007 | struct breakpoint *b, *b_tmp; |
c906108c | 14008 | |
ea9365bb TT |
14009 | dont_repeat (); |
14010 | ||
c906108c SS |
14011 | if (arg == 0) |
14012 | { | |
14013 | int breaks_to_delete = 0; | |
14014 | ||
46c6471b PA |
14015 | /* Delete all breakpoints if no argument. Do not delete |
14016 | internal breakpoints, these have to be deleted with an | |
14017 | explicit breakpoint number argument. */ | |
c5aa993b | 14018 | ALL_BREAKPOINTS (b) |
46c6471b | 14019 | if (user_breakpoint_p (b)) |
973d738b DJ |
14020 | { |
14021 | breaks_to_delete = 1; | |
14022 | break; | |
14023 | } | |
c906108c SS |
14024 | |
14025 | /* Ask user only if there are some breakpoints to delete. */ | |
14026 | if (!from_tty | |
e2e0b3e5 | 14027 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14028 | { |
35df4500 | 14029 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14030 | if (user_breakpoint_p (b)) |
c5aa993b | 14031 | delete_breakpoint (b); |
c906108c SS |
14032 | } |
14033 | } | |
14034 | else | |
51be5b68 | 14035 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14036 | } |
14037 | ||
c2f4122d PA |
14038 | /* Return true if all locations of B bound to PSPACE are pending. If |
14039 | PSPACE is NULL, all locations of all program spaces are | |
14040 | considered. */ | |
14041 | ||
0d381245 | 14042 | static int |
c2f4122d | 14043 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 14044 | { |
c2f4122d PA |
14045 | struct bp_location *loc; |
14046 | ||
14047 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
14048 | if ((pspace == NULL | |
14049 | || loc->pspace == pspace) | |
14050 | && !loc->shlib_disabled | |
8645ff69 | 14051 | && !loc->pspace->executing_startup) |
0d381245 VP |
14052 | return 0; |
14053 | return 1; | |
fe3f5fa8 VP |
14054 | } |
14055 | ||
776592bf DE |
14056 | /* Subroutine of update_breakpoint_locations to simplify it. |
14057 | Return non-zero if multiple fns in list LOC have the same name. | |
14058 | Null names are ignored. */ | |
14059 | ||
14060 | static int | |
14061 | ambiguous_names_p (struct bp_location *loc) | |
14062 | { | |
14063 | struct bp_location *l; | |
14064 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14065 | (int (*) (const void *, |
14066 | const void *)) streq, | |
776592bf DE |
14067 | NULL, xcalloc, xfree); |
14068 | ||
14069 | for (l = loc; l != NULL; l = l->next) | |
14070 | { | |
14071 | const char **slot; | |
14072 | const char *name = l->function_name; | |
14073 | ||
14074 | /* Allow for some names to be NULL, ignore them. */ | |
14075 | if (name == NULL) | |
14076 | continue; | |
14077 | ||
14078 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14079 | INSERT); | |
4a64f543 MS |
14080 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14081 | returns NULL. */ | |
776592bf DE |
14082 | if (*slot != NULL) |
14083 | { | |
14084 | htab_delete (htab); | |
14085 | return 1; | |
14086 | } | |
14087 | *slot = name; | |
14088 | } | |
14089 | ||
14090 | htab_delete (htab); | |
14091 | return 0; | |
14092 | } | |
14093 | ||
0fb4aa4b PA |
14094 | /* When symbols change, it probably means the sources changed as well, |
14095 | and it might mean the static tracepoint markers are no longer at | |
14096 | the same address or line numbers they used to be at last we | |
14097 | checked. Losing your static tracepoints whenever you rebuild is | |
14098 | undesirable. This function tries to resync/rematch gdb static | |
14099 | tracepoints with the markers on the target, for static tracepoints | |
14100 | that have not been set by marker id. Static tracepoint that have | |
14101 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14102 | The heuristic is: | |
14103 | ||
14104 | 1) For a tracepoint set at a specific address, look for a marker at | |
14105 | the old PC. If one is found there, assume to be the same marker. | |
14106 | If the name / string id of the marker found is different from the | |
14107 | previous known name, assume that means the user renamed the marker | |
14108 | in the sources, and output a warning. | |
14109 | ||
14110 | 2) For a tracepoint set at a given line number, look for a marker | |
14111 | at the new address of the old line number. If one is found there, | |
14112 | assume to be the same marker. If the name / string id of the | |
14113 | marker found is different from the previous known name, assume that | |
14114 | means the user renamed the marker in the sources, and output a | |
14115 | warning. | |
14116 | ||
14117 | 3) If a marker is no longer found at the same address or line, it | |
14118 | may mean the marker no longer exists. But it may also just mean | |
14119 | the code changed a bit. Maybe the user added a few lines of code | |
14120 | that made the marker move up or down (in line number terms). Ask | |
14121 | the target for info about the marker with the string id as we knew | |
14122 | it. If found, update line number and address in the matching | |
14123 | static tracepoint. This will get confused if there's more than one | |
14124 | marker with the same ID (possible in UST, although unadvised | |
14125 | precisely because it confuses tools). */ | |
14126 | ||
14127 | static struct symtab_and_line | |
14128 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14129 | { | |
d9b3f62e | 14130 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14131 | struct static_tracepoint_marker marker; |
14132 | CORE_ADDR pc; | |
0fb4aa4b PA |
14133 | |
14134 | pc = sal.pc; | |
14135 | if (sal.line) | |
14136 | find_line_pc (sal.symtab, sal.line, &pc); | |
14137 | ||
14138 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14139 | { | |
d9b3f62e | 14140 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14141 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14142 | b->number, | |
d9b3f62e | 14143 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14144 | |
d9b3f62e PA |
14145 | xfree (tp->static_trace_marker_id); |
14146 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14147 | release_static_tracepoint_marker (&marker); |
14148 | ||
14149 | return sal; | |
14150 | } | |
14151 | ||
14152 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14153 | by string ID. */ | |
14154 | if (!sal.explicit_pc | |
14155 | && sal.line != 0 | |
14156 | && sal.symtab != NULL | |
d9b3f62e | 14157 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14158 | { |
14159 | VEC(static_tracepoint_marker_p) *markers; | |
14160 | ||
14161 | markers | |
d9b3f62e | 14162 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14163 | |
14164 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14165 | { | |
80e1d417 | 14166 | struct symtab_and_line sal2; |
0fb4aa4b | 14167 | struct symbol *sym; |
80e1d417 | 14168 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14169 | struct ui_out *uiout = current_uiout; |
67994074 | 14170 | struct explicit_location explicit_loc; |
0fb4aa4b | 14171 | |
80e1d417 | 14172 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14173 | |
d9b3f62e | 14174 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14175 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14176 | |
14177 | warning (_("marker for static tracepoint %d (%s) not " | |
14178 | "found at previous line number"), | |
d9b3f62e | 14179 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14180 | |
80e1d417 | 14181 | init_sal (&sal2); |
0fb4aa4b | 14182 | |
80e1d417 | 14183 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14184 | |
80e1d417 AS |
14185 | sal2 = find_pc_line (tpmarker->address, 0); |
14186 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14187 | ui_out_text (uiout, "Now in "); |
14188 | if (sym) | |
14189 | { | |
14190 | ui_out_field_string (uiout, "func", | |
14191 | SYMBOL_PRINT_NAME (sym)); | |
14192 | ui_out_text (uiout, " at "); | |
14193 | } | |
05cba821 JK |
14194 | ui_out_field_string (uiout, "file", |
14195 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14196 | ui_out_text (uiout, ":"); |
14197 | ||
14198 | if (ui_out_is_mi_like_p (uiout)) | |
14199 | { | |
0b0865da | 14200 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14201 | |
f35a17b5 | 14202 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14203 | } |
14204 | ||
80e1d417 | 14205 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14206 | ui_out_text (uiout, "\n"); |
14207 | ||
80e1d417 | 14208 | b->loc->line_number = sal2.line; |
2f202fde | 14209 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14210 | |
f00aae0f | 14211 | delete_event_location (b->location); |
67994074 KS |
14212 | initialize_explicit_location (&explicit_loc); |
14213 | explicit_loc.source_filename | |
00e52e53 | 14214 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14215 | explicit_loc.line_offset.offset = b->loc->line_number; |
14216 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
14217 | b->location = new_explicit_location (&explicit_loc); | |
0fb4aa4b PA |
14218 | |
14219 | /* Might be nice to check if function changed, and warn if | |
14220 | so. */ | |
14221 | ||
80e1d417 | 14222 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14223 | } |
14224 | } | |
14225 | return sal; | |
14226 | } | |
14227 | ||
8d3788bd VP |
14228 | /* Returns 1 iff locations A and B are sufficiently same that |
14229 | we don't need to report breakpoint as changed. */ | |
14230 | ||
14231 | static int | |
14232 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14233 | { | |
14234 | while (a && b) | |
14235 | { | |
14236 | if (a->address != b->address) | |
14237 | return 0; | |
14238 | ||
14239 | if (a->shlib_disabled != b->shlib_disabled) | |
14240 | return 0; | |
14241 | ||
14242 | if (a->enabled != b->enabled) | |
14243 | return 0; | |
14244 | ||
14245 | a = a->next; | |
14246 | b = b->next; | |
14247 | } | |
14248 | ||
14249 | if ((a == NULL) != (b == NULL)) | |
14250 | return 0; | |
14251 | ||
14252 | return 1; | |
14253 | } | |
14254 | ||
c2f4122d PA |
14255 | /* Split all locations of B that are bound to PSPACE out of B's |
14256 | location list to a separate list and return that list's head. If | |
14257 | PSPACE is NULL, hoist out all locations of B. */ | |
14258 | ||
14259 | static struct bp_location * | |
14260 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14261 | { | |
14262 | struct bp_location head; | |
14263 | struct bp_location *i = b->loc; | |
14264 | struct bp_location **i_link = &b->loc; | |
14265 | struct bp_location *hoisted = &head; | |
14266 | ||
14267 | if (pspace == NULL) | |
14268 | { | |
14269 | i = b->loc; | |
14270 | b->loc = NULL; | |
14271 | return i; | |
14272 | } | |
14273 | ||
14274 | head.next = NULL; | |
14275 | ||
14276 | while (i != NULL) | |
14277 | { | |
14278 | if (i->pspace == pspace) | |
14279 | { | |
14280 | *i_link = i->next; | |
14281 | i->next = NULL; | |
14282 | hoisted->next = i; | |
14283 | hoisted = i; | |
14284 | } | |
14285 | else | |
14286 | i_link = &i->next; | |
14287 | i = *i_link; | |
14288 | } | |
14289 | ||
14290 | return head.next; | |
14291 | } | |
14292 | ||
14293 | /* Create new breakpoint locations for B (a hardware or software | |
14294 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14295 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14296 | FILTER_PSPACE. Locations of other program spaces are left | |
14297 | untouched. */ | |
f1310107 | 14298 | |
0e30163f | 14299 | void |
0d381245 | 14300 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14301 | struct program_space *filter_pspace, |
f1310107 TJB |
14302 | struct symtabs_and_lines sals, |
14303 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14304 | { |
14305 | int i; | |
c2f4122d | 14306 | struct bp_location *existing_locations; |
0d381245 | 14307 | |
f8eba3c6 TT |
14308 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14309 | { | |
14310 | /* Ranged breakpoints have only one start location and one end | |
14311 | location. */ | |
14312 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14313 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14314 | "multiple locations found\n"), | |
14315 | b->number); | |
14316 | return; | |
14317 | } | |
f1310107 | 14318 | |
4a64f543 MS |
14319 | /* If there's no new locations, and all existing locations are |
14320 | pending, don't do anything. This optimizes the common case where | |
14321 | all locations are in the same shared library, that was unloaded. | |
14322 | We'd like to retain the location, so that when the library is | |
14323 | loaded again, we don't loose the enabled/disabled status of the | |
14324 | individual locations. */ | |
c2f4122d | 14325 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14326 | return; |
14327 | ||
c2f4122d | 14328 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14329 | |
0d381245 | 14330 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14331 | { |
f8eba3c6 TT |
14332 | struct bp_location *new_loc; |
14333 | ||
14334 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14335 | ||
14336 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14337 | |
0d381245 VP |
14338 | /* Reparse conditions, they might contain references to the |
14339 | old symtab. */ | |
14340 | if (b->cond_string != NULL) | |
14341 | { | |
bbc13ae3 | 14342 | const char *s; |
fe3f5fa8 | 14343 | |
0d381245 | 14344 | s = b->cond_string; |
492d29ea | 14345 | TRY |
0d381245 | 14346 | { |
1bb9788d TT |
14347 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14348 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14349 | 0); |
14350 | } | |
492d29ea | 14351 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14352 | { |
3e43a32a MS |
14353 | warning (_("failed to reevaluate condition " |
14354 | "for breakpoint %d: %s"), | |
0d381245 VP |
14355 | b->number, e.message); |
14356 | new_loc->enabled = 0; | |
14357 | } | |
492d29ea | 14358 | END_CATCH |
0d381245 | 14359 | } |
fe3f5fa8 | 14360 | |
f1310107 TJB |
14361 | if (sals_end.nelts) |
14362 | { | |
14363 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14364 | ||
14365 | new_loc->length = end - sals.sals[0].pc + 1; | |
14366 | } | |
0d381245 | 14367 | } |
fe3f5fa8 | 14368 | |
4a64f543 MS |
14369 | /* If possible, carry over 'disable' status from existing |
14370 | breakpoints. */ | |
0d381245 VP |
14371 | { |
14372 | struct bp_location *e = existing_locations; | |
776592bf DE |
14373 | /* If there are multiple breakpoints with the same function name, |
14374 | e.g. for inline functions, comparing function names won't work. | |
14375 | Instead compare pc addresses; this is just a heuristic as things | |
14376 | may have moved, but in practice it gives the correct answer | |
14377 | often enough until a better solution is found. */ | |
14378 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14379 | ||
0d381245 VP |
14380 | for (; e; e = e->next) |
14381 | { | |
14382 | if (!e->enabled && e->function_name) | |
14383 | { | |
14384 | struct bp_location *l = b->loc; | |
776592bf DE |
14385 | if (have_ambiguous_names) |
14386 | { | |
14387 | for (; l; l = l->next) | |
f1310107 | 14388 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14389 | { |
14390 | l->enabled = 0; | |
14391 | break; | |
14392 | } | |
14393 | } | |
14394 | else | |
14395 | { | |
14396 | for (; l; l = l->next) | |
14397 | if (l->function_name | |
14398 | && strcmp (e->function_name, l->function_name) == 0) | |
14399 | { | |
14400 | l->enabled = 0; | |
14401 | break; | |
14402 | } | |
14403 | } | |
0d381245 VP |
14404 | } |
14405 | } | |
14406 | } | |
fe3f5fa8 | 14407 | |
8d3788bd VP |
14408 | if (!locations_are_equal (existing_locations, b->loc)) |
14409 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14410 | } |
14411 | ||
f00aae0f | 14412 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14413 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14414 | ||
14415 | static struct symtabs_and_lines | |
f00aae0f | 14416 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14417 | struct program_space *search_pspace, int *found) |
ef23e705 | 14418 | { |
02d20e4a | 14419 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14420 | struct gdb_exception exception = exception_none; |
ef23e705 | 14421 | |
983af33b | 14422 | gdb_assert (b->ops != NULL); |
ef23e705 | 14423 | |
492d29ea | 14424 | TRY |
ef23e705 | 14425 | { |
c2f4122d | 14426 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14427 | } |
492d29ea | 14428 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14429 | { |
14430 | int not_found_and_ok = 0; | |
492d29ea PA |
14431 | |
14432 | exception = e; | |
14433 | ||
ef23e705 TJB |
14434 | /* For pending breakpoints, it's expected that parsing will |
14435 | fail until the right shared library is loaded. User has | |
14436 | already told to create pending breakpoints and don't need | |
14437 | extra messages. If breakpoint is in bp_shlib_disabled | |
14438 | state, then user already saw the message about that | |
14439 | breakpoint being disabled, and don't want to see more | |
14440 | errors. */ | |
58438ac1 | 14441 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14442 | && (b->condition_not_parsed |
14443 | || (b->loc != NULL | |
14444 | && search_pspace != NULL | |
14445 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14446 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14447 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14448 | || b->enable_state == bp_disabled)) |
14449 | not_found_and_ok = 1; | |
14450 | ||
14451 | if (!not_found_and_ok) | |
14452 | { | |
14453 | /* We surely don't want to warn about the same breakpoint | |
14454 | 10 times. One solution, implemented here, is disable | |
14455 | the breakpoint on error. Another solution would be to | |
14456 | have separate 'warning emitted' flag. Since this | |
14457 | happens only when a binary has changed, I don't know | |
14458 | which approach is better. */ | |
14459 | b->enable_state = bp_disabled; | |
14460 | throw_exception (e); | |
14461 | } | |
14462 | } | |
492d29ea | 14463 | END_CATCH |
ef23e705 | 14464 | |
492d29ea | 14465 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14466 | { |
f8eba3c6 | 14467 | int i; |
ef23e705 | 14468 | |
f8eba3c6 TT |
14469 | for (i = 0; i < sals.nelts; ++i) |
14470 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14471 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14472 | { |
ed1d1739 KS |
14473 | char *cond_string, *extra_string; |
14474 | int thread, task; | |
ef23e705 | 14475 | |
f00aae0f | 14476 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14477 | &cond_string, &thread, &task, |
14478 | &extra_string); | |
f00aae0f | 14479 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14480 | if (cond_string) |
14481 | b->cond_string = cond_string; | |
14482 | b->thread = thread; | |
14483 | b->task = task; | |
e7e0cddf | 14484 | if (extra_string) |
f00aae0f KS |
14485 | { |
14486 | xfree (b->extra_string); | |
14487 | b->extra_string = extra_string; | |
14488 | } | |
ef23e705 TJB |
14489 | b->condition_not_parsed = 0; |
14490 | } | |
14491 | ||
983af33b | 14492 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14493 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14494 | |
58438ac1 TT |
14495 | *found = 1; |
14496 | } | |
14497 | else | |
14498 | *found = 0; | |
ef23e705 TJB |
14499 | |
14500 | return sals; | |
14501 | } | |
14502 | ||
348d480f PA |
14503 | /* The default re_set method, for typical hardware or software |
14504 | breakpoints. Reevaluate the breakpoint and recreate its | |
14505 | locations. */ | |
14506 | ||
14507 | static void | |
28010a5d | 14508 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14509 | { |
14510 | int found; | |
f1310107 | 14511 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14512 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14513 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14514 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14515 | |
c2f4122d | 14516 | sals = location_to_sals (b, b->location, filter_pspace, &found); |
ef23e705 TJB |
14517 | if (found) |
14518 | { | |
14519 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14520 | expanded = sals; |
ef23e705 TJB |
14521 | } |
14522 | ||
f00aae0f | 14523 | if (b->location_range_end != NULL) |
f1310107 | 14524 | { |
c2f4122d PA |
14525 | sals_end = location_to_sals (b, b->location_range_end, |
14526 | filter_pspace, &found); | |
f1310107 TJB |
14527 | if (found) |
14528 | { | |
14529 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14530 | expanded_end = sals_end; |
f1310107 TJB |
14531 | } |
14532 | } | |
14533 | ||
c2f4122d | 14534 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14535 | } |
14536 | ||
983af33b SDJ |
14537 | /* Default method for creating SALs from an address string. It basically |
14538 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14539 | ||
14540 | static void | |
f00aae0f KS |
14541 | create_sals_from_location_default (const struct event_location *location, |
14542 | struct linespec_result *canonical, | |
14543 | enum bptype type_wanted) | |
983af33b | 14544 | { |
f00aae0f | 14545 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14546 | } |
14547 | ||
14548 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14549 | function for the `create_breakpoints_sal' method of | |
14550 | breakpoint_ops. */ | |
14551 | ||
14552 | static void | |
14553 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14554 | struct linespec_result *canonical, | |
983af33b | 14555 | char *cond_string, |
e7e0cddf | 14556 | char *extra_string, |
983af33b SDJ |
14557 | enum bptype type_wanted, |
14558 | enum bpdisp disposition, | |
14559 | int thread, | |
14560 | int task, int ignore_count, | |
14561 | const struct breakpoint_ops *ops, | |
14562 | int from_tty, int enabled, | |
44f238bb | 14563 | int internal, unsigned flags) |
983af33b SDJ |
14564 | { |
14565 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14566 | extra_string, |
983af33b SDJ |
14567 | type_wanted, disposition, |
14568 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14569 | enabled, internal, flags); |
983af33b SDJ |
14570 | } |
14571 | ||
14572 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14573 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14574 | |
14575 | static void | |
f00aae0f KS |
14576 | decode_location_default (struct breakpoint *b, |
14577 | const struct event_location *location, | |
c2f4122d | 14578 | struct program_space *search_pspace, |
983af33b SDJ |
14579 | struct symtabs_and_lines *sals) |
14580 | { | |
14581 | struct linespec_result canonical; | |
14582 | ||
14583 | init_linespec_result (&canonical); | |
c2f4122d | 14584 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14585 | (struct symtab *) NULL, 0, |
14586 | &canonical, multiple_symbols_all, | |
14587 | b->filter); | |
14588 | ||
14589 | /* We should get 0 or 1 resulting SALs. */ | |
14590 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14591 | ||
14592 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14593 | { | |
14594 | struct linespec_sals *lsal; | |
14595 | ||
14596 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14597 | *sals = lsal->sals; | |
14598 | /* Arrange it so the destructor does not free the | |
14599 | contents. */ | |
14600 | lsal->sals.sals = NULL; | |
14601 | } | |
14602 | ||
14603 | destroy_linespec_result (&canonical); | |
14604 | } | |
14605 | ||
28010a5d PA |
14606 | /* Prepare the global context for a re-set of breakpoint B. */ |
14607 | ||
14608 | static struct cleanup * | |
14609 | prepare_re_set_context (struct breakpoint *b) | |
14610 | { | |
28010a5d | 14611 | input_radix = b->input_radix; |
28010a5d PA |
14612 | set_language (b->language); |
14613 | ||
c2f4122d | 14614 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14615 | } |
14616 | ||
c906108c SS |
14617 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14618 | The value we return ends up being the return value from catch_errors. | |
14619 | Unused in this case. */ | |
14620 | ||
14621 | static int | |
4efb68b1 | 14622 | breakpoint_re_set_one (void *bint) |
c906108c | 14623 | { |
4a64f543 | 14624 | /* Get past catch_errs. */ |
53a5351d | 14625 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14626 | struct cleanup *cleanups; |
c906108c | 14627 | |
348d480f PA |
14628 | cleanups = prepare_re_set_context (b); |
14629 | b->ops->re_set (b); | |
14630 | do_cleanups (cleanups); | |
c906108c SS |
14631 | return 0; |
14632 | } | |
14633 | ||
c2f4122d PA |
14634 | /* Re-set breakpoint locations for the current program space. |
14635 | Locations bound to other program spaces are left untouched. */ | |
14636 | ||
c906108c | 14637 | void |
69de3c6a | 14638 | breakpoint_re_set (void) |
c906108c | 14639 | { |
35df4500 | 14640 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14641 | enum language save_language; |
14642 | int save_input_radix; | |
6c95b8df | 14643 | struct cleanup *old_chain; |
c5aa993b | 14644 | |
c906108c SS |
14645 | save_language = current_language->la_language; |
14646 | save_input_radix = input_radix; | |
c2f4122d | 14647 | old_chain = save_current_space_and_thread (); |
6c95b8df | 14648 | |
2a7f3dff PA |
14649 | /* Note: we must not try to insert locations until after all |
14650 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14651 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14652 | hadn't been re-set yet, and thus may have stale locations. */ | |
14653 | ||
35df4500 | 14654 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14655 | { |
4a64f543 | 14656 | /* Format possible error msg. */ |
fe3f5fa8 | 14657 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14658 | b->number); |
14659 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14660 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14661 | do_cleanups (cleanups); |
c5aa993b | 14662 | } |
c906108c SS |
14663 | set_language (save_language); |
14664 | input_radix = save_input_radix; | |
e62c965a | 14665 | |
0756c555 | 14666 | jit_breakpoint_re_set (); |
4efc6507 | 14667 | |
6c95b8df PA |
14668 | do_cleanups (old_chain); |
14669 | ||
af02033e PP |
14670 | create_overlay_event_breakpoint (); |
14671 | create_longjmp_master_breakpoint (); | |
14672 | create_std_terminate_master_breakpoint (); | |
186c406b | 14673 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14674 | |
14675 | /* Now we can insert. */ | |
14676 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14677 | } |
14678 | \f | |
c906108c SS |
14679 | /* Reset the thread number of this breakpoint: |
14680 | ||
14681 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14682 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14683 | void |
fba45db2 | 14684 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14685 | { |
14686 | if (b->thread != -1) | |
14687 | { | |
39f77062 | 14688 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14689 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14690 | |
14691 | /* We're being called after following a fork. The new fork is | |
14692 | selected as current, and unless this was a vfork will have a | |
14693 | different program space from the original thread. Reset that | |
14694 | as well. */ | |
14695 | b->loc->pspace = current_program_space; | |
c906108c SS |
14696 | } |
14697 | } | |
14698 | ||
03ac34d5 MS |
14699 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14700 | If from_tty is nonzero, it prints a message to that effect, | |
14701 | which ends with a period (no newline). */ | |
14702 | ||
c906108c | 14703 | void |
fba45db2 | 14704 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14705 | { |
52f0bd74 | 14706 | struct breakpoint *b; |
c906108c SS |
14707 | |
14708 | if (count < 0) | |
14709 | count = 0; | |
14710 | ||
14711 | ALL_BREAKPOINTS (b) | |
14712 | if (b->number == bptnum) | |
c5aa993b | 14713 | { |
d77f58be SS |
14714 | if (is_tracepoint (b)) |
14715 | { | |
14716 | if (from_tty && count != 0) | |
14717 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14718 | bptnum); | |
14719 | return; | |
14720 | } | |
14721 | ||
c5aa993b | 14722 | b->ignore_count = count; |
221ea385 KS |
14723 | if (from_tty) |
14724 | { | |
14725 | if (count == 0) | |
3e43a32a MS |
14726 | printf_filtered (_("Will stop next time " |
14727 | "breakpoint %d is reached."), | |
221ea385 KS |
14728 | bptnum); |
14729 | else if (count == 1) | |
a3f17187 | 14730 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14731 | bptnum); |
14732 | else | |
3e43a32a MS |
14733 | printf_filtered (_("Will ignore next %d " |
14734 | "crossings of breakpoint %d."), | |
221ea385 KS |
14735 | count, bptnum); |
14736 | } | |
8d3788bd | 14737 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14738 | return; |
14739 | } | |
c906108c | 14740 | |
8a3fe4f8 | 14741 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14742 | } |
14743 | ||
c906108c SS |
14744 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14745 | ||
14746 | static void | |
fba45db2 | 14747 | ignore_command (char *args, int from_tty) |
c906108c SS |
14748 | { |
14749 | char *p = args; | |
52f0bd74 | 14750 | int num; |
c906108c SS |
14751 | |
14752 | if (p == 0) | |
e2e0b3e5 | 14753 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14754 | |
c906108c | 14755 | num = get_number (&p); |
5c44784c | 14756 | if (num == 0) |
8a3fe4f8 | 14757 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14758 | if (*p == 0) |
8a3fe4f8 | 14759 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14760 | |
14761 | set_ignore_count (num, | |
14762 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14763 | from_tty); | |
221ea385 KS |
14764 | if (from_tty) |
14765 | printf_filtered ("\n"); | |
c906108c SS |
14766 | } |
14767 | \f | |
14768 | /* Call FUNCTION on each of the breakpoints | |
14769 | whose numbers are given in ARGS. */ | |
14770 | ||
14771 | static void | |
95a42b64 TT |
14772 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14773 | void *), | |
14774 | void *data) | |
c906108c | 14775 | { |
52f0bd74 AC |
14776 | int num; |
14777 | struct breakpoint *b, *tmp; | |
c906108c | 14778 | |
b9d61307 | 14779 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14780 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14781 | |
bfd28288 | 14782 | number_or_range_parser parser (args); |
197f0a60 | 14783 | |
bfd28288 | 14784 | while (!parser.finished ()) |
c906108c | 14785 | { |
bfd28288 PA |
14786 | const char *p = parser.cur_tok (); |
14787 | bool match = false; | |
197f0a60 | 14788 | |
bfd28288 | 14789 | num = parser.get_number (); |
5c44784c | 14790 | if (num == 0) |
c5aa993b | 14791 | { |
8a3fe4f8 | 14792 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14793 | } |
14794 | else | |
14795 | { | |
14796 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14797 | if (b->number == num) | |
14798 | { | |
bfd28288 | 14799 | match = true; |
cdac0397 | 14800 | function (b, data); |
11cf8741 | 14801 | break; |
5c44784c | 14802 | } |
bfd28288 | 14803 | if (!match) |
a3f17187 | 14804 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14805 | } |
c906108c SS |
14806 | } |
14807 | } | |
14808 | ||
0d381245 VP |
14809 | static struct bp_location * |
14810 | find_location_by_number (char *number) | |
14811 | { | |
14812 | char *dot = strchr (number, '.'); | |
14813 | char *p1; | |
14814 | int bp_num; | |
14815 | int loc_num; | |
14816 | struct breakpoint *b; | |
14817 | struct bp_location *loc; | |
14818 | ||
14819 | *dot = '\0'; | |
14820 | ||
14821 | p1 = number; | |
197f0a60 | 14822 | bp_num = get_number (&p1); |
0d381245 VP |
14823 | if (bp_num == 0) |
14824 | error (_("Bad breakpoint number '%s'"), number); | |
14825 | ||
14826 | ALL_BREAKPOINTS (b) | |
14827 | if (b->number == bp_num) | |
14828 | { | |
14829 | break; | |
14830 | } | |
14831 | ||
14832 | if (!b || b->number != bp_num) | |
14833 | error (_("Bad breakpoint number '%s'"), number); | |
14834 | ||
14835 | p1 = dot+1; | |
197f0a60 | 14836 | loc_num = get_number (&p1); |
0d381245 VP |
14837 | if (loc_num == 0) |
14838 | error (_("Bad breakpoint location number '%s'"), number); | |
14839 | ||
14840 | --loc_num; | |
14841 | loc = b->loc; | |
14842 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14843 | ; | |
14844 | if (!loc) | |
14845 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14846 | ||
14847 | return loc; | |
14848 | } | |
14849 | ||
14850 | ||
1900040c MS |
14851 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14852 | If from_tty is nonzero, it prints a message to that effect, | |
14853 | which ends with a period (no newline). */ | |
14854 | ||
c906108c | 14855 | void |
fba45db2 | 14856 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14857 | { |
14858 | /* Never disable a watchpoint scope breakpoint; we want to | |
14859 | hit them when we leave scope so we can delete both the | |
14860 | watchpoint and its scope breakpoint at that time. */ | |
14861 | if (bpt->type == bp_watchpoint_scope) | |
14862 | return; | |
14863 | ||
b5de0fa7 | 14864 | bpt->enable_state = bp_disabled; |
c906108c | 14865 | |
b775012e LM |
14866 | /* Mark breakpoint locations modified. */ |
14867 | mark_breakpoint_modified (bpt); | |
14868 | ||
d248b706 KY |
14869 | if (target_supports_enable_disable_tracepoint () |
14870 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14871 | { | |
14872 | struct bp_location *location; | |
14873 | ||
14874 | for (location = bpt->loc; location; location = location->next) | |
14875 | target_disable_tracepoint (location); | |
14876 | } | |
14877 | ||
44702360 | 14878 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14879 | |
8d3788bd | 14880 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14881 | } |
14882 | ||
51be5b68 PA |
14883 | /* A callback for iterate_over_related_breakpoints. */ |
14884 | ||
14885 | static void | |
14886 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14887 | { | |
14888 | disable_breakpoint (b); | |
14889 | } | |
14890 | ||
95a42b64 TT |
14891 | /* A callback for map_breakpoint_numbers that calls |
14892 | disable_breakpoint. */ | |
14893 | ||
14894 | static void | |
14895 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14896 | { | |
51be5b68 | 14897 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14898 | } |
14899 | ||
c906108c | 14900 | static void |
fba45db2 | 14901 | disable_command (char *args, int from_tty) |
c906108c | 14902 | { |
c906108c | 14903 | if (args == 0) |
46c6471b PA |
14904 | { |
14905 | struct breakpoint *bpt; | |
14906 | ||
14907 | ALL_BREAKPOINTS (bpt) | |
14908 | if (user_breakpoint_p (bpt)) | |
14909 | disable_breakpoint (bpt); | |
14910 | } | |
9eaabc75 | 14911 | else |
0d381245 | 14912 | { |
9eaabc75 MW |
14913 | char *num = extract_arg (&args); |
14914 | ||
14915 | while (num) | |
d248b706 | 14916 | { |
9eaabc75 | 14917 | if (strchr (num, '.')) |
b775012e | 14918 | { |
9eaabc75 MW |
14919 | struct bp_location *loc = find_location_by_number (num); |
14920 | ||
14921 | if (loc) | |
14922 | { | |
14923 | if (loc->enabled) | |
14924 | { | |
14925 | loc->enabled = 0; | |
14926 | mark_breakpoint_location_modified (loc); | |
14927 | } | |
14928 | if (target_supports_enable_disable_tracepoint () | |
14929 | && current_trace_status ()->running && loc->owner | |
14930 | && is_tracepoint (loc->owner)) | |
14931 | target_disable_tracepoint (loc); | |
14932 | } | |
44702360 | 14933 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14934 | } |
9eaabc75 MW |
14935 | else |
14936 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14937 | num = extract_arg (&args); | |
d248b706 | 14938 | } |
0d381245 | 14939 | } |
c906108c SS |
14940 | } |
14941 | ||
14942 | static void | |
816338b5 SS |
14943 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14944 | int count) | |
c906108c | 14945 | { |
afe38095 | 14946 | int target_resources_ok; |
c906108c SS |
14947 | |
14948 | if (bpt->type == bp_hardware_breakpoint) | |
14949 | { | |
14950 | int i; | |
c5aa993b | 14951 | i = hw_breakpoint_used_count (); |
53a5351d | 14952 | target_resources_ok = |
d92524f1 | 14953 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14954 | i + 1, 0); |
c906108c | 14955 | if (target_resources_ok == 0) |
8a3fe4f8 | 14956 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14957 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14958 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14959 | } |
14960 | ||
cc60f2e3 | 14961 | if (is_watchpoint (bpt)) |
c906108c | 14962 | { |
d07205c2 | 14963 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14964 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14965 | |
492d29ea | 14966 | TRY |
c906108c | 14967 | { |
3a5c3e22 PA |
14968 | struct watchpoint *w = (struct watchpoint *) bpt; |
14969 | ||
1e718ff1 TJB |
14970 | orig_enable_state = bpt->enable_state; |
14971 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14972 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14973 | } |
492d29ea | 14974 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14975 | { |
1e718ff1 | 14976 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14977 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14978 | bpt->number); | |
14979 | return; | |
c5aa993b | 14980 | } |
492d29ea | 14981 | END_CATCH |
c906108c | 14982 | } |
0101ce28 | 14983 | |
b775012e LM |
14984 | bpt->enable_state = bp_enabled; |
14985 | ||
14986 | /* Mark breakpoint locations modified. */ | |
14987 | mark_breakpoint_modified (bpt); | |
14988 | ||
d248b706 KY |
14989 | if (target_supports_enable_disable_tracepoint () |
14990 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14991 | { | |
14992 | struct bp_location *location; | |
14993 | ||
14994 | for (location = bpt->loc; location; location = location->next) | |
14995 | target_enable_tracepoint (location); | |
14996 | } | |
14997 | ||
b4c291bb | 14998 | bpt->disposition = disposition; |
816338b5 | 14999 | bpt->enable_count = count; |
44702360 | 15000 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 15001 | |
8d3788bd | 15002 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15003 | } |
15004 | ||
fe3f5fa8 | 15005 | |
c906108c | 15006 | void |
fba45db2 | 15007 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 15008 | { |
816338b5 | 15009 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
15010 | } |
15011 | ||
15012 | static void | |
15013 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
15014 | { | |
15015 | enable_breakpoint (bpt); | |
c906108c SS |
15016 | } |
15017 | ||
95a42b64 TT |
15018 | /* A callback for map_breakpoint_numbers that calls |
15019 | enable_breakpoint. */ | |
15020 | ||
15021 | static void | |
15022 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15023 | { | |
51be5b68 | 15024 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15025 | } |
15026 | ||
c906108c SS |
15027 | /* The enable command enables the specified breakpoints (or all defined |
15028 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15029 | in stopping the inferior. */ |
c906108c | 15030 | |
c906108c | 15031 | static void |
fba45db2 | 15032 | enable_command (char *args, int from_tty) |
c906108c | 15033 | { |
c906108c | 15034 | if (args == 0) |
46c6471b PA |
15035 | { |
15036 | struct breakpoint *bpt; | |
15037 | ||
15038 | ALL_BREAKPOINTS (bpt) | |
15039 | if (user_breakpoint_p (bpt)) | |
15040 | enable_breakpoint (bpt); | |
15041 | } | |
9eaabc75 | 15042 | else |
0d381245 | 15043 | { |
9eaabc75 MW |
15044 | char *num = extract_arg (&args); |
15045 | ||
15046 | while (num) | |
d248b706 | 15047 | { |
9eaabc75 | 15048 | if (strchr (num, '.')) |
b775012e | 15049 | { |
9eaabc75 MW |
15050 | struct bp_location *loc = find_location_by_number (num); |
15051 | ||
15052 | if (loc) | |
15053 | { | |
15054 | if (!loc->enabled) | |
15055 | { | |
15056 | loc->enabled = 1; | |
15057 | mark_breakpoint_location_modified (loc); | |
15058 | } | |
15059 | if (target_supports_enable_disable_tracepoint () | |
15060 | && current_trace_status ()->running && loc->owner | |
15061 | && is_tracepoint (loc->owner)) | |
15062 | target_enable_tracepoint (loc); | |
15063 | } | |
44702360 | 15064 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15065 | } |
9eaabc75 MW |
15066 | else |
15067 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15068 | num = extract_arg (&args); | |
d248b706 | 15069 | } |
0d381245 | 15070 | } |
c906108c SS |
15071 | } |
15072 | ||
816338b5 SS |
15073 | /* This struct packages up disposition data for application to multiple |
15074 | breakpoints. */ | |
15075 | ||
15076 | struct disp_data | |
15077 | { | |
15078 | enum bpdisp disp; | |
15079 | int count; | |
15080 | }; | |
15081 | ||
c906108c | 15082 | static void |
51be5b68 PA |
15083 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15084 | { | |
816338b5 | 15085 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15086 | |
816338b5 | 15087 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15088 | } |
15089 | ||
15090 | static void | |
15091 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15092 | { |
816338b5 | 15093 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15094 | |
15095 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15096 | } |
15097 | ||
c906108c | 15098 | static void |
fba45db2 | 15099 | enable_once_command (char *args, int from_tty) |
c906108c | 15100 | { |
51be5b68 | 15101 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15102 | } |
15103 | ||
816338b5 SS |
15104 | static void |
15105 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15106 | { | |
15107 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15108 | ||
15109 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15110 | } | |
15111 | ||
15112 | static void | |
15113 | enable_count_command (char *args, int from_tty) | |
15114 | { | |
b9d61307 SM |
15115 | int count; |
15116 | ||
15117 | if (args == NULL) | |
15118 | error_no_arg (_("hit count")); | |
15119 | ||
15120 | count = get_number (&args); | |
816338b5 SS |
15121 | |
15122 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15123 | } | |
15124 | ||
c906108c | 15125 | static void |
51be5b68 | 15126 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15127 | { |
816338b5 | 15128 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15129 | |
15130 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15131 | } |
15132 | ||
c906108c | 15133 | static void |
fba45db2 | 15134 | enable_delete_command (char *args, int from_tty) |
c906108c | 15135 | { |
51be5b68 | 15136 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15137 | } |
15138 | \f | |
fa8d40ab JJ |
15139 | static void |
15140 | set_breakpoint_cmd (char *args, int from_tty) | |
15141 | { | |
15142 | } | |
15143 | ||
15144 | static void | |
15145 | show_breakpoint_cmd (char *args, int from_tty) | |
15146 | { | |
15147 | } | |
15148 | ||
1f3b5d1b PP |
15149 | /* Invalidate last known value of any hardware watchpoint if |
15150 | the memory which that value represents has been written to by | |
15151 | GDB itself. */ | |
15152 | ||
15153 | static void | |
8de0566d YQ |
15154 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15155 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15156 | const bfd_byte *data) |
15157 | { | |
15158 | struct breakpoint *bp; | |
15159 | ||
15160 | ALL_BREAKPOINTS (bp) | |
15161 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15162 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15163 | { |
3a5c3e22 | 15164 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15165 | |
3a5c3e22 PA |
15166 | if (wp->val_valid && wp->val) |
15167 | { | |
15168 | struct bp_location *loc; | |
15169 | ||
15170 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15171 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15172 | && loc->address + loc->length > addr | |
15173 | && addr + len > loc->address) | |
15174 | { | |
15175 | value_free (wp->val); | |
15176 | wp->val = NULL; | |
15177 | wp->val_valid = 0; | |
15178 | } | |
15179 | } | |
1f3b5d1b PP |
15180 | } |
15181 | } | |
15182 | ||
8181d85f DJ |
15183 | /* Create and insert a breakpoint for software single step. */ |
15184 | ||
15185 | void | |
6c95b8df | 15186 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15187 | struct address_space *aspace, |
15188 | CORE_ADDR next_pc) | |
8181d85f | 15189 | { |
7c16b83e PA |
15190 | struct thread_info *tp = inferior_thread (); |
15191 | struct symtab_and_line sal; | |
15192 | CORE_ADDR pc = next_pc; | |
8181d85f | 15193 | |
34b7e8a6 PA |
15194 | if (tp->control.single_step_breakpoints == NULL) |
15195 | { | |
15196 | tp->control.single_step_breakpoints | |
5d5658a1 | 15197 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 15198 | } |
8181d85f | 15199 | |
7c16b83e PA |
15200 | sal = find_pc_line (pc, 0); |
15201 | sal.pc = pc; | |
15202 | sal.section = find_pc_overlay (pc); | |
15203 | sal.explicit_pc = 1; | |
34b7e8a6 | 15204 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15205 | |
7c16b83e | 15206 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15207 | } |
15208 | ||
34b7e8a6 | 15209 | /* See breakpoint.h. */ |
f02253f1 HZ |
15210 | |
15211 | int | |
7c16b83e PA |
15212 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15213 | struct address_space *aspace, | |
15214 | CORE_ADDR pc) | |
1aafd4da | 15215 | { |
7c16b83e | 15216 | struct bp_location *loc; |
1aafd4da | 15217 | |
7c16b83e PA |
15218 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15219 | if (loc->inserted | |
15220 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15221 | return 1; | |
1aafd4da | 15222 | |
7c16b83e | 15223 | return 0; |
ef370185 JB |
15224 | } |
15225 | ||
15226 | /* Check whether a software single-step breakpoint is inserted at | |
15227 | PC. */ | |
15228 | ||
15229 | int | |
15230 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15231 | CORE_ADDR pc) | |
15232 | { | |
34b7e8a6 PA |
15233 | struct breakpoint *bpt; |
15234 | ||
15235 | ALL_BREAKPOINTS (bpt) | |
15236 | { | |
15237 | if (bpt->type == bp_single_step | |
15238 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15239 | return 1; | |
15240 | } | |
15241 | return 0; | |
1aafd4da UW |
15242 | } |
15243 | ||
1042e4c0 SS |
15244 | /* Tracepoint-specific operations. */ |
15245 | ||
15246 | /* Set tracepoint count to NUM. */ | |
15247 | static void | |
15248 | set_tracepoint_count (int num) | |
15249 | { | |
15250 | tracepoint_count = num; | |
4fa62494 | 15251 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15252 | } |
15253 | ||
70221824 | 15254 | static void |
1042e4c0 SS |
15255 | trace_command (char *arg, int from_tty) |
15256 | { | |
55aa24fb | 15257 | struct breakpoint_ops *ops; |
f00aae0f KS |
15258 | struct event_location *location; |
15259 | struct cleanup *back_to; | |
55aa24fb | 15260 | |
f00aae0f KS |
15261 | location = string_to_event_location (&arg, current_language); |
15262 | back_to = make_cleanup_delete_event_location (location); | |
5b56227b KS |
15263 | if (location != NULL |
15264 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
15265 | ops = &tracepoint_probe_breakpoint_ops; |
15266 | else | |
15267 | ops = &tracepoint_breakpoint_ops; | |
15268 | ||
558a9d82 | 15269 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15270 | location, |
15271 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15272 | 0 /* tempflag */, |
15273 | bp_tracepoint /* type_wanted */, | |
15274 | 0 /* Ignore count */, | |
15275 | pending_break_support, | |
15276 | ops, | |
15277 | from_tty, | |
15278 | 1 /* enabled */, | |
15279 | 0 /* internal */, 0); | |
f00aae0f | 15280 | do_cleanups (back_to); |
1042e4c0 SS |
15281 | } |
15282 | ||
70221824 | 15283 | static void |
7a697b8d SS |
15284 | ftrace_command (char *arg, int from_tty) |
15285 | { | |
f00aae0f KS |
15286 | struct event_location *location; |
15287 | struct cleanup *back_to; | |
15288 | ||
15289 | location = string_to_event_location (&arg, current_language); | |
15290 | back_to = make_cleanup_delete_event_location (location); | |
558a9d82 | 15291 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15292 | location, |
15293 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15294 | 0 /* tempflag */, |
15295 | bp_fast_tracepoint /* type_wanted */, | |
15296 | 0 /* Ignore count */, | |
15297 | pending_break_support, | |
15298 | &tracepoint_breakpoint_ops, | |
15299 | from_tty, | |
15300 | 1 /* enabled */, | |
15301 | 0 /* internal */, 0); | |
f00aae0f | 15302 | do_cleanups (back_to); |
0fb4aa4b PA |
15303 | } |
15304 | ||
15305 | /* strace command implementation. Creates a static tracepoint. */ | |
15306 | ||
70221824 | 15307 | static void |
0fb4aa4b PA |
15308 | strace_command (char *arg, int from_tty) |
15309 | { | |
983af33b | 15310 | struct breakpoint_ops *ops; |
f00aae0f KS |
15311 | struct event_location *location; |
15312 | struct cleanup *back_to; | |
983af33b SDJ |
15313 | |
15314 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15315 | or with a normal static tracepoint. */ | |
61012eef | 15316 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15317 | { |
15318 | ops = &strace_marker_breakpoint_ops; | |
15319 | location = new_linespec_location (&arg); | |
15320 | } | |
983af33b | 15321 | else |
f00aae0f KS |
15322 | { |
15323 | ops = &tracepoint_breakpoint_ops; | |
15324 | location = string_to_event_location (&arg, current_language); | |
15325 | } | |
983af33b | 15326 | |
f00aae0f | 15327 | back_to = make_cleanup_delete_event_location (location); |
558a9d82 | 15328 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15329 | location, |
15330 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15331 | 0 /* tempflag */, |
15332 | bp_static_tracepoint /* type_wanted */, | |
15333 | 0 /* Ignore count */, | |
15334 | pending_break_support, | |
15335 | ops, | |
15336 | from_tty, | |
15337 | 1 /* enabled */, | |
15338 | 0 /* internal */, 0); | |
f00aae0f | 15339 | do_cleanups (back_to); |
7a697b8d SS |
15340 | } |
15341 | ||
409873ef SS |
15342 | /* Set up a fake reader function that gets command lines from a linked |
15343 | list that was acquired during tracepoint uploading. */ | |
15344 | ||
15345 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15346 | static int next_cmd; |
409873ef SS |
15347 | |
15348 | static char * | |
15349 | read_uploaded_action (void) | |
15350 | { | |
15351 | char *rslt; | |
15352 | ||
3149d8c1 | 15353 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15354 | |
3149d8c1 | 15355 | next_cmd++; |
409873ef SS |
15356 | |
15357 | return rslt; | |
15358 | } | |
15359 | ||
00bf0b85 SS |
15360 | /* Given information about a tracepoint as recorded on a target (which |
15361 | can be either a live system or a trace file), attempt to create an | |
15362 | equivalent GDB tracepoint. This is not a reliable process, since | |
15363 | the target does not necessarily have all the information used when | |
15364 | the tracepoint was originally defined. */ | |
15365 | ||
d9b3f62e | 15366 | struct tracepoint * |
00bf0b85 | 15367 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15368 | { |
409873ef | 15369 | char *addr_str, small_buf[100]; |
d9b3f62e | 15370 | struct tracepoint *tp; |
f00aae0f KS |
15371 | struct event_location *location; |
15372 | struct cleanup *cleanup; | |
fd9b8c24 | 15373 | |
409873ef SS |
15374 | if (utp->at_string) |
15375 | addr_str = utp->at_string; | |
15376 | else | |
15377 | { | |
15378 | /* In the absence of a source location, fall back to raw | |
15379 | address. Since there is no way to confirm that the address | |
15380 | means the same thing as when the trace was started, warn the | |
15381 | user. */ | |
3e43a32a MS |
15382 | warning (_("Uploaded tracepoint %d has no " |
15383 | "source location, using raw address"), | |
409873ef | 15384 | utp->number); |
8c042590 | 15385 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15386 | addr_str = small_buf; |
15387 | } | |
15388 | ||
15389 | /* There's not much we can do with a sequence of bytecodes. */ | |
15390 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15391 | warning (_("Uploaded tracepoint %d condition " |
15392 | "has no source form, ignoring it"), | |
409873ef | 15393 | utp->number); |
d5551862 | 15394 | |
f00aae0f KS |
15395 | location = string_to_event_location (&addr_str, current_language); |
15396 | cleanup = make_cleanup_delete_event_location (location); | |
8cdf0e15 | 15397 | if (!create_breakpoint (get_current_arch (), |
f00aae0f KS |
15398 | location, |
15399 | utp->cond_string, -1, addr_str, | |
e7e0cddf | 15400 | 0 /* parse cond/thread */, |
8cdf0e15 | 15401 | 0 /* tempflag */, |
0fb4aa4b | 15402 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15403 | 0 /* Ignore count */, |
15404 | pending_break_support, | |
348d480f | 15405 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15406 | 0 /* from_tty */, |
84f4c1fe | 15407 | utp->enabled /* enabled */, |
44f238bb PA |
15408 | 0 /* internal */, |
15409 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
f00aae0f KS |
15410 | { |
15411 | do_cleanups (cleanup); | |
15412 | return NULL; | |
15413 | } | |
15414 | ||
15415 | do_cleanups (cleanup); | |
fd9b8c24 | 15416 | |
409873ef | 15417 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15418 | tp = get_tracepoint (tracepoint_count); |
15419 | gdb_assert (tp != NULL); | |
d5551862 | 15420 | |
00bf0b85 SS |
15421 | if (utp->pass > 0) |
15422 | { | |
8c042590 PM |
15423 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15424 | tp->base.number); | |
00bf0b85 | 15425 | |
409873ef | 15426 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15427 | } |
15428 | ||
409873ef SS |
15429 | /* If we have uploaded versions of the original commands, set up a |
15430 | special-purpose "reader" function and call the usual command line | |
15431 | reader, then pass the result to the breakpoint command-setting | |
15432 | function. */ | |
3149d8c1 | 15433 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15434 | { |
409873ef | 15435 | struct command_line *cmd_list; |
00bf0b85 | 15436 | |
409873ef | 15437 | this_utp = utp; |
3149d8c1 | 15438 | next_cmd = 0; |
d5551862 | 15439 | |
409873ef SS |
15440 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15441 | ||
d9b3f62e | 15442 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15443 | } |
3149d8c1 SS |
15444 | else if (!VEC_empty (char_ptr, utp->actions) |
15445 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15446 | warning (_("Uploaded tracepoint %d actions " |
15447 | "have no source form, ignoring them"), | |
409873ef | 15448 | utp->number); |
00bf0b85 | 15449 | |
f196051f SS |
15450 | /* Copy any status information that might be available. */ |
15451 | tp->base.hit_count = utp->hit_count; | |
15452 | tp->traceframe_usage = utp->traceframe_usage; | |
15453 | ||
00bf0b85 | 15454 | return tp; |
d9b3f62e | 15455 | } |
00bf0b85 | 15456 | |
1042e4c0 SS |
15457 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15458 | omitted. */ | |
15459 | ||
15460 | static void | |
e5a67952 | 15461 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15462 | { |
79a45e25 | 15463 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15464 | int num_printed; |
1042e4c0 | 15465 | |
e5a67952 | 15466 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15467 | |
15468 | if (num_printed == 0) | |
1042e4c0 | 15469 | { |
e5a67952 | 15470 | if (args == NULL || *args == '\0') |
d77f58be SS |
15471 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15472 | else | |
e5a67952 | 15473 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15474 | } |
ad443146 SS |
15475 | |
15476 | default_collect_info (); | |
1042e4c0 SS |
15477 | } |
15478 | ||
4a64f543 | 15479 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15480 | Not supported by all targets. */ |
15481 | static void | |
15482 | enable_trace_command (char *args, int from_tty) | |
15483 | { | |
15484 | enable_command (args, from_tty); | |
15485 | } | |
15486 | ||
4a64f543 | 15487 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15488 | Not supported by all targets. */ |
15489 | static void | |
15490 | disable_trace_command (char *args, int from_tty) | |
15491 | { | |
15492 | disable_command (args, from_tty); | |
15493 | } | |
15494 | ||
4a64f543 | 15495 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15496 | static void |
15497 | delete_trace_command (char *arg, int from_tty) | |
15498 | { | |
35df4500 | 15499 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15500 | |
15501 | dont_repeat (); | |
15502 | ||
15503 | if (arg == 0) | |
15504 | { | |
15505 | int breaks_to_delete = 0; | |
15506 | ||
15507 | /* Delete all breakpoints if no argument. | |
15508 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15509 | have to be deleted with an explicit breakpoint number |
15510 | argument. */ | |
1042e4c0 | 15511 | ALL_TRACEPOINTS (b) |
46c6471b | 15512 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15513 | { |
15514 | breaks_to_delete = 1; | |
15515 | break; | |
15516 | } | |
1042e4c0 SS |
15517 | |
15518 | /* Ask user only if there are some breakpoints to delete. */ | |
15519 | if (!from_tty | |
15520 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15521 | { | |
35df4500 | 15522 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15523 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15524 | delete_breakpoint (b); |
1042e4c0 SS |
15525 | } |
15526 | } | |
15527 | else | |
51be5b68 | 15528 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15529 | } |
15530 | ||
197f0a60 TT |
15531 | /* Helper function for trace_pass_command. */ |
15532 | ||
15533 | static void | |
d9b3f62e | 15534 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15535 | { |
d9b3f62e | 15536 | tp->pass_count = count; |
6f6484cd | 15537 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15538 | if (from_tty) |
15539 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15540 | tp->base.number, count); |
197f0a60 TT |
15541 | } |
15542 | ||
1042e4c0 SS |
15543 | /* Set passcount for tracepoint. |
15544 | ||
15545 | First command argument is passcount, second is tracepoint number. | |
15546 | If tracepoint number omitted, apply to most recently defined. | |
15547 | Also accepts special argument "all". */ | |
15548 | ||
15549 | static void | |
15550 | trace_pass_command (char *args, int from_tty) | |
15551 | { | |
d9b3f62e | 15552 | struct tracepoint *t1; |
1042e4c0 | 15553 | unsigned int count; |
1042e4c0 SS |
15554 | |
15555 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15556 | error (_("passcount command requires an " |
15557 | "argument (count + optional TP num)")); | |
1042e4c0 | 15558 | |
4a64f543 | 15559 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15560 | |
529480d0 | 15561 | args = skip_spaces (args); |
1042e4c0 SS |
15562 | if (*args && strncasecmp (args, "all", 3) == 0) |
15563 | { | |
d9b3f62e PA |
15564 | struct breakpoint *b; |
15565 | ||
1042e4c0 | 15566 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15567 | if (*args) |
15568 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15569 | |
d9b3f62e | 15570 | ALL_TRACEPOINTS (b) |
197f0a60 | 15571 | { |
d9b3f62e | 15572 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15573 | trace_pass_set_count (t1, count, from_tty); |
15574 | } | |
15575 | } | |
15576 | else if (*args == '\0') | |
1042e4c0 | 15577 | { |
5fa1d40e | 15578 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15579 | if (t1) |
197f0a60 TT |
15580 | trace_pass_set_count (t1, count, from_tty); |
15581 | } | |
15582 | else | |
15583 | { | |
bfd28288 PA |
15584 | number_or_range_parser parser (args); |
15585 | while (!parser.finished ()) | |
1042e4c0 | 15586 | { |
bfd28288 | 15587 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15588 | if (t1) |
15589 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15590 | } |
15591 | } | |
1042e4c0 SS |
15592 | } |
15593 | ||
d9b3f62e | 15594 | struct tracepoint * |
1042e4c0 SS |
15595 | get_tracepoint (int num) |
15596 | { | |
15597 | struct breakpoint *t; | |
15598 | ||
15599 | ALL_TRACEPOINTS (t) | |
15600 | if (t->number == num) | |
d9b3f62e | 15601 | return (struct tracepoint *) t; |
1042e4c0 SS |
15602 | |
15603 | return NULL; | |
15604 | } | |
15605 | ||
d5551862 SS |
15606 | /* Find the tracepoint with the given target-side number (which may be |
15607 | different from the tracepoint number after disconnecting and | |
15608 | reconnecting). */ | |
15609 | ||
d9b3f62e | 15610 | struct tracepoint * |
d5551862 SS |
15611 | get_tracepoint_by_number_on_target (int num) |
15612 | { | |
d9b3f62e | 15613 | struct breakpoint *b; |
d5551862 | 15614 | |
d9b3f62e PA |
15615 | ALL_TRACEPOINTS (b) |
15616 | { | |
15617 | struct tracepoint *t = (struct tracepoint *) b; | |
15618 | ||
15619 | if (t->number_on_target == num) | |
15620 | return t; | |
15621 | } | |
d5551862 SS |
15622 | |
15623 | return NULL; | |
15624 | } | |
15625 | ||
1042e4c0 | 15626 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15627 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15628 | If the argument is missing, the most recent tracepoint |
15629 | (tracepoint_count) is returned. */ | |
15630 | ||
d9b3f62e | 15631 | struct tracepoint * |
197f0a60 | 15632 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15633 | number_or_range_parser *parser) |
1042e4c0 | 15634 | { |
1042e4c0 SS |
15635 | struct breakpoint *t; |
15636 | int tpnum; | |
15637 | char *instring = arg == NULL ? NULL : *arg; | |
15638 | ||
bfd28288 | 15639 | if (parser != NULL) |
197f0a60 | 15640 | { |
bfd28288 PA |
15641 | gdb_assert (!parser->finished ()); |
15642 | tpnum = parser->get_number (); | |
197f0a60 TT |
15643 | } |
15644 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15645 | tpnum = tracepoint_count; |
1042e4c0 | 15646 | else |
197f0a60 | 15647 | tpnum = get_number (arg); |
1042e4c0 SS |
15648 | |
15649 | if (tpnum <= 0) | |
15650 | { | |
15651 | if (instring && *instring) | |
15652 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15653 | instring); | |
15654 | else | |
5fa1d40e | 15655 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15656 | return NULL; |
15657 | } | |
15658 | ||
15659 | ALL_TRACEPOINTS (t) | |
15660 | if (t->number == tpnum) | |
15661 | { | |
d9b3f62e | 15662 | return (struct tracepoint *) t; |
1042e4c0 SS |
15663 | } |
15664 | ||
1042e4c0 SS |
15665 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15666 | return NULL; | |
15667 | } | |
15668 | ||
d9b3f62e PA |
15669 | void |
15670 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15671 | { | |
15672 | if (b->thread != -1) | |
15673 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15674 | ||
15675 | if (b->task != 0) | |
15676 | fprintf_unfiltered (fp, " task %d", b->task); | |
15677 | ||
15678 | fprintf_unfiltered (fp, "\n"); | |
15679 | } | |
15680 | ||
6149aea9 PA |
15681 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15682 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15683 | on each breakpoint and only include the ones for which it returns | |
15684 | non-zero. */ | |
15685 | ||
1042e4c0 | 15686 | static void |
6149aea9 PA |
15687 | save_breakpoints (char *filename, int from_tty, |
15688 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15689 | { |
15690 | struct breakpoint *tp; | |
6149aea9 | 15691 | int any = 0; |
1042e4c0 | 15692 | struct cleanup *cleanup; |
a7bdde9e | 15693 | struct ui_file *fp; |
6149aea9 | 15694 | int extra_trace_bits = 0; |
1042e4c0 | 15695 | |
6149aea9 PA |
15696 | if (filename == 0 || *filename == 0) |
15697 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15698 | |
15699 | /* See if we have anything to save. */ | |
6149aea9 | 15700 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15701 | { |
6149aea9 | 15702 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15703 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15704 | continue; |
15705 | ||
15706 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15707 | if (filter && !filter (tp)) | |
15708 | continue; | |
15709 | ||
15710 | any = 1; | |
15711 | ||
15712 | if (is_tracepoint (tp)) | |
15713 | { | |
15714 | extra_trace_bits = 1; | |
15715 | ||
15716 | /* We can stop searching. */ | |
15717 | break; | |
15718 | } | |
1042e4c0 | 15719 | } |
6149aea9 PA |
15720 | |
15721 | if (!any) | |
1042e4c0 | 15722 | { |
6149aea9 | 15723 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15724 | return; |
15725 | } | |
15726 | ||
c718be47 PA |
15727 | filename = tilde_expand (filename); |
15728 | cleanup = make_cleanup (xfree, filename); | |
15729 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15730 | if (!fp) |
6149aea9 PA |
15731 | error (_("Unable to open file '%s' for saving (%s)"), |
15732 | filename, safe_strerror (errno)); | |
a7bdde9e | 15733 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15734 | |
6149aea9 PA |
15735 | if (extra_trace_bits) |
15736 | save_trace_state_variables (fp); | |
8bf6485c | 15737 | |
6149aea9 | 15738 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15739 | { |
6149aea9 | 15740 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15741 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15742 | continue; |
8bf6485c | 15743 | |
6149aea9 PA |
15744 | /* If we have a filter, only save the breakpoints it accepts. */ |
15745 | if (filter && !filter (tp)) | |
15746 | continue; | |
15747 | ||
348d480f | 15748 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15749 | |
6149aea9 PA |
15750 | /* Note, we can't rely on tp->number for anything, as we can't |
15751 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15752 | instead. */ | |
15753 | ||
15754 | if (tp->cond_string) | |
15755 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15756 | ||
15757 | if (tp->ignore_count) | |
15758 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15759 | ||
2d9442cc | 15760 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15761 | { |
6149aea9 | 15762 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15763 | |
79a45e25 | 15764 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15765 | TRY |
1042e4c0 | 15766 | { |
79a45e25 | 15767 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15768 | } |
492d29ea PA |
15769 | CATCH (ex, RETURN_MASK_ALL) |
15770 | { | |
6c63c96a | 15771 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15772 | throw_exception (ex); |
15773 | } | |
15774 | END_CATCH | |
1042e4c0 | 15775 | |
6c63c96a | 15776 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15777 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15778 | } |
6149aea9 PA |
15779 | |
15780 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15781 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15782 | |
15783 | /* If this is a multi-location breakpoint, check if the locations | |
15784 | should be individually disabled. Watchpoint locations are | |
15785 | special, and not user visible. */ | |
15786 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15787 | { | |
15788 | struct bp_location *loc; | |
15789 | int n = 1; | |
15790 | ||
15791 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15792 | if (!loc->enabled) | |
15793 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15794 | } | |
1042e4c0 | 15795 | } |
8bf6485c | 15796 | |
6149aea9 | 15797 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15798 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15799 | ||
1042e4c0 | 15800 | if (from_tty) |
6149aea9 | 15801 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15802 | do_cleanups (cleanup); |
6149aea9 PA |
15803 | } |
15804 | ||
15805 | /* The `save breakpoints' command. */ | |
15806 | ||
15807 | static void | |
15808 | save_breakpoints_command (char *args, int from_tty) | |
15809 | { | |
15810 | save_breakpoints (args, from_tty, NULL); | |
15811 | } | |
15812 | ||
15813 | /* The `save tracepoints' command. */ | |
15814 | ||
15815 | static void | |
15816 | save_tracepoints_command (char *args, int from_tty) | |
15817 | { | |
15818 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15819 | } |
15820 | ||
15821 | /* Create a vector of all tracepoints. */ | |
15822 | ||
15823 | VEC(breakpoint_p) * | |
eeae04df | 15824 | all_tracepoints (void) |
1042e4c0 SS |
15825 | { |
15826 | VEC(breakpoint_p) *tp_vec = 0; | |
15827 | struct breakpoint *tp; | |
15828 | ||
15829 | ALL_TRACEPOINTS (tp) | |
15830 | { | |
15831 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15832 | } | |
15833 | ||
15834 | return tp_vec; | |
15835 | } | |
15836 | ||
c906108c | 15837 | \f |
629500fa KS |
15838 | /* This help string is used to consolidate all the help string for specifying |
15839 | locations used by several commands. */ | |
15840 | ||
15841 | #define LOCATION_HELP_STRING \ | |
15842 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15843 | source filename, function name, label name, and line number.\n\ | |
15844 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15845 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15846 | \"factorial.c:fact:the_top\".\n\ | |
15847 | \n\ | |
15848 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15849 | program. Example: To specify the fourth byte past the start function\n\ | |
15850 | \"main\", use \"*main + 4\".\n\ | |
15851 | \n\ | |
15852 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15853 | syntax to specify location parameters.\n\ | |
15854 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15855 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15856 | -function fact -label the_top\".\n" | |
15857 | ||
4a64f543 MS |
15858 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15859 | commands. It is defined as a macro to prevent duplication. | |
15860 | COMMAND should be a string constant containing the name of the | |
15861 | command. */ | |
629500fa | 15862 | |
31e2b00f | 15863 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15864 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15865 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15866 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15867 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15868 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15869 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15870 | below.\n\ | |
15871 | \n\ | |
dc10affe PA |
15872 | With no LOCATION, uses current execution address of the selected\n\ |
15873 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15874 | \n\ |
15875 | THREADNUM is the number from \"info threads\".\n\ | |
15876 | CONDITION is a boolean expression.\n\ | |
629500fa | 15877 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15878 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15879 | conditions are different.\n\ | |
31e2b00f AS |
15880 | \n\ |
15881 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15882 | ||
44feb3ce TT |
15883 | /* List of subcommands for "catch". */ |
15884 | static struct cmd_list_element *catch_cmdlist; | |
15885 | ||
15886 | /* List of subcommands for "tcatch". */ | |
15887 | static struct cmd_list_element *tcatch_cmdlist; | |
15888 | ||
9ac4176b | 15889 | void |
44feb3ce | 15890 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15891 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15892 | completer_ftype *completer, |
44feb3ce TT |
15893 | void *user_data_catch, |
15894 | void *user_data_tcatch) | |
15895 | { | |
15896 | struct cmd_list_element *command; | |
15897 | ||
15898 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15899 | &catch_cmdlist); | |
15900 | set_cmd_sfunc (command, sfunc); | |
15901 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15902 | set_cmd_completer (command, completer); |
44feb3ce TT |
15903 | |
15904 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15905 | &tcatch_cmdlist); | |
15906 | set_cmd_sfunc (command, sfunc); | |
15907 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15908 | set_cmd_completer (command, completer); |
44feb3ce TT |
15909 | } |
15910 | ||
6149aea9 PA |
15911 | static void |
15912 | save_command (char *arg, int from_tty) | |
15913 | { | |
3e43a32a MS |
15914 | printf_unfiltered (_("\"save\" must be followed by " |
15915 | "the name of a save subcommand.\n")); | |
635c7e8a | 15916 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15917 | } |
15918 | ||
84f4c1fe PM |
15919 | struct breakpoint * |
15920 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15921 | void *data) | |
15922 | { | |
35df4500 | 15923 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15924 | |
35df4500 | 15925 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15926 | { |
15927 | if ((*callback) (b, data)) | |
15928 | return b; | |
15929 | } | |
15930 | ||
15931 | return NULL; | |
15932 | } | |
15933 | ||
0574c78f GB |
15934 | /* Zero if any of the breakpoint's locations could be a location where |
15935 | functions have been inlined, nonzero otherwise. */ | |
15936 | ||
15937 | static int | |
15938 | is_non_inline_function (struct breakpoint *b) | |
15939 | { | |
15940 | /* The shared library event breakpoint is set on the address of a | |
15941 | non-inline function. */ | |
15942 | if (b->type == bp_shlib_event) | |
15943 | return 1; | |
15944 | ||
15945 | return 0; | |
15946 | } | |
15947 | ||
15948 | /* Nonzero if the specified PC cannot be a location where functions | |
15949 | have been inlined. */ | |
15950 | ||
15951 | int | |
09ac7c10 TT |
15952 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15953 | const struct target_waitstatus *ws) | |
0574c78f GB |
15954 | { |
15955 | struct breakpoint *b; | |
15956 | struct bp_location *bl; | |
15957 | ||
15958 | ALL_BREAKPOINTS (b) | |
15959 | { | |
15960 | if (!is_non_inline_function (b)) | |
15961 | continue; | |
15962 | ||
15963 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15964 | { | |
15965 | if (!bl->shlib_disabled | |
09ac7c10 | 15966 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15967 | return 1; |
15968 | } | |
15969 | } | |
15970 | ||
15971 | return 0; | |
15972 | } | |
15973 | ||
2f202fde JK |
15974 | /* Remove any references to OBJFILE which is going to be freed. */ |
15975 | ||
15976 | void | |
15977 | breakpoint_free_objfile (struct objfile *objfile) | |
15978 | { | |
15979 | struct bp_location **locp, *loc; | |
15980 | ||
15981 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15982 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15983 | loc->symtab = NULL; |
15984 | } | |
15985 | ||
2060206e PA |
15986 | void |
15987 | initialize_breakpoint_ops (void) | |
15988 | { | |
15989 | static int initialized = 0; | |
15990 | ||
15991 | struct breakpoint_ops *ops; | |
15992 | ||
15993 | if (initialized) | |
15994 | return; | |
15995 | initialized = 1; | |
15996 | ||
15997 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15998 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15999 | internal and momentary breakpoints, etc.). */ | |
16000 | ops = &bkpt_base_breakpoint_ops; | |
16001 | *ops = base_breakpoint_ops; | |
16002 | ops->re_set = bkpt_re_set; | |
16003 | ops->insert_location = bkpt_insert_location; | |
16004 | ops->remove_location = bkpt_remove_location; | |
16005 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 16006 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 16007 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 16008 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
16009 | |
16010 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16011 | ops = &bkpt_breakpoint_ops; | |
16012 | *ops = bkpt_base_breakpoint_ops; | |
16013 | ops->re_set = bkpt_re_set; | |
16014 | ops->resources_needed = bkpt_resources_needed; | |
16015 | ops->print_it = bkpt_print_it; | |
16016 | ops->print_mention = bkpt_print_mention; | |
16017 | ops->print_recreate = bkpt_print_recreate; | |
16018 | ||
16019 | /* Ranged breakpoints. */ | |
16020 | ops = &ranged_breakpoint_ops; | |
16021 | *ops = bkpt_breakpoint_ops; | |
16022 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16023 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16024 | ops->print_it = print_it_ranged_breakpoint; | |
16025 | ops->print_one = print_one_ranged_breakpoint; | |
16026 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16027 | ops->print_mention = print_mention_ranged_breakpoint; | |
16028 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16029 | ||
16030 | /* Internal breakpoints. */ | |
16031 | ops = &internal_breakpoint_ops; | |
16032 | *ops = bkpt_base_breakpoint_ops; | |
16033 | ops->re_set = internal_bkpt_re_set; | |
16034 | ops->check_status = internal_bkpt_check_status; | |
16035 | ops->print_it = internal_bkpt_print_it; | |
16036 | ops->print_mention = internal_bkpt_print_mention; | |
16037 | ||
16038 | /* Momentary breakpoints. */ | |
16039 | ops = &momentary_breakpoint_ops; | |
16040 | *ops = bkpt_base_breakpoint_ops; | |
16041 | ops->re_set = momentary_bkpt_re_set; | |
16042 | ops->check_status = momentary_bkpt_check_status; | |
16043 | ops->print_it = momentary_bkpt_print_it; | |
16044 | ops->print_mention = momentary_bkpt_print_mention; | |
16045 | ||
e2e4d78b JK |
16046 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16047 | ops = &longjmp_breakpoint_ops; | |
16048 | *ops = momentary_breakpoint_ops; | |
16049 | ops->dtor = longjmp_bkpt_dtor; | |
16050 | ||
55aa24fb SDJ |
16051 | /* Probe breakpoints. */ |
16052 | ops = &bkpt_probe_breakpoint_ops; | |
16053 | *ops = bkpt_breakpoint_ops; | |
16054 | ops->insert_location = bkpt_probe_insert_location; | |
16055 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
16056 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
16057 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 16058 | |
2060206e PA |
16059 | /* Watchpoints. */ |
16060 | ops = &watchpoint_breakpoint_ops; | |
16061 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16062 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16063 | ops->re_set = re_set_watchpoint; |
16064 | ops->insert_location = insert_watchpoint; | |
16065 | ops->remove_location = remove_watchpoint; | |
16066 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16067 | ops->check_status = check_status_watchpoint; | |
16068 | ops->resources_needed = resources_needed_watchpoint; | |
16069 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16070 | ops->print_it = print_it_watchpoint; | |
16071 | ops->print_mention = print_mention_watchpoint; | |
16072 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16073 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16074 | |
16075 | /* Masked watchpoints. */ | |
16076 | ops = &masked_watchpoint_breakpoint_ops; | |
16077 | *ops = watchpoint_breakpoint_ops; | |
16078 | ops->insert_location = insert_masked_watchpoint; | |
16079 | ops->remove_location = remove_masked_watchpoint; | |
16080 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16081 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16082 | ops->print_it = print_it_masked_watchpoint; | |
16083 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16084 | ops->print_mention = print_mention_masked_watchpoint; | |
16085 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16086 | ||
16087 | /* Tracepoints. */ | |
16088 | ops = &tracepoint_breakpoint_ops; | |
16089 | *ops = base_breakpoint_ops; | |
16090 | ops->re_set = tracepoint_re_set; | |
16091 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16092 | ops->print_one_detail = tracepoint_print_one_detail; | |
16093 | ops->print_mention = tracepoint_print_mention; | |
16094 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 16095 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 16096 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 16097 | ops->decode_location = tracepoint_decode_location; |
983af33b | 16098 | |
55aa24fb SDJ |
16099 | /* Probe tracepoints. */ |
16100 | ops = &tracepoint_probe_breakpoint_ops; | |
16101 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
16102 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
16103 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 16104 | |
983af33b SDJ |
16105 | /* Static tracepoints with marker (`-m'). */ |
16106 | ops = &strace_marker_breakpoint_ops; | |
16107 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 16108 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 16109 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 16110 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
16111 | |
16112 | /* Fork catchpoints. */ | |
16113 | ops = &catch_fork_breakpoint_ops; | |
16114 | *ops = base_breakpoint_ops; | |
16115 | ops->insert_location = insert_catch_fork; | |
16116 | ops->remove_location = remove_catch_fork; | |
16117 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16118 | ops->print_it = print_it_catch_fork; | |
16119 | ops->print_one = print_one_catch_fork; | |
16120 | ops->print_mention = print_mention_catch_fork; | |
16121 | ops->print_recreate = print_recreate_catch_fork; | |
16122 | ||
16123 | /* Vfork catchpoints. */ | |
16124 | ops = &catch_vfork_breakpoint_ops; | |
16125 | *ops = base_breakpoint_ops; | |
16126 | ops->insert_location = insert_catch_vfork; | |
16127 | ops->remove_location = remove_catch_vfork; | |
16128 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16129 | ops->print_it = print_it_catch_vfork; | |
16130 | ops->print_one = print_one_catch_vfork; | |
16131 | ops->print_mention = print_mention_catch_vfork; | |
16132 | ops->print_recreate = print_recreate_catch_vfork; | |
16133 | ||
16134 | /* Exec catchpoints. */ | |
16135 | ops = &catch_exec_breakpoint_ops; | |
16136 | *ops = base_breakpoint_ops; | |
16137 | ops->dtor = dtor_catch_exec; | |
16138 | ops->insert_location = insert_catch_exec; | |
16139 | ops->remove_location = remove_catch_exec; | |
16140 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16141 | ops->print_it = print_it_catch_exec; | |
16142 | ops->print_one = print_one_catch_exec; | |
16143 | ops->print_mention = print_mention_catch_exec; | |
16144 | ops->print_recreate = print_recreate_catch_exec; | |
16145 | ||
edcc5120 TT |
16146 | /* Solib-related catchpoints. */ |
16147 | ops = &catch_solib_breakpoint_ops; | |
16148 | *ops = base_breakpoint_ops; | |
16149 | ops->dtor = dtor_catch_solib; | |
16150 | ops->insert_location = insert_catch_solib; | |
16151 | ops->remove_location = remove_catch_solib; | |
16152 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16153 | ops->check_status = check_status_catch_solib; | |
16154 | ops->print_it = print_it_catch_solib; | |
16155 | ops->print_one = print_one_catch_solib; | |
16156 | ops->print_mention = print_mention_catch_solib; | |
16157 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16158 | |
16159 | ops = &dprintf_breakpoint_ops; | |
16160 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16161 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16162 | ops->resources_needed = bkpt_resources_needed; |
16163 | ops->print_it = bkpt_print_it; | |
16164 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16165 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16166 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16167 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16168 | } |
16169 | ||
8bfd80db YQ |
16170 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16171 | ||
16172 | static struct cmd_list_element *enablebreaklist = NULL; | |
16173 | ||
c906108c | 16174 | void |
fba45db2 | 16175 | _initialize_breakpoint (void) |
c906108c SS |
16176 | { |
16177 | struct cmd_list_element *c; | |
16178 | ||
2060206e PA |
16179 | initialize_breakpoint_ops (); |
16180 | ||
84acb35a | 16181 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16182 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16183 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16184 | |
55aa24fb SDJ |
16185 | breakpoint_objfile_key |
16186 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16187 | |
c906108c SS |
16188 | breakpoint_chain = 0; |
16189 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16190 | before a breakpoint is set. */ | |
16191 | breakpoint_count = 0; | |
16192 | ||
1042e4c0 SS |
16193 | tracepoint_count = 0; |
16194 | ||
1bedd215 AC |
16195 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16196 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16197 | Usage is `ignore N COUNT'.")); | |
c906108c | 16198 | |
1bedd215 AC |
16199 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16200 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16201 | Give breakpoint number as argument after \"commands\".\n\ |
16202 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16203 | The commands themselves follow starting on the next line.\n\ | |
16204 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16205 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16206 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16207 | |
d55637df | 16208 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16209 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16210 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16211 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16212 | set_cmd_completer (c, condition_completer); |
c906108c | 16213 | |
1bedd215 | 16214 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16215 | Set a temporary breakpoint.\n\ |
c906108c SS |
16216 | Like \"break\" except the breakpoint is only temporary,\n\ |
16217 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16218 | by using \"enable delete\" on the breakpoint number.\n\ |
16219 | \n" | |
16220 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16221 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16222 | |
1bedd215 | 16223 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16224 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16225 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16226 | some target hardware may not have this support.\n\ |
16227 | \n" | |
16228 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16229 | set_cmd_completer (c, location_completer); |
c906108c | 16230 | |
1bedd215 | 16231 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16232 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16233 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16234 | so it will be deleted when hit.\n\ |
16235 | \n" | |
16236 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16237 | set_cmd_completer (c, location_completer); |
c906108c | 16238 | |
1bedd215 AC |
16239 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16240 | Enable some breakpoints.\n\ | |
c906108c SS |
16241 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16242 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16243 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16244 | With a subcommand you can enable temporarily."), |
c906108c | 16245 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16246 | |
16247 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16248 | ||
84951ab5 | 16249 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16250 | Enable some breakpoints.\n\ |
c906108c SS |
16251 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16252 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16253 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16254 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16255 | |
1a966eab AC |
16256 | add_cmd ("once", no_class, enable_once_command, _("\ |
16257 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16258 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16259 | &enablebreaklist); |
16260 | ||
1a966eab AC |
16261 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16262 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16263 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16264 | &enablebreaklist); |
16265 | ||
816338b5 SS |
16266 | add_cmd ("count", no_class, enable_count_command, _("\ |
16267 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16268 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16269 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16270 | &enablebreaklist); | |
16271 | ||
1a966eab AC |
16272 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16273 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16274 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16275 | &enablelist); |
16276 | ||
1a966eab AC |
16277 | add_cmd ("once", no_class, enable_once_command, _("\ |
16278 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16279 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16280 | &enablelist); |
16281 | ||
16282 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16283 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16284 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16285 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16286 | &enablelist); |
16287 | ||
1bedd215 AC |
16288 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16289 | Disable some breakpoints.\n\ | |
c906108c SS |
16290 | Arguments are breakpoint numbers with spaces in between.\n\ |
16291 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16292 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16293 | &disablelist, "disable ", 1, &cmdlist); |
16294 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16295 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16296 | |
1a966eab AC |
16297 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16298 | Disable some breakpoints.\n\ | |
c906108c SS |
16299 | Arguments are breakpoint numbers with spaces in between.\n\ |
16300 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16301 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16302 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16303 | &disablelist); |
16304 | ||
1bedd215 AC |
16305 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16306 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16307 | Arguments are breakpoint numbers with spaces in between.\n\ |
16308 | To delete all breakpoints, give no argument.\n\ | |
16309 | \n\ | |
16310 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16311 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16312 | &deletelist, "delete ", 1, &cmdlist); |
16313 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16314 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16315 | |
1a966eab AC |
16316 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16317 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16318 | Arguments are breakpoint numbers with spaces in between.\n\ |
16319 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16320 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16321 | &deletelist); |
16322 | ||
1bedd215 | 16323 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16324 | Clear breakpoint at specified location.\n\ |
16325 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16326 | \n\ |
16327 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16328 | is executing in.\n" |
16329 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16330 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16331 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16332 | |
1bedd215 | 16333 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16334 | Set breakpoint at specified location.\n" |
31e2b00f | 16335 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16336 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16337 | |
c906108c SS |
16338 | add_com_alias ("b", "break", class_run, 1); |
16339 | add_com_alias ("br", "break", class_run, 1); | |
16340 | add_com_alias ("bre", "break", class_run, 1); | |
16341 | add_com_alias ("brea", "break", class_run, 1); | |
16342 | ||
c906108c SS |
16343 | if (dbx_commands) |
16344 | { | |
1bedd215 AC |
16345 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16346 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16347 | &stoplist, "stop ", 1, &cmdlist); |
16348 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16349 | _("Break in function or address."), &stoplist); |
c5aa993b | 16350 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16351 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16352 | add_com ("status", class_info, breakpoints_info, _("\ |
16353 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16354 | The \"Type\" column indicates one of:\n\ |
16355 | \tbreakpoint - normal breakpoint\n\ | |
16356 | \twatchpoint - watchpoint\n\ | |
16357 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16358 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16359 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16360 | address and file/line number respectively.\n\ |
16361 | \n\ | |
16362 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16363 | are set to the address of the last breakpoint listed unless the command\n\ |
16364 | is prefixed with \"server \".\n\n\ | |
c906108c | 16365 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16366 | breakpoint set.")); |
c906108c SS |
16367 | } |
16368 | ||
1bedd215 | 16369 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16370 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16371 | The \"Type\" column indicates one of:\n\ |
16372 | \tbreakpoint - normal breakpoint\n\ | |
16373 | \twatchpoint - watchpoint\n\ | |
16374 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16375 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16376 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16377 | address and file/line number respectively.\n\ |
16378 | \n\ | |
16379 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16380 | are set to the address of the last breakpoint listed unless the command\n\ |
16381 | is prefixed with \"server \".\n\n\ | |
c906108c | 16382 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16383 | breakpoint set.")); |
c906108c | 16384 | |
6b04bdb7 MS |
16385 | add_info_alias ("b", "breakpoints", 1); |
16386 | ||
1a966eab AC |
16387 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16388 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16389 | The \"Type\" column indicates one of:\n\ |
16390 | \tbreakpoint - normal breakpoint\n\ | |
16391 | \twatchpoint - watchpoint\n\ | |
16392 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16393 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16394 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16395 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16396 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16397 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16398 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16399 | address and file/line number respectively.\n\ |
16400 | \n\ | |
16401 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16402 | are set to the address of the last breakpoint listed unless the command\n\ |
16403 | is prefixed with \"server \".\n\n\ | |
c906108c | 16404 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16405 | breakpoint set."), |
c906108c SS |
16406 | &maintenanceinfolist); |
16407 | ||
44feb3ce TT |
16408 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16409 | Set catchpoints to catch events."), | |
16410 | &catch_cmdlist, "catch ", | |
16411 | 0/*allow-unknown*/, &cmdlist); | |
16412 | ||
16413 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16414 | Set temporary catchpoints to catch events."), | |
16415 | &tcatch_cmdlist, "tcatch ", | |
16416 | 0/*allow-unknown*/, &cmdlist); | |
16417 | ||
44feb3ce TT |
16418 | add_catch_command ("fork", _("Catch calls to fork."), |
16419 | catch_fork_command_1, | |
a96d9b2e | 16420 | NULL, |
44feb3ce TT |
16421 | (void *) (uintptr_t) catch_fork_permanent, |
16422 | (void *) (uintptr_t) catch_fork_temporary); | |
16423 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16424 | catch_fork_command_1, | |
a96d9b2e | 16425 | NULL, |
44feb3ce TT |
16426 | (void *) (uintptr_t) catch_vfork_permanent, |
16427 | (void *) (uintptr_t) catch_vfork_temporary); | |
16428 | add_catch_command ("exec", _("Catch calls to exec."), | |
16429 | catch_exec_command_1, | |
a96d9b2e SDJ |
16430 | NULL, |
16431 | CATCH_PERMANENT, | |
16432 | CATCH_TEMPORARY); | |
edcc5120 TT |
16433 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16434 | Usage: catch load [REGEX]\n\ | |
16435 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16436 | catch_load_command_1, | |
16437 | NULL, | |
16438 | CATCH_PERMANENT, | |
16439 | CATCH_TEMPORARY); | |
16440 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16441 | Usage: catch unload [REGEX]\n\ | |
16442 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16443 | catch_unload_command_1, | |
16444 | NULL, | |
16445 | CATCH_PERMANENT, | |
16446 | CATCH_TEMPORARY); | |
c5aa993b | 16447 | |
1bedd215 AC |
16448 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16449 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16450 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16451 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16452 | an expression changes.\n\ |
16453 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16454 | the memory to which it refers.")); | |
65d12d83 | 16455 | set_cmd_completer (c, expression_completer); |
c906108c | 16456 | |
1bedd215 AC |
16457 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16458 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16459 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16460 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16461 | an expression is read.\n\ |
16462 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16463 | the memory to which it refers.")); | |
65d12d83 | 16464 | set_cmd_completer (c, expression_completer); |
c906108c | 16465 | |
1bedd215 AC |
16466 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16467 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16468 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16469 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16470 | an expression is either read or written.\n\ |
16471 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16472 | the memory to which it refers.")); | |
65d12d83 | 16473 | set_cmd_completer (c, expression_completer); |
c906108c | 16474 | |
d77f58be | 16475 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16476 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16477 | |
920d2a44 AC |
16478 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16479 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16480 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16481 | &can_use_hw_watchpoints, _("\ | |
16482 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16483 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16484 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16485 | such is available. (However, any hardware watchpoints that were\n\ | |
16486 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16487 | hardware.)"), |
16488 | NULL, | |
920d2a44 | 16489 | show_can_use_hw_watchpoints, |
85c07804 | 16490 | &setlist, &showlist); |
c906108c SS |
16491 | |
16492 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16493 | |
1042e4c0 SS |
16494 | /* Tracepoint manipulation commands. */ |
16495 | ||
16496 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16497 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16498 | \n" |
16499 | BREAK_ARGS_HELP ("trace") "\n\ | |
16500 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16501 | set_cmd_completer (c, location_completer); | |
16502 | ||
16503 | add_com_alias ("tp", "trace", class_alias, 0); | |
16504 | add_com_alias ("tr", "trace", class_alias, 1); | |
16505 | add_com_alias ("tra", "trace", class_alias, 1); | |
16506 | add_com_alias ("trac", "trace", class_alias, 1); | |
16507 | ||
7a697b8d | 16508 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16509 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16510 | \n" |
16511 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16512 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16513 | set_cmd_completer (c, location_completer); | |
16514 | ||
0fb4aa4b | 16515 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16516 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16517 | \n\ |
16518 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16519 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16520 | or -m MARKER_ID.\n\n\ | |
16521 | If a marker id is specified, probe the marker with that name. With\n\ | |
16522 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16523 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16524 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16525 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16526 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16527 | \n\ | |
16528 | CONDITION is a boolean expression.\n\ | |
629500fa | 16529 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16530 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16531 | conditions are different.\n\ | |
0fb4aa4b PA |
16532 | \n\ |
16533 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16534 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16535 | set_cmd_completer (c, location_completer); | |
16536 | ||
1042e4c0 | 16537 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16538 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16539 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16540 | last tracepoint set.")); | |
16541 | ||
16542 | add_info_alias ("tp", "tracepoints", 1); | |
16543 | ||
16544 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16545 | Delete specified tracepoints.\n\ | |
16546 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16547 | No argument means delete all tracepoints."), | |
16548 | &deletelist); | |
7e20dfcd | 16549 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16550 | |
16551 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16552 | Disable specified tracepoints.\n\ | |
16553 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16554 | No argument means disable all tracepoints."), | |
16555 | &disablelist); | |
16556 | deprecate_cmd (c, "disable"); | |
16557 | ||
16558 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16559 | Enable specified tracepoints.\n\ | |
16560 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16561 | No argument means enable all tracepoints."), | |
16562 | &enablelist); | |
16563 | deprecate_cmd (c, "enable"); | |
16564 | ||
16565 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16566 | Set the passcount for a tracepoint.\n\ | |
16567 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16568 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16569 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16570 | ||
6149aea9 PA |
16571 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16572 | _("Save breakpoint definitions as a script."), | |
16573 | &save_cmdlist, "save ", | |
16574 | 0/*allow-unknown*/, &cmdlist); | |
16575 | ||
16576 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16577 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16578 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16579 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16580 | session to restore them."), | |
16581 | &save_cmdlist); | |
16582 | set_cmd_completer (c, filename_completer); | |
16583 | ||
16584 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16585 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16586 | Use the 'source' command in another debug session to restore them."), |
16587 | &save_cmdlist); | |
1042e4c0 SS |
16588 | set_cmd_completer (c, filename_completer); |
16589 | ||
6149aea9 PA |
16590 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16591 | deprecate_cmd (c, "save tracepoints"); | |
16592 | ||
1bedd215 | 16593 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16594 | Breakpoint specific settings\n\ |
16595 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16596 | pending breakpoint behavior"), |
fa8d40ab JJ |
16597 | &breakpoint_set_cmdlist, "set breakpoint ", |
16598 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16599 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16600 | Breakpoint specific settings\n\ |
16601 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16602 | pending breakpoint behavior"), |
fa8d40ab JJ |
16603 | &breakpoint_show_cmdlist, "show breakpoint ", |
16604 | 0/*allow-unknown*/, &showlist); | |
16605 | ||
7915a72c AC |
16606 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16607 | &pending_break_support, _("\ | |
16608 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16609 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16610 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16611 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16612 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16613 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16614 | NULL, |
920d2a44 | 16615 | show_pending_break_support, |
6e1d7d6c AC |
16616 | &breakpoint_set_cmdlist, |
16617 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16618 | |
16619 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16620 | |
16621 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16622 | &automatic_hardware_breakpoints, _("\ | |
16623 | Set automatic usage of hardware breakpoints."), _("\ | |
16624 | Show automatic usage of hardware breakpoints."), _("\ | |
16625 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16626 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16627 | a warning will be emitted for such breakpoints."), | |
16628 | NULL, | |
16629 | show_automatic_hardware_breakpoints, | |
16630 | &breakpoint_set_cmdlist, | |
16631 | &breakpoint_show_cmdlist); | |
74960c60 | 16632 | |
a25a5a45 PA |
16633 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16634 | &always_inserted_mode, _("\ | |
74960c60 VP |
16635 | Set mode for inserting breakpoints."), _("\ |
16636 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16637 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16638 | they're created, kept inserted even when execution stops, and removed\n\ | |
16639 | only when the user deletes them. When this mode is off (the default),\n\ | |
16640 | breakpoints are inserted only when execution continues, and removed\n\ | |
16641 | when execution stops."), | |
72d0e2c5 YQ |
16642 | NULL, |
16643 | &show_always_inserted_mode, | |
16644 | &breakpoint_set_cmdlist, | |
16645 | &breakpoint_show_cmdlist); | |
f1310107 | 16646 | |
b775012e LM |
16647 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16648 | condition_evaluation_enums, | |
16649 | &condition_evaluation_mode_1, _("\ | |
16650 | Set mode of breakpoint condition evaluation."), _("\ | |
16651 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16652 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16653 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16654 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16655 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16656 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16657 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16658 | be set to \"gdb\""), | |
16659 | &set_condition_evaluation_mode, | |
16660 | &show_condition_evaluation_mode, | |
16661 | &breakpoint_set_cmdlist, | |
16662 | &breakpoint_show_cmdlist); | |
16663 | ||
f1310107 TJB |
16664 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16665 | Set a breakpoint for an address range.\n\ | |
16666 | break-range START-LOCATION, END-LOCATION\n\ | |
16667 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16668 | LINENUM, for that line in the current file,\n\ | |
16669 | FILE:LINENUM, for that line in that file,\n\ | |
16670 | +OFFSET, for that number of lines after the current line\n\ | |
16671 | or the start of the range\n\ | |
16672 | FUNCTION, for the first line in that function,\n\ | |
16673 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16674 | *ADDRESS, for the instruction at that address.\n\ | |
16675 | \n\ | |
16676 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16677 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16678 | range (including START-LOCATION and END-LOCATION).")); | |
16679 | ||
e7e0cddf | 16680 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16681 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16682 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16683 | location may be a linespec, explicit, or address location.\n" |
16684 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16685 | set_cmd_completer (c, location_completer); |
16686 | ||
16687 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16688 | dprintf_style_enums, &dprintf_style, _("\ | |
16689 | Set the style of usage for dynamic printf."), _("\ | |
16690 | Show the style of usage for dynamic printf."), _("\ | |
16691 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16692 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16693 | console, as with the \"printf\" command.\n\ | |
16694 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16695 | program; by default printf(), but you can choose a different function or\n\ | |
16696 | output stream by setting dprintf-function and dprintf-channel."), | |
16697 | update_dprintf_commands, NULL, | |
16698 | &setlist, &showlist); | |
16699 | ||
16700 | dprintf_function = xstrdup ("printf"); | |
16701 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16702 | &dprintf_function, _("\ | |
16703 | Set the function to use for dynamic printf"), _("\ | |
16704 | Show the function to use for dynamic printf"), NULL, | |
16705 | update_dprintf_commands, NULL, | |
16706 | &setlist, &showlist); | |
16707 | ||
16708 | dprintf_channel = xstrdup (""); | |
16709 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16710 | &dprintf_channel, _("\ | |
16711 | Set the channel to use for dynamic printf"), _("\ | |
16712 | Show the channel to use for dynamic printf"), NULL, | |
16713 | update_dprintf_commands, NULL, | |
16714 | &setlist, &showlist); | |
16715 | ||
d3ce09f5 SS |
16716 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16717 | &disconnected_dprintf, _("\ | |
16718 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16719 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16720 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16721 | even if GDB disconnects or detaches from the target."), | |
16722 | NULL, | |
16723 | NULL, | |
16724 | &setlist, &showlist); | |
16725 | ||
16726 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16727 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16728 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16729 | ||
765dc015 | 16730 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16731 | |
16732 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16733 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16734 | } |