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 | ||
833b7ab5 YQ |
2606 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2607 | of breakpoint according to ADDR except single-step breakpoint. | |
2608 | Get the kind of single-step breakpoint according to the current | |
2609 | registers state. */ | |
cd6c3b4f YQ |
2610 | |
2611 | static int | |
2612 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2613 | { | |
833b7ab5 YQ |
2614 | if (bl->owner->type == bp_single_step) |
2615 | { | |
2616 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2617 | struct regcache *regcache; | |
2618 | ||
2619 | regcache = get_thread_regcache (thr->ptid); | |
2620 | ||
2621 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2622 | regcache, addr); | |
2623 | } | |
2624 | else | |
2625 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2626 | } |
2627 | ||
35df4500 TJB |
2628 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2629 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2630 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2631 | Returns 0 for success, 1 if the bp_location type is not supported or |
2632 | -1 for failure. | |
879bfdc2 | 2633 | |
4a64f543 MS |
2634 | NOTE drow/2003-09-09: This routine could be broken down to an |
2635 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2636 | static int |
35df4500 | 2637 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2638 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2639 | int *disabled_breaks, |
dd61ec5c MW |
2640 | int *hw_breakpoint_error, |
2641 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2642 | { |
0000e5cc PA |
2643 | enum errors bp_err = GDB_NO_ERROR; |
2644 | const char *bp_err_message = NULL; | |
879bfdc2 | 2645 | |
b775012e | 2646 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2647 | return 0; |
2648 | ||
35c63cd8 JB |
2649 | /* Note we don't initialize bl->target_info, as that wipes out |
2650 | the breakpoint location's shadow_contents if the breakpoint | |
2651 | is still inserted at that location. This in turn breaks | |
2652 | target_read_memory which depends on these buffers when | |
2653 | a memory read is requested at the breakpoint location: | |
2654 | Once the target_info has been wiped, we fail to see that | |
2655 | we have a breakpoint inserted at that address and thus | |
2656 | read the breakpoint instead of returning the data saved in | |
2657 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2658 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2659 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2660 | bl->target_info.length = bl->length; |
8181d85f | 2661 | |
b775012e LM |
2662 | /* When working with target-side conditions, we must pass all the conditions |
2663 | for the same breakpoint address down to the target since GDB will not | |
2664 | insert those locations. With a list of breakpoint conditions, the target | |
2665 | can decide when to stop and notify GDB. */ | |
2666 | ||
2667 | if (is_breakpoint (bl->owner)) | |
2668 | { | |
2669 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2670 | build_target_command_list (bl); |
2671 | /* Reset the modification marker. */ | |
b775012e LM |
2672 | bl->needs_update = 0; |
2673 | } | |
2674 | ||
35df4500 TJB |
2675 | if (bl->loc_type == bp_loc_software_breakpoint |
2676 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2677 | { |
35df4500 | 2678 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2679 | { |
2680 | /* If the explicitly specified breakpoint type | |
2681 | is not hardware breakpoint, check the memory map to see | |
2682 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2683 | |
765dc015 VP |
2684 | Two important cases are: |
2685 | - location type is not hardware breakpoint, memory | |
2686 | is readonly. We change the type of the location to | |
2687 | hardware breakpoint. | |
4a64f543 MS |
2688 | - location type is hardware breakpoint, memory is |
2689 | read-write. This means we've previously made the | |
2690 | location hardware one, but then the memory map changed, | |
2691 | so we undo. | |
765dc015 | 2692 | |
4a64f543 MS |
2693 | When breakpoints are removed, remove_breakpoints will use |
2694 | location types we've just set here, the only possible | |
2695 | problem is that memory map has changed during running | |
2696 | program, but it's not going to work anyway with current | |
2697 | gdb. */ | |
765dc015 | 2698 | struct mem_region *mr |
0d5ed153 | 2699 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2700 | |
2701 | if (mr) | |
2702 | { | |
2703 | if (automatic_hardware_breakpoints) | |
2704 | { | |
765dc015 VP |
2705 | enum bp_loc_type new_type; |
2706 | ||
2707 | if (mr->attrib.mode != MEM_RW) | |
2708 | new_type = bp_loc_hardware_breakpoint; | |
2709 | else | |
2710 | new_type = bp_loc_software_breakpoint; | |
2711 | ||
35df4500 | 2712 | if (new_type != bl->loc_type) |
765dc015 VP |
2713 | { |
2714 | static int said = 0; | |
cc59ec59 | 2715 | |
35df4500 | 2716 | bl->loc_type = new_type; |
765dc015 VP |
2717 | if (!said) |
2718 | { | |
3e43a32a MS |
2719 | fprintf_filtered (gdb_stdout, |
2720 | _("Note: automatically using " | |
2721 | "hardware breakpoints for " | |
2722 | "read-only addresses.\n")); | |
765dc015 VP |
2723 | said = 1; |
2724 | } | |
2725 | } | |
2726 | } | |
35df4500 | 2727 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2728 | && mr->attrib.mode != MEM_RW) |
2729 | { | |
2730 | fprintf_unfiltered (tmp_error_stream, | |
2731 | _("Cannot insert breakpoint %d.\n" | |
2732 | "Cannot set software breakpoint " | |
2733 | "at read-only address %s\n"), | |
2734 | bl->owner->number, | |
2735 | paddress (bl->gdbarch, bl->address)); | |
2736 | return 1; | |
2737 | } | |
765dc015 VP |
2738 | } |
2739 | } | |
2740 | ||
879bfdc2 DJ |
2741 | /* First check to see if we have to handle an overlay. */ |
2742 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2743 | || bl->section == NULL |
2744 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2745 | { |
2746 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2747 | TRY |
dd61ec5c | 2748 | { |
0000e5cc PA |
2749 | int val; |
2750 | ||
dd61ec5c | 2751 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2752 | if (val) |
2753 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2754 | } |
492d29ea | 2755 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2756 | { |
0000e5cc PA |
2757 | bp_err = e.error; |
2758 | bp_err_message = e.message; | |
dd61ec5c | 2759 | } |
492d29ea | 2760 | END_CATCH |
879bfdc2 DJ |
2761 | } |
2762 | else | |
2763 | { | |
4a64f543 | 2764 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2765 | Shall we set a breakpoint at the LMA? */ |
2766 | if (!overlay_events_enabled) | |
2767 | { | |
2768 | /* Yes -- overlay event support is not active, | |
2769 | so we must try to set a breakpoint at the LMA. | |
2770 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2771 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2772 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2773 | bl->owner->number); |
879bfdc2 DJ |
2774 | else |
2775 | { | |
35df4500 TJB |
2776 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2777 | bl->section); | |
879bfdc2 | 2778 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2779 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2780 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2781 | |
2782 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2783 | TRY |
0000e5cc PA |
2784 | { |
2785 | int val; | |
2786 | ||
579c6ad9 | 2787 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2788 | = breakpoint_kind (bl, &addr); |
2789 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2790 | val = target_insert_breakpoint (bl->gdbarch, |
2791 | &bl->overlay_target_info); | |
2792 | if (val) | |
2793 | bp_err = GENERIC_ERROR; | |
2794 | } | |
492d29ea | 2795 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2796 | { |
2797 | bp_err = e.error; | |
2798 | bp_err_message = e.message; | |
2799 | } | |
492d29ea | 2800 | END_CATCH |
0000e5cc PA |
2801 | |
2802 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2803 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2804 | "Overlay breakpoint %d " |
2805 | "failed: in ROM?\n", | |
35df4500 | 2806 | bl->owner->number); |
879bfdc2 DJ |
2807 | } |
2808 | } | |
2809 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2810 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2811 | { |
2812 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2813 | TRY |
dd61ec5c | 2814 | { |
0000e5cc PA |
2815 | int val; |
2816 | ||
dd61ec5c | 2817 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2818 | if (val) |
2819 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2820 | } |
492d29ea | 2821 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2822 | { |
0000e5cc PA |
2823 | bp_err = e.error; |
2824 | bp_err_message = e.message; | |
dd61ec5c | 2825 | } |
492d29ea | 2826 | END_CATCH |
879bfdc2 DJ |
2827 | } |
2828 | else | |
2829 | { | |
2830 | /* No. This breakpoint will not be inserted. | |
2831 | No error, but do not mark the bp as 'inserted'. */ | |
2832 | return 0; | |
2833 | } | |
2834 | } | |
2835 | ||
0000e5cc | 2836 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2837 | { |
2838 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2839 | |
2840 | /* In some cases, we might not be able to insert a | |
2841 | breakpoint in a shared library that has already been | |
2842 | removed, but we have not yet processed the shlib unload | |
2843 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2844 | breakpoint insertion themselves can't tell why the |
2845 | breakpoint insertion failed (e.g., the remote target | |
2846 | doesn't define error codes), so we must treat generic | |
2847 | errors as memory errors. */ | |
0000e5cc | 2848 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2849 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2850 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2851 | || shared_objfile_contains_address_p (bl->pspace, |
2852 | bl->address))) | |
879bfdc2 | 2853 | { |
4a64f543 | 2854 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2855 | bl->shlib_disabled = 1; |
8d3788bd | 2856 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2857 | if (!*disabled_breaks) |
2858 | { | |
2859 | fprintf_unfiltered (tmp_error_stream, | |
2860 | "Cannot insert breakpoint %d.\n", | |
2861 | bl->owner->number); | |
2862 | fprintf_unfiltered (tmp_error_stream, | |
2863 | "Temporarily disabling shared " | |
2864 | "library breakpoints:\n"); | |
2865 | } | |
2866 | *disabled_breaks = 1; | |
879bfdc2 | 2867 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2868 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2869 | return 0; |
879bfdc2 DJ |
2870 | } |
2871 | else | |
879bfdc2 | 2872 | { |
35df4500 | 2873 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2874 | { |
0000e5cc PA |
2875 | *hw_breakpoint_error = 1; |
2876 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2877 | fprintf_unfiltered (tmp_error_stream, |
2878 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2879 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2880 | if (bp_err_message != NULL) | |
2881 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2882 | } |
2883 | else | |
2884 | { | |
0000e5cc PA |
2885 | if (bp_err_message == NULL) |
2886 | { | |
2887 | char *message | |
2888 | = memory_error_message (TARGET_XFER_E_IO, | |
2889 | bl->gdbarch, bl->address); | |
2890 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2891 | ||
2892 | fprintf_unfiltered (tmp_error_stream, | |
2893 | "Cannot insert breakpoint %d.\n" | |
2894 | "%s\n", | |
2895 | bl->owner->number, message); | |
2896 | do_cleanups (old_chain); | |
2897 | } | |
2898 | else | |
2899 | { | |
2900 | fprintf_unfiltered (tmp_error_stream, | |
2901 | "Cannot insert breakpoint %d: %s\n", | |
2902 | bl->owner->number, | |
2903 | bp_err_message); | |
2904 | } | |
879bfdc2 | 2905 | } |
0000e5cc | 2906 | return 1; |
879bfdc2 DJ |
2907 | |
2908 | } | |
2909 | } | |
2910 | else | |
35df4500 | 2911 | bl->inserted = 1; |
879bfdc2 | 2912 | |
0000e5cc | 2913 | return 0; |
879bfdc2 DJ |
2914 | } |
2915 | ||
35df4500 | 2916 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2917 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2918 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2919 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2920 | { |
0000e5cc PA |
2921 | int val; |
2922 | ||
77b06cd7 TJB |
2923 | gdb_assert (bl->owner->ops != NULL |
2924 | && bl->owner->ops->insert_location != NULL); | |
2925 | ||
2926 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2927 | |
2928 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2929 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2930 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2931 | { |
2932 | struct bp_location *loc, **loc_temp; | |
2933 | ||
2934 | /* But don't try to insert it, if there's already another | |
2935 | hw_access location that would be considered a duplicate | |
2936 | of this one. */ | |
2937 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2938 | if (loc != bl |
85d721b8 | 2939 | && loc->watchpoint_type == hw_access |
35df4500 | 2940 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2941 | { |
35df4500 TJB |
2942 | bl->duplicate = 1; |
2943 | bl->inserted = 1; | |
2944 | bl->target_info = loc->target_info; | |
2945 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2946 | val = 0; |
2947 | break; | |
2948 | } | |
2949 | ||
2950 | if (val == 1) | |
2951 | { | |
77b06cd7 TJB |
2952 | bl->watchpoint_type = hw_access; |
2953 | val = bl->owner->ops->insert_location (bl); | |
2954 | ||
2955 | if (val) | |
2956 | /* Back to the original value. */ | |
2957 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2958 | } |
2959 | } | |
2960 | ||
35df4500 | 2961 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2962 | } |
2963 | ||
35df4500 | 2964 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2965 | { |
0000e5cc PA |
2966 | int val; |
2967 | ||
77b06cd7 TJB |
2968 | gdb_assert (bl->owner->ops != NULL |
2969 | && bl->owner->ops->insert_location != NULL); | |
2970 | ||
2971 | val = bl->owner->ops->insert_location (bl); | |
2972 | if (val) | |
2973 | { | |
2974 | bl->owner->enable_state = bp_disabled; | |
2975 | ||
2976 | if (val == 1) | |
2977 | warning (_("\ | |
2978 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2979 | of catchpoint."), bl->owner->number); | |
2980 | else | |
2981 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2982 | } | |
2983 | ||
2984 | bl->inserted = (val == 0); | |
1640b821 DJ |
2985 | |
2986 | /* We've already printed an error message if there was a problem | |
2987 | inserting this catchpoint, and we've disabled the catchpoint, | |
2988 | so just return success. */ | |
2989 | return 0; | |
879bfdc2 DJ |
2990 | } |
2991 | ||
2992 | return 0; | |
2993 | } | |
2994 | ||
6c95b8df PA |
2995 | /* This function is called when program space PSPACE is about to be |
2996 | deleted. It takes care of updating breakpoints to not reference | |
2997 | PSPACE anymore. */ | |
2998 | ||
2999 | void | |
3000 | breakpoint_program_space_exit (struct program_space *pspace) | |
3001 | { | |
3002 | struct breakpoint *b, *b_temp; | |
876fa593 | 3003 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
3004 | |
3005 | /* Remove any breakpoint that was set through this program space. */ | |
3006 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
3007 | { | |
3008 | if (b->pspace == pspace) | |
3009 | delete_breakpoint (b); | |
3010 | } | |
3011 | ||
3012 | /* Breakpoints set through other program spaces could have locations | |
3013 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 3014 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
3015 | { |
3016 | struct bp_location *tmp; | |
3017 | ||
3018 | if (loc->pspace == pspace) | |
3019 | { | |
2bdf28a0 | 3020 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
3021 | if (loc->owner->loc == loc) |
3022 | loc->owner->loc = loc->next; | |
3023 | else | |
3024 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3025 | if (tmp->next == loc) | |
3026 | { | |
3027 | tmp->next = loc->next; | |
3028 | break; | |
3029 | } | |
3030 | } | |
3031 | } | |
3032 | ||
3033 | /* Now update the global location list to permanently delete the | |
3034 | removed locations above. */ | |
44702360 | 3035 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3036 | } |
3037 | ||
74960c60 VP |
3038 | /* Make sure all breakpoints are inserted in inferior. |
3039 | Throws exception on any error. | |
3040 | A breakpoint that is already inserted won't be inserted | |
3041 | again, so calling this function twice is safe. */ | |
3042 | void | |
3043 | insert_breakpoints (void) | |
3044 | { | |
3045 | struct breakpoint *bpt; | |
3046 | ||
3047 | ALL_BREAKPOINTS (bpt) | |
3048 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3049 | { |
3050 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3051 | ||
3052 | update_watchpoint (w, 0 /* don't reparse. */); | |
3053 | } | |
74960c60 | 3054 | |
04086b45 PA |
3055 | /* Updating watchpoints creates new locations, so update the global |
3056 | location list. Explicitly tell ugll to insert locations and | |
3057 | ignore breakpoints_always_inserted_mode. */ | |
3058 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3059 | } |
3060 | ||
20388dd6 YQ |
3061 | /* Invoke CALLBACK for each of bp_location. */ |
3062 | ||
3063 | void | |
3064 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3065 | { | |
3066 | struct bp_location *loc, **loc_tmp; | |
3067 | ||
3068 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3069 | { | |
3070 | callback (loc, NULL); | |
3071 | } | |
3072 | } | |
3073 | ||
b775012e LM |
3074 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3075 | target. It is the case with deleting and disabling of breakpoints when using | |
3076 | always-inserted mode. */ | |
3077 | ||
3078 | static void | |
3079 | update_inserted_breakpoint_locations (void) | |
3080 | { | |
3081 | struct bp_location *bl, **blp_tmp; | |
3082 | int error_flag = 0; | |
3083 | int val = 0; | |
3084 | int disabled_breaks = 0; | |
3085 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3086 | int hw_bp_details_reported = 0; |
b775012e LM |
3087 | |
3088 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3089 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3090 | ||
3091 | /* Explicitly mark the warning -- this will only be printed if | |
3092 | there was an error. */ | |
3093 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3094 | ||
3095 | save_current_space_and_thread (); | |
3096 | ||
3097 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3098 | { | |
3099 | /* We only want to update software breakpoints and hardware | |
3100 | breakpoints. */ | |
3101 | if (!is_breakpoint (bl->owner)) | |
3102 | continue; | |
3103 | ||
3104 | /* We only want to update locations that are already inserted | |
3105 | and need updating. This is to avoid unwanted insertion during | |
3106 | deletion of breakpoints. */ | |
3107 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3108 | continue; | |
3109 | ||
3110 | switch_to_program_space_and_thread (bl->pspace); | |
3111 | ||
3112 | /* For targets that support global breakpoints, there's no need | |
3113 | to select an inferior to insert breakpoint to. In fact, even | |
3114 | if we aren't attached to any process yet, we should still | |
3115 | insert breakpoints. */ | |
f5656ead | 3116 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3117 | && ptid_equal (inferior_ptid, null_ptid)) |
3118 | continue; | |
3119 | ||
3120 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3121 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3122 | if (val) |
3123 | error_flag = val; | |
3124 | } | |
3125 | ||
3126 | if (error_flag) | |
3127 | { | |
3128 | target_terminal_ours_for_output (); | |
3129 | error_stream (tmp_error_stream); | |
3130 | } | |
3131 | ||
3132 | do_cleanups (cleanups); | |
3133 | } | |
3134 | ||
c30eee59 | 3135 | /* Used when starting or continuing the program. */ |
c906108c | 3136 | |
74960c60 VP |
3137 | static void |
3138 | insert_breakpoint_locations (void) | |
c906108c | 3139 | { |
a5606eee | 3140 | struct breakpoint *bpt; |
35df4500 | 3141 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3142 | int error_flag = 0; |
c906108c | 3143 | int val = 0; |
3fbb6ffa | 3144 | int disabled_breaks = 0; |
81d0cc19 | 3145 | int hw_breakpoint_error = 0; |
dd61ec5c | 3146 | int hw_bp_error_explained_already = 0; |
c906108c | 3147 | |
81d0cc19 | 3148 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3149 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3150 | |
81d0cc19 GS |
3151 | /* Explicitly mark the warning -- this will only be printed if |
3152 | there was an error. */ | |
3153 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3154 | |
3155 | save_current_space_and_thread (); | |
3156 | ||
35df4500 | 3157 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3158 | { |
b775012e | 3159 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3160 | continue; |
3161 | ||
4a64f543 MS |
3162 | /* There is no point inserting thread-specific breakpoints if |
3163 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3164 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3165 | if (bl->owner->thread != -1 |
5d5658a1 | 3166 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3167 | continue; |
3168 | ||
35df4500 | 3169 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3170 | |
3171 | /* For targets that support global breakpoints, there's no need | |
3172 | to select an inferior to insert breakpoint to. In fact, even | |
3173 | if we aren't attached to any process yet, we should still | |
3174 | insert breakpoints. */ | |
f5656ead | 3175 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3176 | && ptid_equal (inferior_ptid, null_ptid)) |
3177 | continue; | |
3178 | ||
3fbb6ffa | 3179 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3180 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3181 | if (val) |
eacd795a | 3182 | error_flag = val; |
879bfdc2 | 3183 | } |
c906108c | 3184 | |
4a64f543 MS |
3185 | /* If we failed to insert all locations of a watchpoint, remove |
3186 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3187 | ALL_BREAKPOINTS (bpt) |
3188 | { | |
3189 | int some_failed = 0; | |
3190 | struct bp_location *loc; | |
3191 | ||
3192 | if (!is_hardware_watchpoint (bpt)) | |
3193 | continue; | |
3194 | ||
d6b74ac4 | 3195 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3196 | continue; |
74960c60 VP |
3197 | |
3198 | if (bpt->disposition == disp_del_at_next_stop) | |
3199 | continue; | |
a5606eee VP |
3200 | |
3201 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3202 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3203 | { |
3204 | some_failed = 1; | |
3205 | break; | |
3206 | } | |
3207 | if (some_failed) | |
3208 | { | |
3209 | for (loc = bpt->loc; loc; loc = loc->next) | |
3210 | if (loc->inserted) | |
834c0d03 | 3211 | remove_breakpoint (loc); |
a5606eee VP |
3212 | |
3213 | hw_breakpoint_error = 1; | |
3214 | fprintf_unfiltered (tmp_error_stream, | |
3215 | "Could not insert hardware watchpoint %d.\n", | |
3216 | bpt->number); | |
eacd795a | 3217 | error_flag = -1; |
a5606eee VP |
3218 | } |
3219 | } | |
3220 | ||
eacd795a | 3221 | if (error_flag) |
81d0cc19 GS |
3222 | { |
3223 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3224 | message about possibly exhausted resources. */ | |
dd61ec5c | 3225 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3226 | { |
c6510018 MS |
3227 | fprintf_unfiltered (tmp_error_stream, |
3228 | "Could not insert hardware breakpoints:\n\ | |
3229 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3230 | } |
81d0cc19 GS |
3231 | target_terminal_ours_for_output (); |
3232 | error_stream (tmp_error_stream); | |
3233 | } | |
f7545552 TT |
3234 | |
3235 | do_cleanups (cleanups); | |
c906108c SS |
3236 | } |
3237 | ||
c30eee59 TJB |
3238 | /* Used when the program stops. |
3239 | Returns zero if successful, or non-zero if there was a problem | |
3240 | removing a breakpoint location. */ | |
3241 | ||
c906108c | 3242 | int |
fba45db2 | 3243 | remove_breakpoints (void) |
c906108c | 3244 | { |
35df4500 | 3245 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3246 | int val = 0; |
c906108c | 3247 | |
35df4500 | 3248 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3249 | { |
1e4d1764 | 3250 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3251 | val |= remove_breakpoint (bl); |
c5aa993b | 3252 | } |
3a1bae8e | 3253 | return val; |
c906108c SS |
3254 | } |
3255 | ||
49fa26b0 PA |
3256 | /* When a thread exits, remove breakpoints that are related to |
3257 | that thread. */ | |
3258 | ||
3259 | static void | |
3260 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3261 | { | |
3262 | struct breakpoint *b, *b_tmp; | |
3263 | ||
3264 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3265 | { | |
5d5658a1 | 3266 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3267 | { |
3268 | b->disposition = disp_del_at_next_stop; | |
3269 | ||
3270 | printf_filtered (_("\ | |
43792cf0 PA |
3271 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3272 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3273 | |
3274 | /* Hide it from the user. */ | |
3275 | b->number = 0; | |
3276 | } | |
3277 | } | |
3278 | } | |
3279 | ||
6c95b8df PA |
3280 | /* Remove breakpoints of process PID. */ |
3281 | ||
3282 | int | |
3283 | remove_breakpoints_pid (int pid) | |
3284 | { | |
35df4500 | 3285 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3286 | int val; |
3287 | struct inferior *inf = find_inferior_pid (pid); | |
3288 | ||
35df4500 | 3289 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3290 | { |
35df4500 | 3291 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3292 | continue; |
3293 | ||
fc126975 | 3294 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3295 | { |
834c0d03 | 3296 | val = remove_breakpoint (bl); |
6c95b8df PA |
3297 | if (val != 0) |
3298 | return val; | |
3299 | } | |
3300 | } | |
3301 | return 0; | |
3302 | } | |
3303 | ||
c906108c | 3304 | int |
fba45db2 | 3305 | reattach_breakpoints (int pid) |
c906108c | 3306 | { |
6c95b8df | 3307 | struct cleanup *old_chain; |
35df4500 | 3308 | struct bp_location *bl, **blp_tmp; |
c906108c | 3309 | int val; |
86b887df | 3310 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3311 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3312 | struct inferior *inf; |
3313 | struct thread_info *tp; | |
3314 | ||
3315 | tp = any_live_thread_of_process (pid); | |
3316 | if (tp == NULL) | |
3317 | return 1; | |
3318 | ||
3319 | inf = find_inferior_pid (pid); | |
3320 | old_chain = save_inferior_ptid (); | |
3321 | ||
3322 | inferior_ptid = tp->ptid; | |
a4954f26 | 3323 | |
86b887df | 3324 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3325 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3326 | |
35df4500 | 3327 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3328 | { |
35df4500 | 3329 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3330 | continue; |
3331 | ||
35df4500 | 3332 | if (bl->inserted) |
c5aa993b | 3333 | { |
35df4500 | 3334 | bl->inserted = 0; |
dd61ec5c | 3335 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3336 | if (val != 0) |
3337 | { | |
ce696e05 | 3338 | do_cleanups (old_chain); |
c5aa993b JM |
3339 | return val; |
3340 | } | |
3341 | } | |
3342 | } | |
ce696e05 | 3343 | do_cleanups (old_chain); |
c906108c SS |
3344 | return 0; |
3345 | } | |
3346 | ||
e58b0e63 PA |
3347 | static int internal_breakpoint_number = -1; |
3348 | ||
84f4c1fe PM |
3349 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3350 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3351 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3352 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3353 | breakpoint_count and that value incremented. Internal breakpoints |
3354 | do not set the internal var bpnum. */ | |
3355 | static void | |
3356 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3357 | { | |
3358 | if (internal) | |
3359 | b->number = internal_breakpoint_number--; | |
3360 | else | |
3361 | { | |
3362 | set_breakpoint_count (breakpoint_count + 1); | |
3363 | b->number = breakpoint_count; | |
3364 | } | |
3365 | } | |
3366 | ||
e62c965a | 3367 | static struct breakpoint * |
a6d9a66e | 3368 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3369 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3370 | const struct breakpoint_ops *ops) |
e62c965a | 3371 | { |
e62c965a PP |
3372 | struct symtab_and_line sal; |
3373 | struct breakpoint *b; | |
3374 | ||
4a64f543 | 3375 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3376 | |
3377 | sal.pc = address; | |
3378 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3379 | sal.pspace = current_program_space; |
e62c965a | 3380 | |
06edf0c0 | 3381 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3382 | b->number = internal_breakpoint_number--; |
3383 | b->disposition = disp_donttouch; | |
3384 | ||
3385 | return b; | |
3386 | } | |
3387 | ||
17450429 PP |
3388 | static const char *const longjmp_names[] = |
3389 | { | |
3390 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3391 | }; | |
3392 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3393 | ||
3394 | /* Per-objfile data private to breakpoint.c. */ | |
3395 | struct breakpoint_objfile_data | |
3396 | { | |
3397 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3398 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3399 | |
3400 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3401 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3402 | |
28106bc2 SDJ |
3403 | /* True if we have looked for longjmp probes. */ |
3404 | int longjmp_searched; | |
3405 | ||
3406 | /* SystemTap probe points for longjmp (if any). */ | |
3407 | VEC (probe_p) *longjmp_probes; | |
3408 | ||
17450429 | 3409 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3410 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3411 | |
3412 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3413 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3414 | |
3415 | /* True if we have looked for exception probes. */ | |
3416 | int exception_searched; | |
3417 | ||
3418 | /* SystemTap probe points for unwinding (if any). */ | |
3419 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3420 | }; |
3421 | ||
3422 | static const struct objfile_data *breakpoint_objfile_key; | |
3423 | ||
3424 | /* Minimal symbol not found sentinel. */ | |
3425 | static struct minimal_symbol msym_not_found; | |
3426 | ||
3427 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3428 | ||
3429 | static int | |
3430 | msym_not_found_p (const struct minimal_symbol *msym) | |
3431 | { | |
3432 | return msym == &msym_not_found; | |
3433 | } | |
3434 | ||
3435 | /* Return per-objfile data needed by breakpoint.c. | |
3436 | Allocate the data if necessary. */ | |
3437 | ||
3438 | static struct breakpoint_objfile_data * | |
3439 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3440 | { | |
3441 | struct breakpoint_objfile_data *bp_objfile_data; | |
3442 | ||
9a3c8263 SM |
3443 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3444 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3445 | if (bp_objfile_data == NULL) |
3446 | { | |
8d749320 SM |
3447 | bp_objfile_data = |
3448 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3449 | |
3450 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3451 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3452 | } | |
3453 | return bp_objfile_data; | |
3454 | } | |
3455 | ||
28106bc2 SDJ |
3456 | static void |
3457 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3458 | { | |
9a3c8263 SM |
3459 | struct breakpoint_objfile_data *bp_objfile_data |
3460 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3461 | |
3462 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3463 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3464 | } | |
3465 | ||
e62c965a | 3466 | static void |
af02033e | 3467 | create_overlay_event_breakpoint (void) |
e62c965a | 3468 | { |
69de3c6a | 3469 | struct objfile *objfile; |
af02033e | 3470 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3471 | |
69de3c6a PP |
3472 | ALL_OBJFILES (objfile) |
3473 | { | |
3474 | struct breakpoint *b; | |
17450429 PP |
3475 | struct breakpoint_objfile_data *bp_objfile_data; |
3476 | CORE_ADDR addr; | |
67994074 | 3477 | struct explicit_location explicit_loc; |
69de3c6a | 3478 | |
17450429 PP |
3479 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3480 | ||
3b7344d5 | 3481 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3482 | continue; |
3483 | ||
3b7344d5 | 3484 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3485 | { |
3b7344d5 | 3486 | struct bound_minimal_symbol m; |
17450429 PP |
3487 | |
3488 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3489 | if (m.minsym == NULL) |
17450429 PP |
3490 | { |
3491 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3492 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3493 | continue; |
3494 | } | |
3495 | bp_objfile_data->overlay_msym = m; | |
3496 | } | |
e62c965a | 3497 | |
77e371c0 | 3498 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3499 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3500 | bp_overlay_event, |
3501 | &internal_breakpoint_ops); | |
67994074 KS |
3502 | initialize_explicit_location (&explicit_loc); |
3503 | explicit_loc.function_name = ASTRDUP (func_name); | |
3504 | b->location = new_explicit_location (&explicit_loc); | |
e62c965a | 3505 | |
69de3c6a PP |
3506 | if (overlay_debugging == ovly_auto) |
3507 | { | |
3508 | b->enable_state = bp_enabled; | |
3509 | overlay_events_enabled = 1; | |
3510 | } | |
3511 | else | |
3512 | { | |
3513 | b->enable_state = bp_disabled; | |
3514 | overlay_events_enabled = 0; | |
3515 | } | |
e62c965a | 3516 | } |
e62c965a PP |
3517 | } |
3518 | ||
0fd8e87f | 3519 | static void |
af02033e | 3520 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3521 | { |
6c95b8df | 3522 | struct program_space *pspace; |
6c95b8df PA |
3523 | struct cleanup *old_chain; |
3524 | ||
3525 | old_chain = save_current_program_space (); | |
0fd8e87f | 3526 | |
6c95b8df | 3527 | ALL_PSPACES (pspace) |
af02033e PP |
3528 | { |
3529 | struct objfile *objfile; | |
3530 | ||
3531 | set_current_program_space (pspace); | |
3532 | ||
3533 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3534 | { |
af02033e PP |
3535 | int i; |
3536 | struct gdbarch *gdbarch; | |
17450429 | 3537 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3538 | |
af02033e | 3539 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3540 | |
17450429 PP |
3541 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3542 | ||
28106bc2 SDJ |
3543 | if (!bp_objfile_data->longjmp_searched) |
3544 | { | |
25f9533e SDJ |
3545 | VEC (probe_p) *ret; |
3546 | ||
3547 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3548 | if (ret != NULL) | |
3549 | { | |
3550 | /* We are only interested in checking one element. */ | |
3551 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3552 | ||
3553 | if (!can_evaluate_probe_arguments (p)) | |
3554 | { | |
3555 | /* We cannot use the probe interface here, because it does | |
3556 | not know how to evaluate arguments. */ | |
3557 | VEC_free (probe_p, ret); | |
3558 | ret = NULL; | |
3559 | } | |
3560 | } | |
3561 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3562 | bp_objfile_data->longjmp_searched = 1; |
3563 | } | |
3564 | ||
3565 | if (bp_objfile_data->longjmp_probes != NULL) | |
3566 | { | |
3567 | int i; | |
3568 | struct probe *probe; | |
3569 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3570 | ||
3571 | for (i = 0; | |
3572 | VEC_iterate (probe_p, | |
3573 | bp_objfile_data->longjmp_probes, | |
3574 | i, probe); | |
3575 | ++i) | |
3576 | { | |
3577 | struct breakpoint *b; | |
3578 | ||
729662a5 TT |
3579 | b = create_internal_breakpoint (gdbarch, |
3580 | get_probe_address (probe, | |
3581 | objfile), | |
28106bc2 SDJ |
3582 | bp_longjmp_master, |
3583 | &internal_breakpoint_ops); | |
5b56227b KS |
3584 | b->location |
3585 | = new_probe_location ("-probe-stap libc:longjmp"); | |
28106bc2 SDJ |
3586 | b->enable_state = bp_disabled; |
3587 | } | |
3588 | ||
3589 | continue; | |
3590 | } | |
3591 | ||
0569175e TSD |
3592 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3593 | continue; | |
3594 | ||
17450429 | 3595 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3596 | { |
3597 | struct breakpoint *b; | |
af02033e | 3598 | const char *func_name; |
17450429 | 3599 | CORE_ADDR addr; |
67994074 | 3600 | struct explicit_location explicit_loc; |
6c95b8df | 3601 | |
3b7344d5 | 3602 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3603 | continue; |
0fd8e87f | 3604 | |
17450429 | 3605 | func_name = longjmp_names[i]; |
3b7344d5 | 3606 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3607 | { |
3b7344d5 | 3608 | struct bound_minimal_symbol m; |
17450429 PP |
3609 | |
3610 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3611 | if (m.minsym == NULL) |
17450429 PP |
3612 | { |
3613 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3614 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3615 | continue; |
3616 | } | |
3617 | bp_objfile_data->longjmp_msym[i] = m; | |
3618 | } | |
3619 | ||
77e371c0 | 3620 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3621 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3622 | &internal_breakpoint_ops); | |
67994074 KS |
3623 | initialize_explicit_location (&explicit_loc); |
3624 | explicit_loc.function_name = ASTRDUP (func_name); | |
3625 | b->location = new_explicit_location (&explicit_loc); | |
af02033e PP |
3626 | b->enable_state = bp_disabled; |
3627 | } | |
0fd8e87f | 3628 | } |
af02033e | 3629 | } |
6c95b8df PA |
3630 | |
3631 | do_cleanups (old_chain); | |
0fd8e87f UW |
3632 | } |
3633 | ||
af02033e | 3634 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3635 | static void |
af02033e | 3636 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3637 | { |
3638 | struct program_space *pspace; | |
aa7d318d | 3639 | struct cleanup *old_chain; |
af02033e | 3640 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3641 | |
3642 | old_chain = save_current_program_space (); | |
3643 | ||
3644 | ALL_PSPACES (pspace) | |
17450429 PP |
3645 | { |
3646 | struct objfile *objfile; | |
3647 | CORE_ADDR addr; | |
3648 | ||
3649 | set_current_program_space (pspace); | |
3650 | ||
aa7d318d TT |
3651 | ALL_OBJFILES (objfile) |
3652 | { | |
3653 | struct breakpoint *b; | |
17450429 | 3654 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3655 | struct explicit_location explicit_loc; |
aa7d318d | 3656 | |
17450429 | 3657 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3658 | |
3b7344d5 | 3659 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3660 | continue; |
3661 | ||
3b7344d5 | 3662 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3663 | { |
3b7344d5 | 3664 | struct bound_minimal_symbol m; |
17450429 PP |
3665 | |
3666 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3667 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3668 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3669 | { |
3670 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3671 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3672 | continue; |
3673 | } | |
3674 | bp_objfile_data->terminate_msym = m; | |
3675 | } | |
aa7d318d | 3676 | |
77e371c0 | 3677 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3678 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3679 | bp_std_terminate_master, |
3680 | &internal_breakpoint_ops); | |
67994074 KS |
3681 | initialize_explicit_location (&explicit_loc); |
3682 | explicit_loc.function_name = ASTRDUP (func_name); | |
3683 | b->location = new_explicit_location (&explicit_loc); | |
aa7d318d TT |
3684 | b->enable_state = bp_disabled; |
3685 | } | |
17450429 PP |
3686 | } |
3687 | ||
aa7d318d TT |
3688 | do_cleanups (old_chain); |
3689 | } | |
3690 | ||
186c406b TT |
3691 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3692 | ||
70221824 | 3693 | static void |
186c406b TT |
3694 | create_exception_master_breakpoint (void) |
3695 | { | |
3696 | struct objfile *objfile; | |
17450429 | 3697 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3698 | |
3699 | ALL_OBJFILES (objfile) | |
3700 | { | |
17450429 PP |
3701 | struct breakpoint *b; |
3702 | struct gdbarch *gdbarch; | |
3703 | struct breakpoint_objfile_data *bp_objfile_data; | |
3704 | CORE_ADDR addr; | |
67994074 | 3705 | struct explicit_location explicit_loc; |
17450429 PP |
3706 | |
3707 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3708 | ||
28106bc2 SDJ |
3709 | /* We prefer the SystemTap probe point if it exists. */ |
3710 | if (!bp_objfile_data->exception_searched) | |
3711 | { | |
25f9533e SDJ |
3712 | VEC (probe_p) *ret; |
3713 | ||
3714 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3715 | ||
3716 | if (ret != NULL) | |
3717 | { | |
3718 | /* We are only interested in checking one element. */ | |
3719 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3720 | ||
3721 | if (!can_evaluate_probe_arguments (p)) | |
3722 | { | |
3723 | /* We cannot use the probe interface here, because it does | |
3724 | not know how to evaluate arguments. */ | |
3725 | VEC_free (probe_p, ret); | |
3726 | ret = NULL; | |
3727 | } | |
3728 | } | |
3729 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3730 | bp_objfile_data->exception_searched = 1; |
3731 | } | |
3732 | ||
3733 | if (bp_objfile_data->exception_probes != NULL) | |
3734 | { | |
3735 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3736 | int i; | |
3737 | struct probe *probe; | |
3738 | ||
3739 | for (i = 0; | |
3740 | VEC_iterate (probe_p, | |
3741 | bp_objfile_data->exception_probes, | |
3742 | i, probe); | |
3743 | ++i) | |
3744 | { | |
3745 | struct breakpoint *b; | |
3746 | ||
729662a5 TT |
3747 | b = create_internal_breakpoint (gdbarch, |
3748 | get_probe_address (probe, | |
3749 | objfile), | |
28106bc2 SDJ |
3750 | bp_exception_master, |
3751 | &internal_breakpoint_ops); | |
5b56227b KS |
3752 | b->location |
3753 | = new_probe_location ("-probe-stap libgcc:unwind"); | |
28106bc2 SDJ |
3754 | b->enable_state = bp_disabled; |
3755 | } | |
3756 | ||
3757 | continue; | |
3758 | } | |
3759 | ||
3760 | /* Otherwise, try the hook function. */ | |
3761 | ||
3b7344d5 | 3762 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3763 | continue; |
3764 | ||
3765 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3766 | |
3b7344d5 | 3767 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3768 | { |
3b7344d5 | 3769 | struct bound_minimal_symbol debug_hook; |
186c406b | 3770 | |
17450429 | 3771 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3772 | if (debug_hook.minsym == NULL) |
17450429 | 3773 | { |
3b7344d5 | 3774 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3775 | continue; |
3776 | } | |
3777 | ||
3778 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3779 | } |
17450429 | 3780 | |
77e371c0 | 3781 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3782 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3783 | ¤t_target); | |
06edf0c0 PA |
3784 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3785 | &internal_breakpoint_ops); | |
67994074 KS |
3786 | initialize_explicit_location (&explicit_loc); |
3787 | explicit_loc.function_name = ASTRDUP (func_name); | |
3788 | b->location = new_explicit_location (&explicit_loc); | |
17450429 | 3789 | b->enable_state = bp_disabled; |
186c406b | 3790 | } |
186c406b TT |
3791 | } |
3792 | ||
9ef9e6a6 KS |
3793 | /* Does B have a location spec? */ |
3794 | ||
3795 | static int | |
3796 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3797 | { | |
3798 | return b->location != NULL && event_location_empty_p (b->location); | |
3799 | } | |
3800 | ||
c906108c | 3801 | void |
fba45db2 | 3802 | update_breakpoints_after_exec (void) |
c906108c | 3803 | { |
35df4500 | 3804 | struct breakpoint *b, *b_tmp; |
876fa593 | 3805 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3806 | |
25b22b0a PA |
3807 | /* We're about to delete breakpoints from GDB's lists. If the |
3808 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3809 | writing the breakpoints' "shadow contents" back into memory. The | |
3810 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3811 | do that. Instead, the target is responsible from marking | |
3812 | breakpoints out as soon as it detects an exec. We don't do that | |
3813 | here instead, because there may be other attempts to delete | |
3814 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3815 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3816 | if (bploc->pspace == current_program_space) |
3817 | gdb_assert (!bploc->inserted); | |
c906108c | 3818 | |
35df4500 | 3819 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3820 | { |
6c95b8df PA |
3821 | if (b->pspace != current_program_space) |
3822 | continue; | |
3823 | ||
4a64f543 | 3824 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3825 | if (b->type == bp_shlib_event) |
3826 | { | |
3827 | delete_breakpoint (b); | |
3828 | continue; | |
3829 | } | |
c906108c | 3830 | |
4a64f543 | 3831 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3832 | if (b->type == bp_jit_event) |
3833 | { | |
3834 | delete_breakpoint (b); | |
3835 | continue; | |
3836 | } | |
3837 | ||
1900040c | 3838 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3839 | as must overlay event and longjmp master breakpoints. */ |
3840 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3841 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3842 | || b->type == bp_exception_master) | |
c4093a6a JM |
3843 | { |
3844 | delete_breakpoint (b); | |
3845 | continue; | |
3846 | } | |
3847 | ||
4a64f543 | 3848 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3849 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3850 | { |
3851 | delete_breakpoint (b); | |
3852 | continue; | |
3853 | } | |
3854 | ||
7c16b83e PA |
3855 | /* Just like single-step breakpoints. */ |
3856 | if (b->type == bp_single_step) | |
3857 | { | |
3858 | delete_breakpoint (b); | |
3859 | continue; | |
3860 | } | |
3861 | ||
611c83ae PA |
3862 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3863 | after an exec. */ | |
186c406b | 3864 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3865 | || b->type == bp_longjmp_call_dummy |
186c406b | 3866 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3867 | { |
3868 | delete_breakpoint (b); | |
3869 | continue; | |
3870 | } | |
3871 | ||
ce78b96d JB |
3872 | if (b->type == bp_catchpoint) |
3873 | { | |
3874 | /* For now, none of the bp_catchpoint breakpoints need to | |
3875 | do anything at this point. In the future, if some of | |
3876 | the catchpoints need to something, we will need to add | |
3877 | a new method, and call this method from here. */ | |
3878 | continue; | |
3879 | } | |
3880 | ||
c5aa993b JM |
3881 | /* bp_finish is a special case. The only way we ought to be able |
3882 | to see one of these when an exec() has happened, is if the user | |
3883 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3884 | carries them to the call-site of the current callee, by setting | |
3885 | a temporary bp there and resuming. But in this case, the finish | |
3886 | will carry them entirely through the vfork & exec. | |
3887 | ||
3888 | We don't want to allow a bp_finish to remain inserted now. But | |
3889 | we can't safely delete it, 'cause finish_command has a handle to | |
3890 | the bp on a bpstat, and will later want to delete it. There's a | |
3891 | chance (and I've seen it happen) that if we delete the bp_finish | |
3892 | here, that its storage will get reused by the time finish_command | |
3893 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3894 | We really must allow finish_command to delete a bp_finish. | |
3895 | ||
e5dd4106 | 3896 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3897 | it's safe to delete something others may have handles to?" |
3898 | problem, what we'll do here is just uninsert the bp_finish, and | |
3899 | let finish_command delete it. | |
3900 | ||
3901 | (We know the bp_finish is "doomed" in the sense that it's | |
3902 | momentary, and will be deleted as soon as finish_command sees | |
3903 | the inferior stopped. So it doesn't matter that the bp's | |
3904 | address is probably bogus in the new a.out, unlike e.g., the | |
3905 | solib breakpoints.) */ | |
c5aa993b | 3906 | |
c5aa993b JM |
3907 | if (b->type == bp_finish) |
3908 | { | |
3909 | continue; | |
3910 | } | |
3911 | ||
3912 | /* Without a symbolic address, we have little hope of the | |
3913 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3914 | a.out. */ |
9ef9e6a6 | 3915 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3916 | { |
3917 | delete_breakpoint (b); | |
3918 | continue; | |
3919 | } | |
c5aa993b | 3920 | } |
c906108c SS |
3921 | } |
3922 | ||
3923 | int | |
d80ee84f | 3924 | detach_breakpoints (ptid_t ptid) |
c906108c | 3925 | { |
35df4500 | 3926 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3927 | int val = 0; |
ce696e05 | 3928 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3929 | struct inferior *inf = current_inferior (); |
c5aa993b | 3930 | |
dfd4cc63 | 3931 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3932 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3933 | |
6c95b8df | 3934 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3935 | inferior_ptid = ptid; |
35df4500 | 3936 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3937 | { |
35df4500 | 3938 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3939 | continue; |
3940 | ||
bd9673a4 PW |
3941 | /* This function must physically remove breakpoints locations |
3942 | from the specified ptid, without modifying the breakpoint | |
3943 | package's state. Locations of type bp_loc_other are only | |
3944 | maintained at GDB side. So, there is no need to remove | |
3945 | these bp_loc_other locations. Moreover, removing these | |
3946 | would modify the breakpoint package's state. */ | |
3947 | if (bl->loc_type == bp_loc_other) | |
3948 | continue; | |
3949 | ||
35df4500 | 3950 | if (bl->inserted) |
b2b6a7da | 3951 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3952 | } |
d03285ec | 3953 | |
ce696e05 | 3954 | do_cleanups (old_chain); |
3a1bae8e | 3955 | return val; |
c906108c SS |
3956 | } |
3957 | ||
35df4500 | 3958 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3959 | Note that this is used to detach breakpoints from a child fork. |
3960 | When we get here, the child isn't in the inferior list, and neither | |
3961 | do we have objects to represent its address space --- we should | |
35df4500 | 3962 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3963 | |
c906108c | 3964 | static int |
b2b6a7da | 3965 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3966 | { |
3967 | int val; | |
c5aa993b | 3968 | |
35df4500 TJB |
3969 | /* BL is never in moribund_locations by our callers. */ |
3970 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3971 | |
74960c60 VP |
3972 | /* The type of none suggests that owner is actually deleted. |
3973 | This should not ever happen. */ | |
35df4500 | 3974 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3975 | |
35df4500 TJB |
3976 | if (bl->loc_type == bp_loc_software_breakpoint |
3977 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3978 | { |
c02f5703 MS |
3979 | /* "Normal" instruction breakpoint: either the standard |
3980 | trap-instruction bp (bp_breakpoint), or a | |
3981 | bp_hardware_breakpoint. */ | |
3982 | ||
3983 | /* First check to see if we have to handle an overlay. */ | |
3984 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3985 | || bl->section == NULL |
3986 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3987 | { |
3988 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3989 | |
3990 | /* If we're trying to uninsert a memory breakpoint that we | |
3991 | know is set in a dynamic object that is marked | |
3992 | shlib_disabled, then either the dynamic object was | |
3993 | removed with "remove-symbol-file" or with | |
3994 | "nosharedlibrary". In the former case, we don't know | |
3995 | whether another dynamic object might have loaded over the | |
3996 | breakpoint's address -- the user might well let us know | |
3997 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3998 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3999 | list of dynamically loaded objects). If we have the |
4000 | breakpoint's shadow memory, that is, this is a software | |
4001 | breakpoint managed by GDB, check whether the breakpoint | |
4002 | is still inserted in memory, to avoid overwriting wrong | |
4003 | code with stale saved shadow contents. Note that HW | |
4004 | breakpoints don't have shadow memory, as they're | |
4005 | implemented using a mechanism that is not dependent on | |
4006 | being able to modify the target's memory, and as such | |
4007 | they should always be removed. */ | |
4008 | if (bl->shlib_disabled | |
4009 | && bl->target_info.shadow_len != 0 | |
4010 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
4011 | val = 0; | |
4012 | else | |
73971819 | 4013 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 4014 | } |
c906108c SS |
4015 | else |
4016 | { | |
4a64f543 | 4017 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
4018 | Did we set a breakpoint at the LMA? */ |
4019 | if (!overlay_events_enabled) | |
4020 | { | |
4021 | /* Yes -- overlay event support is not active, so we | |
4022 | should have set a breakpoint at the LMA. Remove it. | |
4023 | */ | |
c02f5703 MS |
4024 | /* Ignore any failures: if the LMA is in ROM, we will |
4025 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
4026 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
4027 | target_remove_hw_breakpoint (bl->gdbarch, | |
4028 | &bl->overlay_target_info); | |
c02f5703 | 4029 | else |
35df4500 | 4030 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
4031 | &bl->overlay_target_info, |
4032 | reason); | |
c02f5703 MS |
4033 | } |
4034 | /* Did we set a breakpoint at the VMA? | |
4035 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4036 | if (bl->inserted) |
c906108c | 4037 | { |
c02f5703 MS |
4038 | /* Yes -- remove it. Previously we did not bother to |
4039 | remove the breakpoint if the section had been | |
4040 | unmapped, but let's not rely on that being safe. We | |
4041 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4042 | |
4043 | /* However, we should remove *software* breakpoints only | |
4044 | if the section is still mapped, or else we overwrite | |
4045 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4046 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4047 | || section_is_mapped (bl->section)) | |
73971819 | 4048 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
4049 | else |
4050 | val = 0; | |
c906108c | 4051 | } |
c02f5703 MS |
4052 | else |
4053 | { | |
4054 | /* No -- not inserted, so no need to remove. No error. */ | |
4055 | val = 0; | |
4056 | } | |
c906108c | 4057 | } |
879d1e6b | 4058 | |
08351840 PA |
4059 | /* In some cases, we might not be able to remove a breakpoint in |
4060 | a shared library that has already been removed, but we have | |
4061 | not yet processed the shlib unload event. Similarly for an | |
4062 | unloaded add-symbol-file object - the user might not yet have | |
4063 | had the chance to remove-symbol-file it. shlib_disabled will | |
4064 | be set if the library/object has already been removed, but | |
4065 | the breakpoint hasn't been uninserted yet, e.g., after | |
4066 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4067 | always-inserted mode. */ | |
076855f9 | 4068 | if (val |
08351840 PA |
4069 | && (bl->loc_type == bp_loc_software_breakpoint |
4070 | && (bl->shlib_disabled | |
4071 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4072 | || shared_objfile_contains_address_p (bl->pspace, |
4073 | bl->address)))) | |
879d1e6b UW |
4074 | val = 0; |
4075 | ||
c906108c SS |
4076 | if (val) |
4077 | return val; | |
b2b6a7da | 4078 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 4079 | } |
35df4500 | 4080 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4081 | { |
77b06cd7 TJB |
4082 | gdb_assert (bl->owner->ops != NULL |
4083 | && bl->owner->ops->remove_location != NULL); | |
4084 | ||
b2b6a7da | 4085 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 4086 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 4087 | |
c906108c | 4088 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 4089 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 4090 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4091 | bl->owner->number); |
c906108c | 4092 | } |
35df4500 TJB |
4093 | else if (bl->owner->type == bp_catchpoint |
4094 | && breakpoint_enabled (bl->owner) | |
4095 | && !bl->duplicate) | |
ce78b96d | 4096 | { |
77b06cd7 TJB |
4097 | gdb_assert (bl->owner->ops != NULL |
4098 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4099 | |
73971819 | 4100 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
4101 | if (val) |
4102 | return val; | |
77b06cd7 | 4103 | |
b2b6a7da | 4104 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 4105 | } |
c906108c SS |
4106 | |
4107 | return 0; | |
4108 | } | |
4109 | ||
6c95b8df | 4110 | static int |
834c0d03 | 4111 | remove_breakpoint (struct bp_location *bl) |
6c95b8df PA |
4112 | { |
4113 | int ret; | |
4114 | struct cleanup *old_chain; | |
4115 | ||
35df4500 TJB |
4116 | /* BL is never in moribund_locations by our callers. */ |
4117 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4118 | |
6c95b8df PA |
4119 | /* The type of none suggests that owner is actually deleted. |
4120 | This should not ever happen. */ | |
35df4500 | 4121 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4122 | |
4123 | old_chain = save_current_space_and_thread (); | |
4124 | ||
35df4500 | 4125 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4126 | |
b2b6a7da | 4127 | ret = remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4128 | |
4129 | do_cleanups (old_chain); | |
4130 | return ret; | |
4131 | } | |
4132 | ||
c906108c SS |
4133 | /* Clear the "inserted" flag in all breakpoints. */ |
4134 | ||
25b22b0a | 4135 | void |
fba45db2 | 4136 | mark_breakpoints_out (void) |
c906108c | 4137 | { |
35df4500 | 4138 | struct bp_location *bl, **blp_tmp; |
c906108c | 4139 | |
35df4500 | 4140 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4141 | if (bl->pspace == current_program_space) |
35df4500 | 4142 | bl->inserted = 0; |
c906108c SS |
4143 | } |
4144 | ||
53a5351d JM |
4145 | /* Clear the "inserted" flag in all breakpoints and delete any |
4146 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4147 | |
4148 | Plus other such housekeeping that has to be done for breakpoints | |
4149 | between runs. | |
4150 | ||
53a5351d JM |
4151 | Note: this function gets called at the end of a run (by |
4152 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4153 | init_wait_for_inferior). */ |
c906108c SS |
4154 | |
4155 | ||
4156 | ||
4157 | void | |
fba45db2 | 4158 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4159 | { |
35df4500 | 4160 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4161 | struct bp_location *bl; |
1c5cfe86 | 4162 | int ix; |
6c95b8df | 4163 | struct program_space *pspace = current_program_space; |
c906108c | 4164 | |
50c71eaf PA |
4165 | /* If breakpoint locations are shared across processes, then there's |
4166 | nothing to do. */ | |
f5656ead | 4167 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4168 | return; |
4169 | ||
1a853c52 | 4170 | mark_breakpoints_out (); |
075f6582 | 4171 | |
35df4500 | 4172 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4173 | { |
6c95b8df PA |
4174 | if (b->loc && b->loc->pspace != pspace) |
4175 | continue; | |
4176 | ||
c5aa993b JM |
4177 | switch (b->type) |
4178 | { | |
4179 | case bp_call_dummy: | |
e2e4d78b | 4180 | case bp_longjmp_call_dummy: |
c906108c | 4181 | |
c5aa993b | 4182 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4183 | cause problems when the inferior is rerun, so we better get |
4184 | rid of it. */ | |
4185 | ||
4186 | case bp_watchpoint_scope: | |
4187 | ||
4188 | /* Also get rid of scope breakpoints. */ | |
4189 | ||
4190 | case bp_shlib_event: | |
4191 | ||
4192 | /* Also remove solib event breakpoints. Their addresses may | |
4193 | have changed since the last time we ran the program. | |
4194 | Actually we may now be debugging against different target; | |
4195 | and so the solib backend that installed this breakpoint may | |
4196 | not be used in by the target. E.g., | |
4197 | ||
4198 | (gdb) file prog-linux | |
4199 | (gdb) run # native linux target | |
4200 | ... | |
4201 | (gdb) kill | |
4202 | (gdb) file prog-win.exe | |
4203 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4204 | */ | |
c906108c | 4205 | |
f59f708a PA |
4206 | case bp_step_resume: |
4207 | ||
4208 | /* Also remove step-resume breakpoints. */ | |
4209 | ||
7c16b83e PA |
4210 | case bp_single_step: |
4211 | ||
4212 | /* Also remove single-step breakpoints. */ | |
4213 | ||
c5aa993b JM |
4214 | delete_breakpoint (b); |
4215 | break; | |
c906108c | 4216 | |
c5aa993b JM |
4217 | case bp_watchpoint: |
4218 | case bp_hardware_watchpoint: | |
4219 | case bp_read_watchpoint: | |
4220 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4221 | { |
4222 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4223 | |
3a5c3e22 PA |
4224 | /* Likewise for watchpoints on local expressions. */ |
4225 | if (w->exp_valid_block != NULL) | |
4226 | delete_breakpoint (b); | |
63000888 | 4227 | else |
3a5c3e22 | 4228 | { |
63000888 PA |
4229 | /* Get rid of existing locations, which are no longer |
4230 | valid. New ones will be created in | |
4231 | update_watchpoint, when the inferior is restarted. | |
4232 | The next update_global_location_list call will | |
4233 | garbage collect them. */ | |
4234 | b->loc = NULL; | |
4235 | ||
4236 | if (context == inf_starting) | |
4237 | { | |
4238 | /* Reset val field to force reread of starting value in | |
4239 | insert_breakpoints. */ | |
4240 | if (w->val) | |
4241 | value_free (w->val); | |
4242 | w->val = NULL; | |
4243 | w->val_valid = 0; | |
4244 | } | |
4245 | } | |
3a5c3e22 | 4246 | } |
c5aa993b JM |
4247 | break; |
4248 | default: | |
c5aa993b JM |
4249 | break; |
4250 | } | |
4251 | } | |
1c5cfe86 PA |
4252 | |
4253 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4254 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4255 | decref_bp_location (&bl); | |
1c5cfe86 | 4256 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4257 | } |
4258 | ||
6c95b8df PA |
4259 | /* These functions concern about actual breakpoints inserted in the |
4260 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4261 | we need to hop over the bkpt --- so we check for address space | |
4262 | match, not program space. */ | |
4263 | ||
c2c6d25f JM |
4264 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4265 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4266 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4267 | permanent breakpoint. | |
4268 | - When continuing from a location with an ordinary breakpoint, we | |
4269 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4270 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4271 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4272 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4273 | |
c2c6d25f | 4274 | enum breakpoint_here |
6c95b8df | 4275 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4276 | { |
35df4500 | 4277 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4278 | int any_breakpoint_here = 0; |
c906108c | 4279 | |
35df4500 | 4280 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4281 | { |
35df4500 TJB |
4282 | if (bl->loc_type != bp_loc_software_breakpoint |
4283 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4284 | continue; |
4285 | ||
f1310107 | 4286 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4287 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4288 | || bl->permanent) |
f1310107 | 4289 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4290 | { |
4291 | if (overlay_debugging | |
35df4500 TJB |
4292 | && section_is_overlay (bl->section) |
4293 | && !section_is_mapped (bl->section)) | |
075f6582 | 4294 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4295 | else if (bl->permanent) |
075f6582 DJ |
4296 | return permanent_breakpoint_here; |
4297 | else | |
4298 | any_breakpoint_here = 1; | |
4299 | } | |
4300 | } | |
c906108c | 4301 | |
f486487f | 4302 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4303 | } |
4304 | ||
d35ae833 PA |
4305 | /* See breakpoint.h. */ |
4306 | ||
4307 | int | |
4308 | breakpoint_in_range_p (struct address_space *aspace, | |
4309 | CORE_ADDR addr, ULONGEST len) | |
4310 | { | |
4311 | struct bp_location *bl, **blp_tmp; | |
4312 | ||
4313 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4314 | { | |
4315 | if (bl->loc_type != bp_loc_software_breakpoint | |
4316 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4317 | continue; | |
4318 | ||
4319 | if ((breakpoint_enabled (bl->owner) | |
4320 | || bl->permanent) | |
4321 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4322 | addr, len)) | |
4323 | { | |
4324 | if (overlay_debugging | |
4325 | && section_is_overlay (bl->section) | |
4326 | && !section_is_mapped (bl->section)) | |
4327 | { | |
4328 | /* Unmapped overlay -- can't be a match. */ | |
4329 | continue; | |
4330 | } | |
4331 | ||
4332 | return 1; | |
4333 | } | |
4334 | } | |
4335 | ||
4336 | return 0; | |
4337 | } | |
4338 | ||
1c5cfe86 PA |
4339 | /* Return true if there's a moribund breakpoint at PC. */ |
4340 | ||
4341 | int | |
6c95b8df | 4342 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4343 | { |
4344 | struct bp_location *loc; | |
4345 | int ix; | |
4346 | ||
4347 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4348 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4349 | return 1; |
4350 | ||
4351 | return 0; | |
4352 | } | |
c2c6d25f | 4353 | |
f7ce857f PA |
4354 | /* Returns non-zero iff BL is inserted at PC, in address space |
4355 | ASPACE. */ | |
4356 | ||
4357 | static int | |
4358 | bp_location_inserted_here_p (struct bp_location *bl, | |
4359 | struct address_space *aspace, CORE_ADDR pc) | |
4360 | { | |
4361 | if (bl->inserted | |
4362 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4363 | aspace, pc)) | |
4364 | { | |
4365 | if (overlay_debugging | |
4366 | && section_is_overlay (bl->section) | |
4367 | && !section_is_mapped (bl->section)) | |
4368 | return 0; /* unmapped overlay -- can't be a match */ | |
4369 | else | |
4370 | return 1; | |
4371 | } | |
4372 | return 0; | |
4373 | } | |
4374 | ||
a1fd2fa5 | 4375 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4376 | |
4377 | int | |
a1fd2fa5 | 4378 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4379 | { |
f7ce857f | 4380 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4381 | |
f7ce857f | 4382 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4383 | { |
f7ce857f PA |
4384 | struct bp_location *bl = *blp; |
4385 | ||
35df4500 TJB |
4386 | if (bl->loc_type != bp_loc_software_breakpoint |
4387 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4388 | continue; |
4389 | ||
f7ce857f PA |
4390 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4391 | return 1; | |
c5aa993b | 4392 | } |
c36b740a VP |
4393 | return 0; |
4394 | } | |
4395 | ||
a1fd2fa5 PA |
4396 | /* This function returns non-zero iff there is a software breakpoint |
4397 | inserted at PC. */ | |
c36b740a VP |
4398 | |
4399 | int | |
a1fd2fa5 PA |
4400 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4401 | CORE_ADDR pc) | |
4fa8626c | 4402 | { |
f7ce857f | 4403 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4404 | |
f7ce857f | 4405 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4406 | { |
f7ce857f PA |
4407 | struct bp_location *bl = *blp; |
4408 | ||
35df4500 | 4409 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4410 | continue; |
4411 | ||
f7ce857f PA |
4412 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4413 | return 1; | |
4fa8626c DJ |
4414 | } |
4415 | ||
4416 | return 0; | |
9c02b525 PA |
4417 | } |
4418 | ||
4419 | /* See breakpoint.h. */ | |
4420 | ||
4421 | int | |
4422 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4423 | CORE_ADDR pc) | |
4424 | { | |
4425 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4426 | |
4427 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4428 | { | |
4429 | struct bp_location *bl = *blp; | |
4430 | ||
4431 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4432 | continue; | |
4433 | ||
4434 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4435 | return 1; | |
4436 | } | |
4437 | ||
4438 | return 0; | |
4fa8626c DJ |
4439 | } |
4440 | ||
9093389c PA |
4441 | int |
4442 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4443 | CORE_ADDR addr, ULONGEST len) | |
4444 | { | |
4445 | struct breakpoint *bpt; | |
4446 | ||
4447 | ALL_BREAKPOINTS (bpt) | |
4448 | { | |
4449 | struct bp_location *loc; | |
4450 | ||
4451 | if (bpt->type != bp_hardware_watchpoint | |
4452 | && bpt->type != bp_access_watchpoint) | |
4453 | continue; | |
4454 | ||
4455 | if (!breakpoint_enabled (bpt)) | |
4456 | continue; | |
4457 | ||
4458 | for (loc = bpt->loc; loc; loc = loc->next) | |
4459 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4460 | { | |
4461 | CORE_ADDR l, h; | |
4462 | ||
4463 | /* Check for intersection. */ | |
768adc05 PA |
4464 | l = std::max<CORE_ADDR> (loc->address, addr); |
4465 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4466 | if (l < h) |
4467 | return 1; | |
4468 | } | |
4469 | } | |
4470 | return 0; | |
4471 | } | |
c906108c | 4472 | \f |
c5aa993b | 4473 | |
c906108c SS |
4474 | /* bpstat stuff. External routines' interfaces are documented |
4475 | in breakpoint.h. */ | |
4476 | ||
4477 | int | |
c326b90e | 4478 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4479 | { |
533be4dd | 4480 | return (ep->type == bp_catchpoint); |
c906108c SS |
4481 | } |
4482 | ||
f431efe5 PA |
4483 | /* Frees any storage that is part of a bpstat. Does not walk the |
4484 | 'next' chain. */ | |
4485 | ||
4486 | static void | |
198757a8 VP |
4487 | bpstat_free (bpstat bs) |
4488 | { | |
4489 | if (bs->old_val != NULL) | |
4490 | value_free (bs->old_val); | |
9add0f1b | 4491 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4492 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4493 | xfree (bs); |
4494 | } | |
4495 | ||
c906108c SS |
4496 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4497 | Also free any storage that is part of a bpstat. */ | |
4498 | ||
4499 | void | |
fba45db2 | 4500 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4501 | { |
4502 | bpstat p; | |
4503 | bpstat q; | |
4504 | ||
4505 | if (bsp == 0) | |
4506 | return; | |
4507 | p = *bsp; | |
4508 | while (p != NULL) | |
4509 | { | |
4510 | q = p->next; | |
198757a8 | 4511 | bpstat_free (p); |
c906108c SS |
4512 | p = q; |
4513 | } | |
4514 | *bsp = NULL; | |
4515 | } | |
4516 | ||
4517 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4518 | is part of the bpstat is copied as well. */ | |
4519 | ||
4520 | bpstat | |
fba45db2 | 4521 | bpstat_copy (bpstat bs) |
c906108c SS |
4522 | { |
4523 | bpstat p = NULL; | |
4524 | bpstat tmp; | |
4525 | bpstat retval = NULL; | |
4526 | ||
4527 | if (bs == NULL) | |
4528 | return bs; | |
4529 | ||
4530 | for (; bs != NULL; bs = bs->next) | |
4531 | { | |
4532 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4533 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4534 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4535 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4536 | if (bs->old_val != NULL) |
3c3185ac JK |
4537 | { |
4538 | tmp->old_val = value_copy (bs->old_val); | |
4539 | release_value (tmp->old_val); | |
4540 | } | |
31cc81e9 | 4541 | |
c906108c SS |
4542 | if (p == NULL) |
4543 | /* This is the first thing in the chain. */ | |
4544 | retval = tmp; | |
4545 | else | |
4546 | p->next = tmp; | |
4547 | p = tmp; | |
4548 | } | |
4549 | p->next = NULL; | |
4550 | return retval; | |
4551 | } | |
4552 | ||
4a64f543 | 4553 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4554 | |
4555 | bpstat | |
fba45db2 | 4556 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4557 | { |
c5aa993b JM |
4558 | if (bsp == NULL) |
4559 | return NULL; | |
c906108c | 4560 | |
c5aa993b JM |
4561 | for (; bsp != NULL; bsp = bsp->next) |
4562 | { | |
f431efe5 | 4563 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4564 | return bsp; |
4565 | } | |
c906108c SS |
4566 | return NULL; |
4567 | } | |
4568 | ||
ab04a2af TT |
4569 | /* See breakpoint.h. */ |
4570 | ||
47591c29 | 4571 | int |
427cd150 | 4572 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4573 | { |
ab04a2af TT |
4574 | for (; bsp != NULL; bsp = bsp->next) |
4575 | { | |
427cd150 TT |
4576 | if (bsp->breakpoint_at == NULL) |
4577 | { | |
4578 | /* A moribund location can never explain a signal other than | |
4579 | GDB_SIGNAL_TRAP. */ | |
4580 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4581 | return 1; |
427cd150 TT |
4582 | } |
4583 | else | |
47591c29 PA |
4584 | { |
4585 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4586 | sig)) | |
4587 | return 1; | |
4588 | } | |
ab04a2af TT |
4589 | } |
4590 | ||
47591c29 | 4591 | return 0; |
ab04a2af TT |
4592 | } |
4593 | ||
4a64f543 MS |
4594 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4595 | stopped at. *BSP upon return is a bpstat which points to the | |
4596 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4597 | good for anything but further calls to bpstat_num). | |
4598 | ||
8671a17b PA |
4599 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4600 | Return -1 if stopped at a breakpoint that has been deleted since | |
4601 | we set it. | |
4602 | Return 1 otherwise. */ | |
c906108c SS |
4603 | |
4604 | int | |
8671a17b | 4605 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4606 | { |
4607 | struct breakpoint *b; | |
4608 | ||
4609 | if ((*bsp) == NULL) | |
4610 | return 0; /* No more breakpoint values */ | |
8671a17b | 4611 | |
4a64f543 MS |
4612 | /* We assume we'll never have several bpstats that correspond to a |
4613 | single breakpoint -- otherwise, this function might return the | |
4614 | same number more than once and this will look ugly. */ | |
f431efe5 | 4615 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4616 | *bsp = (*bsp)->next; |
4617 | if (b == NULL) | |
4618 | return -1; /* breakpoint that's been deleted since */ | |
4619 | ||
4620 | *num = b->number; /* We have its number */ | |
4621 | return 1; | |
c906108c SS |
4622 | } |
4623 | ||
e93ca019 | 4624 | /* See breakpoint.h. */ |
c906108c SS |
4625 | |
4626 | void | |
e93ca019 | 4627 | bpstat_clear_actions (void) |
c906108c | 4628 | { |
e93ca019 JK |
4629 | struct thread_info *tp; |
4630 | bpstat bs; | |
4631 | ||
4632 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4633 | return; | |
4634 | ||
4635 | tp = find_thread_ptid (inferior_ptid); | |
4636 | if (tp == NULL) | |
4637 | return; | |
4638 | ||
4639 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4640 | { |
9add0f1b | 4641 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4642 | |
c906108c SS |
4643 | if (bs->old_val != NULL) |
4644 | { | |
4645 | value_free (bs->old_val); | |
4646 | bs->old_val = NULL; | |
4647 | } | |
4648 | } | |
4649 | } | |
4650 | ||
f3b1572e PA |
4651 | /* Called when a command is about to proceed the inferior. */ |
4652 | ||
4653 | static void | |
4654 | breakpoint_about_to_proceed (void) | |
4655 | { | |
4656 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4657 | { | |
4658 | struct thread_info *tp = inferior_thread (); | |
4659 | ||
4660 | /* Allow inferior function calls in breakpoint commands to not | |
4661 | interrupt the command list. When the call finishes | |
4662 | successfully, the inferior will be standing at the same | |
4663 | breakpoint as if nothing happened. */ | |
16c381f0 | 4664 | if (tp->control.in_infcall) |
f3b1572e PA |
4665 | return; |
4666 | } | |
4667 | ||
4668 | breakpoint_proceeded = 1; | |
4669 | } | |
4670 | ||
4a64f543 MS |
4671 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4672 | command. */ | |
c906108c | 4673 | static void |
4efb68b1 | 4674 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4675 | { |
4676 | executing_breakpoint_commands = 0; | |
4677 | } | |
4678 | ||
abf85f46 JK |
4679 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4680 | or its equivalent. */ | |
4681 | ||
4682 | static int | |
4683 | command_line_is_silent (struct command_line *cmd) | |
4684 | { | |
4f45d445 | 4685 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4686 | } |
4687 | ||
4a64f543 MS |
4688 | /* Execute all the commands associated with all the breakpoints at |
4689 | this location. Any of these commands could cause the process to | |
4690 | proceed beyond this point, etc. We look out for such changes by | |
4691 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4692 | |
347bddb7 PA |
4693 | Returns true if a breakpoint command resumed the inferior. In that |
4694 | case, it is the caller's responsibility to recall it again with the | |
4695 | bpstat of the current thread. */ | |
4696 | ||
4697 | static int | |
4698 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4699 | { |
4700 | bpstat bs; | |
4701 | struct cleanup *old_chain; | |
347bddb7 | 4702 | int again = 0; |
c906108c SS |
4703 | |
4704 | /* Avoid endless recursion if a `source' command is contained | |
4705 | in bs->commands. */ | |
4706 | if (executing_breakpoint_commands) | |
347bddb7 | 4707 | return 0; |
c906108c SS |
4708 | |
4709 | executing_breakpoint_commands = 1; | |
4710 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4711 | ||
cf6c5ffb TT |
4712 | prevent_dont_repeat (); |
4713 | ||
4a64f543 | 4714 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4715 | bs = *bsp; |
4716 | ||
4717 | breakpoint_proceeded = 0; | |
4718 | for (; bs != NULL; bs = bs->next) | |
4719 | { | |
9add0f1b | 4720 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4721 | struct command_line *cmd; |
4722 | struct cleanup *this_cmd_tree_chain; | |
4723 | ||
4724 | /* Take ownership of the BSP's command tree, if it has one. | |
4725 | ||
4726 | The command tree could legitimately contain commands like | |
4727 | 'step' and 'next', which call clear_proceed_status, which | |
4728 | frees stop_bpstat's command tree. To make sure this doesn't | |
4729 | free the tree we're executing out from under us, we need to | |
4730 | take ownership of the tree ourselves. Since a given bpstat's | |
4731 | commands are only executed once, we don't need to copy it; we | |
4732 | can clear the pointer in the bpstat, and make sure we free | |
4733 | the tree when we're done. */ | |
9add0f1b TT |
4734 | ccmd = bs->commands; |
4735 | bs->commands = NULL; | |
abf85f46 JK |
4736 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4737 | cmd = ccmd ? ccmd->commands : NULL; | |
4738 | if (command_line_is_silent (cmd)) | |
4739 | { | |
4740 | /* The action has been already done by bpstat_stop_status. */ | |
4741 | cmd = cmd->next; | |
4742 | } | |
6c50ab1c | 4743 | |
c906108c SS |
4744 | while (cmd != NULL) |
4745 | { | |
4746 | execute_control_command (cmd); | |
4747 | ||
4748 | if (breakpoint_proceeded) | |
4749 | break; | |
4750 | else | |
4751 | cmd = cmd->next; | |
4752 | } | |
6c50ab1c JB |
4753 | |
4754 | /* We can free this command tree now. */ | |
4755 | do_cleanups (this_cmd_tree_chain); | |
4756 | ||
c906108c | 4757 | if (breakpoint_proceeded) |
32c1e744 | 4758 | { |
cb814510 | 4759 | if (current_ui->async) |
347bddb7 PA |
4760 | /* If we are in async mode, then the target might be still |
4761 | running, not stopped at any breakpoint, so nothing for | |
4762 | us to do here -- just return to the event loop. */ | |
4763 | ; | |
32c1e744 VP |
4764 | else |
4765 | /* In sync mode, when execute_control_command returns | |
4766 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4767 | Breakpoint commands for that stop were not run, since |
4768 | execute_command does not run breakpoint commands -- | |
4769 | only command_line_handler does, but that one is not | |
4770 | involved in execution of breakpoint commands. So, we | |
4771 | can now execute breakpoint commands. It should be | |
4772 | noted that making execute_command do bpstat actions is | |
4773 | not an option -- in this case we'll have recursive | |
4774 | invocation of bpstat for each breakpoint with a | |
4775 | command, and can easily blow up GDB stack. Instead, we | |
4776 | return true, which will trigger the caller to recall us | |
4777 | with the new stop_bpstat. */ | |
4778 | again = 1; | |
4779 | break; | |
32c1e744 | 4780 | } |
c906108c | 4781 | } |
c2b8ed2c | 4782 | do_cleanups (old_chain); |
347bddb7 PA |
4783 | return again; |
4784 | } | |
4785 | ||
4786 | void | |
4787 | bpstat_do_actions (void) | |
4788 | { | |
353d1d73 JK |
4789 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4790 | ||
347bddb7 PA |
4791 | /* Do any commands attached to breakpoint we are stopped at. */ |
4792 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4793 | && target_has_execution | |
4794 | && !is_exited (inferior_ptid) | |
4795 | && !is_executing (inferior_ptid)) | |
4796 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4797 | and only return when it is stopped at the next breakpoint, we | |
4798 | keep doing breakpoint actions until it returns false to | |
4799 | indicate the inferior was not resumed. */ | |
16c381f0 | 4800 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4801 | break; |
353d1d73 JK |
4802 | |
4803 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4804 | } |
4805 | ||
fa4727a6 DJ |
4806 | /* Print out the (old or new) value associated with a watchpoint. */ |
4807 | ||
4808 | static void | |
4809 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4810 | { | |
4811 | if (val == NULL) | |
4812 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4813 | else | |
79a45b7d TT |
4814 | { |
4815 | struct value_print_options opts; | |
4816 | get_user_print_options (&opts); | |
4817 | value_print (val, stream, &opts); | |
4818 | } | |
fa4727a6 DJ |
4819 | } |
4820 | ||
f303dbd6 PA |
4821 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4822 | debugging multiple threads. */ | |
4823 | ||
4824 | void | |
4825 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4826 | { | |
4827 | if (ui_out_is_mi_like_p (uiout)) | |
4828 | return; | |
4829 | ||
4830 | ui_out_text (uiout, "\n"); | |
4831 | ||
4832 | if (show_thread_that_caused_stop ()) | |
4833 | { | |
4834 | const char *name; | |
4835 | struct thread_info *thr = inferior_thread (); | |
4836 | ||
4837 | ui_out_text (uiout, "Thread "); | |
4838 | ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr)); | |
4839 | ||
4840 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4841 | if (name != NULL) | |
4842 | { | |
4843 | ui_out_text (uiout, " \""); | |
4844 | ui_out_field_fmt (uiout, "name", "%s", name); | |
4845 | ui_out_text (uiout, "\""); | |
4846 | } | |
4847 | ||
4848 | ui_out_text (uiout, " hit "); | |
4849 | } | |
4850 | } | |
4851 | ||
e514a9d6 | 4852 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4853 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4854 | 'print_it' in the bpstat structure. Under some circumstances we |
4855 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4856 | normal_stop(). */ |
e514a9d6 JM |
4857 | |
4858 | static enum print_stop_action | |
4859 | print_bp_stop_message (bpstat bs) | |
4860 | { | |
4861 | switch (bs->print_it) | |
4862 | { | |
4863 | case print_it_noop: | |
4a64f543 | 4864 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4865 | return PRINT_UNKNOWN; |
4866 | break; | |
4867 | ||
4868 | case print_it_done: | |
4869 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4870 | relevant messages. */ |
e514a9d6 JM |
4871 | return PRINT_SRC_AND_LOC; |
4872 | break; | |
4873 | ||
4874 | case print_it_normal: | |
4f8d1dc6 | 4875 | { |
f431efe5 PA |
4876 | struct breakpoint *b = bs->breakpoint_at; |
4877 | ||
1a6a67de TJB |
4878 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4879 | which has since been deleted. */ | |
4880 | if (b == NULL) | |
4881 | return PRINT_UNKNOWN; | |
4882 | ||
348d480f PA |
4883 | /* Normal case. Call the breakpoint's print_it method. */ |
4884 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4885 | } |
348d480f | 4886 | break; |
3086aeae | 4887 | |
e514a9d6 | 4888 | default: |
8e65ff28 | 4889 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4890 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4891 | break; |
c906108c | 4892 | } |
c906108c SS |
4893 | } |
4894 | ||
edcc5120 TT |
4895 | /* A helper function that prints a shared library stopped event. */ |
4896 | ||
4897 | static void | |
4898 | print_solib_event (int is_catchpoint) | |
4899 | { | |
4900 | int any_deleted | |
4901 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4902 | int any_added | |
4903 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4904 | ||
4905 | if (!is_catchpoint) | |
4906 | { | |
4907 | if (any_added || any_deleted) | |
4908 | ui_out_text (current_uiout, | |
4909 | _("Stopped due to shared library event:\n")); | |
4910 | else | |
4911 | ui_out_text (current_uiout, | |
4912 | _("Stopped due to shared library event (no " | |
4913 | "libraries added or removed)\n")); | |
4914 | } | |
4915 | ||
4916 | if (ui_out_is_mi_like_p (current_uiout)) | |
4917 | ui_out_field_string (current_uiout, "reason", | |
4918 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4919 | ||
4920 | if (any_deleted) | |
4921 | { | |
4922 | struct cleanup *cleanup; | |
4923 | char *name; | |
4924 | int ix; | |
4925 | ||
4926 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4927 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4928 | "removed"); | |
4929 | for (ix = 0; | |
4930 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4931 | ix, name); | |
4932 | ++ix) | |
4933 | { | |
4934 | if (ix > 0) | |
4935 | ui_out_text (current_uiout, " "); | |
4936 | ui_out_field_string (current_uiout, "library", name); | |
4937 | ui_out_text (current_uiout, "\n"); | |
4938 | } | |
4939 | ||
4940 | do_cleanups (cleanup); | |
4941 | } | |
4942 | ||
4943 | if (any_added) | |
4944 | { | |
4945 | struct so_list *iter; | |
4946 | int ix; | |
4947 | struct cleanup *cleanup; | |
4948 | ||
4949 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4950 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4951 | "added"); | |
4952 | for (ix = 0; | |
4953 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4954 | ix, iter); | |
4955 | ++ix) | |
4956 | { | |
4957 | if (ix > 0) | |
4958 | ui_out_text (current_uiout, " "); | |
4959 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4960 | ui_out_text (current_uiout, "\n"); | |
4961 | } | |
4962 | ||
4963 | do_cleanups (cleanup); | |
4964 | } | |
4965 | } | |
4966 | ||
e514a9d6 JM |
4967 | /* Print a message indicating what happened. This is called from |
4968 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4969 | list - a list of the eventpoints that caused this stop. KIND is |
4970 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4971 | routine calls the generic print routine for printing a message |
4972 | about reasons for stopping. This will print (for example) the | |
4973 | "Breakpoint n," part of the output. The return value of this | |
4974 | routine is one of: | |
c906108c | 4975 | |
4a64f543 | 4976 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4977 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4978 | code to print the location. An example is |
c5aa993b JM |
4979 | "Breakpoint 1, " which should be followed by |
4980 | the location. | |
917317f4 | 4981 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4982 | to also print the location part of the message. |
4983 | An example is the catch/throw messages, which | |
4a64f543 | 4984 | don't require a location appended to the end. |
917317f4 | 4985 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4986 | further info to be printed. */ |
c906108c | 4987 | |
917317f4 | 4988 | enum print_stop_action |
36dfb11c | 4989 | bpstat_print (bpstat bs, int kind) |
c906108c | 4990 | { |
f486487f | 4991 | enum print_stop_action val; |
c5aa993b | 4992 | |
c906108c | 4993 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4994 | (Currently all watchpoints go on the bpstat whether hit or not. |
4995 | That probably could (should) be changed, provided care is taken | |
c906108c | 4996 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4997 | for (; bs; bs = bs->next) |
4998 | { | |
4999 | val = print_bp_stop_message (bs); | |
5000 | if (val == PRINT_SRC_ONLY | |
5001 | || val == PRINT_SRC_AND_LOC | |
5002 | || val == PRINT_NOTHING) | |
5003 | return val; | |
5004 | } | |
c906108c | 5005 | |
36dfb11c TT |
5006 | /* If we had hit a shared library event breakpoint, |
5007 | print_bp_stop_message would print out this message. If we hit an | |
5008 | OS-level shared library event, do the same thing. */ | |
5009 | if (kind == TARGET_WAITKIND_LOADED) | |
5010 | { | |
edcc5120 | 5011 | print_solib_event (0); |
36dfb11c TT |
5012 | return PRINT_NOTHING; |
5013 | } | |
5014 | ||
e514a9d6 | 5015 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 5016 | with and nothing was printed. */ |
917317f4 | 5017 | return PRINT_UNKNOWN; |
c906108c SS |
5018 | } |
5019 | ||
c42bd95a DE |
5020 | /* Evaluate the expression EXP and return 1 if value is zero. |
5021 | This returns the inverse of the condition because it is called | |
5022 | from catch_errors which returns 0 if an exception happened, and if an | |
5023 | exception happens we want execution to stop. | |
4a64f543 | 5024 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 5025 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
5026 | |
5027 | static int | |
4efb68b1 | 5028 | breakpoint_cond_eval (void *exp) |
c906108c | 5029 | { |
278cd55f | 5030 | struct value *mark = value_mark (); |
c5aa993b | 5031 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 5032 | |
c906108c SS |
5033 | value_free_to_mark (mark); |
5034 | return i; | |
5035 | } | |
5036 | ||
5760d0ab | 5037 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5038 | |
5039 | static bpstat | |
5760d0ab | 5040 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5041 | { |
5042 | bpstat bs; | |
5043 | ||
5044 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5045 | bs->next = NULL; |
5046 | **bs_link_pointer = bs; | |
5047 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5048 | bs->breakpoint_at = bl->owner; |
5049 | bs->bp_location_at = bl; | |
5050 | incref_bp_location (bl); | |
c906108c SS |
5051 | /* If the condition is false, etc., don't do the commands. */ |
5052 | bs->commands = NULL; | |
5053 | bs->old_val = NULL; | |
5054 | bs->print_it = print_it_normal; | |
5055 | return bs; | |
5056 | } | |
5057 | \f | |
d983da9c DJ |
5058 | /* The target has stopped with waitstatus WS. Check if any hardware |
5059 | watchpoints have triggered, according to the target. */ | |
5060 | ||
5061 | int | |
5062 | watchpoints_triggered (struct target_waitstatus *ws) | |
5063 | { | |
d92524f1 | 5064 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5065 | CORE_ADDR addr; |
5066 | struct breakpoint *b; | |
5067 | ||
5068 | if (!stopped_by_watchpoint) | |
5069 | { | |
5070 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5071 | as not triggered. */ | |
5072 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5073 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5074 | { |
5075 | struct watchpoint *w = (struct watchpoint *) b; | |
5076 | ||
5077 | w->watchpoint_triggered = watch_triggered_no; | |
5078 | } | |
d983da9c DJ |
5079 | |
5080 | return 0; | |
5081 | } | |
5082 | ||
5083 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5084 | { | |
5085 | /* We were stopped by a watchpoint, but we don't know where. | |
5086 | Mark all watchpoints as unknown. */ | |
5087 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5088 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5089 | { |
5090 | struct watchpoint *w = (struct watchpoint *) b; | |
5091 | ||
5092 | w->watchpoint_triggered = watch_triggered_unknown; | |
5093 | } | |
d983da9c | 5094 | |
3c4797ba | 5095 | return 1; |
d983da9c DJ |
5096 | } |
5097 | ||
5098 | /* The target could report the data address. Mark watchpoints | |
5099 | affected by this data address as triggered, and all others as not | |
5100 | triggered. */ | |
5101 | ||
5102 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5103 | if (is_hardware_watchpoint (b)) |
d983da9c | 5104 | { |
3a5c3e22 | 5105 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5106 | struct bp_location *loc; |
d983da9c | 5107 | |
3a5c3e22 | 5108 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5109 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5110 | { |
3a5c3e22 | 5111 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5112 | { |
3a5c3e22 PA |
5113 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5114 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5115 | |
5116 | if (newaddr == start) | |
5117 | { | |
3a5c3e22 | 5118 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5119 | break; |
5120 | } | |
5121 | } | |
5122 | /* Exact match not required. Within range is sufficient. */ | |
5123 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5124 | addr, loc->address, | |
5125 | loc->length)) | |
5126 | { | |
3a5c3e22 | 5127 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5128 | break; |
5129 | } | |
5130 | } | |
d983da9c DJ |
5131 | } |
5132 | ||
5133 | return 1; | |
5134 | } | |
5135 | ||
c906108c SS |
5136 | /* Possible return values for watchpoint_check (this can't be an enum |
5137 | because of check_errors). */ | |
5138 | /* The watchpoint has been deleted. */ | |
5139 | #define WP_DELETED 1 | |
5140 | /* The value has changed. */ | |
5141 | #define WP_VALUE_CHANGED 2 | |
5142 | /* The value has not changed. */ | |
5143 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5144 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5145 | #define WP_IGNORE 4 | |
c906108c SS |
5146 | |
5147 | #define BP_TEMPFLAG 1 | |
5148 | #define BP_HARDWAREFLAG 2 | |
5149 | ||
4a64f543 MS |
5150 | /* Evaluate watchpoint condition expression and check if its value |
5151 | changed. | |
553e4c11 JB |
5152 | |
5153 | P should be a pointer to struct bpstat, but is defined as a void * | |
5154 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5155 | |
5156 | static int | |
4efb68b1 | 5157 | watchpoint_check (void *p) |
c906108c SS |
5158 | { |
5159 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5160 | struct watchpoint *b; |
c906108c SS |
5161 | struct frame_info *fr; |
5162 | int within_current_scope; | |
5163 | ||
f431efe5 | 5164 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5165 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5166 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5167 | |
f6bc2008 PA |
5168 | /* If this is a local watchpoint, we only want to check if the |
5169 | watchpoint frame is in scope if the current thread is the thread | |
5170 | that was used to create the watchpoint. */ | |
5171 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5172 | return WP_IGNORE; |
f6bc2008 | 5173 | |
c906108c SS |
5174 | if (b->exp_valid_block == NULL) |
5175 | within_current_scope = 1; | |
5176 | else | |
5177 | { | |
edb3359d DJ |
5178 | struct frame_info *frame = get_current_frame (); |
5179 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5180 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5181 | ||
c9cf6e20 | 5182 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5183 | still in the function but the stack frame has already been |
5184 | invalidated. Since we can't rely on the values of local | |
5185 | variables after the stack has been destroyed, we are treating | |
5186 | the watchpoint in that state as `not changed' without further | |
5187 | checking. Don't mark watchpoints as changed if the current | |
5188 | frame is in an epilogue - even if they are in some other | |
5189 | frame, our view of the stack is likely to be wrong and | |
5190 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5191 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5192 | return WP_IGNORE; |
a0f49112 | 5193 | |
101dcfbe | 5194 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5195 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5196 | |
5197 | /* If we've gotten confused in the unwinder, we might have | |
5198 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5199 | if (within_current_scope) |
5200 | { | |
5201 | struct symbol *function; | |
5202 | ||
5203 | function = get_frame_function (fr); | |
5204 | if (function == NULL | |
5205 | || !contained_in (b->exp_valid_block, | |
5206 | SYMBOL_BLOCK_VALUE (function))) | |
5207 | within_current_scope = 0; | |
5208 | } | |
69fbadd5 | 5209 | |
edb3359d | 5210 | if (within_current_scope) |
c906108c SS |
5211 | /* If we end up stopping, the current frame will get selected |
5212 | in normal_stop. So this call to select_frame won't affect | |
5213 | the user. */ | |
0f7d239c | 5214 | select_frame (fr); |
c906108c | 5215 | } |
c5aa993b | 5216 | |
c906108c SS |
5217 | if (within_current_scope) |
5218 | { | |
4a64f543 MS |
5219 | /* We use value_{,free_to_}mark because it could be a *long* |
5220 | time before we return to the command level and call | |
5221 | free_all_values. We can't call free_all_values because we | |
5222 | might be in the middle of evaluating a function call. */ | |
c906108c | 5223 | |
0cf6dd15 | 5224 | int pc = 0; |
9c06b0b4 | 5225 | struct value *mark; |
fa4727a6 DJ |
5226 | struct value *new_val; |
5227 | ||
3a5c3e22 | 5228 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5229 | /* Since we don't know the exact trigger address (from |
5230 | stopped_data_address), just tell the user we've triggered | |
5231 | a mask watchpoint. */ | |
5232 | return WP_VALUE_CHANGED; | |
5233 | ||
5234 | mark = value_mark (); | |
3a1115a0 | 5235 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5236 | |
bb9d5f81 PP |
5237 | if (b->val_bitsize != 0) |
5238 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5239 | ||
4a64f543 MS |
5240 | /* We use value_equal_contents instead of value_equal because |
5241 | the latter coerces an array to a pointer, thus comparing just | |
5242 | the address of the array instead of its contents. This is | |
5243 | not what we want. */ | |
fa4727a6 | 5244 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5245 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5246 | { |
fa4727a6 DJ |
5247 | if (new_val != NULL) |
5248 | { | |
5249 | release_value (new_val); | |
5250 | value_free_to_mark (mark); | |
5251 | } | |
c906108c SS |
5252 | bs->old_val = b->val; |
5253 | b->val = new_val; | |
fa4727a6 | 5254 | b->val_valid = 1; |
c906108c SS |
5255 | return WP_VALUE_CHANGED; |
5256 | } | |
5257 | else | |
5258 | { | |
60e1c644 | 5259 | /* Nothing changed. */ |
c906108c | 5260 | value_free_to_mark (mark); |
c906108c SS |
5261 | return WP_VALUE_NOT_CHANGED; |
5262 | } | |
5263 | } | |
5264 | else | |
5265 | { | |
5266 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5267 | if we temporarily ignored the watchpoint, then when |
5268 | we reenter the block in which it is valid it contains | |
5269 | garbage (in the case of a function, it may have two | |
5270 | garbage values, one before and one after the prologue). | |
5271 | So we can't even detect the first assignment to it and | |
5272 | watch after that (since the garbage may or may not equal | |
5273 | the first value assigned). */ | |
348d480f PA |
5274 | /* We print all the stop information in |
5275 | breakpoint_ops->print_it, but in this case, by the time we | |
5276 | call breakpoint_ops->print_it this bp will be deleted | |
5277 | already. So we have no choice but print the information | |
5278 | here. */ | |
468afe6c | 5279 | |
0e454242 | 5280 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5281 | { |
5282 | struct ui_out *uiout = current_uiout; | |
5283 | ||
5284 | if (ui_out_is_mi_like_p (uiout)) | |
5285 | ui_out_field_string | |
5286 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5287 | ui_out_text (uiout, "\nWatchpoint "); | |
5288 | ui_out_field_int (uiout, "wpnum", b->base.number); | |
5289 | ui_out_text (uiout, | |
5290 | " deleted because the program has left the block in\n" | |
5291 | "which its expression is valid.\n"); | |
5292 | } | |
4ce44c66 | 5293 | |
cdac0397 | 5294 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5295 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5296 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5297 | |
5298 | return WP_DELETED; | |
5299 | } | |
5300 | } | |
5301 | ||
18a18393 | 5302 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5303 | breakpoint location BL. This function does not check if we should |
5304 | stop, only if BL explains the stop. */ | |
5305 | ||
18a18393 | 5306 | static int |
6c95b8df | 5307 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5308 | struct address_space *aspace, CORE_ADDR bp_addr, |
5309 | const struct target_waitstatus *ws) | |
18a18393 VP |
5310 | { |
5311 | struct breakpoint *b = bl->owner; | |
5312 | ||
348d480f | 5313 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5314 | gdb_assert (b != NULL); |
5315 | ||
09ac7c10 | 5316 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5317 | } |
5318 | ||
3a5c3e22 PA |
5319 | /* Determine if the watched values have actually changed, and we |
5320 | should stop. If not, set BS->stop to 0. */ | |
5321 | ||
18a18393 VP |
5322 | static void |
5323 | bpstat_check_watchpoint (bpstat bs) | |
5324 | { | |
2bdf28a0 | 5325 | const struct bp_location *bl; |
3a5c3e22 | 5326 | struct watchpoint *b; |
2bdf28a0 JK |
5327 | |
5328 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5329 | bl = bs->bp_location_at; |
2bdf28a0 | 5330 | gdb_assert (bl != NULL); |
3a5c3e22 | 5331 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5332 | gdb_assert (b != NULL); |
18a18393 | 5333 | |
18a18393 | 5334 | { |
18a18393 VP |
5335 | int must_check_value = 0; |
5336 | ||
3a5c3e22 | 5337 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5338 | /* For a software watchpoint, we must always check the |
5339 | watched value. */ | |
5340 | must_check_value = 1; | |
5341 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5342 | /* We have a hardware watchpoint (read, write, or access) | |
5343 | and the target earlier reported an address watched by | |
5344 | this watchpoint. */ | |
5345 | must_check_value = 1; | |
5346 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5347 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5348 | /* We were stopped by a hardware watchpoint, but the target could |
5349 | not report the data address. We must check the watchpoint's | |
5350 | value. Access and read watchpoints are out of luck; without | |
5351 | a data address, we can't figure it out. */ | |
5352 | must_check_value = 1; | |
3a5c3e22 | 5353 | |
18a18393 VP |
5354 | if (must_check_value) |
5355 | { | |
3e43a32a MS |
5356 | char *message |
5357 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5358 | b->base.number); |
18a18393 VP |
5359 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5360 | int e = catch_errors (watchpoint_check, bs, message, | |
5361 | RETURN_MASK_ALL); | |
5362 | do_cleanups (cleanups); | |
5363 | switch (e) | |
5364 | { | |
5365 | case WP_DELETED: | |
5366 | /* We've already printed what needs to be printed. */ | |
5367 | bs->print_it = print_it_done; | |
5368 | /* Stop. */ | |
5369 | break; | |
60e1c644 PA |
5370 | case WP_IGNORE: |
5371 | bs->print_it = print_it_noop; | |
5372 | bs->stop = 0; | |
5373 | break; | |
18a18393 | 5374 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5375 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5376 | { |
85d721b8 PA |
5377 | /* There are two cases to consider here: |
5378 | ||
4a64f543 | 5379 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5380 | In that case, trust the target, and always report |
5381 | the watchpoint hit to the user. Even though | |
5382 | reads don't cause value changes, the value may | |
5383 | have changed since the last time it was read, and | |
5384 | since we're not trapping writes, we will not see | |
5385 | those, and as such we should ignore our notion of | |
5386 | old value. | |
5387 | ||
4a64f543 | 5388 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5389 | reads and writes. There are two ways this may |
5390 | happen: | |
5391 | ||
4a64f543 | 5392 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5393 | reads only, but can break on accesses (reads or |
5394 | writes), such as e.g., x86. We detect this case | |
5395 | at the time we try to insert read watchpoints. | |
5396 | ||
4a64f543 | 5397 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5398 | watchpoints, but, the user set an access or write |
5399 | watchpoint watching the same memory as this read | |
5400 | watchpoint. | |
5401 | ||
5402 | If we're watching memory writes as well as reads, | |
5403 | ignore watchpoint hits when we find that the | |
5404 | value hasn't changed, as reads don't cause | |
5405 | changes. This still gives false positives when | |
5406 | the program writes the same value to memory as | |
5407 | what there was already in memory (we will confuse | |
5408 | it for a read), but it's much better than | |
5409 | nothing. */ | |
5410 | ||
5411 | int other_write_watchpoint = 0; | |
5412 | ||
5413 | if (bl->watchpoint_type == hw_read) | |
5414 | { | |
5415 | struct breakpoint *other_b; | |
5416 | ||
5417 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5418 | if (other_b->type == bp_hardware_watchpoint |
5419 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5420 | { |
3a5c3e22 PA |
5421 | struct watchpoint *other_w = |
5422 | (struct watchpoint *) other_b; | |
5423 | ||
5424 | if (other_w->watchpoint_triggered | |
5425 | == watch_triggered_yes) | |
5426 | { | |
5427 | other_write_watchpoint = 1; | |
5428 | break; | |
5429 | } | |
85d721b8 PA |
5430 | } |
5431 | } | |
5432 | ||
5433 | if (other_write_watchpoint | |
5434 | || bl->watchpoint_type == hw_access) | |
5435 | { | |
5436 | /* We're watching the same memory for writes, | |
5437 | and the value changed since the last time we | |
5438 | updated it, so this trap must be for a write. | |
5439 | Ignore it. */ | |
5440 | bs->print_it = print_it_noop; | |
5441 | bs->stop = 0; | |
5442 | } | |
18a18393 VP |
5443 | } |
5444 | break; | |
5445 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5446 | if (b->base.type == bp_hardware_watchpoint |
5447 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5448 | { |
5449 | /* Don't stop: write watchpoints shouldn't fire if | |
5450 | the value hasn't changed. */ | |
5451 | bs->print_it = print_it_noop; | |
5452 | bs->stop = 0; | |
5453 | } | |
5454 | /* Stop. */ | |
5455 | break; | |
5456 | default: | |
5457 | /* Can't happen. */ | |
5458 | case 0: | |
5459 | /* Error from catch_errors. */ | |
468afe6c | 5460 | { |
0e454242 | 5461 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5462 | { |
5463 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5464 | b->base.number); | |
5465 | } | |
5466 | watchpoint_del_at_next_stop (b); | |
5467 | /* We've already printed what needs to be printed. */ | |
5468 | bs->print_it = print_it_done; | |
5469 | } | |
18a18393 VP |
5470 | break; |
5471 | } | |
5472 | } | |
5473 | else /* must_check_value == 0 */ | |
5474 | { | |
5475 | /* This is a case where some watchpoint(s) triggered, but | |
5476 | not at the address of this watchpoint, or else no | |
5477 | watchpoint triggered after all. So don't print | |
5478 | anything for this watchpoint. */ | |
5479 | bs->print_it = print_it_noop; | |
5480 | bs->stop = 0; | |
5481 | } | |
5482 | } | |
5483 | } | |
5484 | ||
7d4df6a4 DE |
5485 | /* For breakpoints that are currently marked as telling gdb to stop, |
5486 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5487 | of breakpoint referred to by BS. If we should not stop for this |
5488 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5489 | |
18a18393 VP |
5490 | static void |
5491 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5492 | { | |
2bdf28a0 JK |
5493 | const struct bp_location *bl; |
5494 | struct breakpoint *b; | |
7d4df6a4 DE |
5495 | int value_is_zero = 0; |
5496 | struct expression *cond; | |
5497 | ||
5498 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5499 | |
5500 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5501 | bl = bs->bp_location_at; |
2bdf28a0 | 5502 | gdb_assert (bl != NULL); |
f431efe5 | 5503 | b = bs->breakpoint_at; |
2bdf28a0 | 5504 | gdb_assert (b != NULL); |
18a18393 | 5505 | |
b775012e LM |
5506 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5507 | need to do so again since GDB does not know if we stopped due to a | |
5508 | breakpoint or a single step breakpoint. */ | |
5509 | ||
18a18393 | 5510 | if (frame_id_p (b->frame_id) |
edb3359d | 5511 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5512 | { |
7d4df6a4 DE |
5513 | bs->stop = 0; |
5514 | return; | |
5515 | } | |
60e1c644 | 5516 | |
12ab52e9 PA |
5517 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5518 | evaluating the condition if this isn't the specified | |
5519 | thread/task. */ | |
5d5658a1 | 5520 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5521 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5522 | ||
6c1b0f7b DE |
5523 | { |
5524 | bs->stop = 0; | |
5525 | return; | |
5526 | } | |
5527 | ||
6dddc817 DE |
5528 | /* Evaluate extension language breakpoints that have a "stop" method |
5529 | implemented. */ | |
5530 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5531 | |
7d4df6a4 DE |
5532 | if (is_watchpoint (b)) |
5533 | { | |
5534 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5535 | |
7d4df6a4 DE |
5536 | cond = w->cond_exp; |
5537 | } | |
5538 | else | |
5539 | cond = bl->cond; | |
60e1c644 | 5540 | |
7d4df6a4 DE |
5541 | if (cond && b->disposition != disp_del_at_next_stop) |
5542 | { | |
5543 | int within_current_scope = 1; | |
5544 | struct watchpoint * w; | |
60e1c644 | 5545 | |
7d4df6a4 DE |
5546 | /* We use value_mark and value_free_to_mark because it could |
5547 | be a long time before we return to the command level and | |
5548 | call free_all_values. We can't call free_all_values | |
5549 | because we might be in the middle of evaluating a | |
5550 | function call. */ | |
5551 | struct value *mark = value_mark (); | |
5552 | ||
5553 | if (is_watchpoint (b)) | |
5554 | w = (struct watchpoint *) b; | |
5555 | else | |
5556 | w = NULL; | |
5557 | ||
5558 | /* Need to select the frame, with all that implies so that | |
5559 | the conditions will have the right context. Because we | |
5560 | use the frame, we will not see an inlined function's | |
5561 | variables when we arrive at a breakpoint at the start | |
5562 | of the inlined function; the current frame will be the | |
5563 | call site. */ | |
5564 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5565 | select_frame (get_current_frame ()); | |
5566 | else | |
18a18393 | 5567 | { |
7d4df6a4 DE |
5568 | struct frame_info *frame; |
5569 | ||
5570 | /* For local watchpoint expressions, which particular | |
5571 | instance of a local is being watched matters, so we | |
5572 | keep track of the frame to evaluate the expression | |
5573 | in. To evaluate the condition however, it doesn't | |
5574 | really matter which instantiation of the function | |
5575 | where the condition makes sense triggers the | |
5576 | watchpoint. This allows an expression like "watch | |
5577 | global if q > 10" set in `func', catch writes to | |
5578 | global on all threads that call `func', or catch | |
5579 | writes on all recursive calls of `func' by a single | |
5580 | thread. We simply always evaluate the condition in | |
5581 | the innermost frame that's executing where it makes | |
5582 | sense to evaluate the condition. It seems | |
5583 | intuitive. */ | |
5584 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5585 | if (frame != NULL) | |
5586 | select_frame (frame); | |
5587 | else | |
5588 | within_current_scope = 0; | |
18a18393 | 5589 | } |
7d4df6a4 DE |
5590 | if (within_current_scope) |
5591 | value_is_zero | |
5592 | = catch_errors (breakpoint_cond_eval, cond, | |
5593 | "Error in testing breakpoint condition:\n", | |
5594 | RETURN_MASK_ALL); | |
5595 | else | |
18a18393 | 5596 | { |
7d4df6a4 DE |
5597 | warning (_("Watchpoint condition cannot be tested " |
5598 | "in the current scope")); | |
5599 | /* If we failed to set the right context for this | |
5600 | watchpoint, unconditionally report it. */ | |
5601 | value_is_zero = 0; | |
18a18393 | 5602 | } |
7d4df6a4 DE |
5603 | /* FIXME-someday, should give breakpoint #. */ |
5604 | value_free_to_mark (mark); | |
18a18393 | 5605 | } |
7d4df6a4 DE |
5606 | |
5607 | if (cond && value_is_zero) | |
5608 | { | |
5609 | bs->stop = 0; | |
5610 | } | |
7d4df6a4 DE |
5611 | else if (b->ignore_count > 0) |
5612 | { | |
5613 | b->ignore_count--; | |
5614 | bs->stop = 0; | |
5615 | /* Increase the hit count even though we don't stop. */ | |
5616 | ++(b->hit_count); | |
5617 | observer_notify_breakpoint_modified (b); | |
5618 | } | |
18a18393 VP |
5619 | } |
5620 | ||
1cf4d951 PA |
5621 | /* Returns true if we need to track moribund locations of LOC's type |
5622 | on the current target. */ | |
5623 | ||
5624 | static int | |
5625 | need_moribund_for_location_type (struct bp_location *loc) | |
5626 | { | |
5627 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5628 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5629 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5630 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5631 | } | |
5632 | ||
18a18393 | 5633 | |
9709f61c | 5634 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5635 | BP_ADDR in thread PTID. |
c906108c | 5636 | |
d983da9c | 5637 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5638 | don't understand this stop. Result is a chain of bpstat's such |
5639 | that: | |
c906108c | 5640 | |
c5aa993b | 5641 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5642 | |
c5aa993b | 5643 | if we understand why we stopped, the result is not null. |
c906108c | 5644 | |
c5aa993b JM |
5645 | Each element of the chain refers to a particular breakpoint or |
5646 | watchpoint at which we have stopped. (We may have stopped for | |
5647 | several reasons concurrently.) | |
c906108c | 5648 | |
c5aa993b JM |
5649 | Each element of the chain has valid next, breakpoint_at, |
5650 | commands, FIXME??? fields. */ | |
c906108c SS |
5651 | |
5652 | bpstat | |
6c95b8df | 5653 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5654 | CORE_ADDR bp_addr, ptid_t ptid, |
5655 | const struct target_waitstatus *ws) | |
c906108c | 5656 | { |
0d381245 | 5657 | struct breakpoint *b = NULL; |
afe38095 | 5658 | struct bp_location *bl; |
20874c92 | 5659 | struct bp_location *loc; |
5760d0ab JK |
5660 | /* First item of allocated bpstat's. */ |
5661 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5662 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5663 | bpstat bs; |
20874c92 | 5664 | int ix; |
429374b8 | 5665 | int need_remove_insert; |
f431efe5 | 5666 | int removed_any; |
c906108c | 5667 | |
f431efe5 PA |
5668 | /* First, build the bpstat chain with locations that explain a |
5669 | target stop, while being careful to not set the target running, | |
5670 | as that may invalidate locations (in particular watchpoint | |
5671 | locations are recreated). Resuming will happen here with | |
5672 | breakpoint conditions or watchpoint expressions that include | |
5673 | inferior function calls. */ | |
c5aa993b | 5674 | |
429374b8 JK |
5675 | ALL_BREAKPOINTS (b) |
5676 | { | |
1a853c52 | 5677 | if (!breakpoint_enabled (b)) |
429374b8 | 5678 | continue; |
a5606eee | 5679 | |
429374b8 JK |
5680 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5681 | { | |
4a64f543 MS |
5682 | /* For hardware watchpoints, we look only at the first |
5683 | location. The watchpoint_check function will work on the | |
5684 | entire expression, not the individual locations. For | |
5685 | read watchpoints, the watchpoints_triggered function has | |
5686 | checked all locations already. */ | |
429374b8 JK |
5687 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5688 | break; | |
18a18393 | 5689 | |
f6592439 | 5690 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5691 | continue; |
c5aa993b | 5692 | |
09ac7c10 | 5693 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5694 | continue; |
c5aa993b | 5695 | |
4a64f543 MS |
5696 | /* Come here if it's a watchpoint, or if the break address |
5697 | matches. */ | |
c5aa993b | 5698 | |
4a64f543 MS |
5699 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5700 | explain stop. */ | |
c5aa993b | 5701 | |
f431efe5 PA |
5702 | /* Assume we stop. Should we find a watchpoint that is not |
5703 | actually triggered, or if the condition of the breakpoint | |
5704 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5705 | bs->stop = 1; |
5706 | bs->print = 1; | |
d983da9c | 5707 | |
f431efe5 PA |
5708 | /* If this is a scope breakpoint, mark the associated |
5709 | watchpoint as triggered so that we will handle the | |
5710 | out-of-scope event. We'll get to the watchpoint next | |
5711 | iteration. */ | |
d0fb5eae | 5712 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5713 | { |
5714 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5715 | ||
5716 | w->watchpoint_triggered = watch_triggered_yes; | |
5717 | } | |
f431efe5 PA |
5718 | } |
5719 | } | |
5720 | ||
7c16b83e | 5721 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5722 | if (!target_supports_stopped_by_sw_breakpoint () |
5723 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5724 | { |
1cf4d951 | 5725 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5726 | { |
1cf4d951 PA |
5727 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5728 | && need_moribund_for_location_type (loc)) | |
5729 | { | |
5730 | bs = bpstat_alloc (loc, &bs_link); | |
5731 | /* For hits of moribund locations, we should just proceed. */ | |
5732 | bs->stop = 0; | |
5733 | bs->print = 0; | |
5734 | bs->print_it = print_it_noop; | |
5735 | } | |
f431efe5 PA |
5736 | } |
5737 | } | |
5738 | ||
edcc5120 TT |
5739 | /* A bit of special processing for shlib breakpoints. We need to |
5740 | process solib loading here, so that the lists of loaded and | |
5741 | unloaded libraries are correct before we handle "catch load" and | |
5742 | "catch unload". */ | |
5743 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5744 | { | |
5d268276 | 5745 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5746 | { |
5747 | handle_solib_event (); | |
5748 | break; | |
5749 | } | |
5750 | } | |
5751 | ||
f431efe5 PA |
5752 | /* Now go through the locations that caused the target to stop, and |
5753 | check whether we're interested in reporting this stop to higher | |
5754 | layers, or whether we should resume the target transparently. */ | |
5755 | ||
5756 | removed_any = 0; | |
5757 | ||
5760d0ab | 5758 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5759 | { |
5760 | if (!bs->stop) | |
5761 | continue; | |
5762 | ||
f431efe5 | 5763 | b = bs->breakpoint_at; |
348d480f PA |
5764 | b->ops->check_status (bs); |
5765 | if (bs->stop) | |
28010a5d | 5766 | { |
348d480f | 5767 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5768 | |
429374b8 JK |
5769 | if (bs->stop) |
5770 | { | |
5771 | ++(b->hit_count); | |
8d3788bd | 5772 | observer_notify_breakpoint_modified (b); |
c906108c | 5773 | |
4a64f543 | 5774 | /* We will stop here. */ |
429374b8 JK |
5775 | if (b->disposition == disp_disable) |
5776 | { | |
816338b5 | 5777 | --(b->enable_count); |
1a853c52 | 5778 | if (b->enable_count <= 0) |
429374b8 | 5779 | b->enable_state = bp_disabled; |
f431efe5 | 5780 | removed_any = 1; |
429374b8 JK |
5781 | } |
5782 | if (b->silent) | |
5783 | bs->print = 0; | |
5784 | bs->commands = b->commands; | |
9add0f1b | 5785 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5786 | if (command_line_is_silent (bs->commands |
5787 | ? bs->commands->commands : NULL)) | |
5788 | bs->print = 0; | |
9d6e6e84 HZ |
5789 | |
5790 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5791 | } |
5792 | ||
348d480f | 5793 | } |
a9b3a50f PA |
5794 | |
5795 | /* Print nothing for this entry if we don't stop or don't | |
5796 | print. */ | |
5797 | if (!bs->stop || !bs->print) | |
5798 | bs->print_it = print_it_noop; | |
429374b8 | 5799 | } |
876fa593 | 5800 | |
d983da9c DJ |
5801 | /* If we aren't stopping, the value of some hardware watchpoint may |
5802 | not have changed, but the intermediate memory locations we are | |
5803 | watching may have. Don't bother if we're stopping; this will get | |
5804 | done later. */ | |
d832cb68 | 5805 | need_remove_insert = 0; |
5760d0ab JK |
5806 | if (! bpstat_causes_stop (bs_head)) |
5807 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5808 | if (!bs->stop |
f431efe5 PA |
5809 | && bs->breakpoint_at |
5810 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5811 | { |
3a5c3e22 PA |
5812 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5813 | ||
5814 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5815 | need_remove_insert = 1; |
d983da9c DJ |
5816 | } |
5817 | ||
d832cb68 | 5818 | if (need_remove_insert) |
44702360 | 5819 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5820 | else if (removed_any) |
44702360 | 5821 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5822 | |
5760d0ab | 5823 | return bs_head; |
c906108c | 5824 | } |
628fe4e4 JK |
5825 | |
5826 | static void | |
5827 | handle_jit_event (void) | |
5828 | { | |
5829 | struct frame_info *frame; | |
5830 | struct gdbarch *gdbarch; | |
5831 | ||
243a9253 PA |
5832 | if (debug_infrun) |
5833 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5834 | ||
628fe4e4 JK |
5835 | /* Switch terminal for any messages produced by |
5836 | breakpoint_re_set. */ | |
5837 | target_terminal_ours_for_output (); | |
5838 | ||
5839 | frame = get_current_frame (); | |
5840 | gdbarch = get_frame_arch (frame); | |
5841 | ||
5842 | jit_event_handler (gdbarch); | |
5843 | ||
5844 | target_terminal_inferior (); | |
5845 | } | |
5846 | ||
5847 | /* Prepare WHAT final decision for infrun. */ | |
5848 | ||
5849 | /* Decide what infrun needs to do with this bpstat. */ | |
5850 | ||
c906108c | 5851 | struct bpstat_what |
0e30163f | 5852 | bpstat_what (bpstat bs_head) |
c906108c | 5853 | { |
c906108c | 5854 | struct bpstat_what retval; |
0e30163f | 5855 | bpstat bs; |
c906108c | 5856 | |
628fe4e4 | 5857 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5858 | retval.call_dummy = STOP_NONE; |
186c406b | 5859 | retval.is_longjmp = 0; |
628fe4e4 | 5860 | |
0e30163f | 5861 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5862 | { |
628fe4e4 JK |
5863 | /* Extract this BS's action. After processing each BS, we check |
5864 | if its action overrides all we've seem so far. */ | |
5865 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5866 | enum bptype bptype; | |
5867 | ||
c906108c | 5868 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5869 | { |
5870 | /* I suspect this can happen if it was a momentary | |
5871 | breakpoint which has since been deleted. */ | |
5872 | bptype = bp_none; | |
5873 | } | |
20874c92 | 5874 | else |
f431efe5 | 5875 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5876 | |
5877 | switch (bptype) | |
c906108c SS |
5878 | { |
5879 | case bp_none: | |
628fe4e4 | 5880 | break; |
c906108c SS |
5881 | case bp_breakpoint: |
5882 | case bp_hardware_breakpoint: | |
7c16b83e | 5883 | case bp_single_step: |
c906108c SS |
5884 | case bp_until: |
5885 | case bp_finish: | |
a9b3a50f | 5886 | case bp_shlib_event: |
c906108c SS |
5887 | if (bs->stop) |
5888 | { | |
5889 | if (bs->print) | |
628fe4e4 | 5890 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5891 | else |
628fe4e4 | 5892 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5893 | } |
5894 | else | |
628fe4e4 | 5895 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5896 | break; |
5897 | case bp_watchpoint: | |
5898 | case bp_hardware_watchpoint: | |
5899 | case bp_read_watchpoint: | |
5900 | case bp_access_watchpoint: | |
5901 | if (bs->stop) | |
5902 | { | |
5903 | if (bs->print) | |
628fe4e4 | 5904 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5905 | else |
628fe4e4 | 5906 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5907 | } |
5908 | else | |
628fe4e4 JK |
5909 | { |
5910 | /* There was a watchpoint, but we're not stopping. | |
5911 | This requires no further action. */ | |
5912 | } | |
c906108c SS |
5913 | break; |
5914 | case bp_longjmp: | |
e2e4d78b | 5915 | case bp_longjmp_call_dummy: |
186c406b | 5916 | case bp_exception: |
0a39bb32 PA |
5917 | if (bs->stop) |
5918 | { | |
5919 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5920 | retval.is_longjmp = bptype != bp_exception; | |
5921 | } | |
5922 | else | |
5923 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5924 | break; |
5925 | case bp_longjmp_resume: | |
186c406b | 5926 | case bp_exception_resume: |
0a39bb32 PA |
5927 | if (bs->stop) |
5928 | { | |
5929 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5930 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5931 | } | |
5932 | else | |
5933 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5934 | break; |
5935 | case bp_step_resume: | |
5936 | if (bs->stop) | |
628fe4e4 JK |
5937 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5938 | else | |
c906108c | 5939 | { |
628fe4e4 JK |
5940 | /* It is for the wrong frame. */ |
5941 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5942 | } |
c906108c | 5943 | break; |
2c03e5be PA |
5944 | case bp_hp_step_resume: |
5945 | if (bs->stop) | |
5946 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5947 | else | |
5948 | { | |
5949 | /* It is for the wrong frame. */ | |
5950 | this_action = BPSTAT_WHAT_SINGLE; | |
5951 | } | |
5952 | break; | |
c906108c | 5953 | case bp_watchpoint_scope: |
c4093a6a | 5954 | case bp_thread_event: |
1900040c | 5955 | case bp_overlay_event: |
0fd8e87f | 5956 | case bp_longjmp_master: |
aa7d318d | 5957 | case bp_std_terminate_master: |
186c406b | 5958 | case bp_exception_master: |
628fe4e4 | 5959 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5960 | break; |
ce78b96d | 5961 | case bp_catchpoint: |
c5aa993b JM |
5962 | if (bs->stop) |
5963 | { | |
5964 | if (bs->print) | |
628fe4e4 | 5965 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5966 | else |
628fe4e4 | 5967 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5968 | } |
5969 | else | |
628fe4e4 JK |
5970 | { |
5971 | /* There was a catchpoint, but we're not stopping. | |
5972 | This requires no further action. */ | |
5973 | } | |
5974 | break; | |
628fe4e4 | 5975 | case bp_jit_event: |
628fe4e4 | 5976 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5977 | break; |
c906108c | 5978 | case bp_call_dummy: |
53a5351d JM |
5979 | /* Make sure the action is stop (silent or noisy), |
5980 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5981 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5982 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5983 | break; |
5984 | case bp_std_terminate: | |
5985 | /* Make sure the action is stop (silent or noisy), | |
5986 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5987 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5988 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5989 | break; |
1042e4c0 | 5990 | case bp_tracepoint: |
7a697b8d | 5991 | case bp_fast_tracepoint: |
0fb4aa4b | 5992 | case bp_static_tracepoint: |
1042e4c0 SS |
5993 | /* Tracepoint hits should not be reported back to GDB, and |
5994 | if one got through somehow, it should have been filtered | |
5995 | out already. */ | |
5996 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5997 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5998 | break; |
5999 | case bp_gnu_ifunc_resolver: | |
6000 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
6001 | this_action = BPSTAT_WHAT_SINGLE; | |
6002 | break; | |
6003 | case bp_gnu_ifunc_resolver_return: | |
6004 | /* The breakpoint will be removed, execution will restart from the | |
6005 | PC of the former breakpoint. */ | |
6006 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
6007 | break; | |
e7e0cddf SS |
6008 | |
6009 | case bp_dprintf: | |
a11cfd87 HZ |
6010 | if (bs->stop) |
6011 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
6012 | else | |
6013 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
6014 | break; |
6015 | ||
628fe4e4 JK |
6016 | default: |
6017 | internal_error (__FILE__, __LINE__, | |
6018 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 6019 | } |
628fe4e4 | 6020 | |
325fac50 | 6021 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 6022 | } |
628fe4e4 | 6023 | |
243a9253 PA |
6024 | return retval; |
6025 | } | |
628fe4e4 | 6026 | |
243a9253 PA |
6027 | void |
6028 | bpstat_run_callbacks (bpstat bs_head) | |
6029 | { | |
6030 | bpstat bs; | |
628fe4e4 | 6031 | |
0e30163f JK |
6032 | for (bs = bs_head; bs != NULL; bs = bs->next) |
6033 | { | |
6034 | struct breakpoint *b = bs->breakpoint_at; | |
6035 | ||
6036 | if (b == NULL) | |
6037 | continue; | |
6038 | switch (b->type) | |
6039 | { | |
243a9253 PA |
6040 | case bp_jit_event: |
6041 | handle_jit_event (); | |
6042 | break; | |
0e30163f JK |
6043 | case bp_gnu_ifunc_resolver: |
6044 | gnu_ifunc_resolver_stop (b); | |
6045 | break; | |
6046 | case bp_gnu_ifunc_resolver_return: | |
6047 | gnu_ifunc_resolver_return_stop (b); | |
6048 | break; | |
6049 | } | |
6050 | } | |
c906108c SS |
6051 | } |
6052 | ||
6053 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6054 | without hardware support). This isn't related to a specific bpstat, | |
6055 | just to things like whether watchpoints are set. */ | |
6056 | ||
c5aa993b | 6057 | int |
fba45db2 | 6058 | bpstat_should_step (void) |
c906108c SS |
6059 | { |
6060 | struct breakpoint *b; | |
cc59ec59 | 6061 | |
c906108c | 6062 | ALL_BREAKPOINTS (b) |
717a8278 | 6063 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6064 | return 1; |
c906108c SS |
6065 | return 0; |
6066 | } | |
6067 | ||
67822962 PA |
6068 | int |
6069 | bpstat_causes_stop (bpstat bs) | |
6070 | { | |
6071 | for (; bs != NULL; bs = bs->next) | |
6072 | if (bs->stop) | |
6073 | return 1; | |
6074 | ||
6075 | return 0; | |
6076 | } | |
6077 | ||
c906108c | 6078 | \f |
c5aa993b | 6079 | |
170b53b2 UW |
6080 | /* Compute a string of spaces suitable to indent the next line |
6081 | so it starts at the position corresponding to the table column | |
6082 | named COL_NAME in the currently active table of UIOUT. */ | |
6083 | ||
6084 | static char * | |
6085 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6086 | { | |
6087 | static char wrap_indent[80]; | |
6088 | int i, total_width, width, align; | |
6089 | char *text; | |
6090 | ||
6091 | total_width = 0; | |
6092 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
6093 | { | |
6094 | if (strcmp (text, col_name) == 0) | |
6095 | { | |
6096 | gdb_assert (total_width < sizeof wrap_indent); | |
6097 | memset (wrap_indent, ' ', total_width); | |
6098 | wrap_indent[total_width] = 0; | |
6099 | ||
6100 | return wrap_indent; | |
6101 | } | |
6102 | ||
6103 | total_width += width + 1; | |
6104 | } | |
6105 | ||
6106 | return NULL; | |
6107 | } | |
6108 | ||
b775012e LM |
6109 | /* Determine if the locations of this breakpoint will have their conditions |
6110 | evaluated by the target, host or a mix of both. Returns the following: | |
6111 | ||
6112 | "host": Host evals condition. | |
6113 | "host or target": Host or Target evals condition. | |
6114 | "target": Target evals condition. | |
6115 | */ | |
6116 | ||
6117 | static const char * | |
6118 | bp_condition_evaluator (struct breakpoint *b) | |
6119 | { | |
6120 | struct bp_location *bl; | |
6121 | char host_evals = 0; | |
6122 | char target_evals = 0; | |
6123 | ||
6124 | if (!b) | |
6125 | return NULL; | |
6126 | ||
6127 | if (!is_breakpoint (b)) | |
6128 | return NULL; | |
6129 | ||
6130 | if (gdb_evaluates_breakpoint_condition_p () | |
6131 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6132 | return condition_evaluation_host; | |
6133 | ||
6134 | for (bl = b->loc; bl; bl = bl->next) | |
6135 | { | |
6136 | if (bl->cond_bytecode) | |
6137 | target_evals++; | |
6138 | else | |
6139 | host_evals++; | |
6140 | } | |
6141 | ||
6142 | if (host_evals && target_evals) | |
6143 | return condition_evaluation_both; | |
6144 | else if (target_evals) | |
6145 | return condition_evaluation_target; | |
6146 | else | |
6147 | return condition_evaluation_host; | |
6148 | } | |
6149 | ||
6150 | /* Determine the breakpoint location's condition evaluator. This is | |
6151 | similar to bp_condition_evaluator, but for locations. */ | |
6152 | ||
6153 | static const char * | |
6154 | bp_location_condition_evaluator (struct bp_location *bl) | |
6155 | { | |
6156 | if (bl && !is_breakpoint (bl->owner)) | |
6157 | return NULL; | |
6158 | ||
6159 | if (gdb_evaluates_breakpoint_condition_p () | |
6160 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6161 | return condition_evaluation_host; | |
6162 | ||
6163 | if (bl && bl->cond_bytecode) | |
6164 | return condition_evaluation_target; | |
6165 | else | |
6166 | return condition_evaluation_host; | |
6167 | } | |
6168 | ||
859825b8 JK |
6169 | /* Print the LOC location out of the list of B->LOC locations. */ |
6170 | ||
170b53b2 UW |
6171 | static void |
6172 | print_breakpoint_location (struct breakpoint *b, | |
6173 | struct bp_location *loc) | |
0d381245 | 6174 | { |
79a45e25 | 6175 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6176 | struct cleanup *old_chain = save_current_program_space (); |
6177 | ||
859825b8 JK |
6178 | if (loc != NULL && loc->shlib_disabled) |
6179 | loc = NULL; | |
6180 | ||
6c95b8df PA |
6181 | if (loc != NULL) |
6182 | set_current_program_space (loc->pspace); | |
6183 | ||
56435ebe | 6184 | if (b->display_canonical) |
f00aae0f KS |
6185 | ui_out_field_string (uiout, "what", |
6186 | event_location_to_string (b->location)); | |
2f202fde | 6187 | else if (loc && loc->symtab) |
0d381245 VP |
6188 | { |
6189 | struct symbol *sym | |
6190 | = find_pc_sect_function (loc->address, loc->section); | |
6191 | if (sym) | |
6192 | { | |
6193 | ui_out_text (uiout, "in "); | |
6194 | ui_out_field_string (uiout, "func", | |
6195 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6196 | ui_out_text (uiout, " "); |
6197 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6198 | ui_out_text (uiout, "at "); | |
0d381245 | 6199 | } |
05cba821 JK |
6200 | ui_out_field_string (uiout, "file", |
6201 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6202 | ui_out_text (uiout, ":"); |
05cba821 | 6203 | |
0d381245 | 6204 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6205 | ui_out_field_string (uiout, "fullname", |
6206 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6207 | |
f8eba3c6 | 6208 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6209 | } |
859825b8 | 6210 | else if (loc) |
0d381245 | 6211 | { |
f99d8bf4 PA |
6212 | struct ui_file *stb = mem_fileopen (); |
6213 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6214 | |
f99d8bf4 | 6215 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6216 | demangle, ""); |
0d381245 | 6217 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6218 | |
6219 | do_cleanups (stb_chain); | |
0d381245 | 6220 | } |
859825b8 | 6221 | else |
f00aae0f KS |
6222 | { |
6223 | ui_out_field_string (uiout, "pending", | |
6224 | event_location_to_string (b->location)); | |
6225 | /* If extra_string is available, it could be holding a condition | |
6226 | or dprintf arguments. In either case, make sure it is printed, | |
6227 | too, but only for non-MI streams. */ | |
6228 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) | |
6229 | { | |
6230 | if (b->type == bp_dprintf) | |
6231 | ui_out_text (uiout, ","); | |
6232 | else | |
6233 | ui_out_text (uiout, " "); | |
6234 | ui_out_text (uiout, b->extra_string); | |
6235 | } | |
6236 | } | |
6c95b8df | 6237 | |
b775012e LM |
6238 | if (loc && is_breakpoint (b) |
6239 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6240 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6241 | { | |
6242 | ui_out_text (uiout, " ("); | |
6243 | ui_out_field_string (uiout, "evaluated-by", | |
6244 | bp_location_condition_evaluator (loc)); | |
6245 | ui_out_text (uiout, ")"); | |
6246 | } | |
6247 | ||
6c95b8df | 6248 | do_cleanups (old_chain); |
0d381245 VP |
6249 | } |
6250 | ||
269b11a2 PA |
6251 | static const char * |
6252 | bptype_string (enum bptype type) | |
c906108c | 6253 | { |
c4093a6a JM |
6254 | struct ep_type_description |
6255 | { | |
6256 | enum bptype type; | |
6257 | char *description; | |
6258 | }; | |
6259 | static struct ep_type_description bptypes[] = | |
c906108c | 6260 | { |
c5aa993b JM |
6261 | {bp_none, "?deleted?"}, |
6262 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6263 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6264 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6265 | {bp_until, "until"}, |
6266 | {bp_finish, "finish"}, | |
6267 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6268 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6269 | {bp_read_watchpoint, "read watchpoint"}, |
6270 | {bp_access_watchpoint, "acc watchpoint"}, | |
6271 | {bp_longjmp, "longjmp"}, | |
6272 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6273 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6274 | {bp_exception, "exception"}, |
6275 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6276 | {bp_step_resume, "step resume"}, |
2c03e5be | 6277 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6278 | {bp_watchpoint_scope, "watchpoint scope"}, |
6279 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6280 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6281 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6282 | {bp_thread_event, "thread events"}, |
1900040c | 6283 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6284 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6285 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6286 | {bp_exception_master, "exception master"}, |
ce78b96d | 6287 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6288 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6289 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6290 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6291 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6292 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6293 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6294 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6295 | }; |
269b11a2 PA |
6296 | |
6297 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6298 | || ((int) type != bptypes[(int) type].type)) | |
6299 | internal_error (__FILE__, __LINE__, | |
6300 | _("bptypes table does not describe type #%d."), | |
6301 | (int) type); | |
6302 | ||
6303 | return bptypes[(int) type].description; | |
6304 | } | |
6305 | ||
998580f1 MK |
6306 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6307 | For CLI, prefix the list with the string 'inf'. */ | |
6308 | ||
6309 | static void | |
6310 | output_thread_groups (struct ui_out *uiout, | |
6311 | const char *field_name, | |
6312 | VEC(int) *inf_num, | |
6313 | int mi_only) | |
6314 | { | |
752eb8b4 | 6315 | struct cleanup *back_to; |
998580f1 MK |
6316 | int is_mi = ui_out_is_mi_like_p (uiout); |
6317 | int inf; | |
6318 | int i; | |
6319 | ||
6320 | /* For backward compatibility, don't display inferiors in CLI unless | |
6321 | there are several. Always display them for MI. */ | |
6322 | if (!is_mi && mi_only) | |
6323 | return; | |
6324 | ||
752eb8b4 TT |
6325 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6326 | ||
998580f1 MK |
6327 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6328 | { | |
6329 | if (is_mi) | |
6330 | { | |
6331 | char mi_group[10]; | |
6332 | ||
6333 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6334 | ui_out_field_string (uiout, NULL, mi_group); | |
6335 | } | |
6336 | else | |
6337 | { | |
6338 | if (i == 0) | |
6339 | ui_out_text (uiout, " inf "); | |
6340 | else | |
6341 | ui_out_text (uiout, ", "); | |
6342 | ||
6343 | ui_out_text (uiout, plongest (inf)); | |
6344 | } | |
6345 | } | |
6346 | ||
6347 | do_cleanups (back_to); | |
6348 | } | |
6349 | ||
269b11a2 PA |
6350 | /* Print B to gdb_stdout. */ |
6351 | ||
6352 | static void | |
6353 | print_one_breakpoint_location (struct breakpoint *b, | |
6354 | struct bp_location *loc, | |
6355 | int loc_number, | |
6356 | struct bp_location **last_loc, | |
269b11a2 PA |
6357 | int allflag) |
6358 | { | |
6359 | struct command_line *l; | |
c2c6d25f | 6360 | static char bpenables[] = "nynny"; |
c906108c | 6361 | |
79a45e25 | 6362 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6363 | int header_of_multiple = 0; |
6364 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6365 | struct value_print_options opts; |
6366 | ||
6367 | get_user_print_options (&opts); | |
0d381245 VP |
6368 | |
6369 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6370 | /* See comment in print_one_breakpoint concerning treatment of |
6371 | breakpoints with single disabled location. */ | |
0d381245 VP |
6372 | if (loc == NULL |
6373 | && (b->loc != NULL | |
6374 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6375 | header_of_multiple = 1; | |
6376 | if (loc == NULL) | |
6377 | loc = b->loc; | |
6378 | ||
c4093a6a JM |
6379 | annotate_record (); |
6380 | ||
6381 | /* 1 */ | |
6382 | annotate_field (0); | |
0d381245 VP |
6383 | if (part_of_multiple) |
6384 | { | |
6385 | char *formatted; | |
0c6773c1 | 6386 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6387 | ui_out_field_string (uiout, "number", formatted); |
6388 | xfree (formatted); | |
6389 | } | |
6390 | else | |
6391 | { | |
6392 | ui_out_field_int (uiout, "number", b->number); | |
6393 | } | |
c4093a6a JM |
6394 | |
6395 | /* 2 */ | |
6396 | annotate_field (1); | |
0d381245 VP |
6397 | if (part_of_multiple) |
6398 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6399 | else |
6400 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6401 | |
6402 | /* 3 */ | |
6403 | annotate_field (2); | |
0d381245 VP |
6404 | if (part_of_multiple) |
6405 | ui_out_field_skip (uiout, "disp"); | |
6406 | else | |
2cec12e5 | 6407 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6408 | |
c4093a6a JM |
6409 | |
6410 | /* 4 */ | |
6411 | annotate_field (3); | |
0d381245 | 6412 | if (part_of_multiple) |
54e52265 | 6413 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6414 | else |
4a64f543 MS |
6415 | ui_out_field_fmt (uiout, "enabled", "%c", |
6416 | bpenables[(int) b->enable_state]); | |
54e52265 | 6417 | ui_out_spaces (uiout, 2); |
0d381245 | 6418 | |
c4093a6a JM |
6419 | |
6420 | /* 5 and 6 */ | |
3086aeae | 6421 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6422 | { |
4a64f543 MS |
6423 | /* Although the print_one can possibly print all locations, |
6424 | calling it here is not likely to get any nice result. So, | |
6425 | make sure there's just one location. */ | |
0d381245 | 6426 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6427 | b->ops->print_one (b, last_loc); |
0d381245 | 6428 | } |
3086aeae DJ |
6429 | else |
6430 | switch (b->type) | |
6431 | { | |
6432 | case bp_none: | |
6433 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6434 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6435 | break; |
c906108c | 6436 | |
3086aeae DJ |
6437 | case bp_watchpoint: |
6438 | case bp_hardware_watchpoint: | |
6439 | case bp_read_watchpoint: | |
6440 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6441 | { |
6442 | struct watchpoint *w = (struct watchpoint *) b; | |
6443 | ||
6444 | /* Field 4, the address, is omitted (which makes the columns | |
6445 | not line up too nicely with the headers, but the effect | |
6446 | is relatively readable). */ | |
6447 | if (opts.addressprint) | |
6448 | ui_out_field_skip (uiout, "addr"); | |
6449 | annotate_field (5); | |
6450 | ui_out_field_string (uiout, "what", w->exp_string); | |
6451 | } | |
3086aeae DJ |
6452 | break; |
6453 | ||
3086aeae DJ |
6454 | case bp_breakpoint: |
6455 | case bp_hardware_breakpoint: | |
7c16b83e | 6456 | case bp_single_step: |
3086aeae DJ |
6457 | case bp_until: |
6458 | case bp_finish: | |
6459 | case bp_longjmp: | |
6460 | case bp_longjmp_resume: | |
e2e4d78b | 6461 | case bp_longjmp_call_dummy: |
186c406b TT |
6462 | case bp_exception: |
6463 | case bp_exception_resume: | |
3086aeae | 6464 | case bp_step_resume: |
2c03e5be | 6465 | case bp_hp_step_resume: |
3086aeae DJ |
6466 | case bp_watchpoint_scope: |
6467 | case bp_call_dummy: | |
aa7d318d | 6468 | case bp_std_terminate: |
3086aeae DJ |
6469 | case bp_shlib_event: |
6470 | case bp_thread_event: | |
6471 | case bp_overlay_event: | |
0fd8e87f | 6472 | case bp_longjmp_master: |
aa7d318d | 6473 | case bp_std_terminate_master: |
186c406b | 6474 | case bp_exception_master: |
1042e4c0 | 6475 | case bp_tracepoint: |
7a697b8d | 6476 | case bp_fast_tracepoint: |
0fb4aa4b | 6477 | case bp_static_tracepoint: |
e7e0cddf | 6478 | case bp_dprintf: |
4efc6507 | 6479 | case bp_jit_event: |
0e30163f JK |
6480 | case bp_gnu_ifunc_resolver: |
6481 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6482 | if (opts.addressprint) |
3086aeae DJ |
6483 | { |
6484 | annotate_field (4); | |
54e52265 | 6485 | if (header_of_multiple) |
0d381245 | 6486 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6487 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6488 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6489 | else |
5af949e3 UW |
6490 | ui_out_field_core_addr (uiout, "addr", |
6491 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6492 | } |
6493 | annotate_field (5); | |
0d381245 | 6494 | if (!header_of_multiple) |
170b53b2 | 6495 | print_breakpoint_location (b, loc); |
0d381245 | 6496 | if (b->loc) |
a6d9a66e | 6497 | *last_loc = b->loc; |
3086aeae DJ |
6498 | break; |
6499 | } | |
c906108c | 6500 | |
6c95b8df | 6501 | |
998580f1 | 6502 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6503 | { |
6504 | struct inferior *inf; | |
998580f1 MK |
6505 | VEC(int) *inf_num = NULL; |
6506 | int mi_only = 1; | |
6c95b8df | 6507 | |
998580f1 | 6508 | ALL_INFERIORS (inf) |
6c95b8df PA |
6509 | { |
6510 | if (inf->pspace == loc->pspace) | |
998580f1 | 6511 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6512 | } |
998580f1 MK |
6513 | |
6514 | /* For backward compatibility, don't display inferiors in CLI unless | |
6515 | there are several. Always display for MI. */ | |
6516 | if (allflag | |
6517 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6518 | && (number_of_program_spaces () > 1 | |
6519 | || number_of_inferiors () > 1) | |
6520 | /* LOC is for existing B, it cannot be in | |
6521 | moribund_locations and thus having NULL OWNER. */ | |
6522 | && loc->owner->type != bp_catchpoint)) | |
6523 | mi_only = 0; | |
6524 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6525 | VEC_free (int, inf_num); | |
6c95b8df PA |
6526 | } |
6527 | ||
4a306c9a | 6528 | if (!part_of_multiple) |
c4093a6a | 6529 | { |
4a306c9a JB |
6530 | if (b->thread != -1) |
6531 | { | |
6532 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6533 | "stop only in" line a little further down. */ |
4a306c9a JB |
6534 | ui_out_text (uiout, " thread "); |
6535 | ui_out_field_int (uiout, "thread", b->thread); | |
6536 | } | |
6537 | else if (b->task != 0) | |
6538 | { | |
6539 | ui_out_text (uiout, " task "); | |
6540 | ui_out_field_int (uiout, "task", b->task); | |
6541 | } | |
c4093a6a | 6542 | } |
f1310107 | 6543 | |
8b93c638 | 6544 | ui_out_text (uiout, "\n"); |
f1310107 | 6545 | |
348d480f | 6546 | if (!part_of_multiple) |
f1310107 TJB |
6547 | b->ops->print_one_detail (b, uiout); |
6548 | ||
0d381245 | 6549 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6550 | { |
6551 | annotate_field (6); | |
8b93c638 | 6552 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6553 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6554 | the frame ID. */ |
5af949e3 UW |
6555 | ui_out_field_core_addr (uiout, "frame", |
6556 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6557 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6558 | } |
6559 | ||
28010a5d | 6560 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6561 | { |
6562 | annotate_field (7); | |
d77f58be | 6563 | if (is_tracepoint (b)) |
1042e4c0 SS |
6564 | ui_out_text (uiout, "\ttrace only if "); |
6565 | else | |
6566 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6567 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6568 | |
6569 | /* Print whether the target is doing the breakpoint's condition | |
6570 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6571 | if (is_breakpoint (b) | |
6572 | && breakpoint_condition_evaluation_mode () | |
6573 | == condition_evaluation_target) | |
6574 | { | |
6575 | ui_out_text (uiout, " ("); | |
6576 | ui_out_field_string (uiout, "evaluated-by", | |
6577 | bp_condition_evaluator (b)); | |
6578 | ui_out_text (uiout, " evals)"); | |
6579 | } | |
0101ce28 JJ |
6580 | ui_out_text (uiout, "\n"); |
6581 | } | |
6582 | ||
0d381245 | 6583 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6584 | { |
4a64f543 | 6585 | /* FIXME should make an annotation for this. */ |
8b93c638 | 6586 | ui_out_text (uiout, "\tstop only in thread "); |
5d5658a1 PA |
6587 | if (ui_out_is_mi_like_p (uiout)) |
6588 | ui_out_field_int (uiout, "thread", b->thread); | |
6589 | else | |
6590 | { | |
6591 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6592 | ||
6593 | ui_out_field_string (uiout, "thread", print_thread_id (thr)); | |
6594 | } | |
8b93c638 | 6595 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6596 | } |
6597 | ||
556ec64d YQ |
6598 | if (!part_of_multiple) |
6599 | { | |
6600 | if (b->hit_count) | |
31f56a27 YQ |
6601 | { |
6602 | /* FIXME should make an annotation for this. */ | |
6603 | if (is_catchpoint (b)) | |
6604 | ui_out_text (uiout, "\tcatchpoint"); | |
6605 | else if (is_tracepoint (b)) | |
6606 | ui_out_text (uiout, "\ttracepoint"); | |
6607 | else | |
6608 | ui_out_text (uiout, "\tbreakpoint"); | |
6609 | ui_out_text (uiout, " already hit "); | |
6610 | ui_out_field_int (uiout, "times", b->hit_count); | |
6611 | if (b->hit_count == 1) | |
6612 | ui_out_text (uiout, " time\n"); | |
6613 | else | |
6614 | ui_out_text (uiout, " times\n"); | |
6615 | } | |
556ec64d YQ |
6616 | else |
6617 | { | |
31f56a27 YQ |
6618 | /* Output the count also if it is zero, but only if this is mi. */ |
6619 | if (ui_out_is_mi_like_p (uiout)) | |
6620 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6621 | } |
6622 | } | |
8b93c638 | 6623 | |
0d381245 | 6624 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6625 | { |
6626 | annotate_field (8); | |
8b93c638 JM |
6627 | ui_out_text (uiout, "\tignore next "); |
6628 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6629 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6630 | } |
059fb39f | 6631 | |
816338b5 SS |
6632 | /* Note that an enable count of 1 corresponds to "enable once" |
6633 | behavior, which is reported by the combination of enablement and | |
6634 | disposition, so we don't need to mention it here. */ | |
6635 | if (!part_of_multiple && b->enable_count > 1) | |
6636 | { | |
6637 | annotate_field (8); | |
6638 | ui_out_text (uiout, "\tdisable after "); | |
6639 | /* Tweak the wording to clarify that ignore and enable counts | |
6640 | are distinct, and have additive effect. */ | |
6641 | if (b->ignore_count) | |
6642 | ui_out_text (uiout, "additional "); | |
6643 | else | |
6644 | ui_out_text (uiout, "next "); | |
6645 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6646 | ui_out_text (uiout, " hits\n"); | |
6647 | } | |
6648 | ||
f196051f SS |
6649 | if (!part_of_multiple && is_tracepoint (b)) |
6650 | { | |
6651 | struct tracepoint *tp = (struct tracepoint *) b; | |
6652 | ||
6653 | if (tp->traceframe_usage) | |
6654 | { | |
6655 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6656 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6657 | ui_out_text (uiout, " bytes\n"); | |
6658 | } | |
6659 | } | |
d3ce09f5 | 6660 | |
9add0f1b | 6661 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6662 | if (!part_of_multiple && l) |
c4093a6a | 6663 | { |
3b31d625 EZ |
6664 | struct cleanup *script_chain; |
6665 | ||
c4093a6a | 6666 | annotate_field (9); |
3b31d625 | 6667 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6668 | print_command_lines (uiout, l, 4); |
3b31d625 | 6669 | do_cleanups (script_chain); |
c4093a6a | 6670 | } |
d24317b4 | 6671 | |
d9b3f62e | 6672 | if (is_tracepoint (b)) |
1042e4c0 | 6673 | { |
d9b3f62e PA |
6674 | struct tracepoint *t = (struct tracepoint *) b; |
6675 | ||
6676 | if (!part_of_multiple && t->pass_count) | |
6677 | { | |
6678 | annotate_field (10); | |
6679 | ui_out_text (uiout, "\tpass count "); | |
6680 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6681 | ui_out_text (uiout, " \n"); | |
6682 | } | |
f2a8bc8a YQ |
6683 | |
6684 | /* Don't display it when tracepoint or tracepoint location is | |
6685 | pending. */ | |
6686 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6687 | { | |
6688 | annotate_field (11); | |
6689 | ||
6690 | if (ui_out_is_mi_like_p (uiout)) | |
6691 | ui_out_field_string (uiout, "installed", | |
6692 | loc->inserted ? "y" : "n"); | |
6693 | else | |
6694 | { | |
6695 | if (loc->inserted) | |
6696 | ui_out_text (uiout, "\t"); | |
6697 | else | |
6698 | ui_out_text (uiout, "\tnot "); | |
6699 | ui_out_text (uiout, "installed on target\n"); | |
6700 | } | |
6701 | } | |
1042e4c0 SS |
6702 | } |
6703 | ||
d24317b4 VP |
6704 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6705 | { | |
3a5c3e22 PA |
6706 | if (is_watchpoint (b)) |
6707 | { | |
6708 | struct watchpoint *w = (struct watchpoint *) b; | |
6709 | ||
6710 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6711 | } | |
f00aae0f KS |
6712 | else if (b->location != NULL |
6713 | && event_location_to_string (b->location) != NULL) | |
6714 | ui_out_field_string (uiout, "original-location", | |
6715 | event_location_to_string (b->location)); | |
d24317b4 | 6716 | } |
c4093a6a | 6717 | } |
c5aa993b | 6718 | |
0d381245 VP |
6719 | static void |
6720 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6721 | struct bp_location **last_loc, |
6c95b8df | 6722 | int allflag) |
0d381245 | 6723 | { |
8d3788bd | 6724 | struct cleanup *bkpt_chain; |
79a45e25 | 6725 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6726 | |
6727 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6728 | ||
12c5a436 | 6729 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6730 | do_cleanups (bkpt_chain); |
0d381245 VP |
6731 | |
6732 | /* If this breakpoint has custom print function, | |
6733 | it's already printed. Otherwise, print individual | |
6734 | locations, if any. */ | |
6735 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6736 | { | |
4a64f543 MS |
6737 | /* If breakpoint has a single location that is disabled, we |
6738 | print it as if it had several locations, since otherwise it's | |
6739 | hard to represent "breakpoint enabled, location disabled" | |
6740 | situation. | |
6741 | ||
6742 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6743 | internally, that's not a property exposed to user. */ |
0d381245 | 6744 | if (b->loc |
a5606eee | 6745 | && !is_hardware_watchpoint (b) |
8d3788bd | 6746 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6747 | { |
6748 | struct bp_location *loc; | |
6749 | int n = 1; | |
8d3788bd | 6750 | |
0d381245 | 6751 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6752 | { |
6753 | struct cleanup *inner2 = | |
6754 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6755 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6756 | do_cleanups (inner2); | |
6757 | } | |
0d381245 VP |
6758 | } |
6759 | } | |
6760 | } | |
6761 | ||
a6d9a66e UW |
6762 | static int |
6763 | breakpoint_address_bits (struct breakpoint *b) | |
6764 | { | |
6765 | int print_address_bits = 0; | |
6766 | struct bp_location *loc; | |
6767 | ||
c6d81124 PA |
6768 | /* Software watchpoints that aren't watching memory don't have an |
6769 | address to print. */ | |
6770 | if (is_no_memory_software_watchpoint (b)) | |
6771 | return 0; | |
6772 | ||
a6d9a66e UW |
6773 | for (loc = b->loc; loc; loc = loc->next) |
6774 | { | |
c7437ca6 PA |
6775 | int addr_bit; |
6776 | ||
c7437ca6 | 6777 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6778 | if (addr_bit > print_address_bits) |
6779 | print_address_bits = addr_bit; | |
6780 | } | |
6781 | ||
6782 | return print_address_bits; | |
6783 | } | |
0d381245 | 6784 | |
c4093a6a JM |
6785 | struct captured_breakpoint_query_args |
6786 | { | |
6787 | int bnum; | |
6788 | }; | |
c5aa993b | 6789 | |
c4093a6a | 6790 | static int |
2b65245e | 6791 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6792 | { |
9a3c8263 SM |
6793 | struct captured_breakpoint_query_args *args |
6794 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6795 | struct breakpoint *b; |
a6d9a66e | 6796 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6797 | |
c4093a6a JM |
6798 | ALL_BREAKPOINTS (b) |
6799 | { | |
6800 | if (args->bnum == b->number) | |
c5aa993b | 6801 | { |
12c5a436 | 6802 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6803 | return GDB_RC_OK; |
c5aa993b | 6804 | } |
c4093a6a JM |
6805 | } |
6806 | return GDB_RC_NONE; | |
6807 | } | |
c5aa993b | 6808 | |
c4093a6a | 6809 | enum gdb_rc |
4a64f543 MS |
6810 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6811 | char **error_message) | |
c4093a6a JM |
6812 | { |
6813 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6814 | |
c4093a6a JM |
6815 | args.bnum = bnum; |
6816 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6817 | an error. */ |
b0b13bb4 DJ |
6818 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6819 | error_message, RETURN_MASK_ALL) < 0) | |
6820 | return GDB_RC_FAIL; | |
6821 | else | |
6822 | return GDB_RC_OK; | |
c4093a6a | 6823 | } |
c5aa993b | 6824 | |
09d682a4 TT |
6825 | /* Return true if this breakpoint was set by the user, false if it is |
6826 | internal or momentary. */ | |
6827 | ||
6828 | int | |
6829 | user_breakpoint_p (struct breakpoint *b) | |
6830 | { | |
46c6471b | 6831 | return b->number > 0; |
09d682a4 TT |
6832 | } |
6833 | ||
93daf339 TT |
6834 | /* See breakpoint.h. */ |
6835 | ||
6836 | int | |
6837 | pending_breakpoint_p (struct breakpoint *b) | |
6838 | { | |
6839 | return b->loc == NULL; | |
6840 | } | |
6841 | ||
7f3b0473 | 6842 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6843 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6844 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6845 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6846 | ones for which it returns non-zero. Return the total number of | |
6847 | breakpoints listed. */ | |
c906108c | 6848 | |
d77f58be | 6849 | static int |
e5a67952 | 6850 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6851 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6852 | { |
52f0bd74 | 6853 | struct breakpoint *b; |
a6d9a66e | 6854 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6855 | int nr_printable_breakpoints; |
3b31d625 | 6856 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6857 | struct value_print_options opts; |
a6d9a66e | 6858 | int print_address_bits = 0; |
269b11a2 | 6859 | int print_type_col_width = 14; |
79a45e25 | 6860 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6861 | |
79a45b7d TT |
6862 | get_user_print_options (&opts); |
6863 | ||
4a64f543 MS |
6864 | /* Compute the number of rows in the table, as well as the size |
6865 | required for address fields. */ | |
7f3b0473 AC |
6866 | nr_printable_breakpoints = 0; |
6867 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6868 | { |
6869 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6870 | if (filter && !filter (b)) | |
6871 | continue; | |
6872 | ||
6873 | /* If we have an "args" string, it is a list of breakpoints to | |
6874 | accept. Skip the others. */ | |
6875 | if (args != NULL && *args != '\0') | |
6876 | { | |
6877 | if (allflag && parse_and_eval_long (args) != b->number) | |
6878 | continue; | |
6879 | if (!allflag && !number_is_in_list (args, b->number)) | |
6880 | continue; | |
6881 | } | |
269b11a2 | 6882 | |
e5a67952 MS |
6883 | if (allflag || user_breakpoint_p (b)) |
6884 | { | |
6885 | int addr_bit, type_len; | |
a6d9a66e | 6886 | |
e5a67952 MS |
6887 | addr_bit = breakpoint_address_bits (b); |
6888 | if (addr_bit > print_address_bits) | |
6889 | print_address_bits = addr_bit; | |
269b11a2 | 6890 | |
e5a67952 MS |
6891 | type_len = strlen (bptype_string (b->type)); |
6892 | if (type_len > print_type_col_width) | |
6893 | print_type_col_width = type_len; | |
6894 | ||
6895 | nr_printable_breakpoints++; | |
6896 | } | |
6897 | } | |
7f3b0473 | 6898 | |
79a45b7d | 6899 | if (opts.addressprint) |
3b31d625 | 6900 | bkpttbl_chain |
3e43a32a MS |
6901 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6902 | nr_printable_breakpoints, | |
3b31d625 | 6903 | "BreakpointTable"); |
8b93c638 | 6904 | else |
3b31d625 | 6905 | bkpttbl_chain |
3e43a32a MS |
6906 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6907 | nr_printable_breakpoints, | |
3b31d625 | 6908 | "BreakpointTable"); |
8b93c638 | 6909 | |
7f3b0473 | 6910 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6911 | annotate_breakpoints_headers (); |
6912 | if (nr_printable_breakpoints > 0) | |
6913 | annotate_field (0); | |
4a64f543 | 6914 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6915 | if (nr_printable_breakpoints > 0) |
6916 | annotate_field (1); | |
269b11a2 | 6917 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6918 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6919 | if (nr_printable_breakpoints > 0) |
6920 | annotate_field (2); | |
4a64f543 | 6921 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6922 | if (nr_printable_breakpoints > 0) |
6923 | annotate_field (3); | |
54e52265 | 6924 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6925 | if (opts.addressprint) |
e5a67952 MS |
6926 | { |
6927 | if (nr_printable_breakpoints > 0) | |
6928 | annotate_field (4); | |
6929 | if (print_address_bits <= 32) | |
6930 | ui_out_table_header (uiout, 10, ui_left, | |
6931 | "addr", "Address"); /* 5 */ | |
6932 | else | |
6933 | ui_out_table_header (uiout, 18, ui_left, | |
6934 | "addr", "Address"); /* 5 */ | |
6935 | } | |
d7faa9e7 AC |
6936 | if (nr_printable_breakpoints > 0) |
6937 | annotate_field (5); | |
6938 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6939 | ui_out_table_body (uiout); | |
6940 | if (nr_printable_breakpoints > 0) | |
6941 | annotate_breakpoints_table (); | |
7f3b0473 | 6942 | |
c4093a6a | 6943 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6944 | { |
6945 | QUIT; | |
6946 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6947 | if (filter && !filter (b)) | |
6948 | continue; | |
6949 | ||
6950 | /* If we have an "args" string, it is a list of breakpoints to | |
6951 | accept. Skip the others. */ | |
6952 | ||
6953 | if (args != NULL && *args != '\0') | |
6954 | { | |
6955 | if (allflag) /* maintenance info breakpoint */ | |
6956 | { | |
6957 | if (parse_and_eval_long (args) != b->number) | |
6958 | continue; | |
6959 | } | |
6960 | else /* all others */ | |
6961 | { | |
6962 | if (!number_is_in_list (args, b->number)) | |
6963 | continue; | |
6964 | } | |
6965 | } | |
6966 | /* We only print out user settable breakpoints unless the | |
6967 | allflag is set. */ | |
6968 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6969 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6970 | } |
6971 | ||
3b31d625 | 6972 | do_cleanups (bkpttbl_chain); |
698384cd | 6973 | |
7f3b0473 | 6974 | if (nr_printable_breakpoints == 0) |
c906108c | 6975 | { |
4a64f543 MS |
6976 | /* If there's a filter, let the caller decide how to report |
6977 | empty list. */ | |
d77f58be SS |
6978 | if (!filter) |
6979 | { | |
e5a67952 | 6980 | if (args == NULL || *args == '\0') |
d77f58be SS |
6981 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6982 | else | |
4a64f543 | 6983 | ui_out_message (uiout, 0, |
e5a67952 MS |
6984 | "No breakpoint or watchpoint matching '%s'.\n", |
6985 | args); | |
d77f58be | 6986 | } |
c906108c SS |
6987 | } |
6988 | else | |
c4093a6a | 6989 | { |
a6d9a66e UW |
6990 | if (last_loc && !server_command) |
6991 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6992 | } |
c906108c | 6993 | |
4a64f543 | 6994 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6995 | there have been breakpoints? */ |
c906108c | 6996 | annotate_breakpoints_table_end (); |
d77f58be SS |
6997 | |
6998 | return nr_printable_breakpoints; | |
c906108c SS |
6999 | } |
7000 | ||
ad443146 SS |
7001 | /* Display the value of default-collect in a way that is generally |
7002 | compatible with the breakpoint list. */ | |
7003 | ||
7004 | static void | |
7005 | default_collect_info (void) | |
7006 | { | |
79a45e25 PA |
7007 | struct ui_out *uiout = current_uiout; |
7008 | ||
ad443146 SS |
7009 | /* If it has no value (which is frequently the case), say nothing; a |
7010 | message like "No default-collect." gets in user's face when it's | |
7011 | not wanted. */ | |
7012 | if (!*default_collect) | |
7013 | return; | |
7014 | ||
7015 | /* The following phrase lines up nicely with per-tracepoint collect | |
7016 | actions. */ | |
7017 | ui_out_text (uiout, "default collect "); | |
7018 | ui_out_field_string (uiout, "default-collect", default_collect); | |
7019 | ui_out_text (uiout, " \n"); | |
7020 | } | |
7021 | ||
c906108c | 7022 | static void |
e5a67952 | 7023 | breakpoints_info (char *args, int from_tty) |
c906108c | 7024 | { |
e5a67952 | 7025 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
7026 | |
7027 | default_collect_info (); | |
d77f58be SS |
7028 | } |
7029 | ||
7030 | static void | |
e5a67952 | 7031 | watchpoints_info (char *args, int from_tty) |
d77f58be | 7032 | { |
e5a67952 | 7033 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 7034 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
7035 | |
7036 | if (num_printed == 0) | |
7037 | { | |
e5a67952 | 7038 | if (args == NULL || *args == '\0') |
d77f58be SS |
7039 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
7040 | else | |
e5a67952 | 7041 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 7042 | } |
c906108c SS |
7043 | } |
7044 | ||
7a292a7a | 7045 | static void |
e5a67952 | 7046 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 7047 | { |
e5a67952 | 7048 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
7049 | |
7050 | default_collect_info (); | |
c906108c SS |
7051 | } |
7052 | ||
0d381245 | 7053 | static int |
714835d5 | 7054 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7055 | struct program_space *pspace, |
714835d5 | 7056 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7057 | { |
7058 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7059 | |
0d381245 VP |
7060 | for (; bl; bl = bl->next) |
7061 | { | |
6c95b8df PA |
7062 | if (bl->pspace == pspace |
7063 | && bl->address == pc | |
0d381245 VP |
7064 | && (!overlay_debugging || bl->section == section)) |
7065 | return 1; | |
7066 | } | |
7067 | return 0; | |
7068 | } | |
7069 | ||
672f9b60 | 7070 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7071 | concerns with logical breakpoints, so we match program spaces, not |
7072 | address spaces. */ | |
c906108c SS |
7073 | |
7074 | static void | |
6c95b8df PA |
7075 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7076 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7077 | struct obj_section *section, int thread) |
c906108c | 7078 | { |
52f0bd74 AC |
7079 | int others = 0; |
7080 | struct breakpoint *b; | |
c906108c SS |
7081 | |
7082 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7083 | others += (user_breakpoint_p (b) |
7084 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7085 | if (others > 0) |
7086 | { | |
a3f17187 AC |
7087 | if (others == 1) |
7088 | printf_filtered (_("Note: breakpoint ")); | |
7089 | else /* if (others == ???) */ | |
7090 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7091 | ALL_BREAKPOINTS (b) |
672f9b60 | 7092 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7093 | { |
7094 | others--; | |
7095 | printf_filtered ("%d", b->number); | |
7096 | if (b->thread == -1 && thread != -1) | |
7097 | printf_filtered (" (all threads)"); | |
7098 | else if (b->thread != -1) | |
7099 | printf_filtered (" (thread %d)", b->thread); | |
7100 | printf_filtered ("%s%s ", | |
059fb39f | 7101 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7102 | || b->enable_state == bp_call_disabled) |
0d381245 | 7103 | ? " (disabled)" |
0d381245 VP |
7104 | : ""), |
7105 | (others > 1) ? "," | |
7106 | : ((others == 1) ? " and" : "")); | |
7107 | } | |
a3f17187 | 7108 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7109 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7110 | printf_filtered (".\n"); |
7111 | } | |
7112 | } | |
7113 | \f | |
c906108c | 7114 | |
e4f237da | 7115 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7116 | BPT locations. For some breakpoint types, the locations' address members |
7117 | are irrelevant and it makes no sense to attempt to compare them to other | |
7118 | addresses (or use them for any other purpose either). | |
e4f237da | 7119 | |
4a64f543 | 7120 | More specifically, each of the following breakpoint types will |
244558af | 7121 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7122 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7123 | breakpoint location at address zero: |
e4f237da KB |
7124 | |
7125 | bp_watchpoint | |
2d134ed3 PA |
7126 | bp_catchpoint |
7127 | ||
7128 | */ | |
e4f237da KB |
7129 | |
7130 | static int | |
7131 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7132 | { | |
7133 | enum bptype type = bpt->type; | |
7134 | ||
2d134ed3 PA |
7135 | return (type != bp_watchpoint && type != bp_catchpoint); |
7136 | } | |
7137 | ||
7138 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7139 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7140 | ||
7141 | static int | |
4a64f543 MS |
7142 | watchpoint_locations_match (struct bp_location *loc1, |
7143 | struct bp_location *loc2) | |
2d134ed3 | 7144 | { |
3a5c3e22 PA |
7145 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7146 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7147 | ||
7148 | /* Both of them must exist. */ | |
7149 | gdb_assert (w1 != NULL); | |
7150 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7151 | |
4a64f543 MS |
7152 | /* If the target can evaluate the condition expression in hardware, |
7153 | then we we need to insert both watchpoints even if they are at | |
7154 | the same place. Otherwise the watchpoint will only trigger when | |
7155 | the condition of whichever watchpoint was inserted evaluates to | |
7156 | true, not giving a chance for GDB to check the condition of the | |
7157 | other watchpoint. */ | |
3a5c3e22 | 7158 | if ((w1->cond_exp |
4a64f543 MS |
7159 | && target_can_accel_watchpoint_condition (loc1->address, |
7160 | loc1->length, | |
0cf6dd15 | 7161 | loc1->watchpoint_type, |
3a5c3e22 PA |
7162 | w1->cond_exp)) |
7163 | || (w2->cond_exp | |
4a64f543 MS |
7164 | && target_can_accel_watchpoint_condition (loc2->address, |
7165 | loc2->length, | |
0cf6dd15 | 7166 | loc2->watchpoint_type, |
3a5c3e22 | 7167 | w2->cond_exp))) |
0cf6dd15 TJB |
7168 | return 0; |
7169 | ||
85d721b8 PA |
7170 | /* Note that this checks the owner's type, not the location's. In |
7171 | case the target does not support read watchpoints, but does | |
7172 | support access watchpoints, we'll have bp_read_watchpoint | |
7173 | watchpoints with hw_access locations. Those should be considered | |
7174 | duplicates of hw_read locations. The hw_read locations will | |
7175 | become hw_access locations later. */ | |
2d134ed3 PA |
7176 | return (loc1->owner->type == loc2->owner->type |
7177 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7178 | && loc1->address == loc2->address | |
7179 | && loc1->length == loc2->length); | |
e4f237da KB |
7180 | } |
7181 | ||
31e77af2 | 7182 | /* See breakpoint.h. */ |
6c95b8df | 7183 | |
31e77af2 | 7184 | int |
6c95b8df PA |
7185 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7186 | struct address_space *aspace2, CORE_ADDR addr2) | |
7187 | { | |
f5656ead | 7188 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7189 | || aspace1 == aspace2) |
7190 | && addr1 == addr2); | |
7191 | } | |
7192 | ||
f1310107 TJB |
7193 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7194 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7195 | matches ASPACE2. On targets that have global breakpoints, the address | |
7196 | space doesn't really matter. */ | |
7197 | ||
7198 | static int | |
7199 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7200 | int len1, struct address_space *aspace2, | |
7201 | CORE_ADDR addr2) | |
7202 | { | |
f5656ead | 7203 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7204 | || aspace1 == aspace2) |
7205 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7206 | } | |
7207 | ||
7208 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7209 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7210 | matches the breakpoint's address space. On targets that have global | |
7211 | breakpoints, the address space doesn't really matter. */ | |
7212 | ||
7213 | static int | |
7214 | breakpoint_location_address_match (struct bp_location *bl, | |
7215 | struct address_space *aspace, | |
7216 | CORE_ADDR addr) | |
7217 | { | |
7218 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7219 | aspace, addr) | |
7220 | || (bl->length | |
7221 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7222 | bl->address, bl->length, | |
7223 | aspace, addr))); | |
7224 | } | |
7225 | ||
d35ae833 PA |
7226 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7227 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7228 | match happens only if ASPACE matches the breakpoint's address | |
7229 | space. On targets that have global breakpoints, the address space | |
7230 | doesn't really matter. */ | |
7231 | ||
7232 | static int | |
7233 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7234 | struct address_space *aspace, | |
7235 | CORE_ADDR addr, int len) | |
7236 | { | |
7237 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7238 | || bl->pspace->aspace == aspace) | |
7239 | { | |
7240 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7241 | ||
7242 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7243 | return 1; | |
7244 | } | |
7245 | return 0; | |
7246 | } | |
7247 | ||
1e4d1764 YQ |
7248 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7249 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7250 | true, otherwise returns false. */ | |
7251 | ||
7252 | static int | |
7253 | tracepoint_locations_match (struct bp_location *loc1, | |
7254 | struct bp_location *loc2) | |
7255 | { | |
7256 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7257 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7258 | locations at the same address of different tracepoints are regarded as | |
7259 | different locations. */ | |
7260 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7261 | else | |
7262 | return 0; | |
7263 | } | |
7264 | ||
2d134ed3 PA |
7265 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7266 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7267 | represent the same location. */ | |
7268 | ||
7269 | static int | |
4a64f543 MS |
7270 | breakpoint_locations_match (struct bp_location *loc1, |
7271 | struct bp_location *loc2) | |
2d134ed3 | 7272 | { |
2bdf28a0 JK |
7273 | int hw_point1, hw_point2; |
7274 | ||
7275 | /* Both of them must not be in moribund_locations. */ | |
7276 | gdb_assert (loc1->owner != NULL); | |
7277 | gdb_assert (loc2->owner != NULL); | |
7278 | ||
7279 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7280 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7281 | |
7282 | if (hw_point1 != hw_point2) | |
7283 | return 0; | |
7284 | else if (hw_point1) | |
7285 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7286 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7287 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7288 | else |
f1310107 TJB |
7289 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7290 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7291 | loc2->pspace->aspace, loc2->address) | |
7292 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7293 | } |
7294 | ||
76897487 KB |
7295 | static void |
7296 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7297 | int bnum, int have_bnum) | |
7298 | { | |
f63fbe86 MS |
7299 | /* The longest string possibly returned by hex_string_custom |
7300 | is 50 chars. These must be at least that big for safety. */ | |
7301 | char astr1[64]; | |
7302 | char astr2[64]; | |
76897487 | 7303 | |
bb599908 PH |
7304 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7305 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7306 | if (have_bnum) |
8a3fe4f8 | 7307 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7308 | bnum, astr1, astr2); |
7309 | else | |
8a3fe4f8 | 7310 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7311 | } |
7312 | ||
4a64f543 MS |
7313 | /* Adjust a breakpoint's address to account for architectural |
7314 | constraints on breakpoint placement. Return the adjusted address. | |
7315 | Note: Very few targets require this kind of adjustment. For most | |
7316 | targets, this function is simply the identity function. */ | |
76897487 KB |
7317 | |
7318 | static CORE_ADDR | |
a6d9a66e UW |
7319 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7320 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7321 | { |
a6d9a66e | 7322 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7323 | { |
7324 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7325 | return bpaddr; | |
7326 | } | |
88f7da05 KB |
7327 | else if (bptype == bp_watchpoint |
7328 | || bptype == bp_hardware_watchpoint | |
7329 | || bptype == bp_read_watchpoint | |
7330 | || bptype == bp_access_watchpoint | |
fe798b75 | 7331 | || bptype == bp_catchpoint) |
88f7da05 KB |
7332 | { |
7333 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7334 | have their addresses modified. */ | |
7335 | return bpaddr; | |
7336 | } | |
7c16b83e PA |
7337 | else if (bptype == bp_single_step) |
7338 | { | |
7339 | /* Single-step breakpoints should not have their addresses | |
7340 | modified. If there's any architectural constrain that | |
7341 | applies to this address, then it should have already been | |
7342 | taken into account when the breakpoint was created in the | |
7343 | first place. If we didn't do this, stepping through e.g., | |
7344 | Thumb-2 IT blocks would break. */ | |
7345 | return bpaddr; | |
7346 | } | |
76897487 KB |
7347 | else |
7348 | { | |
7349 | CORE_ADDR adjusted_bpaddr; | |
7350 | ||
7351 | /* Some targets have architectural constraints on the placement | |
7352 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7353 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7354 | |
7355 | /* An adjusted breakpoint address can significantly alter | |
7356 | a user's expectations. Print a warning if an adjustment | |
7357 | is required. */ | |
7358 | if (adjusted_bpaddr != bpaddr) | |
7359 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7360 | ||
7361 | return adjusted_bpaddr; | |
7362 | } | |
7363 | } | |
7364 | ||
28010a5d PA |
7365 | void |
7366 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7367 | struct breakpoint *owner) | |
7cc221ef | 7368 | { |
7cc221ef DJ |
7369 | memset (loc, 0, sizeof (*loc)); |
7370 | ||
348d480f PA |
7371 | gdb_assert (ops != NULL); |
7372 | ||
28010a5d PA |
7373 | loc->ops = ops; |
7374 | loc->owner = owner; | |
511a6cd4 | 7375 | loc->cond = NULL; |
b775012e | 7376 | loc->cond_bytecode = NULL; |
0d381245 VP |
7377 | loc->shlib_disabled = 0; |
7378 | loc->enabled = 1; | |
e049a4b5 | 7379 | |
28010a5d | 7380 | switch (owner->type) |
e049a4b5 DJ |
7381 | { |
7382 | case bp_breakpoint: | |
7c16b83e | 7383 | case bp_single_step: |
e049a4b5 DJ |
7384 | case bp_until: |
7385 | case bp_finish: | |
7386 | case bp_longjmp: | |
7387 | case bp_longjmp_resume: | |
e2e4d78b | 7388 | case bp_longjmp_call_dummy: |
186c406b TT |
7389 | case bp_exception: |
7390 | case bp_exception_resume: | |
e049a4b5 | 7391 | case bp_step_resume: |
2c03e5be | 7392 | case bp_hp_step_resume: |
e049a4b5 DJ |
7393 | case bp_watchpoint_scope: |
7394 | case bp_call_dummy: | |
aa7d318d | 7395 | case bp_std_terminate: |
e049a4b5 DJ |
7396 | case bp_shlib_event: |
7397 | case bp_thread_event: | |
7398 | case bp_overlay_event: | |
4efc6507 | 7399 | case bp_jit_event: |
0fd8e87f | 7400 | case bp_longjmp_master: |
aa7d318d | 7401 | case bp_std_terminate_master: |
186c406b | 7402 | case bp_exception_master: |
0e30163f JK |
7403 | case bp_gnu_ifunc_resolver: |
7404 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7405 | case bp_dprintf: |
e049a4b5 | 7406 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7407 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7408 | break; |
7409 | case bp_hardware_breakpoint: | |
7410 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7411 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7412 | break; |
7413 | case bp_hardware_watchpoint: | |
7414 | case bp_read_watchpoint: | |
7415 | case bp_access_watchpoint: | |
7416 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7417 | break; | |
7418 | case bp_watchpoint: | |
ce78b96d | 7419 | case bp_catchpoint: |
15c3d785 PA |
7420 | case bp_tracepoint: |
7421 | case bp_fast_tracepoint: | |
0fb4aa4b | 7422 | case bp_static_tracepoint: |
e049a4b5 DJ |
7423 | loc->loc_type = bp_loc_other; |
7424 | break; | |
7425 | default: | |
e2e0b3e5 | 7426 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7427 | } |
7428 | ||
f431efe5 | 7429 | loc->refc = 1; |
28010a5d PA |
7430 | } |
7431 | ||
7432 | /* Allocate a struct bp_location. */ | |
7433 | ||
7434 | static struct bp_location * | |
7435 | allocate_bp_location (struct breakpoint *bpt) | |
7436 | { | |
348d480f PA |
7437 | return bpt->ops->allocate_location (bpt); |
7438 | } | |
7cc221ef | 7439 | |
f431efe5 PA |
7440 | static void |
7441 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7442 | { |
348d480f | 7443 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7444 | xfree (loc); |
7445 | } | |
7446 | ||
f431efe5 PA |
7447 | /* Increment reference count. */ |
7448 | ||
7449 | static void | |
7450 | incref_bp_location (struct bp_location *bl) | |
7451 | { | |
7452 | ++bl->refc; | |
7453 | } | |
7454 | ||
7455 | /* Decrement reference count. If the reference count reaches 0, | |
7456 | destroy the bp_location. Sets *BLP to NULL. */ | |
7457 | ||
7458 | static void | |
7459 | decref_bp_location (struct bp_location **blp) | |
7460 | { | |
0807b50c PA |
7461 | gdb_assert ((*blp)->refc > 0); |
7462 | ||
f431efe5 PA |
7463 | if (--(*blp)->refc == 0) |
7464 | free_bp_location (*blp); | |
7465 | *blp = NULL; | |
7466 | } | |
7467 | ||
346774a9 | 7468 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7469 | |
346774a9 PA |
7470 | static void |
7471 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7472 | { |
346774a9 | 7473 | struct breakpoint *b1; |
c906108c | 7474 | |
346774a9 PA |
7475 | /* Add this breakpoint to the end of the chain so that a list of |
7476 | breakpoints will come out in order of increasing numbers. */ | |
7477 | ||
7478 | b1 = breakpoint_chain; | |
7479 | if (b1 == 0) | |
7480 | breakpoint_chain = b; | |
7481 | else | |
7482 | { | |
7483 | while (b1->next) | |
7484 | b1 = b1->next; | |
7485 | b1->next = b; | |
7486 | } | |
7487 | } | |
7488 | ||
7489 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7490 | ||
7491 | static void | |
7492 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7493 | struct gdbarch *gdbarch, | |
28010a5d | 7494 | enum bptype bptype, |
c0a91b2b | 7495 | const struct breakpoint_ops *ops) |
346774a9 | 7496 | { |
c906108c | 7497 | memset (b, 0, sizeof (*b)); |
2219d63c | 7498 | |
348d480f PA |
7499 | gdb_assert (ops != NULL); |
7500 | ||
28010a5d | 7501 | b->ops = ops; |
4d28f7a8 | 7502 | b->type = bptype; |
a6d9a66e | 7503 | b->gdbarch = gdbarch; |
c906108c SS |
7504 | b->language = current_language->la_language; |
7505 | b->input_radix = input_radix; | |
7506 | b->thread = -1; | |
b5de0fa7 | 7507 | b->enable_state = bp_enabled; |
c906108c SS |
7508 | b->next = 0; |
7509 | b->silent = 0; | |
7510 | b->ignore_count = 0; | |
7511 | b->commands = NULL; | |
818dd999 | 7512 | b->frame_id = null_frame_id; |
0d381245 | 7513 | b->condition_not_parsed = 0; |
84f4c1fe | 7514 | b->py_bp_object = NULL; |
d0fb5eae | 7515 | b->related_breakpoint = b; |
f00aae0f | 7516 | b->location = NULL; |
346774a9 PA |
7517 | } |
7518 | ||
7519 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7520 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7521 | |
7522 | static struct breakpoint * | |
7523 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7524 | enum bptype bptype, |
c0a91b2b | 7525 | const struct breakpoint_ops *ops) |
346774a9 PA |
7526 | { |
7527 | struct breakpoint *b = XNEW (struct breakpoint); | |
7528 | ||
348d480f | 7529 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7530 | add_to_breakpoint_chain (b); |
0d381245 VP |
7531 | return b; |
7532 | } | |
7533 | ||
0e30163f JK |
7534 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7535 | resolutions should be made as the user specified the location explicitly | |
7536 | enough. */ | |
7537 | ||
0d381245 | 7538 | static void |
0e30163f | 7539 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7540 | { |
2bdf28a0 JK |
7541 | gdb_assert (loc->owner != NULL); |
7542 | ||
0d381245 | 7543 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7544 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7545 | || is_tracepoint (loc->owner)) |
0d381245 | 7546 | { |
0e30163f | 7547 | int is_gnu_ifunc; |
2c02bd72 | 7548 | const char *function_name; |
6a3a010b | 7549 | CORE_ADDR func_addr; |
0e30163f | 7550 | |
2c02bd72 | 7551 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7552 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7553 | |
7554 | if (is_gnu_ifunc && !explicit_loc) | |
7555 | { | |
7556 | struct breakpoint *b = loc->owner; | |
7557 | ||
7558 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7559 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7560 | &loc->requested_address)) |
7561 | { | |
7562 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7563 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7564 | loc->requested_address, | |
7565 | b->type); | |
7566 | } | |
7567 | else if (b->type == bp_breakpoint && b->loc == loc | |
7568 | && loc->next == NULL && b->related_breakpoint == b) | |
7569 | { | |
7570 | /* Create only the whole new breakpoint of this type but do not | |
7571 | mess more complicated breakpoints with multiple locations. */ | |
7572 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7573 | /* Remember the resolver's address for use by the return |
7574 | breakpoint. */ | |
7575 | loc->related_address = func_addr; | |
0e30163f JK |
7576 | } |
7577 | } | |
7578 | ||
2c02bd72 DE |
7579 | if (function_name) |
7580 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7581 | } |
7582 | } | |
7583 | ||
a6d9a66e | 7584 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7585 | struct gdbarch * |
a6d9a66e UW |
7586 | get_sal_arch (struct symtab_and_line sal) |
7587 | { | |
7588 | if (sal.section) | |
7589 | return get_objfile_arch (sal.section->objfile); | |
7590 | if (sal.symtab) | |
eb822aa6 | 7591 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7592 | |
7593 | return NULL; | |
7594 | } | |
7595 | ||
346774a9 PA |
7596 | /* Low level routine for partially initializing a breakpoint of type |
7597 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7598 | file name, and line number are provided by SAL. |
0d381245 VP |
7599 | |
7600 | It is expected that the caller will complete the initialization of | |
7601 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7602 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7603 | |
346774a9 PA |
7604 | static void |
7605 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7606 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7607 | const struct breakpoint_ops *ops) |
0d381245 | 7608 | { |
28010a5d | 7609 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7610 | |
3742cc8b | 7611 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7612 | |
6c95b8df PA |
7613 | if (bptype != bp_catchpoint) |
7614 | gdb_assert (sal.pspace != NULL); | |
7615 | ||
f8eba3c6 TT |
7616 | /* Store the program space that was used to set the breakpoint, |
7617 | except for ordinary breakpoints, which are independent of the | |
7618 | program space. */ | |
7619 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7620 | b->pspace = sal.pspace; | |
346774a9 | 7621 | } |
c906108c | 7622 | |
346774a9 PA |
7623 | /* set_raw_breakpoint is a low level routine for allocating and |
7624 | partially initializing a breakpoint of type BPTYPE. The newly | |
7625 | created breakpoint's address, section, source file name, and line | |
7626 | number are provided by SAL. The newly created and partially | |
7627 | initialized breakpoint is added to the breakpoint chain and | |
7628 | is also returned as the value of this function. | |
7629 | ||
7630 | It is expected that the caller will complete the initialization of | |
7631 | the newly created breakpoint struct as well as output any status | |
7632 | information regarding the creation of a new breakpoint. In | |
7633 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7634 | number! Care should be taken to not allow an error to occur | |
7635 | prior to completing the initialization of the breakpoint. If this | |
7636 | should happen, a bogus breakpoint will be left on the chain. */ | |
7637 | ||
7638 | struct breakpoint * | |
7639 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7640 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7641 | const struct breakpoint_ops *ops) |
346774a9 PA |
7642 | { |
7643 | struct breakpoint *b = XNEW (struct breakpoint); | |
7644 | ||
348d480f | 7645 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7646 | add_to_breakpoint_chain (b); |
c906108c SS |
7647 | return b; |
7648 | } | |
7649 | ||
53a5351d | 7650 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7651 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7652 | initiated the operation. */ | |
c906108c SS |
7653 | |
7654 | void | |
186c406b | 7655 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7656 | { |
35df4500 | 7657 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7658 | int thread = tp->global_num; |
0fd8e87f UW |
7659 | |
7660 | /* To avoid having to rescan all objfile symbols at every step, | |
7661 | we maintain a list of continually-inserted but always disabled | |
7662 | longjmp "master" breakpoints. Here, we simply create momentary | |
7663 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7664 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7665 | if (b->pspace == current_program_space |
186c406b TT |
7666 | && (b->type == bp_longjmp_master |
7667 | || b->type == bp_exception_master)) | |
0fd8e87f | 7668 | { |
06edf0c0 PA |
7669 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7670 | struct breakpoint *clone; | |
cc59ec59 | 7671 | |
e2e4d78b JK |
7672 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7673 | after their removal. */ | |
06edf0c0 | 7674 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7675 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7676 | clone->thread = thread; |
7677 | } | |
186c406b TT |
7678 | |
7679 | tp->initiating_frame = frame; | |
c906108c SS |
7680 | } |
7681 | ||
611c83ae | 7682 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7683 | void |
611c83ae | 7684 | delete_longjmp_breakpoint (int thread) |
c906108c | 7685 | { |
35df4500 | 7686 | struct breakpoint *b, *b_tmp; |
c906108c | 7687 | |
35df4500 | 7688 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7689 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7690 | { |
7691 | if (b->thread == thread) | |
7692 | delete_breakpoint (b); | |
7693 | } | |
c906108c SS |
7694 | } |
7695 | ||
f59f708a PA |
7696 | void |
7697 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7698 | { | |
7699 | struct breakpoint *b, *b_tmp; | |
7700 | ||
7701 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7702 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7703 | { | |
7704 | if (b->thread == thread) | |
7705 | b->disposition = disp_del_at_next_stop; | |
7706 | } | |
7707 | } | |
7708 | ||
e2e4d78b JK |
7709 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7710 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7711 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7712 | breakpoints. */ | |
7713 | ||
7714 | struct breakpoint * | |
7715 | set_longjmp_breakpoint_for_call_dummy (void) | |
7716 | { | |
7717 | struct breakpoint *b, *retval = NULL; | |
7718 | ||
7719 | ALL_BREAKPOINTS (b) | |
7720 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7721 | { | |
7722 | struct breakpoint *new_b; | |
7723 | ||
7724 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7725 | &momentary_breakpoint_ops, |
7726 | 1); | |
5d5658a1 | 7727 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7728 | |
7729 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7730 | ||
7731 | gdb_assert (new_b->related_breakpoint == new_b); | |
7732 | if (retval == NULL) | |
7733 | retval = new_b; | |
7734 | new_b->related_breakpoint = retval; | |
7735 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7736 | retval = retval->related_breakpoint; | |
7737 | retval->related_breakpoint = new_b; | |
7738 | } | |
7739 | ||
7740 | return retval; | |
7741 | } | |
7742 | ||
7743 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7744 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7745 | stack. |
7746 | ||
7747 | You should call this function only at places where it is safe to currently | |
7748 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7749 | frames. */ | |
7750 | ||
7751 | void | |
b67a2c6f | 7752 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7753 | { |
7754 | struct breakpoint *b, *b_tmp; | |
7755 | ||
7756 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7757 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7758 | { |
7759 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7760 | ||
7761 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7762 | dummy_b = dummy_b->related_breakpoint; | |
7763 | if (dummy_b->type != bp_call_dummy | |
7764 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7765 | continue; | |
7766 | ||
b67a2c6f | 7767 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7768 | |
7769 | while (b->related_breakpoint != b) | |
7770 | { | |
7771 | if (b_tmp == b->related_breakpoint) | |
7772 | b_tmp = b->related_breakpoint->next; | |
7773 | delete_breakpoint (b->related_breakpoint); | |
7774 | } | |
7775 | delete_breakpoint (b); | |
7776 | } | |
7777 | } | |
7778 | ||
1900040c MS |
7779 | void |
7780 | enable_overlay_breakpoints (void) | |
7781 | { | |
52f0bd74 | 7782 | struct breakpoint *b; |
1900040c MS |
7783 | |
7784 | ALL_BREAKPOINTS (b) | |
7785 | if (b->type == bp_overlay_event) | |
7786 | { | |
7787 | b->enable_state = bp_enabled; | |
44702360 | 7788 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7789 | overlay_events_enabled = 1; |
1900040c MS |
7790 | } |
7791 | } | |
7792 | ||
7793 | void | |
7794 | disable_overlay_breakpoints (void) | |
7795 | { | |
52f0bd74 | 7796 | struct breakpoint *b; |
1900040c MS |
7797 | |
7798 | ALL_BREAKPOINTS (b) | |
7799 | if (b->type == bp_overlay_event) | |
7800 | { | |
7801 | b->enable_state = bp_disabled; | |
44702360 | 7802 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7803 | overlay_events_enabled = 0; |
1900040c MS |
7804 | } |
7805 | } | |
7806 | ||
aa7d318d TT |
7807 | /* Set an active std::terminate breakpoint for each std::terminate |
7808 | master breakpoint. */ | |
7809 | void | |
7810 | set_std_terminate_breakpoint (void) | |
7811 | { | |
35df4500 | 7812 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7813 | |
35df4500 | 7814 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7815 | if (b->pspace == current_program_space |
7816 | && b->type == bp_std_terminate_master) | |
7817 | { | |
06edf0c0 | 7818 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7819 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7820 | } |
7821 | } | |
7822 | ||
7823 | /* Delete all the std::terminate breakpoints. */ | |
7824 | void | |
7825 | delete_std_terminate_breakpoint (void) | |
7826 | { | |
35df4500 | 7827 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7828 | |
35df4500 | 7829 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7830 | if (b->type == bp_std_terminate) |
7831 | delete_breakpoint (b); | |
7832 | } | |
7833 | ||
c4093a6a | 7834 | struct breakpoint * |
a6d9a66e | 7835 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7836 | { |
7837 | struct breakpoint *b; | |
c4093a6a | 7838 | |
06edf0c0 PA |
7839 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7840 | &internal_breakpoint_ops); | |
7841 | ||
b5de0fa7 | 7842 | b->enable_state = bp_enabled; |
f00aae0f | 7843 | /* location has to be used or breakpoint_re_set will delete me. */ |
305e13e6 | 7844 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7845 | |
44702360 | 7846 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7847 | |
c4093a6a JM |
7848 | return b; |
7849 | } | |
7850 | ||
0101ce28 JJ |
7851 | struct lang_and_radix |
7852 | { | |
7853 | enum language lang; | |
7854 | int radix; | |
7855 | }; | |
7856 | ||
4efc6507 DE |
7857 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7858 | ||
7859 | struct breakpoint * | |
7860 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7861 | { | |
2a7f3dff PA |
7862 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7863 | &internal_breakpoint_ops); | |
4efc6507 | 7864 | } |
0101ce28 | 7865 | |
03673fc7 PP |
7866 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7867 | ||
7868 | void | |
7869 | remove_jit_event_breakpoints (void) | |
7870 | { | |
7871 | struct breakpoint *b, *b_tmp; | |
7872 | ||
7873 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7874 | if (b->type == bp_jit_event | |
7875 | && b->loc->pspace == current_program_space) | |
7876 | delete_breakpoint (b); | |
7877 | } | |
7878 | ||
cae688ec JJ |
7879 | void |
7880 | remove_solib_event_breakpoints (void) | |
7881 | { | |
35df4500 | 7882 | struct breakpoint *b, *b_tmp; |
cae688ec | 7883 | |
35df4500 | 7884 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7885 | if (b->type == bp_shlib_event |
7886 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7887 | delete_breakpoint (b); |
7888 | } | |
7889 | ||
f37f681c PA |
7890 | /* See breakpoint.h. */ |
7891 | ||
7892 | void | |
7893 | remove_solib_event_breakpoints_at_next_stop (void) | |
7894 | { | |
7895 | struct breakpoint *b, *b_tmp; | |
7896 | ||
7897 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7898 | if (b->type == bp_shlib_event | |
7899 | && b->loc->pspace == current_program_space) | |
7900 | b->disposition = disp_del_at_next_stop; | |
7901 | } | |
7902 | ||
04086b45 PA |
7903 | /* Helper for create_solib_event_breakpoint / |
7904 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7905 | INSERT_MODE to pass through to update_global_location_list. */ | |
7906 | ||
7907 | static struct breakpoint * | |
7908 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7909 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7910 | { |
7911 | struct breakpoint *b; | |
7912 | ||
06edf0c0 PA |
7913 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7914 | &internal_breakpoint_ops); | |
04086b45 | 7915 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7916 | return b; |
7917 | } | |
7918 | ||
04086b45 PA |
7919 | struct breakpoint * |
7920 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7921 | { | |
7922 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7923 | } | |
7924 | ||
f37f681c PA |
7925 | /* See breakpoint.h. */ |
7926 | ||
7927 | struct breakpoint * | |
7928 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7929 | { | |
7930 | struct breakpoint *b; | |
7931 | ||
04086b45 PA |
7932 | /* Explicitly tell update_global_location_list to insert |
7933 | locations. */ | |
7934 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7935 | if (!b->loc->inserted) |
7936 | { | |
7937 | delete_breakpoint (b); | |
7938 | return NULL; | |
7939 | } | |
7940 | return b; | |
7941 | } | |
7942 | ||
cae688ec JJ |
7943 | /* Disable any breakpoints that are on code in shared libraries. Only |
7944 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7945 | ||
7946 | void | |
cb851954 | 7947 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7948 | { |
876fa593 | 7949 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7950 | |
876fa593 | 7951 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7952 | { |
2bdf28a0 | 7953 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7954 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7955 | |
4a64f543 MS |
7956 | /* We apply the check to all breakpoints, including disabled for |
7957 | those with loc->duplicate set. This is so that when breakpoint | |
7958 | becomes enabled, or the duplicate is removed, gdb will try to | |
7959 | insert all breakpoints. If we don't set shlib_disabled here, | |
7960 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7961 | if (((b->type == bp_breakpoint) |
508ccb1f | 7962 | || (b->type == bp_jit_event) |
1042e4c0 | 7963 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7964 | || (is_tracepoint (b))) |
6c95b8df | 7965 | && loc->pspace == current_program_space |
0d381245 | 7966 | && !loc->shlib_disabled |
6c95b8df | 7967 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7968 | ) |
0d381245 VP |
7969 | { |
7970 | loc->shlib_disabled = 1; | |
7971 | } | |
cae688ec JJ |
7972 | } |
7973 | } | |
7974 | ||
63644780 NB |
7975 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7976 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7977 | disabled ones can just stay disabled. */ | |
84acb35a | 7978 | |
75149521 | 7979 | static void |
84acb35a JJ |
7980 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7981 | { | |
876fa593 | 7982 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7983 | int disabled_shlib_breaks = 0; |
7984 | ||
c86cf029 VP |
7985 | /* SunOS a.out shared libraries are always mapped, so do not |
7986 | disable breakpoints; they will only be reported as unloaded | |
7987 | through clear_solib when GDB discards its shared library | |
7988 | list. See clear_solib for more information. */ | |
7989 | if (exec_bfd != NULL | |
7990 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7991 | return; | |
7992 | ||
876fa593 | 7993 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7994 | { |
2bdf28a0 | 7995 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7996 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7997 | |
1e4d1764 | 7998 | if (solib->pspace == loc->pspace |
e2dd7057 | 7999 | && !loc->shlib_disabled |
1e4d1764 YQ |
8000 | && (((b->type == bp_breakpoint |
8001 | || b->type == bp_jit_event | |
8002 | || b->type == bp_hardware_breakpoint) | |
8003 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
8004 | || loc->loc_type == bp_loc_software_breakpoint)) | |
8005 | || is_tracepoint (b)) | |
e2dd7057 | 8006 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 8007 | { |
e2dd7057 PP |
8008 | loc->shlib_disabled = 1; |
8009 | /* At this point, we cannot rely on remove_breakpoint | |
8010 | succeeding so we must mark the breakpoint as not inserted | |
8011 | to prevent future errors occurring in remove_breakpoints. */ | |
8012 | loc->inserted = 0; | |
8d3788bd VP |
8013 | |
8014 | /* This may cause duplicate notifications for the same breakpoint. */ | |
8015 | observer_notify_breakpoint_modified (b); | |
8016 | ||
e2dd7057 PP |
8017 | if (!disabled_shlib_breaks) |
8018 | { | |
8019 | target_terminal_ours_for_output (); | |
3e43a32a MS |
8020 | warning (_("Temporarily disabling breakpoints " |
8021 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 8022 | solib->so_name); |
84acb35a | 8023 | } |
e2dd7057 | 8024 | disabled_shlib_breaks = 1; |
84acb35a JJ |
8025 | } |
8026 | } | |
84acb35a JJ |
8027 | } |
8028 | ||
63644780 NB |
8029 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
8030 | notification of free_objfile. Only apply to enabled breakpoints, | |
8031 | disabled ones can just stay disabled. */ | |
8032 | ||
8033 | static void | |
8034 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
8035 | { | |
8036 | struct breakpoint *b; | |
8037 | ||
8038 | if (objfile == NULL) | |
8039 | return; | |
8040 | ||
d03de421 PA |
8041 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
8042 | managed by the user with add-symbol-file/remove-symbol-file. | |
8043 | Similarly to how breakpoints in shared libraries are handled in | |
8044 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
8045 | shlib_disabled so they end up uninserted on the next global |
8046 | location list update. Shared libraries not loaded by the user | |
8047 | aren't handled here -- they're already handled in | |
8048 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
8049 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
8050 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
8051 | main objfile). */ | |
8052 | if ((objfile->flags & OBJF_SHARED) == 0 | |
8053 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
8054 | return; |
8055 | ||
8056 | ALL_BREAKPOINTS (b) | |
8057 | { | |
8058 | struct bp_location *loc; | |
8059 | int bp_modified = 0; | |
8060 | ||
8061 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
8062 | continue; | |
8063 | ||
8064 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
8065 | { | |
8066 | CORE_ADDR loc_addr = loc->address; | |
8067 | ||
8068 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8069 | && loc->loc_type != bp_loc_software_breakpoint) | |
8070 | continue; | |
8071 | ||
8072 | if (loc->shlib_disabled != 0) | |
8073 | continue; | |
8074 | ||
8075 | if (objfile->pspace != loc->pspace) | |
8076 | continue; | |
8077 | ||
8078 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8079 | && loc->loc_type != bp_loc_software_breakpoint) | |
8080 | continue; | |
8081 | ||
8082 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8083 | { | |
8084 | loc->shlib_disabled = 1; | |
08351840 PA |
8085 | /* At this point, we don't know whether the object was |
8086 | unmapped from the inferior or not, so leave the | |
8087 | inserted flag alone. We'll handle failure to | |
8088 | uninsert quietly, in case the object was indeed | |
8089 | unmapped. */ | |
63644780 NB |
8090 | |
8091 | mark_breakpoint_location_modified (loc); | |
8092 | ||
8093 | bp_modified = 1; | |
8094 | } | |
8095 | } | |
8096 | ||
8097 | if (bp_modified) | |
8098 | observer_notify_breakpoint_modified (b); | |
8099 | } | |
8100 | } | |
8101 | ||
ce78b96d JB |
8102 | /* FORK & VFORK catchpoints. */ |
8103 | ||
e29a4733 PA |
8104 | /* An instance of this type is used to represent a fork or vfork |
8105 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8106 | class; users downcast to "struct breakpoint *" when needed. A | |
8107 | breakpoint is really of this type iff its ops pointer points to | |
8108 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8109 | ||
8110 | struct fork_catchpoint | |
8111 | { | |
8112 | /* The base class. */ | |
8113 | struct breakpoint base; | |
8114 | ||
8115 | /* Process id of a child process whose forking triggered this | |
8116 | catchpoint. This field is only valid immediately after this | |
8117 | catchpoint has triggered. */ | |
8118 | ptid_t forked_inferior_pid; | |
8119 | }; | |
8120 | ||
4a64f543 MS |
8121 | /* Implement the "insert" breakpoint_ops method for fork |
8122 | catchpoints. */ | |
ce78b96d | 8123 | |
77b06cd7 TJB |
8124 | static int |
8125 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8126 | { |
dfd4cc63 | 8127 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8128 | } |
8129 | ||
4a64f543 MS |
8130 | /* Implement the "remove" breakpoint_ops method for fork |
8131 | catchpoints. */ | |
ce78b96d JB |
8132 | |
8133 | static int | |
73971819 | 8134 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8135 | { |
dfd4cc63 | 8136 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8137 | } |
8138 | ||
8139 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8140 | catchpoints. */ | |
8141 | ||
8142 | static int | |
f1310107 | 8143 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8144 | struct address_space *aspace, CORE_ADDR bp_addr, |
8145 | const struct target_waitstatus *ws) | |
ce78b96d | 8146 | { |
e29a4733 PA |
8147 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8148 | ||
f90263c1 TT |
8149 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8150 | return 0; | |
8151 | ||
8152 | c->forked_inferior_pid = ws->value.related_pid; | |
8153 | return 1; | |
ce78b96d JB |
8154 | } |
8155 | ||
4a64f543 MS |
8156 | /* Implement the "print_it" breakpoint_ops method for fork |
8157 | catchpoints. */ | |
ce78b96d JB |
8158 | |
8159 | static enum print_stop_action | |
348d480f | 8160 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8161 | { |
36dfb11c | 8162 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8163 | struct breakpoint *b = bs->breakpoint_at; |
8164 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8165 | |
ce78b96d | 8166 | annotate_catchpoint (b->number); |
f303dbd6 | 8167 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8168 | if (b->disposition == disp_del) |
f303dbd6 | 8169 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8170 | else |
f303dbd6 | 8171 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8172 | if (ui_out_is_mi_like_p (uiout)) |
8173 | { | |
8174 | ui_out_field_string (uiout, "reason", | |
8175 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8176 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8177 | } | |
8178 | ui_out_field_int (uiout, "bkptno", b->number); | |
8179 | ui_out_text (uiout, " (forked process "); | |
8180 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8181 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8182 | return PRINT_SRC_AND_LOC; |
8183 | } | |
8184 | ||
4a64f543 MS |
8185 | /* Implement the "print_one" breakpoint_ops method for fork |
8186 | catchpoints. */ | |
ce78b96d JB |
8187 | |
8188 | static void | |
a6d9a66e | 8189 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8190 | { |
e29a4733 | 8191 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8192 | struct value_print_options opts; |
79a45e25 | 8193 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8194 | |
8195 | get_user_print_options (&opts); | |
8196 | ||
4a64f543 MS |
8197 | /* Field 4, the address, is omitted (which makes the columns not |
8198 | line up too nicely with the headers, but the effect is relatively | |
8199 | readable). */ | |
79a45b7d | 8200 | if (opts.addressprint) |
ce78b96d JB |
8201 | ui_out_field_skip (uiout, "addr"); |
8202 | annotate_field (5); | |
8203 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8204 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8205 | { |
8206 | ui_out_text (uiout, ", process "); | |
8207 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8208 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8209 | ui_out_spaces (uiout, 1); |
8210 | } | |
8ac3646f TT |
8211 | |
8212 | if (ui_out_is_mi_like_p (uiout)) | |
8213 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8214 | } |
8215 | ||
8216 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8217 | catchpoints. */ | |
8218 | ||
8219 | static void | |
8220 | print_mention_catch_fork (struct breakpoint *b) | |
8221 | { | |
8222 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8223 | } | |
8224 | ||
6149aea9 PA |
8225 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8226 | catchpoints. */ | |
8227 | ||
8228 | static void | |
8229 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8230 | { | |
8231 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8232 | print_recreate_thread (b, fp); |
6149aea9 PA |
8233 | } |
8234 | ||
ce78b96d JB |
8235 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8236 | ||
2060206e | 8237 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8238 | |
4a64f543 MS |
8239 | /* Implement the "insert" breakpoint_ops method for vfork |
8240 | catchpoints. */ | |
ce78b96d | 8241 | |
77b06cd7 TJB |
8242 | static int |
8243 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8244 | { |
dfd4cc63 | 8245 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8246 | } |
8247 | ||
4a64f543 MS |
8248 | /* Implement the "remove" breakpoint_ops method for vfork |
8249 | catchpoints. */ | |
ce78b96d JB |
8250 | |
8251 | static int | |
73971819 | 8252 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8253 | { |
dfd4cc63 | 8254 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8255 | } |
8256 | ||
8257 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8258 | catchpoints. */ | |
8259 | ||
8260 | static int | |
f1310107 | 8261 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8262 | struct address_space *aspace, CORE_ADDR bp_addr, |
8263 | const struct target_waitstatus *ws) | |
ce78b96d | 8264 | { |
e29a4733 PA |
8265 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8266 | ||
f90263c1 TT |
8267 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8268 | return 0; | |
8269 | ||
8270 | c->forked_inferior_pid = ws->value.related_pid; | |
8271 | return 1; | |
ce78b96d JB |
8272 | } |
8273 | ||
4a64f543 MS |
8274 | /* Implement the "print_it" breakpoint_ops method for vfork |
8275 | catchpoints. */ | |
ce78b96d JB |
8276 | |
8277 | static enum print_stop_action | |
348d480f | 8278 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8279 | { |
36dfb11c | 8280 | struct ui_out *uiout = current_uiout; |
348d480f | 8281 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8282 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8283 | ||
ce78b96d | 8284 | annotate_catchpoint (b->number); |
f303dbd6 | 8285 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8286 | if (b->disposition == disp_del) |
f303dbd6 | 8287 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8288 | else |
f303dbd6 | 8289 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8290 | if (ui_out_is_mi_like_p (uiout)) |
8291 | { | |
8292 | ui_out_field_string (uiout, "reason", | |
8293 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8294 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8295 | } | |
8296 | ui_out_field_int (uiout, "bkptno", b->number); | |
8297 | ui_out_text (uiout, " (vforked process "); | |
8298 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8299 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8300 | return PRINT_SRC_AND_LOC; |
8301 | } | |
8302 | ||
4a64f543 MS |
8303 | /* Implement the "print_one" breakpoint_ops method for vfork |
8304 | catchpoints. */ | |
ce78b96d JB |
8305 | |
8306 | static void | |
a6d9a66e | 8307 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8308 | { |
e29a4733 | 8309 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8310 | struct value_print_options opts; |
79a45e25 | 8311 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8312 | |
8313 | get_user_print_options (&opts); | |
4a64f543 MS |
8314 | /* Field 4, the address, is omitted (which makes the columns not |
8315 | line up too nicely with the headers, but the effect is relatively | |
8316 | readable). */ | |
79a45b7d | 8317 | if (opts.addressprint) |
ce78b96d JB |
8318 | ui_out_field_skip (uiout, "addr"); |
8319 | annotate_field (5); | |
8320 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8321 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8322 | { |
8323 | ui_out_text (uiout, ", process "); | |
8324 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8325 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8326 | ui_out_spaces (uiout, 1); |
8327 | } | |
8ac3646f TT |
8328 | |
8329 | if (ui_out_is_mi_like_p (uiout)) | |
8330 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8331 | } |
8332 | ||
8333 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8334 | catchpoints. */ | |
8335 | ||
8336 | static void | |
8337 | print_mention_catch_vfork (struct breakpoint *b) | |
8338 | { | |
8339 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8340 | } | |
8341 | ||
6149aea9 PA |
8342 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8343 | catchpoints. */ | |
8344 | ||
8345 | static void | |
8346 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8347 | { | |
8348 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8349 | print_recreate_thread (b, fp); |
6149aea9 PA |
8350 | } |
8351 | ||
ce78b96d JB |
8352 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8353 | ||
2060206e | 8354 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8355 | |
edcc5120 TT |
8356 | /* An instance of this type is used to represent an solib catchpoint. |
8357 | It includes a "struct breakpoint" as a kind of base class; users | |
8358 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8359 | really of this type iff its ops pointer points to | |
8360 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8361 | ||
8362 | struct solib_catchpoint | |
8363 | { | |
8364 | /* The base class. */ | |
8365 | struct breakpoint base; | |
8366 | ||
8367 | /* True for "catch load", false for "catch unload". */ | |
8368 | unsigned char is_load; | |
8369 | ||
8370 | /* Regular expression to match, if any. COMPILED is only valid when | |
8371 | REGEX is non-NULL. */ | |
8372 | char *regex; | |
8373 | regex_t compiled; | |
8374 | }; | |
8375 | ||
8376 | static void | |
8377 | dtor_catch_solib (struct breakpoint *b) | |
8378 | { | |
8379 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8380 | ||
8381 | if (self->regex) | |
8382 | regfree (&self->compiled); | |
8383 | xfree (self->regex); | |
8384 | ||
8385 | base_breakpoint_ops.dtor (b); | |
8386 | } | |
8387 | ||
8388 | static int | |
8389 | insert_catch_solib (struct bp_location *ignore) | |
8390 | { | |
8391 | return 0; | |
8392 | } | |
8393 | ||
8394 | static int | |
73971819 | 8395 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8396 | { |
8397 | return 0; | |
8398 | } | |
8399 | ||
8400 | static int | |
8401 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8402 | struct address_space *aspace, | |
8403 | CORE_ADDR bp_addr, | |
8404 | const struct target_waitstatus *ws) | |
8405 | { | |
8406 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8407 | struct breakpoint *other; | |
8408 | ||
8409 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8410 | return 1; | |
8411 | ||
8412 | ALL_BREAKPOINTS (other) | |
8413 | { | |
8414 | struct bp_location *other_bl; | |
8415 | ||
8416 | if (other == bl->owner) | |
8417 | continue; | |
8418 | ||
8419 | if (other->type != bp_shlib_event) | |
8420 | continue; | |
8421 | ||
8422 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8423 | continue; | |
8424 | ||
8425 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8426 | { | |
8427 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8428 | return 1; | |
8429 | } | |
8430 | } | |
8431 | ||
8432 | return 0; | |
8433 | } | |
8434 | ||
8435 | static void | |
8436 | check_status_catch_solib (struct bpstats *bs) | |
8437 | { | |
8438 | struct solib_catchpoint *self | |
8439 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8440 | int ix; | |
8441 | ||
8442 | if (self->is_load) | |
8443 | { | |
8444 | struct so_list *iter; | |
8445 | ||
8446 | for (ix = 0; | |
8447 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8448 | ix, iter); | |
8449 | ++ix) | |
8450 | { | |
8451 | if (!self->regex | |
8452 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8453 | return; | |
8454 | } | |
8455 | } | |
8456 | else | |
8457 | { | |
8458 | char *iter; | |
8459 | ||
8460 | for (ix = 0; | |
8461 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8462 | ix, iter); | |
8463 | ++ix) | |
8464 | { | |
8465 | if (!self->regex | |
8466 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8467 | return; | |
8468 | } | |
8469 | } | |
8470 | ||
8471 | bs->stop = 0; | |
8472 | bs->print_it = print_it_noop; | |
8473 | } | |
8474 | ||
8475 | static enum print_stop_action | |
8476 | print_it_catch_solib (bpstat bs) | |
8477 | { | |
8478 | struct breakpoint *b = bs->breakpoint_at; | |
8479 | struct ui_out *uiout = current_uiout; | |
8480 | ||
8481 | annotate_catchpoint (b->number); | |
f303dbd6 | 8482 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8483 | if (b->disposition == disp_del) |
f303dbd6 | 8484 | ui_out_text (uiout, "Temporary catchpoint "); |
edcc5120 | 8485 | else |
f303dbd6 | 8486 | ui_out_text (uiout, "Catchpoint "); |
edcc5120 TT |
8487 | ui_out_field_int (uiout, "bkptno", b->number); |
8488 | ui_out_text (uiout, "\n"); | |
8489 | if (ui_out_is_mi_like_p (uiout)) | |
8490 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8491 | print_solib_event (1); | |
8492 | return PRINT_SRC_AND_LOC; | |
8493 | } | |
8494 | ||
8495 | static void | |
8496 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8497 | { | |
8498 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8499 | struct value_print_options opts; | |
8500 | struct ui_out *uiout = current_uiout; | |
8501 | char *msg; | |
8502 | ||
8503 | get_user_print_options (&opts); | |
8504 | /* Field 4, the address, is omitted (which makes the columns not | |
8505 | line up too nicely with the headers, but the effect is relatively | |
8506 | readable). */ | |
8507 | if (opts.addressprint) | |
8508 | { | |
8509 | annotate_field (4); | |
8510 | ui_out_field_skip (uiout, "addr"); | |
8511 | } | |
8512 | ||
8513 | annotate_field (5); | |
8514 | if (self->is_load) | |
8515 | { | |
8516 | if (self->regex) | |
8517 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8518 | else | |
8519 | msg = xstrdup (_("load of library")); | |
8520 | } | |
8521 | else | |
8522 | { | |
8523 | if (self->regex) | |
8524 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8525 | else | |
8526 | msg = xstrdup (_("unload of library")); | |
8527 | } | |
8528 | ui_out_field_string (uiout, "what", msg); | |
8529 | xfree (msg); | |
8ac3646f TT |
8530 | |
8531 | if (ui_out_is_mi_like_p (uiout)) | |
8532 | ui_out_field_string (uiout, "catch-type", | |
8533 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8534 | } |
8535 | ||
8536 | static void | |
8537 | print_mention_catch_solib (struct breakpoint *b) | |
8538 | { | |
8539 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8540 | ||
8541 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8542 | self->is_load ? "load" : "unload"); | |
8543 | } | |
8544 | ||
8545 | static void | |
8546 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8547 | { | |
8548 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8549 | ||
8550 | fprintf_unfiltered (fp, "%s %s", | |
8551 | b->disposition == disp_del ? "tcatch" : "catch", | |
8552 | self->is_load ? "load" : "unload"); | |
8553 | if (self->regex) | |
8554 | fprintf_unfiltered (fp, " %s", self->regex); | |
8555 | fprintf_unfiltered (fp, "\n"); | |
8556 | } | |
8557 | ||
8558 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8559 | ||
91985142 MG |
8560 | /* Shared helper function (MI and CLI) for creating and installing |
8561 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8562 | the events to be caught are load events, otherwise they are | |
8563 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8564 | temporary one. If ENABLED is non-zero the catchpoint is | |
8565 | created in an enabled state. */ | |
edcc5120 | 8566 | |
91985142 MG |
8567 | void |
8568 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8569 | { |
8570 | struct solib_catchpoint *c; | |
8571 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8572 | struct cleanup *cleanup; |
8573 | ||
edcc5120 TT |
8574 | if (!arg) |
8575 | arg = ""; | |
8576 | arg = skip_spaces (arg); | |
8577 | ||
8578 | c = XCNEW (struct solib_catchpoint); | |
8579 | cleanup = make_cleanup (xfree, c); | |
8580 | ||
8581 | if (*arg != '\0') | |
8582 | { | |
8583 | int errcode; | |
8584 | ||
8585 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8586 | if (errcode != 0) | |
8587 | { | |
8588 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8589 | ||
8590 | make_cleanup (xfree, err); | |
8591 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8592 | } | |
8593 | c->regex = xstrdup (arg); | |
8594 | } | |
8595 | ||
8596 | c->is_load = is_load; | |
91985142 | 8597 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8598 | &catch_solib_breakpoint_ops); |
8599 | ||
91985142 MG |
8600 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8601 | ||
edcc5120 TT |
8602 | discard_cleanups (cleanup); |
8603 | install_breakpoint (0, &c->base, 1); | |
8604 | } | |
8605 | ||
91985142 MG |
8606 | /* A helper function that does all the work for "catch load" and |
8607 | "catch unload". */ | |
8608 | ||
8609 | static void | |
8610 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8611 | struct cmd_list_element *command) | |
8612 | { | |
8613 | int tempflag; | |
8614 | const int enabled = 1; | |
8615 | ||
8616 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8617 | ||
8618 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8619 | } | |
8620 | ||
edcc5120 TT |
8621 | static void |
8622 | catch_load_command_1 (char *arg, int from_tty, | |
8623 | struct cmd_list_element *command) | |
8624 | { | |
8625 | catch_load_or_unload (arg, from_tty, 1, command); | |
8626 | } | |
8627 | ||
8628 | static void | |
8629 | catch_unload_command_1 (char *arg, int from_tty, | |
8630 | struct cmd_list_element *command) | |
8631 | { | |
8632 | catch_load_or_unload (arg, from_tty, 0, command); | |
8633 | } | |
8634 | ||
346774a9 PA |
8635 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8636 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8637 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8638 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8639 | |
ab04a2af | 8640 | void |
346774a9 PA |
8641 | init_catchpoint (struct breakpoint *b, |
8642 | struct gdbarch *gdbarch, int tempflag, | |
8643 | char *cond_string, | |
c0a91b2b | 8644 | const struct breakpoint_ops *ops) |
c906108c | 8645 | { |
c5aa993b | 8646 | struct symtab_and_line sal; |
346774a9 | 8647 | |
fe39c653 | 8648 | init_sal (&sal); |
6c95b8df | 8649 | sal.pspace = current_program_space; |
c5aa993b | 8650 | |
28010a5d | 8651 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8652 | |
1b36a34b | 8653 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8654 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8655 | } |
8656 | ||
28010a5d | 8657 | void |
3ea46bff | 8658 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8659 | { |
8660 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8661 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8662 | if (is_tracepoint (b)) |
8663 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8664 | if (!internal) |
8665 | mention (b); | |
c56053d2 | 8666 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8667 | |
8668 | if (update_gll) | |
44702360 | 8669 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8670 | } |
8671 | ||
9b70b993 | 8672 | static void |
a6d9a66e UW |
8673 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8674 | int tempflag, char *cond_string, | |
c0a91b2b | 8675 | const struct breakpoint_ops *ops) |
c906108c | 8676 | { |
e29a4733 | 8677 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8678 | |
e29a4733 PA |
8679 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8680 | ||
8681 | c->forked_inferior_pid = null_ptid; | |
8682 | ||
3ea46bff | 8683 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8684 | } |
8685 | ||
fe798b75 JB |
8686 | /* Exec catchpoints. */ |
8687 | ||
b4d90040 PA |
8688 | /* An instance of this type is used to represent an exec catchpoint. |
8689 | It includes a "struct breakpoint" as a kind of base class; users | |
8690 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8691 | really of this type iff its ops pointer points to | |
8692 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8693 | ||
8694 | struct exec_catchpoint | |
8695 | { | |
8696 | /* The base class. */ | |
8697 | struct breakpoint base; | |
8698 | ||
8699 | /* Filename of a program whose exec triggered this catchpoint. | |
8700 | This field is only valid immediately after this catchpoint has | |
8701 | triggered. */ | |
8702 | char *exec_pathname; | |
8703 | }; | |
8704 | ||
8705 | /* Implement the "dtor" breakpoint_ops method for exec | |
8706 | catchpoints. */ | |
8707 | ||
8708 | static void | |
8709 | dtor_catch_exec (struct breakpoint *b) | |
8710 | { | |
8711 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8712 | ||
8713 | xfree (c->exec_pathname); | |
348d480f | 8714 | |
2060206e | 8715 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8716 | } |
8717 | ||
77b06cd7 TJB |
8718 | static int |
8719 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8720 | { |
dfd4cc63 | 8721 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8722 | } |
c906108c | 8723 | |
fe798b75 | 8724 | static int |
73971819 | 8725 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8726 | { |
dfd4cc63 | 8727 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8728 | } |
c906108c | 8729 | |
fe798b75 | 8730 | static int |
f1310107 | 8731 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8732 | struct address_space *aspace, CORE_ADDR bp_addr, |
8733 | const struct target_waitstatus *ws) | |
fe798b75 | 8734 | { |
b4d90040 PA |
8735 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8736 | ||
f90263c1 TT |
8737 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8738 | return 0; | |
8739 | ||
8740 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8741 | return 1; | |
fe798b75 | 8742 | } |
c906108c | 8743 | |
fe798b75 | 8744 | static enum print_stop_action |
348d480f | 8745 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8746 | { |
36dfb11c | 8747 | struct ui_out *uiout = current_uiout; |
348d480f | 8748 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8749 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8750 | ||
fe798b75 | 8751 | annotate_catchpoint (b->number); |
f303dbd6 | 8752 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8753 | if (b->disposition == disp_del) |
f303dbd6 | 8754 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8755 | else |
f303dbd6 | 8756 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8757 | if (ui_out_is_mi_like_p (uiout)) |
8758 | { | |
8759 | ui_out_field_string (uiout, "reason", | |
8760 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8761 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8762 | } | |
8763 | ui_out_field_int (uiout, "bkptno", b->number); | |
8764 | ui_out_text (uiout, " (exec'd "); | |
8765 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8766 | ui_out_text (uiout, "), "); | |
8767 | ||
fe798b75 | 8768 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8769 | } |
8770 | ||
fe798b75 | 8771 | static void |
a6d9a66e | 8772 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8773 | { |
b4d90040 | 8774 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8775 | struct value_print_options opts; |
79a45e25 | 8776 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8777 | |
8778 | get_user_print_options (&opts); | |
8779 | ||
8780 | /* Field 4, the address, is omitted (which makes the columns | |
8781 | not line up too nicely with the headers, but the effect | |
8782 | is relatively readable). */ | |
8783 | if (opts.addressprint) | |
8784 | ui_out_field_skip (uiout, "addr"); | |
8785 | annotate_field (5); | |
8786 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8787 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8788 | { |
8789 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8790 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8791 | ui_out_text (uiout, "\" "); |
8792 | } | |
8ac3646f TT |
8793 | |
8794 | if (ui_out_is_mi_like_p (uiout)) | |
8795 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8796 | } |
8797 | ||
8798 | static void | |
8799 | print_mention_catch_exec (struct breakpoint *b) | |
8800 | { | |
8801 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8802 | } | |
8803 | ||
6149aea9 PA |
8804 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8805 | catchpoints. */ | |
8806 | ||
8807 | static void | |
8808 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8809 | { | |
8810 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8811 | print_recreate_thread (b, fp); |
6149aea9 PA |
8812 | } |
8813 | ||
2060206e | 8814 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8815 | |
c906108c | 8816 | static int |
fba45db2 | 8817 | hw_breakpoint_used_count (void) |
c906108c | 8818 | { |
c906108c | 8819 | int i = 0; |
f1310107 TJB |
8820 | struct breakpoint *b; |
8821 | struct bp_location *bl; | |
c906108c SS |
8822 | |
8823 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8824 | { |
d6b74ac4 | 8825 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8826 | for (bl = b->loc; bl; bl = bl->next) |
8827 | { | |
8828 | /* Special types of hardware breakpoints may use more than | |
8829 | one register. */ | |
348d480f | 8830 | i += b->ops->resources_needed (bl); |
f1310107 | 8831 | } |
c5aa993b | 8832 | } |
c906108c SS |
8833 | |
8834 | return i; | |
8835 | } | |
8836 | ||
a1398e0c PA |
8837 | /* Returns the resources B would use if it were a hardware |
8838 | watchpoint. */ | |
8839 | ||
c906108c | 8840 | static int |
a1398e0c | 8841 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8842 | { |
c906108c | 8843 | int i = 0; |
e09342b5 | 8844 | struct bp_location *bl; |
c906108c | 8845 | |
a1398e0c PA |
8846 | if (!breakpoint_enabled (b)) |
8847 | return 0; | |
8848 | ||
8849 | for (bl = b->loc; bl; bl = bl->next) | |
8850 | { | |
8851 | /* Special types of hardware watchpoints may use more than | |
8852 | one register. */ | |
8853 | i += b->ops->resources_needed (bl); | |
8854 | } | |
8855 | ||
8856 | return i; | |
8857 | } | |
8858 | ||
8859 | /* Returns the sum the used resources of all hardware watchpoints of | |
8860 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8861 | the sum of the used resources of all hardware watchpoints of other | |
8862 | types _not_ TYPE. */ | |
8863 | ||
8864 | static int | |
8865 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8866 | enum bptype type, int *other_type_used) | |
8867 | { | |
8868 | int i = 0; | |
8869 | struct breakpoint *b; | |
8870 | ||
c906108c SS |
8871 | *other_type_used = 0; |
8872 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8873 | { |
a1398e0c PA |
8874 | if (b == except) |
8875 | continue; | |
e09342b5 TJB |
8876 | if (!breakpoint_enabled (b)) |
8877 | continue; | |
8878 | ||
a1398e0c PA |
8879 | if (b->type == type) |
8880 | i += hw_watchpoint_use_count (b); | |
8881 | else if (is_hardware_watchpoint (b)) | |
8882 | *other_type_used = 1; | |
e09342b5 TJB |
8883 | } |
8884 | ||
c906108c SS |
8885 | return i; |
8886 | } | |
8887 | ||
c906108c | 8888 | void |
fba45db2 | 8889 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8890 | { |
c5aa993b | 8891 | struct breakpoint *b; |
c906108c SS |
8892 | |
8893 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8894 | { |
cc60f2e3 | 8895 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8896 | { |
b5de0fa7 | 8897 | b->enable_state = bp_call_disabled; |
44702360 | 8898 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8899 | } |
8900 | } | |
c906108c SS |
8901 | } |
8902 | ||
8903 | void | |
fba45db2 | 8904 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8905 | { |
c5aa993b | 8906 | struct breakpoint *b; |
c906108c SS |
8907 | |
8908 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8909 | { |
cc60f2e3 | 8910 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8911 | { |
b5de0fa7 | 8912 | b->enable_state = bp_enabled; |
44702360 | 8913 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8914 | } |
8915 | } | |
c906108c SS |
8916 | } |
8917 | ||
8bea4e01 UW |
8918 | void |
8919 | disable_breakpoints_before_startup (void) | |
8920 | { | |
6c95b8df | 8921 | current_program_space->executing_startup = 1; |
44702360 | 8922 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8923 | } |
8924 | ||
8925 | void | |
8926 | enable_breakpoints_after_startup (void) | |
8927 | { | |
6c95b8df | 8928 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8929 | breakpoint_re_set (); |
8bea4e01 UW |
8930 | } |
8931 | ||
7c16b83e PA |
8932 | /* Create a new single-step breakpoint for thread THREAD, with no |
8933 | locations. */ | |
c906108c | 8934 | |
7c16b83e PA |
8935 | static struct breakpoint * |
8936 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8937 | { | |
8938 | struct breakpoint *b = XNEW (struct breakpoint); | |
8939 | ||
8940 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8941 | &momentary_breakpoint_ops); | |
8942 | ||
8943 | b->disposition = disp_donttouch; | |
8944 | b->frame_id = null_frame_id; | |
8945 | ||
8946 | b->thread = thread; | |
8947 | gdb_assert (b->thread != 0); | |
8948 | ||
8949 | add_to_breakpoint_chain (b); | |
8950 | ||
8951 | return b; | |
8952 | } | |
8953 | ||
8954 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8955 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8956 | frame. */ | |
c906108c SS |
8957 | |
8958 | struct breakpoint * | |
a6d9a66e UW |
8959 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8960 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8961 | { |
52f0bd74 | 8962 | struct breakpoint *b; |
edb3359d | 8963 | |
193facb3 JK |
8964 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8965 | tail-called one. */ | |
8966 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8967 | |
06edf0c0 | 8968 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8969 | b->enable_state = bp_enabled; |
8970 | b->disposition = disp_donttouch; | |
818dd999 | 8971 | b->frame_id = frame_id; |
c906108c | 8972 | |
4a64f543 MS |
8973 | /* If we're debugging a multi-threaded program, then we want |
8974 | momentary breakpoints to be active in only a single thread of | |
8975 | control. */ | |
39f77062 | 8976 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8977 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8978 | |
44702360 | 8979 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8980 | |
c906108c SS |
8981 | return b; |
8982 | } | |
611c83ae | 8983 | |
06edf0c0 | 8984 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8985 | The new breakpoint will have type TYPE, use OPS as its |
8986 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8987 | |
06edf0c0 PA |
8988 | static struct breakpoint * |
8989 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8990 | enum bptype type, | |
a1aa2221 LM |
8991 | const struct breakpoint_ops *ops, |
8992 | int loc_enabled) | |
e58b0e63 PA |
8993 | { |
8994 | struct breakpoint *copy; | |
8995 | ||
06edf0c0 | 8996 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8997 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8998 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8999 | |
a6d9a66e | 9000 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
9001 | copy->loc->requested_address = orig->loc->requested_address; |
9002 | copy->loc->address = orig->loc->address; | |
9003 | copy->loc->section = orig->loc->section; | |
6c95b8df | 9004 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 9005 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 9006 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 9007 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 9008 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
9009 | copy->frame_id = orig->frame_id; |
9010 | copy->thread = orig->thread; | |
6c95b8df | 9011 | copy->pspace = orig->pspace; |
e58b0e63 PA |
9012 | |
9013 | copy->enable_state = bp_enabled; | |
9014 | copy->disposition = disp_donttouch; | |
9015 | copy->number = internal_breakpoint_number--; | |
9016 | ||
44702360 | 9017 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
9018 | return copy; |
9019 | } | |
9020 | ||
06edf0c0 PA |
9021 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9022 | ORIG is NULL. */ | |
9023 | ||
9024 | struct breakpoint * | |
9025 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9026 | { | |
9027 | /* If there's nothing to clone, then return nothing. */ | |
9028 | if (orig == NULL) | |
9029 | return NULL; | |
9030 | ||
a1aa2221 | 9031 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
9032 | } |
9033 | ||
611c83ae | 9034 | struct breakpoint * |
a6d9a66e UW |
9035 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9036 | enum bptype type) | |
611c83ae PA |
9037 | { |
9038 | struct symtab_and_line sal; | |
9039 | ||
9040 | sal = find_pc_line (pc, 0); | |
9041 | sal.pc = pc; | |
9042 | sal.section = find_pc_overlay (pc); | |
9043 | sal.explicit_pc = 1; | |
9044 | ||
a6d9a66e | 9045 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9046 | } |
c906108c | 9047 | \f |
c5aa993b | 9048 | |
c906108c SS |
9049 | /* Tell the user we have just set a breakpoint B. */ |
9050 | ||
9051 | static void | |
fba45db2 | 9052 | mention (struct breakpoint *b) |
c906108c | 9053 | { |
348d480f | 9054 | b->ops->print_mention (b); |
79a45e25 | 9055 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9056 | return; |
c906108c SS |
9057 | printf_filtered ("\n"); |
9058 | } | |
c906108c | 9059 | \f |
c5aa993b | 9060 | |
1a853c52 PA |
9061 | static int bp_loc_is_permanent (struct bp_location *loc); |
9062 | ||
0d381245 | 9063 | static struct bp_location * |
39d61571 | 9064 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9065 | const struct symtab_and_line *sal) |
9066 | { | |
9067 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9068 | CORE_ADDR adjusted_address; |
9069 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9070 | ||
9071 | if (loc_gdbarch == NULL) | |
9072 | loc_gdbarch = b->gdbarch; | |
9073 | ||
9074 | /* Adjust the breakpoint's address prior to allocating a location. | |
9075 | Once we call allocate_bp_location(), that mostly uninitialized | |
9076 | location will be placed on the location chain. Adjustment of the | |
9077 | breakpoint may cause target_read_memory() to be called and we do | |
9078 | not want its scan of the location chain to find a breakpoint and | |
9079 | location that's only been partially initialized. */ | |
9080 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9081 | sal->pc, b->type); | |
0d381245 | 9082 | |
d30113d4 | 9083 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9084 | loc = allocate_bp_location (b); |
d30113d4 JK |
9085 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9086 | tmp = &((*tmp)->next)) | |
0d381245 | 9087 | ; |
d30113d4 | 9088 | loc->next = *tmp; |
0d381245 | 9089 | *tmp = loc; |
3742cc8b | 9090 | |
0d381245 | 9091 | loc->requested_address = sal->pc; |
3742cc8b | 9092 | loc->address = adjusted_address; |
6c95b8df | 9093 | loc->pspace = sal->pspace; |
729662a5 TT |
9094 | loc->probe.probe = sal->probe; |
9095 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9096 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9097 | loc->section = sal->section; |
3742cc8b | 9098 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9099 | loc->line_number = sal->line; |
2f202fde | 9100 | loc->symtab = sal->symtab; |
f8eba3c6 | 9101 | |
0e30163f JK |
9102 | set_breakpoint_location_function (loc, |
9103 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9104 | |
6ae88661 LM |
9105 | /* While by definition, permanent breakpoints are already present in the |
9106 | code, we don't mark the location as inserted. Normally one would expect | |
9107 | that GDB could rely on that breakpoint instruction to stop the program, | |
9108 | thus removing the need to insert its own breakpoint, except that executing | |
9109 | the breakpoint instruction can kill the target instead of reporting a | |
9110 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9111 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9112 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9113 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9114 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9115 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9116 | it manually increments the PC, thus avoiding executing the breakpoint | |
9117 | instruction.) */ | |
1a853c52 | 9118 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9119 | loc->permanent = 1; |
1a853c52 | 9120 | |
0d381245 VP |
9121 | return loc; |
9122 | } | |
514f746b AR |
9123 | \f |
9124 | ||
1cf4d951 | 9125 | /* See breakpoint.h. */ |
514f746b | 9126 | |
1cf4d951 PA |
9127 | int |
9128 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9129 | { |
9130 | int len; | |
9131 | CORE_ADDR addr; | |
1afeeb75 | 9132 | const gdb_byte *bpoint; |
514f746b | 9133 | gdb_byte *target_mem; |
939c61fa JK |
9134 | struct cleanup *cleanup; |
9135 | int retval = 0; | |
514f746b | 9136 | |
1cf4d951 PA |
9137 | addr = address; |
9138 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9139 | ||
9140 | /* Software breakpoints unsupported? */ | |
9141 | if (bpoint == NULL) | |
9142 | return 0; | |
9143 | ||
224c3ddb | 9144 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9145 | |
9146 | /* Enable the automatic memory restoration from breakpoints while | |
9147 | we read the memory. Otherwise we could say about our temporary | |
9148 | breakpoints they are permanent. */ | |
9149 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9150 | ||
9151 | if (target_read_memory (address, target_mem, len) == 0 | |
9152 | && memcmp (target_mem, bpoint, len) == 0) | |
9153 | retval = 1; | |
9154 | ||
9155 | do_cleanups (cleanup); | |
9156 | ||
9157 | return retval; | |
9158 | } | |
9159 | ||
9160 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9161 | return 0 otherwise. */ | |
9162 | ||
9163 | static int | |
9164 | bp_loc_is_permanent (struct bp_location *loc) | |
9165 | { | |
9166 | struct cleanup *cleanup; | |
9167 | int retval; | |
9168 | ||
514f746b AR |
9169 | gdb_assert (loc != NULL); |
9170 | ||
244558af LM |
9171 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9172 | attempt to read from the addresses the locations of these breakpoint types | |
9173 | point to. program_breakpoint_here_p, below, will attempt to read | |
9174 | memory. */ | |
9175 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9176 | return 0; | |
9177 | ||
6c95b8df | 9178 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9179 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9180 | |
1cf4d951 | 9181 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9182 | |
939c61fa JK |
9183 | do_cleanups (cleanup); |
9184 | ||
9185 | return retval; | |
514f746b AR |
9186 | } |
9187 | ||
e7e0cddf SS |
9188 | /* Build a command list for the dprintf corresponding to the current |
9189 | settings of the dprintf style options. */ | |
9190 | ||
9191 | static void | |
9192 | update_dprintf_command_list (struct breakpoint *b) | |
9193 | { | |
9194 | char *dprintf_args = b->extra_string; | |
9195 | char *printf_line = NULL; | |
9196 | ||
9197 | if (!dprintf_args) | |
9198 | return; | |
9199 | ||
9200 | dprintf_args = skip_spaces (dprintf_args); | |
9201 | ||
9202 | /* Allow a comma, as it may have terminated a location, but don't | |
9203 | insist on it. */ | |
9204 | if (*dprintf_args == ',') | |
9205 | ++dprintf_args; | |
9206 | dprintf_args = skip_spaces (dprintf_args); | |
9207 | ||
9208 | if (*dprintf_args != '"') | |
9209 | error (_("Bad format string, missing '\"'.")); | |
9210 | ||
d3ce09f5 | 9211 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9212 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9213 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9214 | { |
9215 | if (!dprintf_function) | |
9216 | error (_("No function supplied for dprintf call")); | |
9217 | ||
9218 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9219 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9220 | dprintf_function, | |
9221 | dprintf_channel, | |
9222 | dprintf_args); | |
9223 | else | |
9224 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9225 | dprintf_function, | |
9226 | dprintf_args); | |
9227 | } | |
d3ce09f5 SS |
9228 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9229 | { | |
9230 | if (target_can_run_breakpoint_commands ()) | |
9231 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9232 | else | |
9233 | { | |
9234 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9235 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9236 | } | |
9237 | } | |
e7e0cddf SS |
9238 | else |
9239 | internal_error (__FILE__, __LINE__, | |
9240 | _("Invalid dprintf style.")); | |
9241 | ||
f28045c2 | 9242 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9243 | /* Manufacture a printf sequence. */ |
f28045c2 | 9244 | { |
8d749320 | 9245 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9246 | |
f28045c2 YQ |
9247 | printf_cmd_line->control_type = simple_control; |
9248 | printf_cmd_line->body_count = 0; | |
9249 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9250 | printf_cmd_line->next = NULL; |
f28045c2 | 9251 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9252 | |
f28045c2 YQ |
9253 | breakpoint_set_commands (b, printf_cmd_line); |
9254 | } | |
e7e0cddf SS |
9255 | } |
9256 | ||
9257 | /* Update all dprintf commands, making their command lists reflect | |
9258 | current style settings. */ | |
9259 | ||
9260 | static void | |
9261 | update_dprintf_commands (char *args, int from_tty, | |
9262 | struct cmd_list_element *c) | |
9263 | { | |
9264 | struct breakpoint *b; | |
9265 | ||
9266 | ALL_BREAKPOINTS (b) | |
9267 | { | |
9268 | if (b->type == bp_dprintf) | |
9269 | update_dprintf_command_list (b); | |
9270 | } | |
9271 | } | |
c3f6f71d | 9272 | |
f00aae0f KS |
9273 | /* Create a breakpoint with SAL as location. Use LOCATION |
9274 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9275 | as condition expression. If LOCATION is NULL then create an |
9276 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9277 | |
9278 | static void | |
d9b3f62e | 9279 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f KS |
9280 | struct symtabs_and_lines sals, |
9281 | struct event_location *location, | |
f8eba3c6 | 9282 | char *filter, char *cond_string, |
e7e0cddf | 9283 | char *extra_string, |
d9b3f62e PA |
9284 | enum bptype type, enum bpdisp disposition, |
9285 | int thread, int task, int ignore_count, | |
c0a91b2b | 9286 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9287 | int enabled, int internal, unsigned flags, |
9288 | int display_canonical) | |
018d34a4 | 9289 | { |
0d381245 | 9290 | int i; |
018d34a4 VP |
9291 | |
9292 | if (type == bp_hardware_breakpoint) | |
9293 | { | |
fbbd034e AS |
9294 | int target_resources_ok; |
9295 | ||
9296 | i = hw_breakpoint_used_count (); | |
9297 | target_resources_ok = | |
9298 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9299 | i + 1, 0); |
9300 | if (target_resources_ok == 0) | |
9301 | error (_("No hardware breakpoint support in the target.")); | |
9302 | else if (target_resources_ok < 0) | |
9303 | error (_("Hardware breakpoints used exceeds limit.")); | |
9304 | } | |
9305 | ||
6c95b8df PA |
9306 | gdb_assert (sals.nelts > 0); |
9307 | ||
0d381245 VP |
9308 | for (i = 0; i < sals.nelts; ++i) |
9309 | { | |
9310 | struct symtab_and_line sal = sals.sals[i]; | |
9311 | struct bp_location *loc; | |
9312 | ||
9313 | if (from_tty) | |
5af949e3 UW |
9314 | { |
9315 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9316 | if (!loc_gdbarch) | |
9317 | loc_gdbarch = gdbarch; | |
9318 | ||
9319 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9320 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9321 | } |
0d381245 VP |
9322 | |
9323 | if (i == 0) | |
9324 | { | |
d9b3f62e | 9325 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9326 | b->thread = thread; |
4a306c9a | 9327 | b->task = task; |
855a6e68 | 9328 | |
0d381245 | 9329 | b->cond_string = cond_string; |
e7e0cddf | 9330 | b->extra_string = extra_string; |
0d381245 | 9331 | b->ignore_count = ignore_count; |
41447f92 | 9332 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9333 | b->disposition = disposition; |
6c95b8df | 9334 | |
44f238bb PA |
9335 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9336 | b->loc->inserted = 1; | |
9337 | ||
0fb4aa4b PA |
9338 | if (type == bp_static_tracepoint) |
9339 | { | |
d9b3f62e | 9340 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9341 | struct static_tracepoint_marker marker; |
9342 | ||
983af33b | 9343 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9344 | { |
9345 | /* We already know the marker exists, otherwise, we | |
9346 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9347 | const char *p = &event_location_to_string (b->location)[3]; |
9348 | const char *endp; | |
0fb4aa4b | 9349 | char *marker_str; |
0fb4aa4b | 9350 | |
f00aae0f | 9351 | p = skip_spaces_const (p); |
0fb4aa4b | 9352 | |
f00aae0f | 9353 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9354 | |
9355 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9356 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9357 | |
3e43a32a MS |
9358 | printf_filtered (_("Probed static tracepoint " |
9359 | "marker \"%s\"\n"), | |
d9b3f62e | 9360 | t->static_trace_marker_id); |
0fb4aa4b PA |
9361 | } |
9362 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9363 | { | |
d9b3f62e | 9364 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9365 | release_static_tracepoint_marker (&marker); |
9366 | ||
3e43a32a MS |
9367 | printf_filtered (_("Probed static tracepoint " |
9368 | "marker \"%s\"\n"), | |
d9b3f62e | 9369 | t->static_trace_marker_id); |
0fb4aa4b PA |
9370 | } |
9371 | else | |
3e43a32a MS |
9372 | warning (_("Couldn't determine the static " |
9373 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9374 | } |
9375 | ||
0d381245 VP |
9376 | loc = b->loc; |
9377 | } | |
9378 | else | |
018d34a4 | 9379 | { |
39d61571 | 9380 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9381 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9382 | loc->inserted = 1; | |
0d381245 VP |
9383 | } |
9384 | ||
9385 | if (b->cond_string) | |
9386 | { | |
bbc13ae3 KS |
9387 | const char *arg = b->cond_string; |
9388 | ||
1bb9788d TT |
9389 | loc->cond = parse_exp_1 (&arg, loc->address, |
9390 | block_for_pc (loc->address), 0); | |
0d381245 | 9391 | if (*arg) |
588ae58c | 9392 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9393 | } |
e7e0cddf SS |
9394 | |
9395 | /* Dynamic printf requires and uses additional arguments on the | |
9396 | command line, otherwise it's an error. */ | |
9397 | if (type == bp_dprintf) | |
9398 | { | |
9399 | if (b->extra_string) | |
9400 | update_dprintf_command_list (b); | |
9401 | else | |
9402 | error (_("Format string required")); | |
9403 | } | |
9404 | else if (b->extra_string) | |
588ae58c | 9405 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9406 | } |
018d34a4 | 9407 | |
56435ebe | 9408 | b->display_canonical = display_canonical; |
f00aae0f KS |
9409 | if (location != NULL) |
9410 | b->location = location; | |
018d34a4 | 9411 | else |
305e13e6 JB |
9412 | { |
9413 | const char *addr_string = NULL; | |
9414 | int addr_string_len = 0; | |
9415 | ||
9416 | if (location != NULL) | |
9417 | addr_string = event_location_to_string (location); | |
9418 | if (addr_string != NULL) | |
9419 | addr_string_len = strlen (addr_string); | |
9420 | ||
9421 | b->location = new_address_location (b->loc->address, | |
9422 | addr_string, addr_string_len); | |
9423 | } | |
f8eba3c6 | 9424 | b->filter = filter; |
d9b3f62e | 9425 | } |
018d34a4 | 9426 | |
d9b3f62e PA |
9427 | static void |
9428 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f KS |
9429 | struct symtabs_and_lines sals, |
9430 | struct event_location *location, | |
f8eba3c6 | 9431 | char *filter, char *cond_string, |
e7e0cddf | 9432 | char *extra_string, |
d9b3f62e PA |
9433 | enum bptype type, enum bpdisp disposition, |
9434 | int thread, int task, int ignore_count, | |
c0a91b2b | 9435 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9436 | int enabled, int internal, unsigned flags, |
9437 | int display_canonical) | |
d9b3f62e PA |
9438 | { |
9439 | struct breakpoint *b; | |
9440 | struct cleanup *old_chain; | |
9441 | ||
9442 | if (is_tracepoint_type (type)) | |
9443 | { | |
9444 | struct tracepoint *t; | |
9445 | ||
9446 | t = XCNEW (struct tracepoint); | |
9447 | b = &t->base; | |
9448 | } | |
9449 | else | |
9450 | b = XNEW (struct breakpoint); | |
9451 | ||
9452 | old_chain = make_cleanup (xfree, b); | |
9453 | ||
9454 | init_breakpoint_sal (b, gdbarch, | |
f00aae0f | 9455 | sals, location, |
e7e0cddf | 9456 | filter, cond_string, extra_string, |
d9b3f62e PA |
9457 | type, disposition, |
9458 | thread, task, ignore_count, | |
9459 | ops, from_tty, | |
44f238bb PA |
9460 | enabled, internal, flags, |
9461 | display_canonical); | |
d9b3f62e PA |
9462 | discard_cleanups (old_chain); |
9463 | ||
3ea46bff | 9464 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9465 | } |
9466 | ||
9467 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9468 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9469 | value. COND_STRING, if not NULL, specified the condition to be | |
9470 | used for all breakpoints. Essentially the only case where | |
9471 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9472 | function. In that case, it's still not possible to specify | |
9473 | separate conditions for different overloaded functions, so | |
9474 | we take just a single condition string. | |
9475 | ||
c3f6f71d | 9476 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9477 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9478 | array contents). If the function fails (error() is called), the |
9479 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9480 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9481 | |
9482 | static void | |
8cdf0e15 | 9483 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9484 | struct linespec_result *canonical, |
e7e0cddf | 9485 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9486 | enum bptype type, enum bpdisp disposition, |
9487 | int thread, int task, int ignore_count, | |
c0a91b2b | 9488 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9489 | int enabled, int internal, unsigned flags) |
c906108c | 9490 | { |
018d34a4 | 9491 | int i; |
f8eba3c6 | 9492 | struct linespec_sals *lsal; |
cc59ec59 | 9493 | |
f8eba3c6 TT |
9494 | if (canonical->pre_expanded) |
9495 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9496 | ||
9497 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9498 | { |
f00aae0f | 9499 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9500 | 'break', without arguments. */ |
f00aae0f KS |
9501 | struct event_location *location |
9502 | = (canonical->location != NULL | |
9503 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9504 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
f00aae0f | 9505 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
0d381245 | 9506 | |
f8eba3c6 TT |
9507 | make_cleanup (xfree, filter_string); |
9508 | create_breakpoint_sal (gdbarch, lsal->sals, | |
f00aae0f | 9509 | location, |
f8eba3c6 | 9510 | filter_string, |
e7e0cddf SS |
9511 | cond_string, extra_string, |
9512 | type, disposition, | |
84f4c1fe | 9513 | thread, task, ignore_count, ops, |
44f238bb | 9514 | from_tty, enabled, internal, flags, |
56435ebe | 9515 | canonical->special_display); |
f8eba3c6 | 9516 | discard_cleanups (inner); |
c3f6f71d | 9517 | } |
c3f6f71d | 9518 | } |
c906108c | 9519 | |
f00aae0f | 9520 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9521 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9522 | addresses found. LOCATION points to the end of the SAL (for |
9523 | linespec locations). | |
9998af43 TJB |
9524 | |
9525 | The array and the line spec strings are allocated on the heap, it is | |
9526 | the caller's responsibility to free them. */ | |
c906108c | 9527 | |
b9362cc7 | 9528 | static void |
f00aae0f | 9529 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9530 | struct linespec_result *canonical) |
c3f6f71d | 9531 | { |
f00aae0f KS |
9532 | struct symtab_and_line cursal; |
9533 | ||
9534 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9535 | { | |
9536 | const char *address = get_linespec_location (location); | |
9537 | ||
9538 | if (address == NULL) | |
9539 | { | |
9540 | /* The last displayed codepoint, if it's valid, is our default | |
9541 | breakpoint address. */ | |
9542 | if (last_displayed_sal_is_valid ()) | |
9543 | { | |
9544 | struct linespec_sals lsal; | |
9545 | struct symtab_and_line sal; | |
9546 | CORE_ADDR pc; | |
9547 | ||
9548 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9549 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9550 | |
9551 | /* Set sal's pspace, pc, symtab, and line to the values | |
9552 | corresponding to the last call to print_frame_info. | |
9553 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9554 | as the breakpoint line number is inappropriate otherwise. | |
9555 | find_pc_line would adjust PC, re-set it back. */ | |
9556 | get_last_displayed_sal (&sal); | |
9557 | pc = sal.pc; | |
9558 | sal = find_pc_line (pc, 0); | |
9559 | ||
9560 | /* "break" without arguments is equivalent to "break *PC" | |
9561 | where PC is the last displayed codepoint's address. So | |
9562 | make sure to set sal.explicit_pc to prevent GDB from | |
9563 | trying to expand the list of sals to include all other | |
9564 | instances with the same symtab and line. */ | |
9565 | sal.pc = pc; | |
9566 | sal.explicit_pc = 1; | |
9567 | ||
9568 | lsal.sals.sals[0] = sal; | |
9569 | lsal.sals.nelts = 1; | |
9570 | lsal.canonical = NULL; | |
9571 | ||
9572 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9573 | return; | |
9574 | } | |
9575 | else | |
9576 | error (_("No default breakpoint address now.")); | |
c906108c | 9577 | } |
c906108c | 9578 | } |
f00aae0f KS |
9579 | |
9580 | /* Force almost all breakpoints to be in terms of the | |
9581 | current_source_symtab (which is decode_line_1's default). | |
9582 | This should produce the results we want almost all of the | |
9583 | time while leaving default_breakpoint_* alone. | |
9584 | ||
9585 | ObjC: However, don't match an Objective-C method name which | |
9586 | may have a '+' or '-' succeeded by a '['. */ | |
9587 | cursal = get_current_source_symtab_and_line (); | |
9588 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9589 | { |
f00aae0f | 9590 | const char *address = NULL; |
cc80f267 | 9591 | |
f00aae0f KS |
9592 | if (event_location_type (location) == LINESPEC_LOCATION) |
9593 | address = get_linespec_location (location); | |
cc80f267 | 9594 | |
f00aae0f KS |
9595 | if (!cursal.symtab |
9596 | || (address != NULL | |
9597 | && strchr ("+-", address[0]) != NULL | |
9598 | && address[1] != '[')) | |
9599 | { | |
c2f4122d | 9600 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9601 | get_last_displayed_symtab (), |
9602 | get_last_displayed_line (), | |
9603 | canonical, NULL, NULL); | |
9604 | return; | |
9605 | } | |
c906108c | 9606 | } |
f00aae0f | 9607 | |
c2f4122d | 9608 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9609 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9610 | } |
c906108c | 9611 | |
c906108c | 9612 | |
c3f6f71d | 9613 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9614 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9615 | |
b9362cc7 | 9616 | static void |
23e7acfb | 9617 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9618 | { |
9619 | int i; | |
cc59ec59 | 9620 | |
c3f6f71d | 9621 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9622 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9623 | } |
9624 | ||
7a697b8d SS |
9625 | /* Fast tracepoints may have restrictions on valid locations. For |
9626 | instance, a fast tracepoint using a jump instead of a trap will | |
9627 | likely have to overwrite more bytes than a trap would, and so can | |
9628 | only be placed where the instruction is longer than the jump, or a | |
9629 | multi-instruction sequence does not have a jump into the middle of | |
9630 | it, etc. */ | |
9631 | ||
9632 | static void | |
9633 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9634 | struct symtabs_and_lines *sals) | |
9635 | { | |
9636 | int i, rslt; | |
9637 | struct symtab_and_line *sal; | |
9638 | char *msg; | |
9639 | struct cleanup *old_chain; | |
9640 | ||
9641 | for (i = 0; i < sals->nelts; i++) | |
9642 | { | |
f8eba3c6 TT |
9643 | struct gdbarch *sarch; |
9644 | ||
7a697b8d SS |
9645 | sal = &sals->sals[i]; |
9646 | ||
f8eba3c6 TT |
9647 | sarch = get_sal_arch (*sal); |
9648 | /* We fall back to GDBARCH if there is no architecture | |
9649 | associated with SAL. */ | |
9650 | if (sarch == NULL) | |
9651 | sarch = gdbarch; | |
6b940e6a | 9652 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9653 | old_chain = make_cleanup (xfree, msg); |
9654 | ||
9655 | if (!rslt) | |
9656 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9657 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9658 | |
9659 | do_cleanups (old_chain); | |
9660 | } | |
9661 | } | |
9662 | ||
018d34a4 VP |
9663 | /* Given TOK, a string specification of condition and thread, as |
9664 | accepted by the 'break' command, extract the condition | |
9665 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9666 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9667 | If no condition is found, *COND_STRING is set to NULL. |
9668 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9669 | |
9670 | static void | |
bbc13ae3 | 9671 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9672 | char **cond_string, int *thread, int *task, |
9673 | char **rest) | |
018d34a4 VP |
9674 | { |
9675 | *cond_string = NULL; | |
9676 | *thread = -1; | |
ed1d1739 KS |
9677 | *task = 0; |
9678 | *rest = NULL; | |
9679 | ||
018d34a4 VP |
9680 | while (tok && *tok) |
9681 | { | |
bbc13ae3 | 9682 | const char *end_tok; |
018d34a4 | 9683 | int toklen; |
bbc13ae3 KS |
9684 | const char *cond_start = NULL; |
9685 | const char *cond_end = NULL; | |
cc59ec59 | 9686 | |
bbc13ae3 | 9687 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9688 | |
9689 | if ((*tok == '"' || *tok == ',') && rest) | |
9690 | { | |
9691 | *rest = savestring (tok, strlen (tok)); | |
9692 | return; | |
9693 | } | |
9694 | ||
bbc13ae3 | 9695 | end_tok = skip_to_space_const (tok); |
d634f2de | 9696 | |
018d34a4 | 9697 | toklen = end_tok - tok; |
d634f2de | 9698 | |
018d34a4 VP |
9699 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9700 | { | |
f7545552 TT |
9701 | struct expression *expr; |
9702 | ||
018d34a4 | 9703 | tok = cond_start = end_tok + 1; |
1bb9788d | 9704 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9705 | xfree (expr); |
018d34a4 | 9706 | cond_end = tok; |
d634f2de | 9707 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9708 | } |
9709 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9710 | { | |
5d5658a1 PA |
9711 | const char *tmptok; |
9712 | struct thread_info *thr; | |
d634f2de | 9713 | |
018d34a4 | 9714 | tok = end_tok + 1; |
5d5658a1 | 9715 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9716 | if (tok == tmptok) |
9717 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9718 | *thread = thr->global_num; |
bbc13ae3 | 9719 | tok = tmptok; |
018d34a4 | 9720 | } |
4a306c9a JB |
9721 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9722 | { | |
9723 | char *tmptok; | |
9724 | ||
9725 | tok = end_tok + 1; | |
bbc13ae3 | 9726 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9727 | if (tok == tmptok) |
9728 | error (_("Junk after task keyword.")); | |
9729 | if (!valid_task_id (*task)) | |
b6199126 | 9730 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9731 | tok = tmptok; |
4a306c9a | 9732 | } |
e7e0cddf SS |
9733 | else if (rest) |
9734 | { | |
9735 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9736 | return; |
e7e0cddf | 9737 | } |
018d34a4 VP |
9738 | else |
9739 | error (_("Junk at end of arguments.")); | |
9740 | } | |
9741 | } | |
9742 | ||
0fb4aa4b PA |
9743 | /* Decode a static tracepoint marker spec. */ |
9744 | ||
9745 | static struct symtabs_and_lines | |
f00aae0f | 9746 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9747 | { |
9748 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9749 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9750 | struct cleanup *old_chain; |
f00aae0f KS |
9751 | const char *p = &(*arg_p)[3]; |
9752 | const char *endp; | |
0fb4aa4b PA |
9753 | char *marker_str; |
9754 | int i; | |
9755 | ||
f00aae0f | 9756 | p = skip_spaces_const (p); |
0fb4aa4b | 9757 | |
f00aae0f | 9758 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9759 | |
9760 | marker_str = savestring (p, endp - p); | |
9761 | old_chain = make_cleanup (xfree, marker_str); | |
9762 | ||
9763 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9764 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9765 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9766 | ||
9767 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9768 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9769 | |
9770 | for (i = 0; i < sals.nelts; i++) | |
9771 | { | |
9772 | struct static_tracepoint_marker *marker; | |
9773 | ||
9774 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9775 | ||
9776 | init_sal (&sals.sals[i]); | |
9777 | ||
9778 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9779 | sals.sals[i].pc = marker->address; | |
9780 | ||
9781 | release_static_tracepoint_marker (marker); | |
9782 | } | |
9783 | ||
9784 | do_cleanups (old_chain); | |
9785 | ||
9786 | *arg_p = endp; | |
9787 | return sals; | |
9788 | } | |
9789 | ||
f00aae0f | 9790 | /* See breakpoint.h. */ |
0101ce28 | 9791 | |
8cdf0e15 VP |
9792 | int |
9793 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9794 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9795 | int thread, char *extra_string, |
f00aae0f | 9796 | int parse_extra, |
0fb4aa4b | 9797 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9798 | int ignore_count, |
9799 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9800 | const struct breakpoint_ops *ops, |
44f238bb PA |
9801 | int from_tty, int enabled, int internal, |
9802 | unsigned flags) | |
c3f6f71d | 9803 | { |
7efd8fc2 | 9804 | struct linespec_result canonical; |
c3f6f71d | 9805 | struct cleanup *old_chain; |
80c99de1 | 9806 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9807 | int pending = 0; |
4a306c9a | 9808 | int task = 0; |
86b17b60 | 9809 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9810 | |
348d480f PA |
9811 | gdb_assert (ops != NULL); |
9812 | ||
f00aae0f KS |
9813 | /* If extra_string isn't useful, set it to NULL. */ |
9814 | if (extra_string != NULL && *extra_string == '\0') | |
9815 | extra_string = NULL; | |
9816 | ||
7efd8fc2 | 9817 | init_linespec_result (&canonical); |
c3f6f71d | 9818 | |
492d29ea | 9819 | TRY |
b78a6381 | 9820 | { |
f00aae0f | 9821 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9822 | } |
492d29ea | 9823 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9824 | { |
492d29ea PA |
9825 | /* If caller is interested in rc value from parse, set |
9826 | value. */ | |
9827 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9828 | { |
05ff989b AC |
9829 | /* If pending breakpoint support is turned off, throw |
9830 | error. */ | |
fa8d40ab JJ |
9831 | |
9832 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9833 | throw_exception (e); |
9834 | ||
9835 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9836 | |
05ff989b AC |
9837 | /* If pending breakpoint support is auto query and the user |
9838 | selects no, then simply return the error code. */ | |
059fb39f | 9839 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9840 | && !nquery (_("Make %s pending on future shared library load? "), |
9841 | bptype_string (type_wanted))) | |
fd9b8c24 | 9842 | return 0; |
fa8d40ab | 9843 | |
05ff989b AC |
9844 | /* At this point, either the user was queried about setting |
9845 | a pending breakpoint and selected yes, or pending | |
9846 | breakpoint behavior is on and thus a pending breakpoint | |
9847 | is defaulted on behalf of the user. */ | |
f00aae0f | 9848 | pending = 1; |
0101ce28 | 9849 | } |
492d29ea PA |
9850 | else |
9851 | throw_exception (e); | |
0101ce28 | 9852 | } |
492d29ea PA |
9853 | END_CATCH |
9854 | ||
f00aae0f | 9855 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9856 | return 0; |
c3f6f71d | 9857 | |
4a64f543 | 9858 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9859 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9860 | |
c3f6f71d JM |
9861 | /* ----------------------------- SNIP ----------------------------- |
9862 | Anything added to the cleanup chain beyond this point is assumed | |
9863 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9864 | then the memory is not reclaimed. */ |
9865 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9866 | |
c3f6f71d JM |
9867 | /* Resolve all line numbers to PC's and verify that the addresses |
9868 | are ok for the target. */ | |
0101ce28 | 9869 | if (!pending) |
f8eba3c6 TT |
9870 | { |
9871 | int ix; | |
9872 | struct linespec_sals *iter; | |
9873 | ||
9874 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9875 | breakpoint_sals_to_pc (&iter->sals); | |
9876 | } | |
c3f6f71d | 9877 | |
7a697b8d | 9878 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9879 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9880 | { |
9881 | int ix; | |
9882 | struct linespec_sals *iter; | |
9883 | ||
9884 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9885 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9886 | } | |
7a697b8d | 9887 | |
c3f6f71d JM |
9888 | /* Verify that condition can be parsed, before setting any |
9889 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9890 | breakpoint. */ |
0101ce28 | 9891 | if (!pending) |
c3f6f71d | 9892 | { |
f00aae0f | 9893 | if (parse_extra) |
72b2ff0e | 9894 | { |
0878d0fa | 9895 | char *rest; |
52d361e1 YQ |
9896 | struct linespec_sals *lsal; |
9897 | ||
9898 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9899 | ||
0878d0fa YQ |
9900 | /* Here we only parse 'arg' to separate condition |
9901 | from thread number, so parsing in context of first | |
9902 | sal is OK. When setting the breakpoint we'll | |
9903 | re-parse it in context of each sal. */ | |
9904 | ||
f00aae0f KS |
9905 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9906 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9907 | if (cond_string) |
9908 | make_cleanup (xfree, cond_string); | |
9909 | if (rest) | |
9910 | make_cleanup (xfree, rest); | |
9911 | if (rest) | |
9912 | extra_string = rest; | |
f00aae0f KS |
9913 | else |
9914 | extra_string = NULL; | |
72b2ff0e | 9915 | } |
2f069f6f | 9916 | else |
72b2ff0e | 9917 | { |
f00aae0f KS |
9918 | if (type_wanted != bp_dprintf |
9919 | && extra_string != NULL && *extra_string != '\0') | |
9920 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9921 | |
9922 | /* Create a private copy of condition string. */ | |
9923 | if (cond_string) | |
9924 | { | |
9925 | cond_string = xstrdup (cond_string); | |
9926 | make_cleanup (xfree, cond_string); | |
9927 | } | |
9928 | /* Create a private copy of any extra string. */ | |
9929 | if (extra_string) | |
9930 | { | |
9931 | extra_string = xstrdup (extra_string); | |
9932 | make_cleanup (xfree, extra_string); | |
9933 | } | |
72b2ff0e | 9934 | } |
0fb4aa4b | 9935 | |
52d361e1 | 9936 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9937 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9938 | tempflag ? disp_del : disp_donttouch, |
9939 | thread, task, ignore_count, ops, | |
44f238bb | 9940 | from_tty, enabled, internal, flags); |
c906108c | 9941 | } |
0101ce28 JJ |
9942 | else |
9943 | { | |
0101ce28 JJ |
9944 | struct breakpoint *b; |
9945 | ||
bfccc43c YQ |
9946 | if (is_tracepoint_type (type_wanted)) |
9947 | { | |
9948 | struct tracepoint *t; | |
9949 | ||
9950 | t = XCNEW (struct tracepoint); | |
9951 | b = &t->base; | |
9952 | } | |
9953 | else | |
9954 | b = XNEW (struct breakpoint); | |
9955 | ||
9956 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
f00aae0f | 9957 | b->location = copy_event_location (location); |
bfccc43c | 9958 | |
f00aae0f KS |
9959 | if (parse_extra) |
9960 | b->cond_string = NULL; | |
e12c7713 MK |
9961 | else |
9962 | { | |
9963 | /* Create a private copy of condition string. */ | |
9964 | if (cond_string) | |
9965 | { | |
9966 | cond_string = xstrdup (cond_string); | |
9967 | make_cleanup (xfree, cond_string); | |
9968 | } | |
9969 | b->cond_string = cond_string; | |
15630549 | 9970 | b->thread = thread; |
e12c7713 | 9971 | } |
f00aae0f KS |
9972 | |
9973 | /* Create a private copy of any extra string. */ | |
9974 | if (extra_string != NULL) | |
9975 | { | |
9976 | extra_string = xstrdup (extra_string); | |
9977 | make_cleanup (xfree, extra_string); | |
9978 | } | |
9979 | b->extra_string = extra_string; | |
0101ce28 | 9980 | b->ignore_count = ignore_count; |
0101ce28 | 9981 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9982 | b->condition_not_parsed = 1; |
41447f92 | 9983 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9984 | if ((type_wanted != bp_breakpoint |
9985 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9986 | b->pspace = current_program_space; |
8bea4e01 | 9987 | |
bfccc43c | 9988 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9989 | } |
9990 | ||
f8eba3c6 | 9991 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9992 | { |
3e43a32a MS |
9993 | warning (_("Multiple breakpoints were set.\nUse the " |
9994 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9995 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9996 | } |
9997 | ||
80c99de1 PA |
9998 | /* That's it. Discard the cleanups for data inserted into the |
9999 | breakpoint. */ | |
10000 | discard_cleanups (bkpt_chain); | |
10001 | /* But cleanup everything else. */ | |
c3f6f71d | 10002 | do_cleanups (old_chain); |
217dc9e2 | 10003 | |
80c99de1 | 10004 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 10005 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
10006 | |
10007 | return 1; | |
c3f6f71d | 10008 | } |
c906108c | 10009 | |
348d480f | 10010 | /* Set a breakpoint. |
72b2ff0e VP |
10011 | ARG is a string describing breakpoint address, |
10012 | condition, and thread. | |
10013 | FLAG specifies if a breakpoint is hardware on, | |
10014 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
10015 | and BP_TEMPFLAG. */ | |
348d480f | 10016 | |
98deb0da | 10017 | static void |
72b2ff0e | 10018 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 10019 | { |
72b2ff0e | 10020 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
10021 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
10022 | ? bp_hardware_breakpoint | |
10023 | : bp_breakpoint); | |
55aa24fb | 10024 | struct breakpoint_ops *ops; |
f00aae0f KS |
10025 | struct event_location *location; |
10026 | struct cleanup *cleanup; | |
10027 | ||
10028 | location = string_to_event_location (&arg, current_language); | |
10029 | cleanup = make_cleanup_delete_event_location (location); | |
55aa24fb SDJ |
10030 | |
10031 | /* Matching breakpoints on probes. */ | |
5b56227b KS |
10032 | if (location != NULL |
10033 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
10034 | ops = &bkpt_probe_breakpoint_ops; |
10035 | else | |
10036 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 10037 | |
8cdf0e15 | 10038 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10039 | location, |
10040 | NULL, 0, arg, 1 /* parse arg */, | |
0fb4aa4b | 10041 | tempflag, type_wanted, |
8cdf0e15 VP |
10042 | 0 /* Ignore count */, |
10043 | pending_break_support, | |
55aa24fb | 10044 | ops, |
8cdf0e15 | 10045 | from_tty, |
84f4c1fe | 10046 | 1 /* enabled */, |
44f238bb PA |
10047 | 0 /* internal */, |
10048 | 0); | |
f00aae0f | 10049 | do_cleanups (cleanup); |
c906108c SS |
10050 | } |
10051 | ||
c906108c SS |
10052 | /* Helper function for break_command_1 and disassemble_command. */ |
10053 | ||
10054 | void | |
fba45db2 | 10055 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10056 | { |
10057 | CORE_ADDR pc; | |
10058 | ||
10059 | if (sal->pc == 0 && sal->symtab != NULL) | |
10060 | { | |
10061 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10062 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10063 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10064 | sal->pc = pc; |
6a048695 | 10065 | |
4a64f543 MS |
10066 | /* If this SAL corresponds to a breakpoint inserted using a line |
10067 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10068 | if (sal->explicit_line) |
059acae7 | 10069 | skip_prologue_sal (sal); |
c906108c SS |
10070 | } |
10071 | ||
10072 | if (sal->section == 0 && sal->symtab != NULL) | |
10073 | { | |
346d1dfe | 10074 | const struct blockvector *bv; |
3977b71f | 10075 | const struct block *b; |
c5aa993b | 10076 | struct symbol *sym; |
c906108c | 10077 | |
43f3e411 DE |
10078 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10079 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10080 | if (bv != NULL) |
10081 | { | |
7f0df278 | 10082 | sym = block_linkage_function (b); |
c906108c SS |
10083 | if (sym != NULL) |
10084 | { | |
eb822aa6 DE |
10085 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10086 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10087 | sym); | |
c906108c SS |
10088 | } |
10089 | else | |
10090 | { | |
4a64f543 MS |
10091 | /* It really is worthwhile to have the section, so we'll |
10092 | just have to look harder. This case can be executed | |
10093 | if we have line numbers but no functions (as can | |
10094 | happen in assembly source). */ | |
c906108c | 10095 | |
7cbd4a93 | 10096 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10097 | struct cleanup *old_chain = save_current_space_and_thread (); |
10098 | ||
10099 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10100 | |
10101 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10102 | if (msym.minsym) |
efd66ac6 | 10103 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10104 | |
10105 | do_cleanups (old_chain); | |
c906108c SS |
10106 | } |
10107 | } | |
10108 | } | |
10109 | } | |
10110 | ||
10111 | void | |
fba45db2 | 10112 | break_command (char *arg, int from_tty) |
c906108c | 10113 | { |
db107f19 | 10114 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10115 | } |
10116 | ||
c906108c | 10117 | void |
fba45db2 | 10118 | tbreak_command (char *arg, int from_tty) |
c906108c | 10119 | { |
db107f19 | 10120 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10121 | } |
10122 | ||
c906108c | 10123 | static void |
fba45db2 | 10124 | hbreak_command (char *arg, int from_tty) |
c906108c | 10125 | { |
db107f19 | 10126 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10127 | } |
10128 | ||
10129 | static void | |
fba45db2 | 10130 | thbreak_command (char *arg, int from_tty) |
c906108c | 10131 | { |
db107f19 | 10132 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10133 | } |
10134 | ||
10135 | static void | |
fba45db2 | 10136 | stop_command (char *arg, int from_tty) |
c906108c | 10137 | { |
a3f17187 | 10138 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10139 | Usage: stop in <function | address>\n\ |
a3f17187 | 10140 | stop at <line>\n")); |
c906108c SS |
10141 | } |
10142 | ||
10143 | static void | |
fba45db2 | 10144 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10145 | { |
10146 | int badInput = 0; | |
10147 | ||
c5aa993b | 10148 | if (arg == (char *) NULL) |
c906108c SS |
10149 | badInput = 1; |
10150 | else if (*arg != '*') | |
10151 | { | |
10152 | char *argptr = arg; | |
10153 | int hasColon = 0; | |
10154 | ||
4a64f543 | 10155 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10156 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10157 | function/method name. */ |
c906108c | 10158 | while (*argptr && !hasColon) |
c5aa993b JM |
10159 | { |
10160 | hasColon = (*argptr == ':'); | |
10161 | argptr++; | |
10162 | } | |
c906108c SS |
10163 | |
10164 | if (hasColon) | |
c5aa993b | 10165 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10166 | else |
c5aa993b | 10167 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10168 | } |
10169 | ||
10170 | if (badInput) | |
a3f17187 | 10171 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10172 | else |
db107f19 | 10173 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10174 | } |
10175 | ||
10176 | static void | |
fba45db2 | 10177 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10178 | { |
10179 | int badInput = 0; | |
10180 | ||
c5aa993b | 10181 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10182 | badInput = 1; |
10183 | else | |
10184 | { | |
10185 | char *argptr = arg; | |
10186 | int hasColon = 0; | |
10187 | ||
4a64f543 MS |
10188 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10189 | it is probably a line number. */ | |
c906108c | 10190 | while (*argptr && !hasColon) |
c5aa993b JM |
10191 | { |
10192 | hasColon = (*argptr == ':'); | |
10193 | argptr++; | |
10194 | } | |
c906108c SS |
10195 | |
10196 | if (hasColon) | |
c5aa993b | 10197 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10198 | else |
c5aa993b | 10199 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10200 | } |
10201 | ||
10202 | if (badInput) | |
a3f17187 | 10203 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10204 | else |
db107f19 | 10205 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10206 | } |
10207 | ||
e7e0cddf SS |
10208 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10209 | with a prewired command list consisting of a single output command, | |
10210 | built from extra arguments supplied on the dprintf command | |
10211 | line. */ | |
10212 | ||
da821c7b | 10213 | static void |
e7e0cddf SS |
10214 | dprintf_command (char *arg, int from_tty) |
10215 | { | |
f00aae0f KS |
10216 | struct event_location *location; |
10217 | struct cleanup *cleanup; | |
10218 | ||
10219 | location = string_to_event_location (&arg, current_language); | |
10220 | cleanup = make_cleanup_delete_event_location (location); | |
10221 | ||
10222 | /* If non-NULL, ARG should have been advanced past the location; | |
10223 | the next character must be ','. */ | |
10224 | if (arg != NULL) | |
10225 | { | |
10226 | if (arg[0] != ',' || arg[1] == '\0') | |
10227 | error (_("Format string required")); | |
10228 | else | |
10229 | { | |
10230 | /* Skip the comma. */ | |
10231 | ++arg; | |
10232 | } | |
10233 | } | |
10234 | ||
e7e0cddf | 10235 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10236 | location, |
10237 | NULL, 0, arg, 1 /* parse arg */, | |
e7e0cddf SS |
10238 | 0, bp_dprintf, |
10239 | 0 /* Ignore count */, | |
10240 | pending_break_support, | |
10241 | &dprintf_breakpoint_ops, | |
10242 | from_tty, | |
10243 | 1 /* enabled */, | |
10244 | 0 /* internal */, | |
10245 | 0); | |
f00aae0f | 10246 | do_cleanups (cleanup); |
e7e0cddf SS |
10247 | } |
10248 | ||
d3ce09f5 SS |
10249 | static void |
10250 | agent_printf_command (char *arg, int from_tty) | |
10251 | { | |
10252 | error (_("May only run agent-printf on the target")); | |
10253 | } | |
10254 | ||
f1310107 TJB |
10255 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10256 | ranged breakpoints. */ | |
10257 | ||
10258 | static int | |
10259 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10260 | struct address_space *aspace, | |
09ac7c10 TT |
10261 | CORE_ADDR bp_addr, |
10262 | const struct target_waitstatus *ws) | |
f1310107 | 10263 | { |
09ac7c10 | 10264 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10265 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10266 | return 0; |
10267 | ||
f1310107 TJB |
10268 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10269 | bl->length, aspace, bp_addr); | |
10270 | } | |
10271 | ||
10272 | /* Implement the "resources_needed" breakpoint_ops method for | |
10273 | ranged breakpoints. */ | |
10274 | ||
10275 | static int | |
10276 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10277 | { | |
10278 | return target_ranged_break_num_registers (); | |
10279 | } | |
10280 | ||
10281 | /* Implement the "print_it" breakpoint_ops method for | |
10282 | ranged breakpoints. */ | |
10283 | ||
10284 | static enum print_stop_action | |
348d480f | 10285 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10286 | { |
348d480f | 10287 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10288 | struct bp_location *bl = b->loc; |
79a45e25 | 10289 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10290 | |
10291 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10292 | ||
10293 | /* Ranged breakpoints have only one location. */ | |
10294 | gdb_assert (bl && bl->next == NULL); | |
10295 | ||
10296 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10297 | |
10298 | maybe_print_thread_hit_breakpoint (uiout); | |
10299 | ||
f1310107 | 10300 | if (b->disposition == disp_del) |
f303dbd6 | 10301 | ui_out_text (uiout, "Temporary ranged breakpoint "); |
f1310107 | 10302 | else |
f303dbd6 | 10303 | ui_out_text (uiout, "Ranged breakpoint "); |
f1310107 TJB |
10304 | if (ui_out_is_mi_like_p (uiout)) |
10305 | { | |
10306 | ui_out_field_string (uiout, "reason", | |
10307 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10308 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10309 | } | |
10310 | ui_out_field_int (uiout, "bkptno", b->number); | |
10311 | ui_out_text (uiout, ", "); | |
10312 | ||
10313 | return PRINT_SRC_AND_LOC; | |
10314 | } | |
10315 | ||
10316 | /* Implement the "print_one" breakpoint_ops method for | |
10317 | ranged breakpoints. */ | |
10318 | ||
10319 | static void | |
10320 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10321 | struct bp_location **last_loc) | |
10322 | { | |
10323 | struct bp_location *bl = b->loc; | |
10324 | struct value_print_options opts; | |
79a45e25 | 10325 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10326 | |
10327 | /* Ranged breakpoints have only one location. */ | |
10328 | gdb_assert (bl && bl->next == NULL); | |
10329 | ||
10330 | get_user_print_options (&opts); | |
10331 | ||
10332 | if (opts.addressprint) | |
10333 | /* We don't print the address range here, it will be printed later | |
10334 | by print_one_detail_ranged_breakpoint. */ | |
10335 | ui_out_field_skip (uiout, "addr"); | |
10336 | annotate_field (5); | |
10337 | print_breakpoint_location (b, bl); | |
10338 | *last_loc = bl; | |
10339 | } | |
10340 | ||
10341 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10342 | ranged breakpoints. */ | |
10343 | ||
10344 | static void | |
10345 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10346 | struct ui_out *uiout) | |
10347 | { | |
10348 | CORE_ADDR address_start, address_end; | |
10349 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10350 | struct ui_file *stb = mem_fileopen (); |
10351 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10352 | |
10353 | gdb_assert (bl); | |
10354 | ||
10355 | address_start = bl->address; | |
10356 | address_end = address_start + bl->length - 1; | |
10357 | ||
10358 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10359 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10360 | print_core_address (bl->gdbarch, address_start), |
10361 | print_core_address (bl->gdbarch, address_end)); | |
10362 | ui_out_field_stream (uiout, "addr", stb); | |
10363 | ui_out_text (uiout, "\n"); | |
10364 | ||
10365 | do_cleanups (cleanup); | |
10366 | } | |
10367 | ||
10368 | /* Implement the "print_mention" breakpoint_ops method for | |
10369 | ranged breakpoints. */ | |
10370 | ||
10371 | static void | |
10372 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10373 | { | |
10374 | struct bp_location *bl = b->loc; | |
79a45e25 | 10375 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10376 | |
10377 | gdb_assert (bl); | |
10378 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10379 | ||
10380 | if (ui_out_is_mi_like_p (uiout)) | |
10381 | return; | |
10382 | ||
10383 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10384 | b->number, paddress (bl->gdbarch, bl->address), | |
10385 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10386 | } | |
10387 | ||
10388 | /* Implement the "print_recreate" breakpoint_ops method for | |
10389 | ranged breakpoints. */ | |
10390 | ||
10391 | static void | |
10392 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10393 | { | |
f00aae0f KS |
10394 | fprintf_unfiltered (fp, "break-range %s, %s", |
10395 | event_location_to_string (b->location), | |
10396 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10397 | print_recreate_thread (b, fp); |
f1310107 TJB |
10398 | } |
10399 | ||
10400 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10401 | ||
2060206e | 10402 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10403 | |
10404 | /* Find the address where the end of the breakpoint range should be | |
10405 | placed, given the SAL of the end of the range. This is so that if | |
10406 | the user provides a line number, the end of the range is set to the | |
10407 | last instruction of the given line. */ | |
10408 | ||
10409 | static CORE_ADDR | |
10410 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10411 | { | |
10412 | CORE_ADDR end; | |
10413 | ||
10414 | /* If the user provided a PC value, use it. Otherwise, | |
10415 | find the address of the end of the given location. */ | |
10416 | if (sal.explicit_pc) | |
10417 | end = sal.pc; | |
10418 | else | |
10419 | { | |
10420 | int ret; | |
10421 | CORE_ADDR start; | |
10422 | ||
10423 | ret = find_line_pc_range (sal, &start, &end); | |
10424 | if (!ret) | |
10425 | error (_("Could not find location of the end of the range.")); | |
10426 | ||
10427 | /* find_line_pc_range returns the start of the next line. */ | |
10428 | end--; | |
10429 | } | |
10430 | ||
10431 | return end; | |
10432 | } | |
10433 | ||
10434 | /* Implement the "break-range" CLI command. */ | |
10435 | ||
10436 | static void | |
10437 | break_range_command (char *arg, int from_tty) | |
10438 | { | |
870f88f7 | 10439 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10440 | struct linespec_result canonical_start, canonical_end; |
10441 | int bp_count, can_use_bp, length; | |
10442 | CORE_ADDR end; | |
10443 | struct breakpoint *b; | |
10444 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10445 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10446 | struct linespec_sals *lsal_start, *lsal_end; |
f00aae0f | 10447 | struct event_location *start_location, *end_location; |
f1310107 TJB |
10448 | |
10449 | /* We don't support software ranged breakpoints. */ | |
10450 | if (target_ranged_break_num_registers () < 0) | |
10451 | error (_("This target does not support hardware ranged breakpoints.")); | |
10452 | ||
10453 | bp_count = hw_breakpoint_used_count (); | |
10454 | bp_count += target_ranged_break_num_registers (); | |
10455 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10456 | bp_count, 0); | |
10457 | if (can_use_bp < 0) | |
10458 | error (_("Hardware breakpoints used exceeds limit.")); | |
10459 | ||
f8eba3c6 | 10460 | arg = skip_spaces (arg); |
f1310107 TJB |
10461 | if (arg == NULL || arg[0] == '\0') |
10462 | error(_("No address range specified.")); | |
10463 | ||
f1310107 TJB |
10464 | init_linespec_result (&canonical_start); |
10465 | ||
f8eba3c6 | 10466 | arg_start = arg; |
f00aae0f KS |
10467 | start_location = string_to_event_location (&arg, current_language); |
10468 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); | |
10469 | parse_breakpoint_sals (start_location, &canonical_start); | |
10470 | make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10471 | |
10472 | if (arg[0] != ',') | |
10473 | error (_("Too few arguments.")); | |
f8eba3c6 | 10474 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10475 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10476 | |
10477 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10478 | ||
10479 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10480 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10481 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10482 | ||
f8eba3c6 TT |
10483 | sal_start = lsal_start->sals.sals[0]; |
10484 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10485 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10486 | |
10487 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10488 | arg = skip_spaces (arg); |
f1310107 TJB |
10489 | |
10490 | /* Parse the end location. */ | |
10491 | ||
f1310107 TJB |
10492 | init_linespec_result (&canonical_end); |
10493 | arg_start = arg; | |
10494 | ||
f8eba3c6 | 10495 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10496 | parse_breakpoint_sals because we need to specify the start location's |
10497 | symtab and line as the default symtab and line for the end of the | |
10498 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10499 | where +14 means 14 lines from the start location. */ | |
f00aae0f KS |
10500 | end_location = string_to_event_location (&arg, current_language); |
10501 | make_cleanup_delete_event_location (end_location); | |
c2f4122d | 10502 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f8eba3c6 TT |
10503 | sal_start.symtab, sal_start.line, |
10504 | &canonical_end, NULL, NULL); | |
10505 | ||
10506 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10507 | |
f8eba3c6 | 10508 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10509 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10510 | |
10511 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10512 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10513 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10514 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10515 | ||
f8eba3c6 | 10516 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10517 | |
10518 | end = find_breakpoint_range_end (sal_end); | |
10519 | if (sal_start.pc > end) | |
177b42fe | 10520 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10521 | |
10522 | length = end - sal_start.pc + 1; | |
10523 | if (length < 0) | |
10524 | /* Length overflowed. */ | |
10525 | error (_("Address range too large.")); | |
10526 | else if (length == 1) | |
10527 | { | |
10528 | /* This range is simple enough to be handled by | |
10529 | the `hbreak' command. */ | |
10530 | hbreak_command (addr_string_start, 1); | |
10531 | ||
10532 | do_cleanups (cleanup_bkpt); | |
10533 | ||
10534 | return; | |
10535 | } | |
10536 | ||
10537 | /* Now set up the breakpoint. */ | |
10538 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10539 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10540 | set_breakpoint_count (breakpoint_count + 1); |
10541 | b->number = breakpoint_count; | |
10542 | b->disposition = disp_donttouch; | |
f00aae0f KS |
10543 | b->location = copy_event_location (start_location); |
10544 | b->location_range_end = copy_event_location (end_location); | |
f1310107 TJB |
10545 | b->loc->length = length; |
10546 | ||
f8eba3c6 | 10547 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10548 | |
10549 | mention (b); | |
8d3788bd | 10550 | observer_notify_breakpoint_created (b); |
44702360 | 10551 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10552 | } |
10553 | ||
4a64f543 MS |
10554 | /* Return non-zero if EXP is verified as constant. Returned zero |
10555 | means EXP is variable. Also the constant detection may fail for | |
10556 | some constant expressions and in such case still falsely return | |
10557 | zero. */ | |
2e6e3d9c | 10558 | |
65d79d4b SDJ |
10559 | static int |
10560 | watchpoint_exp_is_const (const struct expression *exp) | |
10561 | { | |
10562 | int i = exp->nelts; | |
10563 | ||
10564 | while (i > 0) | |
10565 | { | |
10566 | int oplenp, argsp; | |
10567 | ||
10568 | /* We are only interested in the descriptor of each element. */ | |
10569 | operator_length (exp, i, &oplenp, &argsp); | |
10570 | i -= oplenp; | |
10571 | ||
10572 | switch (exp->elts[i].opcode) | |
10573 | { | |
10574 | case BINOP_ADD: | |
10575 | case BINOP_SUB: | |
10576 | case BINOP_MUL: | |
10577 | case BINOP_DIV: | |
10578 | case BINOP_REM: | |
10579 | case BINOP_MOD: | |
10580 | case BINOP_LSH: | |
10581 | case BINOP_RSH: | |
10582 | case BINOP_LOGICAL_AND: | |
10583 | case BINOP_LOGICAL_OR: | |
10584 | case BINOP_BITWISE_AND: | |
10585 | case BINOP_BITWISE_IOR: | |
10586 | case BINOP_BITWISE_XOR: | |
10587 | case BINOP_EQUAL: | |
10588 | case BINOP_NOTEQUAL: | |
10589 | case BINOP_LESS: | |
10590 | case BINOP_GTR: | |
10591 | case BINOP_LEQ: | |
10592 | case BINOP_GEQ: | |
10593 | case BINOP_REPEAT: | |
10594 | case BINOP_COMMA: | |
10595 | case BINOP_EXP: | |
10596 | case BINOP_MIN: | |
10597 | case BINOP_MAX: | |
10598 | case BINOP_INTDIV: | |
10599 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10600 | case TERNOP_COND: |
10601 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10602 | |
10603 | case OP_LONG: | |
10604 | case OP_DOUBLE: | |
10605 | case OP_DECFLOAT: | |
10606 | case OP_LAST: | |
10607 | case OP_COMPLEX: | |
10608 | case OP_STRING: | |
65d79d4b SDJ |
10609 | case OP_ARRAY: |
10610 | case OP_TYPE: | |
608b4967 TT |
10611 | case OP_TYPEOF: |
10612 | case OP_DECLTYPE: | |
6e72ca20 | 10613 | case OP_TYPEID: |
65d79d4b SDJ |
10614 | case OP_NAME: |
10615 | case OP_OBJC_NSSTRING: | |
10616 | ||
10617 | case UNOP_NEG: | |
10618 | case UNOP_LOGICAL_NOT: | |
10619 | case UNOP_COMPLEMENT: | |
10620 | case UNOP_ADDR: | |
10621 | case UNOP_HIGH: | |
aeaa2474 | 10622 | case UNOP_CAST: |
9eaf6705 TT |
10623 | |
10624 | case UNOP_CAST_TYPE: | |
10625 | case UNOP_REINTERPRET_CAST: | |
10626 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10627 | /* Unary, binary and ternary operators: We have to check |
10628 | their operands. If they are constant, then so is the | |
10629 | result of that operation. For instance, if A and B are | |
10630 | determined to be constants, then so is "A + B". | |
10631 | ||
10632 | UNOP_IND is one exception to the rule above, because the | |
10633 | value of *ADDR is not necessarily a constant, even when | |
10634 | ADDR is. */ | |
65d79d4b SDJ |
10635 | break; |
10636 | ||
10637 | case OP_VAR_VALUE: | |
10638 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10639 | |
65d79d4b | 10640 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10641 | possible that a buggy compiler could mark a variable as |
10642 | constant even when it is not, and TYPE_CONST would return | |
10643 | true in this case, while SYMBOL_CLASS wouldn't. | |
10644 | ||
10645 | We also have to check for function symbols because they | |
10646 | are always constant. */ | |
65d79d4b SDJ |
10647 | { |
10648 | struct symbol *s = exp->elts[i + 2].symbol; | |
10649 | ||
10650 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10651 | && SYMBOL_CLASS (s) != LOC_CONST | |
10652 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10653 | return 0; | |
10654 | break; | |
10655 | } | |
10656 | ||
10657 | /* The default action is to return 0 because we are using | |
10658 | the optimistic approach here: If we don't know something, | |
10659 | then it is not a constant. */ | |
10660 | default: | |
10661 | return 0; | |
10662 | } | |
10663 | } | |
10664 | ||
10665 | return 1; | |
10666 | } | |
10667 | ||
3a5c3e22 PA |
10668 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10669 | ||
10670 | static void | |
10671 | dtor_watchpoint (struct breakpoint *self) | |
10672 | { | |
10673 | struct watchpoint *w = (struct watchpoint *) self; | |
10674 | ||
10675 | xfree (w->cond_exp); | |
10676 | xfree (w->exp); | |
10677 | xfree (w->exp_string); | |
10678 | xfree (w->exp_string_reparse); | |
10679 | value_free (w->val); | |
10680 | ||
10681 | base_breakpoint_ops.dtor (self); | |
10682 | } | |
10683 | ||
348d480f PA |
10684 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10685 | ||
10686 | static void | |
10687 | re_set_watchpoint (struct breakpoint *b) | |
10688 | { | |
3a5c3e22 PA |
10689 | struct watchpoint *w = (struct watchpoint *) b; |
10690 | ||
348d480f PA |
10691 | /* Watchpoint can be either on expression using entirely global |
10692 | variables, or it can be on local variables. | |
10693 | ||
10694 | Watchpoints of the first kind are never auto-deleted, and even | |
10695 | persist across program restarts. Since they can use variables | |
10696 | from shared libraries, we need to reparse expression as libraries | |
10697 | are loaded and unloaded. | |
10698 | ||
10699 | Watchpoints on local variables can also change meaning as result | |
10700 | of solib event. For example, if a watchpoint uses both a local | |
10701 | and a global variables in expression, it's a local watchpoint, | |
10702 | but unloading of a shared library will make the expression | |
10703 | invalid. This is not a very common use case, but we still | |
10704 | re-evaluate expression, to avoid surprises to the user. | |
10705 | ||
10706 | Note that for local watchpoints, we re-evaluate it only if | |
10707 | watchpoints frame id is still valid. If it's not, it means the | |
10708 | watchpoint is out of scope and will be deleted soon. In fact, | |
10709 | I'm not sure we'll ever be called in this case. | |
10710 | ||
10711 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10712 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10713 | |
3a5c3e22 PA |
10714 | Don't do anything about disabled watchpoints, since they will be |
10715 | reevaluated again when enabled. */ | |
10716 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10717 | } |
10718 | ||
77b06cd7 TJB |
10719 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10720 | ||
10721 | static int | |
10722 | insert_watchpoint (struct bp_location *bl) | |
10723 | { | |
3a5c3e22 PA |
10724 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10725 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10726 | |
10727 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10728 | w->cond_exp); |
77b06cd7 TJB |
10729 | } |
10730 | ||
10731 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10732 | ||
10733 | static int | |
73971819 | 10734 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10735 | { |
3a5c3e22 PA |
10736 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10737 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10738 | |
10739 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10740 | w->cond_exp); |
e09342b5 TJB |
10741 | } |
10742 | ||
e09342b5 | 10743 | static int |
348d480f | 10744 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10745 | struct address_space *aspace, CORE_ADDR bp_addr, |
10746 | const struct target_waitstatus *ws) | |
e09342b5 | 10747 | { |
348d480f | 10748 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10749 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10750 | |
348d480f PA |
10751 | /* Continuable hardware watchpoints are treated as non-existent if the |
10752 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10753 | some data address). Otherwise gdb won't stop on a break instruction | |
10754 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10755 | been defined. Also skip watchpoints which we know did not trigger | |
10756 | (did not match the data address). */ | |
10757 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10758 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10759 | return 0; |
9c06b0b4 | 10760 | |
348d480f | 10761 | return 1; |
9c06b0b4 TJB |
10762 | } |
10763 | ||
348d480f PA |
10764 | static void |
10765 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10766 | { |
348d480f | 10767 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10768 | |
348d480f | 10769 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10770 | } |
10771 | ||
10772 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10773 | hardware watchpoints. */ |
9c06b0b4 TJB |
10774 | |
10775 | static int | |
348d480f | 10776 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10777 | { |
3a5c3e22 PA |
10778 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10779 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10780 | |
10781 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10782 | } |
10783 | ||
10784 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10785 | hardware watchpoints. */ |
9c06b0b4 TJB |
10786 | |
10787 | static int | |
348d480f | 10788 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10789 | { |
efa80663 PA |
10790 | /* Read and access watchpoints only work with hardware support. */ |
10791 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10792 | } |
10793 | ||
9c06b0b4 | 10794 | static enum print_stop_action |
348d480f | 10795 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10796 | { |
348d480f PA |
10797 | struct cleanup *old_chain; |
10798 | struct breakpoint *b; | |
f99d8bf4 | 10799 | struct ui_file *stb; |
348d480f | 10800 | enum print_stop_action result; |
3a5c3e22 | 10801 | struct watchpoint *w; |
79a45e25 | 10802 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10803 | |
10804 | gdb_assert (bs->bp_location_at != NULL); | |
10805 | ||
348d480f | 10806 | b = bs->breakpoint_at; |
3a5c3e22 | 10807 | w = (struct watchpoint *) b; |
348d480f | 10808 | |
f99d8bf4 PA |
10809 | stb = mem_fileopen (); |
10810 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 | 10811 | |
f303dbd6 PA |
10812 | annotate_watchpoint (b->number); |
10813 | maybe_print_thread_hit_breakpoint (uiout); | |
10814 | ||
9c06b0b4 TJB |
10815 | switch (b->type) |
10816 | { | |
348d480f | 10817 | case bp_watchpoint: |
9c06b0b4 | 10818 | case bp_hardware_watchpoint: |
9c06b0b4 TJB |
10819 | if (ui_out_is_mi_like_p (uiout)) |
10820 | ui_out_field_string | |
10821 | (uiout, "reason", | |
10822 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10823 | mention (b); |
10824 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10825 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10826 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10827 | ui_out_field_stream (uiout, "old", stb); |
10828 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10829 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10830 | ui_out_field_stream (uiout, "new", stb); |
10831 | ui_out_text (uiout, "\n"); | |
10832 | /* More than one watchpoint may have been triggered. */ | |
10833 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10834 | break; |
10835 | ||
10836 | case bp_read_watchpoint: | |
10837 | if (ui_out_is_mi_like_p (uiout)) | |
10838 | ui_out_field_string | |
10839 | (uiout, "reason", | |
10840 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10841 | mention (b); |
10842 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10843 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10844 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10845 | ui_out_field_stream (uiout, "value", stb); |
10846 | ui_out_text (uiout, "\n"); | |
10847 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10848 | break; |
10849 | ||
10850 | case bp_access_watchpoint: | |
348d480f PA |
10851 | if (bs->old_val != NULL) |
10852 | { | |
348d480f PA |
10853 | if (ui_out_is_mi_like_p (uiout)) |
10854 | ui_out_field_string | |
10855 | (uiout, "reason", | |
10856 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10857 | mention (b); | |
10858 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10859 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10860 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10861 | ui_out_field_stream (uiout, "old", stb); |
10862 | ui_out_text (uiout, "\nNew value = "); | |
10863 | } | |
10864 | else | |
10865 | { | |
10866 | mention (b); | |
10867 | if (ui_out_is_mi_like_p (uiout)) | |
10868 | ui_out_field_string | |
10869 | (uiout, "reason", | |
10870 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10871 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10872 | ui_out_text (uiout, "\nValue = "); | |
10873 | } | |
f99d8bf4 | 10874 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10875 | ui_out_field_stream (uiout, "new", stb); |
10876 | ui_out_text (uiout, "\n"); | |
10877 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10878 | break; |
10879 | default: | |
348d480f | 10880 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10881 | } |
10882 | ||
348d480f PA |
10883 | do_cleanups (old_chain); |
10884 | return result; | |
10885 | } | |
10886 | ||
10887 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10888 | watchpoints. */ | |
10889 | ||
10890 | static void | |
10891 | print_mention_watchpoint (struct breakpoint *b) | |
10892 | { | |
10893 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10894 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10895 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10896 | |
10897 | switch (b->type) | |
10898 | { | |
10899 | case bp_watchpoint: | |
10900 | ui_out_text (uiout, "Watchpoint "); | |
10901 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10902 | break; | |
10903 | case bp_hardware_watchpoint: | |
10904 | ui_out_text (uiout, "Hardware watchpoint "); | |
10905 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10906 | break; | |
10907 | case bp_read_watchpoint: | |
10908 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10909 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10910 | break; | |
10911 | case bp_access_watchpoint: | |
10912 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10913 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10914 | break; | |
10915 | default: | |
10916 | internal_error (__FILE__, __LINE__, | |
10917 | _("Invalid hardware watchpoint type.")); | |
10918 | } | |
10919 | ||
10920 | ui_out_field_int (uiout, "number", b->number); | |
10921 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10922 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10923 | do_cleanups (ui_out_chain); |
10924 | } | |
10925 | ||
10926 | /* Implement the "print_recreate" breakpoint_ops method for | |
10927 | watchpoints. */ | |
10928 | ||
10929 | static void | |
10930 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10931 | { | |
3a5c3e22 PA |
10932 | struct watchpoint *w = (struct watchpoint *) b; |
10933 | ||
348d480f PA |
10934 | switch (b->type) |
10935 | { | |
10936 | case bp_watchpoint: | |
10937 | case bp_hardware_watchpoint: | |
10938 | fprintf_unfiltered (fp, "watch"); | |
10939 | break; | |
10940 | case bp_read_watchpoint: | |
10941 | fprintf_unfiltered (fp, "rwatch"); | |
10942 | break; | |
10943 | case bp_access_watchpoint: | |
10944 | fprintf_unfiltered (fp, "awatch"); | |
10945 | break; | |
10946 | default: | |
10947 | internal_error (__FILE__, __LINE__, | |
10948 | _("Invalid watchpoint type.")); | |
10949 | } | |
10950 | ||
3a5c3e22 | 10951 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10952 | print_recreate_thread (b, fp); |
348d480f PA |
10953 | } |
10954 | ||
427cd150 TT |
10955 | /* Implement the "explains_signal" breakpoint_ops method for |
10956 | watchpoints. */ | |
10957 | ||
47591c29 | 10958 | static int |
427cd150 TT |
10959 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10960 | { | |
10961 | /* A software watchpoint cannot cause a signal other than | |
10962 | GDB_SIGNAL_TRAP. */ | |
10963 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10964 | return 0; |
427cd150 | 10965 | |
47591c29 | 10966 | return 1; |
427cd150 TT |
10967 | } |
10968 | ||
348d480f PA |
10969 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10970 | ||
2060206e | 10971 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10972 | |
10973 | /* Implement the "insert" breakpoint_ops method for | |
10974 | masked hardware watchpoints. */ | |
10975 | ||
10976 | static int | |
10977 | insert_masked_watchpoint (struct bp_location *bl) | |
10978 | { | |
3a5c3e22 PA |
10979 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10980 | ||
10981 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10982 | bl->watchpoint_type); |
10983 | } | |
10984 | ||
10985 | /* Implement the "remove" breakpoint_ops method for | |
10986 | masked hardware watchpoints. */ | |
10987 | ||
10988 | static int | |
73971819 | 10989 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10990 | { |
3a5c3e22 PA |
10991 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10992 | ||
10993 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10994 | bl->watchpoint_type); |
10995 | } | |
10996 | ||
10997 | /* Implement the "resources_needed" breakpoint_ops method for | |
10998 | masked hardware watchpoints. */ | |
10999 | ||
11000 | static int | |
11001 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
11002 | { | |
3a5c3e22 PA |
11003 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11004 | ||
11005 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
11006 | } |
11007 | ||
11008 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
11009 | masked hardware watchpoints. */ | |
11010 | ||
11011 | static int | |
11012 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
11013 | { | |
11014 | return 0; | |
11015 | } | |
11016 | ||
11017 | /* Implement the "print_it" breakpoint_ops method for | |
11018 | masked hardware watchpoints. */ | |
11019 | ||
11020 | static enum print_stop_action | |
11021 | print_it_masked_watchpoint (bpstat bs) | |
11022 | { | |
11023 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 11024 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11025 | |
11026 | /* Masked watchpoints have only one location. */ | |
11027 | gdb_assert (b->loc && b->loc->next == NULL); | |
11028 | ||
f303dbd6 PA |
11029 | annotate_watchpoint (b->number); |
11030 | maybe_print_thread_hit_breakpoint (uiout); | |
11031 | ||
348d480f PA |
11032 | switch (b->type) |
11033 | { | |
11034 | case bp_hardware_watchpoint: | |
348d480f PA |
11035 | if (ui_out_is_mi_like_p (uiout)) |
11036 | ui_out_field_string | |
11037 | (uiout, "reason", | |
11038 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11039 | break; | |
11040 | ||
11041 | case bp_read_watchpoint: | |
11042 | if (ui_out_is_mi_like_p (uiout)) | |
11043 | ui_out_field_string | |
11044 | (uiout, "reason", | |
11045 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11046 | break; | |
11047 | ||
11048 | case bp_access_watchpoint: | |
11049 | if (ui_out_is_mi_like_p (uiout)) | |
11050 | ui_out_field_string | |
11051 | (uiout, "reason", | |
11052 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11053 | break; | |
11054 | default: | |
11055 | internal_error (__FILE__, __LINE__, | |
11056 | _("Invalid hardware watchpoint type.")); | |
11057 | } | |
11058 | ||
11059 | mention (b); | |
9c06b0b4 TJB |
11060 | ui_out_text (uiout, _("\n\ |
11061 | Check the underlying instruction at PC for the memory\n\ | |
11062 | address and value which triggered this watchpoint.\n")); | |
11063 | ui_out_text (uiout, "\n"); | |
11064 | ||
11065 | /* More than one watchpoint may have been triggered. */ | |
11066 | return PRINT_UNKNOWN; | |
11067 | } | |
11068 | ||
11069 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11070 | masked hardware watchpoints. */ | |
11071 | ||
11072 | static void | |
11073 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11074 | struct ui_out *uiout) | |
11075 | { | |
3a5c3e22 PA |
11076 | struct watchpoint *w = (struct watchpoint *) b; |
11077 | ||
9c06b0b4 TJB |
11078 | /* Masked watchpoints have only one location. */ |
11079 | gdb_assert (b->loc && b->loc->next == NULL); | |
11080 | ||
11081 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11082 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11083 | ui_out_text (uiout, "\n"); |
11084 | } | |
11085 | ||
11086 | /* Implement the "print_mention" breakpoint_ops method for | |
11087 | masked hardware watchpoints. */ | |
11088 | ||
11089 | static void | |
11090 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11091 | { | |
3a5c3e22 | 11092 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11093 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11094 | struct cleanup *ui_out_chain; |
11095 | ||
11096 | switch (b->type) | |
11097 | { | |
11098 | case bp_hardware_watchpoint: | |
11099 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11100 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11101 | break; | |
11102 | case bp_read_watchpoint: | |
11103 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11104 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11105 | break; | |
11106 | case bp_access_watchpoint: | |
11107 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11108 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11109 | break; | |
11110 | default: | |
11111 | internal_error (__FILE__, __LINE__, | |
11112 | _("Invalid hardware watchpoint type.")); | |
11113 | } | |
11114 | ||
11115 | ui_out_field_int (uiout, "number", b->number); | |
11116 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11117 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11118 | do_cleanups (ui_out_chain); |
11119 | } | |
11120 | ||
11121 | /* Implement the "print_recreate" breakpoint_ops method for | |
11122 | masked hardware watchpoints. */ | |
11123 | ||
11124 | static void | |
11125 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11126 | { | |
3a5c3e22 | 11127 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11128 | char tmp[40]; |
11129 | ||
11130 | switch (b->type) | |
11131 | { | |
11132 | case bp_hardware_watchpoint: | |
11133 | fprintf_unfiltered (fp, "watch"); | |
11134 | break; | |
11135 | case bp_read_watchpoint: | |
11136 | fprintf_unfiltered (fp, "rwatch"); | |
11137 | break; | |
11138 | case bp_access_watchpoint: | |
11139 | fprintf_unfiltered (fp, "awatch"); | |
11140 | break; | |
11141 | default: | |
11142 | internal_error (__FILE__, __LINE__, | |
11143 | _("Invalid hardware watchpoint type.")); | |
11144 | } | |
11145 | ||
3a5c3e22 PA |
11146 | sprintf_vma (tmp, w->hw_wp_mask); |
11147 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11148 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11149 | } |
11150 | ||
11151 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11152 | ||
2060206e | 11153 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11154 | |
11155 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11156 | ||
11157 | static int | |
11158 | is_masked_watchpoint (const struct breakpoint *b) | |
11159 | { | |
11160 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11161 | } | |
11162 | ||
53a5351d JM |
11163 | /* accessflag: hw_write: watch write, |
11164 | hw_read: watch read, | |
11165 | hw_access: watch access (read or write) */ | |
c906108c | 11166 | static void |
bbc13ae3 | 11167 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11168 | int just_location, int internal) |
c906108c | 11169 | { |
d983da9c | 11170 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11171 | struct expression *exp; |
270140bd | 11172 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11173 | struct value *val, *mark, *result; |
bb9d5f81 | 11174 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11175 | struct frame_info *frame; |
bbc13ae3 KS |
11176 | const char *exp_start = NULL; |
11177 | const char *exp_end = NULL; | |
11178 | const char *tok, *end_tok; | |
9c06b0b4 | 11179 | int toklen = -1; |
bbc13ae3 KS |
11180 | const char *cond_start = NULL; |
11181 | const char *cond_end = NULL; | |
c906108c | 11182 | enum bptype bp_type; |
37e4754d | 11183 | int thread = -1; |
0cf6dd15 | 11184 | int pc = 0; |
9c06b0b4 TJB |
11185 | /* Flag to indicate whether we are going to use masks for |
11186 | the hardware watchpoint. */ | |
11187 | int use_mask = 0; | |
11188 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11189 | struct watchpoint *w; |
bbc13ae3 KS |
11190 | char *expression; |
11191 | struct cleanup *back_to; | |
c906108c | 11192 | |
37e4754d LM |
11193 | /* Make sure that we actually have parameters to parse. */ |
11194 | if (arg != NULL && arg[0] != '\0') | |
11195 | { | |
bbc13ae3 KS |
11196 | const char *value_start; |
11197 | ||
11198 | exp_end = arg + strlen (arg); | |
37e4754d | 11199 | |
9c06b0b4 TJB |
11200 | /* Look for "parameter value" pairs at the end |
11201 | of the arguments string. */ | |
bbc13ae3 | 11202 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11203 | { |
11204 | /* Skip whitespace at the end of the argument list. */ | |
11205 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11206 | tok--; | |
11207 | ||
11208 | /* Find the beginning of the last token. | |
11209 | This is the value of the parameter. */ | |
11210 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11211 | tok--; | |
11212 | value_start = tok + 1; | |
11213 | ||
11214 | /* Skip whitespace. */ | |
11215 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11216 | tok--; | |
11217 | ||
11218 | end_tok = tok; | |
11219 | ||
11220 | /* Find the beginning of the second to last token. | |
11221 | This is the parameter itself. */ | |
11222 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11223 | tok--; | |
11224 | tok++; | |
11225 | toklen = end_tok - tok + 1; | |
11226 | ||
61012eef | 11227 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11228 | { |
5d5658a1 | 11229 | struct thread_info *thr; |
9c06b0b4 TJB |
11230 | /* At this point we've found a "thread" token, which means |
11231 | the user is trying to set a watchpoint that triggers | |
11232 | only in a specific thread. */ | |
5d5658a1 | 11233 | const char *endp; |
37e4754d | 11234 | |
9c06b0b4 TJB |
11235 | if (thread != -1) |
11236 | error(_("You can specify only one thread.")); | |
37e4754d | 11237 | |
9c06b0b4 | 11238 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11239 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11240 | |
5d5658a1 | 11241 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11242 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11243 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11244 | |
5d5658a1 | 11245 | thread = thr->global_num; |
9c06b0b4 | 11246 | } |
61012eef | 11247 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11248 | { |
11249 | /* We've found a "mask" token, which means the user wants to | |
11250 | create a hardware watchpoint that is going to have the mask | |
11251 | facility. */ | |
11252 | struct value *mask_value, *mark; | |
37e4754d | 11253 | |
9c06b0b4 TJB |
11254 | if (use_mask) |
11255 | error(_("You can specify only one mask.")); | |
37e4754d | 11256 | |
9c06b0b4 | 11257 | use_mask = just_location = 1; |
37e4754d | 11258 | |
9c06b0b4 TJB |
11259 | mark = value_mark (); |
11260 | mask_value = parse_to_comma_and_eval (&value_start); | |
11261 | mask = value_as_address (mask_value); | |
11262 | value_free_to_mark (mark); | |
11263 | } | |
11264 | else | |
11265 | /* We didn't recognize what we found. We should stop here. */ | |
11266 | break; | |
37e4754d | 11267 | |
9c06b0b4 TJB |
11268 | /* Truncate the string and get rid of the "parameter value" pair before |
11269 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11270 | exp_end = tok; |
9c06b0b4 | 11271 | } |
37e4754d | 11272 | } |
bbc13ae3 KS |
11273 | else |
11274 | exp_end = arg; | |
37e4754d | 11275 | |
bbc13ae3 KS |
11276 | /* Parse the rest of the arguments. From here on out, everything |
11277 | is in terms of a newly allocated string instead of the original | |
11278 | ARG. */ | |
c906108c | 11279 | innermost_block = NULL; |
bbc13ae3 KS |
11280 | expression = savestring (arg, exp_end - arg); |
11281 | back_to = make_cleanup (xfree, expression); | |
11282 | exp_start = arg = expression; | |
1bb9788d | 11283 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11284 | exp_end = arg; |
fa8a61dc TT |
11285 | /* Remove trailing whitespace from the expression before saving it. |
11286 | This makes the eventual display of the expression string a bit | |
11287 | prettier. */ | |
11288 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11289 | --exp_end; | |
11290 | ||
65d79d4b SDJ |
11291 | /* Checking if the expression is not constant. */ |
11292 | if (watchpoint_exp_is_const (exp)) | |
11293 | { | |
11294 | int len; | |
11295 | ||
11296 | len = exp_end - exp_start; | |
11297 | while (len > 0 && isspace (exp_start[len - 1])) | |
11298 | len--; | |
11299 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11300 | } | |
11301 | ||
c906108c SS |
11302 | exp_valid_block = innermost_block; |
11303 | mark = value_mark (); | |
3a1115a0 | 11304 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11305 | |
bb9d5f81 PP |
11306 | if (val != NULL && just_location) |
11307 | { | |
11308 | saved_bitpos = value_bitpos (val); | |
11309 | saved_bitsize = value_bitsize (val); | |
11310 | } | |
11311 | ||
06a64a0b TT |
11312 | if (just_location) |
11313 | { | |
9c06b0b4 TJB |
11314 | int ret; |
11315 | ||
06a64a0b | 11316 | exp_valid_block = NULL; |
a1442452 | 11317 | val = value_addr (result); |
06a64a0b TT |
11318 | release_value (val); |
11319 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11320 | |
11321 | if (use_mask) | |
11322 | { | |
11323 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11324 | mask); | |
11325 | if (ret == -1) | |
11326 | error (_("This target does not support masked watchpoints.")); | |
11327 | else if (ret == -2) | |
11328 | error (_("Invalid mask or memory region.")); | |
11329 | } | |
06a64a0b TT |
11330 | } |
11331 | else if (val != NULL) | |
fa4727a6 | 11332 | release_value (val); |
c906108c | 11333 | |
bbc13ae3 KS |
11334 | tok = skip_spaces_const (arg); |
11335 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11336 | |
11337 | toklen = end_tok - tok; | |
11338 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11339 | { | |
2d134ed3 PA |
11340 | struct expression *cond; |
11341 | ||
60e1c644 | 11342 | innermost_block = NULL; |
c906108c | 11343 | tok = cond_start = end_tok + 1; |
1bb9788d | 11344 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11345 | |
11346 | /* The watchpoint expression may not be local, but the condition | |
11347 | may still be. E.g.: `watch global if local > 0'. */ | |
11348 | cond_exp_valid_block = innermost_block; | |
11349 | ||
2d134ed3 | 11350 | xfree (cond); |
c906108c SS |
11351 | cond_end = tok; |
11352 | } | |
11353 | if (*tok) | |
8a3fe4f8 | 11354 | error (_("Junk at end of command.")); |
c906108c | 11355 | |
d983da9c | 11356 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11357 | |
11358 | /* If the expression is "local", then set up a "watchpoint scope" | |
11359 | breakpoint at the point where we've left the scope of the watchpoint | |
11360 | expression. Create the scope breakpoint before the watchpoint, so | |
11361 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11362 | if (exp_valid_block && frame) |
d983da9c | 11363 | { |
edb3359d DJ |
11364 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11365 | { | |
11366 | scope_breakpoint | |
a6d9a66e UW |
11367 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11368 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11369 | bp_watchpoint_scope, |
11370 | &momentary_breakpoint_ops); | |
d983da9c | 11371 | |
edb3359d | 11372 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11373 | |
edb3359d DJ |
11374 | /* Automatically delete the breakpoint when it hits. */ |
11375 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11376 | |
edb3359d DJ |
11377 | /* Only break in the proper frame (help with recursion). */ |
11378 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11379 | |
edb3359d | 11380 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11381 | scope_breakpoint->loc->gdbarch |
11382 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11383 | scope_breakpoint->loc->requested_address |
11384 | = frame_unwind_caller_pc (frame); | |
11385 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11386 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11387 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11388 | scope_breakpoint->type); |
11389 | } | |
d983da9c DJ |
11390 | } |
11391 | ||
e8369a73 AB |
11392 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11393 | watchpoints here even if hardware watchpoints are turned off, a call | |
11394 | to update_watchpoint later in this function will cause the type to | |
11395 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11396 | ||
11397 | if (accessflag == hw_read) | |
11398 | bp_type = bp_read_watchpoint; | |
11399 | else if (accessflag == hw_access) | |
11400 | bp_type = bp_access_watchpoint; | |
11401 | else | |
11402 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11403 | |
11404 | w = XCNEW (struct watchpoint); | |
11405 | b = &w->base; | |
348d480f | 11406 | if (use_mask) |
3a5c3e22 PA |
11407 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11408 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11409 | else |
3a5c3e22 PA |
11410 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11411 | &watchpoint_breakpoint_ops); | |
37e4754d | 11412 | b->thread = thread; |
b5de0fa7 | 11413 | b->disposition = disp_donttouch; |
348d480f | 11414 | b->pspace = current_program_space; |
3a5c3e22 PA |
11415 | w->exp = exp; |
11416 | w->exp_valid_block = exp_valid_block; | |
11417 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11418 | if (just_location) |
11419 | { | |
11420 | struct type *t = value_type (val); | |
11421 | CORE_ADDR addr = value_as_address (val); | |
11422 | char *name; | |
11423 | ||
11424 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11425 | name = type_to_string (t); | |
11426 | ||
3a5c3e22 | 11427 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11428 | core_addr_to_string (addr)); |
06a64a0b TT |
11429 | xfree (name); |
11430 | ||
3a5c3e22 | 11431 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11432 | (int) (exp_end - exp_start), exp_start); |
11433 | ||
06a64a0b TT |
11434 | /* The above expression is in C. */ |
11435 | b->language = language_c; | |
11436 | } | |
11437 | else | |
3a5c3e22 | 11438 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11439 | |
11440 | if (use_mask) | |
11441 | { | |
3a5c3e22 | 11442 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11443 | } |
11444 | else | |
11445 | { | |
3a5c3e22 | 11446 | w->val = val; |
bb9d5f81 PP |
11447 | w->val_bitpos = saved_bitpos; |
11448 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11449 | w->val_valid = 1; |
9c06b0b4 | 11450 | } |
77b06cd7 | 11451 | |
c906108c SS |
11452 | if (cond_start) |
11453 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11454 | else | |
11455 | b->cond_string = 0; | |
c5aa993b | 11456 | |
c906108c | 11457 | if (frame) |
f6bc2008 | 11458 | { |
3a5c3e22 PA |
11459 | w->watchpoint_frame = get_frame_id (frame); |
11460 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11461 | } |
c906108c | 11462 | else |
f6bc2008 | 11463 | { |
3a5c3e22 PA |
11464 | w->watchpoint_frame = null_frame_id; |
11465 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11466 | } |
c906108c | 11467 | |
d983da9c | 11468 | if (scope_breakpoint != NULL) |
c906108c | 11469 | { |
d983da9c DJ |
11470 | /* The scope breakpoint is related to the watchpoint. We will |
11471 | need to act on them together. */ | |
11472 | b->related_breakpoint = scope_breakpoint; | |
11473 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11474 | } |
d983da9c | 11475 | |
06a64a0b TT |
11476 | if (!just_location) |
11477 | value_free_to_mark (mark); | |
2d134ed3 | 11478 | |
492d29ea | 11479 | TRY |
a9634178 TJB |
11480 | { |
11481 | /* Finally update the new watchpoint. This creates the locations | |
11482 | that should be inserted. */ | |
3a5c3e22 | 11483 | update_watchpoint (w, 1); |
a9634178 | 11484 | } |
492d29ea | 11485 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11486 | { |
11487 | delete_breakpoint (b); | |
11488 | throw_exception (e); | |
11489 | } | |
492d29ea | 11490 | END_CATCH |
a9634178 | 11491 | |
3ea46bff | 11492 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11493 | do_cleanups (back_to); |
c906108c SS |
11494 | } |
11495 | ||
e09342b5 | 11496 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11497 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11498 | |
c906108c | 11499 | static int |
a9634178 | 11500 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11501 | { |
11502 | int found_memory_cnt = 0; | |
2e70b7b9 | 11503 | struct value *head = v; |
c906108c SS |
11504 | |
11505 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11506 | if (!can_use_hw_watchpoints) |
c906108c | 11507 | return 0; |
c5aa993b | 11508 | |
5c44784c JM |
11509 | /* Make sure that the value of the expression depends only upon |
11510 | memory contents, and values computed from them within GDB. If we | |
11511 | find any register references or function calls, we can't use a | |
11512 | hardware watchpoint. | |
11513 | ||
11514 | The idea here is that evaluating an expression generates a series | |
11515 | of values, one holding the value of every subexpression. (The | |
11516 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11517 | a*b+c.) GDB's values hold almost enough information to establish | |
11518 | the criteria given above --- they identify memory lvalues, | |
11519 | register lvalues, computed values, etcetera. So we can evaluate | |
11520 | the expression, and then scan the chain of values that leaves | |
11521 | behind to decide whether we can detect any possible change to the | |
11522 | expression's final value using only hardware watchpoints. | |
11523 | ||
11524 | However, I don't think that the values returned by inferior | |
11525 | function calls are special in any way. So this function may not | |
11526 | notice that an expression involving an inferior function call | |
11527 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11528 | for (; v; v = value_next (v)) |
c906108c | 11529 | { |
5c44784c | 11530 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11531 | { |
8464be76 DJ |
11532 | if (v != head && value_lazy (v)) |
11533 | /* A lazy memory lvalue in the chain is one that GDB never | |
11534 | needed to fetch; we either just used its address (e.g., | |
11535 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11536 | in `a,b'). This doesn't apply to HEAD; if that is | |
11537 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11538 | ; |
53a5351d | 11539 | else |
5c44784c JM |
11540 | { |
11541 | /* Ahh, memory we actually used! Check if we can cover | |
11542 | it with hardware watchpoints. */ | |
df407dfe | 11543 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11544 | |
11545 | /* We only watch structs and arrays if user asked for it | |
11546 | explicitly, never if they just happen to appear in a | |
11547 | middle of some value chain. */ | |
11548 | if (v == head | |
11549 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11550 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11551 | { | |
42ae5230 | 11552 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11553 | int len; |
11554 | int num_regs; | |
11555 | ||
a9634178 | 11556 | len = (target_exact_watchpoints |
e09342b5 TJB |
11557 | && is_scalar_type_recursive (vtype))? |
11558 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11559 | |
e09342b5 TJB |
11560 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11561 | if (!num_regs) | |
2e70b7b9 MS |
11562 | return 0; |
11563 | else | |
e09342b5 | 11564 | found_memory_cnt += num_regs; |
2e70b7b9 | 11565 | } |
5c44784c | 11566 | } |
c5aa993b | 11567 | } |
5086187c AC |
11568 | else if (VALUE_LVAL (v) != not_lval |
11569 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11570 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11571 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11572 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11573 | } |
11574 | ||
11575 | /* The expression itself looks suitable for using a hardware | |
11576 | watchpoint, but give the target machine a chance to reject it. */ | |
11577 | return found_memory_cnt; | |
11578 | } | |
11579 | ||
8b93c638 | 11580 | void |
84f4c1fe | 11581 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11582 | { |
84f4c1fe | 11583 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11584 | } |
11585 | ||
06a64a0b TT |
11586 | /* A helper function that looks for the "-location" argument and then |
11587 | calls watch_command_1. */ | |
11588 | ||
11589 | static void | |
11590 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11591 | { | |
11592 | int just_location = 0; | |
11593 | ||
11594 | if (arg | |
11595 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11596 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11597 | { | |
e9cafbcc | 11598 | arg = skip_spaces (arg); |
06a64a0b TT |
11599 | just_location = 1; |
11600 | } | |
11601 | ||
84f4c1fe | 11602 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11603 | } |
8926118c | 11604 | |
c5aa993b | 11605 | static void |
fba45db2 | 11606 | watch_command (char *arg, int from_tty) |
c906108c | 11607 | { |
06a64a0b | 11608 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11609 | } |
11610 | ||
8b93c638 | 11611 | void |
84f4c1fe | 11612 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11613 | { |
84f4c1fe | 11614 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11615 | } |
8926118c | 11616 | |
c5aa993b | 11617 | static void |
fba45db2 | 11618 | rwatch_command (char *arg, int from_tty) |
c906108c | 11619 | { |
06a64a0b | 11620 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11621 | } |
11622 | ||
8b93c638 | 11623 | void |
84f4c1fe | 11624 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11625 | { |
84f4c1fe | 11626 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11627 | } |
8926118c | 11628 | |
c5aa993b | 11629 | static void |
fba45db2 | 11630 | awatch_command (char *arg, int from_tty) |
c906108c | 11631 | { |
06a64a0b | 11632 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11633 | } |
c906108c | 11634 | \f |
c5aa993b | 11635 | |
cfc31633 PA |
11636 | /* Data for the FSM that manages the until(location)/advance commands |
11637 | in infcmd.c. Here because it uses the mechanisms of | |
11638 | breakpoints. */ | |
c906108c | 11639 | |
cfc31633 | 11640 | struct until_break_fsm |
bfec99b2 | 11641 | { |
cfc31633 PA |
11642 | /* The base class. */ |
11643 | struct thread_fsm thread_fsm; | |
11644 | ||
11645 | /* The thread that as current when the command was executed. */ | |
11646 | int thread; | |
11647 | ||
11648 | /* The breakpoint set at the destination location. */ | |
11649 | struct breakpoint *location_breakpoint; | |
11650 | ||
11651 | /* Breakpoint set at the return address in the caller frame. May be | |
11652 | NULL. */ | |
11653 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11654 | }; |
11655 | ||
8980e177 PA |
11656 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11657 | struct thread_info *thread); | |
11658 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11659 | struct thread_info *thread); | |
cfc31633 PA |
11660 | static enum async_reply_reason |
11661 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11662 | ||
11663 | /* until_break_fsm's vtable. */ | |
11664 | ||
11665 | static struct thread_fsm_ops until_break_fsm_ops = | |
11666 | { | |
11667 | NULL, /* dtor */ | |
11668 | until_break_fsm_clean_up, | |
11669 | until_break_fsm_should_stop, | |
11670 | NULL, /* return_value */ | |
11671 | until_break_fsm_async_reply_reason, | |
11672 | }; | |
11673 | ||
11674 | /* Allocate a new until_break_command_fsm. */ | |
11675 | ||
11676 | static struct until_break_fsm * | |
8980e177 | 11677 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11678 | struct breakpoint *location_breakpoint, |
11679 | struct breakpoint *caller_breakpoint) | |
11680 | { | |
11681 | struct until_break_fsm *sm; | |
11682 | ||
11683 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11684 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11685 | |
11686 | sm->thread = thread; | |
11687 | sm->location_breakpoint = location_breakpoint; | |
11688 | sm->caller_breakpoint = caller_breakpoint; | |
11689 | ||
11690 | return sm; | |
11691 | } | |
11692 | ||
11693 | /* Implementation of the 'should_stop' FSM method for the | |
11694 | until(location)/advance commands. */ | |
11695 | ||
11696 | static int | |
8980e177 PA |
11697 | until_break_fsm_should_stop (struct thread_fsm *self, |
11698 | struct thread_info *tp) | |
cfc31633 PA |
11699 | { |
11700 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11701 | |
11702 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11703 | sm->location_breakpoint) != NULL | |
11704 | || (sm->caller_breakpoint != NULL | |
11705 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11706 | sm->caller_breakpoint) != NULL)) | |
11707 | thread_fsm_set_finished (self); | |
11708 | ||
11709 | return 1; | |
11710 | } | |
11711 | ||
11712 | /* Implementation of the 'clean_up' FSM method for the | |
11713 | until(location)/advance commands. */ | |
11714 | ||
c2c6d25f | 11715 | static void |
8980e177 PA |
11716 | until_break_fsm_clean_up (struct thread_fsm *self, |
11717 | struct thread_info *thread) | |
43ff13b4 | 11718 | { |
cfc31633 | 11719 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11720 | |
cfc31633 PA |
11721 | /* Clean up our temporary breakpoints. */ |
11722 | if (sm->location_breakpoint != NULL) | |
11723 | { | |
11724 | delete_breakpoint (sm->location_breakpoint); | |
11725 | sm->location_breakpoint = NULL; | |
11726 | } | |
11727 | if (sm->caller_breakpoint != NULL) | |
11728 | { | |
11729 | delete_breakpoint (sm->caller_breakpoint); | |
11730 | sm->caller_breakpoint = NULL; | |
11731 | } | |
11732 | delete_longjmp_breakpoint (sm->thread); | |
11733 | } | |
11734 | ||
11735 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11736 | until(location)/advance commands. */ | |
11737 | ||
11738 | static enum async_reply_reason | |
11739 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11740 | { | |
11741 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11742 | } |
11743 | ||
c906108c | 11744 | void |
ae66c1fc | 11745 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11746 | { |
11747 | struct symtabs_and_lines sals; | |
11748 | struct symtab_and_line sal; | |
8556afb4 PA |
11749 | struct frame_info *frame; |
11750 | struct gdbarch *frame_gdbarch; | |
11751 | struct frame_id stack_frame_id; | |
11752 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11753 | struct breakpoint *location_breakpoint; |
11754 | struct breakpoint *caller_breakpoint = NULL; | |
f00aae0f | 11755 | struct cleanup *old_chain, *cleanup; |
186c406b TT |
11756 | int thread; |
11757 | struct thread_info *tp; | |
f00aae0f | 11758 | struct event_location *location; |
cfc31633 | 11759 | struct until_break_fsm *sm; |
c906108c | 11760 | |
70509625 | 11761 | clear_proceed_status (0); |
c906108c SS |
11762 | |
11763 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11764 | this function. */ |
c5aa993b | 11765 | |
f00aae0f KS |
11766 | location = string_to_event_location (&arg, current_language); |
11767 | cleanup = make_cleanup_delete_event_location (location); | |
11768 | ||
1bfeeb0f | 11769 | if (last_displayed_sal_is_valid ()) |
c2f4122d | 11770 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11771 | get_last_displayed_symtab (), |
f8eba3c6 | 11772 | get_last_displayed_line ()); |
c906108c | 11773 | else |
f00aae0f | 11774 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11775 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11776 | |
c906108c | 11777 | if (sals.nelts != 1) |
8a3fe4f8 | 11778 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11779 | |
c906108c | 11780 | sal = sals.sals[0]; |
4a64f543 | 11781 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11782 | |
c906108c | 11783 | if (*arg) |
8a3fe4f8 | 11784 | error (_("Junk at end of arguments.")); |
c5aa993b | 11785 | |
c906108c | 11786 | resolve_sal_pc (&sal); |
c5aa993b | 11787 | |
186c406b | 11788 | tp = inferior_thread (); |
5d5658a1 | 11789 | thread = tp->global_num; |
186c406b | 11790 | |
883bc8d1 PA |
11791 | old_chain = make_cleanup (null_cleanup, NULL); |
11792 | ||
8556afb4 PA |
11793 | /* Note linespec handling above invalidates the frame chain. |
11794 | Installing a breakpoint also invalidates the frame chain (as it | |
11795 | may need to switch threads), so do any frame handling before | |
11796 | that. */ | |
11797 | ||
11798 | frame = get_selected_frame (NULL); | |
11799 | frame_gdbarch = get_frame_arch (frame); | |
11800 | stack_frame_id = get_stack_frame_id (frame); | |
11801 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11802 | |
ae66c1fc EZ |
11803 | /* Keep within the current frame, or in frames called by the current |
11804 | one. */ | |
edb3359d | 11805 | |
883bc8d1 | 11806 | if (frame_id_p (caller_frame_id)) |
c906108c | 11807 | { |
883bc8d1 | 11808 | struct symtab_and_line sal2; |
cfc31633 | 11809 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11810 | |
11811 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11812 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11813 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11814 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11815 | sal2, | |
11816 | caller_frame_id, | |
11817 | bp_until); | |
11818 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11819 | |
883bc8d1 | 11820 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11821 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11822 | } |
c5aa993b | 11823 | |
c70a6932 JK |
11824 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11825 | frame = NULL; | |
11826 | ||
883bc8d1 PA |
11827 | if (anywhere) |
11828 | /* If the user told us to continue until a specified location, | |
11829 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11830 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11831 | null_frame_id, bp_until); | |
883bc8d1 PA |
11832 | else |
11833 | /* Otherwise, specify the selected frame, because we want to stop | |
11834 | only at the very same frame. */ | |
cfc31633 PA |
11835 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11836 | stack_frame_id, bp_until); | |
11837 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11838 | |
8980e177 | 11839 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11840 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11841 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11842 | |
cfc31633 | 11843 | discard_cleanups (old_chain); |
f107f563 | 11844 | |
cfc31633 | 11845 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f00aae0f KS |
11846 | |
11847 | do_cleanups (cleanup); | |
c906108c | 11848 | } |
ae66c1fc | 11849 | |
c906108c SS |
11850 | /* This function attempts to parse an optional "if <cond>" clause |
11851 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11852 | |
c906108c SS |
11853 | Else, it returns a pointer to the condition string. (It does not |
11854 | attempt to evaluate the string against a particular block.) And, | |
11855 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11856 | if clause in the arg string. */ |
53a5351d | 11857 | |
916703c0 | 11858 | char * |
fba45db2 | 11859 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11860 | { |
c5aa993b JM |
11861 | char *cond_string; |
11862 | ||
11863 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11864 | return NULL; |
c5aa993b | 11865 | |
4a64f543 | 11866 | /* Skip the "if" keyword. */ |
c906108c | 11867 | (*arg) += 2; |
c5aa993b | 11868 | |
c906108c | 11869 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11870 | condition string. */ |
e9cafbcc | 11871 | *arg = skip_spaces (*arg); |
c906108c | 11872 | cond_string = *arg; |
c5aa993b | 11873 | |
4a64f543 MS |
11874 | /* Assume that the condition occupies the remainder of the arg |
11875 | string. */ | |
c906108c | 11876 | (*arg) += strlen (cond_string); |
c5aa993b | 11877 | |
c906108c SS |
11878 | return cond_string; |
11879 | } | |
c5aa993b | 11880 | |
c906108c SS |
11881 | /* Commands to deal with catching events, such as signals, exceptions, |
11882 | process start/exit, etc. */ | |
c5aa993b JM |
11883 | |
11884 | typedef enum | |
11885 | { | |
44feb3ce TT |
11886 | catch_fork_temporary, catch_vfork_temporary, |
11887 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11888 | } |
11889 | catch_fork_kind; | |
11890 | ||
c906108c | 11891 | static void |
cc59ec59 MS |
11892 | catch_fork_command_1 (char *arg, int from_tty, |
11893 | struct cmd_list_element *command) | |
c906108c | 11894 | { |
a6d9a66e | 11895 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11896 | char *cond_string = NULL; |
44feb3ce TT |
11897 | catch_fork_kind fork_kind; |
11898 | int tempflag; | |
11899 | ||
11900 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11901 | tempflag = (fork_kind == catch_fork_temporary | |
11902 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11903 | |
44feb3ce TT |
11904 | if (!arg) |
11905 | arg = ""; | |
e9cafbcc | 11906 | arg = skip_spaces (arg); |
c5aa993b | 11907 | |
c906108c | 11908 | /* The allowed syntax is: |
c5aa993b JM |
11909 | catch [v]fork |
11910 | catch [v]fork if <cond> | |
11911 | ||
4a64f543 | 11912 | First, check if there's an if clause. */ |
c906108c | 11913 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11914 | |
c906108c | 11915 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11916 | error (_("Junk at end of arguments.")); |
c5aa993b | 11917 | |
c906108c | 11918 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11919 | and enable reporting of such events. */ |
c5aa993b JM |
11920 | switch (fork_kind) |
11921 | { | |
44feb3ce TT |
11922 | case catch_fork_temporary: |
11923 | case catch_fork_permanent: | |
a6d9a66e | 11924 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11925 | &catch_fork_breakpoint_ops); |
c906108c | 11926 | break; |
44feb3ce TT |
11927 | case catch_vfork_temporary: |
11928 | case catch_vfork_permanent: | |
a6d9a66e | 11929 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11930 | &catch_vfork_breakpoint_ops); |
c906108c | 11931 | break; |
c5aa993b | 11932 | default: |
8a3fe4f8 | 11933 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11934 | break; |
c5aa993b | 11935 | } |
c906108c SS |
11936 | } |
11937 | ||
11938 | static void | |
cc59ec59 MS |
11939 | catch_exec_command_1 (char *arg, int from_tty, |
11940 | struct cmd_list_element *command) | |
c906108c | 11941 | { |
b4d90040 | 11942 | struct exec_catchpoint *c; |
a6d9a66e | 11943 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11944 | int tempflag; |
c5aa993b | 11945 | char *cond_string = NULL; |
c906108c | 11946 | |
44feb3ce TT |
11947 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11948 | ||
11949 | if (!arg) | |
11950 | arg = ""; | |
e9cafbcc | 11951 | arg = skip_spaces (arg); |
c906108c SS |
11952 | |
11953 | /* The allowed syntax is: | |
c5aa993b JM |
11954 | catch exec |
11955 | catch exec if <cond> | |
c906108c | 11956 | |
4a64f543 | 11957 | First, check if there's an if clause. */ |
c906108c SS |
11958 | cond_string = ep_parse_optional_if_clause (&arg); |
11959 | ||
11960 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11961 | error (_("Junk at end of arguments.")); |
c906108c | 11962 | |
b4d90040 PA |
11963 | c = XNEW (struct exec_catchpoint); |
11964 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11965 | &catch_exec_breakpoint_ops); | |
11966 | c->exec_pathname = NULL; | |
11967 | ||
3ea46bff | 11968 | install_breakpoint (0, &c->base, 1); |
c906108c | 11969 | } |
c5aa993b | 11970 | |
9ac4176b | 11971 | void |
28010a5d PA |
11972 | init_ada_exception_breakpoint (struct breakpoint *b, |
11973 | struct gdbarch *gdbarch, | |
11974 | struct symtab_and_line sal, | |
11975 | char *addr_string, | |
c0a91b2b | 11976 | const struct breakpoint_ops *ops, |
28010a5d | 11977 | int tempflag, |
349774ef | 11978 | int enabled, |
28010a5d | 11979 | int from_tty) |
f7f9143b | 11980 | { |
f7f9143b JB |
11981 | if (from_tty) |
11982 | { | |
5af949e3 UW |
11983 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11984 | if (!loc_gdbarch) | |
11985 | loc_gdbarch = gdbarch; | |
11986 | ||
6c95b8df PA |
11987 | describe_other_breakpoints (loc_gdbarch, |
11988 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11989 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11990 | version for exception catchpoints, because two catchpoints | |
11991 | used for different exception names will use the same address. | |
11992 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11993 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11994 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11995 | the user what type of catchpoint it is. The above is good |
11996 | enough for now, though. */ | |
11997 | } | |
11998 | ||
28010a5d | 11999 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 12000 | |
349774ef | 12001 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 12002 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f00aae0f KS |
12003 | b->location = string_to_event_location (&addr_string, |
12004 | language_def (language_ada)); | |
f7f9143b | 12005 | b->language = language_ada; |
f7f9143b JB |
12006 | } |
12007 | ||
c906108c | 12008 | static void |
fba45db2 | 12009 | catch_command (char *arg, int from_tty) |
c906108c | 12010 | { |
44feb3ce | 12011 | error (_("Catch requires an event name.")); |
c906108c SS |
12012 | } |
12013 | \f | |
12014 | ||
12015 | static void | |
fba45db2 | 12016 | tcatch_command (char *arg, int from_tty) |
c906108c | 12017 | { |
44feb3ce | 12018 | error (_("Catch requires an event name.")); |
c906108c SS |
12019 | } |
12020 | ||
8a2c437b TT |
12021 | /* A qsort comparison function that sorts breakpoints in order. */ |
12022 | ||
12023 | static int | |
12024 | compare_breakpoints (const void *a, const void *b) | |
12025 | { | |
9a3c8263 | 12026 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 12027 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 12028 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
12029 | uintptr_t ub = (uintptr_t) *bb; |
12030 | ||
12031 | if ((*ba)->number < (*bb)->number) | |
12032 | return -1; | |
12033 | else if ((*ba)->number > (*bb)->number) | |
12034 | return 1; | |
12035 | ||
12036 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
12037 | the number 0. */ | |
12038 | if (ua < ub) | |
12039 | return -1; | |
94b0e70d | 12040 | return ua > ub ? 1 : 0; |
8a2c437b TT |
12041 | } |
12042 | ||
80f8a6eb | 12043 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12044 | |
12045 | static void | |
fba45db2 | 12046 | clear_command (char *arg, int from_tty) |
c906108c | 12047 | { |
8a2c437b | 12048 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12049 | VEC(breakpoint_p) *found = 0; |
12050 | int ix; | |
c906108c SS |
12051 | int default_match; |
12052 | struct symtabs_and_lines sals; | |
12053 | struct symtab_and_line sal; | |
c906108c | 12054 | int i; |
8a2c437b | 12055 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12056 | |
12057 | if (arg) | |
12058 | { | |
39cf75f7 DE |
12059 | sals = decode_line_with_current_source (arg, |
12060 | (DECODE_LINE_FUNFIRSTLINE | |
12061 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12062 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12063 | default_match = 0; |
12064 | } | |
12065 | else | |
12066 | { | |
8d749320 | 12067 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 12068 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12069 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12070 | |
12071 | /* Set sal's line, symtab, pc, and pspace to the values | |
12072 | corresponding to the last call to print_frame_info. If the | |
12073 | codepoint is not valid, this will set all the fields to 0. */ | |
12074 | get_last_displayed_sal (&sal); | |
c906108c | 12075 | if (sal.symtab == 0) |
8a3fe4f8 | 12076 | error (_("No source file specified.")); |
c906108c SS |
12077 | |
12078 | sals.sals[0] = sal; | |
12079 | sals.nelts = 1; | |
12080 | ||
12081 | default_match = 1; | |
12082 | } | |
12083 | ||
4a64f543 MS |
12084 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12085 | seems, because all existing breakpoints typically have both | |
12086 | file/line and pc set. So, if clear is given file/line, we can | |
12087 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12088 | |
12089 | We only support clearing given the address explicitly | |
12090 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12091 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12092 | due to optimization, all in one block. |
4a64f543 MS |
12093 | |
12094 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12095 | PC corresponding to the same file:line, the breakpoint won't |
12096 | be cleared. We probably can still clear the breakpoint, but | |
12097 | since the other PC value is never presented to user, user | |
12098 | can only find it by guessing, and it does not seem important | |
12099 | to support that. */ | |
12100 | ||
4a64f543 MS |
12101 | /* For each line spec given, delete bps which correspond to it. Do |
12102 | it in two passes, solely to preserve the current behavior that | |
12103 | from_tty is forced true if we delete more than one | |
12104 | breakpoint. */ | |
c906108c | 12105 | |
80f8a6eb | 12106 | found = NULL; |
8a2c437b | 12107 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12108 | for (i = 0; i < sals.nelts; i++) |
12109 | { | |
05cba821 JK |
12110 | const char *sal_fullname; |
12111 | ||
c906108c | 12112 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12113 | If line given (pc == 0), clear all bpts on specified line. |
12114 | If defaulting, clear all bpts on default line | |
c906108c | 12115 | or at default pc. |
c5aa993b JM |
12116 | |
12117 | defaulting sal.pc != 0 tests to do | |
12118 | ||
12119 | 0 1 pc | |
12120 | 1 1 pc _and_ line | |
12121 | 0 0 line | |
12122 | 1 0 <can't happen> */ | |
c906108c SS |
12123 | |
12124 | sal = sals.sals[i]; | |
05cba821 JK |
12125 | sal_fullname = (sal.symtab == NULL |
12126 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12127 | |
4a64f543 | 12128 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12129 | ALL_BREAKPOINTS (b) |
c5aa993b | 12130 | { |
0d381245 | 12131 | int match = 0; |
4a64f543 | 12132 | /* Are we going to delete b? */ |
cc60f2e3 | 12133 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12134 | { |
12135 | struct bp_location *loc = b->loc; | |
12136 | for (; loc; loc = loc->next) | |
12137 | { | |
f8eba3c6 TT |
12138 | /* If the user specified file:line, don't allow a PC |
12139 | match. This matches historical gdb behavior. */ | |
12140 | int pc_match = (!sal.explicit_line | |
12141 | && sal.pc | |
12142 | && (loc->pspace == sal.pspace) | |
12143 | && (loc->address == sal.pc) | |
12144 | && (!section_is_overlay (loc->section) | |
12145 | || loc->section == sal.section)); | |
4aac40c8 TT |
12146 | int line_match = 0; |
12147 | ||
12148 | if ((default_match || sal.explicit_line) | |
2f202fde | 12149 | && loc->symtab != NULL |
05cba821 | 12150 | && sal_fullname != NULL |
4aac40c8 | 12151 | && sal.pspace == loc->pspace |
05cba821 JK |
12152 | && loc->line_number == sal.line |
12153 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12154 | sal_fullname) == 0) | |
12155 | line_match = 1; | |
4aac40c8 | 12156 | |
0d381245 VP |
12157 | if (pc_match || line_match) |
12158 | { | |
12159 | match = 1; | |
12160 | break; | |
12161 | } | |
12162 | } | |
12163 | } | |
12164 | ||
12165 | if (match) | |
d6e956e5 | 12166 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12167 | } |
80f8a6eb | 12168 | } |
8a2c437b | 12169 | |
80f8a6eb | 12170 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12171 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12172 | { |
12173 | if (arg) | |
8a3fe4f8 | 12174 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12175 | else |
8a3fe4f8 | 12176 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12177 | } |
c906108c | 12178 | |
8a2c437b TT |
12179 | /* Remove duplicates from the vec. */ |
12180 | qsort (VEC_address (breakpoint_p, found), | |
12181 | VEC_length (breakpoint_p, found), | |
12182 | sizeof (breakpoint_p), | |
12183 | compare_breakpoints); | |
12184 | prev = VEC_index (breakpoint_p, found, 0); | |
12185 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12186 | { | |
12187 | if (b == prev) | |
12188 | { | |
12189 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12190 | --ix; | |
12191 | } | |
12192 | } | |
12193 | ||
d6e956e5 | 12194 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12195 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12196 | if (from_tty) |
a3f17187 | 12197 | { |
d6e956e5 | 12198 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12199 | printf_unfiltered (_("Deleted breakpoint ")); |
12200 | else | |
12201 | printf_unfiltered (_("Deleted breakpoints ")); | |
12202 | } | |
d6e956e5 VP |
12203 | |
12204 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12205 | { |
c5aa993b | 12206 | if (from_tty) |
d6e956e5 VP |
12207 | printf_unfiltered ("%d ", b->number); |
12208 | delete_breakpoint (b); | |
c906108c | 12209 | } |
80f8a6eb MS |
12210 | if (from_tty) |
12211 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12212 | |
12213 | do_cleanups (cleanups); | |
c906108c SS |
12214 | } |
12215 | \f | |
12216 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12217 | all breakpoints that are marked for deletion, whether hit or not. | |
12218 | This is called after any breakpoint is hit, or after errors. */ | |
12219 | ||
12220 | void | |
fba45db2 | 12221 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12222 | { |
35df4500 | 12223 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12224 | |
12225 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12226 | if (bs->breakpoint_at |
12227 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12228 | && bs->stop) |
f431efe5 | 12229 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12230 | |
35df4500 | 12231 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12232 | { |
b5de0fa7 | 12233 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12234 | delete_breakpoint (b); |
12235 | } | |
c906108c SS |
12236 | } |
12237 | ||
4a64f543 MS |
12238 | /* A comparison function for bp_location AP and BP being interfaced to |
12239 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12240 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12241 | secondarily by ordering first permanent elements and |
4a64f543 | 12242 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12243 | qsort being an unstable algorithm. */ |
876fa593 JK |
12244 | |
12245 | static int | |
494cfb0f | 12246 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12247 | { |
9a3c8263 SM |
12248 | const struct bp_location *a = *(const struct bp_location **) ap; |
12249 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12250 | |
12251 | if (a->address != b->address) | |
12252 | return (a->address > b->address) - (a->address < b->address); | |
12253 | ||
dea2aa5f LM |
12254 | /* Sort locations at the same address by their pspace number, keeping |
12255 | locations of the same inferior (in a multi-inferior environment) | |
12256 | grouped. */ | |
12257 | ||
12258 | if (a->pspace->num != b->pspace->num) | |
12259 | return ((a->pspace->num > b->pspace->num) | |
12260 | - (a->pspace->num < b->pspace->num)); | |
12261 | ||
876fa593 | 12262 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12263 | if (a->permanent != b->permanent) |
12264 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12265 | |
c56a97f9 JK |
12266 | /* Make the internal GDB representation stable across GDB runs |
12267 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12268 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12269 | |
12270 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12271 | return ((a->owner->number > b->owner->number) |
12272 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12273 | |
12274 | return (a > b) - (a < b); | |
12275 | } | |
12276 | ||
876fa593 | 12277 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12278 | bp_location_shadow_len_after_address_max according to the current |
12279 | content of the bp_location array. */ | |
f7545552 TT |
12280 | |
12281 | static void | |
876fa593 | 12282 | bp_location_target_extensions_update (void) |
f7545552 | 12283 | { |
876fa593 JK |
12284 | struct bp_location *bl, **blp_tmp; |
12285 | ||
12286 | bp_location_placed_address_before_address_max = 0; | |
12287 | bp_location_shadow_len_after_address_max = 0; | |
12288 | ||
12289 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12290 | { | |
12291 | CORE_ADDR start, end, addr; | |
12292 | ||
12293 | if (!bp_location_has_shadow (bl)) | |
12294 | continue; | |
12295 | ||
12296 | start = bl->target_info.placed_address; | |
12297 | end = start + bl->target_info.shadow_len; | |
12298 | ||
12299 | gdb_assert (bl->address >= start); | |
12300 | addr = bl->address - start; | |
12301 | if (addr > bp_location_placed_address_before_address_max) | |
12302 | bp_location_placed_address_before_address_max = addr; | |
12303 | ||
12304 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12305 | ||
12306 | gdb_assert (bl->address < end); | |
12307 | addr = end - bl->address; | |
12308 | if (addr > bp_location_shadow_len_after_address_max) | |
12309 | bp_location_shadow_len_after_address_max = addr; | |
12310 | } | |
f7545552 TT |
12311 | } |
12312 | ||
1e4d1764 YQ |
12313 | /* Download tracepoint locations if they haven't been. */ |
12314 | ||
12315 | static void | |
12316 | download_tracepoint_locations (void) | |
12317 | { | |
7ed2c994 | 12318 | struct breakpoint *b; |
1e4d1764 | 12319 | struct cleanup *old_chain; |
dd2e65cc | 12320 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12321 | |
12322 | old_chain = save_current_space_and_thread (); | |
12323 | ||
7ed2c994 | 12324 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12325 | { |
7ed2c994 | 12326 | struct bp_location *bl; |
1e4d1764 | 12327 | struct tracepoint *t; |
f2a8bc8a | 12328 | int bp_location_downloaded = 0; |
1e4d1764 | 12329 | |
7ed2c994 | 12330 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12331 | ? !may_insert_fast_tracepoints |
12332 | : !may_insert_tracepoints)) | |
12333 | continue; | |
12334 | ||
dd2e65cc YQ |
12335 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12336 | { | |
12337 | if (target_can_download_tracepoint ()) | |
12338 | can_download_tracepoint = TRIBOOL_TRUE; | |
12339 | else | |
12340 | can_download_tracepoint = TRIBOOL_FALSE; | |
12341 | } | |
12342 | ||
12343 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12344 | break; | |
12345 | ||
7ed2c994 YQ |
12346 | for (bl = b->loc; bl; bl = bl->next) |
12347 | { | |
12348 | /* In tracepoint, locations are _never_ duplicated, so | |
12349 | should_be_inserted is equivalent to | |
12350 | unduplicated_should_be_inserted. */ | |
12351 | if (!should_be_inserted (bl) || bl->inserted) | |
12352 | continue; | |
1e4d1764 | 12353 | |
7ed2c994 | 12354 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12355 | |
7ed2c994 | 12356 | target_download_tracepoint (bl); |
1e4d1764 | 12357 | |
7ed2c994 | 12358 | bl->inserted = 1; |
f2a8bc8a | 12359 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12360 | } |
12361 | t = (struct tracepoint *) b; | |
12362 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12363 | if (bp_location_downloaded) |
12364 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12365 | } |
12366 | ||
12367 | do_cleanups (old_chain); | |
12368 | } | |
12369 | ||
934709f0 PW |
12370 | /* Swap the insertion/duplication state between two locations. */ |
12371 | ||
12372 | static void | |
12373 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12374 | { | |
12375 | const int left_inserted = left->inserted; | |
12376 | const int left_duplicate = left->duplicate; | |
b775012e | 12377 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12378 | const struct bp_target_info left_target_info = left->target_info; |
12379 | ||
1e4d1764 YQ |
12380 | /* Locations of tracepoints can never be duplicated. */ |
12381 | if (is_tracepoint (left->owner)) | |
12382 | gdb_assert (!left->duplicate); | |
12383 | if (is_tracepoint (right->owner)) | |
12384 | gdb_assert (!right->duplicate); | |
12385 | ||
934709f0 PW |
12386 | left->inserted = right->inserted; |
12387 | left->duplicate = right->duplicate; | |
b775012e | 12388 | left->needs_update = right->needs_update; |
934709f0 PW |
12389 | left->target_info = right->target_info; |
12390 | right->inserted = left_inserted; | |
12391 | right->duplicate = left_duplicate; | |
b775012e | 12392 | right->needs_update = left_needs_update; |
934709f0 PW |
12393 | right->target_info = left_target_info; |
12394 | } | |
12395 | ||
b775012e LM |
12396 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12397 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12398 | conditions on the target's side. Such conditions need to be updated on | |
12399 | the target. */ | |
12400 | ||
12401 | static void | |
12402 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12403 | { | |
12404 | struct bp_location **locp = NULL, **loc2p; | |
12405 | struct bp_location *loc; | |
12406 | CORE_ADDR address = 0; | |
12407 | int pspace_num; | |
12408 | ||
12409 | address = bl->address; | |
12410 | pspace_num = bl->pspace->num; | |
12411 | ||
12412 | /* This is only meaningful if the target is | |
12413 | evaluating conditions and if the user has | |
12414 | opted for condition evaluation on the target's | |
12415 | side. */ | |
12416 | if (gdb_evaluates_breakpoint_condition_p () | |
12417 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12418 | return; | |
12419 | ||
12420 | /* Flag all breakpoint locations with this address and | |
12421 | the same program space as the location | |
12422 | as "its condition has changed". We need to | |
12423 | update the conditions on the target's side. */ | |
12424 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12425 | { | |
12426 | loc = *loc2p; | |
12427 | ||
12428 | if (!is_breakpoint (loc->owner) | |
12429 | || pspace_num != loc->pspace->num) | |
12430 | continue; | |
12431 | ||
12432 | /* Flag the location appropriately. We use a different state to | |
12433 | let everyone know that we already updated the set of locations | |
12434 | with addr bl->address and program space bl->pspace. This is so | |
12435 | we don't have to keep calling these functions just to mark locations | |
12436 | that have already been marked. */ | |
12437 | loc->condition_changed = condition_updated; | |
12438 | ||
12439 | /* Free the agent expression bytecode as well. We will compute | |
12440 | it later on. */ | |
12441 | if (loc->cond_bytecode) | |
12442 | { | |
12443 | free_agent_expr (loc->cond_bytecode); | |
12444 | loc->cond_bytecode = NULL; | |
12445 | } | |
12446 | } | |
12447 | } | |
44702360 PA |
12448 | /* Called whether new breakpoints are created, or existing breakpoints |
12449 | deleted, to update the global location list and recompute which | |
12450 | locations are duplicate of which. | |
b775012e | 12451 | |
04086b45 PA |
12452 | The INSERT_MODE flag determines whether locations may not, may, or |
12453 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12454 | info. */ | |
b60e7edf | 12455 | |
0d381245 | 12456 | static void |
44702360 | 12457 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12458 | { |
74960c60 | 12459 | struct breakpoint *b; |
876fa593 | 12460 | struct bp_location **locp, *loc; |
f7545552 | 12461 | struct cleanup *cleanups; |
b775012e LM |
12462 | /* Last breakpoint location address that was marked for update. */ |
12463 | CORE_ADDR last_addr = 0; | |
12464 | /* Last breakpoint location program space that was marked for update. */ | |
12465 | int last_pspace_num = -1; | |
f7545552 | 12466 | |
2d134ed3 PA |
12467 | /* Used in the duplicates detection below. When iterating over all |
12468 | bp_locations, points to the first bp_location of a given address. | |
12469 | Breakpoints and watchpoints of different types are never | |
12470 | duplicates of each other. Keep one pointer for each type of | |
12471 | breakpoint/watchpoint, so we only need to loop over all locations | |
12472 | once. */ | |
12473 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12474 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12475 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12476 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12477 | |
4a64f543 MS |
12478 | /* Saved former bp_location array which we compare against the newly |
12479 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12480 | struct bp_location **old_location, **old_locp; |
12481 | unsigned old_location_count; | |
12482 | ||
12483 | old_location = bp_location; | |
12484 | old_location_count = bp_location_count; | |
12485 | bp_location = NULL; | |
12486 | bp_location_count = 0; | |
12487 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12488 | |
74960c60 | 12489 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12490 | for (loc = b->loc; loc; loc = loc->next) |
12491 | bp_location_count++; | |
12492 | ||
8d749320 | 12493 | bp_location = XNEWVEC (struct bp_location *, bp_location_count); |
876fa593 JK |
12494 | locp = bp_location; |
12495 | ALL_BREAKPOINTS (b) | |
12496 | for (loc = b->loc; loc; loc = loc->next) | |
12497 | *locp++ = loc; | |
12498 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12499 | bp_location_compare); |
876fa593 JK |
12500 | |
12501 | bp_location_target_extensions_update (); | |
74960c60 | 12502 | |
4a64f543 MS |
12503 | /* Identify bp_location instances that are no longer present in the |
12504 | new list, and therefore should be freed. Note that it's not | |
12505 | necessary that those locations should be removed from inferior -- | |
12506 | if there's another location at the same address (previously | |
12507 | marked as duplicate), we don't need to remove/insert the | |
12508 | location. | |
876fa593 | 12509 | |
4a64f543 MS |
12510 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12511 | and former bp_location array state respectively. */ | |
876fa593 JK |
12512 | |
12513 | locp = bp_location; | |
12514 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12515 | old_locp++) | |
74960c60 | 12516 | { |
876fa593 | 12517 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12518 | struct bp_location **loc2p; |
876fa593 | 12519 | |
e5dd4106 | 12520 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12521 | not, we have to free it. */ |
c7d46a38 | 12522 | int found_object = 0; |
20874c92 VP |
12523 | /* Tells if the location should remain inserted in the target. */ |
12524 | int keep_in_target = 0; | |
12525 | int removed = 0; | |
876fa593 | 12526 | |
4a64f543 MS |
12527 | /* Skip LOCP entries which will definitely never be needed. |
12528 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12529 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12530 | && (*locp)->address < old_loc->address) |
876fa593 | 12531 | locp++; |
c7d46a38 PA |
12532 | |
12533 | for (loc2p = locp; | |
12534 | (loc2p < bp_location + bp_location_count | |
12535 | && (*loc2p)->address == old_loc->address); | |
12536 | loc2p++) | |
12537 | { | |
b775012e LM |
12538 | /* Check if this is a new/duplicated location or a duplicated |
12539 | location that had its condition modified. If so, we want to send | |
12540 | its condition to the target if evaluation of conditions is taking | |
12541 | place there. */ | |
12542 | if ((*loc2p)->condition_changed == condition_modified | |
12543 | && (last_addr != old_loc->address | |
12544 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12545 | { |
b775012e LM |
12546 | force_breakpoint_reinsertion (*loc2p); |
12547 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12548 | } |
b775012e LM |
12549 | |
12550 | if (*loc2p == old_loc) | |
12551 | found_object = 1; | |
c7d46a38 | 12552 | } |
74960c60 | 12553 | |
b775012e LM |
12554 | /* We have already handled this address, update it so that we don't |
12555 | have to go through updates again. */ | |
12556 | last_addr = old_loc->address; | |
12557 | ||
12558 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12559 | if (!found_object) | |
12560 | force_breakpoint_reinsertion (old_loc); | |
12561 | ||
4a64f543 MS |
12562 | /* If this location is no longer present, and inserted, look if |
12563 | there's maybe a new location at the same address. If so, | |
12564 | mark that one inserted, and don't remove this one. This is | |
12565 | needed so that we don't have a time window where a breakpoint | |
12566 | at certain location is not inserted. */ | |
74960c60 | 12567 | |
876fa593 | 12568 | if (old_loc->inserted) |
0d381245 | 12569 | { |
4a64f543 MS |
12570 | /* If the location is inserted now, we might have to remove |
12571 | it. */ | |
74960c60 | 12572 | |
876fa593 | 12573 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12574 | { |
4a64f543 MS |
12575 | /* The location is still present in the location list, |
12576 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12577 | keep_in_target = 1; |
74960c60 VP |
12578 | } |
12579 | else | |
12580 | { | |
b775012e LM |
12581 | /* This location still exists, but it won't be kept in the |
12582 | target since it may have been disabled. We proceed to | |
12583 | remove its target-side condition. */ | |
12584 | ||
4a64f543 MS |
12585 | /* The location is either no longer present, or got |
12586 | disabled. See if there's another location at the | |
12587 | same address, in which case we don't need to remove | |
12588 | this one from the target. */ | |
876fa593 | 12589 | |
2bdf28a0 | 12590 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12591 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12592 | { | |
876fa593 | 12593 | for (loc2p = locp; |
c7d46a38 PA |
12594 | (loc2p < bp_location + bp_location_count |
12595 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12596 | loc2p++) |
12597 | { | |
12598 | struct bp_location *loc2 = *loc2p; | |
12599 | ||
2d134ed3 | 12600 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12601 | { |
85d721b8 PA |
12602 | /* Read watchpoint locations are switched to |
12603 | access watchpoints, if the former are not | |
12604 | supported, but the latter are. */ | |
12605 | if (is_hardware_watchpoint (old_loc->owner)) | |
12606 | { | |
12607 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12608 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12609 | } | |
12610 | ||
934709f0 PW |
12611 | /* loc2 is a duplicated location. We need to check |
12612 | if it should be inserted in case it will be | |
12613 | unduplicated. */ | |
12614 | if (loc2 != old_loc | |
12615 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12616 | { |
934709f0 | 12617 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12618 | keep_in_target = 1; |
12619 | break; | |
12620 | } | |
876fa593 JK |
12621 | } |
12622 | } | |
12623 | } | |
74960c60 VP |
12624 | } |
12625 | ||
20874c92 VP |
12626 | if (!keep_in_target) |
12627 | { | |
834c0d03 | 12628 | if (remove_breakpoint (old_loc)) |
20874c92 | 12629 | { |
4a64f543 MS |
12630 | /* This is just about all we can do. We could keep |
12631 | this location on the global list, and try to | |
12632 | remove it next time, but there's no particular | |
12633 | reason why we will succeed next time. | |
20874c92 | 12634 | |
4a64f543 MS |
12635 | Note that at this point, old_loc->owner is still |
12636 | valid, as delete_breakpoint frees the breakpoint | |
12637 | only after calling us. */ | |
3e43a32a MS |
12638 | printf_filtered (_("warning: Error removing " |
12639 | "breakpoint %d\n"), | |
876fa593 | 12640 | old_loc->owner->number); |
20874c92 VP |
12641 | } |
12642 | removed = 1; | |
12643 | } | |
0d381245 | 12644 | } |
74960c60 VP |
12645 | |
12646 | if (!found_object) | |
1c5cfe86 | 12647 | { |
fbea99ea | 12648 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12649 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12650 | { |
db82e815 PA |
12651 | /* This location was removed from the target. In |
12652 | non-stop mode, a race condition is possible where | |
12653 | we've removed a breakpoint, but stop events for that | |
12654 | breakpoint are already queued and will arrive later. | |
12655 | We apply an heuristic to be able to distinguish such | |
12656 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12657 | breakpoint location for a bit, and will retire it | |
12658 | after we see some number of events. The theory here | |
12659 | is that reporting of events should, "on the average", | |
12660 | be fair, so after a while we'll see events from all | |
12661 | threads that have anything of interest, and no longer | |
12662 | need to keep this breakpoint location around. We | |
12663 | don't hold locations forever so to reduce chances of | |
12664 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12665 | SIGTRAP. | |
12666 | ||
12667 | The heuristic failing can be disastrous on | |
12668 | decr_pc_after_break targets. | |
12669 | ||
12670 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12671 | if we fail to recognize a late breakpoint SIGTRAP, | |
12672 | because events_till_retirement has reached 0 too | |
12673 | soon, we'll fail to do the PC adjustment, and report | |
12674 | a random SIGTRAP to the user. When the user resumes | |
12675 | the inferior, it will most likely immediately crash | |
2dec564e | 12676 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12677 | corrupted, because of being resumed e.g., in the |
12678 | middle of a multi-byte instruction, or skipped a | |
12679 | one-byte instruction. This was actually seen happen | |
12680 | on native x86-linux, and should be less rare on | |
12681 | targets that do not support new thread events, like | |
12682 | remote, due to the heuristic depending on | |
12683 | thread_count. | |
12684 | ||
12685 | Mistaking a random SIGTRAP for a breakpoint trap | |
12686 | causes similar symptoms (PC adjustment applied when | |
12687 | it shouldn't), but then again, playing with SIGTRAPs | |
12688 | behind the debugger's back is asking for trouble. | |
12689 | ||
12690 | Since hardware watchpoint traps are always | |
12691 | distinguishable from other traps, so we don't need to | |
12692 | apply keep hardware watchpoint moribund locations | |
12693 | around. We simply always ignore hardware watchpoint | |
12694 | traps we can no longer explain. */ | |
12695 | ||
876fa593 JK |
12696 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12697 | old_loc->owner = NULL; | |
20874c92 | 12698 | |
876fa593 | 12699 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12700 | } |
12701 | else | |
f431efe5 PA |
12702 | { |
12703 | old_loc->owner = NULL; | |
12704 | decref_bp_location (&old_loc); | |
12705 | } | |
20874c92 | 12706 | } |
74960c60 | 12707 | } |
1c5cfe86 | 12708 | |
348d480f PA |
12709 | /* Rescan breakpoints at the same address and section, marking the |
12710 | first one as "first" and any others as "duplicates". This is so | |
12711 | that the bpt instruction is only inserted once. If we have a | |
12712 | permanent breakpoint at the same place as BPT, make that one the | |
12713 | official one, and the rest as duplicates. Permanent breakpoints | |
12714 | are sorted first for the same address. | |
12715 | ||
12716 | Do the same for hardware watchpoints, but also considering the | |
12717 | watchpoint's type (regular/access/read) and length. */ | |
12718 | ||
12719 | bp_loc_first = NULL; | |
12720 | wp_loc_first = NULL; | |
12721 | awp_loc_first = NULL; | |
12722 | rwp_loc_first = NULL; | |
12723 | ALL_BP_LOCATIONS (loc, locp) | |
12724 | { | |
12725 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12726 | non-NULL. */ | |
348d480f | 12727 | struct bp_location **loc_first_p; |
d3fbdd86 | 12728 | b = loc->owner; |
348d480f | 12729 | |
6f380991 | 12730 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12731 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12732 | /* Don't detect duplicate for tracepoint locations because they are |
12733 | never duplicated. See the comments in field `duplicate' of | |
12734 | `struct bp_location'. */ | |
348d480f | 12735 | || is_tracepoint (b)) |
b775012e LM |
12736 | { |
12737 | /* Clear the condition modification flag. */ | |
12738 | loc->condition_changed = condition_unchanged; | |
12739 | continue; | |
12740 | } | |
348d480f | 12741 | |
348d480f PA |
12742 | if (b->type == bp_hardware_watchpoint) |
12743 | loc_first_p = &wp_loc_first; | |
12744 | else if (b->type == bp_read_watchpoint) | |
12745 | loc_first_p = &rwp_loc_first; | |
12746 | else if (b->type == bp_access_watchpoint) | |
12747 | loc_first_p = &awp_loc_first; | |
12748 | else | |
12749 | loc_first_p = &bp_loc_first; | |
12750 | ||
12751 | if (*loc_first_p == NULL | |
12752 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12753 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12754 | { | |
12755 | *loc_first_p = loc; | |
12756 | loc->duplicate = 0; | |
b775012e LM |
12757 | |
12758 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12759 | { | |
12760 | loc->needs_update = 1; | |
12761 | /* Clear the condition modification flag. */ | |
12762 | loc->condition_changed = condition_unchanged; | |
12763 | } | |
348d480f PA |
12764 | continue; |
12765 | } | |
12766 | ||
934709f0 PW |
12767 | |
12768 | /* This and the above ensure the invariant that the first location | |
12769 | is not duplicated, and is the inserted one. | |
12770 | All following are marked as duplicated, and are not inserted. */ | |
12771 | if (loc->inserted) | |
12772 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12773 | loc->duplicate = 1; |
12774 | ||
b775012e LM |
12775 | /* Clear the condition modification flag. */ |
12776 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12777 | } |
12778 | ||
a25a5a45 | 12779 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12780 | { |
04086b45 | 12781 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12782 | insert_breakpoint_locations (); |
12783 | else | |
12784 | { | |
44702360 PA |
12785 | /* Even though the caller told us to not insert new |
12786 | locations, we may still need to update conditions on the | |
12787 | target's side of breakpoints that were already inserted | |
12788 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12789 | only update conditions for locations that are marked |
12790 | "needs_update". */ | |
12791 | update_inserted_breakpoint_locations (); | |
12792 | } | |
12793 | } | |
348d480f | 12794 | |
04086b45 | 12795 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12796 | download_tracepoint_locations (); |
12797 | ||
348d480f PA |
12798 | do_cleanups (cleanups); |
12799 | } | |
12800 | ||
12801 | void | |
12802 | breakpoint_retire_moribund (void) | |
12803 | { | |
12804 | struct bp_location *loc; | |
12805 | int ix; | |
12806 | ||
12807 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12808 | if (--(loc->events_till_retirement) == 0) | |
12809 | { | |
12810 | decref_bp_location (&loc); | |
12811 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12812 | --ix; | |
12813 | } | |
12814 | } | |
12815 | ||
12816 | static void | |
44702360 | 12817 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12818 | { |
348d480f | 12819 | |
492d29ea PA |
12820 | TRY |
12821 | { | |
12822 | update_global_location_list (insert_mode); | |
12823 | } | |
12824 | CATCH (e, RETURN_MASK_ERROR) | |
12825 | { | |
12826 | } | |
12827 | END_CATCH | |
348d480f PA |
12828 | } |
12829 | ||
12830 | /* Clear BKP from a BPS. */ | |
12831 | ||
12832 | static void | |
12833 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12834 | { | |
12835 | bpstat bs; | |
12836 | ||
12837 | for (bs = bps; bs; bs = bs->next) | |
12838 | if (bs->breakpoint_at == bpt) | |
12839 | { | |
12840 | bs->breakpoint_at = NULL; | |
12841 | bs->old_val = NULL; | |
12842 | /* bs->commands will be freed later. */ | |
12843 | } | |
12844 | } | |
12845 | ||
12846 | /* Callback for iterate_over_threads. */ | |
12847 | static int | |
12848 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12849 | { | |
9a3c8263 | 12850 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12851 | |
12852 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12853 | return 0; | |
12854 | } | |
12855 | ||
12856 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12857 | callbacks. */ | |
12858 | ||
12859 | static void | |
12860 | say_where (struct breakpoint *b) | |
12861 | { | |
12862 | struct value_print_options opts; | |
12863 | ||
12864 | get_user_print_options (&opts); | |
12865 | ||
12866 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12867 | single string. */ | |
12868 | if (b->loc == NULL) | |
12869 | { | |
f00aae0f KS |
12870 | /* For pending locations, the output differs slightly based |
12871 | on b->extra_string. If this is non-NULL, it contains either | |
12872 | a condition or dprintf arguments. */ | |
12873 | if (b->extra_string == NULL) | |
12874 | { | |
12875 | printf_filtered (_(" (%s) pending."), | |
12876 | event_location_to_string (b->location)); | |
12877 | } | |
12878 | else if (b->type == bp_dprintf) | |
12879 | { | |
12880 | printf_filtered (_(" (%s,%s) pending."), | |
12881 | event_location_to_string (b->location), | |
12882 | b->extra_string); | |
12883 | } | |
12884 | else | |
12885 | { | |
12886 | printf_filtered (_(" (%s %s) pending."), | |
12887 | event_location_to_string (b->location), | |
12888 | b->extra_string); | |
12889 | } | |
348d480f PA |
12890 | } |
12891 | else | |
12892 | { | |
2f202fde | 12893 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12894 | { |
12895 | printf_filtered (" at "); | |
12896 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12897 | gdb_stdout); | |
12898 | } | |
2f202fde | 12899 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12900 | { |
12901 | /* If there is a single location, we can print the location | |
12902 | more nicely. */ | |
12903 | if (b->loc->next == NULL) | |
12904 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12905 | symtab_to_filename_for_display (b->loc->symtab), |
12906 | b->loc->line_number); | |
f8eba3c6 TT |
12907 | else |
12908 | /* This is not ideal, but each location may have a | |
12909 | different file name, and this at least reflects the | |
12910 | real situation somewhat. */ | |
f00aae0f KS |
12911 | printf_filtered (": %s.", |
12912 | event_location_to_string (b->location)); | |
f8eba3c6 | 12913 | } |
348d480f PA |
12914 | |
12915 | if (b->loc->next) | |
12916 | { | |
12917 | struct bp_location *loc = b->loc; | |
12918 | int n = 0; | |
12919 | for (; loc; loc = loc->next) | |
12920 | ++n; | |
12921 | printf_filtered (" (%d locations)", n); | |
12922 | } | |
12923 | } | |
12924 | } | |
12925 | ||
348d480f PA |
12926 | /* Default bp_location_ops methods. */ |
12927 | ||
12928 | static void | |
12929 | bp_location_dtor (struct bp_location *self) | |
12930 | { | |
12931 | xfree (self->cond); | |
b775012e LM |
12932 | if (self->cond_bytecode) |
12933 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12934 | xfree (self->function_name); |
8b4f3082 PA |
12935 | |
12936 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12937 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12938 | } |
12939 | ||
12940 | static const struct bp_location_ops bp_location_ops = | |
12941 | { | |
12942 | bp_location_dtor | |
12943 | }; | |
12944 | ||
2060206e PA |
12945 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12946 | inherit from. */ | |
348d480f | 12947 | |
2060206e PA |
12948 | static void |
12949 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12950 | { |
12951 | decref_counted_command_line (&self->commands); | |
12952 | xfree (self->cond_string); | |
fb81d016 | 12953 | xfree (self->extra_string); |
f8eba3c6 | 12954 | xfree (self->filter); |
f00aae0f KS |
12955 | delete_event_location (self->location); |
12956 | delete_event_location (self->location_range_end); | |
348d480f PA |
12957 | } |
12958 | ||
2060206e PA |
12959 | static struct bp_location * |
12960 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12961 | { |
12962 | struct bp_location *loc; | |
12963 | ||
12964 | loc = XNEW (struct bp_location); | |
12965 | init_bp_location (loc, &bp_location_ops, self); | |
12966 | return loc; | |
12967 | } | |
12968 | ||
2060206e PA |
12969 | static void |
12970 | base_breakpoint_re_set (struct breakpoint *b) | |
12971 | { | |
12972 | /* Nothing to re-set. */ | |
12973 | } | |
12974 | ||
12975 | #define internal_error_pure_virtual_called() \ | |
12976 | gdb_assert_not_reached ("pure virtual function called") | |
12977 | ||
12978 | static int | |
12979 | base_breakpoint_insert_location (struct bp_location *bl) | |
12980 | { | |
12981 | internal_error_pure_virtual_called (); | |
12982 | } | |
12983 | ||
12984 | static int | |
73971819 PA |
12985 | base_breakpoint_remove_location (struct bp_location *bl, |
12986 | enum remove_bp_reason reason) | |
2060206e PA |
12987 | { |
12988 | internal_error_pure_virtual_called (); | |
12989 | } | |
12990 | ||
12991 | static int | |
12992 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12993 | struct address_space *aspace, | |
09ac7c10 TT |
12994 | CORE_ADDR bp_addr, |
12995 | const struct target_waitstatus *ws) | |
2060206e PA |
12996 | { |
12997 | internal_error_pure_virtual_called (); | |
12998 | } | |
12999 | ||
13000 | static void | |
13001 | base_breakpoint_check_status (bpstat bs) | |
13002 | { | |
13003 | /* Always stop. */ | |
13004 | } | |
13005 | ||
13006 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
13007 | errors. */ | |
13008 | ||
13009 | static int | |
13010 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
13011 | { | |
13012 | internal_error_pure_virtual_called (); | |
13013 | } | |
13014 | ||
13015 | /* A "resources_needed" breakpoint_ops method that just internal | |
13016 | errors. */ | |
13017 | ||
13018 | static int | |
13019 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
13020 | { | |
13021 | internal_error_pure_virtual_called (); | |
13022 | } | |
13023 | ||
13024 | static enum print_stop_action | |
13025 | base_breakpoint_print_it (bpstat bs) | |
13026 | { | |
13027 | internal_error_pure_virtual_called (); | |
13028 | } | |
13029 | ||
13030 | static void | |
13031 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
13032 | struct ui_out *uiout) | |
13033 | { | |
13034 | /* nothing */ | |
13035 | } | |
13036 | ||
13037 | static void | |
13038 | base_breakpoint_print_mention (struct breakpoint *b) | |
13039 | { | |
13040 | internal_error_pure_virtual_called (); | |
13041 | } | |
13042 | ||
13043 | static void | |
13044 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13045 | { | |
13046 | internal_error_pure_virtual_called (); | |
13047 | } | |
13048 | ||
983af33b | 13049 | static void |
f00aae0f KS |
13050 | base_breakpoint_create_sals_from_location |
13051 | (const struct event_location *location, | |
13052 | struct linespec_result *canonical, | |
13053 | enum bptype type_wanted) | |
983af33b SDJ |
13054 | { |
13055 | internal_error_pure_virtual_called (); | |
13056 | } | |
13057 | ||
13058 | static void | |
13059 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13060 | struct linespec_result *c, | |
983af33b | 13061 | char *cond_string, |
e7e0cddf | 13062 | char *extra_string, |
983af33b SDJ |
13063 | enum bptype type_wanted, |
13064 | enum bpdisp disposition, | |
13065 | int thread, | |
13066 | int task, int ignore_count, | |
13067 | const struct breakpoint_ops *o, | |
13068 | int from_tty, int enabled, | |
44f238bb | 13069 | int internal, unsigned flags) |
983af33b SDJ |
13070 | { |
13071 | internal_error_pure_virtual_called (); | |
13072 | } | |
13073 | ||
13074 | static void | |
f00aae0f KS |
13075 | base_breakpoint_decode_location (struct breakpoint *b, |
13076 | const struct event_location *location, | |
c2f4122d | 13077 | struct program_space *search_pspace, |
983af33b SDJ |
13078 | struct symtabs_and_lines *sals) |
13079 | { | |
13080 | internal_error_pure_virtual_called (); | |
13081 | } | |
13082 | ||
ab04a2af TT |
13083 | /* The default 'explains_signal' method. */ |
13084 | ||
47591c29 | 13085 | static int |
427cd150 | 13086 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13087 | { |
47591c29 | 13088 | return 1; |
ab04a2af TT |
13089 | } |
13090 | ||
9d6e6e84 HZ |
13091 | /* The default "after_condition_true" method. */ |
13092 | ||
13093 | static void | |
13094 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13095 | { | |
13096 | /* Nothing to do. */ | |
13097 | } | |
13098 | ||
ab04a2af | 13099 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13100 | { |
13101 | base_breakpoint_dtor, | |
13102 | base_breakpoint_allocate_location, | |
13103 | base_breakpoint_re_set, | |
13104 | base_breakpoint_insert_location, | |
13105 | base_breakpoint_remove_location, | |
13106 | base_breakpoint_breakpoint_hit, | |
13107 | base_breakpoint_check_status, | |
13108 | base_breakpoint_resources_needed, | |
13109 | base_breakpoint_works_in_software_mode, | |
13110 | base_breakpoint_print_it, | |
13111 | NULL, | |
13112 | base_breakpoint_print_one_detail, | |
13113 | base_breakpoint_print_mention, | |
983af33b | 13114 | base_breakpoint_print_recreate, |
5f700d83 | 13115 | base_breakpoint_create_sals_from_location, |
983af33b | 13116 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 13117 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
13118 | base_breakpoint_explains_signal, |
13119 | base_breakpoint_after_condition_true, | |
2060206e PA |
13120 | }; |
13121 | ||
13122 | /* Default breakpoint_ops methods. */ | |
13123 | ||
13124 | static void | |
348d480f PA |
13125 | bkpt_re_set (struct breakpoint *b) |
13126 | { | |
06edf0c0 | 13127 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 13128 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 13129 | { |
f00aae0f | 13130 | /* Anything without a location can't be re-set. */ |
348d480f | 13131 | delete_breakpoint (b); |
06edf0c0 | 13132 | return; |
348d480f | 13133 | } |
06edf0c0 PA |
13134 | |
13135 | breakpoint_re_set_default (b); | |
348d480f PA |
13136 | } |
13137 | ||
2060206e | 13138 | static int |
348d480f PA |
13139 | bkpt_insert_location (struct bp_location *bl) |
13140 | { | |
cd6c3b4f YQ |
13141 | CORE_ADDR addr = bl->target_info.reqstd_address; |
13142 | ||
579c6ad9 | 13143 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
13144 | bl->target_info.placed_address = addr; |
13145 | ||
348d480f | 13146 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 13147 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13148 | else |
7c16b83e | 13149 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13150 | } |
13151 | ||
2060206e | 13152 | static int |
73971819 | 13153 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
13154 | { |
13155 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13156 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13157 | else | |
73971819 | 13158 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
13159 | } |
13160 | ||
2060206e | 13161 | static int |
348d480f | 13162 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13163 | struct address_space *aspace, CORE_ADDR bp_addr, |
13164 | const struct target_waitstatus *ws) | |
348d480f | 13165 | { |
09ac7c10 | 13166 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13167 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13168 | return 0; |
13169 | ||
348d480f PA |
13170 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13171 | aspace, bp_addr)) | |
13172 | return 0; | |
13173 | ||
13174 | if (overlay_debugging /* unmapped overlay section */ | |
13175 | && section_is_overlay (bl->section) | |
13176 | && !section_is_mapped (bl->section)) | |
13177 | return 0; | |
13178 | ||
13179 | return 1; | |
13180 | } | |
13181 | ||
cd1608cc PA |
13182 | static int |
13183 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13184 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13185 | const struct target_waitstatus *ws) | |
13186 | { | |
13187 | if (dprintf_style == dprintf_style_agent | |
13188 | && target_can_run_breakpoint_commands ()) | |
13189 | { | |
13190 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13191 | for this address it must be for a breakpoint that happens to | |
13192 | be set at the same address. */ | |
13193 | return 0; | |
13194 | } | |
13195 | ||
13196 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13197 | } | |
13198 | ||
2060206e | 13199 | static int |
348d480f PA |
13200 | bkpt_resources_needed (const struct bp_location *bl) |
13201 | { | |
13202 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13203 | ||
13204 | return 1; | |
13205 | } | |
13206 | ||
2060206e | 13207 | static enum print_stop_action |
348d480f PA |
13208 | bkpt_print_it (bpstat bs) |
13209 | { | |
348d480f PA |
13210 | struct breakpoint *b; |
13211 | const struct bp_location *bl; | |
001c8c33 | 13212 | int bp_temp; |
79a45e25 | 13213 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13214 | |
13215 | gdb_assert (bs->bp_location_at != NULL); | |
13216 | ||
13217 | bl = bs->bp_location_at; | |
13218 | b = bs->breakpoint_at; | |
13219 | ||
001c8c33 PA |
13220 | bp_temp = b->disposition == disp_del; |
13221 | if (bl->address != bl->requested_address) | |
13222 | breakpoint_adjustment_warning (bl->requested_address, | |
13223 | bl->address, | |
13224 | b->number, 1); | |
13225 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
13226 | maybe_print_thread_hit_breakpoint (uiout); |
13227 | ||
001c8c33 | 13228 | if (bp_temp) |
f303dbd6 | 13229 | ui_out_text (uiout, "Temporary breakpoint "); |
001c8c33 | 13230 | else |
f303dbd6 | 13231 | ui_out_text (uiout, "Breakpoint "); |
001c8c33 | 13232 | if (ui_out_is_mi_like_p (uiout)) |
348d480f | 13233 | { |
001c8c33 PA |
13234 | ui_out_field_string (uiout, "reason", |
13235 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13236 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13237 | } |
001c8c33 PA |
13238 | ui_out_field_int (uiout, "bkptno", b->number); |
13239 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13240 | |
001c8c33 | 13241 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13242 | } |
13243 | ||
2060206e | 13244 | static void |
06edf0c0 PA |
13245 | bkpt_print_mention (struct breakpoint *b) |
13246 | { | |
79a45e25 | 13247 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13248 | return; |
13249 | ||
13250 | switch (b->type) | |
13251 | { | |
13252 | case bp_breakpoint: | |
13253 | case bp_gnu_ifunc_resolver: | |
13254 | if (b->disposition == disp_del) | |
13255 | printf_filtered (_("Temporary breakpoint")); | |
13256 | else | |
13257 | printf_filtered (_("Breakpoint")); | |
13258 | printf_filtered (_(" %d"), b->number); | |
13259 | if (b->type == bp_gnu_ifunc_resolver) | |
13260 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13261 | break; | |
13262 | case bp_hardware_breakpoint: | |
13263 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13264 | break; | |
e7e0cddf SS |
13265 | case bp_dprintf: |
13266 | printf_filtered (_("Dprintf %d"), b->number); | |
13267 | break; | |
06edf0c0 PA |
13268 | } |
13269 | ||
13270 | say_where (b); | |
13271 | } | |
13272 | ||
2060206e | 13273 | static void |
06edf0c0 PA |
13274 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13275 | { | |
13276 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13277 | fprintf_unfiltered (fp, "tbreak"); | |
13278 | else if (tp->type == bp_breakpoint) | |
13279 | fprintf_unfiltered (fp, "break"); | |
13280 | else if (tp->type == bp_hardware_breakpoint | |
13281 | && tp->disposition == disp_del) | |
13282 | fprintf_unfiltered (fp, "thbreak"); | |
13283 | else if (tp->type == bp_hardware_breakpoint) | |
13284 | fprintf_unfiltered (fp, "hbreak"); | |
13285 | else | |
13286 | internal_error (__FILE__, __LINE__, | |
13287 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13288 | ||
f00aae0f KS |
13289 | fprintf_unfiltered (fp, " %s", |
13290 | event_location_to_string (tp->location)); | |
13291 | ||
13292 | /* Print out extra_string if this breakpoint is pending. It might | |
13293 | contain, for example, conditions that were set by the user. */ | |
13294 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13295 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13296 | ||
dd11a36c | 13297 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13298 | } |
13299 | ||
983af33b | 13300 | static void |
f00aae0f KS |
13301 | bkpt_create_sals_from_location (const struct event_location *location, |
13302 | struct linespec_result *canonical, | |
13303 | enum bptype type_wanted) | |
983af33b | 13304 | { |
f00aae0f | 13305 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13306 | } |
13307 | ||
13308 | static void | |
13309 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13310 | struct linespec_result *canonical, | |
983af33b | 13311 | char *cond_string, |
e7e0cddf | 13312 | char *extra_string, |
983af33b SDJ |
13313 | enum bptype type_wanted, |
13314 | enum bpdisp disposition, | |
13315 | int thread, | |
13316 | int task, int ignore_count, | |
13317 | const struct breakpoint_ops *ops, | |
13318 | int from_tty, int enabled, | |
44f238bb | 13319 | int internal, unsigned flags) |
983af33b | 13320 | { |
023fa29b | 13321 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13322 | cond_string, extra_string, |
13323 | type_wanted, | |
983af33b SDJ |
13324 | disposition, thread, task, |
13325 | ignore_count, ops, from_tty, | |
44f238bb | 13326 | enabled, internal, flags); |
983af33b SDJ |
13327 | } |
13328 | ||
13329 | static void | |
f00aae0f KS |
13330 | bkpt_decode_location (struct breakpoint *b, |
13331 | const struct event_location *location, | |
c2f4122d | 13332 | struct program_space *search_pspace, |
983af33b SDJ |
13333 | struct symtabs_and_lines *sals) |
13334 | { | |
c2f4122d | 13335 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13336 | } |
13337 | ||
06edf0c0 PA |
13338 | /* Virtual table for internal breakpoints. */ |
13339 | ||
13340 | static void | |
13341 | internal_bkpt_re_set (struct breakpoint *b) | |
13342 | { | |
13343 | switch (b->type) | |
13344 | { | |
13345 | /* Delete overlay event and longjmp master breakpoints; they | |
13346 | will be reset later by breakpoint_re_set. */ | |
13347 | case bp_overlay_event: | |
13348 | case bp_longjmp_master: | |
13349 | case bp_std_terminate_master: | |
13350 | case bp_exception_master: | |
13351 | delete_breakpoint (b); | |
13352 | break; | |
13353 | ||
13354 | /* This breakpoint is special, it's set up when the inferior | |
13355 | starts and we really don't want to touch it. */ | |
13356 | case bp_shlib_event: | |
13357 | ||
13358 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13359 | it is set up, we do not want to touch it. */ | |
13360 | case bp_thread_event: | |
13361 | break; | |
13362 | } | |
13363 | } | |
13364 | ||
13365 | static void | |
13366 | internal_bkpt_check_status (bpstat bs) | |
13367 | { | |
a9b3a50f PA |
13368 | if (bs->breakpoint_at->type == bp_shlib_event) |
13369 | { | |
13370 | /* If requested, stop when the dynamic linker notifies GDB of | |
13371 | events. This allows the user to get control and place | |
13372 | breakpoints in initializer routines for dynamically loaded | |
13373 | objects (among other things). */ | |
13374 | bs->stop = stop_on_solib_events; | |
13375 | bs->print = stop_on_solib_events; | |
13376 | } | |
13377 | else | |
13378 | bs->stop = 0; | |
06edf0c0 PA |
13379 | } |
13380 | ||
13381 | static enum print_stop_action | |
13382 | internal_bkpt_print_it (bpstat bs) | |
13383 | { | |
06edf0c0 | 13384 | struct breakpoint *b; |
06edf0c0 | 13385 | |
06edf0c0 PA |
13386 | b = bs->breakpoint_at; |
13387 | ||
06edf0c0 PA |
13388 | switch (b->type) |
13389 | { | |
348d480f PA |
13390 | case bp_shlib_event: |
13391 | /* Did we stop because the user set the stop_on_solib_events | |
13392 | variable? (If so, we report this as a generic, "Stopped due | |
13393 | to shlib event" message.) */ | |
edcc5120 | 13394 | print_solib_event (0); |
348d480f PA |
13395 | break; |
13396 | ||
13397 | case bp_thread_event: | |
13398 | /* Not sure how we will get here. | |
13399 | GDB should not stop for these breakpoints. */ | |
13400 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13401 | break; |
13402 | ||
13403 | case bp_overlay_event: | |
13404 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13405 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13406 | break; |
13407 | ||
13408 | case bp_longjmp_master: | |
13409 | /* These should never be enabled. */ | |
13410 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13411 | break; |
13412 | ||
13413 | case bp_std_terminate_master: | |
13414 | /* These should never be enabled. */ | |
13415 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13416 | "gdb should not stop!\n")); | |
348d480f PA |
13417 | break; |
13418 | ||
13419 | case bp_exception_master: | |
13420 | /* These should never be enabled. */ | |
13421 | printf_filtered (_("Exception Master Breakpoint: " | |
13422 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13423 | break; |
13424 | } | |
13425 | ||
001c8c33 | 13426 | return PRINT_NOTHING; |
06edf0c0 PA |
13427 | } |
13428 | ||
13429 | static void | |
13430 | internal_bkpt_print_mention (struct breakpoint *b) | |
13431 | { | |
13432 | /* Nothing to mention. These breakpoints are internal. */ | |
13433 | } | |
13434 | ||
06edf0c0 PA |
13435 | /* Virtual table for momentary breakpoints */ |
13436 | ||
13437 | static void | |
13438 | momentary_bkpt_re_set (struct breakpoint *b) | |
13439 | { | |
13440 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13441 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13442 | Otherwise these should have been blown away via the cleanup chain |
13443 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13444 | } | |
13445 | ||
13446 | static void | |
13447 | momentary_bkpt_check_status (bpstat bs) | |
13448 | { | |
13449 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13450 | } | |
13451 | ||
13452 | static enum print_stop_action | |
13453 | momentary_bkpt_print_it (bpstat bs) | |
13454 | { | |
001c8c33 | 13455 | return PRINT_UNKNOWN; |
348d480f PA |
13456 | } |
13457 | ||
06edf0c0 PA |
13458 | static void |
13459 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13460 | { |
06edf0c0 | 13461 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13462 | } |
13463 | ||
e2e4d78b JK |
13464 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13465 | ||
13466 | It gets cleared already on the removal of the first one of such placed | |
13467 | breakpoints. This is OK as they get all removed altogether. */ | |
13468 | ||
13469 | static void | |
13470 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13471 | { | |
5d5658a1 | 13472 | struct thread_info *tp = find_thread_global_id (self->thread); |
e2e4d78b JK |
13473 | |
13474 | if (tp) | |
13475 | tp->initiating_frame = null_frame_id; | |
13476 | ||
13477 | momentary_breakpoint_ops.dtor (self); | |
13478 | } | |
13479 | ||
55aa24fb SDJ |
13480 | /* Specific methods for probe breakpoints. */ |
13481 | ||
13482 | static int | |
13483 | bkpt_probe_insert_location (struct bp_location *bl) | |
13484 | { | |
13485 | int v = bkpt_insert_location (bl); | |
13486 | ||
13487 | if (v == 0) | |
13488 | { | |
13489 | /* The insertion was successful, now let's set the probe's semaphore | |
13490 | if needed. */ | |
0ea5cda8 SDJ |
13491 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13492 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13493 | bl->probe.objfile, | |
13494 | bl->gdbarch); | |
55aa24fb SDJ |
13495 | } |
13496 | ||
13497 | return v; | |
13498 | } | |
13499 | ||
13500 | static int | |
73971819 PA |
13501 | bkpt_probe_remove_location (struct bp_location *bl, |
13502 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13503 | { |
13504 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13505 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13506 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13507 | bl->probe.objfile, | |
13508 | bl->gdbarch); | |
55aa24fb | 13509 | |
73971819 | 13510 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13511 | } |
13512 | ||
13513 | static void | |
f00aae0f | 13514 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13515 | struct linespec_result *canonical, |
f00aae0f | 13516 | enum bptype type_wanted) |
55aa24fb SDJ |
13517 | { |
13518 | struct linespec_sals lsal; | |
13519 | ||
c2f4122d | 13520 | lsal.sals = parse_probes (location, NULL, canonical); |
f00aae0f | 13521 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
55aa24fb SDJ |
13522 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13523 | } | |
13524 | ||
13525 | static void | |
f00aae0f KS |
13526 | bkpt_probe_decode_location (struct breakpoint *b, |
13527 | const struct event_location *location, | |
c2f4122d | 13528 | struct program_space *search_pspace, |
55aa24fb SDJ |
13529 | struct symtabs_and_lines *sals) |
13530 | { | |
c2f4122d | 13531 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13532 | if (!sals->sals) |
13533 | error (_("probe not found")); | |
13534 | } | |
13535 | ||
348d480f | 13536 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13537 | |
348d480f PA |
13538 | static void |
13539 | tracepoint_re_set (struct breakpoint *b) | |
13540 | { | |
13541 | breakpoint_re_set_default (b); | |
13542 | } | |
876fa593 | 13543 | |
348d480f PA |
13544 | static int |
13545 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13546 | struct address_space *aspace, CORE_ADDR bp_addr, |
13547 | const struct target_waitstatus *ws) | |
348d480f PA |
13548 | { |
13549 | /* By definition, the inferior does not report stops at | |
13550 | tracepoints. */ | |
13551 | return 0; | |
74960c60 VP |
13552 | } |
13553 | ||
13554 | static void | |
348d480f PA |
13555 | tracepoint_print_one_detail (const struct breakpoint *self, |
13556 | struct ui_out *uiout) | |
74960c60 | 13557 | { |
d9b3f62e PA |
13558 | struct tracepoint *tp = (struct tracepoint *) self; |
13559 | if (tp->static_trace_marker_id) | |
348d480f PA |
13560 | { |
13561 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13562 | |
348d480f PA |
13563 | ui_out_text (uiout, "\tmarker id is "); |
13564 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13565 | tp->static_trace_marker_id); |
348d480f PA |
13566 | ui_out_text (uiout, "\n"); |
13567 | } | |
0d381245 VP |
13568 | } |
13569 | ||
a474d7c2 | 13570 | static void |
348d480f | 13571 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13572 | { |
79a45e25 | 13573 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13574 | return; |
cc59ec59 | 13575 | |
348d480f PA |
13576 | switch (b->type) |
13577 | { | |
13578 | case bp_tracepoint: | |
13579 | printf_filtered (_("Tracepoint")); | |
13580 | printf_filtered (_(" %d"), b->number); | |
13581 | break; | |
13582 | case bp_fast_tracepoint: | |
13583 | printf_filtered (_("Fast tracepoint")); | |
13584 | printf_filtered (_(" %d"), b->number); | |
13585 | break; | |
13586 | case bp_static_tracepoint: | |
13587 | printf_filtered (_("Static tracepoint")); | |
13588 | printf_filtered (_(" %d"), b->number); | |
13589 | break; | |
13590 | default: | |
13591 | internal_error (__FILE__, __LINE__, | |
13592 | _("unhandled tracepoint type %d"), (int) b->type); | |
13593 | } | |
13594 | ||
13595 | say_where (b); | |
a474d7c2 PA |
13596 | } |
13597 | ||
348d480f | 13598 | static void |
d9b3f62e | 13599 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13600 | { |
d9b3f62e PA |
13601 | struct tracepoint *tp = (struct tracepoint *) self; |
13602 | ||
13603 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13604 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13605 | else if (self->type == bp_static_tracepoint) |
348d480f | 13606 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13607 | else if (self->type == bp_tracepoint) |
348d480f PA |
13608 | fprintf_unfiltered (fp, "trace"); |
13609 | else | |
13610 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13611 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13612 | |
f00aae0f KS |
13613 | fprintf_unfiltered (fp, " %s", |
13614 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13615 | print_recreate_thread (self, fp); |
13616 | ||
13617 | if (tp->pass_count) | |
13618 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13619 | } |
13620 | ||
983af33b | 13621 | static void |
f00aae0f KS |
13622 | tracepoint_create_sals_from_location (const struct event_location *location, |
13623 | struct linespec_result *canonical, | |
13624 | enum bptype type_wanted) | |
983af33b | 13625 | { |
f00aae0f | 13626 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13627 | } |
13628 | ||
13629 | static void | |
13630 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13631 | struct linespec_result *canonical, | |
983af33b | 13632 | char *cond_string, |
e7e0cddf | 13633 | char *extra_string, |
983af33b SDJ |
13634 | enum bptype type_wanted, |
13635 | enum bpdisp disposition, | |
13636 | int thread, | |
13637 | int task, int ignore_count, | |
13638 | const struct breakpoint_ops *ops, | |
13639 | int from_tty, int enabled, | |
44f238bb | 13640 | int internal, unsigned flags) |
983af33b | 13641 | { |
023fa29b | 13642 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13643 | cond_string, extra_string, |
13644 | type_wanted, | |
983af33b SDJ |
13645 | disposition, thread, task, |
13646 | ignore_count, ops, from_tty, | |
44f238bb | 13647 | enabled, internal, flags); |
983af33b SDJ |
13648 | } |
13649 | ||
13650 | static void | |
f00aae0f KS |
13651 | tracepoint_decode_location (struct breakpoint *b, |
13652 | const struct event_location *location, | |
c2f4122d | 13653 | struct program_space *search_pspace, |
983af33b SDJ |
13654 | struct symtabs_and_lines *sals) |
13655 | { | |
c2f4122d | 13656 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13657 | } |
13658 | ||
2060206e | 13659 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13660 | |
55aa24fb SDJ |
13661 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13662 | static probe. */ | |
13663 | ||
13664 | static void | |
f00aae0f KS |
13665 | tracepoint_probe_create_sals_from_location |
13666 | (const struct event_location *location, | |
13667 | struct linespec_result *canonical, | |
13668 | enum bptype type_wanted) | |
55aa24fb SDJ |
13669 | { |
13670 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13671 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13672 | } |
13673 | ||
13674 | static void | |
f00aae0f KS |
13675 | tracepoint_probe_decode_location (struct breakpoint *b, |
13676 | const struct event_location *location, | |
c2f4122d | 13677 | struct program_space *search_pspace, |
55aa24fb SDJ |
13678 | struct symtabs_and_lines *sals) |
13679 | { | |
13680 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13681 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13682 | } |
13683 | ||
13684 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13685 | ||
5c2b4418 HZ |
13686 | /* Dprintf breakpoint_ops methods. */ |
13687 | ||
13688 | static void | |
13689 | dprintf_re_set (struct breakpoint *b) | |
13690 | { | |
13691 | breakpoint_re_set_default (b); | |
13692 | ||
f00aae0f KS |
13693 | /* extra_string should never be non-NULL for dprintf. */ |
13694 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13695 | |
13696 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13697 | 2 - create a dprintf, which resolves fine. | |
13698 | 3 - disconnect from target 1 | |
13699 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13700 | ||
13701 | After steps #3/#4, you'll want the dprintf command list to | |
13702 | be updated, because target 1 and 2 may well return different | |
13703 | answers for target_can_run_breakpoint_commands(). | |
13704 | Given absence of finer grained resetting, we get to do | |
13705 | it all the time. */ | |
13706 | if (b->extra_string != NULL) | |
13707 | update_dprintf_command_list (b); | |
13708 | } | |
13709 | ||
2d9442cc HZ |
13710 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13711 | ||
13712 | static void | |
13713 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13714 | { | |
f00aae0f KS |
13715 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13716 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13717 | tp->extra_string); |
13718 | print_recreate_thread (tp, fp); | |
13719 | } | |
13720 | ||
9d6e6e84 HZ |
13721 | /* Implement the "after_condition_true" breakpoint_ops method for |
13722 | dprintf. | |
13723 | ||
13724 | dprintf's are implemented with regular commands in their command | |
13725 | list, but we run the commands here instead of before presenting the | |
13726 | stop to the user, as dprintf's don't actually cause a stop. This | |
13727 | also makes it so that the commands of multiple dprintfs at the same | |
13728 | address are all handled. */ | |
13729 | ||
13730 | static void | |
13731 | dprintf_after_condition_true (struct bpstats *bs) | |
13732 | { | |
13733 | struct cleanup *old_chain; | |
13734 | struct bpstats tmp_bs = { NULL }; | |
13735 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13736 | ||
13737 | /* dprintf's never cause a stop. This wasn't set in the | |
13738 | check_status hook instead because that would make the dprintf's | |
13739 | condition not be evaluated. */ | |
13740 | bs->stop = 0; | |
13741 | ||
13742 | /* Run the command list here. Take ownership of it instead of | |
13743 | copying. We never want these commands to run later in | |
13744 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13745 | be set at same address as this dprintf, or even if running the | |
13746 | commands here throws. */ | |
13747 | tmp_bs.commands = bs->commands; | |
13748 | bs->commands = NULL; | |
13749 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13750 | ||
13751 | bpstat_do_actions_1 (&tmp_bs_p); | |
13752 | ||
13753 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13754 | bpstat_do_actions_1 may return early without processing the whole | |
13755 | list. */ | |
13756 | do_cleanups (old_chain); | |
13757 | } | |
13758 | ||
983af33b SDJ |
13759 | /* The breakpoint_ops structure to be used on static tracepoints with |
13760 | markers (`-m'). */ | |
13761 | ||
13762 | static void | |
f00aae0f | 13763 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13764 | struct linespec_result *canonical, |
f00aae0f | 13765 | enum bptype type_wanted) |
983af33b SDJ |
13766 | { |
13767 | struct linespec_sals lsal; | |
f00aae0f KS |
13768 | const char *arg_start, *arg; |
13769 | char *str; | |
13770 | struct cleanup *cleanup; | |
983af33b | 13771 | |
f00aae0f KS |
13772 | arg = arg_start = get_linespec_location (location); |
13773 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13774 | |
f00aae0f KS |
13775 | str = savestring (arg_start, arg - arg_start); |
13776 | cleanup = make_cleanup (xfree, str); | |
13777 | canonical->location = new_linespec_location (&str); | |
13778 | do_cleanups (cleanup); | |
983af33b | 13779 | |
f00aae0f | 13780 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13781 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13782 | } | |
13783 | ||
13784 | static void | |
13785 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13786 | struct linespec_result *canonical, | |
983af33b | 13787 | char *cond_string, |
e7e0cddf | 13788 | char *extra_string, |
983af33b SDJ |
13789 | enum bptype type_wanted, |
13790 | enum bpdisp disposition, | |
13791 | int thread, | |
13792 | int task, int ignore_count, | |
13793 | const struct breakpoint_ops *ops, | |
13794 | int from_tty, int enabled, | |
44f238bb | 13795 | int internal, unsigned flags) |
983af33b SDJ |
13796 | { |
13797 | int i; | |
52d361e1 YQ |
13798 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13799 | canonical->sals, 0); | |
983af33b SDJ |
13800 | |
13801 | /* If the user is creating a static tracepoint by marker id | |
13802 | (strace -m MARKER_ID), then store the sals index, so that | |
13803 | breakpoint_re_set can try to match up which of the newly | |
13804 | found markers corresponds to this one, and, don't try to | |
13805 | expand multiple locations for each sal, given than SALS | |
13806 | already should contain all sals for MARKER_ID. */ | |
13807 | ||
13808 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13809 | { | |
13810 | struct symtabs_and_lines expanded; | |
13811 | struct tracepoint *tp; | |
13812 | struct cleanup *old_chain; | |
f00aae0f | 13813 | struct event_location *location; |
983af33b SDJ |
13814 | |
13815 | expanded.nelts = 1; | |
13816 | expanded.sals = &lsal->sals.sals[i]; | |
13817 | ||
f00aae0f KS |
13818 | location = copy_event_location (canonical->location); |
13819 | old_chain = make_cleanup_delete_event_location (location); | |
983af33b SDJ |
13820 | |
13821 | tp = XCNEW (struct tracepoint); | |
13822 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
f00aae0f | 13823 | location, NULL, |
e7e0cddf SS |
13824 | cond_string, extra_string, |
13825 | type_wanted, disposition, | |
983af33b | 13826 | thread, task, ignore_count, ops, |
44f238bb | 13827 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13828 | canonical->special_display); |
13829 | /* Given that its possible to have multiple markers with | |
13830 | the same string id, if the user is creating a static | |
13831 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13832 | store the sals index, so that breakpoint_re_set can | |
13833 | try to match up which of the newly found markers | |
13834 | corresponds to this one */ | |
13835 | tp->static_trace_marker_id_idx = i; | |
13836 | ||
13837 | install_breakpoint (internal, &tp->base, 0); | |
13838 | ||
13839 | discard_cleanups (old_chain); | |
13840 | } | |
13841 | } | |
13842 | ||
13843 | static void | |
f00aae0f KS |
13844 | strace_marker_decode_location (struct breakpoint *b, |
13845 | const struct event_location *location, | |
c2f4122d | 13846 | struct program_space *search_pspace, |
983af33b SDJ |
13847 | struct symtabs_and_lines *sals) |
13848 | { | |
13849 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13850 | const char *s = get_linespec_location (location); |
983af33b | 13851 | |
f00aae0f | 13852 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13853 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13854 | { | |
13855 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13856 | sals->nelts = 1; | |
13857 | } | |
13858 | else | |
13859 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13860 | } | |
13861 | ||
13862 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13863 | ||
13864 | static int | |
13865 | strace_marker_p (struct breakpoint *b) | |
13866 | { | |
13867 | return b->ops == &strace_marker_breakpoint_ops; | |
13868 | } | |
13869 | ||
53a5351d | 13870 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13871 | structures. */ |
c906108c SS |
13872 | |
13873 | void | |
fba45db2 | 13874 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13875 | { |
52f0bd74 | 13876 | struct breakpoint *b; |
c906108c | 13877 | |
8a3fe4f8 | 13878 | gdb_assert (bpt != NULL); |
c906108c | 13879 | |
4a64f543 MS |
13880 | /* Has this bp already been deleted? This can happen because |
13881 | multiple lists can hold pointers to bp's. bpstat lists are | |
13882 | especial culprits. | |
13883 | ||
13884 | One example of this happening is a watchpoint's scope bp. When | |
13885 | the scope bp triggers, we notice that the watchpoint is out of | |
13886 | scope, and delete it. We also delete its scope bp. But the | |
13887 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13888 | That bpstat is then checked for auto-deleting bp's, which are | |
13889 | deleted. | |
13890 | ||
13891 | A real solution to this problem might involve reference counts in | |
13892 | bp's, and/or giving them pointers back to their referencing | |
13893 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13894 | storage when no more references were extent. A cheaper bandaid | |
13895 | was chosen. */ | |
c906108c SS |
13896 | if (bpt->type == bp_none) |
13897 | return; | |
13898 | ||
4a64f543 MS |
13899 | /* At least avoid this stale reference until the reference counting |
13900 | of breakpoints gets resolved. */ | |
d0fb5eae | 13901 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13902 | { |
d0fb5eae | 13903 | struct breakpoint *related; |
3a5c3e22 | 13904 | struct watchpoint *w; |
d0fb5eae JK |
13905 | |
13906 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13907 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13908 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13909 | w = (struct watchpoint *) bpt; |
13910 | else | |
13911 | w = NULL; | |
13912 | if (w != NULL) | |
13913 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13914 | |
13915 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13916 | for (related = bpt; related->related_breakpoint != bpt; | |
13917 | related = related->related_breakpoint); | |
13918 | related->related_breakpoint = bpt->related_breakpoint; | |
13919 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13920 | } |
13921 | ||
a9634178 TJB |
13922 | /* watch_command_1 creates a watchpoint but only sets its number if |
13923 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13924 | a problem in that process, we'll be asked to delete the half-created | |
13925 | watchpoint. In that case, don't announce the deletion. */ | |
13926 | if (bpt->number) | |
13927 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13928 | |
c906108c SS |
13929 | if (breakpoint_chain == bpt) |
13930 | breakpoint_chain = bpt->next; | |
13931 | ||
c906108c SS |
13932 | ALL_BREAKPOINTS (b) |
13933 | if (b->next == bpt) | |
c5aa993b JM |
13934 | { |
13935 | b->next = bpt->next; | |
13936 | break; | |
13937 | } | |
c906108c | 13938 | |
f431efe5 PA |
13939 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13940 | been freed. */ | |
13941 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13942 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13943 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13944 | commands are associated with the bpstat; if we remove it here, | |
13945 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13946 | event-top.c won't do anything, and temporary breakpoints with | |
13947 | commands won't work. */ | |
13948 | ||
13949 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13950 | ||
4a64f543 MS |
13951 | /* Now that breakpoint is removed from breakpoint list, update the |
13952 | global location list. This will remove locations that used to | |
13953 | belong to this breakpoint. Do this before freeing the breakpoint | |
13954 | itself, since remove_breakpoint looks at location's owner. It | |
13955 | might be better design to have location completely | |
13956 | self-contained, but it's not the case now. */ | |
44702360 | 13957 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13958 | |
348d480f | 13959 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13960 | /* On the chance that someone will soon try again to delete this |
13961 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13962 | bpt->type = bp_none; |
b8c9b27d | 13963 | xfree (bpt); |
c906108c SS |
13964 | } |
13965 | ||
4d6140d9 AC |
13966 | static void |
13967 | do_delete_breakpoint_cleanup (void *b) | |
13968 | { | |
9a3c8263 | 13969 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13970 | } |
13971 | ||
13972 | struct cleanup * | |
13973 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13974 | { | |
13975 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13976 | } | |
13977 | ||
51be5b68 PA |
13978 | /* Iterator function to call a user-provided callback function once |
13979 | for each of B and its related breakpoints. */ | |
13980 | ||
13981 | static void | |
13982 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13983 | void (*function) (struct breakpoint *, | |
13984 | void *), | |
13985 | void *data) | |
13986 | { | |
13987 | struct breakpoint *related; | |
13988 | ||
13989 | related = b; | |
13990 | do | |
13991 | { | |
13992 | struct breakpoint *next; | |
13993 | ||
13994 | /* FUNCTION may delete RELATED. */ | |
13995 | next = related->related_breakpoint; | |
13996 | ||
13997 | if (next == related) | |
13998 | { | |
13999 | /* RELATED is the last ring entry. */ | |
14000 | function (related, data); | |
14001 | ||
14002 | /* FUNCTION may have deleted it, so we'd never reach back to | |
14003 | B. There's nothing left to do anyway, so just break | |
14004 | out. */ | |
14005 | break; | |
14006 | } | |
14007 | else | |
14008 | function (related, data); | |
14009 | ||
14010 | related = next; | |
14011 | } | |
14012 | while (related != b); | |
14013 | } | |
95a42b64 TT |
14014 | |
14015 | static void | |
14016 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14017 | { | |
14018 | delete_breakpoint (b); | |
14019 | } | |
14020 | ||
51be5b68 PA |
14021 | /* A callback for map_breakpoint_numbers that calls |
14022 | delete_breakpoint. */ | |
14023 | ||
14024 | static void | |
14025 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14026 | { | |
14027 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
14028 | } | |
14029 | ||
c906108c | 14030 | void |
fba45db2 | 14031 | delete_command (char *arg, int from_tty) |
c906108c | 14032 | { |
35df4500 | 14033 | struct breakpoint *b, *b_tmp; |
c906108c | 14034 | |
ea9365bb TT |
14035 | dont_repeat (); |
14036 | ||
c906108c SS |
14037 | if (arg == 0) |
14038 | { | |
14039 | int breaks_to_delete = 0; | |
14040 | ||
46c6471b PA |
14041 | /* Delete all breakpoints if no argument. Do not delete |
14042 | internal breakpoints, these have to be deleted with an | |
14043 | explicit breakpoint number argument. */ | |
c5aa993b | 14044 | ALL_BREAKPOINTS (b) |
46c6471b | 14045 | if (user_breakpoint_p (b)) |
973d738b DJ |
14046 | { |
14047 | breaks_to_delete = 1; | |
14048 | break; | |
14049 | } | |
c906108c SS |
14050 | |
14051 | /* Ask user only if there are some breakpoints to delete. */ | |
14052 | if (!from_tty | |
e2e0b3e5 | 14053 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14054 | { |
35df4500 | 14055 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14056 | if (user_breakpoint_p (b)) |
c5aa993b | 14057 | delete_breakpoint (b); |
c906108c SS |
14058 | } |
14059 | } | |
14060 | else | |
51be5b68 | 14061 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14062 | } |
14063 | ||
c2f4122d PA |
14064 | /* Return true if all locations of B bound to PSPACE are pending. If |
14065 | PSPACE is NULL, all locations of all program spaces are | |
14066 | considered. */ | |
14067 | ||
0d381245 | 14068 | static int |
c2f4122d | 14069 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 14070 | { |
c2f4122d PA |
14071 | struct bp_location *loc; |
14072 | ||
14073 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
14074 | if ((pspace == NULL | |
14075 | || loc->pspace == pspace) | |
14076 | && !loc->shlib_disabled | |
8645ff69 | 14077 | && !loc->pspace->executing_startup) |
0d381245 VP |
14078 | return 0; |
14079 | return 1; | |
fe3f5fa8 VP |
14080 | } |
14081 | ||
776592bf DE |
14082 | /* Subroutine of update_breakpoint_locations to simplify it. |
14083 | Return non-zero if multiple fns in list LOC have the same name. | |
14084 | Null names are ignored. */ | |
14085 | ||
14086 | static int | |
14087 | ambiguous_names_p (struct bp_location *loc) | |
14088 | { | |
14089 | struct bp_location *l; | |
14090 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14091 | (int (*) (const void *, |
14092 | const void *)) streq, | |
776592bf DE |
14093 | NULL, xcalloc, xfree); |
14094 | ||
14095 | for (l = loc; l != NULL; l = l->next) | |
14096 | { | |
14097 | const char **slot; | |
14098 | const char *name = l->function_name; | |
14099 | ||
14100 | /* Allow for some names to be NULL, ignore them. */ | |
14101 | if (name == NULL) | |
14102 | continue; | |
14103 | ||
14104 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14105 | INSERT); | |
4a64f543 MS |
14106 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14107 | returns NULL. */ | |
776592bf DE |
14108 | if (*slot != NULL) |
14109 | { | |
14110 | htab_delete (htab); | |
14111 | return 1; | |
14112 | } | |
14113 | *slot = name; | |
14114 | } | |
14115 | ||
14116 | htab_delete (htab); | |
14117 | return 0; | |
14118 | } | |
14119 | ||
0fb4aa4b PA |
14120 | /* When symbols change, it probably means the sources changed as well, |
14121 | and it might mean the static tracepoint markers are no longer at | |
14122 | the same address or line numbers they used to be at last we | |
14123 | checked. Losing your static tracepoints whenever you rebuild is | |
14124 | undesirable. This function tries to resync/rematch gdb static | |
14125 | tracepoints with the markers on the target, for static tracepoints | |
14126 | that have not been set by marker id. Static tracepoint that have | |
14127 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14128 | The heuristic is: | |
14129 | ||
14130 | 1) For a tracepoint set at a specific address, look for a marker at | |
14131 | the old PC. If one is found there, assume to be the same marker. | |
14132 | If the name / string id of the marker found is different from the | |
14133 | previous known name, assume that means the user renamed the marker | |
14134 | in the sources, and output a warning. | |
14135 | ||
14136 | 2) For a tracepoint set at a given line number, look for a marker | |
14137 | at the new address of the old line number. If one is found there, | |
14138 | assume to be the same marker. If the name / string id of the | |
14139 | marker found is different from the previous known name, assume that | |
14140 | means the user renamed the marker in the sources, and output a | |
14141 | warning. | |
14142 | ||
14143 | 3) If a marker is no longer found at the same address or line, it | |
14144 | may mean the marker no longer exists. But it may also just mean | |
14145 | the code changed a bit. Maybe the user added a few lines of code | |
14146 | that made the marker move up or down (in line number terms). Ask | |
14147 | the target for info about the marker with the string id as we knew | |
14148 | it. If found, update line number and address in the matching | |
14149 | static tracepoint. This will get confused if there's more than one | |
14150 | marker with the same ID (possible in UST, although unadvised | |
14151 | precisely because it confuses tools). */ | |
14152 | ||
14153 | static struct symtab_and_line | |
14154 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14155 | { | |
d9b3f62e | 14156 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14157 | struct static_tracepoint_marker marker; |
14158 | CORE_ADDR pc; | |
0fb4aa4b PA |
14159 | |
14160 | pc = sal.pc; | |
14161 | if (sal.line) | |
14162 | find_line_pc (sal.symtab, sal.line, &pc); | |
14163 | ||
14164 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14165 | { | |
d9b3f62e | 14166 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14167 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14168 | b->number, | |
d9b3f62e | 14169 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14170 | |
d9b3f62e PA |
14171 | xfree (tp->static_trace_marker_id); |
14172 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14173 | release_static_tracepoint_marker (&marker); |
14174 | ||
14175 | return sal; | |
14176 | } | |
14177 | ||
14178 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14179 | by string ID. */ | |
14180 | if (!sal.explicit_pc | |
14181 | && sal.line != 0 | |
14182 | && sal.symtab != NULL | |
d9b3f62e | 14183 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14184 | { |
14185 | VEC(static_tracepoint_marker_p) *markers; | |
14186 | ||
14187 | markers | |
d9b3f62e | 14188 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14189 | |
14190 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14191 | { | |
80e1d417 | 14192 | struct symtab_and_line sal2; |
0fb4aa4b | 14193 | struct symbol *sym; |
80e1d417 | 14194 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14195 | struct ui_out *uiout = current_uiout; |
67994074 | 14196 | struct explicit_location explicit_loc; |
0fb4aa4b | 14197 | |
80e1d417 | 14198 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14199 | |
d9b3f62e | 14200 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14201 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14202 | |
14203 | warning (_("marker for static tracepoint %d (%s) not " | |
14204 | "found at previous line number"), | |
d9b3f62e | 14205 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14206 | |
80e1d417 | 14207 | init_sal (&sal2); |
0fb4aa4b | 14208 | |
80e1d417 | 14209 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14210 | |
80e1d417 AS |
14211 | sal2 = find_pc_line (tpmarker->address, 0); |
14212 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14213 | ui_out_text (uiout, "Now in "); |
14214 | if (sym) | |
14215 | { | |
14216 | ui_out_field_string (uiout, "func", | |
14217 | SYMBOL_PRINT_NAME (sym)); | |
14218 | ui_out_text (uiout, " at "); | |
14219 | } | |
05cba821 JK |
14220 | ui_out_field_string (uiout, "file", |
14221 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14222 | ui_out_text (uiout, ":"); |
14223 | ||
14224 | if (ui_out_is_mi_like_p (uiout)) | |
14225 | { | |
0b0865da | 14226 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14227 | |
f35a17b5 | 14228 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14229 | } |
14230 | ||
80e1d417 | 14231 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14232 | ui_out_text (uiout, "\n"); |
14233 | ||
80e1d417 | 14234 | b->loc->line_number = sal2.line; |
2f202fde | 14235 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14236 | |
f00aae0f | 14237 | delete_event_location (b->location); |
67994074 KS |
14238 | initialize_explicit_location (&explicit_loc); |
14239 | explicit_loc.source_filename | |
00e52e53 | 14240 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14241 | explicit_loc.line_offset.offset = b->loc->line_number; |
14242 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
14243 | b->location = new_explicit_location (&explicit_loc); | |
0fb4aa4b PA |
14244 | |
14245 | /* Might be nice to check if function changed, and warn if | |
14246 | so. */ | |
14247 | ||
80e1d417 | 14248 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14249 | } |
14250 | } | |
14251 | return sal; | |
14252 | } | |
14253 | ||
8d3788bd VP |
14254 | /* Returns 1 iff locations A and B are sufficiently same that |
14255 | we don't need to report breakpoint as changed. */ | |
14256 | ||
14257 | static int | |
14258 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14259 | { | |
14260 | while (a && b) | |
14261 | { | |
14262 | if (a->address != b->address) | |
14263 | return 0; | |
14264 | ||
14265 | if (a->shlib_disabled != b->shlib_disabled) | |
14266 | return 0; | |
14267 | ||
14268 | if (a->enabled != b->enabled) | |
14269 | return 0; | |
14270 | ||
14271 | a = a->next; | |
14272 | b = b->next; | |
14273 | } | |
14274 | ||
14275 | if ((a == NULL) != (b == NULL)) | |
14276 | return 0; | |
14277 | ||
14278 | return 1; | |
14279 | } | |
14280 | ||
c2f4122d PA |
14281 | /* Split all locations of B that are bound to PSPACE out of B's |
14282 | location list to a separate list and return that list's head. If | |
14283 | PSPACE is NULL, hoist out all locations of B. */ | |
14284 | ||
14285 | static struct bp_location * | |
14286 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14287 | { | |
14288 | struct bp_location head; | |
14289 | struct bp_location *i = b->loc; | |
14290 | struct bp_location **i_link = &b->loc; | |
14291 | struct bp_location *hoisted = &head; | |
14292 | ||
14293 | if (pspace == NULL) | |
14294 | { | |
14295 | i = b->loc; | |
14296 | b->loc = NULL; | |
14297 | return i; | |
14298 | } | |
14299 | ||
14300 | head.next = NULL; | |
14301 | ||
14302 | while (i != NULL) | |
14303 | { | |
14304 | if (i->pspace == pspace) | |
14305 | { | |
14306 | *i_link = i->next; | |
14307 | i->next = NULL; | |
14308 | hoisted->next = i; | |
14309 | hoisted = i; | |
14310 | } | |
14311 | else | |
14312 | i_link = &i->next; | |
14313 | i = *i_link; | |
14314 | } | |
14315 | ||
14316 | return head.next; | |
14317 | } | |
14318 | ||
14319 | /* Create new breakpoint locations for B (a hardware or software | |
14320 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14321 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14322 | FILTER_PSPACE. Locations of other program spaces are left | |
14323 | untouched. */ | |
f1310107 | 14324 | |
0e30163f | 14325 | void |
0d381245 | 14326 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14327 | struct program_space *filter_pspace, |
f1310107 TJB |
14328 | struct symtabs_and_lines sals, |
14329 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14330 | { |
14331 | int i; | |
c2f4122d | 14332 | struct bp_location *existing_locations; |
0d381245 | 14333 | |
f8eba3c6 TT |
14334 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14335 | { | |
14336 | /* Ranged breakpoints have only one start location and one end | |
14337 | location. */ | |
14338 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14339 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14340 | "multiple locations found\n"), | |
14341 | b->number); | |
14342 | return; | |
14343 | } | |
f1310107 | 14344 | |
4a64f543 MS |
14345 | /* If there's no new locations, and all existing locations are |
14346 | pending, don't do anything. This optimizes the common case where | |
14347 | all locations are in the same shared library, that was unloaded. | |
14348 | We'd like to retain the location, so that when the library is | |
14349 | loaded again, we don't loose the enabled/disabled status of the | |
14350 | individual locations. */ | |
c2f4122d | 14351 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14352 | return; |
14353 | ||
c2f4122d | 14354 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14355 | |
0d381245 | 14356 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14357 | { |
f8eba3c6 TT |
14358 | struct bp_location *new_loc; |
14359 | ||
14360 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14361 | ||
14362 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14363 | |
0d381245 VP |
14364 | /* Reparse conditions, they might contain references to the |
14365 | old symtab. */ | |
14366 | if (b->cond_string != NULL) | |
14367 | { | |
bbc13ae3 | 14368 | const char *s; |
fe3f5fa8 | 14369 | |
0d381245 | 14370 | s = b->cond_string; |
492d29ea | 14371 | TRY |
0d381245 | 14372 | { |
1bb9788d TT |
14373 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14374 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14375 | 0); |
14376 | } | |
492d29ea | 14377 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14378 | { |
3e43a32a MS |
14379 | warning (_("failed to reevaluate condition " |
14380 | "for breakpoint %d: %s"), | |
0d381245 VP |
14381 | b->number, e.message); |
14382 | new_loc->enabled = 0; | |
14383 | } | |
492d29ea | 14384 | END_CATCH |
0d381245 | 14385 | } |
fe3f5fa8 | 14386 | |
f1310107 TJB |
14387 | if (sals_end.nelts) |
14388 | { | |
14389 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14390 | ||
14391 | new_loc->length = end - sals.sals[0].pc + 1; | |
14392 | } | |
0d381245 | 14393 | } |
fe3f5fa8 | 14394 | |
4a64f543 MS |
14395 | /* If possible, carry over 'disable' status from existing |
14396 | breakpoints. */ | |
0d381245 VP |
14397 | { |
14398 | struct bp_location *e = existing_locations; | |
776592bf DE |
14399 | /* If there are multiple breakpoints with the same function name, |
14400 | e.g. for inline functions, comparing function names won't work. | |
14401 | Instead compare pc addresses; this is just a heuristic as things | |
14402 | may have moved, but in practice it gives the correct answer | |
14403 | often enough until a better solution is found. */ | |
14404 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14405 | ||
0d381245 VP |
14406 | for (; e; e = e->next) |
14407 | { | |
14408 | if (!e->enabled && e->function_name) | |
14409 | { | |
14410 | struct bp_location *l = b->loc; | |
776592bf DE |
14411 | if (have_ambiguous_names) |
14412 | { | |
14413 | for (; l; l = l->next) | |
f1310107 | 14414 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14415 | { |
14416 | l->enabled = 0; | |
14417 | break; | |
14418 | } | |
14419 | } | |
14420 | else | |
14421 | { | |
14422 | for (; l; l = l->next) | |
14423 | if (l->function_name | |
14424 | && strcmp (e->function_name, l->function_name) == 0) | |
14425 | { | |
14426 | l->enabled = 0; | |
14427 | break; | |
14428 | } | |
14429 | } | |
0d381245 VP |
14430 | } |
14431 | } | |
14432 | } | |
fe3f5fa8 | 14433 | |
8d3788bd VP |
14434 | if (!locations_are_equal (existing_locations, b->loc)) |
14435 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14436 | } |
14437 | ||
f00aae0f | 14438 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14439 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14440 | ||
14441 | static struct symtabs_and_lines | |
f00aae0f | 14442 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14443 | struct program_space *search_pspace, int *found) |
ef23e705 | 14444 | { |
02d20e4a | 14445 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14446 | struct gdb_exception exception = exception_none; |
ef23e705 | 14447 | |
983af33b | 14448 | gdb_assert (b->ops != NULL); |
ef23e705 | 14449 | |
492d29ea | 14450 | TRY |
ef23e705 | 14451 | { |
c2f4122d | 14452 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14453 | } |
492d29ea | 14454 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14455 | { |
14456 | int not_found_and_ok = 0; | |
492d29ea PA |
14457 | |
14458 | exception = e; | |
14459 | ||
ef23e705 TJB |
14460 | /* For pending breakpoints, it's expected that parsing will |
14461 | fail until the right shared library is loaded. User has | |
14462 | already told to create pending breakpoints and don't need | |
14463 | extra messages. If breakpoint is in bp_shlib_disabled | |
14464 | state, then user already saw the message about that | |
14465 | breakpoint being disabled, and don't want to see more | |
14466 | errors. */ | |
58438ac1 | 14467 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14468 | && (b->condition_not_parsed |
14469 | || (b->loc != NULL | |
14470 | && search_pspace != NULL | |
14471 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14472 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14473 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14474 | || b->enable_state == bp_disabled)) |
14475 | not_found_and_ok = 1; | |
14476 | ||
14477 | if (!not_found_and_ok) | |
14478 | { | |
14479 | /* We surely don't want to warn about the same breakpoint | |
14480 | 10 times. One solution, implemented here, is disable | |
14481 | the breakpoint on error. Another solution would be to | |
14482 | have separate 'warning emitted' flag. Since this | |
14483 | happens only when a binary has changed, I don't know | |
14484 | which approach is better. */ | |
14485 | b->enable_state = bp_disabled; | |
14486 | throw_exception (e); | |
14487 | } | |
14488 | } | |
492d29ea | 14489 | END_CATCH |
ef23e705 | 14490 | |
492d29ea | 14491 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14492 | { |
f8eba3c6 | 14493 | int i; |
ef23e705 | 14494 | |
f8eba3c6 TT |
14495 | for (i = 0; i < sals.nelts; ++i) |
14496 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14497 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14498 | { |
ed1d1739 KS |
14499 | char *cond_string, *extra_string; |
14500 | int thread, task; | |
ef23e705 | 14501 | |
f00aae0f | 14502 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14503 | &cond_string, &thread, &task, |
14504 | &extra_string); | |
f00aae0f | 14505 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14506 | if (cond_string) |
14507 | b->cond_string = cond_string; | |
14508 | b->thread = thread; | |
14509 | b->task = task; | |
e7e0cddf | 14510 | if (extra_string) |
f00aae0f KS |
14511 | { |
14512 | xfree (b->extra_string); | |
14513 | b->extra_string = extra_string; | |
14514 | } | |
ef23e705 TJB |
14515 | b->condition_not_parsed = 0; |
14516 | } | |
14517 | ||
983af33b | 14518 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14519 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14520 | |
58438ac1 TT |
14521 | *found = 1; |
14522 | } | |
14523 | else | |
14524 | *found = 0; | |
ef23e705 TJB |
14525 | |
14526 | return sals; | |
14527 | } | |
14528 | ||
348d480f PA |
14529 | /* The default re_set method, for typical hardware or software |
14530 | breakpoints. Reevaluate the breakpoint and recreate its | |
14531 | locations. */ | |
14532 | ||
14533 | static void | |
28010a5d | 14534 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14535 | { |
14536 | int found; | |
f1310107 | 14537 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14538 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14539 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14540 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14541 | |
c2f4122d | 14542 | sals = location_to_sals (b, b->location, filter_pspace, &found); |
ef23e705 TJB |
14543 | if (found) |
14544 | { | |
14545 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14546 | expanded = sals; |
ef23e705 TJB |
14547 | } |
14548 | ||
f00aae0f | 14549 | if (b->location_range_end != NULL) |
f1310107 | 14550 | { |
c2f4122d PA |
14551 | sals_end = location_to_sals (b, b->location_range_end, |
14552 | filter_pspace, &found); | |
f1310107 TJB |
14553 | if (found) |
14554 | { | |
14555 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14556 | expanded_end = sals_end; |
f1310107 TJB |
14557 | } |
14558 | } | |
14559 | ||
c2f4122d | 14560 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14561 | } |
14562 | ||
983af33b SDJ |
14563 | /* Default method for creating SALs from an address string. It basically |
14564 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14565 | ||
14566 | static void | |
f00aae0f KS |
14567 | create_sals_from_location_default (const struct event_location *location, |
14568 | struct linespec_result *canonical, | |
14569 | enum bptype type_wanted) | |
983af33b | 14570 | { |
f00aae0f | 14571 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14572 | } |
14573 | ||
14574 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14575 | function for the `create_breakpoints_sal' method of | |
14576 | breakpoint_ops. */ | |
14577 | ||
14578 | static void | |
14579 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14580 | struct linespec_result *canonical, | |
983af33b | 14581 | char *cond_string, |
e7e0cddf | 14582 | char *extra_string, |
983af33b SDJ |
14583 | enum bptype type_wanted, |
14584 | enum bpdisp disposition, | |
14585 | int thread, | |
14586 | int task, int ignore_count, | |
14587 | const struct breakpoint_ops *ops, | |
14588 | int from_tty, int enabled, | |
44f238bb | 14589 | int internal, unsigned flags) |
983af33b SDJ |
14590 | { |
14591 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14592 | extra_string, |
983af33b SDJ |
14593 | type_wanted, disposition, |
14594 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14595 | enabled, internal, flags); |
983af33b SDJ |
14596 | } |
14597 | ||
14598 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14599 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14600 | |
14601 | static void | |
f00aae0f KS |
14602 | decode_location_default (struct breakpoint *b, |
14603 | const struct event_location *location, | |
c2f4122d | 14604 | struct program_space *search_pspace, |
983af33b SDJ |
14605 | struct symtabs_and_lines *sals) |
14606 | { | |
14607 | struct linespec_result canonical; | |
14608 | ||
14609 | init_linespec_result (&canonical); | |
c2f4122d | 14610 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14611 | (struct symtab *) NULL, 0, |
14612 | &canonical, multiple_symbols_all, | |
14613 | b->filter); | |
14614 | ||
14615 | /* We should get 0 or 1 resulting SALs. */ | |
14616 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14617 | ||
14618 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14619 | { | |
14620 | struct linespec_sals *lsal; | |
14621 | ||
14622 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14623 | *sals = lsal->sals; | |
14624 | /* Arrange it so the destructor does not free the | |
14625 | contents. */ | |
14626 | lsal->sals.sals = NULL; | |
14627 | } | |
14628 | ||
14629 | destroy_linespec_result (&canonical); | |
14630 | } | |
14631 | ||
28010a5d PA |
14632 | /* Prepare the global context for a re-set of breakpoint B. */ |
14633 | ||
14634 | static struct cleanup * | |
14635 | prepare_re_set_context (struct breakpoint *b) | |
14636 | { | |
28010a5d | 14637 | input_radix = b->input_radix; |
28010a5d PA |
14638 | set_language (b->language); |
14639 | ||
c2f4122d | 14640 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14641 | } |
14642 | ||
c906108c SS |
14643 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14644 | The value we return ends up being the return value from catch_errors. | |
14645 | Unused in this case. */ | |
14646 | ||
14647 | static int | |
4efb68b1 | 14648 | breakpoint_re_set_one (void *bint) |
c906108c | 14649 | { |
4a64f543 | 14650 | /* Get past catch_errs. */ |
53a5351d | 14651 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14652 | struct cleanup *cleanups; |
c906108c | 14653 | |
348d480f PA |
14654 | cleanups = prepare_re_set_context (b); |
14655 | b->ops->re_set (b); | |
14656 | do_cleanups (cleanups); | |
c906108c SS |
14657 | return 0; |
14658 | } | |
14659 | ||
c2f4122d PA |
14660 | /* Re-set breakpoint locations for the current program space. |
14661 | Locations bound to other program spaces are left untouched. */ | |
14662 | ||
c906108c | 14663 | void |
69de3c6a | 14664 | breakpoint_re_set (void) |
c906108c | 14665 | { |
35df4500 | 14666 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14667 | enum language save_language; |
14668 | int save_input_radix; | |
6c95b8df | 14669 | struct cleanup *old_chain; |
c5aa993b | 14670 | |
c906108c SS |
14671 | save_language = current_language->la_language; |
14672 | save_input_radix = input_radix; | |
c2f4122d | 14673 | old_chain = save_current_space_and_thread (); |
6c95b8df | 14674 | |
2a7f3dff PA |
14675 | /* Note: we must not try to insert locations until after all |
14676 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14677 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14678 | hadn't been re-set yet, and thus may have stale locations. */ | |
14679 | ||
35df4500 | 14680 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14681 | { |
4a64f543 | 14682 | /* Format possible error msg. */ |
fe3f5fa8 | 14683 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14684 | b->number); |
14685 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14686 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14687 | do_cleanups (cleanups); |
c5aa993b | 14688 | } |
c906108c SS |
14689 | set_language (save_language); |
14690 | input_radix = save_input_radix; | |
e62c965a | 14691 | |
0756c555 | 14692 | jit_breakpoint_re_set (); |
4efc6507 | 14693 | |
6c95b8df PA |
14694 | do_cleanups (old_chain); |
14695 | ||
af02033e PP |
14696 | create_overlay_event_breakpoint (); |
14697 | create_longjmp_master_breakpoint (); | |
14698 | create_std_terminate_master_breakpoint (); | |
186c406b | 14699 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14700 | |
14701 | /* Now we can insert. */ | |
14702 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14703 | } |
14704 | \f | |
c906108c SS |
14705 | /* Reset the thread number of this breakpoint: |
14706 | ||
14707 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14708 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14709 | void |
fba45db2 | 14710 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14711 | { |
14712 | if (b->thread != -1) | |
14713 | { | |
39f77062 | 14714 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14715 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14716 | |
14717 | /* We're being called after following a fork. The new fork is | |
14718 | selected as current, and unless this was a vfork will have a | |
14719 | different program space from the original thread. Reset that | |
14720 | as well. */ | |
14721 | b->loc->pspace = current_program_space; | |
c906108c SS |
14722 | } |
14723 | } | |
14724 | ||
03ac34d5 MS |
14725 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14726 | If from_tty is nonzero, it prints a message to that effect, | |
14727 | which ends with a period (no newline). */ | |
14728 | ||
c906108c | 14729 | void |
fba45db2 | 14730 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14731 | { |
52f0bd74 | 14732 | struct breakpoint *b; |
c906108c SS |
14733 | |
14734 | if (count < 0) | |
14735 | count = 0; | |
14736 | ||
14737 | ALL_BREAKPOINTS (b) | |
14738 | if (b->number == bptnum) | |
c5aa993b | 14739 | { |
d77f58be SS |
14740 | if (is_tracepoint (b)) |
14741 | { | |
14742 | if (from_tty && count != 0) | |
14743 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14744 | bptnum); | |
14745 | return; | |
14746 | } | |
14747 | ||
c5aa993b | 14748 | b->ignore_count = count; |
221ea385 KS |
14749 | if (from_tty) |
14750 | { | |
14751 | if (count == 0) | |
3e43a32a MS |
14752 | printf_filtered (_("Will stop next time " |
14753 | "breakpoint %d is reached."), | |
221ea385 KS |
14754 | bptnum); |
14755 | else if (count == 1) | |
a3f17187 | 14756 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14757 | bptnum); |
14758 | else | |
3e43a32a MS |
14759 | printf_filtered (_("Will ignore next %d " |
14760 | "crossings of breakpoint %d."), | |
221ea385 KS |
14761 | count, bptnum); |
14762 | } | |
8d3788bd | 14763 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14764 | return; |
14765 | } | |
c906108c | 14766 | |
8a3fe4f8 | 14767 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14768 | } |
14769 | ||
c906108c SS |
14770 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14771 | ||
14772 | static void | |
fba45db2 | 14773 | ignore_command (char *args, int from_tty) |
c906108c SS |
14774 | { |
14775 | char *p = args; | |
52f0bd74 | 14776 | int num; |
c906108c SS |
14777 | |
14778 | if (p == 0) | |
e2e0b3e5 | 14779 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14780 | |
c906108c | 14781 | num = get_number (&p); |
5c44784c | 14782 | if (num == 0) |
8a3fe4f8 | 14783 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14784 | if (*p == 0) |
8a3fe4f8 | 14785 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14786 | |
14787 | set_ignore_count (num, | |
14788 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14789 | from_tty); | |
221ea385 KS |
14790 | if (from_tty) |
14791 | printf_filtered ("\n"); | |
c906108c SS |
14792 | } |
14793 | \f | |
14794 | /* Call FUNCTION on each of the breakpoints | |
14795 | whose numbers are given in ARGS. */ | |
14796 | ||
14797 | static void | |
95a42b64 TT |
14798 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14799 | void *), | |
14800 | void *data) | |
c906108c | 14801 | { |
52f0bd74 AC |
14802 | int num; |
14803 | struct breakpoint *b, *tmp; | |
c906108c | 14804 | |
b9d61307 | 14805 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14806 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14807 | |
bfd28288 | 14808 | number_or_range_parser parser (args); |
197f0a60 | 14809 | |
bfd28288 | 14810 | while (!parser.finished ()) |
c906108c | 14811 | { |
bfd28288 PA |
14812 | const char *p = parser.cur_tok (); |
14813 | bool match = false; | |
197f0a60 | 14814 | |
bfd28288 | 14815 | num = parser.get_number (); |
5c44784c | 14816 | if (num == 0) |
c5aa993b | 14817 | { |
8a3fe4f8 | 14818 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14819 | } |
14820 | else | |
14821 | { | |
14822 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14823 | if (b->number == num) | |
14824 | { | |
bfd28288 | 14825 | match = true; |
cdac0397 | 14826 | function (b, data); |
11cf8741 | 14827 | break; |
5c44784c | 14828 | } |
bfd28288 | 14829 | if (!match) |
a3f17187 | 14830 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14831 | } |
c906108c SS |
14832 | } |
14833 | } | |
14834 | ||
0d381245 VP |
14835 | static struct bp_location * |
14836 | find_location_by_number (char *number) | |
14837 | { | |
14838 | char *dot = strchr (number, '.'); | |
14839 | char *p1; | |
14840 | int bp_num; | |
14841 | int loc_num; | |
14842 | struct breakpoint *b; | |
14843 | struct bp_location *loc; | |
14844 | ||
14845 | *dot = '\0'; | |
14846 | ||
14847 | p1 = number; | |
197f0a60 | 14848 | bp_num = get_number (&p1); |
0d381245 VP |
14849 | if (bp_num == 0) |
14850 | error (_("Bad breakpoint number '%s'"), number); | |
14851 | ||
14852 | ALL_BREAKPOINTS (b) | |
14853 | if (b->number == bp_num) | |
14854 | { | |
14855 | break; | |
14856 | } | |
14857 | ||
14858 | if (!b || b->number != bp_num) | |
14859 | error (_("Bad breakpoint number '%s'"), number); | |
14860 | ||
14861 | p1 = dot+1; | |
197f0a60 | 14862 | loc_num = get_number (&p1); |
0d381245 VP |
14863 | if (loc_num == 0) |
14864 | error (_("Bad breakpoint location number '%s'"), number); | |
14865 | ||
14866 | --loc_num; | |
14867 | loc = b->loc; | |
14868 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14869 | ; | |
14870 | if (!loc) | |
14871 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14872 | ||
14873 | return loc; | |
14874 | } | |
14875 | ||
14876 | ||
1900040c MS |
14877 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14878 | If from_tty is nonzero, it prints a message to that effect, | |
14879 | which ends with a period (no newline). */ | |
14880 | ||
c906108c | 14881 | void |
fba45db2 | 14882 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14883 | { |
14884 | /* Never disable a watchpoint scope breakpoint; we want to | |
14885 | hit them when we leave scope so we can delete both the | |
14886 | watchpoint and its scope breakpoint at that time. */ | |
14887 | if (bpt->type == bp_watchpoint_scope) | |
14888 | return; | |
14889 | ||
b5de0fa7 | 14890 | bpt->enable_state = bp_disabled; |
c906108c | 14891 | |
b775012e LM |
14892 | /* Mark breakpoint locations modified. */ |
14893 | mark_breakpoint_modified (bpt); | |
14894 | ||
d248b706 KY |
14895 | if (target_supports_enable_disable_tracepoint () |
14896 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14897 | { | |
14898 | struct bp_location *location; | |
14899 | ||
14900 | for (location = bpt->loc; location; location = location->next) | |
14901 | target_disable_tracepoint (location); | |
14902 | } | |
14903 | ||
44702360 | 14904 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14905 | |
8d3788bd | 14906 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14907 | } |
14908 | ||
51be5b68 PA |
14909 | /* A callback for iterate_over_related_breakpoints. */ |
14910 | ||
14911 | static void | |
14912 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14913 | { | |
14914 | disable_breakpoint (b); | |
14915 | } | |
14916 | ||
95a42b64 TT |
14917 | /* A callback for map_breakpoint_numbers that calls |
14918 | disable_breakpoint. */ | |
14919 | ||
14920 | static void | |
14921 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14922 | { | |
51be5b68 | 14923 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14924 | } |
14925 | ||
c906108c | 14926 | static void |
fba45db2 | 14927 | disable_command (char *args, int from_tty) |
c906108c | 14928 | { |
c906108c | 14929 | if (args == 0) |
46c6471b PA |
14930 | { |
14931 | struct breakpoint *bpt; | |
14932 | ||
14933 | ALL_BREAKPOINTS (bpt) | |
14934 | if (user_breakpoint_p (bpt)) | |
14935 | disable_breakpoint (bpt); | |
14936 | } | |
9eaabc75 | 14937 | else |
0d381245 | 14938 | { |
9eaabc75 MW |
14939 | char *num = extract_arg (&args); |
14940 | ||
14941 | while (num) | |
d248b706 | 14942 | { |
9eaabc75 | 14943 | if (strchr (num, '.')) |
b775012e | 14944 | { |
9eaabc75 MW |
14945 | struct bp_location *loc = find_location_by_number (num); |
14946 | ||
14947 | if (loc) | |
14948 | { | |
14949 | if (loc->enabled) | |
14950 | { | |
14951 | loc->enabled = 0; | |
14952 | mark_breakpoint_location_modified (loc); | |
14953 | } | |
14954 | if (target_supports_enable_disable_tracepoint () | |
14955 | && current_trace_status ()->running && loc->owner | |
14956 | && is_tracepoint (loc->owner)) | |
14957 | target_disable_tracepoint (loc); | |
14958 | } | |
44702360 | 14959 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14960 | } |
9eaabc75 MW |
14961 | else |
14962 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14963 | num = extract_arg (&args); | |
d248b706 | 14964 | } |
0d381245 | 14965 | } |
c906108c SS |
14966 | } |
14967 | ||
14968 | static void | |
816338b5 SS |
14969 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14970 | int count) | |
c906108c | 14971 | { |
afe38095 | 14972 | int target_resources_ok; |
c906108c SS |
14973 | |
14974 | if (bpt->type == bp_hardware_breakpoint) | |
14975 | { | |
14976 | int i; | |
c5aa993b | 14977 | i = hw_breakpoint_used_count (); |
53a5351d | 14978 | target_resources_ok = |
d92524f1 | 14979 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14980 | i + 1, 0); |
c906108c | 14981 | if (target_resources_ok == 0) |
8a3fe4f8 | 14982 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14983 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14984 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14985 | } |
14986 | ||
cc60f2e3 | 14987 | if (is_watchpoint (bpt)) |
c906108c | 14988 | { |
d07205c2 | 14989 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14990 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14991 | |
492d29ea | 14992 | TRY |
c906108c | 14993 | { |
3a5c3e22 PA |
14994 | struct watchpoint *w = (struct watchpoint *) bpt; |
14995 | ||
1e718ff1 TJB |
14996 | orig_enable_state = bpt->enable_state; |
14997 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14998 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14999 | } |
492d29ea | 15000 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 15001 | { |
1e718ff1 | 15002 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
15003 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
15004 | bpt->number); | |
15005 | return; | |
c5aa993b | 15006 | } |
492d29ea | 15007 | END_CATCH |
c906108c | 15008 | } |
0101ce28 | 15009 | |
b775012e LM |
15010 | bpt->enable_state = bp_enabled; |
15011 | ||
15012 | /* Mark breakpoint locations modified. */ | |
15013 | mark_breakpoint_modified (bpt); | |
15014 | ||
d248b706 KY |
15015 | if (target_supports_enable_disable_tracepoint () |
15016 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
15017 | { | |
15018 | struct bp_location *location; | |
15019 | ||
15020 | for (location = bpt->loc; location; location = location->next) | |
15021 | target_enable_tracepoint (location); | |
15022 | } | |
15023 | ||
b4c291bb | 15024 | bpt->disposition = disposition; |
816338b5 | 15025 | bpt->enable_count = count; |
44702360 | 15026 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 15027 | |
8d3788bd | 15028 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15029 | } |
15030 | ||
fe3f5fa8 | 15031 | |
c906108c | 15032 | void |
fba45db2 | 15033 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 15034 | { |
816338b5 | 15035 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
15036 | } |
15037 | ||
15038 | static void | |
15039 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
15040 | { | |
15041 | enable_breakpoint (bpt); | |
c906108c SS |
15042 | } |
15043 | ||
95a42b64 TT |
15044 | /* A callback for map_breakpoint_numbers that calls |
15045 | enable_breakpoint. */ | |
15046 | ||
15047 | static void | |
15048 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15049 | { | |
51be5b68 | 15050 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15051 | } |
15052 | ||
c906108c SS |
15053 | /* The enable command enables the specified breakpoints (or all defined |
15054 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15055 | in stopping the inferior. */ |
c906108c | 15056 | |
c906108c | 15057 | static void |
fba45db2 | 15058 | enable_command (char *args, int from_tty) |
c906108c | 15059 | { |
c906108c | 15060 | if (args == 0) |
46c6471b PA |
15061 | { |
15062 | struct breakpoint *bpt; | |
15063 | ||
15064 | ALL_BREAKPOINTS (bpt) | |
15065 | if (user_breakpoint_p (bpt)) | |
15066 | enable_breakpoint (bpt); | |
15067 | } | |
9eaabc75 | 15068 | else |
0d381245 | 15069 | { |
9eaabc75 MW |
15070 | char *num = extract_arg (&args); |
15071 | ||
15072 | while (num) | |
d248b706 | 15073 | { |
9eaabc75 | 15074 | if (strchr (num, '.')) |
b775012e | 15075 | { |
9eaabc75 MW |
15076 | struct bp_location *loc = find_location_by_number (num); |
15077 | ||
15078 | if (loc) | |
15079 | { | |
15080 | if (!loc->enabled) | |
15081 | { | |
15082 | loc->enabled = 1; | |
15083 | mark_breakpoint_location_modified (loc); | |
15084 | } | |
15085 | if (target_supports_enable_disable_tracepoint () | |
15086 | && current_trace_status ()->running && loc->owner | |
15087 | && is_tracepoint (loc->owner)) | |
15088 | target_enable_tracepoint (loc); | |
15089 | } | |
44702360 | 15090 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15091 | } |
9eaabc75 MW |
15092 | else |
15093 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15094 | num = extract_arg (&args); | |
d248b706 | 15095 | } |
0d381245 | 15096 | } |
c906108c SS |
15097 | } |
15098 | ||
816338b5 SS |
15099 | /* This struct packages up disposition data for application to multiple |
15100 | breakpoints. */ | |
15101 | ||
15102 | struct disp_data | |
15103 | { | |
15104 | enum bpdisp disp; | |
15105 | int count; | |
15106 | }; | |
15107 | ||
c906108c | 15108 | static void |
51be5b68 PA |
15109 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15110 | { | |
816338b5 | 15111 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15112 | |
816338b5 | 15113 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15114 | } |
15115 | ||
15116 | static void | |
15117 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15118 | { |
816338b5 | 15119 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15120 | |
15121 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15122 | } |
15123 | ||
c906108c | 15124 | static void |
fba45db2 | 15125 | enable_once_command (char *args, int from_tty) |
c906108c | 15126 | { |
51be5b68 | 15127 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15128 | } |
15129 | ||
816338b5 SS |
15130 | static void |
15131 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15132 | { | |
15133 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15134 | ||
15135 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15136 | } | |
15137 | ||
15138 | static void | |
15139 | enable_count_command (char *args, int from_tty) | |
15140 | { | |
b9d61307 SM |
15141 | int count; |
15142 | ||
15143 | if (args == NULL) | |
15144 | error_no_arg (_("hit count")); | |
15145 | ||
15146 | count = get_number (&args); | |
816338b5 SS |
15147 | |
15148 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15149 | } | |
15150 | ||
c906108c | 15151 | static void |
51be5b68 | 15152 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15153 | { |
816338b5 | 15154 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15155 | |
15156 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15157 | } |
15158 | ||
c906108c | 15159 | static void |
fba45db2 | 15160 | enable_delete_command (char *args, int from_tty) |
c906108c | 15161 | { |
51be5b68 | 15162 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15163 | } |
15164 | \f | |
fa8d40ab JJ |
15165 | static void |
15166 | set_breakpoint_cmd (char *args, int from_tty) | |
15167 | { | |
15168 | } | |
15169 | ||
15170 | static void | |
15171 | show_breakpoint_cmd (char *args, int from_tty) | |
15172 | { | |
15173 | } | |
15174 | ||
1f3b5d1b PP |
15175 | /* Invalidate last known value of any hardware watchpoint if |
15176 | the memory which that value represents has been written to by | |
15177 | GDB itself. */ | |
15178 | ||
15179 | static void | |
8de0566d YQ |
15180 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15181 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15182 | const bfd_byte *data) |
15183 | { | |
15184 | struct breakpoint *bp; | |
15185 | ||
15186 | ALL_BREAKPOINTS (bp) | |
15187 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15188 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15189 | { |
3a5c3e22 | 15190 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15191 | |
3a5c3e22 PA |
15192 | if (wp->val_valid && wp->val) |
15193 | { | |
15194 | struct bp_location *loc; | |
15195 | ||
15196 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15197 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15198 | && loc->address + loc->length > addr | |
15199 | && addr + len > loc->address) | |
15200 | { | |
15201 | value_free (wp->val); | |
15202 | wp->val = NULL; | |
15203 | wp->val_valid = 0; | |
15204 | } | |
15205 | } | |
1f3b5d1b PP |
15206 | } |
15207 | } | |
15208 | ||
8181d85f DJ |
15209 | /* Create and insert a breakpoint for software single step. */ |
15210 | ||
15211 | void | |
6c95b8df | 15212 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15213 | struct address_space *aspace, |
15214 | CORE_ADDR next_pc) | |
8181d85f | 15215 | { |
7c16b83e PA |
15216 | struct thread_info *tp = inferior_thread (); |
15217 | struct symtab_and_line sal; | |
15218 | CORE_ADDR pc = next_pc; | |
8181d85f | 15219 | |
34b7e8a6 PA |
15220 | if (tp->control.single_step_breakpoints == NULL) |
15221 | { | |
15222 | tp->control.single_step_breakpoints | |
5d5658a1 | 15223 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 15224 | } |
8181d85f | 15225 | |
7c16b83e PA |
15226 | sal = find_pc_line (pc, 0); |
15227 | sal.pc = pc; | |
15228 | sal.section = find_pc_overlay (pc); | |
15229 | sal.explicit_pc = 1; | |
34b7e8a6 | 15230 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15231 | |
7c16b83e | 15232 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15233 | } |
15234 | ||
34b7e8a6 | 15235 | /* See breakpoint.h. */ |
f02253f1 HZ |
15236 | |
15237 | int | |
7c16b83e PA |
15238 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15239 | struct address_space *aspace, | |
15240 | CORE_ADDR pc) | |
1aafd4da | 15241 | { |
7c16b83e | 15242 | struct bp_location *loc; |
1aafd4da | 15243 | |
7c16b83e PA |
15244 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15245 | if (loc->inserted | |
15246 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15247 | return 1; | |
1aafd4da | 15248 | |
7c16b83e | 15249 | return 0; |
ef370185 JB |
15250 | } |
15251 | ||
15252 | /* Check whether a software single-step breakpoint is inserted at | |
15253 | PC. */ | |
15254 | ||
15255 | int | |
15256 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15257 | CORE_ADDR pc) | |
15258 | { | |
34b7e8a6 PA |
15259 | struct breakpoint *bpt; |
15260 | ||
15261 | ALL_BREAKPOINTS (bpt) | |
15262 | { | |
15263 | if (bpt->type == bp_single_step | |
15264 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15265 | return 1; | |
15266 | } | |
15267 | return 0; | |
1aafd4da UW |
15268 | } |
15269 | ||
1042e4c0 SS |
15270 | /* Tracepoint-specific operations. */ |
15271 | ||
15272 | /* Set tracepoint count to NUM. */ | |
15273 | static void | |
15274 | set_tracepoint_count (int num) | |
15275 | { | |
15276 | tracepoint_count = num; | |
4fa62494 | 15277 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15278 | } |
15279 | ||
70221824 | 15280 | static void |
1042e4c0 SS |
15281 | trace_command (char *arg, int from_tty) |
15282 | { | |
55aa24fb | 15283 | struct breakpoint_ops *ops; |
f00aae0f KS |
15284 | struct event_location *location; |
15285 | struct cleanup *back_to; | |
55aa24fb | 15286 | |
f00aae0f KS |
15287 | location = string_to_event_location (&arg, current_language); |
15288 | back_to = make_cleanup_delete_event_location (location); | |
5b56227b KS |
15289 | if (location != NULL |
15290 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
15291 | ops = &tracepoint_probe_breakpoint_ops; |
15292 | else | |
15293 | ops = &tracepoint_breakpoint_ops; | |
15294 | ||
558a9d82 | 15295 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15296 | location, |
15297 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15298 | 0 /* tempflag */, |
15299 | bp_tracepoint /* type_wanted */, | |
15300 | 0 /* Ignore count */, | |
15301 | pending_break_support, | |
15302 | ops, | |
15303 | from_tty, | |
15304 | 1 /* enabled */, | |
15305 | 0 /* internal */, 0); | |
f00aae0f | 15306 | do_cleanups (back_to); |
1042e4c0 SS |
15307 | } |
15308 | ||
70221824 | 15309 | static void |
7a697b8d SS |
15310 | ftrace_command (char *arg, int from_tty) |
15311 | { | |
f00aae0f KS |
15312 | struct event_location *location; |
15313 | struct cleanup *back_to; | |
15314 | ||
15315 | location = string_to_event_location (&arg, current_language); | |
15316 | back_to = make_cleanup_delete_event_location (location); | |
558a9d82 | 15317 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15318 | location, |
15319 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15320 | 0 /* tempflag */, |
15321 | bp_fast_tracepoint /* type_wanted */, | |
15322 | 0 /* Ignore count */, | |
15323 | pending_break_support, | |
15324 | &tracepoint_breakpoint_ops, | |
15325 | from_tty, | |
15326 | 1 /* enabled */, | |
15327 | 0 /* internal */, 0); | |
f00aae0f | 15328 | do_cleanups (back_to); |
0fb4aa4b PA |
15329 | } |
15330 | ||
15331 | /* strace command implementation. Creates a static tracepoint. */ | |
15332 | ||
70221824 | 15333 | static void |
0fb4aa4b PA |
15334 | strace_command (char *arg, int from_tty) |
15335 | { | |
983af33b | 15336 | struct breakpoint_ops *ops; |
f00aae0f KS |
15337 | struct event_location *location; |
15338 | struct cleanup *back_to; | |
983af33b SDJ |
15339 | |
15340 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15341 | or with a normal static tracepoint. */ | |
61012eef | 15342 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15343 | { |
15344 | ops = &strace_marker_breakpoint_ops; | |
15345 | location = new_linespec_location (&arg); | |
15346 | } | |
983af33b | 15347 | else |
f00aae0f KS |
15348 | { |
15349 | ops = &tracepoint_breakpoint_ops; | |
15350 | location = string_to_event_location (&arg, current_language); | |
15351 | } | |
983af33b | 15352 | |
f00aae0f | 15353 | back_to = make_cleanup_delete_event_location (location); |
558a9d82 | 15354 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15355 | location, |
15356 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15357 | 0 /* tempflag */, |
15358 | bp_static_tracepoint /* type_wanted */, | |
15359 | 0 /* Ignore count */, | |
15360 | pending_break_support, | |
15361 | ops, | |
15362 | from_tty, | |
15363 | 1 /* enabled */, | |
15364 | 0 /* internal */, 0); | |
f00aae0f | 15365 | do_cleanups (back_to); |
7a697b8d SS |
15366 | } |
15367 | ||
409873ef SS |
15368 | /* Set up a fake reader function that gets command lines from a linked |
15369 | list that was acquired during tracepoint uploading. */ | |
15370 | ||
15371 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15372 | static int next_cmd; |
409873ef SS |
15373 | |
15374 | static char * | |
15375 | read_uploaded_action (void) | |
15376 | { | |
15377 | char *rslt; | |
15378 | ||
3149d8c1 | 15379 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15380 | |
3149d8c1 | 15381 | next_cmd++; |
409873ef SS |
15382 | |
15383 | return rslt; | |
15384 | } | |
15385 | ||
00bf0b85 SS |
15386 | /* Given information about a tracepoint as recorded on a target (which |
15387 | can be either a live system or a trace file), attempt to create an | |
15388 | equivalent GDB tracepoint. This is not a reliable process, since | |
15389 | the target does not necessarily have all the information used when | |
15390 | the tracepoint was originally defined. */ | |
15391 | ||
d9b3f62e | 15392 | struct tracepoint * |
00bf0b85 | 15393 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15394 | { |
409873ef | 15395 | char *addr_str, small_buf[100]; |
d9b3f62e | 15396 | struct tracepoint *tp; |
f00aae0f KS |
15397 | struct event_location *location; |
15398 | struct cleanup *cleanup; | |
fd9b8c24 | 15399 | |
409873ef SS |
15400 | if (utp->at_string) |
15401 | addr_str = utp->at_string; | |
15402 | else | |
15403 | { | |
15404 | /* In the absence of a source location, fall back to raw | |
15405 | address. Since there is no way to confirm that the address | |
15406 | means the same thing as when the trace was started, warn the | |
15407 | user. */ | |
3e43a32a MS |
15408 | warning (_("Uploaded tracepoint %d has no " |
15409 | "source location, using raw address"), | |
409873ef | 15410 | utp->number); |
8c042590 | 15411 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15412 | addr_str = small_buf; |
15413 | } | |
15414 | ||
15415 | /* There's not much we can do with a sequence of bytecodes. */ | |
15416 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15417 | warning (_("Uploaded tracepoint %d condition " |
15418 | "has no source form, ignoring it"), | |
409873ef | 15419 | utp->number); |
d5551862 | 15420 | |
f00aae0f KS |
15421 | location = string_to_event_location (&addr_str, current_language); |
15422 | cleanup = make_cleanup_delete_event_location (location); | |
8cdf0e15 | 15423 | if (!create_breakpoint (get_current_arch (), |
f00aae0f KS |
15424 | location, |
15425 | utp->cond_string, -1, addr_str, | |
e7e0cddf | 15426 | 0 /* parse cond/thread */, |
8cdf0e15 | 15427 | 0 /* tempflag */, |
0fb4aa4b | 15428 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15429 | 0 /* Ignore count */, |
15430 | pending_break_support, | |
348d480f | 15431 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15432 | 0 /* from_tty */, |
84f4c1fe | 15433 | utp->enabled /* enabled */, |
44f238bb PA |
15434 | 0 /* internal */, |
15435 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
f00aae0f KS |
15436 | { |
15437 | do_cleanups (cleanup); | |
15438 | return NULL; | |
15439 | } | |
15440 | ||
15441 | do_cleanups (cleanup); | |
fd9b8c24 | 15442 | |
409873ef | 15443 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15444 | tp = get_tracepoint (tracepoint_count); |
15445 | gdb_assert (tp != NULL); | |
d5551862 | 15446 | |
00bf0b85 SS |
15447 | if (utp->pass > 0) |
15448 | { | |
8c042590 PM |
15449 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15450 | tp->base.number); | |
00bf0b85 | 15451 | |
409873ef | 15452 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15453 | } |
15454 | ||
409873ef SS |
15455 | /* If we have uploaded versions of the original commands, set up a |
15456 | special-purpose "reader" function and call the usual command line | |
15457 | reader, then pass the result to the breakpoint command-setting | |
15458 | function. */ | |
3149d8c1 | 15459 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15460 | { |
409873ef | 15461 | struct command_line *cmd_list; |
00bf0b85 | 15462 | |
409873ef | 15463 | this_utp = utp; |
3149d8c1 | 15464 | next_cmd = 0; |
d5551862 | 15465 | |
409873ef SS |
15466 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15467 | ||
d9b3f62e | 15468 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15469 | } |
3149d8c1 SS |
15470 | else if (!VEC_empty (char_ptr, utp->actions) |
15471 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15472 | warning (_("Uploaded tracepoint %d actions " |
15473 | "have no source form, ignoring them"), | |
409873ef | 15474 | utp->number); |
00bf0b85 | 15475 | |
f196051f SS |
15476 | /* Copy any status information that might be available. */ |
15477 | tp->base.hit_count = utp->hit_count; | |
15478 | tp->traceframe_usage = utp->traceframe_usage; | |
15479 | ||
00bf0b85 | 15480 | return tp; |
d9b3f62e | 15481 | } |
00bf0b85 | 15482 | |
1042e4c0 SS |
15483 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15484 | omitted. */ | |
15485 | ||
15486 | static void | |
e5a67952 | 15487 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15488 | { |
79a45e25 | 15489 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15490 | int num_printed; |
1042e4c0 | 15491 | |
e5a67952 | 15492 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15493 | |
15494 | if (num_printed == 0) | |
1042e4c0 | 15495 | { |
e5a67952 | 15496 | if (args == NULL || *args == '\0') |
d77f58be SS |
15497 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15498 | else | |
e5a67952 | 15499 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15500 | } |
ad443146 SS |
15501 | |
15502 | default_collect_info (); | |
1042e4c0 SS |
15503 | } |
15504 | ||
4a64f543 | 15505 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15506 | Not supported by all targets. */ |
15507 | static void | |
15508 | enable_trace_command (char *args, int from_tty) | |
15509 | { | |
15510 | enable_command (args, from_tty); | |
15511 | } | |
15512 | ||
4a64f543 | 15513 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15514 | Not supported by all targets. */ |
15515 | static void | |
15516 | disable_trace_command (char *args, int from_tty) | |
15517 | { | |
15518 | disable_command (args, from_tty); | |
15519 | } | |
15520 | ||
4a64f543 | 15521 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15522 | static void |
15523 | delete_trace_command (char *arg, int from_tty) | |
15524 | { | |
35df4500 | 15525 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15526 | |
15527 | dont_repeat (); | |
15528 | ||
15529 | if (arg == 0) | |
15530 | { | |
15531 | int breaks_to_delete = 0; | |
15532 | ||
15533 | /* Delete all breakpoints if no argument. | |
15534 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15535 | have to be deleted with an explicit breakpoint number |
15536 | argument. */ | |
1042e4c0 | 15537 | ALL_TRACEPOINTS (b) |
46c6471b | 15538 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15539 | { |
15540 | breaks_to_delete = 1; | |
15541 | break; | |
15542 | } | |
1042e4c0 SS |
15543 | |
15544 | /* Ask user only if there are some breakpoints to delete. */ | |
15545 | if (!from_tty | |
15546 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15547 | { | |
35df4500 | 15548 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15549 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15550 | delete_breakpoint (b); |
1042e4c0 SS |
15551 | } |
15552 | } | |
15553 | else | |
51be5b68 | 15554 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15555 | } |
15556 | ||
197f0a60 TT |
15557 | /* Helper function for trace_pass_command. */ |
15558 | ||
15559 | static void | |
d9b3f62e | 15560 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15561 | { |
d9b3f62e | 15562 | tp->pass_count = count; |
6f6484cd | 15563 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15564 | if (from_tty) |
15565 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15566 | tp->base.number, count); |
197f0a60 TT |
15567 | } |
15568 | ||
1042e4c0 SS |
15569 | /* Set passcount for tracepoint. |
15570 | ||
15571 | First command argument is passcount, second is tracepoint number. | |
15572 | If tracepoint number omitted, apply to most recently defined. | |
15573 | Also accepts special argument "all". */ | |
15574 | ||
15575 | static void | |
15576 | trace_pass_command (char *args, int from_tty) | |
15577 | { | |
d9b3f62e | 15578 | struct tracepoint *t1; |
1042e4c0 | 15579 | unsigned int count; |
1042e4c0 SS |
15580 | |
15581 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15582 | error (_("passcount command requires an " |
15583 | "argument (count + optional TP num)")); | |
1042e4c0 | 15584 | |
4a64f543 | 15585 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15586 | |
529480d0 | 15587 | args = skip_spaces (args); |
1042e4c0 SS |
15588 | if (*args && strncasecmp (args, "all", 3) == 0) |
15589 | { | |
d9b3f62e PA |
15590 | struct breakpoint *b; |
15591 | ||
1042e4c0 | 15592 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15593 | if (*args) |
15594 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15595 | |
d9b3f62e | 15596 | ALL_TRACEPOINTS (b) |
197f0a60 | 15597 | { |
d9b3f62e | 15598 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15599 | trace_pass_set_count (t1, count, from_tty); |
15600 | } | |
15601 | } | |
15602 | else if (*args == '\0') | |
1042e4c0 | 15603 | { |
5fa1d40e | 15604 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15605 | if (t1) |
197f0a60 TT |
15606 | trace_pass_set_count (t1, count, from_tty); |
15607 | } | |
15608 | else | |
15609 | { | |
bfd28288 PA |
15610 | number_or_range_parser parser (args); |
15611 | while (!parser.finished ()) | |
1042e4c0 | 15612 | { |
bfd28288 | 15613 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15614 | if (t1) |
15615 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15616 | } |
15617 | } | |
1042e4c0 SS |
15618 | } |
15619 | ||
d9b3f62e | 15620 | struct tracepoint * |
1042e4c0 SS |
15621 | get_tracepoint (int num) |
15622 | { | |
15623 | struct breakpoint *t; | |
15624 | ||
15625 | ALL_TRACEPOINTS (t) | |
15626 | if (t->number == num) | |
d9b3f62e | 15627 | return (struct tracepoint *) t; |
1042e4c0 SS |
15628 | |
15629 | return NULL; | |
15630 | } | |
15631 | ||
d5551862 SS |
15632 | /* Find the tracepoint with the given target-side number (which may be |
15633 | different from the tracepoint number after disconnecting and | |
15634 | reconnecting). */ | |
15635 | ||
d9b3f62e | 15636 | struct tracepoint * |
d5551862 SS |
15637 | get_tracepoint_by_number_on_target (int num) |
15638 | { | |
d9b3f62e | 15639 | struct breakpoint *b; |
d5551862 | 15640 | |
d9b3f62e PA |
15641 | ALL_TRACEPOINTS (b) |
15642 | { | |
15643 | struct tracepoint *t = (struct tracepoint *) b; | |
15644 | ||
15645 | if (t->number_on_target == num) | |
15646 | return t; | |
15647 | } | |
d5551862 SS |
15648 | |
15649 | return NULL; | |
15650 | } | |
15651 | ||
1042e4c0 | 15652 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15653 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15654 | If the argument is missing, the most recent tracepoint |
15655 | (tracepoint_count) is returned. */ | |
15656 | ||
d9b3f62e | 15657 | struct tracepoint * |
197f0a60 | 15658 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15659 | number_or_range_parser *parser) |
1042e4c0 | 15660 | { |
1042e4c0 SS |
15661 | struct breakpoint *t; |
15662 | int tpnum; | |
15663 | char *instring = arg == NULL ? NULL : *arg; | |
15664 | ||
bfd28288 | 15665 | if (parser != NULL) |
197f0a60 | 15666 | { |
bfd28288 PA |
15667 | gdb_assert (!parser->finished ()); |
15668 | tpnum = parser->get_number (); | |
197f0a60 TT |
15669 | } |
15670 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15671 | tpnum = tracepoint_count; |
1042e4c0 | 15672 | else |
197f0a60 | 15673 | tpnum = get_number (arg); |
1042e4c0 SS |
15674 | |
15675 | if (tpnum <= 0) | |
15676 | { | |
15677 | if (instring && *instring) | |
15678 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15679 | instring); | |
15680 | else | |
5fa1d40e | 15681 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15682 | return NULL; |
15683 | } | |
15684 | ||
15685 | ALL_TRACEPOINTS (t) | |
15686 | if (t->number == tpnum) | |
15687 | { | |
d9b3f62e | 15688 | return (struct tracepoint *) t; |
1042e4c0 SS |
15689 | } |
15690 | ||
1042e4c0 SS |
15691 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15692 | return NULL; | |
15693 | } | |
15694 | ||
d9b3f62e PA |
15695 | void |
15696 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15697 | { | |
15698 | if (b->thread != -1) | |
15699 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15700 | ||
15701 | if (b->task != 0) | |
15702 | fprintf_unfiltered (fp, " task %d", b->task); | |
15703 | ||
15704 | fprintf_unfiltered (fp, "\n"); | |
15705 | } | |
15706 | ||
6149aea9 PA |
15707 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15708 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15709 | on each breakpoint and only include the ones for which it returns | |
15710 | non-zero. */ | |
15711 | ||
1042e4c0 | 15712 | static void |
6149aea9 PA |
15713 | save_breakpoints (char *filename, int from_tty, |
15714 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15715 | { |
15716 | struct breakpoint *tp; | |
6149aea9 | 15717 | int any = 0; |
1042e4c0 | 15718 | struct cleanup *cleanup; |
a7bdde9e | 15719 | struct ui_file *fp; |
6149aea9 | 15720 | int extra_trace_bits = 0; |
1042e4c0 | 15721 | |
6149aea9 PA |
15722 | if (filename == 0 || *filename == 0) |
15723 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15724 | |
15725 | /* See if we have anything to save. */ | |
6149aea9 | 15726 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15727 | { |
6149aea9 | 15728 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15729 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15730 | continue; |
15731 | ||
15732 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15733 | if (filter && !filter (tp)) | |
15734 | continue; | |
15735 | ||
15736 | any = 1; | |
15737 | ||
15738 | if (is_tracepoint (tp)) | |
15739 | { | |
15740 | extra_trace_bits = 1; | |
15741 | ||
15742 | /* We can stop searching. */ | |
15743 | break; | |
15744 | } | |
1042e4c0 | 15745 | } |
6149aea9 PA |
15746 | |
15747 | if (!any) | |
1042e4c0 | 15748 | { |
6149aea9 | 15749 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15750 | return; |
15751 | } | |
15752 | ||
c718be47 PA |
15753 | filename = tilde_expand (filename); |
15754 | cleanup = make_cleanup (xfree, filename); | |
15755 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15756 | if (!fp) |
6149aea9 PA |
15757 | error (_("Unable to open file '%s' for saving (%s)"), |
15758 | filename, safe_strerror (errno)); | |
a7bdde9e | 15759 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15760 | |
6149aea9 PA |
15761 | if (extra_trace_bits) |
15762 | save_trace_state_variables (fp); | |
8bf6485c | 15763 | |
6149aea9 | 15764 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15765 | { |
6149aea9 | 15766 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15767 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15768 | continue; |
8bf6485c | 15769 | |
6149aea9 PA |
15770 | /* If we have a filter, only save the breakpoints it accepts. */ |
15771 | if (filter && !filter (tp)) | |
15772 | continue; | |
15773 | ||
348d480f | 15774 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15775 | |
6149aea9 PA |
15776 | /* Note, we can't rely on tp->number for anything, as we can't |
15777 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15778 | instead. */ | |
15779 | ||
15780 | if (tp->cond_string) | |
15781 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15782 | ||
15783 | if (tp->ignore_count) | |
15784 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15785 | ||
2d9442cc | 15786 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15787 | { |
6149aea9 | 15788 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15789 | |
79a45e25 | 15790 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15791 | TRY |
1042e4c0 | 15792 | { |
79a45e25 | 15793 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15794 | } |
492d29ea PA |
15795 | CATCH (ex, RETURN_MASK_ALL) |
15796 | { | |
6c63c96a | 15797 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15798 | throw_exception (ex); |
15799 | } | |
15800 | END_CATCH | |
1042e4c0 | 15801 | |
6c63c96a | 15802 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15803 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15804 | } |
6149aea9 PA |
15805 | |
15806 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15807 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15808 | |
15809 | /* If this is a multi-location breakpoint, check if the locations | |
15810 | should be individually disabled. Watchpoint locations are | |
15811 | special, and not user visible. */ | |
15812 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15813 | { | |
15814 | struct bp_location *loc; | |
15815 | int n = 1; | |
15816 | ||
15817 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15818 | if (!loc->enabled) | |
15819 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15820 | } | |
1042e4c0 | 15821 | } |
8bf6485c | 15822 | |
6149aea9 | 15823 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15824 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15825 | ||
1042e4c0 | 15826 | if (from_tty) |
6149aea9 | 15827 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15828 | do_cleanups (cleanup); |
6149aea9 PA |
15829 | } |
15830 | ||
15831 | /* The `save breakpoints' command. */ | |
15832 | ||
15833 | static void | |
15834 | save_breakpoints_command (char *args, int from_tty) | |
15835 | { | |
15836 | save_breakpoints (args, from_tty, NULL); | |
15837 | } | |
15838 | ||
15839 | /* The `save tracepoints' command. */ | |
15840 | ||
15841 | static void | |
15842 | save_tracepoints_command (char *args, int from_tty) | |
15843 | { | |
15844 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15845 | } |
15846 | ||
15847 | /* Create a vector of all tracepoints. */ | |
15848 | ||
15849 | VEC(breakpoint_p) * | |
eeae04df | 15850 | all_tracepoints (void) |
1042e4c0 SS |
15851 | { |
15852 | VEC(breakpoint_p) *tp_vec = 0; | |
15853 | struct breakpoint *tp; | |
15854 | ||
15855 | ALL_TRACEPOINTS (tp) | |
15856 | { | |
15857 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15858 | } | |
15859 | ||
15860 | return tp_vec; | |
15861 | } | |
15862 | ||
c906108c | 15863 | \f |
629500fa KS |
15864 | /* This help string is used to consolidate all the help string for specifying |
15865 | locations used by several commands. */ | |
15866 | ||
15867 | #define LOCATION_HELP_STRING \ | |
15868 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15869 | source filename, function name, label name, and line number.\n\ | |
15870 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15871 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15872 | \"factorial.c:fact:the_top\".\n\ | |
15873 | \n\ | |
15874 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15875 | program. Example: To specify the fourth byte past the start function\n\ | |
15876 | \"main\", use \"*main + 4\".\n\ | |
15877 | \n\ | |
15878 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15879 | syntax to specify location parameters.\n\ | |
15880 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15881 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15882 | -function fact -label the_top\".\n" | |
15883 | ||
4a64f543 MS |
15884 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15885 | commands. It is defined as a macro to prevent duplication. | |
15886 | COMMAND should be a string constant containing the name of the | |
15887 | command. */ | |
629500fa | 15888 | |
31e2b00f | 15889 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15890 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15891 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15892 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15893 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15894 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15895 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15896 | below.\n\ | |
15897 | \n\ | |
dc10affe PA |
15898 | With no LOCATION, uses current execution address of the selected\n\ |
15899 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15900 | \n\ |
15901 | THREADNUM is the number from \"info threads\".\n\ | |
15902 | CONDITION is a boolean expression.\n\ | |
629500fa | 15903 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15904 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15905 | conditions are different.\n\ | |
31e2b00f AS |
15906 | \n\ |
15907 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15908 | ||
44feb3ce TT |
15909 | /* List of subcommands for "catch". */ |
15910 | static struct cmd_list_element *catch_cmdlist; | |
15911 | ||
15912 | /* List of subcommands for "tcatch". */ | |
15913 | static struct cmd_list_element *tcatch_cmdlist; | |
15914 | ||
9ac4176b | 15915 | void |
44feb3ce | 15916 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15917 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15918 | completer_ftype *completer, |
44feb3ce TT |
15919 | void *user_data_catch, |
15920 | void *user_data_tcatch) | |
15921 | { | |
15922 | struct cmd_list_element *command; | |
15923 | ||
15924 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15925 | &catch_cmdlist); | |
15926 | set_cmd_sfunc (command, sfunc); | |
15927 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15928 | set_cmd_completer (command, completer); |
44feb3ce TT |
15929 | |
15930 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15931 | &tcatch_cmdlist); | |
15932 | set_cmd_sfunc (command, sfunc); | |
15933 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15934 | set_cmd_completer (command, completer); |
44feb3ce TT |
15935 | } |
15936 | ||
6149aea9 PA |
15937 | static void |
15938 | save_command (char *arg, int from_tty) | |
15939 | { | |
3e43a32a MS |
15940 | printf_unfiltered (_("\"save\" must be followed by " |
15941 | "the name of a save subcommand.\n")); | |
635c7e8a | 15942 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15943 | } |
15944 | ||
84f4c1fe PM |
15945 | struct breakpoint * |
15946 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15947 | void *data) | |
15948 | { | |
35df4500 | 15949 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15950 | |
35df4500 | 15951 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15952 | { |
15953 | if ((*callback) (b, data)) | |
15954 | return b; | |
15955 | } | |
15956 | ||
15957 | return NULL; | |
15958 | } | |
15959 | ||
0574c78f GB |
15960 | /* Zero if any of the breakpoint's locations could be a location where |
15961 | functions have been inlined, nonzero otherwise. */ | |
15962 | ||
15963 | static int | |
15964 | is_non_inline_function (struct breakpoint *b) | |
15965 | { | |
15966 | /* The shared library event breakpoint is set on the address of a | |
15967 | non-inline function. */ | |
15968 | if (b->type == bp_shlib_event) | |
15969 | return 1; | |
15970 | ||
15971 | return 0; | |
15972 | } | |
15973 | ||
15974 | /* Nonzero if the specified PC cannot be a location where functions | |
15975 | have been inlined. */ | |
15976 | ||
15977 | int | |
09ac7c10 TT |
15978 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15979 | const struct target_waitstatus *ws) | |
0574c78f GB |
15980 | { |
15981 | struct breakpoint *b; | |
15982 | struct bp_location *bl; | |
15983 | ||
15984 | ALL_BREAKPOINTS (b) | |
15985 | { | |
15986 | if (!is_non_inline_function (b)) | |
15987 | continue; | |
15988 | ||
15989 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15990 | { | |
15991 | if (!bl->shlib_disabled | |
09ac7c10 | 15992 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15993 | return 1; |
15994 | } | |
15995 | } | |
15996 | ||
15997 | return 0; | |
15998 | } | |
15999 | ||
2f202fde JK |
16000 | /* Remove any references to OBJFILE which is going to be freed. */ |
16001 | ||
16002 | void | |
16003 | breakpoint_free_objfile (struct objfile *objfile) | |
16004 | { | |
16005 | struct bp_location **locp, *loc; | |
16006 | ||
16007 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 16008 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
16009 | loc->symtab = NULL; |
16010 | } | |
16011 | ||
2060206e PA |
16012 | void |
16013 | initialize_breakpoint_ops (void) | |
16014 | { | |
16015 | static int initialized = 0; | |
16016 | ||
16017 | struct breakpoint_ops *ops; | |
16018 | ||
16019 | if (initialized) | |
16020 | return; | |
16021 | initialized = 1; | |
16022 | ||
16023 | /* The breakpoint_ops structure to be inherit by all kinds of | |
16024 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
16025 | internal and momentary breakpoints, etc.). */ | |
16026 | ops = &bkpt_base_breakpoint_ops; | |
16027 | *ops = base_breakpoint_ops; | |
16028 | ops->re_set = bkpt_re_set; | |
16029 | ops->insert_location = bkpt_insert_location; | |
16030 | ops->remove_location = bkpt_remove_location; | |
16031 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 16032 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 16033 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 16034 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
16035 | |
16036 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16037 | ops = &bkpt_breakpoint_ops; | |
16038 | *ops = bkpt_base_breakpoint_ops; | |
16039 | ops->re_set = bkpt_re_set; | |
16040 | ops->resources_needed = bkpt_resources_needed; | |
16041 | ops->print_it = bkpt_print_it; | |
16042 | ops->print_mention = bkpt_print_mention; | |
16043 | ops->print_recreate = bkpt_print_recreate; | |
16044 | ||
16045 | /* Ranged breakpoints. */ | |
16046 | ops = &ranged_breakpoint_ops; | |
16047 | *ops = bkpt_breakpoint_ops; | |
16048 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16049 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16050 | ops->print_it = print_it_ranged_breakpoint; | |
16051 | ops->print_one = print_one_ranged_breakpoint; | |
16052 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16053 | ops->print_mention = print_mention_ranged_breakpoint; | |
16054 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16055 | ||
16056 | /* Internal breakpoints. */ | |
16057 | ops = &internal_breakpoint_ops; | |
16058 | *ops = bkpt_base_breakpoint_ops; | |
16059 | ops->re_set = internal_bkpt_re_set; | |
16060 | ops->check_status = internal_bkpt_check_status; | |
16061 | ops->print_it = internal_bkpt_print_it; | |
16062 | ops->print_mention = internal_bkpt_print_mention; | |
16063 | ||
16064 | /* Momentary breakpoints. */ | |
16065 | ops = &momentary_breakpoint_ops; | |
16066 | *ops = bkpt_base_breakpoint_ops; | |
16067 | ops->re_set = momentary_bkpt_re_set; | |
16068 | ops->check_status = momentary_bkpt_check_status; | |
16069 | ops->print_it = momentary_bkpt_print_it; | |
16070 | ops->print_mention = momentary_bkpt_print_mention; | |
16071 | ||
e2e4d78b JK |
16072 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16073 | ops = &longjmp_breakpoint_ops; | |
16074 | *ops = momentary_breakpoint_ops; | |
16075 | ops->dtor = longjmp_bkpt_dtor; | |
16076 | ||
55aa24fb SDJ |
16077 | /* Probe breakpoints. */ |
16078 | ops = &bkpt_probe_breakpoint_ops; | |
16079 | *ops = bkpt_breakpoint_ops; | |
16080 | ops->insert_location = bkpt_probe_insert_location; | |
16081 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
16082 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
16083 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 16084 | |
2060206e PA |
16085 | /* Watchpoints. */ |
16086 | ops = &watchpoint_breakpoint_ops; | |
16087 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16088 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16089 | ops->re_set = re_set_watchpoint; |
16090 | ops->insert_location = insert_watchpoint; | |
16091 | ops->remove_location = remove_watchpoint; | |
16092 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16093 | ops->check_status = check_status_watchpoint; | |
16094 | ops->resources_needed = resources_needed_watchpoint; | |
16095 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16096 | ops->print_it = print_it_watchpoint; | |
16097 | ops->print_mention = print_mention_watchpoint; | |
16098 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16099 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16100 | |
16101 | /* Masked watchpoints. */ | |
16102 | ops = &masked_watchpoint_breakpoint_ops; | |
16103 | *ops = watchpoint_breakpoint_ops; | |
16104 | ops->insert_location = insert_masked_watchpoint; | |
16105 | ops->remove_location = remove_masked_watchpoint; | |
16106 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16107 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16108 | ops->print_it = print_it_masked_watchpoint; | |
16109 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16110 | ops->print_mention = print_mention_masked_watchpoint; | |
16111 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16112 | ||
16113 | /* Tracepoints. */ | |
16114 | ops = &tracepoint_breakpoint_ops; | |
16115 | *ops = base_breakpoint_ops; | |
16116 | ops->re_set = tracepoint_re_set; | |
16117 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16118 | ops->print_one_detail = tracepoint_print_one_detail; | |
16119 | ops->print_mention = tracepoint_print_mention; | |
16120 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 16121 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 16122 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 16123 | ops->decode_location = tracepoint_decode_location; |
983af33b | 16124 | |
55aa24fb SDJ |
16125 | /* Probe tracepoints. */ |
16126 | ops = &tracepoint_probe_breakpoint_ops; | |
16127 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
16128 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
16129 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 16130 | |
983af33b SDJ |
16131 | /* Static tracepoints with marker (`-m'). */ |
16132 | ops = &strace_marker_breakpoint_ops; | |
16133 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 16134 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 16135 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 16136 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
16137 | |
16138 | /* Fork catchpoints. */ | |
16139 | ops = &catch_fork_breakpoint_ops; | |
16140 | *ops = base_breakpoint_ops; | |
16141 | ops->insert_location = insert_catch_fork; | |
16142 | ops->remove_location = remove_catch_fork; | |
16143 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16144 | ops->print_it = print_it_catch_fork; | |
16145 | ops->print_one = print_one_catch_fork; | |
16146 | ops->print_mention = print_mention_catch_fork; | |
16147 | ops->print_recreate = print_recreate_catch_fork; | |
16148 | ||
16149 | /* Vfork catchpoints. */ | |
16150 | ops = &catch_vfork_breakpoint_ops; | |
16151 | *ops = base_breakpoint_ops; | |
16152 | ops->insert_location = insert_catch_vfork; | |
16153 | ops->remove_location = remove_catch_vfork; | |
16154 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16155 | ops->print_it = print_it_catch_vfork; | |
16156 | ops->print_one = print_one_catch_vfork; | |
16157 | ops->print_mention = print_mention_catch_vfork; | |
16158 | ops->print_recreate = print_recreate_catch_vfork; | |
16159 | ||
16160 | /* Exec catchpoints. */ | |
16161 | ops = &catch_exec_breakpoint_ops; | |
16162 | *ops = base_breakpoint_ops; | |
16163 | ops->dtor = dtor_catch_exec; | |
16164 | ops->insert_location = insert_catch_exec; | |
16165 | ops->remove_location = remove_catch_exec; | |
16166 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16167 | ops->print_it = print_it_catch_exec; | |
16168 | ops->print_one = print_one_catch_exec; | |
16169 | ops->print_mention = print_mention_catch_exec; | |
16170 | ops->print_recreate = print_recreate_catch_exec; | |
16171 | ||
edcc5120 TT |
16172 | /* Solib-related catchpoints. */ |
16173 | ops = &catch_solib_breakpoint_ops; | |
16174 | *ops = base_breakpoint_ops; | |
16175 | ops->dtor = dtor_catch_solib; | |
16176 | ops->insert_location = insert_catch_solib; | |
16177 | ops->remove_location = remove_catch_solib; | |
16178 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16179 | ops->check_status = check_status_catch_solib; | |
16180 | ops->print_it = print_it_catch_solib; | |
16181 | ops->print_one = print_one_catch_solib; | |
16182 | ops->print_mention = print_mention_catch_solib; | |
16183 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16184 | |
16185 | ops = &dprintf_breakpoint_ops; | |
16186 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16187 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16188 | ops->resources_needed = bkpt_resources_needed; |
16189 | ops->print_it = bkpt_print_it; | |
16190 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16191 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16192 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16193 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16194 | } |
16195 | ||
8bfd80db YQ |
16196 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16197 | ||
16198 | static struct cmd_list_element *enablebreaklist = NULL; | |
16199 | ||
c906108c | 16200 | void |
fba45db2 | 16201 | _initialize_breakpoint (void) |
c906108c SS |
16202 | { |
16203 | struct cmd_list_element *c; | |
16204 | ||
2060206e PA |
16205 | initialize_breakpoint_ops (); |
16206 | ||
84acb35a | 16207 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16208 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16209 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16210 | |
55aa24fb SDJ |
16211 | breakpoint_objfile_key |
16212 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16213 | |
c906108c SS |
16214 | breakpoint_chain = 0; |
16215 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16216 | before a breakpoint is set. */ | |
16217 | breakpoint_count = 0; | |
16218 | ||
1042e4c0 SS |
16219 | tracepoint_count = 0; |
16220 | ||
1bedd215 AC |
16221 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16222 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16223 | Usage is `ignore N COUNT'.")); | |
c906108c | 16224 | |
1bedd215 AC |
16225 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16226 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16227 | Give breakpoint number as argument after \"commands\".\n\ |
16228 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16229 | The commands themselves follow starting on the next line.\n\ | |
16230 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16231 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16232 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16233 | |
d55637df | 16234 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16235 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16236 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16237 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16238 | set_cmd_completer (c, condition_completer); |
c906108c | 16239 | |
1bedd215 | 16240 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16241 | Set a temporary breakpoint.\n\ |
c906108c SS |
16242 | Like \"break\" except the breakpoint is only temporary,\n\ |
16243 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16244 | by using \"enable delete\" on the breakpoint number.\n\ |
16245 | \n" | |
16246 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16247 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16248 | |
1bedd215 | 16249 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16250 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16251 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16252 | some target hardware may not have this support.\n\ |
16253 | \n" | |
16254 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16255 | set_cmd_completer (c, location_completer); |
c906108c | 16256 | |
1bedd215 | 16257 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16258 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16259 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16260 | so it will be deleted when hit.\n\ |
16261 | \n" | |
16262 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16263 | set_cmd_completer (c, location_completer); |
c906108c | 16264 | |
1bedd215 AC |
16265 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16266 | Enable some breakpoints.\n\ | |
c906108c SS |
16267 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16268 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16269 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16270 | With a subcommand you can enable temporarily."), |
c906108c | 16271 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16272 | |
16273 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16274 | ||
84951ab5 | 16275 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16276 | Enable some breakpoints.\n\ |
c906108c SS |
16277 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16278 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16279 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16280 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16281 | |
1a966eab AC |
16282 | add_cmd ("once", no_class, enable_once_command, _("\ |
16283 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16284 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16285 | &enablebreaklist); |
16286 | ||
1a966eab AC |
16287 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16288 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16289 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16290 | &enablebreaklist); |
16291 | ||
816338b5 SS |
16292 | add_cmd ("count", no_class, enable_count_command, _("\ |
16293 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16294 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16295 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16296 | &enablebreaklist); | |
16297 | ||
1a966eab AC |
16298 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16299 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16300 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16301 | &enablelist); |
16302 | ||
1a966eab AC |
16303 | add_cmd ("once", no_class, enable_once_command, _("\ |
16304 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16305 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16306 | &enablelist); |
16307 | ||
16308 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16309 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16310 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16311 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16312 | &enablelist); |
16313 | ||
1bedd215 AC |
16314 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16315 | Disable some breakpoints.\n\ | |
c906108c SS |
16316 | Arguments are breakpoint numbers with spaces in between.\n\ |
16317 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16318 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16319 | &disablelist, "disable ", 1, &cmdlist); |
16320 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16321 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16322 | |
1a966eab AC |
16323 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16324 | Disable some breakpoints.\n\ | |
c906108c SS |
16325 | Arguments are breakpoint numbers with spaces in between.\n\ |
16326 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16327 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16328 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16329 | &disablelist); |
16330 | ||
1bedd215 AC |
16331 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16332 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16333 | Arguments are breakpoint numbers with spaces in between.\n\ |
16334 | To delete all breakpoints, give no argument.\n\ | |
16335 | \n\ | |
16336 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16337 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16338 | &deletelist, "delete ", 1, &cmdlist); |
16339 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16340 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16341 | |
1a966eab AC |
16342 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16343 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16344 | Arguments are breakpoint numbers with spaces in between.\n\ |
16345 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16346 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16347 | &deletelist); |
16348 | ||
1bedd215 | 16349 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16350 | Clear breakpoint at specified location.\n\ |
16351 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16352 | \n\ |
16353 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16354 | is executing in.\n" |
16355 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16356 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16357 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16358 | |
1bedd215 | 16359 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16360 | Set breakpoint at specified location.\n" |
31e2b00f | 16361 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16362 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16363 | |
c906108c SS |
16364 | add_com_alias ("b", "break", class_run, 1); |
16365 | add_com_alias ("br", "break", class_run, 1); | |
16366 | add_com_alias ("bre", "break", class_run, 1); | |
16367 | add_com_alias ("brea", "break", class_run, 1); | |
16368 | ||
c906108c SS |
16369 | if (dbx_commands) |
16370 | { | |
1bedd215 AC |
16371 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16372 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16373 | &stoplist, "stop ", 1, &cmdlist); |
16374 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16375 | _("Break in function or address."), &stoplist); |
c5aa993b | 16376 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16377 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16378 | add_com ("status", class_info, breakpoints_info, _("\ |
16379 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16380 | The \"Type\" column indicates one of:\n\ |
16381 | \tbreakpoint - normal breakpoint\n\ | |
16382 | \twatchpoint - watchpoint\n\ | |
16383 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16384 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16385 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16386 | address and file/line number respectively.\n\ |
16387 | \n\ | |
16388 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16389 | are set to the address of the last breakpoint listed unless the command\n\ |
16390 | is prefixed with \"server \".\n\n\ | |
c906108c | 16391 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16392 | breakpoint set.")); |
c906108c SS |
16393 | } |
16394 | ||
1bedd215 | 16395 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16396 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16397 | The \"Type\" column indicates one of:\n\ |
16398 | \tbreakpoint - normal breakpoint\n\ | |
16399 | \twatchpoint - watchpoint\n\ | |
16400 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16401 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16402 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16403 | address and file/line number respectively.\n\ |
16404 | \n\ | |
16405 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16406 | are set to the address of the last breakpoint listed unless the command\n\ |
16407 | is prefixed with \"server \".\n\n\ | |
c906108c | 16408 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16409 | breakpoint set.")); |
c906108c | 16410 | |
6b04bdb7 MS |
16411 | add_info_alias ("b", "breakpoints", 1); |
16412 | ||
1a966eab AC |
16413 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16414 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16415 | The \"Type\" column indicates one of:\n\ |
16416 | \tbreakpoint - normal breakpoint\n\ | |
16417 | \twatchpoint - watchpoint\n\ | |
16418 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16419 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16420 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16421 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16422 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16423 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16424 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16425 | address and file/line number respectively.\n\ |
16426 | \n\ | |
16427 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16428 | are set to the address of the last breakpoint listed unless the command\n\ |
16429 | is prefixed with \"server \".\n\n\ | |
c906108c | 16430 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16431 | breakpoint set."), |
c906108c SS |
16432 | &maintenanceinfolist); |
16433 | ||
44feb3ce TT |
16434 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16435 | Set catchpoints to catch events."), | |
16436 | &catch_cmdlist, "catch ", | |
16437 | 0/*allow-unknown*/, &cmdlist); | |
16438 | ||
16439 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16440 | Set temporary catchpoints to catch events."), | |
16441 | &tcatch_cmdlist, "tcatch ", | |
16442 | 0/*allow-unknown*/, &cmdlist); | |
16443 | ||
44feb3ce TT |
16444 | add_catch_command ("fork", _("Catch calls to fork."), |
16445 | catch_fork_command_1, | |
a96d9b2e | 16446 | NULL, |
44feb3ce TT |
16447 | (void *) (uintptr_t) catch_fork_permanent, |
16448 | (void *) (uintptr_t) catch_fork_temporary); | |
16449 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16450 | catch_fork_command_1, | |
a96d9b2e | 16451 | NULL, |
44feb3ce TT |
16452 | (void *) (uintptr_t) catch_vfork_permanent, |
16453 | (void *) (uintptr_t) catch_vfork_temporary); | |
16454 | add_catch_command ("exec", _("Catch calls to exec."), | |
16455 | catch_exec_command_1, | |
a96d9b2e SDJ |
16456 | NULL, |
16457 | CATCH_PERMANENT, | |
16458 | CATCH_TEMPORARY); | |
edcc5120 TT |
16459 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16460 | Usage: catch load [REGEX]\n\ | |
16461 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16462 | catch_load_command_1, | |
16463 | NULL, | |
16464 | CATCH_PERMANENT, | |
16465 | CATCH_TEMPORARY); | |
16466 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16467 | Usage: catch unload [REGEX]\n\ | |
16468 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16469 | catch_unload_command_1, | |
16470 | NULL, | |
16471 | CATCH_PERMANENT, | |
16472 | CATCH_TEMPORARY); | |
c5aa993b | 16473 | |
1bedd215 AC |
16474 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16475 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16476 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16477 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16478 | an expression changes.\n\ |
16479 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16480 | the memory to which it refers.")); | |
65d12d83 | 16481 | set_cmd_completer (c, expression_completer); |
c906108c | 16482 | |
1bedd215 AC |
16483 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16484 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16485 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16486 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16487 | an expression is read.\n\ |
16488 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16489 | the memory to which it refers.")); | |
65d12d83 | 16490 | set_cmd_completer (c, expression_completer); |
c906108c | 16491 | |
1bedd215 AC |
16492 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16493 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16494 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16495 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16496 | an expression is either read or written.\n\ |
16497 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16498 | the memory to which it refers.")); | |
65d12d83 | 16499 | set_cmd_completer (c, expression_completer); |
c906108c | 16500 | |
d77f58be | 16501 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16502 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16503 | |
920d2a44 AC |
16504 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16505 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16506 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16507 | &can_use_hw_watchpoints, _("\ | |
16508 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16509 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16510 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16511 | such is available. (However, any hardware watchpoints that were\n\ | |
16512 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16513 | hardware.)"), |
16514 | NULL, | |
920d2a44 | 16515 | show_can_use_hw_watchpoints, |
85c07804 | 16516 | &setlist, &showlist); |
c906108c SS |
16517 | |
16518 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16519 | |
1042e4c0 SS |
16520 | /* Tracepoint manipulation commands. */ |
16521 | ||
16522 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16523 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16524 | \n" |
16525 | BREAK_ARGS_HELP ("trace") "\n\ | |
16526 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16527 | set_cmd_completer (c, location_completer); | |
16528 | ||
16529 | add_com_alias ("tp", "trace", class_alias, 0); | |
16530 | add_com_alias ("tr", "trace", class_alias, 1); | |
16531 | add_com_alias ("tra", "trace", class_alias, 1); | |
16532 | add_com_alias ("trac", "trace", class_alias, 1); | |
16533 | ||
7a697b8d | 16534 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16535 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16536 | \n" |
16537 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16538 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16539 | set_cmd_completer (c, location_completer); | |
16540 | ||
0fb4aa4b | 16541 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16542 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16543 | \n\ |
16544 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16545 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16546 | or -m MARKER_ID.\n\n\ | |
16547 | If a marker id is specified, probe the marker with that name. With\n\ | |
16548 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16549 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16550 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16551 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16552 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16553 | \n\ | |
16554 | CONDITION is a boolean expression.\n\ | |
629500fa | 16555 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16556 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16557 | conditions are different.\n\ | |
0fb4aa4b PA |
16558 | \n\ |
16559 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16560 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16561 | set_cmd_completer (c, location_completer); | |
16562 | ||
1042e4c0 | 16563 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16564 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16565 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16566 | last tracepoint set.")); | |
16567 | ||
16568 | add_info_alias ("tp", "tracepoints", 1); | |
16569 | ||
16570 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16571 | Delete specified tracepoints.\n\ | |
16572 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16573 | No argument means delete all tracepoints."), | |
16574 | &deletelist); | |
7e20dfcd | 16575 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16576 | |
16577 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16578 | Disable specified tracepoints.\n\ | |
16579 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16580 | No argument means disable all tracepoints."), | |
16581 | &disablelist); | |
16582 | deprecate_cmd (c, "disable"); | |
16583 | ||
16584 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16585 | Enable specified tracepoints.\n\ | |
16586 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16587 | No argument means enable all tracepoints."), | |
16588 | &enablelist); | |
16589 | deprecate_cmd (c, "enable"); | |
16590 | ||
16591 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16592 | Set the passcount for a tracepoint.\n\ | |
16593 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16594 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16595 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16596 | ||
6149aea9 PA |
16597 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16598 | _("Save breakpoint definitions as a script."), | |
16599 | &save_cmdlist, "save ", | |
16600 | 0/*allow-unknown*/, &cmdlist); | |
16601 | ||
16602 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16603 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16604 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16605 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16606 | session to restore them."), | |
16607 | &save_cmdlist); | |
16608 | set_cmd_completer (c, filename_completer); | |
16609 | ||
16610 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16611 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16612 | Use the 'source' command in another debug session to restore them."), |
16613 | &save_cmdlist); | |
1042e4c0 SS |
16614 | set_cmd_completer (c, filename_completer); |
16615 | ||
6149aea9 PA |
16616 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16617 | deprecate_cmd (c, "save tracepoints"); | |
16618 | ||
1bedd215 | 16619 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16620 | Breakpoint specific settings\n\ |
16621 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16622 | pending breakpoint behavior"), |
fa8d40ab JJ |
16623 | &breakpoint_set_cmdlist, "set breakpoint ", |
16624 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16625 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16626 | Breakpoint specific settings\n\ |
16627 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16628 | pending breakpoint behavior"), |
fa8d40ab JJ |
16629 | &breakpoint_show_cmdlist, "show breakpoint ", |
16630 | 0/*allow-unknown*/, &showlist); | |
16631 | ||
7915a72c AC |
16632 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16633 | &pending_break_support, _("\ | |
16634 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16635 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16636 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16637 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16638 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16639 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16640 | NULL, |
920d2a44 | 16641 | show_pending_break_support, |
6e1d7d6c AC |
16642 | &breakpoint_set_cmdlist, |
16643 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16644 | |
16645 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16646 | |
16647 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16648 | &automatic_hardware_breakpoints, _("\ | |
16649 | Set automatic usage of hardware breakpoints."), _("\ | |
16650 | Show automatic usage of hardware breakpoints."), _("\ | |
16651 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16652 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16653 | a warning will be emitted for such breakpoints."), | |
16654 | NULL, | |
16655 | show_automatic_hardware_breakpoints, | |
16656 | &breakpoint_set_cmdlist, | |
16657 | &breakpoint_show_cmdlist); | |
74960c60 | 16658 | |
a25a5a45 PA |
16659 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16660 | &always_inserted_mode, _("\ | |
74960c60 VP |
16661 | Set mode for inserting breakpoints."), _("\ |
16662 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16663 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16664 | they're created, kept inserted even when execution stops, and removed\n\ | |
16665 | only when the user deletes them. When this mode is off (the default),\n\ | |
16666 | breakpoints are inserted only when execution continues, and removed\n\ | |
16667 | when execution stops."), | |
72d0e2c5 YQ |
16668 | NULL, |
16669 | &show_always_inserted_mode, | |
16670 | &breakpoint_set_cmdlist, | |
16671 | &breakpoint_show_cmdlist); | |
f1310107 | 16672 | |
b775012e LM |
16673 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16674 | condition_evaluation_enums, | |
16675 | &condition_evaluation_mode_1, _("\ | |
16676 | Set mode of breakpoint condition evaluation."), _("\ | |
16677 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16678 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16679 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16680 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16681 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16682 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16683 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16684 | be set to \"gdb\""), | |
16685 | &set_condition_evaluation_mode, | |
16686 | &show_condition_evaluation_mode, | |
16687 | &breakpoint_set_cmdlist, | |
16688 | &breakpoint_show_cmdlist); | |
16689 | ||
f1310107 TJB |
16690 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16691 | Set a breakpoint for an address range.\n\ | |
16692 | break-range START-LOCATION, END-LOCATION\n\ | |
16693 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16694 | LINENUM, for that line in the current file,\n\ | |
16695 | FILE:LINENUM, for that line in that file,\n\ | |
16696 | +OFFSET, for that number of lines after the current line\n\ | |
16697 | or the start of the range\n\ | |
16698 | FUNCTION, for the first line in that function,\n\ | |
16699 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16700 | *ADDRESS, for the instruction at that address.\n\ | |
16701 | \n\ | |
16702 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16703 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16704 | range (including START-LOCATION and END-LOCATION).")); | |
16705 | ||
e7e0cddf | 16706 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16707 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16708 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16709 | location may be a linespec, explicit, or address location.\n" |
16710 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16711 | set_cmd_completer (c, location_completer); |
16712 | ||
16713 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16714 | dprintf_style_enums, &dprintf_style, _("\ | |
16715 | Set the style of usage for dynamic printf."), _("\ | |
16716 | Show the style of usage for dynamic printf."), _("\ | |
16717 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16718 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16719 | console, as with the \"printf\" command.\n\ | |
16720 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16721 | program; by default printf(), but you can choose a different function or\n\ | |
16722 | output stream by setting dprintf-function and dprintf-channel."), | |
16723 | update_dprintf_commands, NULL, | |
16724 | &setlist, &showlist); | |
16725 | ||
16726 | dprintf_function = xstrdup ("printf"); | |
16727 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16728 | &dprintf_function, _("\ | |
16729 | Set the function to use for dynamic printf"), _("\ | |
16730 | Show the function to use for dynamic printf"), NULL, | |
16731 | update_dprintf_commands, NULL, | |
16732 | &setlist, &showlist); | |
16733 | ||
16734 | dprintf_channel = xstrdup (""); | |
16735 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16736 | &dprintf_channel, _("\ | |
16737 | Set the channel to use for dynamic printf"), _("\ | |
16738 | Show the channel to use for dynamic printf"), NULL, | |
16739 | update_dprintf_commands, NULL, | |
16740 | &setlist, &showlist); | |
16741 | ||
d3ce09f5 SS |
16742 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16743 | &disconnected_dprintf, _("\ | |
16744 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16745 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16746 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16747 | even if GDB disconnects or detaches from the target."), | |
16748 | NULL, | |
16749 | NULL, | |
16750 | &setlist, &showlist); | |
16751 | ||
16752 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16753 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16754 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16755 | ||
765dc015 | 16756 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16757 | |
16758 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16759 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16760 | } |