Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
61baf725 | 3 | Copyright (C) 1986-2017 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
8b93c638 | 47 | #include "ui-out.h" |
e1507482 | 48 | #include "cli/cli-script.h" |
fe898f56 | 49 | #include "block.h" |
a77053c2 | 50 | #include "solib.h" |
84acb35a JJ |
51 | #include "solist.h" |
52 | #include "observer.h" | |
765dc015 | 53 | #include "memattr.h" |
f7f9143b | 54 | #include "ada-lang.h" |
d1aa2f50 | 55 | #include "top.h" |
79a45b7d | 56 | #include "valprint.h" |
4efc6507 | 57 | #include "jit.h" |
65d79d4b | 58 | #include "parser-defs.h" |
55aa24fb SDJ |
59 | #include "gdb_regex.h" |
60 | #include "probe.h" | |
e9cafbcc | 61 | #include "cli/cli-utils.h" |
be34f849 | 62 | #include "continuations.h" |
1bfeeb0f JL |
63 | #include "stack.h" |
64 | #include "skip.h" | |
b775012e | 65 | #include "ax-gdb.h" |
e2e4d78b | 66 | #include "dummy-frame.h" |
5589af0e | 67 | #include "interps.h" |
d3ce09f5 | 68 | #include "format.h" |
cfc31633 | 69 | #include "thread-fsm.h" |
5d5658a1 | 70 | #include "tid-parse.h" |
d3ce09f5 | 71 | |
1042e4c0 SS |
72 | /* readline include files */ |
73 | #include "readline/readline.h" | |
74 | #include "readline/history.h" | |
75 | ||
76 | /* readline defines this. */ | |
77 | #undef savestring | |
78 | ||
034dad6f | 79 | #include "mi/mi-common.h" |
6dddc817 | 80 | #include "extension.h" |
325fac50 | 81 | #include <algorithm> |
5ed8105e | 82 | #include "progspace-and-thread.h" |
6c5b2ebe | 83 | #include "common/array-view.h" |
76f9c9cf | 84 | #include "common/gdb_optional.h" |
104c1213 | 85 | |
e7e8980f YQ |
86 | /* Enums for exception-handling support. */ |
87 | enum exception_event_kind | |
88 | { | |
89 | EX_EVENT_THROW, | |
591f19e8 | 90 | EX_EVENT_RETHROW, |
e7e8980f YQ |
91 | EX_EVENT_CATCH |
92 | }; | |
93 | ||
4a64f543 | 94 | /* Prototypes for local functions. */ |
c906108c | 95 | |
a14ed312 | 96 | static void disable_command (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void enable_command (char *, int); |
c906108c | 99 | |
896b6bda | 100 | static void map_breakpoint_numbers (const char *, |
48649e1b | 101 | gdb::function_view<void (breakpoint *)>); |
c906108c | 102 | |
a14ed312 | 103 | static void ignore_command (char *, int); |
c906108c | 104 | |
348d480f PA |
105 | static void breakpoint_re_set_default (struct breakpoint *); |
106 | ||
f00aae0f KS |
107 | static void |
108 | create_sals_from_location_default (const struct event_location *location, | |
109 | struct linespec_result *canonical, | |
110 | enum bptype type_wanted); | |
983af33b SDJ |
111 | |
112 | static void create_breakpoints_sal_default (struct gdbarch *, | |
113 | struct linespec_result *, | |
e1e01040 PA |
114 | gdb::unique_xmalloc_ptr<char>, |
115 | gdb::unique_xmalloc_ptr<char>, | |
116 | enum bptype, | |
983af33b SDJ |
117 | enum bpdisp, int, int, |
118 | int, | |
119 | const struct breakpoint_ops *, | |
44f238bb | 120 | int, int, int, unsigned); |
983af33b | 121 | |
6c5b2ebe PA |
122 | static std::vector<symtab_and_line> decode_location_default |
123 | (struct breakpoint *b, const struct event_location *location, | |
124 | struct program_space *search_pspace); | |
983af33b | 125 | |
a14ed312 | 126 | static void clear_command (char *, int); |
c906108c | 127 | |
a14ed312 | 128 | static void catch_command (char *, int); |
c906108c | 129 | |
a9634178 | 130 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 131 | |
a14ed312 | 132 | static void mention (struct breakpoint *); |
c906108c | 133 | |
348d480f PA |
134 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
135 | enum bptype, | |
c0a91b2b | 136 | const struct breakpoint_ops *); |
3742cc8b YQ |
137 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
138 | const struct symtab_and_line *); | |
139 | ||
4a64f543 MS |
140 | /* This function is used in gdbtk sources and thus can not be made |
141 | static. */ | |
63c252f8 | 142 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 143 | struct symtab_and_line, |
c0a91b2b TT |
144 | enum bptype, |
145 | const struct breakpoint_ops *); | |
c906108c | 146 | |
06edf0c0 PA |
147 | static struct breakpoint * |
148 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
149 | enum bptype type, | |
a1aa2221 LM |
150 | const struct breakpoint_ops *ops, |
151 | int loc_enabled); | |
06edf0c0 | 152 | |
76897487 KB |
153 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
154 | ||
a6d9a66e UW |
155 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
156 | CORE_ADDR bpaddr, | |
88f7da05 | 157 | enum bptype bptype); |
76897487 | 158 | |
6c95b8df PA |
159 | static void describe_other_breakpoints (struct gdbarch *, |
160 | struct program_space *, CORE_ADDR, | |
5af949e3 | 161 | struct obj_section *, int); |
c906108c | 162 | |
85d721b8 PA |
163 | static int watchpoint_locations_match (struct bp_location *loc1, |
164 | struct bp_location *loc2); | |
165 | ||
f1310107 TJB |
166 | static int breakpoint_location_address_match (struct bp_location *bl, |
167 | struct address_space *aspace, | |
168 | CORE_ADDR addr); | |
169 | ||
d35ae833 PA |
170 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
171 | struct address_space *, | |
172 | CORE_ADDR, int); | |
173 | ||
11db9430 | 174 | static void info_breakpoints_command (char *, int); |
c906108c | 175 | |
11db9430 | 176 | static void info_watchpoints_command (char *, int); |
d77f58be | 177 | |
4efb68b1 | 178 | static void cleanup_executing_breakpoints (void *); |
c906108c | 179 | |
a14ed312 | 180 | static void commands_command (char *, int); |
c906108c | 181 | |
a14ed312 | 182 | static void condition_command (char *, int); |
c906108c | 183 | |
834c0d03 | 184 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 185 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 186 | |
e514a9d6 | 187 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 188 | |
a14ed312 | 189 | static int hw_breakpoint_used_count (void); |
c906108c | 190 | |
a1398e0c PA |
191 | static int hw_watchpoint_use_count (struct breakpoint *); |
192 | ||
193 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
194 | enum bptype type, | |
195 | int *other_type_used); | |
c906108c | 196 | |
a14ed312 | 197 | static void hbreak_command (char *, int); |
c906108c | 198 | |
a14ed312 | 199 | static void thbreak_command (char *, int); |
c906108c | 200 | |
816338b5 SS |
201 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
202 | int count); | |
c906108c | 203 | |
a14ed312 | 204 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 205 | |
a14ed312 | 206 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 207 | |
fe3f5fa8 | 208 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
209 | static void incref_bp_location (struct bp_location *loc); |
210 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 211 | |
39d61571 | 212 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 213 | |
44702360 PA |
214 | /* update_global_location_list's modes of operation wrt to whether to |
215 | insert locations now. */ | |
216 | enum ugll_insert_mode | |
217 | { | |
218 | /* Don't insert any breakpoint locations into the inferior, only | |
219 | remove already-inserted locations that no longer should be | |
220 | inserted. Functions that delete a breakpoint or breakpoints | |
221 | should specify this mode, so that deleting a breakpoint doesn't | |
222 | have the side effect of inserting the locations of other | |
223 | breakpoints that are marked not-inserted, but should_be_inserted | |
224 | returns true on them. | |
225 | ||
226 | This behavior is useful is situations close to tear-down -- e.g., | |
227 | after an exec, while the target still has execution, but | |
228 | breakpoint shadows of the previous executable image should *NOT* | |
229 | be restored to the new image; or before detaching, where the | |
230 | target still has execution and wants to delete breakpoints from | |
231 | GDB's lists, and all breakpoints had already been removed from | |
232 | the inferior. */ | |
233 | UGLL_DONT_INSERT, | |
234 | ||
a25a5a45 PA |
235 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
236 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
237 | UGLL_MAY_INSERT, |
238 | ||
a25a5a45 PA |
239 | /* Insert locations now, irrespective of |
240 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
241 | stopped right now, and the user did "continue". We need to | |
242 | insert breakpoints _before_ resuming the target, but | |
243 | UGLL_MAY_INSERT wouldn't insert them, because | |
244 | breakpoints_should_be_inserted_now returns false at that point, | |
245 | as no thread is running yet. */ | |
04086b45 | 246 | UGLL_INSERT |
44702360 PA |
247 | }; |
248 | ||
249 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 250 | |
44702360 | 251 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 252 | |
d77f58be | 253 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
254 | |
255 | static void insert_breakpoint_locations (void); | |
a5606eee | 256 | |
11db9430 | 257 | static void info_tracepoints_command (char *, int); |
1042e4c0 | 258 | |
1042e4c0 SS |
259 | static void enable_trace_command (char *, int); |
260 | ||
261 | static void disable_trace_command (char *, int); | |
262 | ||
263 | static void trace_pass_command (char *, int); | |
264 | ||
558a9d82 YQ |
265 | static void set_tracepoint_count (int num); |
266 | ||
9c06b0b4 TJB |
267 | static int is_masked_watchpoint (const struct breakpoint *b); |
268 | ||
b775012e LM |
269 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
270 | ||
983af33b SDJ |
271 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
272 | otherwise. */ | |
273 | ||
274 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 275 | |
2060206e PA |
276 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
277 | that are implemented on top of software or hardware breakpoints | |
278 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
279 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
280 | ||
281 | /* Internal breakpoints class type. */ | |
06edf0c0 | 282 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
283 | |
284 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
285 | static struct breakpoint_ops momentary_breakpoint_ops; |
286 | ||
2060206e PA |
287 | /* The breakpoint_ops structure to be used in regular user created |
288 | breakpoints. */ | |
289 | struct breakpoint_ops bkpt_breakpoint_ops; | |
290 | ||
55aa24fb SDJ |
291 | /* Breakpoints set on probes. */ |
292 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
293 | ||
e7e0cddf | 294 | /* Dynamic printf class type. */ |
c5867ab6 | 295 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 296 | |
d3ce09f5 SS |
297 | /* The style in which to perform a dynamic printf. This is a user |
298 | option because different output options have different tradeoffs; | |
299 | if GDB does the printing, there is better error handling if there | |
300 | is a problem with any of the arguments, but using an inferior | |
301 | function lets you have special-purpose printers and sending of | |
302 | output to the same place as compiled-in print functions. */ | |
303 | ||
304 | static const char dprintf_style_gdb[] = "gdb"; | |
305 | static const char dprintf_style_call[] = "call"; | |
306 | static const char dprintf_style_agent[] = "agent"; | |
307 | static const char *const dprintf_style_enums[] = { | |
308 | dprintf_style_gdb, | |
309 | dprintf_style_call, | |
310 | dprintf_style_agent, | |
311 | NULL | |
312 | }; | |
313 | static const char *dprintf_style = dprintf_style_gdb; | |
314 | ||
315 | /* The function to use for dynamic printf if the preferred style is to | |
316 | call into the inferior. The value is simply a string that is | |
317 | copied into the command, so it can be anything that GDB can | |
318 | evaluate to a callable address, not necessarily a function name. */ | |
319 | ||
bde6261a | 320 | static char *dprintf_function; |
d3ce09f5 SS |
321 | |
322 | /* The channel to use for dynamic printf if the preferred style is to | |
323 | call into the inferior; if a nonempty string, it will be passed to | |
324 | the call as the first argument, with the format string as the | |
325 | second. As with the dprintf function, this can be anything that | |
326 | GDB knows how to evaluate, so in addition to common choices like | |
327 | "stderr", this could be an app-specific expression like | |
328 | "mystreams[curlogger]". */ | |
329 | ||
bde6261a | 330 | static char *dprintf_channel; |
d3ce09f5 SS |
331 | |
332 | /* True if dprintf commands should continue to operate even if GDB | |
333 | has disconnected. */ | |
334 | static int disconnected_dprintf = 1; | |
335 | ||
5cea2a26 PA |
336 | struct command_line * |
337 | breakpoint_commands (struct breakpoint *b) | |
338 | { | |
d1b0a7bf | 339 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 340 | } |
3daf8fe5 | 341 | |
f3b1572e PA |
342 | /* Flag indicating that a command has proceeded the inferior past the |
343 | current breakpoint. */ | |
344 | ||
345 | static int breakpoint_proceeded; | |
346 | ||
956a9fb9 | 347 | const char * |
2cec12e5 AR |
348 | bpdisp_text (enum bpdisp disp) |
349 | { | |
4a64f543 MS |
350 | /* NOTE: the following values are a part of MI protocol and |
351 | represent values of 'disp' field returned when inferior stops at | |
352 | a breakpoint. */ | |
bc043ef3 | 353 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 354 | |
2cec12e5 AR |
355 | return bpdisps[(int) disp]; |
356 | } | |
c906108c | 357 | |
4a64f543 | 358 | /* Prototypes for exported functions. */ |
c906108c | 359 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 360 | if such is available. */ |
c906108c SS |
361 | static int can_use_hw_watchpoints; |
362 | ||
920d2a44 AC |
363 | static void |
364 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
365 | struct cmd_list_element *c, | |
366 | const char *value) | |
367 | { | |
3e43a32a MS |
368 | fprintf_filtered (file, |
369 | _("Debugger's willingness to use " | |
370 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
371 | value); |
372 | } | |
373 | ||
fa8d40ab JJ |
374 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
375 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 376 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
377 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
378 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
379 | static void |
380 | show_pending_break_support (struct ui_file *file, int from_tty, | |
381 | struct cmd_list_element *c, | |
382 | const char *value) | |
383 | { | |
3e43a32a MS |
384 | fprintf_filtered (file, |
385 | _("Debugger's behavior regarding " | |
386 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
387 | value); |
388 | } | |
fa8d40ab | 389 | |
765dc015 | 390 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 391 | set with "break" but falling in read-only memory. |
765dc015 VP |
392 | If 0, gdb will warn about such breakpoints, but won't automatically |
393 | use hardware breakpoints. */ | |
394 | static int automatic_hardware_breakpoints; | |
395 | static void | |
396 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
397 | struct cmd_list_element *c, | |
398 | const char *value) | |
399 | { | |
3e43a32a MS |
400 | fprintf_filtered (file, |
401 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
402 | value); |
403 | } | |
404 | ||
a25a5a45 PA |
405 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
406 | stopped, and immediately inserts any new breakpoints as soon as | |
407 | they're created. If off (default), GDB keeps breakpoints off of | |
408 | the target as long as possible. That is, it delays inserting | |
409 | breakpoints until the next resume, and removes them again when the | |
410 | target fully stops. This is a bit safer in case GDB crashes while | |
411 | processing user input. */ | |
412 | static int always_inserted_mode = 0; | |
72d0e2c5 | 413 | |
33e5cbd6 | 414 | static void |
74960c60 | 415 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 416 | struct cmd_list_element *c, const char *value) |
74960c60 | 417 | { |
a25a5a45 PA |
418 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
419 | value); | |
74960c60 VP |
420 | } |
421 | ||
b57bacec PA |
422 | /* See breakpoint.h. */ |
423 | ||
33e5cbd6 | 424 | int |
a25a5a45 | 425 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 426 | { |
a25a5a45 PA |
427 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
428 | { | |
429 | /* If breakpoints are global, they should be inserted even if no | |
430 | thread under gdb's control is running, or even if there are | |
431 | no threads under GDB's control yet. */ | |
432 | return 1; | |
433 | } | |
434 | else if (target_has_execution) | |
435 | { | |
372316f1 PA |
436 | struct thread_info *tp; |
437 | ||
a25a5a45 PA |
438 | if (always_inserted_mode) |
439 | { | |
440 | /* The user wants breakpoints inserted even if all threads | |
441 | are stopped. */ | |
442 | return 1; | |
443 | } | |
444 | ||
b57bacec PA |
445 | if (threads_are_executing ()) |
446 | return 1; | |
372316f1 PA |
447 | |
448 | /* Don't remove breakpoints yet if, even though all threads are | |
449 | stopped, we still have events to process. */ | |
450 | ALL_NON_EXITED_THREADS (tp) | |
451 | if (tp->resumed | |
452 | && tp->suspend.waitstatus_pending_p) | |
453 | return 1; | |
a25a5a45 PA |
454 | } |
455 | return 0; | |
33e5cbd6 | 456 | } |
765dc015 | 457 | |
b775012e LM |
458 | static const char condition_evaluation_both[] = "host or target"; |
459 | ||
460 | /* Modes for breakpoint condition evaluation. */ | |
461 | static const char condition_evaluation_auto[] = "auto"; | |
462 | static const char condition_evaluation_host[] = "host"; | |
463 | static const char condition_evaluation_target[] = "target"; | |
464 | static const char *const condition_evaluation_enums[] = { | |
465 | condition_evaluation_auto, | |
466 | condition_evaluation_host, | |
467 | condition_evaluation_target, | |
468 | NULL | |
469 | }; | |
470 | ||
471 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
472 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
473 | ||
474 | /* Global that we use to display information to the user (gets its value from | |
475 | condition_evaluation_mode_1. */ | |
476 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
477 | ||
478 | /* Translate a condition evaluation mode MODE into either "host" | |
479 | or "target". This is used mostly to translate from "auto" to the | |
480 | real setting that is being used. It returns the translated | |
481 | evaluation mode. */ | |
482 | ||
483 | static const char * | |
484 | translate_condition_evaluation_mode (const char *mode) | |
485 | { | |
486 | if (mode == condition_evaluation_auto) | |
487 | { | |
488 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
489 | return condition_evaluation_target; | |
490 | else | |
491 | return condition_evaluation_host; | |
492 | } | |
493 | else | |
494 | return mode; | |
495 | } | |
496 | ||
497 | /* Discovers what condition_evaluation_auto translates to. */ | |
498 | ||
499 | static const char * | |
500 | breakpoint_condition_evaluation_mode (void) | |
501 | { | |
502 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
503 | } | |
504 | ||
505 | /* Return true if GDB should evaluate breakpoint conditions or false | |
506 | otherwise. */ | |
507 | ||
508 | static int | |
509 | gdb_evaluates_breakpoint_condition_p (void) | |
510 | { | |
511 | const char *mode = breakpoint_condition_evaluation_mode (); | |
512 | ||
513 | return (mode == condition_evaluation_host); | |
514 | } | |
515 | ||
c906108c SS |
516 | /* Are we executing breakpoint commands? */ |
517 | static int executing_breakpoint_commands; | |
518 | ||
c02f5703 MS |
519 | /* Are overlay event breakpoints enabled? */ |
520 | static int overlay_events_enabled; | |
521 | ||
e09342b5 TJB |
522 | /* See description in breakpoint.h. */ |
523 | int target_exact_watchpoints = 0; | |
524 | ||
c906108c | 525 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 526 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 527 | current breakpoint. */ |
c906108c | 528 | |
5c44784c | 529 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 530 | |
5c44784c JM |
531 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
532 | for (B = breakpoint_chain; \ | |
533 | B ? (TMP=B->next, 1): 0; \ | |
534 | B = TMP) | |
c906108c | 535 | |
4a64f543 MS |
536 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
537 | not provided so update_global_location_list must not be called | |
538 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 539 | |
876fa593 | 540 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
541 | for (BP_TMP = bp_locations; \ |
542 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 543 | BP_TMP++) |
7cc221ef | 544 | |
b775012e LM |
545 | /* Iterates through locations with address ADDRESS for the currently selected |
546 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
547 | to where the loop should start from. | |
548 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
549 | appropriate location to start with. */ | |
550 | ||
551 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
552 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
553 | BP_LOCP_TMP = BP_LOCP_START; \ | |
554 | BP_LOCP_START \ | |
f5336ca5 | 555 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
556 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
557 | BP_LOCP_TMP++) | |
558 | ||
1042e4c0 SS |
559 | /* Iterator for tracepoints only. */ |
560 | ||
561 | #define ALL_TRACEPOINTS(B) \ | |
562 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 563 | if (is_tracepoint (B)) |
1042e4c0 | 564 | |
7cc221ef | 565 | /* Chains of all breakpoints defined. */ |
c906108c SS |
566 | |
567 | struct breakpoint *breakpoint_chain; | |
568 | ||
f5336ca5 | 569 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
876fa593 | 570 | |
f5336ca5 | 571 | static struct bp_location **bp_locations; |
876fa593 | 572 | |
f5336ca5 | 573 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 574 | |
f5336ca5 | 575 | static unsigned bp_locations_count; |
876fa593 | 576 | |
4a64f543 | 577 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 578 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 579 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 580 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 581 | an address you need to read. */ |
876fa593 | 582 | |
f5336ca5 | 583 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 584 | |
4a64f543 MS |
585 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
586 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
587 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
588 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 589 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 590 | |
f5336ca5 | 591 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 592 | |
4a64f543 | 593 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
594 | from the bp_locations array, but for which a hit may still be |
595 | reported by a target. */ | |
20874c92 VP |
596 | VEC(bp_location_p) *moribund_locations = NULL; |
597 | ||
c906108c SS |
598 | /* Number of last breakpoint made. */ |
599 | ||
95a42b64 TT |
600 | static int breakpoint_count; |
601 | ||
86b17b60 PA |
602 | /* The value of `breakpoint_count' before the last command that |
603 | created breakpoints. If the last (break-like) command created more | |
604 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
605 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
606 | static int prev_breakpoint_count; | |
c906108c | 607 | |
1042e4c0 SS |
608 | /* Number of last tracepoint made. */ |
609 | ||
95a42b64 | 610 | static int tracepoint_count; |
1042e4c0 | 611 | |
6149aea9 PA |
612 | static struct cmd_list_element *breakpoint_set_cmdlist; |
613 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 614 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 615 | |
badd37ce SDJ |
616 | /* See declaration at breakpoint.h. */ |
617 | ||
618 | struct breakpoint * | |
619 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
620 | void *user_data) | |
621 | { | |
622 | struct breakpoint *b = NULL; | |
623 | ||
624 | ALL_BREAKPOINTS (b) | |
625 | { | |
626 | if (func (b, user_data) != 0) | |
627 | break; | |
628 | } | |
629 | ||
630 | return b; | |
631 | } | |
632 | ||
468d015d JJ |
633 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
634 | static int | |
635 | breakpoint_enabled (struct breakpoint *b) | |
636 | { | |
0d381245 | 637 | return (b->enable_state == bp_enabled); |
468d015d JJ |
638 | } |
639 | ||
c906108c SS |
640 | /* Set breakpoint count to NUM. */ |
641 | ||
95a42b64 | 642 | static void |
fba45db2 | 643 | set_breakpoint_count (int num) |
c906108c | 644 | { |
86b17b60 | 645 | prev_breakpoint_count = breakpoint_count; |
c906108c | 646 | breakpoint_count = num; |
4fa62494 | 647 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
648 | } |
649 | ||
86b17b60 PA |
650 | /* Used by `start_rbreak_breakpoints' below, to record the current |
651 | breakpoint count before "rbreak" creates any breakpoint. */ | |
652 | static int rbreak_start_breakpoint_count; | |
653 | ||
95a42b64 TT |
654 | /* Called at the start an "rbreak" command to record the first |
655 | breakpoint made. */ | |
86b17b60 | 656 | |
95a42b64 TT |
657 | void |
658 | start_rbreak_breakpoints (void) | |
659 | { | |
86b17b60 | 660 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
661 | } |
662 | ||
663 | /* Called at the end of an "rbreak" command to record the last | |
664 | breakpoint made. */ | |
86b17b60 | 665 | |
95a42b64 TT |
666 | void |
667 | end_rbreak_breakpoints (void) | |
668 | { | |
86b17b60 | 669 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
670 | } |
671 | ||
4a64f543 | 672 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
673 | |
674 | void | |
fba45db2 | 675 | clear_breakpoint_hit_counts (void) |
c906108c SS |
676 | { |
677 | struct breakpoint *b; | |
678 | ||
679 | ALL_BREAKPOINTS (b) | |
680 | b->hit_count = 0; | |
681 | } | |
682 | ||
c906108c | 683 | \f |
48cb2d85 VP |
684 | /* Return the breakpoint with the specified number, or NULL |
685 | if the number does not refer to an existing breakpoint. */ | |
686 | ||
687 | struct breakpoint * | |
688 | get_breakpoint (int num) | |
689 | { | |
690 | struct breakpoint *b; | |
691 | ||
692 | ALL_BREAKPOINTS (b) | |
693 | if (b->number == num) | |
694 | return b; | |
695 | ||
696 | return NULL; | |
697 | } | |
5c44784c | 698 | |
c906108c | 699 | \f |
adc36818 | 700 | |
b775012e LM |
701 | /* Mark locations as "conditions have changed" in case the target supports |
702 | evaluating conditions on its side. */ | |
703 | ||
704 | static void | |
705 | mark_breakpoint_modified (struct breakpoint *b) | |
706 | { | |
707 | struct bp_location *loc; | |
708 | ||
709 | /* This is only meaningful if the target is | |
710 | evaluating conditions and if the user has | |
711 | opted for condition evaluation on the target's | |
712 | side. */ | |
713 | if (gdb_evaluates_breakpoint_condition_p () | |
714 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
715 | return; | |
716 | ||
717 | if (!is_breakpoint (b)) | |
718 | return; | |
719 | ||
720 | for (loc = b->loc; loc; loc = loc->next) | |
721 | loc->condition_changed = condition_modified; | |
722 | } | |
723 | ||
724 | /* Mark location as "conditions have changed" in case the target supports | |
725 | evaluating conditions on its side. */ | |
726 | ||
727 | static void | |
728 | mark_breakpoint_location_modified (struct bp_location *loc) | |
729 | { | |
730 | /* This is only meaningful if the target is | |
731 | evaluating conditions and if the user has | |
732 | opted for condition evaluation on the target's | |
733 | side. */ | |
734 | if (gdb_evaluates_breakpoint_condition_p () | |
735 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
736 | ||
737 | return; | |
738 | ||
739 | if (!is_breakpoint (loc->owner)) | |
740 | return; | |
741 | ||
742 | loc->condition_changed = condition_modified; | |
743 | } | |
744 | ||
745 | /* Sets the condition-evaluation mode using the static global | |
746 | condition_evaluation_mode. */ | |
747 | ||
748 | static void | |
749 | set_condition_evaluation_mode (char *args, int from_tty, | |
750 | struct cmd_list_element *c) | |
751 | { | |
b775012e LM |
752 | const char *old_mode, *new_mode; |
753 | ||
754 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
755 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
756 | { | |
757 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
758 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
759 | "Using host evaluation mode instead.")); | |
760 | return; | |
761 | } | |
762 | ||
763 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
764 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
765 | ||
abf1152a JK |
766 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
767 | settings was "auto". */ | |
768 | condition_evaluation_mode = condition_evaluation_mode_1; | |
769 | ||
b775012e LM |
770 | /* Only update the mode if the user picked a different one. */ |
771 | if (new_mode != old_mode) | |
772 | { | |
773 | struct bp_location *loc, **loc_tmp; | |
774 | /* If the user switched to a different evaluation mode, we | |
775 | need to synch the changes with the target as follows: | |
776 | ||
777 | "host" -> "target": Send all (valid) conditions to the target. | |
778 | "target" -> "host": Remove all the conditions from the target. | |
779 | */ | |
780 | ||
b775012e LM |
781 | if (new_mode == condition_evaluation_target) |
782 | { | |
783 | /* Mark everything modified and synch conditions with the | |
784 | target. */ | |
785 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
786 | mark_breakpoint_location_modified (loc); | |
787 | } | |
788 | else | |
789 | { | |
790 | /* Manually mark non-duplicate locations to synch conditions | |
791 | with the target. We do this to remove all the conditions the | |
792 | target knows about. */ | |
793 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
794 | if (is_breakpoint (loc->owner) && loc->inserted) | |
795 | loc->needs_update = 1; | |
796 | } | |
797 | ||
798 | /* Do the update. */ | |
44702360 | 799 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
800 | } |
801 | ||
802 | return; | |
803 | } | |
804 | ||
805 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
806 | what "auto" is translating to. */ | |
807 | ||
808 | static void | |
809 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
810 | struct cmd_list_element *c, const char *value) | |
811 | { | |
812 | if (condition_evaluation_mode == condition_evaluation_auto) | |
813 | fprintf_filtered (file, | |
814 | _("Breakpoint condition evaluation " | |
815 | "mode is %s (currently %s).\n"), | |
816 | value, | |
817 | breakpoint_condition_evaluation_mode ()); | |
818 | else | |
819 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
820 | value); | |
821 | } | |
822 | ||
823 | /* A comparison function for bp_location AP and BP that is used by | |
824 | bsearch. This comparison function only cares about addresses, unlike | |
f5336ca5 | 825 | the more general bp_locations_compare function. */ |
b775012e LM |
826 | |
827 | static int | |
f5336ca5 | 828 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 829 | { |
9a3c8263 SM |
830 | const struct bp_location *a = *(const struct bp_location **) ap; |
831 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
832 | |
833 | if (a->address == b->address) | |
834 | return 0; | |
835 | else | |
836 | return ((a->address > b->address) - (a->address < b->address)); | |
837 | } | |
838 | ||
839 | /* Helper function to skip all bp_locations with addresses | |
840 | less than ADDRESS. It returns the first bp_location that | |
841 | is greater than or equal to ADDRESS. If none is found, just | |
842 | return NULL. */ | |
843 | ||
844 | static struct bp_location ** | |
845 | get_first_locp_gte_addr (CORE_ADDR address) | |
846 | { | |
847 | struct bp_location dummy_loc; | |
848 | struct bp_location *dummy_locp = &dummy_loc; | |
849 | struct bp_location **locp_found = NULL; | |
850 | ||
851 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
852 | dummy_loc.address = address; |
853 | ||
854 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 855 | locp_found = ((struct bp_location **) |
f5336ca5 | 856 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 857 | sizeof (struct bp_location **), |
f5336ca5 | 858 | bp_locations_compare_addrs)); |
b775012e LM |
859 | |
860 | /* Nothing was found, nothing left to do. */ | |
861 | if (locp_found == NULL) | |
862 | return NULL; | |
863 | ||
864 | /* We may have found a location that is at ADDRESS but is not the first in the | |
865 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 866 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
867 | && (*(locp_found - 1))->address == address) |
868 | locp_found--; | |
869 | ||
870 | return locp_found; | |
871 | } | |
872 | ||
adc36818 | 873 | void |
7a26bd4d | 874 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
875 | int from_tty) |
876 | { | |
3a5c3e22 PA |
877 | xfree (b->cond_string); |
878 | b->cond_string = NULL; | |
adc36818 | 879 | |
3a5c3e22 | 880 | if (is_watchpoint (b)) |
adc36818 | 881 | { |
3a5c3e22 PA |
882 | struct watchpoint *w = (struct watchpoint *) b; |
883 | ||
4d01a485 | 884 | w->cond_exp.reset (); |
3a5c3e22 PA |
885 | } |
886 | else | |
887 | { | |
888 | struct bp_location *loc; | |
889 | ||
890 | for (loc = b->loc; loc; loc = loc->next) | |
891 | { | |
4d01a485 | 892 | loc->cond.reset (); |
b775012e LM |
893 | |
894 | /* No need to free the condition agent expression | |
895 | bytecode (if we have one). We will handle this | |
896 | when we go through update_global_location_list. */ | |
3a5c3e22 | 897 | } |
adc36818 | 898 | } |
adc36818 PM |
899 | |
900 | if (*exp == 0) | |
901 | { | |
902 | if (from_tty) | |
903 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
904 | } | |
905 | else | |
906 | { | |
bbc13ae3 | 907 | const char *arg = exp; |
cc59ec59 | 908 | |
adc36818 PM |
909 | /* I don't know if it matters whether this is the string the user |
910 | typed in or the decompiled expression. */ | |
911 | b->cond_string = xstrdup (arg); | |
912 | b->condition_not_parsed = 0; | |
913 | ||
914 | if (is_watchpoint (b)) | |
915 | { | |
3a5c3e22 PA |
916 | struct watchpoint *w = (struct watchpoint *) b; |
917 | ||
adc36818 PM |
918 | innermost_block = NULL; |
919 | arg = exp; | |
1bb9788d | 920 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
921 | if (*arg) |
922 | error (_("Junk at end of expression")); | |
3a5c3e22 | 923 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
924 | } |
925 | else | |
926 | { | |
3a5c3e22 PA |
927 | struct bp_location *loc; |
928 | ||
adc36818 PM |
929 | for (loc = b->loc; loc; loc = loc->next) |
930 | { | |
931 | arg = exp; | |
932 | loc->cond = | |
1bb9788d TT |
933 | parse_exp_1 (&arg, loc->address, |
934 | block_for_pc (loc->address), 0); | |
adc36818 PM |
935 | if (*arg) |
936 | error (_("Junk at end of expression")); | |
937 | } | |
938 | } | |
939 | } | |
b775012e LM |
940 | mark_breakpoint_modified (b); |
941 | ||
8d3788bd | 942 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
943 | } |
944 | ||
d55637df TT |
945 | /* Completion for the "condition" command. */ |
946 | ||
eb3ff9a5 | 947 | static void |
6f937416 | 948 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 949 | completion_tracker &tracker, |
6f937416 | 950 | const char *text, const char *word) |
d55637df | 951 | { |
6f937416 | 952 | const char *space; |
d55637df | 953 | |
f1735a53 TT |
954 | text = skip_spaces (text); |
955 | space = skip_to_space (text); | |
d55637df TT |
956 | if (*space == '\0') |
957 | { | |
958 | int len; | |
959 | struct breakpoint *b; | |
960 | VEC (char_ptr) *result = NULL; | |
961 | ||
962 | if (text[0] == '$') | |
963 | { | |
964 | /* We don't support completion of history indices. */ | |
eb3ff9a5 PA |
965 | if (!isdigit (text[1])) |
966 | complete_internalvar (tracker, &text[1]); | |
967 | return; | |
d55637df TT |
968 | } |
969 | ||
970 | /* We're completing the breakpoint number. */ | |
971 | len = strlen (text); | |
972 | ||
973 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
974 | { |
975 | char number[50]; | |
976 | ||
977 | xsnprintf (number, sizeof (number), "%d", b->number); | |
978 | ||
979 | if (strncmp (number, text, len) == 0) | |
eb3ff9a5 PA |
980 | { |
981 | gdb::unique_xmalloc_ptr<char> copy (xstrdup (number)); | |
982 | tracker.add_completion (std::move (copy)); | |
983 | } | |
58ce7251 | 984 | } |
d55637df | 985 | |
eb3ff9a5 | 986 | return; |
d55637df TT |
987 | } |
988 | ||
989 | /* We're completing the expression part. */ | |
f1735a53 | 990 | text = skip_spaces (space); |
eb3ff9a5 | 991 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
992 | } |
993 | ||
c906108c SS |
994 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
995 | ||
996 | static void | |
fba45db2 | 997 | condition_command (char *arg, int from_tty) |
c906108c | 998 | { |
52f0bd74 | 999 | struct breakpoint *b; |
c906108c | 1000 | char *p; |
52f0bd74 | 1001 | int bnum; |
c906108c SS |
1002 | |
1003 | if (arg == 0) | |
e2e0b3e5 | 1004 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1005 | |
1006 | p = arg; | |
1007 | bnum = get_number (&p); | |
5c44784c | 1008 | if (bnum == 0) |
8a3fe4f8 | 1009 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1010 | |
1011 | ALL_BREAKPOINTS (b) | |
1012 | if (b->number == bnum) | |
2f069f6f | 1013 | { |
6dddc817 DE |
1014 | /* Check if this breakpoint has a "stop" method implemented in an |
1015 | extension language. This method and conditions entered into GDB | |
1016 | from the CLI are mutually exclusive. */ | |
1017 | const struct extension_language_defn *extlang | |
1018 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1019 | ||
1020 | if (extlang != NULL) | |
1021 | { | |
1022 | error (_("Only one stop condition allowed. There is currently" | |
1023 | " a %s stop condition defined for this breakpoint."), | |
1024 | ext_lang_capitalized_name (extlang)); | |
1025 | } | |
2566ad2d | 1026 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1027 | |
1028 | if (is_breakpoint (b)) | |
44702360 | 1029 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1030 | |
2f069f6f JB |
1031 | return; |
1032 | } | |
c906108c | 1033 | |
8a3fe4f8 | 1034 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1035 | } |
1036 | ||
a7bdde9e VP |
1037 | /* Check that COMMAND do not contain commands that are suitable |
1038 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1039 | Throw if any such commands is found. */ |
1040 | ||
a7bdde9e VP |
1041 | static void |
1042 | check_no_tracepoint_commands (struct command_line *commands) | |
1043 | { | |
1044 | struct command_line *c; | |
cc59ec59 | 1045 | |
a7bdde9e VP |
1046 | for (c = commands; c; c = c->next) |
1047 | { | |
1048 | int i; | |
1049 | ||
1050 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1051 | error (_("The 'while-stepping' command can " |
1052 | "only be used for tracepoints")); | |
a7bdde9e VP |
1053 | |
1054 | for (i = 0; i < c->body_count; ++i) | |
1055 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1056 | ||
1057 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1058 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1059 | command directly. */ |
1060 | if (strstr (c->line, "collect ") == c->line) | |
1061 | error (_("The 'collect' command can only be used for tracepoints")); | |
1062 | ||
51661e93 VP |
1063 | if (strstr (c->line, "teval ") == c->line) |
1064 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1065 | } |
1066 | } | |
1067 | ||
c1fc2657 | 1068 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1069 | { |
c1fc2657 | 1070 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1071 | }; |
1072 | ||
d77f58be SS |
1073 | /* Encapsulate tests for different types of tracepoints. */ |
1074 | ||
3b0871f4 SM |
1075 | static bool |
1076 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1077 | { |
1078 | return (type == bp_tracepoint | |
1079 | || type == bp_fast_tracepoint | |
1080 | || type == bp_static_tracepoint); | |
1081 | } | |
1082 | ||
3b0871f4 SM |
1083 | static bool |
1084 | is_longjmp_type (bptype type) | |
1085 | { | |
1086 | return type == bp_longjmp || type == bp_exception; | |
1087 | } | |
1088 | ||
a7bdde9e | 1089 | int |
d77f58be | 1090 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1091 | { |
d9b3f62e | 1092 | return is_tracepoint_type (b->type); |
a7bdde9e | 1093 | } |
d9b3f62e | 1094 | |
a5e364af SM |
1095 | /* Factory function to create an appropriate instance of breakpoint given |
1096 | TYPE. */ | |
1097 | ||
1098 | static std::unique_ptr<breakpoint> | |
1099 | new_breakpoint_from_type (bptype type) | |
1100 | { | |
1101 | breakpoint *b; | |
1102 | ||
1103 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1104 | b = new tracepoint (); |
3b0871f4 | 1105 | else if (is_longjmp_type (type)) |
c1fc2657 | 1106 | b = new longjmp_breakpoint (); |
a5e364af SM |
1107 | else |
1108 | b = new breakpoint (); | |
1109 | ||
1110 | return std::unique_ptr<breakpoint> (b); | |
1111 | } | |
1112 | ||
e5dd4106 | 1113 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1114 | breakpoint. This function will throw an exception if a problem is |
1115 | found. */ | |
48cb2d85 | 1116 | |
95a42b64 TT |
1117 | static void |
1118 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1119 | struct command_line *commands) | |
48cb2d85 | 1120 | { |
d77f58be | 1121 | if (is_tracepoint (b)) |
a7bdde9e | 1122 | { |
c9a6ce02 | 1123 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1124 | struct command_line *c; |
1125 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1126 | |
1127 | /* Reset the while-stepping step count. The previous commands | |
1128 | might have included a while-stepping action, while the new | |
1129 | ones might not. */ | |
1130 | t->step_count = 0; | |
1131 | ||
1132 | /* We need to verify that each top-level element of commands is | |
1133 | valid for tracepoints, that there's at most one | |
1134 | while-stepping element, and that the while-stepping's body | |
1135 | has valid tracing commands excluding nested while-stepping. | |
1136 | We also need to validate the tracepoint action line in the | |
1137 | context of the tracepoint --- validate_actionline actually | |
1138 | has side effects, like setting the tracepoint's | |
1139 | while-stepping STEP_COUNT, in addition to checking if the | |
1140 | collect/teval actions parse and make sense in the | |
1141 | tracepoint's context. */ | |
a7bdde9e VP |
1142 | for (c = commands; c; c = c->next) |
1143 | { | |
a7bdde9e VP |
1144 | if (c->control_type == while_stepping_control) |
1145 | { | |
1146 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1147 | error (_("The 'while-stepping' command " |
1148 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1149 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1150 | error (_("The 'while-stepping' command " |
1151 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1152 | |
1153 | if (while_stepping) | |
3e43a32a MS |
1154 | error (_("The 'while-stepping' command " |
1155 | "can be used only once")); | |
a7bdde9e VP |
1156 | else |
1157 | while_stepping = c; | |
1158 | } | |
c9a6ce02 PA |
1159 | |
1160 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1161 | } |
1162 | if (while_stepping) | |
1163 | { | |
1164 | struct command_line *c2; | |
1165 | ||
1166 | gdb_assert (while_stepping->body_count == 1); | |
1167 | c2 = while_stepping->body_list[0]; | |
1168 | for (; c2; c2 = c2->next) | |
1169 | { | |
a7bdde9e VP |
1170 | if (c2->control_type == while_stepping_control) |
1171 | error (_("The 'while-stepping' command cannot be nested")); | |
1172 | } | |
1173 | } | |
1174 | } | |
1175 | else | |
1176 | { | |
1177 | check_no_tracepoint_commands (commands); | |
1178 | } | |
95a42b64 TT |
1179 | } |
1180 | ||
0fb4aa4b PA |
1181 | /* Return a vector of all the static tracepoints set at ADDR. The |
1182 | caller is responsible for releasing the vector. */ | |
1183 | ||
1184 | VEC(breakpoint_p) * | |
1185 | static_tracepoints_here (CORE_ADDR addr) | |
1186 | { | |
1187 | struct breakpoint *b; | |
1188 | VEC(breakpoint_p) *found = 0; | |
1189 | struct bp_location *loc; | |
1190 | ||
1191 | ALL_BREAKPOINTS (b) | |
1192 | if (b->type == bp_static_tracepoint) | |
1193 | { | |
1194 | for (loc = b->loc; loc; loc = loc->next) | |
1195 | if (loc->address == addr) | |
1196 | VEC_safe_push(breakpoint_p, found, b); | |
1197 | } | |
1198 | ||
1199 | return found; | |
1200 | } | |
1201 | ||
95a42b64 | 1202 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1203 | validate that only allowed commands are included. */ |
95a42b64 TT |
1204 | |
1205 | void | |
4a64f543 | 1206 | breakpoint_set_commands (struct breakpoint *b, |
93921405 | 1207 | command_line_up &&commands) |
95a42b64 | 1208 | { |
93921405 | 1209 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1210 | |
d1b0a7bf | 1211 | b->commands = std::move (commands); |
8d3788bd | 1212 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1213 | } |
1214 | ||
45a43567 TT |
1215 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1216 | is not the same as the "silent" that may appear in the breakpoint's | |
1217 | commands. */ | |
1218 | ||
1219 | void | |
1220 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1221 | { | |
1222 | int old_silent = b->silent; | |
1223 | ||
1224 | b->silent = silent; | |
1225 | if (old_silent != silent) | |
8d3788bd | 1226 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1227 | } |
1228 | ||
1229 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1230 | breakpoint work for any thread. */ | |
1231 | ||
1232 | void | |
1233 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1234 | { | |
1235 | int old_thread = b->thread; | |
1236 | ||
1237 | b->thread = thread; | |
1238 | if (old_thread != thread) | |
8d3788bd | 1239 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1240 | } |
1241 | ||
1242 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1243 | breakpoint work for any task. */ | |
1244 | ||
1245 | void | |
1246 | breakpoint_set_task (struct breakpoint *b, int task) | |
1247 | { | |
1248 | int old_task = b->task; | |
1249 | ||
1250 | b->task = task; | |
1251 | if (old_task != task) | |
8d3788bd | 1252 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1253 | } |
1254 | ||
95a42b64 TT |
1255 | void |
1256 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1257 | { |
9a3c8263 | 1258 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1259 | |
6f937416 | 1260 | validate_actionline (line, b); |
a7bdde9e VP |
1261 | } |
1262 | ||
95a42b64 | 1263 | static void |
896b6bda | 1264 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1265 | struct command_line *control) |
95a42b64 | 1266 | { |
d1b0a7bf | 1267 | counted_command_line cmd; |
95a42b64 | 1268 | |
896b6bda PA |
1269 | std::string new_arg; |
1270 | ||
95a42b64 TT |
1271 | if (arg == NULL || !*arg) |
1272 | { | |
86b17b60 | 1273 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1274 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1275 | breakpoint_count); | |
95a42b64 | 1276 | else if (breakpoint_count > 0) |
896b6bda | 1277 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b TT |
1278 | arg = new_arg.c_str (); |
1279 | } | |
1280 | ||
1281 | map_breakpoint_numbers | |
1282 | (arg, [&] (breakpoint *b) | |
1283 | { | |
1284 | if (cmd == NULL) | |
1285 | { | |
48649e1b | 1286 | if (control != NULL) |
d1b0a7bf | 1287 | cmd = copy_command_lines (control->body_list[0]); |
48649e1b TT |
1288 | else |
1289 | { | |
1290 | struct cleanup *old_chain; | |
1291 | char *str; | |
1292 | ||
1293 | str = xstrprintf (_("Type commands for breakpoint(s) " | |
1294 | "%s, one per line."), | |
1295 | arg); | |
1296 | ||
1297 | old_chain = make_cleanup (xfree, str); | |
1298 | ||
d1b0a7bf TT |
1299 | cmd = read_command_lines (str, |
1300 | from_tty, 1, | |
1301 | (is_tracepoint (b) | |
1302 | ? check_tracepoint_command : 0), | |
1303 | b); | |
48649e1b TT |
1304 | |
1305 | do_cleanups (old_chain); | |
1306 | } | |
48649e1b TT |
1307 | } |
1308 | ||
1309 | /* If a breakpoint was on the list more than once, we don't need to | |
1310 | do anything. */ | |
1311 | if (b->commands != cmd) | |
1312 | { | |
d1b0a7bf | 1313 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b TT |
1314 | b->commands = cmd; |
1315 | observer_notify_breakpoint_modified (b); | |
1316 | } | |
1317 | }); | |
95a42b64 | 1318 | |
48649e1b | 1319 | if (cmd == NULL) |
95a42b64 | 1320 | error (_("No breakpoints specified.")); |
95a42b64 TT |
1321 | } |
1322 | ||
1323 | static void | |
1324 | commands_command (char *arg, int from_tty) | |
1325 | { | |
1326 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1327 | } |
40c03ae8 EZ |
1328 | |
1329 | /* Like commands_command, but instead of reading the commands from | |
1330 | input stream, takes them from an already parsed command structure. | |
1331 | ||
1332 | This is used by cli-script.c to DTRT with breakpoint commands | |
1333 | that are part of if and while bodies. */ | |
1334 | enum command_control_type | |
896b6bda | 1335 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1336 | { |
95a42b64 TT |
1337 | commands_command_1 (arg, 0, cmd); |
1338 | return simple_control; | |
40c03ae8 | 1339 | } |
876fa593 JK |
1340 | |
1341 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1342 | ||
1343 | static int | |
1344 | bp_location_has_shadow (struct bp_location *bl) | |
1345 | { | |
1346 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1347 | return 0; | |
1348 | if (!bl->inserted) | |
1349 | return 0; | |
1350 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1351 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1352 | return 0; |
1353 | return 1; | |
1354 | } | |
1355 | ||
9d497a19 PA |
1356 | /* Update BUF, which is LEN bytes read from the target address |
1357 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1358 | contents. | |
1359 | ||
1360 | If READBUF is not NULL, this buffer must not overlap with the of | |
1361 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1362 | failed assertion internal error will be raised. */ | |
1363 | ||
1364 | static void | |
1365 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1366 | const gdb_byte *writebuf_org, | |
1367 | ULONGEST memaddr, LONGEST len, | |
1368 | struct bp_target_info *target_info, | |
1369 | struct gdbarch *gdbarch) | |
1370 | { | |
1371 | /* Now do full processing of the found relevant range of elements. */ | |
1372 | CORE_ADDR bp_addr = 0; | |
1373 | int bp_size = 0; | |
1374 | int bptoffset = 0; | |
1375 | ||
1376 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1377 | current_program_space->aspace, 0)) | |
1378 | { | |
1379 | /* The breakpoint is inserted in a different address space. */ | |
1380 | return; | |
1381 | } | |
1382 | ||
1383 | /* Addresses and length of the part of the breakpoint that | |
1384 | we need to copy. */ | |
1385 | bp_addr = target_info->placed_address; | |
1386 | bp_size = target_info->shadow_len; | |
1387 | ||
1388 | if (bp_addr + bp_size <= memaddr) | |
1389 | { | |
1390 | /* The breakpoint is entirely before the chunk of memory we are | |
1391 | reading. */ | |
1392 | return; | |
1393 | } | |
1394 | ||
1395 | if (bp_addr >= memaddr + len) | |
1396 | { | |
1397 | /* The breakpoint is entirely after the chunk of memory we are | |
1398 | reading. */ | |
1399 | return; | |
1400 | } | |
1401 | ||
1402 | /* Offset within shadow_contents. */ | |
1403 | if (bp_addr < memaddr) | |
1404 | { | |
1405 | /* Only copy the second part of the breakpoint. */ | |
1406 | bp_size -= memaddr - bp_addr; | |
1407 | bptoffset = memaddr - bp_addr; | |
1408 | bp_addr = memaddr; | |
1409 | } | |
1410 | ||
1411 | if (bp_addr + bp_size > memaddr + len) | |
1412 | { | |
1413 | /* Only copy the first part of the breakpoint. */ | |
1414 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1415 | } | |
1416 | ||
1417 | if (readbuf != NULL) | |
1418 | { | |
1419 | /* Verify that the readbuf buffer does not overlap with the | |
1420 | shadow_contents buffer. */ | |
1421 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1422 | || readbuf >= (target_info->shadow_contents | |
1423 | + target_info->shadow_len)); | |
1424 | ||
1425 | /* Update the read buffer with this inserted breakpoint's | |
1426 | shadow. */ | |
1427 | memcpy (readbuf + bp_addr - memaddr, | |
1428 | target_info->shadow_contents + bptoffset, bp_size); | |
1429 | } | |
1430 | else | |
1431 | { | |
1432 | const unsigned char *bp; | |
0d5ed153 MR |
1433 | CORE_ADDR addr = target_info->reqstd_address; |
1434 | int placed_size; | |
9d497a19 PA |
1435 | |
1436 | /* Update the shadow with what we want to write to memory. */ | |
1437 | memcpy (target_info->shadow_contents + bptoffset, | |
1438 | writebuf_org + bp_addr - memaddr, bp_size); | |
1439 | ||
1440 | /* Determine appropriate breakpoint contents and size for this | |
1441 | address. */ | |
0d5ed153 | 1442 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1443 | |
1444 | /* Update the final write buffer with this inserted | |
1445 | breakpoint's INSN. */ | |
1446 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1447 | } | |
1448 | } | |
1449 | ||
8defab1a | 1450 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1451 | by replacing any memory breakpoints with their shadowed contents. |
1452 | ||
35c63cd8 JB |
1453 | If READBUF is not NULL, this buffer must not overlap with any of |
1454 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1455 | a failed assertion internal error will be raised. | |
1456 | ||
876fa593 | 1457 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1458 | bl->address - bp_locations_placed_address_before_address_max |
1459 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1460 | The range we were requested to resolve shadows for is: |
1461 | memaddr ... memaddr + len | |
1462 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1463 | memaddr + len <= (bl->address |
f5336ca5 | 1464 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1465 | and: |
f5336ca5 | 1466 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1467 | |
8defab1a | 1468 | void |
f0ba3972 PA |
1469 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1470 | const gdb_byte *writebuf_org, | |
1471 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1472 | { |
4a64f543 MS |
1473 | /* Left boundary, right boundary and median element of our binary |
1474 | search. */ | |
876fa593 JK |
1475 | unsigned bc_l, bc_r, bc; |
1476 | ||
4a64f543 MS |
1477 | /* Find BC_L which is a leftmost element which may affect BUF |
1478 | content. It is safe to report lower value but a failure to | |
1479 | report higher one. */ | |
876fa593 JK |
1480 | |
1481 | bc_l = 0; | |
f5336ca5 | 1482 | bc_r = bp_locations_count; |
876fa593 JK |
1483 | while (bc_l + 1 < bc_r) |
1484 | { | |
35df4500 | 1485 | struct bp_location *bl; |
876fa593 JK |
1486 | |
1487 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1488 | bl = bp_locations[bc]; |
876fa593 | 1489 | |
4a64f543 MS |
1490 | /* Check first BL->ADDRESS will not overflow due to the added |
1491 | constant. Then advance the left boundary only if we are sure | |
1492 | the BC element can in no way affect the BUF content (MEMADDR | |
1493 | to MEMADDR + LEN range). | |
876fa593 | 1494 | |
f5336ca5 | 1495 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1496 | offset so that we cannot miss a breakpoint with its shadow |
1497 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1498 | |
f5336ca5 | 1499 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1500 | >= bl->address) |
f5336ca5 | 1501 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1502 | <= memaddr)) |
876fa593 JK |
1503 | bc_l = bc; |
1504 | else | |
1505 | bc_r = bc; | |
1506 | } | |
1507 | ||
128070bb PA |
1508 | /* Due to the binary search above, we need to make sure we pick the |
1509 | first location that's at BC_L's address. E.g., if there are | |
1510 | multiple locations at the same address, BC_L may end up pointing | |
1511 | at a duplicate location, and miss the "master"/"inserted" | |
1512 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1513 | B: | |
1514 | ||
1515 | L1@A, L2@A, L3@B, ... | |
1516 | ||
1517 | BC_L could end up pointing at location L2, while the "master" | |
1518 | location could be L1. Since the `loc->inserted' flag is only set | |
1519 | on "master" locations, we'd forget to restore the shadow of L1 | |
1520 | and L2. */ | |
1521 | while (bc_l > 0 | |
f5336ca5 | 1522 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1523 | bc_l--; |
1524 | ||
876fa593 JK |
1525 | /* Now do full processing of the found relevant range of elements. */ |
1526 | ||
f5336ca5 | 1527 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1528 | { |
f5336ca5 | 1529 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1530 | |
35df4500 TJB |
1531 | /* bp_location array has BL->OWNER always non-NULL. */ |
1532 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1533 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1534 | bl->owner->number); |
ffce0d52 | 1535 | |
e5dd4106 | 1536 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1537 | content. */ |
1538 | ||
f5336ca5 PA |
1539 | if (bl->address >= bp_locations_placed_address_before_address_max |
1540 | && memaddr + len <= (bl->address | |
1541 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1542 | break; |
1543 | ||
35df4500 | 1544 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1545 | continue; |
6c95b8df | 1546 | |
9d497a19 PA |
1547 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1548 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1549 | } | |
c906108c | 1550 | } |
9d497a19 | 1551 | |
c906108c | 1552 | \f |
c5aa993b | 1553 | |
b775012e LM |
1554 | /* Return true if BPT is either a software breakpoint or a hardware |
1555 | breakpoint. */ | |
1556 | ||
1557 | int | |
1558 | is_breakpoint (const struct breakpoint *bpt) | |
1559 | { | |
1560 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1561 | || bpt->type == bp_hardware_breakpoint |
1562 | || bpt->type == bp_dprintf); | |
b775012e LM |
1563 | } |
1564 | ||
60e1c644 PA |
1565 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1566 | ||
a5606eee | 1567 | static int |
d77f58be | 1568 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1569 | { |
1570 | return (bpt->type == bp_hardware_watchpoint | |
1571 | || bpt->type == bp_read_watchpoint | |
1572 | || bpt->type == bp_access_watchpoint); | |
1573 | } | |
7270d8f2 | 1574 | |
60e1c644 PA |
1575 | /* Return true if BPT is of any watchpoint kind, hardware or |
1576 | software. */ | |
1577 | ||
3a5c3e22 | 1578 | int |
d77f58be | 1579 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1580 | { |
1581 | return (is_hardware_watchpoint (bpt) | |
1582 | || bpt->type == bp_watchpoint); | |
1583 | } | |
1584 | ||
3a5c3e22 PA |
1585 | /* Returns true if the current thread and its running state are safe |
1586 | to evaluate or update watchpoint B. Watchpoints on local | |
1587 | expressions need to be evaluated in the context of the thread that | |
1588 | was current when the watchpoint was created, and, that thread needs | |
1589 | to be stopped to be able to select the correct frame context. | |
1590 | Watchpoints on global expressions can be evaluated on any thread, | |
1591 | and in any state. It is presently left to the target allowing | |
1592 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1593 | |
1594 | static int | |
3a5c3e22 | 1595 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1596 | { |
c1fc2657 | 1597 | return (b->pspace == current_program_space |
d0d8b0c6 JK |
1598 | && (ptid_equal (b->watchpoint_thread, null_ptid) |
1599 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1600 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1601 | } |
1602 | ||
d0fb5eae JK |
1603 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1604 | associated bp_watchpoint_scope breakpoint. */ | |
1605 | ||
1606 | static void | |
3a5c3e22 | 1607 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1608 | { |
c1fc2657 | 1609 | if (w->related_breakpoint != w) |
d0fb5eae | 1610 | { |
c1fc2657 SM |
1611 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1612 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1613 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1614 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1615 | w->related_breakpoint = w; | |
d0fb5eae | 1616 | } |
c1fc2657 | 1617 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1618 | } |
1619 | ||
bb9d5f81 PP |
1620 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1621 | watchpoint W. */ | |
1622 | ||
1623 | static struct value * | |
1624 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1625 | { | |
1626 | struct value *bit_val; | |
1627 | ||
1628 | if (val == NULL) | |
1629 | return NULL; | |
1630 | ||
1631 | bit_val = allocate_value (value_type (val)); | |
1632 | ||
1633 | unpack_value_bitfield (bit_val, | |
1634 | w->val_bitpos, | |
1635 | w->val_bitsize, | |
1636 | value_contents_for_printing (val), | |
1637 | value_offset (val), | |
1638 | val); | |
1639 | ||
1640 | return bit_val; | |
1641 | } | |
1642 | ||
c6d81124 PA |
1643 | /* Allocate a dummy location and add it to B, which must be a software |
1644 | watchpoint. This is required because even if a software watchpoint | |
1645 | is not watching any memory, bpstat_stop_status requires a location | |
1646 | to be able to report stops. */ | |
1647 | ||
1648 | static void | |
1649 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1650 | struct program_space *pspace) | |
1651 | { | |
1652 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1653 | ||
1654 | b->loc = allocate_bp_location (b); | |
1655 | b->loc->pspace = pspace; | |
1656 | b->loc->address = -1; | |
1657 | b->loc->length = -1; | |
1658 | } | |
1659 | ||
1660 | /* Returns true if B is a software watchpoint that is not watching any | |
1661 | memory (e.g., "watch $pc"). */ | |
1662 | ||
1663 | static int | |
1664 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1665 | { | |
1666 | return (b->type == bp_watchpoint | |
1667 | && b->loc != NULL | |
1668 | && b->loc->next == NULL | |
1669 | && b->loc->address == -1 | |
1670 | && b->loc->length == -1); | |
1671 | } | |
1672 | ||
567e1b4e JB |
1673 | /* Assuming that B is a watchpoint: |
1674 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1675 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1676 | - Evaluate the condition if there is one, and store the result |
1677 | in b->loc->cond. | |
a5606eee VP |
1678 | - Update the list of values that must be watched in B->loc. |
1679 | ||
4a64f543 MS |
1680 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1681 | nothing. If this is local watchpoint that is out of scope, delete | |
1682 | it. | |
1683 | ||
1684 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1685 | removed + inserted on each stop here. Normal breakpoints must | |
1686 | never be removed because they might be missed by a running thread | |
1687 | when debugging in non-stop mode. On the other hand, hardware | |
1688 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1689 | to each LWP since they are stored in each LWP's hardware debug | |
1690 | registers. Therefore, such LWP must be stopped first in order to | |
1691 | be able to modify its hardware watchpoints. | |
1692 | ||
1693 | Hardware watchpoints must be reset exactly once after being | |
1694 | presented to the user. It cannot be done sooner, because it would | |
1695 | reset the data used to present the watchpoint hit to the user. And | |
1696 | it must not be done later because it could display the same single | |
1697 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1698 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1699 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1700 | not user-visible - its hit is suppressed if the memory content has | |
1701 | not changed. | |
1702 | ||
1703 | The following constraints influence the location where we can reset | |
1704 | hardware watchpoints: | |
1705 | ||
1706 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1707 | called several times when GDB stops. | |
1708 | ||
1709 | [linux] | |
1710 | * Multiple hardware watchpoints can be hit at the same time, | |
1711 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1712 | hit at a time as the reason for stopping, and all the other hits | |
1713 | are presented later, one after the other, each time the user | |
1714 | requests the execution to be resumed. Execution is not resumed | |
1715 | for the threads still having pending hit event stored in | |
1716 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1717 | the inferior on the first stop the thread hit event is kept being | |
1718 | reported from its cached value by linux_nat_stopped_data_address | |
1719 | until the real thread resume happens after the watchpoint gets | |
1720 | presented and thus its LWP_INFO->STATUS gets reset. | |
1721 | ||
1722 | Therefore the hardware watchpoint hit can get safely reset on the | |
1723 | watchpoint removal from inferior. */ | |
a79d3c27 | 1724 | |
b40ce68a | 1725 | static void |
3a5c3e22 | 1726 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1727 | { |
a5606eee | 1728 | int within_current_scope; |
a5606eee | 1729 | struct frame_id saved_frame_id; |
66076460 | 1730 | int frame_saved; |
a5606eee | 1731 | |
f6bc2008 PA |
1732 | /* If this is a local watchpoint, we only want to check if the |
1733 | watchpoint frame is in scope if the current thread is the thread | |
1734 | that was used to create the watchpoint. */ | |
1735 | if (!watchpoint_in_thread_scope (b)) | |
1736 | return; | |
1737 | ||
c1fc2657 | 1738 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1739 | return; |
1740 | ||
66076460 | 1741 | frame_saved = 0; |
a5606eee VP |
1742 | |
1743 | /* Determine if the watchpoint is within scope. */ | |
1744 | if (b->exp_valid_block == NULL) | |
1745 | within_current_scope = 1; | |
1746 | else | |
1747 | { | |
b5db5dfc UW |
1748 | struct frame_info *fi = get_current_frame (); |
1749 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1750 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1751 | ||
c9cf6e20 MG |
1752 | /* If we're at a point where the stack has been destroyed |
1753 | (e.g. in a function epilogue), unwinding may not work | |
1754 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1755 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1756 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1757 | return; |
66076460 DJ |
1758 | |
1759 | /* Save the current frame's ID so we can restore it after | |
1760 | evaluating the watchpoint expression on its own frame. */ | |
1761 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1762 | took a frame parameter, so that we didn't have to change the | |
1763 | selected frame. */ | |
1764 | frame_saved = 1; | |
1765 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1766 | ||
a5606eee VP |
1767 | fi = frame_find_by_id (b->watchpoint_frame); |
1768 | within_current_scope = (fi != NULL); | |
1769 | if (within_current_scope) | |
1770 | select_frame (fi); | |
1771 | } | |
1772 | ||
b5db5dfc UW |
1773 | /* We don't free locations. They are stored in the bp_location array |
1774 | and update_global_location_list will eventually delete them and | |
1775 | remove breakpoints if needed. */ | |
c1fc2657 | 1776 | b->loc = NULL; |
b5db5dfc | 1777 | |
a5606eee VP |
1778 | if (within_current_scope && reparse) |
1779 | { | |
bbc13ae3 | 1780 | const char *s; |
d63d0675 | 1781 | |
4d01a485 | 1782 | b->exp.reset (); |
d63d0675 | 1783 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1784 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1785 | /* If the meaning of expression itself changed, the old value is |
1786 | no longer relevant. We don't want to report a watchpoint hit | |
1787 | to the user when the old value and the new value may actually | |
1788 | be completely different objects. */ | |
1789 | value_free (b->val); | |
fa4727a6 DJ |
1790 | b->val = NULL; |
1791 | b->val_valid = 0; | |
60e1c644 PA |
1792 | |
1793 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1794 | expression is stored in the breakpoint object, not in the | |
1795 | locations (re)created below. */ | |
c1fc2657 | 1796 | if (b->cond_string != NULL) |
60e1c644 | 1797 | { |
4d01a485 | 1798 | b->cond_exp.reset (); |
60e1c644 | 1799 | |
c1fc2657 | 1800 | s = b->cond_string; |
1bb9788d | 1801 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1802 | } |
a5606eee | 1803 | } |
a5606eee VP |
1804 | |
1805 | /* If we failed to parse the expression, for example because | |
1806 | it refers to a global variable in a not-yet-loaded shared library, | |
1807 | don't try to insert watchpoint. We don't automatically delete | |
1808 | such watchpoint, though, since failure to parse expression | |
1809 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1810 | if (!target_has_execution) |
2d134ed3 PA |
1811 | { |
1812 | /* Without execution, memory can't change. No use to try and | |
1813 | set watchpoint locations. The watchpoint will be reset when | |
1814 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1815 | if (!can_use_hw_watchpoints) |
1816 | { | |
c1fc2657 SM |
1817 | if (b->ops->works_in_software_mode (b)) |
1818 | b->type = bp_watchpoint; | |
e8369a73 | 1819 | else |
638aa5a1 AB |
1820 | error (_("Can't set read/access watchpoint when " |
1821 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1822 | } |
2d134ed3 PA |
1823 | } |
1824 | else if (within_current_scope && b->exp) | |
a5606eee | 1825 | { |
0cf6dd15 | 1826 | int pc = 0; |
fa4727a6 | 1827 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1828 | struct program_space *frame_pspace; |
a5606eee | 1829 | |
4d01a485 | 1830 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1831 | |
a5606eee VP |
1832 | /* Avoid setting b->val if it's already set. The meaning of |
1833 | b->val is 'the last value' user saw, and we should update | |
1834 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1835 | happens, the code that reports it updates b->val directly. |
1836 | We don't keep track of the memory value for masked | |
1837 | watchpoints. */ | |
c1fc2657 | 1838 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1839 | { |
bb9d5f81 PP |
1840 | if (b->val_bitsize != 0) |
1841 | { | |
1842 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1843 | if (v != NULL) | |
1844 | release_value (v); | |
1845 | } | |
fa4727a6 DJ |
1846 | b->val = v; |
1847 | b->val_valid = 1; | |
1848 | } | |
a5606eee | 1849 | |
2d134ed3 PA |
1850 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1851 | ||
a5606eee | 1852 | /* Look at each value on the value chain. */ |
9fa40276 | 1853 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1854 | { |
1855 | /* If it's a memory location, and GDB actually needed | |
1856 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1857 | must watch it. If the first value returned is |
1858 | still lazy, that means an error occurred reading it; | |
1859 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1860 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1861 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1862 | { |
1863 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1864 | |
a5606eee VP |
1865 | /* We only watch structs and arrays if user asked |
1866 | for it explicitly, never if they just happen to | |
1867 | appear in the middle of some value chain. */ | |
fa4727a6 | 1868 | if (v == result |
a5606eee VP |
1869 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1870 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1871 | { | |
1872 | CORE_ADDR addr; | |
f486487f | 1873 | enum target_hw_bp_type type; |
a5606eee | 1874 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1875 | int bitpos = 0, bitsize = 0; |
1876 | ||
1877 | if (value_bitsize (v) != 0) | |
1878 | { | |
1879 | /* Extract the bit parameters out from the bitfield | |
1880 | sub-expression. */ | |
1881 | bitpos = value_bitpos (v); | |
1882 | bitsize = value_bitsize (v); | |
1883 | } | |
1884 | else if (v == result && b->val_bitsize != 0) | |
1885 | { | |
1886 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1887 | lvalue whose bit parameters are saved in the fields | |
1888 | VAL_BITPOS and VAL_BITSIZE. */ | |
1889 | bitpos = b->val_bitpos; | |
1890 | bitsize = b->val_bitsize; | |
1891 | } | |
a5606eee | 1892 | |
42ae5230 | 1893 | addr = value_address (v); |
bb9d5f81 PP |
1894 | if (bitsize != 0) |
1895 | { | |
1896 | /* Skip the bytes that don't contain the bitfield. */ | |
1897 | addr += bitpos / 8; | |
1898 | } | |
1899 | ||
a5606eee | 1900 | type = hw_write; |
c1fc2657 | 1901 | if (b->type == bp_read_watchpoint) |
a5606eee | 1902 | type = hw_read; |
c1fc2657 | 1903 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1904 | type = hw_access; |
3a5c3e22 | 1905 | |
c1fc2657 SM |
1906 | loc = allocate_bp_location (b); |
1907 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1908 | ; |
1909 | *tmp = loc; | |
a6d9a66e | 1910 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1911 | |
1912 | loc->pspace = frame_pspace; | |
a5606eee | 1913 | loc->address = addr; |
bb9d5f81 PP |
1914 | |
1915 | if (bitsize != 0) | |
1916 | { | |
1917 | /* Just cover the bytes that make up the bitfield. */ | |
1918 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1919 | } | |
1920 | else | |
1921 | loc->length = TYPE_LENGTH (value_type (v)); | |
1922 | ||
a5606eee VP |
1923 | loc->watchpoint_type = type; |
1924 | } | |
1925 | } | |
9fa40276 TJB |
1926 | } |
1927 | ||
1928 | /* Change the type of breakpoint between hardware assisted or | |
1929 | an ordinary watchpoint depending on the hardware support | |
1930 | and free hardware slots. REPARSE is set when the inferior | |
1931 | is started. */ | |
a9634178 | 1932 | if (reparse) |
9fa40276 | 1933 | { |
e09342b5 | 1934 | int reg_cnt; |
9fa40276 TJB |
1935 | enum bp_loc_type loc_type; |
1936 | struct bp_location *bl; | |
a5606eee | 1937 | |
a9634178 | 1938 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1939 | |
1940 | if (reg_cnt) | |
9fa40276 TJB |
1941 | { |
1942 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1943 | enum bptype type; |
9fa40276 | 1944 | |
a9634178 TJB |
1945 | /* Use an exact watchpoint when there's only one memory region to be |
1946 | watched, and only one debug register is needed to watch it. */ | |
1947 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1948 | ||
9fa40276 | 1949 | /* We need to determine how many resources are already |
e09342b5 TJB |
1950 | used for all other hardware watchpoints plus this one |
1951 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1952 | this watchpoint in as well. */ |
1953 | ||
1954 | /* If this is a software watchpoint, we try to turn it | |
1955 | to a hardware one -- count resources as if B was of | |
1956 | hardware watchpoint type. */ | |
c1fc2657 | 1957 | type = b->type; |
a1398e0c PA |
1958 | if (type == bp_watchpoint) |
1959 | type = bp_hardware_watchpoint; | |
1960 | ||
1961 | /* This watchpoint may or may not have been placed on | |
1962 | the list yet at this point (it won't be in the list | |
1963 | if we're trying to create it for the first time, | |
1964 | through watch_command), so always account for it | |
1965 | manually. */ | |
1966 | ||
1967 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 1968 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
1969 | |
1970 | /* Add in the resources needed for B. */ | |
c1fc2657 | 1971 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
1972 | |
1973 | target_resources_ok | |
1974 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1975 | if (target_resources_ok <= 0) |
a9634178 | 1976 | { |
c1fc2657 | 1977 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
1978 | |
1979 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1980 | error (_("Target does not support this type of " |
1981 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1982 | else if (target_resources_ok < 0 && !sw_mode) |
1983 | error (_("There are not enough available hardware " | |
1984 | "resources for this watchpoint.")); | |
a1398e0c PA |
1985 | |
1986 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 1987 | b->type = bp_watchpoint; |
a1398e0c PA |
1988 | } |
1989 | else | |
1990 | { | |
1991 | /* If this was a software watchpoint, we've just | |
1992 | found we have enough resources to turn it to a | |
1993 | hardware watchpoint. Otherwise, this is a | |
1994 | nop. */ | |
c1fc2657 | 1995 | b->type = type; |
a9634178 | 1996 | } |
9fa40276 | 1997 | } |
c1fc2657 | 1998 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
1999 | { |
2000 | if (!can_use_hw_watchpoints) | |
2001 | error (_("Can't set read/access watchpoint when " | |
2002 | "hardware watchpoints are disabled.")); | |
2003 | else | |
2004 | error (_("Expression cannot be implemented with " | |
2005 | "read/access watchpoint.")); | |
2006 | } | |
9fa40276 | 2007 | else |
c1fc2657 | 2008 | b->type = bp_watchpoint; |
9fa40276 | 2009 | |
c1fc2657 | 2010 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 2011 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 2012 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
2013 | bl->loc_type = loc_type; |
2014 | } | |
2015 | ||
2016 | for (v = val_chain; v; v = next) | |
2017 | { | |
a5606eee VP |
2018 | next = value_next (v); |
2019 | if (v != b->val) | |
2020 | value_free (v); | |
2021 | } | |
2022 | ||
c7437ca6 PA |
2023 | /* If a software watchpoint is not watching any memory, then the |
2024 | above left it without any location set up. But, | |
2025 | bpstat_stop_status requires a location to be able to report | |
2026 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
2027 | if (b->type == bp_watchpoint && b->loc == NULL) |
2028 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
2029 | } |
2030 | else if (!within_current_scope) | |
7270d8f2 | 2031 | { |
ac74f770 MS |
2032 | printf_filtered (_("\ |
2033 | Watchpoint %d deleted because the program has left the block\n\ | |
2034 | in which its expression is valid.\n"), | |
c1fc2657 | 2035 | b->number); |
d0fb5eae | 2036 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2037 | } |
a5606eee VP |
2038 | |
2039 | /* Restore the selected frame. */ | |
66076460 DJ |
2040 | if (frame_saved) |
2041 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2042 | } |
2043 | ||
a5606eee | 2044 | |
74960c60 | 2045 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2046 | inserted in the inferior. We don't differentiate the type of BL's owner |
2047 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2048 | breakpoint_ops is not defined, because in insert_bp_location, | |
2049 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2050 | static int |
35df4500 | 2051 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2052 | { |
35df4500 | 2053 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2054 | return 0; |
2055 | ||
35df4500 | 2056 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2057 | return 0; |
2058 | ||
35df4500 | 2059 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2060 | return 0; |
2061 | ||
f8eba3c6 TT |
2062 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2063 | return 0; | |
2064 | ||
56710373 PA |
2065 | /* This is set for example, when we're attached to the parent of a |
2066 | vfork, and have detached from the child. The child is running | |
2067 | free, and we expect it to do an exec or exit, at which point the | |
2068 | OS makes the parent schedulable again (and the target reports | |
2069 | that the vfork is done). Until the child is done with the shared | |
2070 | memory region, do not insert breakpoints in the parent, otherwise | |
2071 | the child could still trip on the parent's breakpoints. Since | |
2072 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2073 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2074 | return 0; |
2075 | ||
31e77af2 | 2076 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2077 | location, except if the breakpoint is a single-step breakpoint, |
2078 | and the breakpoint's thread is the thread which is stepping past | |
2079 | a breakpoint. */ | |
31e77af2 PA |
2080 | if ((bl->loc_type == bp_loc_software_breakpoint |
2081 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2082 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2083 | bl->address) |
2084 | /* The single-step breakpoint may be inserted at the location | |
2085 | we're trying to step if the instruction branches to itself. | |
2086 | However, the instruction won't be executed at all and it may | |
2087 | break the semantics of the instruction, for example, the | |
2088 | instruction is a conditional branch or updates some flags. | |
2089 | We can't fix it unless GDB is able to emulate the instruction | |
2090 | or switch to displaced stepping. */ | |
2091 | && !(bl->owner->type == bp_single_step | |
2092 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2093 | { |
2094 | if (debug_infrun) | |
2095 | { | |
2096 | fprintf_unfiltered (gdb_stdlog, | |
2097 | "infrun: skipping breakpoint: " | |
2098 | "stepping past insn at: %s\n", | |
2099 | paddress (bl->gdbarch, bl->address)); | |
2100 | } | |
2101 | return 0; | |
2102 | } | |
31e77af2 | 2103 | |
963f9c80 PA |
2104 | /* Don't insert watchpoints if we're trying to step past the |
2105 | instruction that triggered one. */ | |
2106 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2107 | && stepping_past_nonsteppable_watchpoint ()) | |
2108 | { | |
2109 | if (debug_infrun) | |
2110 | { | |
2111 | fprintf_unfiltered (gdb_stdlog, | |
2112 | "infrun: stepping past non-steppable watchpoint. " | |
2113 | "skipping watchpoint at %s:%d\n", | |
2114 | paddress (bl->gdbarch, bl->address), | |
2115 | bl->length); | |
2116 | } | |
2117 | return 0; | |
2118 | } | |
2119 | ||
74960c60 VP |
2120 | return 1; |
2121 | } | |
2122 | ||
934709f0 PW |
2123 | /* Same as should_be_inserted but does the check assuming |
2124 | that the location is not duplicated. */ | |
2125 | ||
2126 | static int | |
2127 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2128 | { | |
2129 | int result; | |
2130 | const int save_duplicate = bl->duplicate; | |
2131 | ||
2132 | bl->duplicate = 0; | |
2133 | result = should_be_inserted (bl); | |
2134 | bl->duplicate = save_duplicate; | |
2135 | return result; | |
2136 | } | |
2137 | ||
b775012e LM |
2138 | /* Parses a conditional described by an expression COND into an |
2139 | agent expression bytecode suitable for evaluation | |
2140 | by the bytecode interpreter. Return NULL if there was | |
2141 | any error during parsing. */ | |
2142 | ||
833177a4 | 2143 | static agent_expr_up |
b775012e LM |
2144 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2145 | { | |
833177a4 | 2146 | if (cond == NULL) |
b775012e LM |
2147 | return NULL; |
2148 | ||
833177a4 PA |
2149 | agent_expr_up aexpr; |
2150 | ||
b775012e LM |
2151 | /* We don't want to stop processing, so catch any errors |
2152 | that may show up. */ | |
492d29ea | 2153 | TRY |
b775012e | 2154 | { |
036e657b | 2155 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2156 | } |
2157 | ||
492d29ea | 2158 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2159 | { |
2160 | /* If we got here, it means the condition could not be parsed to a valid | |
2161 | bytecode expression and thus can't be evaluated on the target's side. | |
2162 | It's no use iterating through the conditions. */ | |
b775012e | 2163 | } |
492d29ea | 2164 | END_CATCH |
b775012e LM |
2165 | |
2166 | /* We have a valid agent expression. */ | |
2167 | return aexpr; | |
2168 | } | |
2169 | ||
2170 | /* Based on location BL, create a list of breakpoint conditions to be | |
2171 | passed on to the target. If we have duplicated locations with different | |
2172 | conditions, we will add such conditions to the list. The idea is that the | |
2173 | target will evaluate the list of conditions and will only notify GDB when | |
2174 | one of them is true. */ | |
2175 | ||
2176 | static void | |
2177 | build_target_condition_list (struct bp_location *bl) | |
2178 | { | |
2179 | struct bp_location **locp = NULL, **loc2p; | |
2180 | int null_condition_or_parse_error = 0; | |
2181 | int modified = bl->needs_update; | |
2182 | struct bp_location *loc; | |
2183 | ||
8b4f3082 | 2184 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2185 | bl->target_info.conditions.clear (); |
8b4f3082 | 2186 | |
b775012e LM |
2187 | /* This is only meaningful if the target is |
2188 | evaluating conditions and if the user has | |
2189 | opted for condition evaluation on the target's | |
2190 | side. */ | |
2191 | if (gdb_evaluates_breakpoint_condition_p () | |
2192 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2193 | return; | |
2194 | ||
2195 | /* Do a first pass to check for locations with no assigned | |
2196 | conditions or conditions that fail to parse to a valid agent expression | |
2197 | bytecode. If any of these happen, then it's no use to send conditions | |
2198 | to the target since this location will always trigger and generate a | |
2199 | response back to GDB. */ | |
2200 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2201 | { | |
2202 | loc = (*loc2p); | |
2203 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2204 | { | |
2205 | if (modified) | |
2206 | { | |
b775012e LM |
2207 | /* Re-parse the conditions since something changed. In that |
2208 | case we already freed the condition bytecodes (see | |
2209 | force_breakpoint_reinsertion). We just | |
2210 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2211 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2212 | loc->cond.get ()); | |
b775012e LM |
2213 | } |
2214 | ||
2215 | /* If we have a NULL bytecode expression, it means something | |
2216 | went wrong or we have a null condition expression. */ | |
2217 | if (!loc->cond_bytecode) | |
2218 | { | |
2219 | null_condition_or_parse_error = 1; | |
2220 | break; | |
2221 | } | |
2222 | } | |
2223 | } | |
2224 | ||
2225 | /* If any of these happened, it means we will have to evaluate the conditions | |
2226 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2227 | for all the other duplicate locations, thus we free all of them here. | |
2228 | ||
2229 | This is so we have a finer control over which locations' conditions are | |
2230 | being evaluated by GDB or the remote stub. */ | |
2231 | if (null_condition_or_parse_error) | |
2232 | { | |
2233 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2234 | { | |
2235 | loc = (*loc2p); | |
2236 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2237 | { | |
2238 | /* Only go as far as the first NULL bytecode is | |
2239 | located. */ | |
2240 | if (!loc->cond_bytecode) | |
2241 | return; | |
2242 | ||
833177a4 | 2243 | loc->cond_bytecode.reset (); |
b775012e LM |
2244 | } |
2245 | } | |
2246 | } | |
2247 | ||
2248 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2249 | for this location's address. */ | |
2250 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2251 | { | |
2252 | loc = (*loc2p); | |
2253 | if (loc->cond | |
2254 | && is_breakpoint (loc->owner) | |
2255 | && loc->pspace->num == bl->pspace->num | |
2256 | && loc->owner->enable_state == bp_enabled | |
2257 | && loc->enabled) | |
3cde5c42 PA |
2258 | { |
2259 | /* Add the condition to the vector. This will be used later | |
2260 | to send the conditions to the target. */ | |
2261 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2262 | } | |
b775012e LM |
2263 | } |
2264 | ||
2265 | return; | |
2266 | } | |
2267 | ||
d3ce09f5 SS |
2268 | /* Parses a command described by string CMD into an agent expression |
2269 | bytecode suitable for evaluation by the bytecode interpreter. | |
2270 | Return NULL if there was any error during parsing. */ | |
2271 | ||
833177a4 | 2272 | static agent_expr_up |
d3ce09f5 SS |
2273 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2274 | { | |
2275 | struct cleanup *old_cleanups = 0; | |
4d01a485 | 2276 | struct expression **argvec; |
bbc13ae3 KS |
2277 | const char *cmdrest; |
2278 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2279 | struct format_piece *fpieces; |
2280 | int nargs; | |
2281 | struct gdbarch *gdbarch = get_current_arch (); | |
2282 | ||
833177a4 | 2283 | if (cmd == NULL) |
d3ce09f5 SS |
2284 | return NULL; |
2285 | ||
2286 | cmdrest = cmd; | |
2287 | ||
2288 | if (*cmdrest == ',') | |
2289 | ++cmdrest; | |
f1735a53 | 2290 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2291 | |
2292 | if (*cmdrest++ != '"') | |
2293 | error (_("No format string following the location")); | |
2294 | ||
2295 | format_start = cmdrest; | |
2296 | ||
2297 | fpieces = parse_format_string (&cmdrest); | |
2298 | ||
2299 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2300 | ||
2301 | format_end = cmdrest; | |
2302 | ||
2303 | if (*cmdrest++ != '"') | |
2304 | error (_("Bad format string, non-terminated '\"'.")); | |
2305 | ||
f1735a53 | 2306 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2307 | |
2308 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2309 | error (_("Invalid argument syntax")); | |
2310 | ||
2311 | if (*cmdrest == ',') | |
2312 | cmdrest++; | |
f1735a53 | 2313 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2314 | |
2315 | /* For each argument, make an expression. */ | |
2316 | ||
2317 | argvec = (struct expression **) alloca (strlen (cmd) | |
2318 | * sizeof (struct expression *)); | |
2319 | ||
2320 | nargs = 0; | |
2321 | while (*cmdrest != '\0') | |
2322 | { | |
bbc13ae3 | 2323 | const char *cmd1; |
d3ce09f5 SS |
2324 | |
2325 | cmd1 = cmdrest; | |
4d01a485 PA |
2326 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
2327 | argvec[nargs++] = expr.release (); | |
d3ce09f5 SS |
2328 | cmdrest = cmd1; |
2329 | if (*cmdrest == ',') | |
2330 | ++cmdrest; | |
2331 | } | |
2332 | ||
833177a4 PA |
2333 | agent_expr_up aexpr; |
2334 | ||
d3ce09f5 SS |
2335 | /* We don't want to stop processing, so catch any errors |
2336 | that may show up. */ | |
492d29ea | 2337 | TRY |
d3ce09f5 | 2338 | { |
036e657b JB |
2339 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2340 | format_start, format_end - format_start, | |
2341 | fpieces, nargs, argvec); | |
d3ce09f5 | 2342 | } |
492d29ea | 2343 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2344 | { |
2345 | /* If we got here, it means the command could not be parsed to a valid | |
2346 | bytecode expression and thus can't be evaluated on the target's side. | |
2347 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2348 | } |
492d29ea PA |
2349 | END_CATCH |
2350 | ||
2351 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2352 | |
d3ce09f5 SS |
2353 | /* We have a valid agent expression, return it. */ |
2354 | return aexpr; | |
2355 | } | |
2356 | ||
2357 | /* Based on location BL, create a list of breakpoint commands to be | |
2358 | passed on to the target. If we have duplicated locations with | |
2359 | different commands, we will add any such to the list. */ | |
2360 | ||
2361 | static void | |
2362 | build_target_command_list (struct bp_location *bl) | |
2363 | { | |
2364 | struct bp_location **locp = NULL, **loc2p; | |
2365 | int null_command_or_parse_error = 0; | |
2366 | int modified = bl->needs_update; | |
2367 | struct bp_location *loc; | |
2368 | ||
3cde5c42 PA |
2369 | /* Clear commands left over from a previous insert. */ |
2370 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2371 | |
41fac0cf | 2372 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2373 | return; |
2374 | ||
41fac0cf PA |
2375 | /* For now, limit to agent-style dprintf breakpoints. */ |
2376 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2377 | return; |
2378 | ||
41fac0cf PA |
2379 | /* For now, if we have any duplicate location that isn't a dprintf, |
2380 | don't install the target-side commands, as that would make the | |
2381 | breakpoint not be reported to the core, and we'd lose | |
2382 | control. */ | |
2383 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2384 | { | |
2385 | loc = (*loc2p); | |
2386 | if (is_breakpoint (loc->owner) | |
2387 | && loc->pspace->num == bl->pspace->num | |
2388 | && loc->owner->type != bp_dprintf) | |
2389 | return; | |
2390 | } | |
2391 | ||
d3ce09f5 SS |
2392 | /* Do a first pass to check for locations with no assigned |
2393 | conditions or conditions that fail to parse to a valid agent expression | |
2394 | bytecode. If any of these happen, then it's no use to send conditions | |
2395 | to the target since this location will always trigger and generate a | |
2396 | response back to GDB. */ | |
2397 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2398 | { | |
2399 | loc = (*loc2p); | |
2400 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2401 | { | |
2402 | if (modified) | |
2403 | { | |
d3ce09f5 SS |
2404 | /* Re-parse the commands since something changed. In that |
2405 | case we already freed the command bytecodes (see | |
2406 | force_breakpoint_reinsertion). We just | |
2407 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2408 | loc->cmd_bytecode |
2409 | = parse_cmd_to_aexpr (bl->address, | |
2410 | loc->owner->extra_string); | |
d3ce09f5 SS |
2411 | } |
2412 | ||
2413 | /* If we have a NULL bytecode expression, it means something | |
2414 | went wrong or we have a null command expression. */ | |
2415 | if (!loc->cmd_bytecode) | |
2416 | { | |
2417 | null_command_or_parse_error = 1; | |
2418 | break; | |
2419 | } | |
2420 | } | |
2421 | } | |
2422 | ||
2423 | /* If anything failed, then we're not doing target-side commands, | |
2424 | and so clean up. */ | |
2425 | if (null_command_or_parse_error) | |
2426 | { | |
2427 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2428 | { | |
2429 | loc = (*loc2p); | |
2430 | if (is_breakpoint (loc->owner) | |
2431 | && loc->pspace->num == bl->pspace->num) | |
2432 | { | |
2433 | /* Only go as far as the first NULL bytecode is | |
2434 | located. */ | |
40fb6c5e | 2435 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2436 | return; |
2437 | ||
833177a4 | 2438 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2439 | } |
2440 | } | |
2441 | } | |
2442 | ||
2443 | /* No NULL commands or failed bytecode generation. Build a command list | |
2444 | for this location's address. */ | |
2445 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2446 | { | |
2447 | loc = (*loc2p); | |
2448 | if (loc->owner->extra_string | |
2449 | && is_breakpoint (loc->owner) | |
2450 | && loc->pspace->num == bl->pspace->num | |
2451 | && loc->owner->enable_state == bp_enabled | |
2452 | && loc->enabled) | |
3cde5c42 PA |
2453 | { |
2454 | /* Add the command to the vector. This will be used later | |
2455 | to send the commands to the target. */ | |
2456 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2457 | } | |
d3ce09f5 SS |
2458 | } |
2459 | ||
2460 | bl->target_info.persist = 0; | |
2461 | /* Maybe flag this location as persistent. */ | |
2462 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2463 | bl->target_info.persist = 1; | |
2464 | } | |
2465 | ||
833b7ab5 YQ |
2466 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2467 | of breakpoint according to ADDR except single-step breakpoint. | |
2468 | Get the kind of single-step breakpoint according to the current | |
2469 | registers state. */ | |
cd6c3b4f YQ |
2470 | |
2471 | static int | |
2472 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2473 | { | |
833b7ab5 YQ |
2474 | if (bl->owner->type == bp_single_step) |
2475 | { | |
2476 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2477 | struct regcache *regcache; | |
2478 | ||
2479 | regcache = get_thread_regcache (thr->ptid); | |
2480 | ||
2481 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2482 | regcache, addr); | |
2483 | } | |
2484 | else | |
2485 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2486 | } |
2487 | ||
35df4500 TJB |
2488 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2489 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2490 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2491 | Returns 0 for success, 1 if the bp_location type is not supported or |
2492 | -1 for failure. | |
879bfdc2 | 2493 | |
4a64f543 MS |
2494 | NOTE drow/2003-09-09: This routine could be broken down to an |
2495 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2496 | static int |
35df4500 | 2497 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2498 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2499 | int *disabled_breaks, |
dd61ec5c MW |
2500 | int *hw_breakpoint_error, |
2501 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2502 | { |
0000e5cc PA |
2503 | enum errors bp_err = GDB_NO_ERROR; |
2504 | const char *bp_err_message = NULL; | |
879bfdc2 | 2505 | |
b775012e | 2506 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2507 | return 0; |
2508 | ||
35c63cd8 JB |
2509 | /* Note we don't initialize bl->target_info, as that wipes out |
2510 | the breakpoint location's shadow_contents if the breakpoint | |
2511 | is still inserted at that location. This in turn breaks | |
2512 | target_read_memory which depends on these buffers when | |
2513 | a memory read is requested at the breakpoint location: | |
2514 | Once the target_info has been wiped, we fail to see that | |
2515 | we have a breakpoint inserted at that address and thus | |
2516 | read the breakpoint instead of returning the data saved in | |
2517 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2518 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2519 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2520 | bl->target_info.length = bl->length; |
8181d85f | 2521 | |
b775012e LM |
2522 | /* When working with target-side conditions, we must pass all the conditions |
2523 | for the same breakpoint address down to the target since GDB will not | |
2524 | insert those locations. With a list of breakpoint conditions, the target | |
2525 | can decide when to stop and notify GDB. */ | |
2526 | ||
2527 | if (is_breakpoint (bl->owner)) | |
2528 | { | |
2529 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2530 | build_target_command_list (bl); |
2531 | /* Reset the modification marker. */ | |
b775012e LM |
2532 | bl->needs_update = 0; |
2533 | } | |
2534 | ||
35df4500 TJB |
2535 | if (bl->loc_type == bp_loc_software_breakpoint |
2536 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2537 | { |
35df4500 | 2538 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2539 | { |
2540 | /* If the explicitly specified breakpoint type | |
2541 | is not hardware breakpoint, check the memory map to see | |
2542 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2543 | |
765dc015 VP |
2544 | Two important cases are: |
2545 | - location type is not hardware breakpoint, memory | |
2546 | is readonly. We change the type of the location to | |
2547 | hardware breakpoint. | |
4a64f543 MS |
2548 | - location type is hardware breakpoint, memory is |
2549 | read-write. This means we've previously made the | |
2550 | location hardware one, but then the memory map changed, | |
2551 | so we undo. | |
765dc015 | 2552 | |
4a64f543 MS |
2553 | When breakpoints are removed, remove_breakpoints will use |
2554 | location types we've just set here, the only possible | |
2555 | problem is that memory map has changed during running | |
2556 | program, but it's not going to work anyway with current | |
2557 | gdb. */ | |
765dc015 | 2558 | struct mem_region *mr |
0d5ed153 | 2559 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2560 | |
2561 | if (mr) | |
2562 | { | |
2563 | if (automatic_hardware_breakpoints) | |
2564 | { | |
765dc015 VP |
2565 | enum bp_loc_type new_type; |
2566 | ||
2567 | if (mr->attrib.mode != MEM_RW) | |
2568 | new_type = bp_loc_hardware_breakpoint; | |
2569 | else | |
2570 | new_type = bp_loc_software_breakpoint; | |
2571 | ||
35df4500 | 2572 | if (new_type != bl->loc_type) |
765dc015 VP |
2573 | { |
2574 | static int said = 0; | |
cc59ec59 | 2575 | |
35df4500 | 2576 | bl->loc_type = new_type; |
765dc015 VP |
2577 | if (!said) |
2578 | { | |
3e43a32a MS |
2579 | fprintf_filtered (gdb_stdout, |
2580 | _("Note: automatically using " | |
2581 | "hardware breakpoints for " | |
2582 | "read-only addresses.\n")); | |
765dc015 VP |
2583 | said = 1; |
2584 | } | |
2585 | } | |
2586 | } | |
35df4500 | 2587 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2588 | && mr->attrib.mode != MEM_RW) |
2589 | { | |
2590 | fprintf_unfiltered (tmp_error_stream, | |
2591 | _("Cannot insert breakpoint %d.\n" | |
2592 | "Cannot set software breakpoint " | |
2593 | "at read-only address %s\n"), | |
2594 | bl->owner->number, | |
2595 | paddress (bl->gdbarch, bl->address)); | |
2596 | return 1; | |
2597 | } | |
765dc015 VP |
2598 | } |
2599 | } | |
2600 | ||
879bfdc2 DJ |
2601 | /* First check to see if we have to handle an overlay. */ |
2602 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2603 | || bl->section == NULL |
2604 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2605 | { |
2606 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2607 | TRY |
dd61ec5c | 2608 | { |
0000e5cc PA |
2609 | int val; |
2610 | ||
dd61ec5c | 2611 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2612 | if (val) |
2613 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2614 | } |
492d29ea | 2615 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2616 | { |
0000e5cc PA |
2617 | bp_err = e.error; |
2618 | bp_err_message = e.message; | |
dd61ec5c | 2619 | } |
492d29ea | 2620 | END_CATCH |
879bfdc2 DJ |
2621 | } |
2622 | else | |
2623 | { | |
4a64f543 | 2624 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2625 | Shall we set a breakpoint at the LMA? */ |
2626 | if (!overlay_events_enabled) | |
2627 | { | |
2628 | /* Yes -- overlay event support is not active, | |
2629 | so we must try to set a breakpoint at the LMA. | |
2630 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2631 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2632 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2633 | bl->owner->number); |
879bfdc2 DJ |
2634 | else |
2635 | { | |
35df4500 TJB |
2636 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2637 | bl->section); | |
879bfdc2 | 2638 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2639 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2640 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2641 | |
2642 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2643 | TRY |
0000e5cc PA |
2644 | { |
2645 | int val; | |
2646 | ||
579c6ad9 | 2647 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2648 | = breakpoint_kind (bl, &addr); |
2649 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2650 | val = target_insert_breakpoint (bl->gdbarch, |
2651 | &bl->overlay_target_info); | |
2652 | if (val) | |
2653 | bp_err = GENERIC_ERROR; | |
2654 | } | |
492d29ea | 2655 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2656 | { |
2657 | bp_err = e.error; | |
2658 | bp_err_message = e.message; | |
2659 | } | |
492d29ea | 2660 | END_CATCH |
0000e5cc PA |
2661 | |
2662 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2663 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2664 | "Overlay breakpoint %d " |
2665 | "failed: in ROM?\n", | |
35df4500 | 2666 | bl->owner->number); |
879bfdc2 DJ |
2667 | } |
2668 | } | |
2669 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2670 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2671 | { |
2672 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2673 | TRY |
dd61ec5c | 2674 | { |
0000e5cc PA |
2675 | int val; |
2676 | ||
dd61ec5c | 2677 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2678 | if (val) |
2679 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2680 | } |
492d29ea | 2681 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2682 | { |
0000e5cc PA |
2683 | bp_err = e.error; |
2684 | bp_err_message = e.message; | |
dd61ec5c | 2685 | } |
492d29ea | 2686 | END_CATCH |
879bfdc2 DJ |
2687 | } |
2688 | else | |
2689 | { | |
2690 | /* No. This breakpoint will not be inserted. | |
2691 | No error, but do not mark the bp as 'inserted'. */ | |
2692 | return 0; | |
2693 | } | |
2694 | } | |
2695 | ||
0000e5cc | 2696 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2697 | { |
2698 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2699 | |
2700 | /* In some cases, we might not be able to insert a | |
2701 | breakpoint in a shared library that has already been | |
2702 | removed, but we have not yet processed the shlib unload | |
2703 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2704 | breakpoint insertion themselves can't tell why the |
2705 | breakpoint insertion failed (e.g., the remote target | |
2706 | doesn't define error codes), so we must treat generic | |
2707 | errors as memory errors. */ | |
0000e5cc | 2708 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2709 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2710 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2711 | || shared_objfile_contains_address_p (bl->pspace, |
2712 | bl->address))) | |
879bfdc2 | 2713 | { |
4a64f543 | 2714 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2715 | bl->shlib_disabled = 1; |
8d3788bd | 2716 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2717 | if (!*disabled_breaks) |
2718 | { | |
2719 | fprintf_unfiltered (tmp_error_stream, | |
2720 | "Cannot insert breakpoint %d.\n", | |
2721 | bl->owner->number); | |
2722 | fprintf_unfiltered (tmp_error_stream, | |
2723 | "Temporarily disabling shared " | |
2724 | "library breakpoints:\n"); | |
2725 | } | |
2726 | *disabled_breaks = 1; | |
879bfdc2 | 2727 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2728 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2729 | return 0; |
879bfdc2 DJ |
2730 | } |
2731 | else | |
879bfdc2 | 2732 | { |
35df4500 | 2733 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2734 | { |
0000e5cc PA |
2735 | *hw_breakpoint_error = 1; |
2736 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2737 | fprintf_unfiltered (tmp_error_stream, |
2738 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2739 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2740 | if (bp_err_message != NULL) | |
2741 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2742 | } |
2743 | else | |
2744 | { | |
0000e5cc PA |
2745 | if (bp_err_message == NULL) |
2746 | { | |
1ccbe998 | 2747 | std::string message |
0000e5cc PA |
2748 | = memory_error_message (TARGET_XFER_E_IO, |
2749 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2750 | |
2751 | fprintf_unfiltered (tmp_error_stream, | |
2752 | "Cannot insert breakpoint %d.\n" | |
2753 | "%s\n", | |
1ccbe998 | 2754 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2755 | } |
2756 | else | |
2757 | { | |
2758 | fprintf_unfiltered (tmp_error_stream, | |
2759 | "Cannot insert breakpoint %d: %s\n", | |
2760 | bl->owner->number, | |
2761 | bp_err_message); | |
2762 | } | |
879bfdc2 | 2763 | } |
0000e5cc | 2764 | return 1; |
879bfdc2 DJ |
2765 | |
2766 | } | |
2767 | } | |
2768 | else | |
35df4500 | 2769 | bl->inserted = 1; |
879bfdc2 | 2770 | |
0000e5cc | 2771 | return 0; |
879bfdc2 DJ |
2772 | } |
2773 | ||
35df4500 | 2774 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2775 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2776 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2777 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2778 | { |
0000e5cc PA |
2779 | int val; |
2780 | ||
77b06cd7 TJB |
2781 | gdb_assert (bl->owner->ops != NULL |
2782 | && bl->owner->ops->insert_location != NULL); | |
2783 | ||
2784 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2785 | |
2786 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2787 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2788 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2789 | { |
2790 | struct bp_location *loc, **loc_temp; | |
2791 | ||
2792 | /* But don't try to insert it, if there's already another | |
2793 | hw_access location that would be considered a duplicate | |
2794 | of this one. */ | |
2795 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2796 | if (loc != bl |
85d721b8 | 2797 | && loc->watchpoint_type == hw_access |
35df4500 | 2798 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2799 | { |
35df4500 TJB |
2800 | bl->duplicate = 1; |
2801 | bl->inserted = 1; | |
2802 | bl->target_info = loc->target_info; | |
2803 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2804 | val = 0; |
2805 | break; | |
2806 | } | |
2807 | ||
2808 | if (val == 1) | |
2809 | { | |
77b06cd7 TJB |
2810 | bl->watchpoint_type = hw_access; |
2811 | val = bl->owner->ops->insert_location (bl); | |
2812 | ||
2813 | if (val) | |
2814 | /* Back to the original value. */ | |
2815 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2816 | } |
2817 | } | |
2818 | ||
35df4500 | 2819 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2820 | } |
2821 | ||
35df4500 | 2822 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2823 | { |
0000e5cc PA |
2824 | int val; |
2825 | ||
77b06cd7 TJB |
2826 | gdb_assert (bl->owner->ops != NULL |
2827 | && bl->owner->ops->insert_location != NULL); | |
2828 | ||
2829 | val = bl->owner->ops->insert_location (bl); | |
2830 | if (val) | |
2831 | { | |
2832 | bl->owner->enable_state = bp_disabled; | |
2833 | ||
2834 | if (val == 1) | |
2835 | warning (_("\ | |
2836 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2837 | of catchpoint."), bl->owner->number); | |
2838 | else | |
2839 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2840 | } | |
2841 | ||
2842 | bl->inserted = (val == 0); | |
1640b821 DJ |
2843 | |
2844 | /* We've already printed an error message if there was a problem | |
2845 | inserting this catchpoint, and we've disabled the catchpoint, | |
2846 | so just return success. */ | |
2847 | return 0; | |
879bfdc2 DJ |
2848 | } |
2849 | ||
2850 | return 0; | |
2851 | } | |
2852 | ||
6c95b8df PA |
2853 | /* This function is called when program space PSPACE is about to be |
2854 | deleted. It takes care of updating breakpoints to not reference | |
2855 | PSPACE anymore. */ | |
2856 | ||
2857 | void | |
2858 | breakpoint_program_space_exit (struct program_space *pspace) | |
2859 | { | |
2860 | struct breakpoint *b, *b_temp; | |
876fa593 | 2861 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2862 | |
2863 | /* Remove any breakpoint that was set through this program space. */ | |
2864 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2865 | { | |
2866 | if (b->pspace == pspace) | |
2867 | delete_breakpoint (b); | |
2868 | } | |
2869 | ||
2870 | /* Breakpoints set through other program spaces could have locations | |
2871 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2872 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2873 | { |
2874 | struct bp_location *tmp; | |
2875 | ||
2876 | if (loc->pspace == pspace) | |
2877 | { | |
2bdf28a0 | 2878 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2879 | if (loc->owner->loc == loc) |
2880 | loc->owner->loc = loc->next; | |
2881 | else | |
2882 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2883 | if (tmp->next == loc) | |
2884 | { | |
2885 | tmp->next = loc->next; | |
2886 | break; | |
2887 | } | |
2888 | } | |
2889 | } | |
2890 | ||
2891 | /* Now update the global location list to permanently delete the | |
2892 | removed locations above. */ | |
44702360 | 2893 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2894 | } |
2895 | ||
74960c60 VP |
2896 | /* Make sure all breakpoints are inserted in inferior. |
2897 | Throws exception on any error. | |
2898 | A breakpoint that is already inserted won't be inserted | |
2899 | again, so calling this function twice is safe. */ | |
2900 | void | |
2901 | insert_breakpoints (void) | |
2902 | { | |
2903 | struct breakpoint *bpt; | |
2904 | ||
2905 | ALL_BREAKPOINTS (bpt) | |
2906 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2907 | { |
2908 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2909 | ||
2910 | update_watchpoint (w, 0 /* don't reparse. */); | |
2911 | } | |
74960c60 | 2912 | |
04086b45 PA |
2913 | /* Updating watchpoints creates new locations, so update the global |
2914 | location list. Explicitly tell ugll to insert locations and | |
2915 | ignore breakpoints_always_inserted_mode. */ | |
2916 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
2917 | } |
2918 | ||
20388dd6 YQ |
2919 | /* Invoke CALLBACK for each of bp_location. */ |
2920 | ||
2921 | void | |
2922 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2923 | { | |
2924 | struct bp_location *loc, **loc_tmp; | |
2925 | ||
2926 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2927 | { | |
2928 | callback (loc, NULL); | |
2929 | } | |
2930 | } | |
2931 | ||
b775012e LM |
2932 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2933 | target. It is the case with deleting and disabling of breakpoints when using | |
2934 | always-inserted mode. */ | |
2935 | ||
2936 | static void | |
2937 | update_inserted_breakpoint_locations (void) | |
2938 | { | |
2939 | struct bp_location *bl, **blp_tmp; | |
2940 | int error_flag = 0; | |
2941 | int val = 0; | |
2942 | int disabled_breaks = 0; | |
2943 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2944 | int hw_bp_details_reported = 0; |
b775012e | 2945 | |
d7e74731 | 2946 | string_file tmp_error_stream; |
b775012e LM |
2947 | |
2948 | /* Explicitly mark the warning -- this will only be printed if | |
2949 | there was an error. */ | |
d7e74731 | 2950 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2951 | |
5ed8105e | 2952 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2953 | |
2954 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2955 | { | |
2956 | /* We only want to update software breakpoints and hardware | |
2957 | breakpoints. */ | |
2958 | if (!is_breakpoint (bl->owner)) | |
2959 | continue; | |
2960 | ||
2961 | /* We only want to update locations that are already inserted | |
2962 | and need updating. This is to avoid unwanted insertion during | |
2963 | deletion of breakpoints. */ | |
2964 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2965 | continue; | |
2966 | ||
2967 | switch_to_program_space_and_thread (bl->pspace); | |
2968 | ||
2969 | /* For targets that support global breakpoints, there's no need | |
2970 | to select an inferior to insert breakpoint to. In fact, even | |
2971 | if we aren't attached to any process yet, we should still | |
2972 | insert breakpoints. */ | |
f5656ead | 2973 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2974 | && ptid_equal (inferior_ptid, null_ptid)) |
2975 | continue; | |
2976 | ||
d7e74731 | 2977 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2978 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2979 | if (val) |
2980 | error_flag = val; | |
2981 | } | |
2982 | ||
2983 | if (error_flag) | |
2984 | { | |
223ffa71 | 2985 | target_terminal::ours_for_output (); |
b775012e LM |
2986 | error_stream (tmp_error_stream); |
2987 | } | |
b775012e LM |
2988 | } |
2989 | ||
c30eee59 | 2990 | /* Used when starting or continuing the program. */ |
c906108c | 2991 | |
74960c60 VP |
2992 | static void |
2993 | insert_breakpoint_locations (void) | |
c906108c | 2994 | { |
a5606eee | 2995 | struct breakpoint *bpt; |
35df4500 | 2996 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2997 | int error_flag = 0; |
c906108c | 2998 | int val = 0; |
3fbb6ffa | 2999 | int disabled_breaks = 0; |
81d0cc19 | 3000 | int hw_breakpoint_error = 0; |
dd61ec5c | 3001 | int hw_bp_error_explained_already = 0; |
c906108c | 3002 | |
d7e74731 PA |
3003 | string_file tmp_error_stream; |
3004 | ||
81d0cc19 GS |
3005 | /* Explicitly mark the warning -- this will only be printed if |
3006 | there was an error. */ | |
d7e74731 | 3007 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3008 | |
5ed8105e | 3009 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3010 | |
35df4500 | 3011 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3012 | { |
b775012e | 3013 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3014 | continue; |
3015 | ||
4a64f543 MS |
3016 | /* There is no point inserting thread-specific breakpoints if |
3017 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3018 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3019 | if (bl->owner->thread != -1 |
5d5658a1 | 3020 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3021 | continue; |
3022 | ||
35df4500 | 3023 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3024 | |
3025 | /* For targets that support global breakpoints, there's no need | |
3026 | to select an inferior to insert breakpoint to. In fact, even | |
3027 | if we aren't attached to any process yet, we should still | |
3028 | insert breakpoints. */ | |
f5656ead | 3029 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3030 | && ptid_equal (inferior_ptid, null_ptid)) |
3031 | continue; | |
3032 | ||
d7e74731 | 3033 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3034 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3035 | if (val) |
eacd795a | 3036 | error_flag = val; |
879bfdc2 | 3037 | } |
c906108c | 3038 | |
4a64f543 MS |
3039 | /* If we failed to insert all locations of a watchpoint, remove |
3040 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3041 | ALL_BREAKPOINTS (bpt) |
3042 | { | |
3043 | int some_failed = 0; | |
3044 | struct bp_location *loc; | |
3045 | ||
3046 | if (!is_hardware_watchpoint (bpt)) | |
3047 | continue; | |
3048 | ||
d6b74ac4 | 3049 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3050 | continue; |
74960c60 VP |
3051 | |
3052 | if (bpt->disposition == disp_del_at_next_stop) | |
3053 | continue; | |
a5606eee VP |
3054 | |
3055 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3056 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3057 | { |
3058 | some_failed = 1; | |
3059 | break; | |
3060 | } | |
3061 | if (some_failed) | |
3062 | { | |
3063 | for (loc = bpt->loc; loc; loc = loc->next) | |
3064 | if (loc->inserted) | |
834c0d03 | 3065 | remove_breakpoint (loc); |
a5606eee VP |
3066 | |
3067 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3068 | tmp_error_stream.printf ("Could not insert " |
3069 | "hardware watchpoint %d.\n", | |
3070 | bpt->number); | |
eacd795a | 3071 | error_flag = -1; |
a5606eee VP |
3072 | } |
3073 | } | |
3074 | ||
eacd795a | 3075 | if (error_flag) |
81d0cc19 GS |
3076 | { |
3077 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3078 | message about possibly exhausted resources. */ | |
dd61ec5c | 3079 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3080 | { |
d7e74731 | 3081 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3082 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3083 | } |
223ffa71 | 3084 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3085 | error_stream (tmp_error_stream); |
3086 | } | |
c906108c SS |
3087 | } |
3088 | ||
c30eee59 TJB |
3089 | /* Used when the program stops. |
3090 | Returns zero if successful, or non-zero if there was a problem | |
3091 | removing a breakpoint location. */ | |
3092 | ||
c906108c | 3093 | int |
fba45db2 | 3094 | remove_breakpoints (void) |
c906108c | 3095 | { |
35df4500 | 3096 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3097 | int val = 0; |
c906108c | 3098 | |
35df4500 | 3099 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3100 | { |
1e4d1764 | 3101 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3102 | val |= remove_breakpoint (bl); |
c5aa993b | 3103 | } |
3a1bae8e | 3104 | return val; |
c906108c SS |
3105 | } |
3106 | ||
49fa26b0 PA |
3107 | /* When a thread exits, remove breakpoints that are related to |
3108 | that thread. */ | |
3109 | ||
3110 | static void | |
3111 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3112 | { | |
3113 | struct breakpoint *b, *b_tmp; | |
3114 | ||
3115 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3116 | { | |
5d5658a1 | 3117 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3118 | { |
3119 | b->disposition = disp_del_at_next_stop; | |
3120 | ||
3121 | printf_filtered (_("\ | |
43792cf0 PA |
3122 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3123 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3124 | |
3125 | /* Hide it from the user. */ | |
3126 | b->number = 0; | |
3127 | } | |
3128 | } | |
3129 | } | |
3130 | ||
6c95b8df PA |
3131 | /* Remove breakpoints of process PID. */ |
3132 | ||
3133 | int | |
3134 | remove_breakpoints_pid (int pid) | |
3135 | { | |
35df4500 | 3136 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3137 | int val; |
3138 | struct inferior *inf = find_inferior_pid (pid); | |
3139 | ||
35df4500 | 3140 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3141 | { |
35df4500 | 3142 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3143 | continue; |
3144 | ||
fc126975 | 3145 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3146 | { |
834c0d03 | 3147 | val = remove_breakpoint (bl); |
6c95b8df PA |
3148 | if (val != 0) |
3149 | return val; | |
3150 | } | |
3151 | } | |
3152 | return 0; | |
3153 | } | |
3154 | ||
c906108c | 3155 | int |
fba45db2 | 3156 | reattach_breakpoints (int pid) |
c906108c | 3157 | { |
35df4500 | 3158 | struct bp_location *bl, **blp_tmp; |
c906108c | 3159 | int val; |
dd61ec5c | 3160 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3161 | struct inferior *inf; |
3162 | struct thread_info *tp; | |
3163 | ||
3164 | tp = any_live_thread_of_process (pid); | |
3165 | if (tp == NULL) | |
3166 | return 1; | |
3167 | ||
3168 | inf = find_inferior_pid (pid); | |
6c95b8df | 3169 | |
2989a365 | 3170 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3171 | inferior_ptid = tp->ptid; |
a4954f26 | 3172 | |
d7e74731 | 3173 | string_file tmp_error_stream; |
c906108c | 3174 | |
35df4500 | 3175 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3176 | { |
35df4500 | 3177 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3178 | continue; |
3179 | ||
35df4500 | 3180 | if (bl->inserted) |
c5aa993b | 3181 | { |
35df4500 | 3182 | bl->inserted = 0; |
d7e74731 | 3183 | val = insert_bp_location (bl, &tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b | 3184 | if (val != 0) |
2989a365 | 3185 | return val; |
c5aa993b JM |
3186 | } |
3187 | } | |
c906108c SS |
3188 | return 0; |
3189 | } | |
3190 | ||
e58b0e63 PA |
3191 | static int internal_breakpoint_number = -1; |
3192 | ||
84f4c1fe PM |
3193 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3194 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3195 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3196 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3197 | breakpoint_count and that value incremented. Internal breakpoints |
3198 | do not set the internal var bpnum. */ | |
3199 | static void | |
3200 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3201 | { | |
3202 | if (internal) | |
3203 | b->number = internal_breakpoint_number--; | |
3204 | else | |
3205 | { | |
3206 | set_breakpoint_count (breakpoint_count + 1); | |
3207 | b->number = breakpoint_count; | |
3208 | } | |
3209 | } | |
3210 | ||
e62c965a | 3211 | static struct breakpoint * |
a6d9a66e | 3212 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3213 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3214 | const struct breakpoint_ops *ops) |
e62c965a | 3215 | { |
51abb421 | 3216 | symtab_and_line sal; |
e62c965a PP |
3217 | sal.pc = address; |
3218 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3219 | sal.pspace = current_program_space; |
e62c965a | 3220 | |
51abb421 | 3221 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3222 | b->number = internal_breakpoint_number--; |
3223 | b->disposition = disp_donttouch; | |
3224 | ||
3225 | return b; | |
3226 | } | |
3227 | ||
17450429 PP |
3228 | static const char *const longjmp_names[] = |
3229 | { | |
3230 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3231 | }; | |
3232 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3233 | ||
3234 | /* Per-objfile data private to breakpoint.c. */ | |
3235 | struct breakpoint_objfile_data | |
3236 | { | |
3237 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3238 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3239 | |
3240 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3241 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3242 | |
28106bc2 SDJ |
3243 | /* True if we have looked for longjmp probes. */ |
3244 | int longjmp_searched; | |
3245 | ||
3246 | /* SystemTap probe points for longjmp (if any). */ | |
3247 | VEC (probe_p) *longjmp_probes; | |
3248 | ||
17450429 | 3249 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3250 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3251 | |
3252 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3253 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3254 | |
3255 | /* True if we have looked for exception probes. */ | |
3256 | int exception_searched; | |
3257 | ||
3258 | /* SystemTap probe points for unwinding (if any). */ | |
3259 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3260 | }; |
3261 | ||
3262 | static const struct objfile_data *breakpoint_objfile_key; | |
3263 | ||
3264 | /* Minimal symbol not found sentinel. */ | |
3265 | static struct minimal_symbol msym_not_found; | |
3266 | ||
3267 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3268 | ||
3269 | static int | |
3270 | msym_not_found_p (const struct minimal_symbol *msym) | |
3271 | { | |
3272 | return msym == &msym_not_found; | |
3273 | } | |
3274 | ||
3275 | /* Return per-objfile data needed by breakpoint.c. | |
3276 | Allocate the data if necessary. */ | |
3277 | ||
3278 | static struct breakpoint_objfile_data * | |
3279 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3280 | { | |
3281 | struct breakpoint_objfile_data *bp_objfile_data; | |
3282 | ||
9a3c8263 SM |
3283 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3284 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3285 | if (bp_objfile_data == NULL) |
3286 | { | |
8d749320 SM |
3287 | bp_objfile_data = |
3288 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3289 | |
3290 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3291 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3292 | } | |
3293 | return bp_objfile_data; | |
3294 | } | |
3295 | ||
28106bc2 SDJ |
3296 | static void |
3297 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3298 | { | |
9a3c8263 SM |
3299 | struct breakpoint_objfile_data *bp_objfile_data |
3300 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3301 | |
3302 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3303 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3304 | } | |
3305 | ||
e62c965a | 3306 | static void |
af02033e | 3307 | create_overlay_event_breakpoint (void) |
e62c965a | 3308 | { |
69de3c6a | 3309 | struct objfile *objfile; |
af02033e | 3310 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3311 | |
69de3c6a PP |
3312 | ALL_OBJFILES (objfile) |
3313 | { | |
3314 | struct breakpoint *b; | |
17450429 PP |
3315 | struct breakpoint_objfile_data *bp_objfile_data; |
3316 | CORE_ADDR addr; | |
67994074 | 3317 | struct explicit_location explicit_loc; |
69de3c6a | 3318 | |
17450429 PP |
3319 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3320 | ||
3b7344d5 | 3321 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3322 | continue; |
3323 | ||
3b7344d5 | 3324 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3325 | { |
3b7344d5 | 3326 | struct bound_minimal_symbol m; |
17450429 PP |
3327 | |
3328 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3329 | if (m.minsym == NULL) |
17450429 PP |
3330 | { |
3331 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3332 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3333 | continue; |
3334 | } | |
3335 | bp_objfile_data->overlay_msym = m; | |
3336 | } | |
e62c965a | 3337 | |
77e371c0 | 3338 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3339 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3340 | bp_overlay_event, |
3341 | &internal_breakpoint_ops); | |
67994074 KS |
3342 | initialize_explicit_location (&explicit_loc); |
3343 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3344 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3345 | |
69de3c6a PP |
3346 | if (overlay_debugging == ovly_auto) |
3347 | { | |
3348 | b->enable_state = bp_enabled; | |
3349 | overlay_events_enabled = 1; | |
3350 | } | |
3351 | else | |
3352 | { | |
3353 | b->enable_state = bp_disabled; | |
3354 | overlay_events_enabled = 0; | |
3355 | } | |
e62c965a | 3356 | } |
e62c965a PP |
3357 | } |
3358 | ||
0fd8e87f | 3359 | static void |
af02033e | 3360 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3361 | { |
6c95b8df | 3362 | struct program_space *pspace; |
6c95b8df | 3363 | |
5ed8105e | 3364 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3365 | |
6c95b8df | 3366 | ALL_PSPACES (pspace) |
af02033e PP |
3367 | { |
3368 | struct objfile *objfile; | |
3369 | ||
3370 | set_current_program_space (pspace); | |
3371 | ||
3372 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3373 | { |
af02033e PP |
3374 | int i; |
3375 | struct gdbarch *gdbarch; | |
17450429 | 3376 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3377 | |
af02033e | 3378 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3379 | |
17450429 PP |
3380 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3381 | ||
28106bc2 SDJ |
3382 | if (!bp_objfile_data->longjmp_searched) |
3383 | { | |
25f9533e SDJ |
3384 | VEC (probe_p) *ret; |
3385 | ||
3386 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3387 | if (ret != NULL) | |
3388 | { | |
3389 | /* We are only interested in checking one element. */ | |
3390 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3391 | ||
3392 | if (!can_evaluate_probe_arguments (p)) | |
3393 | { | |
3394 | /* We cannot use the probe interface here, because it does | |
3395 | not know how to evaluate arguments. */ | |
3396 | VEC_free (probe_p, ret); | |
3397 | ret = NULL; | |
3398 | } | |
3399 | } | |
3400 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3401 | bp_objfile_data->longjmp_searched = 1; |
3402 | } | |
3403 | ||
3404 | if (bp_objfile_data->longjmp_probes != NULL) | |
3405 | { | |
3406 | int i; | |
3407 | struct probe *probe; | |
3408 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3409 | ||
3410 | for (i = 0; | |
3411 | VEC_iterate (probe_p, | |
3412 | bp_objfile_data->longjmp_probes, | |
3413 | i, probe); | |
3414 | ++i) | |
3415 | { | |
3416 | struct breakpoint *b; | |
3417 | ||
729662a5 TT |
3418 | b = create_internal_breakpoint (gdbarch, |
3419 | get_probe_address (probe, | |
3420 | objfile), | |
28106bc2 SDJ |
3421 | bp_longjmp_master, |
3422 | &internal_breakpoint_ops); | |
d28cd78a | 3423 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
28106bc2 SDJ |
3424 | b->enable_state = bp_disabled; |
3425 | } | |
3426 | ||
3427 | continue; | |
3428 | } | |
3429 | ||
0569175e TSD |
3430 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3431 | continue; | |
3432 | ||
17450429 | 3433 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3434 | { |
3435 | struct breakpoint *b; | |
af02033e | 3436 | const char *func_name; |
17450429 | 3437 | CORE_ADDR addr; |
67994074 | 3438 | struct explicit_location explicit_loc; |
6c95b8df | 3439 | |
3b7344d5 | 3440 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3441 | continue; |
0fd8e87f | 3442 | |
17450429 | 3443 | func_name = longjmp_names[i]; |
3b7344d5 | 3444 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3445 | { |
3b7344d5 | 3446 | struct bound_minimal_symbol m; |
17450429 PP |
3447 | |
3448 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3449 | if (m.minsym == NULL) |
17450429 PP |
3450 | { |
3451 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3452 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3453 | continue; |
3454 | } | |
3455 | bp_objfile_data->longjmp_msym[i] = m; | |
3456 | } | |
3457 | ||
77e371c0 | 3458 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3459 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3460 | &internal_breakpoint_ops); | |
67994074 KS |
3461 | initialize_explicit_location (&explicit_loc); |
3462 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3463 | b->location = new_explicit_location (&explicit_loc); |
af02033e PP |
3464 | b->enable_state = bp_disabled; |
3465 | } | |
0fd8e87f | 3466 | } |
af02033e | 3467 | } |
0fd8e87f UW |
3468 | } |
3469 | ||
af02033e | 3470 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3471 | static void |
af02033e | 3472 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3473 | { |
3474 | struct program_space *pspace; | |
af02033e | 3475 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3476 | |
5ed8105e | 3477 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3478 | |
3479 | ALL_PSPACES (pspace) | |
17450429 PP |
3480 | { |
3481 | struct objfile *objfile; | |
3482 | CORE_ADDR addr; | |
3483 | ||
3484 | set_current_program_space (pspace); | |
3485 | ||
aa7d318d TT |
3486 | ALL_OBJFILES (objfile) |
3487 | { | |
3488 | struct breakpoint *b; | |
17450429 | 3489 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3490 | struct explicit_location explicit_loc; |
aa7d318d | 3491 | |
17450429 | 3492 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3493 | |
3b7344d5 | 3494 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3495 | continue; |
3496 | ||
3b7344d5 | 3497 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3498 | { |
3b7344d5 | 3499 | struct bound_minimal_symbol m; |
17450429 PP |
3500 | |
3501 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3502 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3503 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3504 | { |
3505 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3506 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3507 | continue; |
3508 | } | |
3509 | bp_objfile_data->terminate_msym = m; | |
3510 | } | |
aa7d318d | 3511 | |
77e371c0 | 3512 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3513 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3514 | bp_std_terminate_master, |
3515 | &internal_breakpoint_ops); | |
67994074 KS |
3516 | initialize_explicit_location (&explicit_loc); |
3517 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3518 | b->location = new_explicit_location (&explicit_loc); |
aa7d318d TT |
3519 | b->enable_state = bp_disabled; |
3520 | } | |
17450429 | 3521 | } |
aa7d318d TT |
3522 | } |
3523 | ||
186c406b TT |
3524 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3525 | ||
70221824 | 3526 | static void |
186c406b TT |
3527 | create_exception_master_breakpoint (void) |
3528 | { | |
3529 | struct objfile *objfile; | |
17450429 | 3530 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3531 | |
3532 | ALL_OBJFILES (objfile) | |
3533 | { | |
17450429 PP |
3534 | struct breakpoint *b; |
3535 | struct gdbarch *gdbarch; | |
3536 | struct breakpoint_objfile_data *bp_objfile_data; | |
3537 | CORE_ADDR addr; | |
67994074 | 3538 | struct explicit_location explicit_loc; |
17450429 PP |
3539 | |
3540 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3541 | ||
28106bc2 SDJ |
3542 | /* We prefer the SystemTap probe point if it exists. */ |
3543 | if (!bp_objfile_data->exception_searched) | |
3544 | { | |
25f9533e SDJ |
3545 | VEC (probe_p) *ret; |
3546 | ||
3547 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3548 | ||
3549 | if (ret != NULL) | |
3550 | { | |
3551 | /* We are only interested in checking one element. */ | |
3552 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3553 | ||
3554 | if (!can_evaluate_probe_arguments (p)) | |
3555 | { | |
3556 | /* We cannot use the probe interface here, because it does | |
3557 | not know how to evaluate arguments. */ | |
3558 | VEC_free (probe_p, ret); | |
3559 | ret = NULL; | |
3560 | } | |
3561 | } | |
3562 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3563 | bp_objfile_data->exception_searched = 1; |
3564 | } | |
3565 | ||
3566 | if (bp_objfile_data->exception_probes != NULL) | |
3567 | { | |
3568 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3569 | int i; | |
3570 | struct probe *probe; | |
3571 | ||
3572 | for (i = 0; | |
3573 | VEC_iterate (probe_p, | |
3574 | bp_objfile_data->exception_probes, | |
3575 | i, probe); | |
3576 | ++i) | |
3577 | { | |
3578 | struct breakpoint *b; | |
3579 | ||
729662a5 TT |
3580 | b = create_internal_breakpoint (gdbarch, |
3581 | get_probe_address (probe, | |
3582 | objfile), | |
28106bc2 SDJ |
3583 | bp_exception_master, |
3584 | &internal_breakpoint_ops); | |
d28cd78a | 3585 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3586 | b->enable_state = bp_disabled; |
3587 | } | |
3588 | ||
3589 | continue; | |
3590 | } | |
3591 | ||
3592 | /* Otherwise, try the hook function. */ | |
3593 | ||
3b7344d5 | 3594 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3595 | continue; |
3596 | ||
3597 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3598 | |
3b7344d5 | 3599 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3600 | { |
3b7344d5 | 3601 | struct bound_minimal_symbol debug_hook; |
186c406b | 3602 | |
17450429 | 3603 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3604 | if (debug_hook.minsym == NULL) |
17450429 | 3605 | { |
3b7344d5 | 3606 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3607 | continue; |
3608 | } | |
3609 | ||
3610 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3611 | } |
17450429 | 3612 | |
77e371c0 | 3613 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3614 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3615 | ¤t_target); | |
06edf0c0 PA |
3616 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3617 | &internal_breakpoint_ops); | |
67994074 KS |
3618 | initialize_explicit_location (&explicit_loc); |
3619 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3620 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3621 | b->enable_state = bp_disabled; |
186c406b | 3622 | } |
186c406b TT |
3623 | } |
3624 | ||
9ef9e6a6 KS |
3625 | /* Does B have a location spec? */ |
3626 | ||
3627 | static int | |
3628 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3629 | { | |
d28cd78a | 3630 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3631 | } |
3632 | ||
c906108c | 3633 | void |
fba45db2 | 3634 | update_breakpoints_after_exec (void) |
c906108c | 3635 | { |
35df4500 | 3636 | struct breakpoint *b, *b_tmp; |
876fa593 | 3637 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3638 | |
25b22b0a PA |
3639 | /* We're about to delete breakpoints from GDB's lists. If the |
3640 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3641 | writing the breakpoints' "shadow contents" back into memory. The | |
3642 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3643 | do that. Instead, the target is responsible from marking | |
3644 | breakpoints out as soon as it detects an exec. We don't do that | |
3645 | here instead, because there may be other attempts to delete | |
3646 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3647 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3648 | if (bploc->pspace == current_program_space) |
3649 | gdb_assert (!bploc->inserted); | |
c906108c | 3650 | |
35df4500 | 3651 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3652 | { |
6c95b8df PA |
3653 | if (b->pspace != current_program_space) |
3654 | continue; | |
3655 | ||
4a64f543 | 3656 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3657 | if (b->type == bp_shlib_event) |
3658 | { | |
3659 | delete_breakpoint (b); | |
3660 | continue; | |
3661 | } | |
c906108c | 3662 | |
4a64f543 | 3663 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3664 | if (b->type == bp_jit_event) |
3665 | { | |
3666 | delete_breakpoint (b); | |
3667 | continue; | |
3668 | } | |
3669 | ||
1900040c | 3670 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3671 | as must overlay event and longjmp master breakpoints. */ |
3672 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3673 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3674 | || b->type == bp_exception_master) | |
c4093a6a JM |
3675 | { |
3676 | delete_breakpoint (b); | |
3677 | continue; | |
3678 | } | |
3679 | ||
4a64f543 | 3680 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3681 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3682 | { |
3683 | delete_breakpoint (b); | |
3684 | continue; | |
3685 | } | |
3686 | ||
7c16b83e PA |
3687 | /* Just like single-step breakpoints. */ |
3688 | if (b->type == bp_single_step) | |
3689 | { | |
3690 | delete_breakpoint (b); | |
3691 | continue; | |
3692 | } | |
3693 | ||
611c83ae PA |
3694 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3695 | after an exec. */ | |
186c406b | 3696 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3697 | || b->type == bp_longjmp_call_dummy |
186c406b | 3698 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3699 | { |
3700 | delete_breakpoint (b); | |
3701 | continue; | |
3702 | } | |
3703 | ||
ce78b96d JB |
3704 | if (b->type == bp_catchpoint) |
3705 | { | |
3706 | /* For now, none of the bp_catchpoint breakpoints need to | |
3707 | do anything at this point. In the future, if some of | |
3708 | the catchpoints need to something, we will need to add | |
3709 | a new method, and call this method from here. */ | |
3710 | continue; | |
3711 | } | |
3712 | ||
c5aa993b JM |
3713 | /* bp_finish is a special case. The only way we ought to be able |
3714 | to see one of these when an exec() has happened, is if the user | |
3715 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3716 | carries them to the call-site of the current callee, by setting | |
3717 | a temporary bp there and resuming. But in this case, the finish | |
3718 | will carry them entirely through the vfork & exec. | |
3719 | ||
3720 | We don't want to allow a bp_finish to remain inserted now. But | |
3721 | we can't safely delete it, 'cause finish_command has a handle to | |
3722 | the bp on a bpstat, and will later want to delete it. There's a | |
3723 | chance (and I've seen it happen) that if we delete the bp_finish | |
3724 | here, that its storage will get reused by the time finish_command | |
3725 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3726 | We really must allow finish_command to delete a bp_finish. | |
3727 | ||
e5dd4106 | 3728 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3729 | it's safe to delete something others may have handles to?" |
3730 | problem, what we'll do here is just uninsert the bp_finish, and | |
3731 | let finish_command delete it. | |
3732 | ||
3733 | (We know the bp_finish is "doomed" in the sense that it's | |
3734 | momentary, and will be deleted as soon as finish_command sees | |
3735 | the inferior stopped. So it doesn't matter that the bp's | |
3736 | address is probably bogus in the new a.out, unlike e.g., the | |
3737 | solib breakpoints.) */ | |
c5aa993b | 3738 | |
c5aa993b JM |
3739 | if (b->type == bp_finish) |
3740 | { | |
3741 | continue; | |
3742 | } | |
3743 | ||
3744 | /* Without a symbolic address, we have little hope of the | |
3745 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3746 | a.out. */ |
9ef9e6a6 | 3747 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3748 | { |
3749 | delete_breakpoint (b); | |
3750 | continue; | |
3751 | } | |
c5aa993b | 3752 | } |
c906108c SS |
3753 | } |
3754 | ||
3755 | int | |
d80ee84f | 3756 | detach_breakpoints (ptid_t ptid) |
c906108c | 3757 | { |
35df4500 | 3758 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3759 | int val = 0; |
2989a365 | 3760 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3761 | struct inferior *inf = current_inferior (); |
c5aa993b | 3762 | |
dfd4cc63 | 3763 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3764 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3765 | |
6c95b8df | 3766 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3767 | inferior_ptid = ptid; |
35df4500 | 3768 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3769 | { |
35df4500 | 3770 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3771 | continue; |
3772 | ||
bd9673a4 PW |
3773 | /* This function must physically remove breakpoints locations |
3774 | from the specified ptid, without modifying the breakpoint | |
3775 | package's state. Locations of type bp_loc_other are only | |
3776 | maintained at GDB side. So, there is no need to remove | |
3777 | these bp_loc_other locations. Moreover, removing these | |
3778 | would modify the breakpoint package's state. */ | |
3779 | if (bl->loc_type == bp_loc_other) | |
3780 | continue; | |
3781 | ||
35df4500 | 3782 | if (bl->inserted) |
b2b6a7da | 3783 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3784 | } |
d03285ec | 3785 | |
3a1bae8e | 3786 | return val; |
c906108c SS |
3787 | } |
3788 | ||
35df4500 | 3789 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3790 | Note that this is used to detach breakpoints from a child fork. |
3791 | When we get here, the child isn't in the inferior list, and neither | |
3792 | do we have objects to represent its address space --- we should | |
35df4500 | 3793 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3794 | |
c906108c | 3795 | static int |
b2b6a7da | 3796 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3797 | { |
3798 | int val; | |
c5aa993b | 3799 | |
35df4500 TJB |
3800 | /* BL is never in moribund_locations by our callers. */ |
3801 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3802 | |
74960c60 VP |
3803 | /* The type of none suggests that owner is actually deleted. |
3804 | This should not ever happen. */ | |
35df4500 | 3805 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3806 | |
35df4500 TJB |
3807 | if (bl->loc_type == bp_loc_software_breakpoint |
3808 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3809 | { |
c02f5703 MS |
3810 | /* "Normal" instruction breakpoint: either the standard |
3811 | trap-instruction bp (bp_breakpoint), or a | |
3812 | bp_hardware_breakpoint. */ | |
3813 | ||
3814 | /* First check to see if we have to handle an overlay. */ | |
3815 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3816 | || bl->section == NULL |
3817 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3818 | { |
3819 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3820 | |
3821 | /* If we're trying to uninsert a memory breakpoint that we | |
3822 | know is set in a dynamic object that is marked | |
3823 | shlib_disabled, then either the dynamic object was | |
3824 | removed with "remove-symbol-file" or with | |
3825 | "nosharedlibrary". In the former case, we don't know | |
3826 | whether another dynamic object might have loaded over the | |
3827 | breakpoint's address -- the user might well let us know | |
3828 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3829 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3830 | list of dynamically loaded objects). If we have the |
3831 | breakpoint's shadow memory, that is, this is a software | |
3832 | breakpoint managed by GDB, check whether the breakpoint | |
3833 | is still inserted in memory, to avoid overwriting wrong | |
3834 | code with stale saved shadow contents. Note that HW | |
3835 | breakpoints don't have shadow memory, as they're | |
3836 | implemented using a mechanism that is not dependent on | |
3837 | being able to modify the target's memory, and as such | |
3838 | they should always be removed. */ | |
3839 | if (bl->shlib_disabled | |
3840 | && bl->target_info.shadow_len != 0 | |
3841 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3842 | val = 0; | |
3843 | else | |
73971819 | 3844 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3845 | } |
c906108c SS |
3846 | else |
3847 | { | |
4a64f543 | 3848 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3849 | Did we set a breakpoint at the LMA? */ |
3850 | if (!overlay_events_enabled) | |
3851 | { | |
3852 | /* Yes -- overlay event support is not active, so we | |
3853 | should have set a breakpoint at the LMA. Remove it. | |
3854 | */ | |
c02f5703 MS |
3855 | /* Ignore any failures: if the LMA is in ROM, we will |
3856 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3857 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3858 | target_remove_hw_breakpoint (bl->gdbarch, | |
3859 | &bl->overlay_target_info); | |
c02f5703 | 3860 | else |
35df4500 | 3861 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3862 | &bl->overlay_target_info, |
3863 | reason); | |
c02f5703 MS |
3864 | } |
3865 | /* Did we set a breakpoint at the VMA? | |
3866 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3867 | if (bl->inserted) |
c906108c | 3868 | { |
c02f5703 MS |
3869 | /* Yes -- remove it. Previously we did not bother to |
3870 | remove the breakpoint if the section had been | |
3871 | unmapped, but let's not rely on that being safe. We | |
3872 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3873 | |
3874 | /* However, we should remove *software* breakpoints only | |
3875 | if the section is still mapped, or else we overwrite | |
3876 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3877 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3878 | || section_is_mapped (bl->section)) | |
73971819 | 3879 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3880 | else |
3881 | val = 0; | |
c906108c | 3882 | } |
c02f5703 MS |
3883 | else |
3884 | { | |
3885 | /* No -- not inserted, so no need to remove. No error. */ | |
3886 | val = 0; | |
3887 | } | |
c906108c | 3888 | } |
879d1e6b | 3889 | |
08351840 PA |
3890 | /* In some cases, we might not be able to remove a breakpoint in |
3891 | a shared library that has already been removed, but we have | |
3892 | not yet processed the shlib unload event. Similarly for an | |
3893 | unloaded add-symbol-file object - the user might not yet have | |
3894 | had the chance to remove-symbol-file it. shlib_disabled will | |
3895 | be set if the library/object has already been removed, but | |
3896 | the breakpoint hasn't been uninserted yet, e.g., after | |
3897 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3898 | always-inserted mode. */ | |
076855f9 | 3899 | if (val |
08351840 PA |
3900 | && (bl->loc_type == bp_loc_software_breakpoint |
3901 | && (bl->shlib_disabled | |
3902 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3903 | || shared_objfile_contains_address_p (bl->pspace, |
3904 | bl->address)))) | |
879d1e6b UW |
3905 | val = 0; |
3906 | ||
c906108c SS |
3907 | if (val) |
3908 | return val; | |
b2b6a7da | 3909 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3910 | } |
35df4500 | 3911 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3912 | { |
77b06cd7 TJB |
3913 | gdb_assert (bl->owner->ops != NULL |
3914 | && bl->owner->ops->remove_location != NULL); | |
3915 | ||
b2b6a7da | 3916 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3917 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3918 | |
c906108c | 3919 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3920 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3921 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3922 | bl->owner->number); |
c906108c | 3923 | } |
35df4500 TJB |
3924 | else if (bl->owner->type == bp_catchpoint |
3925 | && breakpoint_enabled (bl->owner) | |
3926 | && !bl->duplicate) | |
ce78b96d | 3927 | { |
77b06cd7 TJB |
3928 | gdb_assert (bl->owner->ops != NULL |
3929 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3930 | |
73971819 | 3931 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3932 | if (val) |
3933 | return val; | |
77b06cd7 | 3934 | |
b2b6a7da | 3935 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3936 | } |
c906108c SS |
3937 | |
3938 | return 0; | |
3939 | } | |
3940 | ||
6c95b8df | 3941 | static int |
834c0d03 | 3942 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3943 | { |
35df4500 TJB |
3944 | /* BL is never in moribund_locations by our callers. */ |
3945 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3946 | |
6c95b8df PA |
3947 | /* The type of none suggests that owner is actually deleted. |
3948 | This should not ever happen. */ | |
35df4500 | 3949 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3950 | |
5ed8105e | 3951 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3952 | |
35df4500 | 3953 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3954 | |
5ed8105e | 3955 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3956 | } |
3957 | ||
c906108c SS |
3958 | /* Clear the "inserted" flag in all breakpoints. */ |
3959 | ||
25b22b0a | 3960 | void |
fba45db2 | 3961 | mark_breakpoints_out (void) |
c906108c | 3962 | { |
35df4500 | 3963 | struct bp_location *bl, **blp_tmp; |
c906108c | 3964 | |
35df4500 | 3965 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3966 | if (bl->pspace == current_program_space) |
35df4500 | 3967 | bl->inserted = 0; |
c906108c SS |
3968 | } |
3969 | ||
53a5351d JM |
3970 | /* Clear the "inserted" flag in all breakpoints and delete any |
3971 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3972 | |
3973 | Plus other such housekeeping that has to be done for breakpoints | |
3974 | between runs. | |
3975 | ||
53a5351d JM |
3976 | Note: this function gets called at the end of a run (by |
3977 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3978 | init_wait_for_inferior). */ |
c906108c SS |
3979 | |
3980 | ||
3981 | ||
3982 | void | |
fba45db2 | 3983 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3984 | { |
35df4500 | 3985 | struct breakpoint *b, *b_tmp; |
870f88f7 | 3986 | struct bp_location *bl; |
1c5cfe86 | 3987 | int ix; |
6c95b8df | 3988 | struct program_space *pspace = current_program_space; |
c906108c | 3989 | |
50c71eaf PA |
3990 | /* If breakpoint locations are shared across processes, then there's |
3991 | nothing to do. */ | |
f5656ead | 3992 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3993 | return; |
3994 | ||
1a853c52 | 3995 | mark_breakpoints_out (); |
075f6582 | 3996 | |
35df4500 | 3997 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3998 | { |
6c95b8df PA |
3999 | if (b->loc && b->loc->pspace != pspace) |
4000 | continue; | |
4001 | ||
c5aa993b JM |
4002 | switch (b->type) |
4003 | { | |
4004 | case bp_call_dummy: | |
e2e4d78b | 4005 | case bp_longjmp_call_dummy: |
c906108c | 4006 | |
c5aa993b | 4007 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4008 | cause problems when the inferior is rerun, so we better get |
4009 | rid of it. */ | |
4010 | ||
4011 | case bp_watchpoint_scope: | |
4012 | ||
4013 | /* Also get rid of scope breakpoints. */ | |
4014 | ||
4015 | case bp_shlib_event: | |
4016 | ||
4017 | /* Also remove solib event breakpoints. Their addresses may | |
4018 | have changed since the last time we ran the program. | |
4019 | Actually we may now be debugging against different target; | |
4020 | and so the solib backend that installed this breakpoint may | |
4021 | not be used in by the target. E.g., | |
4022 | ||
4023 | (gdb) file prog-linux | |
4024 | (gdb) run # native linux target | |
4025 | ... | |
4026 | (gdb) kill | |
4027 | (gdb) file prog-win.exe | |
4028 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4029 | */ | |
c906108c | 4030 | |
f59f708a PA |
4031 | case bp_step_resume: |
4032 | ||
4033 | /* Also remove step-resume breakpoints. */ | |
4034 | ||
7c16b83e PA |
4035 | case bp_single_step: |
4036 | ||
4037 | /* Also remove single-step breakpoints. */ | |
4038 | ||
c5aa993b JM |
4039 | delete_breakpoint (b); |
4040 | break; | |
c906108c | 4041 | |
c5aa993b JM |
4042 | case bp_watchpoint: |
4043 | case bp_hardware_watchpoint: | |
4044 | case bp_read_watchpoint: | |
4045 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4046 | { |
4047 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4048 | |
3a5c3e22 PA |
4049 | /* Likewise for watchpoints on local expressions. */ |
4050 | if (w->exp_valid_block != NULL) | |
4051 | delete_breakpoint (b); | |
63000888 | 4052 | else |
3a5c3e22 | 4053 | { |
63000888 PA |
4054 | /* Get rid of existing locations, which are no longer |
4055 | valid. New ones will be created in | |
4056 | update_watchpoint, when the inferior is restarted. | |
4057 | The next update_global_location_list call will | |
4058 | garbage collect them. */ | |
4059 | b->loc = NULL; | |
4060 | ||
4061 | if (context == inf_starting) | |
4062 | { | |
4063 | /* Reset val field to force reread of starting value in | |
4064 | insert_breakpoints. */ | |
4065 | if (w->val) | |
4066 | value_free (w->val); | |
4067 | w->val = NULL; | |
4068 | w->val_valid = 0; | |
4069 | } | |
4070 | } | |
3a5c3e22 | 4071 | } |
c5aa993b JM |
4072 | break; |
4073 | default: | |
c5aa993b JM |
4074 | break; |
4075 | } | |
4076 | } | |
1c5cfe86 PA |
4077 | |
4078 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4079 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4080 | decref_bp_location (&bl); | |
1c5cfe86 | 4081 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4082 | } |
4083 | ||
6c95b8df PA |
4084 | /* These functions concern about actual breakpoints inserted in the |
4085 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4086 | we need to hop over the bkpt --- so we check for address space | |
4087 | match, not program space. */ | |
4088 | ||
c2c6d25f JM |
4089 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4090 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4091 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4092 | permanent breakpoint. | |
4093 | - When continuing from a location with an ordinary breakpoint, we | |
4094 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4095 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4096 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4097 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4098 | |
c2c6d25f | 4099 | enum breakpoint_here |
6c95b8df | 4100 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4101 | { |
35df4500 | 4102 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4103 | int any_breakpoint_here = 0; |
c906108c | 4104 | |
35df4500 | 4105 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4106 | { |
35df4500 TJB |
4107 | if (bl->loc_type != bp_loc_software_breakpoint |
4108 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4109 | continue; |
4110 | ||
f1310107 | 4111 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4112 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4113 | || bl->permanent) |
f1310107 | 4114 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4115 | { |
4116 | if (overlay_debugging | |
35df4500 TJB |
4117 | && section_is_overlay (bl->section) |
4118 | && !section_is_mapped (bl->section)) | |
075f6582 | 4119 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4120 | else if (bl->permanent) |
075f6582 DJ |
4121 | return permanent_breakpoint_here; |
4122 | else | |
4123 | any_breakpoint_here = 1; | |
4124 | } | |
4125 | } | |
c906108c | 4126 | |
f486487f | 4127 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4128 | } |
4129 | ||
d35ae833 PA |
4130 | /* See breakpoint.h. */ |
4131 | ||
4132 | int | |
4133 | breakpoint_in_range_p (struct address_space *aspace, | |
4134 | CORE_ADDR addr, ULONGEST len) | |
4135 | { | |
4136 | struct bp_location *bl, **blp_tmp; | |
4137 | ||
4138 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4139 | { | |
4140 | if (bl->loc_type != bp_loc_software_breakpoint | |
4141 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4142 | continue; | |
4143 | ||
4144 | if ((breakpoint_enabled (bl->owner) | |
4145 | || bl->permanent) | |
4146 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4147 | addr, len)) | |
4148 | { | |
4149 | if (overlay_debugging | |
4150 | && section_is_overlay (bl->section) | |
4151 | && !section_is_mapped (bl->section)) | |
4152 | { | |
4153 | /* Unmapped overlay -- can't be a match. */ | |
4154 | continue; | |
4155 | } | |
4156 | ||
4157 | return 1; | |
4158 | } | |
4159 | } | |
4160 | ||
4161 | return 0; | |
4162 | } | |
4163 | ||
1c5cfe86 PA |
4164 | /* Return true if there's a moribund breakpoint at PC. */ |
4165 | ||
4166 | int | |
6c95b8df | 4167 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4168 | { |
4169 | struct bp_location *loc; | |
4170 | int ix; | |
4171 | ||
4172 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4173 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4174 | return 1; |
4175 | ||
4176 | return 0; | |
4177 | } | |
c2c6d25f | 4178 | |
f7ce857f PA |
4179 | /* Returns non-zero iff BL is inserted at PC, in address space |
4180 | ASPACE. */ | |
4181 | ||
4182 | static int | |
4183 | bp_location_inserted_here_p (struct bp_location *bl, | |
4184 | struct address_space *aspace, CORE_ADDR pc) | |
4185 | { | |
4186 | if (bl->inserted | |
4187 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4188 | aspace, pc)) | |
4189 | { | |
4190 | if (overlay_debugging | |
4191 | && section_is_overlay (bl->section) | |
4192 | && !section_is_mapped (bl->section)) | |
4193 | return 0; /* unmapped overlay -- can't be a match */ | |
4194 | else | |
4195 | return 1; | |
4196 | } | |
4197 | return 0; | |
4198 | } | |
4199 | ||
a1fd2fa5 | 4200 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4201 | |
4202 | int | |
a1fd2fa5 | 4203 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4204 | { |
f7ce857f | 4205 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4206 | |
f7ce857f | 4207 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4208 | { |
f7ce857f PA |
4209 | struct bp_location *bl = *blp; |
4210 | ||
35df4500 TJB |
4211 | if (bl->loc_type != bp_loc_software_breakpoint |
4212 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4213 | continue; |
4214 | ||
f7ce857f PA |
4215 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4216 | return 1; | |
c5aa993b | 4217 | } |
c36b740a VP |
4218 | return 0; |
4219 | } | |
4220 | ||
a1fd2fa5 PA |
4221 | /* This function returns non-zero iff there is a software breakpoint |
4222 | inserted at PC. */ | |
c36b740a VP |
4223 | |
4224 | int | |
a1fd2fa5 PA |
4225 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4226 | CORE_ADDR pc) | |
4fa8626c | 4227 | { |
f7ce857f | 4228 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4229 | |
f7ce857f | 4230 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4231 | { |
f7ce857f PA |
4232 | struct bp_location *bl = *blp; |
4233 | ||
35df4500 | 4234 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4235 | continue; |
4236 | ||
f7ce857f PA |
4237 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4238 | return 1; | |
4fa8626c DJ |
4239 | } |
4240 | ||
4241 | return 0; | |
9c02b525 PA |
4242 | } |
4243 | ||
4244 | /* See breakpoint.h. */ | |
4245 | ||
4246 | int | |
4247 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4248 | CORE_ADDR pc) | |
4249 | { | |
4250 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4251 | |
4252 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4253 | { | |
4254 | struct bp_location *bl = *blp; | |
4255 | ||
4256 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4257 | continue; | |
4258 | ||
4259 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4260 | return 1; | |
4261 | } | |
4262 | ||
4263 | return 0; | |
4fa8626c DJ |
4264 | } |
4265 | ||
9093389c PA |
4266 | int |
4267 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4268 | CORE_ADDR addr, ULONGEST len) | |
4269 | { | |
4270 | struct breakpoint *bpt; | |
4271 | ||
4272 | ALL_BREAKPOINTS (bpt) | |
4273 | { | |
4274 | struct bp_location *loc; | |
4275 | ||
4276 | if (bpt->type != bp_hardware_watchpoint | |
4277 | && bpt->type != bp_access_watchpoint) | |
4278 | continue; | |
4279 | ||
4280 | if (!breakpoint_enabled (bpt)) | |
4281 | continue; | |
4282 | ||
4283 | for (loc = bpt->loc; loc; loc = loc->next) | |
4284 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4285 | { | |
4286 | CORE_ADDR l, h; | |
4287 | ||
4288 | /* Check for intersection. */ | |
768adc05 PA |
4289 | l = std::max<CORE_ADDR> (loc->address, addr); |
4290 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4291 | if (l < h) |
4292 | return 1; | |
4293 | } | |
4294 | } | |
4295 | return 0; | |
4296 | } | |
c906108c | 4297 | \f |
c5aa993b | 4298 | |
c906108c SS |
4299 | /* bpstat stuff. External routines' interfaces are documented |
4300 | in breakpoint.h. */ | |
4301 | ||
4302 | int | |
c326b90e | 4303 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4304 | { |
533be4dd | 4305 | return (ep->type == bp_catchpoint); |
c906108c SS |
4306 | } |
4307 | ||
f431efe5 PA |
4308 | /* Frees any storage that is part of a bpstat. Does not walk the |
4309 | 'next' chain. */ | |
4310 | ||
04afa70c | 4311 | bpstats::~bpstats () |
198757a8 | 4312 | { |
04afa70c TT |
4313 | if (old_val != NULL) |
4314 | value_free (old_val); | |
04afa70c TT |
4315 | if (bp_location_at != NULL) |
4316 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4317 | } |
4318 | ||
c906108c SS |
4319 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4320 | Also free any storage that is part of a bpstat. */ | |
4321 | ||
4322 | void | |
fba45db2 | 4323 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4324 | { |
4325 | bpstat p; | |
4326 | bpstat q; | |
4327 | ||
4328 | if (bsp == 0) | |
4329 | return; | |
4330 | p = *bsp; | |
4331 | while (p != NULL) | |
4332 | { | |
4333 | q = p->next; | |
04afa70c | 4334 | delete p; |
c906108c SS |
4335 | p = q; |
4336 | } | |
4337 | *bsp = NULL; | |
4338 | } | |
4339 | ||
04afa70c TT |
4340 | bpstats::bpstats (const bpstats &other) |
4341 | : next (NULL), | |
4342 | bp_location_at (other.bp_location_at), | |
4343 | breakpoint_at (other.breakpoint_at), | |
4344 | commands (other.commands), | |
4345 | old_val (other.old_val), | |
4346 | print (other.print), | |
4347 | stop (other.stop), | |
4348 | print_it (other.print_it) | |
4349 | { | |
4350 | if (old_val != NULL) | |
4351 | { | |
4352 | old_val = value_copy (old_val); | |
4353 | release_value (old_val); | |
4354 | } | |
4355 | incref_bp_location (bp_location_at); | |
04afa70c TT |
4356 | } |
4357 | ||
c906108c SS |
4358 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4359 | is part of the bpstat is copied as well. */ | |
4360 | ||
4361 | bpstat | |
fba45db2 | 4362 | bpstat_copy (bpstat bs) |
c906108c SS |
4363 | { |
4364 | bpstat p = NULL; | |
4365 | bpstat tmp; | |
4366 | bpstat retval = NULL; | |
4367 | ||
4368 | if (bs == NULL) | |
4369 | return bs; | |
4370 | ||
4371 | for (; bs != NULL; bs = bs->next) | |
4372 | { | |
04afa70c | 4373 | tmp = new bpstats (*bs); |
31cc81e9 | 4374 | |
c906108c SS |
4375 | if (p == NULL) |
4376 | /* This is the first thing in the chain. */ | |
4377 | retval = tmp; | |
4378 | else | |
4379 | p->next = tmp; | |
4380 | p = tmp; | |
4381 | } | |
4382 | p->next = NULL; | |
4383 | return retval; | |
4384 | } | |
4385 | ||
4a64f543 | 4386 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4387 | |
4388 | bpstat | |
fba45db2 | 4389 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4390 | { |
c5aa993b JM |
4391 | if (bsp == NULL) |
4392 | return NULL; | |
c906108c | 4393 | |
c5aa993b JM |
4394 | for (; bsp != NULL; bsp = bsp->next) |
4395 | { | |
f431efe5 | 4396 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4397 | return bsp; |
4398 | } | |
c906108c SS |
4399 | return NULL; |
4400 | } | |
4401 | ||
ab04a2af TT |
4402 | /* See breakpoint.h. */ |
4403 | ||
47591c29 | 4404 | int |
427cd150 | 4405 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4406 | { |
ab04a2af TT |
4407 | for (; bsp != NULL; bsp = bsp->next) |
4408 | { | |
427cd150 TT |
4409 | if (bsp->breakpoint_at == NULL) |
4410 | { | |
4411 | /* A moribund location can never explain a signal other than | |
4412 | GDB_SIGNAL_TRAP. */ | |
4413 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4414 | return 1; |
427cd150 TT |
4415 | } |
4416 | else | |
47591c29 PA |
4417 | { |
4418 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4419 | sig)) | |
4420 | return 1; | |
4421 | } | |
ab04a2af TT |
4422 | } |
4423 | ||
47591c29 | 4424 | return 0; |
ab04a2af TT |
4425 | } |
4426 | ||
4a64f543 MS |
4427 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4428 | stopped at. *BSP upon return is a bpstat which points to the | |
4429 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4430 | good for anything but further calls to bpstat_num). | |
4431 | ||
8671a17b PA |
4432 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4433 | Return -1 if stopped at a breakpoint that has been deleted since | |
4434 | we set it. | |
4435 | Return 1 otherwise. */ | |
c906108c SS |
4436 | |
4437 | int | |
8671a17b | 4438 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4439 | { |
4440 | struct breakpoint *b; | |
4441 | ||
4442 | if ((*bsp) == NULL) | |
4443 | return 0; /* No more breakpoint values */ | |
8671a17b | 4444 | |
4a64f543 MS |
4445 | /* We assume we'll never have several bpstats that correspond to a |
4446 | single breakpoint -- otherwise, this function might return the | |
4447 | same number more than once and this will look ugly. */ | |
f431efe5 | 4448 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4449 | *bsp = (*bsp)->next; |
4450 | if (b == NULL) | |
4451 | return -1; /* breakpoint that's been deleted since */ | |
4452 | ||
4453 | *num = b->number; /* We have its number */ | |
4454 | return 1; | |
c906108c SS |
4455 | } |
4456 | ||
e93ca019 | 4457 | /* See breakpoint.h. */ |
c906108c SS |
4458 | |
4459 | void | |
e93ca019 | 4460 | bpstat_clear_actions (void) |
c906108c | 4461 | { |
e93ca019 JK |
4462 | struct thread_info *tp; |
4463 | bpstat bs; | |
4464 | ||
4465 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4466 | return; | |
4467 | ||
4468 | tp = find_thread_ptid (inferior_ptid); | |
4469 | if (tp == NULL) | |
4470 | return; | |
4471 | ||
4472 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4473 | { |
d1b0a7bf | 4474 | bs->commands = NULL; |
abf85f46 | 4475 | |
c906108c SS |
4476 | if (bs->old_val != NULL) |
4477 | { | |
4478 | value_free (bs->old_val); | |
4479 | bs->old_val = NULL; | |
4480 | } | |
4481 | } | |
4482 | } | |
4483 | ||
f3b1572e PA |
4484 | /* Called when a command is about to proceed the inferior. */ |
4485 | ||
4486 | static void | |
4487 | breakpoint_about_to_proceed (void) | |
4488 | { | |
4489 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4490 | { | |
4491 | struct thread_info *tp = inferior_thread (); | |
4492 | ||
4493 | /* Allow inferior function calls in breakpoint commands to not | |
4494 | interrupt the command list. When the call finishes | |
4495 | successfully, the inferior will be standing at the same | |
4496 | breakpoint as if nothing happened. */ | |
16c381f0 | 4497 | if (tp->control.in_infcall) |
f3b1572e PA |
4498 | return; |
4499 | } | |
4500 | ||
4501 | breakpoint_proceeded = 1; | |
4502 | } | |
4503 | ||
4a64f543 MS |
4504 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4505 | command. */ | |
c906108c | 4506 | static void |
4efb68b1 | 4507 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4508 | { |
4509 | executing_breakpoint_commands = 0; | |
4510 | } | |
4511 | ||
abf85f46 JK |
4512 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4513 | or its equivalent. */ | |
4514 | ||
4515 | static int | |
4516 | command_line_is_silent (struct command_line *cmd) | |
4517 | { | |
4f45d445 | 4518 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4519 | } |
4520 | ||
4a64f543 MS |
4521 | /* Execute all the commands associated with all the breakpoints at |
4522 | this location. Any of these commands could cause the process to | |
4523 | proceed beyond this point, etc. We look out for such changes by | |
4524 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4525 | |
347bddb7 PA |
4526 | Returns true if a breakpoint command resumed the inferior. In that |
4527 | case, it is the caller's responsibility to recall it again with the | |
4528 | bpstat of the current thread. */ | |
4529 | ||
4530 | static int | |
4531 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4532 | { |
4533 | bpstat bs; | |
4534 | struct cleanup *old_chain; | |
347bddb7 | 4535 | int again = 0; |
c906108c SS |
4536 | |
4537 | /* Avoid endless recursion if a `source' command is contained | |
4538 | in bs->commands. */ | |
4539 | if (executing_breakpoint_commands) | |
347bddb7 | 4540 | return 0; |
c906108c SS |
4541 | |
4542 | executing_breakpoint_commands = 1; | |
4543 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4544 | ||
1ac32117 | 4545 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4546 | |
4a64f543 | 4547 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4548 | bs = *bsp; |
4549 | ||
4550 | breakpoint_proceeded = 0; | |
4551 | for (; bs != NULL; bs = bs->next) | |
4552 | { | |
d1b0a7bf | 4553 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4554 | |
4555 | /* Take ownership of the BSP's command tree, if it has one. | |
4556 | ||
4557 | The command tree could legitimately contain commands like | |
4558 | 'step' and 'next', which call clear_proceed_status, which | |
4559 | frees stop_bpstat's command tree. To make sure this doesn't | |
4560 | free the tree we're executing out from under us, we need to | |
4561 | take ownership of the tree ourselves. Since a given bpstat's | |
4562 | commands are only executed once, we don't need to copy it; we | |
4563 | can clear the pointer in the bpstat, and make sure we free | |
4564 | the tree when we're done. */ | |
d1b0a7bf | 4565 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4566 | bs->commands = NULL; |
d1b0a7bf TT |
4567 | if (ccmd != NULL) |
4568 | cmd = ccmd.get (); | |
abf85f46 JK |
4569 | if (command_line_is_silent (cmd)) |
4570 | { | |
4571 | /* The action has been already done by bpstat_stop_status. */ | |
4572 | cmd = cmd->next; | |
4573 | } | |
6c50ab1c | 4574 | |
c906108c SS |
4575 | while (cmd != NULL) |
4576 | { | |
4577 | execute_control_command (cmd); | |
4578 | ||
4579 | if (breakpoint_proceeded) | |
4580 | break; | |
4581 | else | |
4582 | cmd = cmd->next; | |
4583 | } | |
6c50ab1c | 4584 | |
c906108c | 4585 | if (breakpoint_proceeded) |
32c1e744 | 4586 | { |
cb814510 | 4587 | if (current_ui->async) |
347bddb7 PA |
4588 | /* If we are in async mode, then the target might be still |
4589 | running, not stopped at any breakpoint, so nothing for | |
4590 | us to do here -- just return to the event loop. */ | |
4591 | ; | |
32c1e744 VP |
4592 | else |
4593 | /* In sync mode, when execute_control_command returns | |
4594 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4595 | Breakpoint commands for that stop were not run, since |
4596 | execute_command does not run breakpoint commands -- | |
4597 | only command_line_handler does, but that one is not | |
4598 | involved in execution of breakpoint commands. So, we | |
4599 | can now execute breakpoint commands. It should be | |
4600 | noted that making execute_command do bpstat actions is | |
4601 | not an option -- in this case we'll have recursive | |
4602 | invocation of bpstat for each breakpoint with a | |
4603 | command, and can easily blow up GDB stack. Instead, we | |
4604 | return true, which will trigger the caller to recall us | |
4605 | with the new stop_bpstat. */ | |
4606 | again = 1; | |
4607 | break; | |
32c1e744 | 4608 | } |
c906108c | 4609 | } |
c2b8ed2c | 4610 | do_cleanups (old_chain); |
347bddb7 PA |
4611 | return again; |
4612 | } | |
4613 | ||
4614 | void | |
4615 | bpstat_do_actions (void) | |
4616 | { | |
353d1d73 JK |
4617 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4618 | ||
347bddb7 PA |
4619 | /* Do any commands attached to breakpoint we are stopped at. */ |
4620 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4621 | && target_has_execution | |
4622 | && !is_exited (inferior_ptid) | |
4623 | && !is_executing (inferior_ptid)) | |
4624 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4625 | and only return when it is stopped at the next breakpoint, we | |
4626 | keep doing breakpoint actions until it returns false to | |
4627 | indicate the inferior was not resumed. */ | |
16c381f0 | 4628 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4629 | break; |
353d1d73 JK |
4630 | |
4631 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4632 | } |
4633 | ||
fa4727a6 DJ |
4634 | /* Print out the (old or new) value associated with a watchpoint. */ |
4635 | ||
4636 | static void | |
4637 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4638 | { | |
4639 | if (val == NULL) | |
4640 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4641 | else | |
79a45b7d TT |
4642 | { |
4643 | struct value_print_options opts; | |
4644 | get_user_print_options (&opts); | |
4645 | value_print (val, stream, &opts); | |
4646 | } | |
fa4727a6 DJ |
4647 | } |
4648 | ||
f303dbd6 PA |
4649 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4650 | debugging multiple threads. */ | |
4651 | ||
4652 | void | |
4653 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4654 | { | |
112e8700 | 4655 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4656 | return; |
4657 | ||
112e8700 | 4658 | uiout->text ("\n"); |
f303dbd6 PA |
4659 | |
4660 | if (show_thread_that_caused_stop ()) | |
4661 | { | |
4662 | const char *name; | |
4663 | struct thread_info *thr = inferior_thread (); | |
4664 | ||
112e8700 SM |
4665 | uiout->text ("Thread "); |
4666 | uiout->field_fmt ("thread-id", "%s", print_thread_id (thr)); | |
f303dbd6 PA |
4667 | |
4668 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4669 | if (name != NULL) | |
4670 | { | |
112e8700 SM |
4671 | uiout->text (" \""); |
4672 | uiout->field_fmt ("name", "%s", name); | |
4673 | uiout->text ("\""); | |
f303dbd6 PA |
4674 | } |
4675 | ||
112e8700 | 4676 | uiout->text (" hit "); |
f303dbd6 PA |
4677 | } |
4678 | } | |
4679 | ||
e514a9d6 | 4680 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4681 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4682 | 'print_it' in the bpstat structure. Under some circumstances we |
4683 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4684 | normal_stop(). */ |
e514a9d6 JM |
4685 | |
4686 | static enum print_stop_action | |
4687 | print_bp_stop_message (bpstat bs) | |
4688 | { | |
4689 | switch (bs->print_it) | |
4690 | { | |
4691 | case print_it_noop: | |
4a64f543 | 4692 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4693 | return PRINT_UNKNOWN; |
4694 | break; | |
4695 | ||
4696 | case print_it_done: | |
4697 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4698 | relevant messages. */ |
e514a9d6 JM |
4699 | return PRINT_SRC_AND_LOC; |
4700 | break; | |
4701 | ||
4702 | case print_it_normal: | |
4f8d1dc6 | 4703 | { |
f431efe5 PA |
4704 | struct breakpoint *b = bs->breakpoint_at; |
4705 | ||
1a6a67de TJB |
4706 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4707 | which has since been deleted. */ | |
4708 | if (b == NULL) | |
4709 | return PRINT_UNKNOWN; | |
4710 | ||
348d480f PA |
4711 | /* Normal case. Call the breakpoint's print_it method. */ |
4712 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4713 | } |
348d480f | 4714 | break; |
3086aeae | 4715 | |
e514a9d6 | 4716 | default: |
8e65ff28 | 4717 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4718 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4719 | break; |
c906108c | 4720 | } |
c906108c SS |
4721 | } |
4722 | ||
edcc5120 TT |
4723 | /* A helper function that prints a shared library stopped event. */ |
4724 | ||
4725 | static void | |
4726 | print_solib_event (int is_catchpoint) | |
4727 | { | |
4728 | int any_deleted | |
4729 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4730 | int any_added | |
4731 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4732 | ||
4733 | if (!is_catchpoint) | |
4734 | { | |
4735 | if (any_added || any_deleted) | |
112e8700 | 4736 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4737 | else |
112e8700 SM |
4738 | current_uiout->text (_("Stopped due to shared library event (no " |
4739 | "libraries added or removed)\n")); | |
edcc5120 TT |
4740 | } |
4741 | ||
112e8700 SM |
4742 | if (current_uiout->is_mi_like_p ()) |
4743 | current_uiout->field_string ("reason", | |
4744 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4745 | |
4746 | if (any_deleted) | |
4747 | { | |
edcc5120 TT |
4748 | char *name; |
4749 | int ix; | |
4750 | ||
112e8700 | 4751 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4752 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
edcc5120 TT |
4753 | for (ix = 0; |
4754 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4755 | ix, name); | |
4756 | ++ix) | |
4757 | { | |
4758 | if (ix > 0) | |
112e8700 SM |
4759 | current_uiout->text (" "); |
4760 | current_uiout->field_string ("library", name); | |
4761 | current_uiout->text ("\n"); | |
edcc5120 | 4762 | } |
edcc5120 TT |
4763 | } |
4764 | ||
4765 | if (any_added) | |
4766 | { | |
4767 | struct so_list *iter; | |
4768 | int ix; | |
edcc5120 | 4769 | |
112e8700 | 4770 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4771 | ui_out_emit_list list_emitter (current_uiout, "added"); |
edcc5120 TT |
4772 | for (ix = 0; |
4773 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4774 | ix, iter); | |
4775 | ++ix) | |
4776 | { | |
4777 | if (ix > 0) | |
112e8700 SM |
4778 | current_uiout->text (" "); |
4779 | current_uiout->field_string ("library", iter->so_name); | |
4780 | current_uiout->text ("\n"); | |
edcc5120 | 4781 | } |
edcc5120 TT |
4782 | } |
4783 | } | |
4784 | ||
e514a9d6 JM |
4785 | /* Print a message indicating what happened. This is called from |
4786 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4787 | list - a list of the eventpoints that caused this stop. KIND is |
4788 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4789 | routine calls the generic print routine for printing a message |
4790 | about reasons for stopping. This will print (for example) the | |
4791 | "Breakpoint n," part of the output. The return value of this | |
4792 | routine is one of: | |
c906108c | 4793 | |
4a64f543 | 4794 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4795 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4796 | code to print the location. An example is |
c5aa993b JM |
4797 | "Breakpoint 1, " which should be followed by |
4798 | the location. | |
917317f4 | 4799 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4800 | to also print the location part of the message. |
4801 | An example is the catch/throw messages, which | |
4a64f543 | 4802 | don't require a location appended to the end. |
917317f4 | 4803 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4804 | further info to be printed. */ |
c906108c | 4805 | |
917317f4 | 4806 | enum print_stop_action |
36dfb11c | 4807 | bpstat_print (bpstat bs, int kind) |
c906108c | 4808 | { |
f486487f | 4809 | enum print_stop_action val; |
c5aa993b | 4810 | |
c906108c | 4811 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4812 | (Currently all watchpoints go on the bpstat whether hit or not. |
4813 | That probably could (should) be changed, provided care is taken | |
c906108c | 4814 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4815 | for (; bs; bs = bs->next) |
4816 | { | |
4817 | val = print_bp_stop_message (bs); | |
4818 | if (val == PRINT_SRC_ONLY | |
4819 | || val == PRINT_SRC_AND_LOC | |
4820 | || val == PRINT_NOTHING) | |
4821 | return val; | |
4822 | } | |
c906108c | 4823 | |
36dfb11c TT |
4824 | /* If we had hit a shared library event breakpoint, |
4825 | print_bp_stop_message would print out this message. If we hit an | |
4826 | OS-level shared library event, do the same thing. */ | |
4827 | if (kind == TARGET_WAITKIND_LOADED) | |
4828 | { | |
edcc5120 | 4829 | print_solib_event (0); |
36dfb11c TT |
4830 | return PRINT_NOTHING; |
4831 | } | |
4832 | ||
e514a9d6 | 4833 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4834 | with and nothing was printed. */ |
917317f4 | 4835 | return PRINT_UNKNOWN; |
c906108c SS |
4836 | } |
4837 | ||
bf469271 | 4838 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4839 | |
bf469271 PA |
4840 | static bool |
4841 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4842 | { |
278cd55f | 4843 | struct value *mark = value_mark (); |
bf469271 | 4844 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4845 | |
c906108c | 4846 | value_free_to_mark (mark); |
bf469271 | 4847 | return res; |
c906108c SS |
4848 | } |
4849 | ||
5760d0ab | 4850 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4851 | |
04afa70c TT |
4852 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4853 | : next (NULL), | |
4854 | bp_location_at (bl), | |
4855 | breakpoint_at (bl->owner), | |
4856 | commands (NULL), | |
4857 | old_val (NULL), | |
4858 | print (0), | |
4859 | stop (0), | |
4860 | print_it (print_it_normal) | |
c906108c | 4861 | { |
f431efe5 | 4862 | incref_bp_location (bl); |
04afa70c TT |
4863 | **bs_link_pointer = this; |
4864 | *bs_link_pointer = &next; | |
4865 | } | |
4866 | ||
4867 | bpstats::bpstats () | |
4868 | : next (NULL), | |
4869 | bp_location_at (NULL), | |
4870 | breakpoint_at (NULL), | |
4871 | commands (NULL), | |
4872 | old_val (NULL), | |
4873 | print (0), | |
4874 | stop (0), | |
4875 | print_it (print_it_normal) | |
4876 | { | |
c906108c SS |
4877 | } |
4878 | \f | |
d983da9c DJ |
4879 | /* The target has stopped with waitstatus WS. Check if any hardware |
4880 | watchpoints have triggered, according to the target. */ | |
4881 | ||
4882 | int | |
4883 | watchpoints_triggered (struct target_waitstatus *ws) | |
4884 | { | |
d92524f1 | 4885 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4886 | CORE_ADDR addr; |
4887 | struct breakpoint *b; | |
4888 | ||
4889 | if (!stopped_by_watchpoint) | |
4890 | { | |
4891 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4892 | as not triggered. */ | |
4893 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4894 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4895 | { |
4896 | struct watchpoint *w = (struct watchpoint *) b; | |
4897 | ||
4898 | w->watchpoint_triggered = watch_triggered_no; | |
4899 | } | |
d983da9c DJ |
4900 | |
4901 | return 0; | |
4902 | } | |
4903 | ||
4904 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4905 | { | |
4906 | /* We were stopped by a watchpoint, but we don't know where. | |
4907 | Mark all watchpoints as unknown. */ | |
4908 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4909 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4910 | { |
4911 | struct watchpoint *w = (struct watchpoint *) b; | |
4912 | ||
4913 | w->watchpoint_triggered = watch_triggered_unknown; | |
4914 | } | |
d983da9c | 4915 | |
3c4797ba | 4916 | return 1; |
d983da9c DJ |
4917 | } |
4918 | ||
4919 | /* The target could report the data address. Mark watchpoints | |
4920 | affected by this data address as triggered, and all others as not | |
4921 | triggered. */ | |
4922 | ||
4923 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4924 | if (is_hardware_watchpoint (b)) |
d983da9c | 4925 | { |
3a5c3e22 | 4926 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4927 | struct bp_location *loc; |
d983da9c | 4928 | |
3a5c3e22 | 4929 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4930 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4931 | { |
3a5c3e22 | 4932 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4933 | { |
3a5c3e22 PA |
4934 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4935 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4936 | |
4937 | if (newaddr == start) | |
4938 | { | |
3a5c3e22 | 4939 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4940 | break; |
4941 | } | |
4942 | } | |
4943 | /* Exact match not required. Within range is sufficient. */ | |
4944 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4945 | addr, loc->address, | |
4946 | loc->length)) | |
4947 | { | |
3a5c3e22 | 4948 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4949 | break; |
4950 | } | |
4951 | } | |
d983da9c DJ |
4952 | } |
4953 | ||
4954 | return 1; | |
4955 | } | |
4956 | ||
bf469271 PA |
4957 | /* Possible return values for watchpoint_check. */ |
4958 | enum wp_check_result | |
4959 | { | |
4960 | /* The watchpoint has been deleted. */ | |
4961 | WP_DELETED = 1, | |
4962 | ||
4963 | /* The value has changed. */ | |
4964 | WP_VALUE_CHANGED = 2, | |
4965 | ||
4966 | /* The value has not changed. */ | |
4967 | WP_VALUE_NOT_CHANGED = 3, | |
4968 | ||
4969 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4970 | WP_IGNORE = 4, | |
4971 | }; | |
c906108c SS |
4972 | |
4973 | #define BP_TEMPFLAG 1 | |
4974 | #define BP_HARDWAREFLAG 2 | |
4975 | ||
4a64f543 | 4976 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4977 | changed. */ |
553e4c11 | 4978 | |
bf469271 PA |
4979 | static wp_check_result |
4980 | watchpoint_check (bpstat bs) | |
c906108c | 4981 | { |
3a5c3e22 | 4982 | struct watchpoint *b; |
c906108c SS |
4983 | struct frame_info *fr; |
4984 | int within_current_scope; | |
4985 | ||
f431efe5 | 4986 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4987 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4988 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4989 | |
f6bc2008 PA |
4990 | /* If this is a local watchpoint, we only want to check if the |
4991 | watchpoint frame is in scope if the current thread is the thread | |
4992 | that was used to create the watchpoint. */ | |
4993 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4994 | return WP_IGNORE; |
f6bc2008 | 4995 | |
c906108c SS |
4996 | if (b->exp_valid_block == NULL) |
4997 | within_current_scope = 1; | |
4998 | else | |
4999 | { | |
edb3359d DJ |
5000 | struct frame_info *frame = get_current_frame (); |
5001 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5002 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5003 | ||
c9cf6e20 | 5004 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5005 | still in the function but the stack frame has already been |
5006 | invalidated. Since we can't rely on the values of local | |
5007 | variables after the stack has been destroyed, we are treating | |
5008 | the watchpoint in that state as `not changed' without further | |
5009 | checking. Don't mark watchpoints as changed if the current | |
5010 | frame is in an epilogue - even if they are in some other | |
5011 | frame, our view of the stack is likely to be wrong and | |
5012 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5013 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5014 | return WP_IGNORE; |
a0f49112 | 5015 | |
101dcfbe | 5016 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5017 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5018 | |
5019 | /* If we've gotten confused in the unwinder, we might have | |
5020 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5021 | if (within_current_scope) |
5022 | { | |
5023 | struct symbol *function; | |
5024 | ||
5025 | function = get_frame_function (fr); | |
5026 | if (function == NULL | |
5027 | || !contained_in (b->exp_valid_block, | |
5028 | SYMBOL_BLOCK_VALUE (function))) | |
5029 | within_current_scope = 0; | |
5030 | } | |
69fbadd5 | 5031 | |
edb3359d | 5032 | if (within_current_scope) |
c906108c SS |
5033 | /* If we end up stopping, the current frame will get selected |
5034 | in normal_stop. So this call to select_frame won't affect | |
5035 | the user. */ | |
0f7d239c | 5036 | select_frame (fr); |
c906108c | 5037 | } |
c5aa993b | 5038 | |
c906108c SS |
5039 | if (within_current_scope) |
5040 | { | |
4a64f543 MS |
5041 | /* We use value_{,free_to_}mark because it could be a *long* |
5042 | time before we return to the command level and call | |
5043 | free_all_values. We can't call free_all_values because we | |
5044 | might be in the middle of evaluating a function call. */ | |
c906108c | 5045 | |
0cf6dd15 | 5046 | int pc = 0; |
9c06b0b4 | 5047 | struct value *mark; |
fa4727a6 DJ |
5048 | struct value *new_val; |
5049 | ||
c1fc2657 | 5050 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
5051 | /* Since we don't know the exact trigger address (from |
5052 | stopped_data_address), just tell the user we've triggered | |
5053 | a mask watchpoint. */ | |
5054 | return WP_VALUE_CHANGED; | |
5055 | ||
5056 | mark = value_mark (); | |
4d01a485 | 5057 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5058 | |
bb9d5f81 PP |
5059 | if (b->val_bitsize != 0) |
5060 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5061 | ||
4a64f543 MS |
5062 | /* We use value_equal_contents instead of value_equal because |
5063 | the latter coerces an array to a pointer, thus comparing just | |
5064 | the address of the array instead of its contents. This is | |
5065 | not what we want. */ | |
fa4727a6 | 5066 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5067 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5068 | { |
fa4727a6 DJ |
5069 | if (new_val != NULL) |
5070 | { | |
5071 | release_value (new_val); | |
5072 | value_free_to_mark (mark); | |
5073 | } | |
c906108c SS |
5074 | bs->old_val = b->val; |
5075 | b->val = new_val; | |
fa4727a6 | 5076 | b->val_valid = 1; |
c906108c SS |
5077 | return WP_VALUE_CHANGED; |
5078 | } | |
5079 | else | |
5080 | { | |
60e1c644 | 5081 | /* Nothing changed. */ |
c906108c | 5082 | value_free_to_mark (mark); |
c906108c SS |
5083 | return WP_VALUE_NOT_CHANGED; |
5084 | } | |
5085 | } | |
5086 | else | |
5087 | { | |
5088 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5089 | if we temporarily ignored the watchpoint, then when |
5090 | we reenter the block in which it is valid it contains | |
5091 | garbage (in the case of a function, it may have two | |
5092 | garbage values, one before and one after the prologue). | |
5093 | So we can't even detect the first assignment to it and | |
5094 | watch after that (since the garbage may or may not equal | |
5095 | the first value assigned). */ | |
348d480f PA |
5096 | /* We print all the stop information in |
5097 | breakpoint_ops->print_it, but in this case, by the time we | |
5098 | call breakpoint_ops->print_it this bp will be deleted | |
5099 | already. So we have no choice but print the information | |
5100 | here. */ | |
468afe6c | 5101 | |
0e454242 | 5102 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5103 | { |
5104 | struct ui_out *uiout = current_uiout; | |
5105 | ||
112e8700 SM |
5106 | if (uiout->is_mi_like_p ()) |
5107 | uiout->field_string | |
5108 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5109 | uiout->text ("\nWatchpoint "); | |
c1fc2657 | 5110 | uiout->field_int ("wpnum", b->number); |
112e8700 | 5111 | uiout->text (" deleted because the program has left the block in\n" |
468afe6c PA |
5112 | "which its expression is valid.\n"); |
5113 | } | |
4ce44c66 | 5114 | |
cdac0397 | 5115 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 5116 | b->commands = NULL; |
d0fb5eae | 5117 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5118 | |
5119 | return WP_DELETED; | |
5120 | } | |
5121 | } | |
5122 | ||
18a18393 | 5123 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5124 | breakpoint location BL. This function does not check if we should |
5125 | stop, only if BL explains the stop. */ | |
5126 | ||
18a18393 | 5127 | static int |
6c95b8df | 5128 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5129 | struct address_space *aspace, CORE_ADDR bp_addr, |
5130 | const struct target_waitstatus *ws) | |
18a18393 VP |
5131 | { |
5132 | struct breakpoint *b = bl->owner; | |
5133 | ||
348d480f | 5134 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5135 | gdb_assert (b != NULL); |
5136 | ||
09ac7c10 | 5137 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5138 | } |
5139 | ||
3a5c3e22 PA |
5140 | /* Determine if the watched values have actually changed, and we |
5141 | should stop. If not, set BS->stop to 0. */ | |
5142 | ||
18a18393 VP |
5143 | static void |
5144 | bpstat_check_watchpoint (bpstat bs) | |
5145 | { | |
2bdf28a0 | 5146 | const struct bp_location *bl; |
3a5c3e22 | 5147 | struct watchpoint *b; |
2bdf28a0 JK |
5148 | |
5149 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5150 | bl = bs->bp_location_at; |
2bdf28a0 | 5151 | gdb_assert (bl != NULL); |
3a5c3e22 | 5152 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5153 | gdb_assert (b != NULL); |
18a18393 | 5154 | |
18a18393 | 5155 | { |
18a18393 VP |
5156 | int must_check_value = 0; |
5157 | ||
c1fc2657 | 5158 | if (b->type == bp_watchpoint) |
18a18393 VP |
5159 | /* For a software watchpoint, we must always check the |
5160 | watched value. */ | |
5161 | must_check_value = 1; | |
5162 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5163 | /* We have a hardware watchpoint (read, write, or access) | |
5164 | and the target earlier reported an address watched by | |
5165 | this watchpoint. */ | |
5166 | must_check_value = 1; | |
5167 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5168 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5169 | /* We were stopped by a hardware watchpoint, but the target could |
5170 | not report the data address. We must check the watchpoint's | |
5171 | value. Access and read watchpoints are out of luck; without | |
5172 | a data address, we can't figure it out. */ | |
5173 | must_check_value = 1; | |
3a5c3e22 | 5174 | |
18a18393 VP |
5175 | if (must_check_value) |
5176 | { | |
bf469271 PA |
5177 | wp_check_result e; |
5178 | ||
5179 | TRY | |
5180 | { | |
5181 | e = watchpoint_check (bs); | |
5182 | } | |
5183 | CATCH (ex, RETURN_MASK_ALL) | |
5184 | { | |
5185 | exception_fprintf (gdb_stderr, ex, | |
5186 | "Error evaluating expression " | |
5187 | "for watchpoint %d\n", | |
5188 | b->number); | |
5189 | ||
5190 | SWITCH_THRU_ALL_UIS () | |
5191 | { | |
5192 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5193 | b->number); | |
5194 | } | |
5195 | watchpoint_del_at_next_stop (b); | |
5196 | e = WP_DELETED; | |
5197 | } | |
5198 | END_CATCH | |
5199 | ||
18a18393 VP |
5200 | switch (e) |
5201 | { | |
5202 | case WP_DELETED: | |
5203 | /* We've already printed what needs to be printed. */ | |
5204 | bs->print_it = print_it_done; | |
5205 | /* Stop. */ | |
5206 | break; | |
60e1c644 PA |
5207 | case WP_IGNORE: |
5208 | bs->print_it = print_it_noop; | |
5209 | bs->stop = 0; | |
5210 | break; | |
18a18393 | 5211 | case WP_VALUE_CHANGED: |
c1fc2657 | 5212 | if (b->type == bp_read_watchpoint) |
18a18393 | 5213 | { |
85d721b8 PA |
5214 | /* There are two cases to consider here: |
5215 | ||
4a64f543 | 5216 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5217 | In that case, trust the target, and always report |
5218 | the watchpoint hit to the user. Even though | |
5219 | reads don't cause value changes, the value may | |
5220 | have changed since the last time it was read, and | |
5221 | since we're not trapping writes, we will not see | |
5222 | those, and as such we should ignore our notion of | |
5223 | old value. | |
5224 | ||
4a64f543 | 5225 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5226 | reads and writes. There are two ways this may |
5227 | happen: | |
5228 | ||
4a64f543 | 5229 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5230 | reads only, but can break on accesses (reads or |
5231 | writes), such as e.g., x86. We detect this case | |
5232 | at the time we try to insert read watchpoints. | |
5233 | ||
4a64f543 | 5234 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5235 | watchpoints, but, the user set an access or write |
5236 | watchpoint watching the same memory as this read | |
5237 | watchpoint. | |
5238 | ||
5239 | If we're watching memory writes as well as reads, | |
5240 | ignore watchpoint hits when we find that the | |
5241 | value hasn't changed, as reads don't cause | |
5242 | changes. This still gives false positives when | |
5243 | the program writes the same value to memory as | |
5244 | what there was already in memory (we will confuse | |
5245 | it for a read), but it's much better than | |
5246 | nothing. */ | |
5247 | ||
5248 | int other_write_watchpoint = 0; | |
5249 | ||
5250 | if (bl->watchpoint_type == hw_read) | |
5251 | { | |
5252 | struct breakpoint *other_b; | |
5253 | ||
5254 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5255 | if (other_b->type == bp_hardware_watchpoint |
5256 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5257 | { |
3a5c3e22 PA |
5258 | struct watchpoint *other_w = |
5259 | (struct watchpoint *) other_b; | |
5260 | ||
5261 | if (other_w->watchpoint_triggered | |
5262 | == watch_triggered_yes) | |
5263 | { | |
5264 | other_write_watchpoint = 1; | |
5265 | break; | |
5266 | } | |
85d721b8 PA |
5267 | } |
5268 | } | |
5269 | ||
5270 | if (other_write_watchpoint | |
5271 | || bl->watchpoint_type == hw_access) | |
5272 | { | |
5273 | /* We're watching the same memory for writes, | |
5274 | and the value changed since the last time we | |
5275 | updated it, so this trap must be for a write. | |
5276 | Ignore it. */ | |
5277 | bs->print_it = print_it_noop; | |
5278 | bs->stop = 0; | |
5279 | } | |
18a18393 VP |
5280 | } |
5281 | break; | |
5282 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5283 | if (b->type == bp_hardware_watchpoint |
5284 | || b->type == bp_watchpoint) | |
18a18393 VP |
5285 | { |
5286 | /* Don't stop: write watchpoints shouldn't fire if | |
5287 | the value hasn't changed. */ | |
5288 | bs->print_it = print_it_noop; | |
5289 | bs->stop = 0; | |
5290 | } | |
5291 | /* Stop. */ | |
5292 | break; | |
5293 | default: | |
5294 | /* Can't happen. */ | |
18a18393 VP |
5295 | break; |
5296 | } | |
5297 | } | |
5298 | else /* must_check_value == 0 */ | |
5299 | { | |
5300 | /* This is a case where some watchpoint(s) triggered, but | |
5301 | not at the address of this watchpoint, or else no | |
5302 | watchpoint triggered after all. So don't print | |
5303 | anything for this watchpoint. */ | |
5304 | bs->print_it = print_it_noop; | |
5305 | bs->stop = 0; | |
5306 | } | |
5307 | } | |
5308 | } | |
5309 | ||
7d4df6a4 DE |
5310 | /* For breakpoints that are currently marked as telling gdb to stop, |
5311 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5312 | of breakpoint referred to by BS. If we should not stop for this |
5313 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5314 | |
18a18393 VP |
5315 | static void |
5316 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5317 | { | |
2bdf28a0 JK |
5318 | const struct bp_location *bl; |
5319 | struct breakpoint *b; | |
bf469271 PA |
5320 | /* Assume stop. */ |
5321 | bool condition_result = true; | |
7d4df6a4 DE |
5322 | struct expression *cond; |
5323 | ||
5324 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5325 | |
5326 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5327 | bl = bs->bp_location_at; |
2bdf28a0 | 5328 | gdb_assert (bl != NULL); |
f431efe5 | 5329 | b = bs->breakpoint_at; |
2bdf28a0 | 5330 | gdb_assert (b != NULL); |
18a18393 | 5331 | |
b775012e LM |
5332 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5333 | need to do so again since GDB does not know if we stopped due to a | |
5334 | breakpoint or a single step breakpoint. */ | |
5335 | ||
18a18393 | 5336 | if (frame_id_p (b->frame_id) |
edb3359d | 5337 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5338 | { |
7d4df6a4 DE |
5339 | bs->stop = 0; |
5340 | return; | |
5341 | } | |
60e1c644 | 5342 | |
12ab52e9 PA |
5343 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5344 | evaluating the condition if this isn't the specified | |
5345 | thread/task. */ | |
5d5658a1 | 5346 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5347 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5348 | ||
6c1b0f7b DE |
5349 | { |
5350 | bs->stop = 0; | |
5351 | return; | |
5352 | } | |
5353 | ||
6dddc817 DE |
5354 | /* Evaluate extension language breakpoints that have a "stop" method |
5355 | implemented. */ | |
5356 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5357 | |
7d4df6a4 DE |
5358 | if (is_watchpoint (b)) |
5359 | { | |
5360 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5361 | |
4d01a485 | 5362 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5363 | } |
5364 | else | |
4d01a485 | 5365 | cond = bl->cond.get (); |
60e1c644 | 5366 | |
7d4df6a4 DE |
5367 | if (cond && b->disposition != disp_del_at_next_stop) |
5368 | { | |
5369 | int within_current_scope = 1; | |
5370 | struct watchpoint * w; | |
60e1c644 | 5371 | |
7d4df6a4 DE |
5372 | /* We use value_mark and value_free_to_mark because it could |
5373 | be a long time before we return to the command level and | |
5374 | call free_all_values. We can't call free_all_values | |
5375 | because we might be in the middle of evaluating a | |
5376 | function call. */ | |
5377 | struct value *mark = value_mark (); | |
5378 | ||
5379 | if (is_watchpoint (b)) | |
5380 | w = (struct watchpoint *) b; | |
5381 | else | |
5382 | w = NULL; | |
5383 | ||
5384 | /* Need to select the frame, with all that implies so that | |
5385 | the conditions will have the right context. Because we | |
5386 | use the frame, we will not see an inlined function's | |
5387 | variables when we arrive at a breakpoint at the start | |
5388 | of the inlined function; the current frame will be the | |
5389 | call site. */ | |
5390 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5391 | select_frame (get_current_frame ()); | |
5392 | else | |
18a18393 | 5393 | { |
7d4df6a4 DE |
5394 | struct frame_info *frame; |
5395 | ||
5396 | /* For local watchpoint expressions, which particular | |
5397 | instance of a local is being watched matters, so we | |
5398 | keep track of the frame to evaluate the expression | |
5399 | in. To evaluate the condition however, it doesn't | |
5400 | really matter which instantiation of the function | |
5401 | where the condition makes sense triggers the | |
5402 | watchpoint. This allows an expression like "watch | |
5403 | global if q > 10" set in `func', catch writes to | |
5404 | global on all threads that call `func', or catch | |
5405 | writes on all recursive calls of `func' by a single | |
5406 | thread. We simply always evaluate the condition in | |
5407 | the innermost frame that's executing where it makes | |
5408 | sense to evaluate the condition. It seems | |
5409 | intuitive. */ | |
5410 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5411 | if (frame != NULL) | |
5412 | select_frame (frame); | |
5413 | else | |
5414 | within_current_scope = 0; | |
18a18393 | 5415 | } |
7d4df6a4 | 5416 | if (within_current_scope) |
bf469271 PA |
5417 | { |
5418 | TRY | |
5419 | { | |
5420 | condition_result = breakpoint_cond_eval (cond); | |
5421 | } | |
5422 | CATCH (ex, RETURN_MASK_ALL) | |
5423 | { | |
5424 | exception_fprintf (gdb_stderr, ex, | |
5425 | "Error in testing breakpoint condition:\n"); | |
5426 | } | |
5427 | END_CATCH | |
5428 | } | |
7d4df6a4 | 5429 | else |
18a18393 | 5430 | { |
7d4df6a4 DE |
5431 | warning (_("Watchpoint condition cannot be tested " |
5432 | "in the current scope")); | |
5433 | /* If we failed to set the right context for this | |
5434 | watchpoint, unconditionally report it. */ | |
18a18393 | 5435 | } |
7d4df6a4 DE |
5436 | /* FIXME-someday, should give breakpoint #. */ |
5437 | value_free_to_mark (mark); | |
18a18393 | 5438 | } |
7d4df6a4 | 5439 | |
bf469271 | 5440 | if (cond && !condition_result) |
7d4df6a4 DE |
5441 | { |
5442 | bs->stop = 0; | |
5443 | } | |
7d4df6a4 DE |
5444 | else if (b->ignore_count > 0) |
5445 | { | |
5446 | b->ignore_count--; | |
5447 | bs->stop = 0; | |
5448 | /* Increase the hit count even though we don't stop. */ | |
5449 | ++(b->hit_count); | |
5450 | observer_notify_breakpoint_modified (b); | |
5451 | } | |
18a18393 VP |
5452 | } |
5453 | ||
1cf4d951 PA |
5454 | /* Returns true if we need to track moribund locations of LOC's type |
5455 | on the current target. */ | |
5456 | ||
5457 | static int | |
5458 | need_moribund_for_location_type (struct bp_location *loc) | |
5459 | { | |
5460 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5461 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5462 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5463 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5464 | } | |
5465 | ||
18a18393 | 5466 | |
9709f61c | 5467 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5468 | BP_ADDR in thread PTID. |
c906108c | 5469 | |
d983da9c | 5470 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5471 | don't understand this stop. Result is a chain of bpstat's such |
5472 | that: | |
c906108c | 5473 | |
c5aa993b | 5474 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5475 | |
c5aa993b | 5476 | if we understand why we stopped, the result is not null. |
c906108c | 5477 | |
c5aa993b JM |
5478 | Each element of the chain refers to a particular breakpoint or |
5479 | watchpoint at which we have stopped. (We may have stopped for | |
5480 | several reasons concurrently.) | |
c906108c | 5481 | |
c5aa993b JM |
5482 | Each element of the chain has valid next, breakpoint_at, |
5483 | commands, FIXME??? fields. */ | |
c906108c SS |
5484 | |
5485 | bpstat | |
6c95b8df | 5486 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5487 | CORE_ADDR bp_addr, ptid_t ptid, |
5488 | const struct target_waitstatus *ws) | |
c906108c | 5489 | { |
0d381245 | 5490 | struct breakpoint *b = NULL; |
afe38095 | 5491 | struct bp_location *bl; |
20874c92 | 5492 | struct bp_location *loc; |
5760d0ab JK |
5493 | /* First item of allocated bpstat's. */ |
5494 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5495 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5496 | bpstat bs; |
20874c92 | 5497 | int ix; |
429374b8 | 5498 | int need_remove_insert; |
f431efe5 | 5499 | int removed_any; |
c906108c | 5500 | |
f431efe5 PA |
5501 | /* First, build the bpstat chain with locations that explain a |
5502 | target stop, while being careful to not set the target running, | |
5503 | as that may invalidate locations (in particular watchpoint | |
5504 | locations are recreated). Resuming will happen here with | |
5505 | breakpoint conditions or watchpoint expressions that include | |
5506 | inferior function calls. */ | |
c5aa993b | 5507 | |
429374b8 JK |
5508 | ALL_BREAKPOINTS (b) |
5509 | { | |
1a853c52 | 5510 | if (!breakpoint_enabled (b)) |
429374b8 | 5511 | continue; |
a5606eee | 5512 | |
429374b8 JK |
5513 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5514 | { | |
4a64f543 MS |
5515 | /* For hardware watchpoints, we look only at the first |
5516 | location. The watchpoint_check function will work on the | |
5517 | entire expression, not the individual locations. For | |
5518 | read watchpoints, the watchpoints_triggered function has | |
5519 | checked all locations already. */ | |
429374b8 JK |
5520 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5521 | break; | |
18a18393 | 5522 | |
f6592439 | 5523 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5524 | continue; |
c5aa993b | 5525 | |
09ac7c10 | 5526 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5527 | continue; |
c5aa993b | 5528 | |
4a64f543 MS |
5529 | /* Come here if it's a watchpoint, or if the break address |
5530 | matches. */ | |
c5aa993b | 5531 | |
04afa70c | 5532 | bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
4a64f543 | 5533 | explain stop. */ |
c5aa993b | 5534 | |
f431efe5 PA |
5535 | /* Assume we stop. Should we find a watchpoint that is not |
5536 | actually triggered, or if the condition of the breakpoint | |
5537 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5538 | bs->stop = 1; |
5539 | bs->print = 1; | |
d983da9c | 5540 | |
f431efe5 PA |
5541 | /* If this is a scope breakpoint, mark the associated |
5542 | watchpoint as triggered so that we will handle the | |
5543 | out-of-scope event. We'll get to the watchpoint next | |
5544 | iteration. */ | |
d0fb5eae | 5545 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5546 | { |
5547 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5548 | ||
5549 | w->watchpoint_triggered = watch_triggered_yes; | |
5550 | } | |
f431efe5 PA |
5551 | } |
5552 | } | |
5553 | ||
7c16b83e | 5554 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5555 | if (!target_supports_stopped_by_sw_breakpoint () |
5556 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5557 | { |
1cf4d951 | 5558 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5559 | { |
1cf4d951 PA |
5560 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5561 | && need_moribund_for_location_type (loc)) | |
5562 | { | |
04afa70c | 5563 | bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5564 | /* For hits of moribund locations, we should just proceed. */ |
5565 | bs->stop = 0; | |
5566 | bs->print = 0; | |
5567 | bs->print_it = print_it_noop; | |
5568 | } | |
f431efe5 PA |
5569 | } |
5570 | } | |
5571 | ||
edcc5120 TT |
5572 | /* A bit of special processing for shlib breakpoints. We need to |
5573 | process solib loading here, so that the lists of loaded and | |
5574 | unloaded libraries are correct before we handle "catch load" and | |
5575 | "catch unload". */ | |
5576 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5577 | { | |
5d268276 | 5578 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5579 | { |
5580 | handle_solib_event (); | |
5581 | break; | |
5582 | } | |
5583 | } | |
5584 | ||
f431efe5 PA |
5585 | /* Now go through the locations that caused the target to stop, and |
5586 | check whether we're interested in reporting this stop to higher | |
5587 | layers, or whether we should resume the target transparently. */ | |
5588 | ||
5589 | removed_any = 0; | |
5590 | ||
5760d0ab | 5591 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5592 | { |
5593 | if (!bs->stop) | |
5594 | continue; | |
5595 | ||
f431efe5 | 5596 | b = bs->breakpoint_at; |
348d480f PA |
5597 | b->ops->check_status (bs); |
5598 | if (bs->stop) | |
28010a5d | 5599 | { |
348d480f | 5600 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5601 | |
429374b8 JK |
5602 | if (bs->stop) |
5603 | { | |
5604 | ++(b->hit_count); | |
8d3788bd | 5605 | observer_notify_breakpoint_modified (b); |
c906108c | 5606 | |
4a64f543 | 5607 | /* We will stop here. */ |
429374b8 JK |
5608 | if (b->disposition == disp_disable) |
5609 | { | |
816338b5 | 5610 | --(b->enable_count); |
1a853c52 | 5611 | if (b->enable_count <= 0) |
429374b8 | 5612 | b->enable_state = bp_disabled; |
f431efe5 | 5613 | removed_any = 1; |
429374b8 JK |
5614 | } |
5615 | if (b->silent) | |
5616 | bs->print = 0; | |
5617 | bs->commands = b->commands; | |
abf85f46 | 5618 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5619 | ? bs->commands.get () : NULL)) |
abf85f46 | 5620 | bs->print = 0; |
9d6e6e84 HZ |
5621 | |
5622 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5623 | } |
5624 | ||
348d480f | 5625 | } |
a9b3a50f PA |
5626 | |
5627 | /* Print nothing for this entry if we don't stop or don't | |
5628 | print. */ | |
5629 | if (!bs->stop || !bs->print) | |
5630 | bs->print_it = print_it_noop; | |
429374b8 | 5631 | } |
876fa593 | 5632 | |
d983da9c DJ |
5633 | /* If we aren't stopping, the value of some hardware watchpoint may |
5634 | not have changed, but the intermediate memory locations we are | |
5635 | watching may have. Don't bother if we're stopping; this will get | |
5636 | done later. */ | |
d832cb68 | 5637 | need_remove_insert = 0; |
5760d0ab JK |
5638 | if (! bpstat_causes_stop (bs_head)) |
5639 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5640 | if (!bs->stop |
f431efe5 PA |
5641 | && bs->breakpoint_at |
5642 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5643 | { |
3a5c3e22 PA |
5644 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5645 | ||
5646 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5647 | need_remove_insert = 1; |
d983da9c DJ |
5648 | } |
5649 | ||
d832cb68 | 5650 | if (need_remove_insert) |
44702360 | 5651 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5652 | else if (removed_any) |
44702360 | 5653 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5654 | |
5760d0ab | 5655 | return bs_head; |
c906108c | 5656 | } |
628fe4e4 JK |
5657 | |
5658 | static void | |
5659 | handle_jit_event (void) | |
5660 | { | |
5661 | struct frame_info *frame; | |
5662 | struct gdbarch *gdbarch; | |
5663 | ||
243a9253 PA |
5664 | if (debug_infrun) |
5665 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5666 | ||
628fe4e4 JK |
5667 | /* Switch terminal for any messages produced by |
5668 | breakpoint_re_set. */ | |
223ffa71 | 5669 | target_terminal::ours_for_output (); |
628fe4e4 JK |
5670 | |
5671 | frame = get_current_frame (); | |
5672 | gdbarch = get_frame_arch (frame); | |
5673 | ||
5674 | jit_event_handler (gdbarch); | |
5675 | ||
223ffa71 | 5676 | target_terminal::inferior (); |
628fe4e4 JK |
5677 | } |
5678 | ||
5679 | /* Prepare WHAT final decision for infrun. */ | |
5680 | ||
5681 | /* Decide what infrun needs to do with this bpstat. */ | |
5682 | ||
c906108c | 5683 | struct bpstat_what |
0e30163f | 5684 | bpstat_what (bpstat bs_head) |
c906108c | 5685 | { |
c906108c | 5686 | struct bpstat_what retval; |
0e30163f | 5687 | bpstat bs; |
c906108c | 5688 | |
628fe4e4 | 5689 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5690 | retval.call_dummy = STOP_NONE; |
186c406b | 5691 | retval.is_longjmp = 0; |
628fe4e4 | 5692 | |
0e30163f | 5693 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5694 | { |
628fe4e4 JK |
5695 | /* Extract this BS's action. After processing each BS, we check |
5696 | if its action overrides all we've seem so far. */ | |
5697 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5698 | enum bptype bptype; | |
5699 | ||
c906108c | 5700 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5701 | { |
5702 | /* I suspect this can happen if it was a momentary | |
5703 | breakpoint which has since been deleted. */ | |
5704 | bptype = bp_none; | |
5705 | } | |
20874c92 | 5706 | else |
f431efe5 | 5707 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5708 | |
5709 | switch (bptype) | |
c906108c SS |
5710 | { |
5711 | case bp_none: | |
628fe4e4 | 5712 | break; |
c906108c SS |
5713 | case bp_breakpoint: |
5714 | case bp_hardware_breakpoint: | |
7c16b83e | 5715 | case bp_single_step: |
c906108c SS |
5716 | case bp_until: |
5717 | case bp_finish: | |
a9b3a50f | 5718 | case bp_shlib_event: |
c906108c SS |
5719 | if (bs->stop) |
5720 | { | |
5721 | if (bs->print) | |
628fe4e4 | 5722 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5723 | else |
628fe4e4 | 5724 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5725 | } |
5726 | else | |
628fe4e4 | 5727 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5728 | break; |
5729 | case bp_watchpoint: | |
5730 | case bp_hardware_watchpoint: | |
5731 | case bp_read_watchpoint: | |
5732 | case bp_access_watchpoint: | |
5733 | if (bs->stop) | |
5734 | { | |
5735 | if (bs->print) | |
628fe4e4 | 5736 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5737 | else |
628fe4e4 | 5738 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5739 | } |
5740 | else | |
628fe4e4 JK |
5741 | { |
5742 | /* There was a watchpoint, but we're not stopping. | |
5743 | This requires no further action. */ | |
5744 | } | |
c906108c SS |
5745 | break; |
5746 | case bp_longjmp: | |
e2e4d78b | 5747 | case bp_longjmp_call_dummy: |
186c406b | 5748 | case bp_exception: |
0a39bb32 PA |
5749 | if (bs->stop) |
5750 | { | |
5751 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5752 | retval.is_longjmp = bptype != bp_exception; | |
5753 | } | |
5754 | else | |
5755 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5756 | break; |
5757 | case bp_longjmp_resume: | |
186c406b | 5758 | case bp_exception_resume: |
0a39bb32 PA |
5759 | if (bs->stop) |
5760 | { | |
5761 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5762 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5763 | } | |
5764 | else | |
5765 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5766 | break; |
5767 | case bp_step_resume: | |
5768 | if (bs->stop) | |
628fe4e4 JK |
5769 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5770 | else | |
c906108c | 5771 | { |
628fe4e4 JK |
5772 | /* It is for the wrong frame. */ |
5773 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5774 | } |
c906108c | 5775 | break; |
2c03e5be PA |
5776 | case bp_hp_step_resume: |
5777 | if (bs->stop) | |
5778 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5779 | else | |
5780 | { | |
5781 | /* It is for the wrong frame. */ | |
5782 | this_action = BPSTAT_WHAT_SINGLE; | |
5783 | } | |
5784 | break; | |
c906108c | 5785 | case bp_watchpoint_scope: |
c4093a6a | 5786 | case bp_thread_event: |
1900040c | 5787 | case bp_overlay_event: |
0fd8e87f | 5788 | case bp_longjmp_master: |
aa7d318d | 5789 | case bp_std_terminate_master: |
186c406b | 5790 | case bp_exception_master: |
628fe4e4 | 5791 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5792 | break; |
ce78b96d | 5793 | case bp_catchpoint: |
c5aa993b JM |
5794 | if (bs->stop) |
5795 | { | |
5796 | if (bs->print) | |
628fe4e4 | 5797 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5798 | else |
628fe4e4 | 5799 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5800 | } |
5801 | else | |
628fe4e4 JK |
5802 | { |
5803 | /* There was a catchpoint, but we're not stopping. | |
5804 | This requires no further action. */ | |
5805 | } | |
5806 | break; | |
628fe4e4 | 5807 | case bp_jit_event: |
628fe4e4 | 5808 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5809 | break; |
c906108c | 5810 | case bp_call_dummy: |
53a5351d JM |
5811 | /* Make sure the action is stop (silent or noisy), |
5812 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5813 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5814 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5815 | break; |
5816 | case bp_std_terminate: | |
5817 | /* Make sure the action is stop (silent or noisy), | |
5818 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5819 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5820 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5821 | break; |
1042e4c0 | 5822 | case bp_tracepoint: |
7a697b8d | 5823 | case bp_fast_tracepoint: |
0fb4aa4b | 5824 | case bp_static_tracepoint: |
1042e4c0 SS |
5825 | /* Tracepoint hits should not be reported back to GDB, and |
5826 | if one got through somehow, it should have been filtered | |
5827 | out already. */ | |
5828 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5829 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5830 | break; |
5831 | case bp_gnu_ifunc_resolver: | |
5832 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5833 | this_action = BPSTAT_WHAT_SINGLE; | |
5834 | break; | |
5835 | case bp_gnu_ifunc_resolver_return: | |
5836 | /* The breakpoint will be removed, execution will restart from the | |
5837 | PC of the former breakpoint. */ | |
5838 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5839 | break; | |
e7e0cddf SS |
5840 | |
5841 | case bp_dprintf: | |
a11cfd87 HZ |
5842 | if (bs->stop) |
5843 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5844 | else | |
5845 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5846 | break; |
5847 | ||
628fe4e4 JK |
5848 | default: |
5849 | internal_error (__FILE__, __LINE__, | |
5850 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5851 | } |
628fe4e4 | 5852 | |
325fac50 | 5853 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5854 | } |
628fe4e4 | 5855 | |
243a9253 PA |
5856 | return retval; |
5857 | } | |
628fe4e4 | 5858 | |
243a9253 PA |
5859 | void |
5860 | bpstat_run_callbacks (bpstat bs_head) | |
5861 | { | |
5862 | bpstat bs; | |
628fe4e4 | 5863 | |
0e30163f JK |
5864 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5865 | { | |
5866 | struct breakpoint *b = bs->breakpoint_at; | |
5867 | ||
5868 | if (b == NULL) | |
5869 | continue; | |
5870 | switch (b->type) | |
5871 | { | |
243a9253 PA |
5872 | case bp_jit_event: |
5873 | handle_jit_event (); | |
5874 | break; | |
0e30163f JK |
5875 | case bp_gnu_ifunc_resolver: |
5876 | gnu_ifunc_resolver_stop (b); | |
5877 | break; | |
5878 | case bp_gnu_ifunc_resolver_return: | |
5879 | gnu_ifunc_resolver_return_stop (b); | |
5880 | break; | |
5881 | } | |
5882 | } | |
c906108c SS |
5883 | } |
5884 | ||
5885 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5886 | without hardware support). This isn't related to a specific bpstat, | |
5887 | just to things like whether watchpoints are set. */ | |
5888 | ||
c5aa993b | 5889 | int |
fba45db2 | 5890 | bpstat_should_step (void) |
c906108c SS |
5891 | { |
5892 | struct breakpoint *b; | |
cc59ec59 | 5893 | |
c906108c | 5894 | ALL_BREAKPOINTS (b) |
717a8278 | 5895 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5896 | return 1; |
c906108c SS |
5897 | return 0; |
5898 | } | |
5899 | ||
67822962 PA |
5900 | int |
5901 | bpstat_causes_stop (bpstat bs) | |
5902 | { | |
5903 | for (; bs != NULL; bs = bs->next) | |
5904 | if (bs->stop) | |
5905 | return 1; | |
5906 | ||
5907 | return 0; | |
5908 | } | |
5909 | ||
c906108c | 5910 | \f |
c5aa993b | 5911 | |
170b53b2 UW |
5912 | /* Compute a string of spaces suitable to indent the next line |
5913 | so it starts at the position corresponding to the table column | |
5914 | named COL_NAME in the currently active table of UIOUT. */ | |
5915 | ||
5916 | static char * | |
5917 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5918 | { | |
5919 | static char wrap_indent[80]; | |
5920 | int i, total_width, width, align; | |
c5209615 | 5921 | const char *text; |
170b53b2 UW |
5922 | |
5923 | total_width = 0; | |
112e8700 | 5924 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5925 | { |
5926 | if (strcmp (text, col_name) == 0) | |
5927 | { | |
5928 | gdb_assert (total_width < sizeof wrap_indent); | |
5929 | memset (wrap_indent, ' ', total_width); | |
5930 | wrap_indent[total_width] = 0; | |
5931 | ||
5932 | return wrap_indent; | |
5933 | } | |
5934 | ||
5935 | total_width += width + 1; | |
5936 | } | |
5937 | ||
5938 | return NULL; | |
5939 | } | |
5940 | ||
b775012e LM |
5941 | /* Determine if the locations of this breakpoint will have their conditions |
5942 | evaluated by the target, host or a mix of both. Returns the following: | |
5943 | ||
5944 | "host": Host evals condition. | |
5945 | "host or target": Host or Target evals condition. | |
5946 | "target": Target evals condition. | |
5947 | */ | |
5948 | ||
5949 | static const char * | |
5950 | bp_condition_evaluator (struct breakpoint *b) | |
5951 | { | |
5952 | struct bp_location *bl; | |
5953 | char host_evals = 0; | |
5954 | char target_evals = 0; | |
5955 | ||
5956 | if (!b) | |
5957 | return NULL; | |
5958 | ||
5959 | if (!is_breakpoint (b)) | |
5960 | return NULL; | |
5961 | ||
5962 | if (gdb_evaluates_breakpoint_condition_p () | |
5963 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5964 | return condition_evaluation_host; | |
5965 | ||
5966 | for (bl = b->loc; bl; bl = bl->next) | |
5967 | { | |
5968 | if (bl->cond_bytecode) | |
5969 | target_evals++; | |
5970 | else | |
5971 | host_evals++; | |
5972 | } | |
5973 | ||
5974 | if (host_evals && target_evals) | |
5975 | return condition_evaluation_both; | |
5976 | else if (target_evals) | |
5977 | return condition_evaluation_target; | |
5978 | else | |
5979 | return condition_evaluation_host; | |
5980 | } | |
5981 | ||
5982 | /* Determine the breakpoint location's condition evaluator. This is | |
5983 | similar to bp_condition_evaluator, but for locations. */ | |
5984 | ||
5985 | static const char * | |
5986 | bp_location_condition_evaluator (struct bp_location *bl) | |
5987 | { | |
5988 | if (bl && !is_breakpoint (bl->owner)) | |
5989 | return NULL; | |
5990 | ||
5991 | if (gdb_evaluates_breakpoint_condition_p () | |
5992 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5993 | return condition_evaluation_host; | |
5994 | ||
5995 | if (bl && bl->cond_bytecode) | |
5996 | return condition_evaluation_target; | |
5997 | else | |
5998 | return condition_evaluation_host; | |
5999 | } | |
6000 | ||
859825b8 JK |
6001 | /* Print the LOC location out of the list of B->LOC locations. */ |
6002 | ||
170b53b2 UW |
6003 | static void |
6004 | print_breakpoint_location (struct breakpoint *b, | |
6005 | struct bp_location *loc) | |
0d381245 | 6006 | { |
79a45e25 | 6007 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
6008 | |
6009 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 6010 | |
859825b8 JK |
6011 | if (loc != NULL && loc->shlib_disabled) |
6012 | loc = NULL; | |
6013 | ||
6c95b8df PA |
6014 | if (loc != NULL) |
6015 | set_current_program_space (loc->pspace); | |
6016 | ||
56435ebe | 6017 | if (b->display_canonical) |
d28cd78a | 6018 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 6019 | else if (loc && loc->symtab) |
0d381245 VP |
6020 | { |
6021 | struct symbol *sym | |
6022 | = find_pc_sect_function (loc->address, loc->section); | |
6023 | if (sym) | |
6024 | { | |
112e8700 SM |
6025 | uiout->text ("in "); |
6026 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); | |
6027 | uiout->text (" "); | |
6028 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
6029 | uiout->text ("at "); | |
0d381245 | 6030 | } |
112e8700 | 6031 | uiout->field_string ("file", |
05cba821 | 6032 | symtab_to_filename_for_display (loc->symtab)); |
112e8700 | 6033 | uiout->text (":"); |
05cba821 | 6034 | |
112e8700 SM |
6035 | if (uiout->is_mi_like_p ()) |
6036 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 6037 | |
112e8700 | 6038 | uiout->field_int ("line", loc->line_number); |
0d381245 | 6039 | } |
859825b8 | 6040 | else if (loc) |
0d381245 | 6041 | { |
d7e74731 | 6042 | string_file stb; |
170b53b2 | 6043 | |
d7e74731 | 6044 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 6045 | demangle, ""); |
112e8700 | 6046 | uiout->field_stream ("at", stb); |
0d381245 | 6047 | } |
859825b8 | 6048 | else |
f00aae0f | 6049 | { |
d28cd78a TT |
6050 | uiout->field_string ("pending", |
6051 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
6052 | /* If extra_string is available, it could be holding a condition |
6053 | or dprintf arguments. In either case, make sure it is printed, | |
6054 | too, but only for non-MI streams. */ | |
112e8700 | 6055 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
6056 | { |
6057 | if (b->type == bp_dprintf) | |
112e8700 | 6058 | uiout->text (","); |
f00aae0f | 6059 | else |
112e8700 SM |
6060 | uiout->text (" "); |
6061 | uiout->text (b->extra_string); | |
f00aae0f KS |
6062 | } |
6063 | } | |
6c95b8df | 6064 | |
b775012e LM |
6065 | if (loc && is_breakpoint (b) |
6066 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6067 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6068 | { | |
112e8700 SM |
6069 | uiout->text (" ("); |
6070 | uiout->field_string ("evaluated-by", | |
b775012e | 6071 | bp_location_condition_evaluator (loc)); |
112e8700 | 6072 | uiout->text (")"); |
b775012e | 6073 | } |
0d381245 VP |
6074 | } |
6075 | ||
269b11a2 PA |
6076 | static const char * |
6077 | bptype_string (enum bptype type) | |
c906108c | 6078 | { |
c4093a6a JM |
6079 | struct ep_type_description |
6080 | { | |
6081 | enum bptype type; | |
a121b7c1 | 6082 | const char *description; |
c4093a6a JM |
6083 | }; |
6084 | static struct ep_type_description bptypes[] = | |
c906108c | 6085 | { |
c5aa993b JM |
6086 | {bp_none, "?deleted?"}, |
6087 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6088 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6089 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6090 | {bp_until, "until"}, |
6091 | {bp_finish, "finish"}, | |
6092 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6093 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6094 | {bp_read_watchpoint, "read watchpoint"}, |
6095 | {bp_access_watchpoint, "acc watchpoint"}, | |
6096 | {bp_longjmp, "longjmp"}, | |
6097 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6098 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6099 | {bp_exception, "exception"}, |
6100 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6101 | {bp_step_resume, "step resume"}, |
2c03e5be | 6102 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6103 | {bp_watchpoint_scope, "watchpoint scope"}, |
6104 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6105 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6106 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6107 | {bp_thread_event, "thread events"}, |
1900040c | 6108 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6109 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6110 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6111 | {bp_exception_master, "exception master"}, |
ce78b96d | 6112 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6113 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6114 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6115 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6116 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6117 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6118 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6119 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6120 | }; |
269b11a2 PA |
6121 | |
6122 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6123 | || ((int) type != bptypes[(int) type].type)) | |
6124 | internal_error (__FILE__, __LINE__, | |
6125 | _("bptypes table does not describe type #%d."), | |
6126 | (int) type); | |
6127 | ||
6128 | return bptypes[(int) type].description; | |
6129 | } | |
6130 | ||
998580f1 MK |
6131 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6132 | For CLI, prefix the list with the string 'inf'. */ | |
6133 | ||
6134 | static void | |
6135 | output_thread_groups (struct ui_out *uiout, | |
6136 | const char *field_name, | |
6137 | VEC(int) *inf_num, | |
6138 | int mi_only) | |
6139 | { | |
112e8700 | 6140 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6141 | int inf; |
6142 | int i; | |
6143 | ||
6144 | /* For backward compatibility, don't display inferiors in CLI unless | |
6145 | there are several. Always display them for MI. */ | |
6146 | if (!is_mi && mi_only) | |
6147 | return; | |
6148 | ||
10f489e5 | 6149 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6150 | |
998580f1 MK |
6151 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6152 | { | |
6153 | if (is_mi) | |
6154 | { | |
6155 | char mi_group[10]; | |
6156 | ||
6157 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
112e8700 | 6158 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6159 | } |
6160 | else | |
6161 | { | |
6162 | if (i == 0) | |
112e8700 | 6163 | uiout->text (" inf "); |
998580f1 | 6164 | else |
112e8700 | 6165 | uiout->text (", "); |
998580f1 | 6166 | |
112e8700 | 6167 | uiout->text (plongest (inf)); |
998580f1 MK |
6168 | } |
6169 | } | |
998580f1 MK |
6170 | } |
6171 | ||
269b11a2 PA |
6172 | /* Print B to gdb_stdout. */ |
6173 | ||
6174 | static void | |
6175 | print_one_breakpoint_location (struct breakpoint *b, | |
6176 | struct bp_location *loc, | |
6177 | int loc_number, | |
6178 | struct bp_location **last_loc, | |
269b11a2 PA |
6179 | int allflag) |
6180 | { | |
6181 | struct command_line *l; | |
c2c6d25f | 6182 | static char bpenables[] = "nynny"; |
c906108c | 6183 | |
79a45e25 | 6184 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6185 | int header_of_multiple = 0; |
6186 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6187 | struct value_print_options opts; |
6188 | ||
6189 | get_user_print_options (&opts); | |
0d381245 VP |
6190 | |
6191 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6192 | /* See comment in print_one_breakpoint concerning treatment of |
6193 | breakpoints with single disabled location. */ | |
0d381245 VP |
6194 | if (loc == NULL |
6195 | && (b->loc != NULL | |
6196 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6197 | header_of_multiple = 1; | |
6198 | if (loc == NULL) | |
6199 | loc = b->loc; | |
6200 | ||
c4093a6a JM |
6201 | annotate_record (); |
6202 | ||
6203 | /* 1 */ | |
6204 | annotate_field (0); | |
0d381245 VP |
6205 | if (part_of_multiple) |
6206 | { | |
6207 | char *formatted; | |
0c6773c1 | 6208 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
112e8700 | 6209 | uiout->field_string ("number", formatted); |
0d381245 VP |
6210 | xfree (formatted); |
6211 | } | |
6212 | else | |
6213 | { | |
112e8700 | 6214 | uiout->field_int ("number", b->number); |
0d381245 | 6215 | } |
c4093a6a JM |
6216 | |
6217 | /* 2 */ | |
6218 | annotate_field (1); | |
0d381245 | 6219 | if (part_of_multiple) |
112e8700 | 6220 | uiout->field_skip ("type"); |
269b11a2 | 6221 | else |
112e8700 | 6222 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6223 | |
6224 | /* 3 */ | |
6225 | annotate_field (2); | |
0d381245 | 6226 | if (part_of_multiple) |
112e8700 | 6227 | uiout->field_skip ("disp"); |
0d381245 | 6228 | else |
112e8700 | 6229 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6230 | |
c4093a6a JM |
6231 | |
6232 | /* 4 */ | |
6233 | annotate_field (3); | |
0d381245 | 6234 | if (part_of_multiple) |
112e8700 | 6235 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6236 | else |
112e8700 SM |
6237 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
6238 | uiout->spaces (2); | |
0d381245 | 6239 | |
c4093a6a JM |
6240 | |
6241 | /* 5 and 6 */ | |
3086aeae | 6242 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6243 | { |
4a64f543 MS |
6244 | /* Although the print_one can possibly print all locations, |
6245 | calling it here is not likely to get any nice result. So, | |
6246 | make sure there's just one location. */ | |
0d381245 | 6247 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6248 | b->ops->print_one (b, last_loc); |
0d381245 | 6249 | } |
3086aeae DJ |
6250 | else |
6251 | switch (b->type) | |
6252 | { | |
6253 | case bp_none: | |
6254 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6255 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6256 | break; |
c906108c | 6257 | |
3086aeae DJ |
6258 | case bp_watchpoint: |
6259 | case bp_hardware_watchpoint: | |
6260 | case bp_read_watchpoint: | |
6261 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6262 | { |
6263 | struct watchpoint *w = (struct watchpoint *) b; | |
6264 | ||
6265 | /* Field 4, the address, is omitted (which makes the columns | |
6266 | not line up too nicely with the headers, but the effect | |
6267 | is relatively readable). */ | |
6268 | if (opts.addressprint) | |
112e8700 | 6269 | uiout->field_skip ("addr"); |
3a5c3e22 | 6270 | annotate_field (5); |
112e8700 | 6271 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6272 | } |
3086aeae DJ |
6273 | break; |
6274 | ||
3086aeae DJ |
6275 | case bp_breakpoint: |
6276 | case bp_hardware_breakpoint: | |
7c16b83e | 6277 | case bp_single_step: |
3086aeae DJ |
6278 | case bp_until: |
6279 | case bp_finish: | |
6280 | case bp_longjmp: | |
6281 | case bp_longjmp_resume: | |
e2e4d78b | 6282 | case bp_longjmp_call_dummy: |
186c406b TT |
6283 | case bp_exception: |
6284 | case bp_exception_resume: | |
3086aeae | 6285 | case bp_step_resume: |
2c03e5be | 6286 | case bp_hp_step_resume: |
3086aeae DJ |
6287 | case bp_watchpoint_scope: |
6288 | case bp_call_dummy: | |
aa7d318d | 6289 | case bp_std_terminate: |
3086aeae DJ |
6290 | case bp_shlib_event: |
6291 | case bp_thread_event: | |
6292 | case bp_overlay_event: | |
0fd8e87f | 6293 | case bp_longjmp_master: |
aa7d318d | 6294 | case bp_std_terminate_master: |
186c406b | 6295 | case bp_exception_master: |
1042e4c0 | 6296 | case bp_tracepoint: |
7a697b8d | 6297 | case bp_fast_tracepoint: |
0fb4aa4b | 6298 | case bp_static_tracepoint: |
e7e0cddf | 6299 | case bp_dprintf: |
4efc6507 | 6300 | case bp_jit_event: |
0e30163f JK |
6301 | case bp_gnu_ifunc_resolver: |
6302 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6303 | if (opts.addressprint) |
3086aeae DJ |
6304 | { |
6305 | annotate_field (4); | |
54e52265 | 6306 | if (header_of_multiple) |
112e8700 | 6307 | uiout->field_string ("addr", "<MULTIPLE>"); |
e9bbd7c5 | 6308 | else if (b->loc == NULL || loc->shlib_disabled) |
112e8700 | 6309 | uiout->field_string ("addr", "<PENDING>"); |
0101ce28 | 6310 | else |
112e8700 | 6311 | uiout->field_core_addr ("addr", |
5af949e3 | 6312 | loc->gdbarch, loc->address); |
3086aeae DJ |
6313 | } |
6314 | annotate_field (5); | |
0d381245 | 6315 | if (!header_of_multiple) |
170b53b2 | 6316 | print_breakpoint_location (b, loc); |
0d381245 | 6317 | if (b->loc) |
a6d9a66e | 6318 | *last_loc = b->loc; |
3086aeae DJ |
6319 | break; |
6320 | } | |
c906108c | 6321 | |
6c95b8df | 6322 | |
998580f1 | 6323 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6324 | { |
6325 | struct inferior *inf; | |
998580f1 MK |
6326 | VEC(int) *inf_num = NULL; |
6327 | int mi_only = 1; | |
6c95b8df | 6328 | |
998580f1 | 6329 | ALL_INFERIORS (inf) |
6c95b8df PA |
6330 | { |
6331 | if (inf->pspace == loc->pspace) | |
998580f1 | 6332 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6333 | } |
998580f1 MK |
6334 | |
6335 | /* For backward compatibility, don't display inferiors in CLI unless | |
6336 | there are several. Always display for MI. */ | |
6337 | if (allflag | |
6338 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6339 | && (number_of_program_spaces () > 1 | |
6340 | || number_of_inferiors () > 1) | |
6341 | /* LOC is for existing B, it cannot be in | |
6342 | moribund_locations and thus having NULL OWNER. */ | |
6343 | && loc->owner->type != bp_catchpoint)) | |
6344 | mi_only = 0; | |
6345 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6346 | VEC_free (int, inf_num); | |
6c95b8df PA |
6347 | } |
6348 | ||
4a306c9a | 6349 | if (!part_of_multiple) |
c4093a6a | 6350 | { |
4a306c9a JB |
6351 | if (b->thread != -1) |
6352 | { | |
6353 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6354 | "stop only in" line a little further down. */ |
112e8700 SM |
6355 | uiout->text (" thread "); |
6356 | uiout->field_int ("thread", b->thread); | |
4a306c9a JB |
6357 | } |
6358 | else if (b->task != 0) | |
6359 | { | |
112e8700 SM |
6360 | uiout->text (" task "); |
6361 | uiout->field_int ("task", b->task); | |
4a306c9a | 6362 | } |
c4093a6a | 6363 | } |
f1310107 | 6364 | |
112e8700 | 6365 | uiout->text ("\n"); |
f1310107 | 6366 | |
348d480f | 6367 | if (!part_of_multiple) |
f1310107 TJB |
6368 | b->ops->print_one_detail (b, uiout); |
6369 | ||
0d381245 | 6370 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6371 | { |
6372 | annotate_field (6); | |
112e8700 | 6373 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6374 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6375 | the frame ID. */ |
112e8700 | 6376 | uiout->field_core_addr ("frame", |
5af949e3 | 6377 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6378 | uiout->text ("\n"); |
c4093a6a JM |
6379 | } |
6380 | ||
28010a5d | 6381 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6382 | { |
6383 | annotate_field (7); | |
d77f58be | 6384 | if (is_tracepoint (b)) |
112e8700 | 6385 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6386 | else |
112e8700 SM |
6387 | uiout->text ("\tstop only if "); |
6388 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6389 | |
6390 | /* Print whether the target is doing the breakpoint's condition | |
6391 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6392 | if (is_breakpoint (b) | |
6393 | && breakpoint_condition_evaluation_mode () | |
6394 | == condition_evaluation_target) | |
6395 | { | |
112e8700 SM |
6396 | uiout->text (" ("); |
6397 | uiout->field_string ("evaluated-by", | |
b775012e | 6398 | bp_condition_evaluator (b)); |
112e8700 | 6399 | uiout->text (" evals)"); |
b775012e | 6400 | } |
112e8700 | 6401 | uiout->text ("\n"); |
0101ce28 JJ |
6402 | } |
6403 | ||
0d381245 | 6404 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6405 | { |
4a64f543 | 6406 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6407 | uiout->text ("\tstop only in thread "); |
6408 | if (uiout->is_mi_like_p ()) | |
6409 | uiout->field_int ("thread", b->thread); | |
5d5658a1 PA |
6410 | else |
6411 | { | |
6412 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6413 | ||
112e8700 | 6414 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6415 | } |
112e8700 | 6416 | uiout->text ("\n"); |
c4093a6a JM |
6417 | } |
6418 | ||
556ec64d YQ |
6419 | if (!part_of_multiple) |
6420 | { | |
6421 | if (b->hit_count) | |
31f56a27 YQ |
6422 | { |
6423 | /* FIXME should make an annotation for this. */ | |
6424 | if (is_catchpoint (b)) | |
112e8700 | 6425 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6426 | else if (is_tracepoint (b)) |
112e8700 | 6427 | uiout->text ("\ttracepoint"); |
31f56a27 | 6428 | else |
112e8700 SM |
6429 | uiout->text ("\tbreakpoint"); |
6430 | uiout->text (" already hit "); | |
6431 | uiout->field_int ("times", b->hit_count); | |
31f56a27 | 6432 | if (b->hit_count == 1) |
112e8700 | 6433 | uiout->text (" time\n"); |
31f56a27 | 6434 | else |
112e8700 | 6435 | uiout->text (" times\n"); |
31f56a27 | 6436 | } |
556ec64d YQ |
6437 | else |
6438 | { | |
31f56a27 | 6439 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 SM |
6440 | if (uiout->is_mi_like_p ()) |
6441 | uiout->field_int ("times", b->hit_count); | |
556ec64d YQ |
6442 | } |
6443 | } | |
8b93c638 | 6444 | |
0d381245 | 6445 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6446 | { |
6447 | annotate_field (8); | |
112e8700 SM |
6448 | uiout->text ("\tignore next "); |
6449 | uiout->field_int ("ignore", b->ignore_count); | |
6450 | uiout->text (" hits\n"); | |
c4093a6a | 6451 | } |
059fb39f | 6452 | |
816338b5 SS |
6453 | /* Note that an enable count of 1 corresponds to "enable once" |
6454 | behavior, which is reported by the combination of enablement and | |
6455 | disposition, so we don't need to mention it here. */ | |
6456 | if (!part_of_multiple && b->enable_count > 1) | |
6457 | { | |
6458 | annotate_field (8); | |
112e8700 | 6459 | uiout->text ("\tdisable after "); |
816338b5 SS |
6460 | /* Tweak the wording to clarify that ignore and enable counts |
6461 | are distinct, and have additive effect. */ | |
6462 | if (b->ignore_count) | |
112e8700 | 6463 | uiout->text ("additional "); |
816338b5 | 6464 | else |
112e8700 SM |
6465 | uiout->text ("next "); |
6466 | uiout->field_int ("enable", b->enable_count); | |
6467 | uiout->text (" hits\n"); | |
816338b5 SS |
6468 | } |
6469 | ||
f196051f SS |
6470 | if (!part_of_multiple && is_tracepoint (b)) |
6471 | { | |
6472 | struct tracepoint *tp = (struct tracepoint *) b; | |
6473 | ||
6474 | if (tp->traceframe_usage) | |
6475 | { | |
112e8700 SM |
6476 | uiout->text ("\ttrace buffer usage "); |
6477 | uiout->field_int ("traceframe-usage", tp->traceframe_usage); | |
6478 | uiout->text (" bytes\n"); | |
f196051f SS |
6479 | } |
6480 | } | |
d3ce09f5 | 6481 | |
d1b0a7bf | 6482 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6483 | if (!part_of_multiple && l) |
c4093a6a JM |
6484 | { |
6485 | annotate_field (9); | |
2e783024 | 6486 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6487 | print_command_lines (uiout, l, 4); |
c4093a6a | 6488 | } |
d24317b4 | 6489 | |
d9b3f62e | 6490 | if (is_tracepoint (b)) |
1042e4c0 | 6491 | { |
d9b3f62e PA |
6492 | struct tracepoint *t = (struct tracepoint *) b; |
6493 | ||
6494 | if (!part_of_multiple && t->pass_count) | |
6495 | { | |
6496 | annotate_field (10); | |
112e8700 SM |
6497 | uiout->text ("\tpass count "); |
6498 | uiout->field_int ("pass", t->pass_count); | |
6499 | uiout->text (" \n"); | |
d9b3f62e | 6500 | } |
f2a8bc8a YQ |
6501 | |
6502 | /* Don't display it when tracepoint or tracepoint location is | |
6503 | pending. */ | |
6504 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6505 | { | |
6506 | annotate_field (11); | |
6507 | ||
112e8700 SM |
6508 | if (uiout->is_mi_like_p ()) |
6509 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6510 | loc->inserted ? "y" : "n"); |
6511 | else | |
6512 | { | |
6513 | if (loc->inserted) | |
112e8700 | 6514 | uiout->text ("\t"); |
f2a8bc8a | 6515 | else |
112e8700 SM |
6516 | uiout->text ("\tnot "); |
6517 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6518 | } |
6519 | } | |
1042e4c0 SS |
6520 | } |
6521 | ||
112e8700 | 6522 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6523 | { |
3a5c3e22 PA |
6524 | if (is_watchpoint (b)) |
6525 | { | |
6526 | struct watchpoint *w = (struct watchpoint *) b; | |
6527 | ||
112e8700 | 6528 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6529 | } |
f00aae0f | 6530 | else if (b->location != NULL |
d28cd78a | 6531 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6532 | uiout->field_string ("original-location", |
d28cd78a | 6533 | event_location_to_string (b->location.get ())); |
d24317b4 | 6534 | } |
c4093a6a | 6535 | } |
c5aa993b | 6536 | |
0d381245 VP |
6537 | static void |
6538 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6539 | struct bp_location **last_loc, |
6c95b8df | 6540 | int allflag) |
0d381245 | 6541 | { |
79a45e25 | 6542 | struct ui_out *uiout = current_uiout; |
8d3788bd | 6543 | |
2e783024 TT |
6544 | { |
6545 | ui_out_emit_tuple tuple_emitter (uiout, "bkpt"); | |
8d3788bd | 6546 | |
2e783024 TT |
6547 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
6548 | } | |
0d381245 VP |
6549 | |
6550 | /* If this breakpoint has custom print function, | |
6551 | it's already printed. Otherwise, print individual | |
6552 | locations, if any. */ | |
6553 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6554 | { | |
4a64f543 MS |
6555 | /* If breakpoint has a single location that is disabled, we |
6556 | print it as if it had several locations, since otherwise it's | |
6557 | hard to represent "breakpoint enabled, location disabled" | |
6558 | situation. | |
6559 | ||
6560 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6561 | internally, that's not a property exposed to user. */ |
0d381245 | 6562 | if (b->loc |
a5606eee | 6563 | && !is_hardware_watchpoint (b) |
8d3788bd | 6564 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6565 | { |
6566 | struct bp_location *loc; | |
6567 | int n = 1; | |
8d3788bd | 6568 | |
0d381245 | 6569 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd | 6570 | { |
2e783024 | 6571 | ui_out_emit_tuple tuple_emitter (uiout, NULL); |
8d3788bd | 6572 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
8d3788bd | 6573 | } |
0d381245 VP |
6574 | } |
6575 | } | |
6576 | } | |
6577 | ||
a6d9a66e UW |
6578 | static int |
6579 | breakpoint_address_bits (struct breakpoint *b) | |
6580 | { | |
6581 | int print_address_bits = 0; | |
6582 | struct bp_location *loc; | |
6583 | ||
c6d81124 PA |
6584 | /* Software watchpoints that aren't watching memory don't have an |
6585 | address to print. */ | |
6586 | if (is_no_memory_software_watchpoint (b)) | |
6587 | return 0; | |
6588 | ||
a6d9a66e UW |
6589 | for (loc = b->loc; loc; loc = loc->next) |
6590 | { | |
c7437ca6 PA |
6591 | int addr_bit; |
6592 | ||
c7437ca6 | 6593 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6594 | if (addr_bit > print_address_bits) |
6595 | print_address_bits = addr_bit; | |
6596 | } | |
6597 | ||
6598 | return print_address_bits; | |
6599 | } | |
0d381245 | 6600 | |
65630365 | 6601 | /* See breakpoint.h. */ |
c5aa993b | 6602 | |
65630365 PA |
6603 | void |
6604 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6605 | { |
a6d9a66e | 6606 | struct bp_location *dummy_loc = NULL; |
65630365 | 6607 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6608 | } |
c5aa993b | 6609 | |
09d682a4 TT |
6610 | /* Return true if this breakpoint was set by the user, false if it is |
6611 | internal or momentary. */ | |
6612 | ||
6613 | int | |
6614 | user_breakpoint_p (struct breakpoint *b) | |
6615 | { | |
46c6471b | 6616 | return b->number > 0; |
09d682a4 TT |
6617 | } |
6618 | ||
93daf339 TT |
6619 | /* See breakpoint.h. */ |
6620 | ||
6621 | int | |
6622 | pending_breakpoint_p (struct breakpoint *b) | |
6623 | { | |
6624 | return b->loc == NULL; | |
6625 | } | |
6626 | ||
7f3b0473 | 6627 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6628 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6629 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6630 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6631 | ones for which it returns non-zero. Return the total number of | |
6632 | breakpoints listed. */ | |
c906108c | 6633 | |
d77f58be | 6634 | static int |
4495129a | 6635 | breakpoint_1 (const char *args, int allflag, |
4a64f543 | 6636 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6637 | { |
52f0bd74 | 6638 | struct breakpoint *b; |
a6d9a66e | 6639 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6640 | int nr_printable_breakpoints; |
79a45b7d | 6641 | struct value_print_options opts; |
a6d9a66e | 6642 | int print_address_bits = 0; |
269b11a2 | 6643 | int print_type_col_width = 14; |
79a45e25 | 6644 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6645 | |
79a45b7d TT |
6646 | get_user_print_options (&opts); |
6647 | ||
4a64f543 MS |
6648 | /* Compute the number of rows in the table, as well as the size |
6649 | required for address fields. */ | |
7f3b0473 AC |
6650 | nr_printable_breakpoints = 0; |
6651 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6652 | { |
6653 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6654 | if (filter && !filter (b)) | |
6655 | continue; | |
6656 | ||
6657 | /* If we have an "args" string, it is a list of breakpoints to | |
6658 | accept. Skip the others. */ | |
6659 | if (args != NULL && *args != '\0') | |
6660 | { | |
6661 | if (allflag && parse_and_eval_long (args) != b->number) | |
6662 | continue; | |
6663 | if (!allflag && !number_is_in_list (args, b->number)) | |
6664 | continue; | |
6665 | } | |
269b11a2 | 6666 | |
e5a67952 MS |
6667 | if (allflag || user_breakpoint_p (b)) |
6668 | { | |
6669 | int addr_bit, type_len; | |
a6d9a66e | 6670 | |
e5a67952 MS |
6671 | addr_bit = breakpoint_address_bits (b); |
6672 | if (addr_bit > print_address_bits) | |
6673 | print_address_bits = addr_bit; | |
269b11a2 | 6674 | |
e5a67952 MS |
6675 | type_len = strlen (bptype_string (b->type)); |
6676 | if (type_len > print_type_col_width) | |
6677 | print_type_col_width = type_len; | |
6678 | ||
6679 | nr_printable_breakpoints++; | |
6680 | } | |
6681 | } | |
7f3b0473 | 6682 | |
4a2b031d TT |
6683 | { |
6684 | ui_out_emit_table table_emitter (uiout, | |
6685 | opts.addressprint ? 6 : 5, | |
6686 | nr_printable_breakpoints, | |
6687 | "BreakpointTable"); | |
6688 | ||
6689 | if (nr_printable_breakpoints > 0) | |
6690 | annotate_breakpoints_headers (); | |
6691 | if (nr_printable_breakpoints > 0) | |
6692 | annotate_field (0); | |
6693 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6694 | if (nr_printable_breakpoints > 0) | |
6695 | annotate_field (1); | |
6696 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6697 | if (nr_printable_breakpoints > 0) | |
6698 | annotate_field (2); | |
6699 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6700 | if (nr_printable_breakpoints > 0) | |
6701 | annotate_field (3); | |
6702 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6703 | if (opts.addressprint) | |
6704 | { | |
6705 | if (nr_printable_breakpoints > 0) | |
6706 | annotate_field (4); | |
6707 | if (print_address_bits <= 32) | |
6708 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6709 | else | |
6710 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6711 | } | |
6712 | if (nr_printable_breakpoints > 0) | |
6713 | annotate_field (5); | |
6714 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6715 | uiout->table_body (); | |
6716 | if (nr_printable_breakpoints > 0) | |
6717 | annotate_breakpoints_table (); | |
6718 | ||
6719 | ALL_BREAKPOINTS (b) | |
6720 | { | |
6721 | QUIT; | |
6722 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6723 | if (filter && !filter (b)) | |
6724 | continue; | |
e5a67952 | 6725 | |
4a2b031d TT |
6726 | /* If we have an "args" string, it is a list of breakpoints to |
6727 | accept. Skip the others. */ | |
e5a67952 | 6728 | |
4a2b031d TT |
6729 | if (args != NULL && *args != '\0') |
6730 | { | |
6731 | if (allflag) /* maintenance info breakpoint */ | |
6732 | { | |
6733 | if (parse_and_eval_long (args) != b->number) | |
6734 | continue; | |
6735 | } | |
6736 | else /* all others */ | |
6737 | { | |
6738 | if (!number_is_in_list (args, b->number)) | |
6739 | continue; | |
6740 | } | |
6741 | } | |
6742 | /* We only print out user settable breakpoints unless the | |
6743 | allflag is set. */ | |
6744 | if (allflag || user_breakpoint_p (b)) | |
6745 | print_one_breakpoint (b, &last_loc, allflag); | |
6746 | } | |
6747 | } | |
698384cd | 6748 | |
7f3b0473 | 6749 | if (nr_printable_breakpoints == 0) |
c906108c | 6750 | { |
4a64f543 MS |
6751 | /* If there's a filter, let the caller decide how to report |
6752 | empty list. */ | |
d77f58be SS |
6753 | if (!filter) |
6754 | { | |
e5a67952 | 6755 | if (args == NULL || *args == '\0') |
112e8700 | 6756 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6757 | else |
112e8700 | 6758 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
e5a67952 | 6759 | args); |
d77f58be | 6760 | } |
c906108c SS |
6761 | } |
6762 | else | |
c4093a6a | 6763 | { |
a6d9a66e UW |
6764 | if (last_loc && !server_command) |
6765 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6766 | } |
c906108c | 6767 | |
4a64f543 | 6768 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6769 | there have been breakpoints? */ |
c906108c | 6770 | annotate_breakpoints_table_end (); |
d77f58be SS |
6771 | |
6772 | return nr_printable_breakpoints; | |
c906108c SS |
6773 | } |
6774 | ||
ad443146 SS |
6775 | /* Display the value of default-collect in a way that is generally |
6776 | compatible with the breakpoint list. */ | |
6777 | ||
6778 | static void | |
6779 | default_collect_info (void) | |
6780 | { | |
79a45e25 PA |
6781 | struct ui_out *uiout = current_uiout; |
6782 | ||
ad443146 SS |
6783 | /* If it has no value (which is frequently the case), say nothing; a |
6784 | message like "No default-collect." gets in user's face when it's | |
6785 | not wanted. */ | |
6786 | if (!*default_collect) | |
6787 | return; | |
6788 | ||
6789 | /* The following phrase lines up nicely with per-tracepoint collect | |
6790 | actions. */ | |
112e8700 SM |
6791 | uiout->text ("default collect "); |
6792 | uiout->field_string ("default-collect", default_collect); | |
6793 | uiout->text (" \n"); | |
ad443146 SS |
6794 | } |
6795 | ||
c906108c | 6796 | static void |
11db9430 | 6797 | info_breakpoints_command (char *args, int from_tty) |
c906108c | 6798 | { |
e5a67952 | 6799 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6800 | |
6801 | default_collect_info (); | |
d77f58be SS |
6802 | } |
6803 | ||
6804 | static void | |
11db9430 | 6805 | info_watchpoints_command (char *args, int from_tty) |
d77f58be | 6806 | { |
e5a67952 | 6807 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6808 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6809 | |
6810 | if (num_printed == 0) | |
6811 | { | |
e5a67952 | 6812 | if (args == NULL || *args == '\0') |
112e8700 | 6813 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6814 | else |
112e8700 | 6815 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6816 | } |
c906108c SS |
6817 | } |
6818 | ||
7a292a7a | 6819 | static void |
4495129a | 6820 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6821 | { |
e5a67952 | 6822 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6823 | |
6824 | default_collect_info (); | |
c906108c SS |
6825 | } |
6826 | ||
0d381245 | 6827 | static int |
714835d5 | 6828 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6829 | struct program_space *pspace, |
714835d5 | 6830 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6831 | { |
6832 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6833 | |
0d381245 VP |
6834 | for (; bl; bl = bl->next) |
6835 | { | |
6c95b8df PA |
6836 | if (bl->pspace == pspace |
6837 | && bl->address == pc | |
0d381245 VP |
6838 | && (!overlay_debugging || bl->section == section)) |
6839 | return 1; | |
6840 | } | |
6841 | return 0; | |
6842 | } | |
6843 | ||
672f9b60 | 6844 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6845 | concerns with logical breakpoints, so we match program spaces, not |
6846 | address spaces. */ | |
c906108c SS |
6847 | |
6848 | static void | |
6c95b8df PA |
6849 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6850 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6851 | struct obj_section *section, int thread) |
c906108c | 6852 | { |
52f0bd74 AC |
6853 | int others = 0; |
6854 | struct breakpoint *b; | |
c906108c SS |
6855 | |
6856 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6857 | others += (user_breakpoint_p (b) |
6858 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6859 | if (others > 0) |
6860 | { | |
a3f17187 AC |
6861 | if (others == 1) |
6862 | printf_filtered (_("Note: breakpoint ")); | |
6863 | else /* if (others == ???) */ | |
6864 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6865 | ALL_BREAKPOINTS (b) |
672f9b60 | 6866 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6867 | { |
6868 | others--; | |
6869 | printf_filtered ("%d", b->number); | |
6870 | if (b->thread == -1 && thread != -1) | |
6871 | printf_filtered (" (all threads)"); | |
6872 | else if (b->thread != -1) | |
6873 | printf_filtered (" (thread %d)", b->thread); | |
6874 | printf_filtered ("%s%s ", | |
059fb39f | 6875 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6876 | || b->enable_state == bp_call_disabled) |
0d381245 | 6877 | ? " (disabled)" |
0d381245 VP |
6878 | : ""), |
6879 | (others > 1) ? "," | |
6880 | : ((others == 1) ? " and" : "")); | |
6881 | } | |
a3f17187 | 6882 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6883 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6884 | printf_filtered (".\n"); |
6885 | } | |
6886 | } | |
6887 | \f | |
c906108c | 6888 | |
e4f237da | 6889 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
6890 | BPT locations. For some breakpoint types, the locations' address members |
6891 | are irrelevant and it makes no sense to attempt to compare them to other | |
6892 | addresses (or use them for any other purpose either). | |
e4f237da | 6893 | |
4a64f543 | 6894 | More specifically, each of the following breakpoint types will |
244558af | 6895 | always have a zero valued location address and we don't want to mark |
4a64f543 | 6896 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 6897 | breakpoint location at address zero: |
e4f237da KB |
6898 | |
6899 | bp_watchpoint | |
2d134ed3 PA |
6900 | bp_catchpoint |
6901 | ||
6902 | */ | |
e4f237da KB |
6903 | |
6904 | static int | |
6905 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6906 | { | |
6907 | enum bptype type = bpt->type; | |
6908 | ||
2d134ed3 PA |
6909 | return (type != bp_watchpoint && type != bp_catchpoint); |
6910 | } | |
6911 | ||
6912 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6913 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6914 | ||
6915 | static int | |
4a64f543 MS |
6916 | watchpoint_locations_match (struct bp_location *loc1, |
6917 | struct bp_location *loc2) | |
2d134ed3 | 6918 | { |
3a5c3e22 PA |
6919 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6920 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6921 | ||
6922 | /* Both of them must exist. */ | |
6923 | gdb_assert (w1 != NULL); | |
6924 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6925 | |
4a64f543 MS |
6926 | /* If the target can evaluate the condition expression in hardware, |
6927 | then we we need to insert both watchpoints even if they are at | |
6928 | the same place. Otherwise the watchpoint will only trigger when | |
6929 | the condition of whichever watchpoint was inserted evaluates to | |
6930 | true, not giving a chance for GDB to check the condition of the | |
6931 | other watchpoint. */ | |
3a5c3e22 | 6932 | if ((w1->cond_exp |
4a64f543 MS |
6933 | && target_can_accel_watchpoint_condition (loc1->address, |
6934 | loc1->length, | |
0cf6dd15 | 6935 | loc1->watchpoint_type, |
4d01a485 | 6936 | w1->cond_exp.get ())) |
3a5c3e22 | 6937 | || (w2->cond_exp |
4a64f543 MS |
6938 | && target_can_accel_watchpoint_condition (loc2->address, |
6939 | loc2->length, | |
0cf6dd15 | 6940 | loc2->watchpoint_type, |
4d01a485 | 6941 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6942 | return 0; |
6943 | ||
85d721b8 PA |
6944 | /* Note that this checks the owner's type, not the location's. In |
6945 | case the target does not support read watchpoints, but does | |
6946 | support access watchpoints, we'll have bp_read_watchpoint | |
6947 | watchpoints with hw_access locations. Those should be considered | |
6948 | duplicates of hw_read locations. The hw_read locations will | |
6949 | become hw_access locations later. */ | |
2d134ed3 PA |
6950 | return (loc1->owner->type == loc2->owner->type |
6951 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6952 | && loc1->address == loc2->address | |
6953 | && loc1->length == loc2->length); | |
e4f237da KB |
6954 | } |
6955 | ||
31e77af2 | 6956 | /* See breakpoint.h. */ |
6c95b8df | 6957 | |
31e77af2 | 6958 | int |
6c95b8df PA |
6959 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
6960 | struct address_space *aspace2, CORE_ADDR addr2) | |
6961 | { | |
f5656ead | 6962 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6963 | || aspace1 == aspace2) |
6964 | && addr1 == addr2); | |
6965 | } | |
6966 | ||
f1310107 TJB |
6967 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6968 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6969 | matches ASPACE2. On targets that have global breakpoints, the address | |
6970 | space doesn't really matter. */ | |
6971 | ||
6972 | static int | |
6973 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6974 | int len1, struct address_space *aspace2, | |
6975 | CORE_ADDR addr2) | |
6976 | { | |
f5656ead | 6977 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6978 | || aspace1 == aspace2) |
6979 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6980 | } | |
6981 | ||
6982 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6983 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6984 | matches the breakpoint's address space. On targets that have global | |
6985 | breakpoints, the address space doesn't really matter. */ | |
6986 | ||
6987 | static int | |
6988 | breakpoint_location_address_match (struct bp_location *bl, | |
6989 | struct address_space *aspace, | |
6990 | CORE_ADDR addr) | |
6991 | { | |
6992 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6993 | aspace, addr) | |
6994 | || (bl->length | |
6995 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6996 | bl->address, bl->length, | |
6997 | aspace, addr))); | |
6998 | } | |
6999 | ||
d35ae833 PA |
7000 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7001 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7002 | match happens only if ASPACE matches the breakpoint's address | |
7003 | space. On targets that have global breakpoints, the address space | |
7004 | doesn't really matter. */ | |
7005 | ||
7006 | static int | |
7007 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7008 | struct address_space *aspace, | |
7009 | CORE_ADDR addr, int len) | |
7010 | { | |
7011 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7012 | || bl->pspace->aspace == aspace) | |
7013 | { | |
7014 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7015 | ||
7016 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7017 | return 1; | |
7018 | } | |
7019 | return 0; | |
7020 | } | |
7021 | ||
1e4d1764 YQ |
7022 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7023 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7024 | true, otherwise returns false. */ | |
7025 | ||
7026 | static int | |
7027 | tracepoint_locations_match (struct bp_location *loc1, | |
7028 | struct bp_location *loc2) | |
7029 | { | |
7030 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7031 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7032 | locations at the same address of different tracepoints are regarded as | |
7033 | different locations. */ | |
7034 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7035 | else | |
7036 | return 0; | |
7037 | } | |
7038 | ||
2d134ed3 PA |
7039 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7040 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7041 | represent the same location. */ | |
7042 | ||
7043 | static int | |
4a64f543 MS |
7044 | breakpoint_locations_match (struct bp_location *loc1, |
7045 | struct bp_location *loc2) | |
2d134ed3 | 7046 | { |
2bdf28a0 JK |
7047 | int hw_point1, hw_point2; |
7048 | ||
7049 | /* Both of them must not be in moribund_locations. */ | |
7050 | gdb_assert (loc1->owner != NULL); | |
7051 | gdb_assert (loc2->owner != NULL); | |
7052 | ||
7053 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7054 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7055 | |
7056 | if (hw_point1 != hw_point2) | |
7057 | return 0; | |
7058 | else if (hw_point1) | |
7059 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7060 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7061 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7062 | else |
f1310107 TJB |
7063 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7064 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7065 | loc2->pspace->aspace, loc2->address) | |
7066 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7067 | } |
7068 | ||
76897487 KB |
7069 | static void |
7070 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7071 | int bnum, int have_bnum) | |
7072 | { | |
f63fbe86 MS |
7073 | /* The longest string possibly returned by hex_string_custom |
7074 | is 50 chars. These must be at least that big for safety. */ | |
7075 | char astr1[64]; | |
7076 | char astr2[64]; | |
76897487 | 7077 | |
bb599908 PH |
7078 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7079 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7080 | if (have_bnum) |
8a3fe4f8 | 7081 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7082 | bnum, astr1, astr2); |
7083 | else | |
8a3fe4f8 | 7084 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7085 | } |
7086 | ||
4a64f543 MS |
7087 | /* Adjust a breakpoint's address to account for architectural |
7088 | constraints on breakpoint placement. Return the adjusted address. | |
7089 | Note: Very few targets require this kind of adjustment. For most | |
7090 | targets, this function is simply the identity function. */ | |
76897487 KB |
7091 | |
7092 | static CORE_ADDR | |
a6d9a66e UW |
7093 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7094 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7095 | { |
a6d9a66e | 7096 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7097 | { |
7098 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7099 | return bpaddr; | |
7100 | } | |
88f7da05 KB |
7101 | else if (bptype == bp_watchpoint |
7102 | || bptype == bp_hardware_watchpoint | |
7103 | || bptype == bp_read_watchpoint | |
7104 | || bptype == bp_access_watchpoint | |
fe798b75 | 7105 | || bptype == bp_catchpoint) |
88f7da05 KB |
7106 | { |
7107 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7108 | have their addresses modified. */ | |
7109 | return bpaddr; | |
7110 | } | |
7c16b83e PA |
7111 | else if (bptype == bp_single_step) |
7112 | { | |
7113 | /* Single-step breakpoints should not have their addresses | |
7114 | modified. If there's any architectural constrain that | |
7115 | applies to this address, then it should have already been | |
7116 | taken into account when the breakpoint was created in the | |
7117 | first place. If we didn't do this, stepping through e.g., | |
7118 | Thumb-2 IT blocks would break. */ | |
7119 | return bpaddr; | |
7120 | } | |
76897487 KB |
7121 | else |
7122 | { | |
7123 | CORE_ADDR adjusted_bpaddr; | |
7124 | ||
7125 | /* Some targets have architectural constraints on the placement | |
7126 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7127 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7128 | |
7129 | /* An adjusted breakpoint address can significantly alter | |
7130 | a user's expectations. Print a warning if an adjustment | |
7131 | is required. */ | |
7132 | if (adjusted_bpaddr != bpaddr) | |
7133 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7134 | ||
7135 | return adjusted_bpaddr; | |
7136 | } | |
7137 | } | |
7138 | ||
5625a286 | 7139 | bp_location::bp_location (const bp_location_ops *ops, breakpoint *owner) |
7cc221ef | 7140 | { |
5625a286 | 7141 | bp_location *loc = this; |
7cc221ef | 7142 | |
348d480f PA |
7143 | gdb_assert (ops != NULL); |
7144 | ||
28010a5d PA |
7145 | loc->ops = ops; |
7146 | loc->owner = owner; | |
b775012e | 7147 | loc->cond_bytecode = NULL; |
0d381245 VP |
7148 | loc->shlib_disabled = 0; |
7149 | loc->enabled = 1; | |
e049a4b5 | 7150 | |
28010a5d | 7151 | switch (owner->type) |
e049a4b5 DJ |
7152 | { |
7153 | case bp_breakpoint: | |
7c16b83e | 7154 | case bp_single_step: |
e049a4b5 DJ |
7155 | case bp_until: |
7156 | case bp_finish: | |
7157 | case bp_longjmp: | |
7158 | case bp_longjmp_resume: | |
e2e4d78b | 7159 | case bp_longjmp_call_dummy: |
186c406b TT |
7160 | case bp_exception: |
7161 | case bp_exception_resume: | |
e049a4b5 | 7162 | case bp_step_resume: |
2c03e5be | 7163 | case bp_hp_step_resume: |
e049a4b5 DJ |
7164 | case bp_watchpoint_scope: |
7165 | case bp_call_dummy: | |
aa7d318d | 7166 | case bp_std_terminate: |
e049a4b5 DJ |
7167 | case bp_shlib_event: |
7168 | case bp_thread_event: | |
7169 | case bp_overlay_event: | |
4efc6507 | 7170 | case bp_jit_event: |
0fd8e87f | 7171 | case bp_longjmp_master: |
aa7d318d | 7172 | case bp_std_terminate_master: |
186c406b | 7173 | case bp_exception_master: |
0e30163f JK |
7174 | case bp_gnu_ifunc_resolver: |
7175 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7176 | case bp_dprintf: |
e049a4b5 | 7177 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7178 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7179 | break; |
7180 | case bp_hardware_breakpoint: | |
7181 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7182 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7183 | break; |
7184 | case bp_hardware_watchpoint: | |
7185 | case bp_read_watchpoint: | |
7186 | case bp_access_watchpoint: | |
7187 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7188 | break; | |
7189 | case bp_watchpoint: | |
ce78b96d | 7190 | case bp_catchpoint: |
15c3d785 PA |
7191 | case bp_tracepoint: |
7192 | case bp_fast_tracepoint: | |
0fb4aa4b | 7193 | case bp_static_tracepoint: |
e049a4b5 DJ |
7194 | loc->loc_type = bp_loc_other; |
7195 | break; | |
7196 | default: | |
e2e0b3e5 | 7197 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7198 | } |
7199 | ||
f431efe5 | 7200 | loc->refc = 1; |
28010a5d PA |
7201 | } |
7202 | ||
7203 | /* Allocate a struct bp_location. */ | |
7204 | ||
7205 | static struct bp_location * | |
7206 | allocate_bp_location (struct breakpoint *bpt) | |
7207 | { | |
348d480f PA |
7208 | return bpt->ops->allocate_location (bpt); |
7209 | } | |
7cc221ef | 7210 | |
f431efe5 PA |
7211 | static void |
7212 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7213 | { |
348d480f | 7214 | loc->ops->dtor (loc); |
4d01a485 | 7215 | delete loc; |
fe3f5fa8 VP |
7216 | } |
7217 | ||
f431efe5 PA |
7218 | /* Increment reference count. */ |
7219 | ||
7220 | static void | |
7221 | incref_bp_location (struct bp_location *bl) | |
7222 | { | |
7223 | ++bl->refc; | |
7224 | } | |
7225 | ||
7226 | /* Decrement reference count. If the reference count reaches 0, | |
7227 | destroy the bp_location. Sets *BLP to NULL. */ | |
7228 | ||
7229 | static void | |
7230 | decref_bp_location (struct bp_location **blp) | |
7231 | { | |
0807b50c PA |
7232 | gdb_assert ((*blp)->refc > 0); |
7233 | ||
f431efe5 PA |
7234 | if (--(*blp)->refc == 0) |
7235 | free_bp_location (*blp); | |
7236 | *blp = NULL; | |
7237 | } | |
7238 | ||
346774a9 | 7239 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7240 | |
b270e6f9 TT |
7241 | static breakpoint * |
7242 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7243 | { |
346774a9 | 7244 | struct breakpoint *b1; |
b270e6f9 | 7245 | struct breakpoint *result = b.get (); |
c906108c | 7246 | |
346774a9 PA |
7247 | /* Add this breakpoint to the end of the chain so that a list of |
7248 | breakpoints will come out in order of increasing numbers. */ | |
7249 | ||
7250 | b1 = breakpoint_chain; | |
7251 | if (b1 == 0) | |
b270e6f9 | 7252 | breakpoint_chain = b.release (); |
346774a9 PA |
7253 | else |
7254 | { | |
7255 | while (b1->next) | |
7256 | b1 = b1->next; | |
b270e6f9 | 7257 | b1->next = b.release (); |
346774a9 | 7258 | } |
b270e6f9 TT |
7259 | |
7260 | return result; | |
346774a9 PA |
7261 | } |
7262 | ||
7263 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7264 | ||
7265 | static void | |
7266 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7267 | struct gdbarch *gdbarch, | |
28010a5d | 7268 | enum bptype bptype, |
c0a91b2b | 7269 | const struct breakpoint_ops *ops) |
346774a9 | 7270 | { |
348d480f PA |
7271 | gdb_assert (ops != NULL); |
7272 | ||
28010a5d | 7273 | b->ops = ops; |
4d28f7a8 | 7274 | b->type = bptype; |
a6d9a66e | 7275 | b->gdbarch = gdbarch; |
c906108c SS |
7276 | b->language = current_language->la_language; |
7277 | b->input_radix = input_radix; | |
d0fb5eae | 7278 | b->related_breakpoint = b; |
346774a9 PA |
7279 | } |
7280 | ||
7281 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7282 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7283 | |
7284 | static struct breakpoint * | |
7285 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7286 | enum bptype bptype, |
c0a91b2b | 7287 | const struct breakpoint_ops *ops) |
346774a9 | 7288 | { |
3b0871f4 | 7289 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7290 | |
3b0871f4 | 7291 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7292 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7293 | } |
7294 | ||
0e30163f JK |
7295 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7296 | resolutions should be made as the user specified the location explicitly | |
7297 | enough. */ | |
7298 | ||
0d381245 | 7299 | static void |
0e30163f | 7300 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7301 | { |
2bdf28a0 JK |
7302 | gdb_assert (loc->owner != NULL); |
7303 | ||
0d381245 | 7304 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7305 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7306 | || is_tracepoint (loc->owner)) |
0d381245 | 7307 | { |
0e30163f | 7308 | int is_gnu_ifunc; |
2c02bd72 | 7309 | const char *function_name; |
6a3a010b | 7310 | CORE_ADDR func_addr; |
0e30163f | 7311 | |
2c02bd72 | 7312 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7313 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7314 | |
7315 | if (is_gnu_ifunc && !explicit_loc) | |
7316 | { | |
7317 | struct breakpoint *b = loc->owner; | |
7318 | ||
7319 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7320 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7321 | &loc->requested_address)) |
7322 | { | |
7323 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7324 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7325 | loc->requested_address, | |
7326 | b->type); | |
7327 | } | |
7328 | else if (b->type == bp_breakpoint && b->loc == loc | |
7329 | && loc->next == NULL && b->related_breakpoint == b) | |
7330 | { | |
7331 | /* Create only the whole new breakpoint of this type but do not | |
7332 | mess more complicated breakpoints with multiple locations. */ | |
7333 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7334 | /* Remember the resolver's address for use by the return |
7335 | breakpoint. */ | |
7336 | loc->related_address = func_addr; | |
0e30163f JK |
7337 | } |
7338 | } | |
7339 | ||
2c02bd72 DE |
7340 | if (function_name) |
7341 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7342 | } |
7343 | } | |
7344 | ||
a6d9a66e | 7345 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7346 | struct gdbarch * |
a6d9a66e UW |
7347 | get_sal_arch (struct symtab_and_line sal) |
7348 | { | |
7349 | if (sal.section) | |
7350 | return get_objfile_arch (sal.section->objfile); | |
7351 | if (sal.symtab) | |
eb822aa6 | 7352 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7353 | |
7354 | return NULL; | |
7355 | } | |
7356 | ||
346774a9 PA |
7357 | /* Low level routine for partially initializing a breakpoint of type |
7358 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7359 | file name, and line number are provided by SAL. |
0d381245 VP |
7360 | |
7361 | It is expected that the caller will complete the initialization of | |
7362 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7363 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7364 | |
346774a9 PA |
7365 | static void |
7366 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7367 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7368 | const struct breakpoint_ops *ops) |
0d381245 | 7369 | { |
28010a5d | 7370 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7371 | |
3742cc8b | 7372 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7373 | |
6c95b8df PA |
7374 | if (bptype != bp_catchpoint) |
7375 | gdb_assert (sal.pspace != NULL); | |
7376 | ||
f8eba3c6 TT |
7377 | /* Store the program space that was used to set the breakpoint, |
7378 | except for ordinary breakpoints, which are independent of the | |
7379 | program space. */ | |
7380 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7381 | b->pspace = sal.pspace; | |
346774a9 | 7382 | } |
c906108c | 7383 | |
346774a9 PA |
7384 | /* set_raw_breakpoint is a low level routine for allocating and |
7385 | partially initializing a breakpoint of type BPTYPE. The newly | |
7386 | created breakpoint's address, section, source file name, and line | |
7387 | number are provided by SAL. The newly created and partially | |
7388 | initialized breakpoint is added to the breakpoint chain and | |
7389 | is also returned as the value of this function. | |
7390 | ||
7391 | It is expected that the caller will complete the initialization of | |
7392 | the newly created breakpoint struct as well as output any status | |
7393 | information regarding the creation of a new breakpoint. In | |
7394 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7395 | number! Care should be taken to not allow an error to occur | |
7396 | prior to completing the initialization of the breakpoint. If this | |
7397 | should happen, a bogus breakpoint will be left on the chain. */ | |
7398 | ||
7399 | struct breakpoint * | |
7400 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7401 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7402 | const struct breakpoint_ops *ops) |
346774a9 | 7403 | { |
3b0871f4 | 7404 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7405 | |
3b0871f4 | 7406 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7407 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7408 | } |
7409 | ||
53a5351d | 7410 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7411 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7412 | initiated the operation. */ | |
c906108c SS |
7413 | |
7414 | void | |
186c406b | 7415 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7416 | { |
35df4500 | 7417 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7418 | int thread = tp->global_num; |
0fd8e87f UW |
7419 | |
7420 | /* To avoid having to rescan all objfile symbols at every step, | |
7421 | we maintain a list of continually-inserted but always disabled | |
7422 | longjmp "master" breakpoints. Here, we simply create momentary | |
7423 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7424 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7425 | if (b->pspace == current_program_space |
186c406b TT |
7426 | && (b->type == bp_longjmp_master |
7427 | || b->type == bp_exception_master)) | |
0fd8e87f | 7428 | { |
06edf0c0 PA |
7429 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7430 | struct breakpoint *clone; | |
cc59ec59 | 7431 | |
e2e4d78b JK |
7432 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7433 | after their removal. */ | |
06edf0c0 | 7434 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7435 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7436 | clone->thread = thread; |
7437 | } | |
186c406b TT |
7438 | |
7439 | tp->initiating_frame = frame; | |
c906108c SS |
7440 | } |
7441 | ||
611c83ae | 7442 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7443 | void |
611c83ae | 7444 | delete_longjmp_breakpoint (int thread) |
c906108c | 7445 | { |
35df4500 | 7446 | struct breakpoint *b, *b_tmp; |
c906108c | 7447 | |
35df4500 | 7448 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7449 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7450 | { |
7451 | if (b->thread == thread) | |
7452 | delete_breakpoint (b); | |
7453 | } | |
c906108c SS |
7454 | } |
7455 | ||
f59f708a PA |
7456 | void |
7457 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7458 | { | |
7459 | struct breakpoint *b, *b_tmp; | |
7460 | ||
7461 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7462 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7463 | { | |
7464 | if (b->thread == thread) | |
7465 | b->disposition = disp_del_at_next_stop; | |
7466 | } | |
7467 | } | |
7468 | ||
e2e4d78b JK |
7469 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7470 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7471 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7472 | breakpoints. */ | |
7473 | ||
7474 | struct breakpoint * | |
7475 | set_longjmp_breakpoint_for_call_dummy (void) | |
7476 | { | |
7477 | struct breakpoint *b, *retval = NULL; | |
7478 | ||
7479 | ALL_BREAKPOINTS (b) | |
7480 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7481 | { | |
7482 | struct breakpoint *new_b; | |
7483 | ||
7484 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7485 | &momentary_breakpoint_ops, |
7486 | 1); | |
5d5658a1 | 7487 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7488 | |
7489 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7490 | ||
7491 | gdb_assert (new_b->related_breakpoint == new_b); | |
7492 | if (retval == NULL) | |
7493 | retval = new_b; | |
7494 | new_b->related_breakpoint = retval; | |
7495 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7496 | retval = retval->related_breakpoint; | |
7497 | retval->related_breakpoint = new_b; | |
7498 | } | |
7499 | ||
7500 | return retval; | |
7501 | } | |
7502 | ||
7503 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7504 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7505 | stack. |
7506 | ||
7507 | You should call this function only at places where it is safe to currently | |
7508 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7509 | frames. */ | |
7510 | ||
7511 | void | |
b67a2c6f | 7512 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7513 | { |
7514 | struct breakpoint *b, *b_tmp; | |
7515 | ||
7516 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7517 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7518 | { |
7519 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7520 | ||
7521 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7522 | dummy_b = dummy_b->related_breakpoint; | |
7523 | if (dummy_b->type != bp_call_dummy | |
7524 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7525 | continue; | |
7526 | ||
b67a2c6f | 7527 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7528 | |
7529 | while (b->related_breakpoint != b) | |
7530 | { | |
7531 | if (b_tmp == b->related_breakpoint) | |
7532 | b_tmp = b->related_breakpoint->next; | |
7533 | delete_breakpoint (b->related_breakpoint); | |
7534 | } | |
7535 | delete_breakpoint (b); | |
7536 | } | |
7537 | } | |
7538 | ||
1900040c MS |
7539 | void |
7540 | enable_overlay_breakpoints (void) | |
7541 | { | |
52f0bd74 | 7542 | struct breakpoint *b; |
1900040c MS |
7543 | |
7544 | ALL_BREAKPOINTS (b) | |
7545 | if (b->type == bp_overlay_event) | |
7546 | { | |
7547 | b->enable_state = bp_enabled; | |
44702360 | 7548 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7549 | overlay_events_enabled = 1; |
1900040c MS |
7550 | } |
7551 | } | |
7552 | ||
7553 | void | |
7554 | disable_overlay_breakpoints (void) | |
7555 | { | |
52f0bd74 | 7556 | struct breakpoint *b; |
1900040c MS |
7557 | |
7558 | ALL_BREAKPOINTS (b) | |
7559 | if (b->type == bp_overlay_event) | |
7560 | { | |
7561 | b->enable_state = bp_disabled; | |
44702360 | 7562 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7563 | overlay_events_enabled = 0; |
1900040c MS |
7564 | } |
7565 | } | |
7566 | ||
aa7d318d TT |
7567 | /* Set an active std::terminate breakpoint for each std::terminate |
7568 | master breakpoint. */ | |
7569 | void | |
7570 | set_std_terminate_breakpoint (void) | |
7571 | { | |
35df4500 | 7572 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7573 | |
35df4500 | 7574 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7575 | if (b->pspace == current_program_space |
7576 | && b->type == bp_std_terminate_master) | |
7577 | { | |
06edf0c0 | 7578 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7579 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7580 | } |
7581 | } | |
7582 | ||
7583 | /* Delete all the std::terminate breakpoints. */ | |
7584 | void | |
7585 | delete_std_terminate_breakpoint (void) | |
7586 | { | |
35df4500 | 7587 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7588 | |
35df4500 | 7589 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7590 | if (b->type == bp_std_terminate) |
7591 | delete_breakpoint (b); | |
7592 | } | |
7593 | ||
c4093a6a | 7594 | struct breakpoint * |
a6d9a66e | 7595 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7596 | { |
7597 | struct breakpoint *b; | |
c4093a6a | 7598 | |
06edf0c0 PA |
7599 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7600 | &internal_breakpoint_ops); | |
7601 | ||
b5de0fa7 | 7602 | b->enable_state = bp_enabled; |
f00aae0f | 7603 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7604 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7605 | |
44702360 | 7606 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7607 | |
c4093a6a JM |
7608 | return b; |
7609 | } | |
7610 | ||
0101ce28 JJ |
7611 | struct lang_and_radix |
7612 | { | |
7613 | enum language lang; | |
7614 | int radix; | |
7615 | }; | |
7616 | ||
4efc6507 DE |
7617 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7618 | ||
7619 | struct breakpoint * | |
7620 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7621 | { | |
2a7f3dff PA |
7622 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7623 | &internal_breakpoint_ops); | |
4efc6507 | 7624 | } |
0101ce28 | 7625 | |
03673fc7 PP |
7626 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7627 | ||
7628 | void | |
7629 | remove_jit_event_breakpoints (void) | |
7630 | { | |
7631 | struct breakpoint *b, *b_tmp; | |
7632 | ||
7633 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7634 | if (b->type == bp_jit_event | |
7635 | && b->loc->pspace == current_program_space) | |
7636 | delete_breakpoint (b); | |
7637 | } | |
7638 | ||
cae688ec JJ |
7639 | void |
7640 | remove_solib_event_breakpoints (void) | |
7641 | { | |
35df4500 | 7642 | struct breakpoint *b, *b_tmp; |
cae688ec | 7643 | |
35df4500 | 7644 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7645 | if (b->type == bp_shlib_event |
7646 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7647 | delete_breakpoint (b); |
7648 | } | |
7649 | ||
f37f681c PA |
7650 | /* See breakpoint.h. */ |
7651 | ||
7652 | void | |
7653 | remove_solib_event_breakpoints_at_next_stop (void) | |
7654 | { | |
7655 | struct breakpoint *b, *b_tmp; | |
7656 | ||
7657 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7658 | if (b->type == bp_shlib_event | |
7659 | && b->loc->pspace == current_program_space) | |
7660 | b->disposition = disp_del_at_next_stop; | |
7661 | } | |
7662 | ||
04086b45 PA |
7663 | /* Helper for create_solib_event_breakpoint / |
7664 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7665 | INSERT_MODE to pass through to update_global_location_list. */ | |
7666 | ||
7667 | static struct breakpoint * | |
7668 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7669 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7670 | { |
7671 | struct breakpoint *b; | |
7672 | ||
06edf0c0 PA |
7673 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7674 | &internal_breakpoint_ops); | |
04086b45 | 7675 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7676 | return b; |
7677 | } | |
7678 | ||
04086b45 PA |
7679 | struct breakpoint * |
7680 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7681 | { | |
7682 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7683 | } | |
7684 | ||
f37f681c PA |
7685 | /* See breakpoint.h. */ |
7686 | ||
7687 | struct breakpoint * | |
7688 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7689 | { | |
7690 | struct breakpoint *b; | |
7691 | ||
04086b45 PA |
7692 | /* Explicitly tell update_global_location_list to insert |
7693 | locations. */ | |
7694 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7695 | if (!b->loc->inserted) |
7696 | { | |
7697 | delete_breakpoint (b); | |
7698 | return NULL; | |
7699 | } | |
7700 | return b; | |
7701 | } | |
7702 | ||
cae688ec JJ |
7703 | /* Disable any breakpoints that are on code in shared libraries. Only |
7704 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7705 | ||
7706 | void | |
cb851954 | 7707 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7708 | { |
876fa593 | 7709 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7710 | |
876fa593 | 7711 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7712 | { |
2bdf28a0 | 7713 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7714 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7715 | |
4a64f543 MS |
7716 | /* We apply the check to all breakpoints, including disabled for |
7717 | those with loc->duplicate set. This is so that when breakpoint | |
7718 | becomes enabled, or the duplicate is removed, gdb will try to | |
7719 | insert all breakpoints. If we don't set shlib_disabled here, | |
7720 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7721 | if (((b->type == bp_breakpoint) |
508ccb1f | 7722 | || (b->type == bp_jit_event) |
1042e4c0 | 7723 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7724 | || (is_tracepoint (b))) |
6c95b8df | 7725 | && loc->pspace == current_program_space |
0d381245 | 7726 | && !loc->shlib_disabled |
6c95b8df | 7727 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7728 | ) |
0d381245 VP |
7729 | { |
7730 | loc->shlib_disabled = 1; | |
7731 | } | |
cae688ec JJ |
7732 | } |
7733 | } | |
7734 | ||
63644780 NB |
7735 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7736 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7737 | disabled ones can just stay disabled. */ | |
84acb35a | 7738 | |
75149521 | 7739 | static void |
84acb35a JJ |
7740 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7741 | { | |
876fa593 | 7742 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7743 | int disabled_shlib_breaks = 0; |
7744 | ||
876fa593 | 7745 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7746 | { |
2bdf28a0 | 7747 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7748 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7749 | |
1e4d1764 | 7750 | if (solib->pspace == loc->pspace |
e2dd7057 | 7751 | && !loc->shlib_disabled |
1e4d1764 YQ |
7752 | && (((b->type == bp_breakpoint |
7753 | || b->type == bp_jit_event | |
7754 | || b->type == bp_hardware_breakpoint) | |
7755 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7756 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7757 | || is_tracepoint (b)) | |
e2dd7057 | 7758 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7759 | { |
e2dd7057 PP |
7760 | loc->shlib_disabled = 1; |
7761 | /* At this point, we cannot rely on remove_breakpoint | |
7762 | succeeding so we must mark the breakpoint as not inserted | |
7763 | to prevent future errors occurring in remove_breakpoints. */ | |
7764 | loc->inserted = 0; | |
8d3788bd VP |
7765 | |
7766 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7767 | observer_notify_breakpoint_modified (b); | |
7768 | ||
e2dd7057 PP |
7769 | if (!disabled_shlib_breaks) |
7770 | { | |
223ffa71 | 7771 | target_terminal::ours_for_output (); |
3e43a32a MS |
7772 | warning (_("Temporarily disabling breakpoints " |
7773 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7774 | solib->so_name); |
84acb35a | 7775 | } |
e2dd7057 | 7776 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7777 | } |
7778 | } | |
84acb35a JJ |
7779 | } |
7780 | ||
63644780 NB |
7781 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7782 | notification of free_objfile. Only apply to enabled breakpoints, | |
7783 | disabled ones can just stay disabled. */ | |
7784 | ||
7785 | static void | |
7786 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7787 | { | |
7788 | struct breakpoint *b; | |
7789 | ||
7790 | if (objfile == NULL) | |
7791 | return; | |
7792 | ||
d03de421 PA |
7793 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7794 | managed by the user with add-symbol-file/remove-symbol-file. | |
7795 | Similarly to how breakpoints in shared libraries are handled in | |
7796 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7797 | shlib_disabled so they end up uninserted on the next global |
7798 | location list update. Shared libraries not loaded by the user | |
7799 | aren't handled here -- they're already handled in | |
7800 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7801 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7802 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7803 | main objfile). */ | |
7804 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7805 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7806 | return; |
7807 | ||
7808 | ALL_BREAKPOINTS (b) | |
7809 | { | |
7810 | struct bp_location *loc; | |
7811 | int bp_modified = 0; | |
7812 | ||
7813 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7814 | continue; | |
7815 | ||
7816 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7817 | { | |
7818 | CORE_ADDR loc_addr = loc->address; | |
7819 | ||
7820 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7821 | && loc->loc_type != bp_loc_software_breakpoint) | |
7822 | continue; | |
7823 | ||
7824 | if (loc->shlib_disabled != 0) | |
7825 | continue; | |
7826 | ||
7827 | if (objfile->pspace != loc->pspace) | |
7828 | continue; | |
7829 | ||
7830 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7831 | && loc->loc_type != bp_loc_software_breakpoint) | |
7832 | continue; | |
7833 | ||
7834 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7835 | { | |
7836 | loc->shlib_disabled = 1; | |
08351840 PA |
7837 | /* At this point, we don't know whether the object was |
7838 | unmapped from the inferior or not, so leave the | |
7839 | inserted flag alone. We'll handle failure to | |
7840 | uninsert quietly, in case the object was indeed | |
7841 | unmapped. */ | |
63644780 NB |
7842 | |
7843 | mark_breakpoint_location_modified (loc); | |
7844 | ||
7845 | bp_modified = 1; | |
7846 | } | |
7847 | } | |
7848 | ||
7849 | if (bp_modified) | |
7850 | observer_notify_breakpoint_modified (b); | |
7851 | } | |
7852 | } | |
7853 | ||
ce78b96d JB |
7854 | /* FORK & VFORK catchpoints. */ |
7855 | ||
e29a4733 | 7856 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7857 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7858 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7859 | |
c1fc2657 | 7860 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7861 | { |
e29a4733 PA |
7862 | /* Process id of a child process whose forking triggered this |
7863 | catchpoint. This field is only valid immediately after this | |
7864 | catchpoint has triggered. */ | |
7865 | ptid_t forked_inferior_pid; | |
7866 | }; | |
7867 | ||
4a64f543 MS |
7868 | /* Implement the "insert" breakpoint_ops method for fork |
7869 | catchpoints. */ | |
ce78b96d | 7870 | |
77b06cd7 TJB |
7871 | static int |
7872 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7873 | { |
dfd4cc63 | 7874 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7875 | } |
7876 | ||
4a64f543 MS |
7877 | /* Implement the "remove" breakpoint_ops method for fork |
7878 | catchpoints. */ | |
ce78b96d JB |
7879 | |
7880 | static int | |
73971819 | 7881 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7882 | { |
dfd4cc63 | 7883 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7884 | } |
7885 | ||
7886 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7887 | catchpoints. */ | |
7888 | ||
7889 | static int | |
f1310107 | 7890 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7891 | struct address_space *aspace, CORE_ADDR bp_addr, |
7892 | const struct target_waitstatus *ws) | |
ce78b96d | 7893 | { |
e29a4733 PA |
7894 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7895 | ||
f90263c1 TT |
7896 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7897 | return 0; | |
7898 | ||
7899 | c->forked_inferior_pid = ws->value.related_pid; | |
7900 | return 1; | |
ce78b96d JB |
7901 | } |
7902 | ||
4a64f543 MS |
7903 | /* Implement the "print_it" breakpoint_ops method for fork |
7904 | catchpoints. */ | |
ce78b96d JB |
7905 | |
7906 | static enum print_stop_action | |
348d480f | 7907 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7908 | { |
36dfb11c | 7909 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7910 | struct breakpoint *b = bs->breakpoint_at; |
7911 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7912 | |
ce78b96d | 7913 | annotate_catchpoint (b->number); |
f303dbd6 | 7914 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7915 | if (b->disposition == disp_del) |
112e8700 | 7916 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7917 | else |
112e8700 SM |
7918 | uiout->text ("Catchpoint "); |
7919 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7920 | { |
112e8700 SM |
7921 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7922 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7923 | } |
112e8700 SM |
7924 | uiout->field_int ("bkptno", b->number); |
7925 | uiout->text (" (forked process "); | |
7926 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7927 | uiout->text ("), "); | |
ce78b96d JB |
7928 | return PRINT_SRC_AND_LOC; |
7929 | } | |
7930 | ||
4a64f543 MS |
7931 | /* Implement the "print_one" breakpoint_ops method for fork |
7932 | catchpoints. */ | |
ce78b96d JB |
7933 | |
7934 | static void | |
a6d9a66e | 7935 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7936 | { |
e29a4733 | 7937 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7938 | struct value_print_options opts; |
79a45e25 | 7939 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7940 | |
7941 | get_user_print_options (&opts); | |
7942 | ||
4a64f543 MS |
7943 | /* Field 4, the address, is omitted (which makes the columns not |
7944 | line up too nicely with the headers, but the effect is relatively | |
7945 | readable). */ | |
79a45b7d | 7946 | if (opts.addressprint) |
112e8700 | 7947 | uiout->field_skip ("addr"); |
ce78b96d | 7948 | annotate_field (5); |
112e8700 | 7949 | uiout->text ("fork"); |
e29a4733 | 7950 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 7951 | { |
112e8700 SM |
7952 | uiout->text (", process "); |
7953 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
7954 | uiout->spaces (1); | |
ce78b96d | 7955 | } |
8ac3646f | 7956 | |
112e8700 SM |
7957 | if (uiout->is_mi_like_p ()) |
7958 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
7959 | } |
7960 | ||
7961 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7962 | catchpoints. */ | |
7963 | ||
7964 | static void | |
7965 | print_mention_catch_fork (struct breakpoint *b) | |
7966 | { | |
7967 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7968 | } | |
7969 | ||
6149aea9 PA |
7970 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7971 | catchpoints. */ | |
7972 | ||
7973 | static void | |
7974 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7975 | { | |
7976 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7977 | print_recreate_thread (b, fp); |
6149aea9 PA |
7978 | } |
7979 | ||
ce78b96d JB |
7980 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7981 | ||
2060206e | 7982 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7983 | |
4a64f543 MS |
7984 | /* Implement the "insert" breakpoint_ops method for vfork |
7985 | catchpoints. */ | |
ce78b96d | 7986 | |
77b06cd7 TJB |
7987 | static int |
7988 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7989 | { |
dfd4cc63 | 7990 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7991 | } |
7992 | ||
4a64f543 MS |
7993 | /* Implement the "remove" breakpoint_ops method for vfork |
7994 | catchpoints. */ | |
ce78b96d JB |
7995 | |
7996 | static int | |
73971819 | 7997 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7998 | { |
dfd4cc63 | 7999 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8000 | } |
8001 | ||
8002 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8003 | catchpoints. */ | |
8004 | ||
8005 | static int | |
f1310107 | 8006 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8007 | struct address_space *aspace, CORE_ADDR bp_addr, |
8008 | const struct target_waitstatus *ws) | |
ce78b96d | 8009 | { |
e29a4733 PA |
8010 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8011 | ||
f90263c1 TT |
8012 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8013 | return 0; | |
8014 | ||
8015 | c->forked_inferior_pid = ws->value.related_pid; | |
8016 | return 1; | |
ce78b96d JB |
8017 | } |
8018 | ||
4a64f543 MS |
8019 | /* Implement the "print_it" breakpoint_ops method for vfork |
8020 | catchpoints. */ | |
ce78b96d JB |
8021 | |
8022 | static enum print_stop_action | |
348d480f | 8023 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8024 | { |
36dfb11c | 8025 | struct ui_out *uiout = current_uiout; |
348d480f | 8026 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8027 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8028 | ||
ce78b96d | 8029 | annotate_catchpoint (b->number); |
f303dbd6 | 8030 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8031 | if (b->disposition == disp_del) |
112e8700 | 8032 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8033 | else |
112e8700 SM |
8034 | uiout->text ("Catchpoint "); |
8035 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8036 | { |
112e8700 SM |
8037 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
8038 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8039 | } |
112e8700 SM |
8040 | uiout->field_int ("bkptno", b->number); |
8041 | uiout->text (" (vforked process "); | |
8042 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8043 | uiout->text ("), "); | |
ce78b96d JB |
8044 | return PRINT_SRC_AND_LOC; |
8045 | } | |
8046 | ||
4a64f543 MS |
8047 | /* Implement the "print_one" breakpoint_ops method for vfork |
8048 | catchpoints. */ | |
ce78b96d JB |
8049 | |
8050 | static void | |
a6d9a66e | 8051 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8052 | { |
e29a4733 | 8053 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8054 | struct value_print_options opts; |
79a45e25 | 8055 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8056 | |
8057 | get_user_print_options (&opts); | |
4a64f543 MS |
8058 | /* Field 4, the address, is omitted (which makes the columns not |
8059 | line up too nicely with the headers, but the effect is relatively | |
8060 | readable). */ | |
79a45b7d | 8061 | if (opts.addressprint) |
112e8700 | 8062 | uiout->field_skip ("addr"); |
ce78b96d | 8063 | annotate_field (5); |
112e8700 | 8064 | uiout->text ("vfork"); |
e29a4733 | 8065 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8066 | { |
112e8700 SM |
8067 | uiout->text (", process "); |
8068 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8069 | uiout->spaces (1); | |
ce78b96d | 8070 | } |
8ac3646f | 8071 | |
112e8700 SM |
8072 | if (uiout->is_mi_like_p ()) |
8073 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
8074 | } |
8075 | ||
8076 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8077 | catchpoints. */ | |
8078 | ||
8079 | static void | |
8080 | print_mention_catch_vfork (struct breakpoint *b) | |
8081 | { | |
8082 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8083 | } | |
8084 | ||
6149aea9 PA |
8085 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8086 | catchpoints. */ | |
8087 | ||
8088 | static void | |
8089 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8090 | { | |
8091 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8092 | print_recreate_thread (b, fp); |
6149aea9 PA |
8093 | } |
8094 | ||
ce78b96d JB |
8095 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8096 | ||
2060206e | 8097 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8098 | |
edcc5120 | 8099 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 8100 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
8101 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
8102 | ||
c1fc2657 | 8103 | struct solib_catchpoint : public breakpoint |
edcc5120 | 8104 | { |
c1fc2657 | 8105 | ~solib_catchpoint () override; |
edcc5120 TT |
8106 | |
8107 | /* True for "catch load", false for "catch unload". */ | |
8108 | unsigned char is_load; | |
8109 | ||
8110 | /* Regular expression to match, if any. COMPILED is only valid when | |
8111 | REGEX is non-NULL. */ | |
8112 | char *regex; | |
2d7cc5c7 | 8113 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
8114 | }; |
8115 | ||
c1fc2657 | 8116 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 8117 | { |
c1fc2657 | 8118 | xfree (this->regex); |
edcc5120 TT |
8119 | } |
8120 | ||
8121 | static int | |
8122 | insert_catch_solib (struct bp_location *ignore) | |
8123 | { | |
8124 | return 0; | |
8125 | } | |
8126 | ||
8127 | static int | |
73971819 | 8128 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8129 | { |
8130 | return 0; | |
8131 | } | |
8132 | ||
8133 | static int | |
8134 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8135 | struct address_space *aspace, | |
8136 | CORE_ADDR bp_addr, | |
8137 | const struct target_waitstatus *ws) | |
8138 | { | |
8139 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8140 | struct breakpoint *other; | |
8141 | ||
8142 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8143 | return 1; | |
8144 | ||
8145 | ALL_BREAKPOINTS (other) | |
8146 | { | |
8147 | struct bp_location *other_bl; | |
8148 | ||
8149 | if (other == bl->owner) | |
8150 | continue; | |
8151 | ||
8152 | if (other->type != bp_shlib_event) | |
8153 | continue; | |
8154 | ||
c1fc2657 | 8155 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
8156 | continue; |
8157 | ||
8158 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8159 | { | |
8160 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8161 | return 1; | |
8162 | } | |
8163 | } | |
8164 | ||
8165 | return 0; | |
8166 | } | |
8167 | ||
8168 | static void | |
8169 | check_status_catch_solib (struct bpstats *bs) | |
8170 | { | |
8171 | struct solib_catchpoint *self | |
8172 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8173 | int ix; | |
8174 | ||
8175 | if (self->is_load) | |
8176 | { | |
8177 | struct so_list *iter; | |
8178 | ||
8179 | for (ix = 0; | |
8180 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8181 | ix, iter); | |
8182 | ++ix) | |
8183 | { | |
8184 | if (!self->regex | |
2d7cc5c7 | 8185 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
8186 | return; |
8187 | } | |
8188 | } | |
8189 | else | |
8190 | { | |
8191 | char *iter; | |
8192 | ||
8193 | for (ix = 0; | |
8194 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8195 | ix, iter); | |
8196 | ++ix) | |
8197 | { | |
8198 | if (!self->regex | |
2d7cc5c7 | 8199 | || self->compiled->exec (iter, 0, NULL, 0) == 0) |
edcc5120 TT |
8200 | return; |
8201 | } | |
8202 | } | |
8203 | ||
8204 | bs->stop = 0; | |
8205 | bs->print_it = print_it_noop; | |
8206 | } | |
8207 | ||
8208 | static enum print_stop_action | |
8209 | print_it_catch_solib (bpstat bs) | |
8210 | { | |
8211 | struct breakpoint *b = bs->breakpoint_at; | |
8212 | struct ui_out *uiout = current_uiout; | |
8213 | ||
8214 | annotate_catchpoint (b->number); | |
f303dbd6 | 8215 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8216 | if (b->disposition == disp_del) |
112e8700 | 8217 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8218 | else |
112e8700 SM |
8219 | uiout->text ("Catchpoint "); |
8220 | uiout->field_int ("bkptno", b->number); | |
8221 | uiout->text ("\n"); | |
8222 | if (uiout->is_mi_like_p ()) | |
8223 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8224 | print_solib_event (1); |
8225 | return PRINT_SRC_AND_LOC; | |
8226 | } | |
8227 | ||
8228 | static void | |
8229 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8230 | { | |
8231 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8232 | struct value_print_options opts; | |
8233 | struct ui_out *uiout = current_uiout; | |
8234 | char *msg; | |
8235 | ||
8236 | get_user_print_options (&opts); | |
8237 | /* Field 4, the address, is omitted (which makes the columns not | |
8238 | line up too nicely with the headers, but the effect is relatively | |
8239 | readable). */ | |
8240 | if (opts.addressprint) | |
8241 | { | |
8242 | annotate_field (4); | |
112e8700 | 8243 | uiout->field_skip ("addr"); |
edcc5120 TT |
8244 | } |
8245 | ||
8246 | annotate_field (5); | |
8247 | if (self->is_load) | |
8248 | { | |
8249 | if (self->regex) | |
8250 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8251 | else | |
8252 | msg = xstrdup (_("load of library")); | |
8253 | } | |
8254 | else | |
8255 | { | |
8256 | if (self->regex) | |
8257 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8258 | else | |
8259 | msg = xstrdup (_("unload of library")); | |
8260 | } | |
112e8700 | 8261 | uiout->field_string ("what", msg); |
edcc5120 | 8262 | xfree (msg); |
8ac3646f | 8263 | |
112e8700 SM |
8264 | if (uiout->is_mi_like_p ()) |
8265 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8266 | } |
8267 | ||
8268 | static void | |
8269 | print_mention_catch_solib (struct breakpoint *b) | |
8270 | { | |
8271 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8272 | ||
8273 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8274 | self->is_load ? "load" : "unload"); | |
8275 | } | |
8276 | ||
8277 | static void | |
8278 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8279 | { | |
8280 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8281 | ||
8282 | fprintf_unfiltered (fp, "%s %s", | |
8283 | b->disposition == disp_del ? "tcatch" : "catch", | |
8284 | self->is_load ? "load" : "unload"); | |
8285 | if (self->regex) | |
8286 | fprintf_unfiltered (fp, " %s", self->regex); | |
8287 | fprintf_unfiltered (fp, "\n"); | |
8288 | } | |
8289 | ||
8290 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8291 | ||
91985142 MG |
8292 | /* Shared helper function (MI and CLI) for creating and installing |
8293 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8294 | the events to be caught are load events, otherwise they are | |
8295 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8296 | temporary one. If ENABLED is non-zero the catchpoint is | |
8297 | created in an enabled state. */ | |
edcc5120 | 8298 | |
91985142 | 8299 | void |
a121b7c1 | 8300 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8301 | { |
edcc5120 | 8302 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8303 | |
edcc5120 TT |
8304 | if (!arg) |
8305 | arg = ""; | |
f1735a53 | 8306 | arg = skip_spaces (arg); |
edcc5120 | 8307 | |
36bd8eaa | 8308 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8309 | |
8310 | if (*arg != '\0') | |
8311 | { | |
2d7cc5c7 PA |
8312 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8313 | _("Invalid regexp"))); | |
edcc5120 TT |
8314 | c->regex = xstrdup (arg); |
8315 | } | |
8316 | ||
8317 | c->is_load = is_load; | |
36bd8eaa | 8318 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8319 | &catch_solib_breakpoint_ops); |
8320 | ||
c1fc2657 | 8321 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8322 | |
b270e6f9 | 8323 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8324 | } |
8325 | ||
91985142 MG |
8326 | /* A helper function that does all the work for "catch load" and |
8327 | "catch unload". */ | |
8328 | ||
8329 | static void | |
8330 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8331 | struct cmd_list_element *command) | |
8332 | { | |
8333 | int tempflag; | |
8334 | const int enabled = 1; | |
8335 | ||
8336 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8337 | ||
8338 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8339 | } | |
8340 | ||
edcc5120 TT |
8341 | static void |
8342 | catch_load_command_1 (char *arg, int from_tty, | |
8343 | struct cmd_list_element *command) | |
8344 | { | |
8345 | catch_load_or_unload (arg, from_tty, 1, command); | |
8346 | } | |
8347 | ||
8348 | static void | |
8349 | catch_unload_command_1 (char *arg, int from_tty, | |
8350 | struct cmd_list_element *command) | |
8351 | { | |
8352 | catch_load_or_unload (arg, from_tty, 0, command); | |
8353 | } | |
8354 | ||
346774a9 PA |
8355 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8356 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8357 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8358 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8359 | |
ab04a2af | 8360 | void |
346774a9 PA |
8361 | init_catchpoint (struct breakpoint *b, |
8362 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8363 | const char *cond_string, |
c0a91b2b | 8364 | const struct breakpoint_ops *ops) |
c906108c | 8365 | { |
51abb421 | 8366 | symtab_and_line sal; |
6c95b8df | 8367 | sal.pspace = current_program_space; |
c5aa993b | 8368 | |
28010a5d | 8369 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8370 | |
1b36a34b | 8371 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8372 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8373 | } |
8374 | ||
28010a5d | 8375 | void |
b270e6f9 | 8376 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8377 | { |
b270e6f9 | 8378 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8379 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8380 | if (is_tracepoint (b)) |
8381 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8382 | if (!internal) |
8383 | mention (b); | |
c56053d2 | 8384 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8385 | |
8386 | if (update_gll) | |
44702360 | 8387 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8388 | } |
8389 | ||
9b70b993 | 8390 | static void |
a6d9a66e | 8391 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8392 | int tempflag, const char *cond_string, |
c0a91b2b | 8393 | const struct breakpoint_ops *ops) |
c906108c | 8394 | { |
b270e6f9 | 8395 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8396 | |
b270e6f9 | 8397 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8398 | |
8399 | c->forked_inferior_pid = null_ptid; | |
8400 | ||
b270e6f9 | 8401 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8402 | } |
8403 | ||
fe798b75 JB |
8404 | /* Exec catchpoints. */ |
8405 | ||
b4d90040 | 8406 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8407 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8408 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8409 | ||
c1fc2657 | 8410 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8411 | { |
c1fc2657 | 8412 | ~exec_catchpoint () override; |
b4d90040 PA |
8413 | |
8414 | /* Filename of a program whose exec triggered this catchpoint. | |
8415 | This field is only valid immediately after this catchpoint has | |
8416 | triggered. */ | |
8417 | char *exec_pathname; | |
8418 | }; | |
8419 | ||
c1fc2657 | 8420 | /* Exec catchpoint destructor. */ |
b4d90040 | 8421 | |
c1fc2657 | 8422 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8423 | { |
c1fc2657 | 8424 | xfree (this->exec_pathname); |
b4d90040 PA |
8425 | } |
8426 | ||
77b06cd7 TJB |
8427 | static int |
8428 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8429 | { |
dfd4cc63 | 8430 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8431 | } |
c906108c | 8432 | |
fe798b75 | 8433 | static int |
73971819 | 8434 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8435 | { |
dfd4cc63 | 8436 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8437 | } |
c906108c | 8438 | |
fe798b75 | 8439 | static int |
f1310107 | 8440 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8441 | struct address_space *aspace, CORE_ADDR bp_addr, |
8442 | const struct target_waitstatus *ws) | |
fe798b75 | 8443 | { |
b4d90040 PA |
8444 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8445 | ||
f90263c1 TT |
8446 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8447 | return 0; | |
8448 | ||
8449 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8450 | return 1; | |
fe798b75 | 8451 | } |
c906108c | 8452 | |
fe798b75 | 8453 | static enum print_stop_action |
348d480f | 8454 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8455 | { |
36dfb11c | 8456 | struct ui_out *uiout = current_uiout; |
348d480f | 8457 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8458 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8459 | ||
fe798b75 | 8460 | annotate_catchpoint (b->number); |
f303dbd6 | 8461 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8462 | if (b->disposition == disp_del) |
112e8700 | 8463 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8464 | else |
112e8700 SM |
8465 | uiout->text ("Catchpoint "); |
8466 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8467 | { |
112e8700 SM |
8468 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8469 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8470 | } |
112e8700 SM |
8471 | uiout->field_int ("bkptno", b->number); |
8472 | uiout->text (" (exec'd "); | |
8473 | uiout->field_string ("new-exec", c->exec_pathname); | |
8474 | uiout->text ("), "); | |
36dfb11c | 8475 | |
fe798b75 | 8476 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8477 | } |
8478 | ||
fe798b75 | 8479 | static void |
a6d9a66e | 8480 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8481 | { |
b4d90040 | 8482 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8483 | struct value_print_options opts; |
79a45e25 | 8484 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8485 | |
8486 | get_user_print_options (&opts); | |
8487 | ||
8488 | /* Field 4, the address, is omitted (which makes the columns | |
8489 | not line up too nicely with the headers, but the effect | |
8490 | is relatively readable). */ | |
8491 | if (opts.addressprint) | |
112e8700 | 8492 | uiout->field_skip ("addr"); |
fe798b75 | 8493 | annotate_field (5); |
112e8700 | 8494 | uiout->text ("exec"); |
b4d90040 | 8495 | if (c->exec_pathname != NULL) |
fe798b75 | 8496 | { |
112e8700 SM |
8497 | uiout->text (", program \""); |
8498 | uiout->field_string ("what", c->exec_pathname); | |
8499 | uiout->text ("\" "); | |
fe798b75 | 8500 | } |
8ac3646f | 8501 | |
112e8700 SM |
8502 | if (uiout->is_mi_like_p ()) |
8503 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8504 | } |
8505 | ||
8506 | static void | |
8507 | print_mention_catch_exec (struct breakpoint *b) | |
8508 | { | |
8509 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8510 | } | |
8511 | ||
6149aea9 PA |
8512 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8513 | catchpoints. */ | |
8514 | ||
8515 | static void | |
8516 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8517 | { | |
8518 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8519 | print_recreate_thread (b, fp); |
6149aea9 PA |
8520 | } |
8521 | ||
2060206e | 8522 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8523 | |
c906108c | 8524 | static int |
fba45db2 | 8525 | hw_breakpoint_used_count (void) |
c906108c | 8526 | { |
c906108c | 8527 | int i = 0; |
f1310107 TJB |
8528 | struct breakpoint *b; |
8529 | struct bp_location *bl; | |
c906108c SS |
8530 | |
8531 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8532 | { |
d6b74ac4 | 8533 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8534 | for (bl = b->loc; bl; bl = bl->next) |
8535 | { | |
8536 | /* Special types of hardware breakpoints may use more than | |
8537 | one register. */ | |
348d480f | 8538 | i += b->ops->resources_needed (bl); |
f1310107 | 8539 | } |
c5aa993b | 8540 | } |
c906108c SS |
8541 | |
8542 | return i; | |
8543 | } | |
8544 | ||
a1398e0c PA |
8545 | /* Returns the resources B would use if it were a hardware |
8546 | watchpoint. */ | |
8547 | ||
c906108c | 8548 | static int |
a1398e0c | 8549 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8550 | { |
c906108c | 8551 | int i = 0; |
e09342b5 | 8552 | struct bp_location *bl; |
c906108c | 8553 | |
a1398e0c PA |
8554 | if (!breakpoint_enabled (b)) |
8555 | return 0; | |
8556 | ||
8557 | for (bl = b->loc; bl; bl = bl->next) | |
8558 | { | |
8559 | /* Special types of hardware watchpoints may use more than | |
8560 | one register. */ | |
8561 | i += b->ops->resources_needed (bl); | |
8562 | } | |
8563 | ||
8564 | return i; | |
8565 | } | |
8566 | ||
8567 | /* Returns the sum the used resources of all hardware watchpoints of | |
8568 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8569 | the sum of the used resources of all hardware watchpoints of other | |
8570 | types _not_ TYPE. */ | |
8571 | ||
8572 | static int | |
8573 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8574 | enum bptype type, int *other_type_used) | |
8575 | { | |
8576 | int i = 0; | |
8577 | struct breakpoint *b; | |
8578 | ||
c906108c SS |
8579 | *other_type_used = 0; |
8580 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8581 | { |
a1398e0c PA |
8582 | if (b == except) |
8583 | continue; | |
e09342b5 TJB |
8584 | if (!breakpoint_enabled (b)) |
8585 | continue; | |
8586 | ||
a1398e0c PA |
8587 | if (b->type == type) |
8588 | i += hw_watchpoint_use_count (b); | |
8589 | else if (is_hardware_watchpoint (b)) | |
8590 | *other_type_used = 1; | |
e09342b5 TJB |
8591 | } |
8592 | ||
c906108c SS |
8593 | return i; |
8594 | } | |
8595 | ||
c906108c | 8596 | void |
fba45db2 | 8597 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8598 | { |
c5aa993b | 8599 | struct breakpoint *b; |
c906108c SS |
8600 | |
8601 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8602 | { |
cc60f2e3 | 8603 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8604 | { |
b5de0fa7 | 8605 | b->enable_state = bp_call_disabled; |
44702360 | 8606 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8607 | } |
8608 | } | |
c906108c SS |
8609 | } |
8610 | ||
8611 | void | |
fba45db2 | 8612 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8613 | { |
c5aa993b | 8614 | struct breakpoint *b; |
c906108c SS |
8615 | |
8616 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8617 | { |
cc60f2e3 | 8618 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8619 | { |
b5de0fa7 | 8620 | b->enable_state = bp_enabled; |
44702360 | 8621 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8622 | } |
8623 | } | |
c906108c SS |
8624 | } |
8625 | ||
8bea4e01 UW |
8626 | void |
8627 | disable_breakpoints_before_startup (void) | |
8628 | { | |
6c95b8df | 8629 | current_program_space->executing_startup = 1; |
44702360 | 8630 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8631 | } |
8632 | ||
8633 | void | |
8634 | enable_breakpoints_after_startup (void) | |
8635 | { | |
6c95b8df | 8636 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8637 | breakpoint_re_set (); |
8bea4e01 UW |
8638 | } |
8639 | ||
7c16b83e PA |
8640 | /* Create a new single-step breakpoint for thread THREAD, with no |
8641 | locations. */ | |
c906108c | 8642 | |
7c16b83e PA |
8643 | static struct breakpoint * |
8644 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8645 | { | |
b270e6f9 | 8646 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8647 | |
b270e6f9 | 8648 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8649 | &momentary_breakpoint_ops); |
8650 | ||
8651 | b->disposition = disp_donttouch; | |
8652 | b->frame_id = null_frame_id; | |
8653 | ||
8654 | b->thread = thread; | |
8655 | gdb_assert (b->thread != 0); | |
8656 | ||
b270e6f9 | 8657 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8658 | } |
8659 | ||
8660 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8661 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8662 | frame. */ | |
c906108c SS |
8663 | |
8664 | struct breakpoint * | |
a6d9a66e UW |
8665 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8666 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8667 | { |
52f0bd74 | 8668 | struct breakpoint *b; |
edb3359d | 8669 | |
193facb3 JK |
8670 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8671 | tail-called one. */ | |
8672 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8673 | |
06edf0c0 | 8674 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8675 | b->enable_state = bp_enabled; |
8676 | b->disposition = disp_donttouch; | |
818dd999 | 8677 | b->frame_id = frame_id; |
c906108c | 8678 | |
4a64f543 MS |
8679 | /* If we're debugging a multi-threaded program, then we want |
8680 | momentary breakpoints to be active in only a single thread of | |
8681 | control. */ | |
39f77062 | 8682 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8683 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8684 | |
44702360 | 8685 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8686 | |
c906108c SS |
8687 | return b; |
8688 | } | |
611c83ae | 8689 | |
06edf0c0 | 8690 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8691 | The new breakpoint will have type TYPE, use OPS as its |
8692 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8693 | |
06edf0c0 PA |
8694 | static struct breakpoint * |
8695 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8696 | enum bptype type, | |
a1aa2221 LM |
8697 | const struct breakpoint_ops *ops, |
8698 | int loc_enabled) | |
e58b0e63 PA |
8699 | { |
8700 | struct breakpoint *copy; | |
8701 | ||
06edf0c0 | 8702 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8703 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8704 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8705 | |
a6d9a66e | 8706 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8707 | copy->loc->requested_address = orig->loc->requested_address; |
8708 | copy->loc->address = orig->loc->address; | |
8709 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8710 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8711 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8712 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8713 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8714 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8715 | copy->frame_id = orig->frame_id; |
8716 | copy->thread = orig->thread; | |
6c95b8df | 8717 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8718 | |
8719 | copy->enable_state = bp_enabled; | |
8720 | copy->disposition = disp_donttouch; | |
8721 | copy->number = internal_breakpoint_number--; | |
8722 | ||
44702360 | 8723 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8724 | return copy; |
8725 | } | |
8726 | ||
06edf0c0 PA |
8727 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8728 | ORIG is NULL. */ | |
8729 | ||
8730 | struct breakpoint * | |
8731 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8732 | { | |
8733 | /* If there's nothing to clone, then return nothing. */ | |
8734 | if (orig == NULL) | |
8735 | return NULL; | |
8736 | ||
a1aa2221 | 8737 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8738 | } |
8739 | ||
611c83ae | 8740 | struct breakpoint * |
a6d9a66e UW |
8741 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8742 | enum bptype type) | |
611c83ae PA |
8743 | { |
8744 | struct symtab_and_line sal; | |
8745 | ||
8746 | sal = find_pc_line (pc, 0); | |
8747 | sal.pc = pc; | |
8748 | sal.section = find_pc_overlay (pc); | |
8749 | sal.explicit_pc = 1; | |
8750 | ||
a6d9a66e | 8751 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8752 | } |
c906108c | 8753 | \f |
c5aa993b | 8754 | |
c906108c SS |
8755 | /* Tell the user we have just set a breakpoint B. */ |
8756 | ||
8757 | static void | |
fba45db2 | 8758 | mention (struct breakpoint *b) |
c906108c | 8759 | { |
348d480f | 8760 | b->ops->print_mention (b); |
112e8700 | 8761 | if (current_uiout->is_mi_like_p ()) |
fb40c209 | 8762 | return; |
c906108c SS |
8763 | printf_filtered ("\n"); |
8764 | } | |
c906108c | 8765 | \f |
c5aa993b | 8766 | |
1a853c52 PA |
8767 | static int bp_loc_is_permanent (struct bp_location *loc); |
8768 | ||
0d381245 | 8769 | static struct bp_location * |
39d61571 | 8770 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8771 | const struct symtab_and_line *sal) |
8772 | { | |
8773 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8774 | CORE_ADDR adjusted_address; |
8775 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8776 | ||
8777 | if (loc_gdbarch == NULL) | |
8778 | loc_gdbarch = b->gdbarch; | |
8779 | ||
8780 | /* Adjust the breakpoint's address prior to allocating a location. | |
8781 | Once we call allocate_bp_location(), that mostly uninitialized | |
8782 | location will be placed on the location chain. Adjustment of the | |
8783 | breakpoint may cause target_read_memory() to be called and we do | |
8784 | not want its scan of the location chain to find a breakpoint and | |
8785 | location that's only been partially initialized. */ | |
8786 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8787 | sal->pc, b->type); | |
0d381245 | 8788 | |
d30113d4 | 8789 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8790 | loc = allocate_bp_location (b); |
d30113d4 JK |
8791 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8792 | tmp = &((*tmp)->next)) | |
0d381245 | 8793 | ; |
d30113d4 | 8794 | loc->next = *tmp; |
0d381245 | 8795 | *tmp = loc; |
3742cc8b | 8796 | |
0d381245 | 8797 | loc->requested_address = sal->pc; |
3742cc8b | 8798 | loc->address = adjusted_address; |
6c95b8df | 8799 | loc->pspace = sal->pspace; |
729662a5 TT |
8800 | loc->probe.probe = sal->probe; |
8801 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 8802 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8803 | loc->section = sal->section; |
3742cc8b | 8804 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8805 | loc->line_number = sal->line; |
2f202fde | 8806 | loc->symtab = sal->symtab; |
f8eba3c6 | 8807 | |
0e30163f JK |
8808 | set_breakpoint_location_function (loc, |
8809 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 8810 | |
6ae88661 LM |
8811 | /* While by definition, permanent breakpoints are already present in the |
8812 | code, we don't mark the location as inserted. Normally one would expect | |
8813 | that GDB could rely on that breakpoint instruction to stop the program, | |
8814 | thus removing the need to insert its own breakpoint, except that executing | |
8815 | the breakpoint instruction can kill the target instead of reporting a | |
8816 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8817 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8818 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8819 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8820 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8821 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8822 | it manually increments the PC, thus avoiding executing the breakpoint | |
8823 | instruction.) */ | |
1a853c52 | 8824 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8825 | loc->permanent = 1; |
1a853c52 | 8826 | |
0d381245 VP |
8827 | return loc; |
8828 | } | |
514f746b AR |
8829 | \f |
8830 | ||
1cf4d951 | 8831 | /* See breakpoint.h. */ |
514f746b | 8832 | |
1cf4d951 PA |
8833 | int |
8834 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8835 | { |
8836 | int len; | |
8837 | CORE_ADDR addr; | |
1afeeb75 | 8838 | const gdb_byte *bpoint; |
514f746b AR |
8839 | gdb_byte *target_mem; |
8840 | ||
1cf4d951 PA |
8841 | addr = address; |
8842 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8843 | ||
8844 | /* Software breakpoints unsupported? */ | |
8845 | if (bpoint == NULL) | |
8846 | return 0; | |
8847 | ||
224c3ddb | 8848 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
8849 | |
8850 | /* Enable the automatic memory restoration from breakpoints while | |
8851 | we read the memory. Otherwise we could say about our temporary | |
8852 | breakpoints they are permanent. */ | |
cb85b21b TT |
8853 | scoped_restore restore_memory |
8854 | = make_scoped_restore_show_memory_breakpoints (0); | |
1cf4d951 PA |
8855 | |
8856 | if (target_read_memory (address, target_mem, len) == 0 | |
8857 | && memcmp (target_mem, bpoint, len) == 0) | |
cb85b21b | 8858 | return 1; |
1cf4d951 | 8859 | |
cb85b21b | 8860 | return 0; |
1cf4d951 PA |
8861 | } |
8862 | ||
8863 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8864 | return 0 otherwise. */ | |
8865 | ||
8866 | static int | |
8867 | bp_loc_is_permanent (struct bp_location *loc) | |
8868 | { | |
514f746b AR |
8869 | gdb_assert (loc != NULL); |
8870 | ||
244558af LM |
8871 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
8872 | attempt to read from the addresses the locations of these breakpoint types | |
8873 | point to. program_breakpoint_here_p, below, will attempt to read | |
8874 | memory. */ | |
8875 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
8876 | return 0; | |
8877 | ||
5ed8105e | 8878 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8879 | switch_to_program_space_and_thread (loc->pspace); |
5ed8105e | 8880 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8881 | } |
8882 | ||
e7e0cddf SS |
8883 | /* Build a command list for the dprintf corresponding to the current |
8884 | settings of the dprintf style options. */ | |
8885 | ||
8886 | static void | |
8887 | update_dprintf_command_list (struct breakpoint *b) | |
8888 | { | |
8889 | char *dprintf_args = b->extra_string; | |
8890 | char *printf_line = NULL; | |
8891 | ||
8892 | if (!dprintf_args) | |
8893 | return; | |
8894 | ||
8895 | dprintf_args = skip_spaces (dprintf_args); | |
8896 | ||
8897 | /* Allow a comma, as it may have terminated a location, but don't | |
8898 | insist on it. */ | |
8899 | if (*dprintf_args == ',') | |
8900 | ++dprintf_args; | |
8901 | dprintf_args = skip_spaces (dprintf_args); | |
8902 | ||
8903 | if (*dprintf_args != '"') | |
8904 | error (_("Bad format string, missing '\"'.")); | |
8905 | ||
d3ce09f5 | 8906 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8907 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8908 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8909 | { |
8910 | if (!dprintf_function) | |
8911 | error (_("No function supplied for dprintf call")); | |
8912 | ||
8913 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8914 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8915 | dprintf_function, | |
8916 | dprintf_channel, | |
8917 | dprintf_args); | |
8918 | else | |
8919 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8920 | dprintf_function, | |
8921 | dprintf_args); | |
8922 | } | |
d3ce09f5 SS |
8923 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8924 | { | |
8925 | if (target_can_run_breakpoint_commands ()) | |
8926 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8927 | else | |
8928 | { | |
8929 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8930 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8931 | } | |
8932 | } | |
e7e0cddf SS |
8933 | else |
8934 | internal_error (__FILE__, __LINE__, | |
8935 | _("Invalid dprintf style.")); | |
8936 | ||
f28045c2 | 8937 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 8938 | /* Manufacture a printf sequence. */ |
f28045c2 | 8939 | { |
8d749320 | 8940 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 8941 | |
f28045c2 YQ |
8942 | printf_cmd_line->control_type = simple_control; |
8943 | printf_cmd_line->body_count = 0; | |
8944 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 8945 | printf_cmd_line->next = NULL; |
f28045c2 | 8946 | printf_cmd_line->line = printf_line; |
e7e0cddf | 8947 | |
93921405 | 8948 | breakpoint_set_commands (b, command_line_up (printf_cmd_line)); |
f28045c2 | 8949 | } |
e7e0cddf SS |
8950 | } |
8951 | ||
8952 | /* Update all dprintf commands, making their command lists reflect | |
8953 | current style settings. */ | |
8954 | ||
8955 | static void | |
8956 | update_dprintf_commands (char *args, int from_tty, | |
8957 | struct cmd_list_element *c) | |
8958 | { | |
8959 | struct breakpoint *b; | |
8960 | ||
8961 | ALL_BREAKPOINTS (b) | |
8962 | { | |
8963 | if (b->type == bp_dprintf) | |
8964 | update_dprintf_command_list (b); | |
8965 | } | |
8966 | } | |
c3f6f71d | 8967 | |
f00aae0f KS |
8968 | /* Create a breakpoint with SAL as location. Use LOCATION |
8969 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8970 | as condition expression. If LOCATION is NULL then create an |
8971 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8972 | |
8973 | static void | |
d9b3f62e | 8974 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8975 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8976 | event_location_up &&location, |
e1e01040 PA |
8977 | gdb::unique_xmalloc_ptr<char> filter, |
8978 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8979 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8980 | enum bptype type, enum bpdisp disposition, |
8981 | int thread, int task, int ignore_count, | |
c0a91b2b | 8982 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8983 | int enabled, int internal, unsigned flags, |
8984 | int display_canonical) | |
018d34a4 | 8985 | { |
0d381245 | 8986 | int i; |
018d34a4 VP |
8987 | |
8988 | if (type == bp_hardware_breakpoint) | |
8989 | { | |
fbbd034e AS |
8990 | int target_resources_ok; |
8991 | ||
8992 | i = hw_breakpoint_used_count (); | |
8993 | target_resources_ok = | |
8994 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8995 | i + 1, 0); |
8996 | if (target_resources_ok == 0) | |
8997 | error (_("No hardware breakpoint support in the target.")); | |
8998 | else if (target_resources_ok < 0) | |
8999 | error (_("Hardware breakpoints used exceeds limit.")); | |
9000 | } | |
9001 | ||
6c5b2ebe | 9002 | gdb_assert (!sals.empty ()); |
6c95b8df | 9003 | |
6c5b2ebe | 9004 | for (const auto &sal : sals) |
0d381245 | 9005 | { |
0d381245 VP |
9006 | struct bp_location *loc; |
9007 | ||
9008 | if (from_tty) | |
5af949e3 UW |
9009 | { |
9010 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9011 | if (!loc_gdbarch) | |
9012 | loc_gdbarch = gdbarch; | |
9013 | ||
9014 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9015 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9016 | } |
0d381245 | 9017 | |
6c5b2ebe | 9018 | if (&sal == &sals[0]) |
0d381245 | 9019 | { |
d9b3f62e | 9020 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9021 | b->thread = thread; |
4a306c9a | 9022 | b->task = task; |
855a6e68 | 9023 | |
e1e01040 PA |
9024 | b->cond_string = cond_string.release (); |
9025 | b->extra_string = extra_string.release (); | |
0d381245 | 9026 | b->ignore_count = ignore_count; |
41447f92 | 9027 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9028 | b->disposition = disposition; |
6c95b8df | 9029 | |
44f238bb PA |
9030 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9031 | b->loc->inserted = 1; | |
9032 | ||
0fb4aa4b PA |
9033 | if (type == bp_static_tracepoint) |
9034 | { | |
d9b3f62e | 9035 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9036 | struct static_tracepoint_marker marker; |
9037 | ||
983af33b | 9038 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9039 | { |
9040 | /* We already know the marker exists, otherwise, we | |
9041 | wouldn't see a sal for it. */ | |
d28cd78a TT |
9042 | const char *p |
9043 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 9044 | const char *endp; |
0fb4aa4b | 9045 | char *marker_str; |
0fb4aa4b | 9046 | |
f1735a53 | 9047 | p = skip_spaces (p); |
0fb4aa4b | 9048 | |
f1735a53 | 9049 | endp = skip_to_space (p); |
0fb4aa4b PA |
9050 | |
9051 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9052 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9053 | |
3e43a32a MS |
9054 | printf_filtered (_("Probed static tracepoint " |
9055 | "marker \"%s\"\n"), | |
d9b3f62e | 9056 | t->static_trace_marker_id); |
0fb4aa4b PA |
9057 | } |
9058 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9059 | { | |
d9b3f62e | 9060 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9061 | release_static_tracepoint_marker (&marker); |
9062 | ||
3e43a32a MS |
9063 | printf_filtered (_("Probed static tracepoint " |
9064 | "marker \"%s\"\n"), | |
d9b3f62e | 9065 | t->static_trace_marker_id); |
0fb4aa4b PA |
9066 | } |
9067 | else | |
3e43a32a MS |
9068 | warning (_("Couldn't determine the static " |
9069 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9070 | } |
9071 | ||
0d381245 VP |
9072 | loc = b->loc; |
9073 | } | |
9074 | else | |
018d34a4 | 9075 | { |
39d61571 | 9076 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9077 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9078 | loc->inserted = 1; | |
0d381245 VP |
9079 | } |
9080 | ||
9081 | if (b->cond_string) | |
9082 | { | |
bbc13ae3 KS |
9083 | const char *arg = b->cond_string; |
9084 | ||
1bb9788d TT |
9085 | loc->cond = parse_exp_1 (&arg, loc->address, |
9086 | block_for_pc (loc->address), 0); | |
0d381245 | 9087 | if (*arg) |
588ae58c | 9088 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9089 | } |
e7e0cddf SS |
9090 | |
9091 | /* Dynamic printf requires and uses additional arguments on the | |
9092 | command line, otherwise it's an error. */ | |
9093 | if (type == bp_dprintf) | |
9094 | { | |
9095 | if (b->extra_string) | |
9096 | update_dprintf_command_list (b); | |
9097 | else | |
9098 | error (_("Format string required")); | |
9099 | } | |
9100 | else if (b->extra_string) | |
588ae58c | 9101 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9102 | } |
018d34a4 | 9103 | |
56435ebe | 9104 | b->display_canonical = display_canonical; |
f00aae0f | 9105 | if (location != NULL) |
d28cd78a | 9106 | b->location = std::move (location); |
018d34a4 | 9107 | else |
d28cd78a | 9108 | b->location = new_address_location (b->loc->address, NULL, 0); |
e1e01040 | 9109 | b->filter = filter.release (); |
d9b3f62e | 9110 | } |
018d34a4 | 9111 | |
d9b3f62e PA |
9112 | static void |
9113 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 9114 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9115 | event_location_up &&location, |
e1e01040 PA |
9116 | gdb::unique_xmalloc_ptr<char> filter, |
9117 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9118 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9119 | enum bptype type, enum bpdisp disposition, |
9120 | int thread, int task, int ignore_count, | |
c0a91b2b | 9121 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9122 | int enabled, int internal, unsigned flags, |
9123 | int display_canonical) | |
d9b3f62e | 9124 | { |
a5e364af | 9125 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 9126 | |
a5e364af | 9127 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 9128 | sals, std::move (location), |
e1e01040 PA |
9129 | std::move (filter), |
9130 | std::move (cond_string), | |
9131 | std::move (extra_string), | |
d9b3f62e PA |
9132 | type, disposition, |
9133 | thread, task, ignore_count, | |
9134 | ops, from_tty, | |
44f238bb PA |
9135 | enabled, internal, flags, |
9136 | display_canonical); | |
d9b3f62e | 9137 | |
b270e6f9 | 9138 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
9139 | } |
9140 | ||
9141 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9142 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9143 | value. COND_STRING, if not NULL, specified the condition to be | |
9144 | used for all breakpoints. Essentially the only case where | |
9145 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9146 | function. In that case, it's still not possible to specify | |
9147 | separate conditions for different overloaded functions, so | |
9148 | we take just a single condition string. | |
9149 | ||
c3f6f71d | 9150 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9151 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9152 | array contents). If the function fails (error() is called), the |
9153 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9154 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9155 | |
9156 | static void | |
8cdf0e15 | 9157 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9158 | struct linespec_result *canonical, |
e1e01040 PA |
9159 | gdb::unique_xmalloc_ptr<char> cond_string, |
9160 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
9161 | enum bptype type, enum bpdisp disposition, |
9162 | int thread, int task, int ignore_count, | |
c0a91b2b | 9163 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9164 | int enabled, int internal, unsigned flags) |
c906108c | 9165 | { |
f8eba3c6 | 9166 | if (canonical->pre_expanded) |
6c5b2ebe | 9167 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 9168 | |
6c5b2ebe | 9169 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 9170 | { |
f00aae0f | 9171 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9172 | 'break', without arguments. */ |
ffc2605c | 9173 | event_location_up location |
f00aae0f | 9174 | = (canonical->location != NULL |
8e9e35b1 | 9175 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 9176 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 9177 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 9178 | |
6c5b2ebe | 9179 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 9180 | std::move (location), |
e1e01040 PA |
9181 | std::move (filter_string), |
9182 | std::move (cond_string), | |
9183 | std::move (extra_string), | |
e7e0cddf | 9184 | type, disposition, |
84f4c1fe | 9185 | thread, task, ignore_count, ops, |
44f238bb | 9186 | from_tty, enabled, internal, flags, |
56435ebe | 9187 | canonical->special_display); |
c3f6f71d | 9188 | } |
c3f6f71d | 9189 | } |
c906108c | 9190 | |
f00aae0f | 9191 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9192 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9193 | addresses found. LOCATION points to the end of the SAL (for |
9194 | linespec locations). | |
9998af43 TJB |
9195 | |
9196 | The array and the line spec strings are allocated on the heap, it is | |
9197 | the caller's responsibility to free them. */ | |
c906108c | 9198 | |
b9362cc7 | 9199 | static void |
f00aae0f | 9200 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9201 | struct linespec_result *canonical) |
c3f6f71d | 9202 | { |
f00aae0f KS |
9203 | struct symtab_and_line cursal; |
9204 | ||
9205 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9206 | { | |
9207 | const char *address = get_linespec_location (location); | |
9208 | ||
9209 | if (address == NULL) | |
9210 | { | |
9211 | /* The last displayed codepoint, if it's valid, is our default | |
9212 | breakpoint address. */ | |
9213 | if (last_displayed_sal_is_valid ()) | |
9214 | { | |
f00aae0f KS |
9215 | /* Set sal's pspace, pc, symtab, and line to the values |
9216 | corresponding to the last call to print_frame_info. | |
9217 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9218 | as the breakpoint line number is inappropriate otherwise. | |
9219 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
9220 | symtab_and_line sal = get_last_displayed_sal (); |
9221 | CORE_ADDR pc = sal.pc; | |
9222 | ||
f00aae0f KS |
9223 | sal = find_pc_line (pc, 0); |
9224 | ||
9225 | /* "break" without arguments is equivalent to "break *PC" | |
9226 | where PC is the last displayed codepoint's address. So | |
9227 | make sure to set sal.explicit_pc to prevent GDB from | |
9228 | trying to expand the list of sals to include all other | |
9229 | instances with the same symtab and line. */ | |
9230 | sal.pc = pc; | |
9231 | sal.explicit_pc = 1; | |
9232 | ||
6c5b2ebe PA |
9233 | struct linespec_sals lsal; |
9234 | lsal.sals = {sal}; | |
f00aae0f KS |
9235 | lsal.canonical = NULL; |
9236 | ||
6c5b2ebe | 9237 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
9238 | return; |
9239 | } | |
9240 | else | |
9241 | error (_("No default breakpoint address now.")); | |
c906108c | 9242 | } |
c906108c | 9243 | } |
f00aae0f KS |
9244 | |
9245 | /* Force almost all breakpoints to be in terms of the | |
9246 | current_source_symtab (which is decode_line_1's default). | |
9247 | This should produce the results we want almost all of the | |
9248 | time while leaving default_breakpoint_* alone. | |
9249 | ||
9250 | ObjC: However, don't match an Objective-C method name which | |
9251 | may have a '+' or '-' succeeded by a '['. */ | |
9252 | cursal = get_current_source_symtab_and_line (); | |
9253 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9254 | { |
f00aae0f | 9255 | const char *address = NULL; |
cc80f267 | 9256 | |
f00aae0f KS |
9257 | if (event_location_type (location) == LINESPEC_LOCATION) |
9258 | address = get_linespec_location (location); | |
cc80f267 | 9259 | |
f00aae0f KS |
9260 | if (!cursal.symtab |
9261 | || (address != NULL | |
9262 | && strchr ("+-", address[0]) != NULL | |
9263 | && address[1] != '[')) | |
9264 | { | |
c2f4122d | 9265 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9266 | get_last_displayed_symtab (), |
9267 | get_last_displayed_line (), | |
9268 | canonical, NULL, NULL); | |
9269 | return; | |
9270 | } | |
c906108c | 9271 | } |
f00aae0f | 9272 | |
c2f4122d | 9273 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9274 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9275 | } |
c906108c | 9276 | |
c906108c | 9277 | |
c3f6f71d | 9278 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9279 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9280 | |
b9362cc7 | 9281 | static void |
6c5b2ebe | 9282 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9283 | { |
6c5b2ebe PA |
9284 | for (auto &sal : sals) |
9285 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9286 | } |
9287 | ||
7a697b8d SS |
9288 | /* Fast tracepoints may have restrictions on valid locations. For |
9289 | instance, a fast tracepoint using a jump instead of a trap will | |
9290 | likely have to overwrite more bytes than a trap would, and so can | |
9291 | only be placed where the instruction is longer than the jump, or a | |
9292 | multi-instruction sequence does not have a jump into the middle of | |
9293 | it, etc. */ | |
9294 | ||
9295 | static void | |
9296 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9297 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9298 | { |
6c5b2ebe | 9299 | int rslt; |
7a697b8d SS |
9300 | char *msg; |
9301 | struct cleanup *old_chain; | |
9302 | ||
6c5b2ebe | 9303 | for (const auto &sal : sals) |
7a697b8d | 9304 | { |
f8eba3c6 TT |
9305 | struct gdbarch *sarch; |
9306 | ||
6c5b2ebe | 9307 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9308 | /* We fall back to GDBARCH if there is no architecture |
9309 | associated with SAL. */ | |
9310 | if (sarch == NULL) | |
9311 | sarch = gdbarch; | |
6c5b2ebe | 9312 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg); |
7a697b8d SS |
9313 | old_chain = make_cleanup (xfree, msg); |
9314 | ||
9315 | if (!rslt) | |
53c3572a | 9316 | error (_("May not have a fast tracepoint at %s%s"), |
6c5b2ebe | 9317 | paddress (sarch, sal.pc), (msg ? msg : "")); |
7a697b8d SS |
9318 | |
9319 | do_cleanups (old_chain); | |
9320 | } | |
9321 | } | |
9322 | ||
018d34a4 VP |
9323 | /* Given TOK, a string specification of condition and thread, as |
9324 | accepted by the 'break' command, extract the condition | |
9325 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9326 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9327 | If no condition is found, *COND_STRING is set to NULL. |
9328 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9329 | |
9330 | static void | |
bbc13ae3 | 9331 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9332 | char **cond_string, int *thread, int *task, |
9333 | char **rest) | |
018d34a4 VP |
9334 | { |
9335 | *cond_string = NULL; | |
9336 | *thread = -1; | |
ed1d1739 KS |
9337 | *task = 0; |
9338 | *rest = NULL; | |
9339 | ||
018d34a4 VP |
9340 | while (tok && *tok) |
9341 | { | |
bbc13ae3 | 9342 | const char *end_tok; |
018d34a4 | 9343 | int toklen; |
bbc13ae3 KS |
9344 | const char *cond_start = NULL; |
9345 | const char *cond_end = NULL; | |
cc59ec59 | 9346 | |
f1735a53 | 9347 | tok = skip_spaces (tok); |
e7e0cddf SS |
9348 | |
9349 | if ((*tok == '"' || *tok == ',') && rest) | |
9350 | { | |
9351 | *rest = savestring (tok, strlen (tok)); | |
9352 | return; | |
9353 | } | |
9354 | ||
f1735a53 | 9355 | end_tok = skip_to_space (tok); |
d634f2de | 9356 | |
018d34a4 | 9357 | toklen = end_tok - tok; |
d634f2de | 9358 | |
018d34a4 VP |
9359 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9360 | { | |
9361 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9362 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9363 | cond_end = tok; |
d634f2de | 9364 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9365 | } |
9366 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9367 | { | |
5d5658a1 PA |
9368 | const char *tmptok; |
9369 | struct thread_info *thr; | |
d634f2de | 9370 | |
018d34a4 | 9371 | tok = end_tok + 1; |
5d5658a1 | 9372 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9373 | if (tok == tmptok) |
9374 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9375 | *thread = thr->global_num; |
bbc13ae3 | 9376 | tok = tmptok; |
018d34a4 | 9377 | } |
4a306c9a JB |
9378 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9379 | { | |
9380 | char *tmptok; | |
9381 | ||
9382 | tok = end_tok + 1; | |
bbc13ae3 | 9383 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9384 | if (tok == tmptok) |
9385 | error (_("Junk after task keyword.")); | |
9386 | if (!valid_task_id (*task)) | |
b6199126 | 9387 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9388 | tok = tmptok; |
4a306c9a | 9389 | } |
e7e0cddf SS |
9390 | else if (rest) |
9391 | { | |
9392 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9393 | return; |
e7e0cddf | 9394 | } |
018d34a4 VP |
9395 | else |
9396 | error (_("Junk at end of arguments.")); | |
9397 | } | |
9398 | } | |
9399 | ||
0fb4aa4b PA |
9400 | /* Decode a static tracepoint marker spec. */ |
9401 | ||
6c5b2ebe | 9402 | static std::vector<symtab_and_line> |
f00aae0f | 9403 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9404 | { |
9405 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
0fb4aa4b | 9406 | struct cleanup *old_chain; |
f00aae0f KS |
9407 | const char *p = &(*arg_p)[3]; |
9408 | const char *endp; | |
0fb4aa4b PA |
9409 | char *marker_str; |
9410 | int i; | |
9411 | ||
f1735a53 | 9412 | p = skip_spaces (p); |
0fb4aa4b | 9413 | |
f1735a53 | 9414 | endp = skip_to_space (p); |
0fb4aa4b PA |
9415 | |
9416 | marker_str = savestring (p, endp - p); | |
9417 | old_chain = make_cleanup (xfree, marker_str); | |
9418 | ||
9419 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9420 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9421 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9422 | ||
6c5b2ebe PA |
9423 | std::vector<symtab_and_line> sals; |
9424 | sals.reserve (VEC_length(static_tracepoint_marker_p, markers)); | |
0fb4aa4b | 9425 | |
6c5b2ebe | 9426 | for (i = 0; i < VEC_length(static_tracepoint_marker_p, markers); i++) |
0fb4aa4b PA |
9427 | { |
9428 | struct static_tracepoint_marker *marker; | |
9429 | ||
9430 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9431 | ||
51abb421 | 9432 | symtab_and_line sal = find_pc_line (marker->address, 0); |
6c5b2ebe PA |
9433 | sal.pc = marker->address; |
9434 | sals.push_back (sal); | |
0fb4aa4b PA |
9435 | |
9436 | release_static_tracepoint_marker (marker); | |
9437 | } | |
9438 | ||
9439 | do_cleanups (old_chain); | |
9440 | ||
9441 | *arg_p = endp; | |
9442 | return sals; | |
9443 | } | |
9444 | ||
f00aae0f | 9445 | /* See breakpoint.h. */ |
0101ce28 | 9446 | |
8cdf0e15 VP |
9447 | int |
9448 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9449 | const struct event_location *location, |
9450 | const char *cond_string, | |
9451 | int thread, const char *extra_string, | |
f00aae0f | 9452 | int parse_extra, |
0fb4aa4b | 9453 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9454 | int ignore_count, |
9455 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9456 | const struct breakpoint_ops *ops, |
44f238bb PA |
9457 | int from_tty, int enabled, int internal, |
9458 | unsigned flags) | |
c3f6f71d | 9459 | { |
7efd8fc2 | 9460 | struct linespec_result canonical; |
80c99de1 | 9461 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9462 | int pending = 0; |
4a306c9a | 9463 | int task = 0; |
86b17b60 | 9464 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9465 | |
348d480f PA |
9466 | gdb_assert (ops != NULL); |
9467 | ||
f00aae0f KS |
9468 | /* If extra_string isn't useful, set it to NULL. */ |
9469 | if (extra_string != NULL && *extra_string == '\0') | |
9470 | extra_string = NULL; | |
9471 | ||
492d29ea | 9472 | TRY |
b78a6381 | 9473 | { |
f00aae0f | 9474 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9475 | } |
492d29ea | 9476 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9477 | { |
492d29ea PA |
9478 | /* If caller is interested in rc value from parse, set |
9479 | value. */ | |
9480 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9481 | { |
05ff989b AC |
9482 | /* If pending breakpoint support is turned off, throw |
9483 | error. */ | |
fa8d40ab JJ |
9484 | |
9485 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9486 | throw_exception (e); |
9487 | ||
9488 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9489 | |
05ff989b AC |
9490 | /* If pending breakpoint support is auto query and the user |
9491 | selects no, then simply return the error code. */ | |
059fb39f | 9492 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9493 | && !nquery (_("Make %s pending on future shared library load? "), |
9494 | bptype_string (type_wanted))) | |
fd9b8c24 | 9495 | return 0; |
fa8d40ab | 9496 | |
05ff989b AC |
9497 | /* At this point, either the user was queried about setting |
9498 | a pending breakpoint and selected yes, or pending | |
9499 | breakpoint behavior is on and thus a pending breakpoint | |
9500 | is defaulted on behalf of the user. */ | |
f00aae0f | 9501 | pending = 1; |
0101ce28 | 9502 | } |
492d29ea PA |
9503 | else |
9504 | throw_exception (e); | |
0101ce28 | 9505 | } |
492d29ea PA |
9506 | END_CATCH |
9507 | ||
6c5b2ebe | 9508 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9509 | return 0; |
c3f6f71d | 9510 | |
c3f6f71d JM |
9511 | /* ----------------------------- SNIP ----------------------------- |
9512 | Anything added to the cleanup chain beyond this point is assumed | |
9513 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9514 | then the memory is not reclaimed. */ |
9515 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9516 | |
c3f6f71d JM |
9517 | /* Resolve all line numbers to PC's and verify that the addresses |
9518 | are ok for the target. */ | |
0101ce28 | 9519 | if (!pending) |
f8eba3c6 | 9520 | { |
6c5b2ebe PA |
9521 | for (auto &lsal : canonical.lsals) |
9522 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9523 | } |
c3f6f71d | 9524 | |
7a697b8d | 9525 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9526 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9527 | { |
6c5b2ebe PA |
9528 | for (const auto &lsal : canonical.lsals) |
9529 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9530 | } |
7a697b8d | 9531 | |
c3f6f71d JM |
9532 | /* Verify that condition can be parsed, before setting any |
9533 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9534 | breakpoint. */ |
0101ce28 | 9535 | if (!pending) |
c3f6f71d | 9536 | { |
e1e01040 PA |
9537 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9538 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9539 | ||
f00aae0f | 9540 | if (parse_extra) |
72b2ff0e | 9541 | { |
0878d0fa | 9542 | char *rest; |
e1e01040 | 9543 | char *cond; |
52d361e1 | 9544 | |
6c5b2ebe | 9545 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9546 | |
0878d0fa YQ |
9547 | /* Here we only parse 'arg' to separate condition |
9548 | from thread number, so parsing in context of first | |
9549 | sal is OK. When setting the breakpoint we'll | |
9550 | re-parse it in context of each sal. */ | |
9551 | ||
6c5b2ebe | 9552 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9553 | &cond, &thread, &task, &rest); |
9554 | cond_string_copy.reset (cond); | |
9555 | extra_string_copy.reset (rest); | |
72b2ff0e | 9556 | } |
2f069f6f | 9557 | else |
72b2ff0e | 9558 | { |
f00aae0f KS |
9559 | if (type_wanted != bp_dprintf |
9560 | && extra_string != NULL && *extra_string != '\0') | |
9561 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9562 | |
9563 | /* Create a private copy of condition string. */ | |
9564 | if (cond_string) | |
e1e01040 | 9565 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9566 | /* Create a private copy of any extra string. */ |
9567 | if (extra_string) | |
e1e01040 | 9568 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9569 | } |
0fb4aa4b | 9570 | |
52d361e1 | 9571 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9572 | std::move (cond_string_copy), |
9573 | std::move (extra_string_copy), | |
9574 | type_wanted, | |
d9b3f62e PA |
9575 | tempflag ? disp_del : disp_donttouch, |
9576 | thread, task, ignore_count, ops, | |
44f238bb | 9577 | from_tty, enabled, internal, flags); |
c906108c | 9578 | } |
0101ce28 JJ |
9579 | else |
9580 | { | |
a5e364af | 9581 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9582 | |
a5e364af | 9583 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9584 | b->location = copy_event_location (location); |
bfccc43c | 9585 | |
f00aae0f KS |
9586 | if (parse_extra) |
9587 | b->cond_string = NULL; | |
e12c7713 MK |
9588 | else |
9589 | { | |
9590 | /* Create a private copy of condition string. */ | |
e1e01040 | 9591 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9592 | b->thread = thread; |
e12c7713 | 9593 | } |
f00aae0f KS |
9594 | |
9595 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9596 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9597 | b->ignore_count = ignore_count; |
0101ce28 | 9598 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9599 | b->condition_not_parsed = 1; |
41447f92 | 9600 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9601 | if ((type_wanted != bp_breakpoint |
9602 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9603 | b->pspace = current_program_space; |
8bea4e01 | 9604 | |
b270e6f9 | 9605 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9606 | } |
9607 | ||
6c5b2ebe | 9608 | if (canonical.lsals.size () > 1) |
95a42b64 | 9609 | { |
3e43a32a MS |
9610 | warning (_("Multiple breakpoints were set.\nUse the " |
9611 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9612 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9613 | } |
9614 | ||
80c99de1 PA |
9615 | /* That's it. Discard the cleanups for data inserted into the |
9616 | breakpoint. */ | |
9617 | discard_cleanups (bkpt_chain); | |
217dc9e2 | 9618 | |
80c99de1 | 9619 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9620 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9621 | |
9622 | return 1; | |
c3f6f71d | 9623 | } |
c906108c | 9624 | |
348d480f | 9625 | /* Set a breakpoint. |
72b2ff0e VP |
9626 | ARG is a string describing breakpoint address, |
9627 | condition, and thread. | |
9628 | FLAG specifies if a breakpoint is hardware on, | |
9629 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9630 | and BP_TEMPFLAG. */ | |
348d480f | 9631 | |
98deb0da | 9632 | static void |
f2fc3015 | 9633 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9634 | { |
72b2ff0e | 9635 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9636 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9637 | ? bp_hardware_breakpoint | |
9638 | : bp_breakpoint); | |
55aa24fb | 9639 | struct breakpoint_ops *ops; |
f00aae0f | 9640 | |
ffc2605c | 9641 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9642 | |
9643 | /* Matching breakpoints on probes. */ | |
5b56227b | 9644 | if (location != NULL |
ffc2605c | 9645 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9646 | ops = &bkpt_probe_breakpoint_ops; |
9647 | else | |
9648 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9649 | |
8cdf0e15 | 9650 | create_breakpoint (get_current_arch (), |
ffc2605c | 9651 | location.get (), |
f00aae0f | 9652 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9653 | tempflag, type_wanted, |
8cdf0e15 VP |
9654 | 0 /* Ignore count */, |
9655 | pending_break_support, | |
55aa24fb | 9656 | ops, |
8cdf0e15 | 9657 | from_tty, |
84f4c1fe | 9658 | 1 /* enabled */, |
44f238bb PA |
9659 | 0 /* internal */, |
9660 | 0); | |
c906108c SS |
9661 | } |
9662 | ||
c906108c SS |
9663 | /* Helper function for break_command_1 and disassemble_command. */ |
9664 | ||
9665 | void | |
fba45db2 | 9666 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9667 | { |
9668 | CORE_ADDR pc; | |
9669 | ||
9670 | if (sal->pc == 0 && sal->symtab != NULL) | |
9671 | { | |
9672 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9673 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9674 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9675 | sal->pc = pc; |
6a048695 | 9676 | |
4a64f543 MS |
9677 | /* If this SAL corresponds to a breakpoint inserted using a line |
9678 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9679 | if (sal->explicit_line) |
059acae7 | 9680 | skip_prologue_sal (sal); |
c906108c SS |
9681 | } |
9682 | ||
9683 | if (sal->section == 0 && sal->symtab != NULL) | |
9684 | { | |
346d1dfe | 9685 | const struct blockvector *bv; |
3977b71f | 9686 | const struct block *b; |
c5aa993b | 9687 | struct symbol *sym; |
c906108c | 9688 | |
43f3e411 DE |
9689 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9690 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9691 | if (bv != NULL) |
9692 | { | |
7f0df278 | 9693 | sym = block_linkage_function (b); |
c906108c SS |
9694 | if (sym != NULL) |
9695 | { | |
eb822aa6 DE |
9696 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9697 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9698 | sym); | |
c906108c SS |
9699 | } |
9700 | else | |
9701 | { | |
4a64f543 MS |
9702 | /* It really is worthwhile to have the section, so we'll |
9703 | just have to look harder. This case can be executed | |
9704 | if we have line numbers but no functions (as can | |
9705 | happen in assembly source). */ | |
c906108c | 9706 | |
5ed8105e | 9707 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9708 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9709 | |
5ed8105e | 9710 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9711 | if (msym.minsym) |
efd66ac6 | 9712 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9713 | } |
9714 | } | |
9715 | } | |
9716 | } | |
9717 | ||
9718 | void | |
fba45db2 | 9719 | break_command (char *arg, int from_tty) |
c906108c | 9720 | { |
db107f19 | 9721 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9722 | } |
9723 | ||
c906108c | 9724 | void |
fba45db2 | 9725 | tbreak_command (char *arg, int from_tty) |
c906108c | 9726 | { |
db107f19 | 9727 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9728 | } |
9729 | ||
c906108c | 9730 | static void |
fba45db2 | 9731 | hbreak_command (char *arg, int from_tty) |
c906108c | 9732 | { |
db107f19 | 9733 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9734 | } |
9735 | ||
9736 | static void | |
fba45db2 | 9737 | thbreak_command (char *arg, int from_tty) |
c906108c | 9738 | { |
db107f19 | 9739 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9740 | } |
9741 | ||
9742 | static void | |
fba45db2 | 9743 | stop_command (char *arg, int from_tty) |
c906108c | 9744 | { |
a3f17187 | 9745 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9746 | Usage: stop in <function | address>\n\ |
a3f17187 | 9747 | stop at <line>\n")); |
c906108c SS |
9748 | } |
9749 | ||
9750 | static void | |
4495129a | 9751 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9752 | { |
9753 | int badInput = 0; | |
9754 | ||
c5aa993b | 9755 | if (arg == (char *) NULL) |
c906108c SS |
9756 | badInput = 1; |
9757 | else if (*arg != '*') | |
9758 | { | |
4495129a | 9759 | const char *argptr = arg; |
c906108c SS |
9760 | int hasColon = 0; |
9761 | ||
4a64f543 | 9762 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9763 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9764 | function/method name. */ |
c906108c | 9765 | while (*argptr && !hasColon) |
c5aa993b JM |
9766 | { |
9767 | hasColon = (*argptr == ':'); | |
9768 | argptr++; | |
9769 | } | |
c906108c SS |
9770 | |
9771 | if (hasColon) | |
c5aa993b | 9772 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9773 | else |
c5aa993b | 9774 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9775 | } |
9776 | ||
9777 | if (badInput) | |
a3f17187 | 9778 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9779 | else |
db107f19 | 9780 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9781 | } |
9782 | ||
9783 | static void | |
4495129a | 9784 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9785 | { |
9786 | int badInput = 0; | |
9787 | ||
c5aa993b | 9788 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9789 | badInput = 1; |
9790 | else | |
9791 | { | |
4495129a | 9792 | const char *argptr = arg; |
c906108c SS |
9793 | int hasColon = 0; |
9794 | ||
4a64f543 MS |
9795 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9796 | it is probably a line number. */ | |
c906108c | 9797 | while (*argptr && !hasColon) |
c5aa993b JM |
9798 | { |
9799 | hasColon = (*argptr == ':'); | |
9800 | argptr++; | |
9801 | } | |
c906108c SS |
9802 | |
9803 | if (hasColon) | |
c5aa993b | 9804 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9805 | else |
c5aa993b | 9806 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9807 | } |
9808 | ||
9809 | if (badInput) | |
a3f17187 | 9810 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9811 | else |
db107f19 | 9812 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9813 | } |
9814 | ||
e7e0cddf SS |
9815 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9816 | with a prewired command list consisting of a single output command, | |
9817 | built from extra arguments supplied on the dprintf command | |
9818 | line. */ | |
9819 | ||
da821c7b | 9820 | static void |
f2fc3015 | 9821 | dprintf_command (char *arg_in, int from_tty) |
e7e0cddf | 9822 | { |
f2fc3015 | 9823 | const char *arg = arg_in; |
ffc2605c | 9824 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9825 | |
9826 | /* If non-NULL, ARG should have been advanced past the location; | |
9827 | the next character must be ','. */ | |
9828 | if (arg != NULL) | |
9829 | { | |
9830 | if (arg[0] != ',' || arg[1] == '\0') | |
9831 | error (_("Format string required")); | |
9832 | else | |
9833 | { | |
9834 | /* Skip the comma. */ | |
9835 | ++arg; | |
9836 | } | |
9837 | } | |
9838 | ||
e7e0cddf | 9839 | create_breakpoint (get_current_arch (), |
ffc2605c | 9840 | location.get (), |
f00aae0f | 9841 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9842 | 0, bp_dprintf, |
9843 | 0 /* Ignore count */, | |
9844 | pending_break_support, | |
9845 | &dprintf_breakpoint_ops, | |
9846 | from_tty, | |
9847 | 1 /* enabled */, | |
9848 | 0 /* internal */, | |
9849 | 0); | |
9850 | } | |
9851 | ||
d3ce09f5 SS |
9852 | static void |
9853 | agent_printf_command (char *arg, int from_tty) | |
9854 | { | |
9855 | error (_("May only run agent-printf on the target")); | |
9856 | } | |
9857 | ||
f1310107 TJB |
9858 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9859 | ranged breakpoints. */ | |
9860 | ||
9861 | static int | |
9862 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
9863 | struct address_space *aspace, | |
09ac7c10 TT |
9864 | CORE_ADDR bp_addr, |
9865 | const struct target_waitstatus *ws) | |
f1310107 | 9866 | { |
09ac7c10 | 9867 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9868 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9869 | return 0; |
9870 | ||
f1310107 TJB |
9871 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9872 | bl->length, aspace, bp_addr); | |
9873 | } | |
9874 | ||
9875 | /* Implement the "resources_needed" breakpoint_ops method for | |
9876 | ranged breakpoints. */ | |
9877 | ||
9878 | static int | |
9879 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9880 | { | |
9881 | return target_ranged_break_num_registers (); | |
9882 | } | |
9883 | ||
9884 | /* Implement the "print_it" breakpoint_ops method for | |
9885 | ranged breakpoints. */ | |
9886 | ||
9887 | static enum print_stop_action | |
348d480f | 9888 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9889 | { |
348d480f | 9890 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9891 | struct bp_location *bl = b->loc; |
79a45e25 | 9892 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9893 | |
9894 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9895 | ||
9896 | /* Ranged breakpoints have only one location. */ | |
9897 | gdb_assert (bl && bl->next == NULL); | |
9898 | ||
9899 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9900 | |
9901 | maybe_print_thread_hit_breakpoint (uiout); | |
9902 | ||
f1310107 | 9903 | if (b->disposition == disp_del) |
112e8700 | 9904 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9905 | else |
112e8700 SM |
9906 | uiout->text ("Ranged breakpoint "); |
9907 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9908 | { |
112e8700 | 9909 | uiout->field_string ("reason", |
f1310107 | 9910 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9911 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9912 | } |
112e8700 SM |
9913 | uiout->field_int ("bkptno", b->number); |
9914 | uiout->text (", "); | |
f1310107 TJB |
9915 | |
9916 | return PRINT_SRC_AND_LOC; | |
9917 | } | |
9918 | ||
9919 | /* Implement the "print_one" breakpoint_ops method for | |
9920 | ranged breakpoints. */ | |
9921 | ||
9922 | static void | |
9923 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9924 | struct bp_location **last_loc) | |
9925 | { | |
9926 | struct bp_location *bl = b->loc; | |
9927 | struct value_print_options opts; | |
79a45e25 | 9928 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9929 | |
9930 | /* Ranged breakpoints have only one location. */ | |
9931 | gdb_assert (bl && bl->next == NULL); | |
9932 | ||
9933 | get_user_print_options (&opts); | |
9934 | ||
9935 | if (opts.addressprint) | |
9936 | /* We don't print the address range here, it will be printed later | |
9937 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9938 | uiout->field_skip ("addr"); |
f1310107 TJB |
9939 | annotate_field (5); |
9940 | print_breakpoint_location (b, bl); | |
9941 | *last_loc = bl; | |
9942 | } | |
9943 | ||
9944 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9945 | ranged breakpoints. */ | |
9946 | ||
9947 | static void | |
9948 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9949 | struct ui_out *uiout) | |
9950 | { | |
9951 | CORE_ADDR address_start, address_end; | |
9952 | struct bp_location *bl = b->loc; | |
d7e74731 | 9953 | string_file stb; |
f1310107 TJB |
9954 | |
9955 | gdb_assert (bl); | |
9956 | ||
9957 | address_start = bl->address; | |
9958 | address_end = address_start + bl->length - 1; | |
9959 | ||
112e8700 | 9960 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9961 | stb.printf ("[%s, %s]", |
9962 | print_core_address (bl->gdbarch, address_start), | |
9963 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9964 | uiout->field_stream ("addr", stb); |
9965 | uiout->text ("\n"); | |
f1310107 TJB |
9966 | } |
9967 | ||
9968 | /* Implement the "print_mention" breakpoint_ops method for | |
9969 | ranged breakpoints. */ | |
9970 | ||
9971 | static void | |
9972 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9973 | { | |
9974 | struct bp_location *bl = b->loc; | |
79a45e25 | 9975 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9976 | |
9977 | gdb_assert (bl); | |
9978 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9979 | ||
112e8700 | 9980 | if (uiout->is_mi_like_p ()) |
f1310107 TJB |
9981 | return; |
9982 | ||
9983 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
9984 | b->number, paddress (bl->gdbarch, bl->address), | |
9985 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
9986 | } | |
9987 | ||
9988 | /* Implement the "print_recreate" breakpoint_ops method for | |
9989 | ranged breakpoints. */ | |
9990 | ||
9991 | static void | |
9992 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9993 | { | |
f00aae0f | 9994 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9995 | event_location_to_string (b->location.get ()), |
9996 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9997 | print_recreate_thread (b, fp); |
f1310107 TJB |
9998 | } |
9999 | ||
10000 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10001 | ||
2060206e | 10002 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10003 | |
10004 | /* Find the address where the end of the breakpoint range should be | |
10005 | placed, given the SAL of the end of the range. This is so that if | |
10006 | the user provides a line number, the end of the range is set to the | |
10007 | last instruction of the given line. */ | |
10008 | ||
10009 | static CORE_ADDR | |
10010 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10011 | { | |
10012 | CORE_ADDR end; | |
10013 | ||
10014 | /* If the user provided a PC value, use it. Otherwise, | |
10015 | find the address of the end of the given location. */ | |
10016 | if (sal.explicit_pc) | |
10017 | end = sal.pc; | |
10018 | else | |
10019 | { | |
10020 | int ret; | |
10021 | CORE_ADDR start; | |
10022 | ||
10023 | ret = find_line_pc_range (sal, &start, &end); | |
10024 | if (!ret) | |
10025 | error (_("Could not find location of the end of the range.")); | |
10026 | ||
10027 | /* find_line_pc_range returns the start of the next line. */ | |
10028 | end--; | |
10029 | } | |
10030 | ||
10031 | return end; | |
10032 | } | |
10033 | ||
10034 | /* Implement the "break-range" CLI command. */ | |
10035 | ||
10036 | static void | |
f2fc3015 | 10037 | break_range_command (char *arg_in, int from_tty) |
f1310107 | 10038 | { |
f2fc3015 TT |
10039 | const char *arg = arg_in; |
10040 | const char *arg_start; | |
10041 | char *addr_string_start; | |
f1310107 TJB |
10042 | struct linespec_result canonical_start, canonical_end; |
10043 | int bp_count, can_use_bp, length; | |
10044 | CORE_ADDR end; | |
10045 | struct breakpoint *b; | |
f1310107 TJB |
10046 | struct cleanup *cleanup_bkpt; |
10047 | ||
10048 | /* We don't support software ranged breakpoints. */ | |
10049 | if (target_ranged_break_num_registers () < 0) | |
10050 | error (_("This target does not support hardware ranged breakpoints.")); | |
10051 | ||
10052 | bp_count = hw_breakpoint_used_count (); | |
10053 | bp_count += target_ranged_break_num_registers (); | |
10054 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10055 | bp_count, 0); | |
10056 | if (can_use_bp < 0) | |
10057 | error (_("Hardware breakpoints used exceeds limit.")); | |
10058 | ||
f8eba3c6 | 10059 | arg = skip_spaces (arg); |
f1310107 TJB |
10060 | if (arg == NULL || arg[0] == '\0') |
10061 | error(_("No address range specified.")); | |
10062 | ||
f8eba3c6 | 10063 | arg_start = arg; |
ffc2605c TT |
10064 | event_location_up start_location = string_to_event_location (&arg, |
10065 | current_language); | |
10066 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
10067 | |
10068 | if (arg[0] != ',') | |
10069 | error (_("Too few arguments.")); | |
6c5b2ebe | 10070 | else if (canonical_start.lsals.empty ()) |
f1310107 | 10071 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 10072 | |
6c5b2ebe | 10073 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 10074 | |
6c5b2ebe PA |
10075 | if (canonical_start.lsals.size () > 1 |
10076 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
10077 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10078 | ||
6c5b2ebe | 10079 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
f8eba3c6 | 10080 | addr_string_start = savestring (arg_start, arg - arg_start); |
16e802b9 | 10081 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); |
f1310107 TJB |
10082 | |
10083 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10084 | arg = skip_spaces (arg); |
f1310107 TJB |
10085 | |
10086 | /* Parse the end location. */ | |
10087 | ||
f1310107 TJB |
10088 | arg_start = arg; |
10089 | ||
f8eba3c6 | 10090 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10091 | parse_breakpoint_sals because we need to specify the start location's |
10092 | symtab and line as the default symtab and line for the end of the | |
10093 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10094 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
10095 | event_location_up end_location = string_to_event_location (&arg, |
10096 | current_language); | |
10097 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
10098 | sal_start.symtab, sal_start.line, |
10099 | &canonical_end, NULL, NULL); | |
10100 | ||
6c5b2ebe | 10101 | if (canonical_end.lsals.empty ()) |
f1310107 | 10102 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 10103 | |
6c5b2ebe PA |
10104 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
10105 | if (canonical_end.lsals.size () > 1 | |
10106 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
10107 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10108 | ||
6c5b2ebe | 10109 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
10110 | |
10111 | end = find_breakpoint_range_end (sal_end); | |
10112 | if (sal_start.pc > end) | |
177b42fe | 10113 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10114 | |
10115 | length = end - sal_start.pc + 1; | |
10116 | if (length < 0) | |
10117 | /* Length overflowed. */ | |
10118 | error (_("Address range too large.")); | |
10119 | else if (length == 1) | |
10120 | { | |
10121 | /* This range is simple enough to be handled by | |
10122 | the `hbreak' command. */ | |
10123 | hbreak_command (addr_string_start, 1); | |
10124 | ||
10125 | do_cleanups (cleanup_bkpt); | |
10126 | ||
10127 | return; | |
10128 | } | |
10129 | ||
10130 | /* Now set up the breakpoint. */ | |
10131 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10132 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10133 | set_breakpoint_count (breakpoint_count + 1); |
10134 | b->number = breakpoint_count; | |
10135 | b->disposition = disp_donttouch; | |
d28cd78a TT |
10136 | b->location = std::move (start_location); |
10137 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
10138 | b->loc->length = length; |
10139 | ||
f8eba3c6 | 10140 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10141 | |
10142 | mention (b); | |
8d3788bd | 10143 | observer_notify_breakpoint_created (b); |
44702360 | 10144 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10145 | } |
10146 | ||
4a64f543 MS |
10147 | /* Return non-zero if EXP is verified as constant. Returned zero |
10148 | means EXP is variable. Also the constant detection may fail for | |
10149 | some constant expressions and in such case still falsely return | |
10150 | zero. */ | |
2e6e3d9c | 10151 | |
65d79d4b SDJ |
10152 | static int |
10153 | watchpoint_exp_is_const (const struct expression *exp) | |
10154 | { | |
10155 | int i = exp->nelts; | |
10156 | ||
10157 | while (i > 0) | |
10158 | { | |
10159 | int oplenp, argsp; | |
10160 | ||
10161 | /* We are only interested in the descriptor of each element. */ | |
10162 | operator_length (exp, i, &oplenp, &argsp); | |
10163 | i -= oplenp; | |
10164 | ||
10165 | switch (exp->elts[i].opcode) | |
10166 | { | |
10167 | case BINOP_ADD: | |
10168 | case BINOP_SUB: | |
10169 | case BINOP_MUL: | |
10170 | case BINOP_DIV: | |
10171 | case BINOP_REM: | |
10172 | case BINOP_MOD: | |
10173 | case BINOP_LSH: | |
10174 | case BINOP_RSH: | |
10175 | case BINOP_LOGICAL_AND: | |
10176 | case BINOP_LOGICAL_OR: | |
10177 | case BINOP_BITWISE_AND: | |
10178 | case BINOP_BITWISE_IOR: | |
10179 | case BINOP_BITWISE_XOR: | |
10180 | case BINOP_EQUAL: | |
10181 | case BINOP_NOTEQUAL: | |
10182 | case BINOP_LESS: | |
10183 | case BINOP_GTR: | |
10184 | case BINOP_LEQ: | |
10185 | case BINOP_GEQ: | |
10186 | case BINOP_REPEAT: | |
10187 | case BINOP_COMMA: | |
10188 | case BINOP_EXP: | |
10189 | case BINOP_MIN: | |
10190 | case BINOP_MAX: | |
10191 | case BINOP_INTDIV: | |
10192 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10193 | case TERNOP_COND: |
10194 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10195 | |
10196 | case OP_LONG: | |
10197 | case OP_DOUBLE: | |
10198 | case OP_DECFLOAT: | |
10199 | case OP_LAST: | |
10200 | case OP_COMPLEX: | |
10201 | case OP_STRING: | |
65d79d4b SDJ |
10202 | case OP_ARRAY: |
10203 | case OP_TYPE: | |
608b4967 TT |
10204 | case OP_TYPEOF: |
10205 | case OP_DECLTYPE: | |
6e72ca20 | 10206 | case OP_TYPEID: |
65d79d4b SDJ |
10207 | case OP_NAME: |
10208 | case OP_OBJC_NSSTRING: | |
10209 | ||
10210 | case UNOP_NEG: | |
10211 | case UNOP_LOGICAL_NOT: | |
10212 | case UNOP_COMPLEMENT: | |
10213 | case UNOP_ADDR: | |
10214 | case UNOP_HIGH: | |
aeaa2474 | 10215 | case UNOP_CAST: |
9eaf6705 TT |
10216 | |
10217 | case UNOP_CAST_TYPE: | |
10218 | case UNOP_REINTERPRET_CAST: | |
10219 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10220 | /* Unary, binary and ternary operators: We have to check |
10221 | their operands. If they are constant, then so is the | |
10222 | result of that operation. For instance, if A and B are | |
10223 | determined to be constants, then so is "A + B". | |
10224 | ||
10225 | UNOP_IND is one exception to the rule above, because the | |
10226 | value of *ADDR is not necessarily a constant, even when | |
10227 | ADDR is. */ | |
65d79d4b SDJ |
10228 | break; |
10229 | ||
10230 | case OP_VAR_VALUE: | |
10231 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10232 | |
65d79d4b | 10233 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10234 | possible that a buggy compiler could mark a variable as |
10235 | constant even when it is not, and TYPE_CONST would return | |
10236 | true in this case, while SYMBOL_CLASS wouldn't. | |
10237 | ||
10238 | We also have to check for function symbols because they | |
10239 | are always constant. */ | |
65d79d4b SDJ |
10240 | { |
10241 | struct symbol *s = exp->elts[i + 2].symbol; | |
10242 | ||
10243 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10244 | && SYMBOL_CLASS (s) != LOC_CONST | |
10245 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10246 | return 0; | |
10247 | break; | |
10248 | } | |
10249 | ||
10250 | /* The default action is to return 0 because we are using | |
10251 | the optimistic approach here: If we don't know something, | |
10252 | then it is not a constant. */ | |
10253 | default: | |
10254 | return 0; | |
10255 | } | |
10256 | } | |
10257 | ||
10258 | return 1; | |
10259 | } | |
10260 | ||
c1fc2657 | 10261 | /* Watchpoint destructor. */ |
3a5c3e22 | 10262 | |
c1fc2657 | 10263 | watchpoint::~watchpoint () |
3a5c3e22 | 10264 | { |
c1fc2657 SM |
10265 | xfree (this->exp_string); |
10266 | xfree (this->exp_string_reparse); | |
10267 | value_free (this->val); | |
3a5c3e22 PA |
10268 | } |
10269 | ||
348d480f PA |
10270 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10271 | ||
10272 | static void | |
10273 | re_set_watchpoint (struct breakpoint *b) | |
10274 | { | |
3a5c3e22 PA |
10275 | struct watchpoint *w = (struct watchpoint *) b; |
10276 | ||
348d480f PA |
10277 | /* Watchpoint can be either on expression using entirely global |
10278 | variables, or it can be on local variables. | |
10279 | ||
10280 | Watchpoints of the first kind are never auto-deleted, and even | |
10281 | persist across program restarts. Since they can use variables | |
10282 | from shared libraries, we need to reparse expression as libraries | |
10283 | are loaded and unloaded. | |
10284 | ||
10285 | Watchpoints on local variables can also change meaning as result | |
10286 | of solib event. For example, if a watchpoint uses both a local | |
10287 | and a global variables in expression, it's a local watchpoint, | |
10288 | but unloading of a shared library will make the expression | |
10289 | invalid. This is not a very common use case, but we still | |
10290 | re-evaluate expression, to avoid surprises to the user. | |
10291 | ||
10292 | Note that for local watchpoints, we re-evaluate it only if | |
10293 | watchpoints frame id is still valid. If it's not, it means the | |
10294 | watchpoint is out of scope and will be deleted soon. In fact, | |
10295 | I'm not sure we'll ever be called in this case. | |
10296 | ||
10297 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10298 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10299 | |
3a5c3e22 PA |
10300 | Don't do anything about disabled watchpoints, since they will be |
10301 | reevaluated again when enabled. */ | |
10302 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10303 | } |
10304 | ||
77b06cd7 TJB |
10305 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10306 | ||
10307 | static int | |
10308 | insert_watchpoint (struct bp_location *bl) | |
10309 | { | |
3a5c3e22 PA |
10310 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10311 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10312 | |
10313 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10314 | w->cond_exp.get ()); |
77b06cd7 TJB |
10315 | } |
10316 | ||
10317 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10318 | ||
10319 | static int | |
73971819 | 10320 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10321 | { |
3a5c3e22 PA |
10322 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10323 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10324 | |
10325 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10326 | w->cond_exp.get ()); |
e09342b5 TJB |
10327 | } |
10328 | ||
e09342b5 | 10329 | static int |
348d480f | 10330 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10331 | struct address_space *aspace, CORE_ADDR bp_addr, |
10332 | const struct target_waitstatus *ws) | |
e09342b5 | 10333 | { |
348d480f | 10334 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10335 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10336 | |
348d480f PA |
10337 | /* Continuable hardware watchpoints are treated as non-existent if the |
10338 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10339 | some data address). Otherwise gdb won't stop on a break instruction | |
10340 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10341 | been defined. Also skip watchpoints which we know did not trigger | |
10342 | (did not match the data address). */ | |
10343 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10344 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10345 | return 0; |
9c06b0b4 | 10346 | |
348d480f | 10347 | return 1; |
9c06b0b4 TJB |
10348 | } |
10349 | ||
348d480f PA |
10350 | static void |
10351 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10352 | { |
348d480f | 10353 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10354 | |
348d480f | 10355 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10356 | } |
10357 | ||
10358 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10359 | hardware watchpoints. */ |
9c06b0b4 TJB |
10360 | |
10361 | static int | |
348d480f | 10362 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10363 | { |
3a5c3e22 PA |
10364 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10365 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10366 | |
10367 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10368 | } |
10369 | ||
10370 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10371 | hardware watchpoints. */ |
9c06b0b4 TJB |
10372 | |
10373 | static int | |
348d480f | 10374 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10375 | { |
efa80663 PA |
10376 | /* Read and access watchpoints only work with hardware support. */ |
10377 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10378 | } |
10379 | ||
9c06b0b4 | 10380 | static enum print_stop_action |
348d480f | 10381 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10382 | { |
348d480f | 10383 | struct breakpoint *b; |
348d480f | 10384 | enum print_stop_action result; |
3a5c3e22 | 10385 | struct watchpoint *w; |
79a45e25 | 10386 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10387 | |
10388 | gdb_assert (bs->bp_location_at != NULL); | |
10389 | ||
348d480f | 10390 | b = bs->breakpoint_at; |
3a5c3e22 | 10391 | w = (struct watchpoint *) b; |
348d480f | 10392 | |
f303dbd6 PA |
10393 | annotate_watchpoint (b->number); |
10394 | maybe_print_thread_hit_breakpoint (uiout); | |
10395 | ||
d7e74731 PA |
10396 | string_file stb; |
10397 | ||
76f9c9cf | 10398 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10399 | switch (b->type) |
10400 | { | |
348d480f | 10401 | case bp_watchpoint: |
9c06b0b4 | 10402 | case bp_hardware_watchpoint: |
112e8700 SM |
10403 | if (uiout->is_mi_like_p ()) |
10404 | uiout->field_string | |
10405 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10406 | mention (b); |
76f9c9cf | 10407 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10408 | uiout->text ("\nOld value = "); |
d7e74731 | 10409 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10410 | uiout->field_stream ("old", stb); |
10411 | uiout->text ("\nNew value = "); | |
d7e74731 | 10412 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10413 | uiout->field_stream ("new", stb); |
10414 | uiout->text ("\n"); | |
348d480f PA |
10415 | /* More than one watchpoint may have been triggered. */ |
10416 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10417 | break; |
10418 | ||
10419 | case bp_read_watchpoint: | |
112e8700 SM |
10420 | if (uiout->is_mi_like_p ()) |
10421 | uiout->field_string | |
10422 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10423 | mention (b); |
76f9c9cf | 10424 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10425 | uiout->text ("\nValue = "); |
d7e74731 | 10426 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10427 | uiout->field_stream ("value", stb); |
10428 | uiout->text ("\n"); | |
348d480f | 10429 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10430 | break; |
10431 | ||
10432 | case bp_access_watchpoint: | |
348d480f PA |
10433 | if (bs->old_val != NULL) |
10434 | { | |
112e8700 SM |
10435 | if (uiout->is_mi_like_p ()) |
10436 | uiout->field_string | |
10437 | ("reason", | |
348d480f PA |
10438 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10439 | mention (b); | |
76f9c9cf | 10440 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10441 | uiout->text ("\nOld value = "); |
d7e74731 | 10442 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10443 | uiout->field_stream ("old", stb); |
10444 | uiout->text ("\nNew value = "); | |
348d480f PA |
10445 | } |
10446 | else | |
10447 | { | |
10448 | mention (b); | |
112e8700 SM |
10449 | if (uiout->is_mi_like_p ()) |
10450 | uiout->field_string | |
10451 | ("reason", | |
348d480f | 10452 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10453 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10454 | uiout->text ("\nValue = "); |
348d480f | 10455 | } |
d7e74731 | 10456 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10457 | uiout->field_stream ("new", stb); |
10458 | uiout->text ("\n"); | |
348d480f | 10459 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10460 | break; |
10461 | default: | |
348d480f | 10462 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10463 | } |
10464 | ||
348d480f PA |
10465 | return result; |
10466 | } | |
10467 | ||
10468 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10469 | watchpoints. */ | |
10470 | ||
10471 | static void | |
10472 | print_mention_watchpoint (struct breakpoint *b) | |
10473 | { | |
3a5c3e22 | 10474 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10475 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10476 | const char *tuple_name; |
348d480f PA |
10477 | |
10478 | switch (b->type) | |
10479 | { | |
10480 | case bp_watchpoint: | |
112e8700 | 10481 | uiout->text ("Watchpoint "); |
46b9c129 | 10482 | tuple_name = "wpt"; |
348d480f PA |
10483 | break; |
10484 | case bp_hardware_watchpoint: | |
112e8700 | 10485 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10486 | tuple_name = "wpt"; |
348d480f PA |
10487 | break; |
10488 | case bp_read_watchpoint: | |
112e8700 | 10489 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10490 | tuple_name = "hw-rwpt"; |
348d480f PA |
10491 | break; |
10492 | case bp_access_watchpoint: | |
112e8700 | 10493 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10494 | tuple_name = "hw-awpt"; |
348d480f PA |
10495 | break; |
10496 | default: | |
10497 | internal_error (__FILE__, __LINE__, | |
10498 | _("Invalid hardware watchpoint type.")); | |
10499 | } | |
10500 | ||
46b9c129 | 10501 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10502 | uiout->field_int ("number", b->number); |
10503 | uiout->text (": "); | |
10504 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10505 | } |
10506 | ||
10507 | /* Implement the "print_recreate" breakpoint_ops method for | |
10508 | watchpoints. */ | |
10509 | ||
10510 | static void | |
10511 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10512 | { | |
3a5c3e22 PA |
10513 | struct watchpoint *w = (struct watchpoint *) b; |
10514 | ||
348d480f PA |
10515 | switch (b->type) |
10516 | { | |
10517 | case bp_watchpoint: | |
10518 | case bp_hardware_watchpoint: | |
10519 | fprintf_unfiltered (fp, "watch"); | |
10520 | break; | |
10521 | case bp_read_watchpoint: | |
10522 | fprintf_unfiltered (fp, "rwatch"); | |
10523 | break; | |
10524 | case bp_access_watchpoint: | |
10525 | fprintf_unfiltered (fp, "awatch"); | |
10526 | break; | |
10527 | default: | |
10528 | internal_error (__FILE__, __LINE__, | |
10529 | _("Invalid watchpoint type.")); | |
10530 | } | |
10531 | ||
3a5c3e22 | 10532 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10533 | print_recreate_thread (b, fp); |
348d480f PA |
10534 | } |
10535 | ||
427cd150 TT |
10536 | /* Implement the "explains_signal" breakpoint_ops method for |
10537 | watchpoints. */ | |
10538 | ||
47591c29 | 10539 | static int |
427cd150 TT |
10540 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10541 | { | |
10542 | /* A software watchpoint cannot cause a signal other than | |
10543 | GDB_SIGNAL_TRAP. */ | |
10544 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10545 | return 0; |
427cd150 | 10546 | |
47591c29 | 10547 | return 1; |
427cd150 TT |
10548 | } |
10549 | ||
348d480f PA |
10550 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10551 | ||
2060206e | 10552 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10553 | |
10554 | /* Implement the "insert" breakpoint_ops method for | |
10555 | masked hardware watchpoints. */ | |
10556 | ||
10557 | static int | |
10558 | insert_masked_watchpoint (struct bp_location *bl) | |
10559 | { | |
3a5c3e22 PA |
10560 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10561 | ||
10562 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10563 | bl->watchpoint_type); |
10564 | } | |
10565 | ||
10566 | /* Implement the "remove" breakpoint_ops method for | |
10567 | masked hardware watchpoints. */ | |
10568 | ||
10569 | static int | |
73971819 | 10570 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10571 | { |
3a5c3e22 PA |
10572 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10573 | ||
10574 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10575 | bl->watchpoint_type); |
10576 | } | |
10577 | ||
10578 | /* Implement the "resources_needed" breakpoint_ops method for | |
10579 | masked hardware watchpoints. */ | |
10580 | ||
10581 | static int | |
10582 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10583 | { | |
3a5c3e22 PA |
10584 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10585 | ||
10586 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10587 | } |
10588 | ||
10589 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10590 | masked hardware watchpoints. */ | |
10591 | ||
10592 | static int | |
10593 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10594 | { | |
10595 | return 0; | |
10596 | } | |
10597 | ||
10598 | /* Implement the "print_it" breakpoint_ops method for | |
10599 | masked hardware watchpoints. */ | |
10600 | ||
10601 | static enum print_stop_action | |
10602 | print_it_masked_watchpoint (bpstat bs) | |
10603 | { | |
10604 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10605 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10606 | |
10607 | /* Masked watchpoints have only one location. */ | |
10608 | gdb_assert (b->loc && b->loc->next == NULL); | |
10609 | ||
f303dbd6 PA |
10610 | annotate_watchpoint (b->number); |
10611 | maybe_print_thread_hit_breakpoint (uiout); | |
10612 | ||
348d480f PA |
10613 | switch (b->type) |
10614 | { | |
10615 | case bp_hardware_watchpoint: | |
112e8700 SM |
10616 | if (uiout->is_mi_like_p ()) |
10617 | uiout->field_string | |
10618 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10619 | break; |
10620 | ||
10621 | case bp_read_watchpoint: | |
112e8700 SM |
10622 | if (uiout->is_mi_like_p ()) |
10623 | uiout->field_string | |
10624 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10625 | break; |
10626 | ||
10627 | case bp_access_watchpoint: | |
112e8700 SM |
10628 | if (uiout->is_mi_like_p ()) |
10629 | uiout->field_string | |
10630 | ("reason", | |
348d480f PA |
10631 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10632 | break; | |
10633 | default: | |
10634 | internal_error (__FILE__, __LINE__, | |
10635 | _("Invalid hardware watchpoint type.")); | |
10636 | } | |
10637 | ||
10638 | mention (b); | |
112e8700 | 10639 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10640 | Check the underlying instruction at PC for the memory\n\ |
10641 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10642 | uiout->text ("\n"); |
9c06b0b4 TJB |
10643 | |
10644 | /* More than one watchpoint may have been triggered. */ | |
10645 | return PRINT_UNKNOWN; | |
10646 | } | |
10647 | ||
10648 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10649 | masked hardware watchpoints. */ | |
10650 | ||
10651 | static void | |
10652 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10653 | struct ui_out *uiout) | |
10654 | { | |
3a5c3e22 PA |
10655 | struct watchpoint *w = (struct watchpoint *) b; |
10656 | ||
9c06b0b4 TJB |
10657 | /* Masked watchpoints have only one location. */ |
10658 | gdb_assert (b->loc && b->loc->next == NULL); | |
10659 | ||
112e8700 SM |
10660 | uiout->text ("\tmask "); |
10661 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10662 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10663 | } |
10664 | ||
10665 | /* Implement the "print_mention" breakpoint_ops method for | |
10666 | masked hardware watchpoints. */ | |
10667 | ||
10668 | static void | |
10669 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10670 | { | |
3a5c3e22 | 10671 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10672 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10673 | const char *tuple_name; |
9c06b0b4 TJB |
10674 | |
10675 | switch (b->type) | |
10676 | { | |
10677 | case bp_hardware_watchpoint: | |
112e8700 | 10678 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10679 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10680 | break; |
10681 | case bp_read_watchpoint: | |
112e8700 | 10682 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10683 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10684 | break; |
10685 | case bp_access_watchpoint: | |
112e8700 | 10686 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10687 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10688 | break; |
10689 | default: | |
10690 | internal_error (__FILE__, __LINE__, | |
10691 | _("Invalid hardware watchpoint type.")); | |
10692 | } | |
10693 | ||
46b9c129 | 10694 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10695 | uiout->field_int ("number", b->number); |
10696 | uiout->text (": "); | |
10697 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10698 | } |
10699 | ||
10700 | /* Implement the "print_recreate" breakpoint_ops method for | |
10701 | masked hardware watchpoints. */ | |
10702 | ||
10703 | static void | |
10704 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10705 | { | |
3a5c3e22 | 10706 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10707 | char tmp[40]; |
10708 | ||
10709 | switch (b->type) | |
10710 | { | |
10711 | case bp_hardware_watchpoint: | |
10712 | fprintf_unfiltered (fp, "watch"); | |
10713 | break; | |
10714 | case bp_read_watchpoint: | |
10715 | fprintf_unfiltered (fp, "rwatch"); | |
10716 | break; | |
10717 | case bp_access_watchpoint: | |
10718 | fprintf_unfiltered (fp, "awatch"); | |
10719 | break; | |
10720 | default: | |
10721 | internal_error (__FILE__, __LINE__, | |
10722 | _("Invalid hardware watchpoint type.")); | |
10723 | } | |
10724 | ||
3a5c3e22 PA |
10725 | sprintf_vma (tmp, w->hw_wp_mask); |
10726 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10727 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10728 | } |
10729 | ||
10730 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10731 | ||
2060206e | 10732 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10733 | |
10734 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10735 | ||
10736 | static int | |
10737 | is_masked_watchpoint (const struct breakpoint *b) | |
10738 | { | |
10739 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10740 | } | |
10741 | ||
53a5351d JM |
10742 | /* accessflag: hw_write: watch write, |
10743 | hw_read: watch read, | |
10744 | hw_access: watch access (read or write) */ | |
c906108c | 10745 | static void |
bbc13ae3 | 10746 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10747 | int just_location, int internal) |
c906108c | 10748 | { |
c1fc2657 | 10749 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10750 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10751 | struct value *val, *mark, *result; |
bb9d5f81 | 10752 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10753 | const char *exp_start = NULL; |
10754 | const char *exp_end = NULL; | |
10755 | const char *tok, *end_tok; | |
9c06b0b4 | 10756 | int toklen = -1; |
bbc13ae3 KS |
10757 | const char *cond_start = NULL; |
10758 | const char *cond_end = NULL; | |
c906108c | 10759 | enum bptype bp_type; |
37e4754d | 10760 | int thread = -1; |
0cf6dd15 | 10761 | int pc = 0; |
9c06b0b4 TJB |
10762 | /* Flag to indicate whether we are going to use masks for |
10763 | the hardware watchpoint. */ | |
10764 | int use_mask = 0; | |
10765 | CORE_ADDR mask = 0; | |
bbc13ae3 KS |
10766 | char *expression; |
10767 | struct cleanup *back_to; | |
c906108c | 10768 | |
37e4754d LM |
10769 | /* Make sure that we actually have parameters to parse. */ |
10770 | if (arg != NULL && arg[0] != '\0') | |
10771 | { | |
bbc13ae3 KS |
10772 | const char *value_start; |
10773 | ||
10774 | exp_end = arg + strlen (arg); | |
37e4754d | 10775 | |
9c06b0b4 TJB |
10776 | /* Look for "parameter value" pairs at the end |
10777 | of the arguments string. */ | |
bbc13ae3 | 10778 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10779 | { |
10780 | /* Skip whitespace at the end of the argument list. */ | |
10781 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10782 | tok--; | |
10783 | ||
10784 | /* Find the beginning of the last token. | |
10785 | This is the value of the parameter. */ | |
10786 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10787 | tok--; | |
10788 | value_start = tok + 1; | |
10789 | ||
10790 | /* Skip whitespace. */ | |
10791 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10792 | tok--; | |
10793 | ||
10794 | end_tok = tok; | |
10795 | ||
10796 | /* Find the beginning of the second to last token. | |
10797 | This is the parameter itself. */ | |
10798 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10799 | tok--; | |
10800 | tok++; | |
10801 | toklen = end_tok - tok + 1; | |
10802 | ||
61012eef | 10803 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10804 | { |
5d5658a1 | 10805 | struct thread_info *thr; |
9c06b0b4 TJB |
10806 | /* At this point we've found a "thread" token, which means |
10807 | the user is trying to set a watchpoint that triggers | |
10808 | only in a specific thread. */ | |
5d5658a1 | 10809 | const char *endp; |
37e4754d | 10810 | |
9c06b0b4 TJB |
10811 | if (thread != -1) |
10812 | error(_("You can specify only one thread.")); | |
37e4754d | 10813 | |
9c06b0b4 | 10814 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10815 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10816 | |
5d5658a1 | 10817 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10818 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10819 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10820 | |
5d5658a1 | 10821 | thread = thr->global_num; |
9c06b0b4 | 10822 | } |
61012eef | 10823 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10824 | { |
10825 | /* We've found a "mask" token, which means the user wants to | |
10826 | create a hardware watchpoint that is going to have the mask | |
10827 | facility. */ | |
10828 | struct value *mask_value, *mark; | |
37e4754d | 10829 | |
9c06b0b4 TJB |
10830 | if (use_mask) |
10831 | error(_("You can specify only one mask.")); | |
37e4754d | 10832 | |
9c06b0b4 | 10833 | use_mask = just_location = 1; |
37e4754d | 10834 | |
9c06b0b4 TJB |
10835 | mark = value_mark (); |
10836 | mask_value = parse_to_comma_and_eval (&value_start); | |
10837 | mask = value_as_address (mask_value); | |
10838 | value_free_to_mark (mark); | |
10839 | } | |
10840 | else | |
10841 | /* We didn't recognize what we found. We should stop here. */ | |
10842 | break; | |
37e4754d | 10843 | |
9c06b0b4 TJB |
10844 | /* Truncate the string and get rid of the "parameter value" pair before |
10845 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10846 | exp_end = tok; |
9c06b0b4 | 10847 | } |
37e4754d | 10848 | } |
bbc13ae3 KS |
10849 | else |
10850 | exp_end = arg; | |
37e4754d | 10851 | |
bbc13ae3 KS |
10852 | /* Parse the rest of the arguments. From here on out, everything |
10853 | is in terms of a newly allocated string instead of the original | |
10854 | ARG. */ | |
c906108c | 10855 | innermost_block = NULL; |
bbc13ae3 KS |
10856 | expression = savestring (arg, exp_end - arg); |
10857 | back_to = make_cleanup (xfree, expression); | |
10858 | exp_start = arg = expression; | |
4d01a485 | 10859 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 10860 | exp_end = arg; |
fa8a61dc TT |
10861 | /* Remove trailing whitespace from the expression before saving it. |
10862 | This makes the eventual display of the expression string a bit | |
10863 | prettier. */ | |
10864 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10865 | --exp_end; | |
10866 | ||
65d79d4b | 10867 | /* Checking if the expression is not constant. */ |
4d01a485 | 10868 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10869 | { |
10870 | int len; | |
10871 | ||
10872 | len = exp_end - exp_start; | |
10873 | while (len > 0 && isspace (exp_start[len - 1])) | |
10874 | len--; | |
10875 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10876 | } | |
10877 | ||
c906108c SS |
10878 | exp_valid_block = innermost_block; |
10879 | mark = value_mark (); | |
4d01a485 | 10880 | fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location); |
06a64a0b | 10881 | |
bb9d5f81 PP |
10882 | if (val != NULL && just_location) |
10883 | { | |
10884 | saved_bitpos = value_bitpos (val); | |
10885 | saved_bitsize = value_bitsize (val); | |
10886 | } | |
10887 | ||
06a64a0b TT |
10888 | if (just_location) |
10889 | { | |
9c06b0b4 TJB |
10890 | int ret; |
10891 | ||
06a64a0b | 10892 | exp_valid_block = NULL; |
a1442452 | 10893 | val = value_addr (result); |
06a64a0b TT |
10894 | release_value (val); |
10895 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
10896 | |
10897 | if (use_mask) | |
10898 | { | |
10899 | ret = target_masked_watch_num_registers (value_as_address (val), | |
10900 | mask); | |
10901 | if (ret == -1) | |
10902 | error (_("This target does not support masked watchpoints.")); | |
10903 | else if (ret == -2) | |
10904 | error (_("Invalid mask or memory region.")); | |
10905 | } | |
06a64a0b TT |
10906 | } |
10907 | else if (val != NULL) | |
fa4727a6 | 10908 | release_value (val); |
c906108c | 10909 | |
f1735a53 TT |
10910 | tok = skip_spaces (arg); |
10911 | end_tok = skip_to_space (tok); | |
c906108c SS |
10912 | |
10913 | toklen = end_tok - tok; | |
10914 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10915 | { | |
60e1c644 | 10916 | innermost_block = NULL; |
c906108c | 10917 | tok = cond_start = end_tok + 1; |
4d01a485 | 10918 | parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
10919 | |
10920 | /* The watchpoint expression may not be local, but the condition | |
10921 | may still be. E.g.: `watch global if local > 0'. */ | |
10922 | cond_exp_valid_block = innermost_block; | |
10923 | ||
c906108c SS |
10924 | cond_end = tok; |
10925 | } | |
10926 | if (*tok) | |
8a3fe4f8 | 10927 | error (_("Junk at end of command.")); |
c906108c | 10928 | |
441d7c93 PA |
10929 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10930 | ||
10931 | /* Save this because create_internal_breakpoint below invalidates | |
10932 | 'wp_frame'. */ | |
10933 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10934 | |
10935 | /* If the expression is "local", then set up a "watchpoint scope" | |
10936 | breakpoint at the point where we've left the scope of the watchpoint | |
10937 | expression. Create the scope breakpoint before the watchpoint, so | |
10938 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10939 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10940 | { |
441d7c93 PA |
10941 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10942 | ||
10943 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10944 | { |
441d7c93 PA |
10945 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10946 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10947 | ||
edb3359d | 10948 | scope_breakpoint |
441d7c93 | 10949 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10950 | bp_watchpoint_scope, |
10951 | &momentary_breakpoint_ops); | |
d983da9c | 10952 | |
441d7c93 PA |
10953 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10954 | wp_frame = NULL; | |
10955 | ||
edb3359d | 10956 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10957 | |
edb3359d DJ |
10958 | /* Automatically delete the breakpoint when it hits. */ |
10959 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10960 | |
edb3359d | 10961 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10962 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10963 | |
edb3359d | 10964 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10965 | scope_breakpoint->loc->gdbarch = caller_arch; |
10966 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10967 | scope_breakpoint->loc->address |
a6d9a66e UW |
10968 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10969 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10970 | scope_breakpoint->type); |
10971 | } | |
d983da9c DJ |
10972 | } |
10973 | ||
e8369a73 AB |
10974 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10975 | watchpoints here even if hardware watchpoints are turned off, a call | |
10976 | to update_watchpoint later in this function will cause the type to | |
10977 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10978 | ||
10979 | if (accessflag == hw_read) | |
10980 | bp_type = bp_read_watchpoint; | |
10981 | else if (accessflag == hw_access) | |
10982 | bp_type = bp_access_watchpoint; | |
10983 | else | |
10984 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10985 | |
b270e6f9 | 10986 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10987 | |
348d480f | 10988 | if (use_mask) |
b270e6f9 | 10989 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10990 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10991 | else |
b270e6f9 | 10992 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10993 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
10994 | w->thread = thread; |
10995 | w->disposition = disp_donttouch; | |
10996 | w->pspace = current_program_space; | |
b22e99fd | 10997 | w->exp = std::move (exp); |
3a5c3e22 PA |
10998 | w->exp_valid_block = exp_valid_block; |
10999 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11000 | if (just_location) |
11001 | { | |
11002 | struct type *t = value_type (val); | |
11003 | CORE_ADDR addr = value_as_address (val); | |
06a64a0b | 11004 | |
43cc5389 TT |
11005 | w->exp_string_reparse |
11006 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 11007 | |
3a5c3e22 | 11008 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 11009 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
11010 | } |
11011 | else | |
3a5c3e22 | 11012 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11013 | |
11014 | if (use_mask) | |
11015 | { | |
3a5c3e22 | 11016 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11017 | } |
11018 | else | |
11019 | { | |
3a5c3e22 | 11020 | w->val = val; |
bb9d5f81 PP |
11021 | w->val_bitpos = saved_bitpos; |
11022 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11023 | w->val_valid = 1; |
9c06b0b4 | 11024 | } |
77b06cd7 | 11025 | |
c906108c | 11026 | if (cond_start) |
c1fc2657 | 11027 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 11028 | else |
c1fc2657 | 11029 | w->cond_string = 0; |
c5aa993b | 11030 | |
441d7c93 | 11031 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 11032 | { |
441d7c93 | 11033 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 11034 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 11035 | } |
c906108c | 11036 | else |
f6bc2008 | 11037 | { |
3a5c3e22 PA |
11038 | w->watchpoint_frame = null_frame_id; |
11039 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11040 | } |
c906108c | 11041 | |
d983da9c | 11042 | if (scope_breakpoint != NULL) |
c906108c | 11043 | { |
d983da9c DJ |
11044 | /* The scope breakpoint is related to the watchpoint. We will |
11045 | need to act on them together. */ | |
c1fc2657 | 11046 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 11047 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 11048 | } |
d983da9c | 11049 | |
06a64a0b TT |
11050 | if (!just_location) |
11051 | value_free_to_mark (mark); | |
2d134ed3 | 11052 | |
b270e6f9 TT |
11053 | /* Finally update the new watchpoint. This creates the locations |
11054 | that should be inserted. */ | |
11055 | update_watchpoint (w.get (), 1); | |
a9634178 | 11056 | |
b270e6f9 | 11057 | install_breakpoint (internal, std::move (w), 1); |
bbc13ae3 | 11058 | do_cleanups (back_to); |
c906108c SS |
11059 | } |
11060 | ||
e09342b5 | 11061 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11062 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11063 | |
c906108c | 11064 | static int |
a9634178 | 11065 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11066 | { |
11067 | int found_memory_cnt = 0; | |
2e70b7b9 | 11068 | struct value *head = v; |
c906108c SS |
11069 | |
11070 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11071 | if (!can_use_hw_watchpoints) |
c906108c | 11072 | return 0; |
c5aa993b | 11073 | |
5c44784c JM |
11074 | /* Make sure that the value of the expression depends only upon |
11075 | memory contents, and values computed from them within GDB. If we | |
11076 | find any register references or function calls, we can't use a | |
11077 | hardware watchpoint. | |
11078 | ||
11079 | The idea here is that evaluating an expression generates a series | |
11080 | of values, one holding the value of every subexpression. (The | |
11081 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11082 | a*b+c.) GDB's values hold almost enough information to establish | |
11083 | the criteria given above --- they identify memory lvalues, | |
11084 | register lvalues, computed values, etcetera. So we can evaluate | |
11085 | the expression, and then scan the chain of values that leaves | |
11086 | behind to decide whether we can detect any possible change to the | |
11087 | expression's final value using only hardware watchpoints. | |
11088 | ||
11089 | However, I don't think that the values returned by inferior | |
11090 | function calls are special in any way. So this function may not | |
11091 | notice that an expression involving an inferior function call | |
11092 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11093 | for (; v; v = value_next (v)) |
c906108c | 11094 | { |
5c44784c | 11095 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11096 | { |
8464be76 DJ |
11097 | if (v != head && value_lazy (v)) |
11098 | /* A lazy memory lvalue in the chain is one that GDB never | |
11099 | needed to fetch; we either just used its address (e.g., | |
11100 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11101 | in `a,b'). This doesn't apply to HEAD; if that is | |
11102 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11103 | ; |
53a5351d | 11104 | else |
5c44784c JM |
11105 | { |
11106 | /* Ahh, memory we actually used! Check if we can cover | |
11107 | it with hardware watchpoints. */ | |
df407dfe | 11108 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11109 | |
11110 | /* We only watch structs and arrays if user asked for it | |
11111 | explicitly, never if they just happen to appear in a | |
11112 | middle of some value chain. */ | |
11113 | if (v == head | |
11114 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11115 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11116 | { | |
42ae5230 | 11117 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11118 | int len; |
11119 | int num_regs; | |
11120 | ||
a9634178 | 11121 | len = (target_exact_watchpoints |
e09342b5 TJB |
11122 | && is_scalar_type_recursive (vtype))? |
11123 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11124 | |
e09342b5 TJB |
11125 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11126 | if (!num_regs) | |
2e70b7b9 MS |
11127 | return 0; |
11128 | else | |
e09342b5 | 11129 | found_memory_cnt += num_regs; |
2e70b7b9 | 11130 | } |
5c44784c | 11131 | } |
c5aa993b | 11132 | } |
5086187c AC |
11133 | else if (VALUE_LVAL (v) != not_lval |
11134 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11135 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11136 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11137 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11138 | } |
11139 | ||
11140 | /* The expression itself looks suitable for using a hardware | |
11141 | watchpoint, but give the target machine a chance to reject it. */ | |
11142 | return found_memory_cnt; | |
11143 | } | |
11144 | ||
8b93c638 | 11145 | void |
f2fc3015 | 11146 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 11147 | { |
84f4c1fe | 11148 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11149 | } |
11150 | ||
06a64a0b TT |
11151 | /* A helper function that looks for the "-location" argument and then |
11152 | calls watch_command_1. */ | |
11153 | ||
11154 | static void | |
11155 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11156 | { | |
11157 | int just_location = 0; | |
11158 | ||
11159 | if (arg | |
11160 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11161 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11162 | { | |
e9cafbcc | 11163 | arg = skip_spaces (arg); |
06a64a0b TT |
11164 | just_location = 1; |
11165 | } | |
11166 | ||
84f4c1fe | 11167 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11168 | } |
8926118c | 11169 | |
c5aa993b | 11170 | static void |
fba45db2 | 11171 | watch_command (char *arg, int from_tty) |
c906108c | 11172 | { |
06a64a0b | 11173 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11174 | } |
11175 | ||
8b93c638 | 11176 | void |
f2fc3015 | 11177 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 11178 | { |
84f4c1fe | 11179 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11180 | } |
8926118c | 11181 | |
c5aa993b | 11182 | static void |
fba45db2 | 11183 | rwatch_command (char *arg, int from_tty) |
c906108c | 11184 | { |
06a64a0b | 11185 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11186 | } |
11187 | ||
8b93c638 | 11188 | void |
f2fc3015 | 11189 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 11190 | { |
84f4c1fe | 11191 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11192 | } |
8926118c | 11193 | |
c5aa993b | 11194 | static void |
fba45db2 | 11195 | awatch_command (char *arg, int from_tty) |
c906108c | 11196 | { |
06a64a0b | 11197 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11198 | } |
c906108c | 11199 | \f |
c5aa993b | 11200 | |
cfc31633 PA |
11201 | /* Data for the FSM that manages the until(location)/advance commands |
11202 | in infcmd.c. Here because it uses the mechanisms of | |
11203 | breakpoints. */ | |
c906108c | 11204 | |
cfc31633 | 11205 | struct until_break_fsm |
bfec99b2 | 11206 | { |
cfc31633 PA |
11207 | /* The base class. */ |
11208 | struct thread_fsm thread_fsm; | |
11209 | ||
11210 | /* The thread that as current when the command was executed. */ | |
11211 | int thread; | |
11212 | ||
11213 | /* The breakpoint set at the destination location. */ | |
11214 | struct breakpoint *location_breakpoint; | |
11215 | ||
11216 | /* Breakpoint set at the return address in the caller frame. May be | |
11217 | NULL. */ | |
11218 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11219 | }; |
11220 | ||
8980e177 PA |
11221 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11222 | struct thread_info *thread); | |
11223 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11224 | struct thread_info *thread); | |
cfc31633 PA |
11225 | static enum async_reply_reason |
11226 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11227 | ||
11228 | /* until_break_fsm's vtable. */ | |
11229 | ||
11230 | static struct thread_fsm_ops until_break_fsm_ops = | |
11231 | { | |
11232 | NULL, /* dtor */ | |
11233 | until_break_fsm_clean_up, | |
11234 | until_break_fsm_should_stop, | |
11235 | NULL, /* return_value */ | |
11236 | until_break_fsm_async_reply_reason, | |
11237 | }; | |
11238 | ||
11239 | /* Allocate a new until_break_command_fsm. */ | |
11240 | ||
11241 | static struct until_break_fsm * | |
8980e177 | 11242 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11243 | struct breakpoint *location_breakpoint, |
11244 | struct breakpoint *caller_breakpoint) | |
11245 | { | |
11246 | struct until_break_fsm *sm; | |
11247 | ||
11248 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11249 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11250 | |
11251 | sm->thread = thread; | |
11252 | sm->location_breakpoint = location_breakpoint; | |
11253 | sm->caller_breakpoint = caller_breakpoint; | |
11254 | ||
11255 | return sm; | |
11256 | } | |
11257 | ||
11258 | /* Implementation of the 'should_stop' FSM method for the | |
11259 | until(location)/advance commands. */ | |
11260 | ||
11261 | static int | |
8980e177 PA |
11262 | until_break_fsm_should_stop (struct thread_fsm *self, |
11263 | struct thread_info *tp) | |
cfc31633 PA |
11264 | { |
11265 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11266 | |
11267 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11268 | sm->location_breakpoint) != NULL | |
11269 | || (sm->caller_breakpoint != NULL | |
11270 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11271 | sm->caller_breakpoint) != NULL)) | |
11272 | thread_fsm_set_finished (self); | |
11273 | ||
11274 | return 1; | |
11275 | } | |
11276 | ||
11277 | /* Implementation of the 'clean_up' FSM method for the | |
11278 | until(location)/advance commands. */ | |
11279 | ||
c2c6d25f | 11280 | static void |
8980e177 PA |
11281 | until_break_fsm_clean_up (struct thread_fsm *self, |
11282 | struct thread_info *thread) | |
43ff13b4 | 11283 | { |
cfc31633 | 11284 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11285 | |
cfc31633 PA |
11286 | /* Clean up our temporary breakpoints. */ |
11287 | if (sm->location_breakpoint != NULL) | |
11288 | { | |
11289 | delete_breakpoint (sm->location_breakpoint); | |
11290 | sm->location_breakpoint = NULL; | |
11291 | } | |
11292 | if (sm->caller_breakpoint != NULL) | |
11293 | { | |
11294 | delete_breakpoint (sm->caller_breakpoint); | |
11295 | sm->caller_breakpoint = NULL; | |
11296 | } | |
11297 | delete_longjmp_breakpoint (sm->thread); | |
11298 | } | |
11299 | ||
11300 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11301 | until(location)/advance commands. */ | |
11302 | ||
11303 | static enum async_reply_reason | |
11304 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11305 | { | |
11306 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11307 | } |
11308 | ||
c906108c | 11309 | void |
f2fc3015 | 11310 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 11311 | { |
8556afb4 PA |
11312 | struct frame_info *frame; |
11313 | struct gdbarch *frame_gdbarch; | |
11314 | struct frame_id stack_frame_id; | |
11315 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11316 | struct breakpoint *location_breakpoint; |
11317 | struct breakpoint *caller_breakpoint = NULL; | |
ffc2605c | 11318 | struct cleanup *old_chain; |
186c406b TT |
11319 | int thread; |
11320 | struct thread_info *tp; | |
cfc31633 | 11321 | struct until_break_fsm *sm; |
c906108c | 11322 | |
70509625 | 11323 | clear_proceed_status (0); |
c906108c SS |
11324 | |
11325 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11326 | this function. */ |
c5aa993b | 11327 | |
ffc2605c | 11328 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11329 | |
6c5b2ebe PA |
11330 | std::vector<symtab_and_line> sals |
11331 | = (last_displayed_sal_is_valid () | |
11332 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
11333 | get_last_displayed_symtab (), | |
11334 | get_last_displayed_line ()) | |
11335 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
11336 | NULL, (struct symtab *) NULL, 0)); | |
c5aa993b | 11337 | |
6c5b2ebe | 11338 | if (sals.size () != 1) |
8a3fe4f8 | 11339 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11340 | |
6c5b2ebe | 11341 | symtab_and_line &sal = sals[0]; |
c5aa993b | 11342 | |
c906108c | 11343 | if (*arg) |
8a3fe4f8 | 11344 | error (_("Junk at end of arguments.")); |
c5aa993b | 11345 | |
c906108c | 11346 | resolve_sal_pc (&sal); |
c5aa993b | 11347 | |
186c406b | 11348 | tp = inferior_thread (); |
5d5658a1 | 11349 | thread = tp->global_num; |
186c406b | 11350 | |
883bc8d1 PA |
11351 | old_chain = make_cleanup (null_cleanup, NULL); |
11352 | ||
8556afb4 PA |
11353 | /* Note linespec handling above invalidates the frame chain. |
11354 | Installing a breakpoint also invalidates the frame chain (as it | |
11355 | may need to switch threads), so do any frame handling before | |
11356 | that. */ | |
11357 | ||
11358 | frame = get_selected_frame (NULL); | |
11359 | frame_gdbarch = get_frame_arch (frame); | |
11360 | stack_frame_id = get_stack_frame_id (frame); | |
11361 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11362 | |
ae66c1fc EZ |
11363 | /* Keep within the current frame, or in frames called by the current |
11364 | one. */ | |
edb3359d | 11365 | |
883bc8d1 | 11366 | if (frame_id_p (caller_frame_id)) |
c906108c | 11367 | { |
883bc8d1 | 11368 | struct symtab_and_line sal2; |
cfc31633 | 11369 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11370 | |
11371 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11372 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11373 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11374 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11375 | sal2, | |
11376 | caller_frame_id, | |
11377 | bp_until); | |
11378 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11379 | |
883bc8d1 | 11380 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11381 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11382 | } |
c5aa993b | 11383 | |
c70a6932 JK |
11384 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11385 | frame = NULL; | |
11386 | ||
883bc8d1 PA |
11387 | if (anywhere) |
11388 | /* If the user told us to continue until a specified location, | |
11389 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11390 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11391 | null_frame_id, bp_until); | |
883bc8d1 PA |
11392 | else |
11393 | /* Otherwise, specify the selected frame, because we want to stop | |
11394 | only at the very same frame. */ | |
cfc31633 PA |
11395 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11396 | stack_frame_id, bp_until); | |
11397 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11398 | |
8980e177 | 11399 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11400 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11401 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11402 | |
cfc31633 | 11403 | discard_cleanups (old_chain); |
f107f563 | 11404 | |
cfc31633 | 11405 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11406 | } |
ae66c1fc | 11407 | |
c906108c SS |
11408 | /* This function attempts to parse an optional "if <cond>" clause |
11409 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11410 | |
c906108c SS |
11411 | Else, it returns a pointer to the condition string. (It does not |
11412 | attempt to evaluate the string against a particular block.) And, | |
11413 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11414 | if clause in the arg string. */ |
53a5351d | 11415 | |
63160a43 PA |
11416 | const char * |
11417 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11418 | { |
63160a43 | 11419 | const char *cond_string; |
c5aa993b JM |
11420 | |
11421 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11422 | return NULL; |
c5aa993b | 11423 | |
4a64f543 | 11424 | /* Skip the "if" keyword. */ |
c906108c | 11425 | (*arg) += 2; |
c5aa993b | 11426 | |
c906108c | 11427 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11428 | condition string. */ |
f1735a53 | 11429 | *arg = skip_spaces (*arg); |
c906108c | 11430 | cond_string = *arg; |
c5aa993b | 11431 | |
4a64f543 MS |
11432 | /* Assume that the condition occupies the remainder of the arg |
11433 | string. */ | |
c906108c | 11434 | (*arg) += strlen (cond_string); |
c5aa993b | 11435 | |
c906108c SS |
11436 | return cond_string; |
11437 | } | |
c5aa993b | 11438 | |
c906108c SS |
11439 | /* Commands to deal with catching events, such as signals, exceptions, |
11440 | process start/exit, etc. */ | |
c5aa993b JM |
11441 | |
11442 | typedef enum | |
11443 | { | |
44feb3ce TT |
11444 | catch_fork_temporary, catch_vfork_temporary, |
11445 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11446 | } |
11447 | catch_fork_kind; | |
11448 | ||
c906108c | 11449 | static void |
63160a43 | 11450 | catch_fork_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11451 | struct cmd_list_element *command) |
c906108c | 11452 | { |
63160a43 | 11453 | const char *arg = arg_entry; |
a6d9a66e | 11454 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11455 | const char *cond_string = NULL; |
44feb3ce TT |
11456 | catch_fork_kind fork_kind; |
11457 | int tempflag; | |
11458 | ||
11459 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11460 | tempflag = (fork_kind == catch_fork_temporary | |
11461 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11462 | |
44feb3ce TT |
11463 | if (!arg) |
11464 | arg = ""; | |
f1735a53 | 11465 | arg = skip_spaces (arg); |
c5aa993b | 11466 | |
c906108c | 11467 | /* The allowed syntax is: |
c5aa993b JM |
11468 | catch [v]fork |
11469 | catch [v]fork if <cond> | |
11470 | ||
4a64f543 | 11471 | First, check if there's an if clause. */ |
c906108c | 11472 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11473 | |
c906108c | 11474 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11475 | error (_("Junk at end of arguments.")); |
c5aa993b | 11476 | |
c906108c | 11477 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11478 | and enable reporting of such events. */ |
c5aa993b JM |
11479 | switch (fork_kind) |
11480 | { | |
44feb3ce TT |
11481 | case catch_fork_temporary: |
11482 | case catch_fork_permanent: | |
a6d9a66e | 11483 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11484 | &catch_fork_breakpoint_ops); |
c906108c | 11485 | break; |
44feb3ce TT |
11486 | case catch_vfork_temporary: |
11487 | case catch_vfork_permanent: | |
a6d9a66e | 11488 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11489 | &catch_vfork_breakpoint_ops); |
c906108c | 11490 | break; |
c5aa993b | 11491 | default: |
8a3fe4f8 | 11492 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11493 | break; |
c5aa993b | 11494 | } |
c906108c SS |
11495 | } |
11496 | ||
11497 | static void | |
63160a43 | 11498 | catch_exec_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11499 | struct cmd_list_element *command) |
c906108c | 11500 | { |
63160a43 | 11501 | const char *arg = arg_entry; |
a6d9a66e | 11502 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11503 | int tempflag; |
63160a43 | 11504 | const char *cond_string = NULL; |
c906108c | 11505 | |
44feb3ce TT |
11506 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11507 | ||
11508 | if (!arg) | |
11509 | arg = ""; | |
f1735a53 | 11510 | arg = skip_spaces (arg); |
c906108c SS |
11511 | |
11512 | /* The allowed syntax is: | |
c5aa993b JM |
11513 | catch exec |
11514 | catch exec if <cond> | |
c906108c | 11515 | |
4a64f543 | 11516 | First, check if there's an if clause. */ |
c906108c SS |
11517 | cond_string = ep_parse_optional_if_clause (&arg); |
11518 | ||
11519 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11520 | error (_("Junk at end of arguments.")); |
c906108c | 11521 | |
b270e6f9 TT |
11522 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11523 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11524 | &catch_exec_breakpoint_ops); |
11525 | c->exec_pathname = NULL; | |
11526 | ||
b270e6f9 | 11527 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11528 | } |
c5aa993b | 11529 | |
9ac4176b | 11530 | void |
28010a5d PA |
11531 | init_ada_exception_breakpoint (struct breakpoint *b, |
11532 | struct gdbarch *gdbarch, | |
11533 | struct symtab_and_line sal, | |
f2fc3015 | 11534 | const char *addr_string, |
c0a91b2b | 11535 | const struct breakpoint_ops *ops, |
28010a5d | 11536 | int tempflag, |
349774ef | 11537 | int enabled, |
28010a5d | 11538 | int from_tty) |
f7f9143b | 11539 | { |
f7f9143b JB |
11540 | if (from_tty) |
11541 | { | |
5af949e3 UW |
11542 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11543 | if (!loc_gdbarch) | |
11544 | loc_gdbarch = gdbarch; | |
11545 | ||
6c95b8df PA |
11546 | describe_other_breakpoints (loc_gdbarch, |
11547 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11548 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11549 | version for exception catchpoints, because two catchpoints | |
11550 | used for different exception names will use the same address. | |
11551 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11552 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11553 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11554 | the user what type of catchpoint it is. The above is good |
11555 | enough for now, though. */ | |
11556 | } | |
11557 | ||
28010a5d | 11558 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11559 | |
349774ef | 11560 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11561 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11562 | b->location = string_to_event_location (&addr_string, |
11563 | language_def (language_ada)); | |
f7f9143b | 11564 | b->language = language_ada; |
f7f9143b JB |
11565 | } |
11566 | ||
c906108c | 11567 | static void |
fba45db2 | 11568 | catch_command (char *arg, int from_tty) |
c906108c | 11569 | { |
44feb3ce | 11570 | error (_("Catch requires an event name.")); |
c906108c SS |
11571 | } |
11572 | \f | |
11573 | ||
11574 | static void | |
fba45db2 | 11575 | tcatch_command (char *arg, int from_tty) |
c906108c | 11576 | { |
44feb3ce | 11577 | error (_("Catch requires an event name.")); |
c906108c SS |
11578 | } |
11579 | ||
8a2c437b TT |
11580 | /* A qsort comparison function that sorts breakpoints in order. */ |
11581 | ||
11582 | static int | |
11583 | compare_breakpoints (const void *a, const void *b) | |
11584 | { | |
9a3c8263 | 11585 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11586 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11587 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11588 | uintptr_t ub = (uintptr_t) *bb; |
11589 | ||
11590 | if ((*ba)->number < (*bb)->number) | |
11591 | return -1; | |
11592 | else if ((*ba)->number > (*bb)->number) | |
11593 | return 1; | |
11594 | ||
11595 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11596 | the number 0. */ | |
11597 | if (ua < ub) | |
11598 | return -1; | |
94b0e70d | 11599 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11600 | } |
11601 | ||
80f8a6eb | 11602 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11603 | |
11604 | static void | |
fba45db2 | 11605 | clear_command (char *arg, int from_tty) |
c906108c | 11606 | { |
8a2c437b | 11607 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11608 | VEC(breakpoint_p) *found = 0; |
11609 | int ix; | |
c906108c | 11610 | int default_match; |
c906108c | 11611 | int i; |
8a2c437b | 11612 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c | 11613 | |
6c5b2ebe PA |
11614 | std::vector<symtab_and_line> decoded_sals; |
11615 | symtab_and_line last_sal; | |
11616 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11617 | if (arg) |
11618 | { | |
6c5b2ebe PA |
11619 | decoded_sals |
11620 | = decode_line_with_current_source (arg, | |
11621 | (DECODE_LINE_FUNFIRSTLINE | |
11622 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11623 | default_match = 0; |
6c5b2ebe | 11624 | sals = decoded_sals; |
c906108c SS |
11625 | } |
11626 | else | |
11627 | { | |
1bfeeb0f JL |
11628 | /* Set sal's line, symtab, pc, and pspace to the values |
11629 | corresponding to the last call to print_frame_info. If the | |
11630 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11631 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11632 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11633 | error (_("No source file specified.")); |
c906108c | 11634 | |
c906108c | 11635 | default_match = 1; |
6c5b2ebe | 11636 | sals = last_sal; |
c906108c SS |
11637 | } |
11638 | ||
4a64f543 MS |
11639 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11640 | seems, because all existing breakpoints typically have both | |
11641 | file/line and pc set. So, if clear is given file/line, we can | |
11642 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11643 | |
11644 | We only support clearing given the address explicitly | |
11645 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11646 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11647 | due to optimization, all in one block. |
4a64f543 MS |
11648 | |
11649 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11650 | PC corresponding to the same file:line, the breakpoint won't |
11651 | be cleared. We probably can still clear the breakpoint, but | |
11652 | since the other PC value is never presented to user, user | |
11653 | can only find it by guessing, and it does not seem important | |
11654 | to support that. */ | |
11655 | ||
4a64f543 MS |
11656 | /* For each line spec given, delete bps which correspond to it. Do |
11657 | it in two passes, solely to preserve the current behavior that | |
11658 | from_tty is forced true if we delete more than one | |
11659 | breakpoint. */ | |
c906108c | 11660 | |
80f8a6eb | 11661 | found = NULL; |
8a2c437b | 11662 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
6c5b2ebe | 11663 | for (const auto &sal : sals) |
c906108c | 11664 | { |
05cba821 JK |
11665 | const char *sal_fullname; |
11666 | ||
c906108c | 11667 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11668 | If line given (pc == 0), clear all bpts on specified line. |
11669 | If defaulting, clear all bpts on default line | |
c906108c | 11670 | or at default pc. |
c5aa993b JM |
11671 | |
11672 | defaulting sal.pc != 0 tests to do | |
11673 | ||
11674 | 0 1 pc | |
11675 | 1 1 pc _and_ line | |
11676 | 0 0 line | |
11677 | 1 0 <can't happen> */ | |
c906108c | 11678 | |
05cba821 JK |
11679 | sal_fullname = (sal.symtab == NULL |
11680 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11681 | |
4a64f543 | 11682 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11683 | ALL_BREAKPOINTS (b) |
c5aa993b | 11684 | { |
0d381245 | 11685 | int match = 0; |
4a64f543 | 11686 | /* Are we going to delete b? */ |
cc60f2e3 | 11687 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11688 | { |
11689 | struct bp_location *loc = b->loc; | |
11690 | for (; loc; loc = loc->next) | |
11691 | { | |
f8eba3c6 TT |
11692 | /* If the user specified file:line, don't allow a PC |
11693 | match. This matches historical gdb behavior. */ | |
11694 | int pc_match = (!sal.explicit_line | |
11695 | && sal.pc | |
11696 | && (loc->pspace == sal.pspace) | |
11697 | && (loc->address == sal.pc) | |
11698 | && (!section_is_overlay (loc->section) | |
11699 | || loc->section == sal.section)); | |
4aac40c8 TT |
11700 | int line_match = 0; |
11701 | ||
11702 | if ((default_match || sal.explicit_line) | |
2f202fde | 11703 | && loc->symtab != NULL |
05cba821 | 11704 | && sal_fullname != NULL |
4aac40c8 | 11705 | && sal.pspace == loc->pspace |
05cba821 JK |
11706 | && loc->line_number == sal.line |
11707 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11708 | sal_fullname) == 0) | |
11709 | line_match = 1; | |
4aac40c8 | 11710 | |
0d381245 VP |
11711 | if (pc_match || line_match) |
11712 | { | |
11713 | match = 1; | |
11714 | break; | |
11715 | } | |
11716 | } | |
11717 | } | |
11718 | ||
11719 | if (match) | |
d6e956e5 | 11720 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11721 | } |
80f8a6eb | 11722 | } |
8a2c437b | 11723 | |
80f8a6eb | 11724 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11725 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11726 | { |
11727 | if (arg) | |
8a3fe4f8 | 11728 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11729 | else |
8a3fe4f8 | 11730 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11731 | } |
c906108c | 11732 | |
8a2c437b TT |
11733 | /* Remove duplicates from the vec. */ |
11734 | qsort (VEC_address (breakpoint_p, found), | |
11735 | VEC_length (breakpoint_p, found), | |
11736 | sizeof (breakpoint_p), | |
11737 | compare_breakpoints); | |
11738 | prev = VEC_index (breakpoint_p, found, 0); | |
11739 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11740 | { | |
11741 | if (b == prev) | |
11742 | { | |
11743 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11744 | --ix; | |
11745 | } | |
11746 | } | |
11747 | ||
d6e956e5 | 11748 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11749 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11750 | if (from_tty) |
a3f17187 | 11751 | { |
d6e956e5 | 11752 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11753 | printf_unfiltered (_("Deleted breakpoint ")); |
11754 | else | |
11755 | printf_unfiltered (_("Deleted breakpoints ")); | |
11756 | } | |
d6e956e5 VP |
11757 | |
11758 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11759 | { |
c5aa993b | 11760 | if (from_tty) |
d6e956e5 VP |
11761 | printf_unfiltered ("%d ", b->number); |
11762 | delete_breakpoint (b); | |
c906108c | 11763 | } |
80f8a6eb MS |
11764 | if (from_tty) |
11765 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11766 | |
11767 | do_cleanups (cleanups); | |
c906108c SS |
11768 | } |
11769 | \f | |
11770 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11771 | all breakpoints that are marked for deletion, whether hit or not. | |
11772 | This is called after any breakpoint is hit, or after errors. */ | |
11773 | ||
11774 | void | |
fba45db2 | 11775 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11776 | { |
35df4500 | 11777 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11778 | |
11779 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11780 | if (bs->breakpoint_at |
11781 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11782 | && bs->stop) |
f431efe5 | 11783 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11784 | |
35df4500 | 11785 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11786 | { |
b5de0fa7 | 11787 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11788 | delete_breakpoint (b); |
11789 | } | |
c906108c SS |
11790 | } |
11791 | ||
4a64f543 MS |
11792 | /* A comparison function for bp_location AP and BP being interfaced to |
11793 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11794 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 11795 | secondarily by ordering first permanent elements and |
4a64f543 | 11796 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 11797 | qsort being an unstable algorithm. */ |
876fa593 JK |
11798 | |
11799 | static int | |
f5336ca5 | 11800 | bp_locations_compare (const void *ap, const void *bp) |
876fa593 | 11801 | { |
9a3c8263 SM |
11802 | const struct bp_location *a = *(const struct bp_location **) ap; |
11803 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
11804 | |
11805 | if (a->address != b->address) | |
11806 | return (a->address > b->address) - (a->address < b->address); | |
11807 | ||
dea2aa5f LM |
11808 | /* Sort locations at the same address by their pspace number, keeping |
11809 | locations of the same inferior (in a multi-inferior environment) | |
11810 | grouped. */ | |
11811 | ||
11812 | if (a->pspace->num != b->pspace->num) | |
11813 | return ((a->pspace->num > b->pspace->num) | |
11814 | - (a->pspace->num < b->pspace->num)); | |
11815 | ||
876fa593 | 11816 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
11817 | if (a->permanent != b->permanent) |
11818 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 11819 | |
c56a97f9 JK |
11820 | /* Make the internal GDB representation stable across GDB runs |
11821 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11822 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11823 | |
11824 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11825 | return ((a->owner->number > b->owner->number) |
11826 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11827 | |
11828 | return (a > b) - (a < b); | |
11829 | } | |
11830 | ||
f5336ca5 PA |
11831 | /* Set bp_locations_placed_address_before_address_max and |
11832 | bp_locations_shadow_len_after_address_max according to the current | |
11833 | content of the bp_locations array. */ | |
f7545552 TT |
11834 | |
11835 | static void | |
f5336ca5 | 11836 | bp_locations_target_extensions_update (void) |
f7545552 | 11837 | { |
876fa593 JK |
11838 | struct bp_location *bl, **blp_tmp; |
11839 | ||
f5336ca5 PA |
11840 | bp_locations_placed_address_before_address_max = 0; |
11841 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11842 | |
11843 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11844 | { | |
11845 | CORE_ADDR start, end, addr; | |
11846 | ||
11847 | if (!bp_location_has_shadow (bl)) | |
11848 | continue; | |
11849 | ||
11850 | start = bl->target_info.placed_address; | |
11851 | end = start + bl->target_info.shadow_len; | |
11852 | ||
11853 | gdb_assert (bl->address >= start); | |
11854 | addr = bl->address - start; | |
f5336ca5 PA |
11855 | if (addr > bp_locations_placed_address_before_address_max) |
11856 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11857 | |
11858 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11859 | ||
11860 | gdb_assert (bl->address < end); | |
11861 | addr = end - bl->address; | |
f5336ca5 PA |
11862 | if (addr > bp_locations_shadow_len_after_address_max) |
11863 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11864 | } |
f7545552 TT |
11865 | } |
11866 | ||
1e4d1764 YQ |
11867 | /* Download tracepoint locations if they haven't been. */ |
11868 | ||
11869 | static void | |
11870 | download_tracepoint_locations (void) | |
11871 | { | |
7ed2c994 | 11872 | struct breakpoint *b; |
dd2e65cc | 11873 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11874 | |
5ed8105e | 11875 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11876 | |
7ed2c994 | 11877 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11878 | { |
7ed2c994 | 11879 | struct bp_location *bl; |
1e4d1764 | 11880 | struct tracepoint *t; |
f2a8bc8a | 11881 | int bp_location_downloaded = 0; |
1e4d1764 | 11882 | |
7ed2c994 | 11883 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11884 | ? !may_insert_fast_tracepoints |
11885 | : !may_insert_tracepoints)) | |
11886 | continue; | |
11887 | ||
dd2e65cc YQ |
11888 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11889 | { | |
11890 | if (target_can_download_tracepoint ()) | |
11891 | can_download_tracepoint = TRIBOOL_TRUE; | |
11892 | else | |
11893 | can_download_tracepoint = TRIBOOL_FALSE; | |
11894 | } | |
11895 | ||
11896 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11897 | break; | |
11898 | ||
7ed2c994 YQ |
11899 | for (bl = b->loc; bl; bl = bl->next) |
11900 | { | |
11901 | /* In tracepoint, locations are _never_ duplicated, so | |
11902 | should_be_inserted is equivalent to | |
11903 | unduplicated_should_be_inserted. */ | |
11904 | if (!should_be_inserted (bl) || bl->inserted) | |
11905 | continue; | |
1e4d1764 | 11906 | |
7ed2c994 | 11907 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11908 | |
7ed2c994 | 11909 | target_download_tracepoint (bl); |
1e4d1764 | 11910 | |
7ed2c994 | 11911 | bl->inserted = 1; |
f2a8bc8a | 11912 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11913 | } |
11914 | t = (struct tracepoint *) b; | |
11915 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
11916 | if (bp_location_downloaded) |
11917 | observer_notify_breakpoint_modified (b); | |
1e4d1764 | 11918 | } |
1e4d1764 YQ |
11919 | } |
11920 | ||
934709f0 PW |
11921 | /* Swap the insertion/duplication state between two locations. */ |
11922 | ||
11923 | static void | |
11924 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11925 | { | |
11926 | const int left_inserted = left->inserted; | |
11927 | const int left_duplicate = left->duplicate; | |
b775012e | 11928 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11929 | const struct bp_target_info left_target_info = left->target_info; |
11930 | ||
1e4d1764 YQ |
11931 | /* Locations of tracepoints can never be duplicated. */ |
11932 | if (is_tracepoint (left->owner)) | |
11933 | gdb_assert (!left->duplicate); | |
11934 | if (is_tracepoint (right->owner)) | |
11935 | gdb_assert (!right->duplicate); | |
11936 | ||
934709f0 PW |
11937 | left->inserted = right->inserted; |
11938 | left->duplicate = right->duplicate; | |
b775012e | 11939 | left->needs_update = right->needs_update; |
934709f0 PW |
11940 | left->target_info = right->target_info; |
11941 | right->inserted = left_inserted; | |
11942 | right->duplicate = left_duplicate; | |
b775012e | 11943 | right->needs_update = left_needs_update; |
934709f0 PW |
11944 | right->target_info = left_target_info; |
11945 | } | |
11946 | ||
b775012e LM |
11947 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11948 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11949 | conditions on the target's side. Such conditions need to be updated on | |
11950 | the target. */ | |
11951 | ||
11952 | static void | |
11953 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11954 | { | |
11955 | struct bp_location **locp = NULL, **loc2p; | |
11956 | struct bp_location *loc; | |
11957 | CORE_ADDR address = 0; | |
11958 | int pspace_num; | |
11959 | ||
11960 | address = bl->address; | |
11961 | pspace_num = bl->pspace->num; | |
11962 | ||
11963 | /* This is only meaningful if the target is | |
11964 | evaluating conditions and if the user has | |
11965 | opted for condition evaluation on the target's | |
11966 | side. */ | |
11967 | if (gdb_evaluates_breakpoint_condition_p () | |
11968 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11969 | return; | |
11970 | ||
11971 | /* Flag all breakpoint locations with this address and | |
11972 | the same program space as the location | |
11973 | as "its condition has changed". We need to | |
11974 | update the conditions on the target's side. */ | |
11975 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11976 | { | |
11977 | loc = *loc2p; | |
11978 | ||
11979 | if (!is_breakpoint (loc->owner) | |
11980 | || pspace_num != loc->pspace->num) | |
11981 | continue; | |
11982 | ||
11983 | /* Flag the location appropriately. We use a different state to | |
11984 | let everyone know that we already updated the set of locations | |
11985 | with addr bl->address and program space bl->pspace. This is so | |
11986 | we don't have to keep calling these functions just to mark locations | |
11987 | that have already been marked. */ | |
11988 | loc->condition_changed = condition_updated; | |
11989 | ||
11990 | /* Free the agent expression bytecode as well. We will compute | |
11991 | it later on. */ | |
833177a4 | 11992 | loc->cond_bytecode.reset (); |
b775012e LM |
11993 | } |
11994 | } | |
44702360 PA |
11995 | /* Called whether new breakpoints are created, or existing breakpoints |
11996 | deleted, to update the global location list and recompute which | |
11997 | locations are duplicate of which. | |
b775012e | 11998 | |
04086b45 PA |
11999 | The INSERT_MODE flag determines whether locations may not, may, or |
12000 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12001 | info. */ | |
b60e7edf | 12002 | |
0d381245 | 12003 | static void |
44702360 | 12004 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12005 | { |
74960c60 | 12006 | struct breakpoint *b; |
876fa593 | 12007 | struct bp_location **locp, *loc; |
f7545552 | 12008 | struct cleanup *cleanups; |
b775012e LM |
12009 | /* Last breakpoint location address that was marked for update. */ |
12010 | CORE_ADDR last_addr = 0; | |
12011 | /* Last breakpoint location program space that was marked for update. */ | |
12012 | int last_pspace_num = -1; | |
f7545552 | 12013 | |
2d134ed3 PA |
12014 | /* Used in the duplicates detection below. When iterating over all |
12015 | bp_locations, points to the first bp_location of a given address. | |
12016 | Breakpoints and watchpoints of different types are never | |
12017 | duplicates of each other. Keep one pointer for each type of | |
12018 | breakpoint/watchpoint, so we only need to loop over all locations | |
12019 | once. */ | |
12020 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12021 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12022 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12023 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12024 | |
f5336ca5 PA |
12025 | /* Saved former bp_locations array which we compare against the newly |
12026 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
12027 | struct bp_location **old_locations, **old_locp; | |
12028 | unsigned old_locations_count; | |
876fa593 | 12029 | |
f5336ca5 PA |
12030 | old_locations = bp_locations; |
12031 | old_locations_count = bp_locations_count; | |
12032 | bp_locations = NULL; | |
12033 | bp_locations_count = 0; | |
12034 | cleanups = make_cleanup (xfree, old_locations); | |
0d381245 | 12035 | |
74960c60 | 12036 | ALL_BREAKPOINTS (b) |
876fa593 | 12037 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 12038 | bp_locations_count++; |
876fa593 | 12039 | |
f5336ca5 PA |
12040 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
12041 | locp = bp_locations; | |
876fa593 JK |
12042 | ALL_BREAKPOINTS (b) |
12043 | for (loc = b->loc; loc; loc = loc->next) | |
12044 | *locp++ = loc; | |
f5336ca5 PA |
12045 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
12046 | bp_locations_compare); | |
876fa593 | 12047 | |
f5336ca5 | 12048 | bp_locations_target_extensions_update (); |
74960c60 | 12049 | |
4a64f543 MS |
12050 | /* Identify bp_location instances that are no longer present in the |
12051 | new list, and therefore should be freed. Note that it's not | |
12052 | necessary that those locations should be removed from inferior -- | |
12053 | if there's another location at the same address (previously | |
12054 | marked as duplicate), we don't need to remove/insert the | |
12055 | location. | |
876fa593 | 12056 | |
4a64f543 MS |
12057 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12058 | and former bp_location array state respectively. */ | |
876fa593 | 12059 | |
f5336ca5 PA |
12060 | locp = bp_locations; |
12061 | for (old_locp = old_locations; | |
12062 | old_locp < old_locations + old_locations_count; | |
876fa593 | 12063 | old_locp++) |
74960c60 | 12064 | { |
876fa593 | 12065 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12066 | struct bp_location **loc2p; |
876fa593 | 12067 | |
e5dd4106 | 12068 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12069 | not, we have to free it. */ |
c7d46a38 | 12070 | int found_object = 0; |
20874c92 VP |
12071 | /* Tells if the location should remain inserted in the target. */ |
12072 | int keep_in_target = 0; | |
12073 | int removed = 0; | |
876fa593 | 12074 | |
4a64f543 MS |
12075 | /* Skip LOCP entries which will definitely never be needed. |
12076 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 12077 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 12078 | && (*locp)->address < old_loc->address) |
876fa593 | 12079 | locp++; |
c7d46a38 PA |
12080 | |
12081 | for (loc2p = locp; | |
f5336ca5 | 12082 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
12083 | && (*loc2p)->address == old_loc->address); |
12084 | loc2p++) | |
12085 | { | |
b775012e LM |
12086 | /* Check if this is a new/duplicated location or a duplicated |
12087 | location that had its condition modified. If so, we want to send | |
12088 | its condition to the target if evaluation of conditions is taking | |
12089 | place there. */ | |
12090 | if ((*loc2p)->condition_changed == condition_modified | |
12091 | && (last_addr != old_loc->address | |
12092 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12093 | { |
b775012e LM |
12094 | force_breakpoint_reinsertion (*loc2p); |
12095 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12096 | } |
b775012e LM |
12097 | |
12098 | if (*loc2p == old_loc) | |
12099 | found_object = 1; | |
c7d46a38 | 12100 | } |
74960c60 | 12101 | |
b775012e LM |
12102 | /* We have already handled this address, update it so that we don't |
12103 | have to go through updates again. */ | |
12104 | last_addr = old_loc->address; | |
12105 | ||
12106 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12107 | if (!found_object) | |
12108 | force_breakpoint_reinsertion (old_loc); | |
12109 | ||
4a64f543 MS |
12110 | /* If this location is no longer present, and inserted, look if |
12111 | there's maybe a new location at the same address. If so, | |
12112 | mark that one inserted, and don't remove this one. This is | |
12113 | needed so that we don't have a time window where a breakpoint | |
12114 | at certain location is not inserted. */ | |
74960c60 | 12115 | |
876fa593 | 12116 | if (old_loc->inserted) |
0d381245 | 12117 | { |
4a64f543 MS |
12118 | /* If the location is inserted now, we might have to remove |
12119 | it. */ | |
74960c60 | 12120 | |
876fa593 | 12121 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12122 | { |
4a64f543 MS |
12123 | /* The location is still present in the location list, |
12124 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12125 | keep_in_target = 1; |
74960c60 VP |
12126 | } |
12127 | else | |
12128 | { | |
b775012e LM |
12129 | /* This location still exists, but it won't be kept in the |
12130 | target since it may have been disabled. We proceed to | |
12131 | remove its target-side condition. */ | |
12132 | ||
4a64f543 MS |
12133 | /* The location is either no longer present, or got |
12134 | disabled. See if there's another location at the | |
12135 | same address, in which case we don't need to remove | |
12136 | this one from the target. */ | |
876fa593 | 12137 | |
2bdf28a0 | 12138 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12139 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12140 | { | |
876fa593 | 12141 | for (loc2p = locp; |
f5336ca5 | 12142 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 12143 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
12144 | loc2p++) |
12145 | { | |
12146 | struct bp_location *loc2 = *loc2p; | |
12147 | ||
2d134ed3 | 12148 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12149 | { |
85d721b8 PA |
12150 | /* Read watchpoint locations are switched to |
12151 | access watchpoints, if the former are not | |
12152 | supported, but the latter are. */ | |
12153 | if (is_hardware_watchpoint (old_loc->owner)) | |
12154 | { | |
12155 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12156 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12157 | } | |
12158 | ||
934709f0 PW |
12159 | /* loc2 is a duplicated location. We need to check |
12160 | if it should be inserted in case it will be | |
12161 | unduplicated. */ | |
12162 | if (loc2 != old_loc | |
12163 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12164 | { |
934709f0 | 12165 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12166 | keep_in_target = 1; |
12167 | break; | |
12168 | } | |
876fa593 JK |
12169 | } |
12170 | } | |
12171 | } | |
74960c60 VP |
12172 | } |
12173 | ||
20874c92 VP |
12174 | if (!keep_in_target) |
12175 | { | |
834c0d03 | 12176 | if (remove_breakpoint (old_loc)) |
20874c92 | 12177 | { |
4a64f543 MS |
12178 | /* This is just about all we can do. We could keep |
12179 | this location on the global list, and try to | |
12180 | remove it next time, but there's no particular | |
12181 | reason why we will succeed next time. | |
20874c92 | 12182 | |
4a64f543 MS |
12183 | Note that at this point, old_loc->owner is still |
12184 | valid, as delete_breakpoint frees the breakpoint | |
12185 | only after calling us. */ | |
3e43a32a MS |
12186 | printf_filtered (_("warning: Error removing " |
12187 | "breakpoint %d\n"), | |
876fa593 | 12188 | old_loc->owner->number); |
20874c92 VP |
12189 | } |
12190 | removed = 1; | |
12191 | } | |
0d381245 | 12192 | } |
74960c60 VP |
12193 | |
12194 | if (!found_object) | |
1c5cfe86 | 12195 | { |
fbea99ea | 12196 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12197 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12198 | { |
db82e815 PA |
12199 | /* This location was removed from the target. In |
12200 | non-stop mode, a race condition is possible where | |
12201 | we've removed a breakpoint, but stop events for that | |
12202 | breakpoint are already queued and will arrive later. | |
12203 | We apply an heuristic to be able to distinguish such | |
12204 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12205 | breakpoint location for a bit, and will retire it | |
12206 | after we see some number of events. The theory here | |
12207 | is that reporting of events should, "on the average", | |
12208 | be fair, so after a while we'll see events from all | |
12209 | threads that have anything of interest, and no longer | |
12210 | need to keep this breakpoint location around. We | |
12211 | don't hold locations forever so to reduce chances of | |
12212 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12213 | SIGTRAP. | |
12214 | ||
12215 | The heuristic failing can be disastrous on | |
12216 | decr_pc_after_break targets. | |
12217 | ||
12218 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12219 | if we fail to recognize a late breakpoint SIGTRAP, | |
12220 | because events_till_retirement has reached 0 too | |
12221 | soon, we'll fail to do the PC adjustment, and report | |
12222 | a random SIGTRAP to the user. When the user resumes | |
12223 | the inferior, it will most likely immediately crash | |
2dec564e | 12224 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12225 | corrupted, because of being resumed e.g., in the |
12226 | middle of a multi-byte instruction, or skipped a | |
12227 | one-byte instruction. This was actually seen happen | |
12228 | on native x86-linux, and should be less rare on | |
12229 | targets that do not support new thread events, like | |
12230 | remote, due to the heuristic depending on | |
12231 | thread_count. | |
12232 | ||
12233 | Mistaking a random SIGTRAP for a breakpoint trap | |
12234 | causes similar symptoms (PC adjustment applied when | |
12235 | it shouldn't), but then again, playing with SIGTRAPs | |
12236 | behind the debugger's back is asking for trouble. | |
12237 | ||
12238 | Since hardware watchpoint traps are always | |
12239 | distinguishable from other traps, so we don't need to | |
12240 | apply keep hardware watchpoint moribund locations | |
12241 | around. We simply always ignore hardware watchpoint | |
12242 | traps we can no longer explain. */ | |
12243 | ||
876fa593 JK |
12244 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12245 | old_loc->owner = NULL; | |
20874c92 | 12246 | |
876fa593 | 12247 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12248 | } |
12249 | else | |
f431efe5 PA |
12250 | { |
12251 | old_loc->owner = NULL; | |
12252 | decref_bp_location (&old_loc); | |
12253 | } | |
20874c92 | 12254 | } |
74960c60 | 12255 | } |
1c5cfe86 | 12256 | |
348d480f PA |
12257 | /* Rescan breakpoints at the same address and section, marking the |
12258 | first one as "first" and any others as "duplicates". This is so | |
12259 | that the bpt instruction is only inserted once. If we have a | |
12260 | permanent breakpoint at the same place as BPT, make that one the | |
12261 | official one, and the rest as duplicates. Permanent breakpoints | |
12262 | are sorted first for the same address. | |
12263 | ||
12264 | Do the same for hardware watchpoints, but also considering the | |
12265 | watchpoint's type (regular/access/read) and length. */ | |
12266 | ||
12267 | bp_loc_first = NULL; | |
12268 | wp_loc_first = NULL; | |
12269 | awp_loc_first = NULL; | |
12270 | rwp_loc_first = NULL; | |
12271 | ALL_BP_LOCATIONS (loc, locp) | |
12272 | { | |
12273 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12274 | non-NULL. */ | |
348d480f | 12275 | struct bp_location **loc_first_p; |
d3fbdd86 | 12276 | b = loc->owner; |
348d480f | 12277 | |
6f380991 | 12278 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12279 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12280 | /* Don't detect duplicate for tracepoint locations because they are |
12281 | never duplicated. See the comments in field `duplicate' of | |
12282 | `struct bp_location'. */ | |
348d480f | 12283 | || is_tracepoint (b)) |
b775012e LM |
12284 | { |
12285 | /* Clear the condition modification flag. */ | |
12286 | loc->condition_changed = condition_unchanged; | |
12287 | continue; | |
12288 | } | |
348d480f | 12289 | |
348d480f PA |
12290 | if (b->type == bp_hardware_watchpoint) |
12291 | loc_first_p = &wp_loc_first; | |
12292 | else if (b->type == bp_read_watchpoint) | |
12293 | loc_first_p = &rwp_loc_first; | |
12294 | else if (b->type == bp_access_watchpoint) | |
12295 | loc_first_p = &awp_loc_first; | |
12296 | else | |
12297 | loc_first_p = &bp_loc_first; | |
12298 | ||
12299 | if (*loc_first_p == NULL | |
12300 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12301 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12302 | { | |
12303 | *loc_first_p = loc; | |
12304 | loc->duplicate = 0; | |
b775012e LM |
12305 | |
12306 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12307 | { | |
12308 | loc->needs_update = 1; | |
12309 | /* Clear the condition modification flag. */ | |
12310 | loc->condition_changed = condition_unchanged; | |
12311 | } | |
348d480f PA |
12312 | continue; |
12313 | } | |
12314 | ||
934709f0 PW |
12315 | |
12316 | /* This and the above ensure the invariant that the first location | |
12317 | is not duplicated, and is the inserted one. | |
12318 | All following are marked as duplicated, and are not inserted. */ | |
12319 | if (loc->inserted) | |
12320 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12321 | loc->duplicate = 1; |
12322 | ||
b775012e LM |
12323 | /* Clear the condition modification flag. */ |
12324 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12325 | } |
12326 | ||
a25a5a45 | 12327 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12328 | { |
04086b45 | 12329 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12330 | insert_breakpoint_locations (); |
12331 | else | |
12332 | { | |
44702360 PA |
12333 | /* Even though the caller told us to not insert new |
12334 | locations, we may still need to update conditions on the | |
12335 | target's side of breakpoints that were already inserted | |
12336 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12337 | only update conditions for locations that are marked |
12338 | "needs_update". */ | |
12339 | update_inserted_breakpoint_locations (); | |
12340 | } | |
12341 | } | |
348d480f | 12342 | |
04086b45 | 12343 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12344 | download_tracepoint_locations (); |
12345 | ||
348d480f PA |
12346 | do_cleanups (cleanups); |
12347 | } | |
12348 | ||
12349 | void | |
12350 | breakpoint_retire_moribund (void) | |
12351 | { | |
12352 | struct bp_location *loc; | |
12353 | int ix; | |
12354 | ||
12355 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12356 | if (--(loc->events_till_retirement) == 0) | |
12357 | { | |
12358 | decref_bp_location (&loc); | |
12359 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12360 | --ix; | |
12361 | } | |
12362 | } | |
12363 | ||
12364 | static void | |
44702360 | 12365 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12366 | { |
348d480f | 12367 | |
492d29ea PA |
12368 | TRY |
12369 | { | |
12370 | update_global_location_list (insert_mode); | |
12371 | } | |
12372 | CATCH (e, RETURN_MASK_ERROR) | |
12373 | { | |
12374 | } | |
12375 | END_CATCH | |
348d480f PA |
12376 | } |
12377 | ||
12378 | /* Clear BKP from a BPS. */ | |
12379 | ||
12380 | static void | |
12381 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12382 | { | |
12383 | bpstat bs; | |
12384 | ||
12385 | for (bs = bps; bs; bs = bs->next) | |
12386 | if (bs->breakpoint_at == bpt) | |
12387 | { | |
12388 | bs->breakpoint_at = NULL; | |
12389 | bs->old_val = NULL; | |
12390 | /* bs->commands will be freed later. */ | |
12391 | } | |
12392 | } | |
12393 | ||
12394 | /* Callback for iterate_over_threads. */ | |
12395 | static int | |
12396 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12397 | { | |
9a3c8263 | 12398 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12399 | |
12400 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12401 | return 0; | |
12402 | } | |
12403 | ||
12404 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12405 | callbacks. */ | |
12406 | ||
12407 | static void | |
12408 | say_where (struct breakpoint *b) | |
12409 | { | |
12410 | struct value_print_options opts; | |
12411 | ||
12412 | get_user_print_options (&opts); | |
12413 | ||
12414 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12415 | single string. */ | |
12416 | if (b->loc == NULL) | |
12417 | { | |
f00aae0f KS |
12418 | /* For pending locations, the output differs slightly based |
12419 | on b->extra_string. If this is non-NULL, it contains either | |
12420 | a condition or dprintf arguments. */ | |
12421 | if (b->extra_string == NULL) | |
12422 | { | |
12423 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12424 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12425 | } |
12426 | else if (b->type == bp_dprintf) | |
12427 | { | |
12428 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12429 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12430 | b->extra_string); |
12431 | } | |
12432 | else | |
12433 | { | |
12434 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12435 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12436 | b->extra_string); |
12437 | } | |
348d480f PA |
12438 | } |
12439 | else | |
12440 | { | |
2f202fde | 12441 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12442 | { |
12443 | printf_filtered (" at "); | |
12444 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12445 | gdb_stdout); | |
12446 | } | |
2f202fde | 12447 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12448 | { |
12449 | /* If there is a single location, we can print the location | |
12450 | more nicely. */ | |
12451 | if (b->loc->next == NULL) | |
12452 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12453 | symtab_to_filename_for_display (b->loc->symtab), |
12454 | b->loc->line_number); | |
f8eba3c6 TT |
12455 | else |
12456 | /* This is not ideal, but each location may have a | |
12457 | different file name, and this at least reflects the | |
12458 | real situation somewhat. */ | |
f00aae0f | 12459 | printf_filtered (": %s.", |
d28cd78a | 12460 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12461 | } |
348d480f PA |
12462 | |
12463 | if (b->loc->next) | |
12464 | { | |
12465 | struct bp_location *loc = b->loc; | |
12466 | int n = 0; | |
12467 | for (; loc; loc = loc->next) | |
12468 | ++n; | |
12469 | printf_filtered (" (%d locations)", n); | |
12470 | } | |
12471 | } | |
12472 | } | |
12473 | ||
348d480f PA |
12474 | /* Default bp_location_ops methods. */ |
12475 | ||
12476 | static void | |
12477 | bp_location_dtor (struct bp_location *self) | |
12478 | { | |
348d480f PA |
12479 | xfree (self->function_name); |
12480 | } | |
12481 | ||
12482 | static const struct bp_location_ops bp_location_ops = | |
12483 | { | |
12484 | bp_location_dtor | |
12485 | }; | |
12486 | ||
c1fc2657 | 12487 | /* Destructor for the breakpoint base class. */ |
348d480f | 12488 | |
c1fc2657 | 12489 | breakpoint::~breakpoint () |
348d480f | 12490 | { |
c1fc2657 SM |
12491 | xfree (this->cond_string); |
12492 | xfree (this->extra_string); | |
12493 | xfree (this->filter); | |
348d480f PA |
12494 | } |
12495 | ||
2060206e PA |
12496 | static struct bp_location * |
12497 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12498 | { |
5625a286 | 12499 | return new bp_location (&bp_location_ops, self); |
348d480f PA |
12500 | } |
12501 | ||
2060206e PA |
12502 | static void |
12503 | base_breakpoint_re_set (struct breakpoint *b) | |
12504 | { | |
12505 | /* Nothing to re-set. */ | |
12506 | } | |
12507 | ||
12508 | #define internal_error_pure_virtual_called() \ | |
12509 | gdb_assert_not_reached ("pure virtual function called") | |
12510 | ||
12511 | static int | |
12512 | base_breakpoint_insert_location (struct bp_location *bl) | |
12513 | { | |
12514 | internal_error_pure_virtual_called (); | |
12515 | } | |
12516 | ||
12517 | static int | |
73971819 PA |
12518 | base_breakpoint_remove_location (struct bp_location *bl, |
12519 | enum remove_bp_reason reason) | |
2060206e PA |
12520 | { |
12521 | internal_error_pure_virtual_called (); | |
12522 | } | |
12523 | ||
12524 | static int | |
12525 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12526 | struct address_space *aspace, | |
09ac7c10 TT |
12527 | CORE_ADDR bp_addr, |
12528 | const struct target_waitstatus *ws) | |
2060206e PA |
12529 | { |
12530 | internal_error_pure_virtual_called (); | |
12531 | } | |
12532 | ||
12533 | static void | |
12534 | base_breakpoint_check_status (bpstat bs) | |
12535 | { | |
12536 | /* Always stop. */ | |
12537 | } | |
12538 | ||
12539 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12540 | errors. */ | |
12541 | ||
12542 | static int | |
12543 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12544 | { | |
12545 | internal_error_pure_virtual_called (); | |
12546 | } | |
12547 | ||
12548 | /* A "resources_needed" breakpoint_ops method that just internal | |
12549 | errors. */ | |
12550 | ||
12551 | static int | |
12552 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12553 | { | |
12554 | internal_error_pure_virtual_called (); | |
12555 | } | |
12556 | ||
12557 | static enum print_stop_action | |
12558 | base_breakpoint_print_it (bpstat bs) | |
12559 | { | |
12560 | internal_error_pure_virtual_called (); | |
12561 | } | |
12562 | ||
12563 | static void | |
12564 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12565 | struct ui_out *uiout) | |
12566 | { | |
12567 | /* nothing */ | |
12568 | } | |
12569 | ||
12570 | static void | |
12571 | base_breakpoint_print_mention (struct breakpoint *b) | |
12572 | { | |
12573 | internal_error_pure_virtual_called (); | |
12574 | } | |
12575 | ||
12576 | static void | |
12577 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12578 | { | |
12579 | internal_error_pure_virtual_called (); | |
12580 | } | |
12581 | ||
983af33b | 12582 | static void |
f00aae0f KS |
12583 | base_breakpoint_create_sals_from_location |
12584 | (const struct event_location *location, | |
12585 | struct linespec_result *canonical, | |
12586 | enum bptype type_wanted) | |
983af33b SDJ |
12587 | { |
12588 | internal_error_pure_virtual_called (); | |
12589 | } | |
12590 | ||
12591 | static void | |
12592 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12593 | struct linespec_result *c, | |
e1e01040 PA |
12594 | gdb::unique_xmalloc_ptr<char> cond_string, |
12595 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12596 | enum bptype type_wanted, |
12597 | enum bpdisp disposition, | |
12598 | int thread, | |
12599 | int task, int ignore_count, | |
12600 | const struct breakpoint_ops *o, | |
12601 | int from_tty, int enabled, | |
44f238bb | 12602 | int internal, unsigned flags) |
983af33b SDJ |
12603 | { |
12604 | internal_error_pure_virtual_called (); | |
12605 | } | |
12606 | ||
6c5b2ebe | 12607 | static std::vector<symtab_and_line> |
f00aae0f KS |
12608 | base_breakpoint_decode_location (struct breakpoint *b, |
12609 | const struct event_location *location, | |
6c5b2ebe | 12610 | struct program_space *search_pspace) |
983af33b SDJ |
12611 | { |
12612 | internal_error_pure_virtual_called (); | |
12613 | } | |
12614 | ||
ab04a2af TT |
12615 | /* The default 'explains_signal' method. */ |
12616 | ||
47591c29 | 12617 | static int |
427cd150 | 12618 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12619 | { |
47591c29 | 12620 | return 1; |
ab04a2af TT |
12621 | } |
12622 | ||
9d6e6e84 HZ |
12623 | /* The default "after_condition_true" method. */ |
12624 | ||
12625 | static void | |
12626 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12627 | { | |
12628 | /* Nothing to do. */ | |
12629 | } | |
12630 | ||
ab04a2af | 12631 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12632 | { |
2060206e PA |
12633 | base_breakpoint_allocate_location, |
12634 | base_breakpoint_re_set, | |
12635 | base_breakpoint_insert_location, | |
12636 | base_breakpoint_remove_location, | |
12637 | base_breakpoint_breakpoint_hit, | |
12638 | base_breakpoint_check_status, | |
12639 | base_breakpoint_resources_needed, | |
12640 | base_breakpoint_works_in_software_mode, | |
12641 | base_breakpoint_print_it, | |
12642 | NULL, | |
12643 | base_breakpoint_print_one_detail, | |
12644 | base_breakpoint_print_mention, | |
983af33b | 12645 | base_breakpoint_print_recreate, |
5f700d83 | 12646 | base_breakpoint_create_sals_from_location, |
983af33b | 12647 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12648 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12649 | base_breakpoint_explains_signal, |
12650 | base_breakpoint_after_condition_true, | |
2060206e PA |
12651 | }; |
12652 | ||
12653 | /* Default breakpoint_ops methods. */ | |
12654 | ||
12655 | static void | |
348d480f PA |
12656 | bkpt_re_set (struct breakpoint *b) |
12657 | { | |
06edf0c0 | 12658 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12659 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12660 | { |
f00aae0f | 12661 | /* Anything without a location can't be re-set. */ |
348d480f | 12662 | delete_breakpoint (b); |
06edf0c0 | 12663 | return; |
348d480f | 12664 | } |
06edf0c0 PA |
12665 | |
12666 | breakpoint_re_set_default (b); | |
348d480f PA |
12667 | } |
12668 | ||
2060206e | 12669 | static int |
348d480f PA |
12670 | bkpt_insert_location (struct bp_location *bl) |
12671 | { | |
cd6c3b4f YQ |
12672 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12673 | ||
579c6ad9 | 12674 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12675 | bl->target_info.placed_address = addr; |
12676 | ||
348d480f | 12677 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12678 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12679 | else |
7c16b83e | 12680 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12681 | } |
12682 | ||
2060206e | 12683 | static int |
73971819 | 12684 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12685 | { |
12686 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12687 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12688 | else | |
73971819 | 12689 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12690 | } |
12691 | ||
2060206e | 12692 | static int |
348d480f | 12693 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12694 | struct address_space *aspace, CORE_ADDR bp_addr, |
12695 | const struct target_waitstatus *ws) | |
348d480f | 12696 | { |
09ac7c10 | 12697 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12698 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12699 | return 0; |
12700 | ||
348d480f PA |
12701 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12702 | aspace, bp_addr)) | |
12703 | return 0; | |
12704 | ||
12705 | if (overlay_debugging /* unmapped overlay section */ | |
12706 | && section_is_overlay (bl->section) | |
12707 | && !section_is_mapped (bl->section)) | |
12708 | return 0; | |
12709 | ||
12710 | return 1; | |
12711 | } | |
12712 | ||
cd1608cc PA |
12713 | static int |
12714 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
12715 | struct address_space *aspace, CORE_ADDR bp_addr, | |
12716 | const struct target_waitstatus *ws) | |
12717 | { | |
12718 | if (dprintf_style == dprintf_style_agent | |
12719 | && target_can_run_breakpoint_commands ()) | |
12720 | { | |
12721 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12722 | for this address it must be for a breakpoint that happens to | |
12723 | be set at the same address. */ | |
12724 | return 0; | |
12725 | } | |
12726 | ||
12727 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12728 | } | |
12729 | ||
2060206e | 12730 | static int |
348d480f PA |
12731 | bkpt_resources_needed (const struct bp_location *bl) |
12732 | { | |
12733 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12734 | ||
12735 | return 1; | |
12736 | } | |
12737 | ||
2060206e | 12738 | static enum print_stop_action |
348d480f PA |
12739 | bkpt_print_it (bpstat bs) |
12740 | { | |
348d480f PA |
12741 | struct breakpoint *b; |
12742 | const struct bp_location *bl; | |
001c8c33 | 12743 | int bp_temp; |
79a45e25 | 12744 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12745 | |
12746 | gdb_assert (bs->bp_location_at != NULL); | |
12747 | ||
12748 | bl = bs->bp_location_at; | |
12749 | b = bs->breakpoint_at; | |
12750 | ||
001c8c33 PA |
12751 | bp_temp = b->disposition == disp_del; |
12752 | if (bl->address != bl->requested_address) | |
12753 | breakpoint_adjustment_warning (bl->requested_address, | |
12754 | bl->address, | |
12755 | b->number, 1); | |
12756 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12757 | maybe_print_thread_hit_breakpoint (uiout); |
12758 | ||
001c8c33 | 12759 | if (bp_temp) |
112e8700 | 12760 | uiout->text ("Temporary breakpoint "); |
001c8c33 | 12761 | else |
112e8700 SM |
12762 | uiout->text ("Breakpoint "); |
12763 | if (uiout->is_mi_like_p ()) | |
348d480f | 12764 | { |
112e8700 | 12765 | uiout->field_string ("reason", |
001c8c33 | 12766 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12767 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12768 | } |
112e8700 SM |
12769 | uiout->field_int ("bkptno", b->number); |
12770 | uiout->text (", "); | |
06edf0c0 | 12771 | |
001c8c33 | 12772 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12773 | } |
12774 | ||
2060206e | 12775 | static void |
06edf0c0 PA |
12776 | bkpt_print_mention (struct breakpoint *b) |
12777 | { | |
112e8700 | 12778 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12779 | return; |
12780 | ||
12781 | switch (b->type) | |
12782 | { | |
12783 | case bp_breakpoint: | |
12784 | case bp_gnu_ifunc_resolver: | |
12785 | if (b->disposition == disp_del) | |
12786 | printf_filtered (_("Temporary breakpoint")); | |
12787 | else | |
12788 | printf_filtered (_("Breakpoint")); | |
12789 | printf_filtered (_(" %d"), b->number); | |
12790 | if (b->type == bp_gnu_ifunc_resolver) | |
12791 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12792 | break; | |
12793 | case bp_hardware_breakpoint: | |
12794 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12795 | break; | |
e7e0cddf SS |
12796 | case bp_dprintf: |
12797 | printf_filtered (_("Dprintf %d"), b->number); | |
12798 | break; | |
06edf0c0 PA |
12799 | } |
12800 | ||
12801 | say_where (b); | |
12802 | } | |
12803 | ||
2060206e | 12804 | static void |
06edf0c0 PA |
12805 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12806 | { | |
12807 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12808 | fprintf_unfiltered (fp, "tbreak"); | |
12809 | else if (tp->type == bp_breakpoint) | |
12810 | fprintf_unfiltered (fp, "break"); | |
12811 | else if (tp->type == bp_hardware_breakpoint | |
12812 | && tp->disposition == disp_del) | |
12813 | fprintf_unfiltered (fp, "thbreak"); | |
12814 | else if (tp->type == bp_hardware_breakpoint) | |
12815 | fprintf_unfiltered (fp, "hbreak"); | |
12816 | else | |
12817 | internal_error (__FILE__, __LINE__, | |
12818 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12819 | ||
f00aae0f | 12820 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12821 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12822 | |
12823 | /* Print out extra_string if this breakpoint is pending. It might | |
12824 | contain, for example, conditions that were set by the user. */ | |
12825 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12826 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12827 | ||
dd11a36c | 12828 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12829 | } |
12830 | ||
983af33b | 12831 | static void |
f00aae0f KS |
12832 | bkpt_create_sals_from_location (const struct event_location *location, |
12833 | struct linespec_result *canonical, | |
12834 | enum bptype type_wanted) | |
983af33b | 12835 | { |
f00aae0f | 12836 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12837 | } |
12838 | ||
12839 | static void | |
12840 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12841 | struct linespec_result *canonical, | |
e1e01040 PA |
12842 | gdb::unique_xmalloc_ptr<char> cond_string, |
12843 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12844 | enum bptype type_wanted, |
12845 | enum bpdisp disposition, | |
12846 | int thread, | |
12847 | int task, int ignore_count, | |
12848 | const struct breakpoint_ops *ops, | |
12849 | int from_tty, int enabled, | |
44f238bb | 12850 | int internal, unsigned flags) |
983af33b | 12851 | { |
023fa29b | 12852 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12853 | std::move (cond_string), |
12854 | std::move (extra_string), | |
e7e0cddf | 12855 | type_wanted, |
983af33b SDJ |
12856 | disposition, thread, task, |
12857 | ignore_count, ops, from_tty, | |
44f238bb | 12858 | enabled, internal, flags); |
983af33b SDJ |
12859 | } |
12860 | ||
6c5b2ebe | 12861 | static std::vector<symtab_and_line> |
f00aae0f KS |
12862 | bkpt_decode_location (struct breakpoint *b, |
12863 | const struct event_location *location, | |
6c5b2ebe | 12864 | struct program_space *search_pspace) |
983af33b | 12865 | { |
6c5b2ebe | 12866 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12867 | } |
12868 | ||
06edf0c0 PA |
12869 | /* Virtual table for internal breakpoints. */ |
12870 | ||
12871 | static void | |
12872 | internal_bkpt_re_set (struct breakpoint *b) | |
12873 | { | |
12874 | switch (b->type) | |
12875 | { | |
12876 | /* Delete overlay event and longjmp master breakpoints; they | |
12877 | will be reset later by breakpoint_re_set. */ | |
12878 | case bp_overlay_event: | |
12879 | case bp_longjmp_master: | |
12880 | case bp_std_terminate_master: | |
12881 | case bp_exception_master: | |
12882 | delete_breakpoint (b); | |
12883 | break; | |
12884 | ||
12885 | /* This breakpoint is special, it's set up when the inferior | |
12886 | starts and we really don't want to touch it. */ | |
12887 | case bp_shlib_event: | |
12888 | ||
12889 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12890 | it is set up, we do not want to touch it. */ | |
12891 | case bp_thread_event: | |
12892 | break; | |
12893 | } | |
12894 | } | |
12895 | ||
12896 | static void | |
12897 | internal_bkpt_check_status (bpstat bs) | |
12898 | { | |
a9b3a50f PA |
12899 | if (bs->breakpoint_at->type == bp_shlib_event) |
12900 | { | |
12901 | /* If requested, stop when the dynamic linker notifies GDB of | |
12902 | events. This allows the user to get control and place | |
12903 | breakpoints in initializer routines for dynamically loaded | |
12904 | objects (among other things). */ | |
12905 | bs->stop = stop_on_solib_events; | |
12906 | bs->print = stop_on_solib_events; | |
12907 | } | |
12908 | else | |
12909 | bs->stop = 0; | |
06edf0c0 PA |
12910 | } |
12911 | ||
12912 | static enum print_stop_action | |
12913 | internal_bkpt_print_it (bpstat bs) | |
12914 | { | |
06edf0c0 | 12915 | struct breakpoint *b; |
06edf0c0 | 12916 | |
06edf0c0 PA |
12917 | b = bs->breakpoint_at; |
12918 | ||
06edf0c0 PA |
12919 | switch (b->type) |
12920 | { | |
348d480f PA |
12921 | case bp_shlib_event: |
12922 | /* Did we stop because the user set the stop_on_solib_events | |
12923 | variable? (If so, we report this as a generic, "Stopped due | |
12924 | to shlib event" message.) */ | |
edcc5120 | 12925 | print_solib_event (0); |
348d480f PA |
12926 | break; |
12927 | ||
12928 | case bp_thread_event: | |
12929 | /* Not sure how we will get here. | |
12930 | GDB should not stop for these breakpoints. */ | |
12931 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12932 | break; |
12933 | ||
12934 | case bp_overlay_event: | |
12935 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12936 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12937 | break; |
12938 | ||
12939 | case bp_longjmp_master: | |
12940 | /* These should never be enabled. */ | |
12941 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12942 | break; |
12943 | ||
12944 | case bp_std_terminate_master: | |
12945 | /* These should never be enabled. */ | |
12946 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12947 | "gdb should not stop!\n")); | |
348d480f PA |
12948 | break; |
12949 | ||
12950 | case bp_exception_master: | |
12951 | /* These should never be enabled. */ | |
12952 | printf_filtered (_("Exception Master Breakpoint: " | |
12953 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12954 | break; |
12955 | } | |
12956 | ||
001c8c33 | 12957 | return PRINT_NOTHING; |
06edf0c0 PA |
12958 | } |
12959 | ||
12960 | static void | |
12961 | internal_bkpt_print_mention (struct breakpoint *b) | |
12962 | { | |
12963 | /* Nothing to mention. These breakpoints are internal. */ | |
12964 | } | |
12965 | ||
06edf0c0 PA |
12966 | /* Virtual table for momentary breakpoints */ |
12967 | ||
12968 | static void | |
12969 | momentary_bkpt_re_set (struct breakpoint *b) | |
12970 | { | |
12971 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12972 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12973 | Otherwise these should have been blown away via the cleanup chain |
12974 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12975 | } | |
12976 | ||
12977 | static void | |
12978 | momentary_bkpt_check_status (bpstat bs) | |
12979 | { | |
12980 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12981 | } | |
12982 | ||
12983 | static enum print_stop_action | |
12984 | momentary_bkpt_print_it (bpstat bs) | |
12985 | { | |
001c8c33 | 12986 | return PRINT_UNKNOWN; |
348d480f PA |
12987 | } |
12988 | ||
06edf0c0 PA |
12989 | static void |
12990 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12991 | { |
06edf0c0 | 12992 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12993 | } |
12994 | ||
e2e4d78b JK |
12995 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12996 | ||
12997 | It gets cleared already on the removal of the first one of such placed | |
12998 | breakpoints. This is OK as they get all removed altogether. */ | |
12999 | ||
c1fc2657 | 13000 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 13001 | { |
c1fc2657 | 13002 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 13003 | |
c1fc2657 | 13004 | if (tp != NULL) |
e2e4d78b | 13005 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
13006 | } |
13007 | ||
55aa24fb SDJ |
13008 | /* Specific methods for probe breakpoints. */ |
13009 | ||
13010 | static int | |
13011 | bkpt_probe_insert_location (struct bp_location *bl) | |
13012 | { | |
13013 | int v = bkpt_insert_location (bl); | |
13014 | ||
13015 | if (v == 0) | |
13016 | { | |
13017 | /* The insertion was successful, now let's set the probe's semaphore | |
13018 | if needed. */ | |
0ea5cda8 SDJ |
13019 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13020 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13021 | bl->probe.objfile, | |
13022 | bl->gdbarch); | |
55aa24fb SDJ |
13023 | } |
13024 | ||
13025 | return v; | |
13026 | } | |
13027 | ||
13028 | static int | |
73971819 PA |
13029 | bkpt_probe_remove_location (struct bp_location *bl, |
13030 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13031 | { |
13032 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13033 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13034 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13035 | bl->probe.objfile, | |
13036 | bl->gdbarch); | |
55aa24fb | 13037 | |
73971819 | 13038 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13039 | } |
13040 | ||
13041 | static void | |
f00aae0f | 13042 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13043 | struct linespec_result *canonical, |
f00aae0f | 13044 | enum bptype type_wanted) |
55aa24fb SDJ |
13045 | { |
13046 | struct linespec_sals lsal; | |
13047 | ||
c2f4122d | 13048 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
13049 | lsal.canonical |
13050 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13051 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
13052 | } |
13053 | ||
6c5b2ebe | 13054 | static std::vector<symtab_and_line> |
f00aae0f KS |
13055 | bkpt_probe_decode_location (struct breakpoint *b, |
13056 | const struct event_location *location, | |
6c5b2ebe | 13057 | struct program_space *search_pspace) |
55aa24fb | 13058 | { |
6c5b2ebe PA |
13059 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
13060 | if (sals.empty ()) | |
55aa24fb | 13061 | error (_("probe not found")); |
6c5b2ebe | 13062 | return sals; |
55aa24fb SDJ |
13063 | } |
13064 | ||
348d480f | 13065 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13066 | |
348d480f PA |
13067 | static void |
13068 | tracepoint_re_set (struct breakpoint *b) | |
13069 | { | |
13070 | breakpoint_re_set_default (b); | |
13071 | } | |
876fa593 | 13072 | |
348d480f PA |
13073 | static int |
13074 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13075 | struct address_space *aspace, CORE_ADDR bp_addr, |
13076 | const struct target_waitstatus *ws) | |
348d480f PA |
13077 | { |
13078 | /* By definition, the inferior does not report stops at | |
13079 | tracepoints. */ | |
13080 | return 0; | |
74960c60 VP |
13081 | } |
13082 | ||
13083 | static void | |
348d480f PA |
13084 | tracepoint_print_one_detail (const struct breakpoint *self, |
13085 | struct ui_out *uiout) | |
74960c60 | 13086 | { |
d9b3f62e PA |
13087 | struct tracepoint *tp = (struct tracepoint *) self; |
13088 | if (tp->static_trace_marker_id) | |
348d480f PA |
13089 | { |
13090 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13091 | |
112e8700 SM |
13092 | uiout->text ("\tmarker id is "); |
13093 | uiout->field_string ("static-tracepoint-marker-string-id", | |
d9b3f62e | 13094 | tp->static_trace_marker_id); |
112e8700 | 13095 | uiout->text ("\n"); |
348d480f | 13096 | } |
0d381245 VP |
13097 | } |
13098 | ||
a474d7c2 | 13099 | static void |
348d480f | 13100 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13101 | { |
112e8700 | 13102 | if (current_uiout->is_mi_like_p ()) |
348d480f | 13103 | return; |
cc59ec59 | 13104 | |
348d480f PA |
13105 | switch (b->type) |
13106 | { | |
13107 | case bp_tracepoint: | |
13108 | printf_filtered (_("Tracepoint")); | |
13109 | printf_filtered (_(" %d"), b->number); | |
13110 | break; | |
13111 | case bp_fast_tracepoint: | |
13112 | printf_filtered (_("Fast tracepoint")); | |
13113 | printf_filtered (_(" %d"), b->number); | |
13114 | break; | |
13115 | case bp_static_tracepoint: | |
13116 | printf_filtered (_("Static tracepoint")); | |
13117 | printf_filtered (_(" %d"), b->number); | |
13118 | break; | |
13119 | default: | |
13120 | internal_error (__FILE__, __LINE__, | |
13121 | _("unhandled tracepoint type %d"), (int) b->type); | |
13122 | } | |
13123 | ||
13124 | say_where (b); | |
a474d7c2 PA |
13125 | } |
13126 | ||
348d480f | 13127 | static void |
d9b3f62e | 13128 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13129 | { |
d9b3f62e PA |
13130 | struct tracepoint *tp = (struct tracepoint *) self; |
13131 | ||
13132 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13133 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13134 | else if (self->type == bp_static_tracepoint) |
348d480f | 13135 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13136 | else if (self->type == bp_tracepoint) |
348d480f PA |
13137 | fprintf_unfiltered (fp, "trace"); |
13138 | else | |
13139 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13140 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13141 | |
f00aae0f | 13142 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13143 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
13144 | print_recreate_thread (self, fp); |
13145 | ||
13146 | if (tp->pass_count) | |
13147 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13148 | } |
13149 | ||
983af33b | 13150 | static void |
f00aae0f KS |
13151 | tracepoint_create_sals_from_location (const struct event_location *location, |
13152 | struct linespec_result *canonical, | |
13153 | enum bptype type_wanted) | |
983af33b | 13154 | { |
f00aae0f | 13155 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13156 | } |
13157 | ||
13158 | static void | |
13159 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13160 | struct linespec_result *canonical, | |
e1e01040 PA |
13161 | gdb::unique_xmalloc_ptr<char> cond_string, |
13162 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13163 | enum bptype type_wanted, |
13164 | enum bpdisp disposition, | |
13165 | int thread, | |
13166 | int task, int ignore_count, | |
13167 | const struct breakpoint_ops *ops, | |
13168 | int from_tty, int enabled, | |
44f238bb | 13169 | int internal, unsigned flags) |
983af33b | 13170 | { |
023fa29b | 13171 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13172 | std::move (cond_string), |
13173 | std::move (extra_string), | |
e7e0cddf | 13174 | type_wanted, |
983af33b SDJ |
13175 | disposition, thread, task, |
13176 | ignore_count, ops, from_tty, | |
44f238bb | 13177 | enabled, internal, flags); |
983af33b SDJ |
13178 | } |
13179 | ||
6c5b2ebe | 13180 | static std::vector<symtab_and_line> |
f00aae0f KS |
13181 | tracepoint_decode_location (struct breakpoint *b, |
13182 | const struct event_location *location, | |
6c5b2ebe | 13183 | struct program_space *search_pspace) |
983af33b | 13184 | { |
6c5b2ebe | 13185 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
13186 | } |
13187 | ||
2060206e | 13188 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13189 | |
55aa24fb SDJ |
13190 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13191 | static probe. */ | |
13192 | ||
13193 | static void | |
f00aae0f KS |
13194 | tracepoint_probe_create_sals_from_location |
13195 | (const struct event_location *location, | |
13196 | struct linespec_result *canonical, | |
13197 | enum bptype type_wanted) | |
55aa24fb SDJ |
13198 | { |
13199 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13200 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13201 | } |
13202 | ||
6c5b2ebe | 13203 | static std::vector<symtab_and_line> |
f00aae0f KS |
13204 | tracepoint_probe_decode_location (struct breakpoint *b, |
13205 | const struct event_location *location, | |
6c5b2ebe | 13206 | struct program_space *search_pspace) |
55aa24fb SDJ |
13207 | { |
13208 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 13209 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
13210 | } |
13211 | ||
13212 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13213 | ||
5c2b4418 HZ |
13214 | /* Dprintf breakpoint_ops methods. */ |
13215 | ||
13216 | static void | |
13217 | dprintf_re_set (struct breakpoint *b) | |
13218 | { | |
13219 | breakpoint_re_set_default (b); | |
13220 | ||
f00aae0f KS |
13221 | /* extra_string should never be non-NULL for dprintf. */ |
13222 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13223 | |
13224 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13225 | 2 - create a dprintf, which resolves fine. | |
13226 | 3 - disconnect from target 1 | |
13227 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13228 | ||
13229 | After steps #3/#4, you'll want the dprintf command list to | |
13230 | be updated, because target 1 and 2 may well return different | |
13231 | answers for target_can_run_breakpoint_commands(). | |
13232 | Given absence of finer grained resetting, we get to do | |
13233 | it all the time. */ | |
13234 | if (b->extra_string != NULL) | |
13235 | update_dprintf_command_list (b); | |
13236 | } | |
13237 | ||
2d9442cc HZ |
13238 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13239 | ||
13240 | static void | |
13241 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13242 | { | |
f00aae0f | 13243 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 13244 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
13245 | tp->extra_string); |
13246 | print_recreate_thread (tp, fp); | |
13247 | } | |
13248 | ||
9d6e6e84 HZ |
13249 | /* Implement the "after_condition_true" breakpoint_ops method for |
13250 | dprintf. | |
13251 | ||
13252 | dprintf's are implemented with regular commands in their command | |
13253 | list, but we run the commands here instead of before presenting the | |
13254 | stop to the user, as dprintf's don't actually cause a stop. This | |
13255 | also makes it so that the commands of multiple dprintfs at the same | |
13256 | address are all handled. */ | |
13257 | ||
13258 | static void | |
13259 | dprintf_after_condition_true (struct bpstats *bs) | |
13260 | { | |
04afa70c | 13261 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
13262 | struct bpstats *tmp_bs_p = &tmp_bs; |
13263 | ||
13264 | /* dprintf's never cause a stop. This wasn't set in the | |
13265 | check_status hook instead because that would make the dprintf's | |
13266 | condition not be evaluated. */ | |
13267 | bs->stop = 0; | |
13268 | ||
13269 | /* Run the command list here. Take ownership of it instead of | |
13270 | copying. We never want these commands to run later in | |
13271 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13272 | be set at same address as this dprintf, or even if running the | |
13273 | commands here throws. */ | |
13274 | tmp_bs.commands = bs->commands; | |
13275 | bs->commands = NULL; | |
9d6e6e84 HZ |
13276 | |
13277 | bpstat_do_actions_1 (&tmp_bs_p); | |
13278 | ||
13279 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13280 | bpstat_do_actions_1 may return early without processing the whole | |
13281 | list. */ | |
9d6e6e84 HZ |
13282 | } |
13283 | ||
983af33b SDJ |
13284 | /* The breakpoint_ops structure to be used on static tracepoints with |
13285 | markers (`-m'). */ | |
13286 | ||
13287 | static void | |
f00aae0f | 13288 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13289 | struct linespec_result *canonical, |
f00aae0f | 13290 | enum bptype type_wanted) |
983af33b SDJ |
13291 | { |
13292 | struct linespec_sals lsal; | |
f00aae0f | 13293 | const char *arg_start, *arg; |
983af33b | 13294 | |
f00aae0f KS |
13295 | arg = arg_start = get_linespec_location (location); |
13296 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13297 | |
f2fc3015 TT |
13298 | std::string str (arg_start, arg - arg_start); |
13299 | const char *ptr = str.c_str (); | |
13300 | canonical->location = new_linespec_location (&ptr); | |
983af33b | 13301 | |
8e9e35b1 TT |
13302 | lsal.canonical |
13303 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13304 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
13305 | } |
13306 | ||
13307 | static void | |
13308 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13309 | struct linespec_result *canonical, | |
e1e01040 PA |
13310 | gdb::unique_xmalloc_ptr<char> cond_string, |
13311 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13312 | enum bptype type_wanted, |
13313 | enum bpdisp disposition, | |
13314 | int thread, | |
13315 | int task, int ignore_count, | |
13316 | const struct breakpoint_ops *ops, | |
13317 | int from_tty, int enabled, | |
44f238bb | 13318 | int internal, unsigned flags) |
983af33b | 13319 | { |
6c5b2ebe | 13320 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
13321 | |
13322 | /* If the user is creating a static tracepoint by marker id | |
13323 | (strace -m MARKER_ID), then store the sals index, so that | |
13324 | breakpoint_re_set can try to match up which of the newly | |
13325 | found markers corresponds to this one, and, don't try to | |
13326 | expand multiple locations for each sal, given than SALS | |
13327 | already should contain all sals for MARKER_ID. */ | |
13328 | ||
6c5b2ebe | 13329 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 13330 | { |
6c5b2ebe PA |
13331 | event_location_up location |
13332 | = copy_event_location (canonical->location.get ()); | |
983af33b | 13333 | |
b270e6f9 | 13334 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 13335 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 13336 | std::move (location), NULL, |
e1e01040 PA |
13337 | std::move (cond_string), |
13338 | std::move (extra_string), | |
e7e0cddf | 13339 | type_wanted, disposition, |
983af33b | 13340 | thread, task, ignore_count, ops, |
44f238bb | 13341 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13342 | canonical->special_display); |
13343 | /* Given that its possible to have multiple markers with | |
13344 | the same string id, if the user is creating a static | |
13345 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13346 | store the sals index, so that breakpoint_re_set can | |
13347 | try to match up which of the newly found markers | |
13348 | corresponds to this one */ | |
13349 | tp->static_trace_marker_id_idx = i; | |
13350 | ||
b270e6f9 | 13351 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
13352 | } |
13353 | } | |
13354 | ||
6c5b2ebe | 13355 | static std::vector<symtab_and_line> |
f00aae0f KS |
13356 | strace_marker_decode_location (struct breakpoint *b, |
13357 | const struct event_location *location, | |
6c5b2ebe | 13358 | struct program_space *search_pspace) |
983af33b SDJ |
13359 | { |
13360 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13361 | const char *s = get_linespec_location (location); |
983af33b | 13362 | |
6c5b2ebe PA |
13363 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
13364 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 13365 | { |
6c5b2ebe PA |
13366 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
13367 | sals.resize (1); | |
13368 | return sals; | |
983af33b SDJ |
13369 | } |
13370 | else | |
13371 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13372 | } | |
13373 | ||
13374 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13375 | ||
13376 | static int | |
13377 | strace_marker_p (struct breakpoint *b) | |
13378 | { | |
13379 | return b->ops == &strace_marker_breakpoint_ops; | |
13380 | } | |
13381 | ||
53a5351d | 13382 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13383 | structures. */ |
c906108c SS |
13384 | |
13385 | void | |
fba45db2 | 13386 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13387 | { |
52f0bd74 | 13388 | struct breakpoint *b; |
c906108c | 13389 | |
8a3fe4f8 | 13390 | gdb_assert (bpt != NULL); |
c906108c | 13391 | |
4a64f543 MS |
13392 | /* Has this bp already been deleted? This can happen because |
13393 | multiple lists can hold pointers to bp's. bpstat lists are | |
13394 | especial culprits. | |
13395 | ||
13396 | One example of this happening is a watchpoint's scope bp. When | |
13397 | the scope bp triggers, we notice that the watchpoint is out of | |
13398 | scope, and delete it. We also delete its scope bp. But the | |
13399 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13400 | That bpstat is then checked for auto-deleting bp's, which are | |
13401 | deleted. | |
13402 | ||
13403 | A real solution to this problem might involve reference counts in | |
13404 | bp's, and/or giving them pointers back to their referencing | |
13405 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13406 | storage when no more references were extent. A cheaper bandaid | |
13407 | was chosen. */ | |
c906108c SS |
13408 | if (bpt->type == bp_none) |
13409 | return; | |
13410 | ||
4a64f543 MS |
13411 | /* At least avoid this stale reference until the reference counting |
13412 | of breakpoints gets resolved. */ | |
d0fb5eae | 13413 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13414 | { |
d0fb5eae | 13415 | struct breakpoint *related; |
3a5c3e22 | 13416 | struct watchpoint *w; |
d0fb5eae JK |
13417 | |
13418 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13419 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13420 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13421 | w = (struct watchpoint *) bpt; |
13422 | else | |
13423 | w = NULL; | |
13424 | if (w != NULL) | |
13425 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13426 | |
13427 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13428 | for (related = bpt; related->related_breakpoint != bpt; | |
13429 | related = related->related_breakpoint); | |
13430 | related->related_breakpoint = bpt->related_breakpoint; | |
13431 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13432 | } |
13433 | ||
a9634178 TJB |
13434 | /* watch_command_1 creates a watchpoint but only sets its number if |
13435 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13436 | a problem in that process, we'll be asked to delete the half-created | |
13437 | watchpoint. In that case, don't announce the deletion. */ | |
13438 | if (bpt->number) | |
13439 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13440 | |
c906108c SS |
13441 | if (breakpoint_chain == bpt) |
13442 | breakpoint_chain = bpt->next; | |
13443 | ||
c906108c SS |
13444 | ALL_BREAKPOINTS (b) |
13445 | if (b->next == bpt) | |
c5aa993b JM |
13446 | { |
13447 | b->next = bpt->next; | |
13448 | break; | |
13449 | } | |
c906108c | 13450 | |
f431efe5 PA |
13451 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13452 | been freed. */ | |
13453 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13454 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13455 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13456 | commands are associated with the bpstat; if we remove it here, | |
13457 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13458 | event-top.c won't do anything, and temporary breakpoints with | |
13459 | commands won't work. */ | |
13460 | ||
13461 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13462 | ||
4a64f543 MS |
13463 | /* Now that breakpoint is removed from breakpoint list, update the |
13464 | global location list. This will remove locations that used to | |
13465 | belong to this breakpoint. Do this before freeing the breakpoint | |
13466 | itself, since remove_breakpoint looks at location's owner. It | |
13467 | might be better design to have location completely | |
13468 | self-contained, but it's not the case now. */ | |
44702360 | 13469 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13470 | |
4a64f543 MS |
13471 | /* On the chance that someone will soon try again to delete this |
13472 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13473 | bpt->type = bp_none; |
4d01a485 | 13474 | delete bpt; |
c906108c SS |
13475 | } |
13476 | ||
4d6140d9 AC |
13477 | static void |
13478 | do_delete_breakpoint_cleanup (void *b) | |
13479 | { | |
9a3c8263 | 13480 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13481 | } |
13482 | ||
13483 | struct cleanup * | |
13484 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13485 | { | |
13486 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13487 | } | |
13488 | ||
51be5b68 PA |
13489 | /* Iterator function to call a user-provided callback function once |
13490 | for each of B and its related breakpoints. */ | |
13491 | ||
13492 | static void | |
13493 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13494 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13495 | { |
13496 | struct breakpoint *related; | |
13497 | ||
13498 | related = b; | |
13499 | do | |
13500 | { | |
13501 | struct breakpoint *next; | |
13502 | ||
13503 | /* FUNCTION may delete RELATED. */ | |
13504 | next = related->related_breakpoint; | |
13505 | ||
13506 | if (next == related) | |
13507 | { | |
13508 | /* RELATED is the last ring entry. */ | |
48649e1b | 13509 | function (related); |
51be5b68 PA |
13510 | |
13511 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13512 | B. There's nothing left to do anyway, so just break | |
13513 | out. */ | |
13514 | break; | |
13515 | } | |
13516 | else | |
48649e1b | 13517 | function (related); |
51be5b68 PA |
13518 | |
13519 | related = next; | |
13520 | } | |
13521 | while (related != b); | |
13522 | } | |
95a42b64 | 13523 | |
4495129a | 13524 | static void |
fba45db2 | 13525 | delete_command (char *arg, int from_tty) |
c906108c | 13526 | { |
35df4500 | 13527 | struct breakpoint *b, *b_tmp; |
c906108c | 13528 | |
ea9365bb TT |
13529 | dont_repeat (); |
13530 | ||
c906108c SS |
13531 | if (arg == 0) |
13532 | { | |
13533 | int breaks_to_delete = 0; | |
13534 | ||
46c6471b PA |
13535 | /* Delete all breakpoints if no argument. Do not delete |
13536 | internal breakpoints, these have to be deleted with an | |
13537 | explicit breakpoint number argument. */ | |
c5aa993b | 13538 | ALL_BREAKPOINTS (b) |
46c6471b | 13539 | if (user_breakpoint_p (b)) |
973d738b DJ |
13540 | { |
13541 | breaks_to_delete = 1; | |
13542 | break; | |
13543 | } | |
c906108c SS |
13544 | |
13545 | /* Ask user only if there are some breakpoints to delete. */ | |
13546 | if (!from_tty | |
e2e0b3e5 | 13547 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13548 | { |
35df4500 | 13549 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13550 | if (user_breakpoint_p (b)) |
c5aa993b | 13551 | delete_breakpoint (b); |
c906108c SS |
13552 | } |
13553 | } | |
13554 | else | |
48649e1b TT |
13555 | map_breakpoint_numbers |
13556 | (arg, [&] (breakpoint *b) | |
13557 | { | |
13558 | iterate_over_related_breakpoints (b, delete_breakpoint); | |
13559 | }); | |
c906108c SS |
13560 | } |
13561 | ||
c2f4122d PA |
13562 | /* Return true if all locations of B bound to PSPACE are pending. If |
13563 | PSPACE is NULL, all locations of all program spaces are | |
13564 | considered. */ | |
13565 | ||
0d381245 | 13566 | static int |
c2f4122d | 13567 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13568 | { |
c2f4122d PA |
13569 | struct bp_location *loc; |
13570 | ||
13571 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13572 | if ((pspace == NULL | |
13573 | || loc->pspace == pspace) | |
13574 | && !loc->shlib_disabled | |
8645ff69 | 13575 | && !loc->pspace->executing_startup) |
0d381245 VP |
13576 | return 0; |
13577 | return 1; | |
fe3f5fa8 VP |
13578 | } |
13579 | ||
776592bf DE |
13580 | /* Subroutine of update_breakpoint_locations to simplify it. |
13581 | Return non-zero if multiple fns in list LOC have the same name. | |
13582 | Null names are ignored. */ | |
13583 | ||
13584 | static int | |
13585 | ambiguous_names_p (struct bp_location *loc) | |
13586 | { | |
13587 | struct bp_location *l; | |
13588 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13589 | (int (*) (const void *, |
13590 | const void *)) streq, | |
776592bf DE |
13591 | NULL, xcalloc, xfree); |
13592 | ||
13593 | for (l = loc; l != NULL; l = l->next) | |
13594 | { | |
13595 | const char **slot; | |
13596 | const char *name = l->function_name; | |
13597 | ||
13598 | /* Allow for some names to be NULL, ignore them. */ | |
13599 | if (name == NULL) | |
13600 | continue; | |
13601 | ||
13602 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13603 | INSERT); | |
4a64f543 MS |
13604 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13605 | returns NULL. */ | |
776592bf DE |
13606 | if (*slot != NULL) |
13607 | { | |
13608 | htab_delete (htab); | |
13609 | return 1; | |
13610 | } | |
13611 | *slot = name; | |
13612 | } | |
13613 | ||
13614 | htab_delete (htab); | |
13615 | return 0; | |
13616 | } | |
13617 | ||
0fb4aa4b PA |
13618 | /* When symbols change, it probably means the sources changed as well, |
13619 | and it might mean the static tracepoint markers are no longer at | |
13620 | the same address or line numbers they used to be at last we | |
13621 | checked. Losing your static tracepoints whenever you rebuild is | |
13622 | undesirable. This function tries to resync/rematch gdb static | |
13623 | tracepoints with the markers on the target, for static tracepoints | |
13624 | that have not been set by marker id. Static tracepoint that have | |
13625 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13626 | The heuristic is: | |
13627 | ||
13628 | 1) For a tracepoint set at a specific address, look for a marker at | |
13629 | the old PC. If one is found there, assume to be the same marker. | |
13630 | If the name / string id of the marker found is different from the | |
13631 | previous known name, assume that means the user renamed the marker | |
13632 | in the sources, and output a warning. | |
13633 | ||
13634 | 2) For a tracepoint set at a given line number, look for a marker | |
13635 | at the new address of the old line number. If one is found there, | |
13636 | assume to be the same marker. If the name / string id of the | |
13637 | marker found is different from the previous known name, assume that | |
13638 | means the user renamed the marker in the sources, and output a | |
13639 | warning. | |
13640 | ||
13641 | 3) If a marker is no longer found at the same address or line, it | |
13642 | may mean the marker no longer exists. But it may also just mean | |
13643 | the code changed a bit. Maybe the user added a few lines of code | |
13644 | that made the marker move up or down (in line number terms). Ask | |
13645 | the target for info about the marker with the string id as we knew | |
13646 | it. If found, update line number and address in the matching | |
13647 | static tracepoint. This will get confused if there's more than one | |
13648 | marker with the same ID (possible in UST, although unadvised | |
13649 | precisely because it confuses tools). */ | |
13650 | ||
13651 | static struct symtab_and_line | |
13652 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13653 | { | |
d9b3f62e | 13654 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13655 | struct static_tracepoint_marker marker; |
13656 | CORE_ADDR pc; | |
0fb4aa4b PA |
13657 | |
13658 | pc = sal.pc; | |
13659 | if (sal.line) | |
13660 | find_line_pc (sal.symtab, sal.line, &pc); | |
13661 | ||
13662 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13663 | { | |
d9b3f62e | 13664 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13665 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13666 | b->number, | |
d9b3f62e | 13667 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13668 | |
d9b3f62e PA |
13669 | xfree (tp->static_trace_marker_id); |
13670 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13671 | release_static_tracepoint_marker (&marker); |
13672 | ||
13673 | return sal; | |
13674 | } | |
13675 | ||
13676 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13677 | by string ID. */ | |
13678 | if (!sal.explicit_pc | |
13679 | && sal.line != 0 | |
13680 | && sal.symtab != NULL | |
d9b3f62e | 13681 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13682 | { |
13683 | VEC(static_tracepoint_marker_p) *markers; | |
13684 | ||
13685 | markers | |
d9b3f62e | 13686 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13687 | |
13688 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13689 | { | |
0fb4aa4b | 13690 | struct symbol *sym; |
80e1d417 | 13691 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13692 | struct ui_out *uiout = current_uiout; |
67994074 | 13693 | struct explicit_location explicit_loc; |
0fb4aa4b | 13694 | |
80e1d417 | 13695 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13696 | |
d9b3f62e | 13697 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13698 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13699 | |
13700 | warning (_("marker for static tracepoint %d (%s) not " | |
13701 | "found at previous line number"), | |
d9b3f62e | 13702 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13703 | |
51abb421 | 13704 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13705 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13706 | uiout->text ("Now in "); |
0fb4aa4b PA |
13707 | if (sym) |
13708 | { | |
112e8700 SM |
13709 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); |
13710 | uiout->text (" at "); | |
0fb4aa4b | 13711 | } |
112e8700 | 13712 | uiout->field_string ("file", |
05cba821 | 13713 | symtab_to_filename_for_display (sal2.symtab)); |
112e8700 | 13714 | uiout->text (":"); |
0fb4aa4b | 13715 | |
112e8700 | 13716 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13717 | { |
0b0865da | 13718 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13719 | |
112e8700 | 13720 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13721 | } |
13722 | ||
112e8700 SM |
13723 | uiout->field_int ("line", sal2.line); |
13724 | uiout->text ("\n"); | |
0fb4aa4b | 13725 | |
80e1d417 | 13726 | b->loc->line_number = sal2.line; |
2f202fde | 13727 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13728 | |
d28cd78a | 13729 | b->location.reset (NULL); |
67994074 KS |
13730 | initialize_explicit_location (&explicit_loc); |
13731 | explicit_loc.source_filename | |
00e52e53 | 13732 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13733 | explicit_loc.line_offset.offset = b->loc->line_number; |
13734 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13735 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13736 | |
13737 | /* Might be nice to check if function changed, and warn if | |
13738 | so. */ | |
13739 | ||
80e1d417 | 13740 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
13741 | } |
13742 | } | |
13743 | return sal; | |
13744 | } | |
13745 | ||
8d3788bd VP |
13746 | /* Returns 1 iff locations A and B are sufficiently same that |
13747 | we don't need to report breakpoint as changed. */ | |
13748 | ||
13749 | static int | |
13750 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13751 | { | |
13752 | while (a && b) | |
13753 | { | |
13754 | if (a->address != b->address) | |
13755 | return 0; | |
13756 | ||
13757 | if (a->shlib_disabled != b->shlib_disabled) | |
13758 | return 0; | |
13759 | ||
13760 | if (a->enabled != b->enabled) | |
13761 | return 0; | |
13762 | ||
13763 | a = a->next; | |
13764 | b = b->next; | |
13765 | } | |
13766 | ||
13767 | if ((a == NULL) != (b == NULL)) | |
13768 | return 0; | |
13769 | ||
13770 | return 1; | |
13771 | } | |
13772 | ||
c2f4122d PA |
13773 | /* Split all locations of B that are bound to PSPACE out of B's |
13774 | location list to a separate list and return that list's head. If | |
13775 | PSPACE is NULL, hoist out all locations of B. */ | |
13776 | ||
13777 | static struct bp_location * | |
13778 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13779 | { | |
13780 | struct bp_location head; | |
13781 | struct bp_location *i = b->loc; | |
13782 | struct bp_location **i_link = &b->loc; | |
13783 | struct bp_location *hoisted = &head; | |
13784 | ||
13785 | if (pspace == NULL) | |
13786 | { | |
13787 | i = b->loc; | |
13788 | b->loc = NULL; | |
13789 | return i; | |
13790 | } | |
13791 | ||
13792 | head.next = NULL; | |
13793 | ||
13794 | while (i != NULL) | |
13795 | { | |
13796 | if (i->pspace == pspace) | |
13797 | { | |
13798 | *i_link = i->next; | |
13799 | i->next = NULL; | |
13800 | hoisted->next = i; | |
13801 | hoisted = i; | |
13802 | } | |
13803 | else | |
13804 | i_link = &i->next; | |
13805 | i = *i_link; | |
13806 | } | |
13807 | ||
13808 | return head.next; | |
13809 | } | |
13810 | ||
13811 | /* Create new breakpoint locations for B (a hardware or software | |
13812 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13813 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13814 | FILTER_PSPACE. Locations of other program spaces are left | |
13815 | untouched. */ | |
f1310107 | 13816 | |
0e30163f | 13817 | void |
0d381245 | 13818 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13819 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13820 | gdb::array_view<const symtab_and_line> sals, |
13821 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 VP |
13822 | { |
13823 | int i; | |
c2f4122d | 13824 | struct bp_location *existing_locations; |
0d381245 | 13825 | |
6c5b2ebe | 13826 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13827 | { |
13828 | /* Ranged breakpoints have only one start location and one end | |
13829 | location. */ | |
13830 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13831 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13832 | "multiple locations found\n"), | |
13833 | b->number); | |
13834 | return; | |
13835 | } | |
f1310107 | 13836 | |
4a64f543 MS |
13837 | /* If there's no new locations, and all existing locations are |
13838 | pending, don't do anything. This optimizes the common case where | |
13839 | all locations are in the same shared library, that was unloaded. | |
13840 | We'd like to retain the location, so that when the library is | |
13841 | loaded again, we don't loose the enabled/disabled status of the | |
13842 | individual locations. */ | |
6c5b2ebe | 13843 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13844 | return; |
13845 | ||
c2f4122d | 13846 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13847 | |
6c5b2ebe | 13848 | for (const auto &sal : sals) |
fe3f5fa8 | 13849 | { |
f8eba3c6 TT |
13850 | struct bp_location *new_loc; |
13851 | ||
6c5b2ebe | 13852 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13853 | |
6c5b2ebe | 13854 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13855 | |
0d381245 VP |
13856 | /* Reparse conditions, they might contain references to the |
13857 | old symtab. */ | |
13858 | if (b->cond_string != NULL) | |
13859 | { | |
bbc13ae3 | 13860 | const char *s; |
fe3f5fa8 | 13861 | |
0d381245 | 13862 | s = b->cond_string; |
492d29ea | 13863 | TRY |
0d381245 | 13864 | { |
6c5b2ebe PA |
13865 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13866 | block_for_pc (sal.pc), | |
0d381245 VP |
13867 | 0); |
13868 | } | |
492d29ea | 13869 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 13870 | { |
3e43a32a MS |
13871 | warning (_("failed to reevaluate condition " |
13872 | "for breakpoint %d: %s"), | |
0d381245 VP |
13873 | b->number, e.message); |
13874 | new_loc->enabled = 0; | |
13875 | } | |
492d29ea | 13876 | END_CATCH |
0d381245 | 13877 | } |
fe3f5fa8 | 13878 | |
6c5b2ebe | 13879 | if (!sals_end.empty ()) |
f1310107 | 13880 | { |
6c5b2ebe | 13881 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13882 | |
6c5b2ebe | 13883 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13884 | } |
0d381245 | 13885 | } |
fe3f5fa8 | 13886 | |
4a64f543 MS |
13887 | /* If possible, carry over 'disable' status from existing |
13888 | breakpoints. */ | |
0d381245 VP |
13889 | { |
13890 | struct bp_location *e = existing_locations; | |
776592bf DE |
13891 | /* If there are multiple breakpoints with the same function name, |
13892 | e.g. for inline functions, comparing function names won't work. | |
13893 | Instead compare pc addresses; this is just a heuristic as things | |
13894 | may have moved, but in practice it gives the correct answer | |
13895 | often enough until a better solution is found. */ | |
13896 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13897 | ||
0d381245 VP |
13898 | for (; e; e = e->next) |
13899 | { | |
13900 | if (!e->enabled && e->function_name) | |
13901 | { | |
13902 | struct bp_location *l = b->loc; | |
776592bf DE |
13903 | if (have_ambiguous_names) |
13904 | { | |
13905 | for (; l; l = l->next) | |
f1310107 | 13906 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13907 | { |
13908 | l->enabled = 0; | |
13909 | break; | |
13910 | } | |
13911 | } | |
13912 | else | |
13913 | { | |
13914 | for (; l; l = l->next) | |
13915 | if (l->function_name | |
13916 | && strcmp (e->function_name, l->function_name) == 0) | |
13917 | { | |
13918 | l->enabled = 0; | |
13919 | break; | |
13920 | } | |
13921 | } | |
0d381245 VP |
13922 | } |
13923 | } | |
13924 | } | |
fe3f5fa8 | 13925 | |
8d3788bd VP |
13926 | if (!locations_are_equal (existing_locations, b->loc)) |
13927 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
13928 | } |
13929 | ||
f00aae0f | 13930 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13931 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13932 | ||
6c5b2ebe | 13933 | static std::vector<symtab_and_line> |
f00aae0f | 13934 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13935 | struct program_space *search_pspace, int *found) |
ef23e705 | 13936 | { |
492d29ea | 13937 | struct gdb_exception exception = exception_none; |
ef23e705 | 13938 | |
983af33b | 13939 | gdb_assert (b->ops != NULL); |
ef23e705 | 13940 | |
6c5b2ebe PA |
13941 | std::vector<symtab_and_line> sals; |
13942 | ||
492d29ea | 13943 | TRY |
ef23e705 | 13944 | { |
6c5b2ebe | 13945 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13946 | } |
492d29ea | 13947 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
13948 | { |
13949 | int not_found_and_ok = 0; | |
492d29ea PA |
13950 | |
13951 | exception = e; | |
13952 | ||
ef23e705 TJB |
13953 | /* For pending breakpoints, it's expected that parsing will |
13954 | fail until the right shared library is loaded. User has | |
13955 | already told to create pending breakpoints and don't need | |
13956 | extra messages. If breakpoint is in bp_shlib_disabled | |
13957 | state, then user already saw the message about that | |
13958 | breakpoint being disabled, and don't want to see more | |
13959 | errors. */ | |
58438ac1 | 13960 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13961 | && (b->condition_not_parsed |
13962 | || (b->loc != NULL | |
13963 | && search_pspace != NULL | |
13964 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13965 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13966 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13967 | || b->enable_state == bp_disabled)) |
13968 | not_found_and_ok = 1; | |
13969 | ||
13970 | if (!not_found_and_ok) | |
13971 | { | |
13972 | /* We surely don't want to warn about the same breakpoint | |
13973 | 10 times. One solution, implemented here, is disable | |
13974 | the breakpoint on error. Another solution would be to | |
13975 | have separate 'warning emitted' flag. Since this | |
13976 | happens only when a binary has changed, I don't know | |
13977 | which approach is better. */ | |
13978 | b->enable_state = bp_disabled; | |
13979 | throw_exception (e); | |
13980 | } | |
13981 | } | |
492d29ea | 13982 | END_CATCH |
ef23e705 | 13983 | |
492d29ea | 13984 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13985 | { |
6c5b2ebe PA |
13986 | for (auto &sal : sals) |
13987 | resolve_sal_pc (&sal); | |
f00aae0f | 13988 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13989 | { |
ed1d1739 KS |
13990 | char *cond_string, *extra_string; |
13991 | int thread, task; | |
ef23e705 | 13992 | |
6c5b2ebe | 13993 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
13994 | &cond_string, &thread, &task, |
13995 | &extra_string); | |
f00aae0f | 13996 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
13997 | if (cond_string) |
13998 | b->cond_string = cond_string; | |
13999 | b->thread = thread; | |
14000 | b->task = task; | |
e7e0cddf | 14001 | if (extra_string) |
f00aae0f KS |
14002 | { |
14003 | xfree (b->extra_string); | |
14004 | b->extra_string = extra_string; | |
14005 | } | |
ef23e705 TJB |
14006 | b->condition_not_parsed = 0; |
14007 | } | |
14008 | ||
983af33b | 14009 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 14010 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 14011 | |
58438ac1 TT |
14012 | *found = 1; |
14013 | } | |
14014 | else | |
14015 | *found = 0; | |
ef23e705 TJB |
14016 | |
14017 | return sals; | |
14018 | } | |
14019 | ||
348d480f PA |
14020 | /* The default re_set method, for typical hardware or software |
14021 | breakpoints. Reevaluate the breakpoint and recreate its | |
14022 | locations. */ | |
14023 | ||
14024 | static void | |
28010a5d | 14025 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 14026 | { |
c2f4122d | 14027 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 14028 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 14029 | |
6c5b2ebe PA |
14030 | int found; |
14031 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
14032 | filter_pspace, &found); | |
ef23e705 | 14033 | if (found) |
6c5b2ebe | 14034 | expanded = std::move (sals); |
ef23e705 | 14035 | |
f00aae0f | 14036 | if (b->location_range_end != NULL) |
f1310107 | 14037 | { |
6c5b2ebe PA |
14038 | std::vector<symtab_and_line> sals_end |
14039 | = location_to_sals (b, b->location_range_end.get (), | |
14040 | filter_pspace, &found); | |
f1310107 | 14041 | if (found) |
6c5b2ebe | 14042 | expanded_end = std::move (sals_end); |
f1310107 TJB |
14043 | } |
14044 | ||
c2f4122d | 14045 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14046 | } |
14047 | ||
983af33b SDJ |
14048 | /* Default method for creating SALs from an address string. It basically |
14049 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14050 | ||
14051 | static void | |
f00aae0f KS |
14052 | create_sals_from_location_default (const struct event_location *location, |
14053 | struct linespec_result *canonical, | |
14054 | enum bptype type_wanted) | |
983af33b | 14055 | { |
f00aae0f | 14056 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14057 | } |
14058 | ||
14059 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14060 | function for the `create_breakpoints_sal' method of | |
14061 | breakpoint_ops. */ | |
14062 | ||
14063 | static void | |
14064 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14065 | struct linespec_result *canonical, | |
e1e01040 PA |
14066 | gdb::unique_xmalloc_ptr<char> cond_string, |
14067 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
14068 | enum bptype type_wanted, |
14069 | enum bpdisp disposition, | |
14070 | int thread, | |
14071 | int task, int ignore_count, | |
14072 | const struct breakpoint_ops *ops, | |
14073 | int from_tty, int enabled, | |
44f238bb | 14074 | int internal, unsigned flags) |
983af33b | 14075 | { |
e1e01040 PA |
14076 | create_breakpoints_sal (gdbarch, canonical, |
14077 | std::move (cond_string), | |
14078 | std::move (extra_string), | |
983af33b SDJ |
14079 | type_wanted, disposition, |
14080 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14081 | enabled, internal, flags); |
983af33b SDJ |
14082 | } |
14083 | ||
14084 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14085 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 14086 | |
6c5b2ebe | 14087 | static std::vector<symtab_and_line> |
f00aae0f KS |
14088 | decode_location_default (struct breakpoint *b, |
14089 | const struct event_location *location, | |
6c5b2ebe | 14090 | struct program_space *search_pspace) |
983af33b SDJ |
14091 | { |
14092 | struct linespec_result canonical; | |
14093 | ||
c2f4122d | 14094 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14095 | (struct symtab *) NULL, 0, |
14096 | &canonical, multiple_symbols_all, | |
14097 | b->filter); | |
14098 | ||
14099 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 14100 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 14101 | |
6c5b2ebe | 14102 | if (!canonical.lsals.empty ()) |
983af33b | 14103 | { |
6c5b2ebe PA |
14104 | const linespec_sals &lsal = canonical.lsals[0]; |
14105 | return std::move (lsal.sals); | |
983af33b | 14106 | } |
6c5b2ebe | 14107 | return {}; |
983af33b SDJ |
14108 | } |
14109 | ||
28010a5d PA |
14110 | /* Prepare the global context for a re-set of breakpoint B. */ |
14111 | ||
14112 | static struct cleanup * | |
14113 | prepare_re_set_context (struct breakpoint *b) | |
14114 | { | |
28010a5d | 14115 | input_radix = b->input_radix; |
28010a5d PA |
14116 | set_language (b->language); |
14117 | ||
c2f4122d | 14118 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14119 | } |
14120 | ||
bf469271 | 14121 | /* Reset a breakpoint. */ |
c906108c | 14122 | |
bf469271 PA |
14123 | static void |
14124 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 14125 | { |
348d480f | 14126 | struct cleanup *cleanups; |
c906108c | 14127 | |
348d480f PA |
14128 | cleanups = prepare_re_set_context (b); |
14129 | b->ops->re_set (b); | |
14130 | do_cleanups (cleanups); | |
c906108c SS |
14131 | } |
14132 | ||
c2f4122d PA |
14133 | /* Re-set breakpoint locations for the current program space. |
14134 | Locations bound to other program spaces are left untouched. */ | |
14135 | ||
c906108c | 14136 | void |
69de3c6a | 14137 | breakpoint_re_set (void) |
c906108c | 14138 | { |
35df4500 | 14139 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14140 | enum language save_language; |
14141 | int save_input_radix; | |
c5aa993b | 14142 | |
c906108c SS |
14143 | save_language = current_language->la_language; |
14144 | save_input_radix = input_radix; | |
2a7f3dff | 14145 | |
c5aa993b | 14146 | { |
5ed8105e | 14147 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 14148 | |
5ed8105e PA |
14149 | /* Note: we must not try to insert locations until after all |
14150 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14151 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14152 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 14153 | |
5ed8105e PA |
14154 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
14155 | { | |
bf469271 PA |
14156 | TRY |
14157 | { | |
14158 | breakpoint_re_set_one (b); | |
14159 | } | |
14160 | CATCH (ex, RETURN_MASK_ALL) | |
14161 | { | |
14162 | exception_fprintf (gdb_stderr, ex, | |
14163 | "Error in re-setting breakpoint %d: ", | |
14164 | b->number); | |
14165 | } | |
14166 | END_CATCH | |
5ed8105e PA |
14167 | } |
14168 | set_language (save_language); | |
14169 | input_radix = save_input_radix; | |
14170 | ||
14171 | jit_breakpoint_re_set (); | |
14172 | } | |
6c95b8df | 14173 | |
af02033e PP |
14174 | create_overlay_event_breakpoint (); |
14175 | create_longjmp_master_breakpoint (); | |
14176 | create_std_terminate_master_breakpoint (); | |
186c406b | 14177 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14178 | |
14179 | /* Now we can insert. */ | |
14180 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14181 | } |
14182 | \f | |
c906108c SS |
14183 | /* Reset the thread number of this breakpoint: |
14184 | ||
14185 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14186 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14187 | void |
fba45db2 | 14188 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14189 | { |
14190 | if (b->thread != -1) | |
14191 | { | |
39f77062 | 14192 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14193 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14194 | |
14195 | /* We're being called after following a fork. The new fork is | |
14196 | selected as current, and unless this was a vfork will have a | |
14197 | different program space from the original thread. Reset that | |
14198 | as well. */ | |
14199 | b->loc->pspace = current_program_space; | |
c906108c SS |
14200 | } |
14201 | } | |
14202 | ||
03ac34d5 MS |
14203 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14204 | If from_tty is nonzero, it prints a message to that effect, | |
14205 | which ends with a period (no newline). */ | |
14206 | ||
c906108c | 14207 | void |
fba45db2 | 14208 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14209 | { |
52f0bd74 | 14210 | struct breakpoint *b; |
c906108c SS |
14211 | |
14212 | if (count < 0) | |
14213 | count = 0; | |
14214 | ||
14215 | ALL_BREAKPOINTS (b) | |
14216 | if (b->number == bptnum) | |
c5aa993b | 14217 | { |
d77f58be SS |
14218 | if (is_tracepoint (b)) |
14219 | { | |
14220 | if (from_tty && count != 0) | |
14221 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14222 | bptnum); | |
14223 | return; | |
14224 | } | |
14225 | ||
c5aa993b | 14226 | b->ignore_count = count; |
221ea385 KS |
14227 | if (from_tty) |
14228 | { | |
14229 | if (count == 0) | |
3e43a32a MS |
14230 | printf_filtered (_("Will stop next time " |
14231 | "breakpoint %d is reached."), | |
221ea385 KS |
14232 | bptnum); |
14233 | else if (count == 1) | |
a3f17187 | 14234 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14235 | bptnum); |
14236 | else | |
3e43a32a MS |
14237 | printf_filtered (_("Will ignore next %d " |
14238 | "crossings of breakpoint %d."), | |
221ea385 KS |
14239 | count, bptnum); |
14240 | } | |
8d3788bd | 14241 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14242 | return; |
14243 | } | |
c906108c | 14244 | |
8a3fe4f8 | 14245 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14246 | } |
14247 | ||
c906108c SS |
14248 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14249 | ||
14250 | static void | |
fba45db2 | 14251 | ignore_command (char *args, int from_tty) |
c906108c SS |
14252 | { |
14253 | char *p = args; | |
52f0bd74 | 14254 | int num; |
c906108c SS |
14255 | |
14256 | if (p == 0) | |
e2e0b3e5 | 14257 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14258 | |
c906108c | 14259 | num = get_number (&p); |
5c44784c | 14260 | if (num == 0) |
8a3fe4f8 | 14261 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14262 | if (*p == 0) |
8a3fe4f8 | 14263 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14264 | |
14265 | set_ignore_count (num, | |
14266 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14267 | from_tty); | |
221ea385 KS |
14268 | if (from_tty) |
14269 | printf_filtered ("\n"); | |
c906108c SS |
14270 | } |
14271 | \f | |
14272 | /* Call FUNCTION on each of the breakpoints | |
14273 | whose numbers are given in ARGS. */ | |
14274 | ||
14275 | static void | |
896b6bda | 14276 | map_breakpoint_numbers (const char *args, |
48649e1b | 14277 | gdb::function_view<void (breakpoint *)> function) |
c906108c | 14278 | { |
52f0bd74 AC |
14279 | int num; |
14280 | struct breakpoint *b, *tmp; | |
c906108c | 14281 | |
b9d61307 | 14282 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14283 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14284 | |
bfd28288 | 14285 | number_or_range_parser parser (args); |
197f0a60 | 14286 | |
bfd28288 | 14287 | while (!parser.finished ()) |
c906108c | 14288 | { |
bfd28288 PA |
14289 | const char *p = parser.cur_tok (); |
14290 | bool match = false; | |
197f0a60 | 14291 | |
bfd28288 | 14292 | num = parser.get_number (); |
5c44784c | 14293 | if (num == 0) |
c5aa993b | 14294 | { |
8a3fe4f8 | 14295 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14296 | } |
14297 | else | |
14298 | { | |
14299 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14300 | if (b->number == num) | |
14301 | { | |
bfd28288 | 14302 | match = true; |
48649e1b | 14303 | function (b); |
11cf8741 | 14304 | break; |
5c44784c | 14305 | } |
bfd28288 | 14306 | if (!match) |
a3f17187 | 14307 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14308 | } |
c906108c SS |
14309 | } |
14310 | } | |
14311 | ||
0d381245 | 14312 | static struct bp_location * |
cb791d59 | 14313 | find_location_by_number (const char *number) |
0d381245 | 14314 | { |
cb791d59 | 14315 | const char *p1; |
0d381245 VP |
14316 | int bp_num; |
14317 | int loc_num; | |
14318 | struct breakpoint *b; | |
14319 | struct bp_location *loc; | |
14320 | ||
0d381245 | 14321 | p1 = number; |
cb791d59 TT |
14322 | bp_num = get_number_trailer (&p1, '.'); |
14323 | if (bp_num == 0 || p1[0] != '.') | |
0d381245 VP |
14324 | error (_("Bad breakpoint number '%s'"), number); |
14325 | ||
14326 | ALL_BREAKPOINTS (b) | |
14327 | if (b->number == bp_num) | |
14328 | { | |
14329 | break; | |
14330 | } | |
14331 | ||
14332 | if (!b || b->number != bp_num) | |
14333 | error (_("Bad breakpoint number '%s'"), number); | |
14334 | ||
cb791d59 TT |
14335 | /* Skip the dot. */ |
14336 | ++p1; | |
14337 | const char *save = p1; | |
197f0a60 | 14338 | loc_num = get_number (&p1); |
0d381245 VP |
14339 | if (loc_num == 0) |
14340 | error (_("Bad breakpoint location number '%s'"), number); | |
14341 | ||
14342 | --loc_num; | |
14343 | loc = b->loc; | |
14344 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14345 | ; | |
14346 | if (!loc) | |
cb791d59 | 14347 | error (_("Bad breakpoint location number '%s'"), save); |
0d381245 VP |
14348 | |
14349 | return loc; | |
14350 | } | |
14351 | ||
14352 | ||
1900040c MS |
14353 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14354 | If from_tty is nonzero, it prints a message to that effect, | |
14355 | which ends with a period (no newline). */ | |
14356 | ||
c906108c | 14357 | void |
fba45db2 | 14358 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14359 | { |
14360 | /* Never disable a watchpoint scope breakpoint; we want to | |
14361 | hit them when we leave scope so we can delete both the | |
14362 | watchpoint and its scope breakpoint at that time. */ | |
14363 | if (bpt->type == bp_watchpoint_scope) | |
14364 | return; | |
14365 | ||
b5de0fa7 | 14366 | bpt->enable_state = bp_disabled; |
c906108c | 14367 | |
b775012e LM |
14368 | /* Mark breakpoint locations modified. */ |
14369 | mark_breakpoint_modified (bpt); | |
14370 | ||
d248b706 KY |
14371 | if (target_supports_enable_disable_tracepoint () |
14372 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14373 | { | |
14374 | struct bp_location *location; | |
14375 | ||
14376 | for (location = bpt->loc; location; location = location->next) | |
14377 | target_disable_tracepoint (location); | |
14378 | } | |
14379 | ||
44702360 | 14380 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14381 | |
8d3788bd | 14382 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14383 | } |
14384 | ||
c906108c | 14385 | static void |
fba45db2 | 14386 | disable_command (char *args, int from_tty) |
c906108c | 14387 | { |
c906108c | 14388 | if (args == 0) |
46c6471b PA |
14389 | { |
14390 | struct breakpoint *bpt; | |
14391 | ||
14392 | ALL_BREAKPOINTS (bpt) | |
14393 | if (user_breakpoint_p (bpt)) | |
14394 | disable_breakpoint (bpt); | |
14395 | } | |
9eaabc75 | 14396 | else |
0d381245 | 14397 | { |
cb791d59 | 14398 | std::string num = extract_arg (&args); |
9eaabc75 | 14399 | |
cb791d59 | 14400 | while (!num.empty ()) |
d248b706 | 14401 | { |
cb791d59 | 14402 | if (num.find ('.') != std::string::npos) |
b775012e | 14403 | { |
cb791d59 | 14404 | struct bp_location *loc = find_location_by_number (num.c_str ()); |
9eaabc75 MW |
14405 | |
14406 | if (loc) | |
14407 | { | |
14408 | if (loc->enabled) | |
14409 | { | |
14410 | loc->enabled = 0; | |
14411 | mark_breakpoint_location_modified (loc); | |
14412 | } | |
14413 | if (target_supports_enable_disable_tracepoint () | |
14414 | && current_trace_status ()->running && loc->owner | |
14415 | && is_tracepoint (loc->owner)) | |
14416 | target_disable_tracepoint (loc); | |
14417 | } | |
44702360 | 14418 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14419 | } |
9eaabc75 | 14420 | else |
48649e1b TT |
14421 | map_breakpoint_numbers |
14422 | (num.c_str (), [&] (breakpoint *b) | |
14423 | { | |
14424 | iterate_over_related_breakpoints (b, disable_breakpoint); | |
14425 | }); | |
9eaabc75 | 14426 | num = extract_arg (&args); |
d248b706 | 14427 | } |
0d381245 | 14428 | } |
c906108c SS |
14429 | } |
14430 | ||
14431 | static void | |
816338b5 SS |
14432 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14433 | int count) | |
c906108c | 14434 | { |
afe38095 | 14435 | int target_resources_ok; |
c906108c SS |
14436 | |
14437 | if (bpt->type == bp_hardware_breakpoint) | |
14438 | { | |
14439 | int i; | |
c5aa993b | 14440 | i = hw_breakpoint_used_count (); |
53a5351d | 14441 | target_resources_ok = |
d92524f1 | 14442 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14443 | i + 1, 0); |
c906108c | 14444 | if (target_resources_ok == 0) |
8a3fe4f8 | 14445 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14446 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14447 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14448 | } |
14449 | ||
cc60f2e3 | 14450 | if (is_watchpoint (bpt)) |
c906108c | 14451 | { |
d07205c2 | 14452 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14453 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14454 | |
492d29ea | 14455 | TRY |
c906108c | 14456 | { |
3a5c3e22 PA |
14457 | struct watchpoint *w = (struct watchpoint *) bpt; |
14458 | ||
1e718ff1 TJB |
14459 | orig_enable_state = bpt->enable_state; |
14460 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14461 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14462 | } |
492d29ea | 14463 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14464 | { |
1e718ff1 | 14465 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14466 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14467 | bpt->number); | |
14468 | return; | |
c5aa993b | 14469 | } |
492d29ea | 14470 | END_CATCH |
c906108c | 14471 | } |
0101ce28 | 14472 | |
b775012e LM |
14473 | bpt->enable_state = bp_enabled; |
14474 | ||
14475 | /* Mark breakpoint locations modified. */ | |
14476 | mark_breakpoint_modified (bpt); | |
14477 | ||
d248b706 KY |
14478 | if (target_supports_enable_disable_tracepoint () |
14479 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14480 | { | |
14481 | struct bp_location *location; | |
14482 | ||
14483 | for (location = bpt->loc; location; location = location->next) | |
14484 | target_enable_tracepoint (location); | |
14485 | } | |
14486 | ||
b4c291bb | 14487 | bpt->disposition = disposition; |
816338b5 | 14488 | bpt->enable_count = count; |
44702360 | 14489 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14490 | |
8d3788bd | 14491 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14492 | } |
14493 | ||
fe3f5fa8 | 14494 | |
c906108c | 14495 | void |
fba45db2 | 14496 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14497 | { |
816338b5 | 14498 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14499 | } |
14500 | ||
c906108c SS |
14501 | /* The enable command enables the specified breakpoints (or all defined |
14502 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14503 | in stopping the inferior. */ |
c906108c | 14504 | |
c906108c | 14505 | static void |
fba45db2 | 14506 | enable_command (char *args, int from_tty) |
c906108c | 14507 | { |
c906108c | 14508 | if (args == 0) |
46c6471b PA |
14509 | { |
14510 | struct breakpoint *bpt; | |
14511 | ||
14512 | ALL_BREAKPOINTS (bpt) | |
14513 | if (user_breakpoint_p (bpt)) | |
14514 | enable_breakpoint (bpt); | |
14515 | } | |
9eaabc75 | 14516 | else |
0d381245 | 14517 | { |
cb791d59 | 14518 | std::string num = extract_arg (&args); |
9eaabc75 | 14519 | |
cb791d59 | 14520 | while (!num.empty ()) |
d248b706 | 14521 | { |
cb791d59 | 14522 | if (num.find ('.') != std::string::npos) |
b775012e | 14523 | { |
cb791d59 | 14524 | struct bp_location *loc = find_location_by_number (num.c_str ()); |
9eaabc75 MW |
14525 | |
14526 | if (loc) | |
14527 | { | |
14528 | if (!loc->enabled) | |
14529 | { | |
14530 | loc->enabled = 1; | |
14531 | mark_breakpoint_location_modified (loc); | |
14532 | } | |
14533 | if (target_supports_enable_disable_tracepoint () | |
14534 | && current_trace_status ()->running && loc->owner | |
14535 | && is_tracepoint (loc->owner)) | |
14536 | target_enable_tracepoint (loc); | |
14537 | } | |
44702360 | 14538 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14539 | } |
9eaabc75 | 14540 | else |
48649e1b TT |
14541 | map_breakpoint_numbers |
14542 | (num.c_str (), [&] (breakpoint *b) | |
14543 | { | |
14544 | iterate_over_related_breakpoints (b, enable_breakpoint); | |
14545 | }); | |
9eaabc75 | 14546 | num = extract_arg (&args); |
d248b706 | 14547 | } |
0d381245 | 14548 | } |
c906108c SS |
14549 | } |
14550 | ||
c906108c | 14551 | static void |
4495129a | 14552 | enable_once_command (const char *args, int from_tty) |
c906108c | 14553 | { |
48649e1b TT |
14554 | map_breakpoint_numbers |
14555 | (args, [&] (breakpoint *b) | |
14556 | { | |
14557 | iterate_over_related_breakpoints | |
14558 | (b, [&] (breakpoint *bpt) | |
14559 | { | |
14560 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14561 | }); | |
14562 | }); | |
816338b5 SS |
14563 | } |
14564 | ||
14565 | static void | |
4495129a | 14566 | enable_count_command (const char *args, int from_tty) |
816338b5 | 14567 | { |
b9d61307 SM |
14568 | int count; |
14569 | ||
14570 | if (args == NULL) | |
14571 | error_no_arg (_("hit count")); | |
14572 | ||
14573 | count = get_number (&args); | |
816338b5 | 14574 | |
48649e1b TT |
14575 | map_breakpoint_numbers |
14576 | (args, [&] (breakpoint *b) | |
14577 | { | |
14578 | iterate_over_related_breakpoints | |
14579 | (b, [&] (breakpoint *bpt) | |
14580 | { | |
14581 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14582 | }); | |
14583 | }); | |
c906108c SS |
14584 | } |
14585 | ||
c906108c | 14586 | static void |
4495129a | 14587 | enable_delete_command (const char *args, int from_tty) |
c906108c | 14588 | { |
48649e1b TT |
14589 | map_breakpoint_numbers |
14590 | (args, [&] (breakpoint *b) | |
14591 | { | |
14592 | iterate_over_related_breakpoints | |
14593 | (b, [&] (breakpoint *bpt) | |
14594 | { | |
14595 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14596 | }); | |
14597 | }); | |
c906108c SS |
14598 | } |
14599 | \f | |
fa8d40ab JJ |
14600 | static void |
14601 | set_breakpoint_cmd (char *args, int from_tty) | |
14602 | { | |
14603 | } | |
14604 | ||
14605 | static void | |
14606 | show_breakpoint_cmd (char *args, int from_tty) | |
14607 | { | |
14608 | } | |
14609 | ||
1f3b5d1b PP |
14610 | /* Invalidate last known value of any hardware watchpoint if |
14611 | the memory which that value represents has been written to by | |
14612 | GDB itself. */ | |
14613 | ||
14614 | static void | |
8de0566d YQ |
14615 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14616 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14617 | const bfd_byte *data) |
14618 | { | |
14619 | struct breakpoint *bp; | |
14620 | ||
14621 | ALL_BREAKPOINTS (bp) | |
14622 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14623 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14624 | { |
3a5c3e22 | 14625 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14626 | |
3a5c3e22 PA |
14627 | if (wp->val_valid && wp->val) |
14628 | { | |
14629 | struct bp_location *loc; | |
14630 | ||
14631 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14632 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14633 | && loc->address + loc->length > addr | |
14634 | && addr + len > loc->address) | |
14635 | { | |
14636 | value_free (wp->val); | |
14637 | wp->val = NULL; | |
14638 | wp->val_valid = 0; | |
14639 | } | |
14640 | } | |
1f3b5d1b PP |
14641 | } |
14642 | } | |
14643 | ||
8181d85f DJ |
14644 | /* Create and insert a breakpoint for software single step. */ |
14645 | ||
14646 | void | |
6c95b8df | 14647 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14648 | struct address_space *aspace, |
14649 | CORE_ADDR next_pc) | |
8181d85f | 14650 | { |
7c16b83e PA |
14651 | struct thread_info *tp = inferior_thread (); |
14652 | struct symtab_and_line sal; | |
14653 | CORE_ADDR pc = next_pc; | |
8181d85f | 14654 | |
34b7e8a6 PA |
14655 | if (tp->control.single_step_breakpoints == NULL) |
14656 | { | |
14657 | tp->control.single_step_breakpoints | |
5d5658a1 | 14658 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14659 | } |
8181d85f | 14660 | |
7c16b83e PA |
14661 | sal = find_pc_line (pc, 0); |
14662 | sal.pc = pc; | |
14663 | sal.section = find_pc_overlay (pc); | |
14664 | sal.explicit_pc = 1; | |
34b7e8a6 | 14665 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14666 | |
7c16b83e | 14667 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14668 | } |
14669 | ||
93f9a11f YQ |
14670 | /* Insert single step breakpoints according to the current state. */ |
14671 | ||
14672 | int | |
14673 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14674 | { | |
f5ea389a | 14675 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14676 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14677 | |
f5ea389a | 14678 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14679 | |
a0ff9e1a | 14680 | if (!next_pcs.empty ()) |
93f9a11f | 14681 | { |
f5ea389a | 14682 | struct frame_info *frame = get_current_frame (); |
93f9a11f YQ |
14683 | struct address_space *aspace = get_frame_address_space (frame); |
14684 | ||
a0ff9e1a | 14685 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14686 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14687 | ||
93f9a11f YQ |
14688 | return 1; |
14689 | } | |
14690 | else | |
14691 | return 0; | |
14692 | } | |
14693 | ||
34b7e8a6 | 14694 | /* See breakpoint.h. */ |
f02253f1 HZ |
14695 | |
14696 | int | |
7c16b83e PA |
14697 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
14698 | struct address_space *aspace, | |
14699 | CORE_ADDR pc) | |
1aafd4da | 14700 | { |
7c16b83e | 14701 | struct bp_location *loc; |
1aafd4da | 14702 | |
7c16b83e PA |
14703 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14704 | if (loc->inserted | |
14705 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14706 | return 1; | |
1aafd4da | 14707 | |
7c16b83e | 14708 | return 0; |
ef370185 JB |
14709 | } |
14710 | ||
14711 | /* Check whether a software single-step breakpoint is inserted at | |
14712 | PC. */ | |
14713 | ||
14714 | int | |
14715 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
14716 | CORE_ADDR pc) | |
14717 | { | |
34b7e8a6 PA |
14718 | struct breakpoint *bpt; |
14719 | ||
14720 | ALL_BREAKPOINTS (bpt) | |
14721 | { | |
14722 | if (bpt->type == bp_single_step | |
14723 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14724 | return 1; | |
14725 | } | |
14726 | return 0; | |
1aafd4da UW |
14727 | } |
14728 | ||
1042e4c0 SS |
14729 | /* Tracepoint-specific operations. */ |
14730 | ||
14731 | /* Set tracepoint count to NUM. */ | |
14732 | static void | |
14733 | set_tracepoint_count (int num) | |
14734 | { | |
14735 | tracepoint_count = num; | |
4fa62494 | 14736 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14737 | } |
14738 | ||
70221824 | 14739 | static void |
f2fc3015 | 14740 | trace_command (char *arg_in, int from_tty) |
1042e4c0 | 14741 | { |
f2fc3015 | 14742 | const char *arg = arg_in; |
55aa24fb | 14743 | struct breakpoint_ops *ops; |
55aa24fb | 14744 | |
ffc2605c TT |
14745 | event_location_up location = string_to_event_location (&arg, |
14746 | current_language); | |
5b56227b | 14747 | if (location != NULL |
ffc2605c | 14748 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
14749 | ops = &tracepoint_probe_breakpoint_ops; |
14750 | else | |
14751 | ops = &tracepoint_breakpoint_ops; | |
14752 | ||
558a9d82 | 14753 | create_breakpoint (get_current_arch (), |
ffc2605c | 14754 | location.get (), |
f00aae0f | 14755 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14756 | 0 /* tempflag */, |
14757 | bp_tracepoint /* type_wanted */, | |
14758 | 0 /* Ignore count */, | |
14759 | pending_break_support, | |
14760 | ops, | |
14761 | from_tty, | |
14762 | 1 /* enabled */, | |
14763 | 0 /* internal */, 0); | |
1042e4c0 SS |
14764 | } |
14765 | ||
70221824 | 14766 | static void |
f2fc3015 | 14767 | ftrace_command (char *arg_in, int from_tty) |
7a697b8d | 14768 | { |
f2fc3015 | 14769 | const char *arg = arg_in; |
ffc2605c TT |
14770 | event_location_up location = string_to_event_location (&arg, |
14771 | current_language); | |
558a9d82 | 14772 | create_breakpoint (get_current_arch (), |
ffc2605c | 14773 | location.get (), |
f00aae0f | 14774 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14775 | 0 /* tempflag */, |
14776 | bp_fast_tracepoint /* type_wanted */, | |
14777 | 0 /* Ignore count */, | |
14778 | pending_break_support, | |
14779 | &tracepoint_breakpoint_ops, | |
14780 | from_tty, | |
14781 | 1 /* enabled */, | |
14782 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14783 | } |
14784 | ||
14785 | /* strace command implementation. Creates a static tracepoint. */ | |
14786 | ||
70221824 | 14787 | static void |
f2fc3015 | 14788 | strace_command (char *arg_in, int from_tty) |
0fb4aa4b | 14789 | { |
f2fc3015 | 14790 | const char *arg = arg_in; |
983af33b | 14791 | struct breakpoint_ops *ops; |
ffc2605c | 14792 | event_location_up location; |
f00aae0f | 14793 | struct cleanup *back_to; |
983af33b SDJ |
14794 | |
14795 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14796 | or with a normal static tracepoint. */ | |
61012eef | 14797 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14798 | { |
14799 | ops = &strace_marker_breakpoint_ops; | |
14800 | location = new_linespec_location (&arg); | |
14801 | } | |
983af33b | 14802 | else |
f00aae0f KS |
14803 | { |
14804 | ops = &tracepoint_breakpoint_ops; | |
14805 | location = string_to_event_location (&arg, current_language); | |
14806 | } | |
983af33b | 14807 | |
558a9d82 | 14808 | create_breakpoint (get_current_arch (), |
ffc2605c | 14809 | location.get (), |
f00aae0f | 14810 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14811 | 0 /* tempflag */, |
14812 | bp_static_tracepoint /* type_wanted */, | |
14813 | 0 /* Ignore count */, | |
14814 | pending_break_support, | |
14815 | ops, | |
14816 | from_tty, | |
14817 | 1 /* enabled */, | |
14818 | 0 /* internal */, 0); | |
7a697b8d SS |
14819 | } |
14820 | ||
409873ef SS |
14821 | /* Set up a fake reader function that gets command lines from a linked |
14822 | list that was acquired during tracepoint uploading. */ | |
14823 | ||
14824 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14825 | static int next_cmd; |
409873ef SS |
14826 | |
14827 | static char * | |
14828 | read_uploaded_action (void) | |
14829 | { | |
14830 | char *rslt; | |
14831 | ||
3149d8c1 | 14832 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 14833 | |
3149d8c1 | 14834 | next_cmd++; |
409873ef SS |
14835 | |
14836 | return rslt; | |
14837 | } | |
14838 | ||
00bf0b85 SS |
14839 | /* Given information about a tracepoint as recorded on a target (which |
14840 | can be either a live system or a trace file), attempt to create an | |
14841 | equivalent GDB tracepoint. This is not a reliable process, since | |
14842 | the target does not necessarily have all the information used when | |
14843 | the tracepoint was originally defined. */ | |
14844 | ||
d9b3f62e | 14845 | struct tracepoint * |
00bf0b85 | 14846 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14847 | { |
f2fc3015 TT |
14848 | const char *addr_str; |
14849 | char small_buf[100]; | |
d9b3f62e | 14850 | struct tracepoint *tp; |
fd9b8c24 | 14851 | |
409873ef SS |
14852 | if (utp->at_string) |
14853 | addr_str = utp->at_string; | |
14854 | else | |
14855 | { | |
14856 | /* In the absence of a source location, fall back to raw | |
14857 | address. Since there is no way to confirm that the address | |
14858 | means the same thing as when the trace was started, warn the | |
14859 | user. */ | |
3e43a32a MS |
14860 | warning (_("Uploaded tracepoint %d has no " |
14861 | "source location, using raw address"), | |
409873ef | 14862 | utp->number); |
8c042590 | 14863 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14864 | addr_str = small_buf; |
14865 | } | |
14866 | ||
14867 | /* There's not much we can do with a sequence of bytecodes. */ | |
14868 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14869 | warning (_("Uploaded tracepoint %d condition " |
14870 | "has no source form, ignoring it"), | |
409873ef | 14871 | utp->number); |
d5551862 | 14872 | |
ffc2605c TT |
14873 | event_location_up location = string_to_event_location (&addr_str, |
14874 | current_language); | |
8cdf0e15 | 14875 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14876 | location.get (), |
f00aae0f | 14877 | utp->cond_string, -1, addr_str, |
e7e0cddf | 14878 | 0 /* parse cond/thread */, |
8cdf0e15 | 14879 | 0 /* tempflag */, |
0fb4aa4b | 14880 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14881 | 0 /* Ignore count */, |
14882 | pending_break_support, | |
348d480f | 14883 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14884 | 0 /* from_tty */, |
84f4c1fe | 14885 | utp->enabled /* enabled */, |
44f238bb PA |
14886 | 0 /* internal */, |
14887 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14888 | return NULL; |
fd9b8c24 | 14889 | |
409873ef | 14890 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14891 | tp = get_tracepoint (tracepoint_count); |
14892 | gdb_assert (tp != NULL); | |
d5551862 | 14893 | |
00bf0b85 SS |
14894 | if (utp->pass > 0) |
14895 | { | |
8c042590 | 14896 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14897 | tp->number); |
00bf0b85 | 14898 | |
409873ef | 14899 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14900 | } |
14901 | ||
409873ef SS |
14902 | /* If we have uploaded versions of the original commands, set up a |
14903 | special-purpose "reader" function and call the usual command line | |
14904 | reader, then pass the result to the breakpoint command-setting | |
14905 | function. */ | |
3149d8c1 | 14906 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 14907 | { |
93921405 | 14908 | command_line_up cmd_list; |
00bf0b85 | 14909 | |
409873ef | 14910 | this_utp = utp; |
3149d8c1 | 14911 | next_cmd = 0; |
d5551862 | 14912 | |
409873ef SS |
14913 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
14914 | ||
c1fc2657 | 14915 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14916 | } |
3149d8c1 SS |
14917 | else if (!VEC_empty (char_ptr, utp->actions) |
14918 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
14919 | warning (_("Uploaded tracepoint %d actions " |
14920 | "have no source form, ignoring them"), | |
409873ef | 14921 | utp->number); |
00bf0b85 | 14922 | |
f196051f | 14923 | /* Copy any status information that might be available. */ |
c1fc2657 | 14924 | tp->hit_count = utp->hit_count; |
f196051f SS |
14925 | tp->traceframe_usage = utp->traceframe_usage; |
14926 | ||
00bf0b85 | 14927 | return tp; |
d9b3f62e | 14928 | } |
00bf0b85 | 14929 | |
1042e4c0 SS |
14930 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14931 | omitted. */ | |
14932 | ||
14933 | static void | |
11db9430 | 14934 | info_tracepoints_command (char *args, int from_tty) |
1042e4c0 | 14935 | { |
79a45e25 | 14936 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14937 | int num_printed; |
1042e4c0 | 14938 | |
e5a67952 | 14939 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
14940 | |
14941 | if (num_printed == 0) | |
1042e4c0 | 14942 | { |
e5a67952 | 14943 | if (args == NULL || *args == '\0') |
112e8700 | 14944 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14945 | else |
112e8700 | 14946 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14947 | } |
ad443146 SS |
14948 | |
14949 | default_collect_info (); | |
1042e4c0 SS |
14950 | } |
14951 | ||
4a64f543 | 14952 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14953 | Not supported by all targets. */ |
14954 | static void | |
14955 | enable_trace_command (char *args, int from_tty) | |
14956 | { | |
14957 | enable_command (args, from_tty); | |
14958 | } | |
14959 | ||
4a64f543 | 14960 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14961 | Not supported by all targets. */ |
14962 | static void | |
14963 | disable_trace_command (char *args, int from_tty) | |
14964 | { | |
14965 | disable_command (args, from_tty); | |
14966 | } | |
14967 | ||
4a64f543 | 14968 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 14969 | static void |
4495129a | 14970 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 14971 | { |
35df4500 | 14972 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14973 | |
14974 | dont_repeat (); | |
14975 | ||
14976 | if (arg == 0) | |
14977 | { | |
14978 | int breaks_to_delete = 0; | |
14979 | ||
14980 | /* Delete all breakpoints if no argument. | |
14981 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14982 | have to be deleted with an explicit breakpoint number |
14983 | argument. */ | |
1042e4c0 | 14984 | ALL_TRACEPOINTS (b) |
46c6471b | 14985 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14986 | { |
14987 | breaks_to_delete = 1; | |
14988 | break; | |
14989 | } | |
1042e4c0 SS |
14990 | |
14991 | /* Ask user only if there are some breakpoints to delete. */ | |
14992 | if (!from_tty | |
14993 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14994 | { | |
35df4500 | 14995 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14996 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14997 | delete_breakpoint (b); |
1042e4c0 SS |
14998 | } |
14999 | } | |
15000 | else | |
48649e1b TT |
15001 | map_breakpoint_numbers |
15002 | (arg, [&] (breakpoint *b) | |
15003 | { | |
15004 | iterate_over_related_breakpoints (b, delete_breakpoint); | |
15005 | }); | |
1042e4c0 SS |
15006 | } |
15007 | ||
197f0a60 TT |
15008 | /* Helper function for trace_pass_command. */ |
15009 | ||
15010 | static void | |
d9b3f62e | 15011 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15012 | { |
d9b3f62e | 15013 | tp->pass_count = count; |
c1fc2657 | 15014 | observer_notify_breakpoint_modified (tp); |
197f0a60 TT |
15015 | if (from_tty) |
15016 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 15017 | tp->number, count); |
197f0a60 TT |
15018 | } |
15019 | ||
1042e4c0 SS |
15020 | /* Set passcount for tracepoint. |
15021 | ||
15022 | First command argument is passcount, second is tracepoint number. | |
15023 | If tracepoint number omitted, apply to most recently defined. | |
15024 | Also accepts special argument "all". */ | |
15025 | ||
15026 | static void | |
15027 | trace_pass_command (char *args, int from_tty) | |
15028 | { | |
d9b3f62e | 15029 | struct tracepoint *t1; |
1042e4c0 | 15030 | unsigned int count; |
1042e4c0 SS |
15031 | |
15032 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15033 | error (_("passcount command requires an " |
15034 | "argument (count + optional TP num)")); | |
1042e4c0 | 15035 | |
4a64f543 | 15036 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15037 | |
529480d0 | 15038 | args = skip_spaces (args); |
1042e4c0 SS |
15039 | if (*args && strncasecmp (args, "all", 3) == 0) |
15040 | { | |
d9b3f62e PA |
15041 | struct breakpoint *b; |
15042 | ||
1042e4c0 | 15043 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15044 | if (*args) |
15045 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15046 | |
d9b3f62e | 15047 | ALL_TRACEPOINTS (b) |
197f0a60 | 15048 | { |
d9b3f62e | 15049 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15050 | trace_pass_set_count (t1, count, from_tty); |
15051 | } | |
15052 | } | |
15053 | else if (*args == '\0') | |
1042e4c0 | 15054 | { |
5fa1d40e | 15055 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15056 | if (t1) |
197f0a60 TT |
15057 | trace_pass_set_count (t1, count, from_tty); |
15058 | } | |
15059 | else | |
15060 | { | |
bfd28288 PA |
15061 | number_or_range_parser parser (args); |
15062 | while (!parser.finished ()) | |
1042e4c0 | 15063 | { |
bfd28288 | 15064 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15065 | if (t1) |
15066 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15067 | } |
15068 | } | |
1042e4c0 SS |
15069 | } |
15070 | ||
d9b3f62e | 15071 | struct tracepoint * |
1042e4c0 SS |
15072 | get_tracepoint (int num) |
15073 | { | |
15074 | struct breakpoint *t; | |
15075 | ||
15076 | ALL_TRACEPOINTS (t) | |
15077 | if (t->number == num) | |
d9b3f62e | 15078 | return (struct tracepoint *) t; |
1042e4c0 SS |
15079 | |
15080 | return NULL; | |
15081 | } | |
15082 | ||
d5551862 SS |
15083 | /* Find the tracepoint with the given target-side number (which may be |
15084 | different from the tracepoint number after disconnecting and | |
15085 | reconnecting). */ | |
15086 | ||
d9b3f62e | 15087 | struct tracepoint * |
d5551862 SS |
15088 | get_tracepoint_by_number_on_target (int num) |
15089 | { | |
d9b3f62e | 15090 | struct breakpoint *b; |
d5551862 | 15091 | |
d9b3f62e PA |
15092 | ALL_TRACEPOINTS (b) |
15093 | { | |
15094 | struct tracepoint *t = (struct tracepoint *) b; | |
15095 | ||
15096 | if (t->number_on_target == num) | |
15097 | return t; | |
15098 | } | |
d5551862 SS |
15099 | |
15100 | return NULL; | |
15101 | } | |
15102 | ||
1042e4c0 | 15103 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15104 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15105 | If the argument is missing, the most recent tracepoint |
15106 | (tracepoint_count) is returned. */ | |
15107 | ||
d9b3f62e | 15108 | struct tracepoint * |
197f0a60 | 15109 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15110 | number_or_range_parser *parser) |
1042e4c0 | 15111 | { |
1042e4c0 SS |
15112 | struct breakpoint *t; |
15113 | int tpnum; | |
15114 | char *instring = arg == NULL ? NULL : *arg; | |
15115 | ||
bfd28288 | 15116 | if (parser != NULL) |
197f0a60 | 15117 | { |
bfd28288 PA |
15118 | gdb_assert (!parser->finished ()); |
15119 | tpnum = parser->get_number (); | |
197f0a60 TT |
15120 | } |
15121 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15122 | tpnum = tracepoint_count; |
1042e4c0 | 15123 | else |
197f0a60 | 15124 | tpnum = get_number (arg); |
1042e4c0 SS |
15125 | |
15126 | if (tpnum <= 0) | |
15127 | { | |
15128 | if (instring && *instring) | |
15129 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15130 | instring); | |
15131 | else | |
5fa1d40e | 15132 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15133 | return NULL; |
15134 | } | |
15135 | ||
15136 | ALL_TRACEPOINTS (t) | |
15137 | if (t->number == tpnum) | |
15138 | { | |
d9b3f62e | 15139 | return (struct tracepoint *) t; |
1042e4c0 SS |
15140 | } |
15141 | ||
1042e4c0 SS |
15142 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15143 | return NULL; | |
15144 | } | |
15145 | ||
d9b3f62e PA |
15146 | void |
15147 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15148 | { | |
15149 | if (b->thread != -1) | |
15150 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15151 | ||
15152 | if (b->task != 0) | |
15153 | fprintf_unfiltered (fp, " task %d", b->task); | |
15154 | ||
15155 | fprintf_unfiltered (fp, "\n"); | |
15156 | } | |
15157 | ||
6149aea9 PA |
15158 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15159 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15160 | on each breakpoint and only include the ones for which it returns | |
15161 | non-zero. */ | |
15162 | ||
1042e4c0 | 15163 | static void |
4495129a | 15164 | save_breakpoints (const char *filename, int from_tty, |
6149aea9 | 15165 | int (*filter) (const struct breakpoint *)) |
1042e4c0 SS |
15166 | { |
15167 | struct breakpoint *tp; | |
6149aea9 | 15168 | int any = 0; |
6149aea9 | 15169 | int extra_trace_bits = 0; |
1042e4c0 | 15170 | |
6149aea9 PA |
15171 | if (filename == 0 || *filename == 0) |
15172 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15173 | |
15174 | /* See if we have anything to save. */ | |
6149aea9 | 15175 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15176 | { |
6149aea9 | 15177 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15178 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15179 | continue; |
15180 | ||
15181 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15182 | if (filter && !filter (tp)) | |
15183 | continue; | |
15184 | ||
15185 | any = 1; | |
15186 | ||
15187 | if (is_tracepoint (tp)) | |
15188 | { | |
15189 | extra_trace_bits = 1; | |
15190 | ||
15191 | /* We can stop searching. */ | |
15192 | break; | |
15193 | } | |
1042e4c0 | 15194 | } |
6149aea9 PA |
15195 | |
15196 | if (!any) | |
1042e4c0 | 15197 | { |
6149aea9 | 15198 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15199 | return; |
15200 | } | |
15201 | ||
ee0c3293 | 15202 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
15203 | |
15204 | stdio_file fp; | |
15205 | ||
ee0c3293 | 15206 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 15207 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 15208 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 15209 | |
6149aea9 | 15210 | if (extra_trace_bits) |
d7e74731 | 15211 | save_trace_state_variables (&fp); |
8bf6485c | 15212 | |
6149aea9 | 15213 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15214 | { |
6149aea9 | 15215 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15216 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15217 | continue; |
8bf6485c | 15218 | |
6149aea9 PA |
15219 | /* If we have a filter, only save the breakpoints it accepts. */ |
15220 | if (filter && !filter (tp)) | |
15221 | continue; | |
15222 | ||
d7e74731 | 15223 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15224 | |
6149aea9 PA |
15225 | /* Note, we can't rely on tp->number for anything, as we can't |
15226 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15227 | instead. */ | |
15228 | ||
15229 | if (tp->cond_string) | |
d7e74731 | 15230 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15231 | |
15232 | if (tp->ignore_count) | |
d7e74731 | 15233 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15234 | |
2d9442cc | 15235 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15236 | { |
d7e74731 | 15237 | fp.puts (" commands\n"); |
a7bdde9e | 15238 | |
d7e74731 | 15239 | current_uiout->redirect (&fp); |
492d29ea | 15240 | TRY |
1042e4c0 | 15241 | { |
d1b0a7bf | 15242 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 15243 | } |
492d29ea PA |
15244 | CATCH (ex, RETURN_MASK_ALL) |
15245 | { | |
112e8700 | 15246 | current_uiout->redirect (NULL); |
492d29ea PA |
15247 | throw_exception (ex); |
15248 | } | |
15249 | END_CATCH | |
1042e4c0 | 15250 | |
112e8700 | 15251 | current_uiout->redirect (NULL); |
d7e74731 | 15252 | fp.puts (" end\n"); |
1042e4c0 | 15253 | } |
6149aea9 PA |
15254 | |
15255 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15256 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15257 | |
15258 | /* If this is a multi-location breakpoint, check if the locations | |
15259 | should be individually disabled. Watchpoint locations are | |
15260 | special, and not user visible. */ | |
15261 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15262 | { | |
15263 | struct bp_location *loc; | |
15264 | int n = 1; | |
15265 | ||
15266 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15267 | if (!loc->enabled) | |
d7e74731 | 15268 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15269 | } |
1042e4c0 | 15270 | } |
8bf6485c | 15271 | |
6149aea9 | 15272 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15273 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15274 | |
1042e4c0 | 15275 | if (from_tty) |
ee0c3293 | 15276 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15277 | } |
15278 | ||
15279 | /* The `save breakpoints' command. */ | |
15280 | ||
15281 | static void | |
4495129a | 15282 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
15283 | { |
15284 | save_breakpoints (args, from_tty, NULL); | |
15285 | } | |
15286 | ||
15287 | /* The `save tracepoints' command. */ | |
15288 | ||
15289 | static void | |
4495129a | 15290 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
15291 | { |
15292 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15293 | } |
15294 | ||
15295 | /* Create a vector of all tracepoints. */ | |
15296 | ||
15297 | VEC(breakpoint_p) * | |
eeae04df | 15298 | all_tracepoints (void) |
1042e4c0 SS |
15299 | { |
15300 | VEC(breakpoint_p) *tp_vec = 0; | |
15301 | struct breakpoint *tp; | |
15302 | ||
15303 | ALL_TRACEPOINTS (tp) | |
15304 | { | |
15305 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15306 | } | |
15307 | ||
15308 | return tp_vec; | |
15309 | } | |
15310 | ||
c906108c | 15311 | \f |
629500fa KS |
15312 | /* This help string is used to consolidate all the help string for specifying |
15313 | locations used by several commands. */ | |
15314 | ||
15315 | #define LOCATION_HELP_STRING \ | |
15316 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15317 | source filename, function name, label name, and line number.\n\ | |
15318 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15319 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15320 | \"factorial.c:fact:the_top\".\n\ | |
15321 | \n\ | |
15322 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15323 | program. Example: To specify the fourth byte past the start function\n\ | |
15324 | \"main\", use \"*main + 4\".\n\ | |
15325 | \n\ | |
15326 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15327 | syntax to specify location parameters.\n\ | |
15328 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15329 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15330 | -function fact -label the_top\".\n" | |
15331 | ||
4a64f543 MS |
15332 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15333 | commands. It is defined as a macro to prevent duplication. | |
15334 | COMMAND should be a string constant containing the name of the | |
15335 | command. */ | |
629500fa | 15336 | |
31e2b00f | 15337 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15338 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15339 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15340 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15341 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15342 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15343 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15344 | below.\n\ | |
15345 | \n\ | |
dc10affe PA |
15346 | With no LOCATION, uses current execution address of the selected\n\ |
15347 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15348 | \n\ |
15349 | THREADNUM is the number from \"info threads\".\n\ | |
15350 | CONDITION is a boolean expression.\n\ | |
629500fa | 15351 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15352 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15353 | conditions are different.\n\ | |
31e2b00f AS |
15354 | \n\ |
15355 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15356 | ||
44feb3ce TT |
15357 | /* List of subcommands for "catch". */ |
15358 | static struct cmd_list_element *catch_cmdlist; | |
15359 | ||
15360 | /* List of subcommands for "tcatch". */ | |
15361 | static struct cmd_list_element *tcatch_cmdlist; | |
15362 | ||
9ac4176b | 15363 | void |
a121b7c1 | 15364 | add_catch_command (const char *name, const char *docstring, |
82ae6c8d | 15365 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15366 | completer_ftype *completer, |
44feb3ce TT |
15367 | void *user_data_catch, |
15368 | void *user_data_tcatch) | |
15369 | { | |
15370 | struct cmd_list_element *command; | |
15371 | ||
0450cc4c | 15372 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15373 | &catch_cmdlist); |
15374 | set_cmd_sfunc (command, sfunc); | |
15375 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15376 | set_cmd_completer (command, completer); |
44feb3ce | 15377 | |
0450cc4c | 15378 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15379 | &tcatch_cmdlist); |
15380 | set_cmd_sfunc (command, sfunc); | |
15381 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15382 | set_cmd_completer (command, completer); |
44feb3ce TT |
15383 | } |
15384 | ||
6149aea9 PA |
15385 | static void |
15386 | save_command (char *arg, int from_tty) | |
15387 | { | |
3e43a32a MS |
15388 | printf_unfiltered (_("\"save\" must be followed by " |
15389 | "the name of a save subcommand.\n")); | |
635c7e8a | 15390 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15391 | } |
15392 | ||
84f4c1fe PM |
15393 | struct breakpoint * |
15394 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15395 | void *data) | |
15396 | { | |
35df4500 | 15397 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15398 | |
35df4500 | 15399 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15400 | { |
15401 | if ((*callback) (b, data)) | |
15402 | return b; | |
15403 | } | |
15404 | ||
15405 | return NULL; | |
15406 | } | |
15407 | ||
0574c78f GB |
15408 | /* Zero if any of the breakpoint's locations could be a location where |
15409 | functions have been inlined, nonzero otherwise. */ | |
15410 | ||
15411 | static int | |
15412 | is_non_inline_function (struct breakpoint *b) | |
15413 | { | |
15414 | /* The shared library event breakpoint is set on the address of a | |
15415 | non-inline function. */ | |
15416 | if (b->type == bp_shlib_event) | |
15417 | return 1; | |
15418 | ||
15419 | return 0; | |
15420 | } | |
15421 | ||
15422 | /* Nonzero if the specified PC cannot be a location where functions | |
15423 | have been inlined. */ | |
15424 | ||
15425 | int | |
09ac7c10 TT |
15426 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15427 | const struct target_waitstatus *ws) | |
0574c78f GB |
15428 | { |
15429 | struct breakpoint *b; | |
15430 | struct bp_location *bl; | |
15431 | ||
15432 | ALL_BREAKPOINTS (b) | |
15433 | { | |
15434 | if (!is_non_inline_function (b)) | |
15435 | continue; | |
15436 | ||
15437 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15438 | { | |
15439 | if (!bl->shlib_disabled | |
09ac7c10 | 15440 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15441 | return 1; |
15442 | } | |
15443 | } | |
15444 | ||
15445 | return 0; | |
15446 | } | |
15447 | ||
2f202fde JK |
15448 | /* Remove any references to OBJFILE which is going to be freed. */ |
15449 | ||
15450 | void | |
15451 | breakpoint_free_objfile (struct objfile *objfile) | |
15452 | { | |
15453 | struct bp_location **locp, *loc; | |
15454 | ||
15455 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15456 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15457 | loc->symtab = NULL; |
15458 | } | |
15459 | ||
2060206e PA |
15460 | void |
15461 | initialize_breakpoint_ops (void) | |
15462 | { | |
15463 | static int initialized = 0; | |
15464 | ||
15465 | struct breakpoint_ops *ops; | |
15466 | ||
15467 | if (initialized) | |
15468 | return; | |
15469 | initialized = 1; | |
15470 | ||
15471 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15472 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15473 | internal and momentary breakpoints, etc.). */ | |
15474 | ops = &bkpt_base_breakpoint_ops; | |
15475 | *ops = base_breakpoint_ops; | |
15476 | ops->re_set = bkpt_re_set; | |
15477 | ops->insert_location = bkpt_insert_location; | |
15478 | ops->remove_location = bkpt_remove_location; | |
15479 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15480 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15481 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15482 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15483 | |
15484 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15485 | ops = &bkpt_breakpoint_ops; | |
15486 | *ops = bkpt_base_breakpoint_ops; | |
15487 | ops->re_set = bkpt_re_set; | |
15488 | ops->resources_needed = bkpt_resources_needed; | |
15489 | ops->print_it = bkpt_print_it; | |
15490 | ops->print_mention = bkpt_print_mention; | |
15491 | ops->print_recreate = bkpt_print_recreate; | |
15492 | ||
15493 | /* Ranged breakpoints. */ | |
15494 | ops = &ranged_breakpoint_ops; | |
15495 | *ops = bkpt_breakpoint_ops; | |
15496 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15497 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15498 | ops->print_it = print_it_ranged_breakpoint; | |
15499 | ops->print_one = print_one_ranged_breakpoint; | |
15500 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15501 | ops->print_mention = print_mention_ranged_breakpoint; | |
15502 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15503 | ||
15504 | /* Internal breakpoints. */ | |
15505 | ops = &internal_breakpoint_ops; | |
15506 | *ops = bkpt_base_breakpoint_ops; | |
15507 | ops->re_set = internal_bkpt_re_set; | |
15508 | ops->check_status = internal_bkpt_check_status; | |
15509 | ops->print_it = internal_bkpt_print_it; | |
15510 | ops->print_mention = internal_bkpt_print_mention; | |
15511 | ||
15512 | /* Momentary breakpoints. */ | |
15513 | ops = &momentary_breakpoint_ops; | |
15514 | *ops = bkpt_base_breakpoint_ops; | |
15515 | ops->re_set = momentary_bkpt_re_set; | |
15516 | ops->check_status = momentary_bkpt_check_status; | |
15517 | ops->print_it = momentary_bkpt_print_it; | |
15518 | ops->print_mention = momentary_bkpt_print_mention; | |
15519 | ||
55aa24fb SDJ |
15520 | /* Probe breakpoints. */ |
15521 | ops = &bkpt_probe_breakpoint_ops; | |
15522 | *ops = bkpt_breakpoint_ops; | |
15523 | ops->insert_location = bkpt_probe_insert_location; | |
15524 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15525 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15526 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15527 | |
2060206e PA |
15528 | /* Watchpoints. */ |
15529 | ops = &watchpoint_breakpoint_ops; | |
15530 | *ops = base_breakpoint_ops; | |
15531 | ops->re_set = re_set_watchpoint; | |
15532 | ops->insert_location = insert_watchpoint; | |
15533 | ops->remove_location = remove_watchpoint; | |
15534 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15535 | ops->check_status = check_status_watchpoint; | |
15536 | ops->resources_needed = resources_needed_watchpoint; | |
15537 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15538 | ops->print_it = print_it_watchpoint; | |
15539 | ops->print_mention = print_mention_watchpoint; | |
15540 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15541 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15542 | |
15543 | /* Masked watchpoints. */ | |
15544 | ops = &masked_watchpoint_breakpoint_ops; | |
15545 | *ops = watchpoint_breakpoint_ops; | |
15546 | ops->insert_location = insert_masked_watchpoint; | |
15547 | ops->remove_location = remove_masked_watchpoint; | |
15548 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15549 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15550 | ops->print_it = print_it_masked_watchpoint; | |
15551 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15552 | ops->print_mention = print_mention_masked_watchpoint; | |
15553 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15554 | ||
15555 | /* Tracepoints. */ | |
15556 | ops = &tracepoint_breakpoint_ops; | |
15557 | *ops = base_breakpoint_ops; | |
15558 | ops->re_set = tracepoint_re_set; | |
15559 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15560 | ops->print_one_detail = tracepoint_print_one_detail; | |
15561 | ops->print_mention = tracepoint_print_mention; | |
15562 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15563 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15564 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15565 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15566 | |
55aa24fb SDJ |
15567 | /* Probe tracepoints. */ |
15568 | ops = &tracepoint_probe_breakpoint_ops; | |
15569 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15570 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15571 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15572 | |
983af33b SDJ |
15573 | /* Static tracepoints with marker (`-m'). */ |
15574 | ops = &strace_marker_breakpoint_ops; | |
15575 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15576 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15577 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15578 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15579 | |
15580 | /* Fork catchpoints. */ | |
15581 | ops = &catch_fork_breakpoint_ops; | |
15582 | *ops = base_breakpoint_ops; | |
15583 | ops->insert_location = insert_catch_fork; | |
15584 | ops->remove_location = remove_catch_fork; | |
15585 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15586 | ops->print_it = print_it_catch_fork; | |
15587 | ops->print_one = print_one_catch_fork; | |
15588 | ops->print_mention = print_mention_catch_fork; | |
15589 | ops->print_recreate = print_recreate_catch_fork; | |
15590 | ||
15591 | /* Vfork catchpoints. */ | |
15592 | ops = &catch_vfork_breakpoint_ops; | |
15593 | *ops = base_breakpoint_ops; | |
15594 | ops->insert_location = insert_catch_vfork; | |
15595 | ops->remove_location = remove_catch_vfork; | |
15596 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15597 | ops->print_it = print_it_catch_vfork; | |
15598 | ops->print_one = print_one_catch_vfork; | |
15599 | ops->print_mention = print_mention_catch_vfork; | |
15600 | ops->print_recreate = print_recreate_catch_vfork; | |
15601 | ||
15602 | /* Exec catchpoints. */ | |
15603 | ops = &catch_exec_breakpoint_ops; | |
15604 | *ops = base_breakpoint_ops; | |
2060206e PA |
15605 | ops->insert_location = insert_catch_exec; |
15606 | ops->remove_location = remove_catch_exec; | |
15607 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15608 | ops->print_it = print_it_catch_exec; | |
15609 | ops->print_one = print_one_catch_exec; | |
15610 | ops->print_mention = print_mention_catch_exec; | |
15611 | ops->print_recreate = print_recreate_catch_exec; | |
15612 | ||
edcc5120 TT |
15613 | /* Solib-related catchpoints. */ |
15614 | ops = &catch_solib_breakpoint_ops; | |
15615 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15616 | ops->insert_location = insert_catch_solib; |
15617 | ops->remove_location = remove_catch_solib; | |
15618 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15619 | ops->check_status = check_status_catch_solib; | |
15620 | ops->print_it = print_it_catch_solib; | |
15621 | ops->print_one = print_one_catch_solib; | |
15622 | ops->print_mention = print_mention_catch_solib; | |
15623 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15624 | |
15625 | ops = &dprintf_breakpoint_ops; | |
15626 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15627 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15628 | ops->resources_needed = bkpt_resources_needed; |
15629 | ops->print_it = bkpt_print_it; | |
15630 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15631 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15632 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15633 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15634 | } |
15635 | ||
8bfd80db YQ |
15636 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15637 | ||
15638 | static struct cmd_list_element *enablebreaklist = NULL; | |
15639 | ||
c906108c | 15640 | void |
fba45db2 | 15641 | _initialize_breakpoint (void) |
c906108c SS |
15642 | { |
15643 | struct cmd_list_element *c; | |
15644 | ||
2060206e PA |
15645 | initialize_breakpoint_ops (); |
15646 | ||
84acb35a | 15647 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 15648 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 15649 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15650 | |
55aa24fb SDJ |
15651 | breakpoint_objfile_key |
15652 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 15653 | |
c906108c SS |
15654 | breakpoint_chain = 0; |
15655 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15656 | before a breakpoint is set. */ | |
15657 | breakpoint_count = 0; | |
15658 | ||
1042e4c0 SS |
15659 | tracepoint_count = 0; |
15660 | ||
1bedd215 AC |
15661 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15662 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15663 | Usage is `ignore N COUNT'.")); | |
c906108c | 15664 | |
1bedd215 | 15665 | add_com ("commands", class_breakpoint, commands_command, _("\ |
18da0c51 MG |
15666 | Set commands to be executed when the given breakpoints are hit.\n\ |
15667 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15668 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15669 | (e.g. `5-7').\n\ | |
c906108c SS |
15670 | With no argument, the targeted breakpoint is the last one set.\n\ |
15671 | The commands themselves follow starting on the next line.\n\ | |
15672 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15673 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15674 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15675 | |
d55637df | 15676 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15677 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15678 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15679 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15680 | set_cmd_completer (c, condition_completer); |
c906108c | 15681 | |
1bedd215 | 15682 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15683 | Set a temporary breakpoint.\n\ |
c906108c SS |
15684 | Like \"break\" except the breakpoint is only temporary,\n\ |
15685 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15686 | by using \"enable delete\" on the breakpoint number.\n\ |
15687 | \n" | |
15688 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15689 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15690 | |
1bedd215 | 15691 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15692 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15693 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15694 | some target hardware may not have this support.\n\ |
15695 | \n" | |
15696 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15697 | set_cmd_completer (c, location_completer); |
c906108c | 15698 | |
1bedd215 | 15699 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15700 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15701 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15702 | so it will be deleted when hit.\n\ |
15703 | \n" | |
15704 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15705 | set_cmd_completer (c, location_completer); |
c906108c | 15706 | |
1bedd215 AC |
15707 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15708 | Enable some breakpoints.\n\ | |
c906108c SS |
15709 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15710 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15711 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15712 | With a subcommand you can enable temporarily."), |
c906108c | 15713 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15714 | |
15715 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15716 | ||
84951ab5 | 15717 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15718 | Enable some breakpoints.\n\ |
c906108c SS |
15719 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15720 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15721 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15722 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15723 | |
1a966eab AC |
15724 | add_cmd ("once", no_class, enable_once_command, _("\ |
15725 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15726 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15727 | &enablebreaklist); |
15728 | ||
1a966eab AC |
15729 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15730 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15731 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15732 | &enablebreaklist); |
15733 | ||
816338b5 SS |
15734 | add_cmd ("count", no_class, enable_count_command, _("\ |
15735 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15736 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15737 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15738 | &enablebreaklist); | |
15739 | ||
1a966eab AC |
15740 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15741 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15742 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15743 | &enablelist); |
15744 | ||
1a966eab AC |
15745 | add_cmd ("once", no_class, enable_once_command, _("\ |
15746 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15747 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15748 | &enablelist); |
15749 | ||
15750 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15751 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15752 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15753 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15754 | &enablelist); |
15755 | ||
1bedd215 AC |
15756 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15757 | Disable some breakpoints.\n\ | |
c906108c SS |
15758 | Arguments are breakpoint numbers with spaces in between.\n\ |
15759 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15760 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15761 | &disablelist, "disable ", 1, &cmdlist); |
15762 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15763 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15764 | |
1a966eab AC |
15765 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15766 | Disable some breakpoints.\n\ | |
c906108c SS |
15767 | Arguments are breakpoint numbers with spaces in between.\n\ |
15768 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15769 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15770 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15771 | &disablelist); |
15772 | ||
1bedd215 AC |
15773 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15774 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15775 | Arguments are breakpoint numbers with spaces in between.\n\ |
15776 | To delete all breakpoints, give no argument.\n\ | |
15777 | \n\ | |
15778 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15779 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15780 | &deletelist, "delete ", 1, &cmdlist); |
15781 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15782 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15783 | |
1a966eab AC |
15784 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15785 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15786 | Arguments are breakpoint numbers with spaces in between.\n\ |
15787 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15788 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15789 | &deletelist); |
15790 | ||
1bedd215 | 15791 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15792 | Clear breakpoint at specified location.\n\ |
15793 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15794 | \n\ |
15795 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
15796 | is executing in.\n" |
15797 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 15798 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15799 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15800 | |
1bedd215 | 15801 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15802 | Set breakpoint at specified location.\n" |
31e2b00f | 15803 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15804 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15805 | |
c906108c SS |
15806 | add_com_alias ("b", "break", class_run, 1); |
15807 | add_com_alias ("br", "break", class_run, 1); | |
15808 | add_com_alias ("bre", "break", class_run, 1); | |
15809 | add_com_alias ("brea", "break", class_run, 1); | |
15810 | ||
c906108c SS |
15811 | if (dbx_commands) |
15812 | { | |
1bedd215 AC |
15813 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15814 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15815 | &stoplist, "stop ", 1, &cmdlist); |
15816 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15817 | _("Break in function or address."), &stoplist); |
c5aa993b | 15818 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15819 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15820 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15821 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15822 | The \"Type\" column indicates one of:\n\ |
15823 | \tbreakpoint - normal breakpoint\n\ | |
15824 | \twatchpoint - watchpoint\n\ | |
15825 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15826 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15827 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15828 | address and file/line number respectively.\n\ |
15829 | \n\ | |
15830 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15831 | are set to the address of the last breakpoint listed unless the command\n\ |
15832 | is prefixed with \"server \".\n\n\ | |
c906108c | 15833 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15834 | breakpoint set.")); |
c906108c SS |
15835 | } |
15836 | ||
11db9430 | 15837 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15838 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15839 | The \"Type\" column indicates one of:\n\ |
15840 | \tbreakpoint - normal breakpoint\n\ | |
15841 | \twatchpoint - watchpoint\n\ | |
15842 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15843 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15844 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15845 | address and file/line number respectively.\n\ |
15846 | \n\ | |
15847 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15848 | are set to the address of the last breakpoint listed unless the command\n\ |
15849 | is prefixed with \"server \".\n\n\ | |
c906108c | 15850 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15851 | breakpoint set.")); |
c906108c | 15852 | |
6b04bdb7 MS |
15853 | add_info_alias ("b", "breakpoints", 1); |
15854 | ||
1a966eab AC |
15855 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15856 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15857 | The \"Type\" column indicates one of:\n\ |
15858 | \tbreakpoint - normal breakpoint\n\ | |
15859 | \twatchpoint - watchpoint\n\ | |
15860 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15861 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15862 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15863 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15864 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15865 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15866 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15867 | address and file/line number respectively.\n\ |
15868 | \n\ | |
15869 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15870 | are set to the address of the last breakpoint listed unless the command\n\ |
15871 | is prefixed with \"server \".\n\n\ | |
c906108c | 15872 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15873 | breakpoint set."), |
c906108c SS |
15874 | &maintenanceinfolist); |
15875 | ||
44feb3ce TT |
15876 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15877 | Set catchpoints to catch events."), | |
15878 | &catch_cmdlist, "catch ", | |
15879 | 0/*allow-unknown*/, &cmdlist); | |
15880 | ||
15881 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15882 | Set temporary catchpoints to catch events."), | |
15883 | &tcatch_cmdlist, "tcatch ", | |
15884 | 0/*allow-unknown*/, &cmdlist); | |
15885 | ||
44feb3ce TT |
15886 | add_catch_command ("fork", _("Catch calls to fork."), |
15887 | catch_fork_command_1, | |
a96d9b2e | 15888 | NULL, |
44feb3ce TT |
15889 | (void *) (uintptr_t) catch_fork_permanent, |
15890 | (void *) (uintptr_t) catch_fork_temporary); | |
15891 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15892 | catch_fork_command_1, | |
a96d9b2e | 15893 | NULL, |
44feb3ce TT |
15894 | (void *) (uintptr_t) catch_vfork_permanent, |
15895 | (void *) (uintptr_t) catch_vfork_temporary); | |
15896 | add_catch_command ("exec", _("Catch calls to exec."), | |
15897 | catch_exec_command_1, | |
a96d9b2e SDJ |
15898 | NULL, |
15899 | CATCH_PERMANENT, | |
15900 | CATCH_TEMPORARY); | |
edcc5120 TT |
15901 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15902 | Usage: catch load [REGEX]\n\ | |
15903 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15904 | catch_load_command_1, | |
15905 | NULL, | |
15906 | CATCH_PERMANENT, | |
15907 | CATCH_TEMPORARY); | |
15908 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15909 | Usage: catch unload [REGEX]\n\ | |
15910 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15911 | catch_unload_command_1, | |
15912 | NULL, | |
15913 | CATCH_PERMANENT, | |
15914 | CATCH_TEMPORARY); | |
c5aa993b | 15915 | |
1bedd215 AC |
15916 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15917 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15918 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15919 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15920 | an expression changes.\n\ |
15921 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15922 | the memory to which it refers.")); | |
65d12d83 | 15923 | set_cmd_completer (c, expression_completer); |
c906108c | 15924 | |
1bedd215 AC |
15925 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15926 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15927 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15928 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15929 | an expression is read.\n\ |
15930 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15931 | the memory to which it refers.")); | |
65d12d83 | 15932 | set_cmd_completer (c, expression_completer); |
c906108c | 15933 | |
1bedd215 AC |
15934 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15935 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15936 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15937 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15938 | an expression is either read or written.\n\ |
15939 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15940 | the memory to which it refers.")); | |
65d12d83 | 15941 | set_cmd_completer (c, expression_completer); |
c906108c | 15942 | |
11db9430 | 15943 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15944 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15945 | |
920d2a44 AC |
15946 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15947 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15948 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15949 | &can_use_hw_watchpoints, _("\ | |
15950 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15951 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15952 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15953 | such is available. (However, any hardware watchpoints that were\n\ | |
15954 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15955 | hardware.)"), |
15956 | NULL, | |
920d2a44 | 15957 | show_can_use_hw_watchpoints, |
85c07804 | 15958 | &setlist, &showlist); |
c906108c SS |
15959 | |
15960 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15961 | |
1042e4c0 SS |
15962 | /* Tracepoint manipulation commands. */ |
15963 | ||
15964 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 15965 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
15966 | \n" |
15967 | BREAK_ARGS_HELP ("trace") "\n\ | |
15968 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15969 | set_cmd_completer (c, location_completer); | |
15970 | ||
15971 | add_com_alias ("tp", "trace", class_alias, 0); | |
15972 | add_com_alias ("tr", "trace", class_alias, 1); | |
15973 | add_com_alias ("tra", "trace", class_alias, 1); | |
15974 | add_com_alias ("trac", "trace", class_alias, 1); | |
15975 | ||
7a697b8d | 15976 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 15977 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
15978 | \n" |
15979 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15980 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15981 | set_cmd_completer (c, location_completer); | |
15982 | ||
0fb4aa4b | 15983 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 15984 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
15985 | \n\ |
15986 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
15987 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
15988 | or -m MARKER_ID.\n\n\ | |
15989 | If a marker id is specified, probe the marker with that name. With\n\ | |
15990 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
15991 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
15992 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15993 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15994 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15995 | \n\ | |
15996 | CONDITION is a boolean expression.\n\ | |
629500fa | 15997 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15998 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15999 | conditions are different.\n\ | |
0fb4aa4b PA |
16000 | \n\ |
16001 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16002 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16003 | set_cmd_completer (c, location_completer); | |
16004 | ||
11db9430 | 16005 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 16006 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16007 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16008 | last tracepoint set.")); | |
16009 | ||
16010 | add_info_alias ("tp", "tracepoints", 1); | |
16011 | ||
16012 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16013 | Delete specified tracepoints.\n\ | |
16014 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16015 | No argument means delete all tracepoints."), | |
16016 | &deletelist); | |
7e20dfcd | 16017 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16018 | |
16019 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16020 | Disable specified tracepoints.\n\ | |
16021 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16022 | No argument means disable all tracepoints."), | |
16023 | &disablelist); | |
16024 | deprecate_cmd (c, "disable"); | |
16025 | ||
16026 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16027 | Enable specified tracepoints.\n\ | |
16028 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16029 | No argument means enable all tracepoints."), | |
16030 | &enablelist); | |
16031 | deprecate_cmd (c, "enable"); | |
16032 | ||
16033 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16034 | Set the passcount for a tracepoint.\n\ | |
16035 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16036 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16037 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16038 | ||
6149aea9 PA |
16039 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16040 | _("Save breakpoint definitions as a script."), | |
16041 | &save_cmdlist, "save ", | |
16042 | 0/*allow-unknown*/, &cmdlist); | |
16043 | ||
16044 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16045 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16046 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16047 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16048 | session to restore them."), | |
16049 | &save_cmdlist); | |
16050 | set_cmd_completer (c, filename_completer); | |
16051 | ||
16052 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16053 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16054 | Use the 'source' command in another debug session to restore them."), |
16055 | &save_cmdlist); | |
1042e4c0 SS |
16056 | set_cmd_completer (c, filename_completer); |
16057 | ||
6149aea9 PA |
16058 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16059 | deprecate_cmd (c, "save tracepoints"); | |
16060 | ||
1bedd215 | 16061 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16062 | Breakpoint specific settings\n\ |
16063 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16064 | pending breakpoint behavior"), |
fa8d40ab JJ |
16065 | &breakpoint_set_cmdlist, "set breakpoint ", |
16066 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16067 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16068 | Breakpoint specific settings\n\ |
16069 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16070 | pending breakpoint behavior"), |
fa8d40ab JJ |
16071 | &breakpoint_show_cmdlist, "show breakpoint ", |
16072 | 0/*allow-unknown*/, &showlist); | |
16073 | ||
7915a72c AC |
16074 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16075 | &pending_break_support, _("\ | |
16076 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16077 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16078 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16079 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16080 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16081 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16082 | NULL, |
920d2a44 | 16083 | show_pending_break_support, |
6e1d7d6c AC |
16084 | &breakpoint_set_cmdlist, |
16085 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16086 | |
16087 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16088 | |
16089 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16090 | &automatic_hardware_breakpoints, _("\ | |
16091 | Set automatic usage of hardware breakpoints."), _("\ | |
16092 | Show automatic usage of hardware breakpoints."), _("\ | |
16093 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16094 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16095 | a warning will be emitted for such breakpoints."), | |
16096 | NULL, | |
16097 | show_automatic_hardware_breakpoints, | |
16098 | &breakpoint_set_cmdlist, | |
16099 | &breakpoint_show_cmdlist); | |
74960c60 | 16100 | |
a25a5a45 PA |
16101 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16102 | &always_inserted_mode, _("\ | |
74960c60 VP |
16103 | Set mode for inserting breakpoints."), _("\ |
16104 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16105 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16106 | they're created, kept inserted even when execution stops, and removed\n\ | |
16107 | only when the user deletes them. When this mode is off (the default),\n\ | |
16108 | breakpoints are inserted only when execution continues, and removed\n\ | |
16109 | when execution stops."), | |
72d0e2c5 YQ |
16110 | NULL, |
16111 | &show_always_inserted_mode, | |
16112 | &breakpoint_set_cmdlist, | |
16113 | &breakpoint_show_cmdlist); | |
f1310107 | 16114 | |
b775012e LM |
16115 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16116 | condition_evaluation_enums, | |
16117 | &condition_evaluation_mode_1, _("\ | |
16118 | Set mode of breakpoint condition evaluation."), _("\ | |
16119 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16120 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16121 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16122 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16123 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16124 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16125 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16126 | be set to \"gdb\""), | |
16127 | &set_condition_evaluation_mode, | |
16128 | &show_condition_evaluation_mode, | |
16129 | &breakpoint_set_cmdlist, | |
16130 | &breakpoint_show_cmdlist); | |
16131 | ||
f1310107 TJB |
16132 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16133 | Set a breakpoint for an address range.\n\ | |
16134 | break-range START-LOCATION, END-LOCATION\n\ | |
16135 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16136 | LINENUM, for that line in the current file,\n\ | |
16137 | FILE:LINENUM, for that line in that file,\n\ | |
16138 | +OFFSET, for that number of lines after the current line\n\ | |
16139 | or the start of the range\n\ | |
16140 | FUNCTION, for the first line in that function,\n\ | |
16141 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16142 | *ADDRESS, for the instruction at that address.\n\ | |
16143 | \n\ | |
16144 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16145 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16146 | range (including START-LOCATION and END-LOCATION).")); | |
16147 | ||
e7e0cddf | 16148 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16149 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16150 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16151 | location may be a linespec, explicit, or address location.\n" |
16152 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16153 | set_cmd_completer (c, location_completer); |
16154 | ||
16155 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16156 | dprintf_style_enums, &dprintf_style, _("\ | |
16157 | Set the style of usage for dynamic printf."), _("\ | |
16158 | Show the style of usage for dynamic printf."), _("\ | |
16159 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16160 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16161 | console, as with the \"printf\" command.\n\ | |
16162 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16163 | program; by default printf(), but you can choose a different function or\n\ | |
16164 | output stream by setting dprintf-function and dprintf-channel."), | |
16165 | update_dprintf_commands, NULL, | |
16166 | &setlist, &showlist); | |
16167 | ||
16168 | dprintf_function = xstrdup ("printf"); | |
16169 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16170 | &dprintf_function, _("\ | |
16171 | Set the function to use for dynamic printf"), _("\ | |
16172 | Show the function to use for dynamic printf"), NULL, | |
16173 | update_dprintf_commands, NULL, | |
16174 | &setlist, &showlist); | |
16175 | ||
16176 | dprintf_channel = xstrdup (""); | |
16177 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16178 | &dprintf_channel, _("\ | |
16179 | Set the channel to use for dynamic printf"), _("\ | |
16180 | Show the channel to use for dynamic printf"), NULL, | |
16181 | update_dprintf_commands, NULL, | |
16182 | &setlist, &showlist); | |
16183 | ||
d3ce09f5 SS |
16184 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16185 | &disconnected_dprintf, _("\ | |
16186 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16187 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16188 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16189 | even if GDB disconnects or detaches from the target."), | |
16190 | NULL, | |
16191 | NULL, | |
16192 | &setlist, &showlist); | |
16193 | ||
16194 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16195 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16196 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16197 | ||
765dc015 | 16198 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16199 | |
16200 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16201 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16202 | } |