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 | |
896b6bda PA |
105 | static void map_breakpoint_numbers (const char *, |
106 | void (*) (struct breakpoint *, | |
107 | void *), | |
95a42b64 | 108 | void *); |
c906108c | 109 | |
a14ed312 | 110 | static void ignore_command (char *, int); |
c906108c | 111 | |
4efb68b1 | 112 | static int breakpoint_re_set_one (void *); |
c906108c | 113 | |
348d480f PA |
114 | static void breakpoint_re_set_default (struct breakpoint *); |
115 | ||
f00aae0f KS |
116 | static void |
117 | create_sals_from_location_default (const struct event_location *location, | |
118 | struct linespec_result *canonical, | |
119 | enum bptype type_wanted); | |
983af33b SDJ |
120 | |
121 | static void create_breakpoints_sal_default (struct gdbarch *, | |
122 | struct linespec_result *, | |
e7e0cddf | 123 | char *, char *, enum bptype, |
983af33b SDJ |
124 | enum bpdisp, int, int, |
125 | int, | |
126 | const struct breakpoint_ops *, | |
44f238bb | 127 | int, int, int, unsigned); |
983af33b | 128 | |
f00aae0f KS |
129 | static void decode_location_default (struct breakpoint *b, |
130 | const struct event_location *location, | |
c2f4122d | 131 | struct program_space *search_pspace, |
f00aae0f | 132 | struct symtabs_and_lines *sals); |
983af33b | 133 | |
a14ed312 | 134 | static void clear_command (char *, int); |
c906108c | 135 | |
a14ed312 | 136 | static void catch_command (char *, int); |
c906108c | 137 | |
a9634178 | 138 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 139 | |
98deb0da | 140 | static void break_command_1 (char *, int, int); |
c906108c | 141 | |
a14ed312 | 142 | static void mention (struct breakpoint *); |
c906108c | 143 | |
348d480f PA |
144 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
145 | enum bptype, | |
c0a91b2b | 146 | const struct breakpoint_ops *); |
3742cc8b YQ |
147 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
148 | const struct symtab_and_line *); | |
149 | ||
4a64f543 MS |
150 | /* This function is used in gdbtk sources and thus can not be made |
151 | static. */ | |
63c252f8 | 152 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 153 | struct symtab_and_line, |
c0a91b2b TT |
154 | enum bptype, |
155 | const struct breakpoint_ops *); | |
c906108c | 156 | |
06edf0c0 PA |
157 | static struct breakpoint * |
158 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
159 | enum bptype type, | |
a1aa2221 LM |
160 | const struct breakpoint_ops *ops, |
161 | int loc_enabled); | |
06edf0c0 | 162 | |
76897487 KB |
163 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
164 | ||
a6d9a66e UW |
165 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
166 | CORE_ADDR bpaddr, | |
88f7da05 | 167 | enum bptype bptype); |
76897487 | 168 | |
6c95b8df PA |
169 | static void describe_other_breakpoints (struct gdbarch *, |
170 | struct program_space *, CORE_ADDR, | |
5af949e3 | 171 | struct obj_section *, int); |
c906108c | 172 | |
85d721b8 PA |
173 | static int watchpoint_locations_match (struct bp_location *loc1, |
174 | struct bp_location *loc2); | |
175 | ||
f1310107 TJB |
176 | static int breakpoint_location_address_match (struct bp_location *bl, |
177 | struct address_space *aspace, | |
178 | CORE_ADDR addr); | |
179 | ||
d35ae833 PA |
180 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
181 | struct address_space *, | |
182 | CORE_ADDR, int); | |
183 | ||
a14ed312 | 184 | static void breakpoints_info (char *, int); |
c906108c | 185 | |
d77f58be SS |
186 | static void watchpoints_info (char *, int); |
187 | ||
e5a67952 MS |
188 | static int breakpoint_1 (char *, int, |
189 | int (*) (const struct breakpoint *)); | |
c906108c | 190 | |
4efb68b1 | 191 | static int breakpoint_cond_eval (void *); |
c906108c | 192 | |
4efb68b1 | 193 | static void cleanup_executing_breakpoints (void *); |
c906108c | 194 | |
a14ed312 | 195 | static void commands_command (char *, int); |
c906108c | 196 | |
a14ed312 | 197 | static void condition_command (char *, int); |
c906108c | 198 | |
834c0d03 | 199 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 200 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 201 | |
e514a9d6 | 202 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 203 | |
4efb68b1 | 204 | static int watchpoint_check (void *); |
c906108c | 205 | |
a14ed312 | 206 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 207 | |
a14ed312 | 208 | static int hw_breakpoint_used_count (void); |
c906108c | 209 | |
a1398e0c PA |
210 | static int hw_watchpoint_use_count (struct breakpoint *); |
211 | ||
212 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
213 | enum bptype type, | |
214 | int *other_type_used); | |
c906108c | 215 | |
a14ed312 | 216 | static void hbreak_command (char *, int); |
c906108c | 217 | |
a14ed312 | 218 | static void thbreak_command (char *, int); |
c906108c | 219 | |
816338b5 SS |
220 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
221 | int count); | |
c906108c | 222 | |
a14ed312 | 223 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 224 | |
a14ed312 | 225 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 226 | |
a14ed312 | 227 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 228 | |
a14ed312 | 229 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 230 | |
fe3f5fa8 | 231 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
232 | static void incref_bp_location (struct bp_location *loc); |
233 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 234 | |
39d61571 | 235 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 236 | |
44702360 PA |
237 | /* update_global_location_list's modes of operation wrt to whether to |
238 | insert locations now. */ | |
239 | enum ugll_insert_mode | |
240 | { | |
241 | /* Don't insert any breakpoint locations into the inferior, only | |
242 | remove already-inserted locations that no longer should be | |
243 | inserted. Functions that delete a breakpoint or breakpoints | |
244 | should specify this mode, so that deleting a breakpoint doesn't | |
245 | have the side effect of inserting the locations of other | |
246 | breakpoints that are marked not-inserted, but should_be_inserted | |
247 | returns true on them. | |
248 | ||
249 | This behavior is useful is situations close to tear-down -- e.g., | |
250 | after an exec, while the target still has execution, but | |
251 | breakpoint shadows of the previous executable image should *NOT* | |
252 | be restored to the new image; or before detaching, where the | |
253 | target still has execution and wants to delete breakpoints from | |
254 | GDB's lists, and all breakpoints had already been removed from | |
255 | the inferior. */ | |
256 | UGLL_DONT_INSERT, | |
257 | ||
a25a5a45 PA |
258 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
259 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
260 | UGLL_MAY_INSERT, |
261 | ||
a25a5a45 PA |
262 | /* Insert locations now, irrespective of |
263 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
264 | stopped right now, and the user did "continue". We need to | |
265 | insert breakpoints _before_ resuming the target, but | |
266 | UGLL_MAY_INSERT wouldn't insert them, because | |
267 | breakpoints_should_be_inserted_now returns false at that point, | |
268 | as no thread is running yet. */ | |
04086b45 | 269 | UGLL_INSERT |
44702360 PA |
270 | }; |
271 | ||
272 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 273 | |
44702360 | 274 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 275 | |
d77f58be | 276 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
277 | |
278 | static void insert_breakpoint_locations (void); | |
a5606eee | 279 | |
1042e4c0 SS |
280 | static void tracepoints_info (char *, int); |
281 | ||
282 | static void delete_trace_command (char *, int); | |
283 | ||
284 | static void enable_trace_command (char *, int); | |
285 | ||
286 | static void disable_trace_command (char *, int); | |
287 | ||
288 | static void trace_pass_command (char *, int); | |
289 | ||
558a9d82 YQ |
290 | static void set_tracepoint_count (int num); |
291 | ||
9c06b0b4 TJB |
292 | static int is_masked_watchpoint (const struct breakpoint *b); |
293 | ||
b775012e LM |
294 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
295 | ||
983af33b SDJ |
296 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
297 | otherwise. */ | |
298 | ||
299 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 300 | |
2060206e PA |
301 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
302 | that are implemented on top of software or hardware breakpoints | |
303 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
304 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
305 | ||
306 | /* Internal breakpoints class type. */ | |
06edf0c0 | 307 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
308 | |
309 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
310 | static struct breakpoint_ops momentary_breakpoint_ops; |
311 | ||
e2e4d78b JK |
312 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
313 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
314 | ||
2060206e PA |
315 | /* The breakpoint_ops structure to be used in regular user created |
316 | breakpoints. */ | |
317 | struct breakpoint_ops bkpt_breakpoint_ops; | |
318 | ||
55aa24fb SDJ |
319 | /* Breakpoints set on probes. */ |
320 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
321 | ||
e7e0cddf | 322 | /* Dynamic printf class type. */ |
c5867ab6 | 323 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 324 | |
d3ce09f5 SS |
325 | /* The style in which to perform a dynamic printf. This is a user |
326 | option because different output options have different tradeoffs; | |
327 | if GDB does the printing, there is better error handling if there | |
328 | is a problem with any of the arguments, but using an inferior | |
329 | function lets you have special-purpose printers and sending of | |
330 | output to the same place as compiled-in print functions. */ | |
331 | ||
332 | static const char dprintf_style_gdb[] = "gdb"; | |
333 | static const char dprintf_style_call[] = "call"; | |
334 | static const char dprintf_style_agent[] = "agent"; | |
335 | static const char *const dprintf_style_enums[] = { | |
336 | dprintf_style_gdb, | |
337 | dprintf_style_call, | |
338 | dprintf_style_agent, | |
339 | NULL | |
340 | }; | |
341 | static const char *dprintf_style = dprintf_style_gdb; | |
342 | ||
343 | /* The function to use for dynamic printf if the preferred style is to | |
344 | call into the inferior. The value is simply a string that is | |
345 | copied into the command, so it can be anything that GDB can | |
346 | evaluate to a callable address, not necessarily a function name. */ | |
347 | ||
348 | static char *dprintf_function = ""; | |
349 | ||
350 | /* The channel to use for dynamic printf if the preferred style is to | |
351 | call into the inferior; if a nonempty string, it will be passed to | |
352 | the call as the first argument, with the format string as the | |
353 | second. As with the dprintf function, this can be anything that | |
354 | GDB knows how to evaluate, so in addition to common choices like | |
355 | "stderr", this could be an app-specific expression like | |
356 | "mystreams[curlogger]". */ | |
357 | ||
358 | static char *dprintf_channel = ""; | |
359 | ||
360 | /* True if dprintf commands should continue to operate even if GDB | |
361 | has disconnected. */ | |
362 | static int disconnected_dprintf = 1; | |
363 | ||
5cea2a26 PA |
364 | /* A reference-counted struct command_line. This lets multiple |
365 | breakpoints share a single command list. */ | |
366 | struct counted_command_line | |
367 | { | |
368 | /* The reference count. */ | |
369 | int refc; | |
370 | ||
371 | /* The command list. */ | |
372 | struct command_line *commands; | |
373 | }; | |
374 | ||
375 | struct command_line * | |
376 | breakpoint_commands (struct breakpoint *b) | |
377 | { | |
378 | return b->commands ? b->commands->commands : NULL; | |
379 | } | |
3daf8fe5 | 380 | |
f3b1572e PA |
381 | /* Flag indicating that a command has proceeded the inferior past the |
382 | current breakpoint. */ | |
383 | ||
384 | static int breakpoint_proceeded; | |
385 | ||
956a9fb9 | 386 | const char * |
2cec12e5 AR |
387 | bpdisp_text (enum bpdisp disp) |
388 | { | |
4a64f543 MS |
389 | /* NOTE: the following values are a part of MI protocol and |
390 | represent values of 'disp' field returned when inferior stops at | |
391 | a breakpoint. */ | |
bc043ef3 | 392 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 393 | |
2cec12e5 AR |
394 | return bpdisps[(int) disp]; |
395 | } | |
c906108c | 396 | |
4a64f543 | 397 | /* Prototypes for exported functions. */ |
c906108c | 398 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 399 | if such is available. */ |
c906108c SS |
400 | static int can_use_hw_watchpoints; |
401 | ||
920d2a44 AC |
402 | static void |
403 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
404 | struct cmd_list_element *c, | |
405 | const char *value) | |
406 | { | |
3e43a32a MS |
407 | fprintf_filtered (file, |
408 | _("Debugger's willingness to use " | |
409 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
410 | value); |
411 | } | |
412 | ||
fa8d40ab JJ |
413 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
414 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 415 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
416 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
417 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
418 | static void |
419 | show_pending_break_support (struct ui_file *file, int from_tty, | |
420 | struct cmd_list_element *c, | |
421 | const char *value) | |
422 | { | |
3e43a32a MS |
423 | fprintf_filtered (file, |
424 | _("Debugger's behavior regarding " | |
425 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
426 | value); |
427 | } | |
fa8d40ab | 428 | |
765dc015 | 429 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 430 | set with "break" but falling in read-only memory. |
765dc015 VP |
431 | If 0, gdb will warn about such breakpoints, but won't automatically |
432 | use hardware breakpoints. */ | |
433 | static int automatic_hardware_breakpoints; | |
434 | static void | |
435 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
436 | struct cmd_list_element *c, | |
437 | const char *value) | |
438 | { | |
3e43a32a MS |
439 | fprintf_filtered (file, |
440 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
441 | value); |
442 | } | |
443 | ||
a25a5a45 PA |
444 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
445 | stopped, and immediately inserts any new breakpoints as soon as | |
446 | they're created. If off (default), GDB keeps breakpoints off of | |
447 | the target as long as possible. That is, it delays inserting | |
448 | breakpoints until the next resume, and removes them again when the | |
449 | target fully stops. This is a bit safer in case GDB crashes while | |
450 | processing user input. */ | |
451 | static int always_inserted_mode = 0; | |
72d0e2c5 | 452 | |
33e5cbd6 | 453 | static void |
74960c60 | 454 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 455 | struct cmd_list_element *c, const char *value) |
74960c60 | 456 | { |
a25a5a45 PA |
457 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
458 | value); | |
74960c60 VP |
459 | } |
460 | ||
b57bacec PA |
461 | /* See breakpoint.h. */ |
462 | ||
33e5cbd6 | 463 | int |
a25a5a45 | 464 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 465 | { |
a25a5a45 PA |
466 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
467 | { | |
468 | /* If breakpoints are global, they should be inserted even if no | |
469 | thread under gdb's control is running, or even if there are | |
470 | no threads under GDB's control yet. */ | |
471 | return 1; | |
472 | } | |
473 | else if (target_has_execution) | |
474 | { | |
372316f1 PA |
475 | struct thread_info *tp; |
476 | ||
a25a5a45 PA |
477 | if (always_inserted_mode) |
478 | { | |
479 | /* The user wants breakpoints inserted even if all threads | |
480 | are stopped. */ | |
481 | return 1; | |
482 | } | |
483 | ||
b57bacec PA |
484 | if (threads_are_executing ()) |
485 | return 1; | |
372316f1 PA |
486 | |
487 | /* Don't remove breakpoints yet if, even though all threads are | |
488 | stopped, we still have events to process. */ | |
489 | ALL_NON_EXITED_THREADS (tp) | |
490 | if (tp->resumed | |
491 | && tp->suspend.waitstatus_pending_p) | |
492 | return 1; | |
a25a5a45 PA |
493 | } |
494 | return 0; | |
33e5cbd6 | 495 | } |
765dc015 | 496 | |
b775012e LM |
497 | static const char condition_evaluation_both[] = "host or target"; |
498 | ||
499 | /* Modes for breakpoint condition evaluation. */ | |
500 | static const char condition_evaluation_auto[] = "auto"; | |
501 | static const char condition_evaluation_host[] = "host"; | |
502 | static const char condition_evaluation_target[] = "target"; | |
503 | static const char *const condition_evaluation_enums[] = { | |
504 | condition_evaluation_auto, | |
505 | condition_evaluation_host, | |
506 | condition_evaluation_target, | |
507 | NULL | |
508 | }; | |
509 | ||
510 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
511 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
512 | ||
513 | /* Global that we use to display information to the user (gets its value from | |
514 | condition_evaluation_mode_1. */ | |
515 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
516 | ||
517 | /* Translate a condition evaluation mode MODE into either "host" | |
518 | or "target". This is used mostly to translate from "auto" to the | |
519 | real setting that is being used. It returns the translated | |
520 | evaluation mode. */ | |
521 | ||
522 | static const char * | |
523 | translate_condition_evaluation_mode (const char *mode) | |
524 | { | |
525 | if (mode == condition_evaluation_auto) | |
526 | { | |
527 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
528 | return condition_evaluation_target; | |
529 | else | |
530 | return condition_evaluation_host; | |
531 | } | |
532 | else | |
533 | return mode; | |
534 | } | |
535 | ||
536 | /* Discovers what condition_evaluation_auto translates to. */ | |
537 | ||
538 | static const char * | |
539 | breakpoint_condition_evaluation_mode (void) | |
540 | { | |
541 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
542 | } | |
543 | ||
544 | /* Return true if GDB should evaluate breakpoint conditions or false | |
545 | otherwise. */ | |
546 | ||
547 | static int | |
548 | gdb_evaluates_breakpoint_condition_p (void) | |
549 | { | |
550 | const char *mode = breakpoint_condition_evaluation_mode (); | |
551 | ||
552 | return (mode == condition_evaluation_host); | |
553 | } | |
554 | ||
a14ed312 | 555 | void _initialize_breakpoint (void); |
c906108c | 556 | |
c906108c SS |
557 | /* Are we executing breakpoint commands? */ |
558 | static int executing_breakpoint_commands; | |
559 | ||
c02f5703 MS |
560 | /* Are overlay event breakpoints enabled? */ |
561 | static int overlay_events_enabled; | |
562 | ||
e09342b5 TJB |
563 | /* See description in breakpoint.h. */ |
564 | int target_exact_watchpoints = 0; | |
565 | ||
c906108c | 566 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 567 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 568 | current breakpoint. */ |
c906108c | 569 | |
5c44784c | 570 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 571 | |
5c44784c JM |
572 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
573 | for (B = breakpoint_chain; \ | |
574 | B ? (TMP=B->next, 1): 0; \ | |
575 | B = TMP) | |
c906108c | 576 | |
4a64f543 MS |
577 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
578 | not provided so update_global_location_list must not be called | |
579 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 580 | |
876fa593 JK |
581 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
582 | for (BP_TMP = bp_location; \ | |
583 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
584 | BP_TMP++) | |
7cc221ef | 585 | |
b775012e LM |
586 | /* Iterates through locations with address ADDRESS for the currently selected |
587 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
588 | to where the loop should start from. | |
589 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
590 | appropriate location to start with. */ | |
591 | ||
592 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
593 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
594 | BP_LOCP_TMP = BP_LOCP_START; \ | |
595 | BP_LOCP_START \ | |
596 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
597 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
598 | BP_LOCP_TMP++) | |
599 | ||
1042e4c0 SS |
600 | /* Iterator for tracepoints only. */ |
601 | ||
602 | #define ALL_TRACEPOINTS(B) \ | |
603 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 604 | if (is_tracepoint (B)) |
1042e4c0 | 605 | |
7cc221ef | 606 | /* Chains of all breakpoints defined. */ |
c906108c SS |
607 | |
608 | struct breakpoint *breakpoint_chain; | |
609 | ||
876fa593 JK |
610 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
611 | ||
612 | static struct bp_location **bp_location; | |
613 | ||
614 | /* Number of elements of BP_LOCATION. */ | |
615 | ||
616 | static unsigned bp_location_count; | |
617 | ||
4a64f543 MS |
618 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
619 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
620 | result from bp_location_has_shadow. You can use it for roughly | |
621 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
622 | an address you need to read. */ | |
876fa593 JK |
623 | |
624 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
625 | ||
4a64f543 MS |
626 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
627 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
628 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
629 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
630 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
631 | |
632 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 633 | |
4a64f543 MS |
634 | /* The locations that no longer correspond to any breakpoint, unlinked |
635 | from bp_location array, but for which a hit may still be reported | |
636 | by a target. */ | |
20874c92 VP |
637 | VEC(bp_location_p) *moribund_locations = NULL; |
638 | ||
c906108c SS |
639 | /* Number of last breakpoint made. */ |
640 | ||
95a42b64 TT |
641 | static int breakpoint_count; |
642 | ||
86b17b60 PA |
643 | /* The value of `breakpoint_count' before the last command that |
644 | created breakpoints. If the last (break-like) command created more | |
645 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
646 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
647 | static int prev_breakpoint_count; | |
c906108c | 648 | |
1042e4c0 SS |
649 | /* Number of last tracepoint made. */ |
650 | ||
95a42b64 | 651 | static int tracepoint_count; |
1042e4c0 | 652 | |
6149aea9 PA |
653 | static struct cmd_list_element *breakpoint_set_cmdlist; |
654 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 655 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 656 | |
badd37ce SDJ |
657 | /* See declaration at breakpoint.h. */ |
658 | ||
659 | struct breakpoint * | |
660 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
661 | void *user_data) | |
662 | { | |
663 | struct breakpoint *b = NULL; | |
664 | ||
665 | ALL_BREAKPOINTS (b) | |
666 | { | |
667 | if (func (b, user_data) != 0) | |
668 | break; | |
669 | } | |
670 | ||
671 | return b; | |
672 | } | |
673 | ||
468d015d JJ |
674 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
675 | static int | |
676 | breakpoint_enabled (struct breakpoint *b) | |
677 | { | |
0d381245 | 678 | return (b->enable_state == bp_enabled); |
468d015d JJ |
679 | } |
680 | ||
c906108c SS |
681 | /* Set breakpoint count to NUM. */ |
682 | ||
95a42b64 | 683 | static void |
fba45db2 | 684 | set_breakpoint_count (int num) |
c906108c | 685 | { |
86b17b60 | 686 | prev_breakpoint_count = breakpoint_count; |
c906108c | 687 | breakpoint_count = num; |
4fa62494 | 688 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
689 | } |
690 | ||
86b17b60 PA |
691 | /* Used by `start_rbreak_breakpoints' below, to record the current |
692 | breakpoint count before "rbreak" creates any breakpoint. */ | |
693 | static int rbreak_start_breakpoint_count; | |
694 | ||
95a42b64 TT |
695 | /* Called at the start an "rbreak" command to record the first |
696 | breakpoint made. */ | |
86b17b60 | 697 | |
95a42b64 TT |
698 | void |
699 | start_rbreak_breakpoints (void) | |
700 | { | |
86b17b60 | 701 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
702 | } |
703 | ||
704 | /* Called at the end of an "rbreak" command to record the last | |
705 | breakpoint made. */ | |
86b17b60 | 706 | |
95a42b64 TT |
707 | void |
708 | end_rbreak_breakpoints (void) | |
709 | { | |
86b17b60 | 710 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
711 | } |
712 | ||
4a64f543 | 713 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
714 | |
715 | void | |
fba45db2 | 716 | clear_breakpoint_hit_counts (void) |
c906108c SS |
717 | { |
718 | struct breakpoint *b; | |
719 | ||
720 | ALL_BREAKPOINTS (b) | |
721 | b->hit_count = 0; | |
722 | } | |
723 | ||
9add0f1b TT |
724 | /* Allocate a new counted_command_line with reference count of 1. |
725 | The new structure owns COMMANDS. */ | |
726 | ||
727 | static struct counted_command_line * | |
728 | alloc_counted_command_line (struct command_line *commands) | |
729 | { | |
8d749320 | 730 | struct counted_command_line *result = XNEW (struct counted_command_line); |
cc59ec59 | 731 | |
9add0f1b TT |
732 | result->refc = 1; |
733 | result->commands = commands; | |
8d749320 | 734 | |
9add0f1b TT |
735 | return result; |
736 | } | |
737 | ||
738 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
739 | ||
740 | static void | |
741 | incref_counted_command_line (struct counted_command_line *cmd) | |
742 | { | |
743 | if (cmd) | |
744 | ++cmd->refc; | |
745 | } | |
746 | ||
747 | /* Decrement reference count. If the reference count reaches 0, | |
748 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
749 | nothing if *CMDP is NULL. */ | |
750 | ||
751 | static void | |
752 | decref_counted_command_line (struct counted_command_line **cmdp) | |
753 | { | |
754 | if (*cmdp) | |
755 | { | |
756 | if (--(*cmdp)->refc == 0) | |
757 | { | |
758 | free_command_lines (&(*cmdp)->commands); | |
759 | xfree (*cmdp); | |
760 | } | |
761 | *cmdp = NULL; | |
762 | } | |
763 | } | |
764 | ||
765 | /* A cleanup function that calls decref_counted_command_line. */ | |
766 | ||
767 | static void | |
768 | do_cleanup_counted_command_line (void *arg) | |
769 | { | |
9a3c8263 | 770 | decref_counted_command_line ((struct counted_command_line **) arg); |
9add0f1b TT |
771 | } |
772 | ||
773 | /* Create a cleanup that calls decref_counted_command_line on the | |
774 | argument. */ | |
775 | ||
776 | static struct cleanup * | |
777 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
778 | { | |
779 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
780 | } | |
781 | ||
c906108c | 782 | \f |
48cb2d85 VP |
783 | /* Return the breakpoint with the specified number, or NULL |
784 | if the number does not refer to an existing breakpoint. */ | |
785 | ||
786 | struct breakpoint * | |
787 | get_breakpoint (int num) | |
788 | { | |
789 | struct breakpoint *b; | |
790 | ||
791 | ALL_BREAKPOINTS (b) | |
792 | if (b->number == num) | |
793 | return b; | |
794 | ||
795 | return NULL; | |
796 | } | |
5c44784c | 797 | |
c906108c | 798 | \f |
adc36818 | 799 | |
b775012e LM |
800 | /* Mark locations as "conditions have changed" in case the target supports |
801 | evaluating conditions on its side. */ | |
802 | ||
803 | static void | |
804 | mark_breakpoint_modified (struct breakpoint *b) | |
805 | { | |
806 | struct bp_location *loc; | |
807 | ||
808 | /* This is only meaningful if the target is | |
809 | evaluating conditions and if the user has | |
810 | opted for condition evaluation on the target's | |
811 | side. */ | |
812 | if (gdb_evaluates_breakpoint_condition_p () | |
813 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
814 | return; | |
815 | ||
816 | if (!is_breakpoint (b)) | |
817 | return; | |
818 | ||
819 | for (loc = b->loc; loc; loc = loc->next) | |
820 | loc->condition_changed = condition_modified; | |
821 | } | |
822 | ||
823 | /* Mark location as "conditions have changed" in case the target supports | |
824 | evaluating conditions on its side. */ | |
825 | ||
826 | static void | |
827 | mark_breakpoint_location_modified (struct bp_location *loc) | |
828 | { | |
829 | /* This is only meaningful if the target is | |
830 | evaluating conditions and if the user has | |
831 | opted for condition evaluation on the target's | |
832 | side. */ | |
833 | if (gdb_evaluates_breakpoint_condition_p () | |
834 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
835 | ||
836 | return; | |
837 | ||
838 | if (!is_breakpoint (loc->owner)) | |
839 | return; | |
840 | ||
841 | loc->condition_changed = condition_modified; | |
842 | } | |
843 | ||
844 | /* Sets the condition-evaluation mode using the static global | |
845 | condition_evaluation_mode. */ | |
846 | ||
847 | static void | |
848 | set_condition_evaluation_mode (char *args, int from_tty, | |
849 | struct cmd_list_element *c) | |
850 | { | |
b775012e LM |
851 | const char *old_mode, *new_mode; |
852 | ||
853 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
854 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
855 | { | |
856 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
857 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
858 | "Using host evaluation mode instead.")); | |
859 | return; | |
860 | } | |
861 | ||
862 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
863 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
864 | ||
abf1152a JK |
865 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
866 | settings was "auto". */ | |
867 | condition_evaluation_mode = condition_evaluation_mode_1; | |
868 | ||
b775012e LM |
869 | /* Only update the mode if the user picked a different one. */ |
870 | if (new_mode != old_mode) | |
871 | { | |
872 | struct bp_location *loc, **loc_tmp; | |
873 | /* If the user switched to a different evaluation mode, we | |
874 | need to synch the changes with the target as follows: | |
875 | ||
876 | "host" -> "target": Send all (valid) conditions to the target. | |
877 | "target" -> "host": Remove all the conditions from the target. | |
878 | */ | |
879 | ||
b775012e LM |
880 | if (new_mode == condition_evaluation_target) |
881 | { | |
882 | /* Mark everything modified and synch conditions with the | |
883 | target. */ | |
884 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
885 | mark_breakpoint_location_modified (loc); | |
886 | } | |
887 | else | |
888 | { | |
889 | /* Manually mark non-duplicate locations to synch conditions | |
890 | with the target. We do this to remove all the conditions the | |
891 | target knows about. */ | |
892 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
893 | if (is_breakpoint (loc->owner) && loc->inserted) | |
894 | loc->needs_update = 1; | |
895 | } | |
896 | ||
897 | /* Do the update. */ | |
44702360 | 898 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
899 | } |
900 | ||
901 | return; | |
902 | } | |
903 | ||
904 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
905 | what "auto" is translating to. */ | |
906 | ||
907 | static void | |
908 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
909 | struct cmd_list_element *c, const char *value) | |
910 | { | |
911 | if (condition_evaluation_mode == condition_evaluation_auto) | |
912 | fprintf_filtered (file, | |
913 | _("Breakpoint condition evaluation " | |
914 | "mode is %s (currently %s).\n"), | |
915 | value, | |
916 | breakpoint_condition_evaluation_mode ()); | |
917 | else | |
918 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
919 | value); | |
920 | } | |
921 | ||
922 | /* A comparison function for bp_location AP and BP that is used by | |
923 | bsearch. This comparison function only cares about addresses, unlike | |
924 | the more general bp_location_compare function. */ | |
925 | ||
926 | static int | |
927 | bp_location_compare_addrs (const void *ap, const void *bp) | |
928 | { | |
9a3c8263 SM |
929 | const struct bp_location *a = *(const struct bp_location **) ap; |
930 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
931 | |
932 | if (a->address == b->address) | |
933 | return 0; | |
934 | else | |
935 | return ((a->address > b->address) - (a->address < b->address)); | |
936 | } | |
937 | ||
938 | /* Helper function to skip all bp_locations with addresses | |
939 | less than ADDRESS. It returns the first bp_location that | |
940 | is greater than or equal to ADDRESS. If none is found, just | |
941 | return NULL. */ | |
942 | ||
943 | static struct bp_location ** | |
944 | get_first_locp_gte_addr (CORE_ADDR address) | |
945 | { | |
946 | struct bp_location dummy_loc; | |
947 | struct bp_location *dummy_locp = &dummy_loc; | |
948 | struct bp_location **locp_found = NULL; | |
949 | ||
950 | /* Initialize the dummy location's address field. */ | |
951 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
952 | dummy_loc.address = address; | |
953 | ||
954 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 SM |
955 | locp_found = ((struct bp_location **) |
956 | bsearch (&dummy_locp, bp_location, bp_location_count, | |
957 | sizeof (struct bp_location **), | |
958 | bp_location_compare_addrs)); | |
b775012e LM |
959 | |
960 | /* Nothing was found, nothing left to do. */ | |
961 | if (locp_found == NULL) | |
962 | return NULL; | |
963 | ||
964 | /* We may have found a location that is at ADDRESS but is not the first in the | |
965 | location's list. Go backwards (if possible) and locate the first one. */ | |
966 | while ((locp_found - 1) >= bp_location | |
967 | && (*(locp_found - 1))->address == address) | |
968 | locp_found--; | |
969 | ||
970 | return locp_found; | |
971 | } | |
972 | ||
adc36818 | 973 | void |
7a26bd4d | 974 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
975 | int from_tty) |
976 | { | |
3a5c3e22 PA |
977 | xfree (b->cond_string); |
978 | b->cond_string = NULL; | |
adc36818 | 979 | |
3a5c3e22 | 980 | if (is_watchpoint (b)) |
adc36818 | 981 | { |
3a5c3e22 PA |
982 | struct watchpoint *w = (struct watchpoint *) b; |
983 | ||
4d01a485 | 984 | w->cond_exp.reset (); |
3a5c3e22 PA |
985 | } |
986 | else | |
987 | { | |
988 | struct bp_location *loc; | |
989 | ||
990 | for (loc = b->loc; loc; loc = loc->next) | |
991 | { | |
4d01a485 | 992 | loc->cond.reset (); |
b775012e LM |
993 | |
994 | /* No need to free the condition agent expression | |
995 | bytecode (if we have one). We will handle this | |
996 | when we go through update_global_location_list. */ | |
3a5c3e22 | 997 | } |
adc36818 | 998 | } |
adc36818 PM |
999 | |
1000 | if (*exp == 0) | |
1001 | { | |
1002 | if (from_tty) | |
1003 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1004 | } | |
1005 | else | |
1006 | { | |
bbc13ae3 | 1007 | const char *arg = exp; |
cc59ec59 | 1008 | |
adc36818 PM |
1009 | /* I don't know if it matters whether this is the string the user |
1010 | typed in or the decompiled expression. */ | |
1011 | b->cond_string = xstrdup (arg); | |
1012 | b->condition_not_parsed = 0; | |
1013 | ||
1014 | if (is_watchpoint (b)) | |
1015 | { | |
3a5c3e22 PA |
1016 | struct watchpoint *w = (struct watchpoint *) b; |
1017 | ||
adc36818 PM |
1018 | innermost_block = NULL; |
1019 | arg = exp; | |
1bb9788d | 1020 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1021 | if (*arg) |
1022 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1023 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1024 | } |
1025 | else | |
1026 | { | |
3a5c3e22 PA |
1027 | struct bp_location *loc; |
1028 | ||
adc36818 PM |
1029 | for (loc = b->loc; loc; loc = loc->next) |
1030 | { | |
1031 | arg = exp; | |
1032 | loc->cond = | |
1bb9788d TT |
1033 | parse_exp_1 (&arg, loc->address, |
1034 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1035 | if (*arg) |
1036 | error (_("Junk at end of expression")); | |
1037 | } | |
1038 | } | |
1039 | } | |
b775012e LM |
1040 | mark_breakpoint_modified (b); |
1041 | ||
8d3788bd | 1042 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1043 | } |
1044 | ||
d55637df TT |
1045 | /* Completion for the "condition" command. */ |
1046 | ||
1047 | static VEC (char_ptr) * | |
6f937416 PA |
1048 | condition_completer (struct cmd_list_element *cmd, |
1049 | const char *text, const char *word) | |
d55637df | 1050 | { |
6f937416 | 1051 | const char *space; |
d55637df | 1052 | |
6f937416 PA |
1053 | text = skip_spaces_const (text); |
1054 | space = skip_to_space_const (text); | |
d55637df TT |
1055 | if (*space == '\0') |
1056 | { | |
1057 | int len; | |
1058 | struct breakpoint *b; | |
1059 | VEC (char_ptr) *result = NULL; | |
1060 | ||
1061 | if (text[0] == '$') | |
1062 | { | |
1063 | /* We don't support completion of history indices. */ | |
1064 | if (isdigit (text[1])) | |
1065 | return NULL; | |
1066 | return complete_internalvar (&text[1]); | |
1067 | } | |
1068 | ||
1069 | /* We're completing the breakpoint number. */ | |
1070 | len = strlen (text); | |
1071 | ||
1072 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1073 | { |
1074 | char number[50]; | |
1075 | ||
1076 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1077 | ||
1078 | if (strncmp (number, text, len) == 0) | |
1079 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1080 | } | |
d55637df TT |
1081 | |
1082 | return result; | |
1083 | } | |
1084 | ||
1085 | /* We're completing the expression part. */ | |
6f937416 | 1086 | text = skip_spaces_const (space); |
d55637df TT |
1087 | return expression_completer (cmd, text, word); |
1088 | } | |
1089 | ||
c906108c SS |
1090 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1091 | ||
1092 | static void | |
fba45db2 | 1093 | condition_command (char *arg, int from_tty) |
c906108c | 1094 | { |
52f0bd74 | 1095 | struct breakpoint *b; |
c906108c | 1096 | char *p; |
52f0bd74 | 1097 | int bnum; |
c906108c SS |
1098 | |
1099 | if (arg == 0) | |
e2e0b3e5 | 1100 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1101 | |
1102 | p = arg; | |
1103 | bnum = get_number (&p); | |
5c44784c | 1104 | if (bnum == 0) |
8a3fe4f8 | 1105 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1106 | |
1107 | ALL_BREAKPOINTS (b) | |
1108 | if (b->number == bnum) | |
2f069f6f | 1109 | { |
6dddc817 DE |
1110 | /* Check if this breakpoint has a "stop" method implemented in an |
1111 | extension language. This method and conditions entered into GDB | |
1112 | from the CLI are mutually exclusive. */ | |
1113 | const struct extension_language_defn *extlang | |
1114 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1115 | ||
1116 | if (extlang != NULL) | |
1117 | { | |
1118 | error (_("Only one stop condition allowed. There is currently" | |
1119 | " a %s stop condition defined for this breakpoint."), | |
1120 | ext_lang_capitalized_name (extlang)); | |
1121 | } | |
2566ad2d | 1122 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1123 | |
1124 | if (is_breakpoint (b)) | |
44702360 | 1125 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1126 | |
2f069f6f JB |
1127 | return; |
1128 | } | |
c906108c | 1129 | |
8a3fe4f8 | 1130 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1131 | } |
1132 | ||
a7bdde9e VP |
1133 | /* Check that COMMAND do not contain commands that are suitable |
1134 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1135 | Throw if any such commands is found. */ |
1136 | ||
a7bdde9e VP |
1137 | static void |
1138 | check_no_tracepoint_commands (struct command_line *commands) | |
1139 | { | |
1140 | struct command_line *c; | |
cc59ec59 | 1141 | |
a7bdde9e VP |
1142 | for (c = commands; c; c = c->next) |
1143 | { | |
1144 | int i; | |
1145 | ||
1146 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1147 | error (_("The 'while-stepping' command can " |
1148 | "only be used for tracepoints")); | |
a7bdde9e VP |
1149 | |
1150 | for (i = 0; i < c->body_count; ++i) | |
1151 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1152 | ||
1153 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1154 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1155 | command directly. */ |
1156 | if (strstr (c->line, "collect ") == c->line) | |
1157 | error (_("The 'collect' command can only be used for tracepoints")); | |
1158 | ||
51661e93 VP |
1159 | if (strstr (c->line, "teval ") == c->line) |
1160 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1161 | } |
1162 | } | |
1163 | ||
d77f58be SS |
1164 | /* Encapsulate tests for different types of tracepoints. */ |
1165 | ||
d9b3f62e PA |
1166 | static int |
1167 | is_tracepoint_type (enum bptype type) | |
1168 | { | |
1169 | return (type == bp_tracepoint | |
1170 | || type == bp_fast_tracepoint | |
1171 | || type == bp_static_tracepoint); | |
1172 | } | |
1173 | ||
a7bdde9e | 1174 | int |
d77f58be | 1175 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1176 | { |
d9b3f62e | 1177 | return is_tracepoint_type (b->type); |
a7bdde9e | 1178 | } |
d9b3f62e | 1179 | |
e5dd4106 | 1180 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1181 | breakpoint. This function will throw an exception if a problem is |
1182 | found. */ | |
48cb2d85 | 1183 | |
95a42b64 TT |
1184 | static void |
1185 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1186 | struct command_line *commands) | |
48cb2d85 | 1187 | { |
d77f58be | 1188 | if (is_tracepoint (b)) |
a7bdde9e | 1189 | { |
c9a6ce02 | 1190 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1191 | struct command_line *c; |
1192 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1193 | |
1194 | /* Reset the while-stepping step count. The previous commands | |
1195 | might have included a while-stepping action, while the new | |
1196 | ones might not. */ | |
1197 | t->step_count = 0; | |
1198 | ||
1199 | /* We need to verify that each top-level element of commands is | |
1200 | valid for tracepoints, that there's at most one | |
1201 | while-stepping element, and that the while-stepping's body | |
1202 | has valid tracing commands excluding nested while-stepping. | |
1203 | We also need to validate the tracepoint action line in the | |
1204 | context of the tracepoint --- validate_actionline actually | |
1205 | has side effects, like setting the tracepoint's | |
1206 | while-stepping STEP_COUNT, in addition to checking if the | |
1207 | collect/teval actions parse and make sense in the | |
1208 | tracepoint's context. */ | |
a7bdde9e VP |
1209 | for (c = commands; c; c = c->next) |
1210 | { | |
a7bdde9e VP |
1211 | if (c->control_type == while_stepping_control) |
1212 | { | |
1213 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1214 | error (_("The 'while-stepping' command " |
1215 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1216 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1217 | error (_("The 'while-stepping' command " |
1218 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1219 | |
1220 | if (while_stepping) | |
3e43a32a MS |
1221 | error (_("The 'while-stepping' command " |
1222 | "can be used only once")); | |
a7bdde9e VP |
1223 | else |
1224 | while_stepping = c; | |
1225 | } | |
c9a6ce02 PA |
1226 | |
1227 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1228 | } |
1229 | if (while_stepping) | |
1230 | { | |
1231 | struct command_line *c2; | |
1232 | ||
1233 | gdb_assert (while_stepping->body_count == 1); | |
1234 | c2 = while_stepping->body_list[0]; | |
1235 | for (; c2; c2 = c2->next) | |
1236 | { | |
a7bdde9e VP |
1237 | if (c2->control_type == while_stepping_control) |
1238 | error (_("The 'while-stepping' command cannot be nested")); | |
1239 | } | |
1240 | } | |
1241 | } | |
1242 | else | |
1243 | { | |
1244 | check_no_tracepoint_commands (commands); | |
1245 | } | |
95a42b64 TT |
1246 | } |
1247 | ||
0fb4aa4b PA |
1248 | /* Return a vector of all the static tracepoints set at ADDR. The |
1249 | caller is responsible for releasing the vector. */ | |
1250 | ||
1251 | VEC(breakpoint_p) * | |
1252 | static_tracepoints_here (CORE_ADDR addr) | |
1253 | { | |
1254 | struct breakpoint *b; | |
1255 | VEC(breakpoint_p) *found = 0; | |
1256 | struct bp_location *loc; | |
1257 | ||
1258 | ALL_BREAKPOINTS (b) | |
1259 | if (b->type == bp_static_tracepoint) | |
1260 | { | |
1261 | for (loc = b->loc; loc; loc = loc->next) | |
1262 | if (loc->address == addr) | |
1263 | VEC_safe_push(breakpoint_p, found, b); | |
1264 | } | |
1265 | ||
1266 | return found; | |
1267 | } | |
1268 | ||
95a42b64 | 1269 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1270 | validate that only allowed commands are included. */ |
95a42b64 TT |
1271 | |
1272 | void | |
4a64f543 MS |
1273 | breakpoint_set_commands (struct breakpoint *b, |
1274 | struct command_line *commands) | |
95a42b64 TT |
1275 | { |
1276 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1277 | |
9add0f1b TT |
1278 | decref_counted_command_line (&b->commands); |
1279 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1280 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1281 | } |
1282 | ||
45a43567 TT |
1283 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1284 | is not the same as the "silent" that may appear in the breakpoint's | |
1285 | commands. */ | |
1286 | ||
1287 | void | |
1288 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1289 | { | |
1290 | int old_silent = b->silent; | |
1291 | ||
1292 | b->silent = silent; | |
1293 | if (old_silent != silent) | |
8d3788bd | 1294 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1295 | } |
1296 | ||
1297 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1298 | breakpoint work for any thread. */ | |
1299 | ||
1300 | void | |
1301 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1302 | { | |
1303 | int old_thread = b->thread; | |
1304 | ||
1305 | b->thread = thread; | |
1306 | if (old_thread != thread) | |
8d3788bd | 1307 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1308 | } |
1309 | ||
1310 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1311 | breakpoint work for any task. */ | |
1312 | ||
1313 | void | |
1314 | breakpoint_set_task (struct breakpoint *b, int task) | |
1315 | { | |
1316 | int old_task = b->task; | |
1317 | ||
1318 | b->task = task; | |
1319 | if (old_task != task) | |
8d3788bd | 1320 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1321 | } |
1322 | ||
95a42b64 TT |
1323 | void |
1324 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1325 | { |
9a3c8263 | 1326 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1327 | |
6f937416 | 1328 | validate_actionline (line, b); |
a7bdde9e VP |
1329 | } |
1330 | ||
95a42b64 TT |
1331 | /* A structure used to pass information through |
1332 | map_breakpoint_numbers. */ | |
1333 | ||
1334 | struct commands_info | |
1335 | { | |
1336 | /* True if the command was typed at a tty. */ | |
1337 | int from_tty; | |
86b17b60 PA |
1338 | |
1339 | /* The breakpoint range spec. */ | |
896b6bda | 1340 | const char *arg; |
86b17b60 | 1341 | |
95a42b64 TT |
1342 | /* Non-NULL if the body of the commands are being read from this |
1343 | already-parsed command. */ | |
1344 | struct command_line *control; | |
86b17b60 | 1345 | |
95a42b64 TT |
1346 | /* The command lines read from the user, or NULL if they have not |
1347 | yet been read. */ | |
1348 | struct counted_command_line *cmd; | |
1349 | }; | |
1350 | ||
1351 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1352 | commands_command. */ | |
1353 | ||
c906108c | 1354 | static void |
95a42b64 | 1355 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1356 | { |
9a3c8263 | 1357 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1358 | |
95a42b64 TT |
1359 | if (info->cmd == NULL) |
1360 | { | |
1361 | struct command_line *l; | |
5c44784c | 1362 | |
95a42b64 TT |
1363 | if (info->control != NULL) |
1364 | l = copy_command_lines (info->control->body_list[0]); | |
1365 | else | |
86b17b60 PA |
1366 | { |
1367 | struct cleanup *old_chain; | |
1368 | char *str; | |
c5aa993b | 1369 | |
3e43a32a MS |
1370 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1371 | "%s, one per line."), | |
86b17b60 PA |
1372 | info->arg); |
1373 | ||
1374 | old_chain = make_cleanup (xfree, str); | |
1375 | ||
1376 | l = read_command_lines (str, | |
1377 | info->from_tty, 1, | |
d77f58be | 1378 | (is_tracepoint (b) |
86b17b60 PA |
1379 | ? check_tracepoint_command : 0), |
1380 | b); | |
1381 | ||
1382 | do_cleanups (old_chain); | |
1383 | } | |
a7bdde9e | 1384 | |
95a42b64 TT |
1385 | info->cmd = alloc_counted_command_line (l); |
1386 | } | |
1387 | ||
1388 | /* If a breakpoint was on the list more than once, we don't need to | |
1389 | do anything. */ | |
1390 | if (b->commands != info->cmd) | |
1391 | { | |
1392 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1393 | incref_counted_command_line (info->cmd); | |
1394 | decref_counted_command_line (&b->commands); | |
1395 | b->commands = info->cmd; | |
8d3788bd | 1396 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1397 | } |
95a42b64 TT |
1398 | } |
1399 | ||
1400 | static void | |
896b6bda | 1401 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1402 | struct command_line *control) |
95a42b64 TT |
1403 | { |
1404 | struct cleanup *cleanups; | |
1405 | struct commands_info info; | |
1406 | ||
1407 | info.from_tty = from_tty; | |
1408 | info.control = control; | |
1409 | info.cmd = NULL; | |
1410 | /* If we read command lines from the user, then `info' will hold an | |
1411 | extra reference to the commands that we must clean up. */ | |
1412 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1413 | ||
896b6bda PA |
1414 | std::string new_arg; |
1415 | ||
95a42b64 TT |
1416 | if (arg == NULL || !*arg) |
1417 | { | |
86b17b60 | 1418 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1419 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1420 | breakpoint_count); | |
95a42b64 | 1421 | else if (breakpoint_count > 0) |
896b6bda | 1422 | new_arg = string_printf ("%d", breakpoint_count); |
95a42b64 | 1423 | } |
9766ced4 | 1424 | else |
896b6bda | 1425 | new_arg = arg; |
86b17b60 | 1426 | |
896b6bda | 1427 | info.arg = new_arg.c_str (); |
95a42b64 | 1428 | |
896b6bda | 1429 | map_breakpoint_numbers (info.arg, do_map_commands_command, &info); |
95a42b64 TT |
1430 | |
1431 | if (info.cmd == NULL) | |
1432 | error (_("No breakpoints specified.")); | |
1433 | ||
1434 | do_cleanups (cleanups); | |
1435 | } | |
1436 | ||
1437 | static void | |
1438 | commands_command (char *arg, int from_tty) | |
1439 | { | |
1440 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1441 | } |
40c03ae8 EZ |
1442 | |
1443 | /* Like commands_command, but instead of reading the commands from | |
1444 | input stream, takes them from an already parsed command structure. | |
1445 | ||
1446 | This is used by cli-script.c to DTRT with breakpoint commands | |
1447 | that are part of if and while bodies. */ | |
1448 | enum command_control_type | |
896b6bda | 1449 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1450 | { |
95a42b64 TT |
1451 | commands_command_1 (arg, 0, cmd); |
1452 | return simple_control; | |
40c03ae8 | 1453 | } |
876fa593 JK |
1454 | |
1455 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1456 | ||
1457 | static int | |
1458 | bp_location_has_shadow (struct bp_location *bl) | |
1459 | { | |
1460 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1461 | return 0; | |
1462 | if (!bl->inserted) | |
1463 | return 0; | |
1464 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1465 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1466 | return 0; |
1467 | return 1; | |
1468 | } | |
1469 | ||
9d497a19 PA |
1470 | /* Update BUF, which is LEN bytes read from the target address |
1471 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1472 | contents. | |
1473 | ||
1474 | If READBUF is not NULL, this buffer must not overlap with the of | |
1475 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1476 | failed assertion internal error will be raised. */ | |
1477 | ||
1478 | static void | |
1479 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1480 | const gdb_byte *writebuf_org, | |
1481 | ULONGEST memaddr, LONGEST len, | |
1482 | struct bp_target_info *target_info, | |
1483 | struct gdbarch *gdbarch) | |
1484 | { | |
1485 | /* Now do full processing of the found relevant range of elements. */ | |
1486 | CORE_ADDR bp_addr = 0; | |
1487 | int bp_size = 0; | |
1488 | int bptoffset = 0; | |
1489 | ||
1490 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1491 | current_program_space->aspace, 0)) | |
1492 | { | |
1493 | /* The breakpoint is inserted in a different address space. */ | |
1494 | return; | |
1495 | } | |
1496 | ||
1497 | /* Addresses and length of the part of the breakpoint that | |
1498 | we need to copy. */ | |
1499 | bp_addr = target_info->placed_address; | |
1500 | bp_size = target_info->shadow_len; | |
1501 | ||
1502 | if (bp_addr + bp_size <= memaddr) | |
1503 | { | |
1504 | /* The breakpoint is entirely before the chunk of memory we are | |
1505 | reading. */ | |
1506 | return; | |
1507 | } | |
1508 | ||
1509 | if (bp_addr >= memaddr + len) | |
1510 | { | |
1511 | /* The breakpoint is entirely after the chunk of memory we are | |
1512 | reading. */ | |
1513 | return; | |
1514 | } | |
1515 | ||
1516 | /* Offset within shadow_contents. */ | |
1517 | if (bp_addr < memaddr) | |
1518 | { | |
1519 | /* Only copy the second part of the breakpoint. */ | |
1520 | bp_size -= memaddr - bp_addr; | |
1521 | bptoffset = memaddr - bp_addr; | |
1522 | bp_addr = memaddr; | |
1523 | } | |
1524 | ||
1525 | if (bp_addr + bp_size > memaddr + len) | |
1526 | { | |
1527 | /* Only copy the first part of the breakpoint. */ | |
1528 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1529 | } | |
1530 | ||
1531 | if (readbuf != NULL) | |
1532 | { | |
1533 | /* Verify that the readbuf buffer does not overlap with the | |
1534 | shadow_contents buffer. */ | |
1535 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1536 | || readbuf >= (target_info->shadow_contents | |
1537 | + target_info->shadow_len)); | |
1538 | ||
1539 | /* Update the read buffer with this inserted breakpoint's | |
1540 | shadow. */ | |
1541 | memcpy (readbuf + bp_addr - memaddr, | |
1542 | target_info->shadow_contents + bptoffset, bp_size); | |
1543 | } | |
1544 | else | |
1545 | { | |
1546 | const unsigned char *bp; | |
0d5ed153 MR |
1547 | CORE_ADDR addr = target_info->reqstd_address; |
1548 | int placed_size; | |
9d497a19 PA |
1549 | |
1550 | /* Update the shadow with what we want to write to memory. */ | |
1551 | memcpy (target_info->shadow_contents + bptoffset, | |
1552 | writebuf_org + bp_addr - memaddr, bp_size); | |
1553 | ||
1554 | /* Determine appropriate breakpoint contents and size for this | |
1555 | address. */ | |
0d5ed153 | 1556 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1557 | |
1558 | /* Update the final write buffer with this inserted | |
1559 | breakpoint's INSN. */ | |
1560 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1561 | } | |
1562 | } | |
1563 | ||
8defab1a | 1564 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1565 | by replacing any memory breakpoints with their shadowed contents. |
1566 | ||
35c63cd8 JB |
1567 | If READBUF is not NULL, this buffer must not overlap with any of |
1568 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1569 | a failed assertion internal error will be raised. | |
1570 | ||
876fa593 | 1571 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1572 | bl->address - bp_location_placed_address_before_address_max |
1573 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1574 | The range we were requested to resolve shadows for is: |
1575 | memaddr ... memaddr + len | |
1576 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1577 | memaddr + len <= (bl->address |
1578 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1579 | and: |
35df4500 | 1580 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1581 | |
8defab1a | 1582 | void |
f0ba3972 PA |
1583 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1584 | const gdb_byte *writebuf_org, | |
1585 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1586 | { |
4a64f543 MS |
1587 | /* Left boundary, right boundary and median element of our binary |
1588 | search. */ | |
876fa593 JK |
1589 | unsigned bc_l, bc_r, bc; |
1590 | ||
4a64f543 MS |
1591 | /* Find BC_L which is a leftmost element which may affect BUF |
1592 | content. It is safe to report lower value but a failure to | |
1593 | report higher one. */ | |
876fa593 JK |
1594 | |
1595 | bc_l = 0; | |
1596 | bc_r = bp_location_count; | |
1597 | while (bc_l + 1 < bc_r) | |
1598 | { | |
35df4500 | 1599 | struct bp_location *bl; |
876fa593 JK |
1600 | |
1601 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1602 | bl = bp_location[bc]; |
876fa593 | 1603 | |
4a64f543 MS |
1604 | /* Check first BL->ADDRESS will not overflow due to the added |
1605 | constant. Then advance the left boundary only if we are sure | |
1606 | the BC element can in no way affect the BUF content (MEMADDR | |
1607 | to MEMADDR + LEN range). | |
876fa593 | 1608 | |
4a64f543 MS |
1609 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1610 | offset so that we cannot miss a breakpoint with its shadow | |
1611 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1612 | |
35df4500 TJB |
1613 | if ((bl->address + bp_location_shadow_len_after_address_max |
1614 | >= bl->address) | |
1615 | && (bl->address + bp_location_shadow_len_after_address_max | |
1616 | <= memaddr)) | |
876fa593 JK |
1617 | bc_l = bc; |
1618 | else | |
1619 | bc_r = bc; | |
1620 | } | |
1621 | ||
128070bb PA |
1622 | /* Due to the binary search above, we need to make sure we pick the |
1623 | first location that's at BC_L's address. E.g., if there are | |
1624 | multiple locations at the same address, BC_L may end up pointing | |
1625 | at a duplicate location, and miss the "master"/"inserted" | |
1626 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1627 | B: | |
1628 | ||
1629 | L1@A, L2@A, L3@B, ... | |
1630 | ||
1631 | BC_L could end up pointing at location L2, while the "master" | |
1632 | location could be L1. Since the `loc->inserted' flag is only set | |
1633 | on "master" locations, we'd forget to restore the shadow of L1 | |
1634 | and L2. */ | |
1635 | while (bc_l > 0 | |
1636 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1637 | bc_l--; | |
1638 | ||
876fa593 JK |
1639 | /* Now do full processing of the found relevant range of elements. */ |
1640 | ||
1641 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1642 | { |
35df4500 | 1643 | struct bp_location *bl = bp_location[bc]; |
876fa593 | 1644 | |
35df4500 TJB |
1645 | /* bp_location array has BL->OWNER always non-NULL. */ |
1646 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1647 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1648 | bl->owner->number); |
ffce0d52 | 1649 | |
e5dd4106 | 1650 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1651 | content. */ |
1652 | ||
35df4500 TJB |
1653 | if (bl->address >= bp_location_placed_address_before_address_max |
1654 | && memaddr + len <= (bl->address | |
1655 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1656 | break; |
1657 | ||
35df4500 | 1658 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1659 | continue; |
6c95b8df | 1660 | |
9d497a19 PA |
1661 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1662 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1663 | } | |
c906108c | 1664 | } |
9d497a19 | 1665 | |
c906108c | 1666 | \f |
c5aa993b | 1667 | |
b775012e LM |
1668 | /* Return true if BPT is either a software breakpoint or a hardware |
1669 | breakpoint. */ | |
1670 | ||
1671 | int | |
1672 | is_breakpoint (const struct breakpoint *bpt) | |
1673 | { | |
1674 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1675 | || bpt->type == bp_hardware_breakpoint |
1676 | || bpt->type == bp_dprintf); | |
b775012e LM |
1677 | } |
1678 | ||
60e1c644 PA |
1679 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1680 | ||
a5606eee | 1681 | static int |
d77f58be | 1682 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1683 | { |
1684 | return (bpt->type == bp_hardware_watchpoint | |
1685 | || bpt->type == bp_read_watchpoint | |
1686 | || bpt->type == bp_access_watchpoint); | |
1687 | } | |
7270d8f2 | 1688 | |
60e1c644 PA |
1689 | /* Return true if BPT is of any watchpoint kind, hardware or |
1690 | software. */ | |
1691 | ||
3a5c3e22 | 1692 | int |
d77f58be | 1693 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1694 | { |
1695 | return (is_hardware_watchpoint (bpt) | |
1696 | || bpt->type == bp_watchpoint); | |
1697 | } | |
1698 | ||
3a5c3e22 PA |
1699 | /* Returns true if the current thread and its running state are safe |
1700 | to evaluate or update watchpoint B. Watchpoints on local | |
1701 | expressions need to be evaluated in the context of the thread that | |
1702 | was current when the watchpoint was created, and, that thread needs | |
1703 | to be stopped to be able to select the correct frame context. | |
1704 | Watchpoints on global expressions can be evaluated on any thread, | |
1705 | and in any state. It is presently left to the target allowing | |
1706 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1707 | |
1708 | static int | |
3a5c3e22 | 1709 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1710 | { |
d0d8b0c6 JK |
1711 | return (b->base.pspace == current_program_space |
1712 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1713 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1714 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1715 | } |
1716 | ||
d0fb5eae JK |
1717 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1718 | associated bp_watchpoint_scope breakpoint. */ | |
1719 | ||
1720 | static void | |
3a5c3e22 | 1721 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1722 | { |
3a5c3e22 | 1723 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1724 | |
1725 | if (b->related_breakpoint != b) | |
1726 | { | |
1727 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1728 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1729 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1730 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1731 | b->related_breakpoint = b; | |
1732 | } | |
1733 | b->disposition = disp_del_at_next_stop; | |
1734 | } | |
1735 | ||
bb9d5f81 PP |
1736 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1737 | watchpoint W. */ | |
1738 | ||
1739 | static struct value * | |
1740 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1741 | { | |
1742 | struct value *bit_val; | |
1743 | ||
1744 | if (val == NULL) | |
1745 | return NULL; | |
1746 | ||
1747 | bit_val = allocate_value (value_type (val)); | |
1748 | ||
1749 | unpack_value_bitfield (bit_val, | |
1750 | w->val_bitpos, | |
1751 | w->val_bitsize, | |
1752 | value_contents_for_printing (val), | |
1753 | value_offset (val), | |
1754 | val); | |
1755 | ||
1756 | return bit_val; | |
1757 | } | |
1758 | ||
c6d81124 PA |
1759 | /* Allocate a dummy location and add it to B, which must be a software |
1760 | watchpoint. This is required because even if a software watchpoint | |
1761 | is not watching any memory, bpstat_stop_status requires a location | |
1762 | to be able to report stops. */ | |
1763 | ||
1764 | static void | |
1765 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1766 | struct program_space *pspace) | |
1767 | { | |
1768 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1769 | ||
1770 | b->loc = allocate_bp_location (b); | |
1771 | b->loc->pspace = pspace; | |
1772 | b->loc->address = -1; | |
1773 | b->loc->length = -1; | |
1774 | } | |
1775 | ||
1776 | /* Returns true if B is a software watchpoint that is not watching any | |
1777 | memory (e.g., "watch $pc"). */ | |
1778 | ||
1779 | static int | |
1780 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1781 | { | |
1782 | return (b->type == bp_watchpoint | |
1783 | && b->loc != NULL | |
1784 | && b->loc->next == NULL | |
1785 | && b->loc->address == -1 | |
1786 | && b->loc->length == -1); | |
1787 | } | |
1788 | ||
567e1b4e JB |
1789 | /* Assuming that B is a watchpoint: |
1790 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1791 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1792 | - Evaluate the condition if there is one, and store the result |
1793 | in b->loc->cond. | |
a5606eee VP |
1794 | - Update the list of values that must be watched in B->loc. |
1795 | ||
4a64f543 MS |
1796 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1797 | nothing. If this is local watchpoint that is out of scope, delete | |
1798 | it. | |
1799 | ||
1800 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1801 | removed + inserted on each stop here. Normal breakpoints must | |
1802 | never be removed because they might be missed by a running thread | |
1803 | when debugging in non-stop mode. On the other hand, hardware | |
1804 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1805 | to each LWP since they are stored in each LWP's hardware debug | |
1806 | registers. Therefore, such LWP must be stopped first in order to | |
1807 | be able to modify its hardware watchpoints. | |
1808 | ||
1809 | Hardware watchpoints must be reset exactly once after being | |
1810 | presented to the user. It cannot be done sooner, because it would | |
1811 | reset the data used to present the watchpoint hit to the user. And | |
1812 | it must not be done later because it could display the same single | |
1813 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1814 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1815 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1816 | not user-visible - its hit is suppressed if the memory content has | |
1817 | not changed. | |
1818 | ||
1819 | The following constraints influence the location where we can reset | |
1820 | hardware watchpoints: | |
1821 | ||
1822 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1823 | called several times when GDB stops. | |
1824 | ||
1825 | [linux] | |
1826 | * Multiple hardware watchpoints can be hit at the same time, | |
1827 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1828 | hit at a time as the reason for stopping, and all the other hits | |
1829 | are presented later, one after the other, each time the user | |
1830 | requests the execution to be resumed. Execution is not resumed | |
1831 | for the threads still having pending hit event stored in | |
1832 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1833 | the inferior on the first stop the thread hit event is kept being | |
1834 | reported from its cached value by linux_nat_stopped_data_address | |
1835 | until the real thread resume happens after the watchpoint gets | |
1836 | presented and thus its LWP_INFO->STATUS gets reset. | |
1837 | ||
1838 | Therefore the hardware watchpoint hit can get safely reset on the | |
1839 | watchpoint removal from inferior. */ | |
a79d3c27 | 1840 | |
b40ce68a | 1841 | static void |
3a5c3e22 | 1842 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1843 | { |
a5606eee | 1844 | int within_current_scope; |
a5606eee | 1845 | struct frame_id saved_frame_id; |
66076460 | 1846 | int frame_saved; |
a5606eee | 1847 | |
f6bc2008 PA |
1848 | /* If this is a local watchpoint, we only want to check if the |
1849 | watchpoint frame is in scope if the current thread is the thread | |
1850 | that was used to create the watchpoint. */ | |
1851 | if (!watchpoint_in_thread_scope (b)) | |
1852 | return; | |
1853 | ||
3a5c3e22 | 1854 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1855 | return; |
1856 | ||
66076460 | 1857 | frame_saved = 0; |
a5606eee VP |
1858 | |
1859 | /* Determine if the watchpoint is within scope. */ | |
1860 | if (b->exp_valid_block == NULL) | |
1861 | within_current_scope = 1; | |
1862 | else | |
1863 | { | |
b5db5dfc UW |
1864 | struct frame_info *fi = get_current_frame (); |
1865 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1866 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1867 | ||
c9cf6e20 MG |
1868 | /* If we're at a point where the stack has been destroyed |
1869 | (e.g. in a function epilogue), unwinding may not work | |
1870 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1871 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1872 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1873 | return; |
66076460 DJ |
1874 | |
1875 | /* Save the current frame's ID so we can restore it after | |
1876 | evaluating the watchpoint expression on its own frame. */ | |
1877 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1878 | took a frame parameter, so that we didn't have to change the | |
1879 | selected frame. */ | |
1880 | frame_saved = 1; | |
1881 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1882 | ||
a5606eee VP |
1883 | fi = frame_find_by_id (b->watchpoint_frame); |
1884 | within_current_scope = (fi != NULL); | |
1885 | if (within_current_scope) | |
1886 | select_frame (fi); | |
1887 | } | |
1888 | ||
b5db5dfc UW |
1889 | /* We don't free locations. They are stored in the bp_location array |
1890 | and update_global_location_list will eventually delete them and | |
1891 | remove breakpoints if needed. */ | |
3a5c3e22 | 1892 | b->base.loc = NULL; |
b5db5dfc | 1893 | |
a5606eee VP |
1894 | if (within_current_scope && reparse) |
1895 | { | |
bbc13ae3 | 1896 | const char *s; |
d63d0675 | 1897 | |
4d01a485 | 1898 | b->exp.reset (); |
d63d0675 | 1899 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1900 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1901 | /* If the meaning of expression itself changed, the old value is |
1902 | no longer relevant. We don't want to report a watchpoint hit | |
1903 | to the user when the old value and the new value may actually | |
1904 | be completely different objects. */ | |
1905 | value_free (b->val); | |
fa4727a6 DJ |
1906 | b->val = NULL; |
1907 | b->val_valid = 0; | |
60e1c644 PA |
1908 | |
1909 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1910 | expression is stored in the breakpoint object, not in the | |
1911 | locations (re)created below. */ | |
3a5c3e22 | 1912 | if (b->base.cond_string != NULL) |
60e1c644 | 1913 | { |
4d01a485 | 1914 | b->cond_exp.reset (); |
60e1c644 | 1915 | |
3a5c3e22 | 1916 | s = b->base.cond_string; |
1bb9788d | 1917 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1918 | } |
a5606eee | 1919 | } |
a5606eee VP |
1920 | |
1921 | /* If we failed to parse the expression, for example because | |
1922 | it refers to a global variable in a not-yet-loaded shared library, | |
1923 | don't try to insert watchpoint. We don't automatically delete | |
1924 | such watchpoint, though, since failure to parse expression | |
1925 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1926 | if (!target_has_execution) |
2d134ed3 PA |
1927 | { |
1928 | /* Without execution, memory can't change. No use to try and | |
1929 | set watchpoint locations. The watchpoint will be reset when | |
1930 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1931 | if (!can_use_hw_watchpoints) |
1932 | { | |
1933 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1934 | b->base.type = bp_watchpoint; | |
1935 | else | |
638aa5a1 AB |
1936 | error (_("Can't set read/access watchpoint when " |
1937 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1938 | } |
2d134ed3 PA |
1939 | } |
1940 | else if (within_current_scope && b->exp) | |
a5606eee | 1941 | { |
0cf6dd15 | 1942 | int pc = 0; |
fa4727a6 | 1943 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1944 | struct program_space *frame_pspace; |
a5606eee | 1945 | |
4d01a485 | 1946 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1947 | |
a5606eee VP |
1948 | /* Avoid setting b->val if it's already set. The meaning of |
1949 | b->val is 'the last value' user saw, and we should update | |
1950 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1951 | happens, the code that reports it updates b->val directly. |
1952 | We don't keep track of the memory value for masked | |
1953 | watchpoints. */ | |
3a5c3e22 | 1954 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1955 | { |
bb9d5f81 PP |
1956 | if (b->val_bitsize != 0) |
1957 | { | |
1958 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1959 | if (v != NULL) | |
1960 | release_value (v); | |
1961 | } | |
fa4727a6 DJ |
1962 | b->val = v; |
1963 | b->val_valid = 1; | |
1964 | } | |
a5606eee | 1965 | |
2d134ed3 PA |
1966 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1967 | ||
a5606eee | 1968 | /* Look at each value on the value chain. */ |
9fa40276 | 1969 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1970 | { |
1971 | /* If it's a memory location, and GDB actually needed | |
1972 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1973 | must watch it. If the first value returned is |
1974 | still lazy, that means an error occurred reading it; | |
1975 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1976 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1977 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1978 | { |
1979 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1980 | |
a5606eee VP |
1981 | /* We only watch structs and arrays if user asked |
1982 | for it explicitly, never if they just happen to | |
1983 | appear in the middle of some value chain. */ | |
fa4727a6 | 1984 | if (v == result |
a5606eee VP |
1985 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1986 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1987 | { | |
1988 | CORE_ADDR addr; | |
f486487f | 1989 | enum target_hw_bp_type type; |
a5606eee | 1990 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1991 | int bitpos = 0, bitsize = 0; |
1992 | ||
1993 | if (value_bitsize (v) != 0) | |
1994 | { | |
1995 | /* Extract the bit parameters out from the bitfield | |
1996 | sub-expression. */ | |
1997 | bitpos = value_bitpos (v); | |
1998 | bitsize = value_bitsize (v); | |
1999 | } | |
2000 | else if (v == result && b->val_bitsize != 0) | |
2001 | { | |
2002 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2003 | lvalue whose bit parameters are saved in the fields | |
2004 | VAL_BITPOS and VAL_BITSIZE. */ | |
2005 | bitpos = b->val_bitpos; | |
2006 | bitsize = b->val_bitsize; | |
2007 | } | |
a5606eee | 2008 | |
42ae5230 | 2009 | addr = value_address (v); |
bb9d5f81 PP |
2010 | if (bitsize != 0) |
2011 | { | |
2012 | /* Skip the bytes that don't contain the bitfield. */ | |
2013 | addr += bitpos / 8; | |
2014 | } | |
2015 | ||
a5606eee | 2016 | type = hw_write; |
3a5c3e22 | 2017 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2018 | type = hw_read; |
3a5c3e22 | 2019 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2020 | type = hw_access; |
3a5c3e22 PA |
2021 | |
2022 | loc = allocate_bp_location (&b->base); | |
2023 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2024 | ; |
2025 | *tmp = loc; | |
a6d9a66e | 2026 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2027 | |
2028 | loc->pspace = frame_pspace; | |
a5606eee | 2029 | loc->address = addr; |
bb9d5f81 PP |
2030 | |
2031 | if (bitsize != 0) | |
2032 | { | |
2033 | /* Just cover the bytes that make up the bitfield. */ | |
2034 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2035 | } | |
2036 | else | |
2037 | loc->length = TYPE_LENGTH (value_type (v)); | |
2038 | ||
a5606eee VP |
2039 | loc->watchpoint_type = type; |
2040 | } | |
2041 | } | |
9fa40276 TJB |
2042 | } |
2043 | ||
2044 | /* Change the type of breakpoint between hardware assisted or | |
2045 | an ordinary watchpoint depending on the hardware support | |
2046 | and free hardware slots. REPARSE is set when the inferior | |
2047 | is started. */ | |
a9634178 | 2048 | if (reparse) |
9fa40276 | 2049 | { |
e09342b5 | 2050 | int reg_cnt; |
9fa40276 TJB |
2051 | enum bp_loc_type loc_type; |
2052 | struct bp_location *bl; | |
a5606eee | 2053 | |
a9634178 | 2054 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2055 | |
2056 | if (reg_cnt) | |
9fa40276 TJB |
2057 | { |
2058 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2059 | enum bptype type; |
9fa40276 | 2060 | |
a9634178 TJB |
2061 | /* Use an exact watchpoint when there's only one memory region to be |
2062 | watched, and only one debug register is needed to watch it. */ | |
2063 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2064 | ||
9fa40276 | 2065 | /* We need to determine how many resources are already |
e09342b5 TJB |
2066 | used for all other hardware watchpoints plus this one |
2067 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2068 | this watchpoint in as well. */ |
2069 | ||
2070 | /* If this is a software watchpoint, we try to turn it | |
2071 | to a hardware one -- count resources as if B was of | |
2072 | hardware watchpoint type. */ | |
2073 | type = b->base.type; | |
2074 | if (type == bp_watchpoint) | |
2075 | type = bp_hardware_watchpoint; | |
2076 | ||
2077 | /* This watchpoint may or may not have been placed on | |
2078 | the list yet at this point (it won't be in the list | |
2079 | if we're trying to create it for the first time, | |
2080 | through watch_command), so always account for it | |
2081 | manually. */ | |
2082 | ||
2083 | /* Count resources used by all watchpoints except B. */ | |
2084 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2085 | ||
2086 | /* Add in the resources needed for B. */ | |
2087 | i += hw_watchpoint_use_count (&b->base); | |
2088 | ||
2089 | target_resources_ok | |
2090 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2091 | if (target_resources_ok <= 0) |
a9634178 | 2092 | { |
3a5c3e22 | 2093 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2094 | |
2095 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2096 | error (_("Target does not support this type of " |
2097 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2098 | else if (target_resources_ok < 0 && !sw_mode) |
2099 | error (_("There are not enough available hardware " | |
2100 | "resources for this watchpoint.")); | |
a1398e0c PA |
2101 | |
2102 | /* Downgrade to software watchpoint. */ | |
2103 | b->base.type = bp_watchpoint; | |
2104 | } | |
2105 | else | |
2106 | { | |
2107 | /* If this was a software watchpoint, we've just | |
2108 | found we have enough resources to turn it to a | |
2109 | hardware watchpoint. Otherwise, this is a | |
2110 | nop. */ | |
2111 | b->base.type = type; | |
a9634178 | 2112 | } |
9fa40276 | 2113 | } |
3a5c3e22 | 2114 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2115 | { |
2116 | if (!can_use_hw_watchpoints) | |
2117 | error (_("Can't set read/access watchpoint when " | |
2118 | "hardware watchpoints are disabled.")); | |
2119 | else | |
2120 | error (_("Expression cannot be implemented with " | |
2121 | "read/access watchpoint.")); | |
2122 | } | |
9fa40276 | 2123 | else |
3a5c3e22 | 2124 | b->base.type = bp_watchpoint; |
9fa40276 | 2125 | |
3a5c3e22 | 2126 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2127 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2128 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2129 | bl->loc_type = loc_type; |
2130 | } | |
2131 | ||
2132 | for (v = val_chain; v; v = next) | |
2133 | { | |
a5606eee VP |
2134 | next = value_next (v); |
2135 | if (v != b->val) | |
2136 | value_free (v); | |
2137 | } | |
2138 | ||
c7437ca6 PA |
2139 | /* If a software watchpoint is not watching any memory, then the |
2140 | above left it without any location set up. But, | |
2141 | bpstat_stop_status requires a location to be able to report | |
2142 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2143 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c6d81124 | 2144 | software_watchpoint_add_no_memory_location (&b->base, frame_pspace); |
a5606eee VP |
2145 | } |
2146 | else if (!within_current_scope) | |
7270d8f2 | 2147 | { |
ac74f770 MS |
2148 | printf_filtered (_("\ |
2149 | Watchpoint %d deleted because the program has left the block\n\ | |
2150 | in which its expression is valid.\n"), | |
3a5c3e22 | 2151 | b->base.number); |
d0fb5eae | 2152 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2153 | } |
a5606eee VP |
2154 | |
2155 | /* Restore the selected frame. */ | |
66076460 DJ |
2156 | if (frame_saved) |
2157 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2158 | } |
2159 | ||
a5606eee | 2160 | |
74960c60 | 2161 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2162 | inserted in the inferior. We don't differentiate the type of BL's owner |
2163 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2164 | breakpoint_ops is not defined, because in insert_bp_location, | |
2165 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2166 | static int |
35df4500 | 2167 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2168 | { |
35df4500 | 2169 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2170 | return 0; |
2171 | ||
35df4500 | 2172 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2173 | return 0; |
2174 | ||
35df4500 | 2175 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2176 | return 0; |
2177 | ||
f8eba3c6 TT |
2178 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2179 | return 0; | |
2180 | ||
56710373 PA |
2181 | /* This is set for example, when we're attached to the parent of a |
2182 | vfork, and have detached from the child. The child is running | |
2183 | free, and we expect it to do an exec or exit, at which point the | |
2184 | OS makes the parent schedulable again (and the target reports | |
2185 | that the vfork is done). Until the child is done with the shared | |
2186 | memory region, do not insert breakpoints in the parent, otherwise | |
2187 | the child could still trip on the parent's breakpoints. Since | |
2188 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2189 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2190 | return 0; |
2191 | ||
31e77af2 | 2192 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2193 | location, except if the breakpoint is a single-step breakpoint, |
2194 | and the breakpoint's thread is the thread which is stepping past | |
2195 | a breakpoint. */ | |
31e77af2 PA |
2196 | if ((bl->loc_type == bp_loc_software_breakpoint |
2197 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2198 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2199 | bl->address) |
2200 | /* The single-step breakpoint may be inserted at the location | |
2201 | we're trying to step if the instruction branches to itself. | |
2202 | However, the instruction won't be executed at all and it may | |
2203 | break the semantics of the instruction, for example, the | |
2204 | instruction is a conditional branch or updates some flags. | |
2205 | We can't fix it unless GDB is able to emulate the instruction | |
2206 | or switch to displaced stepping. */ | |
2207 | && !(bl->owner->type == bp_single_step | |
2208 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2209 | { |
2210 | if (debug_infrun) | |
2211 | { | |
2212 | fprintf_unfiltered (gdb_stdlog, | |
2213 | "infrun: skipping breakpoint: " | |
2214 | "stepping past insn at: %s\n", | |
2215 | paddress (bl->gdbarch, bl->address)); | |
2216 | } | |
2217 | return 0; | |
2218 | } | |
31e77af2 | 2219 | |
963f9c80 PA |
2220 | /* Don't insert watchpoints if we're trying to step past the |
2221 | instruction that triggered one. */ | |
2222 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2223 | && stepping_past_nonsteppable_watchpoint ()) | |
2224 | { | |
2225 | if (debug_infrun) | |
2226 | { | |
2227 | fprintf_unfiltered (gdb_stdlog, | |
2228 | "infrun: stepping past non-steppable watchpoint. " | |
2229 | "skipping watchpoint at %s:%d\n", | |
2230 | paddress (bl->gdbarch, bl->address), | |
2231 | bl->length); | |
2232 | } | |
2233 | return 0; | |
2234 | } | |
2235 | ||
74960c60 VP |
2236 | return 1; |
2237 | } | |
2238 | ||
934709f0 PW |
2239 | /* Same as should_be_inserted but does the check assuming |
2240 | that the location is not duplicated. */ | |
2241 | ||
2242 | static int | |
2243 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2244 | { | |
2245 | int result; | |
2246 | const int save_duplicate = bl->duplicate; | |
2247 | ||
2248 | bl->duplicate = 0; | |
2249 | result = should_be_inserted (bl); | |
2250 | bl->duplicate = save_duplicate; | |
2251 | return result; | |
2252 | } | |
2253 | ||
b775012e LM |
2254 | /* Parses a conditional described by an expression COND into an |
2255 | agent expression bytecode suitable for evaluation | |
2256 | by the bytecode interpreter. Return NULL if there was | |
2257 | any error during parsing. */ | |
2258 | ||
2259 | static struct agent_expr * | |
2260 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2261 | { | |
2262 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2263 | |
2264 | if (!cond) | |
2265 | return NULL; | |
2266 | ||
2267 | /* We don't want to stop processing, so catch any errors | |
2268 | that may show up. */ | |
492d29ea | 2269 | TRY |
b775012e LM |
2270 | { |
2271 | aexpr = gen_eval_for_expr (scope, cond); | |
2272 | } | |
2273 | ||
492d29ea | 2274 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2275 | { |
2276 | /* If we got here, it means the condition could not be parsed to a valid | |
2277 | bytecode expression and thus can't be evaluated on the target's side. | |
2278 | It's no use iterating through the conditions. */ | |
2279 | return NULL; | |
2280 | } | |
492d29ea | 2281 | END_CATCH |
b775012e LM |
2282 | |
2283 | /* We have a valid agent expression. */ | |
2284 | return aexpr; | |
2285 | } | |
2286 | ||
2287 | /* Based on location BL, create a list of breakpoint conditions to be | |
2288 | passed on to the target. If we have duplicated locations with different | |
2289 | conditions, we will add such conditions to the list. The idea is that the | |
2290 | target will evaluate the list of conditions and will only notify GDB when | |
2291 | one of them is true. */ | |
2292 | ||
2293 | static void | |
2294 | build_target_condition_list (struct bp_location *bl) | |
2295 | { | |
2296 | struct bp_location **locp = NULL, **loc2p; | |
2297 | int null_condition_or_parse_error = 0; | |
2298 | int modified = bl->needs_update; | |
2299 | struct bp_location *loc; | |
2300 | ||
8b4f3082 PA |
2301 | /* Release conditions left over from a previous insert. */ |
2302 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2303 | ||
b775012e LM |
2304 | /* This is only meaningful if the target is |
2305 | evaluating conditions and if the user has | |
2306 | opted for condition evaluation on the target's | |
2307 | side. */ | |
2308 | if (gdb_evaluates_breakpoint_condition_p () | |
2309 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2310 | return; | |
2311 | ||
2312 | /* Do a first pass to check for locations with no assigned | |
2313 | conditions or conditions that fail to parse to a valid agent expression | |
2314 | bytecode. If any of these happen, then it's no use to send conditions | |
2315 | to the target since this location will always trigger and generate a | |
2316 | response back to GDB. */ | |
2317 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2318 | { | |
2319 | loc = (*loc2p); | |
2320 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2321 | { | |
2322 | if (modified) | |
2323 | { | |
2324 | struct agent_expr *aexpr; | |
2325 | ||
2326 | /* Re-parse the conditions since something changed. In that | |
2327 | case we already freed the condition bytecodes (see | |
2328 | force_breakpoint_reinsertion). We just | |
2329 | need to parse the condition to bytecodes again. */ | |
4d01a485 | 2330 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond.get ()); |
b775012e | 2331 | loc->cond_bytecode = aexpr; |
b775012e LM |
2332 | } |
2333 | ||
2334 | /* If we have a NULL bytecode expression, it means something | |
2335 | went wrong or we have a null condition expression. */ | |
2336 | if (!loc->cond_bytecode) | |
2337 | { | |
2338 | null_condition_or_parse_error = 1; | |
2339 | break; | |
2340 | } | |
2341 | } | |
2342 | } | |
2343 | ||
2344 | /* If any of these happened, it means we will have to evaluate the conditions | |
2345 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2346 | for all the other duplicate locations, thus we free all of them here. | |
2347 | ||
2348 | This is so we have a finer control over which locations' conditions are | |
2349 | being evaluated by GDB or the remote stub. */ | |
2350 | if (null_condition_or_parse_error) | |
2351 | { | |
2352 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2353 | { | |
2354 | loc = (*loc2p); | |
2355 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2356 | { | |
2357 | /* Only go as far as the first NULL bytecode is | |
2358 | located. */ | |
2359 | if (!loc->cond_bytecode) | |
2360 | return; | |
2361 | ||
2362 | free_agent_expr (loc->cond_bytecode); | |
2363 | loc->cond_bytecode = NULL; | |
2364 | } | |
2365 | } | |
2366 | } | |
2367 | ||
2368 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2369 | for this location's address. */ | |
2370 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2371 | { | |
2372 | loc = (*loc2p); | |
2373 | if (loc->cond | |
2374 | && is_breakpoint (loc->owner) | |
2375 | && loc->pspace->num == bl->pspace->num | |
2376 | && loc->owner->enable_state == bp_enabled | |
2377 | && loc->enabled) | |
2378 | /* Add the condition to the vector. This will be used later to send the | |
2379 | conditions to the target. */ | |
2380 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2381 | loc->cond_bytecode); | |
2382 | } | |
2383 | ||
2384 | return; | |
2385 | } | |
2386 | ||
d3ce09f5 SS |
2387 | /* Parses a command described by string CMD into an agent expression |
2388 | bytecode suitable for evaluation by the bytecode interpreter. | |
2389 | Return NULL if there was any error during parsing. */ | |
2390 | ||
2391 | static struct agent_expr * | |
2392 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2393 | { | |
2394 | struct cleanup *old_cleanups = 0; | |
4d01a485 | 2395 | struct expression **argvec; |
d3ce09f5 | 2396 | struct agent_expr *aexpr = NULL; |
bbc13ae3 KS |
2397 | const char *cmdrest; |
2398 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2399 | struct format_piece *fpieces; |
2400 | int nargs; | |
2401 | struct gdbarch *gdbarch = get_current_arch (); | |
2402 | ||
2403 | if (!cmd) | |
2404 | return NULL; | |
2405 | ||
2406 | cmdrest = cmd; | |
2407 | ||
2408 | if (*cmdrest == ',') | |
2409 | ++cmdrest; | |
bbc13ae3 | 2410 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2411 | |
2412 | if (*cmdrest++ != '"') | |
2413 | error (_("No format string following the location")); | |
2414 | ||
2415 | format_start = cmdrest; | |
2416 | ||
2417 | fpieces = parse_format_string (&cmdrest); | |
2418 | ||
2419 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2420 | ||
2421 | format_end = cmdrest; | |
2422 | ||
2423 | if (*cmdrest++ != '"') | |
2424 | error (_("Bad format string, non-terminated '\"'.")); | |
2425 | ||
bbc13ae3 | 2426 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2427 | |
2428 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2429 | error (_("Invalid argument syntax")); | |
2430 | ||
2431 | if (*cmdrest == ',') | |
2432 | cmdrest++; | |
bbc13ae3 | 2433 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2434 | |
2435 | /* For each argument, make an expression. */ | |
2436 | ||
2437 | argvec = (struct expression **) alloca (strlen (cmd) | |
2438 | * sizeof (struct expression *)); | |
2439 | ||
2440 | nargs = 0; | |
2441 | while (*cmdrest != '\0') | |
2442 | { | |
bbc13ae3 | 2443 | const char *cmd1; |
d3ce09f5 SS |
2444 | |
2445 | cmd1 = cmdrest; | |
4d01a485 PA |
2446 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
2447 | argvec[nargs++] = expr.release (); | |
d3ce09f5 SS |
2448 | cmdrest = cmd1; |
2449 | if (*cmdrest == ',') | |
2450 | ++cmdrest; | |
2451 | } | |
2452 | ||
2453 | /* We don't want to stop processing, so catch any errors | |
2454 | that may show up. */ | |
492d29ea | 2455 | TRY |
d3ce09f5 SS |
2456 | { |
2457 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2458 | format_start, format_end - format_start, | |
2459 | fpieces, nargs, argvec); | |
2460 | } | |
492d29ea | 2461 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2462 | { |
2463 | /* If we got here, it means the command could not be parsed to a valid | |
2464 | bytecode expression and thus can't be evaluated on the target's side. | |
2465 | It's no use iterating through the other commands. */ | |
492d29ea | 2466 | aexpr = NULL; |
d3ce09f5 | 2467 | } |
492d29ea PA |
2468 | END_CATCH |
2469 | ||
2470 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2471 | |
d3ce09f5 SS |
2472 | /* We have a valid agent expression, return it. */ |
2473 | return aexpr; | |
2474 | } | |
2475 | ||
2476 | /* Based on location BL, create a list of breakpoint commands to be | |
2477 | passed on to the target. If we have duplicated locations with | |
2478 | different commands, we will add any such to the list. */ | |
2479 | ||
2480 | static void | |
2481 | build_target_command_list (struct bp_location *bl) | |
2482 | { | |
2483 | struct bp_location **locp = NULL, **loc2p; | |
2484 | int null_command_or_parse_error = 0; | |
2485 | int modified = bl->needs_update; | |
2486 | struct bp_location *loc; | |
2487 | ||
8b4f3082 PA |
2488 | /* Release commands left over from a previous insert. */ |
2489 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2490 | ||
41fac0cf | 2491 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2492 | return; |
2493 | ||
41fac0cf PA |
2494 | /* For now, limit to agent-style dprintf breakpoints. */ |
2495 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2496 | return; |
2497 | ||
41fac0cf PA |
2498 | /* For now, if we have any duplicate location that isn't a dprintf, |
2499 | don't install the target-side commands, as that would make the | |
2500 | breakpoint not be reported to the core, and we'd lose | |
2501 | control. */ | |
2502 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2503 | { | |
2504 | loc = (*loc2p); | |
2505 | if (is_breakpoint (loc->owner) | |
2506 | && loc->pspace->num == bl->pspace->num | |
2507 | && loc->owner->type != bp_dprintf) | |
2508 | return; | |
2509 | } | |
2510 | ||
d3ce09f5 SS |
2511 | /* Do a first pass to check for locations with no assigned |
2512 | conditions or conditions that fail to parse to a valid agent expression | |
2513 | bytecode. If any of these happen, then it's no use to send conditions | |
2514 | to the target since this location will always trigger and generate a | |
2515 | response back to GDB. */ | |
2516 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2517 | { | |
2518 | loc = (*loc2p); | |
2519 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2520 | { | |
2521 | if (modified) | |
2522 | { | |
2523 | struct agent_expr *aexpr; | |
2524 | ||
2525 | /* Re-parse the commands since something changed. In that | |
2526 | case we already freed the command bytecodes (see | |
2527 | force_breakpoint_reinsertion). We just | |
2528 | need to parse the command to bytecodes again. */ | |
2529 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2530 | loc->owner->extra_string); | |
2531 | loc->cmd_bytecode = aexpr; | |
d3ce09f5 SS |
2532 | } |
2533 | ||
2534 | /* If we have a NULL bytecode expression, it means something | |
2535 | went wrong or we have a null command expression. */ | |
2536 | if (!loc->cmd_bytecode) | |
2537 | { | |
2538 | null_command_or_parse_error = 1; | |
2539 | break; | |
2540 | } | |
2541 | } | |
2542 | } | |
2543 | ||
2544 | /* If anything failed, then we're not doing target-side commands, | |
2545 | and so clean up. */ | |
2546 | if (null_command_or_parse_error) | |
2547 | { | |
2548 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2549 | { | |
2550 | loc = (*loc2p); | |
2551 | if (is_breakpoint (loc->owner) | |
2552 | && loc->pspace->num == bl->pspace->num) | |
2553 | { | |
2554 | /* Only go as far as the first NULL bytecode is | |
2555 | located. */ | |
40fb6c5e | 2556 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2557 | return; |
2558 | ||
40fb6c5e HZ |
2559 | free_agent_expr (loc->cmd_bytecode); |
2560 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2561 | } |
2562 | } | |
2563 | } | |
2564 | ||
2565 | /* No NULL commands or failed bytecode generation. Build a command list | |
2566 | for this location's address. */ | |
2567 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2568 | { | |
2569 | loc = (*loc2p); | |
2570 | if (loc->owner->extra_string | |
2571 | && is_breakpoint (loc->owner) | |
2572 | && loc->pspace->num == bl->pspace->num | |
2573 | && loc->owner->enable_state == bp_enabled | |
2574 | && loc->enabled) | |
2575 | /* Add the command to the vector. This will be used later | |
2576 | to send the commands to the target. */ | |
2577 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2578 | loc->cmd_bytecode); | |
2579 | } | |
2580 | ||
2581 | bl->target_info.persist = 0; | |
2582 | /* Maybe flag this location as persistent. */ | |
2583 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2584 | bl->target_info.persist = 1; | |
2585 | } | |
2586 | ||
833b7ab5 YQ |
2587 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2588 | of breakpoint according to ADDR except single-step breakpoint. | |
2589 | Get the kind of single-step breakpoint according to the current | |
2590 | registers state. */ | |
cd6c3b4f YQ |
2591 | |
2592 | static int | |
2593 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2594 | { | |
833b7ab5 YQ |
2595 | if (bl->owner->type == bp_single_step) |
2596 | { | |
2597 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2598 | struct regcache *regcache; | |
2599 | ||
2600 | regcache = get_thread_regcache (thr->ptid); | |
2601 | ||
2602 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2603 | regcache, addr); | |
2604 | } | |
2605 | else | |
2606 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2607 | } |
2608 | ||
35df4500 TJB |
2609 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2610 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2611 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2612 | Returns 0 for success, 1 if the bp_location type is not supported or |
2613 | -1 for failure. | |
879bfdc2 | 2614 | |
4a64f543 MS |
2615 | NOTE drow/2003-09-09: This routine could be broken down to an |
2616 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2617 | static int |
35df4500 | 2618 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2619 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2620 | int *disabled_breaks, |
dd61ec5c MW |
2621 | int *hw_breakpoint_error, |
2622 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2623 | { |
0000e5cc PA |
2624 | enum errors bp_err = GDB_NO_ERROR; |
2625 | const char *bp_err_message = NULL; | |
879bfdc2 | 2626 | |
b775012e | 2627 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2628 | return 0; |
2629 | ||
35c63cd8 JB |
2630 | /* Note we don't initialize bl->target_info, as that wipes out |
2631 | the breakpoint location's shadow_contents if the breakpoint | |
2632 | is still inserted at that location. This in turn breaks | |
2633 | target_read_memory which depends on these buffers when | |
2634 | a memory read is requested at the breakpoint location: | |
2635 | Once the target_info has been wiped, we fail to see that | |
2636 | we have a breakpoint inserted at that address and thus | |
2637 | read the breakpoint instead of returning the data saved in | |
2638 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2639 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2640 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2641 | bl->target_info.length = bl->length; |
8181d85f | 2642 | |
b775012e LM |
2643 | /* When working with target-side conditions, we must pass all the conditions |
2644 | for the same breakpoint address down to the target since GDB will not | |
2645 | insert those locations. With a list of breakpoint conditions, the target | |
2646 | can decide when to stop and notify GDB. */ | |
2647 | ||
2648 | if (is_breakpoint (bl->owner)) | |
2649 | { | |
2650 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2651 | build_target_command_list (bl); |
2652 | /* Reset the modification marker. */ | |
b775012e LM |
2653 | bl->needs_update = 0; |
2654 | } | |
2655 | ||
35df4500 TJB |
2656 | if (bl->loc_type == bp_loc_software_breakpoint |
2657 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2658 | { |
35df4500 | 2659 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2660 | { |
2661 | /* If the explicitly specified breakpoint type | |
2662 | is not hardware breakpoint, check the memory map to see | |
2663 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2664 | |
765dc015 VP |
2665 | Two important cases are: |
2666 | - location type is not hardware breakpoint, memory | |
2667 | is readonly. We change the type of the location to | |
2668 | hardware breakpoint. | |
4a64f543 MS |
2669 | - location type is hardware breakpoint, memory is |
2670 | read-write. This means we've previously made the | |
2671 | location hardware one, but then the memory map changed, | |
2672 | so we undo. | |
765dc015 | 2673 | |
4a64f543 MS |
2674 | When breakpoints are removed, remove_breakpoints will use |
2675 | location types we've just set here, the only possible | |
2676 | problem is that memory map has changed during running | |
2677 | program, but it's not going to work anyway with current | |
2678 | gdb. */ | |
765dc015 | 2679 | struct mem_region *mr |
0d5ed153 | 2680 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2681 | |
2682 | if (mr) | |
2683 | { | |
2684 | if (automatic_hardware_breakpoints) | |
2685 | { | |
765dc015 VP |
2686 | enum bp_loc_type new_type; |
2687 | ||
2688 | if (mr->attrib.mode != MEM_RW) | |
2689 | new_type = bp_loc_hardware_breakpoint; | |
2690 | else | |
2691 | new_type = bp_loc_software_breakpoint; | |
2692 | ||
35df4500 | 2693 | if (new_type != bl->loc_type) |
765dc015 VP |
2694 | { |
2695 | static int said = 0; | |
cc59ec59 | 2696 | |
35df4500 | 2697 | bl->loc_type = new_type; |
765dc015 VP |
2698 | if (!said) |
2699 | { | |
3e43a32a MS |
2700 | fprintf_filtered (gdb_stdout, |
2701 | _("Note: automatically using " | |
2702 | "hardware breakpoints for " | |
2703 | "read-only addresses.\n")); | |
765dc015 VP |
2704 | said = 1; |
2705 | } | |
2706 | } | |
2707 | } | |
35df4500 | 2708 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2709 | && mr->attrib.mode != MEM_RW) |
2710 | { | |
2711 | fprintf_unfiltered (tmp_error_stream, | |
2712 | _("Cannot insert breakpoint %d.\n" | |
2713 | "Cannot set software breakpoint " | |
2714 | "at read-only address %s\n"), | |
2715 | bl->owner->number, | |
2716 | paddress (bl->gdbarch, bl->address)); | |
2717 | return 1; | |
2718 | } | |
765dc015 VP |
2719 | } |
2720 | } | |
2721 | ||
879bfdc2 DJ |
2722 | /* First check to see if we have to handle an overlay. */ |
2723 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2724 | || bl->section == NULL |
2725 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2726 | { |
2727 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2728 | TRY |
dd61ec5c | 2729 | { |
0000e5cc PA |
2730 | int val; |
2731 | ||
dd61ec5c | 2732 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2733 | if (val) |
2734 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2735 | } |
492d29ea | 2736 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2737 | { |
0000e5cc PA |
2738 | bp_err = e.error; |
2739 | bp_err_message = e.message; | |
dd61ec5c | 2740 | } |
492d29ea | 2741 | END_CATCH |
879bfdc2 DJ |
2742 | } |
2743 | else | |
2744 | { | |
4a64f543 | 2745 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2746 | Shall we set a breakpoint at the LMA? */ |
2747 | if (!overlay_events_enabled) | |
2748 | { | |
2749 | /* Yes -- overlay event support is not active, | |
2750 | so we must try to set a breakpoint at the LMA. | |
2751 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2752 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2753 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2754 | bl->owner->number); |
879bfdc2 DJ |
2755 | else |
2756 | { | |
35df4500 TJB |
2757 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2758 | bl->section); | |
879bfdc2 | 2759 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2760 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2761 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2762 | |
2763 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2764 | TRY |
0000e5cc PA |
2765 | { |
2766 | int val; | |
2767 | ||
579c6ad9 | 2768 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2769 | = breakpoint_kind (bl, &addr); |
2770 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2771 | val = target_insert_breakpoint (bl->gdbarch, |
2772 | &bl->overlay_target_info); | |
2773 | if (val) | |
2774 | bp_err = GENERIC_ERROR; | |
2775 | } | |
492d29ea | 2776 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2777 | { |
2778 | bp_err = e.error; | |
2779 | bp_err_message = e.message; | |
2780 | } | |
492d29ea | 2781 | END_CATCH |
0000e5cc PA |
2782 | |
2783 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2784 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2785 | "Overlay breakpoint %d " |
2786 | "failed: in ROM?\n", | |
35df4500 | 2787 | bl->owner->number); |
879bfdc2 DJ |
2788 | } |
2789 | } | |
2790 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2791 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2792 | { |
2793 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2794 | TRY |
dd61ec5c | 2795 | { |
0000e5cc PA |
2796 | int val; |
2797 | ||
dd61ec5c | 2798 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2799 | if (val) |
2800 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2801 | } |
492d29ea | 2802 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2803 | { |
0000e5cc PA |
2804 | bp_err = e.error; |
2805 | bp_err_message = e.message; | |
dd61ec5c | 2806 | } |
492d29ea | 2807 | END_CATCH |
879bfdc2 DJ |
2808 | } |
2809 | else | |
2810 | { | |
2811 | /* No. This breakpoint will not be inserted. | |
2812 | No error, but do not mark the bp as 'inserted'. */ | |
2813 | return 0; | |
2814 | } | |
2815 | } | |
2816 | ||
0000e5cc | 2817 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2818 | { |
2819 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2820 | |
2821 | /* In some cases, we might not be able to insert a | |
2822 | breakpoint in a shared library that has already been | |
2823 | removed, but we have not yet processed the shlib unload | |
2824 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2825 | breakpoint insertion themselves can't tell why the |
2826 | breakpoint insertion failed (e.g., the remote target | |
2827 | doesn't define error codes), so we must treat generic | |
2828 | errors as memory errors. */ | |
0000e5cc | 2829 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2830 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2831 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2832 | || shared_objfile_contains_address_p (bl->pspace, |
2833 | bl->address))) | |
879bfdc2 | 2834 | { |
4a64f543 | 2835 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2836 | bl->shlib_disabled = 1; |
8d3788bd | 2837 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2838 | if (!*disabled_breaks) |
2839 | { | |
2840 | fprintf_unfiltered (tmp_error_stream, | |
2841 | "Cannot insert breakpoint %d.\n", | |
2842 | bl->owner->number); | |
2843 | fprintf_unfiltered (tmp_error_stream, | |
2844 | "Temporarily disabling shared " | |
2845 | "library breakpoints:\n"); | |
2846 | } | |
2847 | *disabled_breaks = 1; | |
879bfdc2 | 2848 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2849 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2850 | return 0; |
879bfdc2 DJ |
2851 | } |
2852 | else | |
879bfdc2 | 2853 | { |
35df4500 | 2854 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2855 | { |
0000e5cc PA |
2856 | *hw_breakpoint_error = 1; |
2857 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2858 | fprintf_unfiltered (tmp_error_stream, |
2859 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2860 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2861 | if (bp_err_message != NULL) | |
2862 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2863 | } |
2864 | else | |
2865 | { | |
0000e5cc PA |
2866 | if (bp_err_message == NULL) |
2867 | { | |
2868 | char *message | |
2869 | = memory_error_message (TARGET_XFER_E_IO, | |
2870 | bl->gdbarch, bl->address); | |
2871 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2872 | ||
2873 | fprintf_unfiltered (tmp_error_stream, | |
2874 | "Cannot insert breakpoint %d.\n" | |
2875 | "%s\n", | |
2876 | bl->owner->number, message); | |
2877 | do_cleanups (old_chain); | |
2878 | } | |
2879 | else | |
2880 | { | |
2881 | fprintf_unfiltered (tmp_error_stream, | |
2882 | "Cannot insert breakpoint %d: %s\n", | |
2883 | bl->owner->number, | |
2884 | bp_err_message); | |
2885 | } | |
879bfdc2 | 2886 | } |
0000e5cc | 2887 | return 1; |
879bfdc2 DJ |
2888 | |
2889 | } | |
2890 | } | |
2891 | else | |
35df4500 | 2892 | bl->inserted = 1; |
879bfdc2 | 2893 | |
0000e5cc | 2894 | return 0; |
879bfdc2 DJ |
2895 | } |
2896 | ||
35df4500 | 2897 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2898 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2899 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2900 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2901 | { |
0000e5cc PA |
2902 | int val; |
2903 | ||
77b06cd7 TJB |
2904 | gdb_assert (bl->owner->ops != NULL |
2905 | && bl->owner->ops->insert_location != NULL); | |
2906 | ||
2907 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2908 | |
2909 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2910 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2911 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2912 | { |
2913 | struct bp_location *loc, **loc_temp; | |
2914 | ||
2915 | /* But don't try to insert it, if there's already another | |
2916 | hw_access location that would be considered a duplicate | |
2917 | of this one. */ | |
2918 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2919 | if (loc != bl |
85d721b8 | 2920 | && loc->watchpoint_type == hw_access |
35df4500 | 2921 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2922 | { |
35df4500 TJB |
2923 | bl->duplicate = 1; |
2924 | bl->inserted = 1; | |
2925 | bl->target_info = loc->target_info; | |
2926 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2927 | val = 0; |
2928 | break; | |
2929 | } | |
2930 | ||
2931 | if (val == 1) | |
2932 | { | |
77b06cd7 TJB |
2933 | bl->watchpoint_type = hw_access; |
2934 | val = bl->owner->ops->insert_location (bl); | |
2935 | ||
2936 | if (val) | |
2937 | /* Back to the original value. */ | |
2938 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2939 | } |
2940 | } | |
2941 | ||
35df4500 | 2942 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2943 | } |
2944 | ||
35df4500 | 2945 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2946 | { |
0000e5cc PA |
2947 | int val; |
2948 | ||
77b06cd7 TJB |
2949 | gdb_assert (bl->owner->ops != NULL |
2950 | && bl->owner->ops->insert_location != NULL); | |
2951 | ||
2952 | val = bl->owner->ops->insert_location (bl); | |
2953 | if (val) | |
2954 | { | |
2955 | bl->owner->enable_state = bp_disabled; | |
2956 | ||
2957 | if (val == 1) | |
2958 | warning (_("\ | |
2959 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2960 | of catchpoint."), bl->owner->number); | |
2961 | else | |
2962 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2963 | } | |
2964 | ||
2965 | bl->inserted = (val == 0); | |
1640b821 DJ |
2966 | |
2967 | /* We've already printed an error message if there was a problem | |
2968 | inserting this catchpoint, and we've disabled the catchpoint, | |
2969 | so just return success. */ | |
2970 | return 0; | |
879bfdc2 DJ |
2971 | } |
2972 | ||
2973 | return 0; | |
2974 | } | |
2975 | ||
6c95b8df PA |
2976 | /* This function is called when program space PSPACE is about to be |
2977 | deleted. It takes care of updating breakpoints to not reference | |
2978 | PSPACE anymore. */ | |
2979 | ||
2980 | void | |
2981 | breakpoint_program_space_exit (struct program_space *pspace) | |
2982 | { | |
2983 | struct breakpoint *b, *b_temp; | |
876fa593 | 2984 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2985 | |
2986 | /* Remove any breakpoint that was set through this program space. */ | |
2987 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2988 | { | |
2989 | if (b->pspace == pspace) | |
2990 | delete_breakpoint (b); | |
2991 | } | |
2992 | ||
2993 | /* Breakpoints set through other program spaces could have locations | |
2994 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2995 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2996 | { |
2997 | struct bp_location *tmp; | |
2998 | ||
2999 | if (loc->pspace == pspace) | |
3000 | { | |
2bdf28a0 | 3001 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
3002 | if (loc->owner->loc == loc) |
3003 | loc->owner->loc = loc->next; | |
3004 | else | |
3005 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3006 | if (tmp->next == loc) | |
3007 | { | |
3008 | tmp->next = loc->next; | |
3009 | break; | |
3010 | } | |
3011 | } | |
3012 | } | |
3013 | ||
3014 | /* Now update the global location list to permanently delete the | |
3015 | removed locations above. */ | |
44702360 | 3016 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3017 | } |
3018 | ||
74960c60 VP |
3019 | /* Make sure all breakpoints are inserted in inferior. |
3020 | Throws exception on any error. | |
3021 | A breakpoint that is already inserted won't be inserted | |
3022 | again, so calling this function twice is safe. */ | |
3023 | void | |
3024 | insert_breakpoints (void) | |
3025 | { | |
3026 | struct breakpoint *bpt; | |
3027 | ||
3028 | ALL_BREAKPOINTS (bpt) | |
3029 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3030 | { |
3031 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3032 | ||
3033 | update_watchpoint (w, 0 /* don't reparse. */); | |
3034 | } | |
74960c60 | 3035 | |
04086b45 PA |
3036 | /* Updating watchpoints creates new locations, so update the global |
3037 | location list. Explicitly tell ugll to insert locations and | |
3038 | ignore breakpoints_always_inserted_mode. */ | |
3039 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3040 | } |
3041 | ||
20388dd6 YQ |
3042 | /* Invoke CALLBACK for each of bp_location. */ |
3043 | ||
3044 | void | |
3045 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3046 | { | |
3047 | struct bp_location *loc, **loc_tmp; | |
3048 | ||
3049 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3050 | { | |
3051 | callback (loc, NULL); | |
3052 | } | |
3053 | } | |
3054 | ||
b775012e LM |
3055 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3056 | target. It is the case with deleting and disabling of breakpoints when using | |
3057 | always-inserted mode. */ | |
3058 | ||
3059 | static void | |
3060 | update_inserted_breakpoint_locations (void) | |
3061 | { | |
3062 | struct bp_location *bl, **blp_tmp; | |
3063 | int error_flag = 0; | |
3064 | int val = 0; | |
3065 | int disabled_breaks = 0; | |
3066 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3067 | int hw_bp_details_reported = 0; |
b775012e LM |
3068 | |
3069 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3070 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3071 | ||
3072 | /* Explicitly mark the warning -- this will only be printed if | |
3073 | there was an error. */ | |
3074 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3075 | ||
3076 | save_current_space_and_thread (); | |
3077 | ||
3078 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3079 | { | |
3080 | /* We only want to update software breakpoints and hardware | |
3081 | breakpoints. */ | |
3082 | if (!is_breakpoint (bl->owner)) | |
3083 | continue; | |
3084 | ||
3085 | /* We only want to update locations that are already inserted | |
3086 | and need updating. This is to avoid unwanted insertion during | |
3087 | deletion of breakpoints. */ | |
3088 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3089 | continue; | |
3090 | ||
3091 | switch_to_program_space_and_thread (bl->pspace); | |
3092 | ||
3093 | /* For targets that support global breakpoints, there's no need | |
3094 | to select an inferior to insert breakpoint to. In fact, even | |
3095 | if we aren't attached to any process yet, we should still | |
3096 | insert breakpoints. */ | |
f5656ead | 3097 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3098 | && ptid_equal (inferior_ptid, null_ptid)) |
3099 | continue; | |
3100 | ||
3101 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3102 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3103 | if (val) |
3104 | error_flag = val; | |
3105 | } | |
3106 | ||
3107 | if (error_flag) | |
3108 | { | |
3109 | target_terminal_ours_for_output (); | |
3110 | error_stream (tmp_error_stream); | |
3111 | } | |
3112 | ||
3113 | do_cleanups (cleanups); | |
3114 | } | |
3115 | ||
c30eee59 | 3116 | /* Used when starting or continuing the program. */ |
c906108c | 3117 | |
74960c60 VP |
3118 | static void |
3119 | insert_breakpoint_locations (void) | |
c906108c | 3120 | { |
a5606eee | 3121 | struct breakpoint *bpt; |
35df4500 | 3122 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3123 | int error_flag = 0; |
c906108c | 3124 | int val = 0; |
3fbb6ffa | 3125 | int disabled_breaks = 0; |
81d0cc19 | 3126 | int hw_breakpoint_error = 0; |
dd61ec5c | 3127 | int hw_bp_error_explained_already = 0; |
c906108c | 3128 | |
81d0cc19 | 3129 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3130 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3131 | |
81d0cc19 GS |
3132 | /* Explicitly mark the warning -- this will only be printed if |
3133 | there was an error. */ | |
3134 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3135 | |
3136 | save_current_space_and_thread (); | |
3137 | ||
35df4500 | 3138 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3139 | { |
b775012e | 3140 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3141 | continue; |
3142 | ||
4a64f543 MS |
3143 | /* There is no point inserting thread-specific breakpoints if |
3144 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3145 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3146 | if (bl->owner->thread != -1 |
5d5658a1 | 3147 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3148 | continue; |
3149 | ||
35df4500 | 3150 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3151 | |
3152 | /* For targets that support global breakpoints, there's no need | |
3153 | to select an inferior to insert breakpoint to. In fact, even | |
3154 | if we aren't attached to any process yet, we should still | |
3155 | insert breakpoints. */ | |
f5656ead | 3156 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3157 | && ptid_equal (inferior_ptid, null_ptid)) |
3158 | continue; | |
3159 | ||
3fbb6ffa | 3160 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3161 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3162 | if (val) |
eacd795a | 3163 | error_flag = val; |
879bfdc2 | 3164 | } |
c906108c | 3165 | |
4a64f543 MS |
3166 | /* If we failed to insert all locations of a watchpoint, remove |
3167 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3168 | ALL_BREAKPOINTS (bpt) |
3169 | { | |
3170 | int some_failed = 0; | |
3171 | struct bp_location *loc; | |
3172 | ||
3173 | if (!is_hardware_watchpoint (bpt)) | |
3174 | continue; | |
3175 | ||
d6b74ac4 | 3176 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3177 | continue; |
74960c60 VP |
3178 | |
3179 | if (bpt->disposition == disp_del_at_next_stop) | |
3180 | continue; | |
a5606eee VP |
3181 | |
3182 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3183 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3184 | { |
3185 | some_failed = 1; | |
3186 | break; | |
3187 | } | |
3188 | if (some_failed) | |
3189 | { | |
3190 | for (loc = bpt->loc; loc; loc = loc->next) | |
3191 | if (loc->inserted) | |
834c0d03 | 3192 | remove_breakpoint (loc); |
a5606eee VP |
3193 | |
3194 | hw_breakpoint_error = 1; | |
3195 | fprintf_unfiltered (tmp_error_stream, | |
3196 | "Could not insert hardware watchpoint %d.\n", | |
3197 | bpt->number); | |
eacd795a | 3198 | error_flag = -1; |
a5606eee VP |
3199 | } |
3200 | } | |
3201 | ||
eacd795a | 3202 | if (error_flag) |
81d0cc19 GS |
3203 | { |
3204 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3205 | message about possibly exhausted resources. */ | |
dd61ec5c | 3206 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3207 | { |
c6510018 MS |
3208 | fprintf_unfiltered (tmp_error_stream, |
3209 | "Could not insert hardware breakpoints:\n\ | |
3210 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3211 | } |
81d0cc19 GS |
3212 | target_terminal_ours_for_output (); |
3213 | error_stream (tmp_error_stream); | |
3214 | } | |
f7545552 TT |
3215 | |
3216 | do_cleanups (cleanups); | |
c906108c SS |
3217 | } |
3218 | ||
c30eee59 TJB |
3219 | /* Used when the program stops. |
3220 | Returns zero if successful, or non-zero if there was a problem | |
3221 | removing a breakpoint location. */ | |
3222 | ||
c906108c | 3223 | int |
fba45db2 | 3224 | remove_breakpoints (void) |
c906108c | 3225 | { |
35df4500 | 3226 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3227 | int val = 0; |
c906108c | 3228 | |
35df4500 | 3229 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3230 | { |
1e4d1764 | 3231 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3232 | val |= remove_breakpoint (bl); |
c5aa993b | 3233 | } |
3a1bae8e | 3234 | return val; |
c906108c SS |
3235 | } |
3236 | ||
49fa26b0 PA |
3237 | /* When a thread exits, remove breakpoints that are related to |
3238 | that thread. */ | |
3239 | ||
3240 | static void | |
3241 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3242 | { | |
3243 | struct breakpoint *b, *b_tmp; | |
3244 | ||
3245 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3246 | { | |
5d5658a1 | 3247 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3248 | { |
3249 | b->disposition = disp_del_at_next_stop; | |
3250 | ||
3251 | printf_filtered (_("\ | |
43792cf0 PA |
3252 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3253 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3254 | |
3255 | /* Hide it from the user. */ | |
3256 | b->number = 0; | |
3257 | } | |
3258 | } | |
3259 | } | |
3260 | ||
6c95b8df PA |
3261 | /* Remove breakpoints of process PID. */ |
3262 | ||
3263 | int | |
3264 | remove_breakpoints_pid (int pid) | |
3265 | { | |
35df4500 | 3266 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3267 | int val; |
3268 | struct inferior *inf = find_inferior_pid (pid); | |
3269 | ||
35df4500 | 3270 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3271 | { |
35df4500 | 3272 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3273 | continue; |
3274 | ||
fc126975 | 3275 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3276 | { |
834c0d03 | 3277 | val = remove_breakpoint (bl); |
6c95b8df PA |
3278 | if (val != 0) |
3279 | return val; | |
3280 | } | |
3281 | } | |
3282 | return 0; | |
3283 | } | |
3284 | ||
c906108c | 3285 | int |
fba45db2 | 3286 | reattach_breakpoints (int pid) |
c906108c | 3287 | { |
6c95b8df | 3288 | struct cleanup *old_chain; |
35df4500 | 3289 | struct bp_location *bl, **blp_tmp; |
c906108c | 3290 | int val; |
86b887df | 3291 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3292 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3293 | struct inferior *inf; |
3294 | struct thread_info *tp; | |
3295 | ||
3296 | tp = any_live_thread_of_process (pid); | |
3297 | if (tp == NULL) | |
3298 | return 1; | |
3299 | ||
3300 | inf = find_inferior_pid (pid); | |
3301 | old_chain = save_inferior_ptid (); | |
3302 | ||
3303 | inferior_ptid = tp->ptid; | |
a4954f26 | 3304 | |
86b887df | 3305 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3306 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3307 | |
35df4500 | 3308 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3309 | { |
35df4500 | 3310 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3311 | continue; |
3312 | ||
35df4500 | 3313 | if (bl->inserted) |
c5aa993b | 3314 | { |
35df4500 | 3315 | bl->inserted = 0; |
dd61ec5c | 3316 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3317 | if (val != 0) |
3318 | { | |
ce696e05 | 3319 | do_cleanups (old_chain); |
c5aa993b JM |
3320 | return val; |
3321 | } | |
3322 | } | |
3323 | } | |
ce696e05 | 3324 | do_cleanups (old_chain); |
c906108c SS |
3325 | return 0; |
3326 | } | |
3327 | ||
e58b0e63 PA |
3328 | static int internal_breakpoint_number = -1; |
3329 | ||
84f4c1fe PM |
3330 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3331 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3332 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3333 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3334 | breakpoint_count and that value incremented. Internal breakpoints |
3335 | do not set the internal var bpnum. */ | |
3336 | static void | |
3337 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3338 | { | |
3339 | if (internal) | |
3340 | b->number = internal_breakpoint_number--; | |
3341 | else | |
3342 | { | |
3343 | set_breakpoint_count (breakpoint_count + 1); | |
3344 | b->number = breakpoint_count; | |
3345 | } | |
3346 | } | |
3347 | ||
e62c965a | 3348 | static struct breakpoint * |
a6d9a66e | 3349 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3350 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3351 | const struct breakpoint_ops *ops) |
e62c965a | 3352 | { |
e62c965a PP |
3353 | struct symtab_and_line sal; |
3354 | struct breakpoint *b; | |
3355 | ||
4a64f543 | 3356 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3357 | |
3358 | sal.pc = address; | |
3359 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3360 | sal.pspace = current_program_space; |
e62c965a | 3361 | |
06edf0c0 | 3362 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3363 | b->number = internal_breakpoint_number--; |
3364 | b->disposition = disp_donttouch; | |
3365 | ||
3366 | return b; | |
3367 | } | |
3368 | ||
17450429 PP |
3369 | static const char *const longjmp_names[] = |
3370 | { | |
3371 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3372 | }; | |
3373 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3374 | ||
3375 | /* Per-objfile data private to breakpoint.c. */ | |
3376 | struct breakpoint_objfile_data | |
3377 | { | |
3378 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3379 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3380 | |
3381 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3382 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3383 | |
28106bc2 SDJ |
3384 | /* True if we have looked for longjmp probes. */ |
3385 | int longjmp_searched; | |
3386 | ||
3387 | /* SystemTap probe points for longjmp (if any). */ | |
3388 | VEC (probe_p) *longjmp_probes; | |
3389 | ||
17450429 | 3390 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3391 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3392 | |
3393 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3394 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3395 | |
3396 | /* True if we have looked for exception probes. */ | |
3397 | int exception_searched; | |
3398 | ||
3399 | /* SystemTap probe points for unwinding (if any). */ | |
3400 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3401 | }; |
3402 | ||
3403 | static const struct objfile_data *breakpoint_objfile_key; | |
3404 | ||
3405 | /* Minimal symbol not found sentinel. */ | |
3406 | static struct minimal_symbol msym_not_found; | |
3407 | ||
3408 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3409 | ||
3410 | static int | |
3411 | msym_not_found_p (const struct minimal_symbol *msym) | |
3412 | { | |
3413 | return msym == &msym_not_found; | |
3414 | } | |
3415 | ||
3416 | /* Return per-objfile data needed by breakpoint.c. | |
3417 | Allocate the data if necessary. */ | |
3418 | ||
3419 | static struct breakpoint_objfile_data * | |
3420 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3421 | { | |
3422 | struct breakpoint_objfile_data *bp_objfile_data; | |
3423 | ||
9a3c8263 SM |
3424 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3425 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3426 | if (bp_objfile_data == NULL) |
3427 | { | |
8d749320 SM |
3428 | bp_objfile_data = |
3429 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3430 | |
3431 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3432 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3433 | } | |
3434 | return bp_objfile_data; | |
3435 | } | |
3436 | ||
28106bc2 SDJ |
3437 | static void |
3438 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3439 | { | |
9a3c8263 SM |
3440 | struct breakpoint_objfile_data *bp_objfile_data |
3441 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3442 | |
3443 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3444 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3445 | } | |
3446 | ||
e62c965a | 3447 | static void |
af02033e | 3448 | create_overlay_event_breakpoint (void) |
e62c965a | 3449 | { |
69de3c6a | 3450 | struct objfile *objfile; |
af02033e | 3451 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3452 | |
69de3c6a PP |
3453 | ALL_OBJFILES (objfile) |
3454 | { | |
3455 | struct breakpoint *b; | |
17450429 PP |
3456 | struct breakpoint_objfile_data *bp_objfile_data; |
3457 | CORE_ADDR addr; | |
67994074 | 3458 | struct explicit_location explicit_loc; |
69de3c6a | 3459 | |
17450429 PP |
3460 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3461 | ||
3b7344d5 | 3462 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3463 | continue; |
3464 | ||
3b7344d5 | 3465 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3466 | { |
3b7344d5 | 3467 | struct bound_minimal_symbol m; |
17450429 PP |
3468 | |
3469 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3470 | if (m.minsym == NULL) |
17450429 PP |
3471 | { |
3472 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3473 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3474 | continue; |
3475 | } | |
3476 | bp_objfile_data->overlay_msym = m; | |
3477 | } | |
e62c965a | 3478 | |
77e371c0 | 3479 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3480 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3481 | bp_overlay_event, |
3482 | &internal_breakpoint_ops); | |
67994074 KS |
3483 | initialize_explicit_location (&explicit_loc); |
3484 | explicit_loc.function_name = ASTRDUP (func_name); | |
3485 | b->location = new_explicit_location (&explicit_loc); | |
e62c965a | 3486 | |
69de3c6a PP |
3487 | if (overlay_debugging == ovly_auto) |
3488 | { | |
3489 | b->enable_state = bp_enabled; | |
3490 | overlay_events_enabled = 1; | |
3491 | } | |
3492 | else | |
3493 | { | |
3494 | b->enable_state = bp_disabled; | |
3495 | overlay_events_enabled = 0; | |
3496 | } | |
e62c965a | 3497 | } |
e62c965a PP |
3498 | } |
3499 | ||
0fd8e87f | 3500 | static void |
af02033e | 3501 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3502 | { |
6c95b8df | 3503 | struct program_space *pspace; |
6c95b8df PA |
3504 | struct cleanup *old_chain; |
3505 | ||
3506 | old_chain = save_current_program_space (); | |
0fd8e87f | 3507 | |
6c95b8df | 3508 | ALL_PSPACES (pspace) |
af02033e PP |
3509 | { |
3510 | struct objfile *objfile; | |
3511 | ||
3512 | set_current_program_space (pspace); | |
3513 | ||
3514 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3515 | { |
af02033e PP |
3516 | int i; |
3517 | struct gdbarch *gdbarch; | |
17450429 | 3518 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3519 | |
af02033e | 3520 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3521 | |
17450429 PP |
3522 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3523 | ||
28106bc2 SDJ |
3524 | if (!bp_objfile_data->longjmp_searched) |
3525 | { | |
25f9533e SDJ |
3526 | VEC (probe_p) *ret; |
3527 | ||
3528 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3529 | if (ret != NULL) | |
3530 | { | |
3531 | /* We are only interested in checking one element. */ | |
3532 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3533 | ||
3534 | if (!can_evaluate_probe_arguments (p)) | |
3535 | { | |
3536 | /* We cannot use the probe interface here, because it does | |
3537 | not know how to evaluate arguments. */ | |
3538 | VEC_free (probe_p, ret); | |
3539 | ret = NULL; | |
3540 | } | |
3541 | } | |
3542 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3543 | bp_objfile_data->longjmp_searched = 1; |
3544 | } | |
3545 | ||
3546 | if (bp_objfile_data->longjmp_probes != NULL) | |
3547 | { | |
3548 | int i; | |
3549 | struct probe *probe; | |
3550 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3551 | ||
3552 | for (i = 0; | |
3553 | VEC_iterate (probe_p, | |
3554 | bp_objfile_data->longjmp_probes, | |
3555 | i, probe); | |
3556 | ++i) | |
3557 | { | |
3558 | struct breakpoint *b; | |
3559 | ||
729662a5 TT |
3560 | b = create_internal_breakpoint (gdbarch, |
3561 | get_probe_address (probe, | |
3562 | objfile), | |
28106bc2 SDJ |
3563 | bp_longjmp_master, |
3564 | &internal_breakpoint_ops); | |
5b56227b KS |
3565 | b->location |
3566 | = new_probe_location ("-probe-stap libc:longjmp"); | |
28106bc2 SDJ |
3567 | b->enable_state = bp_disabled; |
3568 | } | |
3569 | ||
3570 | continue; | |
3571 | } | |
3572 | ||
0569175e TSD |
3573 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3574 | continue; | |
3575 | ||
17450429 | 3576 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3577 | { |
3578 | struct breakpoint *b; | |
af02033e | 3579 | const char *func_name; |
17450429 | 3580 | CORE_ADDR addr; |
67994074 | 3581 | struct explicit_location explicit_loc; |
6c95b8df | 3582 | |
3b7344d5 | 3583 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3584 | continue; |
0fd8e87f | 3585 | |
17450429 | 3586 | func_name = longjmp_names[i]; |
3b7344d5 | 3587 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3588 | { |
3b7344d5 | 3589 | struct bound_minimal_symbol m; |
17450429 PP |
3590 | |
3591 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3592 | if (m.minsym == NULL) |
17450429 PP |
3593 | { |
3594 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3595 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3596 | continue; |
3597 | } | |
3598 | bp_objfile_data->longjmp_msym[i] = m; | |
3599 | } | |
3600 | ||
77e371c0 | 3601 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3602 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3603 | &internal_breakpoint_ops); | |
67994074 KS |
3604 | initialize_explicit_location (&explicit_loc); |
3605 | explicit_loc.function_name = ASTRDUP (func_name); | |
3606 | b->location = new_explicit_location (&explicit_loc); | |
af02033e PP |
3607 | b->enable_state = bp_disabled; |
3608 | } | |
0fd8e87f | 3609 | } |
af02033e | 3610 | } |
6c95b8df PA |
3611 | |
3612 | do_cleanups (old_chain); | |
0fd8e87f UW |
3613 | } |
3614 | ||
af02033e | 3615 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3616 | static void |
af02033e | 3617 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3618 | { |
3619 | struct program_space *pspace; | |
aa7d318d | 3620 | struct cleanup *old_chain; |
af02033e | 3621 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3622 | |
3623 | old_chain = save_current_program_space (); | |
3624 | ||
3625 | ALL_PSPACES (pspace) | |
17450429 PP |
3626 | { |
3627 | struct objfile *objfile; | |
3628 | CORE_ADDR addr; | |
3629 | ||
3630 | set_current_program_space (pspace); | |
3631 | ||
aa7d318d TT |
3632 | ALL_OBJFILES (objfile) |
3633 | { | |
3634 | struct breakpoint *b; | |
17450429 | 3635 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3636 | struct explicit_location explicit_loc; |
aa7d318d | 3637 | |
17450429 | 3638 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3639 | |
3b7344d5 | 3640 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3641 | continue; |
3642 | ||
3b7344d5 | 3643 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3644 | { |
3b7344d5 | 3645 | struct bound_minimal_symbol m; |
17450429 PP |
3646 | |
3647 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3648 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3649 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3650 | { |
3651 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3652 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3653 | continue; |
3654 | } | |
3655 | bp_objfile_data->terminate_msym = m; | |
3656 | } | |
aa7d318d | 3657 | |
77e371c0 | 3658 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3659 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3660 | bp_std_terminate_master, |
3661 | &internal_breakpoint_ops); | |
67994074 KS |
3662 | initialize_explicit_location (&explicit_loc); |
3663 | explicit_loc.function_name = ASTRDUP (func_name); | |
3664 | b->location = new_explicit_location (&explicit_loc); | |
aa7d318d TT |
3665 | b->enable_state = bp_disabled; |
3666 | } | |
17450429 PP |
3667 | } |
3668 | ||
aa7d318d TT |
3669 | do_cleanups (old_chain); |
3670 | } | |
3671 | ||
186c406b TT |
3672 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3673 | ||
70221824 | 3674 | static void |
186c406b TT |
3675 | create_exception_master_breakpoint (void) |
3676 | { | |
3677 | struct objfile *objfile; | |
17450429 | 3678 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3679 | |
3680 | ALL_OBJFILES (objfile) | |
3681 | { | |
17450429 PP |
3682 | struct breakpoint *b; |
3683 | struct gdbarch *gdbarch; | |
3684 | struct breakpoint_objfile_data *bp_objfile_data; | |
3685 | CORE_ADDR addr; | |
67994074 | 3686 | struct explicit_location explicit_loc; |
17450429 PP |
3687 | |
3688 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3689 | ||
28106bc2 SDJ |
3690 | /* We prefer the SystemTap probe point if it exists. */ |
3691 | if (!bp_objfile_data->exception_searched) | |
3692 | { | |
25f9533e SDJ |
3693 | VEC (probe_p) *ret; |
3694 | ||
3695 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3696 | ||
3697 | if (ret != NULL) | |
3698 | { | |
3699 | /* We are only interested in checking one element. */ | |
3700 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3701 | ||
3702 | if (!can_evaluate_probe_arguments (p)) | |
3703 | { | |
3704 | /* We cannot use the probe interface here, because it does | |
3705 | not know how to evaluate arguments. */ | |
3706 | VEC_free (probe_p, ret); | |
3707 | ret = NULL; | |
3708 | } | |
3709 | } | |
3710 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3711 | bp_objfile_data->exception_searched = 1; |
3712 | } | |
3713 | ||
3714 | if (bp_objfile_data->exception_probes != NULL) | |
3715 | { | |
3716 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3717 | int i; | |
3718 | struct probe *probe; | |
3719 | ||
3720 | for (i = 0; | |
3721 | VEC_iterate (probe_p, | |
3722 | bp_objfile_data->exception_probes, | |
3723 | i, probe); | |
3724 | ++i) | |
3725 | { | |
3726 | struct breakpoint *b; | |
3727 | ||
729662a5 TT |
3728 | b = create_internal_breakpoint (gdbarch, |
3729 | get_probe_address (probe, | |
3730 | objfile), | |
28106bc2 SDJ |
3731 | bp_exception_master, |
3732 | &internal_breakpoint_ops); | |
5b56227b KS |
3733 | b->location |
3734 | = new_probe_location ("-probe-stap libgcc:unwind"); | |
28106bc2 SDJ |
3735 | b->enable_state = bp_disabled; |
3736 | } | |
3737 | ||
3738 | continue; | |
3739 | } | |
3740 | ||
3741 | /* Otherwise, try the hook function. */ | |
3742 | ||
3b7344d5 | 3743 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3744 | continue; |
3745 | ||
3746 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3747 | |
3b7344d5 | 3748 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3749 | { |
3b7344d5 | 3750 | struct bound_minimal_symbol debug_hook; |
186c406b | 3751 | |
17450429 | 3752 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3753 | if (debug_hook.minsym == NULL) |
17450429 | 3754 | { |
3b7344d5 | 3755 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3756 | continue; |
3757 | } | |
3758 | ||
3759 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3760 | } |
17450429 | 3761 | |
77e371c0 | 3762 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3763 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3764 | ¤t_target); | |
06edf0c0 PA |
3765 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3766 | &internal_breakpoint_ops); | |
67994074 KS |
3767 | initialize_explicit_location (&explicit_loc); |
3768 | explicit_loc.function_name = ASTRDUP (func_name); | |
3769 | b->location = new_explicit_location (&explicit_loc); | |
17450429 | 3770 | b->enable_state = bp_disabled; |
186c406b | 3771 | } |
186c406b TT |
3772 | } |
3773 | ||
9ef9e6a6 KS |
3774 | /* Does B have a location spec? */ |
3775 | ||
3776 | static int | |
3777 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3778 | { | |
3779 | return b->location != NULL && event_location_empty_p (b->location); | |
3780 | } | |
3781 | ||
c906108c | 3782 | void |
fba45db2 | 3783 | update_breakpoints_after_exec (void) |
c906108c | 3784 | { |
35df4500 | 3785 | struct breakpoint *b, *b_tmp; |
876fa593 | 3786 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3787 | |
25b22b0a PA |
3788 | /* We're about to delete breakpoints from GDB's lists. If the |
3789 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3790 | writing the breakpoints' "shadow contents" back into memory. The | |
3791 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3792 | do that. Instead, the target is responsible from marking | |
3793 | breakpoints out as soon as it detects an exec. We don't do that | |
3794 | here instead, because there may be other attempts to delete | |
3795 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3796 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3797 | if (bploc->pspace == current_program_space) |
3798 | gdb_assert (!bploc->inserted); | |
c906108c | 3799 | |
35df4500 | 3800 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3801 | { |
6c95b8df PA |
3802 | if (b->pspace != current_program_space) |
3803 | continue; | |
3804 | ||
4a64f543 | 3805 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3806 | if (b->type == bp_shlib_event) |
3807 | { | |
3808 | delete_breakpoint (b); | |
3809 | continue; | |
3810 | } | |
c906108c | 3811 | |
4a64f543 | 3812 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3813 | if (b->type == bp_jit_event) |
3814 | { | |
3815 | delete_breakpoint (b); | |
3816 | continue; | |
3817 | } | |
3818 | ||
1900040c | 3819 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3820 | as must overlay event and longjmp master breakpoints. */ |
3821 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3822 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3823 | || b->type == bp_exception_master) | |
c4093a6a JM |
3824 | { |
3825 | delete_breakpoint (b); | |
3826 | continue; | |
3827 | } | |
3828 | ||
4a64f543 | 3829 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3830 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3831 | { |
3832 | delete_breakpoint (b); | |
3833 | continue; | |
3834 | } | |
3835 | ||
7c16b83e PA |
3836 | /* Just like single-step breakpoints. */ |
3837 | if (b->type == bp_single_step) | |
3838 | { | |
3839 | delete_breakpoint (b); | |
3840 | continue; | |
3841 | } | |
3842 | ||
611c83ae PA |
3843 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3844 | after an exec. */ | |
186c406b | 3845 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3846 | || b->type == bp_longjmp_call_dummy |
186c406b | 3847 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3848 | { |
3849 | delete_breakpoint (b); | |
3850 | continue; | |
3851 | } | |
3852 | ||
ce78b96d JB |
3853 | if (b->type == bp_catchpoint) |
3854 | { | |
3855 | /* For now, none of the bp_catchpoint breakpoints need to | |
3856 | do anything at this point. In the future, if some of | |
3857 | the catchpoints need to something, we will need to add | |
3858 | a new method, and call this method from here. */ | |
3859 | continue; | |
3860 | } | |
3861 | ||
c5aa993b JM |
3862 | /* bp_finish is a special case. The only way we ought to be able |
3863 | to see one of these when an exec() has happened, is if the user | |
3864 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3865 | carries them to the call-site of the current callee, by setting | |
3866 | a temporary bp there and resuming. But in this case, the finish | |
3867 | will carry them entirely through the vfork & exec. | |
3868 | ||
3869 | We don't want to allow a bp_finish to remain inserted now. But | |
3870 | we can't safely delete it, 'cause finish_command has a handle to | |
3871 | the bp on a bpstat, and will later want to delete it. There's a | |
3872 | chance (and I've seen it happen) that if we delete the bp_finish | |
3873 | here, that its storage will get reused by the time finish_command | |
3874 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3875 | We really must allow finish_command to delete a bp_finish. | |
3876 | ||
e5dd4106 | 3877 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3878 | it's safe to delete something others may have handles to?" |
3879 | problem, what we'll do here is just uninsert the bp_finish, and | |
3880 | let finish_command delete it. | |
3881 | ||
3882 | (We know the bp_finish is "doomed" in the sense that it's | |
3883 | momentary, and will be deleted as soon as finish_command sees | |
3884 | the inferior stopped. So it doesn't matter that the bp's | |
3885 | address is probably bogus in the new a.out, unlike e.g., the | |
3886 | solib breakpoints.) */ | |
c5aa993b | 3887 | |
c5aa993b JM |
3888 | if (b->type == bp_finish) |
3889 | { | |
3890 | continue; | |
3891 | } | |
3892 | ||
3893 | /* Without a symbolic address, we have little hope of the | |
3894 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3895 | a.out. */ |
9ef9e6a6 | 3896 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3897 | { |
3898 | delete_breakpoint (b); | |
3899 | continue; | |
3900 | } | |
c5aa993b | 3901 | } |
c906108c SS |
3902 | } |
3903 | ||
3904 | int | |
d80ee84f | 3905 | detach_breakpoints (ptid_t ptid) |
c906108c | 3906 | { |
35df4500 | 3907 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3908 | int val = 0; |
ce696e05 | 3909 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3910 | struct inferior *inf = current_inferior (); |
c5aa993b | 3911 | |
dfd4cc63 | 3912 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3913 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3914 | |
6c95b8df | 3915 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3916 | inferior_ptid = ptid; |
35df4500 | 3917 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3918 | { |
35df4500 | 3919 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3920 | continue; |
3921 | ||
bd9673a4 PW |
3922 | /* This function must physically remove breakpoints locations |
3923 | from the specified ptid, without modifying the breakpoint | |
3924 | package's state. Locations of type bp_loc_other are only | |
3925 | maintained at GDB side. So, there is no need to remove | |
3926 | these bp_loc_other locations. Moreover, removing these | |
3927 | would modify the breakpoint package's state. */ | |
3928 | if (bl->loc_type == bp_loc_other) | |
3929 | continue; | |
3930 | ||
35df4500 | 3931 | if (bl->inserted) |
b2b6a7da | 3932 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3933 | } |
d03285ec | 3934 | |
ce696e05 | 3935 | do_cleanups (old_chain); |
3a1bae8e | 3936 | return val; |
c906108c SS |
3937 | } |
3938 | ||
35df4500 | 3939 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3940 | Note that this is used to detach breakpoints from a child fork. |
3941 | When we get here, the child isn't in the inferior list, and neither | |
3942 | do we have objects to represent its address space --- we should | |
35df4500 | 3943 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3944 | |
c906108c | 3945 | static int |
b2b6a7da | 3946 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3947 | { |
3948 | int val; | |
c5aa993b | 3949 | |
35df4500 TJB |
3950 | /* BL is never in moribund_locations by our callers. */ |
3951 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3952 | |
74960c60 VP |
3953 | /* The type of none suggests that owner is actually deleted. |
3954 | This should not ever happen. */ | |
35df4500 | 3955 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3956 | |
35df4500 TJB |
3957 | if (bl->loc_type == bp_loc_software_breakpoint |
3958 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3959 | { |
c02f5703 MS |
3960 | /* "Normal" instruction breakpoint: either the standard |
3961 | trap-instruction bp (bp_breakpoint), or a | |
3962 | bp_hardware_breakpoint. */ | |
3963 | ||
3964 | /* First check to see if we have to handle an overlay. */ | |
3965 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3966 | || bl->section == NULL |
3967 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3968 | { |
3969 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3970 | |
3971 | /* If we're trying to uninsert a memory breakpoint that we | |
3972 | know is set in a dynamic object that is marked | |
3973 | shlib_disabled, then either the dynamic object was | |
3974 | removed with "remove-symbol-file" or with | |
3975 | "nosharedlibrary". In the former case, we don't know | |
3976 | whether another dynamic object might have loaded over the | |
3977 | breakpoint's address -- the user might well let us know | |
3978 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3979 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3980 | list of dynamically loaded objects). If we have the |
3981 | breakpoint's shadow memory, that is, this is a software | |
3982 | breakpoint managed by GDB, check whether the breakpoint | |
3983 | is still inserted in memory, to avoid overwriting wrong | |
3984 | code with stale saved shadow contents. Note that HW | |
3985 | breakpoints don't have shadow memory, as they're | |
3986 | implemented using a mechanism that is not dependent on | |
3987 | being able to modify the target's memory, and as such | |
3988 | they should always be removed. */ | |
3989 | if (bl->shlib_disabled | |
3990 | && bl->target_info.shadow_len != 0 | |
3991 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3992 | val = 0; | |
3993 | else | |
73971819 | 3994 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3995 | } |
c906108c SS |
3996 | else |
3997 | { | |
4a64f543 | 3998 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3999 | Did we set a breakpoint at the LMA? */ |
4000 | if (!overlay_events_enabled) | |
4001 | { | |
4002 | /* Yes -- overlay event support is not active, so we | |
4003 | should have set a breakpoint at the LMA. Remove it. | |
4004 | */ | |
c02f5703 MS |
4005 | /* Ignore any failures: if the LMA is in ROM, we will |
4006 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
4007 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
4008 | target_remove_hw_breakpoint (bl->gdbarch, | |
4009 | &bl->overlay_target_info); | |
c02f5703 | 4010 | else |
35df4500 | 4011 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
4012 | &bl->overlay_target_info, |
4013 | reason); | |
c02f5703 MS |
4014 | } |
4015 | /* Did we set a breakpoint at the VMA? | |
4016 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4017 | if (bl->inserted) |
c906108c | 4018 | { |
c02f5703 MS |
4019 | /* Yes -- remove it. Previously we did not bother to |
4020 | remove the breakpoint if the section had been | |
4021 | unmapped, but let's not rely on that being safe. We | |
4022 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4023 | |
4024 | /* However, we should remove *software* breakpoints only | |
4025 | if the section is still mapped, or else we overwrite | |
4026 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4027 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4028 | || section_is_mapped (bl->section)) | |
73971819 | 4029 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
4030 | else |
4031 | val = 0; | |
c906108c | 4032 | } |
c02f5703 MS |
4033 | else |
4034 | { | |
4035 | /* No -- not inserted, so no need to remove. No error. */ | |
4036 | val = 0; | |
4037 | } | |
c906108c | 4038 | } |
879d1e6b | 4039 | |
08351840 PA |
4040 | /* In some cases, we might not be able to remove a breakpoint in |
4041 | a shared library that has already been removed, but we have | |
4042 | not yet processed the shlib unload event. Similarly for an | |
4043 | unloaded add-symbol-file object - the user might not yet have | |
4044 | had the chance to remove-symbol-file it. shlib_disabled will | |
4045 | be set if the library/object has already been removed, but | |
4046 | the breakpoint hasn't been uninserted yet, e.g., after | |
4047 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4048 | always-inserted mode. */ | |
076855f9 | 4049 | if (val |
08351840 PA |
4050 | && (bl->loc_type == bp_loc_software_breakpoint |
4051 | && (bl->shlib_disabled | |
4052 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4053 | || shared_objfile_contains_address_p (bl->pspace, |
4054 | bl->address)))) | |
879d1e6b UW |
4055 | val = 0; |
4056 | ||
c906108c SS |
4057 | if (val) |
4058 | return val; | |
b2b6a7da | 4059 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 4060 | } |
35df4500 | 4061 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4062 | { |
77b06cd7 TJB |
4063 | gdb_assert (bl->owner->ops != NULL |
4064 | && bl->owner->ops->remove_location != NULL); | |
4065 | ||
b2b6a7da | 4066 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 4067 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 4068 | |
c906108c | 4069 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 4070 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 4071 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4072 | bl->owner->number); |
c906108c | 4073 | } |
35df4500 TJB |
4074 | else if (bl->owner->type == bp_catchpoint |
4075 | && breakpoint_enabled (bl->owner) | |
4076 | && !bl->duplicate) | |
ce78b96d | 4077 | { |
77b06cd7 TJB |
4078 | gdb_assert (bl->owner->ops != NULL |
4079 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4080 | |
73971819 | 4081 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
4082 | if (val) |
4083 | return val; | |
77b06cd7 | 4084 | |
b2b6a7da | 4085 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 4086 | } |
c906108c SS |
4087 | |
4088 | return 0; | |
4089 | } | |
4090 | ||
6c95b8df | 4091 | static int |
834c0d03 | 4092 | remove_breakpoint (struct bp_location *bl) |
6c95b8df PA |
4093 | { |
4094 | int ret; | |
4095 | struct cleanup *old_chain; | |
4096 | ||
35df4500 TJB |
4097 | /* BL is never in moribund_locations by our callers. */ |
4098 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4099 | |
6c95b8df PA |
4100 | /* The type of none suggests that owner is actually deleted. |
4101 | This should not ever happen. */ | |
35df4500 | 4102 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4103 | |
4104 | old_chain = save_current_space_and_thread (); | |
4105 | ||
35df4500 | 4106 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4107 | |
b2b6a7da | 4108 | ret = remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4109 | |
4110 | do_cleanups (old_chain); | |
4111 | return ret; | |
4112 | } | |
4113 | ||
c906108c SS |
4114 | /* Clear the "inserted" flag in all breakpoints. */ |
4115 | ||
25b22b0a | 4116 | void |
fba45db2 | 4117 | mark_breakpoints_out (void) |
c906108c | 4118 | { |
35df4500 | 4119 | struct bp_location *bl, **blp_tmp; |
c906108c | 4120 | |
35df4500 | 4121 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4122 | if (bl->pspace == current_program_space) |
35df4500 | 4123 | bl->inserted = 0; |
c906108c SS |
4124 | } |
4125 | ||
53a5351d JM |
4126 | /* Clear the "inserted" flag in all breakpoints and delete any |
4127 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4128 | |
4129 | Plus other such housekeeping that has to be done for breakpoints | |
4130 | between runs. | |
4131 | ||
53a5351d JM |
4132 | Note: this function gets called at the end of a run (by |
4133 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4134 | init_wait_for_inferior). */ |
c906108c SS |
4135 | |
4136 | ||
4137 | ||
4138 | void | |
fba45db2 | 4139 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4140 | { |
35df4500 | 4141 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4142 | struct bp_location *bl; |
1c5cfe86 | 4143 | int ix; |
6c95b8df | 4144 | struct program_space *pspace = current_program_space; |
c906108c | 4145 | |
50c71eaf PA |
4146 | /* If breakpoint locations are shared across processes, then there's |
4147 | nothing to do. */ | |
f5656ead | 4148 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4149 | return; |
4150 | ||
1a853c52 | 4151 | mark_breakpoints_out (); |
075f6582 | 4152 | |
35df4500 | 4153 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4154 | { |
6c95b8df PA |
4155 | if (b->loc && b->loc->pspace != pspace) |
4156 | continue; | |
4157 | ||
c5aa993b JM |
4158 | switch (b->type) |
4159 | { | |
4160 | case bp_call_dummy: | |
e2e4d78b | 4161 | case bp_longjmp_call_dummy: |
c906108c | 4162 | |
c5aa993b | 4163 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4164 | cause problems when the inferior is rerun, so we better get |
4165 | rid of it. */ | |
4166 | ||
4167 | case bp_watchpoint_scope: | |
4168 | ||
4169 | /* Also get rid of scope breakpoints. */ | |
4170 | ||
4171 | case bp_shlib_event: | |
4172 | ||
4173 | /* Also remove solib event breakpoints. Their addresses may | |
4174 | have changed since the last time we ran the program. | |
4175 | Actually we may now be debugging against different target; | |
4176 | and so the solib backend that installed this breakpoint may | |
4177 | not be used in by the target. E.g., | |
4178 | ||
4179 | (gdb) file prog-linux | |
4180 | (gdb) run # native linux target | |
4181 | ... | |
4182 | (gdb) kill | |
4183 | (gdb) file prog-win.exe | |
4184 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4185 | */ | |
c906108c | 4186 | |
f59f708a PA |
4187 | case bp_step_resume: |
4188 | ||
4189 | /* Also remove step-resume breakpoints. */ | |
4190 | ||
7c16b83e PA |
4191 | case bp_single_step: |
4192 | ||
4193 | /* Also remove single-step breakpoints. */ | |
4194 | ||
c5aa993b JM |
4195 | delete_breakpoint (b); |
4196 | break; | |
c906108c | 4197 | |
c5aa993b JM |
4198 | case bp_watchpoint: |
4199 | case bp_hardware_watchpoint: | |
4200 | case bp_read_watchpoint: | |
4201 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4202 | { |
4203 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4204 | |
3a5c3e22 PA |
4205 | /* Likewise for watchpoints on local expressions. */ |
4206 | if (w->exp_valid_block != NULL) | |
4207 | delete_breakpoint (b); | |
63000888 | 4208 | else |
3a5c3e22 | 4209 | { |
63000888 PA |
4210 | /* Get rid of existing locations, which are no longer |
4211 | valid. New ones will be created in | |
4212 | update_watchpoint, when the inferior is restarted. | |
4213 | The next update_global_location_list call will | |
4214 | garbage collect them. */ | |
4215 | b->loc = NULL; | |
4216 | ||
4217 | if (context == inf_starting) | |
4218 | { | |
4219 | /* Reset val field to force reread of starting value in | |
4220 | insert_breakpoints. */ | |
4221 | if (w->val) | |
4222 | value_free (w->val); | |
4223 | w->val = NULL; | |
4224 | w->val_valid = 0; | |
4225 | } | |
4226 | } | |
3a5c3e22 | 4227 | } |
c5aa993b JM |
4228 | break; |
4229 | default: | |
c5aa993b JM |
4230 | break; |
4231 | } | |
4232 | } | |
1c5cfe86 PA |
4233 | |
4234 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4235 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4236 | decref_bp_location (&bl); | |
1c5cfe86 | 4237 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4238 | } |
4239 | ||
6c95b8df PA |
4240 | /* These functions concern about actual breakpoints inserted in the |
4241 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4242 | we need to hop over the bkpt --- so we check for address space | |
4243 | match, not program space. */ | |
4244 | ||
c2c6d25f JM |
4245 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4246 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4247 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4248 | permanent breakpoint. | |
4249 | - When continuing from a location with an ordinary breakpoint, we | |
4250 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4251 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4252 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4253 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4254 | |
c2c6d25f | 4255 | enum breakpoint_here |
6c95b8df | 4256 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4257 | { |
35df4500 | 4258 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4259 | int any_breakpoint_here = 0; |
c906108c | 4260 | |
35df4500 | 4261 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4262 | { |
35df4500 TJB |
4263 | if (bl->loc_type != bp_loc_software_breakpoint |
4264 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4265 | continue; |
4266 | ||
f1310107 | 4267 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4268 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4269 | || bl->permanent) |
f1310107 | 4270 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4271 | { |
4272 | if (overlay_debugging | |
35df4500 TJB |
4273 | && section_is_overlay (bl->section) |
4274 | && !section_is_mapped (bl->section)) | |
075f6582 | 4275 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4276 | else if (bl->permanent) |
075f6582 DJ |
4277 | return permanent_breakpoint_here; |
4278 | else | |
4279 | any_breakpoint_here = 1; | |
4280 | } | |
4281 | } | |
c906108c | 4282 | |
f486487f | 4283 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4284 | } |
4285 | ||
d35ae833 PA |
4286 | /* See breakpoint.h. */ |
4287 | ||
4288 | int | |
4289 | breakpoint_in_range_p (struct address_space *aspace, | |
4290 | CORE_ADDR addr, ULONGEST len) | |
4291 | { | |
4292 | struct bp_location *bl, **blp_tmp; | |
4293 | ||
4294 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4295 | { | |
4296 | if (bl->loc_type != bp_loc_software_breakpoint | |
4297 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4298 | continue; | |
4299 | ||
4300 | if ((breakpoint_enabled (bl->owner) | |
4301 | || bl->permanent) | |
4302 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4303 | addr, len)) | |
4304 | { | |
4305 | if (overlay_debugging | |
4306 | && section_is_overlay (bl->section) | |
4307 | && !section_is_mapped (bl->section)) | |
4308 | { | |
4309 | /* Unmapped overlay -- can't be a match. */ | |
4310 | continue; | |
4311 | } | |
4312 | ||
4313 | return 1; | |
4314 | } | |
4315 | } | |
4316 | ||
4317 | return 0; | |
4318 | } | |
4319 | ||
1c5cfe86 PA |
4320 | /* Return true if there's a moribund breakpoint at PC. */ |
4321 | ||
4322 | int | |
6c95b8df | 4323 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4324 | { |
4325 | struct bp_location *loc; | |
4326 | int ix; | |
4327 | ||
4328 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4329 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4330 | return 1; |
4331 | ||
4332 | return 0; | |
4333 | } | |
c2c6d25f | 4334 | |
f7ce857f PA |
4335 | /* Returns non-zero iff BL is inserted at PC, in address space |
4336 | ASPACE. */ | |
4337 | ||
4338 | static int | |
4339 | bp_location_inserted_here_p (struct bp_location *bl, | |
4340 | struct address_space *aspace, CORE_ADDR pc) | |
4341 | { | |
4342 | if (bl->inserted | |
4343 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4344 | aspace, pc)) | |
4345 | { | |
4346 | if (overlay_debugging | |
4347 | && section_is_overlay (bl->section) | |
4348 | && !section_is_mapped (bl->section)) | |
4349 | return 0; /* unmapped overlay -- can't be a match */ | |
4350 | else | |
4351 | return 1; | |
4352 | } | |
4353 | return 0; | |
4354 | } | |
4355 | ||
a1fd2fa5 | 4356 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4357 | |
4358 | int | |
a1fd2fa5 | 4359 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4360 | { |
f7ce857f | 4361 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4362 | |
f7ce857f | 4363 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4364 | { |
f7ce857f PA |
4365 | struct bp_location *bl = *blp; |
4366 | ||
35df4500 TJB |
4367 | if (bl->loc_type != bp_loc_software_breakpoint |
4368 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4369 | continue; |
4370 | ||
f7ce857f PA |
4371 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4372 | return 1; | |
c5aa993b | 4373 | } |
c36b740a VP |
4374 | return 0; |
4375 | } | |
4376 | ||
a1fd2fa5 PA |
4377 | /* This function returns non-zero iff there is a software breakpoint |
4378 | inserted at PC. */ | |
c36b740a VP |
4379 | |
4380 | int | |
a1fd2fa5 PA |
4381 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4382 | CORE_ADDR pc) | |
4fa8626c | 4383 | { |
f7ce857f | 4384 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4385 | |
f7ce857f | 4386 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4387 | { |
f7ce857f PA |
4388 | struct bp_location *bl = *blp; |
4389 | ||
35df4500 | 4390 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4391 | continue; |
4392 | ||
f7ce857f PA |
4393 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4394 | return 1; | |
4fa8626c DJ |
4395 | } |
4396 | ||
4397 | return 0; | |
9c02b525 PA |
4398 | } |
4399 | ||
4400 | /* See breakpoint.h. */ | |
4401 | ||
4402 | int | |
4403 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4404 | CORE_ADDR pc) | |
4405 | { | |
4406 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4407 | |
4408 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4409 | { | |
4410 | struct bp_location *bl = *blp; | |
4411 | ||
4412 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4413 | continue; | |
4414 | ||
4415 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4416 | return 1; | |
4417 | } | |
4418 | ||
4419 | return 0; | |
4fa8626c DJ |
4420 | } |
4421 | ||
9093389c PA |
4422 | int |
4423 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4424 | CORE_ADDR addr, ULONGEST len) | |
4425 | { | |
4426 | struct breakpoint *bpt; | |
4427 | ||
4428 | ALL_BREAKPOINTS (bpt) | |
4429 | { | |
4430 | struct bp_location *loc; | |
4431 | ||
4432 | if (bpt->type != bp_hardware_watchpoint | |
4433 | && bpt->type != bp_access_watchpoint) | |
4434 | continue; | |
4435 | ||
4436 | if (!breakpoint_enabled (bpt)) | |
4437 | continue; | |
4438 | ||
4439 | for (loc = bpt->loc; loc; loc = loc->next) | |
4440 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4441 | { | |
4442 | CORE_ADDR l, h; | |
4443 | ||
4444 | /* Check for intersection. */ | |
768adc05 PA |
4445 | l = std::max<CORE_ADDR> (loc->address, addr); |
4446 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4447 | if (l < h) |
4448 | return 1; | |
4449 | } | |
4450 | } | |
4451 | return 0; | |
4452 | } | |
c906108c | 4453 | \f |
c5aa993b | 4454 | |
c906108c SS |
4455 | /* bpstat stuff. External routines' interfaces are documented |
4456 | in breakpoint.h. */ | |
4457 | ||
4458 | int | |
c326b90e | 4459 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4460 | { |
533be4dd | 4461 | return (ep->type == bp_catchpoint); |
c906108c SS |
4462 | } |
4463 | ||
f431efe5 PA |
4464 | /* Frees any storage that is part of a bpstat. Does not walk the |
4465 | 'next' chain. */ | |
4466 | ||
4467 | static void | |
198757a8 VP |
4468 | bpstat_free (bpstat bs) |
4469 | { | |
4470 | if (bs->old_val != NULL) | |
4471 | value_free (bs->old_val); | |
9add0f1b | 4472 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4473 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4474 | xfree (bs); |
4475 | } | |
4476 | ||
c906108c SS |
4477 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4478 | Also free any storage that is part of a bpstat. */ | |
4479 | ||
4480 | void | |
fba45db2 | 4481 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4482 | { |
4483 | bpstat p; | |
4484 | bpstat q; | |
4485 | ||
4486 | if (bsp == 0) | |
4487 | return; | |
4488 | p = *bsp; | |
4489 | while (p != NULL) | |
4490 | { | |
4491 | q = p->next; | |
198757a8 | 4492 | bpstat_free (p); |
c906108c SS |
4493 | p = q; |
4494 | } | |
4495 | *bsp = NULL; | |
4496 | } | |
4497 | ||
4498 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4499 | is part of the bpstat is copied as well. */ | |
4500 | ||
4501 | bpstat | |
fba45db2 | 4502 | bpstat_copy (bpstat bs) |
c906108c SS |
4503 | { |
4504 | bpstat p = NULL; | |
4505 | bpstat tmp; | |
4506 | bpstat retval = NULL; | |
4507 | ||
4508 | if (bs == NULL) | |
4509 | return bs; | |
4510 | ||
4511 | for (; bs != NULL; bs = bs->next) | |
4512 | { | |
4513 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4514 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4515 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4516 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4517 | if (bs->old_val != NULL) |
3c3185ac JK |
4518 | { |
4519 | tmp->old_val = value_copy (bs->old_val); | |
4520 | release_value (tmp->old_val); | |
4521 | } | |
31cc81e9 | 4522 | |
c906108c SS |
4523 | if (p == NULL) |
4524 | /* This is the first thing in the chain. */ | |
4525 | retval = tmp; | |
4526 | else | |
4527 | p->next = tmp; | |
4528 | p = tmp; | |
4529 | } | |
4530 | p->next = NULL; | |
4531 | return retval; | |
4532 | } | |
4533 | ||
4a64f543 | 4534 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4535 | |
4536 | bpstat | |
fba45db2 | 4537 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4538 | { |
c5aa993b JM |
4539 | if (bsp == NULL) |
4540 | return NULL; | |
c906108c | 4541 | |
c5aa993b JM |
4542 | for (; bsp != NULL; bsp = bsp->next) |
4543 | { | |
f431efe5 | 4544 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4545 | return bsp; |
4546 | } | |
c906108c SS |
4547 | return NULL; |
4548 | } | |
4549 | ||
ab04a2af TT |
4550 | /* See breakpoint.h. */ |
4551 | ||
47591c29 | 4552 | int |
427cd150 | 4553 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4554 | { |
ab04a2af TT |
4555 | for (; bsp != NULL; bsp = bsp->next) |
4556 | { | |
427cd150 TT |
4557 | if (bsp->breakpoint_at == NULL) |
4558 | { | |
4559 | /* A moribund location can never explain a signal other than | |
4560 | GDB_SIGNAL_TRAP. */ | |
4561 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4562 | return 1; |
427cd150 TT |
4563 | } |
4564 | else | |
47591c29 PA |
4565 | { |
4566 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4567 | sig)) | |
4568 | return 1; | |
4569 | } | |
ab04a2af TT |
4570 | } |
4571 | ||
47591c29 | 4572 | return 0; |
ab04a2af TT |
4573 | } |
4574 | ||
4a64f543 MS |
4575 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4576 | stopped at. *BSP upon return is a bpstat which points to the | |
4577 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4578 | good for anything but further calls to bpstat_num). | |
4579 | ||
8671a17b PA |
4580 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4581 | Return -1 if stopped at a breakpoint that has been deleted since | |
4582 | we set it. | |
4583 | Return 1 otherwise. */ | |
c906108c SS |
4584 | |
4585 | int | |
8671a17b | 4586 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4587 | { |
4588 | struct breakpoint *b; | |
4589 | ||
4590 | if ((*bsp) == NULL) | |
4591 | return 0; /* No more breakpoint values */ | |
8671a17b | 4592 | |
4a64f543 MS |
4593 | /* We assume we'll never have several bpstats that correspond to a |
4594 | single breakpoint -- otherwise, this function might return the | |
4595 | same number more than once and this will look ugly. */ | |
f431efe5 | 4596 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4597 | *bsp = (*bsp)->next; |
4598 | if (b == NULL) | |
4599 | return -1; /* breakpoint that's been deleted since */ | |
4600 | ||
4601 | *num = b->number; /* We have its number */ | |
4602 | return 1; | |
c906108c SS |
4603 | } |
4604 | ||
e93ca019 | 4605 | /* See breakpoint.h. */ |
c906108c SS |
4606 | |
4607 | void | |
e93ca019 | 4608 | bpstat_clear_actions (void) |
c906108c | 4609 | { |
e93ca019 JK |
4610 | struct thread_info *tp; |
4611 | bpstat bs; | |
4612 | ||
4613 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4614 | return; | |
4615 | ||
4616 | tp = find_thread_ptid (inferior_ptid); | |
4617 | if (tp == NULL) | |
4618 | return; | |
4619 | ||
4620 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4621 | { |
9add0f1b | 4622 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4623 | |
c906108c SS |
4624 | if (bs->old_val != NULL) |
4625 | { | |
4626 | value_free (bs->old_val); | |
4627 | bs->old_val = NULL; | |
4628 | } | |
4629 | } | |
4630 | } | |
4631 | ||
f3b1572e PA |
4632 | /* Called when a command is about to proceed the inferior. */ |
4633 | ||
4634 | static void | |
4635 | breakpoint_about_to_proceed (void) | |
4636 | { | |
4637 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4638 | { | |
4639 | struct thread_info *tp = inferior_thread (); | |
4640 | ||
4641 | /* Allow inferior function calls in breakpoint commands to not | |
4642 | interrupt the command list. When the call finishes | |
4643 | successfully, the inferior will be standing at the same | |
4644 | breakpoint as if nothing happened. */ | |
16c381f0 | 4645 | if (tp->control.in_infcall) |
f3b1572e PA |
4646 | return; |
4647 | } | |
4648 | ||
4649 | breakpoint_proceeded = 1; | |
4650 | } | |
4651 | ||
4a64f543 MS |
4652 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4653 | command. */ | |
c906108c | 4654 | static void |
4efb68b1 | 4655 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4656 | { |
4657 | executing_breakpoint_commands = 0; | |
4658 | } | |
4659 | ||
abf85f46 JK |
4660 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4661 | or its equivalent. */ | |
4662 | ||
4663 | static int | |
4664 | command_line_is_silent (struct command_line *cmd) | |
4665 | { | |
4f45d445 | 4666 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4667 | } |
4668 | ||
4a64f543 MS |
4669 | /* Execute all the commands associated with all the breakpoints at |
4670 | this location. Any of these commands could cause the process to | |
4671 | proceed beyond this point, etc. We look out for such changes by | |
4672 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4673 | |
347bddb7 PA |
4674 | Returns true if a breakpoint command resumed the inferior. In that |
4675 | case, it is the caller's responsibility to recall it again with the | |
4676 | bpstat of the current thread. */ | |
4677 | ||
4678 | static int | |
4679 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4680 | { |
4681 | bpstat bs; | |
4682 | struct cleanup *old_chain; | |
347bddb7 | 4683 | int again = 0; |
c906108c SS |
4684 | |
4685 | /* Avoid endless recursion if a `source' command is contained | |
4686 | in bs->commands. */ | |
4687 | if (executing_breakpoint_commands) | |
347bddb7 | 4688 | return 0; |
c906108c SS |
4689 | |
4690 | executing_breakpoint_commands = 1; | |
4691 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4692 | ||
cf6c5ffb TT |
4693 | prevent_dont_repeat (); |
4694 | ||
4a64f543 | 4695 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4696 | bs = *bsp; |
4697 | ||
4698 | breakpoint_proceeded = 0; | |
4699 | for (; bs != NULL; bs = bs->next) | |
4700 | { | |
9add0f1b | 4701 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4702 | struct command_line *cmd; |
4703 | struct cleanup *this_cmd_tree_chain; | |
4704 | ||
4705 | /* Take ownership of the BSP's command tree, if it has one. | |
4706 | ||
4707 | The command tree could legitimately contain commands like | |
4708 | 'step' and 'next', which call clear_proceed_status, which | |
4709 | frees stop_bpstat's command tree. To make sure this doesn't | |
4710 | free the tree we're executing out from under us, we need to | |
4711 | take ownership of the tree ourselves. Since a given bpstat's | |
4712 | commands are only executed once, we don't need to copy it; we | |
4713 | can clear the pointer in the bpstat, and make sure we free | |
4714 | the tree when we're done. */ | |
9add0f1b TT |
4715 | ccmd = bs->commands; |
4716 | bs->commands = NULL; | |
abf85f46 JK |
4717 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4718 | cmd = ccmd ? ccmd->commands : NULL; | |
4719 | if (command_line_is_silent (cmd)) | |
4720 | { | |
4721 | /* The action has been already done by bpstat_stop_status. */ | |
4722 | cmd = cmd->next; | |
4723 | } | |
6c50ab1c | 4724 | |
c906108c SS |
4725 | while (cmd != NULL) |
4726 | { | |
4727 | execute_control_command (cmd); | |
4728 | ||
4729 | if (breakpoint_proceeded) | |
4730 | break; | |
4731 | else | |
4732 | cmd = cmd->next; | |
4733 | } | |
6c50ab1c JB |
4734 | |
4735 | /* We can free this command tree now. */ | |
4736 | do_cleanups (this_cmd_tree_chain); | |
4737 | ||
c906108c | 4738 | if (breakpoint_proceeded) |
32c1e744 | 4739 | { |
cb814510 | 4740 | if (current_ui->async) |
347bddb7 PA |
4741 | /* If we are in async mode, then the target might be still |
4742 | running, not stopped at any breakpoint, so nothing for | |
4743 | us to do here -- just return to the event loop. */ | |
4744 | ; | |
32c1e744 VP |
4745 | else |
4746 | /* In sync mode, when execute_control_command returns | |
4747 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4748 | Breakpoint commands for that stop were not run, since |
4749 | execute_command does not run breakpoint commands -- | |
4750 | only command_line_handler does, but that one is not | |
4751 | involved in execution of breakpoint commands. So, we | |
4752 | can now execute breakpoint commands. It should be | |
4753 | noted that making execute_command do bpstat actions is | |
4754 | not an option -- in this case we'll have recursive | |
4755 | invocation of bpstat for each breakpoint with a | |
4756 | command, and can easily blow up GDB stack. Instead, we | |
4757 | return true, which will trigger the caller to recall us | |
4758 | with the new stop_bpstat. */ | |
4759 | again = 1; | |
4760 | break; | |
32c1e744 | 4761 | } |
c906108c | 4762 | } |
c2b8ed2c | 4763 | do_cleanups (old_chain); |
347bddb7 PA |
4764 | return again; |
4765 | } | |
4766 | ||
4767 | void | |
4768 | bpstat_do_actions (void) | |
4769 | { | |
353d1d73 JK |
4770 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4771 | ||
347bddb7 PA |
4772 | /* Do any commands attached to breakpoint we are stopped at. */ |
4773 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4774 | && target_has_execution | |
4775 | && !is_exited (inferior_ptid) | |
4776 | && !is_executing (inferior_ptid)) | |
4777 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4778 | and only return when it is stopped at the next breakpoint, we | |
4779 | keep doing breakpoint actions until it returns false to | |
4780 | indicate the inferior was not resumed. */ | |
16c381f0 | 4781 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4782 | break; |
353d1d73 JK |
4783 | |
4784 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4785 | } |
4786 | ||
fa4727a6 DJ |
4787 | /* Print out the (old or new) value associated with a watchpoint. */ |
4788 | ||
4789 | static void | |
4790 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4791 | { | |
4792 | if (val == NULL) | |
4793 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4794 | else | |
79a45b7d TT |
4795 | { |
4796 | struct value_print_options opts; | |
4797 | get_user_print_options (&opts); | |
4798 | value_print (val, stream, &opts); | |
4799 | } | |
fa4727a6 DJ |
4800 | } |
4801 | ||
f303dbd6 PA |
4802 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4803 | debugging multiple threads. */ | |
4804 | ||
4805 | void | |
4806 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4807 | { | |
4808 | if (ui_out_is_mi_like_p (uiout)) | |
4809 | return; | |
4810 | ||
4811 | ui_out_text (uiout, "\n"); | |
4812 | ||
4813 | if (show_thread_that_caused_stop ()) | |
4814 | { | |
4815 | const char *name; | |
4816 | struct thread_info *thr = inferior_thread (); | |
4817 | ||
4818 | ui_out_text (uiout, "Thread "); | |
4819 | ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr)); | |
4820 | ||
4821 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4822 | if (name != NULL) | |
4823 | { | |
4824 | ui_out_text (uiout, " \""); | |
4825 | ui_out_field_fmt (uiout, "name", "%s", name); | |
4826 | ui_out_text (uiout, "\""); | |
4827 | } | |
4828 | ||
4829 | ui_out_text (uiout, " hit "); | |
4830 | } | |
4831 | } | |
4832 | ||
e514a9d6 | 4833 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4834 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4835 | 'print_it' in the bpstat structure. Under some circumstances we |
4836 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4837 | normal_stop(). */ |
e514a9d6 JM |
4838 | |
4839 | static enum print_stop_action | |
4840 | print_bp_stop_message (bpstat bs) | |
4841 | { | |
4842 | switch (bs->print_it) | |
4843 | { | |
4844 | case print_it_noop: | |
4a64f543 | 4845 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4846 | return PRINT_UNKNOWN; |
4847 | break; | |
4848 | ||
4849 | case print_it_done: | |
4850 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4851 | relevant messages. */ |
e514a9d6 JM |
4852 | return PRINT_SRC_AND_LOC; |
4853 | break; | |
4854 | ||
4855 | case print_it_normal: | |
4f8d1dc6 | 4856 | { |
f431efe5 PA |
4857 | struct breakpoint *b = bs->breakpoint_at; |
4858 | ||
1a6a67de TJB |
4859 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4860 | which has since been deleted. */ | |
4861 | if (b == NULL) | |
4862 | return PRINT_UNKNOWN; | |
4863 | ||
348d480f PA |
4864 | /* Normal case. Call the breakpoint's print_it method. */ |
4865 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4866 | } |
348d480f | 4867 | break; |
3086aeae | 4868 | |
e514a9d6 | 4869 | default: |
8e65ff28 | 4870 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4871 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4872 | break; |
c906108c | 4873 | } |
c906108c SS |
4874 | } |
4875 | ||
edcc5120 TT |
4876 | /* A helper function that prints a shared library stopped event. */ |
4877 | ||
4878 | static void | |
4879 | print_solib_event (int is_catchpoint) | |
4880 | { | |
4881 | int any_deleted | |
4882 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4883 | int any_added | |
4884 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4885 | ||
4886 | if (!is_catchpoint) | |
4887 | { | |
4888 | if (any_added || any_deleted) | |
4889 | ui_out_text (current_uiout, | |
4890 | _("Stopped due to shared library event:\n")); | |
4891 | else | |
4892 | ui_out_text (current_uiout, | |
4893 | _("Stopped due to shared library event (no " | |
4894 | "libraries added or removed)\n")); | |
4895 | } | |
4896 | ||
4897 | if (ui_out_is_mi_like_p (current_uiout)) | |
4898 | ui_out_field_string (current_uiout, "reason", | |
4899 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4900 | ||
4901 | if (any_deleted) | |
4902 | { | |
4903 | struct cleanup *cleanup; | |
4904 | char *name; | |
4905 | int ix; | |
4906 | ||
4907 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4908 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4909 | "removed"); | |
4910 | for (ix = 0; | |
4911 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4912 | ix, name); | |
4913 | ++ix) | |
4914 | { | |
4915 | if (ix > 0) | |
4916 | ui_out_text (current_uiout, " "); | |
4917 | ui_out_field_string (current_uiout, "library", name); | |
4918 | ui_out_text (current_uiout, "\n"); | |
4919 | } | |
4920 | ||
4921 | do_cleanups (cleanup); | |
4922 | } | |
4923 | ||
4924 | if (any_added) | |
4925 | { | |
4926 | struct so_list *iter; | |
4927 | int ix; | |
4928 | struct cleanup *cleanup; | |
4929 | ||
4930 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4931 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4932 | "added"); | |
4933 | for (ix = 0; | |
4934 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4935 | ix, iter); | |
4936 | ++ix) | |
4937 | { | |
4938 | if (ix > 0) | |
4939 | ui_out_text (current_uiout, " "); | |
4940 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4941 | ui_out_text (current_uiout, "\n"); | |
4942 | } | |
4943 | ||
4944 | do_cleanups (cleanup); | |
4945 | } | |
4946 | } | |
4947 | ||
e514a9d6 JM |
4948 | /* Print a message indicating what happened. This is called from |
4949 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4950 | list - a list of the eventpoints that caused this stop. KIND is |
4951 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4952 | routine calls the generic print routine for printing a message |
4953 | about reasons for stopping. This will print (for example) the | |
4954 | "Breakpoint n," part of the output. The return value of this | |
4955 | routine is one of: | |
c906108c | 4956 | |
4a64f543 | 4957 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4958 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4959 | code to print the location. An example is |
c5aa993b JM |
4960 | "Breakpoint 1, " which should be followed by |
4961 | the location. | |
917317f4 | 4962 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4963 | to also print the location part of the message. |
4964 | An example is the catch/throw messages, which | |
4a64f543 | 4965 | don't require a location appended to the end. |
917317f4 | 4966 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4967 | further info to be printed. */ |
c906108c | 4968 | |
917317f4 | 4969 | enum print_stop_action |
36dfb11c | 4970 | bpstat_print (bpstat bs, int kind) |
c906108c | 4971 | { |
f486487f | 4972 | enum print_stop_action val; |
c5aa993b | 4973 | |
c906108c | 4974 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4975 | (Currently all watchpoints go on the bpstat whether hit or not. |
4976 | That probably could (should) be changed, provided care is taken | |
c906108c | 4977 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4978 | for (; bs; bs = bs->next) |
4979 | { | |
4980 | val = print_bp_stop_message (bs); | |
4981 | if (val == PRINT_SRC_ONLY | |
4982 | || val == PRINT_SRC_AND_LOC | |
4983 | || val == PRINT_NOTHING) | |
4984 | return val; | |
4985 | } | |
c906108c | 4986 | |
36dfb11c TT |
4987 | /* If we had hit a shared library event breakpoint, |
4988 | print_bp_stop_message would print out this message. If we hit an | |
4989 | OS-level shared library event, do the same thing. */ | |
4990 | if (kind == TARGET_WAITKIND_LOADED) | |
4991 | { | |
edcc5120 | 4992 | print_solib_event (0); |
36dfb11c TT |
4993 | return PRINT_NOTHING; |
4994 | } | |
4995 | ||
e514a9d6 | 4996 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4997 | with and nothing was printed. */ |
917317f4 | 4998 | return PRINT_UNKNOWN; |
c906108c SS |
4999 | } |
5000 | ||
c42bd95a DE |
5001 | /* Evaluate the expression EXP and return 1 if value is zero. |
5002 | This returns the inverse of the condition because it is called | |
5003 | from catch_errors which returns 0 if an exception happened, and if an | |
5004 | exception happens we want execution to stop. | |
4a64f543 | 5005 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 5006 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
5007 | |
5008 | static int | |
4efb68b1 | 5009 | breakpoint_cond_eval (void *exp) |
c906108c | 5010 | { |
278cd55f | 5011 | struct value *mark = value_mark (); |
c5aa993b | 5012 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 5013 | |
c906108c SS |
5014 | value_free_to_mark (mark); |
5015 | return i; | |
5016 | } | |
5017 | ||
5760d0ab | 5018 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5019 | |
5020 | static bpstat | |
5760d0ab | 5021 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5022 | { |
5023 | bpstat bs; | |
5024 | ||
5025 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5026 | bs->next = NULL; |
5027 | **bs_link_pointer = bs; | |
5028 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5029 | bs->breakpoint_at = bl->owner; |
5030 | bs->bp_location_at = bl; | |
5031 | incref_bp_location (bl); | |
c906108c SS |
5032 | /* If the condition is false, etc., don't do the commands. */ |
5033 | bs->commands = NULL; | |
5034 | bs->old_val = NULL; | |
5035 | bs->print_it = print_it_normal; | |
5036 | return bs; | |
5037 | } | |
5038 | \f | |
d983da9c DJ |
5039 | /* The target has stopped with waitstatus WS. Check if any hardware |
5040 | watchpoints have triggered, according to the target. */ | |
5041 | ||
5042 | int | |
5043 | watchpoints_triggered (struct target_waitstatus *ws) | |
5044 | { | |
d92524f1 | 5045 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5046 | CORE_ADDR addr; |
5047 | struct breakpoint *b; | |
5048 | ||
5049 | if (!stopped_by_watchpoint) | |
5050 | { | |
5051 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5052 | as not triggered. */ | |
5053 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5054 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5055 | { |
5056 | struct watchpoint *w = (struct watchpoint *) b; | |
5057 | ||
5058 | w->watchpoint_triggered = watch_triggered_no; | |
5059 | } | |
d983da9c DJ |
5060 | |
5061 | return 0; | |
5062 | } | |
5063 | ||
5064 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5065 | { | |
5066 | /* We were stopped by a watchpoint, but we don't know where. | |
5067 | Mark all watchpoints as unknown. */ | |
5068 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5069 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5070 | { |
5071 | struct watchpoint *w = (struct watchpoint *) b; | |
5072 | ||
5073 | w->watchpoint_triggered = watch_triggered_unknown; | |
5074 | } | |
d983da9c | 5075 | |
3c4797ba | 5076 | return 1; |
d983da9c DJ |
5077 | } |
5078 | ||
5079 | /* The target could report the data address. Mark watchpoints | |
5080 | affected by this data address as triggered, and all others as not | |
5081 | triggered. */ | |
5082 | ||
5083 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5084 | if (is_hardware_watchpoint (b)) |
d983da9c | 5085 | { |
3a5c3e22 | 5086 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5087 | struct bp_location *loc; |
d983da9c | 5088 | |
3a5c3e22 | 5089 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5090 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5091 | { |
3a5c3e22 | 5092 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5093 | { |
3a5c3e22 PA |
5094 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5095 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5096 | |
5097 | if (newaddr == start) | |
5098 | { | |
3a5c3e22 | 5099 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5100 | break; |
5101 | } | |
5102 | } | |
5103 | /* Exact match not required. Within range is sufficient. */ | |
5104 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5105 | addr, loc->address, | |
5106 | loc->length)) | |
5107 | { | |
3a5c3e22 | 5108 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5109 | break; |
5110 | } | |
5111 | } | |
d983da9c DJ |
5112 | } |
5113 | ||
5114 | return 1; | |
5115 | } | |
5116 | ||
c906108c SS |
5117 | /* Possible return values for watchpoint_check (this can't be an enum |
5118 | because of check_errors). */ | |
5119 | /* The watchpoint has been deleted. */ | |
5120 | #define WP_DELETED 1 | |
5121 | /* The value has changed. */ | |
5122 | #define WP_VALUE_CHANGED 2 | |
5123 | /* The value has not changed. */ | |
5124 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5125 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5126 | #define WP_IGNORE 4 | |
c906108c SS |
5127 | |
5128 | #define BP_TEMPFLAG 1 | |
5129 | #define BP_HARDWAREFLAG 2 | |
5130 | ||
4a64f543 MS |
5131 | /* Evaluate watchpoint condition expression and check if its value |
5132 | changed. | |
553e4c11 JB |
5133 | |
5134 | P should be a pointer to struct bpstat, but is defined as a void * | |
5135 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5136 | |
5137 | static int | |
4efb68b1 | 5138 | watchpoint_check (void *p) |
c906108c SS |
5139 | { |
5140 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5141 | struct watchpoint *b; |
c906108c SS |
5142 | struct frame_info *fr; |
5143 | int within_current_scope; | |
5144 | ||
f431efe5 | 5145 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5146 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5147 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5148 | |
f6bc2008 PA |
5149 | /* If this is a local watchpoint, we only want to check if the |
5150 | watchpoint frame is in scope if the current thread is the thread | |
5151 | that was used to create the watchpoint. */ | |
5152 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5153 | return WP_IGNORE; |
f6bc2008 | 5154 | |
c906108c SS |
5155 | if (b->exp_valid_block == NULL) |
5156 | within_current_scope = 1; | |
5157 | else | |
5158 | { | |
edb3359d DJ |
5159 | struct frame_info *frame = get_current_frame (); |
5160 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5161 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5162 | ||
c9cf6e20 | 5163 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5164 | still in the function but the stack frame has already been |
5165 | invalidated. Since we can't rely on the values of local | |
5166 | variables after the stack has been destroyed, we are treating | |
5167 | the watchpoint in that state as `not changed' without further | |
5168 | checking. Don't mark watchpoints as changed if the current | |
5169 | frame is in an epilogue - even if they are in some other | |
5170 | frame, our view of the stack is likely to be wrong and | |
5171 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5172 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5173 | return WP_IGNORE; |
a0f49112 | 5174 | |
101dcfbe | 5175 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5176 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5177 | |
5178 | /* If we've gotten confused in the unwinder, we might have | |
5179 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5180 | if (within_current_scope) |
5181 | { | |
5182 | struct symbol *function; | |
5183 | ||
5184 | function = get_frame_function (fr); | |
5185 | if (function == NULL | |
5186 | || !contained_in (b->exp_valid_block, | |
5187 | SYMBOL_BLOCK_VALUE (function))) | |
5188 | within_current_scope = 0; | |
5189 | } | |
69fbadd5 | 5190 | |
edb3359d | 5191 | if (within_current_scope) |
c906108c SS |
5192 | /* If we end up stopping, the current frame will get selected |
5193 | in normal_stop. So this call to select_frame won't affect | |
5194 | the user. */ | |
0f7d239c | 5195 | select_frame (fr); |
c906108c | 5196 | } |
c5aa993b | 5197 | |
c906108c SS |
5198 | if (within_current_scope) |
5199 | { | |
4a64f543 MS |
5200 | /* We use value_{,free_to_}mark because it could be a *long* |
5201 | time before we return to the command level and call | |
5202 | free_all_values. We can't call free_all_values because we | |
5203 | might be in the middle of evaluating a function call. */ | |
c906108c | 5204 | |
0cf6dd15 | 5205 | int pc = 0; |
9c06b0b4 | 5206 | struct value *mark; |
fa4727a6 DJ |
5207 | struct value *new_val; |
5208 | ||
3a5c3e22 | 5209 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5210 | /* Since we don't know the exact trigger address (from |
5211 | stopped_data_address), just tell the user we've triggered | |
5212 | a mask watchpoint. */ | |
5213 | return WP_VALUE_CHANGED; | |
5214 | ||
5215 | mark = value_mark (); | |
4d01a485 | 5216 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5217 | |
bb9d5f81 PP |
5218 | if (b->val_bitsize != 0) |
5219 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5220 | ||
4a64f543 MS |
5221 | /* We use value_equal_contents instead of value_equal because |
5222 | the latter coerces an array to a pointer, thus comparing just | |
5223 | the address of the array instead of its contents. This is | |
5224 | not what we want. */ | |
fa4727a6 | 5225 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5226 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5227 | { |
fa4727a6 DJ |
5228 | if (new_val != NULL) |
5229 | { | |
5230 | release_value (new_val); | |
5231 | value_free_to_mark (mark); | |
5232 | } | |
c906108c SS |
5233 | bs->old_val = b->val; |
5234 | b->val = new_val; | |
fa4727a6 | 5235 | b->val_valid = 1; |
c906108c SS |
5236 | return WP_VALUE_CHANGED; |
5237 | } | |
5238 | else | |
5239 | { | |
60e1c644 | 5240 | /* Nothing changed. */ |
c906108c | 5241 | value_free_to_mark (mark); |
c906108c SS |
5242 | return WP_VALUE_NOT_CHANGED; |
5243 | } | |
5244 | } | |
5245 | else | |
5246 | { | |
5247 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5248 | if we temporarily ignored the watchpoint, then when |
5249 | we reenter the block in which it is valid it contains | |
5250 | garbage (in the case of a function, it may have two | |
5251 | garbage values, one before and one after the prologue). | |
5252 | So we can't even detect the first assignment to it and | |
5253 | watch after that (since the garbage may or may not equal | |
5254 | the first value assigned). */ | |
348d480f PA |
5255 | /* We print all the stop information in |
5256 | breakpoint_ops->print_it, but in this case, by the time we | |
5257 | call breakpoint_ops->print_it this bp will be deleted | |
5258 | already. So we have no choice but print the information | |
5259 | here. */ | |
468afe6c | 5260 | |
0e454242 | 5261 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5262 | { |
5263 | struct ui_out *uiout = current_uiout; | |
5264 | ||
5265 | if (ui_out_is_mi_like_p (uiout)) | |
5266 | ui_out_field_string | |
5267 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5268 | ui_out_text (uiout, "\nWatchpoint "); | |
5269 | ui_out_field_int (uiout, "wpnum", b->base.number); | |
5270 | ui_out_text (uiout, | |
5271 | " deleted because the program has left the block in\n" | |
5272 | "which its expression is valid.\n"); | |
5273 | } | |
4ce44c66 | 5274 | |
cdac0397 | 5275 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5276 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5277 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5278 | |
5279 | return WP_DELETED; | |
5280 | } | |
5281 | } | |
5282 | ||
18a18393 | 5283 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5284 | breakpoint location BL. This function does not check if we should |
5285 | stop, only if BL explains the stop. */ | |
5286 | ||
18a18393 | 5287 | static int |
6c95b8df | 5288 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5289 | struct address_space *aspace, CORE_ADDR bp_addr, |
5290 | const struct target_waitstatus *ws) | |
18a18393 VP |
5291 | { |
5292 | struct breakpoint *b = bl->owner; | |
5293 | ||
348d480f | 5294 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5295 | gdb_assert (b != NULL); |
5296 | ||
09ac7c10 | 5297 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5298 | } |
5299 | ||
3a5c3e22 PA |
5300 | /* Determine if the watched values have actually changed, and we |
5301 | should stop. If not, set BS->stop to 0. */ | |
5302 | ||
18a18393 VP |
5303 | static void |
5304 | bpstat_check_watchpoint (bpstat bs) | |
5305 | { | |
2bdf28a0 | 5306 | const struct bp_location *bl; |
3a5c3e22 | 5307 | struct watchpoint *b; |
2bdf28a0 JK |
5308 | |
5309 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5310 | bl = bs->bp_location_at; |
2bdf28a0 | 5311 | gdb_assert (bl != NULL); |
3a5c3e22 | 5312 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5313 | gdb_assert (b != NULL); |
18a18393 | 5314 | |
18a18393 | 5315 | { |
18a18393 VP |
5316 | int must_check_value = 0; |
5317 | ||
3a5c3e22 | 5318 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5319 | /* For a software watchpoint, we must always check the |
5320 | watched value. */ | |
5321 | must_check_value = 1; | |
5322 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5323 | /* We have a hardware watchpoint (read, write, or access) | |
5324 | and the target earlier reported an address watched by | |
5325 | this watchpoint. */ | |
5326 | must_check_value = 1; | |
5327 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5328 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5329 | /* We were stopped by a hardware watchpoint, but the target could |
5330 | not report the data address. We must check the watchpoint's | |
5331 | value. Access and read watchpoints are out of luck; without | |
5332 | a data address, we can't figure it out. */ | |
5333 | must_check_value = 1; | |
3a5c3e22 | 5334 | |
18a18393 VP |
5335 | if (must_check_value) |
5336 | { | |
3e43a32a MS |
5337 | char *message |
5338 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5339 | b->base.number); |
18a18393 VP |
5340 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5341 | int e = catch_errors (watchpoint_check, bs, message, | |
5342 | RETURN_MASK_ALL); | |
5343 | do_cleanups (cleanups); | |
5344 | switch (e) | |
5345 | { | |
5346 | case WP_DELETED: | |
5347 | /* We've already printed what needs to be printed. */ | |
5348 | bs->print_it = print_it_done; | |
5349 | /* Stop. */ | |
5350 | break; | |
60e1c644 PA |
5351 | case WP_IGNORE: |
5352 | bs->print_it = print_it_noop; | |
5353 | bs->stop = 0; | |
5354 | break; | |
18a18393 | 5355 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5356 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5357 | { |
85d721b8 PA |
5358 | /* There are two cases to consider here: |
5359 | ||
4a64f543 | 5360 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5361 | In that case, trust the target, and always report |
5362 | the watchpoint hit to the user. Even though | |
5363 | reads don't cause value changes, the value may | |
5364 | have changed since the last time it was read, and | |
5365 | since we're not trapping writes, we will not see | |
5366 | those, and as such we should ignore our notion of | |
5367 | old value. | |
5368 | ||
4a64f543 | 5369 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5370 | reads and writes. There are two ways this may |
5371 | happen: | |
5372 | ||
4a64f543 | 5373 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5374 | reads only, but can break on accesses (reads or |
5375 | writes), such as e.g., x86. We detect this case | |
5376 | at the time we try to insert read watchpoints. | |
5377 | ||
4a64f543 | 5378 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5379 | watchpoints, but, the user set an access or write |
5380 | watchpoint watching the same memory as this read | |
5381 | watchpoint. | |
5382 | ||
5383 | If we're watching memory writes as well as reads, | |
5384 | ignore watchpoint hits when we find that the | |
5385 | value hasn't changed, as reads don't cause | |
5386 | changes. This still gives false positives when | |
5387 | the program writes the same value to memory as | |
5388 | what there was already in memory (we will confuse | |
5389 | it for a read), but it's much better than | |
5390 | nothing. */ | |
5391 | ||
5392 | int other_write_watchpoint = 0; | |
5393 | ||
5394 | if (bl->watchpoint_type == hw_read) | |
5395 | { | |
5396 | struct breakpoint *other_b; | |
5397 | ||
5398 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5399 | if (other_b->type == bp_hardware_watchpoint |
5400 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5401 | { |
3a5c3e22 PA |
5402 | struct watchpoint *other_w = |
5403 | (struct watchpoint *) other_b; | |
5404 | ||
5405 | if (other_w->watchpoint_triggered | |
5406 | == watch_triggered_yes) | |
5407 | { | |
5408 | other_write_watchpoint = 1; | |
5409 | break; | |
5410 | } | |
85d721b8 PA |
5411 | } |
5412 | } | |
5413 | ||
5414 | if (other_write_watchpoint | |
5415 | || bl->watchpoint_type == hw_access) | |
5416 | { | |
5417 | /* We're watching the same memory for writes, | |
5418 | and the value changed since the last time we | |
5419 | updated it, so this trap must be for a write. | |
5420 | Ignore it. */ | |
5421 | bs->print_it = print_it_noop; | |
5422 | bs->stop = 0; | |
5423 | } | |
18a18393 VP |
5424 | } |
5425 | break; | |
5426 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5427 | if (b->base.type == bp_hardware_watchpoint |
5428 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5429 | { |
5430 | /* Don't stop: write watchpoints shouldn't fire if | |
5431 | the value hasn't changed. */ | |
5432 | bs->print_it = print_it_noop; | |
5433 | bs->stop = 0; | |
5434 | } | |
5435 | /* Stop. */ | |
5436 | break; | |
5437 | default: | |
5438 | /* Can't happen. */ | |
5439 | case 0: | |
5440 | /* Error from catch_errors. */ | |
468afe6c | 5441 | { |
0e454242 | 5442 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5443 | { |
5444 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5445 | b->base.number); | |
5446 | } | |
5447 | watchpoint_del_at_next_stop (b); | |
5448 | /* We've already printed what needs to be printed. */ | |
5449 | bs->print_it = print_it_done; | |
5450 | } | |
18a18393 VP |
5451 | break; |
5452 | } | |
5453 | } | |
5454 | else /* must_check_value == 0 */ | |
5455 | { | |
5456 | /* This is a case where some watchpoint(s) triggered, but | |
5457 | not at the address of this watchpoint, or else no | |
5458 | watchpoint triggered after all. So don't print | |
5459 | anything for this watchpoint. */ | |
5460 | bs->print_it = print_it_noop; | |
5461 | bs->stop = 0; | |
5462 | } | |
5463 | } | |
5464 | } | |
5465 | ||
7d4df6a4 DE |
5466 | /* For breakpoints that are currently marked as telling gdb to stop, |
5467 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5468 | of breakpoint referred to by BS. If we should not stop for this |
5469 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5470 | |
18a18393 VP |
5471 | static void |
5472 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5473 | { | |
2bdf28a0 JK |
5474 | const struct bp_location *bl; |
5475 | struct breakpoint *b; | |
7d4df6a4 DE |
5476 | int value_is_zero = 0; |
5477 | struct expression *cond; | |
5478 | ||
5479 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5480 | |
5481 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5482 | bl = bs->bp_location_at; |
2bdf28a0 | 5483 | gdb_assert (bl != NULL); |
f431efe5 | 5484 | b = bs->breakpoint_at; |
2bdf28a0 | 5485 | gdb_assert (b != NULL); |
18a18393 | 5486 | |
b775012e LM |
5487 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5488 | need to do so again since GDB does not know if we stopped due to a | |
5489 | breakpoint or a single step breakpoint. */ | |
5490 | ||
18a18393 | 5491 | if (frame_id_p (b->frame_id) |
edb3359d | 5492 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5493 | { |
7d4df6a4 DE |
5494 | bs->stop = 0; |
5495 | return; | |
5496 | } | |
60e1c644 | 5497 | |
12ab52e9 PA |
5498 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5499 | evaluating the condition if this isn't the specified | |
5500 | thread/task. */ | |
5d5658a1 | 5501 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5502 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5503 | ||
6c1b0f7b DE |
5504 | { |
5505 | bs->stop = 0; | |
5506 | return; | |
5507 | } | |
5508 | ||
6dddc817 DE |
5509 | /* Evaluate extension language breakpoints that have a "stop" method |
5510 | implemented. */ | |
5511 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5512 | |
7d4df6a4 DE |
5513 | if (is_watchpoint (b)) |
5514 | { | |
5515 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5516 | |
4d01a485 | 5517 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5518 | } |
5519 | else | |
4d01a485 | 5520 | cond = bl->cond.get (); |
60e1c644 | 5521 | |
7d4df6a4 DE |
5522 | if (cond && b->disposition != disp_del_at_next_stop) |
5523 | { | |
5524 | int within_current_scope = 1; | |
5525 | struct watchpoint * w; | |
60e1c644 | 5526 | |
7d4df6a4 DE |
5527 | /* We use value_mark and value_free_to_mark because it could |
5528 | be a long time before we return to the command level and | |
5529 | call free_all_values. We can't call free_all_values | |
5530 | because we might be in the middle of evaluating a | |
5531 | function call. */ | |
5532 | struct value *mark = value_mark (); | |
5533 | ||
5534 | if (is_watchpoint (b)) | |
5535 | w = (struct watchpoint *) b; | |
5536 | else | |
5537 | w = NULL; | |
5538 | ||
5539 | /* Need to select the frame, with all that implies so that | |
5540 | the conditions will have the right context. Because we | |
5541 | use the frame, we will not see an inlined function's | |
5542 | variables when we arrive at a breakpoint at the start | |
5543 | of the inlined function; the current frame will be the | |
5544 | call site. */ | |
5545 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5546 | select_frame (get_current_frame ()); | |
5547 | else | |
18a18393 | 5548 | { |
7d4df6a4 DE |
5549 | struct frame_info *frame; |
5550 | ||
5551 | /* For local watchpoint expressions, which particular | |
5552 | instance of a local is being watched matters, so we | |
5553 | keep track of the frame to evaluate the expression | |
5554 | in. To evaluate the condition however, it doesn't | |
5555 | really matter which instantiation of the function | |
5556 | where the condition makes sense triggers the | |
5557 | watchpoint. This allows an expression like "watch | |
5558 | global if q > 10" set in `func', catch writes to | |
5559 | global on all threads that call `func', or catch | |
5560 | writes on all recursive calls of `func' by a single | |
5561 | thread. We simply always evaluate the condition in | |
5562 | the innermost frame that's executing where it makes | |
5563 | sense to evaluate the condition. It seems | |
5564 | intuitive. */ | |
5565 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5566 | if (frame != NULL) | |
5567 | select_frame (frame); | |
5568 | else | |
5569 | within_current_scope = 0; | |
18a18393 | 5570 | } |
7d4df6a4 DE |
5571 | if (within_current_scope) |
5572 | value_is_zero | |
5573 | = catch_errors (breakpoint_cond_eval, cond, | |
5574 | "Error in testing breakpoint condition:\n", | |
5575 | RETURN_MASK_ALL); | |
5576 | else | |
18a18393 | 5577 | { |
7d4df6a4 DE |
5578 | warning (_("Watchpoint condition cannot be tested " |
5579 | "in the current scope")); | |
5580 | /* If we failed to set the right context for this | |
5581 | watchpoint, unconditionally report it. */ | |
5582 | value_is_zero = 0; | |
18a18393 | 5583 | } |
7d4df6a4 DE |
5584 | /* FIXME-someday, should give breakpoint #. */ |
5585 | value_free_to_mark (mark); | |
18a18393 | 5586 | } |
7d4df6a4 DE |
5587 | |
5588 | if (cond && value_is_zero) | |
5589 | { | |
5590 | bs->stop = 0; | |
5591 | } | |
7d4df6a4 DE |
5592 | else if (b->ignore_count > 0) |
5593 | { | |
5594 | b->ignore_count--; | |
5595 | bs->stop = 0; | |
5596 | /* Increase the hit count even though we don't stop. */ | |
5597 | ++(b->hit_count); | |
5598 | observer_notify_breakpoint_modified (b); | |
5599 | } | |
18a18393 VP |
5600 | } |
5601 | ||
1cf4d951 PA |
5602 | /* Returns true if we need to track moribund locations of LOC's type |
5603 | on the current target. */ | |
5604 | ||
5605 | static int | |
5606 | need_moribund_for_location_type (struct bp_location *loc) | |
5607 | { | |
5608 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5609 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5610 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5611 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5612 | } | |
5613 | ||
18a18393 | 5614 | |
9709f61c | 5615 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5616 | BP_ADDR in thread PTID. |
c906108c | 5617 | |
d983da9c | 5618 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5619 | don't understand this stop. Result is a chain of bpstat's such |
5620 | that: | |
c906108c | 5621 | |
c5aa993b | 5622 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5623 | |
c5aa993b | 5624 | if we understand why we stopped, the result is not null. |
c906108c | 5625 | |
c5aa993b JM |
5626 | Each element of the chain refers to a particular breakpoint or |
5627 | watchpoint at which we have stopped. (We may have stopped for | |
5628 | several reasons concurrently.) | |
c906108c | 5629 | |
c5aa993b JM |
5630 | Each element of the chain has valid next, breakpoint_at, |
5631 | commands, FIXME??? fields. */ | |
c906108c SS |
5632 | |
5633 | bpstat | |
6c95b8df | 5634 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5635 | CORE_ADDR bp_addr, ptid_t ptid, |
5636 | const struct target_waitstatus *ws) | |
c906108c | 5637 | { |
0d381245 | 5638 | struct breakpoint *b = NULL; |
afe38095 | 5639 | struct bp_location *bl; |
20874c92 | 5640 | struct bp_location *loc; |
5760d0ab JK |
5641 | /* First item of allocated bpstat's. */ |
5642 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5643 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5644 | bpstat bs; |
20874c92 | 5645 | int ix; |
429374b8 | 5646 | int need_remove_insert; |
f431efe5 | 5647 | int removed_any; |
c906108c | 5648 | |
f431efe5 PA |
5649 | /* First, build the bpstat chain with locations that explain a |
5650 | target stop, while being careful to not set the target running, | |
5651 | as that may invalidate locations (in particular watchpoint | |
5652 | locations are recreated). Resuming will happen here with | |
5653 | breakpoint conditions or watchpoint expressions that include | |
5654 | inferior function calls. */ | |
c5aa993b | 5655 | |
429374b8 JK |
5656 | ALL_BREAKPOINTS (b) |
5657 | { | |
1a853c52 | 5658 | if (!breakpoint_enabled (b)) |
429374b8 | 5659 | continue; |
a5606eee | 5660 | |
429374b8 JK |
5661 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5662 | { | |
4a64f543 MS |
5663 | /* For hardware watchpoints, we look only at the first |
5664 | location. The watchpoint_check function will work on the | |
5665 | entire expression, not the individual locations. For | |
5666 | read watchpoints, the watchpoints_triggered function has | |
5667 | checked all locations already. */ | |
429374b8 JK |
5668 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5669 | break; | |
18a18393 | 5670 | |
f6592439 | 5671 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5672 | continue; |
c5aa993b | 5673 | |
09ac7c10 | 5674 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5675 | continue; |
c5aa993b | 5676 | |
4a64f543 MS |
5677 | /* Come here if it's a watchpoint, or if the break address |
5678 | matches. */ | |
c5aa993b | 5679 | |
4a64f543 MS |
5680 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5681 | explain stop. */ | |
c5aa993b | 5682 | |
f431efe5 PA |
5683 | /* Assume we stop. Should we find a watchpoint that is not |
5684 | actually triggered, or if the condition of the breakpoint | |
5685 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5686 | bs->stop = 1; |
5687 | bs->print = 1; | |
d983da9c | 5688 | |
f431efe5 PA |
5689 | /* If this is a scope breakpoint, mark the associated |
5690 | watchpoint as triggered so that we will handle the | |
5691 | out-of-scope event. We'll get to the watchpoint next | |
5692 | iteration. */ | |
d0fb5eae | 5693 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5694 | { |
5695 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5696 | ||
5697 | w->watchpoint_triggered = watch_triggered_yes; | |
5698 | } | |
f431efe5 PA |
5699 | } |
5700 | } | |
5701 | ||
7c16b83e | 5702 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5703 | if (!target_supports_stopped_by_sw_breakpoint () |
5704 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5705 | { |
1cf4d951 | 5706 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5707 | { |
1cf4d951 PA |
5708 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5709 | && need_moribund_for_location_type (loc)) | |
5710 | { | |
5711 | bs = bpstat_alloc (loc, &bs_link); | |
5712 | /* For hits of moribund locations, we should just proceed. */ | |
5713 | bs->stop = 0; | |
5714 | bs->print = 0; | |
5715 | bs->print_it = print_it_noop; | |
5716 | } | |
f431efe5 PA |
5717 | } |
5718 | } | |
5719 | ||
edcc5120 TT |
5720 | /* A bit of special processing for shlib breakpoints. We need to |
5721 | process solib loading here, so that the lists of loaded and | |
5722 | unloaded libraries are correct before we handle "catch load" and | |
5723 | "catch unload". */ | |
5724 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5725 | { | |
5d268276 | 5726 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5727 | { |
5728 | handle_solib_event (); | |
5729 | break; | |
5730 | } | |
5731 | } | |
5732 | ||
f431efe5 PA |
5733 | /* Now go through the locations that caused the target to stop, and |
5734 | check whether we're interested in reporting this stop to higher | |
5735 | layers, or whether we should resume the target transparently. */ | |
5736 | ||
5737 | removed_any = 0; | |
5738 | ||
5760d0ab | 5739 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5740 | { |
5741 | if (!bs->stop) | |
5742 | continue; | |
5743 | ||
f431efe5 | 5744 | b = bs->breakpoint_at; |
348d480f PA |
5745 | b->ops->check_status (bs); |
5746 | if (bs->stop) | |
28010a5d | 5747 | { |
348d480f | 5748 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5749 | |
429374b8 JK |
5750 | if (bs->stop) |
5751 | { | |
5752 | ++(b->hit_count); | |
8d3788bd | 5753 | observer_notify_breakpoint_modified (b); |
c906108c | 5754 | |
4a64f543 | 5755 | /* We will stop here. */ |
429374b8 JK |
5756 | if (b->disposition == disp_disable) |
5757 | { | |
816338b5 | 5758 | --(b->enable_count); |
1a853c52 | 5759 | if (b->enable_count <= 0) |
429374b8 | 5760 | b->enable_state = bp_disabled; |
f431efe5 | 5761 | removed_any = 1; |
429374b8 JK |
5762 | } |
5763 | if (b->silent) | |
5764 | bs->print = 0; | |
5765 | bs->commands = b->commands; | |
9add0f1b | 5766 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5767 | if (command_line_is_silent (bs->commands |
5768 | ? bs->commands->commands : NULL)) | |
5769 | bs->print = 0; | |
9d6e6e84 HZ |
5770 | |
5771 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5772 | } |
5773 | ||
348d480f | 5774 | } |
a9b3a50f PA |
5775 | |
5776 | /* Print nothing for this entry if we don't stop or don't | |
5777 | print. */ | |
5778 | if (!bs->stop || !bs->print) | |
5779 | bs->print_it = print_it_noop; | |
429374b8 | 5780 | } |
876fa593 | 5781 | |
d983da9c DJ |
5782 | /* If we aren't stopping, the value of some hardware watchpoint may |
5783 | not have changed, but the intermediate memory locations we are | |
5784 | watching may have. Don't bother if we're stopping; this will get | |
5785 | done later. */ | |
d832cb68 | 5786 | need_remove_insert = 0; |
5760d0ab JK |
5787 | if (! bpstat_causes_stop (bs_head)) |
5788 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5789 | if (!bs->stop |
f431efe5 PA |
5790 | && bs->breakpoint_at |
5791 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5792 | { |
3a5c3e22 PA |
5793 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5794 | ||
5795 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5796 | need_remove_insert = 1; |
d983da9c DJ |
5797 | } |
5798 | ||
d832cb68 | 5799 | if (need_remove_insert) |
44702360 | 5800 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5801 | else if (removed_any) |
44702360 | 5802 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5803 | |
5760d0ab | 5804 | return bs_head; |
c906108c | 5805 | } |
628fe4e4 JK |
5806 | |
5807 | static void | |
5808 | handle_jit_event (void) | |
5809 | { | |
5810 | struct frame_info *frame; | |
5811 | struct gdbarch *gdbarch; | |
5812 | ||
243a9253 PA |
5813 | if (debug_infrun) |
5814 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5815 | ||
628fe4e4 JK |
5816 | /* Switch terminal for any messages produced by |
5817 | breakpoint_re_set. */ | |
5818 | target_terminal_ours_for_output (); | |
5819 | ||
5820 | frame = get_current_frame (); | |
5821 | gdbarch = get_frame_arch (frame); | |
5822 | ||
5823 | jit_event_handler (gdbarch); | |
5824 | ||
5825 | target_terminal_inferior (); | |
5826 | } | |
5827 | ||
5828 | /* Prepare WHAT final decision for infrun. */ | |
5829 | ||
5830 | /* Decide what infrun needs to do with this bpstat. */ | |
5831 | ||
c906108c | 5832 | struct bpstat_what |
0e30163f | 5833 | bpstat_what (bpstat bs_head) |
c906108c | 5834 | { |
c906108c | 5835 | struct bpstat_what retval; |
0e30163f | 5836 | bpstat bs; |
c906108c | 5837 | |
628fe4e4 | 5838 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5839 | retval.call_dummy = STOP_NONE; |
186c406b | 5840 | retval.is_longjmp = 0; |
628fe4e4 | 5841 | |
0e30163f | 5842 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5843 | { |
628fe4e4 JK |
5844 | /* Extract this BS's action. After processing each BS, we check |
5845 | if its action overrides all we've seem so far. */ | |
5846 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5847 | enum bptype bptype; | |
5848 | ||
c906108c | 5849 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5850 | { |
5851 | /* I suspect this can happen if it was a momentary | |
5852 | breakpoint which has since been deleted. */ | |
5853 | bptype = bp_none; | |
5854 | } | |
20874c92 | 5855 | else |
f431efe5 | 5856 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5857 | |
5858 | switch (bptype) | |
c906108c SS |
5859 | { |
5860 | case bp_none: | |
628fe4e4 | 5861 | break; |
c906108c SS |
5862 | case bp_breakpoint: |
5863 | case bp_hardware_breakpoint: | |
7c16b83e | 5864 | case bp_single_step: |
c906108c SS |
5865 | case bp_until: |
5866 | case bp_finish: | |
a9b3a50f | 5867 | case bp_shlib_event: |
c906108c SS |
5868 | if (bs->stop) |
5869 | { | |
5870 | if (bs->print) | |
628fe4e4 | 5871 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5872 | else |
628fe4e4 | 5873 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5874 | } |
5875 | else | |
628fe4e4 | 5876 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5877 | break; |
5878 | case bp_watchpoint: | |
5879 | case bp_hardware_watchpoint: | |
5880 | case bp_read_watchpoint: | |
5881 | case bp_access_watchpoint: | |
5882 | if (bs->stop) | |
5883 | { | |
5884 | if (bs->print) | |
628fe4e4 | 5885 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5886 | else |
628fe4e4 | 5887 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5888 | } |
5889 | else | |
628fe4e4 JK |
5890 | { |
5891 | /* There was a watchpoint, but we're not stopping. | |
5892 | This requires no further action. */ | |
5893 | } | |
c906108c SS |
5894 | break; |
5895 | case bp_longjmp: | |
e2e4d78b | 5896 | case bp_longjmp_call_dummy: |
186c406b | 5897 | case bp_exception: |
0a39bb32 PA |
5898 | if (bs->stop) |
5899 | { | |
5900 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5901 | retval.is_longjmp = bptype != bp_exception; | |
5902 | } | |
5903 | else | |
5904 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5905 | break; |
5906 | case bp_longjmp_resume: | |
186c406b | 5907 | case bp_exception_resume: |
0a39bb32 PA |
5908 | if (bs->stop) |
5909 | { | |
5910 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5911 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5912 | } | |
5913 | else | |
5914 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5915 | break; |
5916 | case bp_step_resume: | |
5917 | if (bs->stop) | |
628fe4e4 JK |
5918 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5919 | else | |
c906108c | 5920 | { |
628fe4e4 JK |
5921 | /* It is for the wrong frame. */ |
5922 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5923 | } |
c906108c | 5924 | break; |
2c03e5be PA |
5925 | case bp_hp_step_resume: |
5926 | if (bs->stop) | |
5927 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5928 | else | |
5929 | { | |
5930 | /* It is for the wrong frame. */ | |
5931 | this_action = BPSTAT_WHAT_SINGLE; | |
5932 | } | |
5933 | break; | |
c906108c | 5934 | case bp_watchpoint_scope: |
c4093a6a | 5935 | case bp_thread_event: |
1900040c | 5936 | case bp_overlay_event: |
0fd8e87f | 5937 | case bp_longjmp_master: |
aa7d318d | 5938 | case bp_std_terminate_master: |
186c406b | 5939 | case bp_exception_master: |
628fe4e4 | 5940 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5941 | break; |
ce78b96d | 5942 | case bp_catchpoint: |
c5aa993b JM |
5943 | if (bs->stop) |
5944 | { | |
5945 | if (bs->print) | |
628fe4e4 | 5946 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5947 | else |
628fe4e4 | 5948 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5949 | } |
5950 | else | |
628fe4e4 JK |
5951 | { |
5952 | /* There was a catchpoint, but we're not stopping. | |
5953 | This requires no further action. */ | |
5954 | } | |
5955 | break; | |
628fe4e4 | 5956 | case bp_jit_event: |
628fe4e4 | 5957 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5958 | break; |
c906108c | 5959 | case bp_call_dummy: |
53a5351d JM |
5960 | /* Make sure the action is stop (silent or noisy), |
5961 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5962 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5963 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5964 | break; |
5965 | case bp_std_terminate: | |
5966 | /* Make sure the action is stop (silent or noisy), | |
5967 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5968 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5969 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5970 | break; |
1042e4c0 | 5971 | case bp_tracepoint: |
7a697b8d | 5972 | case bp_fast_tracepoint: |
0fb4aa4b | 5973 | case bp_static_tracepoint: |
1042e4c0 SS |
5974 | /* Tracepoint hits should not be reported back to GDB, and |
5975 | if one got through somehow, it should have been filtered | |
5976 | out already. */ | |
5977 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5978 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5979 | break; |
5980 | case bp_gnu_ifunc_resolver: | |
5981 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5982 | this_action = BPSTAT_WHAT_SINGLE; | |
5983 | break; | |
5984 | case bp_gnu_ifunc_resolver_return: | |
5985 | /* The breakpoint will be removed, execution will restart from the | |
5986 | PC of the former breakpoint. */ | |
5987 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5988 | break; | |
e7e0cddf SS |
5989 | |
5990 | case bp_dprintf: | |
a11cfd87 HZ |
5991 | if (bs->stop) |
5992 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5993 | else | |
5994 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5995 | break; |
5996 | ||
628fe4e4 JK |
5997 | default: |
5998 | internal_error (__FILE__, __LINE__, | |
5999 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 6000 | } |
628fe4e4 | 6001 | |
325fac50 | 6002 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 6003 | } |
628fe4e4 | 6004 | |
243a9253 PA |
6005 | return retval; |
6006 | } | |
628fe4e4 | 6007 | |
243a9253 PA |
6008 | void |
6009 | bpstat_run_callbacks (bpstat bs_head) | |
6010 | { | |
6011 | bpstat bs; | |
628fe4e4 | 6012 | |
0e30163f JK |
6013 | for (bs = bs_head; bs != NULL; bs = bs->next) |
6014 | { | |
6015 | struct breakpoint *b = bs->breakpoint_at; | |
6016 | ||
6017 | if (b == NULL) | |
6018 | continue; | |
6019 | switch (b->type) | |
6020 | { | |
243a9253 PA |
6021 | case bp_jit_event: |
6022 | handle_jit_event (); | |
6023 | break; | |
0e30163f JK |
6024 | case bp_gnu_ifunc_resolver: |
6025 | gnu_ifunc_resolver_stop (b); | |
6026 | break; | |
6027 | case bp_gnu_ifunc_resolver_return: | |
6028 | gnu_ifunc_resolver_return_stop (b); | |
6029 | break; | |
6030 | } | |
6031 | } | |
c906108c SS |
6032 | } |
6033 | ||
6034 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6035 | without hardware support). This isn't related to a specific bpstat, | |
6036 | just to things like whether watchpoints are set. */ | |
6037 | ||
c5aa993b | 6038 | int |
fba45db2 | 6039 | bpstat_should_step (void) |
c906108c SS |
6040 | { |
6041 | struct breakpoint *b; | |
cc59ec59 | 6042 | |
c906108c | 6043 | ALL_BREAKPOINTS (b) |
717a8278 | 6044 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6045 | return 1; |
c906108c SS |
6046 | return 0; |
6047 | } | |
6048 | ||
67822962 PA |
6049 | int |
6050 | bpstat_causes_stop (bpstat bs) | |
6051 | { | |
6052 | for (; bs != NULL; bs = bs->next) | |
6053 | if (bs->stop) | |
6054 | return 1; | |
6055 | ||
6056 | return 0; | |
6057 | } | |
6058 | ||
c906108c | 6059 | \f |
c5aa993b | 6060 | |
170b53b2 UW |
6061 | /* Compute a string of spaces suitable to indent the next line |
6062 | so it starts at the position corresponding to the table column | |
6063 | named COL_NAME in the currently active table of UIOUT. */ | |
6064 | ||
6065 | static char * | |
6066 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6067 | { | |
6068 | static char wrap_indent[80]; | |
6069 | int i, total_width, width, align; | |
6070 | char *text; | |
6071 | ||
6072 | total_width = 0; | |
6073 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
6074 | { | |
6075 | if (strcmp (text, col_name) == 0) | |
6076 | { | |
6077 | gdb_assert (total_width < sizeof wrap_indent); | |
6078 | memset (wrap_indent, ' ', total_width); | |
6079 | wrap_indent[total_width] = 0; | |
6080 | ||
6081 | return wrap_indent; | |
6082 | } | |
6083 | ||
6084 | total_width += width + 1; | |
6085 | } | |
6086 | ||
6087 | return NULL; | |
6088 | } | |
6089 | ||
b775012e LM |
6090 | /* Determine if the locations of this breakpoint will have their conditions |
6091 | evaluated by the target, host or a mix of both. Returns the following: | |
6092 | ||
6093 | "host": Host evals condition. | |
6094 | "host or target": Host or Target evals condition. | |
6095 | "target": Target evals condition. | |
6096 | */ | |
6097 | ||
6098 | static const char * | |
6099 | bp_condition_evaluator (struct breakpoint *b) | |
6100 | { | |
6101 | struct bp_location *bl; | |
6102 | char host_evals = 0; | |
6103 | char target_evals = 0; | |
6104 | ||
6105 | if (!b) | |
6106 | return NULL; | |
6107 | ||
6108 | if (!is_breakpoint (b)) | |
6109 | return NULL; | |
6110 | ||
6111 | if (gdb_evaluates_breakpoint_condition_p () | |
6112 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6113 | return condition_evaluation_host; | |
6114 | ||
6115 | for (bl = b->loc; bl; bl = bl->next) | |
6116 | { | |
6117 | if (bl->cond_bytecode) | |
6118 | target_evals++; | |
6119 | else | |
6120 | host_evals++; | |
6121 | } | |
6122 | ||
6123 | if (host_evals && target_evals) | |
6124 | return condition_evaluation_both; | |
6125 | else if (target_evals) | |
6126 | return condition_evaluation_target; | |
6127 | else | |
6128 | return condition_evaluation_host; | |
6129 | } | |
6130 | ||
6131 | /* Determine the breakpoint location's condition evaluator. This is | |
6132 | similar to bp_condition_evaluator, but for locations. */ | |
6133 | ||
6134 | static const char * | |
6135 | bp_location_condition_evaluator (struct bp_location *bl) | |
6136 | { | |
6137 | if (bl && !is_breakpoint (bl->owner)) | |
6138 | return NULL; | |
6139 | ||
6140 | if (gdb_evaluates_breakpoint_condition_p () | |
6141 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6142 | return condition_evaluation_host; | |
6143 | ||
6144 | if (bl && bl->cond_bytecode) | |
6145 | return condition_evaluation_target; | |
6146 | else | |
6147 | return condition_evaluation_host; | |
6148 | } | |
6149 | ||
859825b8 JK |
6150 | /* Print the LOC location out of the list of B->LOC locations. */ |
6151 | ||
170b53b2 UW |
6152 | static void |
6153 | print_breakpoint_location (struct breakpoint *b, | |
6154 | struct bp_location *loc) | |
0d381245 | 6155 | { |
79a45e25 | 6156 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6157 | struct cleanup *old_chain = save_current_program_space (); |
6158 | ||
859825b8 JK |
6159 | if (loc != NULL && loc->shlib_disabled) |
6160 | loc = NULL; | |
6161 | ||
6c95b8df PA |
6162 | if (loc != NULL) |
6163 | set_current_program_space (loc->pspace); | |
6164 | ||
56435ebe | 6165 | if (b->display_canonical) |
f00aae0f KS |
6166 | ui_out_field_string (uiout, "what", |
6167 | event_location_to_string (b->location)); | |
2f202fde | 6168 | else if (loc && loc->symtab) |
0d381245 VP |
6169 | { |
6170 | struct symbol *sym | |
6171 | = find_pc_sect_function (loc->address, loc->section); | |
6172 | if (sym) | |
6173 | { | |
6174 | ui_out_text (uiout, "in "); | |
6175 | ui_out_field_string (uiout, "func", | |
6176 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6177 | ui_out_text (uiout, " "); |
6178 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6179 | ui_out_text (uiout, "at "); | |
0d381245 | 6180 | } |
05cba821 JK |
6181 | ui_out_field_string (uiout, "file", |
6182 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6183 | ui_out_text (uiout, ":"); |
05cba821 | 6184 | |
0d381245 | 6185 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6186 | ui_out_field_string (uiout, "fullname", |
6187 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6188 | |
f8eba3c6 | 6189 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6190 | } |
859825b8 | 6191 | else if (loc) |
0d381245 | 6192 | { |
f99d8bf4 PA |
6193 | struct ui_file *stb = mem_fileopen (); |
6194 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6195 | |
f99d8bf4 | 6196 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6197 | demangle, ""); |
0d381245 | 6198 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6199 | |
6200 | do_cleanups (stb_chain); | |
0d381245 | 6201 | } |
859825b8 | 6202 | else |
f00aae0f KS |
6203 | { |
6204 | ui_out_field_string (uiout, "pending", | |
6205 | event_location_to_string (b->location)); | |
6206 | /* If extra_string is available, it could be holding a condition | |
6207 | or dprintf arguments. In either case, make sure it is printed, | |
6208 | too, but only for non-MI streams. */ | |
6209 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) | |
6210 | { | |
6211 | if (b->type == bp_dprintf) | |
6212 | ui_out_text (uiout, ","); | |
6213 | else | |
6214 | ui_out_text (uiout, " "); | |
6215 | ui_out_text (uiout, b->extra_string); | |
6216 | } | |
6217 | } | |
6c95b8df | 6218 | |
b775012e LM |
6219 | if (loc && is_breakpoint (b) |
6220 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6221 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6222 | { | |
6223 | ui_out_text (uiout, " ("); | |
6224 | ui_out_field_string (uiout, "evaluated-by", | |
6225 | bp_location_condition_evaluator (loc)); | |
6226 | ui_out_text (uiout, ")"); | |
6227 | } | |
6228 | ||
6c95b8df | 6229 | do_cleanups (old_chain); |
0d381245 VP |
6230 | } |
6231 | ||
269b11a2 PA |
6232 | static const char * |
6233 | bptype_string (enum bptype type) | |
c906108c | 6234 | { |
c4093a6a JM |
6235 | struct ep_type_description |
6236 | { | |
6237 | enum bptype type; | |
6238 | char *description; | |
6239 | }; | |
6240 | static struct ep_type_description bptypes[] = | |
c906108c | 6241 | { |
c5aa993b JM |
6242 | {bp_none, "?deleted?"}, |
6243 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6244 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6245 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6246 | {bp_until, "until"}, |
6247 | {bp_finish, "finish"}, | |
6248 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6249 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6250 | {bp_read_watchpoint, "read watchpoint"}, |
6251 | {bp_access_watchpoint, "acc watchpoint"}, | |
6252 | {bp_longjmp, "longjmp"}, | |
6253 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6254 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6255 | {bp_exception, "exception"}, |
6256 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6257 | {bp_step_resume, "step resume"}, |
2c03e5be | 6258 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6259 | {bp_watchpoint_scope, "watchpoint scope"}, |
6260 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6261 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6262 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6263 | {bp_thread_event, "thread events"}, |
1900040c | 6264 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6265 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6266 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6267 | {bp_exception_master, "exception master"}, |
ce78b96d | 6268 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6269 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6270 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6271 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6272 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6273 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6274 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6275 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6276 | }; |
269b11a2 PA |
6277 | |
6278 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6279 | || ((int) type != bptypes[(int) type].type)) | |
6280 | internal_error (__FILE__, __LINE__, | |
6281 | _("bptypes table does not describe type #%d."), | |
6282 | (int) type); | |
6283 | ||
6284 | return bptypes[(int) type].description; | |
6285 | } | |
6286 | ||
998580f1 MK |
6287 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6288 | For CLI, prefix the list with the string 'inf'. */ | |
6289 | ||
6290 | static void | |
6291 | output_thread_groups (struct ui_out *uiout, | |
6292 | const char *field_name, | |
6293 | VEC(int) *inf_num, | |
6294 | int mi_only) | |
6295 | { | |
752eb8b4 | 6296 | struct cleanup *back_to; |
998580f1 MK |
6297 | int is_mi = ui_out_is_mi_like_p (uiout); |
6298 | int inf; | |
6299 | int i; | |
6300 | ||
6301 | /* For backward compatibility, don't display inferiors in CLI unless | |
6302 | there are several. Always display them for MI. */ | |
6303 | if (!is_mi && mi_only) | |
6304 | return; | |
6305 | ||
752eb8b4 TT |
6306 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6307 | ||
998580f1 MK |
6308 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6309 | { | |
6310 | if (is_mi) | |
6311 | { | |
6312 | char mi_group[10]; | |
6313 | ||
6314 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6315 | ui_out_field_string (uiout, NULL, mi_group); | |
6316 | } | |
6317 | else | |
6318 | { | |
6319 | if (i == 0) | |
6320 | ui_out_text (uiout, " inf "); | |
6321 | else | |
6322 | ui_out_text (uiout, ", "); | |
6323 | ||
6324 | ui_out_text (uiout, plongest (inf)); | |
6325 | } | |
6326 | } | |
6327 | ||
6328 | do_cleanups (back_to); | |
6329 | } | |
6330 | ||
269b11a2 PA |
6331 | /* Print B to gdb_stdout. */ |
6332 | ||
6333 | static void | |
6334 | print_one_breakpoint_location (struct breakpoint *b, | |
6335 | struct bp_location *loc, | |
6336 | int loc_number, | |
6337 | struct bp_location **last_loc, | |
269b11a2 PA |
6338 | int allflag) |
6339 | { | |
6340 | struct command_line *l; | |
c2c6d25f | 6341 | static char bpenables[] = "nynny"; |
c906108c | 6342 | |
79a45e25 | 6343 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6344 | int header_of_multiple = 0; |
6345 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6346 | struct value_print_options opts; |
6347 | ||
6348 | get_user_print_options (&opts); | |
0d381245 VP |
6349 | |
6350 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6351 | /* See comment in print_one_breakpoint concerning treatment of |
6352 | breakpoints with single disabled location. */ | |
0d381245 VP |
6353 | if (loc == NULL |
6354 | && (b->loc != NULL | |
6355 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6356 | header_of_multiple = 1; | |
6357 | if (loc == NULL) | |
6358 | loc = b->loc; | |
6359 | ||
c4093a6a JM |
6360 | annotate_record (); |
6361 | ||
6362 | /* 1 */ | |
6363 | annotate_field (0); | |
0d381245 VP |
6364 | if (part_of_multiple) |
6365 | { | |
6366 | char *formatted; | |
0c6773c1 | 6367 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6368 | ui_out_field_string (uiout, "number", formatted); |
6369 | xfree (formatted); | |
6370 | } | |
6371 | else | |
6372 | { | |
6373 | ui_out_field_int (uiout, "number", b->number); | |
6374 | } | |
c4093a6a JM |
6375 | |
6376 | /* 2 */ | |
6377 | annotate_field (1); | |
0d381245 VP |
6378 | if (part_of_multiple) |
6379 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6380 | else |
6381 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6382 | |
6383 | /* 3 */ | |
6384 | annotate_field (2); | |
0d381245 VP |
6385 | if (part_of_multiple) |
6386 | ui_out_field_skip (uiout, "disp"); | |
6387 | else | |
2cec12e5 | 6388 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6389 | |
c4093a6a JM |
6390 | |
6391 | /* 4 */ | |
6392 | annotate_field (3); | |
0d381245 | 6393 | if (part_of_multiple) |
54e52265 | 6394 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6395 | else |
4a64f543 MS |
6396 | ui_out_field_fmt (uiout, "enabled", "%c", |
6397 | bpenables[(int) b->enable_state]); | |
54e52265 | 6398 | ui_out_spaces (uiout, 2); |
0d381245 | 6399 | |
c4093a6a JM |
6400 | |
6401 | /* 5 and 6 */ | |
3086aeae | 6402 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6403 | { |
4a64f543 MS |
6404 | /* Although the print_one can possibly print all locations, |
6405 | calling it here is not likely to get any nice result. So, | |
6406 | make sure there's just one location. */ | |
0d381245 | 6407 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6408 | b->ops->print_one (b, last_loc); |
0d381245 | 6409 | } |
3086aeae DJ |
6410 | else |
6411 | switch (b->type) | |
6412 | { | |
6413 | case bp_none: | |
6414 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6415 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6416 | break; |
c906108c | 6417 | |
3086aeae DJ |
6418 | case bp_watchpoint: |
6419 | case bp_hardware_watchpoint: | |
6420 | case bp_read_watchpoint: | |
6421 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6422 | { |
6423 | struct watchpoint *w = (struct watchpoint *) b; | |
6424 | ||
6425 | /* Field 4, the address, is omitted (which makes the columns | |
6426 | not line up too nicely with the headers, but the effect | |
6427 | is relatively readable). */ | |
6428 | if (opts.addressprint) | |
6429 | ui_out_field_skip (uiout, "addr"); | |
6430 | annotate_field (5); | |
6431 | ui_out_field_string (uiout, "what", w->exp_string); | |
6432 | } | |
3086aeae DJ |
6433 | break; |
6434 | ||
3086aeae DJ |
6435 | case bp_breakpoint: |
6436 | case bp_hardware_breakpoint: | |
7c16b83e | 6437 | case bp_single_step: |
3086aeae DJ |
6438 | case bp_until: |
6439 | case bp_finish: | |
6440 | case bp_longjmp: | |
6441 | case bp_longjmp_resume: | |
e2e4d78b | 6442 | case bp_longjmp_call_dummy: |
186c406b TT |
6443 | case bp_exception: |
6444 | case bp_exception_resume: | |
3086aeae | 6445 | case bp_step_resume: |
2c03e5be | 6446 | case bp_hp_step_resume: |
3086aeae DJ |
6447 | case bp_watchpoint_scope: |
6448 | case bp_call_dummy: | |
aa7d318d | 6449 | case bp_std_terminate: |
3086aeae DJ |
6450 | case bp_shlib_event: |
6451 | case bp_thread_event: | |
6452 | case bp_overlay_event: | |
0fd8e87f | 6453 | case bp_longjmp_master: |
aa7d318d | 6454 | case bp_std_terminate_master: |
186c406b | 6455 | case bp_exception_master: |
1042e4c0 | 6456 | case bp_tracepoint: |
7a697b8d | 6457 | case bp_fast_tracepoint: |
0fb4aa4b | 6458 | case bp_static_tracepoint: |
e7e0cddf | 6459 | case bp_dprintf: |
4efc6507 | 6460 | case bp_jit_event: |
0e30163f JK |
6461 | case bp_gnu_ifunc_resolver: |
6462 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6463 | if (opts.addressprint) |
3086aeae DJ |
6464 | { |
6465 | annotate_field (4); | |
54e52265 | 6466 | if (header_of_multiple) |
0d381245 | 6467 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6468 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6469 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6470 | else |
5af949e3 UW |
6471 | ui_out_field_core_addr (uiout, "addr", |
6472 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6473 | } |
6474 | annotate_field (5); | |
0d381245 | 6475 | if (!header_of_multiple) |
170b53b2 | 6476 | print_breakpoint_location (b, loc); |
0d381245 | 6477 | if (b->loc) |
a6d9a66e | 6478 | *last_loc = b->loc; |
3086aeae DJ |
6479 | break; |
6480 | } | |
c906108c | 6481 | |
6c95b8df | 6482 | |
998580f1 | 6483 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6484 | { |
6485 | struct inferior *inf; | |
998580f1 MK |
6486 | VEC(int) *inf_num = NULL; |
6487 | int mi_only = 1; | |
6c95b8df | 6488 | |
998580f1 | 6489 | ALL_INFERIORS (inf) |
6c95b8df PA |
6490 | { |
6491 | if (inf->pspace == loc->pspace) | |
998580f1 | 6492 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6493 | } |
998580f1 MK |
6494 | |
6495 | /* For backward compatibility, don't display inferiors in CLI unless | |
6496 | there are several. Always display for MI. */ | |
6497 | if (allflag | |
6498 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6499 | && (number_of_program_spaces () > 1 | |
6500 | || number_of_inferiors () > 1) | |
6501 | /* LOC is for existing B, it cannot be in | |
6502 | moribund_locations and thus having NULL OWNER. */ | |
6503 | && loc->owner->type != bp_catchpoint)) | |
6504 | mi_only = 0; | |
6505 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6506 | VEC_free (int, inf_num); | |
6c95b8df PA |
6507 | } |
6508 | ||
4a306c9a | 6509 | if (!part_of_multiple) |
c4093a6a | 6510 | { |
4a306c9a JB |
6511 | if (b->thread != -1) |
6512 | { | |
6513 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6514 | "stop only in" line a little further down. */ |
4a306c9a JB |
6515 | ui_out_text (uiout, " thread "); |
6516 | ui_out_field_int (uiout, "thread", b->thread); | |
6517 | } | |
6518 | else if (b->task != 0) | |
6519 | { | |
6520 | ui_out_text (uiout, " task "); | |
6521 | ui_out_field_int (uiout, "task", b->task); | |
6522 | } | |
c4093a6a | 6523 | } |
f1310107 | 6524 | |
8b93c638 | 6525 | ui_out_text (uiout, "\n"); |
f1310107 | 6526 | |
348d480f | 6527 | if (!part_of_multiple) |
f1310107 TJB |
6528 | b->ops->print_one_detail (b, uiout); |
6529 | ||
0d381245 | 6530 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6531 | { |
6532 | annotate_field (6); | |
8b93c638 | 6533 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6534 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6535 | the frame ID. */ |
5af949e3 UW |
6536 | ui_out_field_core_addr (uiout, "frame", |
6537 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6538 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6539 | } |
6540 | ||
28010a5d | 6541 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6542 | { |
6543 | annotate_field (7); | |
d77f58be | 6544 | if (is_tracepoint (b)) |
1042e4c0 SS |
6545 | ui_out_text (uiout, "\ttrace only if "); |
6546 | else | |
6547 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6548 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6549 | |
6550 | /* Print whether the target is doing the breakpoint's condition | |
6551 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6552 | if (is_breakpoint (b) | |
6553 | && breakpoint_condition_evaluation_mode () | |
6554 | == condition_evaluation_target) | |
6555 | { | |
6556 | ui_out_text (uiout, " ("); | |
6557 | ui_out_field_string (uiout, "evaluated-by", | |
6558 | bp_condition_evaluator (b)); | |
6559 | ui_out_text (uiout, " evals)"); | |
6560 | } | |
0101ce28 JJ |
6561 | ui_out_text (uiout, "\n"); |
6562 | } | |
6563 | ||
0d381245 | 6564 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6565 | { |
4a64f543 | 6566 | /* FIXME should make an annotation for this. */ |
8b93c638 | 6567 | ui_out_text (uiout, "\tstop only in thread "); |
5d5658a1 PA |
6568 | if (ui_out_is_mi_like_p (uiout)) |
6569 | ui_out_field_int (uiout, "thread", b->thread); | |
6570 | else | |
6571 | { | |
6572 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6573 | ||
6574 | ui_out_field_string (uiout, "thread", print_thread_id (thr)); | |
6575 | } | |
8b93c638 | 6576 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6577 | } |
6578 | ||
556ec64d YQ |
6579 | if (!part_of_multiple) |
6580 | { | |
6581 | if (b->hit_count) | |
31f56a27 YQ |
6582 | { |
6583 | /* FIXME should make an annotation for this. */ | |
6584 | if (is_catchpoint (b)) | |
6585 | ui_out_text (uiout, "\tcatchpoint"); | |
6586 | else if (is_tracepoint (b)) | |
6587 | ui_out_text (uiout, "\ttracepoint"); | |
6588 | else | |
6589 | ui_out_text (uiout, "\tbreakpoint"); | |
6590 | ui_out_text (uiout, " already hit "); | |
6591 | ui_out_field_int (uiout, "times", b->hit_count); | |
6592 | if (b->hit_count == 1) | |
6593 | ui_out_text (uiout, " time\n"); | |
6594 | else | |
6595 | ui_out_text (uiout, " times\n"); | |
6596 | } | |
556ec64d YQ |
6597 | else |
6598 | { | |
31f56a27 YQ |
6599 | /* Output the count also if it is zero, but only if this is mi. */ |
6600 | if (ui_out_is_mi_like_p (uiout)) | |
6601 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6602 | } |
6603 | } | |
8b93c638 | 6604 | |
0d381245 | 6605 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6606 | { |
6607 | annotate_field (8); | |
8b93c638 JM |
6608 | ui_out_text (uiout, "\tignore next "); |
6609 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6610 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6611 | } |
059fb39f | 6612 | |
816338b5 SS |
6613 | /* Note that an enable count of 1 corresponds to "enable once" |
6614 | behavior, which is reported by the combination of enablement and | |
6615 | disposition, so we don't need to mention it here. */ | |
6616 | if (!part_of_multiple && b->enable_count > 1) | |
6617 | { | |
6618 | annotate_field (8); | |
6619 | ui_out_text (uiout, "\tdisable after "); | |
6620 | /* Tweak the wording to clarify that ignore and enable counts | |
6621 | are distinct, and have additive effect. */ | |
6622 | if (b->ignore_count) | |
6623 | ui_out_text (uiout, "additional "); | |
6624 | else | |
6625 | ui_out_text (uiout, "next "); | |
6626 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6627 | ui_out_text (uiout, " hits\n"); | |
6628 | } | |
6629 | ||
f196051f SS |
6630 | if (!part_of_multiple && is_tracepoint (b)) |
6631 | { | |
6632 | struct tracepoint *tp = (struct tracepoint *) b; | |
6633 | ||
6634 | if (tp->traceframe_usage) | |
6635 | { | |
6636 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6637 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6638 | ui_out_text (uiout, " bytes\n"); | |
6639 | } | |
6640 | } | |
d3ce09f5 | 6641 | |
9add0f1b | 6642 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6643 | if (!part_of_multiple && l) |
c4093a6a | 6644 | { |
3b31d625 EZ |
6645 | struct cleanup *script_chain; |
6646 | ||
c4093a6a | 6647 | annotate_field (9); |
3b31d625 | 6648 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6649 | print_command_lines (uiout, l, 4); |
3b31d625 | 6650 | do_cleanups (script_chain); |
c4093a6a | 6651 | } |
d24317b4 | 6652 | |
d9b3f62e | 6653 | if (is_tracepoint (b)) |
1042e4c0 | 6654 | { |
d9b3f62e PA |
6655 | struct tracepoint *t = (struct tracepoint *) b; |
6656 | ||
6657 | if (!part_of_multiple && t->pass_count) | |
6658 | { | |
6659 | annotate_field (10); | |
6660 | ui_out_text (uiout, "\tpass count "); | |
6661 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6662 | ui_out_text (uiout, " \n"); | |
6663 | } | |
f2a8bc8a YQ |
6664 | |
6665 | /* Don't display it when tracepoint or tracepoint location is | |
6666 | pending. */ | |
6667 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6668 | { | |
6669 | annotate_field (11); | |
6670 | ||
6671 | if (ui_out_is_mi_like_p (uiout)) | |
6672 | ui_out_field_string (uiout, "installed", | |
6673 | loc->inserted ? "y" : "n"); | |
6674 | else | |
6675 | { | |
6676 | if (loc->inserted) | |
6677 | ui_out_text (uiout, "\t"); | |
6678 | else | |
6679 | ui_out_text (uiout, "\tnot "); | |
6680 | ui_out_text (uiout, "installed on target\n"); | |
6681 | } | |
6682 | } | |
1042e4c0 SS |
6683 | } |
6684 | ||
d24317b4 VP |
6685 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6686 | { | |
3a5c3e22 PA |
6687 | if (is_watchpoint (b)) |
6688 | { | |
6689 | struct watchpoint *w = (struct watchpoint *) b; | |
6690 | ||
6691 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6692 | } | |
f00aae0f KS |
6693 | else if (b->location != NULL |
6694 | && event_location_to_string (b->location) != NULL) | |
6695 | ui_out_field_string (uiout, "original-location", | |
6696 | event_location_to_string (b->location)); | |
d24317b4 | 6697 | } |
c4093a6a | 6698 | } |
c5aa993b | 6699 | |
0d381245 VP |
6700 | static void |
6701 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6702 | struct bp_location **last_loc, |
6c95b8df | 6703 | int allflag) |
0d381245 | 6704 | { |
8d3788bd | 6705 | struct cleanup *bkpt_chain; |
79a45e25 | 6706 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6707 | |
6708 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6709 | ||
12c5a436 | 6710 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6711 | do_cleanups (bkpt_chain); |
0d381245 VP |
6712 | |
6713 | /* If this breakpoint has custom print function, | |
6714 | it's already printed. Otherwise, print individual | |
6715 | locations, if any. */ | |
6716 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6717 | { | |
4a64f543 MS |
6718 | /* If breakpoint has a single location that is disabled, we |
6719 | print it as if it had several locations, since otherwise it's | |
6720 | hard to represent "breakpoint enabled, location disabled" | |
6721 | situation. | |
6722 | ||
6723 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6724 | internally, that's not a property exposed to user. */ |
0d381245 | 6725 | if (b->loc |
a5606eee | 6726 | && !is_hardware_watchpoint (b) |
8d3788bd | 6727 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6728 | { |
6729 | struct bp_location *loc; | |
6730 | int n = 1; | |
8d3788bd | 6731 | |
0d381245 | 6732 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6733 | { |
6734 | struct cleanup *inner2 = | |
6735 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6736 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6737 | do_cleanups (inner2); | |
6738 | } | |
0d381245 VP |
6739 | } |
6740 | } | |
6741 | } | |
6742 | ||
a6d9a66e UW |
6743 | static int |
6744 | breakpoint_address_bits (struct breakpoint *b) | |
6745 | { | |
6746 | int print_address_bits = 0; | |
6747 | struct bp_location *loc; | |
6748 | ||
c6d81124 PA |
6749 | /* Software watchpoints that aren't watching memory don't have an |
6750 | address to print. */ | |
6751 | if (is_no_memory_software_watchpoint (b)) | |
6752 | return 0; | |
6753 | ||
a6d9a66e UW |
6754 | for (loc = b->loc; loc; loc = loc->next) |
6755 | { | |
c7437ca6 PA |
6756 | int addr_bit; |
6757 | ||
c7437ca6 | 6758 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6759 | if (addr_bit > print_address_bits) |
6760 | print_address_bits = addr_bit; | |
6761 | } | |
6762 | ||
6763 | return print_address_bits; | |
6764 | } | |
0d381245 | 6765 | |
c4093a6a JM |
6766 | struct captured_breakpoint_query_args |
6767 | { | |
6768 | int bnum; | |
6769 | }; | |
c5aa993b | 6770 | |
c4093a6a | 6771 | static int |
2b65245e | 6772 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6773 | { |
9a3c8263 SM |
6774 | struct captured_breakpoint_query_args *args |
6775 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6776 | struct breakpoint *b; |
a6d9a66e | 6777 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6778 | |
c4093a6a JM |
6779 | ALL_BREAKPOINTS (b) |
6780 | { | |
6781 | if (args->bnum == b->number) | |
c5aa993b | 6782 | { |
12c5a436 | 6783 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6784 | return GDB_RC_OK; |
c5aa993b | 6785 | } |
c4093a6a JM |
6786 | } |
6787 | return GDB_RC_NONE; | |
6788 | } | |
c5aa993b | 6789 | |
c4093a6a | 6790 | enum gdb_rc |
4a64f543 MS |
6791 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6792 | char **error_message) | |
c4093a6a JM |
6793 | { |
6794 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6795 | |
c4093a6a JM |
6796 | args.bnum = bnum; |
6797 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6798 | an error. */ |
b0b13bb4 DJ |
6799 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6800 | error_message, RETURN_MASK_ALL) < 0) | |
6801 | return GDB_RC_FAIL; | |
6802 | else | |
6803 | return GDB_RC_OK; | |
c4093a6a | 6804 | } |
c5aa993b | 6805 | |
09d682a4 TT |
6806 | /* Return true if this breakpoint was set by the user, false if it is |
6807 | internal or momentary. */ | |
6808 | ||
6809 | int | |
6810 | user_breakpoint_p (struct breakpoint *b) | |
6811 | { | |
46c6471b | 6812 | return b->number > 0; |
09d682a4 TT |
6813 | } |
6814 | ||
93daf339 TT |
6815 | /* See breakpoint.h. */ |
6816 | ||
6817 | int | |
6818 | pending_breakpoint_p (struct breakpoint *b) | |
6819 | { | |
6820 | return b->loc == NULL; | |
6821 | } | |
6822 | ||
7f3b0473 | 6823 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6824 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6825 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6826 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6827 | ones for which it returns non-zero. Return the total number of | |
6828 | breakpoints listed. */ | |
c906108c | 6829 | |
d77f58be | 6830 | static int |
e5a67952 | 6831 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6832 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6833 | { |
52f0bd74 | 6834 | struct breakpoint *b; |
a6d9a66e | 6835 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6836 | int nr_printable_breakpoints; |
3b31d625 | 6837 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6838 | struct value_print_options opts; |
a6d9a66e | 6839 | int print_address_bits = 0; |
269b11a2 | 6840 | int print_type_col_width = 14; |
79a45e25 | 6841 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6842 | |
79a45b7d TT |
6843 | get_user_print_options (&opts); |
6844 | ||
4a64f543 MS |
6845 | /* Compute the number of rows in the table, as well as the size |
6846 | required for address fields. */ | |
7f3b0473 AC |
6847 | nr_printable_breakpoints = 0; |
6848 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6849 | { |
6850 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6851 | if (filter && !filter (b)) | |
6852 | continue; | |
6853 | ||
6854 | /* If we have an "args" string, it is a list of breakpoints to | |
6855 | accept. Skip the others. */ | |
6856 | if (args != NULL && *args != '\0') | |
6857 | { | |
6858 | if (allflag && parse_and_eval_long (args) != b->number) | |
6859 | continue; | |
6860 | if (!allflag && !number_is_in_list (args, b->number)) | |
6861 | continue; | |
6862 | } | |
269b11a2 | 6863 | |
e5a67952 MS |
6864 | if (allflag || user_breakpoint_p (b)) |
6865 | { | |
6866 | int addr_bit, type_len; | |
a6d9a66e | 6867 | |
e5a67952 MS |
6868 | addr_bit = breakpoint_address_bits (b); |
6869 | if (addr_bit > print_address_bits) | |
6870 | print_address_bits = addr_bit; | |
269b11a2 | 6871 | |
e5a67952 MS |
6872 | type_len = strlen (bptype_string (b->type)); |
6873 | if (type_len > print_type_col_width) | |
6874 | print_type_col_width = type_len; | |
6875 | ||
6876 | nr_printable_breakpoints++; | |
6877 | } | |
6878 | } | |
7f3b0473 | 6879 | |
79a45b7d | 6880 | if (opts.addressprint) |
3b31d625 | 6881 | bkpttbl_chain |
3e43a32a MS |
6882 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6883 | nr_printable_breakpoints, | |
3b31d625 | 6884 | "BreakpointTable"); |
8b93c638 | 6885 | else |
3b31d625 | 6886 | bkpttbl_chain |
3e43a32a MS |
6887 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6888 | nr_printable_breakpoints, | |
3b31d625 | 6889 | "BreakpointTable"); |
8b93c638 | 6890 | |
7f3b0473 | 6891 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6892 | annotate_breakpoints_headers (); |
6893 | if (nr_printable_breakpoints > 0) | |
6894 | annotate_field (0); | |
4a64f543 | 6895 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6896 | if (nr_printable_breakpoints > 0) |
6897 | annotate_field (1); | |
269b11a2 | 6898 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6899 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6900 | if (nr_printable_breakpoints > 0) |
6901 | annotate_field (2); | |
4a64f543 | 6902 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6903 | if (nr_printable_breakpoints > 0) |
6904 | annotate_field (3); | |
54e52265 | 6905 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6906 | if (opts.addressprint) |
e5a67952 MS |
6907 | { |
6908 | if (nr_printable_breakpoints > 0) | |
6909 | annotate_field (4); | |
6910 | if (print_address_bits <= 32) | |
6911 | ui_out_table_header (uiout, 10, ui_left, | |
6912 | "addr", "Address"); /* 5 */ | |
6913 | else | |
6914 | ui_out_table_header (uiout, 18, ui_left, | |
6915 | "addr", "Address"); /* 5 */ | |
6916 | } | |
d7faa9e7 AC |
6917 | if (nr_printable_breakpoints > 0) |
6918 | annotate_field (5); | |
6919 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6920 | ui_out_table_body (uiout); | |
6921 | if (nr_printable_breakpoints > 0) | |
6922 | annotate_breakpoints_table (); | |
7f3b0473 | 6923 | |
c4093a6a | 6924 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6925 | { |
6926 | QUIT; | |
6927 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6928 | if (filter && !filter (b)) | |
6929 | continue; | |
6930 | ||
6931 | /* If we have an "args" string, it is a list of breakpoints to | |
6932 | accept. Skip the others. */ | |
6933 | ||
6934 | if (args != NULL && *args != '\0') | |
6935 | { | |
6936 | if (allflag) /* maintenance info breakpoint */ | |
6937 | { | |
6938 | if (parse_and_eval_long (args) != b->number) | |
6939 | continue; | |
6940 | } | |
6941 | else /* all others */ | |
6942 | { | |
6943 | if (!number_is_in_list (args, b->number)) | |
6944 | continue; | |
6945 | } | |
6946 | } | |
6947 | /* We only print out user settable breakpoints unless the | |
6948 | allflag is set. */ | |
6949 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6950 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6951 | } |
6952 | ||
3b31d625 | 6953 | do_cleanups (bkpttbl_chain); |
698384cd | 6954 | |
7f3b0473 | 6955 | if (nr_printable_breakpoints == 0) |
c906108c | 6956 | { |
4a64f543 MS |
6957 | /* If there's a filter, let the caller decide how to report |
6958 | empty list. */ | |
d77f58be SS |
6959 | if (!filter) |
6960 | { | |
e5a67952 | 6961 | if (args == NULL || *args == '\0') |
d77f58be SS |
6962 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6963 | else | |
4a64f543 | 6964 | ui_out_message (uiout, 0, |
e5a67952 MS |
6965 | "No breakpoint or watchpoint matching '%s'.\n", |
6966 | args); | |
d77f58be | 6967 | } |
c906108c SS |
6968 | } |
6969 | else | |
c4093a6a | 6970 | { |
a6d9a66e UW |
6971 | if (last_loc && !server_command) |
6972 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6973 | } |
c906108c | 6974 | |
4a64f543 | 6975 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6976 | there have been breakpoints? */ |
c906108c | 6977 | annotate_breakpoints_table_end (); |
d77f58be SS |
6978 | |
6979 | return nr_printable_breakpoints; | |
c906108c SS |
6980 | } |
6981 | ||
ad443146 SS |
6982 | /* Display the value of default-collect in a way that is generally |
6983 | compatible with the breakpoint list. */ | |
6984 | ||
6985 | static void | |
6986 | default_collect_info (void) | |
6987 | { | |
79a45e25 PA |
6988 | struct ui_out *uiout = current_uiout; |
6989 | ||
ad443146 SS |
6990 | /* If it has no value (which is frequently the case), say nothing; a |
6991 | message like "No default-collect." gets in user's face when it's | |
6992 | not wanted. */ | |
6993 | if (!*default_collect) | |
6994 | return; | |
6995 | ||
6996 | /* The following phrase lines up nicely with per-tracepoint collect | |
6997 | actions. */ | |
6998 | ui_out_text (uiout, "default collect "); | |
6999 | ui_out_field_string (uiout, "default-collect", default_collect); | |
7000 | ui_out_text (uiout, " \n"); | |
7001 | } | |
7002 | ||
c906108c | 7003 | static void |
e5a67952 | 7004 | breakpoints_info (char *args, int from_tty) |
c906108c | 7005 | { |
e5a67952 | 7006 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
7007 | |
7008 | default_collect_info (); | |
d77f58be SS |
7009 | } |
7010 | ||
7011 | static void | |
e5a67952 | 7012 | watchpoints_info (char *args, int from_tty) |
d77f58be | 7013 | { |
e5a67952 | 7014 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 7015 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
7016 | |
7017 | if (num_printed == 0) | |
7018 | { | |
e5a67952 | 7019 | if (args == NULL || *args == '\0') |
d77f58be SS |
7020 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
7021 | else | |
e5a67952 | 7022 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 7023 | } |
c906108c SS |
7024 | } |
7025 | ||
7a292a7a | 7026 | static void |
e5a67952 | 7027 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 7028 | { |
e5a67952 | 7029 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
7030 | |
7031 | default_collect_info (); | |
c906108c SS |
7032 | } |
7033 | ||
0d381245 | 7034 | static int |
714835d5 | 7035 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7036 | struct program_space *pspace, |
714835d5 | 7037 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7038 | { |
7039 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7040 | |
0d381245 VP |
7041 | for (; bl; bl = bl->next) |
7042 | { | |
6c95b8df PA |
7043 | if (bl->pspace == pspace |
7044 | && bl->address == pc | |
0d381245 VP |
7045 | && (!overlay_debugging || bl->section == section)) |
7046 | return 1; | |
7047 | } | |
7048 | return 0; | |
7049 | } | |
7050 | ||
672f9b60 | 7051 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7052 | concerns with logical breakpoints, so we match program spaces, not |
7053 | address spaces. */ | |
c906108c SS |
7054 | |
7055 | static void | |
6c95b8df PA |
7056 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7057 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7058 | struct obj_section *section, int thread) |
c906108c | 7059 | { |
52f0bd74 AC |
7060 | int others = 0; |
7061 | struct breakpoint *b; | |
c906108c SS |
7062 | |
7063 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7064 | others += (user_breakpoint_p (b) |
7065 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7066 | if (others > 0) |
7067 | { | |
a3f17187 AC |
7068 | if (others == 1) |
7069 | printf_filtered (_("Note: breakpoint ")); | |
7070 | else /* if (others == ???) */ | |
7071 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7072 | ALL_BREAKPOINTS (b) |
672f9b60 | 7073 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7074 | { |
7075 | others--; | |
7076 | printf_filtered ("%d", b->number); | |
7077 | if (b->thread == -1 && thread != -1) | |
7078 | printf_filtered (" (all threads)"); | |
7079 | else if (b->thread != -1) | |
7080 | printf_filtered (" (thread %d)", b->thread); | |
7081 | printf_filtered ("%s%s ", | |
059fb39f | 7082 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7083 | || b->enable_state == bp_call_disabled) |
0d381245 | 7084 | ? " (disabled)" |
0d381245 VP |
7085 | : ""), |
7086 | (others > 1) ? "," | |
7087 | : ((others == 1) ? " and" : "")); | |
7088 | } | |
a3f17187 | 7089 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7090 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7091 | printf_filtered (".\n"); |
7092 | } | |
7093 | } | |
7094 | \f | |
c906108c | 7095 | |
e4f237da | 7096 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7097 | BPT locations. For some breakpoint types, the locations' address members |
7098 | are irrelevant and it makes no sense to attempt to compare them to other | |
7099 | addresses (or use them for any other purpose either). | |
e4f237da | 7100 | |
4a64f543 | 7101 | More specifically, each of the following breakpoint types will |
244558af | 7102 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7103 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7104 | breakpoint location at address zero: |
e4f237da KB |
7105 | |
7106 | bp_watchpoint | |
2d134ed3 PA |
7107 | bp_catchpoint |
7108 | ||
7109 | */ | |
e4f237da KB |
7110 | |
7111 | static int | |
7112 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7113 | { | |
7114 | enum bptype type = bpt->type; | |
7115 | ||
2d134ed3 PA |
7116 | return (type != bp_watchpoint && type != bp_catchpoint); |
7117 | } | |
7118 | ||
7119 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7120 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7121 | ||
7122 | static int | |
4a64f543 MS |
7123 | watchpoint_locations_match (struct bp_location *loc1, |
7124 | struct bp_location *loc2) | |
2d134ed3 | 7125 | { |
3a5c3e22 PA |
7126 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7127 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7128 | ||
7129 | /* Both of them must exist. */ | |
7130 | gdb_assert (w1 != NULL); | |
7131 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7132 | |
4a64f543 MS |
7133 | /* If the target can evaluate the condition expression in hardware, |
7134 | then we we need to insert both watchpoints even if they are at | |
7135 | the same place. Otherwise the watchpoint will only trigger when | |
7136 | the condition of whichever watchpoint was inserted evaluates to | |
7137 | true, not giving a chance for GDB to check the condition of the | |
7138 | other watchpoint. */ | |
3a5c3e22 | 7139 | if ((w1->cond_exp |
4a64f543 MS |
7140 | && target_can_accel_watchpoint_condition (loc1->address, |
7141 | loc1->length, | |
0cf6dd15 | 7142 | loc1->watchpoint_type, |
4d01a485 | 7143 | w1->cond_exp.get ())) |
3a5c3e22 | 7144 | || (w2->cond_exp |
4a64f543 MS |
7145 | && target_can_accel_watchpoint_condition (loc2->address, |
7146 | loc2->length, | |
0cf6dd15 | 7147 | loc2->watchpoint_type, |
4d01a485 | 7148 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
7149 | return 0; |
7150 | ||
85d721b8 PA |
7151 | /* Note that this checks the owner's type, not the location's. In |
7152 | case the target does not support read watchpoints, but does | |
7153 | support access watchpoints, we'll have bp_read_watchpoint | |
7154 | watchpoints with hw_access locations. Those should be considered | |
7155 | duplicates of hw_read locations. The hw_read locations will | |
7156 | become hw_access locations later. */ | |
2d134ed3 PA |
7157 | return (loc1->owner->type == loc2->owner->type |
7158 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7159 | && loc1->address == loc2->address | |
7160 | && loc1->length == loc2->length); | |
e4f237da KB |
7161 | } |
7162 | ||
31e77af2 | 7163 | /* See breakpoint.h. */ |
6c95b8df | 7164 | |
31e77af2 | 7165 | int |
6c95b8df PA |
7166 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7167 | struct address_space *aspace2, CORE_ADDR addr2) | |
7168 | { | |
f5656ead | 7169 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7170 | || aspace1 == aspace2) |
7171 | && addr1 == addr2); | |
7172 | } | |
7173 | ||
f1310107 TJB |
7174 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7175 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7176 | matches ASPACE2. On targets that have global breakpoints, the address | |
7177 | space doesn't really matter. */ | |
7178 | ||
7179 | static int | |
7180 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7181 | int len1, struct address_space *aspace2, | |
7182 | CORE_ADDR addr2) | |
7183 | { | |
f5656ead | 7184 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7185 | || aspace1 == aspace2) |
7186 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7187 | } | |
7188 | ||
7189 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7190 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7191 | matches the breakpoint's address space. On targets that have global | |
7192 | breakpoints, the address space doesn't really matter. */ | |
7193 | ||
7194 | static int | |
7195 | breakpoint_location_address_match (struct bp_location *bl, | |
7196 | struct address_space *aspace, | |
7197 | CORE_ADDR addr) | |
7198 | { | |
7199 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7200 | aspace, addr) | |
7201 | || (bl->length | |
7202 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7203 | bl->address, bl->length, | |
7204 | aspace, addr))); | |
7205 | } | |
7206 | ||
d35ae833 PA |
7207 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7208 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7209 | match happens only if ASPACE matches the breakpoint's address | |
7210 | space. On targets that have global breakpoints, the address space | |
7211 | doesn't really matter. */ | |
7212 | ||
7213 | static int | |
7214 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7215 | struct address_space *aspace, | |
7216 | CORE_ADDR addr, int len) | |
7217 | { | |
7218 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7219 | || bl->pspace->aspace == aspace) | |
7220 | { | |
7221 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7222 | ||
7223 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7224 | return 1; | |
7225 | } | |
7226 | return 0; | |
7227 | } | |
7228 | ||
1e4d1764 YQ |
7229 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7230 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7231 | true, otherwise returns false. */ | |
7232 | ||
7233 | static int | |
7234 | tracepoint_locations_match (struct bp_location *loc1, | |
7235 | struct bp_location *loc2) | |
7236 | { | |
7237 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7238 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7239 | locations at the same address of different tracepoints are regarded as | |
7240 | different locations. */ | |
7241 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7242 | else | |
7243 | return 0; | |
7244 | } | |
7245 | ||
2d134ed3 PA |
7246 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7247 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7248 | represent the same location. */ | |
7249 | ||
7250 | static int | |
4a64f543 MS |
7251 | breakpoint_locations_match (struct bp_location *loc1, |
7252 | struct bp_location *loc2) | |
2d134ed3 | 7253 | { |
2bdf28a0 JK |
7254 | int hw_point1, hw_point2; |
7255 | ||
7256 | /* Both of them must not be in moribund_locations. */ | |
7257 | gdb_assert (loc1->owner != NULL); | |
7258 | gdb_assert (loc2->owner != NULL); | |
7259 | ||
7260 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7261 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7262 | |
7263 | if (hw_point1 != hw_point2) | |
7264 | return 0; | |
7265 | else if (hw_point1) | |
7266 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7267 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7268 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7269 | else |
f1310107 TJB |
7270 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7271 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7272 | loc2->pspace->aspace, loc2->address) | |
7273 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7274 | } |
7275 | ||
76897487 KB |
7276 | static void |
7277 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7278 | int bnum, int have_bnum) | |
7279 | { | |
f63fbe86 MS |
7280 | /* The longest string possibly returned by hex_string_custom |
7281 | is 50 chars. These must be at least that big for safety. */ | |
7282 | char astr1[64]; | |
7283 | char astr2[64]; | |
76897487 | 7284 | |
bb599908 PH |
7285 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7286 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7287 | if (have_bnum) |
8a3fe4f8 | 7288 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7289 | bnum, astr1, astr2); |
7290 | else | |
8a3fe4f8 | 7291 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7292 | } |
7293 | ||
4a64f543 MS |
7294 | /* Adjust a breakpoint's address to account for architectural |
7295 | constraints on breakpoint placement. Return the adjusted address. | |
7296 | Note: Very few targets require this kind of adjustment. For most | |
7297 | targets, this function is simply the identity function. */ | |
76897487 KB |
7298 | |
7299 | static CORE_ADDR | |
a6d9a66e UW |
7300 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7301 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7302 | { |
a6d9a66e | 7303 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7304 | { |
7305 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7306 | return bpaddr; | |
7307 | } | |
88f7da05 KB |
7308 | else if (bptype == bp_watchpoint |
7309 | || bptype == bp_hardware_watchpoint | |
7310 | || bptype == bp_read_watchpoint | |
7311 | || bptype == bp_access_watchpoint | |
fe798b75 | 7312 | || bptype == bp_catchpoint) |
88f7da05 KB |
7313 | { |
7314 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7315 | have their addresses modified. */ | |
7316 | return bpaddr; | |
7317 | } | |
7c16b83e PA |
7318 | else if (bptype == bp_single_step) |
7319 | { | |
7320 | /* Single-step breakpoints should not have their addresses | |
7321 | modified. If there's any architectural constrain that | |
7322 | applies to this address, then it should have already been | |
7323 | taken into account when the breakpoint was created in the | |
7324 | first place. If we didn't do this, stepping through e.g., | |
7325 | Thumb-2 IT blocks would break. */ | |
7326 | return bpaddr; | |
7327 | } | |
76897487 KB |
7328 | else |
7329 | { | |
7330 | CORE_ADDR adjusted_bpaddr; | |
7331 | ||
7332 | /* Some targets have architectural constraints on the placement | |
7333 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7334 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7335 | |
7336 | /* An adjusted breakpoint address can significantly alter | |
7337 | a user's expectations. Print a warning if an adjustment | |
7338 | is required. */ | |
7339 | if (adjusted_bpaddr != bpaddr) | |
7340 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7341 | ||
7342 | return adjusted_bpaddr; | |
7343 | } | |
7344 | } | |
7345 | ||
28010a5d PA |
7346 | void |
7347 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7348 | struct breakpoint *owner) | |
7cc221ef | 7349 | { |
7cc221ef DJ |
7350 | memset (loc, 0, sizeof (*loc)); |
7351 | ||
348d480f PA |
7352 | gdb_assert (ops != NULL); |
7353 | ||
28010a5d PA |
7354 | loc->ops = ops; |
7355 | loc->owner = owner; | |
b775012e | 7356 | loc->cond_bytecode = NULL; |
0d381245 VP |
7357 | loc->shlib_disabled = 0; |
7358 | loc->enabled = 1; | |
e049a4b5 | 7359 | |
28010a5d | 7360 | switch (owner->type) |
e049a4b5 DJ |
7361 | { |
7362 | case bp_breakpoint: | |
7c16b83e | 7363 | case bp_single_step: |
e049a4b5 DJ |
7364 | case bp_until: |
7365 | case bp_finish: | |
7366 | case bp_longjmp: | |
7367 | case bp_longjmp_resume: | |
e2e4d78b | 7368 | case bp_longjmp_call_dummy: |
186c406b TT |
7369 | case bp_exception: |
7370 | case bp_exception_resume: | |
e049a4b5 | 7371 | case bp_step_resume: |
2c03e5be | 7372 | case bp_hp_step_resume: |
e049a4b5 DJ |
7373 | case bp_watchpoint_scope: |
7374 | case bp_call_dummy: | |
aa7d318d | 7375 | case bp_std_terminate: |
e049a4b5 DJ |
7376 | case bp_shlib_event: |
7377 | case bp_thread_event: | |
7378 | case bp_overlay_event: | |
4efc6507 | 7379 | case bp_jit_event: |
0fd8e87f | 7380 | case bp_longjmp_master: |
aa7d318d | 7381 | case bp_std_terminate_master: |
186c406b | 7382 | case bp_exception_master: |
0e30163f JK |
7383 | case bp_gnu_ifunc_resolver: |
7384 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7385 | case bp_dprintf: |
e049a4b5 | 7386 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7387 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7388 | break; |
7389 | case bp_hardware_breakpoint: | |
7390 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7391 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7392 | break; |
7393 | case bp_hardware_watchpoint: | |
7394 | case bp_read_watchpoint: | |
7395 | case bp_access_watchpoint: | |
7396 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7397 | break; | |
7398 | case bp_watchpoint: | |
ce78b96d | 7399 | case bp_catchpoint: |
15c3d785 PA |
7400 | case bp_tracepoint: |
7401 | case bp_fast_tracepoint: | |
0fb4aa4b | 7402 | case bp_static_tracepoint: |
e049a4b5 DJ |
7403 | loc->loc_type = bp_loc_other; |
7404 | break; | |
7405 | default: | |
e2e0b3e5 | 7406 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7407 | } |
7408 | ||
f431efe5 | 7409 | loc->refc = 1; |
28010a5d PA |
7410 | } |
7411 | ||
7412 | /* Allocate a struct bp_location. */ | |
7413 | ||
7414 | static struct bp_location * | |
7415 | allocate_bp_location (struct breakpoint *bpt) | |
7416 | { | |
348d480f PA |
7417 | return bpt->ops->allocate_location (bpt); |
7418 | } | |
7cc221ef | 7419 | |
f431efe5 PA |
7420 | static void |
7421 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7422 | { |
348d480f | 7423 | loc->ops->dtor (loc); |
4d01a485 | 7424 | delete loc; |
fe3f5fa8 VP |
7425 | } |
7426 | ||
f431efe5 PA |
7427 | /* Increment reference count. */ |
7428 | ||
7429 | static void | |
7430 | incref_bp_location (struct bp_location *bl) | |
7431 | { | |
7432 | ++bl->refc; | |
7433 | } | |
7434 | ||
7435 | /* Decrement reference count. If the reference count reaches 0, | |
7436 | destroy the bp_location. Sets *BLP to NULL. */ | |
7437 | ||
7438 | static void | |
7439 | decref_bp_location (struct bp_location **blp) | |
7440 | { | |
0807b50c PA |
7441 | gdb_assert ((*blp)->refc > 0); |
7442 | ||
f431efe5 PA |
7443 | if (--(*blp)->refc == 0) |
7444 | free_bp_location (*blp); | |
7445 | *blp = NULL; | |
7446 | } | |
7447 | ||
346774a9 | 7448 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7449 | |
346774a9 PA |
7450 | static void |
7451 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7452 | { |
346774a9 | 7453 | struct breakpoint *b1; |
c906108c | 7454 | |
346774a9 PA |
7455 | /* Add this breakpoint to the end of the chain so that a list of |
7456 | breakpoints will come out in order of increasing numbers. */ | |
7457 | ||
7458 | b1 = breakpoint_chain; | |
7459 | if (b1 == 0) | |
7460 | breakpoint_chain = b; | |
7461 | else | |
7462 | { | |
7463 | while (b1->next) | |
7464 | b1 = b1->next; | |
7465 | b1->next = b; | |
7466 | } | |
7467 | } | |
7468 | ||
7469 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7470 | ||
7471 | static void | |
7472 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7473 | struct gdbarch *gdbarch, | |
28010a5d | 7474 | enum bptype bptype, |
c0a91b2b | 7475 | const struct breakpoint_ops *ops) |
346774a9 | 7476 | { |
c906108c | 7477 | memset (b, 0, sizeof (*b)); |
2219d63c | 7478 | |
348d480f PA |
7479 | gdb_assert (ops != NULL); |
7480 | ||
28010a5d | 7481 | b->ops = ops; |
4d28f7a8 | 7482 | b->type = bptype; |
a6d9a66e | 7483 | b->gdbarch = gdbarch; |
c906108c SS |
7484 | b->language = current_language->la_language; |
7485 | b->input_radix = input_radix; | |
7486 | b->thread = -1; | |
b5de0fa7 | 7487 | b->enable_state = bp_enabled; |
c906108c SS |
7488 | b->next = 0; |
7489 | b->silent = 0; | |
7490 | b->ignore_count = 0; | |
7491 | b->commands = NULL; | |
818dd999 | 7492 | b->frame_id = null_frame_id; |
0d381245 | 7493 | b->condition_not_parsed = 0; |
84f4c1fe | 7494 | b->py_bp_object = NULL; |
d0fb5eae | 7495 | b->related_breakpoint = b; |
f00aae0f | 7496 | b->location = NULL; |
346774a9 PA |
7497 | } |
7498 | ||
7499 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7500 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7501 | |
7502 | static struct breakpoint * | |
7503 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7504 | enum bptype bptype, |
c0a91b2b | 7505 | const struct breakpoint_ops *ops) |
346774a9 | 7506 | { |
4d01a485 | 7507 | struct breakpoint *b = new breakpoint (); |
346774a9 | 7508 | |
348d480f | 7509 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7510 | add_to_breakpoint_chain (b); |
0d381245 VP |
7511 | return b; |
7512 | } | |
7513 | ||
0e30163f JK |
7514 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7515 | resolutions should be made as the user specified the location explicitly | |
7516 | enough. */ | |
7517 | ||
0d381245 | 7518 | static void |
0e30163f | 7519 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7520 | { |
2bdf28a0 JK |
7521 | gdb_assert (loc->owner != NULL); |
7522 | ||
0d381245 | 7523 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7524 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7525 | || is_tracepoint (loc->owner)) |
0d381245 | 7526 | { |
0e30163f | 7527 | int is_gnu_ifunc; |
2c02bd72 | 7528 | const char *function_name; |
6a3a010b | 7529 | CORE_ADDR func_addr; |
0e30163f | 7530 | |
2c02bd72 | 7531 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7532 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7533 | |
7534 | if (is_gnu_ifunc && !explicit_loc) | |
7535 | { | |
7536 | struct breakpoint *b = loc->owner; | |
7537 | ||
7538 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7539 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7540 | &loc->requested_address)) |
7541 | { | |
7542 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7543 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7544 | loc->requested_address, | |
7545 | b->type); | |
7546 | } | |
7547 | else if (b->type == bp_breakpoint && b->loc == loc | |
7548 | && loc->next == NULL && b->related_breakpoint == b) | |
7549 | { | |
7550 | /* Create only the whole new breakpoint of this type but do not | |
7551 | mess more complicated breakpoints with multiple locations. */ | |
7552 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7553 | /* Remember the resolver's address for use by the return |
7554 | breakpoint. */ | |
7555 | loc->related_address = func_addr; | |
0e30163f JK |
7556 | } |
7557 | } | |
7558 | ||
2c02bd72 DE |
7559 | if (function_name) |
7560 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7561 | } |
7562 | } | |
7563 | ||
a6d9a66e | 7564 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7565 | struct gdbarch * |
a6d9a66e UW |
7566 | get_sal_arch (struct symtab_and_line sal) |
7567 | { | |
7568 | if (sal.section) | |
7569 | return get_objfile_arch (sal.section->objfile); | |
7570 | if (sal.symtab) | |
eb822aa6 | 7571 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7572 | |
7573 | return NULL; | |
7574 | } | |
7575 | ||
346774a9 PA |
7576 | /* Low level routine for partially initializing a breakpoint of type |
7577 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7578 | file name, and line number are provided by SAL. |
0d381245 VP |
7579 | |
7580 | It is expected that the caller will complete the initialization of | |
7581 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7582 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7583 | |
346774a9 PA |
7584 | static void |
7585 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7586 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7587 | const struct breakpoint_ops *ops) |
0d381245 | 7588 | { |
28010a5d | 7589 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7590 | |
3742cc8b | 7591 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7592 | |
6c95b8df PA |
7593 | if (bptype != bp_catchpoint) |
7594 | gdb_assert (sal.pspace != NULL); | |
7595 | ||
f8eba3c6 TT |
7596 | /* Store the program space that was used to set the breakpoint, |
7597 | except for ordinary breakpoints, which are independent of the | |
7598 | program space. */ | |
7599 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7600 | b->pspace = sal.pspace; | |
346774a9 | 7601 | } |
c906108c | 7602 | |
346774a9 PA |
7603 | /* set_raw_breakpoint is a low level routine for allocating and |
7604 | partially initializing a breakpoint of type BPTYPE. The newly | |
7605 | created breakpoint's address, section, source file name, and line | |
7606 | number are provided by SAL. The newly created and partially | |
7607 | initialized breakpoint is added to the breakpoint chain and | |
7608 | is also returned as the value of this function. | |
7609 | ||
7610 | It is expected that the caller will complete the initialization of | |
7611 | the newly created breakpoint struct as well as output any status | |
7612 | information regarding the creation of a new breakpoint. In | |
7613 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7614 | number! Care should be taken to not allow an error to occur | |
7615 | prior to completing the initialization of the breakpoint. If this | |
7616 | should happen, a bogus breakpoint will be left on the chain. */ | |
7617 | ||
7618 | struct breakpoint * | |
7619 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7620 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7621 | const struct breakpoint_ops *ops) |
346774a9 | 7622 | { |
4d01a485 | 7623 | struct breakpoint *b = new breakpoint (); |
346774a9 | 7624 | |
348d480f | 7625 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7626 | add_to_breakpoint_chain (b); |
c906108c SS |
7627 | return b; |
7628 | } | |
7629 | ||
53a5351d | 7630 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7631 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7632 | initiated the operation. */ | |
c906108c SS |
7633 | |
7634 | void | |
186c406b | 7635 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7636 | { |
35df4500 | 7637 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7638 | int thread = tp->global_num; |
0fd8e87f UW |
7639 | |
7640 | /* To avoid having to rescan all objfile symbols at every step, | |
7641 | we maintain a list of continually-inserted but always disabled | |
7642 | longjmp "master" breakpoints. Here, we simply create momentary | |
7643 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7644 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7645 | if (b->pspace == current_program_space |
186c406b TT |
7646 | && (b->type == bp_longjmp_master |
7647 | || b->type == bp_exception_master)) | |
0fd8e87f | 7648 | { |
06edf0c0 PA |
7649 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7650 | struct breakpoint *clone; | |
cc59ec59 | 7651 | |
e2e4d78b JK |
7652 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7653 | after their removal. */ | |
06edf0c0 | 7654 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7655 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7656 | clone->thread = thread; |
7657 | } | |
186c406b TT |
7658 | |
7659 | tp->initiating_frame = frame; | |
c906108c SS |
7660 | } |
7661 | ||
611c83ae | 7662 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7663 | void |
611c83ae | 7664 | delete_longjmp_breakpoint (int thread) |
c906108c | 7665 | { |
35df4500 | 7666 | struct breakpoint *b, *b_tmp; |
c906108c | 7667 | |
35df4500 | 7668 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7669 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7670 | { |
7671 | if (b->thread == thread) | |
7672 | delete_breakpoint (b); | |
7673 | } | |
c906108c SS |
7674 | } |
7675 | ||
f59f708a PA |
7676 | void |
7677 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7678 | { | |
7679 | struct breakpoint *b, *b_tmp; | |
7680 | ||
7681 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7682 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7683 | { | |
7684 | if (b->thread == thread) | |
7685 | b->disposition = disp_del_at_next_stop; | |
7686 | } | |
7687 | } | |
7688 | ||
e2e4d78b JK |
7689 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7690 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7691 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7692 | breakpoints. */ | |
7693 | ||
7694 | struct breakpoint * | |
7695 | set_longjmp_breakpoint_for_call_dummy (void) | |
7696 | { | |
7697 | struct breakpoint *b, *retval = NULL; | |
7698 | ||
7699 | ALL_BREAKPOINTS (b) | |
7700 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7701 | { | |
7702 | struct breakpoint *new_b; | |
7703 | ||
7704 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7705 | &momentary_breakpoint_ops, |
7706 | 1); | |
5d5658a1 | 7707 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7708 | |
7709 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7710 | ||
7711 | gdb_assert (new_b->related_breakpoint == new_b); | |
7712 | if (retval == NULL) | |
7713 | retval = new_b; | |
7714 | new_b->related_breakpoint = retval; | |
7715 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7716 | retval = retval->related_breakpoint; | |
7717 | retval->related_breakpoint = new_b; | |
7718 | } | |
7719 | ||
7720 | return retval; | |
7721 | } | |
7722 | ||
7723 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7724 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7725 | stack. |
7726 | ||
7727 | You should call this function only at places where it is safe to currently | |
7728 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7729 | frames. */ | |
7730 | ||
7731 | void | |
b67a2c6f | 7732 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7733 | { |
7734 | struct breakpoint *b, *b_tmp; | |
7735 | ||
7736 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7737 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7738 | { |
7739 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7740 | ||
7741 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7742 | dummy_b = dummy_b->related_breakpoint; | |
7743 | if (dummy_b->type != bp_call_dummy | |
7744 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7745 | continue; | |
7746 | ||
b67a2c6f | 7747 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7748 | |
7749 | while (b->related_breakpoint != b) | |
7750 | { | |
7751 | if (b_tmp == b->related_breakpoint) | |
7752 | b_tmp = b->related_breakpoint->next; | |
7753 | delete_breakpoint (b->related_breakpoint); | |
7754 | } | |
7755 | delete_breakpoint (b); | |
7756 | } | |
7757 | } | |
7758 | ||
1900040c MS |
7759 | void |
7760 | enable_overlay_breakpoints (void) | |
7761 | { | |
52f0bd74 | 7762 | struct breakpoint *b; |
1900040c MS |
7763 | |
7764 | ALL_BREAKPOINTS (b) | |
7765 | if (b->type == bp_overlay_event) | |
7766 | { | |
7767 | b->enable_state = bp_enabled; | |
44702360 | 7768 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7769 | overlay_events_enabled = 1; |
1900040c MS |
7770 | } |
7771 | } | |
7772 | ||
7773 | void | |
7774 | disable_overlay_breakpoints (void) | |
7775 | { | |
52f0bd74 | 7776 | struct breakpoint *b; |
1900040c MS |
7777 | |
7778 | ALL_BREAKPOINTS (b) | |
7779 | if (b->type == bp_overlay_event) | |
7780 | { | |
7781 | b->enable_state = bp_disabled; | |
44702360 | 7782 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7783 | overlay_events_enabled = 0; |
1900040c MS |
7784 | } |
7785 | } | |
7786 | ||
aa7d318d TT |
7787 | /* Set an active std::terminate breakpoint for each std::terminate |
7788 | master breakpoint. */ | |
7789 | void | |
7790 | set_std_terminate_breakpoint (void) | |
7791 | { | |
35df4500 | 7792 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7793 | |
35df4500 | 7794 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7795 | if (b->pspace == current_program_space |
7796 | && b->type == bp_std_terminate_master) | |
7797 | { | |
06edf0c0 | 7798 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7799 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7800 | } |
7801 | } | |
7802 | ||
7803 | /* Delete all the std::terminate breakpoints. */ | |
7804 | void | |
7805 | delete_std_terminate_breakpoint (void) | |
7806 | { | |
35df4500 | 7807 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7808 | |
35df4500 | 7809 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7810 | if (b->type == bp_std_terminate) |
7811 | delete_breakpoint (b); | |
7812 | } | |
7813 | ||
c4093a6a | 7814 | struct breakpoint * |
a6d9a66e | 7815 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7816 | { |
7817 | struct breakpoint *b; | |
c4093a6a | 7818 | |
06edf0c0 PA |
7819 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7820 | &internal_breakpoint_ops); | |
7821 | ||
b5de0fa7 | 7822 | b->enable_state = bp_enabled; |
f00aae0f | 7823 | /* location has to be used or breakpoint_re_set will delete me. */ |
305e13e6 | 7824 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7825 | |
44702360 | 7826 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7827 | |
c4093a6a JM |
7828 | return b; |
7829 | } | |
7830 | ||
0101ce28 JJ |
7831 | struct lang_and_radix |
7832 | { | |
7833 | enum language lang; | |
7834 | int radix; | |
7835 | }; | |
7836 | ||
4efc6507 DE |
7837 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7838 | ||
7839 | struct breakpoint * | |
7840 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7841 | { | |
2a7f3dff PA |
7842 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7843 | &internal_breakpoint_ops); | |
4efc6507 | 7844 | } |
0101ce28 | 7845 | |
03673fc7 PP |
7846 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7847 | ||
7848 | void | |
7849 | remove_jit_event_breakpoints (void) | |
7850 | { | |
7851 | struct breakpoint *b, *b_tmp; | |
7852 | ||
7853 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7854 | if (b->type == bp_jit_event | |
7855 | && b->loc->pspace == current_program_space) | |
7856 | delete_breakpoint (b); | |
7857 | } | |
7858 | ||
cae688ec JJ |
7859 | void |
7860 | remove_solib_event_breakpoints (void) | |
7861 | { | |
35df4500 | 7862 | struct breakpoint *b, *b_tmp; |
cae688ec | 7863 | |
35df4500 | 7864 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7865 | if (b->type == bp_shlib_event |
7866 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7867 | delete_breakpoint (b); |
7868 | } | |
7869 | ||
f37f681c PA |
7870 | /* See breakpoint.h. */ |
7871 | ||
7872 | void | |
7873 | remove_solib_event_breakpoints_at_next_stop (void) | |
7874 | { | |
7875 | struct breakpoint *b, *b_tmp; | |
7876 | ||
7877 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7878 | if (b->type == bp_shlib_event | |
7879 | && b->loc->pspace == current_program_space) | |
7880 | b->disposition = disp_del_at_next_stop; | |
7881 | } | |
7882 | ||
04086b45 PA |
7883 | /* Helper for create_solib_event_breakpoint / |
7884 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7885 | INSERT_MODE to pass through to update_global_location_list. */ | |
7886 | ||
7887 | static struct breakpoint * | |
7888 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7889 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7890 | { |
7891 | struct breakpoint *b; | |
7892 | ||
06edf0c0 PA |
7893 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7894 | &internal_breakpoint_ops); | |
04086b45 | 7895 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7896 | return b; |
7897 | } | |
7898 | ||
04086b45 PA |
7899 | struct breakpoint * |
7900 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7901 | { | |
7902 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7903 | } | |
7904 | ||
f37f681c PA |
7905 | /* See breakpoint.h. */ |
7906 | ||
7907 | struct breakpoint * | |
7908 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7909 | { | |
7910 | struct breakpoint *b; | |
7911 | ||
04086b45 PA |
7912 | /* Explicitly tell update_global_location_list to insert |
7913 | locations. */ | |
7914 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7915 | if (!b->loc->inserted) |
7916 | { | |
7917 | delete_breakpoint (b); | |
7918 | return NULL; | |
7919 | } | |
7920 | return b; | |
7921 | } | |
7922 | ||
cae688ec JJ |
7923 | /* Disable any breakpoints that are on code in shared libraries. Only |
7924 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7925 | ||
7926 | void | |
cb851954 | 7927 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7928 | { |
876fa593 | 7929 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7930 | |
876fa593 | 7931 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7932 | { |
2bdf28a0 | 7933 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7934 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7935 | |
4a64f543 MS |
7936 | /* We apply the check to all breakpoints, including disabled for |
7937 | those with loc->duplicate set. This is so that when breakpoint | |
7938 | becomes enabled, or the duplicate is removed, gdb will try to | |
7939 | insert all breakpoints. If we don't set shlib_disabled here, | |
7940 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7941 | if (((b->type == bp_breakpoint) |
508ccb1f | 7942 | || (b->type == bp_jit_event) |
1042e4c0 | 7943 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7944 | || (is_tracepoint (b))) |
6c95b8df | 7945 | && loc->pspace == current_program_space |
0d381245 | 7946 | && !loc->shlib_disabled |
6c95b8df | 7947 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7948 | ) |
0d381245 VP |
7949 | { |
7950 | loc->shlib_disabled = 1; | |
7951 | } | |
cae688ec JJ |
7952 | } |
7953 | } | |
7954 | ||
63644780 NB |
7955 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7956 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7957 | disabled ones can just stay disabled. */ | |
84acb35a | 7958 | |
75149521 | 7959 | static void |
84acb35a JJ |
7960 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7961 | { | |
876fa593 | 7962 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7963 | int disabled_shlib_breaks = 0; |
7964 | ||
c86cf029 VP |
7965 | /* SunOS a.out shared libraries are always mapped, so do not |
7966 | disable breakpoints; they will only be reported as unloaded | |
7967 | through clear_solib when GDB discards its shared library | |
7968 | list. See clear_solib for more information. */ | |
7969 | if (exec_bfd != NULL | |
7970 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7971 | return; | |
7972 | ||
876fa593 | 7973 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7974 | { |
2bdf28a0 | 7975 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7976 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7977 | |
1e4d1764 | 7978 | if (solib->pspace == loc->pspace |
e2dd7057 | 7979 | && !loc->shlib_disabled |
1e4d1764 YQ |
7980 | && (((b->type == bp_breakpoint |
7981 | || b->type == bp_jit_event | |
7982 | || b->type == bp_hardware_breakpoint) | |
7983 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7984 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7985 | || is_tracepoint (b)) | |
e2dd7057 | 7986 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7987 | { |
e2dd7057 PP |
7988 | loc->shlib_disabled = 1; |
7989 | /* At this point, we cannot rely on remove_breakpoint | |
7990 | succeeding so we must mark the breakpoint as not inserted | |
7991 | to prevent future errors occurring in remove_breakpoints. */ | |
7992 | loc->inserted = 0; | |
8d3788bd VP |
7993 | |
7994 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7995 | observer_notify_breakpoint_modified (b); | |
7996 | ||
e2dd7057 PP |
7997 | if (!disabled_shlib_breaks) |
7998 | { | |
7999 | target_terminal_ours_for_output (); | |
3e43a32a MS |
8000 | warning (_("Temporarily disabling breakpoints " |
8001 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 8002 | solib->so_name); |
84acb35a | 8003 | } |
e2dd7057 | 8004 | disabled_shlib_breaks = 1; |
84acb35a JJ |
8005 | } |
8006 | } | |
84acb35a JJ |
8007 | } |
8008 | ||
63644780 NB |
8009 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
8010 | notification of free_objfile. Only apply to enabled breakpoints, | |
8011 | disabled ones can just stay disabled. */ | |
8012 | ||
8013 | static void | |
8014 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
8015 | { | |
8016 | struct breakpoint *b; | |
8017 | ||
8018 | if (objfile == NULL) | |
8019 | return; | |
8020 | ||
d03de421 PA |
8021 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
8022 | managed by the user with add-symbol-file/remove-symbol-file. | |
8023 | Similarly to how breakpoints in shared libraries are handled in | |
8024 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
8025 | shlib_disabled so they end up uninserted on the next global |
8026 | location list update. Shared libraries not loaded by the user | |
8027 | aren't handled here -- they're already handled in | |
8028 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
8029 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
8030 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
8031 | main objfile). */ | |
8032 | if ((objfile->flags & OBJF_SHARED) == 0 | |
8033 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
8034 | return; |
8035 | ||
8036 | ALL_BREAKPOINTS (b) | |
8037 | { | |
8038 | struct bp_location *loc; | |
8039 | int bp_modified = 0; | |
8040 | ||
8041 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
8042 | continue; | |
8043 | ||
8044 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
8045 | { | |
8046 | CORE_ADDR loc_addr = loc->address; | |
8047 | ||
8048 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8049 | && loc->loc_type != bp_loc_software_breakpoint) | |
8050 | continue; | |
8051 | ||
8052 | if (loc->shlib_disabled != 0) | |
8053 | continue; | |
8054 | ||
8055 | if (objfile->pspace != loc->pspace) | |
8056 | continue; | |
8057 | ||
8058 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8059 | && loc->loc_type != bp_loc_software_breakpoint) | |
8060 | continue; | |
8061 | ||
8062 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8063 | { | |
8064 | loc->shlib_disabled = 1; | |
08351840 PA |
8065 | /* At this point, we don't know whether the object was |
8066 | unmapped from the inferior or not, so leave the | |
8067 | inserted flag alone. We'll handle failure to | |
8068 | uninsert quietly, in case the object was indeed | |
8069 | unmapped. */ | |
63644780 NB |
8070 | |
8071 | mark_breakpoint_location_modified (loc); | |
8072 | ||
8073 | bp_modified = 1; | |
8074 | } | |
8075 | } | |
8076 | ||
8077 | if (bp_modified) | |
8078 | observer_notify_breakpoint_modified (b); | |
8079 | } | |
8080 | } | |
8081 | ||
ce78b96d JB |
8082 | /* FORK & VFORK catchpoints. */ |
8083 | ||
e29a4733 PA |
8084 | /* An instance of this type is used to represent a fork or vfork |
8085 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8086 | class; users downcast to "struct breakpoint *" when needed. A | |
8087 | breakpoint is really of this type iff its ops pointer points to | |
8088 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8089 | ||
8090 | struct fork_catchpoint | |
8091 | { | |
8092 | /* The base class. */ | |
8093 | struct breakpoint base; | |
8094 | ||
8095 | /* Process id of a child process whose forking triggered this | |
8096 | catchpoint. This field is only valid immediately after this | |
8097 | catchpoint has triggered. */ | |
8098 | ptid_t forked_inferior_pid; | |
8099 | }; | |
8100 | ||
4a64f543 MS |
8101 | /* Implement the "insert" breakpoint_ops method for fork |
8102 | catchpoints. */ | |
ce78b96d | 8103 | |
77b06cd7 TJB |
8104 | static int |
8105 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8106 | { |
dfd4cc63 | 8107 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8108 | } |
8109 | ||
4a64f543 MS |
8110 | /* Implement the "remove" breakpoint_ops method for fork |
8111 | catchpoints. */ | |
ce78b96d JB |
8112 | |
8113 | static int | |
73971819 | 8114 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8115 | { |
dfd4cc63 | 8116 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8117 | } |
8118 | ||
8119 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8120 | catchpoints. */ | |
8121 | ||
8122 | static int | |
f1310107 | 8123 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8124 | struct address_space *aspace, CORE_ADDR bp_addr, |
8125 | const struct target_waitstatus *ws) | |
ce78b96d | 8126 | { |
e29a4733 PA |
8127 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8128 | ||
f90263c1 TT |
8129 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8130 | return 0; | |
8131 | ||
8132 | c->forked_inferior_pid = ws->value.related_pid; | |
8133 | return 1; | |
ce78b96d JB |
8134 | } |
8135 | ||
4a64f543 MS |
8136 | /* Implement the "print_it" breakpoint_ops method for fork |
8137 | catchpoints. */ | |
ce78b96d JB |
8138 | |
8139 | static enum print_stop_action | |
348d480f | 8140 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8141 | { |
36dfb11c | 8142 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8143 | struct breakpoint *b = bs->breakpoint_at; |
8144 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8145 | |
ce78b96d | 8146 | annotate_catchpoint (b->number); |
f303dbd6 | 8147 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8148 | if (b->disposition == disp_del) |
f303dbd6 | 8149 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8150 | else |
f303dbd6 | 8151 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8152 | if (ui_out_is_mi_like_p (uiout)) |
8153 | { | |
8154 | ui_out_field_string (uiout, "reason", | |
8155 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8156 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8157 | } | |
8158 | ui_out_field_int (uiout, "bkptno", b->number); | |
8159 | ui_out_text (uiout, " (forked process "); | |
8160 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8161 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8162 | return PRINT_SRC_AND_LOC; |
8163 | } | |
8164 | ||
4a64f543 MS |
8165 | /* Implement the "print_one" breakpoint_ops method for fork |
8166 | catchpoints. */ | |
ce78b96d JB |
8167 | |
8168 | static void | |
a6d9a66e | 8169 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8170 | { |
e29a4733 | 8171 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8172 | struct value_print_options opts; |
79a45e25 | 8173 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8174 | |
8175 | get_user_print_options (&opts); | |
8176 | ||
4a64f543 MS |
8177 | /* Field 4, the address, is omitted (which makes the columns not |
8178 | line up too nicely with the headers, but the effect is relatively | |
8179 | readable). */ | |
79a45b7d | 8180 | if (opts.addressprint) |
ce78b96d JB |
8181 | ui_out_field_skip (uiout, "addr"); |
8182 | annotate_field (5); | |
8183 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8184 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8185 | { |
8186 | ui_out_text (uiout, ", process "); | |
8187 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8188 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8189 | ui_out_spaces (uiout, 1); |
8190 | } | |
8ac3646f TT |
8191 | |
8192 | if (ui_out_is_mi_like_p (uiout)) | |
8193 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8194 | } |
8195 | ||
8196 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8197 | catchpoints. */ | |
8198 | ||
8199 | static void | |
8200 | print_mention_catch_fork (struct breakpoint *b) | |
8201 | { | |
8202 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8203 | } | |
8204 | ||
6149aea9 PA |
8205 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8206 | catchpoints. */ | |
8207 | ||
8208 | static void | |
8209 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8210 | { | |
8211 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8212 | print_recreate_thread (b, fp); |
6149aea9 PA |
8213 | } |
8214 | ||
ce78b96d JB |
8215 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8216 | ||
2060206e | 8217 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8218 | |
4a64f543 MS |
8219 | /* Implement the "insert" breakpoint_ops method for vfork |
8220 | catchpoints. */ | |
ce78b96d | 8221 | |
77b06cd7 TJB |
8222 | static int |
8223 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8224 | { |
dfd4cc63 | 8225 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8226 | } |
8227 | ||
4a64f543 MS |
8228 | /* Implement the "remove" breakpoint_ops method for vfork |
8229 | catchpoints. */ | |
ce78b96d JB |
8230 | |
8231 | static int | |
73971819 | 8232 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8233 | { |
dfd4cc63 | 8234 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8235 | } |
8236 | ||
8237 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8238 | catchpoints. */ | |
8239 | ||
8240 | static int | |
f1310107 | 8241 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8242 | struct address_space *aspace, CORE_ADDR bp_addr, |
8243 | const struct target_waitstatus *ws) | |
ce78b96d | 8244 | { |
e29a4733 PA |
8245 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8246 | ||
f90263c1 TT |
8247 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8248 | return 0; | |
8249 | ||
8250 | c->forked_inferior_pid = ws->value.related_pid; | |
8251 | return 1; | |
ce78b96d JB |
8252 | } |
8253 | ||
4a64f543 MS |
8254 | /* Implement the "print_it" breakpoint_ops method for vfork |
8255 | catchpoints. */ | |
ce78b96d JB |
8256 | |
8257 | static enum print_stop_action | |
348d480f | 8258 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8259 | { |
36dfb11c | 8260 | struct ui_out *uiout = current_uiout; |
348d480f | 8261 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8262 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8263 | ||
ce78b96d | 8264 | annotate_catchpoint (b->number); |
f303dbd6 | 8265 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8266 | if (b->disposition == disp_del) |
f303dbd6 | 8267 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8268 | else |
f303dbd6 | 8269 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8270 | if (ui_out_is_mi_like_p (uiout)) |
8271 | { | |
8272 | ui_out_field_string (uiout, "reason", | |
8273 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8274 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8275 | } | |
8276 | ui_out_field_int (uiout, "bkptno", b->number); | |
8277 | ui_out_text (uiout, " (vforked process "); | |
8278 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8279 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8280 | return PRINT_SRC_AND_LOC; |
8281 | } | |
8282 | ||
4a64f543 MS |
8283 | /* Implement the "print_one" breakpoint_ops method for vfork |
8284 | catchpoints. */ | |
ce78b96d JB |
8285 | |
8286 | static void | |
a6d9a66e | 8287 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8288 | { |
e29a4733 | 8289 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8290 | struct value_print_options opts; |
79a45e25 | 8291 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8292 | |
8293 | get_user_print_options (&opts); | |
4a64f543 MS |
8294 | /* Field 4, the address, is omitted (which makes the columns not |
8295 | line up too nicely with the headers, but the effect is relatively | |
8296 | readable). */ | |
79a45b7d | 8297 | if (opts.addressprint) |
ce78b96d JB |
8298 | ui_out_field_skip (uiout, "addr"); |
8299 | annotate_field (5); | |
8300 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8301 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8302 | { |
8303 | ui_out_text (uiout, ", process "); | |
8304 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8305 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8306 | ui_out_spaces (uiout, 1); |
8307 | } | |
8ac3646f TT |
8308 | |
8309 | if (ui_out_is_mi_like_p (uiout)) | |
8310 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8311 | } |
8312 | ||
8313 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8314 | catchpoints. */ | |
8315 | ||
8316 | static void | |
8317 | print_mention_catch_vfork (struct breakpoint *b) | |
8318 | { | |
8319 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8320 | } | |
8321 | ||
6149aea9 PA |
8322 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8323 | catchpoints. */ | |
8324 | ||
8325 | static void | |
8326 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8327 | { | |
8328 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8329 | print_recreate_thread (b, fp); |
6149aea9 PA |
8330 | } |
8331 | ||
ce78b96d JB |
8332 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8333 | ||
2060206e | 8334 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8335 | |
edcc5120 TT |
8336 | /* An instance of this type is used to represent an solib catchpoint. |
8337 | It includes a "struct breakpoint" as a kind of base class; users | |
8338 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8339 | really of this type iff its ops pointer points to | |
8340 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8341 | ||
8342 | struct solib_catchpoint | |
8343 | { | |
8344 | /* The base class. */ | |
8345 | struct breakpoint base; | |
8346 | ||
8347 | /* True for "catch load", false for "catch unload". */ | |
8348 | unsigned char is_load; | |
8349 | ||
8350 | /* Regular expression to match, if any. COMPILED is only valid when | |
8351 | REGEX is non-NULL. */ | |
8352 | char *regex; | |
8353 | regex_t compiled; | |
8354 | }; | |
8355 | ||
8356 | static void | |
8357 | dtor_catch_solib (struct breakpoint *b) | |
8358 | { | |
8359 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8360 | ||
8361 | if (self->regex) | |
8362 | regfree (&self->compiled); | |
8363 | xfree (self->regex); | |
8364 | ||
8365 | base_breakpoint_ops.dtor (b); | |
8366 | } | |
8367 | ||
8368 | static int | |
8369 | insert_catch_solib (struct bp_location *ignore) | |
8370 | { | |
8371 | return 0; | |
8372 | } | |
8373 | ||
8374 | static int | |
73971819 | 8375 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8376 | { |
8377 | return 0; | |
8378 | } | |
8379 | ||
8380 | static int | |
8381 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8382 | struct address_space *aspace, | |
8383 | CORE_ADDR bp_addr, | |
8384 | const struct target_waitstatus *ws) | |
8385 | { | |
8386 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8387 | struct breakpoint *other; | |
8388 | ||
8389 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8390 | return 1; | |
8391 | ||
8392 | ALL_BREAKPOINTS (other) | |
8393 | { | |
8394 | struct bp_location *other_bl; | |
8395 | ||
8396 | if (other == bl->owner) | |
8397 | continue; | |
8398 | ||
8399 | if (other->type != bp_shlib_event) | |
8400 | continue; | |
8401 | ||
8402 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8403 | continue; | |
8404 | ||
8405 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8406 | { | |
8407 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8408 | return 1; | |
8409 | } | |
8410 | } | |
8411 | ||
8412 | return 0; | |
8413 | } | |
8414 | ||
8415 | static void | |
8416 | check_status_catch_solib (struct bpstats *bs) | |
8417 | { | |
8418 | struct solib_catchpoint *self | |
8419 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8420 | int ix; | |
8421 | ||
8422 | if (self->is_load) | |
8423 | { | |
8424 | struct so_list *iter; | |
8425 | ||
8426 | for (ix = 0; | |
8427 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8428 | ix, iter); | |
8429 | ++ix) | |
8430 | { | |
8431 | if (!self->regex | |
8432 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8433 | return; | |
8434 | } | |
8435 | } | |
8436 | else | |
8437 | { | |
8438 | char *iter; | |
8439 | ||
8440 | for (ix = 0; | |
8441 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8442 | ix, iter); | |
8443 | ++ix) | |
8444 | { | |
8445 | if (!self->regex | |
8446 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8447 | return; | |
8448 | } | |
8449 | } | |
8450 | ||
8451 | bs->stop = 0; | |
8452 | bs->print_it = print_it_noop; | |
8453 | } | |
8454 | ||
8455 | static enum print_stop_action | |
8456 | print_it_catch_solib (bpstat bs) | |
8457 | { | |
8458 | struct breakpoint *b = bs->breakpoint_at; | |
8459 | struct ui_out *uiout = current_uiout; | |
8460 | ||
8461 | annotate_catchpoint (b->number); | |
f303dbd6 | 8462 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8463 | if (b->disposition == disp_del) |
f303dbd6 | 8464 | ui_out_text (uiout, "Temporary catchpoint "); |
edcc5120 | 8465 | else |
f303dbd6 | 8466 | ui_out_text (uiout, "Catchpoint "); |
edcc5120 TT |
8467 | ui_out_field_int (uiout, "bkptno", b->number); |
8468 | ui_out_text (uiout, "\n"); | |
8469 | if (ui_out_is_mi_like_p (uiout)) | |
8470 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8471 | print_solib_event (1); | |
8472 | return PRINT_SRC_AND_LOC; | |
8473 | } | |
8474 | ||
8475 | static void | |
8476 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8477 | { | |
8478 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8479 | struct value_print_options opts; | |
8480 | struct ui_out *uiout = current_uiout; | |
8481 | char *msg; | |
8482 | ||
8483 | get_user_print_options (&opts); | |
8484 | /* Field 4, the address, is omitted (which makes the columns not | |
8485 | line up too nicely with the headers, but the effect is relatively | |
8486 | readable). */ | |
8487 | if (opts.addressprint) | |
8488 | { | |
8489 | annotate_field (4); | |
8490 | ui_out_field_skip (uiout, "addr"); | |
8491 | } | |
8492 | ||
8493 | annotate_field (5); | |
8494 | if (self->is_load) | |
8495 | { | |
8496 | if (self->regex) | |
8497 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8498 | else | |
8499 | msg = xstrdup (_("load of library")); | |
8500 | } | |
8501 | else | |
8502 | { | |
8503 | if (self->regex) | |
8504 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8505 | else | |
8506 | msg = xstrdup (_("unload of library")); | |
8507 | } | |
8508 | ui_out_field_string (uiout, "what", msg); | |
8509 | xfree (msg); | |
8ac3646f TT |
8510 | |
8511 | if (ui_out_is_mi_like_p (uiout)) | |
8512 | ui_out_field_string (uiout, "catch-type", | |
8513 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8514 | } |
8515 | ||
8516 | static void | |
8517 | print_mention_catch_solib (struct breakpoint *b) | |
8518 | { | |
8519 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8520 | ||
8521 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8522 | self->is_load ? "load" : "unload"); | |
8523 | } | |
8524 | ||
8525 | static void | |
8526 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8527 | { | |
8528 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8529 | ||
8530 | fprintf_unfiltered (fp, "%s %s", | |
8531 | b->disposition == disp_del ? "tcatch" : "catch", | |
8532 | self->is_load ? "load" : "unload"); | |
8533 | if (self->regex) | |
8534 | fprintf_unfiltered (fp, " %s", self->regex); | |
8535 | fprintf_unfiltered (fp, "\n"); | |
8536 | } | |
8537 | ||
8538 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8539 | ||
91985142 MG |
8540 | /* Shared helper function (MI and CLI) for creating and installing |
8541 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8542 | the events to be caught are load events, otherwise they are | |
8543 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8544 | temporary one. If ENABLED is non-zero the catchpoint is | |
8545 | created in an enabled state. */ | |
edcc5120 | 8546 | |
91985142 MG |
8547 | void |
8548 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8549 | { |
8550 | struct solib_catchpoint *c; | |
8551 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8552 | struct cleanup *cleanup; |
8553 | ||
edcc5120 TT |
8554 | if (!arg) |
8555 | arg = ""; | |
8556 | arg = skip_spaces (arg); | |
8557 | ||
4d01a485 | 8558 | c = new solib_catchpoint (); |
edcc5120 TT |
8559 | cleanup = make_cleanup (xfree, c); |
8560 | ||
8561 | if (*arg != '\0') | |
8562 | { | |
8563 | int errcode; | |
8564 | ||
8565 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8566 | if (errcode != 0) | |
8567 | { | |
8568 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8569 | ||
8570 | make_cleanup (xfree, err); | |
8571 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8572 | } | |
8573 | c->regex = xstrdup (arg); | |
8574 | } | |
8575 | ||
8576 | c->is_load = is_load; | |
91985142 | 8577 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8578 | &catch_solib_breakpoint_ops); |
8579 | ||
91985142 MG |
8580 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8581 | ||
edcc5120 TT |
8582 | discard_cleanups (cleanup); |
8583 | install_breakpoint (0, &c->base, 1); | |
8584 | } | |
8585 | ||
91985142 MG |
8586 | /* A helper function that does all the work for "catch load" and |
8587 | "catch unload". */ | |
8588 | ||
8589 | static void | |
8590 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8591 | struct cmd_list_element *command) | |
8592 | { | |
8593 | int tempflag; | |
8594 | const int enabled = 1; | |
8595 | ||
8596 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8597 | ||
8598 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8599 | } | |
8600 | ||
edcc5120 TT |
8601 | static void |
8602 | catch_load_command_1 (char *arg, int from_tty, | |
8603 | struct cmd_list_element *command) | |
8604 | { | |
8605 | catch_load_or_unload (arg, from_tty, 1, command); | |
8606 | } | |
8607 | ||
8608 | static void | |
8609 | catch_unload_command_1 (char *arg, int from_tty, | |
8610 | struct cmd_list_element *command) | |
8611 | { | |
8612 | catch_load_or_unload (arg, from_tty, 0, command); | |
8613 | } | |
8614 | ||
346774a9 PA |
8615 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8616 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8617 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8618 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8619 | |
ab04a2af | 8620 | void |
346774a9 PA |
8621 | init_catchpoint (struct breakpoint *b, |
8622 | struct gdbarch *gdbarch, int tempflag, | |
8623 | char *cond_string, | |
c0a91b2b | 8624 | const struct breakpoint_ops *ops) |
c906108c | 8625 | { |
c5aa993b | 8626 | struct symtab_and_line sal; |
346774a9 | 8627 | |
fe39c653 | 8628 | init_sal (&sal); |
6c95b8df | 8629 | sal.pspace = current_program_space; |
c5aa993b | 8630 | |
28010a5d | 8631 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8632 | |
1b36a34b | 8633 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8634 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8635 | } |
8636 | ||
28010a5d | 8637 | void |
3ea46bff | 8638 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8639 | { |
8640 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8641 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8642 | if (is_tracepoint (b)) |
8643 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8644 | if (!internal) |
8645 | mention (b); | |
c56053d2 | 8646 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8647 | |
8648 | if (update_gll) | |
44702360 | 8649 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8650 | } |
8651 | ||
9b70b993 | 8652 | static void |
a6d9a66e UW |
8653 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8654 | int tempflag, char *cond_string, | |
c0a91b2b | 8655 | const struct breakpoint_ops *ops) |
c906108c | 8656 | { |
4d01a485 | 8657 | struct fork_catchpoint *c = new fork_catchpoint (); |
ce78b96d | 8658 | |
e29a4733 PA |
8659 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8660 | ||
8661 | c->forked_inferior_pid = null_ptid; | |
8662 | ||
3ea46bff | 8663 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8664 | } |
8665 | ||
fe798b75 JB |
8666 | /* Exec catchpoints. */ |
8667 | ||
b4d90040 PA |
8668 | /* An instance of this type is used to represent an exec catchpoint. |
8669 | It includes a "struct breakpoint" as a kind of base class; users | |
8670 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8671 | really of this type iff its ops pointer points to | |
8672 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8673 | ||
8674 | struct exec_catchpoint | |
8675 | { | |
8676 | /* The base class. */ | |
8677 | struct breakpoint base; | |
8678 | ||
8679 | /* Filename of a program whose exec triggered this catchpoint. | |
8680 | This field is only valid immediately after this catchpoint has | |
8681 | triggered. */ | |
8682 | char *exec_pathname; | |
8683 | }; | |
8684 | ||
8685 | /* Implement the "dtor" breakpoint_ops method for exec | |
8686 | catchpoints. */ | |
8687 | ||
8688 | static void | |
8689 | dtor_catch_exec (struct breakpoint *b) | |
8690 | { | |
8691 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8692 | ||
8693 | xfree (c->exec_pathname); | |
348d480f | 8694 | |
2060206e | 8695 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8696 | } |
8697 | ||
77b06cd7 TJB |
8698 | static int |
8699 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8700 | { |
dfd4cc63 | 8701 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8702 | } |
c906108c | 8703 | |
fe798b75 | 8704 | static int |
73971819 | 8705 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8706 | { |
dfd4cc63 | 8707 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8708 | } |
c906108c | 8709 | |
fe798b75 | 8710 | static int |
f1310107 | 8711 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8712 | struct address_space *aspace, CORE_ADDR bp_addr, |
8713 | const struct target_waitstatus *ws) | |
fe798b75 | 8714 | { |
b4d90040 PA |
8715 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8716 | ||
f90263c1 TT |
8717 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8718 | return 0; | |
8719 | ||
8720 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8721 | return 1; | |
fe798b75 | 8722 | } |
c906108c | 8723 | |
fe798b75 | 8724 | static enum print_stop_action |
348d480f | 8725 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8726 | { |
36dfb11c | 8727 | struct ui_out *uiout = current_uiout; |
348d480f | 8728 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8729 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8730 | ||
fe798b75 | 8731 | annotate_catchpoint (b->number); |
f303dbd6 | 8732 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8733 | if (b->disposition == disp_del) |
f303dbd6 | 8734 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8735 | else |
f303dbd6 | 8736 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8737 | if (ui_out_is_mi_like_p (uiout)) |
8738 | { | |
8739 | ui_out_field_string (uiout, "reason", | |
8740 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8741 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8742 | } | |
8743 | ui_out_field_int (uiout, "bkptno", b->number); | |
8744 | ui_out_text (uiout, " (exec'd "); | |
8745 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8746 | ui_out_text (uiout, "), "); | |
8747 | ||
fe798b75 | 8748 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8749 | } |
8750 | ||
fe798b75 | 8751 | static void |
a6d9a66e | 8752 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8753 | { |
b4d90040 | 8754 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8755 | struct value_print_options opts; |
79a45e25 | 8756 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8757 | |
8758 | get_user_print_options (&opts); | |
8759 | ||
8760 | /* Field 4, the address, is omitted (which makes the columns | |
8761 | not line up too nicely with the headers, but the effect | |
8762 | is relatively readable). */ | |
8763 | if (opts.addressprint) | |
8764 | ui_out_field_skip (uiout, "addr"); | |
8765 | annotate_field (5); | |
8766 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8767 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8768 | { |
8769 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8770 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8771 | ui_out_text (uiout, "\" "); |
8772 | } | |
8ac3646f TT |
8773 | |
8774 | if (ui_out_is_mi_like_p (uiout)) | |
8775 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8776 | } |
8777 | ||
8778 | static void | |
8779 | print_mention_catch_exec (struct breakpoint *b) | |
8780 | { | |
8781 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8782 | } | |
8783 | ||
6149aea9 PA |
8784 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8785 | catchpoints. */ | |
8786 | ||
8787 | static void | |
8788 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8789 | { | |
8790 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8791 | print_recreate_thread (b, fp); |
6149aea9 PA |
8792 | } |
8793 | ||
2060206e | 8794 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8795 | |
c906108c | 8796 | static int |
fba45db2 | 8797 | hw_breakpoint_used_count (void) |
c906108c | 8798 | { |
c906108c | 8799 | int i = 0; |
f1310107 TJB |
8800 | struct breakpoint *b; |
8801 | struct bp_location *bl; | |
c906108c SS |
8802 | |
8803 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8804 | { |
d6b74ac4 | 8805 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8806 | for (bl = b->loc; bl; bl = bl->next) |
8807 | { | |
8808 | /* Special types of hardware breakpoints may use more than | |
8809 | one register. */ | |
348d480f | 8810 | i += b->ops->resources_needed (bl); |
f1310107 | 8811 | } |
c5aa993b | 8812 | } |
c906108c SS |
8813 | |
8814 | return i; | |
8815 | } | |
8816 | ||
a1398e0c PA |
8817 | /* Returns the resources B would use if it were a hardware |
8818 | watchpoint. */ | |
8819 | ||
c906108c | 8820 | static int |
a1398e0c | 8821 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8822 | { |
c906108c | 8823 | int i = 0; |
e09342b5 | 8824 | struct bp_location *bl; |
c906108c | 8825 | |
a1398e0c PA |
8826 | if (!breakpoint_enabled (b)) |
8827 | return 0; | |
8828 | ||
8829 | for (bl = b->loc; bl; bl = bl->next) | |
8830 | { | |
8831 | /* Special types of hardware watchpoints may use more than | |
8832 | one register. */ | |
8833 | i += b->ops->resources_needed (bl); | |
8834 | } | |
8835 | ||
8836 | return i; | |
8837 | } | |
8838 | ||
8839 | /* Returns the sum the used resources of all hardware watchpoints of | |
8840 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8841 | the sum of the used resources of all hardware watchpoints of other | |
8842 | types _not_ TYPE. */ | |
8843 | ||
8844 | static int | |
8845 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8846 | enum bptype type, int *other_type_used) | |
8847 | { | |
8848 | int i = 0; | |
8849 | struct breakpoint *b; | |
8850 | ||
c906108c SS |
8851 | *other_type_used = 0; |
8852 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8853 | { |
a1398e0c PA |
8854 | if (b == except) |
8855 | continue; | |
e09342b5 TJB |
8856 | if (!breakpoint_enabled (b)) |
8857 | continue; | |
8858 | ||
a1398e0c PA |
8859 | if (b->type == type) |
8860 | i += hw_watchpoint_use_count (b); | |
8861 | else if (is_hardware_watchpoint (b)) | |
8862 | *other_type_used = 1; | |
e09342b5 TJB |
8863 | } |
8864 | ||
c906108c SS |
8865 | return i; |
8866 | } | |
8867 | ||
c906108c | 8868 | void |
fba45db2 | 8869 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8870 | { |
c5aa993b | 8871 | struct breakpoint *b; |
c906108c SS |
8872 | |
8873 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8874 | { |
cc60f2e3 | 8875 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8876 | { |
b5de0fa7 | 8877 | b->enable_state = bp_call_disabled; |
44702360 | 8878 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8879 | } |
8880 | } | |
c906108c SS |
8881 | } |
8882 | ||
8883 | void | |
fba45db2 | 8884 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8885 | { |
c5aa993b | 8886 | struct breakpoint *b; |
c906108c SS |
8887 | |
8888 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8889 | { |
cc60f2e3 | 8890 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8891 | { |
b5de0fa7 | 8892 | b->enable_state = bp_enabled; |
44702360 | 8893 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8894 | } |
8895 | } | |
c906108c SS |
8896 | } |
8897 | ||
8bea4e01 UW |
8898 | void |
8899 | disable_breakpoints_before_startup (void) | |
8900 | { | |
6c95b8df | 8901 | current_program_space->executing_startup = 1; |
44702360 | 8902 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8903 | } |
8904 | ||
8905 | void | |
8906 | enable_breakpoints_after_startup (void) | |
8907 | { | |
6c95b8df | 8908 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8909 | breakpoint_re_set (); |
8bea4e01 UW |
8910 | } |
8911 | ||
7c16b83e PA |
8912 | /* Create a new single-step breakpoint for thread THREAD, with no |
8913 | locations. */ | |
c906108c | 8914 | |
7c16b83e PA |
8915 | static struct breakpoint * |
8916 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8917 | { | |
4d01a485 | 8918 | struct breakpoint *b = new breakpoint (); |
7c16b83e PA |
8919 | |
8920 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8921 | &momentary_breakpoint_ops); | |
8922 | ||
8923 | b->disposition = disp_donttouch; | |
8924 | b->frame_id = null_frame_id; | |
8925 | ||
8926 | b->thread = thread; | |
8927 | gdb_assert (b->thread != 0); | |
8928 | ||
8929 | add_to_breakpoint_chain (b); | |
8930 | ||
8931 | return b; | |
8932 | } | |
8933 | ||
8934 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8935 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8936 | frame. */ | |
c906108c SS |
8937 | |
8938 | struct breakpoint * | |
a6d9a66e UW |
8939 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8940 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8941 | { |
52f0bd74 | 8942 | struct breakpoint *b; |
edb3359d | 8943 | |
193facb3 JK |
8944 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8945 | tail-called one. */ | |
8946 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8947 | |
06edf0c0 | 8948 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8949 | b->enable_state = bp_enabled; |
8950 | b->disposition = disp_donttouch; | |
818dd999 | 8951 | b->frame_id = frame_id; |
c906108c | 8952 | |
4a64f543 MS |
8953 | /* If we're debugging a multi-threaded program, then we want |
8954 | momentary breakpoints to be active in only a single thread of | |
8955 | control. */ | |
39f77062 | 8956 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8957 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8958 | |
44702360 | 8959 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8960 | |
c906108c SS |
8961 | return b; |
8962 | } | |
611c83ae | 8963 | |
06edf0c0 | 8964 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8965 | The new breakpoint will have type TYPE, use OPS as its |
8966 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8967 | |
06edf0c0 PA |
8968 | static struct breakpoint * |
8969 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8970 | enum bptype type, | |
a1aa2221 LM |
8971 | const struct breakpoint_ops *ops, |
8972 | int loc_enabled) | |
e58b0e63 PA |
8973 | { |
8974 | struct breakpoint *copy; | |
8975 | ||
06edf0c0 | 8976 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8977 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8978 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8979 | |
a6d9a66e | 8980 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8981 | copy->loc->requested_address = orig->loc->requested_address; |
8982 | copy->loc->address = orig->loc->address; | |
8983 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8984 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8985 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8986 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8987 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8988 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8989 | copy->frame_id = orig->frame_id; |
8990 | copy->thread = orig->thread; | |
6c95b8df | 8991 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8992 | |
8993 | copy->enable_state = bp_enabled; | |
8994 | copy->disposition = disp_donttouch; | |
8995 | copy->number = internal_breakpoint_number--; | |
8996 | ||
44702360 | 8997 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8998 | return copy; |
8999 | } | |
9000 | ||
06edf0c0 PA |
9001 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9002 | ORIG is NULL. */ | |
9003 | ||
9004 | struct breakpoint * | |
9005 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9006 | { | |
9007 | /* If there's nothing to clone, then return nothing. */ | |
9008 | if (orig == NULL) | |
9009 | return NULL; | |
9010 | ||
a1aa2221 | 9011 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
9012 | } |
9013 | ||
611c83ae | 9014 | struct breakpoint * |
a6d9a66e UW |
9015 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9016 | enum bptype type) | |
611c83ae PA |
9017 | { |
9018 | struct symtab_and_line sal; | |
9019 | ||
9020 | sal = find_pc_line (pc, 0); | |
9021 | sal.pc = pc; | |
9022 | sal.section = find_pc_overlay (pc); | |
9023 | sal.explicit_pc = 1; | |
9024 | ||
a6d9a66e | 9025 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9026 | } |
c906108c | 9027 | \f |
c5aa993b | 9028 | |
c906108c SS |
9029 | /* Tell the user we have just set a breakpoint B. */ |
9030 | ||
9031 | static void | |
fba45db2 | 9032 | mention (struct breakpoint *b) |
c906108c | 9033 | { |
348d480f | 9034 | b->ops->print_mention (b); |
79a45e25 | 9035 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9036 | return; |
c906108c SS |
9037 | printf_filtered ("\n"); |
9038 | } | |
c906108c | 9039 | \f |
c5aa993b | 9040 | |
1a853c52 PA |
9041 | static int bp_loc_is_permanent (struct bp_location *loc); |
9042 | ||
0d381245 | 9043 | static struct bp_location * |
39d61571 | 9044 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9045 | const struct symtab_and_line *sal) |
9046 | { | |
9047 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9048 | CORE_ADDR adjusted_address; |
9049 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9050 | ||
9051 | if (loc_gdbarch == NULL) | |
9052 | loc_gdbarch = b->gdbarch; | |
9053 | ||
9054 | /* Adjust the breakpoint's address prior to allocating a location. | |
9055 | Once we call allocate_bp_location(), that mostly uninitialized | |
9056 | location will be placed on the location chain. Adjustment of the | |
9057 | breakpoint may cause target_read_memory() to be called and we do | |
9058 | not want its scan of the location chain to find a breakpoint and | |
9059 | location that's only been partially initialized. */ | |
9060 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9061 | sal->pc, b->type); | |
0d381245 | 9062 | |
d30113d4 | 9063 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9064 | loc = allocate_bp_location (b); |
d30113d4 JK |
9065 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9066 | tmp = &((*tmp)->next)) | |
0d381245 | 9067 | ; |
d30113d4 | 9068 | loc->next = *tmp; |
0d381245 | 9069 | *tmp = loc; |
3742cc8b | 9070 | |
0d381245 | 9071 | loc->requested_address = sal->pc; |
3742cc8b | 9072 | loc->address = adjusted_address; |
6c95b8df | 9073 | loc->pspace = sal->pspace; |
729662a5 TT |
9074 | loc->probe.probe = sal->probe; |
9075 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9076 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9077 | loc->section = sal->section; |
3742cc8b | 9078 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9079 | loc->line_number = sal->line; |
2f202fde | 9080 | loc->symtab = sal->symtab; |
f8eba3c6 | 9081 | |
0e30163f JK |
9082 | set_breakpoint_location_function (loc, |
9083 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9084 | |
6ae88661 LM |
9085 | /* While by definition, permanent breakpoints are already present in the |
9086 | code, we don't mark the location as inserted. Normally one would expect | |
9087 | that GDB could rely on that breakpoint instruction to stop the program, | |
9088 | thus removing the need to insert its own breakpoint, except that executing | |
9089 | the breakpoint instruction can kill the target instead of reporting a | |
9090 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9091 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9092 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9093 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9094 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9095 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9096 | it manually increments the PC, thus avoiding executing the breakpoint | |
9097 | instruction.) */ | |
1a853c52 | 9098 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9099 | loc->permanent = 1; |
1a853c52 | 9100 | |
0d381245 VP |
9101 | return loc; |
9102 | } | |
514f746b AR |
9103 | \f |
9104 | ||
1cf4d951 | 9105 | /* See breakpoint.h. */ |
514f746b | 9106 | |
1cf4d951 PA |
9107 | int |
9108 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9109 | { |
9110 | int len; | |
9111 | CORE_ADDR addr; | |
1afeeb75 | 9112 | const gdb_byte *bpoint; |
514f746b | 9113 | gdb_byte *target_mem; |
939c61fa JK |
9114 | struct cleanup *cleanup; |
9115 | int retval = 0; | |
514f746b | 9116 | |
1cf4d951 PA |
9117 | addr = address; |
9118 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9119 | ||
9120 | /* Software breakpoints unsupported? */ | |
9121 | if (bpoint == NULL) | |
9122 | return 0; | |
9123 | ||
224c3ddb | 9124 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9125 | |
9126 | /* Enable the automatic memory restoration from breakpoints while | |
9127 | we read the memory. Otherwise we could say about our temporary | |
9128 | breakpoints they are permanent. */ | |
9129 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9130 | ||
9131 | if (target_read_memory (address, target_mem, len) == 0 | |
9132 | && memcmp (target_mem, bpoint, len) == 0) | |
9133 | retval = 1; | |
9134 | ||
9135 | do_cleanups (cleanup); | |
9136 | ||
9137 | return retval; | |
9138 | } | |
9139 | ||
9140 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9141 | return 0 otherwise. */ | |
9142 | ||
9143 | static int | |
9144 | bp_loc_is_permanent (struct bp_location *loc) | |
9145 | { | |
9146 | struct cleanup *cleanup; | |
9147 | int retval; | |
9148 | ||
514f746b AR |
9149 | gdb_assert (loc != NULL); |
9150 | ||
244558af LM |
9151 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9152 | attempt to read from the addresses the locations of these breakpoint types | |
9153 | point to. program_breakpoint_here_p, below, will attempt to read | |
9154 | memory. */ | |
9155 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9156 | return 0; | |
9157 | ||
6c95b8df | 9158 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9159 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9160 | |
1cf4d951 | 9161 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9162 | |
939c61fa JK |
9163 | do_cleanups (cleanup); |
9164 | ||
9165 | return retval; | |
514f746b AR |
9166 | } |
9167 | ||
e7e0cddf SS |
9168 | /* Build a command list for the dprintf corresponding to the current |
9169 | settings of the dprintf style options. */ | |
9170 | ||
9171 | static void | |
9172 | update_dprintf_command_list (struct breakpoint *b) | |
9173 | { | |
9174 | char *dprintf_args = b->extra_string; | |
9175 | char *printf_line = NULL; | |
9176 | ||
9177 | if (!dprintf_args) | |
9178 | return; | |
9179 | ||
9180 | dprintf_args = skip_spaces (dprintf_args); | |
9181 | ||
9182 | /* Allow a comma, as it may have terminated a location, but don't | |
9183 | insist on it. */ | |
9184 | if (*dprintf_args == ',') | |
9185 | ++dprintf_args; | |
9186 | dprintf_args = skip_spaces (dprintf_args); | |
9187 | ||
9188 | if (*dprintf_args != '"') | |
9189 | error (_("Bad format string, missing '\"'.")); | |
9190 | ||
d3ce09f5 | 9191 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9192 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9193 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9194 | { |
9195 | if (!dprintf_function) | |
9196 | error (_("No function supplied for dprintf call")); | |
9197 | ||
9198 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9199 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9200 | dprintf_function, | |
9201 | dprintf_channel, | |
9202 | dprintf_args); | |
9203 | else | |
9204 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9205 | dprintf_function, | |
9206 | dprintf_args); | |
9207 | } | |
d3ce09f5 SS |
9208 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9209 | { | |
9210 | if (target_can_run_breakpoint_commands ()) | |
9211 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9212 | else | |
9213 | { | |
9214 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9215 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9216 | } | |
9217 | } | |
e7e0cddf SS |
9218 | else |
9219 | internal_error (__FILE__, __LINE__, | |
9220 | _("Invalid dprintf style.")); | |
9221 | ||
f28045c2 | 9222 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9223 | /* Manufacture a printf sequence. */ |
f28045c2 | 9224 | { |
8d749320 | 9225 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9226 | |
f28045c2 YQ |
9227 | printf_cmd_line->control_type = simple_control; |
9228 | printf_cmd_line->body_count = 0; | |
9229 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9230 | printf_cmd_line->next = NULL; |
f28045c2 | 9231 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9232 | |
f28045c2 YQ |
9233 | breakpoint_set_commands (b, printf_cmd_line); |
9234 | } | |
e7e0cddf SS |
9235 | } |
9236 | ||
9237 | /* Update all dprintf commands, making their command lists reflect | |
9238 | current style settings. */ | |
9239 | ||
9240 | static void | |
9241 | update_dprintf_commands (char *args, int from_tty, | |
9242 | struct cmd_list_element *c) | |
9243 | { | |
9244 | struct breakpoint *b; | |
9245 | ||
9246 | ALL_BREAKPOINTS (b) | |
9247 | { | |
9248 | if (b->type == bp_dprintf) | |
9249 | update_dprintf_command_list (b); | |
9250 | } | |
9251 | } | |
c3f6f71d | 9252 | |
f00aae0f KS |
9253 | /* Create a breakpoint with SAL as location. Use LOCATION |
9254 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9255 | as condition expression. If LOCATION is NULL then create an |
9256 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9257 | |
9258 | static void | |
d9b3f62e | 9259 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f KS |
9260 | struct symtabs_and_lines sals, |
9261 | struct event_location *location, | |
f8eba3c6 | 9262 | char *filter, char *cond_string, |
e7e0cddf | 9263 | char *extra_string, |
d9b3f62e PA |
9264 | enum bptype type, enum bpdisp disposition, |
9265 | int thread, int task, int ignore_count, | |
c0a91b2b | 9266 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9267 | int enabled, int internal, unsigned flags, |
9268 | int display_canonical) | |
018d34a4 | 9269 | { |
0d381245 | 9270 | int i; |
018d34a4 VP |
9271 | |
9272 | if (type == bp_hardware_breakpoint) | |
9273 | { | |
fbbd034e AS |
9274 | int target_resources_ok; |
9275 | ||
9276 | i = hw_breakpoint_used_count (); | |
9277 | target_resources_ok = | |
9278 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9279 | i + 1, 0); |
9280 | if (target_resources_ok == 0) | |
9281 | error (_("No hardware breakpoint support in the target.")); | |
9282 | else if (target_resources_ok < 0) | |
9283 | error (_("Hardware breakpoints used exceeds limit.")); | |
9284 | } | |
9285 | ||
6c95b8df PA |
9286 | gdb_assert (sals.nelts > 0); |
9287 | ||
0d381245 VP |
9288 | for (i = 0; i < sals.nelts; ++i) |
9289 | { | |
9290 | struct symtab_and_line sal = sals.sals[i]; | |
9291 | struct bp_location *loc; | |
9292 | ||
9293 | if (from_tty) | |
5af949e3 UW |
9294 | { |
9295 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9296 | if (!loc_gdbarch) | |
9297 | loc_gdbarch = gdbarch; | |
9298 | ||
9299 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9300 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9301 | } |
0d381245 VP |
9302 | |
9303 | if (i == 0) | |
9304 | { | |
d9b3f62e | 9305 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9306 | b->thread = thread; |
4a306c9a | 9307 | b->task = task; |
855a6e68 | 9308 | |
0d381245 | 9309 | b->cond_string = cond_string; |
e7e0cddf | 9310 | b->extra_string = extra_string; |
0d381245 | 9311 | b->ignore_count = ignore_count; |
41447f92 | 9312 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9313 | b->disposition = disposition; |
6c95b8df | 9314 | |
44f238bb PA |
9315 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9316 | b->loc->inserted = 1; | |
9317 | ||
0fb4aa4b PA |
9318 | if (type == bp_static_tracepoint) |
9319 | { | |
d9b3f62e | 9320 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9321 | struct static_tracepoint_marker marker; |
9322 | ||
983af33b | 9323 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9324 | { |
9325 | /* We already know the marker exists, otherwise, we | |
9326 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9327 | const char *p = &event_location_to_string (b->location)[3]; |
9328 | const char *endp; | |
0fb4aa4b | 9329 | char *marker_str; |
0fb4aa4b | 9330 | |
f00aae0f | 9331 | p = skip_spaces_const (p); |
0fb4aa4b | 9332 | |
f00aae0f | 9333 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9334 | |
9335 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9336 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9337 | |
3e43a32a MS |
9338 | printf_filtered (_("Probed static tracepoint " |
9339 | "marker \"%s\"\n"), | |
d9b3f62e | 9340 | t->static_trace_marker_id); |
0fb4aa4b PA |
9341 | } |
9342 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9343 | { | |
d9b3f62e | 9344 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9345 | release_static_tracepoint_marker (&marker); |
9346 | ||
3e43a32a MS |
9347 | printf_filtered (_("Probed static tracepoint " |
9348 | "marker \"%s\"\n"), | |
d9b3f62e | 9349 | t->static_trace_marker_id); |
0fb4aa4b PA |
9350 | } |
9351 | else | |
3e43a32a MS |
9352 | warning (_("Couldn't determine the static " |
9353 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9354 | } |
9355 | ||
0d381245 VP |
9356 | loc = b->loc; |
9357 | } | |
9358 | else | |
018d34a4 | 9359 | { |
39d61571 | 9360 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9361 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9362 | loc->inserted = 1; | |
0d381245 VP |
9363 | } |
9364 | ||
9365 | if (b->cond_string) | |
9366 | { | |
bbc13ae3 KS |
9367 | const char *arg = b->cond_string; |
9368 | ||
1bb9788d TT |
9369 | loc->cond = parse_exp_1 (&arg, loc->address, |
9370 | block_for_pc (loc->address), 0); | |
0d381245 | 9371 | if (*arg) |
588ae58c | 9372 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9373 | } |
e7e0cddf SS |
9374 | |
9375 | /* Dynamic printf requires and uses additional arguments on the | |
9376 | command line, otherwise it's an error. */ | |
9377 | if (type == bp_dprintf) | |
9378 | { | |
9379 | if (b->extra_string) | |
9380 | update_dprintf_command_list (b); | |
9381 | else | |
9382 | error (_("Format string required")); | |
9383 | } | |
9384 | else if (b->extra_string) | |
588ae58c | 9385 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9386 | } |
018d34a4 | 9387 | |
56435ebe | 9388 | b->display_canonical = display_canonical; |
f00aae0f KS |
9389 | if (location != NULL) |
9390 | b->location = location; | |
018d34a4 | 9391 | else |
305e13e6 JB |
9392 | { |
9393 | const char *addr_string = NULL; | |
9394 | int addr_string_len = 0; | |
9395 | ||
9396 | if (location != NULL) | |
9397 | addr_string = event_location_to_string (location); | |
9398 | if (addr_string != NULL) | |
9399 | addr_string_len = strlen (addr_string); | |
9400 | ||
9401 | b->location = new_address_location (b->loc->address, | |
9402 | addr_string, addr_string_len); | |
9403 | } | |
f8eba3c6 | 9404 | b->filter = filter; |
d9b3f62e | 9405 | } |
018d34a4 | 9406 | |
d9b3f62e PA |
9407 | static void |
9408 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f KS |
9409 | struct symtabs_and_lines sals, |
9410 | struct event_location *location, | |
f8eba3c6 | 9411 | char *filter, char *cond_string, |
e7e0cddf | 9412 | char *extra_string, |
d9b3f62e PA |
9413 | enum bptype type, enum bpdisp disposition, |
9414 | int thread, int task, int ignore_count, | |
c0a91b2b | 9415 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9416 | int enabled, int internal, unsigned flags, |
9417 | int display_canonical) | |
d9b3f62e PA |
9418 | { |
9419 | struct breakpoint *b; | |
9420 | struct cleanup *old_chain; | |
9421 | ||
9422 | if (is_tracepoint_type (type)) | |
9423 | { | |
9424 | struct tracepoint *t; | |
9425 | ||
4d01a485 | 9426 | t = new tracepoint (); |
d9b3f62e PA |
9427 | b = &t->base; |
9428 | } | |
9429 | else | |
4d01a485 | 9430 | b = new breakpoint (); |
d9b3f62e PA |
9431 | |
9432 | old_chain = make_cleanup (xfree, b); | |
9433 | ||
9434 | init_breakpoint_sal (b, gdbarch, | |
f00aae0f | 9435 | sals, location, |
e7e0cddf | 9436 | filter, cond_string, extra_string, |
d9b3f62e PA |
9437 | type, disposition, |
9438 | thread, task, ignore_count, | |
9439 | ops, from_tty, | |
44f238bb PA |
9440 | enabled, internal, flags, |
9441 | display_canonical); | |
d9b3f62e PA |
9442 | discard_cleanups (old_chain); |
9443 | ||
3ea46bff | 9444 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9445 | } |
9446 | ||
9447 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9448 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9449 | value. COND_STRING, if not NULL, specified the condition to be | |
9450 | used for all breakpoints. Essentially the only case where | |
9451 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9452 | function. In that case, it's still not possible to specify | |
9453 | separate conditions for different overloaded functions, so | |
9454 | we take just a single condition string. | |
9455 | ||
c3f6f71d | 9456 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9457 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9458 | array contents). If the function fails (error() is called), the |
9459 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9460 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9461 | |
9462 | static void | |
8cdf0e15 | 9463 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9464 | struct linespec_result *canonical, |
e7e0cddf | 9465 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9466 | enum bptype type, enum bpdisp disposition, |
9467 | int thread, int task, int ignore_count, | |
c0a91b2b | 9468 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9469 | int enabled, int internal, unsigned flags) |
c906108c | 9470 | { |
018d34a4 | 9471 | int i; |
f8eba3c6 | 9472 | struct linespec_sals *lsal; |
cc59ec59 | 9473 | |
f8eba3c6 TT |
9474 | if (canonical->pre_expanded) |
9475 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9476 | ||
9477 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9478 | { |
f00aae0f | 9479 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9480 | 'break', without arguments. */ |
f00aae0f KS |
9481 | struct event_location *location |
9482 | = (canonical->location != NULL | |
9483 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9484 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
f00aae0f | 9485 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
0d381245 | 9486 | |
f8eba3c6 TT |
9487 | make_cleanup (xfree, filter_string); |
9488 | create_breakpoint_sal (gdbarch, lsal->sals, | |
f00aae0f | 9489 | location, |
f8eba3c6 | 9490 | filter_string, |
e7e0cddf SS |
9491 | cond_string, extra_string, |
9492 | type, disposition, | |
84f4c1fe | 9493 | thread, task, ignore_count, ops, |
44f238bb | 9494 | from_tty, enabled, internal, flags, |
56435ebe | 9495 | canonical->special_display); |
f8eba3c6 | 9496 | discard_cleanups (inner); |
c3f6f71d | 9497 | } |
c3f6f71d | 9498 | } |
c906108c | 9499 | |
f00aae0f | 9500 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9501 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9502 | addresses found. LOCATION points to the end of the SAL (for |
9503 | linespec locations). | |
9998af43 TJB |
9504 | |
9505 | The array and the line spec strings are allocated on the heap, it is | |
9506 | the caller's responsibility to free them. */ | |
c906108c | 9507 | |
b9362cc7 | 9508 | static void |
f00aae0f | 9509 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9510 | struct linespec_result *canonical) |
c3f6f71d | 9511 | { |
f00aae0f KS |
9512 | struct symtab_and_line cursal; |
9513 | ||
9514 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9515 | { | |
9516 | const char *address = get_linespec_location (location); | |
9517 | ||
9518 | if (address == NULL) | |
9519 | { | |
9520 | /* The last displayed codepoint, if it's valid, is our default | |
9521 | breakpoint address. */ | |
9522 | if (last_displayed_sal_is_valid ()) | |
9523 | { | |
9524 | struct linespec_sals lsal; | |
9525 | struct symtab_and_line sal; | |
9526 | CORE_ADDR pc; | |
9527 | ||
9528 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9529 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9530 | |
9531 | /* Set sal's pspace, pc, symtab, and line to the values | |
9532 | corresponding to the last call to print_frame_info. | |
9533 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9534 | as the breakpoint line number is inappropriate otherwise. | |
9535 | find_pc_line would adjust PC, re-set it back. */ | |
9536 | get_last_displayed_sal (&sal); | |
9537 | pc = sal.pc; | |
9538 | sal = find_pc_line (pc, 0); | |
9539 | ||
9540 | /* "break" without arguments is equivalent to "break *PC" | |
9541 | where PC is the last displayed codepoint's address. So | |
9542 | make sure to set sal.explicit_pc to prevent GDB from | |
9543 | trying to expand the list of sals to include all other | |
9544 | instances with the same symtab and line. */ | |
9545 | sal.pc = pc; | |
9546 | sal.explicit_pc = 1; | |
9547 | ||
9548 | lsal.sals.sals[0] = sal; | |
9549 | lsal.sals.nelts = 1; | |
9550 | lsal.canonical = NULL; | |
9551 | ||
9552 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9553 | return; | |
9554 | } | |
9555 | else | |
9556 | error (_("No default breakpoint address now.")); | |
c906108c | 9557 | } |
c906108c | 9558 | } |
f00aae0f KS |
9559 | |
9560 | /* Force almost all breakpoints to be in terms of the | |
9561 | current_source_symtab (which is decode_line_1's default). | |
9562 | This should produce the results we want almost all of the | |
9563 | time while leaving default_breakpoint_* alone. | |
9564 | ||
9565 | ObjC: However, don't match an Objective-C method name which | |
9566 | may have a '+' or '-' succeeded by a '['. */ | |
9567 | cursal = get_current_source_symtab_and_line (); | |
9568 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9569 | { |
f00aae0f | 9570 | const char *address = NULL; |
cc80f267 | 9571 | |
f00aae0f KS |
9572 | if (event_location_type (location) == LINESPEC_LOCATION) |
9573 | address = get_linespec_location (location); | |
cc80f267 | 9574 | |
f00aae0f KS |
9575 | if (!cursal.symtab |
9576 | || (address != NULL | |
9577 | && strchr ("+-", address[0]) != NULL | |
9578 | && address[1] != '[')) | |
9579 | { | |
c2f4122d | 9580 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9581 | get_last_displayed_symtab (), |
9582 | get_last_displayed_line (), | |
9583 | canonical, NULL, NULL); | |
9584 | return; | |
9585 | } | |
c906108c | 9586 | } |
f00aae0f | 9587 | |
c2f4122d | 9588 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9589 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9590 | } |
c906108c | 9591 | |
c906108c | 9592 | |
c3f6f71d | 9593 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9594 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9595 | |
b9362cc7 | 9596 | static void |
23e7acfb | 9597 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9598 | { |
9599 | int i; | |
cc59ec59 | 9600 | |
c3f6f71d | 9601 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9602 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9603 | } |
9604 | ||
7a697b8d SS |
9605 | /* Fast tracepoints may have restrictions on valid locations. For |
9606 | instance, a fast tracepoint using a jump instead of a trap will | |
9607 | likely have to overwrite more bytes than a trap would, and so can | |
9608 | only be placed where the instruction is longer than the jump, or a | |
9609 | multi-instruction sequence does not have a jump into the middle of | |
9610 | it, etc. */ | |
9611 | ||
9612 | static void | |
9613 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9614 | struct symtabs_and_lines *sals) | |
9615 | { | |
9616 | int i, rslt; | |
9617 | struct symtab_and_line *sal; | |
9618 | char *msg; | |
9619 | struct cleanup *old_chain; | |
9620 | ||
9621 | for (i = 0; i < sals->nelts; i++) | |
9622 | { | |
f8eba3c6 TT |
9623 | struct gdbarch *sarch; |
9624 | ||
7a697b8d SS |
9625 | sal = &sals->sals[i]; |
9626 | ||
f8eba3c6 TT |
9627 | sarch = get_sal_arch (*sal); |
9628 | /* We fall back to GDBARCH if there is no architecture | |
9629 | associated with SAL. */ | |
9630 | if (sarch == NULL) | |
9631 | sarch = gdbarch; | |
6b940e6a | 9632 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9633 | old_chain = make_cleanup (xfree, msg); |
9634 | ||
9635 | if (!rslt) | |
53c3572a | 9636 | error (_("May not have a fast tracepoint at %s%s"), |
f8eba3c6 | 9637 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9638 | |
9639 | do_cleanups (old_chain); | |
9640 | } | |
9641 | } | |
9642 | ||
018d34a4 VP |
9643 | /* Given TOK, a string specification of condition and thread, as |
9644 | accepted by the 'break' command, extract the condition | |
9645 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9646 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9647 | If no condition is found, *COND_STRING is set to NULL. |
9648 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9649 | |
9650 | static void | |
bbc13ae3 | 9651 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9652 | char **cond_string, int *thread, int *task, |
9653 | char **rest) | |
018d34a4 VP |
9654 | { |
9655 | *cond_string = NULL; | |
9656 | *thread = -1; | |
ed1d1739 KS |
9657 | *task = 0; |
9658 | *rest = NULL; | |
9659 | ||
018d34a4 VP |
9660 | while (tok && *tok) |
9661 | { | |
bbc13ae3 | 9662 | const char *end_tok; |
018d34a4 | 9663 | int toklen; |
bbc13ae3 KS |
9664 | const char *cond_start = NULL; |
9665 | const char *cond_end = NULL; | |
cc59ec59 | 9666 | |
bbc13ae3 | 9667 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9668 | |
9669 | if ((*tok == '"' || *tok == ',') && rest) | |
9670 | { | |
9671 | *rest = savestring (tok, strlen (tok)); | |
9672 | return; | |
9673 | } | |
9674 | ||
bbc13ae3 | 9675 | end_tok = skip_to_space_const (tok); |
d634f2de | 9676 | |
018d34a4 | 9677 | toklen = end_tok - tok; |
d634f2de | 9678 | |
018d34a4 VP |
9679 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9680 | { | |
9681 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9682 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9683 | cond_end = tok; |
d634f2de | 9684 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9685 | } |
9686 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9687 | { | |
5d5658a1 PA |
9688 | const char *tmptok; |
9689 | struct thread_info *thr; | |
d634f2de | 9690 | |
018d34a4 | 9691 | tok = end_tok + 1; |
5d5658a1 | 9692 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9693 | if (tok == tmptok) |
9694 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9695 | *thread = thr->global_num; |
bbc13ae3 | 9696 | tok = tmptok; |
018d34a4 | 9697 | } |
4a306c9a JB |
9698 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9699 | { | |
9700 | char *tmptok; | |
9701 | ||
9702 | tok = end_tok + 1; | |
bbc13ae3 | 9703 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9704 | if (tok == tmptok) |
9705 | error (_("Junk after task keyword.")); | |
9706 | if (!valid_task_id (*task)) | |
b6199126 | 9707 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9708 | tok = tmptok; |
4a306c9a | 9709 | } |
e7e0cddf SS |
9710 | else if (rest) |
9711 | { | |
9712 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9713 | return; |
e7e0cddf | 9714 | } |
018d34a4 VP |
9715 | else |
9716 | error (_("Junk at end of arguments.")); | |
9717 | } | |
9718 | } | |
9719 | ||
0fb4aa4b PA |
9720 | /* Decode a static tracepoint marker spec. */ |
9721 | ||
9722 | static struct symtabs_and_lines | |
f00aae0f | 9723 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9724 | { |
9725 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9726 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9727 | struct cleanup *old_chain; |
f00aae0f KS |
9728 | const char *p = &(*arg_p)[3]; |
9729 | const char *endp; | |
0fb4aa4b PA |
9730 | char *marker_str; |
9731 | int i; | |
9732 | ||
f00aae0f | 9733 | p = skip_spaces_const (p); |
0fb4aa4b | 9734 | |
f00aae0f | 9735 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9736 | |
9737 | marker_str = savestring (p, endp - p); | |
9738 | old_chain = make_cleanup (xfree, marker_str); | |
9739 | ||
9740 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9741 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9742 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9743 | ||
9744 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9745 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9746 | |
9747 | for (i = 0; i < sals.nelts; i++) | |
9748 | { | |
9749 | struct static_tracepoint_marker *marker; | |
9750 | ||
9751 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9752 | ||
9753 | init_sal (&sals.sals[i]); | |
9754 | ||
9755 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9756 | sals.sals[i].pc = marker->address; | |
9757 | ||
9758 | release_static_tracepoint_marker (marker); | |
9759 | } | |
9760 | ||
9761 | do_cleanups (old_chain); | |
9762 | ||
9763 | *arg_p = endp; | |
9764 | return sals; | |
9765 | } | |
9766 | ||
f00aae0f | 9767 | /* See breakpoint.h. */ |
0101ce28 | 9768 | |
8cdf0e15 VP |
9769 | int |
9770 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9771 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9772 | int thread, char *extra_string, |
f00aae0f | 9773 | int parse_extra, |
0fb4aa4b | 9774 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9775 | int ignore_count, |
9776 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9777 | const struct breakpoint_ops *ops, |
44f238bb PA |
9778 | int from_tty, int enabled, int internal, |
9779 | unsigned flags) | |
c3f6f71d | 9780 | { |
7efd8fc2 | 9781 | struct linespec_result canonical; |
c3f6f71d | 9782 | struct cleanup *old_chain; |
80c99de1 | 9783 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9784 | int pending = 0; |
4a306c9a | 9785 | int task = 0; |
86b17b60 | 9786 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9787 | |
348d480f PA |
9788 | gdb_assert (ops != NULL); |
9789 | ||
f00aae0f KS |
9790 | /* If extra_string isn't useful, set it to NULL. */ |
9791 | if (extra_string != NULL && *extra_string == '\0') | |
9792 | extra_string = NULL; | |
9793 | ||
7efd8fc2 | 9794 | init_linespec_result (&canonical); |
c3f6f71d | 9795 | |
492d29ea | 9796 | TRY |
b78a6381 | 9797 | { |
f00aae0f | 9798 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9799 | } |
492d29ea | 9800 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9801 | { |
492d29ea PA |
9802 | /* If caller is interested in rc value from parse, set |
9803 | value. */ | |
9804 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9805 | { |
05ff989b AC |
9806 | /* If pending breakpoint support is turned off, throw |
9807 | error. */ | |
fa8d40ab JJ |
9808 | |
9809 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9810 | throw_exception (e); |
9811 | ||
9812 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9813 | |
05ff989b AC |
9814 | /* If pending breakpoint support is auto query and the user |
9815 | selects no, then simply return the error code. */ | |
059fb39f | 9816 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9817 | && !nquery (_("Make %s pending on future shared library load? "), |
9818 | bptype_string (type_wanted))) | |
fd9b8c24 | 9819 | return 0; |
fa8d40ab | 9820 | |
05ff989b AC |
9821 | /* At this point, either the user was queried about setting |
9822 | a pending breakpoint and selected yes, or pending | |
9823 | breakpoint behavior is on and thus a pending breakpoint | |
9824 | is defaulted on behalf of the user. */ | |
f00aae0f | 9825 | pending = 1; |
0101ce28 | 9826 | } |
492d29ea PA |
9827 | else |
9828 | throw_exception (e); | |
0101ce28 | 9829 | } |
492d29ea PA |
9830 | END_CATCH |
9831 | ||
f00aae0f | 9832 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9833 | return 0; |
c3f6f71d | 9834 | |
4a64f543 | 9835 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9836 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9837 | |
c3f6f71d JM |
9838 | /* ----------------------------- SNIP ----------------------------- |
9839 | Anything added to the cleanup chain beyond this point is assumed | |
9840 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9841 | then the memory is not reclaimed. */ |
9842 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9843 | |
c3f6f71d JM |
9844 | /* Resolve all line numbers to PC's and verify that the addresses |
9845 | are ok for the target. */ | |
0101ce28 | 9846 | if (!pending) |
f8eba3c6 TT |
9847 | { |
9848 | int ix; | |
9849 | struct linespec_sals *iter; | |
9850 | ||
9851 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9852 | breakpoint_sals_to_pc (&iter->sals); | |
9853 | } | |
c3f6f71d | 9854 | |
7a697b8d | 9855 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9856 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9857 | { |
9858 | int ix; | |
9859 | struct linespec_sals *iter; | |
9860 | ||
9861 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9862 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9863 | } | |
7a697b8d | 9864 | |
c3f6f71d JM |
9865 | /* Verify that condition can be parsed, before setting any |
9866 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9867 | breakpoint. */ |
0101ce28 | 9868 | if (!pending) |
c3f6f71d | 9869 | { |
f00aae0f | 9870 | if (parse_extra) |
72b2ff0e | 9871 | { |
0878d0fa | 9872 | char *rest; |
52d361e1 YQ |
9873 | struct linespec_sals *lsal; |
9874 | ||
9875 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9876 | ||
0878d0fa YQ |
9877 | /* Here we only parse 'arg' to separate condition |
9878 | from thread number, so parsing in context of first | |
9879 | sal is OK. When setting the breakpoint we'll | |
9880 | re-parse it in context of each sal. */ | |
9881 | ||
f00aae0f KS |
9882 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9883 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9884 | if (cond_string) |
9885 | make_cleanup (xfree, cond_string); | |
9886 | if (rest) | |
9887 | make_cleanup (xfree, rest); | |
9888 | if (rest) | |
9889 | extra_string = rest; | |
f00aae0f KS |
9890 | else |
9891 | extra_string = NULL; | |
72b2ff0e | 9892 | } |
2f069f6f | 9893 | else |
72b2ff0e | 9894 | { |
f00aae0f KS |
9895 | if (type_wanted != bp_dprintf |
9896 | && extra_string != NULL && *extra_string != '\0') | |
9897 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9898 | |
9899 | /* Create a private copy of condition string. */ | |
9900 | if (cond_string) | |
9901 | { | |
9902 | cond_string = xstrdup (cond_string); | |
9903 | make_cleanup (xfree, cond_string); | |
9904 | } | |
9905 | /* Create a private copy of any extra string. */ | |
9906 | if (extra_string) | |
9907 | { | |
9908 | extra_string = xstrdup (extra_string); | |
9909 | make_cleanup (xfree, extra_string); | |
9910 | } | |
72b2ff0e | 9911 | } |
0fb4aa4b | 9912 | |
52d361e1 | 9913 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9914 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9915 | tempflag ? disp_del : disp_donttouch, |
9916 | thread, task, ignore_count, ops, | |
44f238bb | 9917 | from_tty, enabled, internal, flags); |
c906108c | 9918 | } |
0101ce28 JJ |
9919 | else |
9920 | { | |
0101ce28 JJ |
9921 | struct breakpoint *b; |
9922 | ||
bfccc43c YQ |
9923 | if (is_tracepoint_type (type_wanted)) |
9924 | { | |
9925 | struct tracepoint *t; | |
9926 | ||
4d01a485 | 9927 | t = new tracepoint (); |
bfccc43c YQ |
9928 | b = &t->base; |
9929 | } | |
9930 | else | |
4d01a485 | 9931 | b = new breakpoint (); |
bfccc43c YQ |
9932 | |
9933 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
f00aae0f | 9934 | b->location = copy_event_location (location); |
bfccc43c | 9935 | |
f00aae0f KS |
9936 | if (parse_extra) |
9937 | b->cond_string = NULL; | |
e12c7713 MK |
9938 | else |
9939 | { | |
9940 | /* Create a private copy of condition string. */ | |
9941 | if (cond_string) | |
9942 | { | |
9943 | cond_string = xstrdup (cond_string); | |
9944 | make_cleanup (xfree, cond_string); | |
9945 | } | |
9946 | b->cond_string = cond_string; | |
15630549 | 9947 | b->thread = thread; |
e12c7713 | 9948 | } |
f00aae0f KS |
9949 | |
9950 | /* Create a private copy of any extra string. */ | |
9951 | if (extra_string != NULL) | |
9952 | { | |
9953 | extra_string = xstrdup (extra_string); | |
9954 | make_cleanup (xfree, extra_string); | |
9955 | } | |
9956 | b->extra_string = extra_string; | |
0101ce28 | 9957 | b->ignore_count = ignore_count; |
0101ce28 | 9958 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9959 | b->condition_not_parsed = 1; |
41447f92 | 9960 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9961 | if ((type_wanted != bp_breakpoint |
9962 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9963 | b->pspace = current_program_space; |
8bea4e01 | 9964 | |
bfccc43c | 9965 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9966 | } |
9967 | ||
f8eba3c6 | 9968 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9969 | { |
3e43a32a MS |
9970 | warning (_("Multiple breakpoints were set.\nUse the " |
9971 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9972 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9973 | } |
9974 | ||
80c99de1 PA |
9975 | /* That's it. Discard the cleanups for data inserted into the |
9976 | breakpoint. */ | |
9977 | discard_cleanups (bkpt_chain); | |
9978 | /* But cleanup everything else. */ | |
c3f6f71d | 9979 | do_cleanups (old_chain); |
217dc9e2 | 9980 | |
80c99de1 | 9981 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9982 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9983 | |
9984 | return 1; | |
c3f6f71d | 9985 | } |
c906108c | 9986 | |
348d480f | 9987 | /* Set a breakpoint. |
72b2ff0e VP |
9988 | ARG is a string describing breakpoint address, |
9989 | condition, and thread. | |
9990 | FLAG specifies if a breakpoint is hardware on, | |
9991 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9992 | and BP_TEMPFLAG. */ | |
348d480f | 9993 | |
98deb0da | 9994 | static void |
72b2ff0e | 9995 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9996 | { |
72b2ff0e | 9997 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9998 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9999 | ? bp_hardware_breakpoint | |
10000 | : bp_breakpoint); | |
55aa24fb | 10001 | struct breakpoint_ops *ops; |
f00aae0f KS |
10002 | struct event_location *location; |
10003 | struct cleanup *cleanup; | |
10004 | ||
10005 | location = string_to_event_location (&arg, current_language); | |
10006 | cleanup = make_cleanup_delete_event_location (location); | |
55aa24fb SDJ |
10007 | |
10008 | /* Matching breakpoints on probes. */ | |
5b56227b KS |
10009 | if (location != NULL |
10010 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
10011 | ops = &bkpt_probe_breakpoint_ops; |
10012 | else | |
10013 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 10014 | |
8cdf0e15 | 10015 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10016 | location, |
10017 | NULL, 0, arg, 1 /* parse arg */, | |
0fb4aa4b | 10018 | tempflag, type_wanted, |
8cdf0e15 VP |
10019 | 0 /* Ignore count */, |
10020 | pending_break_support, | |
55aa24fb | 10021 | ops, |
8cdf0e15 | 10022 | from_tty, |
84f4c1fe | 10023 | 1 /* enabled */, |
44f238bb PA |
10024 | 0 /* internal */, |
10025 | 0); | |
f00aae0f | 10026 | do_cleanups (cleanup); |
c906108c SS |
10027 | } |
10028 | ||
c906108c SS |
10029 | /* Helper function for break_command_1 and disassemble_command. */ |
10030 | ||
10031 | void | |
fba45db2 | 10032 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10033 | { |
10034 | CORE_ADDR pc; | |
10035 | ||
10036 | if (sal->pc == 0 && sal->symtab != NULL) | |
10037 | { | |
10038 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10039 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10040 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10041 | sal->pc = pc; |
6a048695 | 10042 | |
4a64f543 MS |
10043 | /* If this SAL corresponds to a breakpoint inserted using a line |
10044 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10045 | if (sal->explicit_line) |
059acae7 | 10046 | skip_prologue_sal (sal); |
c906108c SS |
10047 | } |
10048 | ||
10049 | if (sal->section == 0 && sal->symtab != NULL) | |
10050 | { | |
346d1dfe | 10051 | const struct blockvector *bv; |
3977b71f | 10052 | const struct block *b; |
c5aa993b | 10053 | struct symbol *sym; |
c906108c | 10054 | |
43f3e411 DE |
10055 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10056 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10057 | if (bv != NULL) |
10058 | { | |
7f0df278 | 10059 | sym = block_linkage_function (b); |
c906108c SS |
10060 | if (sym != NULL) |
10061 | { | |
eb822aa6 DE |
10062 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10063 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10064 | sym); | |
c906108c SS |
10065 | } |
10066 | else | |
10067 | { | |
4a64f543 MS |
10068 | /* It really is worthwhile to have the section, so we'll |
10069 | just have to look harder. This case can be executed | |
10070 | if we have line numbers but no functions (as can | |
10071 | happen in assembly source). */ | |
c906108c | 10072 | |
7cbd4a93 | 10073 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10074 | struct cleanup *old_chain = save_current_space_and_thread (); |
10075 | ||
10076 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10077 | |
10078 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10079 | if (msym.minsym) |
efd66ac6 | 10080 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10081 | |
10082 | do_cleanups (old_chain); | |
c906108c SS |
10083 | } |
10084 | } | |
10085 | } | |
10086 | } | |
10087 | ||
10088 | void | |
fba45db2 | 10089 | break_command (char *arg, int from_tty) |
c906108c | 10090 | { |
db107f19 | 10091 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10092 | } |
10093 | ||
c906108c | 10094 | void |
fba45db2 | 10095 | tbreak_command (char *arg, int from_tty) |
c906108c | 10096 | { |
db107f19 | 10097 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10098 | } |
10099 | ||
c906108c | 10100 | static void |
fba45db2 | 10101 | hbreak_command (char *arg, int from_tty) |
c906108c | 10102 | { |
db107f19 | 10103 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10104 | } |
10105 | ||
10106 | static void | |
fba45db2 | 10107 | thbreak_command (char *arg, int from_tty) |
c906108c | 10108 | { |
db107f19 | 10109 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10110 | } |
10111 | ||
10112 | static void | |
fba45db2 | 10113 | stop_command (char *arg, int from_tty) |
c906108c | 10114 | { |
a3f17187 | 10115 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10116 | Usage: stop in <function | address>\n\ |
a3f17187 | 10117 | stop at <line>\n")); |
c906108c SS |
10118 | } |
10119 | ||
10120 | static void | |
fba45db2 | 10121 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10122 | { |
10123 | int badInput = 0; | |
10124 | ||
c5aa993b | 10125 | if (arg == (char *) NULL) |
c906108c SS |
10126 | badInput = 1; |
10127 | else if (*arg != '*') | |
10128 | { | |
10129 | char *argptr = arg; | |
10130 | int hasColon = 0; | |
10131 | ||
4a64f543 | 10132 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10133 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10134 | function/method name. */ |
c906108c | 10135 | while (*argptr && !hasColon) |
c5aa993b JM |
10136 | { |
10137 | hasColon = (*argptr == ':'); | |
10138 | argptr++; | |
10139 | } | |
c906108c SS |
10140 | |
10141 | if (hasColon) | |
c5aa993b | 10142 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10143 | else |
c5aa993b | 10144 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10145 | } |
10146 | ||
10147 | if (badInput) | |
a3f17187 | 10148 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10149 | else |
db107f19 | 10150 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10151 | } |
10152 | ||
10153 | static void | |
fba45db2 | 10154 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10155 | { |
10156 | int badInput = 0; | |
10157 | ||
c5aa993b | 10158 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10159 | badInput = 1; |
10160 | else | |
10161 | { | |
10162 | char *argptr = arg; | |
10163 | int hasColon = 0; | |
10164 | ||
4a64f543 MS |
10165 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10166 | it is probably a line number. */ | |
c906108c | 10167 | while (*argptr && !hasColon) |
c5aa993b JM |
10168 | { |
10169 | hasColon = (*argptr == ':'); | |
10170 | argptr++; | |
10171 | } | |
c906108c SS |
10172 | |
10173 | if (hasColon) | |
c5aa993b | 10174 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10175 | else |
c5aa993b | 10176 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10177 | } |
10178 | ||
10179 | if (badInput) | |
a3f17187 | 10180 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10181 | else |
db107f19 | 10182 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10183 | } |
10184 | ||
e7e0cddf SS |
10185 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10186 | with a prewired command list consisting of a single output command, | |
10187 | built from extra arguments supplied on the dprintf command | |
10188 | line. */ | |
10189 | ||
da821c7b | 10190 | static void |
e7e0cddf SS |
10191 | dprintf_command (char *arg, int from_tty) |
10192 | { | |
f00aae0f KS |
10193 | struct event_location *location; |
10194 | struct cleanup *cleanup; | |
10195 | ||
10196 | location = string_to_event_location (&arg, current_language); | |
10197 | cleanup = make_cleanup_delete_event_location (location); | |
10198 | ||
10199 | /* If non-NULL, ARG should have been advanced past the location; | |
10200 | the next character must be ','. */ | |
10201 | if (arg != NULL) | |
10202 | { | |
10203 | if (arg[0] != ',' || arg[1] == '\0') | |
10204 | error (_("Format string required")); | |
10205 | else | |
10206 | { | |
10207 | /* Skip the comma. */ | |
10208 | ++arg; | |
10209 | } | |
10210 | } | |
10211 | ||
e7e0cddf | 10212 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10213 | location, |
10214 | NULL, 0, arg, 1 /* parse arg */, | |
e7e0cddf SS |
10215 | 0, bp_dprintf, |
10216 | 0 /* Ignore count */, | |
10217 | pending_break_support, | |
10218 | &dprintf_breakpoint_ops, | |
10219 | from_tty, | |
10220 | 1 /* enabled */, | |
10221 | 0 /* internal */, | |
10222 | 0); | |
f00aae0f | 10223 | do_cleanups (cleanup); |
e7e0cddf SS |
10224 | } |
10225 | ||
d3ce09f5 SS |
10226 | static void |
10227 | agent_printf_command (char *arg, int from_tty) | |
10228 | { | |
10229 | error (_("May only run agent-printf on the target")); | |
10230 | } | |
10231 | ||
f1310107 TJB |
10232 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10233 | ranged breakpoints. */ | |
10234 | ||
10235 | static int | |
10236 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10237 | struct address_space *aspace, | |
09ac7c10 TT |
10238 | CORE_ADDR bp_addr, |
10239 | const struct target_waitstatus *ws) | |
f1310107 | 10240 | { |
09ac7c10 | 10241 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10242 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10243 | return 0; |
10244 | ||
f1310107 TJB |
10245 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10246 | bl->length, aspace, bp_addr); | |
10247 | } | |
10248 | ||
10249 | /* Implement the "resources_needed" breakpoint_ops method for | |
10250 | ranged breakpoints. */ | |
10251 | ||
10252 | static int | |
10253 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10254 | { | |
10255 | return target_ranged_break_num_registers (); | |
10256 | } | |
10257 | ||
10258 | /* Implement the "print_it" breakpoint_ops method for | |
10259 | ranged breakpoints. */ | |
10260 | ||
10261 | static enum print_stop_action | |
348d480f | 10262 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10263 | { |
348d480f | 10264 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10265 | struct bp_location *bl = b->loc; |
79a45e25 | 10266 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10267 | |
10268 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10269 | ||
10270 | /* Ranged breakpoints have only one location. */ | |
10271 | gdb_assert (bl && bl->next == NULL); | |
10272 | ||
10273 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10274 | |
10275 | maybe_print_thread_hit_breakpoint (uiout); | |
10276 | ||
f1310107 | 10277 | if (b->disposition == disp_del) |
f303dbd6 | 10278 | ui_out_text (uiout, "Temporary ranged breakpoint "); |
f1310107 | 10279 | else |
f303dbd6 | 10280 | ui_out_text (uiout, "Ranged breakpoint "); |
f1310107 TJB |
10281 | if (ui_out_is_mi_like_p (uiout)) |
10282 | { | |
10283 | ui_out_field_string (uiout, "reason", | |
10284 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10285 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10286 | } | |
10287 | ui_out_field_int (uiout, "bkptno", b->number); | |
10288 | ui_out_text (uiout, ", "); | |
10289 | ||
10290 | return PRINT_SRC_AND_LOC; | |
10291 | } | |
10292 | ||
10293 | /* Implement the "print_one" breakpoint_ops method for | |
10294 | ranged breakpoints. */ | |
10295 | ||
10296 | static void | |
10297 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10298 | struct bp_location **last_loc) | |
10299 | { | |
10300 | struct bp_location *bl = b->loc; | |
10301 | struct value_print_options opts; | |
79a45e25 | 10302 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10303 | |
10304 | /* Ranged breakpoints have only one location. */ | |
10305 | gdb_assert (bl && bl->next == NULL); | |
10306 | ||
10307 | get_user_print_options (&opts); | |
10308 | ||
10309 | if (opts.addressprint) | |
10310 | /* We don't print the address range here, it will be printed later | |
10311 | by print_one_detail_ranged_breakpoint. */ | |
10312 | ui_out_field_skip (uiout, "addr"); | |
10313 | annotate_field (5); | |
10314 | print_breakpoint_location (b, bl); | |
10315 | *last_loc = bl; | |
10316 | } | |
10317 | ||
10318 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10319 | ranged breakpoints. */ | |
10320 | ||
10321 | static void | |
10322 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10323 | struct ui_out *uiout) | |
10324 | { | |
10325 | CORE_ADDR address_start, address_end; | |
10326 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10327 | struct ui_file *stb = mem_fileopen (); |
10328 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10329 | |
10330 | gdb_assert (bl); | |
10331 | ||
10332 | address_start = bl->address; | |
10333 | address_end = address_start + bl->length - 1; | |
10334 | ||
10335 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10336 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10337 | print_core_address (bl->gdbarch, address_start), |
10338 | print_core_address (bl->gdbarch, address_end)); | |
10339 | ui_out_field_stream (uiout, "addr", stb); | |
10340 | ui_out_text (uiout, "\n"); | |
10341 | ||
10342 | do_cleanups (cleanup); | |
10343 | } | |
10344 | ||
10345 | /* Implement the "print_mention" breakpoint_ops method for | |
10346 | ranged breakpoints. */ | |
10347 | ||
10348 | static void | |
10349 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10350 | { | |
10351 | struct bp_location *bl = b->loc; | |
79a45e25 | 10352 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10353 | |
10354 | gdb_assert (bl); | |
10355 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10356 | ||
10357 | if (ui_out_is_mi_like_p (uiout)) | |
10358 | return; | |
10359 | ||
10360 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10361 | b->number, paddress (bl->gdbarch, bl->address), | |
10362 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10363 | } | |
10364 | ||
10365 | /* Implement the "print_recreate" breakpoint_ops method for | |
10366 | ranged breakpoints. */ | |
10367 | ||
10368 | static void | |
10369 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10370 | { | |
f00aae0f KS |
10371 | fprintf_unfiltered (fp, "break-range %s, %s", |
10372 | event_location_to_string (b->location), | |
10373 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10374 | print_recreate_thread (b, fp); |
f1310107 TJB |
10375 | } |
10376 | ||
10377 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10378 | ||
2060206e | 10379 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10380 | |
10381 | /* Find the address where the end of the breakpoint range should be | |
10382 | placed, given the SAL of the end of the range. This is so that if | |
10383 | the user provides a line number, the end of the range is set to the | |
10384 | last instruction of the given line. */ | |
10385 | ||
10386 | static CORE_ADDR | |
10387 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10388 | { | |
10389 | CORE_ADDR end; | |
10390 | ||
10391 | /* If the user provided a PC value, use it. Otherwise, | |
10392 | find the address of the end of the given location. */ | |
10393 | if (sal.explicit_pc) | |
10394 | end = sal.pc; | |
10395 | else | |
10396 | { | |
10397 | int ret; | |
10398 | CORE_ADDR start; | |
10399 | ||
10400 | ret = find_line_pc_range (sal, &start, &end); | |
10401 | if (!ret) | |
10402 | error (_("Could not find location of the end of the range.")); | |
10403 | ||
10404 | /* find_line_pc_range returns the start of the next line. */ | |
10405 | end--; | |
10406 | } | |
10407 | ||
10408 | return end; | |
10409 | } | |
10410 | ||
10411 | /* Implement the "break-range" CLI command. */ | |
10412 | ||
10413 | static void | |
10414 | break_range_command (char *arg, int from_tty) | |
10415 | { | |
870f88f7 | 10416 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10417 | struct linespec_result canonical_start, canonical_end; |
10418 | int bp_count, can_use_bp, length; | |
10419 | CORE_ADDR end; | |
10420 | struct breakpoint *b; | |
10421 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10422 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10423 | struct linespec_sals *lsal_start, *lsal_end; |
f00aae0f | 10424 | struct event_location *start_location, *end_location; |
f1310107 TJB |
10425 | |
10426 | /* We don't support software ranged breakpoints. */ | |
10427 | if (target_ranged_break_num_registers () < 0) | |
10428 | error (_("This target does not support hardware ranged breakpoints.")); | |
10429 | ||
10430 | bp_count = hw_breakpoint_used_count (); | |
10431 | bp_count += target_ranged_break_num_registers (); | |
10432 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10433 | bp_count, 0); | |
10434 | if (can_use_bp < 0) | |
10435 | error (_("Hardware breakpoints used exceeds limit.")); | |
10436 | ||
f8eba3c6 | 10437 | arg = skip_spaces (arg); |
f1310107 TJB |
10438 | if (arg == NULL || arg[0] == '\0') |
10439 | error(_("No address range specified.")); | |
10440 | ||
f1310107 TJB |
10441 | init_linespec_result (&canonical_start); |
10442 | ||
f8eba3c6 | 10443 | arg_start = arg; |
f00aae0f KS |
10444 | start_location = string_to_event_location (&arg, current_language); |
10445 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); | |
10446 | parse_breakpoint_sals (start_location, &canonical_start); | |
10447 | make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10448 | |
10449 | if (arg[0] != ',') | |
10450 | error (_("Too few arguments.")); | |
f8eba3c6 | 10451 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10452 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10453 | |
10454 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10455 | ||
10456 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10457 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10458 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10459 | ||
f8eba3c6 TT |
10460 | sal_start = lsal_start->sals.sals[0]; |
10461 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10462 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10463 | |
10464 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10465 | arg = skip_spaces (arg); |
f1310107 TJB |
10466 | |
10467 | /* Parse the end location. */ | |
10468 | ||
f1310107 TJB |
10469 | init_linespec_result (&canonical_end); |
10470 | arg_start = arg; | |
10471 | ||
f8eba3c6 | 10472 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10473 | parse_breakpoint_sals because we need to specify the start location's |
10474 | symtab and line as the default symtab and line for the end of the | |
10475 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10476 | where +14 means 14 lines from the start location. */ | |
f00aae0f KS |
10477 | end_location = string_to_event_location (&arg, current_language); |
10478 | make_cleanup_delete_event_location (end_location); | |
c2f4122d | 10479 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f8eba3c6 TT |
10480 | sal_start.symtab, sal_start.line, |
10481 | &canonical_end, NULL, NULL); | |
10482 | ||
10483 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10484 | |
f8eba3c6 | 10485 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10486 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10487 | |
10488 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10489 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10490 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10491 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10492 | ||
f8eba3c6 | 10493 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10494 | |
10495 | end = find_breakpoint_range_end (sal_end); | |
10496 | if (sal_start.pc > end) | |
177b42fe | 10497 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10498 | |
10499 | length = end - sal_start.pc + 1; | |
10500 | if (length < 0) | |
10501 | /* Length overflowed. */ | |
10502 | error (_("Address range too large.")); | |
10503 | else if (length == 1) | |
10504 | { | |
10505 | /* This range is simple enough to be handled by | |
10506 | the `hbreak' command. */ | |
10507 | hbreak_command (addr_string_start, 1); | |
10508 | ||
10509 | do_cleanups (cleanup_bkpt); | |
10510 | ||
10511 | return; | |
10512 | } | |
10513 | ||
10514 | /* Now set up the breakpoint. */ | |
10515 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10516 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10517 | set_breakpoint_count (breakpoint_count + 1); |
10518 | b->number = breakpoint_count; | |
10519 | b->disposition = disp_donttouch; | |
f00aae0f KS |
10520 | b->location = copy_event_location (start_location); |
10521 | b->location_range_end = copy_event_location (end_location); | |
f1310107 TJB |
10522 | b->loc->length = length; |
10523 | ||
f8eba3c6 | 10524 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10525 | |
10526 | mention (b); | |
8d3788bd | 10527 | observer_notify_breakpoint_created (b); |
44702360 | 10528 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10529 | } |
10530 | ||
4a64f543 MS |
10531 | /* Return non-zero if EXP is verified as constant. Returned zero |
10532 | means EXP is variable. Also the constant detection may fail for | |
10533 | some constant expressions and in such case still falsely return | |
10534 | zero. */ | |
2e6e3d9c | 10535 | |
65d79d4b SDJ |
10536 | static int |
10537 | watchpoint_exp_is_const (const struct expression *exp) | |
10538 | { | |
10539 | int i = exp->nelts; | |
10540 | ||
10541 | while (i > 0) | |
10542 | { | |
10543 | int oplenp, argsp; | |
10544 | ||
10545 | /* We are only interested in the descriptor of each element. */ | |
10546 | operator_length (exp, i, &oplenp, &argsp); | |
10547 | i -= oplenp; | |
10548 | ||
10549 | switch (exp->elts[i].opcode) | |
10550 | { | |
10551 | case BINOP_ADD: | |
10552 | case BINOP_SUB: | |
10553 | case BINOP_MUL: | |
10554 | case BINOP_DIV: | |
10555 | case BINOP_REM: | |
10556 | case BINOP_MOD: | |
10557 | case BINOP_LSH: | |
10558 | case BINOP_RSH: | |
10559 | case BINOP_LOGICAL_AND: | |
10560 | case BINOP_LOGICAL_OR: | |
10561 | case BINOP_BITWISE_AND: | |
10562 | case BINOP_BITWISE_IOR: | |
10563 | case BINOP_BITWISE_XOR: | |
10564 | case BINOP_EQUAL: | |
10565 | case BINOP_NOTEQUAL: | |
10566 | case BINOP_LESS: | |
10567 | case BINOP_GTR: | |
10568 | case BINOP_LEQ: | |
10569 | case BINOP_GEQ: | |
10570 | case BINOP_REPEAT: | |
10571 | case BINOP_COMMA: | |
10572 | case BINOP_EXP: | |
10573 | case BINOP_MIN: | |
10574 | case BINOP_MAX: | |
10575 | case BINOP_INTDIV: | |
10576 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10577 | case TERNOP_COND: |
10578 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10579 | |
10580 | case OP_LONG: | |
10581 | case OP_DOUBLE: | |
10582 | case OP_DECFLOAT: | |
10583 | case OP_LAST: | |
10584 | case OP_COMPLEX: | |
10585 | case OP_STRING: | |
65d79d4b SDJ |
10586 | case OP_ARRAY: |
10587 | case OP_TYPE: | |
608b4967 TT |
10588 | case OP_TYPEOF: |
10589 | case OP_DECLTYPE: | |
6e72ca20 | 10590 | case OP_TYPEID: |
65d79d4b SDJ |
10591 | case OP_NAME: |
10592 | case OP_OBJC_NSSTRING: | |
10593 | ||
10594 | case UNOP_NEG: | |
10595 | case UNOP_LOGICAL_NOT: | |
10596 | case UNOP_COMPLEMENT: | |
10597 | case UNOP_ADDR: | |
10598 | case UNOP_HIGH: | |
aeaa2474 | 10599 | case UNOP_CAST: |
9eaf6705 TT |
10600 | |
10601 | case UNOP_CAST_TYPE: | |
10602 | case UNOP_REINTERPRET_CAST: | |
10603 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10604 | /* Unary, binary and ternary operators: We have to check |
10605 | their operands. If they are constant, then so is the | |
10606 | result of that operation. For instance, if A and B are | |
10607 | determined to be constants, then so is "A + B". | |
10608 | ||
10609 | UNOP_IND is one exception to the rule above, because the | |
10610 | value of *ADDR is not necessarily a constant, even when | |
10611 | ADDR is. */ | |
65d79d4b SDJ |
10612 | break; |
10613 | ||
10614 | case OP_VAR_VALUE: | |
10615 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10616 | |
65d79d4b | 10617 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10618 | possible that a buggy compiler could mark a variable as |
10619 | constant even when it is not, and TYPE_CONST would return | |
10620 | true in this case, while SYMBOL_CLASS wouldn't. | |
10621 | ||
10622 | We also have to check for function symbols because they | |
10623 | are always constant. */ | |
65d79d4b SDJ |
10624 | { |
10625 | struct symbol *s = exp->elts[i + 2].symbol; | |
10626 | ||
10627 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10628 | && SYMBOL_CLASS (s) != LOC_CONST | |
10629 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10630 | return 0; | |
10631 | break; | |
10632 | } | |
10633 | ||
10634 | /* The default action is to return 0 because we are using | |
10635 | the optimistic approach here: If we don't know something, | |
10636 | then it is not a constant. */ | |
10637 | default: | |
10638 | return 0; | |
10639 | } | |
10640 | } | |
10641 | ||
10642 | return 1; | |
10643 | } | |
10644 | ||
3a5c3e22 PA |
10645 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10646 | ||
10647 | static void | |
10648 | dtor_watchpoint (struct breakpoint *self) | |
10649 | { | |
10650 | struct watchpoint *w = (struct watchpoint *) self; | |
10651 | ||
3a5c3e22 PA |
10652 | xfree (w->exp_string); |
10653 | xfree (w->exp_string_reparse); | |
10654 | value_free (w->val); | |
10655 | ||
10656 | base_breakpoint_ops.dtor (self); | |
10657 | } | |
10658 | ||
348d480f PA |
10659 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10660 | ||
10661 | static void | |
10662 | re_set_watchpoint (struct breakpoint *b) | |
10663 | { | |
3a5c3e22 PA |
10664 | struct watchpoint *w = (struct watchpoint *) b; |
10665 | ||
348d480f PA |
10666 | /* Watchpoint can be either on expression using entirely global |
10667 | variables, or it can be on local variables. | |
10668 | ||
10669 | Watchpoints of the first kind are never auto-deleted, and even | |
10670 | persist across program restarts. Since they can use variables | |
10671 | from shared libraries, we need to reparse expression as libraries | |
10672 | are loaded and unloaded. | |
10673 | ||
10674 | Watchpoints on local variables can also change meaning as result | |
10675 | of solib event. For example, if a watchpoint uses both a local | |
10676 | and a global variables in expression, it's a local watchpoint, | |
10677 | but unloading of a shared library will make the expression | |
10678 | invalid. This is not a very common use case, but we still | |
10679 | re-evaluate expression, to avoid surprises to the user. | |
10680 | ||
10681 | Note that for local watchpoints, we re-evaluate it only if | |
10682 | watchpoints frame id is still valid. If it's not, it means the | |
10683 | watchpoint is out of scope and will be deleted soon. In fact, | |
10684 | I'm not sure we'll ever be called in this case. | |
10685 | ||
10686 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10687 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10688 | |
3a5c3e22 PA |
10689 | Don't do anything about disabled watchpoints, since they will be |
10690 | reevaluated again when enabled. */ | |
10691 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10692 | } |
10693 | ||
77b06cd7 TJB |
10694 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10695 | ||
10696 | static int | |
10697 | insert_watchpoint (struct bp_location *bl) | |
10698 | { | |
3a5c3e22 PA |
10699 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10700 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10701 | |
10702 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10703 | w->cond_exp.get ()); |
77b06cd7 TJB |
10704 | } |
10705 | ||
10706 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10707 | ||
10708 | static int | |
73971819 | 10709 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10710 | { |
3a5c3e22 PA |
10711 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10712 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10713 | |
10714 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10715 | w->cond_exp.get ()); |
e09342b5 TJB |
10716 | } |
10717 | ||
e09342b5 | 10718 | static int |
348d480f | 10719 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10720 | struct address_space *aspace, CORE_ADDR bp_addr, |
10721 | const struct target_waitstatus *ws) | |
e09342b5 | 10722 | { |
348d480f | 10723 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10724 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10725 | |
348d480f PA |
10726 | /* Continuable hardware watchpoints are treated as non-existent if the |
10727 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10728 | some data address). Otherwise gdb won't stop on a break instruction | |
10729 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10730 | been defined. Also skip watchpoints which we know did not trigger | |
10731 | (did not match the data address). */ | |
10732 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10733 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10734 | return 0; |
9c06b0b4 | 10735 | |
348d480f | 10736 | return 1; |
9c06b0b4 TJB |
10737 | } |
10738 | ||
348d480f PA |
10739 | static void |
10740 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10741 | { |
348d480f | 10742 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10743 | |
348d480f | 10744 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10745 | } |
10746 | ||
10747 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10748 | hardware watchpoints. */ |
9c06b0b4 TJB |
10749 | |
10750 | static int | |
348d480f | 10751 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10752 | { |
3a5c3e22 PA |
10753 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10754 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10755 | |
10756 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10757 | } |
10758 | ||
10759 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10760 | hardware watchpoints. */ |
9c06b0b4 TJB |
10761 | |
10762 | static int | |
348d480f | 10763 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10764 | { |
efa80663 PA |
10765 | /* Read and access watchpoints only work with hardware support. */ |
10766 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10767 | } |
10768 | ||
9c06b0b4 | 10769 | static enum print_stop_action |
348d480f | 10770 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10771 | { |
348d480f PA |
10772 | struct cleanup *old_chain; |
10773 | struct breakpoint *b; | |
f99d8bf4 | 10774 | struct ui_file *stb; |
348d480f | 10775 | enum print_stop_action result; |
3a5c3e22 | 10776 | struct watchpoint *w; |
79a45e25 | 10777 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10778 | |
10779 | gdb_assert (bs->bp_location_at != NULL); | |
10780 | ||
348d480f | 10781 | b = bs->breakpoint_at; |
3a5c3e22 | 10782 | w = (struct watchpoint *) b; |
348d480f | 10783 | |
f99d8bf4 PA |
10784 | stb = mem_fileopen (); |
10785 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 | 10786 | |
f303dbd6 PA |
10787 | annotate_watchpoint (b->number); |
10788 | maybe_print_thread_hit_breakpoint (uiout); | |
10789 | ||
9c06b0b4 TJB |
10790 | switch (b->type) |
10791 | { | |
348d480f | 10792 | case bp_watchpoint: |
9c06b0b4 | 10793 | case bp_hardware_watchpoint: |
9c06b0b4 TJB |
10794 | if (ui_out_is_mi_like_p (uiout)) |
10795 | ui_out_field_string | |
10796 | (uiout, "reason", | |
10797 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10798 | mention (b); |
10799 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10800 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10801 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10802 | ui_out_field_stream (uiout, "old", stb); |
10803 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10804 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10805 | ui_out_field_stream (uiout, "new", stb); |
10806 | ui_out_text (uiout, "\n"); | |
10807 | /* More than one watchpoint may have been triggered. */ | |
10808 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10809 | break; |
10810 | ||
10811 | case bp_read_watchpoint: | |
10812 | if (ui_out_is_mi_like_p (uiout)) | |
10813 | ui_out_field_string | |
10814 | (uiout, "reason", | |
10815 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10816 | mention (b); |
10817 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10818 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10819 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10820 | ui_out_field_stream (uiout, "value", stb); |
10821 | ui_out_text (uiout, "\n"); | |
10822 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10823 | break; |
10824 | ||
10825 | case bp_access_watchpoint: | |
348d480f PA |
10826 | if (bs->old_val != NULL) |
10827 | { | |
348d480f PA |
10828 | if (ui_out_is_mi_like_p (uiout)) |
10829 | ui_out_field_string | |
10830 | (uiout, "reason", | |
10831 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10832 | mention (b); | |
10833 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10834 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10835 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10836 | ui_out_field_stream (uiout, "old", stb); |
10837 | ui_out_text (uiout, "\nNew value = "); | |
10838 | } | |
10839 | else | |
10840 | { | |
10841 | mention (b); | |
10842 | if (ui_out_is_mi_like_p (uiout)) | |
10843 | ui_out_field_string | |
10844 | (uiout, "reason", | |
10845 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10846 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10847 | ui_out_text (uiout, "\nValue = "); | |
10848 | } | |
f99d8bf4 | 10849 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10850 | ui_out_field_stream (uiout, "new", stb); |
10851 | ui_out_text (uiout, "\n"); | |
10852 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10853 | break; |
10854 | default: | |
348d480f | 10855 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10856 | } |
10857 | ||
348d480f PA |
10858 | do_cleanups (old_chain); |
10859 | return result; | |
10860 | } | |
10861 | ||
10862 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10863 | watchpoints. */ | |
10864 | ||
10865 | static void | |
10866 | print_mention_watchpoint (struct breakpoint *b) | |
10867 | { | |
10868 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10869 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10870 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10871 | |
10872 | switch (b->type) | |
10873 | { | |
10874 | case bp_watchpoint: | |
10875 | ui_out_text (uiout, "Watchpoint "); | |
10876 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10877 | break; | |
10878 | case bp_hardware_watchpoint: | |
10879 | ui_out_text (uiout, "Hardware watchpoint "); | |
10880 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10881 | break; | |
10882 | case bp_read_watchpoint: | |
10883 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10884 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10885 | break; | |
10886 | case bp_access_watchpoint: | |
10887 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10888 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10889 | break; | |
10890 | default: | |
10891 | internal_error (__FILE__, __LINE__, | |
10892 | _("Invalid hardware watchpoint type.")); | |
10893 | } | |
10894 | ||
10895 | ui_out_field_int (uiout, "number", b->number); | |
10896 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10897 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10898 | do_cleanups (ui_out_chain); |
10899 | } | |
10900 | ||
10901 | /* Implement the "print_recreate" breakpoint_ops method for | |
10902 | watchpoints. */ | |
10903 | ||
10904 | static void | |
10905 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10906 | { | |
3a5c3e22 PA |
10907 | struct watchpoint *w = (struct watchpoint *) b; |
10908 | ||
348d480f PA |
10909 | switch (b->type) |
10910 | { | |
10911 | case bp_watchpoint: | |
10912 | case bp_hardware_watchpoint: | |
10913 | fprintf_unfiltered (fp, "watch"); | |
10914 | break; | |
10915 | case bp_read_watchpoint: | |
10916 | fprintf_unfiltered (fp, "rwatch"); | |
10917 | break; | |
10918 | case bp_access_watchpoint: | |
10919 | fprintf_unfiltered (fp, "awatch"); | |
10920 | break; | |
10921 | default: | |
10922 | internal_error (__FILE__, __LINE__, | |
10923 | _("Invalid watchpoint type.")); | |
10924 | } | |
10925 | ||
3a5c3e22 | 10926 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10927 | print_recreate_thread (b, fp); |
348d480f PA |
10928 | } |
10929 | ||
427cd150 TT |
10930 | /* Implement the "explains_signal" breakpoint_ops method for |
10931 | watchpoints. */ | |
10932 | ||
47591c29 | 10933 | static int |
427cd150 TT |
10934 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10935 | { | |
10936 | /* A software watchpoint cannot cause a signal other than | |
10937 | GDB_SIGNAL_TRAP. */ | |
10938 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10939 | return 0; |
427cd150 | 10940 | |
47591c29 | 10941 | return 1; |
427cd150 TT |
10942 | } |
10943 | ||
348d480f PA |
10944 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10945 | ||
2060206e | 10946 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10947 | |
10948 | /* Implement the "insert" breakpoint_ops method for | |
10949 | masked hardware watchpoints. */ | |
10950 | ||
10951 | static int | |
10952 | insert_masked_watchpoint (struct bp_location *bl) | |
10953 | { | |
3a5c3e22 PA |
10954 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10955 | ||
10956 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10957 | bl->watchpoint_type); |
10958 | } | |
10959 | ||
10960 | /* Implement the "remove" breakpoint_ops method for | |
10961 | masked hardware watchpoints. */ | |
10962 | ||
10963 | static int | |
73971819 | 10964 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10965 | { |
3a5c3e22 PA |
10966 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10967 | ||
10968 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10969 | bl->watchpoint_type); |
10970 | } | |
10971 | ||
10972 | /* Implement the "resources_needed" breakpoint_ops method for | |
10973 | masked hardware watchpoints. */ | |
10974 | ||
10975 | static int | |
10976 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10977 | { | |
3a5c3e22 PA |
10978 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10979 | ||
10980 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10981 | } |
10982 | ||
10983 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10984 | masked hardware watchpoints. */ | |
10985 | ||
10986 | static int | |
10987 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10988 | { | |
10989 | return 0; | |
10990 | } | |
10991 | ||
10992 | /* Implement the "print_it" breakpoint_ops method for | |
10993 | masked hardware watchpoints. */ | |
10994 | ||
10995 | static enum print_stop_action | |
10996 | print_it_masked_watchpoint (bpstat bs) | |
10997 | { | |
10998 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10999 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11000 | |
11001 | /* Masked watchpoints have only one location. */ | |
11002 | gdb_assert (b->loc && b->loc->next == NULL); | |
11003 | ||
f303dbd6 PA |
11004 | annotate_watchpoint (b->number); |
11005 | maybe_print_thread_hit_breakpoint (uiout); | |
11006 | ||
348d480f PA |
11007 | switch (b->type) |
11008 | { | |
11009 | case bp_hardware_watchpoint: | |
348d480f PA |
11010 | if (ui_out_is_mi_like_p (uiout)) |
11011 | ui_out_field_string | |
11012 | (uiout, "reason", | |
11013 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11014 | break; | |
11015 | ||
11016 | case bp_read_watchpoint: | |
11017 | if (ui_out_is_mi_like_p (uiout)) | |
11018 | ui_out_field_string | |
11019 | (uiout, "reason", | |
11020 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11021 | break; | |
11022 | ||
11023 | case bp_access_watchpoint: | |
11024 | if (ui_out_is_mi_like_p (uiout)) | |
11025 | ui_out_field_string | |
11026 | (uiout, "reason", | |
11027 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11028 | break; | |
11029 | default: | |
11030 | internal_error (__FILE__, __LINE__, | |
11031 | _("Invalid hardware watchpoint type.")); | |
11032 | } | |
11033 | ||
11034 | mention (b); | |
9c06b0b4 TJB |
11035 | ui_out_text (uiout, _("\n\ |
11036 | Check the underlying instruction at PC for the memory\n\ | |
11037 | address and value which triggered this watchpoint.\n")); | |
11038 | ui_out_text (uiout, "\n"); | |
11039 | ||
11040 | /* More than one watchpoint may have been triggered. */ | |
11041 | return PRINT_UNKNOWN; | |
11042 | } | |
11043 | ||
11044 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11045 | masked hardware watchpoints. */ | |
11046 | ||
11047 | static void | |
11048 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11049 | struct ui_out *uiout) | |
11050 | { | |
3a5c3e22 PA |
11051 | struct watchpoint *w = (struct watchpoint *) b; |
11052 | ||
9c06b0b4 TJB |
11053 | /* Masked watchpoints have only one location. */ |
11054 | gdb_assert (b->loc && b->loc->next == NULL); | |
11055 | ||
11056 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11057 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11058 | ui_out_text (uiout, "\n"); |
11059 | } | |
11060 | ||
11061 | /* Implement the "print_mention" breakpoint_ops method for | |
11062 | masked hardware watchpoints. */ | |
11063 | ||
11064 | static void | |
11065 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11066 | { | |
3a5c3e22 | 11067 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11068 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11069 | struct cleanup *ui_out_chain; |
11070 | ||
11071 | switch (b->type) | |
11072 | { | |
11073 | case bp_hardware_watchpoint: | |
11074 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11075 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11076 | break; | |
11077 | case bp_read_watchpoint: | |
11078 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11079 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11080 | break; | |
11081 | case bp_access_watchpoint: | |
11082 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11083 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11084 | break; | |
11085 | default: | |
11086 | internal_error (__FILE__, __LINE__, | |
11087 | _("Invalid hardware watchpoint type.")); | |
11088 | } | |
11089 | ||
11090 | ui_out_field_int (uiout, "number", b->number); | |
11091 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11092 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11093 | do_cleanups (ui_out_chain); |
11094 | } | |
11095 | ||
11096 | /* Implement the "print_recreate" breakpoint_ops method for | |
11097 | masked hardware watchpoints. */ | |
11098 | ||
11099 | static void | |
11100 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11101 | { | |
3a5c3e22 | 11102 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11103 | char tmp[40]; |
11104 | ||
11105 | switch (b->type) | |
11106 | { | |
11107 | case bp_hardware_watchpoint: | |
11108 | fprintf_unfiltered (fp, "watch"); | |
11109 | break; | |
11110 | case bp_read_watchpoint: | |
11111 | fprintf_unfiltered (fp, "rwatch"); | |
11112 | break; | |
11113 | case bp_access_watchpoint: | |
11114 | fprintf_unfiltered (fp, "awatch"); | |
11115 | break; | |
11116 | default: | |
11117 | internal_error (__FILE__, __LINE__, | |
11118 | _("Invalid hardware watchpoint type.")); | |
11119 | } | |
11120 | ||
3a5c3e22 PA |
11121 | sprintf_vma (tmp, w->hw_wp_mask); |
11122 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11123 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11124 | } |
11125 | ||
11126 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11127 | ||
2060206e | 11128 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11129 | |
11130 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11131 | ||
11132 | static int | |
11133 | is_masked_watchpoint (const struct breakpoint *b) | |
11134 | { | |
11135 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11136 | } | |
11137 | ||
53a5351d JM |
11138 | /* accessflag: hw_write: watch write, |
11139 | hw_read: watch read, | |
11140 | hw_access: watch access (read or write) */ | |
c906108c | 11141 | static void |
bbc13ae3 | 11142 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11143 | int just_location, int internal) |
c906108c | 11144 | { |
d983da9c | 11145 | struct breakpoint *b, *scope_breakpoint = NULL; |
270140bd | 11146 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11147 | struct value *val, *mark, *result; |
bb9d5f81 | 11148 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11149 | struct frame_info *frame; |
bbc13ae3 KS |
11150 | const char *exp_start = NULL; |
11151 | const char *exp_end = NULL; | |
11152 | const char *tok, *end_tok; | |
9c06b0b4 | 11153 | int toklen = -1; |
bbc13ae3 KS |
11154 | const char *cond_start = NULL; |
11155 | const char *cond_end = NULL; | |
c906108c | 11156 | enum bptype bp_type; |
37e4754d | 11157 | int thread = -1; |
0cf6dd15 | 11158 | int pc = 0; |
9c06b0b4 TJB |
11159 | /* Flag to indicate whether we are going to use masks for |
11160 | the hardware watchpoint. */ | |
11161 | int use_mask = 0; | |
11162 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11163 | struct watchpoint *w; |
bbc13ae3 KS |
11164 | char *expression; |
11165 | struct cleanup *back_to; | |
c906108c | 11166 | |
37e4754d LM |
11167 | /* Make sure that we actually have parameters to parse. */ |
11168 | if (arg != NULL && arg[0] != '\0') | |
11169 | { | |
bbc13ae3 KS |
11170 | const char *value_start; |
11171 | ||
11172 | exp_end = arg + strlen (arg); | |
37e4754d | 11173 | |
9c06b0b4 TJB |
11174 | /* Look for "parameter value" pairs at the end |
11175 | of the arguments string. */ | |
bbc13ae3 | 11176 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11177 | { |
11178 | /* Skip whitespace at the end of the argument list. */ | |
11179 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11180 | tok--; | |
11181 | ||
11182 | /* Find the beginning of the last token. | |
11183 | This is the value of the parameter. */ | |
11184 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11185 | tok--; | |
11186 | value_start = tok + 1; | |
11187 | ||
11188 | /* Skip whitespace. */ | |
11189 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11190 | tok--; | |
11191 | ||
11192 | end_tok = tok; | |
11193 | ||
11194 | /* Find the beginning of the second to last token. | |
11195 | This is the parameter itself. */ | |
11196 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11197 | tok--; | |
11198 | tok++; | |
11199 | toklen = end_tok - tok + 1; | |
11200 | ||
61012eef | 11201 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11202 | { |
5d5658a1 | 11203 | struct thread_info *thr; |
9c06b0b4 TJB |
11204 | /* At this point we've found a "thread" token, which means |
11205 | the user is trying to set a watchpoint that triggers | |
11206 | only in a specific thread. */ | |
5d5658a1 | 11207 | const char *endp; |
37e4754d | 11208 | |
9c06b0b4 TJB |
11209 | if (thread != -1) |
11210 | error(_("You can specify only one thread.")); | |
37e4754d | 11211 | |
9c06b0b4 | 11212 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11213 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11214 | |
5d5658a1 | 11215 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11216 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11217 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11218 | |
5d5658a1 | 11219 | thread = thr->global_num; |
9c06b0b4 | 11220 | } |
61012eef | 11221 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11222 | { |
11223 | /* We've found a "mask" token, which means the user wants to | |
11224 | create a hardware watchpoint that is going to have the mask | |
11225 | facility. */ | |
11226 | struct value *mask_value, *mark; | |
37e4754d | 11227 | |
9c06b0b4 TJB |
11228 | if (use_mask) |
11229 | error(_("You can specify only one mask.")); | |
37e4754d | 11230 | |
9c06b0b4 | 11231 | use_mask = just_location = 1; |
37e4754d | 11232 | |
9c06b0b4 TJB |
11233 | mark = value_mark (); |
11234 | mask_value = parse_to_comma_and_eval (&value_start); | |
11235 | mask = value_as_address (mask_value); | |
11236 | value_free_to_mark (mark); | |
11237 | } | |
11238 | else | |
11239 | /* We didn't recognize what we found. We should stop here. */ | |
11240 | break; | |
37e4754d | 11241 | |
9c06b0b4 TJB |
11242 | /* Truncate the string and get rid of the "parameter value" pair before |
11243 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11244 | exp_end = tok; |
9c06b0b4 | 11245 | } |
37e4754d | 11246 | } |
bbc13ae3 KS |
11247 | else |
11248 | exp_end = arg; | |
37e4754d | 11249 | |
bbc13ae3 KS |
11250 | /* Parse the rest of the arguments. From here on out, everything |
11251 | is in terms of a newly allocated string instead of the original | |
11252 | ARG. */ | |
c906108c | 11253 | innermost_block = NULL; |
bbc13ae3 KS |
11254 | expression = savestring (arg, exp_end - arg); |
11255 | back_to = make_cleanup (xfree, expression); | |
11256 | exp_start = arg = expression; | |
4d01a485 | 11257 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11258 | exp_end = arg; |
fa8a61dc TT |
11259 | /* Remove trailing whitespace from the expression before saving it. |
11260 | This makes the eventual display of the expression string a bit | |
11261 | prettier. */ | |
11262 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11263 | --exp_end; | |
11264 | ||
65d79d4b | 11265 | /* Checking if the expression is not constant. */ |
4d01a485 | 11266 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
11267 | { |
11268 | int len; | |
11269 | ||
11270 | len = exp_end - exp_start; | |
11271 | while (len > 0 && isspace (exp_start[len - 1])) | |
11272 | len--; | |
11273 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11274 | } | |
11275 | ||
c906108c SS |
11276 | exp_valid_block = innermost_block; |
11277 | mark = value_mark (); | |
4d01a485 | 11278 | fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location); |
06a64a0b | 11279 | |
bb9d5f81 PP |
11280 | if (val != NULL && just_location) |
11281 | { | |
11282 | saved_bitpos = value_bitpos (val); | |
11283 | saved_bitsize = value_bitsize (val); | |
11284 | } | |
11285 | ||
06a64a0b TT |
11286 | if (just_location) |
11287 | { | |
9c06b0b4 TJB |
11288 | int ret; |
11289 | ||
06a64a0b | 11290 | exp_valid_block = NULL; |
a1442452 | 11291 | val = value_addr (result); |
06a64a0b TT |
11292 | release_value (val); |
11293 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11294 | |
11295 | if (use_mask) | |
11296 | { | |
11297 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11298 | mask); | |
11299 | if (ret == -1) | |
11300 | error (_("This target does not support masked watchpoints.")); | |
11301 | else if (ret == -2) | |
11302 | error (_("Invalid mask or memory region.")); | |
11303 | } | |
06a64a0b TT |
11304 | } |
11305 | else if (val != NULL) | |
fa4727a6 | 11306 | release_value (val); |
c906108c | 11307 | |
bbc13ae3 KS |
11308 | tok = skip_spaces_const (arg); |
11309 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11310 | |
11311 | toklen = end_tok - tok; | |
11312 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11313 | { | |
60e1c644 | 11314 | innermost_block = NULL; |
c906108c | 11315 | tok = cond_start = end_tok + 1; |
4d01a485 | 11316 | parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11317 | |
11318 | /* The watchpoint expression may not be local, but the condition | |
11319 | may still be. E.g.: `watch global if local > 0'. */ | |
11320 | cond_exp_valid_block = innermost_block; | |
11321 | ||
c906108c SS |
11322 | cond_end = tok; |
11323 | } | |
11324 | if (*tok) | |
8a3fe4f8 | 11325 | error (_("Junk at end of command.")); |
c906108c | 11326 | |
d983da9c | 11327 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11328 | |
11329 | /* If the expression is "local", then set up a "watchpoint scope" | |
11330 | breakpoint at the point where we've left the scope of the watchpoint | |
11331 | expression. Create the scope breakpoint before the watchpoint, so | |
11332 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11333 | if (exp_valid_block && frame) |
d983da9c | 11334 | { |
edb3359d DJ |
11335 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11336 | { | |
11337 | scope_breakpoint | |
a6d9a66e UW |
11338 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11339 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11340 | bp_watchpoint_scope, |
11341 | &momentary_breakpoint_ops); | |
d983da9c | 11342 | |
edb3359d | 11343 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11344 | |
edb3359d DJ |
11345 | /* Automatically delete the breakpoint when it hits. */ |
11346 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11347 | |
edb3359d DJ |
11348 | /* Only break in the proper frame (help with recursion). */ |
11349 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11350 | |
edb3359d | 11351 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11352 | scope_breakpoint->loc->gdbarch |
11353 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11354 | scope_breakpoint->loc->requested_address |
11355 | = frame_unwind_caller_pc (frame); | |
11356 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11357 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11358 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11359 | scope_breakpoint->type); |
11360 | } | |
d983da9c DJ |
11361 | } |
11362 | ||
e8369a73 AB |
11363 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11364 | watchpoints here even if hardware watchpoints are turned off, a call | |
11365 | to update_watchpoint later in this function will cause the type to | |
11366 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11367 | ||
11368 | if (accessflag == hw_read) | |
11369 | bp_type = bp_read_watchpoint; | |
11370 | else if (accessflag == hw_access) | |
11371 | bp_type = bp_access_watchpoint; | |
11372 | else | |
11373 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 11374 | |
4d01a485 | 11375 | w = new watchpoint (); |
3a5c3e22 | 11376 | b = &w->base; |
348d480f | 11377 | if (use_mask) |
3a5c3e22 PA |
11378 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11379 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11380 | else |
3a5c3e22 PA |
11381 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11382 | &watchpoint_breakpoint_ops); | |
37e4754d | 11383 | b->thread = thread; |
b5de0fa7 | 11384 | b->disposition = disp_donttouch; |
348d480f | 11385 | b->pspace = current_program_space; |
4d01a485 | 11386 | w->exp = gdb::move (exp); |
3a5c3e22 PA |
11387 | w->exp_valid_block = exp_valid_block; |
11388 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11389 | if (just_location) |
11390 | { | |
11391 | struct type *t = value_type (val); | |
11392 | CORE_ADDR addr = value_as_address (val); | |
11393 | char *name; | |
11394 | ||
11395 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11396 | name = type_to_string (t); | |
11397 | ||
3a5c3e22 | 11398 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11399 | core_addr_to_string (addr)); |
06a64a0b TT |
11400 | xfree (name); |
11401 | ||
3a5c3e22 | 11402 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11403 | (int) (exp_end - exp_start), exp_start); |
11404 | ||
06a64a0b TT |
11405 | /* The above expression is in C. */ |
11406 | b->language = language_c; | |
11407 | } | |
11408 | else | |
3a5c3e22 | 11409 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11410 | |
11411 | if (use_mask) | |
11412 | { | |
3a5c3e22 | 11413 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11414 | } |
11415 | else | |
11416 | { | |
3a5c3e22 | 11417 | w->val = val; |
bb9d5f81 PP |
11418 | w->val_bitpos = saved_bitpos; |
11419 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11420 | w->val_valid = 1; |
9c06b0b4 | 11421 | } |
77b06cd7 | 11422 | |
c906108c SS |
11423 | if (cond_start) |
11424 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11425 | else | |
11426 | b->cond_string = 0; | |
c5aa993b | 11427 | |
c906108c | 11428 | if (frame) |
f6bc2008 | 11429 | { |
3a5c3e22 PA |
11430 | w->watchpoint_frame = get_frame_id (frame); |
11431 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11432 | } |
c906108c | 11433 | else |
f6bc2008 | 11434 | { |
3a5c3e22 PA |
11435 | w->watchpoint_frame = null_frame_id; |
11436 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11437 | } |
c906108c | 11438 | |
d983da9c | 11439 | if (scope_breakpoint != NULL) |
c906108c | 11440 | { |
d983da9c DJ |
11441 | /* The scope breakpoint is related to the watchpoint. We will |
11442 | need to act on them together. */ | |
11443 | b->related_breakpoint = scope_breakpoint; | |
11444 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11445 | } |
d983da9c | 11446 | |
06a64a0b TT |
11447 | if (!just_location) |
11448 | value_free_to_mark (mark); | |
2d134ed3 | 11449 | |
492d29ea | 11450 | TRY |
a9634178 TJB |
11451 | { |
11452 | /* Finally update the new watchpoint. This creates the locations | |
11453 | that should be inserted. */ | |
3a5c3e22 | 11454 | update_watchpoint (w, 1); |
a9634178 | 11455 | } |
492d29ea | 11456 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11457 | { |
11458 | delete_breakpoint (b); | |
11459 | throw_exception (e); | |
11460 | } | |
492d29ea | 11461 | END_CATCH |
a9634178 | 11462 | |
3ea46bff | 11463 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11464 | do_cleanups (back_to); |
c906108c SS |
11465 | } |
11466 | ||
e09342b5 | 11467 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11468 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11469 | |
c906108c | 11470 | static int |
a9634178 | 11471 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11472 | { |
11473 | int found_memory_cnt = 0; | |
2e70b7b9 | 11474 | struct value *head = v; |
c906108c SS |
11475 | |
11476 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11477 | if (!can_use_hw_watchpoints) |
c906108c | 11478 | return 0; |
c5aa993b | 11479 | |
5c44784c JM |
11480 | /* Make sure that the value of the expression depends only upon |
11481 | memory contents, and values computed from them within GDB. If we | |
11482 | find any register references or function calls, we can't use a | |
11483 | hardware watchpoint. | |
11484 | ||
11485 | The idea here is that evaluating an expression generates a series | |
11486 | of values, one holding the value of every subexpression. (The | |
11487 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11488 | a*b+c.) GDB's values hold almost enough information to establish | |
11489 | the criteria given above --- they identify memory lvalues, | |
11490 | register lvalues, computed values, etcetera. So we can evaluate | |
11491 | the expression, and then scan the chain of values that leaves | |
11492 | behind to decide whether we can detect any possible change to the | |
11493 | expression's final value using only hardware watchpoints. | |
11494 | ||
11495 | However, I don't think that the values returned by inferior | |
11496 | function calls are special in any way. So this function may not | |
11497 | notice that an expression involving an inferior function call | |
11498 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11499 | for (; v; v = value_next (v)) |
c906108c | 11500 | { |
5c44784c | 11501 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11502 | { |
8464be76 DJ |
11503 | if (v != head && value_lazy (v)) |
11504 | /* A lazy memory lvalue in the chain is one that GDB never | |
11505 | needed to fetch; we either just used its address (e.g., | |
11506 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11507 | in `a,b'). This doesn't apply to HEAD; if that is | |
11508 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11509 | ; |
53a5351d | 11510 | else |
5c44784c JM |
11511 | { |
11512 | /* Ahh, memory we actually used! Check if we can cover | |
11513 | it with hardware watchpoints. */ | |
df407dfe | 11514 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11515 | |
11516 | /* We only watch structs and arrays if user asked for it | |
11517 | explicitly, never if they just happen to appear in a | |
11518 | middle of some value chain. */ | |
11519 | if (v == head | |
11520 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11521 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11522 | { | |
42ae5230 | 11523 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11524 | int len; |
11525 | int num_regs; | |
11526 | ||
a9634178 | 11527 | len = (target_exact_watchpoints |
e09342b5 TJB |
11528 | && is_scalar_type_recursive (vtype))? |
11529 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11530 | |
e09342b5 TJB |
11531 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11532 | if (!num_regs) | |
2e70b7b9 MS |
11533 | return 0; |
11534 | else | |
e09342b5 | 11535 | found_memory_cnt += num_regs; |
2e70b7b9 | 11536 | } |
5c44784c | 11537 | } |
c5aa993b | 11538 | } |
5086187c AC |
11539 | else if (VALUE_LVAL (v) != not_lval |
11540 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11541 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11542 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11543 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11544 | } |
11545 | ||
11546 | /* The expression itself looks suitable for using a hardware | |
11547 | watchpoint, but give the target machine a chance to reject it. */ | |
11548 | return found_memory_cnt; | |
11549 | } | |
11550 | ||
8b93c638 | 11551 | void |
84f4c1fe | 11552 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11553 | { |
84f4c1fe | 11554 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11555 | } |
11556 | ||
06a64a0b TT |
11557 | /* A helper function that looks for the "-location" argument and then |
11558 | calls watch_command_1. */ | |
11559 | ||
11560 | static void | |
11561 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11562 | { | |
11563 | int just_location = 0; | |
11564 | ||
11565 | if (arg | |
11566 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11567 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11568 | { | |
e9cafbcc | 11569 | arg = skip_spaces (arg); |
06a64a0b TT |
11570 | just_location = 1; |
11571 | } | |
11572 | ||
84f4c1fe | 11573 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11574 | } |
8926118c | 11575 | |
c5aa993b | 11576 | static void |
fba45db2 | 11577 | watch_command (char *arg, int from_tty) |
c906108c | 11578 | { |
06a64a0b | 11579 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11580 | } |
11581 | ||
8b93c638 | 11582 | void |
84f4c1fe | 11583 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11584 | { |
84f4c1fe | 11585 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11586 | } |
8926118c | 11587 | |
c5aa993b | 11588 | static void |
fba45db2 | 11589 | rwatch_command (char *arg, int from_tty) |
c906108c | 11590 | { |
06a64a0b | 11591 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11592 | } |
11593 | ||
8b93c638 | 11594 | void |
84f4c1fe | 11595 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11596 | { |
84f4c1fe | 11597 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11598 | } |
8926118c | 11599 | |
c5aa993b | 11600 | static void |
fba45db2 | 11601 | awatch_command (char *arg, int from_tty) |
c906108c | 11602 | { |
06a64a0b | 11603 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11604 | } |
c906108c | 11605 | \f |
c5aa993b | 11606 | |
cfc31633 PA |
11607 | /* Data for the FSM that manages the until(location)/advance commands |
11608 | in infcmd.c. Here because it uses the mechanisms of | |
11609 | breakpoints. */ | |
c906108c | 11610 | |
cfc31633 | 11611 | struct until_break_fsm |
bfec99b2 | 11612 | { |
cfc31633 PA |
11613 | /* The base class. */ |
11614 | struct thread_fsm thread_fsm; | |
11615 | ||
11616 | /* The thread that as current when the command was executed. */ | |
11617 | int thread; | |
11618 | ||
11619 | /* The breakpoint set at the destination location. */ | |
11620 | struct breakpoint *location_breakpoint; | |
11621 | ||
11622 | /* Breakpoint set at the return address in the caller frame. May be | |
11623 | NULL. */ | |
11624 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11625 | }; |
11626 | ||
8980e177 PA |
11627 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11628 | struct thread_info *thread); | |
11629 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11630 | struct thread_info *thread); | |
cfc31633 PA |
11631 | static enum async_reply_reason |
11632 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11633 | ||
11634 | /* until_break_fsm's vtable. */ | |
11635 | ||
11636 | static struct thread_fsm_ops until_break_fsm_ops = | |
11637 | { | |
11638 | NULL, /* dtor */ | |
11639 | until_break_fsm_clean_up, | |
11640 | until_break_fsm_should_stop, | |
11641 | NULL, /* return_value */ | |
11642 | until_break_fsm_async_reply_reason, | |
11643 | }; | |
11644 | ||
11645 | /* Allocate a new until_break_command_fsm. */ | |
11646 | ||
11647 | static struct until_break_fsm * | |
8980e177 | 11648 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11649 | struct breakpoint *location_breakpoint, |
11650 | struct breakpoint *caller_breakpoint) | |
11651 | { | |
11652 | struct until_break_fsm *sm; | |
11653 | ||
11654 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11655 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11656 | |
11657 | sm->thread = thread; | |
11658 | sm->location_breakpoint = location_breakpoint; | |
11659 | sm->caller_breakpoint = caller_breakpoint; | |
11660 | ||
11661 | return sm; | |
11662 | } | |
11663 | ||
11664 | /* Implementation of the 'should_stop' FSM method for the | |
11665 | until(location)/advance commands. */ | |
11666 | ||
11667 | static int | |
8980e177 PA |
11668 | until_break_fsm_should_stop (struct thread_fsm *self, |
11669 | struct thread_info *tp) | |
cfc31633 PA |
11670 | { |
11671 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11672 | |
11673 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11674 | sm->location_breakpoint) != NULL | |
11675 | || (sm->caller_breakpoint != NULL | |
11676 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11677 | sm->caller_breakpoint) != NULL)) | |
11678 | thread_fsm_set_finished (self); | |
11679 | ||
11680 | return 1; | |
11681 | } | |
11682 | ||
11683 | /* Implementation of the 'clean_up' FSM method for the | |
11684 | until(location)/advance commands. */ | |
11685 | ||
c2c6d25f | 11686 | static void |
8980e177 PA |
11687 | until_break_fsm_clean_up (struct thread_fsm *self, |
11688 | struct thread_info *thread) | |
43ff13b4 | 11689 | { |
cfc31633 | 11690 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11691 | |
cfc31633 PA |
11692 | /* Clean up our temporary breakpoints. */ |
11693 | if (sm->location_breakpoint != NULL) | |
11694 | { | |
11695 | delete_breakpoint (sm->location_breakpoint); | |
11696 | sm->location_breakpoint = NULL; | |
11697 | } | |
11698 | if (sm->caller_breakpoint != NULL) | |
11699 | { | |
11700 | delete_breakpoint (sm->caller_breakpoint); | |
11701 | sm->caller_breakpoint = NULL; | |
11702 | } | |
11703 | delete_longjmp_breakpoint (sm->thread); | |
11704 | } | |
11705 | ||
11706 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11707 | until(location)/advance commands. */ | |
11708 | ||
11709 | static enum async_reply_reason | |
11710 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11711 | { | |
11712 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11713 | } |
11714 | ||
c906108c | 11715 | void |
ae66c1fc | 11716 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11717 | { |
11718 | struct symtabs_and_lines sals; | |
11719 | struct symtab_and_line sal; | |
8556afb4 PA |
11720 | struct frame_info *frame; |
11721 | struct gdbarch *frame_gdbarch; | |
11722 | struct frame_id stack_frame_id; | |
11723 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11724 | struct breakpoint *location_breakpoint; |
11725 | struct breakpoint *caller_breakpoint = NULL; | |
f00aae0f | 11726 | struct cleanup *old_chain, *cleanup; |
186c406b TT |
11727 | int thread; |
11728 | struct thread_info *tp; | |
f00aae0f | 11729 | struct event_location *location; |
cfc31633 | 11730 | struct until_break_fsm *sm; |
c906108c | 11731 | |
70509625 | 11732 | clear_proceed_status (0); |
c906108c SS |
11733 | |
11734 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11735 | this function. */ |
c5aa993b | 11736 | |
f00aae0f KS |
11737 | location = string_to_event_location (&arg, current_language); |
11738 | cleanup = make_cleanup_delete_event_location (location); | |
11739 | ||
1bfeeb0f | 11740 | if (last_displayed_sal_is_valid ()) |
c2f4122d | 11741 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11742 | get_last_displayed_symtab (), |
f8eba3c6 | 11743 | get_last_displayed_line ()); |
c906108c | 11744 | else |
f00aae0f | 11745 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11746 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11747 | |
c906108c | 11748 | if (sals.nelts != 1) |
8a3fe4f8 | 11749 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11750 | |
c906108c | 11751 | sal = sals.sals[0]; |
4a64f543 | 11752 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11753 | |
c906108c | 11754 | if (*arg) |
8a3fe4f8 | 11755 | error (_("Junk at end of arguments.")); |
c5aa993b | 11756 | |
c906108c | 11757 | resolve_sal_pc (&sal); |
c5aa993b | 11758 | |
186c406b | 11759 | tp = inferior_thread (); |
5d5658a1 | 11760 | thread = tp->global_num; |
186c406b | 11761 | |
883bc8d1 PA |
11762 | old_chain = make_cleanup (null_cleanup, NULL); |
11763 | ||
8556afb4 PA |
11764 | /* Note linespec handling above invalidates the frame chain. |
11765 | Installing a breakpoint also invalidates the frame chain (as it | |
11766 | may need to switch threads), so do any frame handling before | |
11767 | that. */ | |
11768 | ||
11769 | frame = get_selected_frame (NULL); | |
11770 | frame_gdbarch = get_frame_arch (frame); | |
11771 | stack_frame_id = get_stack_frame_id (frame); | |
11772 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11773 | |
ae66c1fc EZ |
11774 | /* Keep within the current frame, or in frames called by the current |
11775 | one. */ | |
edb3359d | 11776 | |
883bc8d1 | 11777 | if (frame_id_p (caller_frame_id)) |
c906108c | 11778 | { |
883bc8d1 | 11779 | struct symtab_and_line sal2; |
cfc31633 | 11780 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11781 | |
11782 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11783 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11784 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11785 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11786 | sal2, | |
11787 | caller_frame_id, | |
11788 | bp_until); | |
11789 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11790 | |
883bc8d1 | 11791 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11792 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11793 | } |
c5aa993b | 11794 | |
c70a6932 JK |
11795 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11796 | frame = NULL; | |
11797 | ||
883bc8d1 PA |
11798 | if (anywhere) |
11799 | /* If the user told us to continue until a specified location, | |
11800 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11801 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11802 | null_frame_id, bp_until); | |
883bc8d1 PA |
11803 | else |
11804 | /* Otherwise, specify the selected frame, because we want to stop | |
11805 | only at the very same frame. */ | |
cfc31633 PA |
11806 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11807 | stack_frame_id, bp_until); | |
11808 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11809 | |
8980e177 | 11810 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11811 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11812 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11813 | |
cfc31633 | 11814 | discard_cleanups (old_chain); |
f107f563 | 11815 | |
cfc31633 | 11816 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f00aae0f KS |
11817 | |
11818 | do_cleanups (cleanup); | |
c906108c | 11819 | } |
ae66c1fc | 11820 | |
c906108c SS |
11821 | /* This function attempts to parse an optional "if <cond>" clause |
11822 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11823 | |
c906108c SS |
11824 | Else, it returns a pointer to the condition string. (It does not |
11825 | attempt to evaluate the string against a particular block.) And, | |
11826 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11827 | if clause in the arg string. */ |
53a5351d | 11828 | |
916703c0 | 11829 | char * |
fba45db2 | 11830 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11831 | { |
c5aa993b JM |
11832 | char *cond_string; |
11833 | ||
11834 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11835 | return NULL; |
c5aa993b | 11836 | |
4a64f543 | 11837 | /* Skip the "if" keyword. */ |
c906108c | 11838 | (*arg) += 2; |
c5aa993b | 11839 | |
c906108c | 11840 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11841 | condition string. */ |
e9cafbcc | 11842 | *arg = skip_spaces (*arg); |
c906108c | 11843 | cond_string = *arg; |
c5aa993b | 11844 | |
4a64f543 MS |
11845 | /* Assume that the condition occupies the remainder of the arg |
11846 | string. */ | |
c906108c | 11847 | (*arg) += strlen (cond_string); |
c5aa993b | 11848 | |
c906108c SS |
11849 | return cond_string; |
11850 | } | |
c5aa993b | 11851 | |
c906108c SS |
11852 | /* Commands to deal with catching events, such as signals, exceptions, |
11853 | process start/exit, etc. */ | |
c5aa993b JM |
11854 | |
11855 | typedef enum | |
11856 | { | |
44feb3ce TT |
11857 | catch_fork_temporary, catch_vfork_temporary, |
11858 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11859 | } |
11860 | catch_fork_kind; | |
11861 | ||
c906108c | 11862 | static void |
cc59ec59 MS |
11863 | catch_fork_command_1 (char *arg, int from_tty, |
11864 | struct cmd_list_element *command) | |
c906108c | 11865 | { |
a6d9a66e | 11866 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11867 | char *cond_string = NULL; |
44feb3ce TT |
11868 | catch_fork_kind fork_kind; |
11869 | int tempflag; | |
11870 | ||
11871 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11872 | tempflag = (fork_kind == catch_fork_temporary | |
11873 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11874 | |
44feb3ce TT |
11875 | if (!arg) |
11876 | arg = ""; | |
e9cafbcc | 11877 | arg = skip_spaces (arg); |
c5aa993b | 11878 | |
c906108c | 11879 | /* The allowed syntax is: |
c5aa993b JM |
11880 | catch [v]fork |
11881 | catch [v]fork if <cond> | |
11882 | ||
4a64f543 | 11883 | First, check if there's an if clause. */ |
c906108c | 11884 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11885 | |
c906108c | 11886 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11887 | error (_("Junk at end of arguments.")); |
c5aa993b | 11888 | |
c906108c | 11889 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11890 | and enable reporting of such events. */ |
c5aa993b JM |
11891 | switch (fork_kind) |
11892 | { | |
44feb3ce TT |
11893 | case catch_fork_temporary: |
11894 | case catch_fork_permanent: | |
a6d9a66e | 11895 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11896 | &catch_fork_breakpoint_ops); |
c906108c | 11897 | break; |
44feb3ce TT |
11898 | case catch_vfork_temporary: |
11899 | case catch_vfork_permanent: | |
a6d9a66e | 11900 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11901 | &catch_vfork_breakpoint_ops); |
c906108c | 11902 | break; |
c5aa993b | 11903 | default: |
8a3fe4f8 | 11904 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11905 | break; |
c5aa993b | 11906 | } |
c906108c SS |
11907 | } |
11908 | ||
11909 | static void | |
cc59ec59 MS |
11910 | catch_exec_command_1 (char *arg, int from_tty, |
11911 | struct cmd_list_element *command) | |
c906108c | 11912 | { |
b4d90040 | 11913 | struct exec_catchpoint *c; |
a6d9a66e | 11914 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11915 | int tempflag; |
c5aa993b | 11916 | char *cond_string = NULL; |
c906108c | 11917 | |
44feb3ce TT |
11918 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11919 | ||
11920 | if (!arg) | |
11921 | arg = ""; | |
e9cafbcc | 11922 | arg = skip_spaces (arg); |
c906108c SS |
11923 | |
11924 | /* The allowed syntax is: | |
c5aa993b JM |
11925 | catch exec |
11926 | catch exec if <cond> | |
c906108c | 11927 | |
4a64f543 | 11928 | First, check if there's an if clause. */ |
c906108c SS |
11929 | cond_string = ep_parse_optional_if_clause (&arg); |
11930 | ||
11931 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11932 | error (_("Junk at end of arguments.")); |
c906108c | 11933 | |
4d01a485 | 11934 | c = new exec_catchpoint (); |
b4d90040 PA |
11935 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, |
11936 | &catch_exec_breakpoint_ops); | |
11937 | c->exec_pathname = NULL; | |
11938 | ||
3ea46bff | 11939 | install_breakpoint (0, &c->base, 1); |
c906108c | 11940 | } |
c5aa993b | 11941 | |
9ac4176b | 11942 | void |
28010a5d PA |
11943 | init_ada_exception_breakpoint (struct breakpoint *b, |
11944 | struct gdbarch *gdbarch, | |
11945 | struct symtab_and_line sal, | |
11946 | char *addr_string, | |
c0a91b2b | 11947 | const struct breakpoint_ops *ops, |
28010a5d | 11948 | int tempflag, |
349774ef | 11949 | int enabled, |
28010a5d | 11950 | int from_tty) |
f7f9143b | 11951 | { |
f7f9143b JB |
11952 | if (from_tty) |
11953 | { | |
5af949e3 UW |
11954 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11955 | if (!loc_gdbarch) | |
11956 | loc_gdbarch = gdbarch; | |
11957 | ||
6c95b8df PA |
11958 | describe_other_breakpoints (loc_gdbarch, |
11959 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11960 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11961 | version for exception catchpoints, because two catchpoints | |
11962 | used for different exception names will use the same address. | |
11963 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11964 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11965 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11966 | the user what type of catchpoint it is. The above is good |
11967 | enough for now, though. */ | |
11968 | } | |
11969 | ||
28010a5d | 11970 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11971 | |
349774ef | 11972 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11973 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f00aae0f KS |
11974 | b->location = string_to_event_location (&addr_string, |
11975 | language_def (language_ada)); | |
f7f9143b | 11976 | b->language = language_ada; |
f7f9143b JB |
11977 | } |
11978 | ||
c906108c | 11979 | static void |
fba45db2 | 11980 | catch_command (char *arg, int from_tty) |
c906108c | 11981 | { |
44feb3ce | 11982 | error (_("Catch requires an event name.")); |
c906108c SS |
11983 | } |
11984 | \f | |
11985 | ||
11986 | static void | |
fba45db2 | 11987 | tcatch_command (char *arg, int from_tty) |
c906108c | 11988 | { |
44feb3ce | 11989 | error (_("Catch requires an event name.")); |
c906108c SS |
11990 | } |
11991 | ||
8a2c437b TT |
11992 | /* A qsort comparison function that sorts breakpoints in order. */ |
11993 | ||
11994 | static int | |
11995 | compare_breakpoints (const void *a, const void *b) | |
11996 | { | |
9a3c8263 | 11997 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11998 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11999 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
12000 | uintptr_t ub = (uintptr_t) *bb; |
12001 | ||
12002 | if ((*ba)->number < (*bb)->number) | |
12003 | return -1; | |
12004 | else if ((*ba)->number > (*bb)->number) | |
12005 | return 1; | |
12006 | ||
12007 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
12008 | the number 0. */ | |
12009 | if (ua < ub) | |
12010 | return -1; | |
94b0e70d | 12011 | return ua > ub ? 1 : 0; |
8a2c437b TT |
12012 | } |
12013 | ||
80f8a6eb | 12014 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12015 | |
12016 | static void | |
fba45db2 | 12017 | clear_command (char *arg, int from_tty) |
c906108c | 12018 | { |
8a2c437b | 12019 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12020 | VEC(breakpoint_p) *found = 0; |
12021 | int ix; | |
c906108c SS |
12022 | int default_match; |
12023 | struct symtabs_and_lines sals; | |
12024 | struct symtab_and_line sal; | |
c906108c | 12025 | int i; |
8a2c437b | 12026 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12027 | |
12028 | if (arg) | |
12029 | { | |
39cf75f7 DE |
12030 | sals = decode_line_with_current_source (arg, |
12031 | (DECODE_LINE_FUNFIRSTLINE | |
12032 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12033 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12034 | default_match = 0; |
12035 | } | |
12036 | else | |
12037 | { | |
8d749320 | 12038 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 12039 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12040 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12041 | |
12042 | /* Set sal's line, symtab, pc, and pspace to the values | |
12043 | corresponding to the last call to print_frame_info. If the | |
12044 | codepoint is not valid, this will set all the fields to 0. */ | |
12045 | get_last_displayed_sal (&sal); | |
c906108c | 12046 | if (sal.symtab == 0) |
8a3fe4f8 | 12047 | error (_("No source file specified.")); |
c906108c SS |
12048 | |
12049 | sals.sals[0] = sal; | |
12050 | sals.nelts = 1; | |
12051 | ||
12052 | default_match = 1; | |
12053 | } | |
12054 | ||
4a64f543 MS |
12055 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12056 | seems, because all existing breakpoints typically have both | |
12057 | file/line and pc set. So, if clear is given file/line, we can | |
12058 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12059 | |
12060 | We only support clearing given the address explicitly | |
12061 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12062 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12063 | due to optimization, all in one block. |
4a64f543 MS |
12064 | |
12065 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12066 | PC corresponding to the same file:line, the breakpoint won't |
12067 | be cleared. We probably can still clear the breakpoint, but | |
12068 | since the other PC value is never presented to user, user | |
12069 | can only find it by guessing, and it does not seem important | |
12070 | to support that. */ | |
12071 | ||
4a64f543 MS |
12072 | /* For each line spec given, delete bps which correspond to it. Do |
12073 | it in two passes, solely to preserve the current behavior that | |
12074 | from_tty is forced true if we delete more than one | |
12075 | breakpoint. */ | |
c906108c | 12076 | |
80f8a6eb | 12077 | found = NULL; |
8a2c437b | 12078 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12079 | for (i = 0; i < sals.nelts; i++) |
12080 | { | |
05cba821 JK |
12081 | const char *sal_fullname; |
12082 | ||
c906108c | 12083 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12084 | If line given (pc == 0), clear all bpts on specified line. |
12085 | If defaulting, clear all bpts on default line | |
c906108c | 12086 | or at default pc. |
c5aa993b JM |
12087 | |
12088 | defaulting sal.pc != 0 tests to do | |
12089 | ||
12090 | 0 1 pc | |
12091 | 1 1 pc _and_ line | |
12092 | 0 0 line | |
12093 | 1 0 <can't happen> */ | |
c906108c SS |
12094 | |
12095 | sal = sals.sals[i]; | |
05cba821 JK |
12096 | sal_fullname = (sal.symtab == NULL |
12097 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12098 | |
4a64f543 | 12099 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12100 | ALL_BREAKPOINTS (b) |
c5aa993b | 12101 | { |
0d381245 | 12102 | int match = 0; |
4a64f543 | 12103 | /* Are we going to delete b? */ |
cc60f2e3 | 12104 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12105 | { |
12106 | struct bp_location *loc = b->loc; | |
12107 | for (; loc; loc = loc->next) | |
12108 | { | |
f8eba3c6 TT |
12109 | /* If the user specified file:line, don't allow a PC |
12110 | match. This matches historical gdb behavior. */ | |
12111 | int pc_match = (!sal.explicit_line | |
12112 | && sal.pc | |
12113 | && (loc->pspace == sal.pspace) | |
12114 | && (loc->address == sal.pc) | |
12115 | && (!section_is_overlay (loc->section) | |
12116 | || loc->section == sal.section)); | |
4aac40c8 TT |
12117 | int line_match = 0; |
12118 | ||
12119 | if ((default_match || sal.explicit_line) | |
2f202fde | 12120 | && loc->symtab != NULL |
05cba821 | 12121 | && sal_fullname != NULL |
4aac40c8 | 12122 | && sal.pspace == loc->pspace |
05cba821 JK |
12123 | && loc->line_number == sal.line |
12124 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12125 | sal_fullname) == 0) | |
12126 | line_match = 1; | |
4aac40c8 | 12127 | |
0d381245 VP |
12128 | if (pc_match || line_match) |
12129 | { | |
12130 | match = 1; | |
12131 | break; | |
12132 | } | |
12133 | } | |
12134 | } | |
12135 | ||
12136 | if (match) | |
d6e956e5 | 12137 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12138 | } |
80f8a6eb | 12139 | } |
8a2c437b | 12140 | |
80f8a6eb | 12141 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12142 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12143 | { |
12144 | if (arg) | |
8a3fe4f8 | 12145 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12146 | else |
8a3fe4f8 | 12147 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12148 | } |
c906108c | 12149 | |
8a2c437b TT |
12150 | /* Remove duplicates from the vec. */ |
12151 | qsort (VEC_address (breakpoint_p, found), | |
12152 | VEC_length (breakpoint_p, found), | |
12153 | sizeof (breakpoint_p), | |
12154 | compare_breakpoints); | |
12155 | prev = VEC_index (breakpoint_p, found, 0); | |
12156 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12157 | { | |
12158 | if (b == prev) | |
12159 | { | |
12160 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12161 | --ix; | |
12162 | } | |
12163 | } | |
12164 | ||
d6e956e5 | 12165 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12166 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12167 | if (from_tty) |
a3f17187 | 12168 | { |
d6e956e5 | 12169 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12170 | printf_unfiltered (_("Deleted breakpoint ")); |
12171 | else | |
12172 | printf_unfiltered (_("Deleted breakpoints ")); | |
12173 | } | |
d6e956e5 VP |
12174 | |
12175 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12176 | { |
c5aa993b | 12177 | if (from_tty) |
d6e956e5 VP |
12178 | printf_unfiltered ("%d ", b->number); |
12179 | delete_breakpoint (b); | |
c906108c | 12180 | } |
80f8a6eb MS |
12181 | if (from_tty) |
12182 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12183 | |
12184 | do_cleanups (cleanups); | |
c906108c SS |
12185 | } |
12186 | \f | |
12187 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12188 | all breakpoints that are marked for deletion, whether hit or not. | |
12189 | This is called after any breakpoint is hit, or after errors. */ | |
12190 | ||
12191 | void | |
fba45db2 | 12192 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12193 | { |
35df4500 | 12194 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12195 | |
12196 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12197 | if (bs->breakpoint_at |
12198 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12199 | && bs->stop) |
f431efe5 | 12200 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12201 | |
35df4500 | 12202 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12203 | { |
b5de0fa7 | 12204 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12205 | delete_breakpoint (b); |
12206 | } | |
c906108c SS |
12207 | } |
12208 | ||
4a64f543 MS |
12209 | /* A comparison function for bp_location AP and BP being interfaced to |
12210 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12211 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12212 | secondarily by ordering first permanent elements and |
4a64f543 | 12213 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12214 | qsort being an unstable algorithm. */ |
876fa593 JK |
12215 | |
12216 | static int | |
494cfb0f | 12217 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12218 | { |
9a3c8263 SM |
12219 | const struct bp_location *a = *(const struct bp_location **) ap; |
12220 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12221 | |
12222 | if (a->address != b->address) | |
12223 | return (a->address > b->address) - (a->address < b->address); | |
12224 | ||
dea2aa5f LM |
12225 | /* Sort locations at the same address by their pspace number, keeping |
12226 | locations of the same inferior (in a multi-inferior environment) | |
12227 | grouped. */ | |
12228 | ||
12229 | if (a->pspace->num != b->pspace->num) | |
12230 | return ((a->pspace->num > b->pspace->num) | |
12231 | - (a->pspace->num < b->pspace->num)); | |
12232 | ||
876fa593 | 12233 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12234 | if (a->permanent != b->permanent) |
12235 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12236 | |
c56a97f9 JK |
12237 | /* Make the internal GDB representation stable across GDB runs |
12238 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12239 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12240 | |
12241 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12242 | return ((a->owner->number > b->owner->number) |
12243 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12244 | |
12245 | return (a > b) - (a < b); | |
12246 | } | |
12247 | ||
876fa593 | 12248 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12249 | bp_location_shadow_len_after_address_max according to the current |
12250 | content of the bp_location array. */ | |
f7545552 TT |
12251 | |
12252 | static void | |
876fa593 | 12253 | bp_location_target_extensions_update (void) |
f7545552 | 12254 | { |
876fa593 JK |
12255 | struct bp_location *bl, **blp_tmp; |
12256 | ||
12257 | bp_location_placed_address_before_address_max = 0; | |
12258 | bp_location_shadow_len_after_address_max = 0; | |
12259 | ||
12260 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12261 | { | |
12262 | CORE_ADDR start, end, addr; | |
12263 | ||
12264 | if (!bp_location_has_shadow (bl)) | |
12265 | continue; | |
12266 | ||
12267 | start = bl->target_info.placed_address; | |
12268 | end = start + bl->target_info.shadow_len; | |
12269 | ||
12270 | gdb_assert (bl->address >= start); | |
12271 | addr = bl->address - start; | |
12272 | if (addr > bp_location_placed_address_before_address_max) | |
12273 | bp_location_placed_address_before_address_max = addr; | |
12274 | ||
12275 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12276 | ||
12277 | gdb_assert (bl->address < end); | |
12278 | addr = end - bl->address; | |
12279 | if (addr > bp_location_shadow_len_after_address_max) | |
12280 | bp_location_shadow_len_after_address_max = addr; | |
12281 | } | |
f7545552 TT |
12282 | } |
12283 | ||
1e4d1764 YQ |
12284 | /* Download tracepoint locations if they haven't been. */ |
12285 | ||
12286 | static void | |
12287 | download_tracepoint_locations (void) | |
12288 | { | |
7ed2c994 | 12289 | struct breakpoint *b; |
1e4d1764 | 12290 | struct cleanup *old_chain; |
dd2e65cc | 12291 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12292 | |
12293 | old_chain = save_current_space_and_thread (); | |
12294 | ||
7ed2c994 | 12295 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12296 | { |
7ed2c994 | 12297 | struct bp_location *bl; |
1e4d1764 | 12298 | struct tracepoint *t; |
f2a8bc8a | 12299 | int bp_location_downloaded = 0; |
1e4d1764 | 12300 | |
7ed2c994 | 12301 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12302 | ? !may_insert_fast_tracepoints |
12303 | : !may_insert_tracepoints)) | |
12304 | continue; | |
12305 | ||
dd2e65cc YQ |
12306 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12307 | { | |
12308 | if (target_can_download_tracepoint ()) | |
12309 | can_download_tracepoint = TRIBOOL_TRUE; | |
12310 | else | |
12311 | can_download_tracepoint = TRIBOOL_FALSE; | |
12312 | } | |
12313 | ||
12314 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12315 | break; | |
12316 | ||
7ed2c994 YQ |
12317 | for (bl = b->loc; bl; bl = bl->next) |
12318 | { | |
12319 | /* In tracepoint, locations are _never_ duplicated, so | |
12320 | should_be_inserted is equivalent to | |
12321 | unduplicated_should_be_inserted. */ | |
12322 | if (!should_be_inserted (bl) || bl->inserted) | |
12323 | continue; | |
1e4d1764 | 12324 | |
7ed2c994 | 12325 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12326 | |
7ed2c994 | 12327 | target_download_tracepoint (bl); |
1e4d1764 | 12328 | |
7ed2c994 | 12329 | bl->inserted = 1; |
f2a8bc8a | 12330 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12331 | } |
12332 | t = (struct tracepoint *) b; | |
12333 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12334 | if (bp_location_downloaded) |
12335 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12336 | } |
12337 | ||
12338 | do_cleanups (old_chain); | |
12339 | } | |
12340 | ||
934709f0 PW |
12341 | /* Swap the insertion/duplication state between two locations. */ |
12342 | ||
12343 | static void | |
12344 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12345 | { | |
12346 | const int left_inserted = left->inserted; | |
12347 | const int left_duplicate = left->duplicate; | |
b775012e | 12348 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12349 | const struct bp_target_info left_target_info = left->target_info; |
12350 | ||
1e4d1764 YQ |
12351 | /* Locations of tracepoints can never be duplicated. */ |
12352 | if (is_tracepoint (left->owner)) | |
12353 | gdb_assert (!left->duplicate); | |
12354 | if (is_tracepoint (right->owner)) | |
12355 | gdb_assert (!right->duplicate); | |
12356 | ||
934709f0 PW |
12357 | left->inserted = right->inserted; |
12358 | left->duplicate = right->duplicate; | |
b775012e | 12359 | left->needs_update = right->needs_update; |
934709f0 PW |
12360 | left->target_info = right->target_info; |
12361 | right->inserted = left_inserted; | |
12362 | right->duplicate = left_duplicate; | |
b775012e | 12363 | right->needs_update = left_needs_update; |
934709f0 PW |
12364 | right->target_info = left_target_info; |
12365 | } | |
12366 | ||
b775012e LM |
12367 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12368 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12369 | conditions on the target's side. Such conditions need to be updated on | |
12370 | the target. */ | |
12371 | ||
12372 | static void | |
12373 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12374 | { | |
12375 | struct bp_location **locp = NULL, **loc2p; | |
12376 | struct bp_location *loc; | |
12377 | CORE_ADDR address = 0; | |
12378 | int pspace_num; | |
12379 | ||
12380 | address = bl->address; | |
12381 | pspace_num = bl->pspace->num; | |
12382 | ||
12383 | /* This is only meaningful if the target is | |
12384 | evaluating conditions and if the user has | |
12385 | opted for condition evaluation on the target's | |
12386 | side. */ | |
12387 | if (gdb_evaluates_breakpoint_condition_p () | |
12388 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12389 | return; | |
12390 | ||
12391 | /* Flag all breakpoint locations with this address and | |
12392 | the same program space as the location | |
12393 | as "its condition has changed". We need to | |
12394 | update the conditions on the target's side. */ | |
12395 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12396 | { | |
12397 | loc = *loc2p; | |
12398 | ||
12399 | if (!is_breakpoint (loc->owner) | |
12400 | || pspace_num != loc->pspace->num) | |
12401 | continue; | |
12402 | ||
12403 | /* Flag the location appropriately. We use a different state to | |
12404 | let everyone know that we already updated the set of locations | |
12405 | with addr bl->address and program space bl->pspace. This is so | |
12406 | we don't have to keep calling these functions just to mark locations | |
12407 | that have already been marked. */ | |
12408 | loc->condition_changed = condition_updated; | |
12409 | ||
12410 | /* Free the agent expression bytecode as well. We will compute | |
12411 | it later on. */ | |
12412 | if (loc->cond_bytecode) | |
12413 | { | |
12414 | free_agent_expr (loc->cond_bytecode); | |
12415 | loc->cond_bytecode = NULL; | |
12416 | } | |
12417 | } | |
12418 | } | |
44702360 PA |
12419 | /* Called whether new breakpoints are created, or existing breakpoints |
12420 | deleted, to update the global location list and recompute which | |
12421 | locations are duplicate of which. | |
b775012e | 12422 | |
04086b45 PA |
12423 | The INSERT_MODE flag determines whether locations may not, may, or |
12424 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12425 | info. */ | |
b60e7edf | 12426 | |
0d381245 | 12427 | static void |
44702360 | 12428 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12429 | { |
74960c60 | 12430 | struct breakpoint *b; |
876fa593 | 12431 | struct bp_location **locp, *loc; |
f7545552 | 12432 | struct cleanup *cleanups; |
b775012e LM |
12433 | /* Last breakpoint location address that was marked for update. */ |
12434 | CORE_ADDR last_addr = 0; | |
12435 | /* Last breakpoint location program space that was marked for update. */ | |
12436 | int last_pspace_num = -1; | |
f7545552 | 12437 | |
2d134ed3 PA |
12438 | /* Used in the duplicates detection below. When iterating over all |
12439 | bp_locations, points to the first bp_location of a given address. | |
12440 | Breakpoints and watchpoints of different types are never | |
12441 | duplicates of each other. Keep one pointer for each type of | |
12442 | breakpoint/watchpoint, so we only need to loop over all locations | |
12443 | once. */ | |
12444 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12445 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12446 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12447 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12448 | |
4a64f543 MS |
12449 | /* Saved former bp_location array which we compare against the newly |
12450 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12451 | struct bp_location **old_location, **old_locp; |
12452 | unsigned old_location_count; | |
12453 | ||
12454 | old_location = bp_location; | |
12455 | old_location_count = bp_location_count; | |
12456 | bp_location = NULL; | |
12457 | bp_location_count = 0; | |
12458 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12459 | |
74960c60 | 12460 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12461 | for (loc = b->loc; loc; loc = loc->next) |
12462 | bp_location_count++; | |
12463 | ||
8d749320 | 12464 | bp_location = XNEWVEC (struct bp_location *, bp_location_count); |
876fa593 JK |
12465 | locp = bp_location; |
12466 | ALL_BREAKPOINTS (b) | |
12467 | for (loc = b->loc; loc; loc = loc->next) | |
12468 | *locp++ = loc; | |
12469 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12470 | bp_location_compare); |
876fa593 JK |
12471 | |
12472 | bp_location_target_extensions_update (); | |
74960c60 | 12473 | |
4a64f543 MS |
12474 | /* Identify bp_location instances that are no longer present in the |
12475 | new list, and therefore should be freed. Note that it's not | |
12476 | necessary that those locations should be removed from inferior -- | |
12477 | if there's another location at the same address (previously | |
12478 | marked as duplicate), we don't need to remove/insert the | |
12479 | location. | |
876fa593 | 12480 | |
4a64f543 MS |
12481 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12482 | and former bp_location array state respectively. */ | |
876fa593 JK |
12483 | |
12484 | locp = bp_location; | |
12485 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12486 | old_locp++) | |
74960c60 | 12487 | { |
876fa593 | 12488 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12489 | struct bp_location **loc2p; |
876fa593 | 12490 | |
e5dd4106 | 12491 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12492 | not, we have to free it. */ |
c7d46a38 | 12493 | int found_object = 0; |
20874c92 VP |
12494 | /* Tells if the location should remain inserted in the target. */ |
12495 | int keep_in_target = 0; | |
12496 | int removed = 0; | |
876fa593 | 12497 | |
4a64f543 MS |
12498 | /* Skip LOCP entries which will definitely never be needed. |
12499 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12500 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12501 | && (*locp)->address < old_loc->address) |
876fa593 | 12502 | locp++; |
c7d46a38 PA |
12503 | |
12504 | for (loc2p = locp; | |
12505 | (loc2p < bp_location + bp_location_count | |
12506 | && (*loc2p)->address == old_loc->address); | |
12507 | loc2p++) | |
12508 | { | |
b775012e LM |
12509 | /* Check if this is a new/duplicated location or a duplicated |
12510 | location that had its condition modified. If so, we want to send | |
12511 | its condition to the target if evaluation of conditions is taking | |
12512 | place there. */ | |
12513 | if ((*loc2p)->condition_changed == condition_modified | |
12514 | && (last_addr != old_loc->address | |
12515 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12516 | { |
b775012e LM |
12517 | force_breakpoint_reinsertion (*loc2p); |
12518 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12519 | } |
b775012e LM |
12520 | |
12521 | if (*loc2p == old_loc) | |
12522 | found_object = 1; | |
c7d46a38 | 12523 | } |
74960c60 | 12524 | |
b775012e LM |
12525 | /* We have already handled this address, update it so that we don't |
12526 | have to go through updates again. */ | |
12527 | last_addr = old_loc->address; | |
12528 | ||
12529 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12530 | if (!found_object) | |
12531 | force_breakpoint_reinsertion (old_loc); | |
12532 | ||
4a64f543 MS |
12533 | /* If this location is no longer present, and inserted, look if |
12534 | there's maybe a new location at the same address. If so, | |
12535 | mark that one inserted, and don't remove this one. This is | |
12536 | needed so that we don't have a time window where a breakpoint | |
12537 | at certain location is not inserted. */ | |
74960c60 | 12538 | |
876fa593 | 12539 | if (old_loc->inserted) |
0d381245 | 12540 | { |
4a64f543 MS |
12541 | /* If the location is inserted now, we might have to remove |
12542 | it. */ | |
74960c60 | 12543 | |
876fa593 | 12544 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12545 | { |
4a64f543 MS |
12546 | /* The location is still present in the location list, |
12547 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12548 | keep_in_target = 1; |
74960c60 VP |
12549 | } |
12550 | else | |
12551 | { | |
b775012e LM |
12552 | /* This location still exists, but it won't be kept in the |
12553 | target since it may have been disabled. We proceed to | |
12554 | remove its target-side condition. */ | |
12555 | ||
4a64f543 MS |
12556 | /* The location is either no longer present, or got |
12557 | disabled. See if there's another location at the | |
12558 | same address, in which case we don't need to remove | |
12559 | this one from the target. */ | |
876fa593 | 12560 | |
2bdf28a0 | 12561 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12562 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12563 | { | |
876fa593 | 12564 | for (loc2p = locp; |
c7d46a38 PA |
12565 | (loc2p < bp_location + bp_location_count |
12566 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12567 | loc2p++) |
12568 | { | |
12569 | struct bp_location *loc2 = *loc2p; | |
12570 | ||
2d134ed3 | 12571 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12572 | { |
85d721b8 PA |
12573 | /* Read watchpoint locations are switched to |
12574 | access watchpoints, if the former are not | |
12575 | supported, but the latter are. */ | |
12576 | if (is_hardware_watchpoint (old_loc->owner)) | |
12577 | { | |
12578 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12579 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12580 | } | |
12581 | ||
934709f0 PW |
12582 | /* loc2 is a duplicated location. We need to check |
12583 | if it should be inserted in case it will be | |
12584 | unduplicated. */ | |
12585 | if (loc2 != old_loc | |
12586 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12587 | { |
934709f0 | 12588 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12589 | keep_in_target = 1; |
12590 | break; | |
12591 | } | |
876fa593 JK |
12592 | } |
12593 | } | |
12594 | } | |
74960c60 VP |
12595 | } |
12596 | ||
20874c92 VP |
12597 | if (!keep_in_target) |
12598 | { | |
834c0d03 | 12599 | if (remove_breakpoint (old_loc)) |
20874c92 | 12600 | { |
4a64f543 MS |
12601 | /* This is just about all we can do. We could keep |
12602 | this location on the global list, and try to | |
12603 | remove it next time, but there's no particular | |
12604 | reason why we will succeed next time. | |
20874c92 | 12605 | |
4a64f543 MS |
12606 | Note that at this point, old_loc->owner is still |
12607 | valid, as delete_breakpoint frees the breakpoint | |
12608 | only after calling us. */ | |
3e43a32a MS |
12609 | printf_filtered (_("warning: Error removing " |
12610 | "breakpoint %d\n"), | |
876fa593 | 12611 | old_loc->owner->number); |
20874c92 VP |
12612 | } |
12613 | removed = 1; | |
12614 | } | |
0d381245 | 12615 | } |
74960c60 VP |
12616 | |
12617 | if (!found_object) | |
1c5cfe86 | 12618 | { |
fbea99ea | 12619 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12620 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12621 | { |
db82e815 PA |
12622 | /* This location was removed from the target. In |
12623 | non-stop mode, a race condition is possible where | |
12624 | we've removed a breakpoint, but stop events for that | |
12625 | breakpoint are already queued and will arrive later. | |
12626 | We apply an heuristic to be able to distinguish such | |
12627 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12628 | breakpoint location for a bit, and will retire it | |
12629 | after we see some number of events. The theory here | |
12630 | is that reporting of events should, "on the average", | |
12631 | be fair, so after a while we'll see events from all | |
12632 | threads that have anything of interest, and no longer | |
12633 | need to keep this breakpoint location around. We | |
12634 | don't hold locations forever so to reduce chances of | |
12635 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12636 | SIGTRAP. | |
12637 | ||
12638 | The heuristic failing can be disastrous on | |
12639 | decr_pc_after_break targets. | |
12640 | ||
12641 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12642 | if we fail to recognize a late breakpoint SIGTRAP, | |
12643 | because events_till_retirement has reached 0 too | |
12644 | soon, we'll fail to do the PC adjustment, and report | |
12645 | a random SIGTRAP to the user. When the user resumes | |
12646 | the inferior, it will most likely immediately crash | |
2dec564e | 12647 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12648 | corrupted, because of being resumed e.g., in the |
12649 | middle of a multi-byte instruction, or skipped a | |
12650 | one-byte instruction. This was actually seen happen | |
12651 | on native x86-linux, and should be less rare on | |
12652 | targets that do not support new thread events, like | |
12653 | remote, due to the heuristic depending on | |
12654 | thread_count. | |
12655 | ||
12656 | Mistaking a random SIGTRAP for a breakpoint trap | |
12657 | causes similar symptoms (PC adjustment applied when | |
12658 | it shouldn't), but then again, playing with SIGTRAPs | |
12659 | behind the debugger's back is asking for trouble. | |
12660 | ||
12661 | Since hardware watchpoint traps are always | |
12662 | distinguishable from other traps, so we don't need to | |
12663 | apply keep hardware watchpoint moribund locations | |
12664 | around. We simply always ignore hardware watchpoint | |
12665 | traps we can no longer explain. */ | |
12666 | ||
876fa593 JK |
12667 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12668 | old_loc->owner = NULL; | |
20874c92 | 12669 | |
876fa593 | 12670 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12671 | } |
12672 | else | |
f431efe5 PA |
12673 | { |
12674 | old_loc->owner = NULL; | |
12675 | decref_bp_location (&old_loc); | |
12676 | } | |
20874c92 | 12677 | } |
74960c60 | 12678 | } |
1c5cfe86 | 12679 | |
348d480f PA |
12680 | /* Rescan breakpoints at the same address and section, marking the |
12681 | first one as "first" and any others as "duplicates". This is so | |
12682 | that the bpt instruction is only inserted once. If we have a | |
12683 | permanent breakpoint at the same place as BPT, make that one the | |
12684 | official one, and the rest as duplicates. Permanent breakpoints | |
12685 | are sorted first for the same address. | |
12686 | ||
12687 | Do the same for hardware watchpoints, but also considering the | |
12688 | watchpoint's type (regular/access/read) and length. */ | |
12689 | ||
12690 | bp_loc_first = NULL; | |
12691 | wp_loc_first = NULL; | |
12692 | awp_loc_first = NULL; | |
12693 | rwp_loc_first = NULL; | |
12694 | ALL_BP_LOCATIONS (loc, locp) | |
12695 | { | |
12696 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12697 | non-NULL. */ | |
348d480f | 12698 | struct bp_location **loc_first_p; |
d3fbdd86 | 12699 | b = loc->owner; |
348d480f | 12700 | |
6f380991 | 12701 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12702 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12703 | /* Don't detect duplicate for tracepoint locations because they are |
12704 | never duplicated. See the comments in field `duplicate' of | |
12705 | `struct bp_location'. */ | |
348d480f | 12706 | || is_tracepoint (b)) |
b775012e LM |
12707 | { |
12708 | /* Clear the condition modification flag. */ | |
12709 | loc->condition_changed = condition_unchanged; | |
12710 | continue; | |
12711 | } | |
348d480f | 12712 | |
348d480f PA |
12713 | if (b->type == bp_hardware_watchpoint) |
12714 | loc_first_p = &wp_loc_first; | |
12715 | else if (b->type == bp_read_watchpoint) | |
12716 | loc_first_p = &rwp_loc_first; | |
12717 | else if (b->type == bp_access_watchpoint) | |
12718 | loc_first_p = &awp_loc_first; | |
12719 | else | |
12720 | loc_first_p = &bp_loc_first; | |
12721 | ||
12722 | if (*loc_first_p == NULL | |
12723 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12724 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12725 | { | |
12726 | *loc_first_p = loc; | |
12727 | loc->duplicate = 0; | |
b775012e LM |
12728 | |
12729 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12730 | { | |
12731 | loc->needs_update = 1; | |
12732 | /* Clear the condition modification flag. */ | |
12733 | loc->condition_changed = condition_unchanged; | |
12734 | } | |
348d480f PA |
12735 | continue; |
12736 | } | |
12737 | ||
934709f0 PW |
12738 | |
12739 | /* This and the above ensure the invariant that the first location | |
12740 | is not duplicated, and is the inserted one. | |
12741 | All following are marked as duplicated, and are not inserted. */ | |
12742 | if (loc->inserted) | |
12743 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12744 | loc->duplicate = 1; |
12745 | ||
b775012e LM |
12746 | /* Clear the condition modification flag. */ |
12747 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12748 | } |
12749 | ||
a25a5a45 | 12750 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12751 | { |
04086b45 | 12752 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12753 | insert_breakpoint_locations (); |
12754 | else | |
12755 | { | |
44702360 PA |
12756 | /* Even though the caller told us to not insert new |
12757 | locations, we may still need to update conditions on the | |
12758 | target's side of breakpoints that were already inserted | |
12759 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12760 | only update conditions for locations that are marked |
12761 | "needs_update". */ | |
12762 | update_inserted_breakpoint_locations (); | |
12763 | } | |
12764 | } | |
348d480f | 12765 | |
04086b45 | 12766 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12767 | download_tracepoint_locations (); |
12768 | ||
348d480f PA |
12769 | do_cleanups (cleanups); |
12770 | } | |
12771 | ||
12772 | void | |
12773 | breakpoint_retire_moribund (void) | |
12774 | { | |
12775 | struct bp_location *loc; | |
12776 | int ix; | |
12777 | ||
12778 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12779 | if (--(loc->events_till_retirement) == 0) | |
12780 | { | |
12781 | decref_bp_location (&loc); | |
12782 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12783 | --ix; | |
12784 | } | |
12785 | } | |
12786 | ||
12787 | static void | |
44702360 | 12788 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12789 | { |
348d480f | 12790 | |
492d29ea PA |
12791 | TRY |
12792 | { | |
12793 | update_global_location_list (insert_mode); | |
12794 | } | |
12795 | CATCH (e, RETURN_MASK_ERROR) | |
12796 | { | |
12797 | } | |
12798 | END_CATCH | |
348d480f PA |
12799 | } |
12800 | ||
12801 | /* Clear BKP from a BPS. */ | |
12802 | ||
12803 | static void | |
12804 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12805 | { | |
12806 | bpstat bs; | |
12807 | ||
12808 | for (bs = bps; bs; bs = bs->next) | |
12809 | if (bs->breakpoint_at == bpt) | |
12810 | { | |
12811 | bs->breakpoint_at = NULL; | |
12812 | bs->old_val = NULL; | |
12813 | /* bs->commands will be freed later. */ | |
12814 | } | |
12815 | } | |
12816 | ||
12817 | /* Callback for iterate_over_threads. */ | |
12818 | static int | |
12819 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12820 | { | |
9a3c8263 | 12821 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12822 | |
12823 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12824 | return 0; | |
12825 | } | |
12826 | ||
12827 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12828 | callbacks. */ | |
12829 | ||
12830 | static void | |
12831 | say_where (struct breakpoint *b) | |
12832 | { | |
12833 | struct value_print_options opts; | |
12834 | ||
12835 | get_user_print_options (&opts); | |
12836 | ||
12837 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12838 | single string. */ | |
12839 | if (b->loc == NULL) | |
12840 | { | |
f00aae0f KS |
12841 | /* For pending locations, the output differs slightly based |
12842 | on b->extra_string. If this is non-NULL, it contains either | |
12843 | a condition or dprintf arguments. */ | |
12844 | if (b->extra_string == NULL) | |
12845 | { | |
12846 | printf_filtered (_(" (%s) pending."), | |
12847 | event_location_to_string (b->location)); | |
12848 | } | |
12849 | else if (b->type == bp_dprintf) | |
12850 | { | |
12851 | printf_filtered (_(" (%s,%s) pending."), | |
12852 | event_location_to_string (b->location), | |
12853 | b->extra_string); | |
12854 | } | |
12855 | else | |
12856 | { | |
12857 | printf_filtered (_(" (%s %s) pending."), | |
12858 | event_location_to_string (b->location), | |
12859 | b->extra_string); | |
12860 | } | |
348d480f PA |
12861 | } |
12862 | else | |
12863 | { | |
2f202fde | 12864 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12865 | { |
12866 | printf_filtered (" at "); | |
12867 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12868 | gdb_stdout); | |
12869 | } | |
2f202fde | 12870 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12871 | { |
12872 | /* If there is a single location, we can print the location | |
12873 | more nicely. */ | |
12874 | if (b->loc->next == NULL) | |
12875 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12876 | symtab_to_filename_for_display (b->loc->symtab), |
12877 | b->loc->line_number); | |
f8eba3c6 TT |
12878 | else |
12879 | /* This is not ideal, but each location may have a | |
12880 | different file name, and this at least reflects the | |
12881 | real situation somewhat. */ | |
f00aae0f KS |
12882 | printf_filtered (": %s.", |
12883 | event_location_to_string (b->location)); | |
f8eba3c6 | 12884 | } |
348d480f PA |
12885 | |
12886 | if (b->loc->next) | |
12887 | { | |
12888 | struct bp_location *loc = b->loc; | |
12889 | int n = 0; | |
12890 | for (; loc; loc = loc->next) | |
12891 | ++n; | |
12892 | printf_filtered (" (%d locations)", n); | |
12893 | } | |
12894 | } | |
12895 | } | |
12896 | ||
348d480f PA |
12897 | /* Default bp_location_ops methods. */ |
12898 | ||
12899 | static void | |
12900 | bp_location_dtor (struct bp_location *self) | |
12901 | { | |
b775012e LM |
12902 | if (self->cond_bytecode) |
12903 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12904 | xfree (self->function_name); |
8b4f3082 PA |
12905 | |
12906 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12907 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12908 | } |
12909 | ||
12910 | static const struct bp_location_ops bp_location_ops = | |
12911 | { | |
12912 | bp_location_dtor | |
12913 | }; | |
12914 | ||
2060206e PA |
12915 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12916 | inherit from. */ | |
348d480f | 12917 | |
2060206e PA |
12918 | static void |
12919 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12920 | { |
12921 | decref_counted_command_line (&self->commands); | |
12922 | xfree (self->cond_string); | |
fb81d016 | 12923 | xfree (self->extra_string); |
f8eba3c6 | 12924 | xfree (self->filter); |
f00aae0f KS |
12925 | delete_event_location (self->location); |
12926 | delete_event_location (self->location_range_end); | |
348d480f PA |
12927 | } |
12928 | ||
2060206e PA |
12929 | static struct bp_location * |
12930 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12931 | { |
12932 | struct bp_location *loc; | |
12933 | ||
4d01a485 | 12934 | loc = new struct bp_location (); |
348d480f PA |
12935 | init_bp_location (loc, &bp_location_ops, self); |
12936 | return loc; | |
12937 | } | |
12938 | ||
2060206e PA |
12939 | static void |
12940 | base_breakpoint_re_set (struct breakpoint *b) | |
12941 | { | |
12942 | /* Nothing to re-set. */ | |
12943 | } | |
12944 | ||
12945 | #define internal_error_pure_virtual_called() \ | |
12946 | gdb_assert_not_reached ("pure virtual function called") | |
12947 | ||
12948 | static int | |
12949 | base_breakpoint_insert_location (struct bp_location *bl) | |
12950 | { | |
12951 | internal_error_pure_virtual_called (); | |
12952 | } | |
12953 | ||
12954 | static int | |
73971819 PA |
12955 | base_breakpoint_remove_location (struct bp_location *bl, |
12956 | enum remove_bp_reason reason) | |
2060206e PA |
12957 | { |
12958 | internal_error_pure_virtual_called (); | |
12959 | } | |
12960 | ||
12961 | static int | |
12962 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12963 | struct address_space *aspace, | |
09ac7c10 TT |
12964 | CORE_ADDR bp_addr, |
12965 | const struct target_waitstatus *ws) | |
2060206e PA |
12966 | { |
12967 | internal_error_pure_virtual_called (); | |
12968 | } | |
12969 | ||
12970 | static void | |
12971 | base_breakpoint_check_status (bpstat bs) | |
12972 | { | |
12973 | /* Always stop. */ | |
12974 | } | |
12975 | ||
12976 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12977 | errors. */ | |
12978 | ||
12979 | static int | |
12980 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12981 | { | |
12982 | internal_error_pure_virtual_called (); | |
12983 | } | |
12984 | ||
12985 | /* A "resources_needed" breakpoint_ops method that just internal | |
12986 | errors. */ | |
12987 | ||
12988 | static int | |
12989 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12990 | { | |
12991 | internal_error_pure_virtual_called (); | |
12992 | } | |
12993 | ||
12994 | static enum print_stop_action | |
12995 | base_breakpoint_print_it (bpstat bs) | |
12996 | { | |
12997 | internal_error_pure_virtual_called (); | |
12998 | } | |
12999 | ||
13000 | static void | |
13001 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
13002 | struct ui_out *uiout) | |
13003 | { | |
13004 | /* nothing */ | |
13005 | } | |
13006 | ||
13007 | static void | |
13008 | base_breakpoint_print_mention (struct breakpoint *b) | |
13009 | { | |
13010 | internal_error_pure_virtual_called (); | |
13011 | } | |
13012 | ||
13013 | static void | |
13014 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13015 | { | |
13016 | internal_error_pure_virtual_called (); | |
13017 | } | |
13018 | ||
983af33b | 13019 | static void |
f00aae0f KS |
13020 | base_breakpoint_create_sals_from_location |
13021 | (const struct event_location *location, | |
13022 | struct linespec_result *canonical, | |
13023 | enum bptype type_wanted) | |
983af33b SDJ |
13024 | { |
13025 | internal_error_pure_virtual_called (); | |
13026 | } | |
13027 | ||
13028 | static void | |
13029 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13030 | struct linespec_result *c, | |
983af33b | 13031 | char *cond_string, |
e7e0cddf | 13032 | char *extra_string, |
983af33b SDJ |
13033 | enum bptype type_wanted, |
13034 | enum bpdisp disposition, | |
13035 | int thread, | |
13036 | int task, int ignore_count, | |
13037 | const struct breakpoint_ops *o, | |
13038 | int from_tty, int enabled, | |
44f238bb | 13039 | int internal, unsigned flags) |
983af33b SDJ |
13040 | { |
13041 | internal_error_pure_virtual_called (); | |
13042 | } | |
13043 | ||
13044 | static void | |
f00aae0f KS |
13045 | base_breakpoint_decode_location (struct breakpoint *b, |
13046 | const struct event_location *location, | |
c2f4122d | 13047 | struct program_space *search_pspace, |
983af33b SDJ |
13048 | struct symtabs_and_lines *sals) |
13049 | { | |
13050 | internal_error_pure_virtual_called (); | |
13051 | } | |
13052 | ||
ab04a2af TT |
13053 | /* The default 'explains_signal' method. */ |
13054 | ||
47591c29 | 13055 | static int |
427cd150 | 13056 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13057 | { |
47591c29 | 13058 | return 1; |
ab04a2af TT |
13059 | } |
13060 | ||
9d6e6e84 HZ |
13061 | /* The default "after_condition_true" method. */ |
13062 | ||
13063 | static void | |
13064 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13065 | { | |
13066 | /* Nothing to do. */ | |
13067 | } | |
13068 | ||
ab04a2af | 13069 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13070 | { |
13071 | base_breakpoint_dtor, | |
13072 | base_breakpoint_allocate_location, | |
13073 | base_breakpoint_re_set, | |
13074 | base_breakpoint_insert_location, | |
13075 | base_breakpoint_remove_location, | |
13076 | base_breakpoint_breakpoint_hit, | |
13077 | base_breakpoint_check_status, | |
13078 | base_breakpoint_resources_needed, | |
13079 | base_breakpoint_works_in_software_mode, | |
13080 | base_breakpoint_print_it, | |
13081 | NULL, | |
13082 | base_breakpoint_print_one_detail, | |
13083 | base_breakpoint_print_mention, | |
983af33b | 13084 | base_breakpoint_print_recreate, |
5f700d83 | 13085 | base_breakpoint_create_sals_from_location, |
983af33b | 13086 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 13087 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
13088 | base_breakpoint_explains_signal, |
13089 | base_breakpoint_after_condition_true, | |
2060206e PA |
13090 | }; |
13091 | ||
13092 | /* Default breakpoint_ops methods. */ | |
13093 | ||
13094 | static void | |
348d480f PA |
13095 | bkpt_re_set (struct breakpoint *b) |
13096 | { | |
06edf0c0 | 13097 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 13098 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 13099 | { |
f00aae0f | 13100 | /* Anything without a location can't be re-set. */ |
348d480f | 13101 | delete_breakpoint (b); |
06edf0c0 | 13102 | return; |
348d480f | 13103 | } |
06edf0c0 PA |
13104 | |
13105 | breakpoint_re_set_default (b); | |
348d480f PA |
13106 | } |
13107 | ||
2060206e | 13108 | static int |
348d480f PA |
13109 | bkpt_insert_location (struct bp_location *bl) |
13110 | { | |
cd6c3b4f YQ |
13111 | CORE_ADDR addr = bl->target_info.reqstd_address; |
13112 | ||
579c6ad9 | 13113 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
13114 | bl->target_info.placed_address = addr; |
13115 | ||
348d480f | 13116 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 13117 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13118 | else |
7c16b83e | 13119 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13120 | } |
13121 | ||
2060206e | 13122 | static int |
73971819 | 13123 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
13124 | { |
13125 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13126 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13127 | else | |
73971819 | 13128 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
13129 | } |
13130 | ||
2060206e | 13131 | static int |
348d480f | 13132 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13133 | struct address_space *aspace, CORE_ADDR bp_addr, |
13134 | const struct target_waitstatus *ws) | |
348d480f | 13135 | { |
09ac7c10 | 13136 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13137 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13138 | return 0; |
13139 | ||
348d480f PA |
13140 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13141 | aspace, bp_addr)) | |
13142 | return 0; | |
13143 | ||
13144 | if (overlay_debugging /* unmapped overlay section */ | |
13145 | && section_is_overlay (bl->section) | |
13146 | && !section_is_mapped (bl->section)) | |
13147 | return 0; | |
13148 | ||
13149 | return 1; | |
13150 | } | |
13151 | ||
cd1608cc PA |
13152 | static int |
13153 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13154 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13155 | const struct target_waitstatus *ws) | |
13156 | { | |
13157 | if (dprintf_style == dprintf_style_agent | |
13158 | && target_can_run_breakpoint_commands ()) | |
13159 | { | |
13160 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13161 | for this address it must be for a breakpoint that happens to | |
13162 | be set at the same address. */ | |
13163 | return 0; | |
13164 | } | |
13165 | ||
13166 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13167 | } | |
13168 | ||
2060206e | 13169 | static int |
348d480f PA |
13170 | bkpt_resources_needed (const struct bp_location *bl) |
13171 | { | |
13172 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13173 | ||
13174 | return 1; | |
13175 | } | |
13176 | ||
2060206e | 13177 | static enum print_stop_action |
348d480f PA |
13178 | bkpt_print_it (bpstat bs) |
13179 | { | |
348d480f PA |
13180 | struct breakpoint *b; |
13181 | const struct bp_location *bl; | |
001c8c33 | 13182 | int bp_temp; |
79a45e25 | 13183 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13184 | |
13185 | gdb_assert (bs->bp_location_at != NULL); | |
13186 | ||
13187 | bl = bs->bp_location_at; | |
13188 | b = bs->breakpoint_at; | |
13189 | ||
001c8c33 PA |
13190 | bp_temp = b->disposition == disp_del; |
13191 | if (bl->address != bl->requested_address) | |
13192 | breakpoint_adjustment_warning (bl->requested_address, | |
13193 | bl->address, | |
13194 | b->number, 1); | |
13195 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
13196 | maybe_print_thread_hit_breakpoint (uiout); |
13197 | ||
001c8c33 | 13198 | if (bp_temp) |
f303dbd6 | 13199 | ui_out_text (uiout, "Temporary breakpoint "); |
001c8c33 | 13200 | else |
f303dbd6 | 13201 | ui_out_text (uiout, "Breakpoint "); |
001c8c33 | 13202 | if (ui_out_is_mi_like_p (uiout)) |
348d480f | 13203 | { |
001c8c33 PA |
13204 | ui_out_field_string (uiout, "reason", |
13205 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13206 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13207 | } |
001c8c33 PA |
13208 | ui_out_field_int (uiout, "bkptno", b->number); |
13209 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13210 | |
001c8c33 | 13211 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13212 | } |
13213 | ||
2060206e | 13214 | static void |
06edf0c0 PA |
13215 | bkpt_print_mention (struct breakpoint *b) |
13216 | { | |
79a45e25 | 13217 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13218 | return; |
13219 | ||
13220 | switch (b->type) | |
13221 | { | |
13222 | case bp_breakpoint: | |
13223 | case bp_gnu_ifunc_resolver: | |
13224 | if (b->disposition == disp_del) | |
13225 | printf_filtered (_("Temporary breakpoint")); | |
13226 | else | |
13227 | printf_filtered (_("Breakpoint")); | |
13228 | printf_filtered (_(" %d"), b->number); | |
13229 | if (b->type == bp_gnu_ifunc_resolver) | |
13230 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13231 | break; | |
13232 | case bp_hardware_breakpoint: | |
13233 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13234 | break; | |
e7e0cddf SS |
13235 | case bp_dprintf: |
13236 | printf_filtered (_("Dprintf %d"), b->number); | |
13237 | break; | |
06edf0c0 PA |
13238 | } |
13239 | ||
13240 | say_where (b); | |
13241 | } | |
13242 | ||
2060206e | 13243 | static void |
06edf0c0 PA |
13244 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13245 | { | |
13246 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13247 | fprintf_unfiltered (fp, "tbreak"); | |
13248 | else if (tp->type == bp_breakpoint) | |
13249 | fprintf_unfiltered (fp, "break"); | |
13250 | else if (tp->type == bp_hardware_breakpoint | |
13251 | && tp->disposition == disp_del) | |
13252 | fprintf_unfiltered (fp, "thbreak"); | |
13253 | else if (tp->type == bp_hardware_breakpoint) | |
13254 | fprintf_unfiltered (fp, "hbreak"); | |
13255 | else | |
13256 | internal_error (__FILE__, __LINE__, | |
13257 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13258 | ||
f00aae0f KS |
13259 | fprintf_unfiltered (fp, " %s", |
13260 | event_location_to_string (tp->location)); | |
13261 | ||
13262 | /* Print out extra_string if this breakpoint is pending. It might | |
13263 | contain, for example, conditions that were set by the user. */ | |
13264 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13265 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13266 | ||
dd11a36c | 13267 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13268 | } |
13269 | ||
983af33b | 13270 | static void |
f00aae0f KS |
13271 | bkpt_create_sals_from_location (const struct event_location *location, |
13272 | struct linespec_result *canonical, | |
13273 | enum bptype type_wanted) | |
983af33b | 13274 | { |
f00aae0f | 13275 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13276 | } |
13277 | ||
13278 | static void | |
13279 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13280 | struct linespec_result *canonical, | |
983af33b | 13281 | char *cond_string, |
e7e0cddf | 13282 | char *extra_string, |
983af33b SDJ |
13283 | enum bptype type_wanted, |
13284 | enum bpdisp disposition, | |
13285 | int thread, | |
13286 | int task, int ignore_count, | |
13287 | const struct breakpoint_ops *ops, | |
13288 | int from_tty, int enabled, | |
44f238bb | 13289 | int internal, unsigned flags) |
983af33b | 13290 | { |
023fa29b | 13291 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13292 | cond_string, extra_string, |
13293 | type_wanted, | |
983af33b SDJ |
13294 | disposition, thread, task, |
13295 | ignore_count, ops, from_tty, | |
44f238bb | 13296 | enabled, internal, flags); |
983af33b SDJ |
13297 | } |
13298 | ||
13299 | static void | |
f00aae0f KS |
13300 | bkpt_decode_location (struct breakpoint *b, |
13301 | const struct event_location *location, | |
c2f4122d | 13302 | struct program_space *search_pspace, |
983af33b SDJ |
13303 | struct symtabs_and_lines *sals) |
13304 | { | |
c2f4122d | 13305 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13306 | } |
13307 | ||
06edf0c0 PA |
13308 | /* Virtual table for internal breakpoints. */ |
13309 | ||
13310 | static void | |
13311 | internal_bkpt_re_set (struct breakpoint *b) | |
13312 | { | |
13313 | switch (b->type) | |
13314 | { | |
13315 | /* Delete overlay event and longjmp master breakpoints; they | |
13316 | will be reset later by breakpoint_re_set. */ | |
13317 | case bp_overlay_event: | |
13318 | case bp_longjmp_master: | |
13319 | case bp_std_terminate_master: | |
13320 | case bp_exception_master: | |
13321 | delete_breakpoint (b); | |
13322 | break; | |
13323 | ||
13324 | /* This breakpoint is special, it's set up when the inferior | |
13325 | starts and we really don't want to touch it. */ | |
13326 | case bp_shlib_event: | |
13327 | ||
13328 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13329 | it is set up, we do not want to touch it. */ | |
13330 | case bp_thread_event: | |
13331 | break; | |
13332 | } | |
13333 | } | |
13334 | ||
13335 | static void | |
13336 | internal_bkpt_check_status (bpstat bs) | |
13337 | { | |
a9b3a50f PA |
13338 | if (bs->breakpoint_at->type == bp_shlib_event) |
13339 | { | |
13340 | /* If requested, stop when the dynamic linker notifies GDB of | |
13341 | events. This allows the user to get control and place | |
13342 | breakpoints in initializer routines for dynamically loaded | |
13343 | objects (among other things). */ | |
13344 | bs->stop = stop_on_solib_events; | |
13345 | bs->print = stop_on_solib_events; | |
13346 | } | |
13347 | else | |
13348 | bs->stop = 0; | |
06edf0c0 PA |
13349 | } |
13350 | ||
13351 | static enum print_stop_action | |
13352 | internal_bkpt_print_it (bpstat bs) | |
13353 | { | |
06edf0c0 | 13354 | struct breakpoint *b; |
06edf0c0 | 13355 | |
06edf0c0 PA |
13356 | b = bs->breakpoint_at; |
13357 | ||
06edf0c0 PA |
13358 | switch (b->type) |
13359 | { | |
348d480f PA |
13360 | case bp_shlib_event: |
13361 | /* Did we stop because the user set the stop_on_solib_events | |
13362 | variable? (If so, we report this as a generic, "Stopped due | |
13363 | to shlib event" message.) */ | |
edcc5120 | 13364 | print_solib_event (0); |
348d480f PA |
13365 | break; |
13366 | ||
13367 | case bp_thread_event: | |
13368 | /* Not sure how we will get here. | |
13369 | GDB should not stop for these breakpoints. */ | |
13370 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13371 | break; |
13372 | ||
13373 | case bp_overlay_event: | |
13374 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13375 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13376 | break; |
13377 | ||
13378 | case bp_longjmp_master: | |
13379 | /* These should never be enabled. */ | |
13380 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13381 | break; |
13382 | ||
13383 | case bp_std_terminate_master: | |
13384 | /* These should never be enabled. */ | |
13385 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13386 | "gdb should not stop!\n")); | |
348d480f PA |
13387 | break; |
13388 | ||
13389 | case bp_exception_master: | |
13390 | /* These should never be enabled. */ | |
13391 | printf_filtered (_("Exception Master Breakpoint: " | |
13392 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13393 | break; |
13394 | } | |
13395 | ||
001c8c33 | 13396 | return PRINT_NOTHING; |
06edf0c0 PA |
13397 | } |
13398 | ||
13399 | static void | |
13400 | internal_bkpt_print_mention (struct breakpoint *b) | |
13401 | { | |
13402 | /* Nothing to mention. These breakpoints are internal. */ | |
13403 | } | |
13404 | ||
06edf0c0 PA |
13405 | /* Virtual table for momentary breakpoints */ |
13406 | ||
13407 | static void | |
13408 | momentary_bkpt_re_set (struct breakpoint *b) | |
13409 | { | |
13410 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13411 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13412 | Otherwise these should have been blown away via the cleanup chain |
13413 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13414 | } | |
13415 | ||
13416 | static void | |
13417 | momentary_bkpt_check_status (bpstat bs) | |
13418 | { | |
13419 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13420 | } | |
13421 | ||
13422 | static enum print_stop_action | |
13423 | momentary_bkpt_print_it (bpstat bs) | |
13424 | { | |
001c8c33 | 13425 | return PRINT_UNKNOWN; |
348d480f PA |
13426 | } |
13427 | ||
06edf0c0 PA |
13428 | static void |
13429 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13430 | { |
06edf0c0 | 13431 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13432 | } |
13433 | ||
e2e4d78b JK |
13434 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13435 | ||
13436 | It gets cleared already on the removal of the first one of such placed | |
13437 | breakpoints. This is OK as they get all removed altogether. */ | |
13438 | ||
13439 | static void | |
13440 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13441 | { | |
5d5658a1 | 13442 | struct thread_info *tp = find_thread_global_id (self->thread); |
e2e4d78b JK |
13443 | |
13444 | if (tp) | |
13445 | tp->initiating_frame = null_frame_id; | |
13446 | ||
13447 | momentary_breakpoint_ops.dtor (self); | |
13448 | } | |
13449 | ||
55aa24fb SDJ |
13450 | /* Specific methods for probe breakpoints. */ |
13451 | ||
13452 | static int | |
13453 | bkpt_probe_insert_location (struct bp_location *bl) | |
13454 | { | |
13455 | int v = bkpt_insert_location (bl); | |
13456 | ||
13457 | if (v == 0) | |
13458 | { | |
13459 | /* The insertion was successful, now let's set the probe's semaphore | |
13460 | if needed. */ | |
0ea5cda8 SDJ |
13461 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13462 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13463 | bl->probe.objfile, | |
13464 | bl->gdbarch); | |
55aa24fb SDJ |
13465 | } |
13466 | ||
13467 | return v; | |
13468 | } | |
13469 | ||
13470 | static int | |
73971819 PA |
13471 | bkpt_probe_remove_location (struct bp_location *bl, |
13472 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13473 | { |
13474 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13475 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13476 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13477 | bl->probe.objfile, | |
13478 | bl->gdbarch); | |
55aa24fb | 13479 | |
73971819 | 13480 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13481 | } |
13482 | ||
13483 | static void | |
f00aae0f | 13484 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13485 | struct linespec_result *canonical, |
f00aae0f | 13486 | enum bptype type_wanted) |
55aa24fb SDJ |
13487 | { |
13488 | struct linespec_sals lsal; | |
13489 | ||
c2f4122d | 13490 | lsal.sals = parse_probes (location, NULL, canonical); |
f00aae0f | 13491 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
55aa24fb SDJ |
13492 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13493 | } | |
13494 | ||
13495 | static void | |
f00aae0f KS |
13496 | bkpt_probe_decode_location (struct breakpoint *b, |
13497 | const struct event_location *location, | |
c2f4122d | 13498 | struct program_space *search_pspace, |
55aa24fb SDJ |
13499 | struct symtabs_and_lines *sals) |
13500 | { | |
c2f4122d | 13501 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13502 | if (!sals->sals) |
13503 | error (_("probe not found")); | |
13504 | } | |
13505 | ||
348d480f | 13506 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13507 | |
348d480f PA |
13508 | static void |
13509 | tracepoint_re_set (struct breakpoint *b) | |
13510 | { | |
13511 | breakpoint_re_set_default (b); | |
13512 | } | |
876fa593 | 13513 | |
348d480f PA |
13514 | static int |
13515 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13516 | struct address_space *aspace, CORE_ADDR bp_addr, |
13517 | const struct target_waitstatus *ws) | |
348d480f PA |
13518 | { |
13519 | /* By definition, the inferior does not report stops at | |
13520 | tracepoints. */ | |
13521 | return 0; | |
74960c60 VP |
13522 | } |
13523 | ||
13524 | static void | |
348d480f PA |
13525 | tracepoint_print_one_detail (const struct breakpoint *self, |
13526 | struct ui_out *uiout) | |
74960c60 | 13527 | { |
d9b3f62e PA |
13528 | struct tracepoint *tp = (struct tracepoint *) self; |
13529 | if (tp->static_trace_marker_id) | |
348d480f PA |
13530 | { |
13531 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13532 | |
348d480f PA |
13533 | ui_out_text (uiout, "\tmarker id is "); |
13534 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13535 | tp->static_trace_marker_id); |
348d480f PA |
13536 | ui_out_text (uiout, "\n"); |
13537 | } | |
0d381245 VP |
13538 | } |
13539 | ||
a474d7c2 | 13540 | static void |
348d480f | 13541 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13542 | { |
79a45e25 | 13543 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13544 | return; |
cc59ec59 | 13545 | |
348d480f PA |
13546 | switch (b->type) |
13547 | { | |
13548 | case bp_tracepoint: | |
13549 | printf_filtered (_("Tracepoint")); | |
13550 | printf_filtered (_(" %d"), b->number); | |
13551 | break; | |
13552 | case bp_fast_tracepoint: | |
13553 | printf_filtered (_("Fast tracepoint")); | |
13554 | printf_filtered (_(" %d"), b->number); | |
13555 | break; | |
13556 | case bp_static_tracepoint: | |
13557 | printf_filtered (_("Static tracepoint")); | |
13558 | printf_filtered (_(" %d"), b->number); | |
13559 | break; | |
13560 | default: | |
13561 | internal_error (__FILE__, __LINE__, | |
13562 | _("unhandled tracepoint type %d"), (int) b->type); | |
13563 | } | |
13564 | ||
13565 | say_where (b); | |
a474d7c2 PA |
13566 | } |
13567 | ||
348d480f | 13568 | static void |
d9b3f62e | 13569 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13570 | { |
d9b3f62e PA |
13571 | struct tracepoint *tp = (struct tracepoint *) self; |
13572 | ||
13573 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13574 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13575 | else if (self->type == bp_static_tracepoint) |
348d480f | 13576 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13577 | else if (self->type == bp_tracepoint) |
348d480f PA |
13578 | fprintf_unfiltered (fp, "trace"); |
13579 | else | |
13580 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13581 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13582 | |
f00aae0f KS |
13583 | fprintf_unfiltered (fp, " %s", |
13584 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13585 | print_recreate_thread (self, fp); |
13586 | ||
13587 | if (tp->pass_count) | |
13588 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13589 | } |
13590 | ||
983af33b | 13591 | static void |
f00aae0f KS |
13592 | tracepoint_create_sals_from_location (const struct event_location *location, |
13593 | struct linespec_result *canonical, | |
13594 | enum bptype type_wanted) | |
983af33b | 13595 | { |
f00aae0f | 13596 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13597 | } |
13598 | ||
13599 | static void | |
13600 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13601 | struct linespec_result *canonical, | |
983af33b | 13602 | char *cond_string, |
e7e0cddf | 13603 | char *extra_string, |
983af33b SDJ |
13604 | enum bptype type_wanted, |
13605 | enum bpdisp disposition, | |
13606 | int thread, | |
13607 | int task, int ignore_count, | |
13608 | const struct breakpoint_ops *ops, | |
13609 | int from_tty, int enabled, | |
44f238bb | 13610 | int internal, unsigned flags) |
983af33b | 13611 | { |
023fa29b | 13612 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13613 | cond_string, extra_string, |
13614 | type_wanted, | |
983af33b SDJ |
13615 | disposition, thread, task, |
13616 | ignore_count, ops, from_tty, | |
44f238bb | 13617 | enabled, internal, flags); |
983af33b SDJ |
13618 | } |
13619 | ||
13620 | static void | |
f00aae0f KS |
13621 | tracepoint_decode_location (struct breakpoint *b, |
13622 | const struct event_location *location, | |
c2f4122d | 13623 | struct program_space *search_pspace, |
983af33b SDJ |
13624 | struct symtabs_and_lines *sals) |
13625 | { | |
c2f4122d | 13626 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13627 | } |
13628 | ||
2060206e | 13629 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13630 | |
55aa24fb SDJ |
13631 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13632 | static probe. */ | |
13633 | ||
13634 | static void | |
f00aae0f KS |
13635 | tracepoint_probe_create_sals_from_location |
13636 | (const struct event_location *location, | |
13637 | struct linespec_result *canonical, | |
13638 | enum bptype type_wanted) | |
55aa24fb SDJ |
13639 | { |
13640 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13641 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13642 | } |
13643 | ||
13644 | static void | |
f00aae0f KS |
13645 | tracepoint_probe_decode_location (struct breakpoint *b, |
13646 | const struct event_location *location, | |
c2f4122d | 13647 | struct program_space *search_pspace, |
55aa24fb SDJ |
13648 | struct symtabs_and_lines *sals) |
13649 | { | |
13650 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13651 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13652 | } |
13653 | ||
13654 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13655 | ||
5c2b4418 HZ |
13656 | /* Dprintf breakpoint_ops methods. */ |
13657 | ||
13658 | static void | |
13659 | dprintf_re_set (struct breakpoint *b) | |
13660 | { | |
13661 | breakpoint_re_set_default (b); | |
13662 | ||
f00aae0f KS |
13663 | /* extra_string should never be non-NULL for dprintf. */ |
13664 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13665 | |
13666 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13667 | 2 - create a dprintf, which resolves fine. | |
13668 | 3 - disconnect from target 1 | |
13669 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13670 | ||
13671 | After steps #3/#4, you'll want the dprintf command list to | |
13672 | be updated, because target 1 and 2 may well return different | |
13673 | answers for target_can_run_breakpoint_commands(). | |
13674 | Given absence of finer grained resetting, we get to do | |
13675 | it all the time. */ | |
13676 | if (b->extra_string != NULL) | |
13677 | update_dprintf_command_list (b); | |
13678 | } | |
13679 | ||
2d9442cc HZ |
13680 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13681 | ||
13682 | static void | |
13683 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13684 | { | |
f00aae0f KS |
13685 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13686 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13687 | tp->extra_string); |
13688 | print_recreate_thread (tp, fp); | |
13689 | } | |
13690 | ||
9d6e6e84 HZ |
13691 | /* Implement the "after_condition_true" breakpoint_ops method for |
13692 | dprintf. | |
13693 | ||
13694 | dprintf's are implemented with regular commands in their command | |
13695 | list, but we run the commands here instead of before presenting the | |
13696 | stop to the user, as dprintf's don't actually cause a stop. This | |
13697 | also makes it so that the commands of multiple dprintfs at the same | |
13698 | address are all handled. */ | |
13699 | ||
13700 | static void | |
13701 | dprintf_after_condition_true (struct bpstats *bs) | |
13702 | { | |
13703 | struct cleanup *old_chain; | |
13704 | struct bpstats tmp_bs = { NULL }; | |
13705 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13706 | ||
13707 | /* dprintf's never cause a stop. This wasn't set in the | |
13708 | check_status hook instead because that would make the dprintf's | |
13709 | condition not be evaluated. */ | |
13710 | bs->stop = 0; | |
13711 | ||
13712 | /* Run the command list here. Take ownership of it instead of | |
13713 | copying. We never want these commands to run later in | |
13714 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13715 | be set at same address as this dprintf, or even if running the | |
13716 | commands here throws. */ | |
13717 | tmp_bs.commands = bs->commands; | |
13718 | bs->commands = NULL; | |
13719 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13720 | ||
13721 | bpstat_do_actions_1 (&tmp_bs_p); | |
13722 | ||
13723 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13724 | bpstat_do_actions_1 may return early without processing the whole | |
13725 | list. */ | |
13726 | do_cleanups (old_chain); | |
13727 | } | |
13728 | ||
983af33b SDJ |
13729 | /* The breakpoint_ops structure to be used on static tracepoints with |
13730 | markers (`-m'). */ | |
13731 | ||
13732 | static void | |
f00aae0f | 13733 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13734 | struct linespec_result *canonical, |
f00aae0f | 13735 | enum bptype type_wanted) |
983af33b SDJ |
13736 | { |
13737 | struct linespec_sals lsal; | |
f00aae0f KS |
13738 | const char *arg_start, *arg; |
13739 | char *str; | |
13740 | struct cleanup *cleanup; | |
983af33b | 13741 | |
f00aae0f KS |
13742 | arg = arg_start = get_linespec_location (location); |
13743 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13744 | |
f00aae0f KS |
13745 | str = savestring (arg_start, arg - arg_start); |
13746 | cleanup = make_cleanup (xfree, str); | |
13747 | canonical->location = new_linespec_location (&str); | |
13748 | do_cleanups (cleanup); | |
983af33b | 13749 | |
f00aae0f | 13750 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13751 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13752 | } | |
13753 | ||
13754 | static void | |
13755 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13756 | struct linespec_result *canonical, | |
983af33b | 13757 | char *cond_string, |
e7e0cddf | 13758 | char *extra_string, |
983af33b SDJ |
13759 | enum bptype type_wanted, |
13760 | enum bpdisp disposition, | |
13761 | int thread, | |
13762 | int task, int ignore_count, | |
13763 | const struct breakpoint_ops *ops, | |
13764 | int from_tty, int enabled, | |
44f238bb | 13765 | int internal, unsigned flags) |
983af33b SDJ |
13766 | { |
13767 | int i; | |
52d361e1 YQ |
13768 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13769 | canonical->sals, 0); | |
983af33b SDJ |
13770 | |
13771 | /* If the user is creating a static tracepoint by marker id | |
13772 | (strace -m MARKER_ID), then store the sals index, so that | |
13773 | breakpoint_re_set can try to match up which of the newly | |
13774 | found markers corresponds to this one, and, don't try to | |
13775 | expand multiple locations for each sal, given than SALS | |
13776 | already should contain all sals for MARKER_ID. */ | |
13777 | ||
13778 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13779 | { | |
13780 | struct symtabs_and_lines expanded; | |
13781 | struct tracepoint *tp; | |
13782 | struct cleanup *old_chain; | |
f00aae0f | 13783 | struct event_location *location; |
983af33b SDJ |
13784 | |
13785 | expanded.nelts = 1; | |
13786 | expanded.sals = &lsal->sals.sals[i]; | |
13787 | ||
f00aae0f KS |
13788 | location = copy_event_location (canonical->location); |
13789 | old_chain = make_cleanup_delete_event_location (location); | |
983af33b | 13790 | |
4d01a485 | 13791 | tp = new tracepoint (); |
983af33b | 13792 | init_breakpoint_sal (&tp->base, gdbarch, expanded, |
f00aae0f | 13793 | location, NULL, |
e7e0cddf SS |
13794 | cond_string, extra_string, |
13795 | type_wanted, disposition, | |
983af33b | 13796 | thread, task, ignore_count, ops, |
44f238bb | 13797 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13798 | canonical->special_display); |
13799 | /* Given that its possible to have multiple markers with | |
13800 | the same string id, if the user is creating a static | |
13801 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13802 | store the sals index, so that breakpoint_re_set can | |
13803 | try to match up which of the newly found markers | |
13804 | corresponds to this one */ | |
13805 | tp->static_trace_marker_id_idx = i; | |
13806 | ||
13807 | install_breakpoint (internal, &tp->base, 0); | |
13808 | ||
13809 | discard_cleanups (old_chain); | |
13810 | } | |
13811 | } | |
13812 | ||
13813 | static void | |
f00aae0f KS |
13814 | strace_marker_decode_location (struct breakpoint *b, |
13815 | const struct event_location *location, | |
c2f4122d | 13816 | struct program_space *search_pspace, |
983af33b SDJ |
13817 | struct symtabs_and_lines *sals) |
13818 | { | |
13819 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13820 | const char *s = get_linespec_location (location); |
983af33b | 13821 | |
f00aae0f | 13822 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13823 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13824 | { | |
13825 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13826 | sals->nelts = 1; | |
13827 | } | |
13828 | else | |
13829 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13830 | } | |
13831 | ||
13832 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13833 | ||
13834 | static int | |
13835 | strace_marker_p (struct breakpoint *b) | |
13836 | { | |
13837 | return b->ops == &strace_marker_breakpoint_ops; | |
13838 | } | |
13839 | ||
53a5351d | 13840 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13841 | structures. */ |
c906108c SS |
13842 | |
13843 | void | |
fba45db2 | 13844 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13845 | { |
52f0bd74 | 13846 | struct breakpoint *b; |
c906108c | 13847 | |
8a3fe4f8 | 13848 | gdb_assert (bpt != NULL); |
c906108c | 13849 | |
4a64f543 MS |
13850 | /* Has this bp already been deleted? This can happen because |
13851 | multiple lists can hold pointers to bp's. bpstat lists are | |
13852 | especial culprits. | |
13853 | ||
13854 | One example of this happening is a watchpoint's scope bp. When | |
13855 | the scope bp triggers, we notice that the watchpoint is out of | |
13856 | scope, and delete it. We also delete its scope bp. But the | |
13857 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13858 | That bpstat is then checked for auto-deleting bp's, which are | |
13859 | deleted. | |
13860 | ||
13861 | A real solution to this problem might involve reference counts in | |
13862 | bp's, and/or giving them pointers back to their referencing | |
13863 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13864 | storage when no more references were extent. A cheaper bandaid | |
13865 | was chosen. */ | |
c906108c SS |
13866 | if (bpt->type == bp_none) |
13867 | return; | |
13868 | ||
4a64f543 MS |
13869 | /* At least avoid this stale reference until the reference counting |
13870 | of breakpoints gets resolved. */ | |
d0fb5eae | 13871 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13872 | { |
d0fb5eae | 13873 | struct breakpoint *related; |
3a5c3e22 | 13874 | struct watchpoint *w; |
d0fb5eae JK |
13875 | |
13876 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13877 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13878 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13879 | w = (struct watchpoint *) bpt; |
13880 | else | |
13881 | w = NULL; | |
13882 | if (w != NULL) | |
13883 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13884 | |
13885 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13886 | for (related = bpt; related->related_breakpoint != bpt; | |
13887 | related = related->related_breakpoint); | |
13888 | related->related_breakpoint = bpt->related_breakpoint; | |
13889 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13890 | } |
13891 | ||
a9634178 TJB |
13892 | /* watch_command_1 creates a watchpoint but only sets its number if |
13893 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13894 | a problem in that process, we'll be asked to delete the half-created | |
13895 | watchpoint. In that case, don't announce the deletion. */ | |
13896 | if (bpt->number) | |
13897 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13898 | |
c906108c SS |
13899 | if (breakpoint_chain == bpt) |
13900 | breakpoint_chain = bpt->next; | |
13901 | ||
c906108c SS |
13902 | ALL_BREAKPOINTS (b) |
13903 | if (b->next == bpt) | |
c5aa993b JM |
13904 | { |
13905 | b->next = bpt->next; | |
13906 | break; | |
13907 | } | |
c906108c | 13908 | |
f431efe5 PA |
13909 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13910 | been freed. */ | |
13911 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13912 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13913 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13914 | commands are associated with the bpstat; if we remove it here, | |
13915 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13916 | event-top.c won't do anything, and temporary breakpoints with | |
13917 | commands won't work. */ | |
13918 | ||
13919 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13920 | ||
4a64f543 MS |
13921 | /* Now that breakpoint is removed from breakpoint list, update the |
13922 | global location list. This will remove locations that used to | |
13923 | belong to this breakpoint. Do this before freeing the breakpoint | |
13924 | itself, since remove_breakpoint looks at location's owner. It | |
13925 | might be better design to have location completely | |
13926 | self-contained, but it's not the case now. */ | |
44702360 | 13927 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13928 | |
348d480f | 13929 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13930 | /* On the chance that someone will soon try again to delete this |
13931 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13932 | bpt->type = bp_none; |
4d01a485 | 13933 | delete bpt; |
c906108c SS |
13934 | } |
13935 | ||
4d6140d9 AC |
13936 | static void |
13937 | do_delete_breakpoint_cleanup (void *b) | |
13938 | { | |
9a3c8263 | 13939 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13940 | } |
13941 | ||
13942 | struct cleanup * | |
13943 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13944 | { | |
13945 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13946 | } | |
13947 | ||
51be5b68 PA |
13948 | /* Iterator function to call a user-provided callback function once |
13949 | for each of B and its related breakpoints. */ | |
13950 | ||
13951 | static void | |
13952 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13953 | void (*function) (struct breakpoint *, | |
13954 | void *), | |
13955 | void *data) | |
13956 | { | |
13957 | struct breakpoint *related; | |
13958 | ||
13959 | related = b; | |
13960 | do | |
13961 | { | |
13962 | struct breakpoint *next; | |
13963 | ||
13964 | /* FUNCTION may delete RELATED. */ | |
13965 | next = related->related_breakpoint; | |
13966 | ||
13967 | if (next == related) | |
13968 | { | |
13969 | /* RELATED is the last ring entry. */ | |
13970 | function (related, data); | |
13971 | ||
13972 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13973 | B. There's nothing left to do anyway, so just break | |
13974 | out. */ | |
13975 | break; | |
13976 | } | |
13977 | else | |
13978 | function (related, data); | |
13979 | ||
13980 | related = next; | |
13981 | } | |
13982 | while (related != b); | |
13983 | } | |
95a42b64 TT |
13984 | |
13985 | static void | |
13986 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13987 | { | |
13988 | delete_breakpoint (b); | |
13989 | } | |
13990 | ||
51be5b68 PA |
13991 | /* A callback for map_breakpoint_numbers that calls |
13992 | delete_breakpoint. */ | |
13993 | ||
13994 | static void | |
13995 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13996 | { | |
13997 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13998 | } | |
13999 | ||
c906108c | 14000 | void |
fba45db2 | 14001 | delete_command (char *arg, int from_tty) |
c906108c | 14002 | { |
35df4500 | 14003 | struct breakpoint *b, *b_tmp; |
c906108c | 14004 | |
ea9365bb TT |
14005 | dont_repeat (); |
14006 | ||
c906108c SS |
14007 | if (arg == 0) |
14008 | { | |
14009 | int breaks_to_delete = 0; | |
14010 | ||
46c6471b PA |
14011 | /* Delete all breakpoints if no argument. Do not delete |
14012 | internal breakpoints, these have to be deleted with an | |
14013 | explicit breakpoint number argument. */ | |
c5aa993b | 14014 | ALL_BREAKPOINTS (b) |
46c6471b | 14015 | if (user_breakpoint_p (b)) |
973d738b DJ |
14016 | { |
14017 | breaks_to_delete = 1; | |
14018 | break; | |
14019 | } | |
c906108c SS |
14020 | |
14021 | /* Ask user only if there are some breakpoints to delete. */ | |
14022 | if (!from_tty | |
e2e0b3e5 | 14023 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14024 | { |
35df4500 | 14025 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14026 | if (user_breakpoint_p (b)) |
c5aa993b | 14027 | delete_breakpoint (b); |
c906108c SS |
14028 | } |
14029 | } | |
14030 | else | |
51be5b68 | 14031 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14032 | } |
14033 | ||
c2f4122d PA |
14034 | /* Return true if all locations of B bound to PSPACE are pending. If |
14035 | PSPACE is NULL, all locations of all program spaces are | |
14036 | considered. */ | |
14037 | ||
0d381245 | 14038 | static int |
c2f4122d | 14039 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 14040 | { |
c2f4122d PA |
14041 | struct bp_location *loc; |
14042 | ||
14043 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
14044 | if ((pspace == NULL | |
14045 | || loc->pspace == pspace) | |
14046 | && !loc->shlib_disabled | |
8645ff69 | 14047 | && !loc->pspace->executing_startup) |
0d381245 VP |
14048 | return 0; |
14049 | return 1; | |
fe3f5fa8 VP |
14050 | } |
14051 | ||
776592bf DE |
14052 | /* Subroutine of update_breakpoint_locations to simplify it. |
14053 | Return non-zero if multiple fns in list LOC have the same name. | |
14054 | Null names are ignored. */ | |
14055 | ||
14056 | static int | |
14057 | ambiguous_names_p (struct bp_location *loc) | |
14058 | { | |
14059 | struct bp_location *l; | |
14060 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14061 | (int (*) (const void *, |
14062 | const void *)) streq, | |
776592bf DE |
14063 | NULL, xcalloc, xfree); |
14064 | ||
14065 | for (l = loc; l != NULL; l = l->next) | |
14066 | { | |
14067 | const char **slot; | |
14068 | const char *name = l->function_name; | |
14069 | ||
14070 | /* Allow for some names to be NULL, ignore them. */ | |
14071 | if (name == NULL) | |
14072 | continue; | |
14073 | ||
14074 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14075 | INSERT); | |
4a64f543 MS |
14076 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14077 | returns NULL. */ | |
776592bf DE |
14078 | if (*slot != NULL) |
14079 | { | |
14080 | htab_delete (htab); | |
14081 | return 1; | |
14082 | } | |
14083 | *slot = name; | |
14084 | } | |
14085 | ||
14086 | htab_delete (htab); | |
14087 | return 0; | |
14088 | } | |
14089 | ||
0fb4aa4b PA |
14090 | /* When symbols change, it probably means the sources changed as well, |
14091 | and it might mean the static tracepoint markers are no longer at | |
14092 | the same address or line numbers they used to be at last we | |
14093 | checked. Losing your static tracepoints whenever you rebuild is | |
14094 | undesirable. This function tries to resync/rematch gdb static | |
14095 | tracepoints with the markers on the target, for static tracepoints | |
14096 | that have not been set by marker id. Static tracepoint that have | |
14097 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14098 | The heuristic is: | |
14099 | ||
14100 | 1) For a tracepoint set at a specific address, look for a marker at | |
14101 | the old PC. If one is found there, assume to be the same marker. | |
14102 | If the name / string id of the marker found is different from the | |
14103 | previous known name, assume that means the user renamed the marker | |
14104 | in the sources, and output a warning. | |
14105 | ||
14106 | 2) For a tracepoint set at a given line number, look for a marker | |
14107 | at the new address of the old line number. If one is found there, | |
14108 | assume to be the same marker. If the name / string id of the | |
14109 | marker found is different from the previous known name, assume that | |
14110 | means the user renamed the marker in the sources, and output a | |
14111 | warning. | |
14112 | ||
14113 | 3) If a marker is no longer found at the same address or line, it | |
14114 | may mean the marker no longer exists. But it may also just mean | |
14115 | the code changed a bit. Maybe the user added a few lines of code | |
14116 | that made the marker move up or down (in line number terms). Ask | |
14117 | the target for info about the marker with the string id as we knew | |
14118 | it. If found, update line number and address in the matching | |
14119 | static tracepoint. This will get confused if there's more than one | |
14120 | marker with the same ID (possible in UST, although unadvised | |
14121 | precisely because it confuses tools). */ | |
14122 | ||
14123 | static struct symtab_and_line | |
14124 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14125 | { | |
d9b3f62e | 14126 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14127 | struct static_tracepoint_marker marker; |
14128 | CORE_ADDR pc; | |
0fb4aa4b PA |
14129 | |
14130 | pc = sal.pc; | |
14131 | if (sal.line) | |
14132 | find_line_pc (sal.symtab, sal.line, &pc); | |
14133 | ||
14134 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14135 | { | |
d9b3f62e | 14136 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14137 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14138 | b->number, | |
d9b3f62e | 14139 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14140 | |
d9b3f62e PA |
14141 | xfree (tp->static_trace_marker_id); |
14142 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14143 | release_static_tracepoint_marker (&marker); |
14144 | ||
14145 | return sal; | |
14146 | } | |
14147 | ||
14148 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14149 | by string ID. */ | |
14150 | if (!sal.explicit_pc | |
14151 | && sal.line != 0 | |
14152 | && sal.symtab != NULL | |
d9b3f62e | 14153 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14154 | { |
14155 | VEC(static_tracepoint_marker_p) *markers; | |
14156 | ||
14157 | markers | |
d9b3f62e | 14158 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14159 | |
14160 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14161 | { | |
80e1d417 | 14162 | struct symtab_and_line sal2; |
0fb4aa4b | 14163 | struct symbol *sym; |
80e1d417 | 14164 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14165 | struct ui_out *uiout = current_uiout; |
67994074 | 14166 | struct explicit_location explicit_loc; |
0fb4aa4b | 14167 | |
80e1d417 | 14168 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14169 | |
d9b3f62e | 14170 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14171 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14172 | |
14173 | warning (_("marker for static tracepoint %d (%s) not " | |
14174 | "found at previous line number"), | |
d9b3f62e | 14175 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14176 | |
80e1d417 | 14177 | init_sal (&sal2); |
0fb4aa4b | 14178 | |
80e1d417 | 14179 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14180 | |
80e1d417 AS |
14181 | sal2 = find_pc_line (tpmarker->address, 0); |
14182 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14183 | ui_out_text (uiout, "Now in "); |
14184 | if (sym) | |
14185 | { | |
14186 | ui_out_field_string (uiout, "func", | |
14187 | SYMBOL_PRINT_NAME (sym)); | |
14188 | ui_out_text (uiout, " at "); | |
14189 | } | |
05cba821 JK |
14190 | ui_out_field_string (uiout, "file", |
14191 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14192 | ui_out_text (uiout, ":"); |
14193 | ||
14194 | if (ui_out_is_mi_like_p (uiout)) | |
14195 | { | |
0b0865da | 14196 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14197 | |
f35a17b5 | 14198 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14199 | } |
14200 | ||
80e1d417 | 14201 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14202 | ui_out_text (uiout, "\n"); |
14203 | ||
80e1d417 | 14204 | b->loc->line_number = sal2.line; |
2f202fde | 14205 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14206 | |
f00aae0f | 14207 | delete_event_location (b->location); |
67994074 KS |
14208 | initialize_explicit_location (&explicit_loc); |
14209 | explicit_loc.source_filename | |
00e52e53 | 14210 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14211 | explicit_loc.line_offset.offset = b->loc->line_number; |
14212 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
14213 | b->location = new_explicit_location (&explicit_loc); | |
0fb4aa4b PA |
14214 | |
14215 | /* Might be nice to check if function changed, and warn if | |
14216 | so. */ | |
14217 | ||
80e1d417 | 14218 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14219 | } |
14220 | } | |
14221 | return sal; | |
14222 | } | |
14223 | ||
8d3788bd VP |
14224 | /* Returns 1 iff locations A and B are sufficiently same that |
14225 | we don't need to report breakpoint as changed. */ | |
14226 | ||
14227 | static int | |
14228 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14229 | { | |
14230 | while (a && b) | |
14231 | { | |
14232 | if (a->address != b->address) | |
14233 | return 0; | |
14234 | ||
14235 | if (a->shlib_disabled != b->shlib_disabled) | |
14236 | return 0; | |
14237 | ||
14238 | if (a->enabled != b->enabled) | |
14239 | return 0; | |
14240 | ||
14241 | a = a->next; | |
14242 | b = b->next; | |
14243 | } | |
14244 | ||
14245 | if ((a == NULL) != (b == NULL)) | |
14246 | return 0; | |
14247 | ||
14248 | return 1; | |
14249 | } | |
14250 | ||
c2f4122d PA |
14251 | /* Split all locations of B that are bound to PSPACE out of B's |
14252 | location list to a separate list and return that list's head. If | |
14253 | PSPACE is NULL, hoist out all locations of B. */ | |
14254 | ||
14255 | static struct bp_location * | |
14256 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14257 | { | |
14258 | struct bp_location head; | |
14259 | struct bp_location *i = b->loc; | |
14260 | struct bp_location **i_link = &b->loc; | |
14261 | struct bp_location *hoisted = &head; | |
14262 | ||
14263 | if (pspace == NULL) | |
14264 | { | |
14265 | i = b->loc; | |
14266 | b->loc = NULL; | |
14267 | return i; | |
14268 | } | |
14269 | ||
14270 | head.next = NULL; | |
14271 | ||
14272 | while (i != NULL) | |
14273 | { | |
14274 | if (i->pspace == pspace) | |
14275 | { | |
14276 | *i_link = i->next; | |
14277 | i->next = NULL; | |
14278 | hoisted->next = i; | |
14279 | hoisted = i; | |
14280 | } | |
14281 | else | |
14282 | i_link = &i->next; | |
14283 | i = *i_link; | |
14284 | } | |
14285 | ||
14286 | return head.next; | |
14287 | } | |
14288 | ||
14289 | /* Create new breakpoint locations for B (a hardware or software | |
14290 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14291 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14292 | FILTER_PSPACE. Locations of other program spaces are left | |
14293 | untouched. */ | |
f1310107 | 14294 | |
0e30163f | 14295 | void |
0d381245 | 14296 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14297 | struct program_space *filter_pspace, |
f1310107 TJB |
14298 | struct symtabs_and_lines sals, |
14299 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14300 | { |
14301 | int i; | |
c2f4122d | 14302 | struct bp_location *existing_locations; |
0d381245 | 14303 | |
f8eba3c6 TT |
14304 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14305 | { | |
14306 | /* Ranged breakpoints have only one start location and one end | |
14307 | location. */ | |
14308 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14309 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14310 | "multiple locations found\n"), | |
14311 | b->number); | |
14312 | return; | |
14313 | } | |
f1310107 | 14314 | |
4a64f543 MS |
14315 | /* If there's no new locations, and all existing locations are |
14316 | pending, don't do anything. This optimizes the common case where | |
14317 | all locations are in the same shared library, that was unloaded. | |
14318 | We'd like to retain the location, so that when the library is | |
14319 | loaded again, we don't loose the enabled/disabled status of the | |
14320 | individual locations. */ | |
c2f4122d | 14321 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14322 | return; |
14323 | ||
c2f4122d | 14324 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14325 | |
0d381245 | 14326 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14327 | { |
f8eba3c6 TT |
14328 | struct bp_location *new_loc; |
14329 | ||
14330 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14331 | ||
14332 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14333 | |
0d381245 VP |
14334 | /* Reparse conditions, they might contain references to the |
14335 | old symtab. */ | |
14336 | if (b->cond_string != NULL) | |
14337 | { | |
bbc13ae3 | 14338 | const char *s; |
fe3f5fa8 | 14339 | |
0d381245 | 14340 | s = b->cond_string; |
492d29ea | 14341 | TRY |
0d381245 | 14342 | { |
1bb9788d TT |
14343 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14344 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14345 | 0); |
14346 | } | |
492d29ea | 14347 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14348 | { |
3e43a32a MS |
14349 | warning (_("failed to reevaluate condition " |
14350 | "for breakpoint %d: %s"), | |
0d381245 VP |
14351 | b->number, e.message); |
14352 | new_loc->enabled = 0; | |
14353 | } | |
492d29ea | 14354 | END_CATCH |
0d381245 | 14355 | } |
fe3f5fa8 | 14356 | |
f1310107 TJB |
14357 | if (sals_end.nelts) |
14358 | { | |
14359 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14360 | ||
14361 | new_loc->length = end - sals.sals[0].pc + 1; | |
14362 | } | |
0d381245 | 14363 | } |
fe3f5fa8 | 14364 | |
4a64f543 MS |
14365 | /* If possible, carry over 'disable' status from existing |
14366 | breakpoints. */ | |
0d381245 VP |
14367 | { |
14368 | struct bp_location *e = existing_locations; | |
776592bf DE |
14369 | /* If there are multiple breakpoints with the same function name, |
14370 | e.g. for inline functions, comparing function names won't work. | |
14371 | Instead compare pc addresses; this is just a heuristic as things | |
14372 | may have moved, but in practice it gives the correct answer | |
14373 | often enough until a better solution is found. */ | |
14374 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14375 | ||
0d381245 VP |
14376 | for (; e; e = e->next) |
14377 | { | |
14378 | if (!e->enabled && e->function_name) | |
14379 | { | |
14380 | struct bp_location *l = b->loc; | |
776592bf DE |
14381 | if (have_ambiguous_names) |
14382 | { | |
14383 | for (; l; l = l->next) | |
f1310107 | 14384 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14385 | { |
14386 | l->enabled = 0; | |
14387 | break; | |
14388 | } | |
14389 | } | |
14390 | else | |
14391 | { | |
14392 | for (; l; l = l->next) | |
14393 | if (l->function_name | |
14394 | && strcmp (e->function_name, l->function_name) == 0) | |
14395 | { | |
14396 | l->enabled = 0; | |
14397 | break; | |
14398 | } | |
14399 | } | |
0d381245 VP |
14400 | } |
14401 | } | |
14402 | } | |
fe3f5fa8 | 14403 | |
8d3788bd VP |
14404 | if (!locations_are_equal (existing_locations, b->loc)) |
14405 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14406 | } |
14407 | ||
f00aae0f | 14408 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14409 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14410 | ||
14411 | static struct symtabs_and_lines | |
f00aae0f | 14412 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14413 | struct program_space *search_pspace, int *found) |
ef23e705 | 14414 | { |
02d20e4a | 14415 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14416 | struct gdb_exception exception = exception_none; |
ef23e705 | 14417 | |
983af33b | 14418 | gdb_assert (b->ops != NULL); |
ef23e705 | 14419 | |
492d29ea | 14420 | TRY |
ef23e705 | 14421 | { |
c2f4122d | 14422 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14423 | } |
492d29ea | 14424 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14425 | { |
14426 | int not_found_and_ok = 0; | |
492d29ea PA |
14427 | |
14428 | exception = e; | |
14429 | ||
ef23e705 TJB |
14430 | /* For pending breakpoints, it's expected that parsing will |
14431 | fail until the right shared library is loaded. User has | |
14432 | already told to create pending breakpoints and don't need | |
14433 | extra messages. If breakpoint is in bp_shlib_disabled | |
14434 | state, then user already saw the message about that | |
14435 | breakpoint being disabled, and don't want to see more | |
14436 | errors. */ | |
58438ac1 | 14437 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14438 | && (b->condition_not_parsed |
14439 | || (b->loc != NULL | |
14440 | && search_pspace != NULL | |
14441 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14442 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14443 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14444 | || b->enable_state == bp_disabled)) |
14445 | not_found_and_ok = 1; | |
14446 | ||
14447 | if (!not_found_and_ok) | |
14448 | { | |
14449 | /* We surely don't want to warn about the same breakpoint | |
14450 | 10 times. One solution, implemented here, is disable | |
14451 | the breakpoint on error. Another solution would be to | |
14452 | have separate 'warning emitted' flag. Since this | |
14453 | happens only when a binary has changed, I don't know | |
14454 | which approach is better. */ | |
14455 | b->enable_state = bp_disabled; | |
14456 | throw_exception (e); | |
14457 | } | |
14458 | } | |
492d29ea | 14459 | END_CATCH |
ef23e705 | 14460 | |
492d29ea | 14461 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14462 | { |
f8eba3c6 | 14463 | int i; |
ef23e705 | 14464 | |
f8eba3c6 TT |
14465 | for (i = 0; i < sals.nelts; ++i) |
14466 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14467 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14468 | { |
ed1d1739 KS |
14469 | char *cond_string, *extra_string; |
14470 | int thread, task; | |
ef23e705 | 14471 | |
f00aae0f | 14472 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14473 | &cond_string, &thread, &task, |
14474 | &extra_string); | |
f00aae0f | 14475 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14476 | if (cond_string) |
14477 | b->cond_string = cond_string; | |
14478 | b->thread = thread; | |
14479 | b->task = task; | |
e7e0cddf | 14480 | if (extra_string) |
f00aae0f KS |
14481 | { |
14482 | xfree (b->extra_string); | |
14483 | b->extra_string = extra_string; | |
14484 | } | |
ef23e705 TJB |
14485 | b->condition_not_parsed = 0; |
14486 | } | |
14487 | ||
983af33b | 14488 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14489 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14490 | |
58438ac1 TT |
14491 | *found = 1; |
14492 | } | |
14493 | else | |
14494 | *found = 0; | |
ef23e705 TJB |
14495 | |
14496 | return sals; | |
14497 | } | |
14498 | ||
348d480f PA |
14499 | /* The default re_set method, for typical hardware or software |
14500 | breakpoints. Reevaluate the breakpoint and recreate its | |
14501 | locations. */ | |
14502 | ||
14503 | static void | |
28010a5d | 14504 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14505 | { |
14506 | int found; | |
f1310107 | 14507 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14508 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14509 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14510 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14511 | |
c2f4122d | 14512 | sals = location_to_sals (b, b->location, filter_pspace, &found); |
ef23e705 TJB |
14513 | if (found) |
14514 | { | |
14515 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14516 | expanded = sals; |
ef23e705 TJB |
14517 | } |
14518 | ||
f00aae0f | 14519 | if (b->location_range_end != NULL) |
f1310107 | 14520 | { |
c2f4122d PA |
14521 | sals_end = location_to_sals (b, b->location_range_end, |
14522 | filter_pspace, &found); | |
f1310107 TJB |
14523 | if (found) |
14524 | { | |
14525 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14526 | expanded_end = sals_end; |
f1310107 TJB |
14527 | } |
14528 | } | |
14529 | ||
c2f4122d | 14530 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14531 | } |
14532 | ||
983af33b SDJ |
14533 | /* Default method for creating SALs from an address string. It basically |
14534 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14535 | ||
14536 | static void | |
f00aae0f KS |
14537 | create_sals_from_location_default (const struct event_location *location, |
14538 | struct linespec_result *canonical, | |
14539 | enum bptype type_wanted) | |
983af33b | 14540 | { |
f00aae0f | 14541 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14542 | } |
14543 | ||
14544 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14545 | function for the `create_breakpoints_sal' method of | |
14546 | breakpoint_ops. */ | |
14547 | ||
14548 | static void | |
14549 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14550 | struct linespec_result *canonical, | |
983af33b | 14551 | char *cond_string, |
e7e0cddf | 14552 | char *extra_string, |
983af33b SDJ |
14553 | enum bptype type_wanted, |
14554 | enum bpdisp disposition, | |
14555 | int thread, | |
14556 | int task, int ignore_count, | |
14557 | const struct breakpoint_ops *ops, | |
14558 | int from_tty, int enabled, | |
44f238bb | 14559 | int internal, unsigned flags) |
983af33b SDJ |
14560 | { |
14561 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14562 | extra_string, |
983af33b SDJ |
14563 | type_wanted, disposition, |
14564 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14565 | enabled, internal, flags); |
983af33b SDJ |
14566 | } |
14567 | ||
14568 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14569 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14570 | |
14571 | static void | |
f00aae0f KS |
14572 | decode_location_default (struct breakpoint *b, |
14573 | const struct event_location *location, | |
c2f4122d | 14574 | struct program_space *search_pspace, |
983af33b SDJ |
14575 | struct symtabs_and_lines *sals) |
14576 | { | |
14577 | struct linespec_result canonical; | |
14578 | ||
14579 | init_linespec_result (&canonical); | |
c2f4122d | 14580 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14581 | (struct symtab *) NULL, 0, |
14582 | &canonical, multiple_symbols_all, | |
14583 | b->filter); | |
14584 | ||
14585 | /* We should get 0 or 1 resulting SALs. */ | |
14586 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14587 | ||
14588 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14589 | { | |
14590 | struct linespec_sals *lsal; | |
14591 | ||
14592 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14593 | *sals = lsal->sals; | |
14594 | /* Arrange it so the destructor does not free the | |
14595 | contents. */ | |
14596 | lsal->sals.sals = NULL; | |
14597 | } | |
14598 | ||
14599 | destroy_linespec_result (&canonical); | |
14600 | } | |
14601 | ||
28010a5d PA |
14602 | /* Prepare the global context for a re-set of breakpoint B. */ |
14603 | ||
14604 | static struct cleanup * | |
14605 | prepare_re_set_context (struct breakpoint *b) | |
14606 | { | |
28010a5d | 14607 | input_radix = b->input_radix; |
28010a5d PA |
14608 | set_language (b->language); |
14609 | ||
c2f4122d | 14610 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14611 | } |
14612 | ||
c906108c SS |
14613 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14614 | The value we return ends up being the return value from catch_errors. | |
14615 | Unused in this case. */ | |
14616 | ||
14617 | static int | |
4efb68b1 | 14618 | breakpoint_re_set_one (void *bint) |
c906108c | 14619 | { |
4a64f543 | 14620 | /* Get past catch_errs. */ |
53a5351d | 14621 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14622 | struct cleanup *cleanups; |
c906108c | 14623 | |
348d480f PA |
14624 | cleanups = prepare_re_set_context (b); |
14625 | b->ops->re_set (b); | |
14626 | do_cleanups (cleanups); | |
c906108c SS |
14627 | return 0; |
14628 | } | |
14629 | ||
c2f4122d PA |
14630 | /* Re-set breakpoint locations for the current program space. |
14631 | Locations bound to other program spaces are left untouched. */ | |
14632 | ||
c906108c | 14633 | void |
69de3c6a | 14634 | breakpoint_re_set (void) |
c906108c | 14635 | { |
35df4500 | 14636 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14637 | enum language save_language; |
14638 | int save_input_radix; | |
6c95b8df | 14639 | struct cleanup *old_chain; |
c5aa993b | 14640 | |
c906108c SS |
14641 | save_language = current_language->la_language; |
14642 | save_input_radix = input_radix; | |
c2f4122d | 14643 | old_chain = save_current_space_and_thread (); |
6c95b8df | 14644 | |
2a7f3dff PA |
14645 | /* Note: we must not try to insert locations until after all |
14646 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14647 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14648 | hadn't been re-set yet, and thus may have stale locations. */ | |
14649 | ||
35df4500 | 14650 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14651 | { |
4a64f543 | 14652 | /* Format possible error msg. */ |
fe3f5fa8 | 14653 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14654 | b->number); |
14655 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14656 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14657 | do_cleanups (cleanups); |
c5aa993b | 14658 | } |
c906108c SS |
14659 | set_language (save_language); |
14660 | input_radix = save_input_radix; | |
e62c965a | 14661 | |
0756c555 | 14662 | jit_breakpoint_re_set (); |
4efc6507 | 14663 | |
6c95b8df PA |
14664 | do_cleanups (old_chain); |
14665 | ||
af02033e PP |
14666 | create_overlay_event_breakpoint (); |
14667 | create_longjmp_master_breakpoint (); | |
14668 | create_std_terminate_master_breakpoint (); | |
186c406b | 14669 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14670 | |
14671 | /* Now we can insert. */ | |
14672 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14673 | } |
14674 | \f | |
c906108c SS |
14675 | /* Reset the thread number of this breakpoint: |
14676 | ||
14677 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14678 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14679 | void |
fba45db2 | 14680 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14681 | { |
14682 | if (b->thread != -1) | |
14683 | { | |
39f77062 | 14684 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14685 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14686 | |
14687 | /* We're being called after following a fork. The new fork is | |
14688 | selected as current, and unless this was a vfork will have a | |
14689 | different program space from the original thread. Reset that | |
14690 | as well. */ | |
14691 | b->loc->pspace = current_program_space; | |
c906108c SS |
14692 | } |
14693 | } | |
14694 | ||
03ac34d5 MS |
14695 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14696 | If from_tty is nonzero, it prints a message to that effect, | |
14697 | which ends with a period (no newline). */ | |
14698 | ||
c906108c | 14699 | void |
fba45db2 | 14700 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14701 | { |
52f0bd74 | 14702 | struct breakpoint *b; |
c906108c SS |
14703 | |
14704 | if (count < 0) | |
14705 | count = 0; | |
14706 | ||
14707 | ALL_BREAKPOINTS (b) | |
14708 | if (b->number == bptnum) | |
c5aa993b | 14709 | { |
d77f58be SS |
14710 | if (is_tracepoint (b)) |
14711 | { | |
14712 | if (from_tty && count != 0) | |
14713 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14714 | bptnum); | |
14715 | return; | |
14716 | } | |
14717 | ||
c5aa993b | 14718 | b->ignore_count = count; |
221ea385 KS |
14719 | if (from_tty) |
14720 | { | |
14721 | if (count == 0) | |
3e43a32a MS |
14722 | printf_filtered (_("Will stop next time " |
14723 | "breakpoint %d is reached."), | |
221ea385 KS |
14724 | bptnum); |
14725 | else if (count == 1) | |
a3f17187 | 14726 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14727 | bptnum); |
14728 | else | |
3e43a32a MS |
14729 | printf_filtered (_("Will ignore next %d " |
14730 | "crossings of breakpoint %d."), | |
221ea385 KS |
14731 | count, bptnum); |
14732 | } | |
8d3788bd | 14733 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14734 | return; |
14735 | } | |
c906108c | 14736 | |
8a3fe4f8 | 14737 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14738 | } |
14739 | ||
c906108c SS |
14740 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14741 | ||
14742 | static void | |
fba45db2 | 14743 | ignore_command (char *args, int from_tty) |
c906108c SS |
14744 | { |
14745 | char *p = args; | |
52f0bd74 | 14746 | int num; |
c906108c SS |
14747 | |
14748 | if (p == 0) | |
e2e0b3e5 | 14749 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14750 | |
c906108c | 14751 | num = get_number (&p); |
5c44784c | 14752 | if (num == 0) |
8a3fe4f8 | 14753 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14754 | if (*p == 0) |
8a3fe4f8 | 14755 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14756 | |
14757 | set_ignore_count (num, | |
14758 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14759 | from_tty); | |
221ea385 KS |
14760 | if (from_tty) |
14761 | printf_filtered ("\n"); | |
c906108c SS |
14762 | } |
14763 | \f | |
14764 | /* Call FUNCTION on each of the breakpoints | |
14765 | whose numbers are given in ARGS. */ | |
14766 | ||
14767 | static void | |
896b6bda PA |
14768 | map_breakpoint_numbers (const char *args, |
14769 | void (*function) (struct breakpoint *, | |
14770 | void *), | |
95a42b64 | 14771 | void *data) |
c906108c | 14772 | { |
52f0bd74 AC |
14773 | int num; |
14774 | struct breakpoint *b, *tmp; | |
c906108c | 14775 | |
b9d61307 | 14776 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14777 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14778 | |
bfd28288 | 14779 | number_or_range_parser parser (args); |
197f0a60 | 14780 | |
bfd28288 | 14781 | while (!parser.finished ()) |
c906108c | 14782 | { |
bfd28288 PA |
14783 | const char *p = parser.cur_tok (); |
14784 | bool match = false; | |
197f0a60 | 14785 | |
bfd28288 | 14786 | num = parser.get_number (); |
5c44784c | 14787 | if (num == 0) |
c5aa993b | 14788 | { |
8a3fe4f8 | 14789 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14790 | } |
14791 | else | |
14792 | { | |
14793 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14794 | if (b->number == num) | |
14795 | { | |
bfd28288 | 14796 | match = true; |
cdac0397 | 14797 | function (b, data); |
11cf8741 | 14798 | break; |
5c44784c | 14799 | } |
bfd28288 | 14800 | if (!match) |
a3f17187 | 14801 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14802 | } |
c906108c SS |
14803 | } |
14804 | } | |
14805 | ||
0d381245 VP |
14806 | static struct bp_location * |
14807 | find_location_by_number (char *number) | |
14808 | { | |
14809 | char *dot = strchr (number, '.'); | |
14810 | char *p1; | |
14811 | int bp_num; | |
14812 | int loc_num; | |
14813 | struct breakpoint *b; | |
14814 | struct bp_location *loc; | |
14815 | ||
14816 | *dot = '\0'; | |
14817 | ||
14818 | p1 = number; | |
197f0a60 | 14819 | bp_num = get_number (&p1); |
0d381245 VP |
14820 | if (bp_num == 0) |
14821 | error (_("Bad breakpoint number '%s'"), number); | |
14822 | ||
14823 | ALL_BREAKPOINTS (b) | |
14824 | if (b->number == bp_num) | |
14825 | { | |
14826 | break; | |
14827 | } | |
14828 | ||
14829 | if (!b || b->number != bp_num) | |
14830 | error (_("Bad breakpoint number '%s'"), number); | |
14831 | ||
14832 | p1 = dot+1; | |
197f0a60 | 14833 | loc_num = get_number (&p1); |
0d381245 VP |
14834 | if (loc_num == 0) |
14835 | error (_("Bad breakpoint location number '%s'"), number); | |
14836 | ||
14837 | --loc_num; | |
14838 | loc = b->loc; | |
14839 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14840 | ; | |
14841 | if (!loc) | |
14842 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14843 | ||
14844 | return loc; | |
14845 | } | |
14846 | ||
14847 | ||
1900040c MS |
14848 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14849 | If from_tty is nonzero, it prints a message to that effect, | |
14850 | which ends with a period (no newline). */ | |
14851 | ||
c906108c | 14852 | void |
fba45db2 | 14853 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14854 | { |
14855 | /* Never disable a watchpoint scope breakpoint; we want to | |
14856 | hit them when we leave scope so we can delete both the | |
14857 | watchpoint and its scope breakpoint at that time. */ | |
14858 | if (bpt->type == bp_watchpoint_scope) | |
14859 | return; | |
14860 | ||
b5de0fa7 | 14861 | bpt->enable_state = bp_disabled; |
c906108c | 14862 | |
b775012e LM |
14863 | /* Mark breakpoint locations modified. */ |
14864 | mark_breakpoint_modified (bpt); | |
14865 | ||
d248b706 KY |
14866 | if (target_supports_enable_disable_tracepoint () |
14867 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14868 | { | |
14869 | struct bp_location *location; | |
14870 | ||
14871 | for (location = bpt->loc; location; location = location->next) | |
14872 | target_disable_tracepoint (location); | |
14873 | } | |
14874 | ||
44702360 | 14875 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14876 | |
8d3788bd | 14877 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14878 | } |
14879 | ||
51be5b68 PA |
14880 | /* A callback for iterate_over_related_breakpoints. */ |
14881 | ||
14882 | static void | |
14883 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14884 | { | |
14885 | disable_breakpoint (b); | |
14886 | } | |
14887 | ||
95a42b64 TT |
14888 | /* A callback for map_breakpoint_numbers that calls |
14889 | disable_breakpoint. */ | |
14890 | ||
14891 | static void | |
14892 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14893 | { | |
51be5b68 | 14894 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14895 | } |
14896 | ||
c906108c | 14897 | static void |
fba45db2 | 14898 | disable_command (char *args, int from_tty) |
c906108c | 14899 | { |
c906108c | 14900 | if (args == 0) |
46c6471b PA |
14901 | { |
14902 | struct breakpoint *bpt; | |
14903 | ||
14904 | ALL_BREAKPOINTS (bpt) | |
14905 | if (user_breakpoint_p (bpt)) | |
14906 | disable_breakpoint (bpt); | |
14907 | } | |
9eaabc75 | 14908 | else |
0d381245 | 14909 | { |
9eaabc75 MW |
14910 | char *num = extract_arg (&args); |
14911 | ||
14912 | while (num) | |
d248b706 | 14913 | { |
9eaabc75 | 14914 | if (strchr (num, '.')) |
b775012e | 14915 | { |
9eaabc75 MW |
14916 | struct bp_location *loc = find_location_by_number (num); |
14917 | ||
14918 | if (loc) | |
14919 | { | |
14920 | if (loc->enabled) | |
14921 | { | |
14922 | loc->enabled = 0; | |
14923 | mark_breakpoint_location_modified (loc); | |
14924 | } | |
14925 | if (target_supports_enable_disable_tracepoint () | |
14926 | && current_trace_status ()->running && loc->owner | |
14927 | && is_tracepoint (loc->owner)) | |
14928 | target_disable_tracepoint (loc); | |
14929 | } | |
44702360 | 14930 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14931 | } |
9eaabc75 MW |
14932 | else |
14933 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14934 | num = extract_arg (&args); | |
d248b706 | 14935 | } |
0d381245 | 14936 | } |
c906108c SS |
14937 | } |
14938 | ||
14939 | static void | |
816338b5 SS |
14940 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14941 | int count) | |
c906108c | 14942 | { |
afe38095 | 14943 | int target_resources_ok; |
c906108c SS |
14944 | |
14945 | if (bpt->type == bp_hardware_breakpoint) | |
14946 | { | |
14947 | int i; | |
c5aa993b | 14948 | i = hw_breakpoint_used_count (); |
53a5351d | 14949 | target_resources_ok = |
d92524f1 | 14950 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14951 | i + 1, 0); |
c906108c | 14952 | if (target_resources_ok == 0) |
8a3fe4f8 | 14953 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14954 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14955 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14956 | } |
14957 | ||
cc60f2e3 | 14958 | if (is_watchpoint (bpt)) |
c906108c | 14959 | { |
d07205c2 | 14960 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14961 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14962 | |
492d29ea | 14963 | TRY |
c906108c | 14964 | { |
3a5c3e22 PA |
14965 | struct watchpoint *w = (struct watchpoint *) bpt; |
14966 | ||
1e718ff1 TJB |
14967 | orig_enable_state = bpt->enable_state; |
14968 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14969 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14970 | } |
492d29ea | 14971 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14972 | { |
1e718ff1 | 14973 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14974 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14975 | bpt->number); | |
14976 | return; | |
c5aa993b | 14977 | } |
492d29ea | 14978 | END_CATCH |
c906108c | 14979 | } |
0101ce28 | 14980 | |
b775012e LM |
14981 | bpt->enable_state = bp_enabled; |
14982 | ||
14983 | /* Mark breakpoint locations modified. */ | |
14984 | mark_breakpoint_modified (bpt); | |
14985 | ||
d248b706 KY |
14986 | if (target_supports_enable_disable_tracepoint () |
14987 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14988 | { | |
14989 | struct bp_location *location; | |
14990 | ||
14991 | for (location = bpt->loc; location; location = location->next) | |
14992 | target_enable_tracepoint (location); | |
14993 | } | |
14994 | ||
b4c291bb | 14995 | bpt->disposition = disposition; |
816338b5 | 14996 | bpt->enable_count = count; |
44702360 | 14997 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14998 | |
8d3788bd | 14999 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15000 | } |
15001 | ||
fe3f5fa8 | 15002 | |
c906108c | 15003 | void |
fba45db2 | 15004 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 15005 | { |
816338b5 | 15006 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
15007 | } |
15008 | ||
15009 | static void | |
15010 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
15011 | { | |
15012 | enable_breakpoint (bpt); | |
c906108c SS |
15013 | } |
15014 | ||
95a42b64 TT |
15015 | /* A callback for map_breakpoint_numbers that calls |
15016 | enable_breakpoint. */ | |
15017 | ||
15018 | static void | |
15019 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15020 | { | |
51be5b68 | 15021 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15022 | } |
15023 | ||
c906108c SS |
15024 | /* The enable command enables the specified breakpoints (or all defined |
15025 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15026 | in stopping the inferior. */ |
c906108c | 15027 | |
c906108c | 15028 | static void |
fba45db2 | 15029 | enable_command (char *args, int from_tty) |
c906108c | 15030 | { |
c906108c | 15031 | if (args == 0) |
46c6471b PA |
15032 | { |
15033 | struct breakpoint *bpt; | |
15034 | ||
15035 | ALL_BREAKPOINTS (bpt) | |
15036 | if (user_breakpoint_p (bpt)) | |
15037 | enable_breakpoint (bpt); | |
15038 | } | |
9eaabc75 | 15039 | else |
0d381245 | 15040 | { |
9eaabc75 MW |
15041 | char *num = extract_arg (&args); |
15042 | ||
15043 | while (num) | |
d248b706 | 15044 | { |
9eaabc75 | 15045 | if (strchr (num, '.')) |
b775012e | 15046 | { |
9eaabc75 MW |
15047 | struct bp_location *loc = find_location_by_number (num); |
15048 | ||
15049 | if (loc) | |
15050 | { | |
15051 | if (!loc->enabled) | |
15052 | { | |
15053 | loc->enabled = 1; | |
15054 | mark_breakpoint_location_modified (loc); | |
15055 | } | |
15056 | if (target_supports_enable_disable_tracepoint () | |
15057 | && current_trace_status ()->running && loc->owner | |
15058 | && is_tracepoint (loc->owner)) | |
15059 | target_enable_tracepoint (loc); | |
15060 | } | |
44702360 | 15061 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15062 | } |
9eaabc75 MW |
15063 | else |
15064 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15065 | num = extract_arg (&args); | |
d248b706 | 15066 | } |
0d381245 | 15067 | } |
c906108c SS |
15068 | } |
15069 | ||
816338b5 SS |
15070 | /* This struct packages up disposition data for application to multiple |
15071 | breakpoints. */ | |
15072 | ||
15073 | struct disp_data | |
15074 | { | |
15075 | enum bpdisp disp; | |
15076 | int count; | |
15077 | }; | |
15078 | ||
c906108c | 15079 | static void |
51be5b68 PA |
15080 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15081 | { | |
816338b5 | 15082 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15083 | |
816338b5 | 15084 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15085 | } |
15086 | ||
15087 | static void | |
15088 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15089 | { |
816338b5 | 15090 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15091 | |
15092 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15093 | } |
15094 | ||
c906108c | 15095 | static void |
fba45db2 | 15096 | enable_once_command (char *args, int from_tty) |
c906108c | 15097 | { |
51be5b68 | 15098 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15099 | } |
15100 | ||
816338b5 SS |
15101 | static void |
15102 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15103 | { | |
15104 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15105 | ||
15106 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15107 | } | |
15108 | ||
15109 | static void | |
15110 | enable_count_command (char *args, int from_tty) | |
15111 | { | |
b9d61307 SM |
15112 | int count; |
15113 | ||
15114 | if (args == NULL) | |
15115 | error_no_arg (_("hit count")); | |
15116 | ||
15117 | count = get_number (&args); | |
816338b5 SS |
15118 | |
15119 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15120 | } | |
15121 | ||
c906108c | 15122 | static void |
51be5b68 | 15123 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15124 | { |
816338b5 | 15125 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15126 | |
15127 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15128 | } |
15129 | ||
c906108c | 15130 | static void |
fba45db2 | 15131 | enable_delete_command (char *args, int from_tty) |
c906108c | 15132 | { |
51be5b68 | 15133 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15134 | } |
15135 | \f | |
fa8d40ab JJ |
15136 | static void |
15137 | set_breakpoint_cmd (char *args, int from_tty) | |
15138 | { | |
15139 | } | |
15140 | ||
15141 | static void | |
15142 | show_breakpoint_cmd (char *args, int from_tty) | |
15143 | { | |
15144 | } | |
15145 | ||
1f3b5d1b PP |
15146 | /* Invalidate last known value of any hardware watchpoint if |
15147 | the memory which that value represents has been written to by | |
15148 | GDB itself. */ | |
15149 | ||
15150 | static void | |
8de0566d YQ |
15151 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15152 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15153 | const bfd_byte *data) |
15154 | { | |
15155 | struct breakpoint *bp; | |
15156 | ||
15157 | ALL_BREAKPOINTS (bp) | |
15158 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15159 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15160 | { |
3a5c3e22 | 15161 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15162 | |
3a5c3e22 PA |
15163 | if (wp->val_valid && wp->val) |
15164 | { | |
15165 | struct bp_location *loc; | |
15166 | ||
15167 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15168 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15169 | && loc->address + loc->length > addr | |
15170 | && addr + len > loc->address) | |
15171 | { | |
15172 | value_free (wp->val); | |
15173 | wp->val = NULL; | |
15174 | wp->val_valid = 0; | |
15175 | } | |
15176 | } | |
1f3b5d1b PP |
15177 | } |
15178 | } | |
15179 | ||
8181d85f DJ |
15180 | /* Create and insert a breakpoint for software single step. */ |
15181 | ||
15182 | void | |
6c95b8df | 15183 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15184 | struct address_space *aspace, |
15185 | CORE_ADDR next_pc) | |
8181d85f | 15186 | { |
7c16b83e PA |
15187 | struct thread_info *tp = inferior_thread (); |
15188 | struct symtab_and_line sal; | |
15189 | CORE_ADDR pc = next_pc; | |
8181d85f | 15190 | |
34b7e8a6 PA |
15191 | if (tp->control.single_step_breakpoints == NULL) |
15192 | { | |
15193 | tp->control.single_step_breakpoints | |
5d5658a1 | 15194 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 15195 | } |
8181d85f | 15196 | |
7c16b83e PA |
15197 | sal = find_pc_line (pc, 0); |
15198 | sal.pc = pc; | |
15199 | sal.section = find_pc_overlay (pc); | |
15200 | sal.explicit_pc = 1; | |
34b7e8a6 | 15201 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15202 | |
7c16b83e | 15203 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15204 | } |
15205 | ||
93f9a11f YQ |
15206 | /* Insert single step breakpoints according to the current state. */ |
15207 | ||
15208 | int | |
15209 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
15210 | { | |
15211 | struct frame_info *frame = get_current_frame (); | |
15212 | VEC (CORE_ADDR) * next_pcs; | |
15213 | ||
15214 | next_pcs = gdbarch_software_single_step (gdbarch, frame); | |
15215 | ||
15216 | if (next_pcs != NULL) | |
15217 | { | |
15218 | int i; | |
15219 | CORE_ADDR pc; | |
15220 | struct address_space *aspace = get_frame_address_space (frame); | |
15221 | ||
15222 | for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); i++) | |
15223 | insert_single_step_breakpoint (gdbarch, aspace, pc); | |
15224 | ||
15225 | VEC_free (CORE_ADDR, next_pcs); | |
15226 | ||
15227 | return 1; | |
15228 | } | |
15229 | else | |
15230 | return 0; | |
15231 | } | |
15232 | ||
34b7e8a6 | 15233 | /* See breakpoint.h. */ |
f02253f1 HZ |
15234 | |
15235 | int | |
7c16b83e PA |
15236 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15237 | struct address_space *aspace, | |
15238 | CORE_ADDR pc) | |
1aafd4da | 15239 | { |
7c16b83e | 15240 | struct bp_location *loc; |
1aafd4da | 15241 | |
7c16b83e PA |
15242 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15243 | if (loc->inserted | |
15244 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15245 | return 1; | |
1aafd4da | 15246 | |
7c16b83e | 15247 | return 0; |
ef370185 JB |
15248 | } |
15249 | ||
15250 | /* Check whether a software single-step breakpoint is inserted at | |
15251 | PC. */ | |
15252 | ||
15253 | int | |
15254 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15255 | CORE_ADDR pc) | |
15256 | { | |
34b7e8a6 PA |
15257 | struct breakpoint *bpt; |
15258 | ||
15259 | ALL_BREAKPOINTS (bpt) | |
15260 | { | |
15261 | if (bpt->type == bp_single_step | |
15262 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15263 | return 1; | |
15264 | } | |
15265 | return 0; | |
1aafd4da UW |
15266 | } |
15267 | ||
1042e4c0 SS |
15268 | /* Tracepoint-specific operations. */ |
15269 | ||
15270 | /* Set tracepoint count to NUM. */ | |
15271 | static void | |
15272 | set_tracepoint_count (int num) | |
15273 | { | |
15274 | tracepoint_count = num; | |
4fa62494 | 15275 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15276 | } |
15277 | ||
70221824 | 15278 | static void |
1042e4c0 SS |
15279 | trace_command (char *arg, int from_tty) |
15280 | { | |
55aa24fb | 15281 | struct breakpoint_ops *ops; |
f00aae0f KS |
15282 | struct event_location *location; |
15283 | struct cleanup *back_to; | |
55aa24fb | 15284 | |
f00aae0f KS |
15285 | location = string_to_event_location (&arg, current_language); |
15286 | back_to = make_cleanup_delete_event_location (location); | |
5b56227b KS |
15287 | if (location != NULL |
15288 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
15289 | ops = &tracepoint_probe_breakpoint_ops; |
15290 | else | |
15291 | ops = &tracepoint_breakpoint_ops; | |
15292 | ||
558a9d82 | 15293 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15294 | location, |
15295 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15296 | 0 /* tempflag */, |
15297 | bp_tracepoint /* type_wanted */, | |
15298 | 0 /* Ignore count */, | |
15299 | pending_break_support, | |
15300 | ops, | |
15301 | from_tty, | |
15302 | 1 /* enabled */, | |
15303 | 0 /* internal */, 0); | |
f00aae0f | 15304 | do_cleanups (back_to); |
1042e4c0 SS |
15305 | } |
15306 | ||
70221824 | 15307 | static void |
7a697b8d SS |
15308 | ftrace_command (char *arg, int from_tty) |
15309 | { | |
f00aae0f KS |
15310 | struct event_location *location; |
15311 | struct cleanup *back_to; | |
15312 | ||
15313 | location = string_to_event_location (&arg, current_language); | |
15314 | back_to = make_cleanup_delete_event_location (location); | |
558a9d82 | 15315 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15316 | location, |
15317 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15318 | 0 /* tempflag */, |
15319 | bp_fast_tracepoint /* type_wanted */, | |
15320 | 0 /* Ignore count */, | |
15321 | pending_break_support, | |
15322 | &tracepoint_breakpoint_ops, | |
15323 | from_tty, | |
15324 | 1 /* enabled */, | |
15325 | 0 /* internal */, 0); | |
f00aae0f | 15326 | do_cleanups (back_to); |
0fb4aa4b PA |
15327 | } |
15328 | ||
15329 | /* strace command implementation. Creates a static tracepoint. */ | |
15330 | ||
70221824 | 15331 | static void |
0fb4aa4b PA |
15332 | strace_command (char *arg, int from_tty) |
15333 | { | |
983af33b | 15334 | struct breakpoint_ops *ops; |
f00aae0f KS |
15335 | struct event_location *location; |
15336 | struct cleanup *back_to; | |
983af33b SDJ |
15337 | |
15338 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15339 | or with a normal static tracepoint. */ | |
61012eef | 15340 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15341 | { |
15342 | ops = &strace_marker_breakpoint_ops; | |
15343 | location = new_linespec_location (&arg); | |
15344 | } | |
983af33b | 15345 | else |
f00aae0f KS |
15346 | { |
15347 | ops = &tracepoint_breakpoint_ops; | |
15348 | location = string_to_event_location (&arg, current_language); | |
15349 | } | |
983af33b | 15350 | |
f00aae0f | 15351 | back_to = make_cleanup_delete_event_location (location); |
558a9d82 | 15352 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15353 | location, |
15354 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15355 | 0 /* tempflag */, |
15356 | bp_static_tracepoint /* type_wanted */, | |
15357 | 0 /* Ignore count */, | |
15358 | pending_break_support, | |
15359 | ops, | |
15360 | from_tty, | |
15361 | 1 /* enabled */, | |
15362 | 0 /* internal */, 0); | |
f00aae0f | 15363 | do_cleanups (back_to); |
7a697b8d SS |
15364 | } |
15365 | ||
409873ef SS |
15366 | /* Set up a fake reader function that gets command lines from a linked |
15367 | list that was acquired during tracepoint uploading. */ | |
15368 | ||
15369 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15370 | static int next_cmd; |
409873ef SS |
15371 | |
15372 | static char * | |
15373 | read_uploaded_action (void) | |
15374 | { | |
15375 | char *rslt; | |
15376 | ||
3149d8c1 | 15377 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15378 | |
3149d8c1 | 15379 | next_cmd++; |
409873ef SS |
15380 | |
15381 | return rslt; | |
15382 | } | |
15383 | ||
00bf0b85 SS |
15384 | /* Given information about a tracepoint as recorded on a target (which |
15385 | can be either a live system or a trace file), attempt to create an | |
15386 | equivalent GDB tracepoint. This is not a reliable process, since | |
15387 | the target does not necessarily have all the information used when | |
15388 | the tracepoint was originally defined. */ | |
15389 | ||
d9b3f62e | 15390 | struct tracepoint * |
00bf0b85 | 15391 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15392 | { |
409873ef | 15393 | char *addr_str, small_buf[100]; |
d9b3f62e | 15394 | struct tracepoint *tp; |
f00aae0f KS |
15395 | struct event_location *location; |
15396 | struct cleanup *cleanup; | |
fd9b8c24 | 15397 | |
409873ef SS |
15398 | if (utp->at_string) |
15399 | addr_str = utp->at_string; | |
15400 | else | |
15401 | { | |
15402 | /* In the absence of a source location, fall back to raw | |
15403 | address. Since there is no way to confirm that the address | |
15404 | means the same thing as when the trace was started, warn the | |
15405 | user. */ | |
3e43a32a MS |
15406 | warning (_("Uploaded tracepoint %d has no " |
15407 | "source location, using raw address"), | |
409873ef | 15408 | utp->number); |
8c042590 | 15409 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15410 | addr_str = small_buf; |
15411 | } | |
15412 | ||
15413 | /* There's not much we can do with a sequence of bytecodes. */ | |
15414 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15415 | warning (_("Uploaded tracepoint %d condition " |
15416 | "has no source form, ignoring it"), | |
409873ef | 15417 | utp->number); |
d5551862 | 15418 | |
f00aae0f KS |
15419 | location = string_to_event_location (&addr_str, current_language); |
15420 | cleanup = make_cleanup_delete_event_location (location); | |
8cdf0e15 | 15421 | if (!create_breakpoint (get_current_arch (), |
f00aae0f KS |
15422 | location, |
15423 | utp->cond_string, -1, addr_str, | |
e7e0cddf | 15424 | 0 /* parse cond/thread */, |
8cdf0e15 | 15425 | 0 /* tempflag */, |
0fb4aa4b | 15426 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15427 | 0 /* Ignore count */, |
15428 | pending_break_support, | |
348d480f | 15429 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15430 | 0 /* from_tty */, |
84f4c1fe | 15431 | utp->enabled /* enabled */, |
44f238bb PA |
15432 | 0 /* internal */, |
15433 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
f00aae0f KS |
15434 | { |
15435 | do_cleanups (cleanup); | |
15436 | return NULL; | |
15437 | } | |
15438 | ||
15439 | do_cleanups (cleanup); | |
fd9b8c24 | 15440 | |
409873ef | 15441 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15442 | tp = get_tracepoint (tracepoint_count); |
15443 | gdb_assert (tp != NULL); | |
d5551862 | 15444 | |
00bf0b85 SS |
15445 | if (utp->pass > 0) |
15446 | { | |
8c042590 PM |
15447 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15448 | tp->base.number); | |
00bf0b85 | 15449 | |
409873ef | 15450 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15451 | } |
15452 | ||
409873ef SS |
15453 | /* If we have uploaded versions of the original commands, set up a |
15454 | special-purpose "reader" function and call the usual command line | |
15455 | reader, then pass the result to the breakpoint command-setting | |
15456 | function. */ | |
3149d8c1 | 15457 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15458 | { |
409873ef | 15459 | struct command_line *cmd_list; |
00bf0b85 | 15460 | |
409873ef | 15461 | this_utp = utp; |
3149d8c1 | 15462 | next_cmd = 0; |
d5551862 | 15463 | |
409873ef SS |
15464 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15465 | ||
d9b3f62e | 15466 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15467 | } |
3149d8c1 SS |
15468 | else if (!VEC_empty (char_ptr, utp->actions) |
15469 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15470 | warning (_("Uploaded tracepoint %d actions " |
15471 | "have no source form, ignoring them"), | |
409873ef | 15472 | utp->number); |
00bf0b85 | 15473 | |
f196051f SS |
15474 | /* Copy any status information that might be available. */ |
15475 | tp->base.hit_count = utp->hit_count; | |
15476 | tp->traceframe_usage = utp->traceframe_usage; | |
15477 | ||
00bf0b85 | 15478 | return tp; |
d9b3f62e | 15479 | } |
00bf0b85 | 15480 | |
1042e4c0 SS |
15481 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15482 | omitted. */ | |
15483 | ||
15484 | static void | |
e5a67952 | 15485 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15486 | { |
79a45e25 | 15487 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15488 | int num_printed; |
1042e4c0 | 15489 | |
e5a67952 | 15490 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15491 | |
15492 | if (num_printed == 0) | |
1042e4c0 | 15493 | { |
e5a67952 | 15494 | if (args == NULL || *args == '\0') |
d77f58be SS |
15495 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15496 | else | |
e5a67952 | 15497 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15498 | } |
ad443146 SS |
15499 | |
15500 | default_collect_info (); | |
1042e4c0 SS |
15501 | } |
15502 | ||
4a64f543 | 15503 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15504 | Not supported by all targets. */ |
15505 | static void | |
15506 | enable_trace_command (char *args, int from_tty) | |
15507 | { | |
15508 | enable_command (args, from_tty); | |
15509 | } | |
15510 | ||
4a64f543 | 15511 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15512 | Not supported by all targets. */ |
15513 | static void | |
15514 | disable_trace_command (char *args, int from_tty) | |
15515 | { | |
15516 | disable_command (args, from_tty); | |
15517 | } | |
15518 | ||
4a64f543 | 15519 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15520 | static void |
15521 | delete_trace_command (char *arg, int from_tty) | |
15522 | { | |
35df4500 | 15523 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15524 | |
15525 | dont_repeat (); | |
15526 | ||
15527 | if (arg == 0) | |
15528 | { | |
15529 | int breaks_to_delete = 0; | |
15530 | ||
15531 | /* Delete all breakpoints if no argument. | |
15532 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15533 | have to be deleted with an explicit breakpoint number |
15534 | argument. */ | |
1042e4c0 | 15535 | ALL_TRACEPOINTS (b) |
46c6471b | 15536 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15537 | { |
15538 | breaks_to_delete = 1; | |
15539 | break; | |
15540 | } | |
1042e4c0 SS |
15541 | |
15542 | /* Ask user only if there are some breakpoints to delete. */ | |
15543 | if (!from_tty | |
15544 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15545 | { | |
35df4500 | 15546 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15547 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15548 | delete_breakpoint (b); |
1042e4c0 SS |
15549 | } |
15550 | } | |
15551 | else | |
51be5b68 | 15552 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15553 | } |
15554 | ||
197f0a60 TT |
15555 | /* Helper function for trace_pass_command. */ |
15556 | ||
15557 | static void | |
d9b3f62e | 15558 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15559 | { |
d9b3f62e | 15560 | tp->pass_count = count; |
6f6484cd | 15561 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15562 | if (from_tty) |
15563 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15564 | tp->base.number, count); |
197f0a60 TT |
15565 | } |
15566 | ||
1042e4c0 SS |
15567 | /* Set passcount for tracepoint. |
15568 | ||
15569 | First command argument is passcount, second is tracepoint number. | |
15570 | If tracepoint number omitted, apply to most recently defined. | |
15571 | Also accepts special argument "all". */ | |
15572 | ||
15573 | static void | |
15574 | trace_pass_command (char *args, int from_tty) | |
15575 | { | |
d9b3f62e | 15576 | struct tracepoint *t1; |
1042e4c0 | 15577 | unsigned int count; |
1042e4c0 SS |
15578 | |
15579 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15580 | error (_("passcount command requires an " |
15581 | "argument (count + optional TP num)")); | |
1042e4c0 | 15582 | |
4a64f543 | 15583 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15584 | |
529480d0 | 15585 | args = skip_spaces (args); |
1042e4c0 SS |
15586 | if (*args && strncasecmp (args, "all", 3) == 0) |
15587 | { | |
d9b3f62e PA |
15588 | struct breakpoint *b; |
15589 | ||
1042e4c0 | 15590 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15591 | if (*args) |
15592 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15593 | |
d9b3f62e | 15594 | ALL_TRACEPOINTS (b) |
197f0a60 | 15595 | { |
d9b3f62e | 15596 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15597 | trace_pass_set_count (t1, count, from_tty); |
15598 | } | |
15599 | } | |
15600 | else if (*args == '\0') | |
1042e4c0 | 15601 | { |
5fa1d40e | 15602 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15603 | if (t1) |
197f0a60 TT |
15604 | trace_pass_set_count (t1, count, from_tty); |
15605 | } | |
15606 | else | |
15607 | { | |
bfd28288 PA |
15608 | number_or_range_parser parser (args); |
15609 | while (!parser.finished ()) | |
1042e4c0 | 15610 | { |
bfd28288 | 15611 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15612 | if (t1) |
15613 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15614 | } |
15615 | } | |
1042e4c0 SS |
15616 | } |
15617 | ||
d9b3f62e | 15618 | struct tracepoint * |
1042e4c0 SS |
15619 | get_tracepoint (int num) |
15620 | { | |
15621 | struct breakpoint *t; | |
15622 | ||
15623 | ALL_TRACEPOINTS (t) | |
15624 | if (t->number == num) | |
d9b3f62e | 15625 | return (struct tracepoint *) t; |
1042e4c0 SS |
15626 | |
15627 | return NULL; | |
15628 | } | |
15629 | ||
d5551862 SS |
15630 | /* Find the tracepoint with the given target-side number (which may be |
15631 | different from the tracepoint number after disconnecting and | |
15632 | reconnecting). */ | |
15633 | ||
d9b3f62e | 15634 | struct tracepoint * |
d5551862 SS |
15635 | get_tracepoint_by_number_on_target (int num) |
15636 | { | |
d9b3f62e | 15637 | struct breakpoint *b; |
d5551862 | 15638 | |
d9b3f62e PA |
15639 | ALL_TRACEPOINTS (b) |
15640 | { | |
15641 | struct tracepoint *t = (struct tracepoint *) b; | |
15642 | ||
15643 | if (t->number_on_target == num) | |
15644 | return t; | |
15645 | } | |
d5551862 SS |
15646 | |
15647 | return NULL; | |
15648 | } | |
15649 | ||
1042e4c0 | 15650 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15651 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15652 | If the argument is missing, the most recent tracepoint |
15653 | (tracepoint_count) is returned. */ | |
15654 | ||
d9b3f62e | 15655 | struct tracepoint * |
197f0a60 | 15656 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15657 | number_or_range_parser *parser) |
1042e4c0 | 15658 | { |
1042e4c0 SS |
15659 | struct breakpoint *t; |
15660 | int tpnum; | |
15661 | char *instring = arg == NULL ? NULL : *arg; | |
15662 | ||
bfd28288 | 15663 | if (parser != NULL) |
197f0a60 | 15664 | { |
bfd28288 PA |
15665 | gdb_assert (!parser->finished ()); |
15666 | tpnum = parser->get_number (); | |
197f0a60 TT |
15667 | } |
15668 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15669 | tpnum = tracepoint_count; |
1042e4c0 | 15670 | else |
197f0a60 | 15671 | tpnum = get_number (arg); |
1042e4c0 SS |
15672 | |
15673 | if (tpnum <= 0) | |
15674 | { | |
15675 | if (instring && *instring) | |
15676 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15677 | instring); | |
15678 | else | |
5fa1d40e | 15679 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15680 | return NULL; |
15681 | } | |
15682 | ||
15683 | ALL_TRACEPOINTS (t) | |
15684 | if (t->number == tpnum) | |
15685 | { | |
d9b3f62e | 15686 | return (struct tracepoint *) t; |
1042e4c0 SS |
15687 | } |
15688 | ||
1042e4c0 SS |
15689 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15690 | return NULL; | |
15691 | } | |
15692 | ||
d9b3f62e PA |
15693 | void |
15694 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15695 | { | |
15696 | if (b->thread != -1) | |
15697 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15698 | ||
15699 | if (b->task != 0) | |
15700 | fprintf_unfiltered (fp, " task %d", b->task); | |
15701 | ||
15702 | fprintf_unfiltered (fp, "\n"); | |
15703 | } | |
15704 | ||
6149aea9 PA |
15705 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15706 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15707 | on each breakpoint and only include the ones for which it returns | |
15708 | non-zero. */ | |
15709 | ||
1042e4c0 | 15710 | static void |
6149aea9 PA |
15711 | save_breakpoints (char *filename, int from_tty, |
15712 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15713 | { |
15714 | struct breakpoint *tp; | |
6149aea9 | 15715 | int any = 0; |
1042e4c0 | 15716 | struct cleanup *cleanup; |
a7bdde9e | 15717 | struct ui_file *fp; |
6149aea9 | 15718 | int extra_trace_bits = 0; |
1042e4c0 | 15719 | |
6149aea9 PA |
15720 | if (filename == 0 || *filename == 0) |
15721 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15722 | |
15723 | /* See if we have anything to save. */ | |
6149aea9 | 15724 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15725 | { |
6149aea9 | 15726 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15727 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15728 | continue; |
15729 | ||
15730 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15731 | if (filter && !filter (tp)) | |
15732 | continue; | |
15733 | ||
15734 | any = 1; | |
15735 | ||
15736 | if (is_tracepoint (tp)) | |
15737 | { | |
15738 | extra_trace_bits = 1; | |
15739 | ||
15740 | /* We can stop searching. */ | |
15741 | break; | |
15742 | } | |
1042e4c0 | 15743 | } |
6149aea9 PA |
15744 | |
15745 | if (!any) | |
1042e4c0 | 15746 | { |
6149aea9 | 15747 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15748 | return; |
15749 | } | |
15750 | ||
c718be47 PA |
15751 | filename = tilde_expand (filename); |
15752 | cleanup = make_cleanup (xfree, filename); | |
15753 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15754 | if (!fp) |
6149aea9 PA |
15755 | error (_("Unable to open file '%s' for saving (%s)"), |
15756 | filename, safe_strerror (errno)); | |
a7bdde9e | 15757 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15758 | |
6149aea9 PA |
15759 | if (extra_trace_bits) |
15760 | save_trace_state_variables (fp); | |
8bf6485c | 15761 | |
6149aea9 | 15762 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15763 | { |
6149aea9 | 15764 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15765 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15766 | continue; |
8bf6485c | 15767 | |
6149aea9 PA |
15768 | /* If we have a filter, only save the breakpoints it accepts. */ |
15769 | if (filter && !filter (tp)) | |
15770 | continue; | |
15771 | ||
348d480f | 15772 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15773 | |
6149aea9 PA |
15774 | /* Note, we can't rely on tp->number for anything, as we can't |
15775 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15776 | instead. */ | |
15777 | ||
15778 | if (tp->cond_string) | |
15779 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15780 | ||
15781 | if (tp->ignore_count) | |
15782 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15783 | ||
2d9442cc | 15784 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15785 | { |
6149aea9 | 15786 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15787 | |
79a45e25 | 15788 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15789 | TRY |
1042e4c0 | 15790 | { |
79a45e25 | 15791 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15792 | } |
492d29ea PA |
15793 | CATCH (ex, RETURN_MASK_ALL) |
15794 | { | |
6c63c96a | 15795 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15796 | throw_exception (ex); |
15797 | } | |
15798 | END_CATCH | |
1042e4c0 | 15799 | |
6c63c96a | 15800 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15801 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15802 | } |
6149aea9 PA |
15803 | |
15804 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15805 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15806 | |
15807 | /* If this is a multi-location breakpoint, check if the locations | |
15808 | should be individually disabled. Watchpoint locations are | |
15809 | special, and not user visible. */ | |
15810 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15811 | { | |
15812 | struct bp_location *loc; | |
15813 | int n = 1; | |
15814 | ||
15815 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15816 | if (!loc->enabled) | |
15817 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15818 | } | |
1042e4c0 | 15819 | } |
8bf6485c | 15820 | |
6149aea9 | 15821 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15822 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15823 | ||
1042e4c0 | 15824 | if (from_tty) |
6149aea9 | 15825 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15826 | do_cleanups (cleanup); |
6149aea9 PA |
15827 | } |
15828 | ||
15829 | /* The `save breakpoints' command. */ | |
15830 | ||
15831 | static void | |
15832 | save_breakpoints_command (char *args, int from_tty) | |
15833 | { | |
15834 | save_breakpoints (args, from_tty, NULL); | |
15835 | } | |
15836 | ||
15837 | /* The `save tracepoints' command. */ | |
15838 | ||
15839 | static void | |
15840 | save_tracepoints_command (char *args, int from_tty) | |
15841 | { | |
15842 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15843 | } |
15844 | ||
15845 | /* Create a vector of all tracepoints. */ | |
15846 | ||
15847 | VEC(breakpoint_p) * | |
eeae04df | 15848 | all_tracepoints (void) |
1042e4c0 SS |
15849 | { |
15850 | VEC(breakpoint_p) *tp_vec = 0; | |
15851 | struct breakpoint *tp; | |
15852 | ||
15853 | ALL_TRACEPOINTS (tp) | |
15854 | { | |
15855 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15856 | } | |
15857 | ||
15858 | return tp_vec; | |
15859 | } | |
15860 | ||
c906108c | 15861 | \f |
629500fa KS |
15862 | /* This help string is used to consolidate all the help string for specifying |
15863 | locations used by several commands. */ | |
15864 | ||
15865 | #define LOCATION_HELP_STRING \ | |
15866 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15867 | source filename, function name, label name, and line number.\n\ | |
15868 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15869 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15870 | \"factorial.c:fact:the_top\".\n\ | |
15871 | \n\ | |
15872 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15873 | program. Example: To specify the fourth byte past the start function\n\ | |
15874 | \"main\", use \"*main + 4\".\n\ | |
15875 | \n\ | |
15876 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15877 | syntax to specify location parameters.\n\ | |
15878 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15879 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15880 | -function fact -label the_top\".\n" | |
15881 | ||
4a64f543 MS |
15882 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15883 | commands. It is defined as a macro to prevent duplication. | |
15884 | COMMAND should be a string constant containing the name of the | |
15885 | command. */ | |
629500fa | 15886 | |
31e2b00f | 15887 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15888 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15889 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15890 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15891 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15892 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15893 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15894 | below.\n\ | |
15895 | \n\ | |
dc10affe PA |
15896 | With no LOCATION, uses current execution address of the selected\n\ |
15897 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15898 | \n\ |
15899 | THREADNUM is the number from \"info threads\".\n\ | |
15900 | CONDITION is a boolean expression.\n\ | |
629500fa | 15901 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15902 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15903 | conditions are different.\n\ | |
31e2b00f AS |
15904 | \n\ |
15905 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15906 | ||
44feb3ce TT |
15907 | /* List of subcommands for "catch". */ |
15908 | static struct cmd_list_element *catch_cmdlist; | |
15909 | ||
15910 | /* List of subcommands for "tcatch". */ | |
15911 | static struct cmd_list_element *tcatch_cmdlist; | |
15912 | ||
9ac4176b | 15913 | void |
44feb3ce | 15914 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15915 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15916 | completer_ftype *completer, |
44feb3ce TT |
15917 | void *user_data_catch, |
15918 | void *user_data_tcatch) | |
15919 | { | |
15920 | struct cmd_list_element *command; | |
15921 | ||
15922 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15923 | &catch_cmdlist); | |
15924 | set_cmd_sfunc (command, sfunc); | |
15925 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15926 | set_cmd_completer (command, completer); |
44feb3ce TT |
15927 | |
15928 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15929 | &tcatch_cmdlist); | |
15930 | set_cmd_sfunc (command, sfunc); | |
15931 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15932 | set_cmd_completer (command, completer); |
44feb3ce TT |
15933 | } |
15934 | ||
6149aea9 PA |
15935 | static void |
15936 | save_command (char *arg, int from_tty) | |
15937 | { | |
3e43a32a MS |
15938 | printf_unfiltered (_("\"save\" must be followed by " |
15939 | "the name of a save subcommand.\n")); | |
635c7e8a | 15940 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15941 | } |
15942 | ||
84f4c1fe PM |
15943 | struct breakpoint * |
15944 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15945 | void *data) | |
15946 | { | |
35df4500 | 15947 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15948 | |
35df4500 | 15949 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15950 | { |
15951 | if ((*callback) (b, data)) | |
15952 | return b; | |
15953 | } | |
15954 | ||
15955 | return NULL; | |
15956 | } | |
15957 | ||
0574c78f GB |
15958 | /* Zero if any of the breakpoint's locations could be a location where |
15959 | functions have been inlined, nonzero otherwise. */ | |
15960 | ||
15961 | static int | |
15962 | is_non_inline_function (struct breakpoint *b) | |
15963 | { | |
15964 | /* The shared library event breakpoint is set on the address of a | |
15965 | non-inline function. */ | |
15966 | if (b->type == bp_shlib_event) | |
15967 | return 1; | |
15968 | ||
15969 | return 0; | |
15970 | } | |
15971 | ||
15972 | /* Nonzero if the specified PC cannot be a location where functions | |
15973 | have been inlined. */ | |
15974 | ||
15975 | int | |
09ac7c10 TT |
15976 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15977 | const struct target_waitstatus *ws) | |
0574c78f GB |
15978 | { |
15979 | struct breakpoint *b; | |
15980 | struct bp_location *bl; | |
15981 | ||
15982 | ALL_BREAKPOINTS (b) | |
15983 | { | |
15984 | if (!is_non_inline_function (b)) | |
15985 | continue; | |
15986 | ||
15987 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15988 | { | |
15989 | if (!bl->shlib_disabled | |
09ac7c10 | 15990 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15991 | return 1; |
15992 | } | |
15993 | } | |
15994 | ||
15995 | return 0; | |
15996 | } | |
15997 | ||
2f202fde JK |
15998 | /* Remove any references to OBJFILE which is going to be freed. */ |
15999 | ||
16000 | void | |
16001 | breakpoint_free_objfile (struct objfile *objfile) | |
16002 | { | |
16003 | struct bp_location **locp, *loc; | |
16004 | ||
16005 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 16006 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
16007 | loc->symtab = NULL; |
16008 | } | |
16009 | ||
2060206e PA |
16010 | void |
16011 | initialize_breakpoint_ops (void) | |
16012 | { | |
16013 | static int initialized = 0; | |
16014 | ||
16015 | struct breakpoint_ops *ops; | |
16016 | ||
16017 | if (initialized) | |
16018 | return; | |
16019 | initialized = 1; | |
16020 | ||
16021 | /* The breakpoint_ops structure to be inherit by all kinds of | |
16022 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
16023 | internal and momentary breakpoints, etc.). */ | |
16024 | ops = &bkpt_base_breakpoint_ops; | |
16025 | *ops = base_breakpoint_ops; | |
16026 | ops->re_set = bkpt_re_set; | |
16027 | ops->insert_location = bkpt_insert_location; | |
16028 | ops->remove_location = bkpt_remove_location; | |
16029 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 16030 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 16031 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 16032 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
16033 | |
16034 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16035 | ops = &bkpt_breakpoint_ops; | |
16036 | *ops = bkpt_base_breakpoint_ops; | |
16037 | ops->re_set = bkpt_re_set; | |
16038 | ops->resources_needed = bkpt_resources_needed; | |
16039 | ops->print_it = bkpt_print_it; | |
16040 | ops->print_mention = bkpt_print_mention; | |
16041 | ops->print_recreate = bkpt_print_recreate; | |
16042 | ||
16043 | /* Ranged breakpoints. */ | |
16044 | ops = &ranged_breakpoint_ops; | |
16045 | *ops = bkpt_breakpoint_ops; | |
16046 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16047 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16048 | ops->print_it = print_it_ranged_breakpoint; | |
16049 | ops->print_one = print_one_ranged_breakpoint; | |
16050 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16051 | ops->print_mention = print_mention_ranged_breakpoint; | |
16052 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16053 | ||
16054 | /* Internal breakpoints. */ | |
16055 | ops = &internal_breakpoint_ops; | |
16056 | *ops = bkpt_base_breakpoint_ops; | |
16057 | ops->re_set = internal_bkpt_re_set; | |
16058 | ops->check_status = internal_bkpt_check_status; | |
16059 | ops->print_it = internal_bkpt_print_it; | |
16060 | ops->print_mention = internal_bkpt_print_mention; | |
16061 | ||
16062 | /* Momentary breakpoints. */ | |
16063 | ops = &momentary_breakpoint_ops; | |
16064 | *ops = bkpt_base_breakpoint_ops; | |
16065 | ops->re_set = momentary_bkpt_re_set; | |
16066 | ops->check_status = momentary_bkpt_check_status; | |
16067 | ops->print_it = momentary_bkpt_print_it; | |
16068 | ops->print_mention = momentary_bkpt_print_mention; | |
16069 | ||
e2e4d78b JK |
16070 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16071 | ops = &longjmp_breakpoint_ops; | |
16072 | *ops = momentary_breakpoint_ops; | |
16073 | ops->dtor = longjmp_bkpt_dtor; | |
16074 | ||
55aa24fb SDJ |
16075 | /* Probe breakpoints. */ |
16076 | ops = &bkpt_probe_breakpoint_ops; | |
16077 | *ops = bkpt_breakpoint_ops; | |
16078 | ops->insert_location = bkpt_probe_insert_location; | |
16079 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
16080 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
16081 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 16082 | |
2060206e PA |
16083 | /* Watchpoints. */ |
16084 | ops = &watchpoint_breakpoint_ops; | |
16085 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16086 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16087 | ops->re_set = re_set_watchpoint; |
16088 | ops->insert_location = insert_watchpoint; | |
16089 | ops->remove_location = remove_watchpoint; | |
16090 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16091 | ops->check_status = check_status_watchpoint; | |
16092 | ops->resources_needed = resources_needed_watchpoint; | |
16093 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16094 | ops->print_it = print_it_watchpoint; | |
16095 | ops->print_mention = print_mention_watchpoint; | |
16096 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16097 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16098 | |
16099 | /* Masked watchpoints. */ | |
16100 | ops = &masked_watchpoint_breakpoint_ops; | |
16101 | *ops = watchpoint_breakpoint_ops; | |
16102 | ops->insert_location = insert_masked_watchpoint; | |
16103 | ops->remove_location = remove_masked_watchpoint; | |
16104 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16105 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16106 | ops->print_it = print_it_masked_watchpoint; | |
16107 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16108 | ops->print_mention = print_mention_masked_watchpoint; | |
16109 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16110 | ||
16111 | /* Tracepoints. */ | |
16112 | ops = &tracepoint_breakpoint_ops; | |
16113 | *ops = base_breakpoint_ops; | |
16114 | ops->re_set = tracepoint_re_set; | |
16115 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16116 | ops->print_one_detail = tracepoint_print_one_detail; | |
16117 | ops->print_mention = tracepoint_print_mention; | |
16118 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 16119 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 16120 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 16121 | ops->decode_location = tracepoint_decode_location; |
983af33b | 16122 | |
55aa24fb SDJ |
16123 | /* Probe tracepoints. */ |
16124 | ops = &tracepoint_probe_breakpoint_ops; | |
16125 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
16126 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
16127 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 16128 | |
983af33b SDJ |
16129 | /* Static tracepoints with marker (`-m'). */ |
16130 | ops = &strace_marker_breakpoint_ops; | |
16131 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 16132 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 16133 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 16134 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
16135 | |
16136 | /* Fork catchpoints. */ | |
16137 | ops = &catch_fork_breakpoint_ops; | |
16138 | *ops = base_breakpoint_ops; | |
16139 | ops->insert_location = insert_catch_fork; | |
16140 | ops->remove_location = remove_catch_fork; | |
16141 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16142 | ops->print_it = print_it_catch_fork; | |
16143 | ops->print_one = print_one_catch_fork; | |
16144 | ops->print_mention = print_mention_catch_fork; | |
16145 | ops->print_recreate = print_recreate_catch_fork; | |
16146 | ||
16147 | /* Vfork catchpoints. */ | |
16148 | ops = &catch_vfork_breakpoint_ops; | |
16149 | *ops = base_breakpoint_ops; | |
16150 | ops->insert_location = insert_catch_vfork; | |
16151 | ops->remove_location = remove_catch_vfork; | |
16152 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16153 | ops->print_it = print_it_catch_vfork; | |
16154 | ops->print_one = print_one_catch_vfork; | |
16155 | ops->print_mention = print_mention_catch_vfork; | |
16156 | ops->print_recreate = print_recreate_catch_vfork; | |
16157 | ||
16158 | /* Exec catchpoints. */ | |
16159 | ops = &catch_exec_breakpoint_ops; | |
16160 | *ops = base_breakpoint_ops; | |
16161 | ops->dtor = dtor_catch_exec; | |
16162 | ops->insert_location = insert_catch_exec; | |
16163 | ops->remove_location = remove_catch_exec; | |
16164 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16165 | ops->print_it = print_it_catch_exec; | |
16166 | ops->print_one = print_one_catch_exec; | |
16167 | ops->print_mention = print_mention_catch_exec; | |
16168 | ops->print_recreate = print_recreate_catch_exec; | |
16169 | ||
edcc5120 TT |
16170 | /* Solib-related catchpoints. */ |
16171 | ops = &catch_solib_breakpoint_ops; | |
16172 | *ops = base_breakpoint_ops; | |
16173 | ops->dtor = dtor_catch_solib; | |
16174 | ops->insert_location = insert_catch_solib; | |
16175 | ops->remove_location = remove_catch_solib; | |
16176 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16177 | ops->check_status = check_status_catch_solib; | |
16178 | ops->print_it = print_it_catch_solib; | |
16179 | ops->print_one = print_one_catch_solib; | |
16180 | ops->print_mention = print_mention_catch_solib; | |
16181 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16182 | |
16183 | ops = &dprintf_breakpoint_ops; | |
16184 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16185 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16186 | ops->resources_needed = bkpt_resources_needed; |
16187 | ops->print_it = bkpt_print_it; | |
16188 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16189 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16190 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16191 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16192 | } |
16193 | ||
8bfd80db YQ |
16194 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16195 | ||
16196 | static struct cmd_list_element *enablebreaklist = NULL; | |
16197 | ||
c906108c | 16198 | void |
fba45db2 | 16199 | _initialize_breakpoint (void) |
c906108c SS |
16200 | { |
16201 | struct cmd_list_element *c; | |
16202 | ||
2060206e PA |
16203 | initialize_breakpoint_ops (); |
16204 | ||
84acb35a | 16205 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16206 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16207 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16208 | |
55aa24fb SDJ |
16209 | breakpoint_objfile_key |
16210 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16211 | |
c906108c SS |
16212 | breakpoint_chain = 0; |
16213 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16214 | before a breakpoint is set. */ | |
16215 | breakpoint_count = 0; | |
16216 | ||
1042e4c0 SS |
16217 | tracepoint_count = 0; |
16218 | ||
1bedd215 AC |
16219 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16220 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16221 | Usage is `ignore N COUNT'.")); | |
c906108c | 16222 | |
1bedd215 AC |
16223 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16224 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16225 | Give breakpoint number as argument after \"commands\".\n\ |
16226 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16227 | The commands themselves follow starting on the next line.\n\ | |
16228 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16229 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16230 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16231 | |
d55637df | 16232 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16233 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16234 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16235 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16236 | set_cmd_completer (c, condition_completer); |
c906108c | 16237 | |
1bedd215 | 16238 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16239 | Set a temporary breakpoint.\n\ |
c906108c SS |
16240 | Like \"break\" except the breakpoint is only temporary,\n\ |
16241 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16242 | by using \"enable delete\" on the breakpoint number.\n\ |
16243 | \n" | |
16244 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16245 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16246 | |
1bedd215 | 16247 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16248 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16249 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16250 | some target hardware may not have this support.\n\ |
16251 | \n" | |
16252 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16253 | set_cmd_completer (c, location_completer); |
c906108c | 16254 | |
1bedd215 | 16255 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16256 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16257 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16258 | so it will be deleted when hit.\n\ |
16259 | \n" | |
16260 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16261 | set_cmd_completer (c, location_completer); |
c906108c | 16262 | |
1bedd215 AC |
16263 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16264 | Enable some breakpoints.\n\ | |
c906108c SS |
16265 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16266 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16267 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16268 | With a subcommand you can enable temporarily."), |
c906108c | 16269 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16270 | |
16271 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16272 | ||
84951ab5 | 16273 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16274 | Enable some breakpoints.\n\ |
c906108c SS |
16275 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16276 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16277 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16278 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16279 | |
1a966eab AC |
16280 | add_cmd ("once", no_class, enable_once_command, _("\ |
16281 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16282 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16283 | &enablebreaklist); |
16284 | ||
1a966eab AC |
16285 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16286 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16287 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16288 | &enablebreaklist); |
16289 | ||
816338b5 SS |
16290 | add_cmd ("count", no_class, enable_count_command, _("\ |
16291 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16292 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16293 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16294 | &enablebreaklist); | |
16295 | ||
1a966eab AC |
16296 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16297 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16298 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16299 | &enablelist); |
16300 | ||
1a966eab AC |
16301 | add_cmd ("once", no_class, enable_once_command, _("\ |
16302 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16303 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16304 | &enablelist); |
16305 | ||
16306 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16307 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16308 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16309 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16310 | &enablelist); |
16311 | ||
1bedd215 AC |
16312 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16313 | Disable some breakpoints.\n\ | |
c906108c SS |
16314 | Arguments are breakpoint numbers with spaces in between.\n\ |
16315 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16316 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16317 | &disablelist, "disable ", 1, &cmdlist); |
16318 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16319 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16320 | |
1a966eab AC |
16321 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16322 | Disable some breakpoints.\n\ | |
c906108c SS |
16323 | Arguments are breakpoint numbers with spaces in between.\n\ |
16324 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16325 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16326 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16327 | &disablelist); |
16328 | ||
1bedd215 AC |
16329 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16330 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16331 | Arguments are breakpoint numbers with spaces in between.\n\ |
16332 | To delete all breakpoints, give no argument.\n\ | |
16333 | \n\ | |
16334 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16335 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16336 | &deletelist, "delete ", 1, &cmdlist); |
16337 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16338 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16339 | |
1a966eab AC |
16340 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16341 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16342 | Arguments are breakpoint numbers with spaces in between.\n\ |
16343 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16344 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16345 | &deletelist); |
16346 | ||
1bedd215 | 16347 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16348 | Clear breakpoint at specified location.\n\ |
16349 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16350 | \n\ |
16351 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16352 | is executing in.\n" |
16353 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16354 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16355 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16356 | |
1bedd215 | 16357 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16358 | Set breakpoint at specified location.\n" |
31e2b00f | 16359 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16360 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16361 | |
c906108c SS |
16362 | add_com_alias ("b", "break", class_run, 1); |
16363 | add_com_alias ("br", "break", class_run, 1); | |
16364 | add_com_alias ("bre", "break", class_run, 1); | |
16365 | add_com_alias ("brea", "break", class_run, 1); | |
16366 | ||
c906108c SS |
16367 | if (dbx_commands) |
16368 | { | |
1bedd215 AC |
16369 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16370 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16371 | &stoplist, "stop ", 1, &cmdlist); |
16372 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16373 | _("Break in function or address."), &stoplist); |
c5aa993b | 16374 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16375 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16376 | add_com ("status", class_info, breakpoints_info, _("\ |
16377 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16378 | The \"Type\" column indicates one of:\n\ |
16379 | \tbreakpoint - normal breakpoint\n\ | |
16380 | \twatchpoint - watchpoint\n\ | |
16381 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16382 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16383 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16384 | address and file/line number respectively.\n\ |
16385 | \n\ | |
16386 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16387 | are set to the address of the last breakpoint listed unless the command\n\ |
16388 | is prefixed with \"server \".\n\n\ | |
c906108c | 16389 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16390 | breakpoint set.")); |
c906108c SS |
16391 | } |
16392 | ||
1bedd215 | 16393 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16394 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16395 | The \"Type\" column indicates one of:\n\ |
16396 | \tbreakpoint - normal breakpoint\n\ | |
16397 | \twatchpoint - watchpoint\n\ | |
16398 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16399 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16400 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16401 | address and file/line number respectively.\n\ |
16402 | \n\ | |
16403 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16404 | are set to the address of the last breakpoint listed unless the command\n\ |
16405 | is prefixed with \"server \".\n\n\ | |
c906108c | 16406 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16407 | breakpoint set.")); |
c906108c | 16408 | |
6b04bdb7 MS |
16409 | add_info_alias ("b", "breakpoints", 1); |
16410 | ||
1a966eab AC |
16411 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16412 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16413 | The \"Type\" column indicates one of:\n\ |
16414 | \tbreakpoint - normal breakpoint\n\ | |
16415 | \twatchpoint - watchpoint\n\ | |
16416 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16417 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16418 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16419 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16420 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16421 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16422 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16423 | address and file/line number respectively.\n\ |
16424 | \n\ | |
16425 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16426 | are set to the address of the last breakpoint listed unless the command\n\ |
16427 | is prefixed with \"server \".\n\n\ | |
c906108c | 16428 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16429 | breakpoint set."), |
c906108c SS |
16430 | &maintenanceinfolist); |
16431 | ||
44feb3ce TT |
16432 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16433 | Set catchpoints to catch events."), | |
16434 | &catch_cmdlist, "catch ", | |
16435 | 0/*allow-unknown*/, &cmdlist); | |
16436 | ||
16437 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16438 | Set temporary catchpoints to catch events."), | |
16439 | &tcatch_cmdlist, "tcatch ", | |
16440 | 0/*allow-unknown*/, &cmdlist); | |
16441 | ||
44feb3ce TT |
16442 | add_catch_command ("fork", _("Catch calls to fork."), |
16443 | catch_fork_command_1, | |
a96d9b2e | 16444 | NULL, |
44feb3ce TT |
16445 | (void *) (uintptr_t) catch_fork_permanent, |
16446 | (void *) (uintptr_t) catch_fork_temporary); | |
16447 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16448 | catch_fork_command_1, | |
a96d9b2e | 16449 | NULL, |
44feb3ce TT |
16450 | (void *) (uintptr_t) catch_vfork_permanent, |
16451 | (void *) (uintptr_t) catch_vfork_temporary); | |
16452 | add_catch_command ("exec", _("Catch calls to exec."), | |
16453 | catch_exec_command_1, | |
a96d9b2e SDJ |
16454 | NULL, |
16455 | CATCH_PERMANENT, | |
16456 | CATCH_TEMPORARY); | |
edcc5120 TT |
16457 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16458 | Usage: catch load [REGEX]\n\ | |
16459 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16460 | catch_load_command_1, | |
16461 | NULL, | |
16462 | CATCH_PERMANENT, | |
16463 | CATCH_TEMPORARY); | |
16464 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16465 | Usage: catch unload [REGEX]\n\ | |
16466 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16467 | catch_unload_command_1, | |
16468 | NULL, | |
16469 | CATCH_PERMANENT, | |
16470 | CATCH_TEMPORARY); | |
c5aa993b | 16471 | |
1bedd215 AC |
16472 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16473 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16474 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16475 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16476 | an expression changes.\n\ |
16477 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16478 | the memory to which it refers.")); | |
65d12d83 | 16479 | set_cmd_completer (c, expression_completer); |
c906108c | 16480 | |
1bedd215 AC |
16481 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16482 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16483 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16484 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16485 | an expression is read.\n\ |
16486 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16487 | the memory to which it refers.")); | |
65d12d83 | 16488 | set_cmd_completer (c, expression_completer); |
c906108c | 16489 | |
1bedd215 AC |
16490 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16491 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16492 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16493 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16494 | an expression is either read or written.\n\ |
16495 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16496 | the memory to which it refers.")); | |
65d12d83 | 16497 | set_cmd_completer (c, expression_completer); |
c906108c | 16498 | |
d77f58be | 16499 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16500 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16501 | |
920d2a44 AC |
16502 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16503 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16504 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16505 | &can_use_hw_watchpoints, _("\ | |
16506 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16507 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16508 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16509 | such is available. (However, any hardware watchpoints that were\n\ | |
16510 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16511 | hardware.)"), |
16512 | NULL, | |
920d2a44 | 16513 | show_can_use_hw_watchpoints, |
85c07804 | 16514 | &setlist, &showlist); |
c906108c SS |
16515 | |
16516 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16517 | |
1042e4c0 SS |
16518 | /* Tracepoint manipulation commands. */ |
16519 | ||
16520 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16521 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16522 | \n" |
16523 | BREAK_ARGS_HELP ("trace") "\n\ | |
16524 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16525 | set_cmd_completer (c, location_completer); | |
16526 | ||
16527 | add_com_alias ("tp", "trace", class_alias, 0); | |
16528 | add_com_alias ("tr", "trace", class_alias, 1); | |
16529 | add_com_alias ("tra", "trace", class_alias, 1); | |
16530 | add_com_alias ("trac", "trace", class_alias, 1); | |
16531 | ||
7a697b8d | 16532 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16533 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16534 | \n" |
16535 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16536 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16537 | set_cmd_completer (c, location_completer); | |
16538 | ||
0fb4aa4b | 16539 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16540 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16541 | \n\ |
16542 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16543 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16544 | or -m MARKER_ID.\n\n\ | |
16545 | If a marker id is specified, probe the marker with that name. With\n\ | |
16546 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16547 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16548 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16549 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16550 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16551 | \n\ | |
16552 | CONDITION is a boolean expression.\n\ | |
629500fa | 16553 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16554 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16555 | conditions are different.\n\ | |
0fb4aa4b PA |
16556 | \n\ |
16557 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16558 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16559 | set_cmd_completer (c, location_completer); | |
16560 | ||
1042e4c0 | 16561 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16562 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16563 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16564 | last tracepoint set.")); | |
16565 | ||
16566 | add_info_alias ("tp", "tracepoints", 1); | |
16567 | ||
16568 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16569 | Delete specified tracepoints.\n\ | |
16570 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16571 | No argument means delete all tracepoints."), | |
16572 | &deletelist); | |
7e20dfcd | 16573 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16574 | |
16575 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16576 | Disable specified tracepoints.\n\ | |
16577 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16578 | No argument means disable all tracepoints."), | |
16579 | &disablelist); | |
16580 | deprecate_cmd (c, "disable"); | |
16581 | ||
16582 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16583 | Enable specified tracepoints.\n\ | |
16584 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16585 | No argument means enable all tracepoints."), | |
16586 | &enablelist); | |
16587 | deprecate_cmd (c, "enable"); | |
16588 | ||
16589 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16590 | Set the passcount for a tracepoint.\n\ | |
16591 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16592 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16593 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16594 | ||
6149aea9 PA |
16595 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16596 | _("Save breakpoint definitions as a script."), | |
16597 | &save_cmdlist, "save ", | |
16598 | 0/*allow-unknown*/, &cmdlist); | |
16599 | ||
16600 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16601 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16602 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16603 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16604 | session to restore them."), | |
16605 | &save_cmdlist); | |
16606 | set_cmd_completer (c, filename_completer); | |
16607 | ||
16608 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16609 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16610 | Use the 'source' command in another debug session to restore them."), |
16611 | &save_cmdlist); | |
1042e4c0 SS |
16612 | set_cmd_completer (c, filename_completer); |
16613 | ||
6149aea9 PA |
16614 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16615 | deprecate_cmd (c, "save tracepoints"); | |
16616 | ||
1bedd215 | 16617 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16618 | Breakpoint specific settings\n\ |
16619 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16620 | pending breakpoint behavior"), |
fa8d40ab JJ |
16621 | &breakpoint_set_cmdlist, "set breakpoint ", |
16622 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16623 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16624 | Breakpoint specific settings\n\ |
16625 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16626 | pending breakpoint behavior"), |
fa8d40ab JJ |
16627 | &breakpoint_show_cmdlist, "show breakpoint ", |
16628 | 0/*allow-unknown*/, &showlist); | |
16629 | ||
7915a72c AC |
16630 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16631 | &pending_break_support, _("\ | |
16632 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16633 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16634 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16635 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16636 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16637 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16638 | NULL, |
920d2a44 | 16639 | show_pending_break_support, |
6e1d7d6c AC |
16640 | &breakpoint_set_cmdlist, |
16641 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16642 | |
16643 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16644 | |
16645 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16646 | &automatic_hardware_breakpoints, _("\ | |
16647 | Set automatic usage of hardware breakpoints."), _("\ | |
16648 | Show automatic usage of hardware breakpoints."), _("\ | |
16649 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16650 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16651 | a warning will be emitted for such breakpoints."), | |
16652 | NULL, | |
16653 | show_automatic_hardware_breakpoints, | |
16654 | &breakpoint_set_cmdlist, | |
16655 | &breakpoint_show_cmdlist); | |
74960c60 | 16656 | |
a25a5a45 PA |
16657 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16658 | &always_inserted_mode, _("\ | |
74960c60 VP |
16659 | Set mode for inserting breakpoints."), _("\ |
16660 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16661 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16662 | they're created, kept inserted even when execution stops, and removed\n\ | |
16663 | only when the user deletes them. When this mode is off (the default),\n\ | |
16664 | breakpoints are inserted only when execution continues, and removed\n\ | |
16665 | when execution stops."), | |
72d0e2c5 YQ |
16666 | NULL, |
16667 | &show_always_inserted_mode, | |
16668 | &breakpoint_set_cmdlist, | |
16669 | &breakpoint_show_cmdlist); | |
f1310107 | 16670 | |
b775012e LM |
16671 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16672 | condition_evaluation_enums, | |
16673 | &condition_evaluation_mode_1, _("\ | |
16674 | Set mode of breakpoint condition evaluation."), _("\ | |
16675 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16676 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16677 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16678 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16679 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16680 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16681 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16682 | be set to \"gdb\""), | |
16683 | &set_condition_evaluation_mode, | |
16684 | &show_condition_evaluation_mode, | |
16685 | &breakpoint_set_cmdlist, | |
16686 | &breakpoint_show_cmdlist); | |
16687 | ||
f1310107 TJB |
16688 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16689 | Set a breakpoint for an address range.\n\ | |
16690 | break-range START-LOCATION, END-LOCATION\n\ | |
16691 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16692 | LINENUM, for that line in the current file,\n\ | |
16693 | FILE:LINENUM, for that line in that file,\n\ | |
16694 | +OFFSET, for that number of lines after the current line\n\ | |
16695 | or the start of the range\n\ | |
16696 | FUNCTION, for the first line in that function,\n\ | |
16697 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16698 | *ADDRESS, for the instruction at that address.\n\ | |
16699 | \n\ | |
16700 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16701 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16702 | range (including START-LOCATION and END-LOCATION).")); | |
16703 | ||
e7e0cddf | 16704 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16705 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16706 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16707 | location may be a linespec, explicit, or address location.\n" |
16708 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16709 | set_cmd_completer (c, location_completer); |
16710 | ||
16711 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16712 | dprintf_style_enums, &dprintf_style, _("\ | |
16713 | Set the style of usage for dynamic printf."), _("\ | |
16714 | Show the style of usage for dynamic printf."), _("\ | |
16715 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16716 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16717 | console, as with the \"printf\" command.\n\ | |
16718 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16719 | program; by default printf(), but you can choose a different function or\n\ | |
16720 | output stream by setting dprintf-function and dprintf-channel."), | |
16721 | update_dprintf_commands, NULL, | |
16722 | &setlist, &showlist); | |
16723 | ||
16724 | dprintf_function = xstrdup ("printf"); | |
16725 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16726 | &dprintf_function, _("\ | |
16727 | Set the function to use for dynamic printf"), _("\ | |
16728 | Show the function to use for dynamic printf"), NULL, | |
16729 | update_dprintf_commands, NULL, | |
16730 | &setlist, &showlist); | |
16731 | ||
16732 | dprintf_channel = xstrdup (""); | |
16733 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16734 | &dprintf_channel, _("\ | |
16735 | Set the channel to use for dynamic printf"), _("\ | |
16736 | Show the channel to use for dynamic printf"), NULL, | |
16737 | update_dprintf_commands, NULL, | |
16738 | &setlist, &showlist); | |
16739 | ||
d3ce09f5 SS |
16740 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16741 | &disconnected_dprintf, _("\ | |
16742 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16743 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16744 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16745 | even if GDB disconnects or detaches from the target."), | |
16746 | NULL, | |
16747 | NULL, | |
16748 | &setlist, &showlist); | |
16749 | ||
16750 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16751 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16752 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16753 | ||
765dc015 | 16754 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16755 | |
16756 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16757 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16758 | } |