]>
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 | |
896b6bda | 96 | static void map_breakpoint_numbers (const char *, |
48649e1b | 97 | gdb::function_view<void (breakpoint *)>); |
c906108c | 98 | |
348d480f PA |
99 | static void breakpoint_re_set_default (struct breakpoint *); |
100 | ||
f00aae0f KS |
101 | static void |
102 | create_sals_from_location_default (const struct event_location *location, | |
103 | struct linespec_result *canonical, | |
104 | enum bptype type_wanted); | |
983af33b SDJ |
105 | |
106 | static void create_breakpoints_sal_default (struct gdbarch *, | |
107 | struct linespec_result *, | |
e1e01040 PA |
108 | gdb::unique_xmalloc_ptr<char>, |
109 | gdb::unique_xmalloc_ptr<char>, | |
110 | enum bptype, | |
983af33b SDJ |
111 | enum bpdisp, int, int, |
112 | int, | |
113 | const struct breakpoint_ops *, | |
44f238bb | 114 | int, int, int, unsigned); |
983af33b | 115 | |
6c5b2ebe PA |
116 | static std::vector<symtab_and_line> decode_location_default |
117 | (struct breakpoint *b, const struct event_location *location, | |
118 | struct program_space *search_pspace); | |
983af33b | 119 | |
a9634178 | 120 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 121 | |
a14ed312 | 122 | static void mention (struct breakpoint *); |
c906108c | 123 | |
348d480f PA |
124 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
125 | enum bptype, | |
c0a91b2b | 126 | const struct breakpoint_ops *); |
3742cc8b YQ |
127 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
128 | const struct symtab_and_line *); | |
129 | ||
4a64f543 MS |
130 | /* This function is used in gdbtk sources and thus can not be made |
131 | static. */ | |
63c252f8 | 132 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 133 | struct symtab_and_line, |
c0a91b2b TT |
134 | enum bptype, |
135 | const struct breakpoint_ops *); | |
c906108c | 136 | |
06edf0c0 PA |
137 | static struct breakpoint * |
138 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
139 | enum bptype type, | |
a1aa2221 LM |
140 | const struct breakpoint_ops *ops, |
141 | int loc_enabled); | |
06edf0c0 | 142 | |
76897487 KB |
143 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
144 | ||
a6d9a66e UW |
145 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
146 | CORE_ADDR bpaddr, | |
88f7da05 | 147 | enum bptype bptype); |
76897487 | 148 | |
6c95b8df PA |
149 | static void describe_other_breakpoints (struct gdbarch *, |
150 | struct program_space *, CORE_ADDR, | |
5af949e3 | 151 | struct obj_section *, int); |
c906108c | 152 | |
85d721b8 PA |
153 | static int watchpoint_locations_match (struct bp_location *loc1, |
154 | struct bp_location *loc2); | |
155 | ||
f1310107 | 156 | static int breakpoint_location_address_match (struct bp_location *bl, |
accd0bcd | 157 | const struct address_space *aspace, |
f1310107 TJB |
158 | CORE_ADDR addr); |
159 | ||
d35ae833 | 160 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
accd0bcd | 161 | const address_space *, |
d35ae833 PA |
162 | CORE_ADDR, int); |
163 | ||
834c0d03 | 164 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 165 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 166 | |
e514a9d6 | 167 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 168 | |
a14ed312 | 169 | static int hw_breakpoint_used_count (void); |
c906108c | 170 | |
a1398e0c PA |
171 | static int hw_watchpoint_use_count (struct breakpoint *); |
172 | ||
173 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
174 | enum bptype type, | |
175 | int *other_type_used); | |
c906108c | 176 | |
816338b5 SS |
177 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
178 | int count); | |
c906108c | 179 | |
fe3f5fa8 | 180 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
181 | static void incref_bp_location (struct bp_location *loc); |
182 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 183 | |
39d61571 | 184 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 185 | |
44702360 PA |
186 | /* update_global_location_list's modes of operation wrt to whether to |
187 | insert locations now. */ | |
188 | enum ugll_insert_mode | |
189 | { | |
190 | /* Don't insert any breakpoint locations into the inferior, only | |
191 | remove already-inserted locations that no longer should be | |
192 | inserted. Functions that delete a breakpoint or breakpoints | |
193 | should specify this mode, so that deleting a breakpoint doesn't | |
194 | have the side effect of inserting the locations of other | |
195 | breakpoints that are marked not-inserted, but should_be_inserted | |
196 | returns true on them. | |
197 | ||
198 | This behavior is useful is situations close to tear-down -- e.g., | |
199 | after an exec, while the target still has execution, but | |
200 | breakpoint shadows of the previous executable image should *NOT* | |
201 | be restored to the new image; or before detaching, where the | |
202 | target still has execution and wants to delete breakpoints from | |
203 | GDB's lists, and all breakpoints had already been removed from | |
204 | the inferior. */ | |
205 | UGLL_DONT_INSERT, | |
206 | ||
a25a5a45 PA |
207 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
208 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
209 | UGLL_MAY_INSERT, |
210 | ||
a25a5a45 PA |
211 | /* Insert locations now, irrespective of |
212 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
213 | stopped right now, and the user did "continue". We need to | |
214 | insert breakpoints _before_ resuming the target, but | |
215 | UGLL_MAY_INSERT wouldn't insert them, because | |
216 | breakpoints_should_be_inserted_now returns false at that point, | |
217 | as no thread is running yet. */ | |
04086b45 | 218 | UGLL_INSERT |
44702360 PA |
219 | }; |
220 | ||
221 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 222 | |
44702360 | 223 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 224 | |
d77f58be | 225 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
226 | |
227 | static void insert_breakpoint_locations (void); | |
a5606eee | 228 | |
0b39b52e | 229 | static void trace_pass_command (const char *, int); |
1042e4c0 | 230 | |
558a9d82 YQ |
231 | static void set_tracepoint_count (int num); |
232 | ||
9c06b0b4 TJB |
233 | static int is_masked_watchpoint (const struct breakpoint *b); |
234 | ||
b775012e LM |
235 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
236 | ||
983af33b SDJ |
237 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
238 | otherwise. */ | |
239 | ||
240 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 241 | |
2060206e PA |
242 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
243 | that are implemented on top of software or hardware breakpoints | |
244 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
245 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
246 | ||
247 | /* Internal breakpoints class type. */ | |
06edf0c0 | 248 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
249 | |
250 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
251 | static struct breakpoint_ops momentary_breakpoint_ops; |
252 | ||
2060206e PA |
253 | /* The breakpoint_ops structure to be used in regular user created |
254 | breakpoints. */ | |
255 | struct breakpoint_ops bkpt_breakpoint_ops; | |
256 | ||
55aa24fb SDJ |
257 | /* Breakpoints set on probes. */ |
258 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
259 | ||
e7e0cddf | 260 | /* Dynamic printf class type. */ |
c5867ab6 | 261 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 262 | |
d3ce09f5 SS |
263 | /* The style in which to perform a dynamic printf. This is a user |
264 | option because different output options have different tradeoffs; | |
265 | if GDB does the printing, there is better error handling if there | |
266 | is a problem with any of the arguments, but using an inferior | |
267 | function lets you have special-purpose printers and sending of | |
268 | output to the same place as compiled-in print functions. */ | |
269 | ||
270 | static const char dprintf_style_gdb[] = "gdb"; | |
271 | static const char dprintf_style_call[] = "call"; | |
272 | static const char dprintf_style_agent[] = "agent"; | |
273 | static const char *const dprintf_style_enums[] = { | |
274 | dprintf_style_gdb, | |
275 | dprintf_style_call, | |
276 | dprintf_style_agent, | |
277 | NULL | |
278 | }; | |
279 | static const char *dprintf_style = dprintf_style_gdb; | |
280 | ||
281 | /* The function to use for dynamic printf if the preferred style is to | |
282 | call into the inferior. The value is simply a string that is | |
283 | copied into the command, so it can be anything that GDB can | |
284 | evaluate to a callable address, not necessarily a function name. */ | |
285 | ||
bde6261a | 286 | static char *dprintf_function; |
d3ce09f5 SS |
287 | |
288 | /* The channel to use for dynamic printf if the preferred style is to | |
289 | call into the inferior; if a nonempty string, it will be passed to | |
290 | the call as the first argument, with the format string as the | |
291 | second. As with the dprintf function, this can be anything that | |
292 | GDB knows how to evaluate, so in addition to common choices like | |
293 | "stderr", this could be an app-specific expression like | |
294 | "mystreams[curlogger]". */ | |
295 | ||
bde6261a | 296 | static char *dprintf_channel; |
d3ce09f5 SS |
297 | |
298 | /* True if dprintf commands should continue to operate even if GDB | |
299 | has disconnected. */ | |
300 | static int disconnected_dprintf = 1; | |
301 | ||
5cea2a26 PA |
302 | struct command_line * |
303 | breakpoint_commands (struct breakpoint *b) | |
304 | { | |
d1b0a7bf | 305 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 306 | } |
3daf8fe5 | 307 | |
f3b1572e PA |
308 | /* Flag indicating that a command has proceeded the inferior past the |
309 | current breakpoint. */ | |
310 | ||
311 | static int breakpoint_proceeded; | |
312 | ||
956a9fb9 | 313 | const char * |
2cec12e5 AR |
314 | bpdisp_text (enum bpdisp disp) |
315 | { | |
4a64f543 MS |
316 | /* NOTE: the following values are a part of MI protocol and |
317 | represent values of 'disp' field returned when inferior stops at | |
318 | a breakpoint. */ | |
bc043ef3 | 319 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 320 | |
2cec12e5 AR |
321 | return bpdisps[(int) disp]; |
322 | } | |
c906108c | 323 | |
4a64f543 | 324 | /* Prototypes for exported functions. */ |
c906108c | 325 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 326 | if such is available. */ |
c906108c SS |
327 | static int can_use_hw_watchpoints; |
328 | ||
920d2a44 AC |
329 | static void |
330 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
331 | struct cmd_list_element *c, | |
332 | const char *value) | |
333 | { | |
3e43a32a MS |
334 | fprintf_filtered (file, |
335 | _("Debugger's willingness to use " | |
336 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
337 | value); |
338 | } | |
339 | ||
fa8d40ab JJ |
340 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
341 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 342 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
343 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
344 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
345 | static void |
346 | show_pending_break_support (struct ui_file *file, int from_tty, | |
347 | struct cmd_list_element *c, | |
348 | const char *value) | |
349 | { | |
3e43a32a MS |
350 | fprintf_filtered (file, |
351 | _("Debugger's behavior regarding " | |
352 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
353 | value); |
354 | } | |
fa8d40ab | 355 | |
765dc015 | 356 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 357 | set with "break" but falling in read-only memory. |
765dc015 VP |
358 | If 0, gdb will warn about such breakpoints, but won't automatically |
359 | use hardware breakpoints. */ | |
360 | static int automatic_hardware_breakpoints; | |
361 | static void | |
362 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
363 | struct cmd_list_element *c, | |
364 | const char *value) | |
365 | { | |
3e43a32a MS |
366 | fprintf_filtered (file, |
367 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
368 | value); |
369 | } | |
370 | ||
a25a5a45 PA |
371 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
372 | stopped, and immediately inserts any new breakpoints as soon as | |
373 | they're created. If off (default), GDB keeps breakpoints off of | |
374 | the target as long as possible. That is, it delays inserting | |
375 | breakpoints until the next resume, and removes them again when the | |
376 | target fully stops. This is a bit safer in case GDB crashes while | |
377 | processing user input. */ | |
378 | static int always_inserted_mode = 0; | |
72d0e2c5 | 379 | |
33e5cbd6 | 380 | static void |
74960c60 | 381 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 382 | struct cmd_list_element *c, const char *value) |
74960c60 | 383 | { |
a25a5a45 PA |
384 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
385 | value); | |
74960c60 VP |
386 | } |
387 | ||
b57bacec PA |
388 | /* See breakpoint.h. */ |
389 | ||
33e5cbd6 | 390 | int |
a25a5a45 | 391 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 392 | { |
a25a5a45 PA |
393 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
394 | { | |
395 | /* If breakpoints are global, they should be inserted even if no | |
396 | thread under gdb's control is running, or even if there are | |
397 | no threads under GDB's control yet. */ | |
398 | return 1; | |
399 | } | |
400 | else if (target_has_execution) | |
401 | { | |
372316f1 PA |
402 | struct thread_info *tp; |
403 | ||
a25a5a45 PA |
404 | if (always_inserted_mode) |
405 | { | |
406 | /* The user wants breakpoints inserted even if all threads | |
407 | are stopped. */ | |
408 | return 1; | |
409 | } | |
410 | ||
b57bacec PA |
411 | if (threads_are_executing ()) |
412 | return 1; | |
372316f1 PA |
413 | |
414 | /* Don't remove breakpoints yet if, even though all threads are | |
415 | stopped, we still have events to process. */ | |
416 | ALL_NON_EXITED_THREADS (tp) | |
417 | if (tp->resumed | |
418 | && tp->suspend.waitstatus_pending_p) | |
419 | return 1; | |
a25a5a45 PA |
420 | } |
421 | return 0; | |
33e5cbd6 | 422 | } |
765dc015 | 423 | |
b775012e LM |
424 | static const char condition_evaluation_both[] = "host or target"; |
425 | ||
426 | /* Modes for breakpoint condition evaluation. */ | |
427 | static const char condition_evaluation_auto[] = "auto"; | |
428 | static const char condition_evaluation_host[] = "host"; | |
429 | static const char condition_evaluation_target[] = "target"; | |
430 | static const char *const condition_evaluation_enums[] = { | |
431 | condition_evaluation_auto, | |
432 | condition_evaluation_host, | |
433 | condition_evaluation_target, | |
434 | NULL | |
435 | }; | |
436 | ||
437 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
438 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
439 | ||
440 | /* Global that we use to display information to the user (gets its value from | |
441 | condition_evaluation_mode_1. */ | |
442 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
443 | ||
444 | /* Translate a condition evaluation mode MODE into either "host" | |
445 | or "target". This is used mostly to translate from "auto" to the | |
446 | real setting that is being used. It returns the translated | |
447 | evaluation mode. */ | |
448 | ||
449 | static const char * | |
450 | translate_condition_evaluation_mode (const char *mode) | |
451 | { | |
452 | if (mode == condition_evaluation_auto) | |
453 | { | |
454 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
455 | return condition_evaluation_target; | |
456 | else | |
457 | return condition_evaluation_host; | |
458 | } | |
459 | else | |
460 | return mode; | |
461 | } | |
462 | ||
463 | /* Discovers what condition_evaluation_auto translates to. */ | |
464 | ||
465 | static const char * | |
466 | breakpoint_condition_evaluation_mode (void) | |
467 | { | |
468 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
469 | } | |
470 | ||
471 | /* Return true if GDB should evaluate breakpoint conditions or false | |
472 | otherwise. */ | |
473 | ||
474 | static int | |
475 | gdb_evaluates_breakpoint_condition_p (void) | |
476 | { | |
477 | const char *mode = breakpoint_condition_evaluation_mode (); | |
478 | ||
479 | return (mode == condition_evaluation_host); | |
480 | } | |
481 | ||
c906108c SS |
482 | /* Are we executing breakpoint commands? */ |
483 | static int executing_breakpoint_commands; | |
484 | ||
c02f5703 MS |
485 | /* Are overlay event breakpoints enabled? */ |
486 | static int overlay_events_enabled; | |
487 | ||
e09342b5 TJB |
488 | /* See description in breakpoint.h. */ |
489 | int target_exact_watchpoints = 0; | |
490 | ||
c906108c | 491 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 492 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 493 | current breakpoint. */ |
c906108c | 494 | |
5c44784c | 495 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 496 | |
5c44784c JM |
497 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
498 | for (B = breakpoint_chain; \ | |
499 | B ? (TMP=B->next, 1): 0; \ | |
500 | B = TMP) | |
c906108c | 501 | |
4a64f543 MS |
502 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
503 | not provided so update_global_location_list must not be called | |
504 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 505 | |
876fa593 | 506 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
507 | for (BP_TMP = bp_locations; \ |
508 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 509 | BP_TMP++) |
7cc221ef | 510 | |
b775012e LM |
511 | /* Iterates through locations with address ADDRESS for the currently selected |
512 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
513 | to where the loop should start from. | |
514 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
515 | appropriate location to start with. */ | |
516 | ||
517 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
518 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
519 | BP_LOCP_TMP = BP_LOCP_START; \ | |
520 | BP_LOCP_START \ | |
f5336ca5 | 521 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
522 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
523 | BP_LOCP_TMP++) | |
524 | ||
1042e4c0 SS |
525 | /* Iterator for tracepoints only. */ |
526 | ||
527 | #define ALL_TRACEPOINTS(B) \ | |
528 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 529 | if (is_tracepoint (B)) |
1042e4c0 | 530 | |
7cc221ef | 531 | /* Chains of all breakpoints defined. */ |
c906108c SS |
532 | |
533 | struct breakpoint *breakpoint_chain; | |
534 | ||
f5336ca5 | 535 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
876fa593 | 536 | |
f5336ca5 | 537 | static struct bp_location **bp_locations; |
876fa593 | 538 | |
f5336ca5 | 539 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 540 | |
f5336ca5 | 541 | static unsigned bp_locations_count; |
876fa593 | 542 | |
4a64f543 | 543 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 544 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 545 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 546 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 547 | an address you need to read. */ |
876fa593 | 548 | |
f5336ca5 | 549 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 550 | |
4a64f543 MS |
551 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
552 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
553 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
554 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 555 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 556 | |
f5336ca5 | 557 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 558 | |
4a64f543 | 559 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
560 | from the bp_locations array, but for which a hit may still be |
561 | reported by a target. */ | |
20874c92 VP |
562 | VEC(bp_location_p) *moribund_locations = NULL; |
563 | ||
c906108c SS |
564 | /* Number of last breakpoint made. */ |
565 | ||
95a42b64 TT |
566 | static int breakpoint_count; |
567 | ||
86b17b60 PA |
568 | /* The value of `breakpoint_count' before the last command that |
569 | created breakpoints. If the last (break-like) command created more | |
570 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
571 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
572 | static int prev_breakpoint_count; | |
c906108c | 573 | |
1042e4c0 SS |
574 | /* Number of last tracepoint made. */ |
575 | ||
95a42b64 | 576 | static int tracepoint_count; |
1042e4c0 | 577 | |
6149aea9 PA |
578 | static struct cmd_list_element *breakpoint_set_cmdlist; |
579 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 580 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 581 | |
badd37ce SDJ |
582 | /* See declaration at breakpoint.h. */ |
583 | ||
584 | struct breakpoint * | |
585 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
586 | void *user_data) | |
587 | { | |
588 | struct breakpoint *b = NULL; | |
589 | ||
590 | ALL_BREAKPOINTS (b) | |
591 | { | |
592 | if (func (b, user_data) != 0) | |
593 | break; | |
594 | } | |
595 | ||
596 | return b; | |
597 | } | |
598 | ||
468d015d JJ |
599 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
600 | static int | |
601 | breakpoint_enabled (struct breakpoint *b) | |
602 | { | |
0d381245 | 603 | return (b->enable_state == bp_enabled); |
468d015d JJ |
604 | } |
605 | ||
c906108c SS |
606 | /* Set breakpoint count to NUM. */ |
607 | ||
95a42b64 | 608 | static void |
fba45db2 | 609 | set_breakpoint_count (int num) |
c906108c | 610 | { |
86b17b60 | 611 | prev_breakpoint_count = breakpoint_count; |
c906108c | 612 | breakpoint_count = num; |
4fa62494 | 613 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
614 | } |
615 | ||
86b17b60 PA |
616 | /* Used by `start_rbreak_breakpoints' below, to record the current |
617 | breakpoint count before "rbreak" creates any breakpoint. */ | |
618 | static int rbreak_start_breakpoint_count; | |
619 | ||
95a42b64 TT |
620 | /* Called at the start an "rbreak" command to record the first |
621 | breakpoint made. */ | |
86b17b60 | 622 | |
c80049d3 | 623 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
95a42b64 | 624 | { |
86b17b60 | 625 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
626 | } |
627 | ||
628 | /* Called at the end of an "rbreak" command to record the last | |
629 | breakpoint made. */ | |
86b17b60 | 630 | |
c80049d3 | 631 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
95a42b64 | 632 | { |
86b17b60 | 633 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
634 | } |
635 | ||
4a64f543 | 636 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
637 | |
638 | void | |
fba45db2 | 639 | clear_breakpoint_hit_counts (void) |
c906108c SS |
640 | { |
641 | struct breakpoint *b; | |
642 | ||
643 | ALL_BREAKPOINTS (b) | |
644 | b->hit_count = 0; | |
645 | } | |
646 | ||
c906108c | 647 | \f |
48cb2d85 VP |
648 | /* Return the breakpoint with the specified number, or NULL |
649 | if the number does not refer to an existing breakpoint. */ | |
650 | ||
651 | struct breakpoint * | |
652 | get_breakpoint (int num) | |
653 | { | |
654 | struct breakpoint *b; | |
655 | ||
656 | ALL_BREAKPOINTS (b) | |
657 | if (b->number == num) | |
658 | return b; | |
659 | ||
660 | return NULL; | |
661 | } | |
5c44784c | 662 | |
c906108c | 663 | \f |
adc36818 | 664 | |
b775012e LM |
665 | /* Mark locations as "conditions have changed" in case the target supports |
666 | evaluating conditions on its side. */ | |
667 | ||
668 | static void | |
669 | mark_breakpoint_modified (struct breakpoint *b) | |
670 | { | |
671 | struct bp_location *loc; | |
672 | ||
673 | /* This is only meaningful if the target is | |
674 | evaluating conditions and if the user has | |
675 | opted for condition evaluation on the target's | |
676 | side. */ | |
677 | if (gdb_evaluates_breakpoint_condition_p () | |
678 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
679 | return; | |
680 | ||
681 | if (!is_breakpoint (b)) | |
682 | return; | |
683 | ||
684 | for (loc = b->loc; loc; loc = loc->next) | |
685 | loc->condition_changed = condition_modified; | |
686 | } | |
687 | ||
688 | /* Mark location as "conditions have changed" in case the target supports | |
689 | evaluating conditions on its side. */ | |
690 | ||
691 | static void | |
692 | mark_breakpoint_location_modified (struct bp_location *loc) | |
693 | { | |
694 | /* This is only meaningful if the target is | |
695 | evaluating conditions and if the user has | |
696 | opted for condition evaluation on the target's | |
697 | side. */ | |
698 | if (gdb_evaluates_breakpoint_condition_p () | |
699 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
700 | ||
701 | return; | |
702 | ||
703 | if (!is_breakpoint (loc->owner)) | |
704 | return; | |
705 | ||
706 | loc->condition_changed = condition_modified; | |
707 | } | |
708 | ||
709 | /* Sets the condition-evaluation mode using the static global | |
710 | condition_evaluation_mode. */ | |
711 | ||
712 | static void | |
eb4c3f4a | 713 | set_condition_evaluation_mode (const char *args, int from_tty, |
b775012e LM |
714 | struct cmd_list_element *c) |
715 | { | |
b775012e LM |
716 | const char *old_mode, *new_mode; |
717 | ||
718 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
719 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
720 | { | |
721 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
722 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
723 | "Using host evaluation mode instead.")); | |
724 | return; | |
725 | } | |
726 | ||
727 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
728 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
729 | ||
abf1152a JK |
730 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
731 | settings was "auto". */ | |
732 | condition_evaluation_mode = condition_evaluation_mode_1; | |
733 | ||
b775012e LM |
734 | /* Only update the mode if the user picked a different one. */ |
735 | if (new_mode != old_mode) | |
736 | { | |
737 | struct bp_location *loc, **loc_tmp; | |
738 | /* If the user switched to a different evaluation mode, we | |
739 | need to synch the changes with the target as follows: | |
740 | ||
741 | "host" -> "target": Send all (valid) conditions to the target. | |
742 | "target" -> "host": Remove all the conditions from the target. | |
743 | */ | |
744 | ||
b775012e LM |
745 | if (new_mode == condition_evaluation_target) |
746 | { | |
747 | /* Mark everything modified and synch conditions with the | |
748 | target. */ | |
749 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
750 | mark_breakpoint_location_modified (loc); | |
751 | } | |
752 | else | |
753 | { | |
754 | /* Manually mark non-duplicate locations to synch conditions | |
755 | with the target. We do this to remove all the conditions the | |
756 | target knows about. */ | |
757 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
758 | if (is_breakpoint (loc->owner) && loc->inserted) | |
759 | loc->needs_update = 1; | |
760 | } | |
761 | ||
762 | /* Do the update. */ | |
44702360 | 763 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
764 | } |
765 | ||
766 | return; | |
767 | } | |
768 | ||
769 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
770 | what "auto" is translating to. */ | |
771 | ||
772 | static void | |
773 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
774 | struct cmd_list_element *c, const char *value) | |
775 | { | |
776 | if (condition_evaluation_mode == condition_evaluation_auto) | |
777 | fprintf_filtered (file, | |
778 | _("Breakpoint condition evaluation " | |
779 | "mode is %s (currently %s).\n"), | |
780 | value, | |
781 | breakpoint_condition_evaluation_mode ()); | |
782 | else | |
783 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
784 | value); | |
785 | } | |
786 | ||
787 | /* A comparison function for bp_location AP and BP that is used by | |
788 | bsearch. This comparison function only cares about addresses, unlike | |
f5336ca5 | 789 | the more general bp_locations_compare function. */ |
b775012e LM |
790 | |
791 | static int | |
f5336ca5 | 792 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 793 | { |
9a3c8263 SM |
794 | const struct bp_location *a = *(const struct bp_location **) ap; |
795 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
796 | |
797 | if (a->address == b->address) | |
798 | return 0; | |
799 | else | |
800 | return ((a->address > b->address) - (a->address < b->address)); | |
801 | } | |
802 | ||
803 | /* Helper function to skip all bp_locations with addresses | |
804 | less than ADDRESS. It returns the first bp_location that | |
805 | is greater than or equal to ADDRESS. If none is found, just | |
806 | return NULL. */ | |
807 | ||
808 | static struct bp_location ** | |
809 | get_first_locp_gte_addr (CORE_ADDR address) | |
810 | { | |
811 | struct bp_location dummy_loc; | |
812 | struct bp_location *dummy_locp = &dummy_loc; | |
813 | struct bp_location **locp_found = NULL; | |
814 | ||
815 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
816 | dummy_loc.address = address; |
817 | ||
818 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 819 | locp_found = ((struct bp_location **) |
f5336ca5 | 820 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 821 | sizeof (struct bp_location **), |
f5336ca5 | 822 | bp_locations_compare_addrs)); |
b775012e LM |
823 | |
824 | /* Nothing was found, nothing left to do. */ | |
825 | if (locp_found == NULL) | |
826 | return NULL; | |
827 | ||
828 | /* We may have found a location that is at ADDRESS but is not the first in the | |
829 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 830 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
831 | && (*(locp_found - 1))->address == address) |
832 | locp_found--; | |
833 | ||
834 | return locp_found; | |
835 | } | |
836 | ||
adc36818 | 837 | void |
7a26bd4d | 838 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
839 | int from_tty) |
840 | { | |
3a5c3e22 PA |
841 | xfree (b->cond_string); |
842 | b->cond_string = NULL; | |
adc36818 | 843 | |
3a5c3e22 | 844 | if (is_watchpoint (b)) |
adc36818 | 845 | { |
3a5c3e22 PA |
846 | struct watchpoint *w = (struct watchpoint *) b; |
847 | ||
4d01a485 | 848 | w->cond_exp.reset (); |
3a5c3e22 PA |
849 | } |
850 | else | |
851 | { | |
852 | struct bp_location *loc; | |
853 | ||
854 | for (loc = b->loc; loc; loc = loc->next) | |
855 | { | |
4d01a485 | 856 | loc->cond.reset (); |
b775012e LM |
857 | |
858 | /* No need to free the condition agent expression | |
859 | bytecode (if we have one). We will handle this | |
860 | when we go through update_global_location_list. */ | |
3a5c3e22 | 861 | } |
adc36818 | 862 | } |
adc36818 PM |
863 | |
864 | if (*exp == 0) | |
865 | { | |
866 | if (from_tty) | |
867 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
868 | } | |
869 | else | |
870 | { | |
bbc13ae3 | 871 | const char *arg = exp; |
cc59ec59 | 872 | |
adc36818 PM |
873 | /* I don't know if it matters whether this is the string the user |
874 | typed in or the decompiled expression. */ | |
875 | b->cond_string = xstrdup (arg); | |
876 | b->condition_not_parsed = 0; | |
877 | ||
878 | if (is_watchpoint (b)) | |
879 | { | |
3a5c3e22 PA |
880 | struct watchpoint *w = (struct watchpoint *) b; |
881 | ||
adc36818 PM |
882 | innermost_block = NULL; |
883 | arg = exp; | |
1bb9788d | 884 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
885 | if (*arg) |
886 | error (_("Junk at end of expression")); | |
3a5c3e22 | 887 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
888 | } |
889 | else | |
890 | { | |
3a5c3e22 PA |
891 | struct bp_location *loc; |
892 | ||
adc36818 PM |
893 | for (loc = b->loc; loc; loc = loc->next) |
894 | { | |
895 | arg = exp; | |
896 | loc->cond = | |
1bb9788d TT |
897 | parse_exp_1 (&arg, loc->address, |
898 | block_for_pc (loc->address), 0); | |
adc36818 PM |
899 | if (*arg) |
900 | error (_("Junk at end of expression")); | |
901 | } | |
902 | } | |
903 | } | |
b775012e LM |
904 | mark_breakpoint_modified (b); |
905 | ||
8d3788bd | 906 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
907 | } |
908 | ||
d55637df TT |
909 | /* Completion for the "condition" command. */ |
910 | ||
eb3ff9a5 | 911 | static void |
6f937416 | 912 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 913 | completion_tracker &tracker, |
6f937416 | 914 | const char *text, const char *word) |
d55637df | 915 | { |
6f937416 | 916 | const char *space; |
d55637df | 917 | |
f1735a53 TT |
918 | text = skip_spaces (text); |
919 | space = skip_to_space (text); | |
d55637df TT |
920 | if (*space == '\0') |
921 | { | |
922 | int len; | |
923 | struct breakpoint *b; | |
d55637df TT |
924 | |
925 | if (text[0] == '$') | |
926 | { | |
927 | /* We don't support completion of history indices. */ | |
eb3ff9a5 PA |
928 | if (!isdigit (text[1])) |
929 | complete_internalvar (tracker, &text[1]); | |
930 | return; | |
d55637df TT |
931 | } |
932 | ||
933 | /* We're completing the breakpoint number. */ | |
934 | len = strlen (text); | |
935 | ||
936 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
937 | { |
938 | char number[50]; | |
939 | ||
940 | xsnprintf (number, sizeof (number), "%d", b->number); | |
941 | ||
942 | if (strncmp (number, text, len) == 0) | |
eb3ff9a5 PA |
943 | { |
944 | gdb::unique_xmalloc_ptr<char> copy (xstrdup (number)); | |
945 | tracker.add_completion (std::move (copy)); | |
946 | } | |
58ce7251 | 947 | } |
d55637df | 948 | |
eb3ff9a5 | 949 | return; |
d55637df TT |
950 | } |
951 | ||
952 | /* We're completing the expression part. */ | |
f1735a53 | 953 | text = skip_spaces (space); |
eb3ff9a5 | 954 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
955 | } |
956 | ||
c906108c SS |
957 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
958 | ||
959 | static void | |
0b39b52e | 960 | condition_command (const char *arg, int from_tty) |
c906108c | 961 | { |
52f0bd74 | 962 | struct breakpoint *b; |
0b39b52e | 963 | const char *p; |
52f0bd74 | 964 | int bnum; |
c906108c SS |
965 | |
966 | if (arg == 0) | |
e2e0b3e5 | 967 | error_no_arg (_("breakpoint number")); |
c906108c SS |
968 | |
969 | p = arg; | |
970 | bnum = get_number (&p); | |
5c44784c | 971 | if (bnum == 0) |
8a3fe4f8 | 972 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
973 | |
974 | ALL_BREAKPOINTS (b) | |
975 | if (b->number == bnum) | |
2f069f6f | 976 | { |
6dddc817 DE |
977 | /* Check if this breakpoint has a "stop" method implemented in an |
978 | extension language. This method and conditions entered into GDB | |
979 | from the CLI are mutually exclusive. */ | |
980 | const struct extension_language_defn *extlang | |
981 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
982 | ||
983 | if (extlang != NULL) | |
984 | { | |
985 | error (_("Only one stop condition allowed. There is currently" | |
986 | " a %s stop condition defined for this breakpoint."), | |
987 | ext_lang_capitalized_name (extlang)); | |
988 | } | |
2566ad2d | 989 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
990 | |
991 | if (is_breakpoint (b)) | |
44702360 | 992 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 993 | |
2f069f6f JB |
994 | return; |
995 | } | |
c906108c | 996 | |
8a3fe4f8 | 997 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
998 | } |
999 | ||
a7bdde9e VP |
1000 | /* Check that COMMAND do not contain commands that are suitable |
1001 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1002 | Throw if any such commands is found. */ |
1003 | ||
a7bdde9e VP |
1004 | static void |
1005 | check_no_tracepoint_commands (struct command_line *commands) | |
1006 | { | |
1007 | struct command_line *c; | |
cc59ec59 | 1008 | |
a7bdde9e VP |
1009 | for (c = commands; c; c = c->next) |
1010 | { | |
1011 | int i; | |
1012 | ||
1013 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1014 | error (_("The 'while-stepping' command can " |
1015 | "only be used for tracepoints")); | |
a7bdde9e VP |
1016 | |
1017 | for (i = 0; i < c->body_count; ++i) | |
1018 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1019 | ||
1020 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1021 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1022 | command directly. */ |
1023 | if (strstr (c->line, "collect ") == c->line) | |
1024 | error (_("The 'collect' command can only be used for tracepoints")); | |
1025 | ||
51661e93 VP |
1026 | if (strstr (c->line, "teval ") == c->line) |
1027 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1028 | } |
1029 | } | |
1030 | ||
c1fc2657 | 1031 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1032 | { |
c1fc2657 | 1033 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1034 | }; |
1035 | ||
d77f58be SS |
1036 | /* Encapsulate tests for different types of tracepoints. */ |
1037 | ||
3b0871f4 SM |
1038 | static bool |
1039 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1040 | { |
1041 | return (type == bp_tracepoint | |
1042 | || type == bp_fast_tracepoint | |
1043 | || type == bp_static_tracepoint); | |
1044 | } | |
1045 | ||
3b0871f4 SM |
1046 | static bool |
1047 | is_longjmp_type (bptype type) | |
1048 | { | |
1049 | return type == bp_longjmp || type == bp_exception; | |
1050 | } | |
1051 | ||
a7bdde9e | 1052 | int |
d77f58be | 1053 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1054 | { |
d9b3f62e | 1055 | return is_tracepoint_type (b->type); |
a7bdde9e | 1056 | } |
d9b3f62e | 1057 | |
a5e364af SM |
1058 | /* Factory function to create an appropriate instance of breakpoint given |
1059 | TYPE. */ | |
1060 | ||
1061 | static std::unique_ptr<breakpoint> | |
1062 | new_breakpoint_from_type (bptype type) | |
1063 | { | |
1064 | breakpoint *b; | |
1065 | ||
1066 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1067 | b = new tracepoint (); |
3b0871f4 | 1068 | else if (is_longjmp_type (type)) |
c1fc2657 | 1069 | b = new longjmp_breakpoint (); |
a5e364af SM |
1070 | else |
1071 | b = new breakpoint (); | |
1072 | ||
1073 | return std::unique_ptr<breakpoint> (b); | |
1074 | } | |
1075 | ||
e5dd4106 | 1076 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1077 | breakpoint. This function will throw an exception if a problem is |
1078 | found. */ | |
48cb2d85 | 1079 | |
95a42b64 TT |
1080 | static void |
1081 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1082 | struct command_line *commands) | |
48cb2d85 | 1083 | { |
d77f58be | 1084 | if (is_tracepoint (b)) |
a7bdde9e | 1085 | { |
c9a6ce02 | 1086 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1087 | struct command_line *c; |
1088 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1089 | |
1090 | /* Reset the while-stepping step count. The previous commands | |
1091 | might have included a while-stepping action, while the new | |
1092 | ones might not. */ | |
1093 | t->step_count = 0; | |
1094 | ||
1095 | /* We need to verify that each top-level element of commands is | |
1096 | valid for tracepoints, that there's at most one | |
1097 | while-stepping element, and that the while-stepping's body | |
1098 | has valid tracing commands excluding nested while-stepping. | |
1099 | We also need to validate the tracepoint action line in the | |
1100 | context of the tracepoint --- validate_actionline actually | |
1101 | has side effects, like setting the tracepoint's | |
1102 | while-stepping STEP_COUNT, in addition to checking if the | |
1103 | collect/teval actions parse and make sense in the | |
1104 | tracepoint's context. */ | |
a7bdde9e VP |
1105 | for (c = commands; c; c = c->next) |
1106 | { | |
a7bdde9e VP |
1107 | if (c->control_type == while_stepping_control) |
1108 | { | |
1109 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1110 | error (_("The 'while-stepping' command " |
1111 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1112 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1113 | error (_("The 'while-stepping' command " |
1114 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1115 | |
1116 | if (while_stepping) | |
3e43a32a MS |
1117 | error (_("The 'while-stepping' command " |
1118 | "can be used only once")); | |
a7bdde9e VP |
1119 | else |
1120 | while_stepping = c; | |
1121 | } | |
c9a6ce02 PA |
1122 | |
1123 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1124 | } |
1125 | if (while_stepping) | |
1126 | { | |
1127 | struct command_line *c2; | |
1128 | ||
1129 | gdb_assert (while_stepping->body_count == 1); | |
1130 | c2 = while_stepping->body_list[0]; | |
1131 | for (; c2; c2 = c2->next) | |
1132 | { | |
a7bdde9e VP |
1133 | if (c2->control_type == while_stepping_control) |
1134 | error (_("The 'while-stepping' command cannot be nested")); | |
1135 | } | |
1136 | } | |
1137 | } | |
1138 | else | |
1139 | { | |
1140 | check_no_tracepoint_commands (commands); | |
1141 | } | |
95a42b64 TT |
1142 | } |
1143 | ||
0fb4aa4b PA |
1144 | /* Return a vector of all the static tracepoints set at ADDR. The |
1145 | caller is responsible for releasing the vector. */ | |
1146 | ||
1147 | VEC(breakpoint_p) * | |
1148 | static_tracepoints_here (CORE_ADDR addr) | |
1149 | { | |
1150 | struct breakpoint *b; | |
1151 | VEC(breakpoint_p) *found = 0; | |
1152 | struct bp_location *loc; | |
1153 | ||
1154 | ALL_BREAKPOINTS (b) | |
1155 | if (b->type == bp_static_tracepoint) | |
1156 | { | |
1157 | for (loc = b->loc; loc; loc = loc->next) | |
1158 | if (loc->address == addr) | |
1159 | VEC_safe_push(breakpoint_p, found, b); | |
1160 | } | |
1161 | ||
1162 | return found; | |
1163 | } | |
1164 | ||
95a42b64 | 1165 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1166 | validate that only allowed commands are included. */ |
95a42b64 TT |
1167 | |
1168 | void | |
4a64f543 | 1169 | breakpoint_set_commands (struct breakpoint *b, |
93921405 | 1170 | command_line_up &&commands) |
95a42b64 | 1171 | { |
93921405 | 1172 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1173 | |
d1b0a7bf | 1174 | b->commands = std::move (commands); |
8d3788bd | 1175 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1176 | } |
1177 | ||
45a43567 TT |
1178 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1179 | is not the same as the "silent" that may appear in the breakpoint's | |
1180 | commands. */ | |
1181 | ||
1182 | void | |
1183 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1184 | { | |
1185 | int old_silent = b->silent; | |
1186 | ||
1187 | b->silent = silent; | |
1188 | if (old_silent != silent) | |
8d3788bd | 1189 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1190 | } |
1191 | ||
1192 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1193 | breakpoint work for any thread. */ | |
1194 | ||
1195 | void | |
1196 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1197 | { | |
1198 | int old_thread = b->thread; | |
1199 | ||
1200 | b->thread = thread; | |
1201 | if (old_thread != thread) | |
8d3788bd | 1202 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1203 | } |
1204 | ||
1205 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1206 | breakpoint work for any task. */ | |
1207 | ||
1208 | void | |
1209 | breakpoint_set_task (struct breakpoint *b, int task) | |
1210 | { | |
1211 | int old_task = b->task; | |
1212 | ||
1213 | b->task = task; | |
1214 | if (old_task != task) | |
8d3788bd | 1215 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1216 | } |
1217 | ||
95a42b64 TT |
1218 | void |
1219 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1220 | { |
9a3c8263 | 1221 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1222 | |
6f937416 | 1223 | validate_actionline (line, b); |
a7bdde9e VP |
1224 | } |
1225 | ||
95a42b64 | 1226 | static void |
896b6bda | 1227 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1228 | struct command_line *control) |
95a42b64 | 1229 | { |
d1b0a7bf | 1230 | counted_command_line cmd; |
95a42b64 | 1231 | |
896b6bda PA |
1232 | std::string new_arg; |
1233 | ||
95a42b64 TT |
1234 | if (arg == NULL || !*arg) |
1235 | { | |
86b17b60 | 1236 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1237 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1238 | breakpoint_count); | |
95a42b64 | 1239 | else if (breakpoint_count > 0) |
896b6bda | 1240 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b TT |
1241 | arg = new_arg.c_str (); |
1242 | } | |
1243 | ||
1244 | map_breakpoint_numbers | |
1245 | (arg, [&] (breakpoint *b) | |
1246 | { | |
1247 | if (cmd == NULL) | |
1248 | { | |
48649e1b | 1249 | if (control != NULL) |
d1b0a7bf | 1250 | cmd = copy_command_lines (control->body_list[0]); |
48649e1b TT |
1251 | else |
1252 | { | |
81b1e71c TT |
1253 | std::string str |
1254 | = string_printf (_("Type commands for breakpoint(s) " | |
1255 | "%s, one per line."), | |
1256 | arg); | |
48649e1b | 1257 | |
81b1e71c | 1258 | cmd = read_command_lines (&str[0], |
d1b0a7bf TT |
1259 | from_tty, 1, |
1260 | (is_tracepoint (b) | |
1261 | ? check_tracepoint_command : 0), | |
1262 | b); | |
48649e1b | 1263 | } |
48649e1b TT |
1264 | } |
1265 | ||
1266 | /* If a breakpoint was on the list more than once, we don't need to | |
1267 | do anything. */ | |
1268 | if (b->commands != cmd) | |
1269 | { | |
d1b0a7bf | 1270 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b TT |
1271 | b->commands = cmd; |
1272 | observer_notify_breakpoint_modified (b); | |
1273 | } | |
1274 | }); | |
95a42b64 | 1275 | |
48649e1b | 1276 | if (cmd == NULL) |
95a42b64 | 1277 | error (_("No breakpoints specified.")); |
95a42b64 TT |
1278 | } |
1279 | ||
1280 | static void | |
0b39b52e | 1281 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1282 | { |
1283 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1284 | } |
40c03ae8 EZ |
1285 | |
1286 | /* Like commands_command, but instead of reading the commands from | |
1287 | input stream, takes them from an already parsed command structure. | |
1288 | ||
1289 | This is used by cli-script.c to DTRT with breakpoint commands | |
1290 | that are part of if and while bodies. */ | |
1291 | enum command_control_type | |
896b6bda | 1292 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1293 | { |
95a42b64 TT |
1294 | commands_command_1 (arg, 0, cmd); |
1295 | return simple_control; | |
40c03ae8 | 1296 | } |
876fa593 JK |
1297 | |
1298 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1299 | ||
1300 | static int | |
1301 | bp_location_has_shadow (struct bp_location *bl) | |
1302 | { | |
1303 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1304 | return 0; | |
1305 | if (!bl->inserted) | |
1306 | return 0; | |
1307 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1308 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1309 | return 0; |
1310 | return 1; | |
1311 | } | |
1312 | ||
9d497a19 PA |
1313 | /* Update BUF, which is LEN bytes read from the target address |
1314 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1315 | contents. | |
1316 | ||
1317 | If READBUF is not NULL, this buffer must not overlap with the of | |
1318 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1319 | failed assertion internal error will be raised. */ | |
1320 | ||
1321 | static void | |
1322 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1323 | const gdb_byte *writebuf_org, | |
1324 | ULONGEST memaddr, LONGEST len, | |
1325 | struct bp_target_info *target_info, | |
1326 | struct gdbarch *gdbarch) | |
1327 | { | |
1328 | /* Now do full processing of the found relevant range of elements. */ | |
1329 | CORE_ADDR bp_addr = 0; | |
1330 | int bp_size = 0; | |
1331 | int bptoffset = 0; | |
1332 | ||
1333 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1334 | current_program_space->aspace, 0)) | |
1335 | { | |
1336 | /* The breakpoint is inserted in a different address space. */ | |
1337 | return; | |
1338 | } | |
1339 | ||
1340 | /* Addresses and length of the part of the breakpoint that | |
1341 | we need to copy. */ | |
1342 | bp_addr = target_info->placed_address; | |
1343 | bp_size = target_info->shadow_len; | |
1344 | ||
1345 | if (bp_addr + bp_size <= memaddr) | |
1346 | { | |
1347 | /* The breakpoint is entirely before the chunk of memory we are | |
1348 | reading. */ | |
1349 | return; | |
1350 | } | |
1351 | ||
1352 | if (bp_addr >= memaddr + len) | |
1353 | { | |
1354 | /* The breakpoint is entirely after the chunk of memory we are | |
1355 | reading. */ | |
1356 | return; | |
1357 | } | |
1358 | ||
1359 | /* Offset within shadow_contents. */ | |
1360 | if (bp_addr < memaddr) | |
1361 | { | |
1362 | /* Only copy the second part of the breakpoint. */ | |
1363 | bp_size -= memaddr - bp_addr; | |
1364 | bptoffset = memaddr - bp_addr; | |
1365 | bp_addr = memaddr; | |
1366 | } | |
1367 | ||
1368 | if (bp_addr + bp_size > memaddr + len) | |
1369 | { | |
1370 | /* Only copy the first part of the breakpoint. */ | |
1371 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1372 | } | |
1373 | ||
1374 | if (readbuf != NULL) | |
1375 | { | |
1376 | /* Verify that the readbuf buffer does not overlap with the | |
1377 | shadow_contents buffer. */ | |
1378 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1379 | || readbuf >= (target_info->shadow_contents | |
1380 | + target_info->shadow_len)); | |
1381 | ||
1382 | /* Update the read buffer with this inserted breakpoint's | |
1383 | shadow. */ | |
1384 | memcpy (readbuf + bp_addr - memaddr, | |
1385 | target_info->shadow_contents + bptoffset, bp_size); | |
1386 | } | |
1387 | else | |
1388 | { | |
1389 | const unsigned char *bp; | |
0d5ed153 MR |
1390 | CORE_ADDR addr = target_info->reqstd_address; |
1391 | int placed_size; | |
9d497a19 PA |
1392 | |
1393 | /* Update the shadow with what we want to write to memory. */ | |
1394 | memcpy (target_info->shadow_contents + bptoffset, | |
1395 | writebuf_org + bp_addr - memaddr, bp_size); | |
1396 | ||
1397 | /* Determine appropriate breakpoint contents and size for this | |
1398 | address. */ | |
0d5ed153 | 1399 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1400 | |
1401 | /* Update the final write buffer with this inserted | |
1402 | breakpoint's INSN. */ | |
1403 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1404 | } | |
1405 | } | |
1406 | ||
8defab1a | 1407 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1408 | by replacing any memory breakpoints with their shadowed contents. |
1409 | ||
35c63cd8 JB |
1410 | If READBUF is not NULL, this buffer must not overlap with any of |
1411 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1412 | a failed assertion internal error will be raised. | |
1413 | ||
876fa593 | 1414 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1415 | bl->address - bp_locations_placed_address_before_address_max |
1416 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1417 | The range we were requested to resolve shadows for is: |
1418 | memaddr ... memaddr + len | |
1419 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1420 | memaddr + len <= (bl->address |
f5336ca5 | 1421 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1422 | and: |
f5336ca5 | 1423 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1424 | |
8defab1a | 1425 | void |
f0ba3972 PA |
1426 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1427 | const gdb_byte *writebuf_org, | |
1428 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1429 | { |
4a64f543 MS |
1430 | /* Left boundary, right boundary and median element of our binary |
1431 | search. */ | |
876fa593 JK |
1432 | unsigned bc_l, bc_r, bc; |
1433 | ||
4a64f543 MS |
1434 | /* Find BC_L which is a leftmost element which may affect BUF |
1435 | content. It is safe to report lower value but a failure to | |
1436 | report higher one. */ | |
876fa593 JK |
1437 | |
1438 | bc_l = 0; | |
f5336ca5 | 1439 | bc_r = bp_locations_count; |
876fa593 JK |
1440 | while (bc_l + 1 < bc_r) |
1441 | { | |
35df4500 | 1442 | struct bp_location *bl; |
876fa593 JK |
1443 | |
1444 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1445 | bl = bp_locations[bc]; |
876fa593 | 1446 | |
4a64f543 MS |
1447 | /* Check first BL->ADDRESS will not overflow due to the added |
1448 | constant. Then advance the left boundary only if we are sure | |
1449 | the BC element can in no way affect the BUF content (MEMADDR | |
1450 | to MEMADDR + LEN range). | |
876fa593 | 1451 | |
f5336ca5 | 1452 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1453 | offset so that we cannot miss a breakpoint with its shadow |
1454 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1455 | |
f5336ca5 | 1456 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1457 | >= bl->address) |
f5336ca5 | 1458 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1459 | <= memaddr)) |
876fa593 JK |
1460 | bc_l = bc; |
1461 | else | |
1462 | bc_r = bc; | |
1463 | } | |
1464 | ||
128070bb PA |
1465 | /* Due to the binary search above, we need to make sure we pick the |
1466 | first location that's at BC_L's address. E.g., if there are | |
1467 | multiple locations at the same address, BC_L may end up pointing | |
1468 | at a duplicate location, and miss the "master"/"inserted" | |
1469 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1470 | B: | |
1471 | ||
1472 | L1@A, L2@A, L3@B, ... | |
1473 | ||
1474 | BC_L could end up pointing at location L2, while the "master" | |
1475 | location could be L1. Since the `loc->inserted' flag is only set | |
1476 | on "master" locations, we'd forget to restore the shadow of L1 | |
1477 | and L2. */ | |
1478 | while (bc_l > 0 | |
f5336ca5 | 1479 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1480 | bc_l--; |
1481 | ||
876fa593 JK |
1482 | /* Now do full processing of the found relevant range of elements. */ |
1483 | ||
f5336ca5 | 1484 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1485 | { |
f5336ca5 | 1486 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1487 | |
35df4500 TJB |
1488 | /* bp_location array has BL->OWNER always non-NULL. */ |
1489 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1490 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1491 | bl->owner->number); |
ffce0d52 | 1492 | |
e5dd4106 | 1493 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1494 | content. */ |
1495 | ||
f5336ca5 PA |
1496 | if (bl->address >= bp_locations_placed_address_before_address_max |
1497 | && memaddr + len <= (bl->address | |
1498 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1499 | break; |
1500 | ||
35df4500 | 1501 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1502 | continue; |
6c95b8df | 1503 | |
9d497a19 PA |
1504 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1505 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1506 | } | |
c906108c | 1507 | } |
9d497a19 | 1508 | |
c906108c | 1509 | \f |
c5aa993b | 1510 | |
b775012e LM |
1511 | /* Return true if BPT is either a software breakpoint or a hardware |
1512 | breakpoint. */ | |
1513 | ||
1514 | int | |
1515 | is_breakpoint (const struct breakpoint *bpt) | |
1516 | { | |
1517 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1518 | || bpt->type == bp_hardware_breakpoint |
1519 | || bpt->type == bp_dprintf); | |
b775012e LM |
1520 | } |
1521 | ||
60e1c644 PA |
1522 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1523 | ||
a5606eee | 1524 | static int |
d77f58be | 1525 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1526 | { |
1527 | return (bpt->type == bp_hardware_watchpoint | |
1528 | || bpt->type == bp_read_watchpoint | |
1529 | || bpt->type == bp_access_watchpoint); | |
1530 | } | |
7270d8f2 | 1531 | |
60e1c644 PA |
1532 | /* Return true if BPT is of any watchpoint kind, hardware or |
1533 | software. */ | |
1534 | ||
3a5c3e22 | 1535 | int |
d77f58be | 1536 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1537 | { |
1538 | return (is_hardware_watchpoint (bpt) | |
1539 | || bpt->type == bp_watchpoint); | |
1540 | } | |
1541 | ||
3a5c3e22 PA |
1542 | /* Returns true if the current thread and its running state are safe |
1543 | to evaluate or update watchpoint B. Watchpoints on local | |
1544 | expressions need to be evaluated in the context of the thread that | |
1545 | was current when the watchpoint was created, and, that thread needs | |
1546 | to be stopped to be able to select the correct frame context. | |
1547 | Watchpoints on global expressions can be evaluated on any thread, | |
1548 | and in any state. It is presently left to the target allowing | |
1549 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1550 | |
1551 | static int | |
3a5c3e22 | 1552 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1553 | { |
c1fc2657 | 1554 | return (b->pspace == current_program_space |
d0d8b0c6 JK |
1555 | && (ptid_equal (b->watchpoint_thread, null_ptid) |
1556 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1557 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1558 | } |
1559 | ||
d0fb5eae JK |
1560 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1561 | associated bp_watchpoint_scope breakpoint. */ | |
1562 | ||
1563 | static void | |
3a5c3e22 | 1564 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1565 | { |
c1fc2657 | 1566 | if (w->related_breakpoint != w) |
d0fb5eae | 1567 | { |
c1fc2657 SM |
1568 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1569 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1570 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1571 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1572 | w->related_breakpoint = w; | |
d0fb5eae | 1573 | } |
c1fc2657 | 1574 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1575 | } |
1576 | ||
bb9d5f81 PP |
1577 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1578 | watchpoint W. */ | |
1579 | ||
1580 | static struct value * | |
1581 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1582 | { | |
1583 | struct value *bit_val; | |
1584 | ||
1585 | if (val == NULL) | |
1586 | return NULL; | |
1587 | ||
1588 | bit_val = allocate_value (value_type (val)); | |
1589 | ||
1590 | unpack_value_bitfield (bit_val, | |
1591 | w->val_bitpos, | |
1592 | w->val_bitsize, | |
1593 | value_contents_for_printing (val), | |
1594 | value_offset (val), | |
1595 | val); | |
1596 | ||
1597 | return bit_val; | |
1598 | } | |
1599 | ||
c6d81124 PA |
1600 | /* Allocate a dummy location and add it to B, which must be a software |
1601 | watchpoint. This is required because even if a software watchpoint | |
1602 | is not watching any memory, bpstat_stop_status requires a location | |
1603 | to be able to report stops. */ | |
1604 | ||
1605 | static void | |
1606 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1607 | struct program_space *pspace) | |
1608 | { | |
1609 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1610 | ||
1611 | b->loc = allocate_bp_location (b); | |
1612 | b->loc->pspace = pspace; | |
1613 | b->loc->address = -1; | |
1614 | b->loc->length = -1; | |
1615 | } | |
1616 | ||
1617 | /* Returns true if B is a software watchpoint that is not watching any | |
1618 | memory (e.g., "watch $pc"). */ | |
1619 | ||
1620 | static int | |
1621 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1622 | { | |
1623 | return (b->type == bp_watchpoint | |
1624 | && b->loc != NULL | |
1625 | && b->loc->next == NULL | |
1626 | && b->loc->address == -1 | |
1627 | && b->loc->length == -1); | |
1628 | } | |
1629 | ||
567e1b4e JB |
1630 | /* Assuming that B is a watchpoint: |
1631 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1632 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1633 | - Evaluate the condition if there is one, and store the result |
1634 | in b->loc->cond. | |
a5606eee VP |
1635 | - Update the list of values that must be watched in B->loc. |
1636 | ||
4a64f543 MS |
1637 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1638 | nothing. If this is local watchpoint that is out of scope, delete | |
1639 | it. | |
1640 | ||
1641 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1642 | removed + inserted on each stop here. Normal breakpoints must | |
1643 | never be removed because they might be missed by a running thread | |
1644 | when debugging in non-stop mode. On the other hand, hardware | |
1645 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1646 | to each LWP since they are stored in each LWP's hardware debug | |
1647 | registers. Therefore, such LWP must be stopped first in order to | |
1648 | be able to modify its hardware watchpoints. | |
1649 | ||
1650 | Hardware watchpoints must be reset exactly once after being | |
1651 | presented to the user. It cannot be done sooner, because it would | |
1652 | reset the data used to present the watchpoint hit to the user. And | |
1653 | it must not be done later because it could display the same single | |
1654 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1655 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1656 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1657 | not user-visible - its hit is suppressed if the memory content has | |
1658 | not changed. | |
1659 | ||
1660 | The following constraints influence the location where we can reset | |
1661 | hardware watchpoints: | |
1662 | ||
1663 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1664 | called several times when GDB stops. | |
1665 | ||
1666 | [linux] | |
1667 | * Multiple hardware watchpoints can be hit at the same time, | |
1668 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1669 | hit at a time as the reason for stopping, and all the other hits | |
1670 | are presented later, one after the other, each time the user | |
1671 | requests the execution to be resumed. Execution is not resumed | |
1672 | for the threads still having pending hit event stored in | |
1673 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1674 | the inferior on the first stop the thread hit event is kept being | |
1675 | reported from its cached value by linux_nat_stopped_data_address | |
1676 | until the real thread resume happens after the watchpoint gets | |
1677 | presented and thus its LWP_INFO->STATUS gets reset. | |
1678 | ||
1679 | Therefore the hardware watchpoint hit can get safely reset on the | |
1680 | watchpoint removal from inferior. */ | |
a79d3c27 | 1681 | |
b40ce68a | 1682 | static void |
3a5c3e22 | 1683 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1684 | { |
a5606eee | 1685 | int within_current_scope; |
a5606eee | 1686 | struct frame_id saved_frame_id; |
66076460 | 1687 | int frame_saved; |
a5606eee | 1688 | |
f6bc2008 PA |
1689 | /* If this is a local watchpoint, we only want to check if the |
1690 | watchpoint frame is in scope if the current thread is the thread | |
1691 | that was used to create the watchpoint. */ | |
1692 | if (!watchpoint_in_thread_scope (b)) | |
1693 | return; | |
1694 | ||
c1fc2657 | 1695 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1696 | return; |
1697 | ||
66076460 | 1698 | frame_saved = 0; |
a5606eee VP |
1699 | |
1700 | /* Determine if the watchpoint is within scope. */ | |
1701 | if (b->exp_valid_block == NULL) | |
1702 | within_current_scope = 1; | |
1703 | else | |
1704 | { | |
b5db5dfc UW |
1705 | struct frame_info *fi = get_current_frame (); |
1706 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1707 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1708 | ||
c9cf6e20 MG |
1709 | /* If we're at a point where the stack has been destroyed |
1710 | (e.g. in a function epilogue), unwinding may not work | |
1711 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1712 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1713 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1714 | return; |
66076460 DJ |
1715 | |
1716 | /* Save the current frame's ID so we can restore it after | |
1717 | evaluating the watchpoint expression on its own frame. */ | |
1718 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1719 | took a frame parameter, so that we didn't have to change the | |
1720 | selected frame. */ | |
1721 | frame_saved = 1; | |
1722 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1723 | ||
a5606eee VP |
1724 | fi = frame_find_by_id (b->watchpoint_frame); |
1725 | within_current_scope = (fi != NULL); | |
1726 | if (within_current_scope) | |
1727 | select_frame (fi); | |
1728 | } | |
1729 | ||
b5db5dfc UW |
1730 | /* We don't free locations. They are stored in the bp_location array |
1731 | and update_global_location_list will eventually delete them and | |
1732 | remove breakpoints if needed. */ | |
c1fc2657 | 1733 | b->loc = NULL; |
b5db5dfc | 1734 | |
a5606eee VP |
1735 | if (within_current_scope && reparse) |
1736 | { | |
bbc13ae3 | 1737 | const char *s; |
d63d0675 | 1738 | |
4d01a485 | 1739 | b->exp.reset (); |
d63d0675 | 1740 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1741 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1742 | /* If the meaning of expression itself changed, the old value is |
1743 | no longer relevant. We don't want to report a watchpoint hit | |
1744 | to the user when the old value and the new value may actually | |
1745 | be completely different objects. */ | |
1746 | value_free (b->val); | |
fa4727a6 DJ |
1747 | b->val = NULL; |
1748 | b->val_valid = 0; | |
60e1c644 PA |
1749 | |
1750 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1751 | expression is stored in the breakpoint object, not in the | |
1752 | locations (re)created below. */ | |
c1fc2657 | 1753 | if (b->cond_string != NULL) |
60e1c644 | 1754 | { |
4d01a485 | 1755 | b->cond_exp.reset (); |
60e1c644 | 1756 | |
c1fc2657 | 1757 | s = b->cond_string; |
1bb9788d | 1758 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1759 | } |
a5606eee | 1760 | } |
a5606eee VP |
1761 | |
1762 | /* If we failed to parse the expression, for example because | |
1763 | it refers to a global variable in a not-yet-loaded shared library, | |
1764 | don't try to insert watchpoint. We don't automatically delete | |
1765 | such watchpoint, though, since failure to parse expression | |
1766 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1767 | if (!target_has_execution) |
2d134ed3 PA |
1768 | { |
1769 | /* Without execution, memory can't change. No use to try and | |
1770 | set watchpoint locations. The watchpoint will be reset when | |
1771 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1772 | if (!can_use_hw_watchpoints) |
1773 | { | |
c1fc2657 SM |
1774 | if (b->ops->works_in_software_mode (b)) |
1775 | b->type = bp_watchpoint; | |
e8369a73 | 1776 | else |
638aa5a1 AB |
1777 | error (_("Can't set read/access watchpoint when " |
1778 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1779 | } |
2d134ed3 PA |
1780 | } |
1781 | else if (within_current_scope && b->exp) | |
a5606eee | 1782 | { |
0cf6dd15 | 1783 | int pc = 0; |
fa4727a6 | 1784 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1785 | struct program_space *frame_pspace; |
a5606eee | 1786 | |
4d01a485 | 1787 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1788 | |
a5606eee VP |
1789 | /* Avoid setting b->val if it's already set. The meaning of |
1790 | b->val is 'the last value' user saw, and we should update | |
1791 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1792 | happens, the code that reports it updates b->val directly. |
1793 | We don't keep track of the memory value for masked | |
1794 | watchpoints. */ | |
c1fc2657 | 1795 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1796 | { |
bb9d5f81 PP |
1797 | if (b->val_bitsize != 0) |
1798 | { | |
1799 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1800 | if (v != NULL) | |
1801 | release_value (v); | |
1802 | } | |
fa4727a6 DJ |
1803 | b->val = v; |
1804 | b->val_valid = 1; | |
1805 | } | |
a5606eee | 1806 | |
2d134ed3 PA |
1807 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1808 | ||
a5606eee | 1809 | /* Look at each value on the value chain. */ |
9fa40276 | 1810 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1811 | { |
1812 | /* If it's a memory location, and GDB actually needed | |
1813 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1814 | must watch it. If the first value returned is |
1815 | still lazy, that means an error occurred reading it; | |
1816 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1817 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1818 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1819 | { |
1820 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1821 | |
a5606eee VP |
1822 | /* We only watch structs and arrays if user asked |
1823 | for it explicitly, never if they just happen to | |
1824 | appear in the middle of some value chain. */ | |
fa4727a6 | 1825 | if (v == result |
a5606eee VP |
1826 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1827 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1828 | { | |
1829 | CORE_ADDR addr; | |
f486487f | 1830 | enum target_hw_bp_type type; |
a5606eee | 1831 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1832 | int bitpos = 0, bitsize = 0; |
1833 | ||
1834 | if (value_bitsize (v) != 0) | |
1835 | { | |
1836 | /* Extract the bit parameters out from the bitfield | |
1837 | sub-expression. */ | |
1838 | bitpos = value_bitpos (v); | |
1839 | bitsize = value_bitsize (v); | |
1840 | } | |
1841 | else if (v == result && b->val_bitsize != 0) | |
1842 | { | |
1843 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1844 | lvalue whose bit parameters are saved in the fields | |
1845 | VAL_BITPOS and VAL_BITSIZE. */ | |
1846 | bitpos = b->val_bitpos; | |
1847 | bitsize = b->val_bitsize; | |
1848 | } | |
a5606eee | 1849 | |
42ae5230 | 1850 | addr = value_address (v); |
bb9d5f81 PP |
1851 | if (bitsize != 0) |
1852 | { | |
1853 | /* Skip the bytes that don't contain the bitfield. */ | |
1854 | addr += bitpos / 8; | |
1855 | } | |
1856 | ||
a5606eee | 1857 | type = hw_write; |
c1fc2657 | 1858 | if (b->type == bp_read_watchpoint) |
a5606eee | 1859 | type = hw_read; |
c1fc2657 | 1860 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1861 | type = hw_access; |
3a5c3e22 | 1862 | |
c1fc2657 SM |
1863 | loc = allocate_bp_location (b); |
1864 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1865 | ; |
1866 | *tmp = loc; | |
a6d9a66e | 1867 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1868 | |
1869 | loc->pspace = frame_pspace; | |
a5606eee | 1870 | loc->address = addr; |
bb9d5f81 PP |
1871 | |
1872 | if (bitsize != 0) | |
1873 | { | |
1874 | /* Just cover the bytes that make up the bitfield. */ | |
1875 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1876 | } | |
1877 | else | |
1878 | loc->length = TYPE_LENGTH (value_type (v)); | |
1879 | ||
a5606eee VP |
1880 | loc->watchpoint_type = type; |
1881 | } | |
1882 | } | |
9fa40276 TJB |
1883 | } |
1884 | ||
1885 | /* Change the type of breakpoint between hardware assisted or | |
1886 | an ordinary watchpoint depending on the hardware support | |
1887 | and free hardware slots. REPARSE is set when the inferior | |
1888 | is started. */ | |
a9634178 | 1889 | if (reparse) |
9fa40276 | 1890 | { |
e09342b5 | 1891 | int reg_cnt; |
9fa40276 TJB |
1892 | enum bp_loc_type loc_type; |
1893 | struct bp_location *bl; | |
a5606eee | 1894 | |
a9634178 | 1895 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1896 | |
1897 | if (reg_cnt) | |
9fa40276 TJB |
1898 | { |
1899 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1900 | enum bptype type; |
9fa40276 | 1901 | |
a9634178 TJB |
1902 | /* Use an exact watchpoint when there's only one memory region to be |
1903 | watched, and only one debug register is needed to watch it. */ | |
1904 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1905 | ||
9fa40276 | 1906 | /* We need to determine how many resources are already |
e09342b5 TJB |
1907 | used for all other hardware watchpoints plus this one |
1908 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1909 | this watchpoint in as well. */ |
1910 | ||
1911 | /* If this is a software watchpoint, we try to turn it | |
1912 | to a hardware one -- count resources as if B was of | |
1913 | hardware watchpoint type. */ | |
c1fc2657 | 1914 | type = b->type; |
a1398e0c PA |
1915 | if (type == bp_watchpoint) |
1916 | type = bp_hardware_watchpoint; | |
1917 | ||
1918 | /* This watchpoint may or may not have been placed on | |
1919 | the list yet at this point (it won't be in the list | |
1920 | if we're trying to create it for the first time, | |
1921 | through watch_command), so always account for it | |
1922 | manually. */ | |
1923 | ||
1924 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 1925 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
1926 | |
1927 | /* Add in the resources needed for B. */ | |
c1fc2657 | 1928 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
1929 | |
1930 | target_resources_ok | |
1931 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1932 | if (target_resources_ok <= 0) |
a9634178 | 1933 | { |
c1fc2657 | 1934 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
1935 | |
1936 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1937 | error (_("Target does not support this type of " |
1938 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1939 | else if (target_resources_ok < 0 && !sw_mode) |
1940 | error (_("There are not enough available hardware " | |
1941 | "resources for this watchpoint.")); | |
a1398e0c PA |
1942 | |
1943 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 1944 | b->type = bp_watchpoint; |
a1398e0c PA |
1945 | } |
1946 | else | |
1947 | { | |
1948 | /* If this was a software watchpoint, we've just | |
1949 | found we have enough resources to turn it to a | |
1950 | hardware watchpoint. Otherwise, this is a | |
1951 | nop. */ | |
c1fc2657 | 1952 | b->type = type; |
a9634178 | 1953 | } |
9fa40276 | 1954 | } |
c1fc2657 | 1955 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
1956 | { |
1957 | if (!can_use_hw_watchpoints) | |
1958 | error (_("Can't set read/access watchpoint when " | |
1959 | "hardware watchpoints are disabled.")); | |
1960 | else | |
1961 | error (_("Expression cannot be implemented with " | |
1962 | "read/access watchpoint.")); | |
1963 | } | |
9fa40276 | 1964 | else |
c1fc2657 | 1965 | b->type = bp_watchpoint; |
9fa40276 | 1966 | |
c1fc2657 | 1967 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 1968 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 1969 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
1970 | bl->loc_type = loc_type; |
1971 | } | |
1972 | ||
1973 | for (v = val_chain; v; v = next) | |
1974 | { | |
a5606eee VP |
1975 | next = value_next (v); |
1976 | if (v != b->val) | |
1977 | value_free (v); | |
1978 | } | |
1979 | ||
c7437ca6 PA |
1980 | /* If a software watchpoint is not watching any memory, then the |
1981 | above left it without any location set up. But, | |
1982 | bpstat_stop_status requires a location to be able to report | |
1983 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
1984 | if (b->type == bp_watchpoint && b->loc == NULL) |
1985 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
1986 | } |
1987 | else if (!within_current_scope) | |
7270d8f2 | 1988 | { |
ac74f770 MS |
1989 | printf_filtered (_("\ |
1990 | Watchpoint %d deleted because the program has left the block\n\ | |
1991 | in which its expression is valid.\n"), | |
c1fc2657 | 1992 | b->number); |
d0fb5eae | 1993 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1994 | } |
a5606eee VP |
1995 | |
1996 | /* Restore the selected frame. */ | |
66076460 DJ |
1997 | if (frame_saved) |
1998 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1999 | } |
2000 | ||
a5606eee | 2001 | |
74960c60 | 2002 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2003 | inserted in the inferior. We don't differentiate the type of BL's owner |
2004 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2005 | breakpoint_ops is not defined, because in insert_bp_location, | |
2006 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2007 | static int |
35df4500 | 2008 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2009 | { |
35df4500 | 2010 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2011 | return 0; |
2012 | ||
35df4500 | 2013 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2014 | return 0; |
2015 | ||
35df4500 | 2016 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2017 | return 0; |
2018 | ||
f8eba3c6 TT |
2019 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2020 | return 0; | |
2021 | ||
56710373 PA |
2022 | /* This is set for example, when we're attached to the parent of a |
2023 | vfork, and have detached from the child. The child is running | |
2024 | free, and we expect it to do an exec or exit, at which point the | |
2025 | OS makes the parent schedulable again (and the target reports | |
2026 | that the vfork is done). Until the child is done with the shared | |
2027 | memory region, do not insert breakpoints in the parent, otherwise | |
2028 | the child could still trip on the parent's breakpoints. Since | |
2029 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2030 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2031 | return 0; |
2032 | ||
31e77af2 | 2033 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2034 | location, except if the breakpoint is a single-step breakpoint, |
2035 | and the breakpoint's thread is the thread which is stepping past | |
2036 | a breakpoint. */ | |
31e77af2 PA |
2037 | if ((bl->loc_type == bp_loc_software_breakpoint |
2038 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2039 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2040 | bl->address) |
2041 | /* The single-step breakpoint may be inserted at the location | |
2042 | we're trying to step if the instruction branches to itself. | |
2043 | However, the instruction won't be executed at all and it may | |
2044 | break the semantics of the instruction, for example, the | |
2045 | instruction is a conditional branch or updates some flags. | |
2046 | We can't fix it unless GDB is able to emulate the instruction | |
2047 | or switch to displaced stepping. */ | |
2048 | && !(bl->owner->type == bp_single_step | |
2049 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2050 | { |
2051 | if (debug_infrun) | |
2052 | { | |
2053 | fprintf_unfiltered (gdb_stdlog, | |
2054 | "infrun: skipping breakpoint: " | |
2055 | "stepping past insn at: %s\n", | |
2056 | paddress (bl->gdbarch, bl->address)); | |
2057 | } | |
2058 | return 0; | |
2059 | } | |
31e77af2 | 2060 | |
963f9c80 PA |
2061 | /* Don't insert watchpoints if we're trying to step past the |
2062 | instruction that triggered one. */ | |
2063 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2064 | && stepping_past_nonsteppable_watchpoint ()) | |
2065 | { | |
2066 | if (debug_infrun) | |
2067 | { | |
2068 | fprintf_unfiltered (gdb_stdlog, | |
2069 | "infrun: stepping past non-steppable watchpoint. " | |
2070 | "skipping watchpoint at %s:%d\n", | |
2071 | paddress (bl->gdbarch, bl->address), | |
2072 | bl->length); | |
2073 | } | |
2074 | return 0; | |
2075 | } | |
2076 | ||
74960c60 VP |
2077 | return 1; |
2078 | } | |
2079 | ||
934709f0 PW |
2080 | /* Same as should_be_inserted but does the check assuming |
2081 | that the location is not duplicated. */ | |
2082 | ||
2083 | static int | |
2084 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2085 | { | |
2086 | int result; | |
2087 | const int save_duplicate = bl->duplicate; | |
2088 | ||
2089 | bl->duplicate = 0; | |
2090 | result = should_be_inserted (bl); | |
2091 | bl->duplicate = save_duplicate; | |
2092 | return result; | |
2093 | } | |
2094 | ||
b775012e LM |
2095 | /* Parses a conditional described by an expression COND into an |
2096 | agent expression bytecode suitable for evaluation | |
2097 | by the bytecode interpreter. Return NULL if there was | |
2098 | any error during parsing. */ | |
2099 | ||
833177a4 | 2100 | static agent_expr_up |
b775012e LM |
2101 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2102 | { | |
833177a4 | 2103 | if (cond == NULL) |
b775012e LM |
2104 | return NULL; |
2105 | ||
833177a4 PA |
2106 | agent_expr_up aexpr; |
2107 | ||
b775012e LM |
2108 | /* We don't want to stop processing, so catch any errors |
2109 | that may show up. */ | |
492d29ea | 2110 | TRY |
b775012e | 2111 | { |
036e657b | 2112 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2113 | } |
2114 | ||
492d29ea | 2115 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2116 | { |
2117 | /* If we got here, it means the condition could not be parsed to a valid | |
2118 | bytecode expression and thus can't be evaluated on the target's side. | |
2119 | It's no use iterating through the conditions. */ | |
b775012e | 2120 | } |
492d29ea | 2121 | END_CATCH |
b775012e LM |
2122 | |
2123 | /* We have a valid agent expression. */ | |
2124 | return aexpr; | |
2125 | } | |
2126 | ||
2127 | /* Based on location BL, create a list of breakpoint conditions to be | |
2128 | passed on to the target. If we have duplicated locations with different | |
2129 | conditions, we will add such conditions to the list. The idea is that the | |
2130 | target will evaluate the list of conditions and will only notify GDB when | |
2131 | one of them is true. */ | |
2132 | ||
2133 | static void | |
2134 | build_target_condition_list (struct bp_location *bl) | |
2135 | { | |
2136 | struct bp_location **locp = NULL, **loc2p; | |
2137 | int null_condition_or_parse_error = 0; | |
2138 | int modified = bl->needs_update; | |
2139 | struct bp_location *loc; | |
2140 | ||
8b4f3082 | 2141 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2142 | bl->target_info.conditions.clear (); |
8b4f3082 | 2143 | |
b775012e LM |
2144 | /* This is only meaningful if the target is |
2145 | evaluating conditions and if the user has | |
2146 | opted for condition evaluation on the target's | |
2147 | side. */ | |
2148 | if (gdb_evaluates_breakpoint_condition_p () | |
2149 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2150 | return; | |
2151 | ||
2152 | /* Do a first pass to check for locations with no assigned | |
2153 | conditions or conditions that fail to parse to a valid agent expression | |
2154 | bytecode. If any of these happen, then it's no use to send conditions | |
2155 | to the target since this location will always trigger and generate a | |
2156 | response back to GDB. */ | |
2157 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2158 | { | |
2159 | loc = (*loc2p); | |
2160 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2161 | { | |
2162 | if (modified) | |
2163 | { | |
b775012e LM |
2164 | /* Re-parse the conditions since something changed. In that |
2165 | case we already freed the condition bytecodes (see | |
2166 | force_breakpoint_reinsertion). We just | |
2167 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2168 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2169 | loc->cond.get ()); | |
b775012e LM |
2170 | } |
2171 | ||
2172 | /* If we have a NULL bytecode expression, it means something | |
2173 | went wrong or we have a null condition expression. */ | |
2174 | if (!loc->cond_bytecode) | |
2175 | { | |
2176 | null_condition_or_parse_error = 1; | |
2177 | break; | |
2178 | } | |
2179 | } | |
2180 | } | |
2181 | ||
2182 | /* If any of these happened, it means we will have to evaluate the conditions | |
2183 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2184 | for all the other duplicate locations, thus we free all of them here. | |
2185 | ||
2186 | This is so we have a finer control over which locations' conditions are | |
2187 | being evaluated by GDB or the remote stub. */ | |
2188 | if (null_condition_or_parse_error) | |
2189 | { | |
2190 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2191 | { | |
2192 | loc = (*loc2p); | |
2193 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2194 | { | |
2195 | /* Only go as far as the first NULL bytecode is | |
2196 | located. */ | |
2197 | if (!loc->cond_bytecode) | |
2198 | return; | |
2199 | ||
833177a4 | 2200 | loc->cond_bytecode.reset (); |
b775012e LM |
2201 | } |
2202 | } | |
2203 | } | |
2204 | ||
2205 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2206 | for this location's address. */ | |
2207 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2208 | { | |
2209 | loc = (*loc2p); | |
2210 | if (loc->cond | |
2211 | && is_breakpoint (loc->owner) | |
2212 | && loc->pspace->num == bl->pspace->num | |
2213 | && loc->owner->enable_state == bp_enabled | |
2214 | && loc->enabled) | |
3cde5c42 PA |
2215 | { |
2216 | /* Add the condition to the vector. This will be used later | |
2217 | to send the conditions to the target. */ | |
2218 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2219 | } | |
b775012e LM |
2220 | } |
2221 | ||
2222 | return; | |
2223 | } | |
2224 | ||
d3ce09f5 SS |
2225 | /* Parses a command described by string CMD into an agent expression |
2226 | bytecode suitable for evaluation by the bytecode interpreter. | |
2227 | Return NULL if there was any error during parsing. */ | |
2228 | ||
833177a4 | 2229 | static agent_expr_up |
d3ce09f5 SS |
2230 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2231 | { | |
2232 | struct cleanup *old_cleanups = 0; | |
4d01a485 | 2233 | struct expression **argvec; |
bbc13ae3 KS |
2234 | const char *cmdrest; |
2235 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2236 | struct format_piece *fpieces; |
2237 | int nargs; | |
2238 | struct gdbarch *gdbarch = get_current_arch (); | |
2239 | ||
833177a4 | 2240 | if (cmd == NULL) |
d3ce09f5 SS |
2241 | return NULL; |
2242 | ||
2243 | cmdrest = cmd; | |
2244 | ||
2245 | if (*cmdrest == ',') | |
2246 | ++cmdrest; | |
f1735a53 | 2247 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2248 | |
2249 | if (*cmdrest++ != '"') | |
2250 | error (_("No format string following the location")); | |
2251 | ||
2252 | format_start = cmdrest; | |
2253 | ||
2254 | fpieces = parse_format_string (&cmdrest); | |
2255 | ||
2256 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2257 | ||
2258 | format_end = cmdrest; | |
2259 | ||
2260 | if (*cmdrest++ != '"') | |
2261 | error (_("Bad format string, non-terminated '\"'.")); | |
2262 | ||
f1735a53 | 2263 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2264 | |
2265 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2266 | error (_("Invalid argument syntax")); | |
2267 | ||
2268 | if (*cmdrest == ',') | |
2269 | cmdrest++; | |
f1735a53 | 2270 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2271 | |
2272 | /* For each argument, make an expression. */ | |
2273 | ||
2274 | argvec = (struct expression **) alloca (strlen (cmd) | |
2275 | * sizeof (struct expression *)); | |
2276 | ||
2277 | nargs = 0; | |
2278 | while (*cmdrest != '\0') | |
2279 | { | |
bbc13ae3 | 2280 | const char *cmd1; |
d3ce09f5 SS |
2281 | |
2282 | cmd1 = cmdrest; | |
4d01a485 PA |
2283 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
2284 | argvec[nargs++] = expr.release (); | |
d3ce09f5 SS |
2285 | cmdrest = cmd1; |
2286 | if (*cmdrest == ',') | |
2287 | ++cmdrest; | |
2288 | } | |
2289 | ||
833177a4 PA |
2290 | agent_expr_up aexpr; |
2291 | ||
d3ce09f5 SS |
2292 | /* We don't want to stop processing, so catch any errors |
2293 | that may show up. */ | |
492d29ea | 2294 | TRY |
d3ce09f5 | 2295 | { |
036e657b JB |
2296 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2297 | format_start, format_end - format_start, | |
2298 | fpieces, nargs, argvec); | |
d3ce09f5 | 2299 | } |
492d29ea | 2300 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2301 | { |
2302 | /* If we got here, it means the command could not be parsed to a valid | |
2303 | bytecode expression and thus can't be evaluated on the target's side. | |
2304 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2305 | } |
492d29ea PA |
2306 | END_CATCH |
2307 | ||
2308 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2309 | |
d3ce09f5 SS |
2310 | /* We have a valid agent expression, return it. */ |
2311 | return aexpr; | |
2312 | } | |
2313 | ||
2314 | /* Based on location BL, create a list of breakpoint commands to be | |
2315 | passed on to the target. If we have duplicated locations with | |
2316 | different commands, we will add any such to the list. */ | |
2317 | ||
2318 | static void | |
2319 | build_target_command_list (struct bp_location *bl) | |
2320 | { | |
2321 | struct bp_location **locp = NULL, **loc2p; | |
2322 | int null_command_or_parse_error = 0; | |
2323 | int modified = bl->needs_update; | |
2324 | struct bp_location *loc; | |
2325 | ||
3cde5c42 PA |
2326 | /* Clear commands left over from a previous insert. */ |
2327 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2328 | |
41fac0cf | 2329 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2330 | return; |
2331 | ||
41fac0cf PA |
2332 | /* For now, limit to agent-style dprintf breakpoints. */ |
2333 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2334 | return; |
2335 | ||
41fac0cf PA |
2336 | /* For now, if we have any duplicate location that isn't a dprintf, |
2337 | don't install the target-side commands, as that would make the | |
2338 | breakpoint not be reported to the core, and we'd lose | |
2339 | control. */ | |
2340 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2341 | { | |
2342 | loc = (*loc2p); | |
2343 | if (is_breakpoint (loc->owner) | |
2344 | && loc->pspace->num == bl->pspace->num | |
2345 | && loc->owner->type != bp_dprintf) | |
2346 | return; | |
2347 | } | |
2348 | ||
d3ce09f5 SS |
2349 | /* Do a first pass to check for locations with no assigned |
2350 | conditions or conditions that fail to parse to a valid agent expression | |
2351 | bytecode. If any of these happen, then it's no use to send conditions | |
2352 | to the target since this location will always trigger and generate a | |
2353 | response back to GDB. */ | |
2354 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2355 | { | |
2356 | loc = (*loc2p); | |
2357 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2358 | { | |
2359 | if (modified) | |
2360 | { | |
d3ce09f5 SS |
2361 | /* Re-parse the commands since something changed. In that |
2362 | case we already freed the command bytecodes (see | |
2363 | force_breakpoint_reinsertion). We just | |
2364 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2365 | loc->cmd_bytecode |
2366 | = parse_cmd_to_aexpr (bl->address, | |
2367 | loc->owner->extra_string); | |
d3ce09f5 SS |
2368 | } |
2369 | ||
2370 | /* If we have a NULL bytecode expression, it means something | |
2371 | went wrong or we have a null command expression. */ | |
2372 | if (!loc->cmd_bytecode) | |
2373 | { | |
2374 | null_command_or_parse_error = 1; | |
2375 | break; | |
2376 | } | |
2377 | } | |
2378 | } | |
2379 | ||
2380 | /* If anything failed, then we're not doing target-side commands, | |
2381 | and so clean up. */ | |
2382 | if (null_command_or_parse_error) | |
2383 | { | |
2384 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2385 | { | |
2386 | loc = (*loc2p); | |
2387 | if (is_breakpoint (loc->owner) | |
2388 | && loc->pspace->num == bl->pspace->num) | |
2389 | { | |
2390 | /* Only go as far as the first NULL bytecode is | |
2391 | located. */ | |
40fb6c5e | 2392 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2393 | return; |
2394 | ||
833177a4 | 2395 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2396 | } |
2397 | } | |
2398 | } | |
2399 | ||
2400 | /* No NULL commands or failed bytecode generation. Build a command list | |
2401 | for this location's address. */ | |
2402 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2403 | { | |
2404 | loc = (*loc2p); | |
2405 | if (loc->owner->extra_string | |
2406 | && is_breakpoint (loc->owner) | |
2407 | && loc->pspace->num == bl->pspace->num | |
2408 | && loc->owner->enable_state == bp_enabled | |
2409 | && loc->enabled) | |
3cde5c42 PA |
2410 | { |
2411 | /* Add the command to the vector. This will be used later | |
2412 | to send the commands to the target. */ | |
2413 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2414 | } | |
d3ce09f5 SS |
2415 | } |
2416 | ||
2417 | bl->target_info.persist = 0; | |
2418 | /* Maybe flag this location as persistent. */ | |
2419 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2420 | bl->target_info.persist = 1; | |
2421 | } | |
2422 | ||
833b7ab5 YQ |
2423 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2424 | of breakpoint according to ADDR except single-step breakpoint. | |
2425 | Get the kind of single-step breakpoint according to the current | |
2426 | registers state. */ | |
cd6c3b4f YQ |
2427 | |
2428 | static int | |
2429 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2430 | { | |
833b7ab5 YQ |
2431 | if (bl->owner->type == bp_single_step) |
2432 | { | |
2433 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2434 | struct regcache *regcache; | |
2435 | ||
2436 | regcache = get_thread_regcache (thr->ptid); | |
2437 | ||
2438 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2439 | regcache, addr); | |
2440 | } | |
2441 | else | |
2442 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2443 | } |
2444 | ||
35df4500 TJB |
2445 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2446 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2447 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2448 | Returns 0 for success, 1 if the bp_location type is not supported or |
2449 | -1 for failure. | |
879bfdc2 | 2450 | |
4a64f543 MS |
2451 | NOTE drow/2003-09-09: This routine could be broken down to an |
2452 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2453 | static int |
35df4500 | 2454 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2455 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2456 | int *disabled_breaks, |
dd61ec5c MW |
2457 | int *hw_breakpoint_error, |
2458 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2459 | { |
688fca4f | 2460 | gdb_exception bp_excpt = exception_none; |
879bfdc2 | 2461 | |
b775012e | 2462 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2463 | return 0; |
2464 | ||
35c63cd8 JB |
2465 | /* Note we don't initialize bl->target_info, as that wipes out |
2466 | the breakpoint location's shadow_contents if the breakpoint | |
2467 | is still inserted at that location. This in turn breaks | |
2468 | target_read_memory which depends on these buffers when | |
2469 | a memory read is requested at the breakpoint location: | |
2470 | Once the target_info has been wiped, we fail to see that | |
2471 | we have a breakpoint inserted at that address and thus | |
2472 | read the breakpoint instead of returning the data saved in | |
2473 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2474 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2475 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2476 | bl->target_info.length = bl->length; |
8181d85f | 2477 | |
b775012e LM |
2478 | /* When working with target-side conditions, we must pass all the conditions |
2479 | for the same breakpoint address down to the target since GDB will not | |
2480 | insert those locations. With a list of breakpoint conditions, the target | |
2481 | can decide when to stop and notify GDB. */ | |
2482 | ||
2483 | if (is_breakpoint (bl->owner)) | |
2484 | { | |
2485 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2486 | build_target_command_list (bl); |
2487 | /* Reset the modification marker. */ | |
b775012e LM |
2488 | bl->needs_update = 0; |
2489 | } | |
2490 | ||
35df4500 TJB |
2491 | if (bl->loc_type == bp_loc_software_breakpoint |
2492 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2493 | { |
35df4500 | 2494 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2495 | { |
2496 | /* If the explicitly specified breakpoint type | |
2497 | is not hardware breakpoint, check the memory map to see | |
2498 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2499 | |
765dc015 VP |
2500 | Two important cases are: |
2501 | - location type is not hardware breakpoint, memory | |
2502 | is readonly. We change the type of the location to | |
2503 | hardware breakpoint. | |
4a64f543 MS |
2504 | - location type is hardware breakpoint, memory is |
2505 | read-write. This means we've previously made the | |
2506 | location hardware one, but then the memory map changed, | |
2507 | so we undo. | |
765dc015 | 2508 | |
4a64f543 MS |
2509 | When breakpoints are removed, remove_breakpoints will use |
2510 | location types we've just set here, the only possible | |
2511 | problem is that memory map has changed during running | |
2512 | program, but it's not going to work anyway with current | |
2513 | gdb. */ | |
765dc015 | 2514 | struct mem_region *mr |
0d5ed153 | 2515 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2516 | |
2517 | if (mr) | |
2518 | { | |
2519 | if (automatic_hardware_breakpoints) | |
2520 | { | |
765dc015 VP |
2521 | enum bp_loc_type new_type; |
2522 | ||
2523 | if (mr->attrib.mode != MEM_RW) | |
2524 | new_type = bp_loc_hardware_breakpoint; | |
2525 | else | |
2526 | new_type = bp_loc_software_breakpoint; | |
2527 | ||
35df4500 | 2528 | if (new_type != bl->loc_type) |
765dc015 VP |
2529 | { |
2530 | static int said = 0; | |
cc59ec59 | 2531 | |
35df4500 | 2532 | bl->loc_type = new_type; |
765dc015 VP |
2533 | if (!said) |
2534 | { | |
3e43a32a MS |
2535 | fprintf_filtered (gdb_stdout, |
2536 | _("Note: automatically using " | |
2537 | "hardware breakpoints for " | |
2538 | "read-only addresses.\n")); | |
765dc015 VP |
2539 | said = 1; |
2540 | } | |
2541 | } | |
2542 | } | |
35df4500 | 2543 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2544 | && mr->attrib.mode != MEM_RW) |
2545 | { | |
2546 | fprintf_unfiltered (tmp_error_stream, | |
2547 | _("Cannot insert breakpoint %d.\n" | |
2548 | "Cannot set software breakpoint " | |
2549 | "at read-only address %s\n"), | |
2550 | bl->owner->number, | |
2551 | paddress (bl->gdbarch, bl->address)); | |
2552 | return 1; | |
2553 | } | |
765dc015 VP |
2554 | } |
2555 | } | |
2556 | ||
879bfdc2 DJ |
2557 | /* First check to see if we have to handle an overlay. */ |
2558 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2559 | || bl->section == NULL |
2560 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2561 | { |
2562 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2563 | TRY |
dd61ec5c | 2564 | { |
0000e5cc PA |
2565 | int val; |
2566 | ||
dd61ec5c | 2567 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2568 | if (val) |
688fca4f | 2569 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2570 | } |
492d29ea | 2571 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2572 | { |
688fca4f | 2573 | bp_excpt = e; |
dd61ec5c | 2574 | } |
492d29ea | 2575 | END_CATCH |
879bfdc2 DJ |
2576 | } |
2577 | else | |
2578 | { | |
4a64f543 | 2579 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2580 | Shall we set a breakpoint at the LMA? */ |
2581 | if (!overlay_events_enabled) | |
2582 | { | |
2583 | /* Yes -- overlay event support is not active, | |
2584 | so we must try to set a breakpoint at the LMA. | |
2585 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2586 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2587 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2588 | bl->owner->number); |
879bfdc2 DJ |
2589 | else |
2590 | { | |
35df4500 TJB |
2591 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2592 | bl->section); | |
879bfdc2 | 2593 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2594 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2595 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2596 | |
2597 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2598 | TRY |
0000e5cc PA |
2599 | { |
2600 | int val; | |
2601 | ||
579c6ad9 | 2602 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2603 | = breakpoint_kind (bl, &addr); |
2604 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2605 | val = target_insert_breakpoint (bl->gdbarch, |
2606 | &bl->overlay_target_info); | |
2607 | if (val) | |
688fca4f PA |
2608 | bp_excpt |
2609 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2610 | } |
492d29ea | 2611 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc | 2612 | { |
688fca4f | 2613 | bp_excpt = e; |
0000e5cc | 2614 | } |
492d29ea | 2615 | END_CATCH |
0000e5cc | 2616 | |
688fca4f | 2617 | if (bp_excpt.reason != 0) |
99361f52 | 2618 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2619 | "Overlay breakpoint %d " |
2620 | "failed: in ROM?\n", | |
35df4500 | 2621 | bl->owner->number); |
879bfdc2 DJ |
2622 | } |
2623 | } | |
2624 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2625 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2626 | { |
2627 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2628 | TRY |
dd61ec5c | 2629 | { |
0000e5cc PA |
2630 | int val; |
2631 | ||
dd61ec5c | 2632 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2633 | if (val) |
688fca4f | 2634 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2635 | } |
492d29ea | 2636 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2637 | { |
688fca4f | 2638 | bp_excpt = e; |
dd61ec5c | 2639 | } |
492d29ea | 2640 | END_CATCH |
879bfdc2 DJ |
2641 | } |
2642 | else | |
2643 | { | |
2644 | /* No. This breakpoint will not be inserted. | |
2645 | No error, but do not mark the bp as 'inserted'. */ | |
2646 | return 0; | |
2647 | } | |
2648 | } | |
2649 | ||
688fca4f | 2650 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2651 | { |
2652 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2653 | |
2654 | /* In some cases, we might not be able to insert a | |
2655 | breakpoint in a shared library that has already been | |
2656 | removed, but we have not yet processed the shlib unload | |
2657 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2658 | breakpoint insertion themselves can't tell why the |
2659 | breakpoint insertion failed (e.g., the remote target | |
2660 | doesn't define error codes), so we must treat generic | |
2661 | errors as memory errors. */ | |
688fca4f PA |
2662 | if (bp_excpt.reason == RETURN_ERROR |
2663 | && (bp_excpt.error == GENERIC_ERROR | |
2664 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2665 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2666 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2667 | || shared_objfile_contains_address_p (bl->pspace, |
2668 | bl->address))) | |
879bfdc2 | 2669 | { |
4a64f543 | 2670 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2671 | bl->shlib_disabled = 1; |
8d3788bd | 2672 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2673 | if (!*disabled_breaks) |
2674 | { | |
2675 | fprintf_unfiltered (tmp_error_stream, | |
2676 | "Cannot insert breakpoint %d.\n", | |
2677 | bl->owner->number); | |
2678 | fprintf_unfiltered (tmp_error_stream, | |
2679 | "Temporarily disabling shared " | |
2680 | "library breakpoints:\n"); | |
2681 | } | |
2682 | *disabled_breaks = 1; | |
879bfdc2 | 2683 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2684 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2685 | return 0; |
879bfdc2 DJ |
2686 | } |
2687 | else | |
879bfdc2 | 2688 | { |
35df4500 | 2689 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2690 | { |
0000e5cc | 2691 | *hw_breakpoint_error = 1; |
688fca4f | 2692 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
dd61ec5c MW |
2693 | fprintf_unfiltered (tmp_error_stream, |
2694 | "Cannot insert hardware breakpoint %d%s", | |
688fca4f PA |
2695 | bl->owner->number, |
2696 | bp_excpt.message ? ":" : ".\n"); | |
2697 | if (bp_excpt.message != NULL) | |
2698 | fprintf_unfiltered (tmp_error_stream, "%s.\n", | |
2699 | bp_excpt.message); | |
879bfdc2 DJ |
2700 | } |
2701 | else | |
2702 | { | |
688fca4f | 2703 | if (bp_excpt.message == NULL) |
0000e5cc | 2704 | { |
1ccbe998 | 2705 | std::string message |
0000e5cc PA |
2706 | = memory_error_message (TARGET_XFER_E_IO, |
2707 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2708 | |
2709 | fprintf_unfiltered (tmp_error_stream, | |
2710 | "Cannot insert breakpoint %d.\n" | |
2711 | "%s\n", | |
1ccbe998 | 2712 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2713 | } |
2714 | else | |
2715 | { | |
2716 | fprintf_unfiltered (tmp_error_stream, | |
2717 | "Cannot insert breakpoint %d: %s\n", | |
2718 | bl->owner->number, | |
688fca4f | 2719 | bp_excpt.message); |
0000e5cc | 2720 | } |
879bfdc2 | 2721 | } |
0000e5cc | 2722 | return 1; |
879bfdc2 DJ |
2723 | |
2724 | } | |
2725 | } | |
2726 | else | |
35df4500 | 2727 | bl->inserted = 1; |
879bfdc2 | 2728 | |
0000e5cc | 2729 | return 0; |
879bfdc2 DJ |
2730 | } |
2731 | ||
35df4500 | 2732 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2733 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2734 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2735 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2736 | { |
0000e5cc PA |
2737 | int val; |
2738 | ||
77b06cd7 TJB |
2739 | gdb_assert (bl->owner->ops != NULL |
2740 | && bl->owner->ops->insert_location != NULL); | |
2741 | ||
2742 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2743 | |
2744 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2745 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2746 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2747 | { |
2748 | struct bp_location *loc, **loc_temp; | |
2749 | ||
2750 | /* But don't try to insert it, if there's already another | |
2751 | hw_access location that would be considered a duplicate | |
2752 | of this one. */ | |
2753 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2754 | if (loc != bl |
85d721b8 | 2755 | && loc->watchpoint_type == hw_access |
35df4500 | 2756 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2757 | { |
35df4500 TJB |
2758 | bl->duplicate = 1; |
2759 | bl->inserted = 1; | |
2760 | bl->target_info = loc->target_info; | |
2761 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2762 | val = 0; |
2763 | break; | |
2764 | } | |
2765 | ||
2766 | if (val == 1) | |
2767 | { | |
77b06cd7 TJB |
2768 | bl->watchpoint_type = hw_access; |
2769 | val = bl->owner->ops->insert_location (bl); | |
2770 | ||
2771 | if (val) | |
2772 | /* Back to the original value. */ | |
2773 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2774 | } |
2775 | } | |
2776 | ||
35df4500 | 2777 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2778 | } |
2779 | ||
35df4500 | 2780 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2781 | { |
0000e5cc PA |
2782 | int val; |
2783 | ||
77b06cd7 TJB |
2784 | gdb_assert (bl->owner->ops != NULL |
2785 | && bl->owner->ops->insert_location != NULL); | |
2786 | ||
2787 | val = bl->owner->ops->insert_location (bl); | |
2788 | if (val) | |
2789 | { | |
2790 | bl->owner->enable_state = bp_disabled; | |
2791 | ||
2792 | if (val == 1) | |
2793 | warning (_("\ | |
2794 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2795 | of catchpoint."), bl->owner->number); | |
2796 | else | |
2797 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2798 | } | |
2799 | ||
2800 | bl->inserted = (val == 0); | |
1640b821 DJ |
2801 | |
2802 | /* We've already printed an error message if there was a problem | |
2803 | inserting this catchpoint, and we've disabled the catchpoint, | |
2804 | so just return success. */ | |
2805 | return 0; | |
879bfdc2 DJ |
2806 | } |
2807 | ||
2808 | return 0; | |
2809 | } | |
2810 | ||
6c95b8df PA |
2811 | /* This function is called when program space PSPACE is about to be |
2812 | deleted. It takes care of updating breakpoints to not reference | |
2813 | PSPACE anymore. */ | |
2814 | ||
2815 | void | |
2816 | breakpoint_program_space_exit (struct program_space *pspace) | |
2817 | { | |
2818 | struct breakpoint *b, *b_temp; | |
876fa593 | 2819 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2820 | |
2821 | /* Remove any breakpoint that was set through this program space. */ | |
2822 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2823 | { | |
2824 | if (b->pspace == pspace) | |
2825 | delete_breakpoint (b); | |
2826 | } | |
2827 | ||
2828 | /* Breakpoints set through other program spaces could have locations | |
2829 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2830 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2831 | { |
2832 | struct bp_location *tmp; | |
2833 | ||
2834 | if (loc->pspace == pspace) | |
2835 | { | |
2bdf28a0 | 2836 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2837 | if (loc->owner->loc == loc) |
2838 | loc->owner->loc = loc->next; | |
2839 | else | |
2840 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2841 | if (tmp->next == loc) | |
2842 | { | |
2843 | tmp->next = loc->next; | |
2844 | break; | |
2845 | } | |
2846 | } | |
2847 | } | |
2848 | ||
2849 | /* Now update the global location list to permanently delete the | |
2850 | removed locations above. */ | |
44702360 | 2851 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2852 | } |
2853 | ||
74960c60 VP |
2854 | /* Make sure all breakpoints are inserted in inferior. |
2855 | Throws exception on any error. | |
2856 | A breakpoint that is already inserted won't be inserted | |
2857 | again, so calling this function twice is safe. */ | |
2858 | void | |
2859 | insert_breakpoints (void) | |
2860 | { | |
2861 | struct breakpoint *bpt; | |
2862 | ||
2863 | ALL_BREAKPOINTS (bpt) | |
2864 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2865 | { |
2866 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2867 | ||
2868 | update_watchpoint (w, 0 /* don't reparse. */); | |
2869 | } | |
74960c60 | 2870 | |
04086b45 PA |
2871 | /* Updating watchpoints creates new locations, so update the global |
2872 | location list. Explicitly tell ugll to insert locations and | |
2873 | ignore breakpoints_always_inserted_mode. */ | |
2874 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
2875 | } |
2876 | ||
20388dd6 YQ |
2877 | /* Invoke CALLBACK for each of bp_location. */ |
2878 | ||
2879 | void | |
2880 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2881 | { | |
2882 | struct bp_location *loc, **loc_tmp; | |
2883 | ||
2884 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2885 | { | |
2886 | callback (loc, NULL); | |
2887 | } | |
2888 | } | |
2889 | ||
b775012e LM |
2890 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2891 | target. It is the case with deleting and disabling of breakpoints when using | |
2892 | always-inserted mode. */ | |
2893 | ||
2894 | static void | |
2895 | update_inserted_breakpoint_locations (void) | |
2896 | { | |
2897 | struct bp_location *bl, **blp_tmp; | |
2898 | int error_flag = 0; | |
2899 | int val = 0; | |
2900 | int disabled_breaks = 0; | |
2901 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2902 | int hw_bp_details_reported = 0; |
b775012e | 2903 | |
d7e74731 | 2904 | string_file tmp_error_stream; |
b775012e LM |
2905 | |
2906 | /* Explicitly mark the warning -- this will only be printed if | |
2907 | there was an error. */ | |
d7e74731 | 2908 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2909 | |
5ed8105e | 2910 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2911 | |
2912 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2913 | { | |
2914 | /* We only want to update software breakpoints and hardware | |
2915 | breakpoints. */ | |
2916 | if (!is_breakpoint (bl->owner)) | |
2917 | continue; | |
2918 | ||
2919 | /* We only want to update locations that are already inserted | |
2920 | and need updating. This is to avoid unwanted insertion during | |
2921 | deletion of breakpoints. */ | |
2922 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2923 | continue; | |
2924 | ||
2925 | switch_to_program_space_and_thread (bl->pspace); | |
2926 | ||
2927 | /* For targets that support global breakpoints, there's no need | |
2928 | to select an inferior to insert breakpoint to. In fact, even | |
2929 | if we aren't attached to any process yet, we should still | |
2930 | insert breakpoints. */ | |
f5656ead | 2931 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2932 | && ptid_equal (inferior_ptid, null_ptid)) |
2933 | continue; | |
2934 | ||
d7e74731 | 2935 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2936 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2937 | if (val) |
2938 | error_flag = val; | |
2939 | } | |
2940 | ||
2941 | if (error_flag) | |
2942 | { | |
223ffa71 | 2943 | target_terminal::ours_for_output (); |
b775012e LM |
2944 | error_stream (tmp_error_stream); |
2945 | } | |
b775012e LM |
2946 | } |
2947 | ||
c30eee59 | 2948 | /* Used when starting or continuing the program. */ |
c906108c | 2949 | |
74960c60 VP |
2950 | static void |
2951 | insert_breakpoint_locations (void) | |
c906108c | 2952 | { |
a5606eee | 2953 | struct breakpoint *bpt; |
35df4500 | 2954 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2955 | int error_flag = 0; |
c906108c | 2956 | int val = 0; |
3fbb6ffa | 2957 | int disabled_breaks = 0; |
81d0cc19 | 2958 | int hw_breakpoint_error = 0; |
dd61ec5c | 2959 | int hw_bp_error_explained_already = 0; |
c906108c | 2960 | |
d7e74731 PA |
2961 | string_file tmp_error_stream; |
2962 | ||
81d0cc19 GS |
2963 | /* Explicitly mark the warning -- this will only be printed if |
2964 | there was an error. */ | |
d7e74731 | 2965 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 2966 | |
5ed8105e | 2967 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 2968 | |
35df4500 | 2969 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2970 | { |
b775012e | 2971 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2972 | continue; |
2973 | ||
4a64f543 MS |
2974 | /* There is no point inserting thread-specific breakpoints if |
2975 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2976 | has BL->OWNER always non-NULL. */ | |
35df4500 | 2977 | if (bl->owner->thread != -1 |
5d5658a1 | 2978 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
2979 | continue; |
2980 | ||
35df4500 | 2981 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2982 | |
2983 | /* For targets that support global breakpoints, there's no need | |
2984 | to select an inferior to insert breakpoint to. In fact, even | |
2985 | if we aren't attached to any process yet, we should still | |
2986 | insert breakpoints. */ | |
f5656ead | 2987 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
2988 | && ptid_equal (inferior_ptid, null_ptid)) |
2989 | continue; | |
2990 | ||
d7e74731 | 2991 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2992 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2993 | if (val) |
eacd795a | 2994 | error_flag = val; |
879bfdc2 | 2995 | } |
c906108c | 2996 | |
4a64f543 MS |
2997 | /* If we failed to insert all locations of a watchpoint, remove |
2998 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2999 | ALL_BREAKPOINTS (bpt) |
3000 | { | |
3001 | int some_failed = 0; | |
3002 | struct bp_location *loc; | |
3003 | ||
3004 | if (!is_hardware_watchpoint (bpt)) | |
3005 | continue; | |
3006 | ||
d6b74ac4 | 3007 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3008 | continue; |
74960c60 VP |
3009 | |
3010 | if (bpt->disposition == disp_del_at_next_stop) | |
3011 | continue; | |
a5606eee VP |
3012 | |
3013 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3014 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3015 | { |
3016 | some_failed = 1; | |
3017 | break; | |
3018 | } | |
3019 | if (some_failed) | |
3020 | { | |
3021 | for (loc = bpt->loc; loc; loc = loc->next) | |
3022 | if (loc->inserted) | |
834c0d03 | 3023 | remove_breakpoint (loc); |
a5606eee VP |
3024 | |
3025 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3026 | tmp_error_stream.printf ("Could not insert " |
3027 | "hardware watchpoint %d.\n", | |
3028 | bpt->number); | |
eacd795a | 3029 | error_flag = -1; |
a5606eee VP |
3030 | } |
3031 | } | |
3032 | ||
eacd795a | 3033 | if (error_flag) |
81d0cc19 GS |
3034 | { |
3035 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3036 | message about possibly exhausted resources. */ | |
dd61ec5c | 3037 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3038 | { |
d7e74731 | 3039 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3040 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3041 | } |
223ffa71 | 3042 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3043 | error_stream (tmp_error_stream); |
3044 | } | |
c906108c SS |
3045 | } |
3046 | ||
c30eee59 TJB |
3047 | /* Used when the program stops. |
3048 | Returns zero if successful, or non-zero if there was a problem | |
3049 | removing a breakpoint location. */ | |
3050 | ||
c906108c | 3051 | int |
fba45db2 | 3052 | remove_breakpoints (void) |
c906108c | 3053 | { |
35df4500 | 3054 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3055 | int val = 0; |
c906108c | 3056 | |
35df4500 | 3057 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3058 | { |
1e4d1764 | 3059 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3060 | val |= remove_breakpoint (bl); |
c5aa993b | 3061 | } |
3a1bae8e | 3062 | return val; |
c906108c SS |
3063 | } |
3064 | ||
49fa26b0 PA |
3065 | /* When a thread exits, remove breakpoints that are related to |
3066 | that thread. */ | |
3067 | ||
3068 | static void | |
3069 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3070 | { | |
3071 | struct breakpoint *b, *b_tmp; | |
3072 | ||
3073 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3074 | { | |
5d5658a1 | 3075 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3076 | { |
3077 | b->disposition = disp_del_at_next_stop; | |
3078 | ||
3079 | printf_filtered (_("\ | |
43792cf0 PA |
3080 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3081 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3082 | |
3083 | /* Hide it from the user. */ | |
3084 | b->number = 0; | |
3085 | } | |
3086 | } | |
3087 | } | |
3088 | ||
6c95b8df PA |
3089 | /* Remove breakpoints of process PID. */ |
3090 | ||
3091 | int | |
3092 | remove_breakpoints_pid (int pid) | |
3093 | { | |
35df4500 | 3094 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3095 | int val; |
3096 | struct inferior *inf = find_inferior_pid (pid); | |
3097 | ||
35df4500 | 3098 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3099 | { |
35df4500 | 3100 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3101 | continue; |
3102 | ||
fc126975 | 3103 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3104 | { |
834c0d03 | 3105 | val = remove_breakpoint (bl); |
6c95b8df PA |
3106 | if (val != 0) |
3107 | return val; | |
3108 | } | |
3109 | } | |
3110 | return 0; | |
3111 | } | |
3112 | ||
e58b0e63 PA |
3113 | static int internal_breakpoint_number = -1; |
3114 | ||
84f4c1fe PM |
3115 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3116 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3117 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3118 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3119 | breakpoint_count and that value incremented. Internal breakpoints |
3120 | do not set the internal var bpnum. */ | |
3121 | static void | |
3122 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3123 | { | |
3124 | if (internal) | |
3125 | b->number = internal_breakpoint_number--; | |
3126 | else | |
3127 | { | |
3128 | set_breakpoint_count (breakpoint_count + 1); | |
3129 | b->number = breakpoint_count; | |
3130 | } | |
3131 | } | |
3132 | ||
e62c965a | 3133 | static struct breakpoint * |
a6d9a66e | 3134 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3135 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3136 | const struct breakpoint_ops *ops) |
e62c965a | 3137 | { |
51abb421 | 3138 | symtab_and_line sal; |
e62c965a PP |
3139 | sal.pc = address; |
3140 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3141 | sal.pspace = current_program_space; |
e62c965a | 3142 | |
51abb421 | 3143 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3144 | b->number = internal_breakpoint_number--; |
3145 | b->disposition = disp_donttouch; | |
3146 | ||
3147 | return b; | |
3148 | } | |
3149 | ||
17450429 PP |
3150 | static const char *const longjmp_names[] = |
3151 | { | |
3152 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3153 | }; | |
3154 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3155 | ||
3156 | /* Per-objfile data private to breakpoint.c. */ | |
3157 | struct breakpoint_objfile_data | |
3158 | { | |
3159 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
43dce439 | 3160 | struct bound_minimal_symbol overlay_msym {}; |
17450429 PP |
3161 | |
3162 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
43dce439 | 3163 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
17450429 | 3164 | |
28106bc2 | 3165 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3166 | int longjmp_searched = 0; |
28106bc2 | 3167 | |
45461e0d SM |
3168 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3169 | references. */ | |
3170 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3171 | |
17450429 | 3172 | /* Minimal symbol for "std::terminate()" (if any). */ |
43dce439 | 3173 | struct bound_minimal_symbol terminate_msym {}; |
17450429 PP |
3174 | |
3175 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
43dce439 | 3176 | struct bound_minimal_symbol exception_msym {}; |
28106bc2 SDJ |
3177 | |
3178 | /* True if we have looked for exception probes. */ | |
43dce439 | 3179 | int exception_searched = 0; |
28106bc2 | 3180 | |
45461e0d SM |
3181 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3182 | references. */ | |
3183 | std::vector<probe *> exception_probes; | |
17450429 PP |
3184 | }; |
3185 | ||
3186 | static const struct objfile_data *breakpoint_objfile_key; | |
3187 | ||
3188 | /* Minimal symbol not found sentinel. */ | |
3189 | static struct minimal_symbol msym_not_found; | |
3190 | ||
3191 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3192 | ||
3193 | static int | |
3194 | msym_not_found_p (const struct minimal_symbol *msym) | |
3195 | { | |
3196 | return msym == &msym_not_found; | |
3197 | } | |
3198 | ||
3199 | /* Return per-objfile data needed by breakpoint.c. | |
3200 | Allocate the data if necessary. */ | |
3201 | ||
3202 | static struct breakpoint_objfile_data * | |
3203 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3204 | { | |
3205 | struct breakpoint_objfile_data *bp_objfile_data; | |
3206 | ||
9a3c8263 SM |
3207 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3208 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3209 | if (bp_objfile_data == NULL) |
3210 | { | |
43dce439 | 3211 | bp_objfile_data = new breakpoint_objfile_data (); |
17450429 PP |
3212 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); |
3213 | } | |
3214 | return bp_objfile_data; | |
3215 | } | |
3216 | ||
28106bc2 | 3217 | static void |
43dce439 | 3218 | free_breakpoint_objfile_data (struct objfile *obj, void *data) |
28106bc2 | 3219 | { |
9a3c8263 SM |
3220 | struct breakpoint_objfile_data *bp_objfile_data |
3221 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 | 3222 | |
43dce439 | 3223 | delete bp_objfile_data; |
28106bc2 SDJ |
3224 | } |
3225 | ||
e62c965a | 3226 | static void |
af02033e | 3227 | create_overlay_event_breakpoint (void) |
e62c965a | 3228 | { |
69de3c6a | 3229 | struct objfile *objfile; |
af02033e | 3230 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3231 | |
69de3c6a PP |
3232 | ALL_OBJFILES (objfile) |
3233 | { | |
3234 | struct breakpoint *b; | |
17450429 PP |
3235 | struct breakpoint_objfile_data *bp_objfile_data; |
3236 | CORE_ADDR addr; | |
67994074 | 3237 | struct explicit_location explicit_loc; |
69de3c6a | 3238 | |
17450429 PP |
3239 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3240 | ||
3b7344d5 | 3241 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3242 | continue; |
3243 | ||
3b7344d5 | 3244 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3245 | { |
3b7344d5 | 3246 | struct bound_minimal_symbol m; |
17450429 PP |
3247 | |
3248 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3249 | if (m.minsym == NULL) |
17450429 PP |
3250 | { |
3251 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3252 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3253 | continue; |
3254 | } | |
3255 | bp_objfile_data->overlay_msym = m; | |
3256 | } | |
e62c965a | 3257 | |
77e371c0 | 3258 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3259 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3260 | bp_overlay_event, |
3261 | &internal_breakpoint_ops); | |
67994074 KS |
3262 | initialize_explicit_location (&explicit_loc); |
3263 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3264 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3265 | |
69de3c6a PP |
3266 | if (overlay_debugging == ovly_auto) |
3267 | { | |
3268 | b->enable_state = bp_enabled; | |
3269 | overlay_events_enabled = 1; | |
3270 | } | |
3271 | else | |
3272 | { | |
3273 | b->enable_state = bp_disabled; | |
3274 | overlay_events_enabled = 0; | |
3275 | } | |
e62c965a | 3276 | } |
e62c965a PP |
3277 | } |
3278 | ||
0fd8e87f | 3279 | static void |
af02033e | 3280 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3281 | { |
6c95b8df | 3282 | struct program_space *pspace; |
6c95b8df | 3283 | |
5ed8105e | 3284 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3285 | |
6c95b8df | 3286 | ALL_PSPACES (pspace) |
af02033e PP |
3287 | { |
3288 | struct objfile *objfile; | |
3289 | ||
3290 | set_current_program_space (pspace); | |
3291 | ||
3292 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3293 | { |
af02033e PP |
3294 | int i; |
3295 | struct gdbarch *gdbarch; | |
17450429 | 3296 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3297 | |
af02033e | 3298 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3299 | |
17450429 PP |
3300 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3301 | ||
28106bc2 SDJ |
3302 | if (!bp_objfile_data->longjmp_searched) |
3303 | { | |
45461e0d SM |
3304 | std::vector<probe *> ret |
3305 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
25f9533e | 3306 | |
45461e0d | 3307 | if (!ret.empty ()) |
25f9533e SDJ |
3308 | { |
3309 | /* We are only interested in checking one element. */ | |
45461e0d | 3310 | probe *p = ret[0]; |
25f9533e | 3311 | |
935676c9 | 3312 | if (!p->can_evaluate_arguments ()) |
25f9533e SDJ |
3313 | { |
3314 | /* We cannot use the probe interface here, because it does | |
3315 | not know how to evaluate arguments. */ | |
45461e0d | 3316 | ret.clear (); |
25f9533e SDJ |
3317 | } |
3318 | } | |
3319 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3320 | bp_objfile_data->longjmp_searched = 1; |
3321 | } | |
3322 | ||
45461e0d | 3323 | if (!bp_objfile_data->longjmp_probes.empty ()) |
28106bc2 | 3324 | { |
28106bc2 SDJ |
3325 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
3326 | ||
45461e0d | 3327 | for (probe *p : bp_objfile_data->longjmp_probes) |
28106bc2 SDJ |
3328 | { |
3329 | struct breakpoint *b; | |
3330 | ||
729662a5 | 3331 | b = create_internal_breakpoint (gdbarch, |
935676c9 | 3332 | p->get_relocated_address (objfile), |
28106bc2 SDJ |
3333 | bp_longjmp_master, |
3334 | &internal_breakpoint_ops); | |
d28cd78a | 3335 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
28106bc2 SDJ |
3336 | b->enable_state = bp_disabled; |
3337 | } | |
3338 | ||
3339 | continue; | |
3340 | } | |
3341 | ||
0569175e TSD |
3342 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3343 | continue; | |
3344 | ||
17450429 | 3345 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3346 | { |
3347 | struct breakpoint *b; | |
af02033e | 3348 | const char *func_name; |
17450429 | 3349 | CORE_ADDR addr; |
67994074 | 3350 | struct explicit_location explicit_loc; |
6c95b8df | 3351 | |
3b7344d5 | 3352 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3353 | continue; |
0fd8e87f | 3354 | |
17450429 | 3355 | func_name = longjmp_names[i]; |
3b7344d5 | 3356 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3357 | { |
3b7344d5 | 3358 | struct bound_minimal_symbol m; |
17450429 PP |
3359 | |
3360 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3361 | if (m.minsym == NULL) |
17450429 PP |
3362 | { |
3363 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3364 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3365 | continue; |
3366 | } | |
3367 | bp_objfile_data->longjmp_msym[i] = m; | |
3368 | } | |
3369 | ||
77e371c0 | 3370 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3371 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3372 | &internal_breakpoint_ops); | |
67994074 KS |
3373 | initialize_explicit_location (&explicit_loc); |
3374 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3375 | b->location = new_explicit_location (&explicit_loc); |
af02033e PP |
3376 | b->enable_state = bp_disabled; |
3377 | } | |
0fd8e87f | 3378 | } |
af02033e | 3379 | } |
0fd8e87f UW |
3380 | } |
3381 | ||
af02033e | 3382 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3383 | static void |
af02033e | 3384 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3385 | { |
3386 | struct program_space *pspace; | |
af02033e | 3387 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3388 | |
5ed8105e | 3389 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3390 | |
3391 | ALL_PSPACES (pspace) | |
17450429 PP |
3392 | { |
3393 | struct objfile *objfile; | |
3394 | CORE_ADDR addr; | |
3395 | ||
3396 | set_current_program_space (pspace); | |
3397 | ||
aa7d318d TT |
3398 | ALL_OBJFILES (objfile) |
3399 | { | |
3400 | struct breakpoint *b; | |
17450429 | 3401 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3402 | struct explicit_location explicit_loc; |
aa7d318d | 3403 | |
17450429 | 3404 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3405 | |
3b7344d5 | 3406 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3407 | continue; |
3408 | ||
3b7344d5 | 3409 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3410 | { |
3b7344d5 | 3411 | struct bound_minimal_symbol m; |
17450429 PP |
3412 | |
3413 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3414 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3415 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3416 | { |
3417 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3418 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3419 | continue; |
3420 | } | |
3421 | bp_objfile_data->terminate_msym = m; | |
3422 | } | |
aa7d318d | 3423 | |
77e371c0 | 3424 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3425 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3426 | bp_std_terminate_master, |
3427 | &internal_breakpoint_ops); | |
67994074 KS |
3428 | initialize_explicit_location (&explicit_loc); |
3429 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3430 | b->location = new_explicit_location (&explicit_loc); |
aa7d318d TT |
3431 | b->enable_state = bp_disabled; |
3432 | } | |
17450429 | 3433 | } |
aa7d318d TT |
3434 | } |
3435 | ||
186c406b TT |
3436 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3437 | ||
70221824 | 3438 | static void |
186c406b TT |
3439 | create_exception_master_breakpoint (void) |
3440 | { | |
3441 | struct objfile *objfile; | |
17450429 | 3442 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3443 | |
3444 | ALL_OBJFILES (objfile) | |
3445 | { | |
17450429 PP |
3446 | struct breakpoint *b; |
3447 | struct gdbarch *gdbarch; | |
3448 | struct breakpoint_objfile_data *bp_objfile_data; | |
3449 | CORE_ADDR addr; | |
67994074 | 3450 | struct explicit_location explicit_loc; |
17450429 PP |
3451 | |
3452 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3453 | ||
28106bc2 SDJ |
3454 | /* We prefer the SystemTap probe point if it exists. */ |
3455 | if (!bp_objfile_data->exception_searched) | |
3456 | { | |
45461e0d SM |
3457 | std::vector<probe *> ret |
3458 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
25f9533e | 3459 | |
45461e0d | 3460 | if (!ret.empty ()) |
25f9533e SDJ |
3461 | { |
3462 | /* We are only interested in checking one element. */ | |
45461e0d | 3463 | probe *p = ret[0]; |
25f9533e | 3464 | |
935676c9 | 3465 | if (!p->can_evaluate_arguments ()) |
25f9533e SDJ |
3466 | { |
3467 | /* We cannot use the probe interface here, because it does | |
3468 | not know how to evaluate arguments. */ | |
45461e0d | 3469 | ret.clear (); |
25f9533e SDJ |
3470 | } |
3471 | } | |
3472 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3473 | bp_objfile_data->exception_searched = 1; |
3474 | } | |
3475 | ||
45461e0d | 3476 | if (!bp_objfile_data->exception_probes.empty ()) |
28106bc2 SDJ |
3477 | { |
3478 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
45461e0d SM |
3479 | |
3480 | for (probe *p : bp_objfile_data->exception_probes) | |
28106bc2 SDJ |
3481 | { |
3482 | struct breakpoint *b; | |
3483 | ||
729662a5 | 3484 | b = create_internal_breakpoint (gdbarch, |
935676c9 | 3485 | p->get_relocated_address (objfile), |
28106bc2 SDJ |
3486 | bp_exception_master, |
3487 | &internal_breakpoint_ops); | |
d28cd78a | 3488 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3489 | b->enable_state = bp_disabled; |
3490 | } | |
3491 | ||
3492 | continue; | |
3493 | } | |
3494 | ||
3495 | /* Otherwise, try the hook function. */ | |
3496 | ||
3b7344d5 | 3497 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3498 | continue; |
3499 | ||
3500 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3501 | |
3b7344d5 | 3502 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3503 | { |
3b7344d5 | 3504 | struct bound_minimal_symbol debug_hook; |
186c406b | 3505 | |
17450429 | 3506 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3507 | if (debug_hook.minsym == NULL) |
17450429 | 3508 | { |
3b7344d5 | 3509 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3510 | continue; |
3511 | } | |
3512 | ||
3513 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3514 | } |
17450429 | 3515 | |
77e371c0 | 3516 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3517 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3518 | ¤t_target); | |
06edf0c0 PA |
3519 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3520 | &internal_breakpoint_ops); | |
67994074 KS |
3521 | initialize_explicit_location (&explicit_loc); |
3522 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3523 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3524 | b->enable_state = bp_disabled; |
186c406b | 3525 | } |
186c406b TT |
3526 | } |
3527 | ||
9ef9e6a6 KS |
3528 | /* Does B have a location spec? */ |
3529 | ||
3530 | static int | |
3531 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3532 | { | |
d28cd78a | 3533 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3534 | } |
3535 | ||
c906108c | 3536 | void |
fba45db2 | 3537 | update_breakpoints_after_exec (void) |
c906108c | 3538 | { |
35df4500 | 3539 | struct breakpoint *b, *b_tmp; |
876fa593 | 3540 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3541 | |
25b22b0a PA |
3542 | /* We're about to delete breakpoints from GDB's lists. If the |
3543 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3544 | writing the breakpoints' "shadow contents" back into memory. The | |
3545 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3546 | do that. Instead, the target is responsible from marking | |
3547 | breakpoints out as soon as it detects an exec. We don't do that | |
3548 | here instead, because there may be other attempts to delete | |
3549 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3550 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3551 | if (bploc->pspace == current_program_space) |
3552 | gdb_assert (!bploc->inserted); | |
c906108c | 3553 | |
35df4500 | 3554 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3555 | { |
6c95b8df PA |
3556 | if (b->pspace != current_program_space) |
3557 | continue; | |
3558 | ||
4a64f543 | 3559 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3560 | if (b->type == bp_shlib_event) |
3561 | { | |
3562 | delete_breakpoint (b); | |
3563 | continue; | |
3564 | } | |
c906108c | 3565 | |
4a64f543 | 3566 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3567 | if (b->type == bp_jit_event) |
3568 | { | |
3569 | delete_breakpoint (b); | |
3570 | continue; | |
3571 | } | |
3572 | ||
1900040c | 3573 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3574 | as must overlay event and longjmp master breakpoints. */ |
3575 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3576 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3577 | || b->type == bp_exception_master) | |
c4093a6a JM |
3578 | { |
3579 | delete_breakpoint (b); | |
3580 | continue; | |
3581 | } | |
3582 | ||
4a64f543 | 3583 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3584 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3585 | { |
3586 | delete_breakpoint (b); | |
3587 | continue; | |
3588 | } | |
3589 | ||
7c16b83e PA |
3590 | /* Just like single-step breakpoints. */ |
3591 | if (b->type == bp_single_step) | |
3592 | { | |
3593 | delete_breakpoint (b); | |
3594 | continue; | |
3595 | } | |
3596 | ||
611c83ae PA |
3597 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3598 | after an exec. */ | |
186c406b | 3599 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3600 | || b->type == bp_longjmp_call_dummy |
186c406b | 3601 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3602 | { |
3603 | delete_breakpoint (b); | |
3604 | continue; | |
3605 | } | |
3606 | ||
ce78b96d JB |
3607 | if (b->type == bp_catchpoint) |
3608 | { | |
3609 | /* For now, none of the bp_catchpoint breakpoints need to | |
3610 | do anything at this point. In the future, if some of | |
3611 | the catchpoints need to something, we will need to add | |
3612 | a new method, and call this method from here. */ | |
3613 | continue; | |
3614 | } | |
3615 | ||
c5aa993b JM |
3616 | /* bp_finish is a special case. The only way we ought to be able |
3617 | to see one of these when an exec() has happened, is if the user | |
3618 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3619 | carries them to the call-site of the current callee, by setting | |
3620 | a temporary bp there and resuming. But in this case, the finish | |
3621 | will carry them entirely through the vfork & exec. | |
3622 | ||
3623 | We don't want to allow a bp_finish to remain inserted now. But | |
3624 | we can't safely delete it, 'cause finish_command has a handle to | |
3625 | the bp on a bpstat, and will later want to delete it. There's a | |
3626 | chance (and I've seen it happen) that if we delete the bp_finish | |
3627 | here, that its storage will get reused by the time finish_command | |
3628 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3629 | We really must allow finish_command to delete a bp_finish. | |
3630 | ||
e5dd4106 | 3631 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3632 | it's safe to delete something others may have handles to?" |
3633 | problem, what we'll do here is just uninsert the bp_finish, and | |
3634 | let finish_command delete it. | |
3635 | ||
3636 | (We know the bp_finish is "doomed" in the sense that it's | |
3637 | momentary, and will be deleted as soon as finish_command sees | |
3638 | the inferior stopped. So it doesn't matter that the bp's | |
3639 | address is probably bogus in the new a.out, unlike e.g., the | |
3640 | solib breakpoints.) */ | |
c5aa993b | 3641 | |
c5aa993b JM |
3642 | if (b->type == bp_finish) |
3643 | { | |
3644 | continue; | |
3645 | } | |
3646 | ||
3647 | /* Without a symbolic address, we have little hope of the | |
3648 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3649 | a.out. */ |
9ef9e6a6 | 3650 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3651 | { |
3652 | delete_breakpoint (b); | |
3653 | continue; | |
3654 | } | |
c5aa993b | 3655 | } |
c906108c SS |
3656 | } |
3657 | ||
3658 | int | |
d80ee84f | 3659 | detach_breakpoints (ptid_t ptid) |
c906108c | 3660 | { |
35df4500 | 3661 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3662 | int val = 0; |
2989a365 | 3663 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3664 | struct inferior *inf = current_inferior (); |
c5aa993b | 3665 | |
dfd4cc63 | 3666 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3667 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3668 | |
6c95b8df | 3669 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3670 | inferior_ptid = ptid; |
35df4500 | 3671 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3672 | { |
35df4500 | 3673 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3674 | continue; |
3675 | ||
bd9673a4 PW |
3676 | /* This function must physically remove breakpoints locations |
3677 | from the specified ptid, without modifying the breakpoint | |
3678 | package's state. Locations of type bp_loc_other are only | |
3679 | maintained at GDB side. So, there is no need to remove | |
3680 | these bp_loc_other locations. Moreover, removing these | |
3681 | would modify the breakpoint package's state. */ | |
3682 | if (bl->loc_type == bp_loc_other) | |
3683 | continue; | |
3684 | ||
35df4500 | 3685 | if (bl->inserted) |
b2b6a7da | 3686 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3687 | } |
d03285ec | 3688 | |
3a1bae8e | 3689 | return val; |
c906108c SS |
3690 | } |
3691 | ||
35df4500 | 3692 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3693 | Note that this is used to detach breakpoints from a child fork. |
3694 | When we get here, the child isn't in the inferior list, and neither | |
3695 | do we have objects to represent its address space --- we should | |
35df4500 | 3696 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3697 | |
c906108c | 3698 | static int |
b2b6a7da | 3699 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3700 | { |
3701 | int val; | |
c5aa993b | 3702 | |
35df4500 TJB |
3703 | /* BL is never in moribund_locations by our callers. */ |
3704 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3705 | |
74960c60 VP |
3706 | /* The type of none suggests that owner is actually deleted. |
3707 | This should not ever happen. */ | |
35df4500 | 3708 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3709 | |
35df4500 TJB |
3710 | if (bl->loc_type == bp_loc_software_breakpoint |
3711 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3712 | { |
c02f5703 MS |
3713 | /* "Normal" instruction breakpoint: either the standard |
3714 | trap-instruction bp (bp_breakpoint), or a | |
3715 | bp_hardware_breakpoint. */ | |
3716 | ||
3717 | /* First check to see if we have to handle an overlay. */ | |
3718 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3719 | || bl->section == NULL |
3720 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3721 | { |
3722 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3723 | |
3724 | /* If we're trying to uninsert a memory breakpoint that we | |
3725 | know is set in a dynamic object that is marked | |
3726 | shlib_disabled, then either the dynamic object was | |
3727 | removed with "remove-symbol-file" or with | |
3728 | "nosharedlibrary". In the former case, we don't know | |
3729 | whether another dynamic object might have loaded over the | |
3730 | breakpoint's address -- the user might well let us know | |
3731 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3732 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3733 | list of dynamically loaded objects). If we have the |
3734 | breakpoint's shadow memory, that is, this is a software | |
3735 | breakpoint managed by GDB, check whether the breakpoint | |
3736 | is still inserted in memory, to avoid overwriting wrong | |
3737 | code with stale saved shadow contents. Note that HW | |
3738 | breakpoints don't have shadow memory, as they're | |
3739 | implemented using a mechanism that is not dependent on | |
3740 | being able to modify the target's memory, and as such | |
3741 | they should always be removed. */ | |
3742 | if (bl->shlib_disabled | |
3743 | && bl->target_info.shadow_len != 0 | |
3744 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3745 | val = 0; | |
3746 | else | |
73971819 | 3747 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3748 | } |
c906108c SS |
3749 | else |
3750 | { | |
4a64f543 | 3751 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3752 | Did we set a breakpoint at the LMA? */ |
3753 | if (!overlay_events_enabled) | |
3754 | { | |
3755 | /* Yes -- overlay event support is not active, so we | |
3756 | should have set a breakpoint at the LMA. Remove it. | |
3757 | */ | |
c02f5703 MS |
3758 | /* Ignore any failures: if the LMA is in ROM, we will |
3759 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3760 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3761 | target_remove_hw_breakpoint (bl->gdbarch, | |
3762 | &bl->overlay_target_info); | |
c02f5703 | 3763 | else |
35df4500 | 3764 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3765 | &bl->overlay_target_info, |
3766 | reason); | |
c02f5703 MS |
3767 | } |
3768 | /* Did we set a breakpoint at the VMA? | |
3769 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3770 | if (bl->inserted) |
c906108c | 3771 | { |
c02f5703 MS |
3772 | /* Yes -- remove it. Previously we did not bother to |
3773 | remove the breakpoint if the section had been | |
3774 | unmapped, but let's not rely on that being safe. We | |
3775 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3776 | |
3777 | /* However, we should remove *software* breakpoints only | |
3778 | if the section is still mapped, or else we overwrite | |
3779 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3780 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3781 | || section_is_mapped (bl->section)) | |
73971819 | 3782 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3783 | else |
3784 | val = 0; | |
c906108c | 3785 | } |
c02f5703 MS |
3786 | else |
3787 | { | |
3788 | /* No -- not inserted, so no need to remove. No error. */ | |
3789 | val = 0; | |
3790 | } | |
c906108c | 3791 | } |
879d1e6b | 3792 | |
08351840 PA |
3793 | /* In some cases, we might not be able to remove a breakpoint in |
3794 | a shared library that has already been removed, but we have | |
3795 | not yet processed the shlib unload event. Similarly for an | |
3796 | unloaded add-symbol-file object - the user might not yet have | |
3797 | had the chance to remove-symbol-file it. shlib_disabled will | |
3798 | be set if the library/object has already been removed, but | |
3799 | the breakpoint hasn't been uninserted yet, e.g., after | |
3800 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3801 | always-inserted mode. */ | |
076855f9 | 3802 | if (val |
08351840 PA |
3803 | && (bl->loc_type == bp_loc_software_breakpoint |
3804 | && (bl->shlib_disabled | |
3805 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3806 | || shared_objfile_contains_address_p (bl->pspace, |
3807 | bl->address)))) | |
879d1e6b UW |
3808 | val = 0; |
3809 | ||
c906108c SS |
3810 | if (val) |
3811 | return val; | |
b2b6a7da | 3812 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3813 | } |
35df4500 | 3814 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3815 | { |
77b06cd7 TJB |
3816 | gdb_assert (bl->owner->ops != NULL |
3817 | && bl->owner->ops->remove_location != NULL); | |
3818 | ||
b2b6a7da | 3819 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3820 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3821 | |
c906108c | 3822 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3823 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3824 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3825 | bl->owner->number); |
c906108c | 3826 | } |
35df4500 TJB |
3827 | else if (bl->owner->type == bp_catchpoint |
3828 | && breakpoint_enabled (bl->owner) | |
3829 | && !bl->duplicate) | |
ce78b96d | 3830 | { |
77b06cd7 TJB |
3831 | gdb_assert (bl->owner->ops != NULL |
3832 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3833 | |
73971819 | 3834 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3835 | if (val) |
3836 | return val; | |
77b06cd7 | 3837 | |
b2b6a7da | 3838 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3839 | } |
c906108c SS |
3840 | |
3841 | return 0; | |
3842 | } | |
3843 | ||
6c95b8df | 3844 | static int |
834c0d03 | 3845 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3846 | { |
35df4500 TJB |
3847 | /* BL is never in moribund_locations by our callers. */ |
3848 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3849 | |
6c95b8df PA |
3850 | /* The type of none suggests that owner is actually deleted. |
3851 | This should not ever happen. */ | |
35df4500 | 3852 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3853 | |
5ed8105e | 3854 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3855 | |
35df4500 | 3856 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3857 | |
5ed8105e | 3858 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3859 | } |
3860 | ||
c906108c SS |
3861 | /* Clear the "inserted" flag in all breakpoints. */ |
3862 | ||
25b22b0a | 3863 | void |
fba45db2 | 3864 | mark_breakpoints_out (void) |
c906108c | 3865 | { |
35df4500 | 3866 | struct bp_location *bl, **blp_tmp; |
c906108c | 3867 | |
35df4500 | 3868 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3869 | if (bl->pspace == current_program_space) |
35df4500 | 3870 | bl->inserted = 0; |
c906108c SS |
3871 | } |
3872 | ||
53a5351d JM |
3873 | /* Clear the "inserted" flag in all breakpoints and delete any |
3874 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3875 | |
3876 | Plus other such housekeeping that has to be done for breakpoints | |
3877 | between runs. | |
3878 | ||
53a5351d JM |
3879 | Note: this function gets called at the end of a run (by |
3880 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3881 | init_wait_for_inferior). */ |
c906108c SS |
3882 | |
3883 | ||
3884 | ||
3885 | void | |
fba45db2 | 3886 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3887 | { |
35df4500 | 3888 | struct breakpoint *b, *b_tmp; |
870f88f7 | 3889 | struct bp_location *bl; |
1c5cfe86 | 3890 | int ix; |
6c95b8df | 3891 | struct program_space *pspace = current_program_space; |
c906108c | 3892 | |
50c71eaf PA |
3893 | /* If breakpoint locations are shared across processes, then there's |
3894 | nothing to do. */ | |
f5656ead | 3895 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3896 | return; |
3897 | ||
1a853c52 | 3898 | mark_breakpoints_out (); |
075f6582 | 3899 | |
35df4500 | 3900 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3901 | { |
6c95b8df PA |
3902 | if (b->loc && b->loc->pspace != pspace) |
3903 | continue; | |
3904 | ||
c5aa993b JM |
3905 | switch (b->type) |
3906 | { | |
3907 | case bp_call_dummy: | |
e2e4d78b | 3908 | case bp_longjmp_call_dummy: |
c906108c | 3909 | |
c5aa993b | 3910 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3911 | cause problems when the inferior is rerun, so we better get |
3912 | rid of it. */ | |
3913 | ||
3914 | case bp_watchpoint_scope: | |
3915 | ||
3916 | /* Also get rid of scope breakpoints. */ | |
3917 | ||
3918 | case bp_shlib_event: | |
3919 | ||
3920 | /* Also remove solib event breakpoints. Their addresses may | |
3921 | have changed since the last time we ran the program. | |
3922 | Actually we may now be debugging against different target; | |
3923 | and so the solib backend that installed this breakpoint may | |
3924 | not be used in by the target. E.g., | |
3925 | ||
3926 | (gdb) file prog-linux | |
3927 | (gdb) run # native linux target | |
3928 | ... | |
3929 | (gdb) kill | |
3930 | (gdb) file prog-win.exe | |
3931 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3932 | */ | |
c906108c | 3933 | |
f59f708a PA |
3934 | case bp_step_resume: |
3935 | ||
3936 | /* Also remove step-resume breakpoints. */ | |
3937 | ||
7c16b83e PA |
3938 | case bp_single_step: |
3939 | ||
3940 | /* Also remove single-step breakpoints. */ | |
3941 | ||
c5aa993b JM |
3942 | delete_breakpoint (b); |
3943 | break; | |
c906108c | 3944 | |
c5aa993b JM |
3945 | case bp_watchpoint: |
3946 | case bp_hardware_watchpoint: | |
3947 | case bp_read_watchpoint: | |
3948 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3949 | { |
3950 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3951 | |
3a5c3e22 PA |
3952 | /* Likewise for watchpoints on local expressions. */ |
3953 | if (w->exp_valid_block != NULL) | |
3954 | delete_breakpoint (b); | |
63000888 | 3955 | else |
3a5c3e22 | 3956 | { |
63000888 PA |
3957 | /* Get rid of existing locations, which are no longer |
3958 | valid. New ones will be created in | |
3959 | update_watchpoint, when the inferior is restarted. | |
3960 | The next update_global_location_list call will | |
3961 | garbage collect them. */ | |
3962 | b->loc = NULL; | |
3963 | ||
3964 | if (context == inf_starting) | |
3965 | { | |
3966 | /* Reset val field to force reread of starting value in | |
3967 | insert_breakpoints. */ | |
3968 | if (w->val) | |
3969 | value_free (w->val); | |
3970 | w->val = NULL; | |
3971 | w->val_valid = 0; | |
3972 | } | |
3973 | } | |
3a5c3e22 | 3974 | } |
c5aa993b JM |
3975 | break; |
3976 | default: | |
c5aa993b JM |
3977 | break; |
3978 | } | |
3979 | } | |
1c5cfe86 PA |
3980 | |
3981 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3982 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3983 | decref_bp_location (&bl); | |
1c5cfe86 | 3984 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3985 | } |
3986 | ||
6c95b8df PA |
3987 | /* These functions concern about actual breakpoints inserted in the |
3988 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3989 | we need to hop over the bkpt --- so we check for address space | |
3990 | match, not program space. */ | |
3991 | ||
c2c6d25f JM |
3992 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3993 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3994 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3995 | permanent breakpoint. | |
3996 | - When continuing from a location with an ordinary breakpoint, we | |
3997 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3998 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3999 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4000 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4001 | |
c2c6d25f | 4002 | enum breakpoint_here |
accd0bcd | 4003 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4004 | { |
35df4500 | 4005 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4006 | int any_breakpoint_here = 0; |
c906108c | 4007 | |
35df4500 | 4008 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4009 | { |
35df4500 TJB |
4010 | if (bl->loc_type != bp_loc_software_breakpoint |
4011 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4012 | continue; |
4013 | ||
f1310107 | 4014 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4015 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4016 | || bl->permanent) |
f1310107 | 4017 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4018 | { |
4019 | if (overlay_debugging | |
35df4500 TJB |
4020 | && section_is_overlay (bl->section) |
4021 | && !section_is_mapped (bl->section)) | |
075f6582 | 4022 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4023 | else if (bl->permanent) |
075f6582 DJ |
4024 | return permanent_breakpoint_here; |
4025 | else | |
4026 | any_breakpoint_here = 1; | |
4027 | } | |
4028 | } | |
c906108c | 4029 | |
f486487f | 4030 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4031 | } |
4032 | ||
d35ae833 PA |
4033 | /* See breakpoint.h. */ |
4034 | ||
4035 | int | |
accd0bcd | 4036 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
4037 | CORE_ADDR addr, ULONGEST len) |
4038 | { | |
4039 | struct bp_location *bl, **blp_tmp; | |
4040 | ||
4041 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4042 | { | |
4043 | if (bl->loc_type != bp_loc_software_breakpoint | |
4044 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4045 | continue; | |
4046 | ||
4047 | if ((breakpoint_enabled (bl->owner) | |
4048 | || bl->permanent) | |
4049 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4050 | addr, len)) | |
4051 | { | |
4052 | if (overlay_debugging | |
4053 | && section_is_overlay (bl->section) | |
4054 | && !section_is_mapped (bl->section)) | |
4055 | { | |
4056 | /* Unmapped overlay -- can't be a match. */ | |
4057 | continue; | |
4058 | } | |
4059 | ||
4060 | return 1; | |
4061 | } | |
4062 | } | |
4063 | ||
4064 | return 0; | |
4065 | } | |
4066 | ||
1c5cfe86 PA |
4067 | /* Return true if there's a moribund breakpoint at PC. */ |
4068 | ||
4069 | int | |
accd0bcd | 4070 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4071 | { |
4072 | struct bp_location *loc; | |
4073 | int ix; | |
4074 | ||
4075 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4076 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4077 | return 1; |
4078 | ||
4079 | return 0; | |
4080 | } | |
c2c6d25f | 4081 | |
f7ce857f PA |
4082 | /* Returns non-zero iff BL is inserted at PC, in address space |
4083 | ASPACE. */ | |
4084 | ||
4085 | static int | |
4086 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 4087 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
4088 | { |
4089 | if (bl->inserted | |
4090 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4091 | aspace, pc)) | |
4092 | { | |
4093 | if (overlay_debugging | |
4094 | && section_is_overlay (bl->section) | |
4095 | && !section_is_mapped (bl->section)) | |
4096 | return 0; /* unmapped overlay -- can't be a match */ | |
4097 | else | |
4098 | return 1; | |
4099 | } | |
4100 | return 0; | |
4101 | } | |
4102 | ||
a1fd2fa5 | 4103 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4104 | |
4105 | int | |
accd0bcd | 4106 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4107 | { |
f7ce857f | 4108 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4109 | |
f7ce857f | 4110 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4111 | { |
f7ce857f PA |
4112 | struct bp_location *bl = *blp; |
4113 | ||
35df4500 TJB |
4114 | if (bl->loc_type != bp_loc_software_breakpoint |
4115 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4116 | continue; |
4117 | ||
f7ce857f PA |
4118 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4119 | return 1; | |
c5aa993b | 4120 | } |
c36b740a VP |
4121 | return 0; |
4122 | } | |
4123 | ||
a1fd2fa5 PA |
4124 | /* This function returns non-zero iff there is a software breakpoint |
4125 | inserted at PC. */ | |
c36b740a VP |
4126 | |
4127 | int | |
accd0bcd | 4128 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4129 | CORE_ADDR pc) |
4fa8626c | 4130 | { |
f7ce857f | 4131 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4132 | |
f7ce857f | 4133 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4134 | { |
f7ce857f PA |
4135 | struct bp_location *bl = *blp; |
4136 | ||
35df4500 | 4137 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4138 | continue; |
4139 | ||
f7ce857f PA |
4140 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4141 | return 1; | |
4fa8626c DJ |
4142 | } |
4143 | ||
4144 | return 0; | |
9c02b525 PA |
4145 | } |
4146 | ||
4147 | /* See breakpoint.h. */ | |
4148 | ||
4149 | int | |
accd0bcd | 4150 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4151 | CORE_ADDR pc) |
4152 | { | |
4153 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4154 | |
4155 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4156 | { | |
4157 | struct bp_location *bl = *blp; | |
4158 | ||
4159 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4160 | continue; | |
4161 | ||
4162 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4163 | return 1; | |
4164 | } | |
4165 | ||
4166 | return 0; | |
4fa8626c DJ |
4167 | } |
4168 | ||
9093389c | 4169 | int |
accd0bcd | 4170 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4171 | CORE_ADDR addr, ULONGEST len) |
4172 | { | |
4173 | struct breakpoint *bpt; | |
4174 | ||
4175 | ALL_BREAKPOINTS (bpt) | |
4176 | { | |
4177 | struct bp_location *loc; | |
4178 | ||
4179 | if (bpt->type != bp_hardware_watchpoint | |
4180 | && bpt->type != bp_access_watchpoint) | |
4181 | continue; | |
4182 | ||
4183 | if (!breakpoint_enabled (bpt)) | |
4184 | continue; | |
4185 | ||
4186 | for (loc = bpt->loc; loc; loc = loc->next) | |
4187 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4188 | { | |
4189 | CORE_ADDR l, h; | |
4190 | ||
4191 | /* Check for intersection. */ | |
768adc05 PA |
4192 | l = std::max<CORE_ADDR> (loc->address, addr); |
4193 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4194 | if (l < h) |
4195 | return 1; | |
4196 | } | |
4197 | } | |
4198 | return 0; | |
4199 | } | |
c906108c | 4200 | \f |
c5aa993b | 4201 | |
c906108c SS |
4202 | /* bpstat stuff. External routines' interfaces are documented |
4203 | in breakpoint.h. */ | |
4204 | ||
4205 | int | |
c326b90e | 4206 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4207 | { |
533be4dd | 4208 | return (ep->type == bp_catchpoint); |
c906108c SS |
4209 | } |
4210 | ||
f431efe5 PA |
4211 | /* Frees any storage that is part of a bpstat. Does not walk the |
4212 | 'next' chain. */ | |
4213 | ||
04afa70c | 4214 | bpstats::~bpstats () |
198757a8 | 4215 | { |
04afa70c TT |
4216 | if (old_val != NULL) |
4217 | value_free (old_val); | |
04afa70c TT |
4218 | if (bp_location_at != NULL) |
4219 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4220 | } |
4221 | ||
c906108c SS |
4222 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4223 | Also free any storage that is part of a bpstat. */ | |
4224 | ||
4225 | void | |
fba45db2 | 4226 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4227 | { |
4228 | bpstat p; | |
4229 | bpstat q; | |
4230 | ||
4231 | if (bsp == 0) | |
4232 | return; | |
4233 | p = *bsp; | |
4234 | while (p != NULL) | |
4235 | { | |
4236 | q = p->next; | |
04afa70c | 4237 | delete p; |
c906108c SS |
4238 | p = q; |
4239 | } | |
4240 | *bsp = NULL; | |
4241 | } | |
4242 | ||
04afa70c TT |
4243 | bpstats::bpstats (const bpstats &other) |
4244 | : next (NULL), | |
4245 | bp_location_at (other.bp_location_at), | |
4246 | breakpoint_at (other.breakpoint_at), | |
4247 | commands (other.commands), | |
4248 | old_val (other.old_val), | |
4249 | print (other.print), | |
4250 | stop (other.stop), | |
4251 | print_it (other.print_it) | |
4252 | { | |
4253 | if (old_val != NULL) | |
4254 | { | |
4255 | old_val = value_copy (old_val); | |
4256 | release_value (old_val); | |
4257 | } | |
4258 | incref_bp_location (bp_location_at); | |
04afa70c TT |
4259 | } |
4260 | ||
c906108c SS |
4261 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4262 | is part of the bpstat is copied as well. */ | |
4263 | ||
4264 | bpstat | |
fba45db2 | 4265 | bpstat_copy (bpstat bs) |
c906108c SS |
4266 | { |
4267 | bpstat p = NULL; | |
4268 | bpstat tmp; | |
4269 | bpstat retval = NULL; | |
4270 | ||
4271 | if (bs == NULL) | |
4272 | return bs; | |
4273 | ||
4274 | for (; bs != NULL; bs = bs->next) | |
4275 | { | |
04afa70c | 4276 | tmp = new bpstats (*bs); |
31cc81e9 | 4277 | |
c906108c SS |
4278 | if (p == NULL) |
4279 | /* This is the first thing in the chain. */ | |
4280 | retval = tmp; | |
4281 | else | |
4282 | p->next = tmp; | |
4283 | p = tmp; | |
4284 | } | |
4285 | p->next = NULL; | |
4286 | return retval; | |
4287 | } | |
4288 | ||
4a64f543 | 4289 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4290 | |
4291 | bpstat | |
fba45db2 | 4292 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4293 | { |
c5aa993b JM |
4294 | if (bsp == NULL) |
4295 | return NULL; | |
c906108c | 4296 | |
c5aa993b JM |
4297 | for (; bsp != NULL; bsp = bsp->next) |
4298 | { | |
f431efe5 | 4299 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4300 | return bsp; |
4301 | } | |
c906108c SS |
4302 | return NULL; |
4303 | } | |
4304 | ||
ab04a2af TT |
4305 | /* See breakpoint.h. */ |
4306 | ||
47591c29 | 4307 | int |
427cd150 | 4308 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4309 | { |
ab04a2af TT |
4310 | for (; bsp != NULL; bsp = bsp->next) |
4311 | { | |
427cd150 TT |
4312 | if (bsp->breakpoint_at == NULL) |
4313 | { | |
4314 | /* A moribund location can never explain a signal other than | |
4315 | GDB_SIGNAL_TRAP. */ | |
4316 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4317 | return 1; |
427cd150 TT |
4318 | } |
4319 | else | |
47591c29 PA |
4320 | { |
4321 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4322 | sig)) | |
4323 | return 1; | |
4324 | } | |
ab04a2af TT |
4325 | } |
4326 | ||
47591c29 | 4327 | return 0; |
ab04a2af TT |
4328 | } |
4329 | ||
4a64f543 MS |
4330 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4331 | stopped at. *BSP upon return is a bpstat which points to the | |
4332 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4333 | good for anything but further calls to bpstat_num). | |
4334 | ||
8671a17b PA |
4335 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4336 | Return -1 if stopped at a breakpoint that has been deleted since | |
4337 | we set it. | |
4338 | Return 1 otherwise. */ | |
c906108c SS |
4339 | |
4340 | int | |
8671a17b | 4341 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4342 | { |
4343 | struct breakpoint *b; | |
4344 | ||
4345 | if ((*bsp) == NULL) | |
4346 | return 0; /* No more breakpoint values */ | |
8671a17b | 4347 | |
4a64f543 MS |
4348 | /* We assume we'll never have several bpstats that correspond to a |
4349 | single breakpoint -- otherwise, this function might return the | |
4350 | same number more than once and this will look ugly. */ | |
f431efe5 | 4351 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4352 | *bsp = (*bsp)->next; |
4353 | if (b == NULL) | |
4354 | return -1; /* breakpoint that's been deleted since */ | |
4355 | ||
4356 | *num = b->number; /* We have its number */ | |
4357 | return 1; | |
c906108c SS |
4358 | } |
4359 | ||
e93ca019 | 4360 | /* See breakpoint.h. */ |
c906108c SS |
4361 | |
4362 | void | |
e93ca019 | 4363 | bpstat_clear_actions (void) |
c906108c | 4364 | { |
e93ca019 JK |
4365 | struct thread_info *tp; |
4366 | bpstat bs; | |
4367 | ||
4368 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4369 | return; | |
4370 | ||
4371 | tp = find_thread_ptid (inferior_ptid); | |
4372 | if (tp == NULL) | |
4373 | return; | |
4374 | ||
4375 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4376 | { |
d1b0a7bf | 4377 | bs->commands = NULL; |
abf85f46 | 4378 | |
c906108c SS |
4379 | if (bs->old_val != NULL) |
4380 | { | |
4381 | value_free (bs->old_val); | |
4382 | bs->old_val = NULL; | |
4383 | } | |
4384 | } | |
4385 | } | |
4386 | ||
f3b1572e PA |
4387 | /* Called when a command is about to proceed the inferior. */ |
4388 | ||
4389 | static void | |
4390 | breakpoint_about_to_proceed (void) | |
4391 | { | |
4392 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4393 | { | |
4394 | struct thread_info *tp = inferior_thread (); | |
4395 | ||
4396 | /* Allow inferior function calls in breakpoint commands to not | |
4397 | interrupt the command list. When the call finishes | |
4398 | successfully, the inferior will be standing at the same | |
4399 | breakpoint as if nothing happened. */ | |
16c381f0 | 4400 | if (tp->control.in_infcall) |
f3b1572e PA |
4401 | return; |
4402 | } | |
4403 | ||
4404 | breakpoint_proceeded = 1; | |
4405 | } | |
4406 | ||
abf85f46 JK |
4407 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4408 | or its equivalent. */ | |
4409 | ||
4410 | static int | |
4411 | command_line_is_silent (struct command_line *cmd) | |
4412 | { | |
4f45d445 | 4413 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4414 | } |
4415 | ||
4a64f543 MS |
4416 | /* Execute all the commands associated with all the breakpoints at |
4417 | this location. Any of these commands could cause the process to | |
4418 | proceed beyond this point, etc. We look out for such changes by | |
4419 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4420 | |
347bddb7 PA |
4421 | Returns true if a breakpoint command resumed the inferior. In that |
4422 | case, it is the caller's responsibility to recall it again with the | |
4423 | bpstat of the current thread. */ | |
4424 | ||
4425 | static int | |
4426 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4427 | { |
4428 | bpstat bs; | |
347bddb7 | 4429 | int again = 0; |
c906108c SS |
4430 | |
4431 | /* Avoid endless recursion if a `source' command is contained | |
4432 | in bs->commands. */ | |
4433 | if (executing_breakpoint_commands) | |
347bddb7 | 4434 | return 0; |
c906108c | 4435 | |
81b1e71c TT |
4436 | scoped_restore save_executing |
4437 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4438 | |
1ac32117 | 4439 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4440 | |
4a64f543 | 4441 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4442 | bs = *bsp; |
4443 | ||
4444 | breakpoint_proceeded = 0; | |
4445 | for (; bs != NULL; bs = bs->next) | |
4446 | { | |
d1b0a7bf | 4447 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4448 | |
4449 | /* Take ownership of the BSP's command tree, if it has one. | |
4450 | ||
4451 | The command tree could legitimately contain commands like | |
4452 | 'step' and 'next', which call clear_proceed_status, which | |
4453 | frees stop_bpstat's command tree. To make sure this doesn't | |
4454 | free the tree we're executing out from under us, we need to | |
4455 | take ownership of the tree ourselves. Since a given bpstat's | |
4456 | commands are only executed once, we don't need to copy it; we | |
4457 | can clear the pointer in the bpstat, and make sure we free | |
4458 | the tree when we're done. */ | |
d1b0a7bf | 4459 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4460 | bs->commands = NULL; |
d1b0a7bf TT |
4461 | if (ccmd != NULL) |
4462 | cmd = ccmd.get (); | |
abf85f46 JK |
4463 | if (command_line_is_silent (cmd)) |
4464 | { | |
4465 | /* The action has been already done by bpstat_stop_status. */ | |
4466 | cmd = cmd->next; | |
4467 | } | |
6c50ab1c | 4468 | |
c906108c SS |
4469 | while (cmd != NULL) |
4470 | { | |
4471 | execute_control_command (cmd); | |
4472 | ||
4473 | if (breakpoint_proceeded) | |
4474 | break; | |
4475 | else | |
4476 | cmd = cmd->next; | |
4477 | } | |
6c50ab1c | 4478 | |
c906108c | 4479 | if (breakpoint_proceeded) |
32c1e744 | 4480 | { |
cb814510 | 4481 | if (current_ui->async) |
347bddb7 PA |
4482 | /* If we are in async mode, then the target might be still |
4483 | running, not stopped at any breakpoint, so nothing for | |
4484 | us to do here -- just return to the event loop. */ | |
4485 | ; | |
32c1e744 VP |
4486 | else |
4487 | /* In sync mode, when execute_control_command returns | |
4488 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4489 | Breakpoint commands for that stop were not run, since |
4490 | execute_command does not run breakpoint commands -- | |
4491 | only command_line_handler does, but that one is not | |
4492 | involved in execution of breakpoint commands. So, we | |
4493 | can now execute breakpoint commands. It should be | |
4494 | noted that making execute_command do bpstat actions is | |
4495 | not an option -- in this case we'll have recursive | |
4496 | invocation of bpstat for each breakpoint with a | |
4497 | command, and can easily blow up GDB stack. Instead, we | |
4498 | return true, which will trigger the caller to recall us | |
4499 | with the new stop_bpstat. */ | |
4500 | again = 1; | |
4501 | break; | |
32c1e744 | 4502 | } |
c906108c | 4503 | } |
347bddb7 PA |
4504 | return again; |
4505 | } | |
4506 | ||
4507 | void | |
4508 | bpstat_do_actions (void) | |
4509 | { | |
353d1d73 JK |
4510 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4511 | ||
347bddb7 PA |
4512 | /* Do any commands attached to breakpoint we are stopped at. */ |
4513 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4514 | && target_has_execution | |
4515 | && !is_exited (inferior_ptid) | |
4516 | && !is_executing (inferior_ptid)) | |
4517 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4518 | and only return when it is stopped at the next breakpoint, we | |
4519 | keep doing breakpoint actions until it returns false to | |
4520 | indicate the inferior was not resumed. */ | |
16c381f0 | 4521 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4522 | break; |
353d1d73 JK |
4523 | |
4524 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4525 | } |
4526 | ||
fa4727a6 DJ |
4527 | /* Print out the (old or new) value associated with a watchpoint. */ |
4528 | ||
4529 | static void | |
4530 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4531 | { | |
4532 | if (val == NULL) | |
4533 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4534 | else | |
79a45b7d TT |
4535 | { |
4536 | struct value_print_options opts; | |
4537 | get_user_print_options (&opts); | |
4538 | value_print (val, stream, &opts); | |
4539 | } | |
fa4727a6 DJ |
4540 | } |
4541 | ||
f303dbd6 PA |
4542 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4543 | debugging multiple threads. */ | |
4544 | ||
4545 | void | |
4546 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4547 | { | |
112e8700 | 4548 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4549 | return; |
4550 | ||
112e8700 | 4551 | uiout->text ("\n"); |
f303dbd6 PA |
4552 | |
4553 | if (show_thread_that_caused_stop ()) | |
4554 | { | |
4555 | const char *name; | |
4556 | struct thread_info *thr = inferior_thread (); | |
4557 | ||
112e8700 SM |
4558 | uiout->text ("Thread "); |
4559 | uiout->field_fmt ("thread-id", "%s", print_thread_id (thr)); | |
f303dbd6 PA |
4560 | |
4561 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4562 | if (name != NULL) | |
4563 | { | |
112e8700 SM |
4564 | uiout->text (" \""); |
4565 | uiout->field_fmt ("name", "%s", name); | |
4566 | uiout->text ("\""); | |
f303dbd6 PA |
4567 | } |
4568 | ||
112e8700 | 4569 | uiout->text (" hit "); |
f303dbd6 PA |
4570 | } |
4571 | } | |
4572 | ||
e514a9d6 | 4573 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4574 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4575 | 'print_it' in the bpstat structure. Under some circumstances we |
4576 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4577 | normal_stop(). */ |
e514a9d6 JM |
4578 | |
4579 | static enum print_stop_action | |
4580 | print_bp_stop_message (bpstat bs) | |
4581 | { | |
4582 | switch (bs->print_it) | |
4583 | { | |
4584 | case print_it_noop: | |
4a64f543 | 4585 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4586 | return PRINT_UNKNOWN; |
4587 | break; | |
4588 | ||
4589 | case print_it_done: | |
4590 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4591 | relevant messages. */ |
e514a9d6 JM |
4592 | return PRINT_SRC_AND_LOC; |
4593 | break; | |
4594 | ||
4595 | case print_it_normal: | |
4f8d1dc6 | 4596 | { |
f431efe5 PA |
4597 | struct breakpoint *b = bs->breakpoint_at; |
4598 | ||
1a6a67de TJB |
4599 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4600 | which has since been deleted. */ | |
4601 | if (b == NULL) | |
4602 | return PRINT_UNKNOWN; | |
4603 | ||
348d480f PA |
4604 | /* Normal case. Call the breakpoint's print_it method. */ |
4605 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4606 | } |
348d480f | 4607 | break; |
3086aeae | 4608 | |
e514a9d6 | 4609 | default: |
8e65ff28 | 4610 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4611 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4612 | break; |
c906108c | 4613 | } |
c906108c SS |
4614 | } |
4615 | ||
edcc5120 TT |
4616 | /* A helper function that prints a shared library stopped event. */ |
4617 | ||
4618 | static void | |
4619 | print_solib_event (int is_catchpoint) | |
4620 | { | |
4621 | int any_deleted | |
4622 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4623 | int any_added | |
4624 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4625 | ||
4626 | if (!is_catchpoint) | |
4627 | { | |
4628 | if (any_added || any_deleted) | |
112e8700 | 4629 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4630 | else |
112e8700 SM |
4631 | current_uiout->text (_("Stopped due to shared library event (no " |
4632 | "libraries added or removed)\n")); | |
edcc5120 TT |
4633 | } |
4634 | ||
112e8700 SM |
4635 | if (current_uiout->is_mi_like_p ()) |
4636 | current_uiout->field_string ("reason", | |
4637 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4638 | |
4639 | if (any_deleted) | |
4640 | { | |
edcc5120 TT |
4641 | char *name; |
4642 | int ix; | |
4643 | ||
112e8700 | 4644 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4645 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
edcc5120 TT |
4646 | for (ix = 0; |
4647 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4648 | ix, name); | |
4649 | ++ix) | |
4650 | { | |
4651 | if (ix > 0) | |
112e8700 SM |
4652 | current_uiout->text (" "); |
4653 | current_uiout->field_string ("library", name); | |
4654 | current_uiout->text ("\n"); | |
edcc5120 | 4655 | } |
edcc5120 TT |
4656 | } |
4657 | ||
4658 | if (any_added) | |
4659 | { | |
4660 | struct so_list *iter; | |
4661 | int ix; | |
edcc5120 | 4662 | |
112e8700 | 4663 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4664 | ui_out_emit_list list_emitter (current_uiout, "added"); |
edcc5120 TT |
4665 | for (ix = 0; |
4666 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4667 | ix, iter); | |
4668 | ++ix) | |
4669 | { | |
4670 | if (ix > 0) | |
112e8700 SM |
4671 | current_uiout->text (" "); |
4672 | current_uiout->field_string ("library", iter->so_name); | |
4673 | current_uiout->text ("\n"); | |
edcc5120 | 4674 | } |
edcc5120 TT |
4675 | } |
4676 | } | |
4677 | ||
e514a9d6 JM |
4678 | /* Print a message indicating what happened. This is called from |
4679 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4680 | list - a list of the eventpoints that caused this stop. KIND is |
4681 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4682 | routine calls the generic print routine for printing a message |
4683 | about reasons for stopping. This will print (for example) the | |
4684 | "Breakpoint n," part of the output. The return value of this | |
4685 | routine is one of: | |
c906108c | 4686 | |
4a64f543 | 4687 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4688 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4689 | code to print the location. An example is |
c5aa993b JM |
4690 | "Breakpoint 1, " which should be followed by |
4691 | the location. | |
917317f4 | 4692 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4693 | to also print the location part of the message. |
4694 | An example is the catch/throw messages, which | |
4a64f543 | 4695 | don't require a location appended to the end. |
917317f4 | 4696 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4697 | further info to be printed. */ |
c906108c | 4698 | |
917317f4 | 4699 | enum print_stop_action |
36dfb11c | 4700 | bpstat_print (bpstat bs, int kind) |
c906108c | 4701 | { |
f486487f | 4702 | enum print_stop_action val; |
c5aa993b | 4703 | |
c906108c | 4704 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4705 | (Currently all watchpoints go on the bpstat whether hit or not. |
4706 | That probably could (should) be changed, provided care is taken | |
c906108c | 4707 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4708 | for (; bs; bs = bs->next) |
4709 | { | |
4710 | val = print_bp_stop_message (bs); | |
4711 | if (val == PRINT_SRC_ONLY | |
4712 | || val == PRINT_SRC_AND_LOC | |
4713 | || val == PRINT_NOTHING) | |
4714 | return val; | |
4715 | } | |
c906108c | 4716 | |
36dfb11c TT |
4717 | /* If we had hit a shared library event breakpoint, |
4718 | print_bp_stop_message would print out this message. If we hit an | |
4719 | OS-level shared library event, do the same thing. */ | |
4720 | if (kind == TARGET_WAITKIND_LOADED) | |
4721 | { | |
edcc5120 | 4722 | print_solib_event (0); |
36dfb11c TT |
4723 | return PRINT_NOTHING; |
4724 | } | |
4725 | ||
e514a9d6 | 4726 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4727 | with and nothing was printed. */ |
917317f4 | 4728 | return PRINT_UNKNOWN; |
c906108c SS |
4729 | } |
4730 | ||
bf469271 | 4731 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4732 | |
bf469271 PA |
4733 | static bool |
4734 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4735 | { |
278cd55f | 4736 | struct value *mark = value_mark (); |
bf469271 | 4737 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4738 | |
c906108c | 4739 | value_free_to_mark (mark); |
bf469271 | 4740 | return res; |
c906108c SS |
4741 | } |
4742 | ||
5760d0ab | 4743 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4744 | |
04afa70c TT |
4745 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4746 | : next (NULL), | |
4747 | bp_location_at (bl), | |
4748 | breakpoint_at (bl->owner), | |
4749 | commands (NULL), | |
4750 | old_val (NULL), | |
4751 | print (0), | |
4752 | stop (0), | |
4753 | print_it (print_it_normal) | |
c906108c | 4754 | { |
f431efe5 | 4755 | incref_bp_location (bl); |
04afa70c TT |
4756 | **bs_link_pointer = this; |
4757 | *bs_link_pointer = &next; | |
4758 | } | |
4759 | ||
4760 | bpstats::bpstats () | |
4761 | : next (NULL), | |
4762 | bp_location_at (NULL), | |
4763 | breakpoint_at (NULL), | |
4764 | commands (NULL), | |
4765 | old_val (NULL), | |
4766 | print (0), | |
4767 | stop (0), | |
4768 | print_it (print_it_normal) | |
4769 | { | |
c906108c SS |
4770 | } |
4771 | \f | |
d983da9c DJ |
4772 | /* The target has stopped with waitstatus WS. Check if any hardware |
4773 | watchpoints have triggered, according to the target. */ | |
4774 | ||
4775 | int | |
4776 | watchpoints_triggered (struct target_waitstatus *ws) | |
4777 | { | |
d92524f1 | 4778 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4779 | CORE_ADDR addr; |
4780 | struct breakpoint *b; | |
4781 | ||
4782 | if (!stopped_by_watchpoint) | |
4783 | { | |
4784 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4785 | as not triggered. */ | |
4786 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4787 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4788 | { |
4789 | struct watchpoint *w = (struct watchpoint *) b; | |
4790 | ||
4791 | w->watchpoint_triggered = watch_triggered_no; | |
4792 | } | |
d983da9c DJ |
4793 | |
4794 | return 0; | |
4795 | } | |
4796 | ||
4797 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4798 | { | |
4799 | /* We were stopped by a watchpoint, but we don't know where. | |
4800 | Mark all watchpoints as unknown. */ | |
4801 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4802 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4803 | { |
4804 | struct watchpoint *w = (struct watchpoint *) b; | |
4805 | ||
4806 | w->watchpoint_triggered = watch_triggered_unknown; | |
4807 | } | |
d983da9c | 4808 | |
3c4797ba | 4809 | return 1; |
d983da9c DJ |
4810 | } |
4811 | ||
4812 | /* The target could report the data address. Mark watchpoints | |
4813 | affected by this data address as triggered, and all others as not | |
4814 | triggered. */ | |
4815 | ||
4816 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4817 | if (is_hardware_watchpoint (b)) |
d983da9c | 4818 | { |
3a5c3e22 | 4819 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4820 | struct bp_location *loc; |
d983da9c | 4821 | |
3a5c3e22 | 4822 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4823 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4824 | { |
3a5c3e22 | 4825 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4826 | { |
3a5c3e22 PA |
4827 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4828 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4829 | |
4830 | if (newaddr == start) | |
4831 | { | |
3a5c3e22 | 4832 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4833 | break; |
4834 | } | |
4835 | } | |
4836 | /* Exact match not required. Within range is sufficient. */ | |
4837 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4838 | addr, loc->address, | |
4839 | loc->length)) | |
4840 | { | |
3a5c3e22 | 4841 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4842 | break; |
4843 | } | |
4844 | } | |
d983da9c DJ |
4845 | } |
4846 | ||
4847 | return 1; | |
4848 | } | |
4849 | ||
bf469271 PA |
4850 | /* Possible return values for watchpoint_check. */ |
4851 | enum wp_check_result | |
4852 | { | |
4853 | /* The watchpoint has been deleted. */ | |
4854 | WP_DELETED = 1, | |
4855 | ||
4856 | /* The value has changed. */ | |
4857 | WP_VALUE_CHANGED = 2, | |
4858 | ||
4859 | /* The value has not changed. */ | |
4860 | WP_VALUE_NOT_CHANGED = 3, | |
4861 | ||
4862 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4863 | WP_IGNORE = 4, | |
4864 | }; | |
c906108c SS |
4865 | |
4866 | #define BP_TEMPFLAG 1 | |
4867 | #define BP_HARDWAREFLAG 2 | |
4868 | ||
4a64f543 | 4869 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4870 | changed. */ |
553e4c11 | 4871 | |
bf469271 PA |
4872 | static wp_check_result |
4873 | watchpoint_check (bpstat bs) | |
c906108c | 4874 | { |
3a5c3e22 | 4875 | struct watchpoint *b; |
c906108c SS |
4876 | struct frame_info *fr; |
4877 | int within_current_scope; | |
4878 | ||
f431efe5 | 4879 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4880 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4881 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4882 | |
f6bc2008 PA |
4883 | /* If this is a local watchpoint, we only want to check if the |
4884 | watchpoint frame is in scope if the current thread is the thread | |
4885 | that was used to create the watchpoint. */ | |
4886 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4887 | return WP_IGNORE; |
f6bc2008 | 4888 | |
c906108c SS |
4889 | if (b->exp_valid_block == NULL) |
4890 | within_current_scope = 1; | |
4891 | else | |
4892 | { | |
edb3359d DJ |
4893 | struct frame_info *frame = get_current_frame (); |
4894 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4895 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4896 | ||
c9cf6e20 | 4897 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4898 | still in the function but the stack frame has already been |
4899 | invalidated. Since we can't rely on the values of local | |
4900 | variables after the stack has been destroyed, we are treating | |
4901 | the watchpoint in that state as `not changed' without further | |
4902 | checking. Don't mark watchpoints as changed if the current | |
4903 | frame is in an epilogue - even if they are in some other | |
4904 | frame, our view of the stack is likely to be wrong and | |
4905 | frame_find_by_id could error out. */ | |
c9cf6e20 | 4906 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 4907 | return WP_IGNORE; |
a0f49112 | 4908 | |
101dcfbe | 4909 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4910 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4911 | |
4912 | /* If we've gotten confused in the unwinder, we might have | |
4913 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4914 | if (within_current_scope) |
4915 | { | |
4916 | struct symbol *function; | |
4917 | ||
4918 | function = get_frame_function (fr); | |
4919 | if (function == NULL | |
4920 | || !contained_in (b->exp_valid_block, | |
4921 | SYMBOL_BLOCK_VALUE (function))) | |
4922 | within_current_scope = 0; | |
4923 | } | |
69fbadd5 | 4924 | |
edb3359d | 4925 | if (within_current_scope) |
c906108c SS |
4926 | /* If we end up stopping, the current frame will get selected |
4927 | in normal_stop. So this call to select_frame won't affect | |
4928 | the user. */ | |
0f7d239c | 4929 | select_frame (fr); |
c906108c | 4930 | } |
c5aa993b | 4931 | |
c906108c SS |
4932 | if (within_current_scope) |
4933 | { | |
4a64f543 MS |
4934 | /* We use value_{,free_to_}mark because it could be a *long* |
4935 | time before we return to the command level and call | |
4936 | free_all_values. We can't call free_all_values because we | |
4937 | might be in the middle of evaluating a function call. */ | |
c906108c | 4938 | |
0cf6dd15 | 4939 | int pc = 0; |
9c06b0b4 | 4940 | struct value *mark; |
fa4727a6 DJ |
4941 | struct value *new_val; |
4942 | ||
c1fc2657 | 4943 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
4944 | /* Since we don't know the exact trigger address (from |
4945 | stopped_data_address), just tell the user we've triggered | |
4946 | a mask watchpoint. */ | |
4947 | return WP_VALUE_CHANGED; | |
4948 | ||
4949 | mark = value_mark (); | |
4d01a485 | 4950 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4951 | |
bb9d5f81 PP |
4952 | if (b->val_bitsize != 0) |
4953 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
4954 | ||
4a64f543 MS |
4955 | /* We use value_equal_contents instead of value_equal because |
4956 | the latter coerces an array to a pointer, thus comparing just | |
4957 | the address of the array instead of its contents. This is | |
4958 | not what we want. */ | |
fa4727a6 | 4959 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4960 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4961 | { |
fa4727a6 DJ |
4962 | if (new_val != NULL) |
4963 | { | |
4964 | release_value (new_val); | |
4965 | value_free_to_mark (mark); | |
4966 | } | |
c906108c SS |
4967 | bs->old_val = b->val; |
4968 | b->val = new_val; | |
fa4727a6 | 4969 | b->val_valid = 1; |
c906108c SS |
4970 | return WP_VALUE_CHANGED; |
4971 | } | |
4972 | else | |
4973 | { | |
60e1c644 | 4974 | /* Nothing changed. */ |
c906108c | 4975 | value_free_to_mark (mark); |
c906108c SS |
4976 | return WP_VALUE_NOT_CHANGED; |
4977 | } | |
4978 | } | |
4979 | else | |
4980 | { | |
4981 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
4982 | if we temporarily ignored the watchpoint, then when |
4983 | we reenter the block in which it is valid it contains | |
4984 | garbage (in the case of a function, it may have two | |
4985 | garbage values, one before and one after the prologue). | |
4986 | So we can't even detect the first assignment to it and | |
4987 | watch after that (since the garbage may or may not equal | |
4988 | the first value assigned). */ | |
348d480f PA |
4989 | /* We print all the stop information in |
4990 | breakpoint_ops->print_it, but in this case, by the time we | |
4991 | call breakpoint_ops->print_it this bp will be deleted | |
4992 | already. So we have no choice but print the information | |
4993 | here. */ | |
468afe6c | 4994 | |
0e454242 | 4995 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
4996 | { |
4997 | struct ui_out *uiout = current_uiout; | |
4998 | ||
112e8700 SM |
4999 | if (uiout->is_mi_like_p ()) |
5000 | uiout->field_string | |
5001 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5002 | uiout->text ("\nWatchpoint "); | |
c1fc2657 | 5003 | uiout->field_int ("wpnum", b->number); |
112e8700 | 5004 | uiout->text (" deleted because the program has left the block in\n" |
468afe6c PA |
5005 | "which its expression is valid.\n"); |
5006 | } | |
4ce44c66 | 5007 | |
cdac0397 | 5008 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 5009 | b->commands = NULL; |
d0fb5eae | 5010 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5011 | |
5012 | return WP_DELETED; | |
5013 | } | |
5014 | } | |
5015 | ||
18a18393 | 5016 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5017 | breakpoint location BL. This function does not check if we should |
5018 | stop, only if BL explains the stop. */ | |
5019 | ||
18a18393 | 5020 | static int |
6c95b8df | 5021 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 5022 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5023 | const struct target_waitstatus *ws) |
18a18393 VP |
5024 | { |
5025 | struct breakpoint *b = bl->owner; | |
5026 | ||
348d480f | 5027 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5028 | gdb_assert (b != NULL); |
5029 | ||
bd522513 | 5030 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5031 | } |
5032 | ||
3a5c3e22 PA |
5033 | /* Determine if the watched values have actually changed, and we |
5034 | should stop. If not, set BS->stop to 0. */ | |
5035 | ||
18a18393 VP |
5036 | static void |
5037 | bpstat_check_watchpoint (bpstat bs) | |
5038 | { | |
2bdf28a0 | 5039 | const struct bp_location *bl; |
3a5c3e22 | 5040 | struct watchpoint *b; |
2bdf28a0 JK |
5041 | |
5042 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5043 | bl = bs->bp_location_at; |
2bdf28a0 | 5044 | gdb_assert (bl != NULL); |
3a5c3e22 | 5045 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5046 | gdb_assert (b != NULL); |
18a18393 | 5047 | |
18a18393 | 5048 | { |
18a18393 VP |
5049 | int must_check_value = 0; |
5050 | ||
c1fc2657 | 5051 | if (b->type == bp_watchpoint) |
18a18393 VP |
5052 | /* For a software watchpoint, we must always check the |
5053 | watched value. */ | |
5054 | must_check_value = 1; | |
5055 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5056 | /* We have a hardware watchpoint (read, write, or access) | |
5057 | and the target earlier reported an address watched by | |
5058 | this watchpoint. */ | |
5059 | must_check_value = 1; | |
5060 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5061 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5062 | /* We were stopped by a hardware watchpoint, but the target could |
5063 | not report the data address. We must check the watchpoint's | |
5064 | value. Access and read watchpoints are out of luck; without | |
5065 | a data address, we can't figure it out. */ | |
5066 | must_check_value = 1; | |
3a5c3e22 | 5067 | |
18a18393 VP |
5068 | if (must_check_value) |
5069 | { | |
bf469271 PA |
5070 | wp_check_result e; |
5071 | ||
5072 | TRY | |
5073 | { | |
5074 | e = watchpoint_check (bs); | |
5075 | } | |
5076 | CATCH (ex, RETURN_MASK_ALL) | |
5077 | { | |
5078 | exception_fprintf (gdb_stderr, ex, | |
5079 | "Error evaluating expression " | |
5080 | "for watchpoint %d\n", | |
5081 | b->number); | |
5082 | ||
5083 | SWITCH_THRU_ALL_UIS () | |
5084 | { | |
5085 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5086 | b->number); | |
5087 | } | |
5088 | watchpoint_del_at_next_stop (b); | |
5089 | e = WP_DELETED; | |
5090 | } | |
5091 | END_CATCH | |
5092 | ||
18a18393 VP |
5093 | switch (e) |
5094 | { | |
5095 | case WP_DELETED: | |
5096 | /* We've already printed what needs to be printed. */ | |
5097 | bs->print_it = print_it_done; | |
5098 | /* Stop. */ | |
5099 | break; | |
60e1c644 PA |
5100 | case WP_IGNORE: |
5101 | bs->print_it = print_it_noop; | |
5102 | bs->stop = 0; | |
5103 | break; | |
18a18393 | 5104 | case WP_VALUE_CHANGED: |
c1fc2657 | 5105 | if (b->type == bp_read_watchpoint) |
18a18393 | 5106 | { |
85d721b8 PA |
5107 | /* There are two cases to consider here: |
5108 | ||
4a64f543 | 5109 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5110 | In that case, trust the target, and always report |
5111 | the watchpoint hit to the user. Even though | |
5112 | reads don't cause value changes, the value may | |
5113 | have changed since the last time it was read, and | |
5114 | since we're not trapping writes, we will not see | |
5115 | those, and as such we should ignore our notion of | |
5116 | old value. | |
5117 | ||
4a64f543 | 5118 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5119 | reads and writes. There are two ways this may |
5120 | happen: | |
5121 | ||
4a64f543 | 5122 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5123 | reads only, but can break on accesses (reads or |
5124 | writes), such as e.g., x86. We detect this case | |
5125 | at the time we try to insert read watchpoints. | |
5126 | ||
4a64f543 | 5127 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5128 | watchpoints, but, the user set an access or write |
5129 | watchpoint watching the same memory as this read | |
5130 | watchpoint. | |
5131 | ||
5132 | If we're watching memory writes as well as reads, | |
5133 | ignore watchpoint hits when we find that the | |
5134 | value hasn't changed, as reads don't cause | |
5135 | changes. This still gives false positives when | |
5136 | the program writes the same value to memory as | |
5137 | what there was already in memory (we will confuse | |
5138 | it for a read), but it's much better than | |
5139 | nothing. */ | |
5140 | ||
5141 | int other_write_watchpoint = 0; | |
5142 | ||
5143 | if (bl->watchpoint_type == hw_read) | |
5144 | { | |
5145 | struct breakpoint *other_b; | |
5146 | ||
5147 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5148 | if (other_b->type == bp_hardware_watchpoint |
5149 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5150 | { |
3a5c3e22 PA |
5151 | struct watchpoint *other_w = |
5152 | (struct watchpoint *) other_b; | |
5153 | ||
5154 | if (other_w->watchpoint_triggered | |
5155 | == watch_triggered_yes) | |
5156 | { | |
5157 | other_write_watchpoint = 1; | |
5158 | break; | |
5159 | } | |
85d721b8 PA |
5160 | } |
5161 | } | |
5162 | ||
5163 | if (other_write_watchpoint | |
5164 | || bl->watchpoint_type == hw_access) | |
5165 | { | |
5166 | /* We're watching the same memory for writes, | |
5167 | and the value changed since the last time we | |
5168 | updated it, so this trap must be for a write. | |
5169 | Ignore it. */ | |
5170 | bs->print_it = print_it_noop; | |
5171 | bs->stop = 0; | |
5172 | } | |
18a18393 VP |
5173 | } |
5174 | break; | |
5175 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5176 | if (b->type == bp_hardware_watchpoint |
5177 | || b->type == bp_watchpoint) | |
18a18393 VP |
5178 | { |
5179 | /* Don't stop: write watchpoints shouldn't fire if | |
5180 | the value hasn't changed. */ | |
5181 | bs->print_it = print_it_noop; | |
5182 | bs->stop = 0; | |
5183 | } | |
5184 | /* Stop. */ | |
5185 | break; | |
5186 | default: | |
5187 | /* Can't happen. */ | |
18a18393 VP |
5188 | break; |
5189 | } | |
5190 | } | |
5191 | else /* must_check_value == 0 */ | |
5192 | { | |
5193 | /* This is a case where some watchpoint(s) triggered, but | |
5194 | not at the address of this watchpoint, or else no | |
5195 | watchpoint triggered after all. So don't print | |
5196 | anything for this watchpoint. */ | |
5197 | bs->print_it = print_it_noop; | |
5198 | bs->stop = 0; | |
5199 | } | |
5200 | } | |
5201 | } | |
5202 | ||
7d4df6a4 DE |
5203 | /* For breakpoints that are currently marked as telling gdb to stop, |
5204 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5205 | of breakpoint referred to by BS. If we should not stop for this |
5206 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5207 | |
18a18393 VP |
5208 | static void |
5209 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5210 | { | |
2bdf28a0 JK |
5211 | const struct bp_location *bl; |
5212 | struct breakpoint *b; | |
bf469271 PA |
5213 | /* Assume stop. */ |
5214 | bool condition_result = true; | |
7d4df6a4 DE |
5215 | struct expression *cond; |
5216 | ||
5217 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5218 | |
5219 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5220 | bl = bs->bp_location_at; |
2bdf28a0 | 5221 | gdb_assert (bl != NULL); |
f431efe5 | 5222 | b = bs->breakpoint_at; |
2bdf28a0 | 5223 | gdb_assert (b != NULL); |
18a18393 | 5224 | |
b775012e LM |
5225 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5226 | need to do so again since GDB does not know if we stopped due to a | |
5227 | breakpoint or a single step breakpoint. */ | |
5228 | ||
18a18393 | 5229 | if (frame_id_p (b->frame_id) |
edb3359d | 5230 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5231 | { |
7d4df6a4 DE |
5232 | bs->stop = 0; |
5233 | return; | |
5234 | } | |
60e1c644 | 5235 | |
12ab52e9 PA |
5236 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5237 | evaluating the condition if this isn't the specified | |
5238 | thread/task. */ | |
5d5658a1 | 5239 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5240 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5241 | ||
6c1b0f7b DE |
5242 | { |
5243 | bs->stop = 0; | |
5244 | return; | |
5245 | } | |
5246 | ||
6dddc817 DE |
5247 | /* Evaluate extension language breakpoints that have a "stop" method |
5248 | implemented. */ | |
5249 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5250 | |
7d4df6a4 DE |
5251 | if (is_watchpoint (b)) |
5252 | { | |
5253 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5254 | |
4d01a485 | 5255 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5256 | } |
5257 | else | |
4d01a485 | 5258 | cond = bl->cond.get (); |
60e1c644 | 5259 | |
7d4df6a4 DE |
5260 | if (cond && b->disposition != disp_del_at_next_stop) |
5261 | { | |
5262 | int within_current_scope = 1; | |
5263 | struct watchpoint * w; | |
60e1c644 | 5264 | |
7d4df6a4 DE |
5265 | /* We use value_mark and value_free_to_mark because it could |
5266 | be a long time before we return to the command level and | |
5267 | call free_all_values. We can't call free_all_values | |
5268 | because we might be in the middle of evaluating a | |
5269 | function call. */ | |
5270 | struct value *mark = value_mark (); | |
5271 | ||
5272 | if (is_watchpoint (b)) | |
5273 | w = (struct watchpoint *) b; | |
5274 | else | |
5275 | w = NULL; | |
5276 | ||
5277 | /* Need to select the frame, with all that implies so that | |
5278 | the conditions will have the right context. Because we | |
5279 | use the frame, we will not see an inlined function's | |
5280 | variables when we arrive at a breakpoint at the start | |
5281 | of the inlined function; the current frame will be the | |
5282 | call site. */ | |
5283 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5284 | select_frame (get_current_frame ()); | |
5285 | else | |
18a18393 | 5286 | { |
7d4df6a4 DE |
5287 | struct frame_info *frame; |
5288 | ||
5289 | /* For local watchpoint expressions, which particular | |
5290 | instance of a local is being watched matters, so we | |
5291 | keep track of the frame to evaluate the expression | |
5292 | in. To evaluate the condition however, it doesn't | |
5293 | really matter which instantiation of the function | |
5294 | where the condition makes sense triggers the | |
5295 | watchpoint. This allows an expression like "watch | |
5296 | global if q > 10" set in `func', catch writes to | |
5297 | global on all threads that call `func', or catch | |
5298 | writes on all recursive calls of `func' by a single | |
5299 | thread. We simply always evaluate the condition in | |
5300 | the innermost frame that's executing where it makes | |
5301 | sense to evaluate the condition. It seems | |
5302 | intuitive. */ | |
5303 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5304 | if (frame != NULL) | |
5305 | select_frame (frame); | |
5306 | else | |
5307 | within_current_scope = 0; | |
18a18393 | 5308 | } |
7d4df6a4 | 5309 | if (within_current_scope) |
bf469271 PA |
5310 | { |
5311 | TRY | |
5312 | { | |
5313 | condition_result = breakpoint_cond_eval (cond); | |
5314 | } | |
5315 | CATCH (ex, RETURN_MASK_ALL) | |
5316 | { | |
5317 | exception_fprintf (gdb_stderr, ex, | |
5318 | "Error in testing breakpoint condition:\n"); | |
5319 | } | |
5320 | END_CATCH | |
5321 | } | |
7d4df6a4 | 5322 | else |
18a18393 | 5323 | { |
7d4df6a4 DE |
5324 | warning (_("Watchpoint condition cannot be tested " |
5325 | "in the current scope")); | |
5326 | /* If we failed to set the right context for this | |
5327 | watchpoint, unconditionally report it. */ | |
18a18393 | 5328 | } |
7d4df6a4 DE |
5329 | /* FIXME-someday, should give breakpoint #. */ |
5330 | value_free_to_mark (mark); | |
18a18393 | 5331 | } |
7d4df6a4 | 5332 | |
bf469271 | 5333 | if (cond && !condition_result) |
7d4df6a4 DE |
5334 | { |
5335 | bs->stop = 0; | |
5336 | } | |
7d4df6a4 DE |
5337 | else if (b->ignore_count > 0) |
5338 | { | |
5339 | b->ignore_count--; | |
5340 | bs->stop = 0; | |
5341 | /* Increase the hit count even though we don't stop. */ | |
5342 | ++(b->hit_count); | |
5343 | observer_notify_breakpoint_modified (b); | |
5344 | } | |
18a18393 VP |
5345 | } |
5346 | ||
1cf4d951 PA |
5347 | /* Returns true if we need to track moribund locations of LOC's type |
5348 | on the current target. */ | |
5349 | ||
5350 | static int | |
5351 | need_moribund_for_location_type (struct bp_location *loc) | |
5352 | { | |
5353 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5354 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5355 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5356 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5357 | } | |
5358 | ||
18a18393 | 5359 | |
9709f61c | 5360 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5361 | BP_ADDR in thread PTID. |
c906108c | 5362 | |
d983da9c | 5363 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5364 | don't understand this stop. Result is a chain of bpstat's such |
5365 | that: | |
c906108c | 5366 | |
c5aa993b | 5367 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5368 | |
c5aa993b | 5369 | if we understand why we stopped, the result is not null. |
c906108c | 5370 | |
c5aa993b JM |
5371 | Each element of the chain refers to a particular breakpoint or |
5372 | watchpoint at which we have stopped. (We may have stopped for | |
5373 | several reasons concurrently.) | |
c906108c | 5374 | |
c5aa993b JM |
5375 | Each element of the chain has valid next, breakpoint_at, |
5376 | commands, FIXME??? fields. */ | |
c906108c SS |
5377 | |
5378 | bpstat | |
accd0bcd | 5379 | bpstat_stop_status (const address_space *aspace, |
09ac7c10 TT |
5380 | CORE_ADDR bp_addr, ptid_t ptid, |
5381 | const struct target_waitstatus *ws) | |
c906108c | 5382 | { |
0d381245 | 5383 | struct breakpoint *b = NULL; |
afe38095 | 5384 | struct bp_location *bl; |
20874c92 | 5385 | struct bp_location *loc; |
5760d0ab JK |
5386 | /* First item of allocated bpstat's. */ |
5387 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5388 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5389 | bpstat bs; |
20874c92 | 5390 | int ix; |
429374b8 | 5391 | int need_remove_insert; |
f431efe5 | 5392 | int removed_any; |
c906108c | 5393 | |
f431efe5 PA |
5394 | /* First, build the bpstat chain with locations that explain a |
5395 | target stop, while being careful to not set the target running, | |
5396 | as that may invalidate locations (in particular watchpoint | |
5397 | locations are recreated). Resuming will happen here with | |
5398 | breakpoint conditions or watchpoint expressions that include | |
5399 | inferior function calls. */ | |
c5aa993b | 5400 | |
429374b8 JK |
5401 | ALL_BREAKPOINTS (b) |
5402 | { | |
1a853c52 | 5403 | if (!breakpoint_enabled (b)) |
429374b8 | 5404 | continue; |
a5606eee | 5405 | |
429374b8 JK |
5406 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5407 | { | |
4a64f543 MS |
5408 | /* For hardware watchpoints, we look only at the first |
5409 | location. The watchpoint_check function will work on the | |
5410 | entire expression, not the individual locations. For | |
5411 | read watchpoints, the watchpoints_triggered function has | |
5412 | checked all locations already. */ | |
429374b8 JK |
5413 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5414 | break; | |
18a18393 | 5415 | |
f6592439 | 5416 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5417 | continue; |
c5aa993b | 5418 | |
09ac7c10 | 5419 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5420 | continue; |
c5aa993b | 5421 | |
4a64f543 MS |
5422 | /* Come here if it's a watchpoint, or if the break address |
5423 | matches. */ | |
c5aa993b | 5424 | |
04afa70c | 5425 | bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
4a64f543 | 5426 | explain stop. */ |
c5aa993b | 5427 | |
f431efe5 PA |
5428 | /* Assume we stop. Should we find a watchpoint that is not |
5429 | actually triggered, or if the condition of the breakpoint | |
5430 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5431 | bs->stop = 1; |
5432 | bs->print = 1; | |
d983da9c | 5433 | |
f431efe5 PA |
5434 | /* If this is a scope breakpoint, mark the associated |
5435 | watchpoint as triggered so that we will handle the | |
5436 | out-of-scope event. We'll get to the watchpoint next | |
5437 | iteration. */ | |
d0fb5eae | 5438 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5439 | { |
5440 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5441 | ||
5442 | w->watchpoint_triggered = watch_triggered_yes; | |
5443 | } | |
f431efe5 PA |
5444 | } |
5445 | } | |
5446 | ||
7c16b83e | 5447 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5448 | if (!target_supports_stopped_by_sw_breakpoint () |
5449 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5450 | { |
1cf4d951 | 5451 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5452 | { |
1cf4d951 PA |
5453 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5454 | && need_moribund_for_location_type (loc)) | |
5455 | { | |
04afa70c | 5456 | bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5457 | /* For hits of moribund locations, we should just proceed. */ |
5458 | bs->stop = 0; | |
5459 | bs->print = 0; | |
5460 | bs->print_it = print_it_noop; | |
5461 | } | |
f431efe5 PA |
5462 | } |
5463 | } | |
5464 | ||
edcc5120 TT |
5465 | /* A bit of special processing for shlib breakpoints. We need to |
5466 | process solib loading here, so that the lists of loaded and | |
5467 | unloaded libraries are correct before we handle "catch load" and | |
5468 | "catch unload". */ | |
5469 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5470 | { | |
5d268276 | 5471 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5472 | { |
5473 | handle_solib_event (); | |
5474 | break; | |
5475 | } | |
5476 | } | |
5477 | ||
f431efe5 PA |
5478 | /* Now go through the locations that caused the target to stop, and |
5479 | check whether we're interested in reporting this stop to higher | |
5480 | layers, or whether we should resume the target transparently. */ | |
5481 | ||
5482 | removed_any = 0; | |
5483 | ||
5760d0ab | 5484 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5485 | { |
5486 | if (!bs->stop) | |
5487 | continue; | |
5488 | ||
f431efe5 | 5489 | b = bs->breakpoint_at; |
348d480f PA |
5490 | b->ops->check_status (bs); |
5491 | if (bs->stop) | |
28010a5d | 5492 | { |
348d480f | 5493 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5494 | |
429374b8 JK |
5495 | if (bs->stop) |
5496 | { | |
5497 | ++(b->hit_count); | |
8d3788bd | 5498 | observer_notify_breakpoint_modified (b); |
c906108c | 5499 | |
4a64f543 | 5500 | /* We will stop here. */ |
429374b8 JK |
5501 | if (b->disposition == disp_disable) |
5502 | { | |
816338b5 | 5503 | --(b->enable_count); |
1a853c52 | 5504 | if (b->enable_count <= 0) |
429374b8 | 5505 | b->enable_state = bp_disabled; |
f431efe5 | 5506 | removed_any = 1; |
429374b8 JK |
5507 | } |
5508 | if (b->silent) | |
5509 | bs->print = 0; | |
5510 | bs->commands = b->commands; | |
abf85f46 | 5511 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5512 | ? bs->commands.get () : NULL)) |
abf85f46 | 5513 | bs->print = 0; |
9d6e6e84 HZ |
5514 | |
5515 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5516 | } |
5517 | ||
348d480f | 5518 | } |
a9b3a50f PA |
5519 | |
5520 | /* Print nothing for this entry if we don't stop or don't | |
5521 | print. */ | |
5522 | if (!bs->stop || !bs->print) | |
5523 | bs->print_it = print_it_noop; | |
429374b8 | 5524 | } |
876fa593 | 5525 | |
d983da9c DJ |
5526 | /* If we aren't stopping, the value of some hardware watchpoint may |
5527 | not have changed, but the intermediate memory locations we are | |
5528 | watching may have. Don't bother if we're stopping; this will get | |
5529 | done later. */ | |
d832cb68 | 5530 | need_remove_insert = 0; |
5760d0ab JK |
5531 | if (! bpstat_causes_stop (bs_head)) |
5532 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5533 | if (!bs->stop |
f431efe5 PA |
5534 | && bs->breakpoint_at |
5535 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5536 | { |
3a5c3e22 PA |
5537 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5538 | ||
5539 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5540 | need_remove_insert = 1; |
d983da9c DJ |
5541 | } |
5542 | ||
d832cb68 | 5543 | if (need_remove_insert) |
44702360 | 5544 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5545 | else if (removed_any) |
44702360 | 5546 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5547 | |
5760d0ab | 5548 | return bs_head; |
c906108c | 5549 | } |
628fe4e4 JK |
5550 | |
5551 | static void | |
5552 | handle_jit_event (void) | |
5553 | { | |
5554 | struct frame_info *frame; | |
5555 | struct gdbarch *gdbarch; | |
5556 | ||
243a9253 PA |
5557 | if (debug_infrun) |
5558 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5559 | ||
628fe4e4 JK |
5560 | /* Switch terminal for any messages produced by |
5561 | breakpoint_re_set. */ | |
223ffa71 | 5562 | target_terminal::ours_for_output (); |
628fe4e4 JK |
5563 | |
5564 | frame = get_current_frame (); | |
5565 | gdbarch = get_frame_arch (frame); | |
5566 | ||
5567 | jit_event_handler (gdbarch); | |
5568 | ||
223ffa71 | 5569 | target_terminal::inferior (); |
628fe4e4 JK |
5570 | } |
5571 | ||
5572 | /* Prepare WHAT final decision for infrun. */ | |
5573 | ||
5574 | /* Decide what infrun needs to do with this bpstat. */ | |
5575 | ||
c906108c | 5576 | struct bpstat_what |
0e30163f | 5577 | bpstat_what (bpstat bs_head) |
c906108c | 5578 | { |
c906108c | 5579 | struct bpstat_what retval; |
0e30163f | 5580 | bpstat bs; |
c906108c | 5581 | |
628fe4e4 | 5582 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5583 | retval.call_dummy = STOP_NONE; |
186c406b | 5584 | retval.is_longjmp = 0; |
628fe4e4 | 5585 | |
0e30163f | 5586 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5587 | { |
628fe4e4 JK |
5588 | /* Extract this BS's action. After processing each BS, we check |
5589 | if its action overrides all we've seem so far. */ | |
5590 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5591 | enum bptype bptype; | |
5592 | ||
c906108c | 5593 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5594 | { |
5595 | /* I suspect this can happen if it was a momentary | |
5596 | breakpoint which has since been deleted. */ | |
5597 | bptype = bp_none; | |
5598 | } | |
20874c92 | 5599 | else |
f431efe5 | 5600 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5601 | |
5602 | switch (bptype) | |
c906108c SS |
5603 | { |
5604 | case bp_none: | |
628fe4e4 | 5605 | break; |
c906108c SS |
5606 | case bp_breakpoint: |
5607 | case bp_hardware_breakpoint: | |
7c16b83e | 5608 | case bp_single_step: |
c906108c SS |
5609 | case bp_until: |
5610 | case bp_finish: | |
a9b3a50f | 5611 | case bp_shlib_event: |
c906108c SS |
5612 | if (bs->stop) |
5613 | { | |
5614 | if (bs->print) | |
628fe4e4 | 5615 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5616 | else |
628fe4e4 | 5617 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5618 | } |
5619 | else | |
628fe4e4 | 5620 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5621 | break; |
5622 | case bp_watchpoint: | |
5623 | case bp_hardware_watchpoint: | |
5624 | case bp_read_watchpoint: | |
5625 | case bp_access_watchpoint: | |
5626 | if (bs->stop) | |
5627 | { | |
5628 | if (bs->print) | |
628fe4e4 | 5629 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5630 | else |
628fe4e4 | 5631 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5632 | } |
5633 | else | |
628fe4e4 JK |
5634 | { |
5635 | /* There was a watchpoint, but we're not stopping. | |
5636 | This requires no further action. */ | |
5637 | } | |
c906108c SS |
5638 | break; |
5639 | case bp_longjmp: | |
e2e4d78b | 5640 | case bp_longjmp_call_dummy: |
186c406b | 5641 | case bp_exception: |
0a39bb32 PA |
5642 | if (bs->stop) |
5643 | { | |
5644 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5645 | retval.is_longjmp = bptype != bp_exception; | |
5646 | } | |
5647 | else | |
5648 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5649 | break; |
5650 | case bp_longjmp_resume: | |
186c406b | 5651 | case bp_exception_resume: |
0a39bb32 PA |
5652 | if (bs->stop) |
5653 | { | |
5654 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5655 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5656 | } | |
5657 | else | |
5658 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5659 | break; |
5660 | case bp_step_resume: | |
5661 | if (bs->stop) | |
628fe4e4 JK |
5662 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5663 | else | |
c906108c | 5664 | { |
628fe4e4 JK |
5665 | /* It is for the wrong frame. */ |
5666 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5667 | } |
c906108c | 5668 | break; |
2c03e5be PA |
5669 | case bp_hp_step_resume: |
5670 | if (bs->stop) | |
5671 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5672 | else | |
5673 | { | |
5674 | /* It is for the wrong frame. */ | |
5675 | this_action = BPSTAT_WHAT_SINGLE; | |
5676 | } | |
5677 | break; | |
c906108c | 5678 | case bp_watchpoint_scope: |
c4093a6a | 5679 | case bp_thread_event: |
1900040c | 5680 | case bp_overlay_event: |
0fd8e87f | 5681 | case bp_longjmp_master: |
aa7d318d | 5682 | case bp_std_terminate_master: |
186c406b | 5683 | case bp_exception_master: |
628fe4e4 | 5684 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5685 | break; |
ce78b96d | 5686 | case bp_catchpoint: |
c5aa993b JM |
5687 | if (bs->stop) |
5688 | { | |
5689 | if (bs->print) | |
628fe4e4 | 5690 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5691 | else |
628fe4e4 | 5692 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5693 | } |
5694 | else | |
628fe4e4 JK |
5695 | { |
5696 | /* There was a catchpoint, but we're not stopping. | |
5697 | This requires no further action. */ | |
5698 | } | |
5699 | break; | |
628fe4e4 | 5700 | case bp_jit_event: |
628fe4e4 | 5701 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5702 | break; |
c906108c | 5703 | case bp_call_dummy: |
53a5351d JM |
5704 | /* Make sure the action is stop (silent or noisy), |
5705 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5706 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5707 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5708 | break; |
5709 | case bp_std_terminate: | |
5710 | /* Make sure the action is stop (silent or noisy), | |
5711 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5712 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5713 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5714 | break; |
1042e4c0 | 5715 | case bp_tracepoint: |
7a697b8d | 5716 | case bp_fast_tracepoint: |
0fb4aa4b | 5717 | case bp_static_tracepoint: |
1042e4c0 SS |
5718 | /* Tracepoint hits should not be reported back to GDB, and |
5719 | if one got through somehow, it should have been filtered | |
5720 | out already. */ | |
5721 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5722 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5723 | break; |
5724 | case bp_gnu_ifunc_resolver: | |
5725 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5726 | this_action = BPSTAT_WHAT_SINGLE; | |
5727 | break; | |
5728 | case bp_gnu_ifunc_resolver_return: | |
5729 | /* The breakpoint will be removed, execution will restart from the | |
5730 | PC of the former breakpoint. */ | |
5731 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5732 | break; | |
e7e0cddf SS |
5733 | |
5734 | case bp_dprintf: | |
a11cfd87 HZ |
5735 | if (bs->stop) |
5736 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5737 | else | |
5738 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5739 | break; |
5740 | ||
628fe4e4 JK |
5741 | default: |
5742 | internal_error (__FILE__, __LINE__, | |
5743 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5744 | } |
628fe4e4 | 5745 | |
325fac50 | 5746 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5747 | } |
628fe4e4 | 5748 | |
243a9253 PA |
5749 | return retval; |
5750 | } | |
628fe4e4 | 5751 | |
243a9253 PA |
5752 | void |
5753 | bpstat_run_callbacks (bpstat bs_head) | |
5754 | { | |
5755 | bpstat bs; | |
628fe4e4 | 5756 | |
0e30163f JK |
5757 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5758 | { | |
5759 | struct breakpoint *b = bs->breakpoint_at; | |
5760 | ||
5761 | if (b == NULL) | |
5762 | continue; | |
5763 | switch (b->type) | |
5764 | { | |
243a9253 PA |
5765 | case bp_jit_event: |
5766 | handle_jit_event (); | |
5767 | break; | |
0e30163f JK |
5768 | case bp_gnu_ifunc_resolver: |
5769 | gnu_ifunc_resolver_stop (b); | |
5770 | break; | |
5771 | case bp_gnu_ifunc_resolver_return: | |
5772 | gnu_ifunc_resolver_return_stop (b); | |
5773 | break; | |
5774 | } | |
5775 | } | |
c906108c SS |
5776 | } |
5777 | ||
5778 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5779 | without hardware support). This isn't related to a specific bpstat, | |
5780 | just to things like whether watchpoints are set. */ | |
5781 | ||
c5aa993b | 5782 | int |
fba45db2 | 5783 | bpstat_should_step (void) |
c906108c SS |
5784 | { |
5785 | struct breakpoint *b; | |
cc59ec59 | 5786 | |
c906108c | 5787 | ALL_BREAKPOINTS (b) |
717a8278 | 5788 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5789 | return 1; |
c906108c SS |
5790 | return 0; |
5791 | } | |
5792 | ||
67822962 PA |
5793 | int |
5794 | bpstat_causes_stop (bpstat bs) | |
5795 | { | |
5796 | for (; bs != NULL; bs = bs->next) | |
5797 | if (bs->stop) | |
5798 | return 1; | |
5799 | ||
5800 | return 0; | |
5801 | } | |
5802 | ||
c906108c | 5803 | \f |
c5aa993b | 5804 | |
170b53b2 UW |
5805 | /* Compute a string of spaces suitable to indent the next line |
5806 | so it starts at the position corresponding to the table column | |
5807 | named COL_NAME in the currently active table of UIOUT. */ | |
5808 | ||
5809 | static char * | |
5810 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5811 | { | |
5812 | static char wrap_indent[80]; | |
5813 | int i, total_width, width, align; | |
c5209615 | 5814 | const char *text; |
170b53b2 UW |
5815 | |
5816 | total_width = 0; | |
112e8700 | 5817 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5818 | { |
5819 | if (strcmp (text, col_name) == 0) | |
5820 | { | |
5821 | gdb_assert (total_width < sizeof wrap_indent); | |
5822 | memset (wrap_indent, ' ', total_width); | |
5823 | wrap_indent[total_width] = 0; | |
5824 | ||
5825 | return wrap_indent; | |
5826 | } | |
5827 | ||
5828 | total_width += width + 1; | |
5829 | } | |
5830 | ||
5831 | return NULL; | |
5832 | } | |
5833 | ||
b775012e LM |
5834 | /* Determine if the locations of this breakpoint will have their conditions |
5835 | evaluated by the target, host or a mix of both. Returns the following: | |
5836 | ||
5837 | "host": Host evals condition. | |
5838 | "host or target": Host or Target evals condition. | |
5839 | "target": Target evals condition. | |
5840 | */ | |
5841 | ||
5842 | static const char * | |
5843 | bp_condition_evaluator (struct breakpoint *b) | |
5844 | { | |
5845 | struct bp_location *bl; | |
5846 | char host_evals = 0; | |
5847 | char target_evals = 0; | |
5848 | ||
5849 | if (!b) | |
5850 | return NULL; | |
5851 | ||
5852 | if (!is_breakpoint (b)) | |
5853 | return NULL; | |
5854 | ||
5855 | if (gdb_evaluates_breakpoint_condition_p () | |
5856 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5857 | return condition_evaluation_host; | |
5858 | ||
5859 | for (bl = b->loc; bl; bl = bl->next) | |
5860 | { | |
5861 | if (bl->cond_bytecode) | |
5862 | target_evals++; | |
5863 | else | |
5864 | host_evals++; | |
5865 | } | |
5866 | ||
5867 | if (host_evals && target_evals) | |
5868 | return condition_evaluation_both; | |
5869 | else if (target_evals) | |
5870 | return condition_evaluation_target; | |
5871 | else | |
5872 | return condition_evaluation_host; | |
5873 | } | |
5874 | ||
5875 | /* Determine the breakpoint location's condition evaluator. This is | |
5876 | similar to bp_condition_evaluator, but for locations. */ | |
5877 | ||
5878 | static const char * | |
5879 | bp_location_condition_evaluator (struct bp_location *bl) | |
5880 | { | |
5881 | if (bl && !is_breakpoint (bl->owner)) | |
5882 | return NULL; | |
5883 | ||
5884 | if (gdb_evaluates_breakpoint_condition_p () | |
5885 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5886 | return condition_evaluation_host; | |
5887 | ||
5888 | if (bl && bl->cond_bytecode) | |
5889 | return condition_evaluation_target; | |
5890 | else | |
5891 | return condition_evaluation_host; | |
5892 | } | |
5893 | ||
859825b8 JK |
5894 | /* Print the LOC location out of the list of B->LOC locations. */ |
5895 | ||
170b53b2 UW |
5896 | static void |
5897 | print_breakpoint_location (struct breakpoint *b, | |
5898 | struct bp_location *loc) | |
0d381245 | 5899 | { |
79a45e25 | 5900 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5901 | |
5902 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5903 | |
859825b8 JK |
5904 | if (loc != NULL && loc->shlib_disabled) |
5905 | loc = NULL; | |
5906 | ||
6c95b8df PA |
5907 | if (loc != NULL) |
5908 | set_current_program_space (loc->pspace); | |
5909 | ||
56435ebe | 5910 | if (b->display_canonical) |
d28cd78a | 5911 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 5912 | else if (loc && loc->symtab) |
0d381245 | 5913 | { |
4a27f119 KS |
5914 | const struct symbol *sym = loc->symbol; |
5915 | ||
5916 | if (sym == NULL) | |
5917 | sym = find_pc_sect_function (loc->address, loc->section); | |
5918 | ||
0d381245 VP |
5919 | if (sym) |
5920 | { | |
112e8700 SM |
5921 | uiout->text ("in "); |
5922 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); | |
5923 | uiout->text (" "); | |
5924 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
5925 | uiout->text ("at "); | |
0d381245 | 5926 | } |
112e8700 | 5927 | uiout->field_string ("file", |
05cba821 | 5928 | symtab_to_filename_for_display (loc->symtab)); |
112e8700 | 5929 | uiout->text (":"); |
05cba821 | 5930 | |
112e8700 SM |
5931 | if (uiout->is_mi_like_p ()) |
5932 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 5933 | |
112e8700 | 5934 | uiout->field_int ("line", loc->line_number); |
0d381245 | 5935 | } |
859825b8 | 5936 | else if (loc) |
0d381245 | 5937 | { |
d7e74731 | 5938 | string_file stb; |
170b53b2 | 5939 | |
d7e74731 | 5940 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 5941 | demangle, ""); |
112e8700 | 5942 | uiout->field_stream ("at", stb); |
0d381245 | 5943 | } |
859825b8 | 5944 | else |
f00aae0f | 5945 | { |
d28cd78a TT |
5946 | uiout->field_string ("pending", |
5947 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
5948 | /* If extra_string is available, it could be holding a condition |
5949 | or dprintf arguments. In either case, make sure it is printed, | |
5950 | too, but only for non-MI streams. */ | |
112e8700 | 5951 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
5952 | { |
5953 | if (b->type == bp_dprintf) | |
112e8700 | 5954 | uiout->text (","); |
f00aae0f | 5955 | else |
112e8700 SM |
5956 | uiout->text (" "); |
5957 | uiout->text (b->extra_string); | |
f00aae0f KS |
5958 | } |
5959 | } | |
6c95b8df | 5960 | |
b775012e LM |
5961 | if (loc && is_breakpoint (b) |
5962 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5963 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5964 | { | |
112e8700 SM |
5965 | uiout->text (" ("); |
5966 | uiout->field_string ("evaluated-by", | |
b775012e | 5967 | bp_location_condition_evaluator (loc)); |
112e8700 | 5968 | uiout->text (")"); |
b775012e | 5969 | } |
0d381245 VP |
5970 | } |
5971 | ||
269b11a2 PA |
5972 | static const char * |
5973 | bptype_string (enum bptype type) | |
c906108c | 5974 | { |
c4093a6a JM |
5975 | struct ep_type_description |
5976 | { | |
5977 | enum bptype type; | |
a121b7c1 | 5978 | const char *description; |
c4093a6a JM |
5979 | }; |
5980 | static struct ep_type_description bptypes[] = | |
c906108c | 5981 | { |
c5aa993b JM |
5982 | {bp_none, "?deleted?"}, |
5983 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5984 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 5985 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
5986 | {bp_until, "until"}, |
5987 | {bp_finish, "finish"}, | |
5988 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5989 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5990 | {bp_read_watchpoint, "read watchpoint"}, |
5991 | {bp_access_watchpoint, "acc watchpoint"}, | |
5992 | {bp_longjmp, "longjmp"}, | |
5993 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5994 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5995 | {bp_exception, "exception"}, |
5996 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5997 | {bp_step_resume, "step resume"}, |
2c03e5be | 5998 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5999 | {bp_watchpoint_scope, "watchpoint scope"}, |
6000 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6001 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6002 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6003 | {bp_thread_event, "thread events"}, |
1900040c | 6004 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6005 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6006 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6007 | {bp_exception_master, "exception master"}, |
ce78b96d | 6008 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6009 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6010 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6011 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6012 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6013 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6014 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6015 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6016 | }; |
269b11a2 PA |
6017 | |
6018 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6019 | || ((int) type != bptypes[(int) type].type)) | |
6020 | internal_error (__FILE__, __LINE__, | |
6021 | _("bptypes table does not describe type #%d."), | |
6022 | (int) type); | |
6023 | ||
6024 | return bptypes[(int) type].description; | |
6025 | } | |
6026 | ||
998580f1 MK |
6027 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6028 | For CLI, prefix the list with the string 'inf'. */ | |
6029 | ||
6030 | static void | |
6031 | output_thread_groups (struct ui_out *uiout, | |
6032 | const char *field_name, | |
5c632425 | 6033 | const std::vector<int> &inf_nums, |
998580f1 MK |
6034 | int mi_only) |
6035 | { | |
112e8700 | 6036 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6037 | |
6038 | /* For backward compatibility, don't display inferiors in CLI unless | |
6039 | there are several. Always display them for MI. */ | |
6040 | if (!is_mi && mi_only) | |
6041 | return; | |
6042 | ||
10f489e5 | 6043 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6044 | |
5c632425 | 6045 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
6046 | { |
6047 | if (is_mi) | |
6048 | { | |
6049 | char mi_group[10]; | |
6050 | ||
5c632425 | 6051 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 6052 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6053 | } |
6054 | else | |
6055 | { | |
6056 | if (i == 0) | |
112e8700 | 6057 | uiout->text (" inf "); |
998580f1 | 6058 | else |
112e8700 | 6059 | uiout->text (", "); |
998580f1 | 6060 | |
5c632425 | 6061 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
6062 | } |
6063 | } | |
998580f1 MK |
6064 | } |
6065 | ||
269b11a2 PA |
6066 | /* Print B to gdb_stdout. */ |
6067 | ||
6068 | static void | |
6069 | print_one_breakpoint_location (struct breakpoint *b, | |
6070 | struct bp_location *loc, | |
6071 | int loc_number, | |
6072 | struct bp_location **last_loc, | |
269b11a2 PA |
6073 | int allflag) |
6074 | { | |
6075 | struct command_line *l; | |
c2c6d25f | 6076 | static char bpenables[] = "nynny"; |
c906108c | 6077 | |
79a45e25 | 6078 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6079 | int header_of_multiple = 0; |
6080 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6081 | struct value_print_options opts; |
6082 | ||
6083 | get_user_print_options (&opts); | |
0d381245 VP |
6084 | |
6085 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6086 | /* See comment in print_one_breakpoint concerning treatment of |
6087 | breakpoints with single disabled location. */ | |
0d381245 VP |
6088 | if (loc == NULL |
6089 | && (b->loc != NULL | |
6090 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6091 | header_of_multiple = 1; | |
6092 | if (loc == NULL) | |
6093 | loc = b->loc; | |
6094 | ||
c4093a6a JM |
6095 | annotate_record (); |
6096 | ||
6097 | /* 1 */ | |
6098 | annotate_field (0); | |
0d381245 VP |
6099 | if (part_of_multiple) |
6100 | { | |
6101 | char *formatted; | |
0c6773c1 | 6102 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
112e8700 | 6103 | uiout->field_string ("number", formatted); |
0d381245 VP |
6104 | xfree (formatted); |
6105 | } | |
6106 | else | |
6107 | { | |
112e8700 | 6108 | uiout->field_int ("number", b->number); |
0d381245 | 6109 | } |
c4093a6a JM |
6110 | |
6111 | /* 2 */ | |
6112 | annotate_field (1); | |
0d381245 | 6113 | if (part_of_multiple) |
112e8700 | 6114 | uiout->field_skip ("type"); |
269b11a2 | 6115 | else |
112e8700 | 6116 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6117 | |
6118 | /* 3 */ | |
6119 | annotate_field (2); | |
0d381245 | 6120 | if (part_of_multiple) |
112e8700 | 6121 | uiout->field_skip ("disp"); |
0d381245 | 6122 | else |
112e8700 | 6123 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6124 | |
c4093a6a JM |
6125 | |
6126 | /* 4 */ | |
6127 | annotate_field (3); | |
0d381245 | 6128 | if (part_of_multiple) |
112e8700 | 6129 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6130 | else |
112e8700 SM |
6131 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
6132 | uiout->spaces (2); | |
0d381245 | 6133 | |
c4093a6a JM |
6134 | |
6135 | /* 5 and 6 */ | |
3086aeae | 6136 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6137 | { |
4a64f543 MS |
6138 | /* Although the print_one can possibly print all locations, |
6139 | calling it here is not likely to get any nice result. So, | |
6140 | make sure there's just one location. */ | |
0d381245 | 6141 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6142 | b->ops->print_one (b, last_loc); |
0d381245 | 6143 | } |
3086aeae DJ |
6144 | else |
6145 | switch (b->type) | |
6146 | { | |
6147 | case bp_none: | |
6148 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6149 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6150 | break; |
c906108c | 6151 | |
3086aeae DJ |
6152 | case bp_watchpoint: |
6153 | case bp_hardware_watchpoint: | |
6154 | case bp_read_watchpoint: | |
6155 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6156 | { |
6157 | struct watchpoint *w = (struct watchpoint *) b; | |
6158 | ||
6159 | /* Field 4, the address, is omitted (which makes the columns | |
6160 | not line up too nicely with the headers, but the effect | |
6161 | is relatively readable). */ | |
6162 | if (opts.addressprint) | |
112e8700 | 6163 | uiout->field_skip ("addr"); |
3a5c3e22 | 6164 | annotate_field (5); |
112e8700 | 6165 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6166 | } |
3086aeae DJ |
6167 | break; |
6168 | ||
3086aeae DJ |
6169 | case bp_breakpoint: |
6170 | case bp_hardware_breakpoint: | |
7c16b83e | 6171 | case bp_single_step: |
3086aeae DJ |
6172 | case bp_until: |
6173 | case bp_finish: | |
6174 | case bp_longjmp: | |
6175 | case bp_longjmp_resume: | |
e2e4d78b | 6176 | case bp_longjmp_call_dummy: |
186c406b TT |
6177 | case bp_exception: |
6178 | case bp_exception_resume: | |
3086aeae | 6179 | case bp_step_resume: |
2c03e5be | 6180 | case bp_hp_step_resume: |
3086aeae DJ |
6181 | case bp_watchpoint_scope: |
6182 | case bp_call_dummy: | |
aa7d318d | 6183 | case bp_std_terminate: |
3086aeae DJ |
6184 | case bp_shlib_event: |
6185 | case bp_thread_event: | |
6186 | case bp_overlay_event: | |
0fd8e87f | 6187 | case bp_longjmp_master: |
aa7d318d | 6188 | case bp_std_terminate_master: |
186c406b | 6189 | case bp_exception_master: |
1042e4c0 | 6190 | case bp_tracepoint: |
7a697b8d | 6191 | case bp_fast_tracepoint: |
0fb4aa4b | 6192 | case bp_static_tracepoint: |
e7e0cddf | 6193 | case bp_dprintf: |
4efc6507 | 6194 | case bp_jit_event: |
0e30163f JK |
6195 | case bp_gnu_ifunc_resolver: |
6196 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6197 | if (opts.addressprint) |
3086aeae DJ |
6198 | { |
6199 | annotate_field (4); | |
54e52265 | 6200 | if (header_of_multiple) |
112e8700 | 6201 | uiout->field_string ("addr", "<MULTIPLE>"); |
e9bbd7c5 | 6202 | else if (b->loc == NULL || loc->shlib_disabled) |
112e8700 | 6203 | uiout->field_string ("addr", "<PENDING>"); |
0101ce28 | 6204 | else |
112e8700 | 6205 | uiout->field_core_addr ("addr", |
5af949e3 | 6206 | loc->gdbarch, loc->address); |
3086aeae DJ |
6207 | } |
6208 | annotate_field (5); | |
0d381245 | 6209 | if (!header_of_multiple) |
170b53b2 | 6210 | print_breakpoint_location (b, loc); |
0d381245 | 6211 | if (b->loc) |
a6d9a66e | 6212 | *last_loc = b->loc; |
3086aeae DJ |
6213 | break; |
6214 | } | |
c906108c | 6215 | |
6c95b8df | 6216 | |
998580f1 | 6217 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6218 | { |
6219 | struct inferior *inf; | |
5c632425 | 6220 | std::vector<int> inf_nums; |
998580f1 | 6221 | int mi_only = 1; |
6c95b8df | 6222 | |
998580f1 | 6223 | ALL_INFERIORS (inf) |
6c95b8df PA |
6224 | { |
6225 | if (inf->pspace == loc->pspace) | |
5c632425 | 6226 | inf_nums.push_back (inf->num); |
6c95b8df | 6227 | } |
998580f1 MK |
6228 | |
6229 | /* For backward compatibility, don't display inferiors in CLI unless | |
6230 | there are several. Always display for MI. */ | |
6231 | if (allflag | |
6232 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6233 | && (number_of_program_spaces () > 1 | |
6234 | || number_of_inferiors () > 1) | |
6235 | /* LOC is for existing B, it cannot be in | |
6236 | moribund_locations and thus having NULL OWNER. */ | |
6237 | && loc->owner->type != bp_catchpoint)) | |
6238 | mi_only = 0; | |
5c632425 | 6239 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6240 | } |
6241 | ||
4a306c9a | 6242 | if (!part_of_multiple) |
c4093a6a | 6243 | { |
4a306c9a JB |
6244 | if (b->thread != -1) |
6245 | { | |
6246 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6247 | "stop only in" line a little further down. */ |
112e8700 SM |
6248 | uiout->text (" thread "); |
6249 | uiout->field_int ("thread", b->thread); | |
4a306c9a JB |
6250 | } |
6251 | else if (b->task != 0) | |
6252 | { | |
112e8700 SM |
6253 | uiout->text (" task "); |
6254 | uiout->field_int ("task", b->task); | |
4a306c9a | 6255 | } |
c4093a6a | 6256 | } |
f1310107 | 6257 | |
112e8700 | 6258 | uiout->text ("\n"); |
f1310107 | 6259 | |
348d480f | 6260 | if (!part_of_multiple) |
f1310107 TJB |
6261 | b->ops->print_one_detail (b, uiout); |
6262 | ||
0d381245 | 6263 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6264 | { |
6265 | annotate_field (6); | |
112e8700 | 6266 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6267 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6268 | the frame ID. */ |
112e8700 | 6269 | uiout->field_core_addr ("frame", |
5af949e3 | 6270 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6271 | uiout->text ("\n"); |
c4093a6a JM |
6272 | } |
6273 | ||
28010a5d | 6274 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6275 | { |
6276 | annotate_field (7); | |
d77f58be | 6277 | if (is_tracepoint (b)) |
112e8700 | 6278 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6279 | else |
112e8700 SM |
6280 | uiout->text ("\tstop only if "); |
6281 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6282 | |
6283 | /* Print whether the target is doing the breakpoint's condition | |
6284 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6285 | if (is_breakpoint (b) | |
6286 | && breakpoint_condition_evaluation_mode () | |
6287 | == condition_evaluation_target) | |
6288 | { | |
112e8700 SM |
6289 | uiout->text (" ("); |
6290 | uiout->field_string ("evaluated-by", | |
b775012e | 6291 | bp_condition_evaluator (b)); |
112e8700 | 6292 | uiout->text (" evals)"); |
b775012e | 6293 | } |
112e8700 | 6294 | uiout->text ("\n"); |
0101ce28 JJ |
6295 | } |
6296 | ||
0d381245 | 6297 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6298 | { |
4a64f543 | 6299 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6300 | uiout->text ("\tstop only in thread "); |
6301 | if (uiout->is_mi_like_p ()) | |
6302 | uiout->field_int ("thread", b->thread); | |
5d5658a1 PA |
6303 | else |
6304 | { | |
6305 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6306 | ||
112e8700 | 6307 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6308 | } |
112e8700 | 6309 | uiout->text ("\n"); |
c4093a6a JM |
6310 | } |
6311 | ||
556ec64d YQ |
6312 | if (!part_of_multiple) |
6313 | { | |
6314 | if (b->hit_count) | |
31f56a27 YQ |
6315 | { |
6316 | /* FIXME should make an annotation for this. */ | |
6317 | if (is_catchpoint (b)) | |
112e8700 | 6318 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6319 | else if (is_tracepoint (b)) |
112e8700 | 6320 | uiout->text ("\ttracepoint"); |
31f56a27 | 6321 | else |
112e8700 SM |
6322 | uiout->text ("\tbreakpoint"); |
6323 | uiout->text (" already hit "); | |
6324 | uiout->field_int ("times", b->hit_count); | |
31f56a27 | 6325 | if (b->hit_count == 1) |
112e8700 | 6326 | uiout->text (" time\n"); |
31f56a27 | 6327 | else |
112e8700 | 6328 | uiout->text (" times\n"); |
31f56a27 | 6329 | } |
556ec64d YQ |
6330 | else |
6331 | { | |
31f56a27 | 6332 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 SM |
6333 | if (uiout->is_mi_like_p ()) |
6334 | uiout->field_int ("times", b->hit_count); | |
556ec64d YQ |
6335 | } |
6336 | } | |
8b93c638 | 6337 | |
0d381245 | 6338 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6339 | { |
6340 | annotate_field (8); | |
112e8700 SM |
6341 | uiout->text ("\tignore next "); |
6342 | uiout->field_int ("ignore", b->ignore_count); | |
6343 | uiout->text (" hits\n"); | |
c4093a6a | 6344 | } |
059fb39f | 6345 | |
816338b5 SS |
6346 | /* Note that an enable count of 1 corresponds to "enable once" |
6347 | behavior, which is reported by the combination of enablement and | |
6348 | disposition, so we don't need to mention it here. */ | |
6349 | if (!part_of_multiple && b->enable_count > 1) | |
6350 | { | |
6351 | annotate_field (8); | |
112e8700 | 6352 | uiout->text ("\tdisable after "); |
816338b5 SS |
6353 | /* Tweak the wording to clarify that ignore and enable counts |
6354 | are distinct, and have additive effect. */ | |
6355 | if (b->ignore_count) | |
112e8700 | 6356 | uiout->text ("additional "); |
816338b5 | 6357 | else |
112e8700 SM |
6358 | uiout->text ("next "); |
6359 | uiout->field_int ("enable", b->enable_count); | |
6360 | uiout->text (" hits\n"); | |
816338b5 SS |
6361 | } |
6362 | ||
f196051f SS |
6363 | if (!part_of_multiple && is_tracepoint (b)) |
6364 | { | |
6365 | struct tracepoint *tp = (struct tracepoint *) b; | |
6366 | ||
6367 | if (tp->traceframe_usage) | |
6368 | { | |
112e8700 SM |
6369 | uiout->text ("\ttrace buffer usage "); |
6370 | uiout->field_int ("traceframe-usage", tp->traceframe_usage); | |
6371 | uiout->text (" bytes\n"); | |
f196051f SS |
6372 | } |
6373 | } | |
d3ce09f5 | 6374 | |
d1b0a7bf | 6375 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6376 | if (!part_of_multiple && l) |
c4093a6a JM |
6377 | { |
6378 | annotate_field (9); | |
2e783024 | 6379 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6380 | print_command_lines (uiout, l, 4); |
c4093a6a | 6381 | } |
d24317b4 | 6382 | |
d9b3f62e | 6383 | if (is_tracepoint (b)) |
1042e4c0 | 6384 | { |
d9b3f62e PA |
6385 | struct tracepoint *t = (struct tracepoint *) b; |
6386 | ||
6387 | if (!part_of_multiple && t->pass_count) | |
6388 | { | |
6389 | annotate_field (10); | |
112e8700 SM |
6390 | uiout->text ("\tpass count "); |
6391 | uiout->field_int ("pass", t->pass_count); | |
6392 | uiout->text (" \n"); | |
d9b3f62e | 6393 | } |
f2a8bc8a YQ |
6394 | |
6395 | /* Don't display it when tracepoint or tracepoint location is | |
6396 | pending. */ | |
6397 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6398 | { | |
6399 | annotate_field (11); | |
6400 | ||
112e8700 SM |
6401 | if (uiout->is_mi_like_p ()) |
6402 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6403 | loc->inserted ? "y" : "n"); |
6404 | else | |
6405 | { | |
6406 | if (loc->inserted) | |
112e8700 | 6407 | uiout->text ("\t"); |
f2a8bc8a | 6408 | else |
112e8700 SM |
6409 | uiout->text ("\tnot "); |
6410 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6411 | } |
6412 | } | |
1042e4c0 SS |
6413 | } |
6414 | ||
112e8700 | 6415 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6416 | { |
3a5c3e22 PA |
6417 | if (is_watchpoint (b)) |
6418 | { | |
6419 | struct watchpoint *w = (struct watchpoint *) b; | |
6420 | ||
112e8700 | 6421 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6422 | } |
f00aae0f | 6423 | else if (b->location != NULL |
d28cd78a | 6424 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6425 | uiout->field_string ("original-location", |
d28cd78a | 6426 | event_location_to_string (b->location.get ())); |
d24317b4 | 6427 | } |
c4093a6a | 6428 | } |
c5aa993b | 6429 | |
0d381245 VP |
6430 | static void |
6431 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6432 | struct bp_location **last_loc, |
6c95b8df | 6433 | int allflag) |
0d381245 | 6434 | { |
79a45e25 | 6435 | struct ui_out *uiout = current_uiout; |
8d3788bd | 6436 | |
2e783024 TT |
6437 | { |
6438 | ui_out_emit_tuple tuple_emitter (uiout, "bkpt"); | |
8d3788bd | 6439 | |
2e783024 TT |
6440 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
6441 | } | |
0d381245 VP |
6442 | |
6443 | /* If this breakpoint has custom print function, | |
6444 | it's already printed. Otherwise, print individual | |
6445 | locations, if any. */ | |
6446 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6447 | { | |
4a64f543 MS |
6448 | /* If breakpoint has a single location that is disabled, we |
6449 | print it as if it had several locations, since otherwise it's | |
6450 | hard to represent "breakpoint enabled, location disabled" | |
6451 | situation. | |
6452 | ||
6453 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6454 | internally, that's not a property exposed to user. */ |
0d381245 | 6455 | if (b->loc |
a5606eee | 6456 | && !is_hardware_watchpoint (b) |
8d3788bd | 6457 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6458 | { |
6459 | struct bp_location *loc; | |
6460 | int n = 1; | |
8d3788bd | 6461 | |
0d381245 | 6462 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd | 6463 | { |
2e783024 | 6464 | ui_out_emit_tuple tuple_emitter (uiout, NULL); |
8d3788bd | 6465 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
8d3788bd | 6466 | } |
0d381245 VP |
6467 | } |
6468 | } | |
6469 | } | |
6470 | ||
a6d9a66e UW |
6471 | static int |
6472 | breakpoint_address_bits (struct breakpoint *b) | |
6473 | { | |
6474 | int print_address_bits = 0; | |
6475 | struct bp_location *loc; | |
6476 | ||
c6d81124 PA |
6477 | /* Software watchpoints that aren't watching memory don't have an |
6478 | address to print. */ | |
6479 | if (is_no_memory_software_watchpoint (b)) | |
6480 | return 0; | |
6481 | ||
a6d9a66e UW |
6482 | for (loc = b->loc; loc; loc = loc->next) |
6483 | { | |
c7437ca6 PA |
6484 | int addr_bit; |
6485 | ||
c7437ca6 | 6486 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6487 | if (addr_bit > print_address_bits) |
6488 | print_address_bits = addr_bit; | |
6489 | } | |
6490 | ||
6491 | return print_address_bits; | |
6492 | } | |
0d381245 | 6493 | |
65630365 | 6494 | /* See breakpoint.h. */ |
c5aa993b | 6495 | |
65630365 PA |
6496 | void |
6497 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6498 | { |
a6d9a66e | 6499 | struct bp_location *dummy_loc = NULL; |
65630365 | 6500 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6501 | } |
c5aa993b | 6502 | |
09d682a4 TT |
6503 | /* Return true if this breakpoint was set by the user, false if it is |
6504 | internal or momentary. */ | |
6505 | ||
6506 | int | |
6507 | user_breakpoint_p (struct breakpoint *b) | |
6508 | { | |
46c6471b | 6509 | return b->number > 0; |
09d682a4 TT |
6510 | } |
6511 | ||
93daf339 TT |
6512 | /* See breakpoint.h. */ |
6513 | ||
6514 | int | |
6515 | pending_breakpoint_p (struct breakpoint *b) | |
6516 | { | |
6517 | return b->loc == NULL; | |
6518 | } | |
6519 | ||
7f3b0473 | 6520 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6521 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6522 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6523 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6524 | ones for which it returns non-zero. Return the total number of | |
6525 | breakpoints listed. */ | |
c906108c | 6526 | |
d77f58be | 6527 | static int |
4495129a | 6528 | breakpoint_1 (const char *args, int allflag, |
4a64f543 | 6529 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6530 | { |
52f0bd74 | 6531 | struct breakpoint *b; |
a6d9a66e | 6532 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6533 | int nr_printable_breakpoints; |
79a45b7d | 6534 | struct value_print_options opts; |
a6d9a66e | 6535 | int print_address_bits = 0; |
269b11a2 | 6536 | int print_type_col_width = 14; |
79a45e25 | 6537 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6538 | |
79a45b7d TT |
6539 | get_user_print_options (&opts); |
6540 | ||
4a64f543 MS |
6541 | /* Compute the number of rows in the table, as well as the size |
6542 | required for address fields. */ | |
7f3b0473 AC |
6543 | nr_printable_breakpoints = 0; |
6544 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6545 | { |
6546 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6547 | if (filter && !filter (b)) | |
6548 | continue; | |
6549 | ||
6550 | /* If we have an "args" string, it is a list of breakpoints to | |
6551 | accept. Skip the others. */ | |
6552 | if (args != NULL && *args != '\0') | |
6553 | { | |
6554 | if (allflag && parse_and_eval_long (args) != b->number) | |
6555 | continue; | |
6556 | if (!allflag && !number_is_in_list (args, b->number)) | |
6557 | continue; | |
6558 | } | |
269b11a2 | 6559 | |
e5a67952 MS |
6560 | if (allflag || user_breakpoint_p (b)) |
6561 | { | |
6562 | int addr_bit, type_len; | |
a6d9a66e | 6563 | |
e5a67952 MS |
6564 | addr_bit = breakpoint_address_bits (b); |
6565 | if (addr_bit > print_address_bits) | |
6566 | print_address_bits = addr_bit; | |
269b11a2 | 6567 | |
e5a67952 MS |
6568 | type_len = strlen (bptype_string (b->type)); |
6569 | if (type_len > print_type_col_width) | |
6570 | print_type_col_width = type_len; | |
6571 | ||
6572 | nr_printable_breakpoints++; | |
6573 | } | |
6574 | } | |
7f3b0473 | 6575 | |
4a2b031d TT |
6576 | { |
6577 | ui_out_emit_table table_emitter (uiout, | |
6578 | opts.addressprint ? 6 : 5, | |
6579 | nr_printable_breakpoints, | |
6580 | "BreakpointTable"); | |
6581 | ||
6582 | if (nr_printable_breakpoints > 0) | |
6583 | annotate_breakpoints_headers (); | |
6584 | if (nr_printable_breakpoints > 0) | |
6585 | annotate_field (0); | |
6586 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6587 | if (nr_printable_breakpoints > 0) | |
6588 | annotate_field (1); | |
6589 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6590 | if (nr_printable_breakpoints > 0) | |
6591 | annotate_field (2); | |
6592 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6593 | if (nr_printable_breakpoints > 0) | |
6594 | annotate_field (3); | |
6595 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6596 | if (opts.addressprint) | |
6597 | { | |
6598 | if (nr_printable_breakpoints > 0) | |
6599 | annotate_field (4); | |
6600 | if (print_address_bits <= 32) | |
6601 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6602 | else | |
6603 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6604 | } | |
6605 | if (nr_printable_breakpoints > 0) | |
6606 | annotate_field (5); | |
6607 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6608 | uiout->table_body (); | |
6609 | if (nr_printable_breakpoints > 0) | |
6610 | annotate_breakpoints_table (); | |
6611 | ||
6612 | ALL_BREAKPOINTS (b) | |
6613 | { | |
6614 | QUIT; | |
6615 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6616 | if (filter && !filter (b)) | |
6617 | continue; | |
e5a67952 | 6618 | |
4a2b031d TT |
6619 | /* If we have an "args" string, it is a list of breakpoints to |
6620 | accept. Skip the others. */ | |
e5a67952 | 6621 | |
4a2b031d TT |
6622 | if (args != NULL && *args != '\0') |
6623 | { | |
6624 | if (allflag) /* maintenance info breakpoint */ | |
6625 | { | |
6626 | if (parse_and_eval_long (args) != b->number) | |
6627 | continue; | |
6628 | } | |
6629 | else /* all others */ | |
6630 | { | |
6631 | if (!number_is_in_list (args, b->number)) | |
6632 | continue; | |
6633 | } | |
6634 | } | |
6635 | /* We only print out user settable breakpoints unless the | |
6636 | allflag is set. */ | |
6637 | if (allflag || user_breakpoint_p (b)) | |
6638 | print_one_breakpoint (b, &last_loc, allflag); | |
6639 | } | |
6640 | } | |
698384cd | 6641 | |
7f3b0473 | 6642 | if (nr_printable_breakpoints == 0) |
c906108c | 6643 | { |
4a64f543 MS |
6644 | /* If there's a filter, let the caller decide how to report |
6645 | empty list. */ | |
d77f58be SS |
6646 | if (!filter) |
6647 | { | |
e5a67952 | 6648 | if (args == NULL || *args == '\0') |
112e8700 | 6649 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6650 | else |
112e8700 | 6651 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
e5a67952 | 6652 | args); |
d77f58be | 6653 | } |
c906108c SS |
6654 | } |
6655 | else | |
c4093a6a | 6656 | { |
a6d9a66e UW |
6657 | if (last_loc && !server_command) |
6658 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6659 | } |
c906108c | 6660 | |
4a64f543 | 6661 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6662 | there have been breakpoints? */ |
c906108c | 6663 | annotate_breakpoints_table_end (); |
d77f58be SS |
6664 | |
6665 | return nr_printable_breakpoints; | |
c906108c SS |
6666 | } |
6667 | ||
ad443146 SS |
6668 | /* Display the value of default-collect in a way that is generally |
6669 | compatible with the breakpoint list. */ | |
6670 | ||
6671 | static void | |
6672 | default_collect_info (void) | |
6673 | { | |
79a45e25 PA |
6674 | struct ui_out *uiout = current_uiout; |
6675 | ||
ad443146 SS |
6676 | /* If it has no value (which is frequently the case), say nothing; a |
6677 | message like "No default-collect." gets in user's face when it's | |
6678 | not wanted. */ | |
6679 | if (!*default_collect) | |
6680 | return; | |
6681 | ||
6682 | /* The following phrase lines up nicely with per-tracepoint collect | |
6683 | actions. */ | |
112e8700 SM |
6684 | uiout->text ("default collect "); |
6685 | uiout->field_string ("default-collect", default_collect); | |
6686 | uiout->text (" \n"); | |
ad443146 SS |
6687 | } |
6688 | ||
c906108c | 6689 | static void |
0b39b52e | 6690 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6691 | { |
e5a67952 | 6692 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6693 | |
6694 | default_collect_info (); | |
d77f58be SS |
6695 | } |
6696 | ||
6697 | static void | |
1d12d88f | 6698 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6699 | { |
e5a67952 | 6700 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6701 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6702 | |
6703 | if (num_printed == 0) | |
6704 | { | |
e5a67952 | 6705 | if (args == NULL || *args == '\0') |
112e8700 | 6706 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6707 | else |
112e8700 | 6708 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6709 | } |
c906108c SS |
6710 | } |
6711 | ||
7a292a7a | 6712 | static void |
4495129a | 6713 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6714 | { |
e5a67952 | 6715 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6716 | |
6717 | default_collect_info (); | |
c906108c SS |
6718 | } |
6719 | ||
0d381245 | 6720 | static int |
714835d5 | 6721 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6722 | struct program_space *pspace, |
714835d5 | 6723 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6724 | { |
6725 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6726 | |
0d381245 VP |
6727 | for (; bl; bl = bl->next) |
6728 | { | |
6c95b8df PA |
6729 | if (bl->pspace == pspace |
6730 | && bl->address == pc | |
0d381245 VP |
6731 | && (!overlay_debugging || bl->section == section)) |
6732 | return 1; | |
6733 | } | |
6734 | return 0; | |
6735 | } | |
6736 | ||
672f9b60 | 6737 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6738 | concerns with logical breakpoints, so we match program spaces, not |
6739 | address spaces. */ | |
c906108c SS |
6740 | |
6741 | static void | |
6c95b8df PA |
6742 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6743 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6744 | struct obj_section *section, int thread) |
c906108c | 6745 | { |
52f0bd74 AC |
6746 | int others = 0; |
6747 | struct breakpoint *b; | |
c906108c SS |
6748 | |
6749 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6750 | others += (user_breakpoint_p (b) |
6751 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6752 | if (others > 0) |
6753 | { | |
a3f17187 AC |
6754 | if (others == 1) |
6755 | printf_filtered (_("Note: breakpoint ")); | |
6756 | else /* if (others == ???) */ | |
6757 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6758 | ALL_BREAKPOINTS (b) |
672f9b60 | 6759 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6760 | { |
6761 | others--; | |
6762 | printf_filtered ("%d", b->number); | |
6763 | if (b->thread == -1 && thread != -1) | |
6764 | printf_filtered (" (all threads)"); | |
6765 | else if (b->thread != -1) | |
6766 | printf_filtered (" (thread %d)", b->thread); | |
6767 | printf_filtered ("%s%s ", | |
059fb39f | 6768 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6769 | || b->enable_state == bp_call_disabled) |
0d381245 | 6770 | ? " (disabled)" |
0d381245 VP |
6771 | : ""), |
6772 | (others > 1) ? "," | |
6773 | : ((others == 1) ? " and" : "")); | |
6774 | } | |
a3f17187 | 6775 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6776 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6777 | printf_filtered (".\n"); |
6778 | } | |
6779 | } | |
6780 | \f | |
c906108c | 6781 | |
e4f237da | 6782 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
6783 | BPT locations. For some breakpoint types, the locations' address members |
6784 | are irrelevant and it makes no sense to attempt to compare them to other | |
6785 | addresses (or use them for any other purpose either). | |
e4f237da | 6786 | |
4a64f543 | 6787 | More specifically, each of the following breakpoint types will |
244558af | 6788 | always have a zero valued location address and we don't want to mark |
4a64f543 | 6789 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 6790 | breakpoint location at address zero: |
e4f237da KB |
6791 | |
6792 | bp_watchpoint | |
2d134ed3 PA |
6793 | bp_catchpoint |
6794 | ||
6795 | */ | |
e4f237da KB |
6796 | |
6797 | static int | |
6798 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6799 | { | |
6800 | enum bptype type = bpt->type; | |
6801 | ||
2d134ed3 PA |
6802 | return (type != bp_watchpoint && type != bp_catchpoint); |
6803 | } | |
6804 | ||
6805 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6806 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6807 | ||
6808 | static int | |
4a64f543 MS |
6809 | watchpoint_locations_match (struct bp_location *loc1, |
6810 | struct bp_location *loc2) | |
2d134ed3 | 6811 | { |
3a5c3e22 PA |
6812 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6813 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6814 | ||
6815 | /* Both of them must exist. */ | |
6816 | gdb_assert (w1 != NULL); | |
6817 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6818 | |
4a64f543 MS |
6819 | /* If the target can evaluate the condition expression in hardware, |
6820 | then we we need to insert both watchpoints even if they are at | |
6821 | the same place. Otherwise the watchpoint will only trigger when | |
6822 | the condition of whichever watchpoint was inserted evaluates to | |
6823 | true, not giving a chance for GDB to check the condition of the | |
6824 | other watchpoint. */ | |
3a5c3e22 | 6825 | if ((w1->cond_exp |
4a64f543 MS |
6826 | && target_can_accel_watchpoint_condition (loc1->address, |
6827 | loc1->length, | |
0cf6dd15 | 6828 | loc1->watchpoint_type, |
4d01a485 | 6829 | w1->cond_exp.get ())) |
3a5c3e22 | 6830 | || (w2->cond_exp |
4a64f543 MS |
6831 | && target_can_accel_watchpoint_condition (loc2->address, |
6832 | loc2->length, | |
0cf6dd15 | 6833 | loc2->watchpoint_type, |
4d01a485 | 6834 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6835 | return 0; |
6836 | ||
85d721b8 PA |
6837 | /* Note that this checks the owner's type, not the location's. In |
6838 | case the target does not support read watchpoints, but does | |
6839 | support access watchpoints, we'll have bp_read_watchpoint | |
6840 | watchpoints with hw_access locations. Those should be considered | |
6841 | duplicates of hw_read locations. The hw_read locations will | |
6842 | become hw_access locations later. */ | |
2d134ed3 PA |
6843 | return (loc1->owner->type == loc2->owner->type |
6844 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6845 | && loc1->address == loc2->address | |
6846 | && loc1->length == loc2->length); | |
e4f237da KB |
6847 | } |
6848 | ||
31e77af2 | 6849 | /* See breakpoint.h. */ |
6c95b8df | 6850 | |
31e77af2 | 6851 | int |
accd0bcd YQ |
6852 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6853 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6854 | { |
f5656ead | 6855 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6856 | || aspace1 == aspace2) |
6857 | && addr1 == addr2); | |
6858 | } | |
6859 | ||
f1310107 TJB |
6860 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6861 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6862 | matches ASPACE2. On targets that have global breakpoints, the address | |
6863 | space doesn't really matter. */ | |
6864 | ||
6865 | static int | |
accd0bcd YQ |
6866 | breakpoint_address_match_range (const address_space *aspace1, |
6867 | CORE_ADDR addr1, | |
6868 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6869 | CORE_ADDR addr2) |
6870 | { | |
f5656ead | 6871 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6872 | || aspace1 == aspace2) |
6873 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6874 | } | |
6875 | ||
6876 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6877 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6878 | matches the breakpoint's address space. On targets that have global | |
6879 | breakpoints, the address space doesn't really matter. */ | |
6880 | ||
6881 | static int | |
6882 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6883 | const address_space *aspace, |
f1310107 TJB |
6884 | CORE_ADDR addr) |
6885 | { | |
6886 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6887 | aspace, addr) | |
6888 | || (bl->length | |
6889 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6890 | bl->address, bl->length, | |
6891 | aspace, addr))); | |
6892 | } | |
6893 | ||
d35ae833 PA |
6894 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6895 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6896 | match happens only if ASPACE matches the breakpoint's address | |
6897 | space. On targets that have global breakpoints, the address space | |
6898 | doesn't really matter. */ | |
6899 | ||
6900 | static int | |
6901 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6902 | const address_space *aspace, |
d35ae833 PA |
6903 | CORE_ADDR addr, int len) |
6904 | { | |
6905 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6906 | || bl->pspace->aspace == aspace) | |
6907 | { | |
6908 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6909 | ||
6910 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
6911 | return 1; | |
6912 | } | |
6913 | return 0; | |
6914 | } | |
6915 | ||
1e4d1764 YQ |
6916 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6917 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6918 | true, otherwise returns false. */ | |
6919 | ||
6920 | static int | |
6921 | tracepoint_locations_match (struct bp_location *loc1, | |
6922 | struct bp_location *loc2) | |
6923 | { | |
6924 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6925 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6926 | locations at the same address of different tracepoints are regarded as | |
6927 | different locations. */ | |
6928 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6929 | else | |
6930 | return 0; | |
6931 | } | |
6932 | ||
2d134ed3 PA |
6933 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6934 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6935 | represent the same location. */ | |
6936 | ||
6937 | static int | |
4a64f543 MS |
6938 | breakpoint_locations_match (struct bp_location *loc1, |
6939 | struct bp_location *loc2) | |
2d134ed3 | 6940 | { |
2bdf28a0 JK |
6941 | int hw_point1, hw_point2; |
6942 | ||
6943 | /* Both of them must not be in moribund_locations. */ | |
6944 | gdb_assert (loc1->owner != NULL); | |
6945 | gdb_assert (loc2->owner != NULL); | |
6946 | ||
6947 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6948 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6949 | |
6950 | if (hw_point1 != hw_point2) | |
6951 | return 0; | |
6952 | else if (hw_point1) | |
6953 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6954 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6955 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6956 | else |
f1310107 TJB |
6957 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6958 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6959 | loc2->pspace->aspace, loc2->address) | |
6960 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6961 | } |
6962 | ||
76897487 KB |
6963 | static void |
6964 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6965 | int bnum, int have_bnum) | |
6966 | { | |
f63fbe86 MS |
6967 | /* The longest string possibly returned by hex_string_custom |
6968 | is 50 chars. These must be at least that big for safety. */ | |
6969 | char astr1[64]; | |
6970 | char astr2[64]; | |
76897487 | 6971 | |
bb599908 PH |
6972 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6973 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6974 | if (have_bnum) |
8a3fe4f8 | 6975 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6976 | bnum, astr1, astr2); |
6977 | else | |
8a3fe4f8 | 6978 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6979 | } |
6980 | ||
4a64f543 MS |
6981 | /* Adjust a breakpoint's address to account for architectural |
6982 | constraints on breakpoint placement. Return the adjusted address. | |
6983 | Note: Very few targets require this kind of adjustment. For most | |
6984 | targets, this function is simply the identity function. */ | |
76897487 KB |
6985 | |
6986 | static CORE_ADDR | |
a6d9a66e UW |
6987 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6988 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6989 | { |
a6d9a66e | 6990 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6991 | { |
6992 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6993 | return bpaddr; | |
6994 | } | |
88f7da05 KB |
6995 | else if (bptype == bp_watchpoint |
6996 | || bptype == bp_hardware_watchpoint | |
6997 | || bptype == bp_read_watchpoint | |
6998 | || bptype == bp_access_watchpoint | |
fe798b75 | 6999 | || bptype == bp_catchpoint) |
88f7da05 KB |
7000 | { |
7001 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7002 | have their addresses modified. */ | |
7003 | return bpaddr; | |
7004 | } | |
7c16b83e PA |
7005 | else if (bptype == bp_single_step) |
7006 | { | |
7007 | /* Single-step breakpoints should not have their addresses | |
7008 | modified. If there's any architectural constrain that | |
7009 | applies to this address, then it should have already been | |
7010 | taken into account when the breakpoint was created in the | |
7011 | first place. If we didn't do this, stepping through e.g., | |
7012 | Thumb-2 IT blocks would break. */ | |
7013 | return bpaddr; | |
7014 | } | |
76897487 KB |
7015 | else |
7016 | { | |
7017 | CORE_ADDR adjusted_bpaddr; | |
7018 | ||
7019 | /* Some targets have architectural constraints on the placement | |
7020 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7021 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7022 | |
7023 | /* An adjusted breakpoint address can significantly alter | |
7024 | a user's expectations. Print a warning if an adjustment | |
7025 | is required. */ | |
7026 | if (adjusted_bpaddr != bpaddr) | |
7027 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7028 | ||
7029 | return adjusted_bpaddr; | |
7030 | } | |
7031 | } | |
7032 | ||
5625a286 | 7033 | bp_location::bp_location (const bp_location_ops *ops, breakpoint *owner) |
7cc221ef | 7034 | { |
5625a286 | 7035 | bp_location *loc = this; |
7cc221ef | 7036 | |
348d480f PA |
7037 | gdb_assert (ops != NULL); |
7038 | ||
28010a5d PA |
7039 | loc->ops = ops; |
7040 | loc->owner = owner; | |
b775012e | 7041 | loc->cond_bytecode = NULL; |
0d381245 VP |
7042 | loc->shlib_disabled = 0; |
7043 | loc->enabled = 1; | |
e049a4b5 | 7044 | |
28010a5d | 7045 | switch (owner->type) |
e049a4b5 DJ |
7046 | { |
7047 | case bp_breakpoint: | |
7c16b83e | 7048 | case bp_single_step: |
e049a4b5 DJ |
7049 | case bp_until: |
7050 | case bp_finish: | |
7051 | case bp_longjmp: | |
7052 | case bp_longjmp_resume: | |
e2e4d78b | 7053 | case bp_longjmp_call_dummy: |
186c406b TT |
7054 | case bp_exception: |
7055 | case bp_exception_resume: | |
e049a4b5 | 7056 | case bp_step_resume: |
2c03e5be | 7057 | case bp_hp_step_resume: |
e049a4b5 DJ |
7058 | case bp_watchpoint_scope: |
7059 | case bp_call_dummy: | |
aa7d318d | 7060 | case bp_std_terminate: |
e049a4b5 DJ |
7061 | case bp_shlib_event: |
7062 | case bp_thread_event: | |
7063 | case bp_overlay_event: | |
4efc6507 | 7064 | case bp_jit_event: |
0fd8e87f | 7065 | case bp_longjmp_master: |
aa7d318d | 7066 | case bp_std_terminate_master: |
186c406b | 7067 | case bp_exception_master: |
0e30163f JK |
7068 | case bp_gnu_ifunc_resolver: |
7069 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7070 | case bp_dprintf: |
e049a4b5 | 7071 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7072 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7073 | break; |
7074 | case bp_hardware_breakpoint: | |
7075 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7076 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7077 | break; |
7078 | case bp_hardware_watchpoint: | |
7079 | case bp_read_watchpoint: | |
7080 | case bp_access_watchpoint: | |
7081 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7082 | break; | |
7083 | case bp_watchpoint: | |
ce78b96d | 7084 | case bp_catchpoint: |
15c3d785 PA |
7085 | case bp_tracepoint: |
7086 | case bp_fast_tracepoint: | |
0fb4aa4b | 7087 | case bp_static_tracepoint: |
e049a4b5 DJ |
7088 | loc->loc_type = bp_loc_other; |
7089 | break; | |
7090 | default: | |
e2e0b3e5 | 7091 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7092 | } |
7093 | ||
f431efe5 | 7094 | loc->refc = 1; |
28010a5d PA |
7095 | } |
7096 | ||
7097 | /* Allocate a struct bp_location. */ | |
7098 | ||
7099 | static struct bp_location * | |
7100 | allocate_bp_location (struct breakpoint *bpt) | |
7101 | { | |
348d480f PA |
7102 | return bpt->ops->allocate_location (bpt); |
7103 | } | |
7cc221ef | 7104 | |
f431efe5 PA |
7105 | static void |
7106 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7107 | { |
348d480f | 7108 | loc->ops->dtor (loc); |
4d01a485 | 7109 | delete loc; |
fe3f5fa8 VP |
7110 | } |
7111 | ||
f431efe5 PA |
7112 | /* Increment reference count. */ |
7113 | ||
7114 | static void | |
7115 | incref_bp_location (struct bp_location *bl) | |
7116 | { | |
7117 | ++bl->refc; | |
7118 | } | |
7119 | ||
7120 | /* Decrement reference count. If the reference count reaches 0, | |
7121 | destroy the bp_location. Sets *BLP to NULL. */ | |
7122 | ||
7123 | static void | |
7124 | decref_bp_location (struct bp_location **blp) | |
7125 | { | |
0807b50c PA |
7126 | gdb_assert ((*blp)->refc > 0); |
7127 | ||
f431efe5 PA |
7128 | if (--(*blp)->refc == 0) |
7129 | free_bp_location (*blp); | |
7130 | *blp = NULL; | |
7131 | } | |
7132 | ||
346774a9 | 7133 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7134 | |
b270e6f9 TT |
7135 | static breakpoint * |
7136 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7137 | { |
346774a9 | 7138 | struct breakpoint *b1; |
b270e6f9 | 7139 | struct breakpoint *result = b.get (); |
c906108c | 7140 | |
346774a9 PA |
7141 | /* Add this breakpoint to the end of the chain so that a list of |
7142 | breakpoints will come out in order of increasing numbers. */ | |
7143 | ||
7144 | b1 = breakpoint_chain; | |
7145 | if (b1 == 0) | |
b270e6f9 | 7146 | breakpoint_chain = b.release (); |
346774a9 PA |
7147 | else |
7148 | { | |
7149 | while (b1->next) | |
7150 | b1 = b1->next; | |
b270e6f9 | 7151 | b1->next = b.release (); |
346774a9 | 7152 | } |
b270e6f9 TT |
7153 | |
7154 | return result; | |
346774a9 PA |
7155 | } |
7156 | ||
7157 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7158 | ||
7159 | static void | |
7160 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7161 | struct gdbarch *gdbarch, | |
28010a5d | 7162 | enum bptype bptype, |
c0a91b2b | 7163 | const struct breakpoint_ops *ops) |
346774a9 | 7164 | { |
348d480f PA |
7165 | gdb_assert (ops != NULL); |
7166 | ||
28010a5d | 7167 | b->ops = ops; |
4d28f7a8 | 7168 | b->type = bptype; |
a6d9a66e | 7169 | b->gdbarch = gdbarch; |
c906108c SS |
7170 | b->language = current_language->la_language; |
7171 | b->input_radix = input_radix; | |
d0fb5eae | 7172 | b->related_breakpoint = b; |
346774a9 PA |
7173 | } |
7174 | ||
7175 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7176 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7177 | |
7178 | static struct breakpoint * | |
7179 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7180 | enum bptype bptype, |
c0a91b2b | 7181 | const struct breakpoint_ops *ops) |
346774a9 | 7182 | { |
3b0871f4 | 7183 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7184 | |
3b0871f4 | 7185 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7186 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7187 | } |
7188 | ||
0e30163f JK |
7189 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7190 | resolutions should be made as the user specified the location explicitly | |
7191 | enough. */ | |
7192 | ||
0d381245 | 7193 | static void |
0e30163f | 7194 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7195 | { |
2bdf28a0 JK |
7196 | gdb_assert (loc->owner != NULL); |
7197 | ||
0d381245 | 7198 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7199 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7200 | || is_tracepoint (loc->owner)) |
0d381245 | 7201 | { |
0e30163f | 7202 | int is_gnu_ifunc; |
2c02bd72 | 7203 | const char *function_name; |
6a3a010b | 7204 | CORE_ADDR func_addr; |
0e30163f | 7205 | |
2c02bd72 | 7206 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7207 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7208 | |
7209 | if (is_gnu_ifunc && !explicit_loc) | |
7210 | { | |
7211 | struct breakpoint *b = loc->owner; | |
7212 | ||
7213 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7214 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7215 | &loc->requested_address)) |
7216 | { | |
7217 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7218 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7219 | loc->requested_address, | |
7220 | b->type); | |
7221 | } | |
7222 | else if (b->type == bp_breakpoint && b->loc == loc | |
7223 | && loc->next == NULL && b->related_breakpoint == b) | |
7224 | { | |
7225 | /* Create only the whole new breakpoint of this type but do not | |
7226 | mess more complicated breakpoints with multiple locations. */ | |
7227 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7228 | /* Remember the resolver's address for use by the return |
7229 | breakpoint. */ | |
7230 | loc->related_address = func_addr; | |
0e30163f JK |
7231 | } |
7232 | } | |
7233 | ||
2c02bd72 DE |
7234 | if (function_name) |
7235 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7236 | } |
7237 | } | |
7238 | ||
a6d9a66e | 7239 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7240 | struct gdbarch * |
a6d9a66e UW |
7241 | get_sal_arch (struct symtab_and_line sal) |
7242 | { | |
7243 | if (sal.section) | |
7244 | return get_objfile_arch (sal.section->objfile); | |
7245 | if (sal.symtab) | |
eb822aa6 | 7246 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7247 | |
7248 | return NULL; | |
7249 | } | |
7250 | ||
346774a9 PA |
7251 | /* Low level routine for partially initializing a breakpoint of type |
7252 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7253 | file name, and line number are provided by SAL. |
0d381245 VP |
7254 | |
7255 | It is expected that the caller will complete the initialization of | |
7256 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7257 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7258 | |
346774a9 PA |
7259 | static void |
7260 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7261 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7262 | const struct breakpoint_ops *ops) |
0d381245 | 7263 | { |
28010a5d | 7264 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7265 | |
3742cc8b | 7266 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7267 | |
6c95b8df PA |
7268 | if (bptype != bp_catchpoint) |
7269 | gdb_assert (sal.pspace != NULL); | |
7270 | ||
f8eba3c6 TT |
7271 | /* Store the program space that was used to set the breakpoint, |
7272 | except for ordinary breakpoints, which are independent of the | |
7273 | program space. */ | |
7274 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7275 | b->pspace = sal.pspace; | |
346774a9 | 7276 | } |
c906108c | 7277 | |
346774a9 PA |
7278 | /* set_raw_breakpoint is a low level routine for allocating and |
7279 | partially initializing a breakpoint of type BPTYPE. The newly | |
7280 | created breakpoint's address, section, source file name, and line | |
7281 | number are provided by SAL. The newly created and partially | |
7282 | initialized breakpoint is added to the breakpoint chain and | |
7283 | is also returned as the value of this function. | |
7284 | ||
7285 | It is expected that the caller will complete the initialization of | |
7286 | the newly created breakpoint struct as well as output any status | |
7287 | information regarding the creation of a new breakpoint. In | |
7288 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7289 | number! Care should be taken to not allow an error to occur | |
7290 | prior to completing the initialization of the breakpoint. If this | |
7291 | should happen, a bogus breakpoint will be left on the chain. */ | |
7292 | ||
7293 | struct breakpoint * | |
7294 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7295 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7296 | const struct breakpoint_ops *ops) |
346774a9 | 7297 | { |
3b0871f4 | 7298 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7299 | |
3b0871f4 | 7300 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7301 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7302 | } |
7303 | ||
53a5351d | 7304 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7305 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7306 | initiated the operation. */ | |
c906108c SS |
7307 | |
7308 | void | |
186c406b | 7309 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7310 | { |
35df4500 | 7311 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7312 | int thread = tp->global_num; |
0fd8e87f UW |
7313 | |
7314 | /* To avoid having to rescan all objfile symbols at every step, | |
7315 | we maintain a list of continually-inserted but always disabled | |
7316 | longjmp "master" breakpoints. Here, we simply create momentary | |
7317 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7318 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7319 | if (b->pspace == current_program_space |
186c406b TT |
7320 | && (b->type == bp_longjmp_master |
7321 | || b->type == bp_exception_master)) | |
0fd8e87f | 7322 | { |
06edf0c0 PA |
7323 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7324 | struct breakpoint *clone; | |
cc59ec59 | 7325 | |
e2e4d78b JK |
7326 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7327 | after their removal. */ | |
06edf0c0 | 7328 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7329 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7330 | clone->thread = thread; |
7331 | } | |
186c406b TT |
7332 | |
7333 | tp->initiating_frame = frame; | |
c906108c SS |
7334 | } |
7335 | ||
611c83ae | 7336 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7337 | void |
611c83ae | 7338 | delete_longjmp_breakpoint (int thread) |
c906108c | 7339 | { |
35df4500 | 7340 | struct breakpoint *b, *b_tmp; |
c906108c | 7341 | |
35df4500 | 7342 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7343 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7344 | { |
7345 | if (b->thread == thread) | |
7346 | delete_breakpoint (b); | |
7347 | } | |
c906108c SS |
7348 | } |
7349 | ||
f59f708a PA |
7350 | void |
7351 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7352 | { | |
7353 | struct breakpoint *b, *b_tmp; | |
7354 | ||
7355 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7356 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7357 | { | |
7358 | if (b->thread == thread) | |
7359 | b->disposition = disp_del_at_next_stop; | |
7360 | } | |
7361 | } | |
7362 | ||
e2e4d78b JK |
7363 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7364 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7365 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7366 | breakpoints. */ | |
7367 | ||
7368 | struct breakpoint * | |
7369 | set_longjmp_breakpoint_for_call_dummy (void) | |
7370 | { | |
7371 | struct breakpoint *b, *retval = NULL; | |
7372 | ||
7373 | ALL_BREAKPOINTS (b) | |
7374 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7375 | { | |
7376 | struct breakpoint *new_b; | |
7377 | ||
7378 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7379 | &momentary_breakpoint_ops, |
7380 | 1); | |
5d5658a1 | 7381 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7382 | |
7383 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7384 | ||
7385 | gdb_assert (new_b->related_breakpoint == new_b); | |
7386 | if (retval == NULL) | |
7387 | retval = new_b; | |
7388 | new_b->related_breakpoint = retval; | |
7389 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7390 | retval = retval->related_breakpoint; | |
7391 | retval->related_breakpoint = new_b; | |
7392 | } | |
7393 | ||
7394 | return retval; | |
7395 | } | |
7396 | ||
7397 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7398 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7399 | stack. |
7400 | ||
7401 | You should call this function only at places where it is safe to currently | |
7402 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7403 | frames. */ | |
7404 | ||
7405 | void | |
b67a2c6f | 7406 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7407 | { |
7408 | struct breakpoint *b, *b_tmp; | |
7409 | ||
7410 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7411 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7412 | { |
7413 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7414 | ||
7415 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7416 | dummy_b = dummy_b->related_breakpoint; | |
7417 | if (dummy_b->type != bp_call_dummy | |
7418 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7419 | continue; | |
7420 | ||
b67a2c6f | 7421 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7422 | |
7423 | while (b->related_breakpoint != b) | |
7424 | { | |
7425 | if (b_tmp == b->related_breakpoint) | |
7426 | b_tmp = b->related_breakpoint->next; | |
7427 | delete_breakpoint (b->related_breakpoint); | |
7428 | } | |
7429 | delete_breakpoint (b); | |
7430 | } | |
7431 | } | |
7432 | ||
1900040c MS |
7433 | void |
7434 | enable_overlay_breakpoints (void) | |
7435 | { | |
52f0bd74 | 7436 | struct breakpoint *b; |
1900040c MS |
7437 | |
7438 | ALL_BREAKPOINTS (b) | |
7439 | if (b->type == bp_overlay_event) | |
7440 | { | |
7441 | b->enable_state = bp_enabled; | |
44702360 | 7442 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7443 | overlay_events_enabled = 1; |
1900040c MS |
7444 | } |
7445 | } | |
7446 | ||
7447 | void | |
7448 | disable_overlay_breakpoints (void) | |
7449 | { | |
52f0bd74 | 7450 | struct breakpoint *b; |
1900040c MS |
7451 | |
7452 | ALL_BREAKPOINTS (b) | |
7453 | if (b->type == bp_overlay_event) | |
7454 | { | |
7455 | b->enable_state = bp_disabled; | |
44702360 | 7456 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7457 | overlay_events_enabled = 0; |
1900040c MS |
7458 | } |
7459 | } | |
7460 | ||
aa7d318d TT |
7461 | /* Set an active std::terminate breakpoint for each std::terminate |
7462 | master breakpoint. */ | |
7463 | void | |
7464 | set_std_terminate_breakpoint (void) | |
7465 | { | |
35df4500 | 7466 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7467 | |
35df4500 | 7468 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7469 | if (b->pspace == current_program_space |
7470 | && b->type == bp_std_terminate_master) | |
7471 | { | |
06edf0c0 | 7472 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7473 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7474 | } |
7475 | } | |
7476 | ||
7477 | /* Delete all the std::terminate breakpoints. */ | |
7478 | void | |
7479 | delete_std_terminate_breakpoint (void) | |
7480 | { | |
35df4500 | 7481 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7482 | |
35df4500 | 7483 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7484 | if (b->type == bp_std_terminate) |
7485 | delete_breakpoint (b); | |
7486 | } | |
7487 | ||
c4093a6a | 7488 | struct breakpoint * |
a6d9a66e | 7489 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7490 | { |
7491 | struct breakpoint *b; | |
c4093a6a | 7492 | |
06edf0c0 PA |
7493 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7494 | &internal_breakpoint_ops); | |
7495 | ||
b5de0fa7 | 7496 | b->enable_state = bp_enabled; |
f00aae0f | 7497 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7498 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7499 | |
44702360 | 7500 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7501 | |
c4093a6a JM |
7502 | return b; |
7503 | } | |
7504 | ||
0101ce28 JJ |
7505 | struct lang_and_radix |
7506 | { | |
7507 | enum language lang; | |
7508 | int radix; | |
7509 | }; | |
7510 | ||
4efc6507 DE |
7511 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7512 | ||
7513 | struct breakpoint * | |
7514 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7515 | { | |
2a7f3dff PA |
7516 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7517 | &internal_breakpoint_ops); | |
4efc6507 | 7518 | } |
0101ce28 | 7519 | |
03673fc7 PP |
7520 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7521 | ||
7522 | void | |
7523 | remove_jit_event_breakpoints (void) | |
7524 | { | |
7525 | struct breakpoint *b, *b_tmp; | |
7526 | ||
7527 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7528 | if (b->type == bp_jit_event | |
7529 | && b->loc->pspace == current_program_space) | |
7530 | delete_breakpoint (b); | |
7531 | } | |
7532 | ||
cae688ec JJ |
7533 | void |
7534 | remove_solib_event_breakpoints (void) | |
7535 | { | |
35df4500 | 7536 | struct breakpoint *b, *b_tmp; |
cae688ec | 7537 | |
35df4500 | 7538 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7539 | if (b->type == bp_shlib_event |
7540 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7541 | delete_breakpoint (b); |
7542 | } | |
7543 | ||
f37f681c PA |
7544 | /* See breakpoint.h. */ |
7545 | ||
7546 | void | |
7547 | remove_solib_event_breakpoints_at_next_stop (void) | |
7548 | { | |
7549 | struct breakpoint *b, *b_tmp; | |
7550 | ||
7551 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7552 | if (b->type == bp_shlib_event | |
7553 | && b->loc->pspace == current_program_space) | |
7554 | b->disposition = disp_del_at_next_stop; | |
7555 | } | |
7556 | ||
04086b45 PA |
7557 | /* Helper for create_solib_event_breakpoint / |
7558 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7559 | INSERT_MODE to pass through to update_global_location_list. */ | |
7560 | ||
7561 | static struct breakpoint * | |
7562 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7563 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7564 | { |
7565 | struct breakpoint *b; | |
7566 | ||
06edf0c0 PA |
7567 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7568 | &internal_breakpoint_ops); | |
04086b45 | 7569 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7570 | return b; |
7571 | } | |
7572 | ||
04086b45 PA |
7573 | struct breakpoint * |
7574 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7575 | { | |
7576 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7577 | } | |
7578 | ||
f37f681c PA |
7579 | /* See breakpoint.h. */ |
7580 | ||
7581 | struct breakpoint * | |
7582 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7583 | { | |
7584 | struct breakpoint *b; | |
7585 | ||
04086b45 PA |
7586 | /* Explicitly tell update_global_location_list to insert |
7587 | locations. */ | |
7588 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7589 | if (!b->loc->inserted) |
7590 | { | |
7591 | delete_breakpoint (b); | |
7592 | return NULL; | |
7593 | } | |
7594 | return b; | |
7595 | } | |
7596 | ||
cae688ec JJ |
7597 | /* Disable any breakpoints that are on code in shared libraries. Only |
7598 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7599 | ||
7600 | void | |
cb851954 | 7601 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7602 | { |
876fa593 | 7603 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7604 | |
876fa593 | 7605 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7606 | { |
2bdf28a0 | 7607 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7608 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7609 | |
4a64f543 MS |
7610 | /* We apply the check to all breakpoints, including disabled for |
7611 | those with loc->duplicate set. This is so that when breakpoint | |
7612 | becomes enabled, or the duplicate is removed, gdb will try to | |
7613 | insert all breakpoints. If we don't set shlib_disabled here, | |
7614 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7615 | if (((b->type == bp_breakpoint) |
508ccb1f | 7616 | || (b->type == bp_jit_event) |
1042e4c0 | 7617 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7618 | || (is_tracepoint (b))) |
6c95b8df | 7619 | && loc->pspace == current_program_space |
0d381245 | 7620 | && !loc->shlib_disabled |
6c95b8df | 7621 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7622 | ) |
0d381245 VP |
7623 | { |
7624 | loc->shlib_disabled = 1; | |
7625 | } | |
cae688ec JJ |
7626 | } |
7627 | } | |
7628 | ||
63644780 NB |
7629 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7630 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7631 | disabled ones can just stay disabled. */ | |
84acb35a | 7632 | |
75149521 | 7633 | static void |
84acb35a JJ |
7634 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7635 | { | |
876fa593 | 7636 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7637 | int disabled_shlib_breaks = 0; |
7638 | ||
876fa593 | 7639 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7640 | { |
2bdf28a0 | 7641 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7642 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7643 | |
1e4d1764 | 7644 | if (solib->pspace == loc->pspace |
e2dd7057 | 7645 | && !loc->shlib_disabled |
1e4d1764 YQ |
7646 | && (((b->type == bp_breakpoint |
7647 | || b->type == bp_jit_event | |
7648 | || b->type == bp_hardware_breakpoint) | |
7649 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7650 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7651 | || is_tracepoint (b)) | |
e2dd7057 | 7652 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7653 | { |
e2dd7057 PP |
7654 | loc->shlib_disabled = 1; |
7655 | /* At this point, we cannot rely on remove_breakpoint | |
7656 | succeeding so we must mark the breakpoint as not inserted | |
7657 | to prevent future errors occurring in remove_breakpoints. */ | |
7658 | loc->inserted = 0; | |
8d3788bd VP |
7659 | |
7660 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7661 | observer_notify_breakpoint_modified (b); | |
7662 | ||
e2dd7057 PP |
7663 | if (!disabled_shlib_breaks) |
7664 | { | |
223ffa71 | 7665 | target_terminal::ours_for_output (); |
3e43a32a MS |
7666 | warning (_("Temporarily disabling breakpoints " |
7667 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7668 | solib->so_name); |
84acb35a | 7669 | } |
e2dd7057 | 7670 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7671 | } |
7672 | } | |
84acb35a JJ |
7673 | } |
7674 | ||
63644780 NB |
7675 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7676 | notification of free_objfile. Only apply to enabled breakpoints, | |
7677 | disabled ones can just stay disabled. */ | |
7678 | ||
7679 | static void | |
7680 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7681 | { | |
7682 | struct breakpoint *b; | |
7683 | ||
7684 | if (objfile == NULL) | |
7685 | return; | |
7686 | ||
d03de421 PA |
7687 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7688 | managed by the user with add-symbol-file/remove-symbol-file. | |
7689 | Similarly to how breakpoints in shared libraries are handled in | |
7690 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7691 | shlib_disabled so they end up uninserted on the next global |
7692 | location list update. Shared libraries not loaded by the user | |
7693 | aren't handled here -- they're already handled in | |
7694 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7695 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7696 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7697 | main objfile). */ | |
7698 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7699 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7700 | return; |
7701 | ||
7702 | ALL_BREAKPOINTS (b) | |
7703 | { | |
7704 | struct bp_location *loc; | |
7705 | int bp_modified = 0; | |
7706 | ||
7707 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7708 | continue; | |
7709 | ||
7710 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7711 | { | |
7712 | CORE_ADDR loc_addr = loc->address; | |
7713 | ||
7714 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7715 | && loc->loc_type != bp_loc_software_breakpoint) | |
7716 | continue; | |
7717 | ||
7718 | if (loc->shlib_disabled != 0) | |
7719 | continue; | |
7720 | ||
7721 | if (objfile->pspace != loc->pspace) | |
7722 | continue; | |
7723 | ||
7724 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7725 | && loc->loc_type != bp_loc_software_breakpoint) | |
7726 | continue; | |
7727 | ||
7728 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7729 | { | |
7730 | loc->shlib_disabled = 1; | |
08351840 PA |
7731 | /* At this point, we don't know whether the object was |
7732 | unmapped from the inferior or not, so leave the | |
7733 | inserted flag alone. We'll handle failure to | |
7734 | uninsert quietly, in case the object was indeed | |
7735 | unmapped. */ | |
63644780 NB |
7736 | |
7737 | mark_breakpoint_location_modified (loc); | |
7738 | ||
7739 | bp_modified = 1; | |
7740 | } | |
7741 | } | |
7742 | ||
7743 | if (bp_modified) | |
7744 | observer_notify_breakpoint_modified (b); | |
7745 | } | |
7746 | } | |
7747 | ||
ce78b96d JB |
7748 | /* FORK & VFORK catchpoints. */ |
7749 | ||
e29a4733 | 7750 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7751 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7752 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7753 | |
c1fc2657 | 7754 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7755 | { |
e29a4733 PA |
7756 | /* Process id of a child process whose forking triggered this |
7757 | catchpoint. This field is only valid immediately after this | |
7758 | catchpoint has triggered. */ | |
7759 | ptid_t forked_inferior_pid; | |
7760 | }; | |
7761 | ||
4a64f543 MS |
7762 | /* Implement the "insert" breakpoint_ops method for fork |
7763 | catchpoints. */ | |
ce78b96d | 7764 | |
77b06cd7 TJB |
7765 | static int |
7766 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7767 | { |
dfd4cc63 | 7768 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7769 | } |
7770 | ||
4a64f543 MS |
7771 | /* Implement the "remove" breakpoint_ops method for fork |
7772 | catchpoints. */ | |
ce78b96d JB |
7773 | |
7774 | static int | |
73971819 | 7775 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7776 | { |
dfd4cc63 | 7777 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7778 | } |
7779 | ||
7780 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7781 | catchpoints. */ | |
7782 | ||
7783 | static int | |
f1310107 | 7784 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
bd522513 | 7785 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7786 | const struct target_waitstatus *ws) |
ce78b96d | 7787 | { |
e29a4733 PA |
7788 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7789 | ||
f90263c1 TT |
7790 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7791 | return 0; | |
7792 | ||
7793 | c->forked_inferior_pid = ws->value.related_pid; | |
7794 | return 1; | |
ce78b96d JB |
7795 | } |
7796 | ||
4a64f543 MS |
7797 | /* Implement the "print_it" breakpoint_ops method for fork |
7798 | catchpoints. */ | |
ce78b96d JB |
7799 | |
7800 | static enum print_stop_action | |
348d480f | 7801 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7802 | { |
36dfb11c | 7803 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7804 | struct breakpoint *b = bs->breakpoint_at; |
7805 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7806 | |
ce78b96d | 7807 | annotate_catchpoint (b->number); |
f303dbd6 | 7808 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7809 | if (b->disposition == disp_del) |
112e8700 | 7810 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7811 | else |
112e8700 SM |
7812 | uiout->text ("Catchpoint "); |
7813 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7814 | { |
112e8700 SM |
7815 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7816 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7817 | } |
112e8700 SM |
7818 | uiout->field_int ("bkptno", b->number); |
7819 | uiout->text (" (forked process "); | |
7820 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7821 | uiout->text ("), "); | |
ce78b96d JB |
7822 | return PRINT_SRC_AND_LOC; |
7823 | } | |
7824 | ||
4a64f543 MS |
7825 | /* Implement the "print_one" breakpoint_ops method for fork |
7826 | catchpoints. */ | |
ce78b96d JB |
7827 | |
7828 | static void | |
a6d9a66e | 7829 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7830 | { |
e29a4733 | 7831 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7832 | struct value_print_options opts; |
79a45e25 | 7833 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7834 | |
7835 | get_user_print_options (&opts); | |
7836 | ||
4a64f543 MS |
7837 | /* Field 4, the address, is omitted (which makes the columns not |
7838 | line up too nicely with the headers, but the effect is relatively | |
7839 | readable). */ | |
79a45b7d | 7840 | if (opts.addressprint) |
112e8700 | 7841 | uiout->field_skip ("addr"); |
ce78b96d | 7842 | annotate_field (5); |
112e8700 | 7843 | uiout->text ("fork"); |
e29a4733 | 7844 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 7845 | { |
112e8700 SM |
7846 | uiout->text (", process "); |
7847 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
7848 | uiout->spaces (1); | |
ce78b96d | 7849 | } |
8ac3646f | 7850 | |
112e8700 SM |
7851 | if (uiout->is_mi_like_p ()) |
7852 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
7853 | } |
7854 | ||
7855 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7856 | catchpoints. */ | |
7857 | ||
7858 | static void | |
7859 | print_mention_catch_fork (struct breakpoint *b) | |
7860 | { | |
7861 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7862 | } | |
7863 | ||
6149aea9 PA |
7864 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7865 | catchpoints. */ | |
7866 | ||
7867 | static void | |
7868 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7869 | { | |
7870 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7871 | print_recreate_thread (b, fp); |
6149aea9 PA |
7872 | } |
7873 | ||
ce78b96d JB |
7874 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7875 | ||
2060206e | 7876 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7877 | |
4a64f543 MS |
7878 | /* Implement the "insert" breakpoint_ops method for vfork |
7879 | catchpoints. */ | |
ce78b96d | 7880 | |
77b06cd7 TJB |
7881 | static int |
7882 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7883 | { |
dfd4cc63 | 7884 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7885 | } |
7886 | ||
4a64f543 MS |
7887 | /* Implement the "remove" breakpoint_ops method for vfork |
7888 | catchpoints. */ | |
ce78b96d JB |
7889 | |
7890 | static int | |
73971819 | 7891 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7892 | { |
dfd4cc63 | 7893 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7894 | } |
7895 | ||
7896 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7897 | catchpoints. */ | |
7898 | ||
7899 | static int | |
f1310107 | 7900 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
bd522513 | 7901 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7902 | const struct target_waitstatus *ws) |
ce78b96d | 7903 | { |
e29a4733 PA |
7904 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7905 | ||
f90263c1 TT |
7906 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7907 | return 0; | |
7908 | ||
7909 | c->forked_inferior_pid = ws->value.related_pid; | |
7910 | return 1; | |
ce78b96d JB |
7911 | } |
7912 | ||
4a64f543 MS |
7913 | /* Implement the "print_it" breakpoint_ops method for vfork |
7914 | catchpoints. */ | |
ce78b96d JB |
7915 | |
7916 | static enum print_stop_action | |
348d480f | 7917 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7918 | { |
36dfb11c | 7919 | struct ui_out *uiout = current_uiout; |
348d480f | 7920 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7921 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7922 | ||
ce78b96d | 7923 | annotate_catchpoint (b->number); |
f303dbd6 | 7924 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7925 | if (b->disposition == disp_del) |
112e8700 | 7926 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7927 | else |
112e8700 SM |
7928 | uiout->text ("Catchpoint "); |
7929 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7930 | { |
112e8700 SM |
7931 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
7932 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7933 | } |
112e8700 SM |
7934 | uiout->field_int ("bkptno", b->number); |
7935 | uiout->text (" (vforked process "); | |
7936 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7937 | uiout->text ("), "); | |
ce78b96d JB |
7938 | return PRINT_SRC_AND_LOC; |
7939 | } | |
7940 | ||
4a64f543 MS |
7941 | /* Implement the "print_one" breakpoint_ops method for vfork |
7942 | catchpoints. */ | |
ce78b96d JB |
7943 | |
7944 | static void | |
a6d9a66e | 7945 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7946 | { |
e29a4733 | 7947 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7948 | struct value_print_options opts; |
79a45e25 | 7949 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7950 | |
7951 | get_user_print_options (&opts); | |
4a64f543 MS |
7952 | /* Field 4, the address, is omitted (which makes the columns not |
7953 | line up too nicely with the headers, but the effect is relatively | |
7954 | readable). */ | |
79a45b7d | 7955 | if (opts.addressprint) |
112e8700 | 7956 | uiout->field_skip ("addr"); |
ce78b96d | 7957 | annotate_field (5); |
112e8700 | 7958 | uiout->text ("vfork"); |
e29a4733 | 7959 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 7960 | { |
112e8700 SM |
7961 | uiout->text (", process "); |
7962 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
7963 | uiout->spaces (1); | |
ce78b96d | 7964 | } |
8ac3646f | 7965 | |
112e8700 SM |
7966 | if (uiout->is_mi_like_p ()) |
7967 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
7968 | } |
7969 | ||
7970 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7971 | catchpoints. */ | |
7972 | ||
7973 | static void | |
7974 | print_mention_catch_vfork (struct breakpoint *b) | |
7975 | { | |
7976 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7977 | } | |
7978 | ||
6149aea9 PA |
7979 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7980 | catchpoints. */ | |
7981 | ||
7982 | static void | |
7983 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7984 | { | |
7985 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7986 | print_recreate_thread (b, fp); |
6149aea9 PA |
7987 | } |
7988 | ||
ce78b96d JB |
7989 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7990 | ||
2060206e | 7991 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7992 | |
edcc5120 | 7993 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 7994 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
7995 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
7996 | ||
c1fc2657 | 7997 | struct solib_catchpoint : public breakpoint |
edcc5120 | 7998 | { |
c1fc2657 | 7999 | ~solib_catchpoint () override; |
edcc5120 TT |
8000 | |
8001 | /* True for "catch load", false for "catch unload". */ | |
8002 | unsigned char is_load; | |
8003 | ||
8004 | /* Regular expression to match, if any. COMPILED is only valid when | |
8005 | REGEX is non-NULL. */ | |
8006 | char *regex; | |
2d7cc5c7 | 8007 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
8008 | }; |
8009 | ||
c1fc2657 | 8010 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 8011 | { |
c1fc2657 | 8012 | xfree (this->regex); |
edcc5120 TT |
8013 | } |
8014 | ||
8015 | static int | |
8016 | insert_catch_solib (struct bp_location *ignore) | |
8017 | { | |
8018 | return 0; | |
8019 | } | |
8020 | ||
8021 | static int | |
73971819 | 8022 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8023 | { |
8024 | return 0; | |
8025 | } | |
8026 | ||
8027 | static int | |
8028 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
bd522513 | 8029 | const address_space *aspace, |
edcc5120 TT |
8030 | CORE_ADDR bp_addr, |
8031 | const struct target_waitstatus *ws) | |
8032 | { | |
8033 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8034 | struct breakpoint *other; | |
8035 | ||
8036 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8037 | return 1; | |
8038 | ||
8039 | ALL_BREAKPOINTS (other) | |
8040 | { | |
8041 | struct bp_location *other_bl; | |
8042 | ||
8043 | if (other == bl->owner) | |
8044 | continue; | |
8045 | ||
8046 | if (other->type != bp_shlib_event) | |
8047 | continue; | |
8048 | ||
c1fc2657 | 8049 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
8050 | continue; |
8051 | ||
8052 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8053 | { | |
8054 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8055 | return 1; | |
8056 | } | |
8057 | } | |
8058 | ||
8059 | return 0; | |
8060 | } | |
8061 | ||
8062 | static void | |
8063 | check_status_catch_solib (struct bpstats *bs) | |
8064 | { | |
8065 | struct solib_catchpoint *self | |
8066 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8067 | int ix; | |
8068 | ||
8069 | if (self->is_load) | |
8070 | { | |
8071 | struct so_list *iter; | |
8072 | ||
8073 | for (ix = 0; | |
8074 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8075 | ix, iter); | |
8076 | ++ix) | |
8077 | { | |
8078 | if (!self->regex | |
2d7cc5c7 | 8079 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
8080 | return; |
8081 | } | |
8082 | } | |
8083 | else | |
8084 | { | |
8085 | char *iter; | |
8086 | ||
8087 | for (ix = 0; | |
8088 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8089 | ix, iter); | |
8090 | ++ix) | |
8091 | { | |
8092 | if (!self->regex | |
2d7cc5c7 | 8093 | || self->compiled->exec (iter, 0, NULL, 0) == 0) |
edcc5120 TT |
8094 | return; |
8095 | } | |
8096 | } | |
8097 | ||
8098 | bs->stop = 0; | |
8099 | bs->print_it = print_it_noop; | |
8100 | } | |
8101 | ||
8102 | static enum print_stop_action | |
8103 | print_it_catch_solib (bpstat bs) | |
8104 | { | |
8105 | struct breakpoint *b = bs->breakpoint_at; | |
8106 | struct ui_out *uiout = current_uiout; | |
8107 | ||
8108 | annotate_catchpoint (b->number); | |
f303dbd6 | 8109 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8110 | if (b->disposition == disp_del) |
112e8700 | 8111 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8112 | else |
112e8700 SM |
8113 | uiout->text ("Catchpoint "); |
8114 | uiout->field_int ("bkptno", b->number); | |
8115 | uiout->text ("\n"); | |
8116 | if (uiout->is_mi_like_p ()) | |
8117 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8118 | print_solib_event (1); |
8119 | return PRINT_SRC_AND_LOC; | |
8120 | } | |
8121 | ||
8122 | static void | |
8123 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8124 | { | |
8125 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8126 | struct value_print_options opts; | |
8127 | struct ui_out *uiout = current_uiout; | |
8128 | char *msg; | |
8129 | ||
8130 | get_user_print_options (&opts); | |
8131 | /* Field 4, the address, is omitted (which makes the columns not | |
8132 | line up too nicely with the headers, but the effect is relatively | |
8133 | readable). */ | |
8134 | if (opts.addressprint) | |
8135 | { | |
8136 | annotate_field (4); | |
112e8700 | 8137 | uiout->field_skip ("addr"); |
edcc5120 TT |
8138 | } |
8139 | ||
8140 | annotate_field (5); | |
8141 | if (self->is_load) | |
8142 | { | |
8143 | if (self->regex) | |
8144 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8145 | else | |
8146 | msg = xstrdup (_("load of library")); | |
8147 | } | |
8148 | else | |
8149 | { | |
8150 | if (self->regex) | |
8151 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8152 | else | |
8153 | msg = xstrdup (_("unload of library")); | |
8154 | } | |
112e8700 | 8155 | uiout->field_string ("what", msg); |
edcc5120 | 8156 | xfree (msg); |
8ac3646f | 8157 | |
112e8700 SM |
8158 | if (uiout->is_mi_like_p ()) |
8159 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8160 | } |
8161 | ||
8162 | static void | |
8163 | print_mention_catch_solib (struct breakpoint *b) | |
8164 | { | |
8165 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8166 | ||
8167 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8168 | self->is_load ? "load" : "unload"); | |
8169 | } | |
8170 | ||
8171 | static void | |
8172 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8173 | { | |
8174 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8175 | ||
8176 | fprintf_unfiltered (fp, "%s %s", | |
8177 | b->disposition == disp_del ? "tcatch" : "catch", | |
8178 | self->is_load ? "load" : "unload"); | |
8179 | if (self->regex) | |
8180 | fprintf_unfiltered (fp, " %s", self->regex); | |
8181 | fprintf_unfiltered (fp, "\n"); | |
8182 | } | |
8183 | ||
8184 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8185 | ||
91985142 MG |
8186 | /* Shared helper function (MI and CLI) for creating and installing |
8187 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8188 | the events to be caught are load events, otherwise they are | |
8189 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8190 | temporary one. If ENABLED is non-zero the catchpoint is | |
8191 | created in an enabled state. */ | |
edcc5120 | 8192 | |
91985142 | 8193 | void |
a121b7c1 | 8194 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8195 | { |
edcc5120 | 8196 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8197 | |
edcc5120 TT |
8198 | if (!arg) |
8199 | arg = ""; | |
f1735a53 | 8200 | arg = skip_spaces (arg); |
edcc5120 | 8201 | |
36bd8eaa | 8202 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8203 | |
8204 | if (*arg != '\0') | |
8205 | { | |
2d7cc5c7 PA |
8206 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8207 | _("Invalid regexp"))); | |
edcc5120 TT |
8208 | c->regex = xstrdup (arg); |
8209 | } | |
8210 | ||
8211 | c->is_load = is_load; | |
36bd8eaa | 8212 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8213 | &catch_solib_breakpoint_ops); |
8214 | ||
c1fc2657 | 8215 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8216 | |
b270e6f9 | 8217 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8218 | } |
8219 | ||
91985142 MG |
8220 | /* A helper function that does all the work for "catch load" and |
8221 | "catch unload". */ | |
8222 | ||
8223 | static void | |
eb4c3f4a | 8224 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
91985142 MG |
8225 | struct cmd_list_element *command) |
8226 | { | |
8227 | int tempflag; | |
8228 | const int enabled = 1; | |
8229 | ||
8230 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8231 | ||
8232 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8233 | } | |
8234 | ||
edcc5120 | 8235 | static void |
eb4c3f4a | 8236 | catch_load_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8237 | struct cmd_list_element *command) |
8238 | { | |
8239 | catch_load_or_unload (arg, from_tty, 1, command); | |
8240 | } | |
8241 | ||
8242 | static void | |
eb4c3f4a | 8243 | catch_unload_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8244 | struct cmd_list_element *command) |
8245 | { | |
8246 | catch_load_or_unload (arg, from_tty, 0, command); | |
8247 | } | |
8248 | ||
346774a9 PA |
8249 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8250 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8251 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8252 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8253 | |
ab04a2af | 8254 | void |
346774a9 PA |
8255 | init_catchpoint (struct breakpoint *b, |
8256 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8257 | const char *cond_string, |
c0a91b2b | 8258 | const struct breakpoint_ops *ops) |
c906108c | 8259 | { |
51abb421 | 8260 | symtab_and_line sal; |
6c95b8df | 8261 | sal.pspace = current_program_space; |
c5aa993b | 8262 | |
28010a5d | 8263 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8264 | |
1b36a34b | 8265 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8266 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8267 | } |
8268 | ||
28010a5d | 8269 | void |
b270e6f9 | 8270 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8271 | { |
b270e6f9 | 8272 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8273 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8274 | if (is_tracepoint (b)) |
8275 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8276 | if (!internal) |
8277 | mention (b); | |
c56053d2 | 8278 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8279 | |
8280 | if (update_gll) | |
44702360 | 8281 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8282 | } |
8283 | ||
9b70b993 | 8284 | static void |
a6d9a66e | 8285 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8286 | int tempflag, const char *cond_string, |
c0a91b2b | 8287 | const struct breakpoint_ops *ops) |
c906108c | 8288 | { |
b270e6f9 | 8289 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8290 | |
b270e6f9 | 8291 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8292 | |
8293 | c->forked_inferior_pid = null_ptid; | |
8294 | ||
b270e6f9 | 8295 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8296 | } |
8297 | ||
fe798b75 JB |
8298 | /* Exec catchpoints. */ |
8299 | ||
b4d90040 | 8300 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8301 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8302 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8303 | ||
c1fc2657 | 8304 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8305 | { |
c1fc2657 | 8306 | ~exec_catchpoint () override; |
b4d90040 PA |
8307 | |
8308 | /* Filename of a program whose exec triggered this catchpoint. | |
8309 | This field is only valid immediately after this catchpoint has | |
8310 | triggered. */ | |
8311 | char *exec_pathname; | |
8312 | }; | |
8313 | ||
c1fc2657 | 8314 | /* Exec catchpoint destructor. */ |
b4d90040 | 8315 | |
c1fc2657 | 8316 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8317 | { |
c1fc2657 | 8318 | xfree (this->exec_pathname); |
b4d90040 PA |
8319 | } |
8320 | ||
77b06cd7 TJB |
8321 | static int |
8322 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8323 | { |
dfd4cc63 | 8324 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8325 | } |
c906108c | 8326 | |
fe798b75 | 8327 | static int |
73971819 | 8328 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8329 | { |
dfd4cc63 | 8330 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8331 | } |
c906108c | 8332 | |
fe798b75 | 8333 | static int |
f1310107 | 8334 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
bd522513 | 8335 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 8336 | const struct target_waitstatus *ws) |
fe798b75 | 8337 | { |
b4d90040 PA |
8338 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8339 | ||
f90263c1 TT |
8340 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8341 | return 0; | |
8342 | ||
8343 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8344 | return 1; | |
fe798b75 | 8345 | } |
c906108c | 8346 | |
fe798b75 | 8347 | static enum print_stop_action |
348d480f | 8348 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8349 | { |
36dfb11c | 8350 | struct ui_out *uiout = current_uiout; |
348d480f | 8351 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8352 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8353 | ||
fe798b75 | 8354 | annotate_catchpoint (b->number); |
f303dbd6 | 8355 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8356 | if (b->disposition == disp_del) |
112e8700 | 8357 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8358 | else |
112e8700 SM |
8359 | uiout->text ("Catchpoint "); |
8360 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8361 | { |
112e8700 SM |
8362 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8363 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8364 | } |
112e8700 SM |
8365 | uiout->field_int ("bkptno", b->number); |
8366 | uiout->text (" (exec'd "); | |
8367 | uiout->field_string ("new-exec", c->exec_pathname); | |
8368 | uiout->text ("), "); | |
36dfb11c | 8369 | |
fe798b75 | 8370 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8371 | } |
8372 | ||
fe798b75 | 8373 | static void |
a6d9a66e | 8374 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8375 | { |
b4d90040 | 8376 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8377 | struct value_print_options opts; |
79a45e25 | 8378 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8379 | |
8380 | get_user_print_options (&opts); | |
8381 | ||
8382 | /* Field 4, the address, is omitted (which makes the columns | |
8383 | not line up too nicely with the headers, but the effect | |
8384 | is relatively readable). */ | |
8385 | if (opts.addressprint) | |
112e8700 | 8386 | uiout->field_skip ("addr"); |
fe798b75 | 8387 | annotate_field (5); |
112e8700 | 8388 | uiout->text ("exec"); |
b4d90040 | 8389 | if (c->exec_pathname != NULL) |
fe798b75 | 8390 | { |
112e8700 SM |
8391 | uiout->text (", program \""); |
8392 | uiout->field_string ("what", c->exec_pathname); | |
8393 | uiout->text ("\" "); | |
fe798b75 | 8394 | } |
8ac3646f | 8395 | |
112e8700 SM |
8396 | if (uiout->is_mi_like_p ()) |
8397 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8398 | } |
8399 | ||
8400 | static void | |
8401 | print_mention_catch_exec (struct breakpoint *b) | |
8402 | { | |
8403 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8404 | } | |
8405 | ||
6149aea9 PA |
8406 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8407 | catchpoints. */ | |
8408 | ||
8409 | static void | |
8410 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8411 | { | |
8412 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8413 | print_recreate_thread (b, fp); |
6149aea9 PA |
8414 | } |
8415 | ||
2060206e | 8416 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8417 | |
c906108c | 8418 | static int |
fba45db2 | 8419 | hw_breakpoint_used_count (void) |
c906108c | 8420 | { |
c906108c | 8421 | int i = 0; |
f1310107 TJB |
8422 | struct breakpoint *b; |
8423 | struct bp_location *bl; | |
c906108c SS |
8424 | |
8425 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8426 | { |
d6b74ac4 | 8427 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8428 | for (bl = b->loc; bl; bl = bl->next) |
8429 | { | |
8430 | /* Special types of hardware breakpoints may use more than | |
8431 | one register. */ | |
348d480f | 8432 | i += b->ops->resources_needed (bl); |
f1310107 | 8433 | } |
c5aa993b | 8434 | } |
c906108c SS |
8435 | |
8436 | return i; | |
8437 | } | |
8438 | ||
a1398e0c PA |
8439 | /* Returns the resources B would use if it were a hardware |
8440 | watchpoint. */ | |
8441 | ||
c906108c | 8442 | static int |
a1398e0c | 8443 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8444 | { |
c906108c | 8445 | int i = 0; |
e09342b5 | 8446 | struct bp_location *bl; |
c906108c | 8447 | |
a1398e0c PA |
8448 | if (!breakpoint_enabled (b)) |
8449 | return 0; | |
8450 | ||
8451 | for (bl = b->loc; bl; bl = bl->next) | |
8452 | { | |
8453 | /* Special types of hardware watchpoints may use more than | |
8454 | one register. */ | |
8455 | i += b->ops->resources_needed (bl); | |
8456 | } | |
8457 | ||
8458 | return i; | |
8459 | } | |
8460 | ||
8461 | /* Returns the sum the used resources of all hardware watchpoints of | |
8462 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8463 | the sum of the used resources of all hardware watchpoints of other | |
8464 | types _not_ TYPE. */ | |
8465 | ||
8466 | static int | |
8467 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8468 | enum bptype type, int *other_type_used) | |
8469 | { | |
8470 | int i = 0; | |
8471 | struct breakpoint *b; | |
8472 | ||
c906108c SS |
8473 | *other_type_used = 0; |
8474 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8475 | { |
a1398e0c PA |
8476 | if (b == except) |
8477 | continue; | |
e09342b5 TJB |
8478 | if (!breakpoint_enabled (b)) |
8479 | continue; | |
8480 | ||
a1398e0c PA |
8481 | if (b->type == type) |
8482 | i += hw_watchpoint_use_count (b); | |
8483 | else if (is_hardware_watchpoint (b)) | |
8484 | *other_type_used = 1; | |
e09342b5 TJB |
8485 | } |
8486 | ||
c906108c SS |
8487 | return i; |
8488 | } | |
8489 | ||
c906108c | 8490 | void |
fba45db2 | 8491 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8492 | { |
c5aa993b | 8493 | struct breakpoint *b; |
c906108c SS |
8494 | |
8495 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8496 | { |
cc60f2e3 | 8497 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8498 | { |
b5de0fa7 | 8499 | b->enable_state = bp_call_disabled; |
44702360 | 8500 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8501 | } |
8502 | } | |
c906108c SS |
8503 | } |
8504 | ||
8505 | void | |
fba45db2 | 8506 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8507 | { |
c5aa993b | 8508 | struct breakpoint *b; |
c906108c SS |
8509 | |
8510 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8511 | { |
cc60f2e3 | 8512 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8513 | { |
b5de0fa7 | 8514 | b->enable_state = bp_enabled; |
44702360 | 8515 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8516 | } |
8517 | } | |
c906108c SS |
8518 | } |
8519 | ||
8bea4e01 UW |
8520 | void |
8521 | disable_breakpoints_before_startup (void) | |
8522 | { | |
6c95b8df | 8523 | current_program_space->executing_startup = 1; |
44702360 | 8524 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8525 | } |
8526 | ||
8527 | void | |
8528 | enable_breakpoints_after_startup (void) | |
8529 | { | |
6c95b8df | 8530 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8531 | breakpoint_re_set (); |
8bea4e01 UW |
8532 | } |
8533 | ||
7c16b83e PA |
8534 | /* Create a new single-step breakpoint for thread THREAD, with no |
8535 | locations. */ | |
c906108c | 8536 | |
7c16b83e PA |
8537 | static struct breakpoint * |
8538 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8539 | { | |
b270e6f9 | 8540 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8541 | |
b270e6f9 | 8542 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8543 | &momentary_breakpoint_ops); |
8544 | ||
8545 | b->disposition = disp_donttouch; | |
8546 | b->frame_id = null_frame_id; | |
8547 | ||
8548 | b->thread = thread; | |
8549 | gdb_assert (b->thread != 0); | |
8550 | ||
b270e6f9 | 8551 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8552 | } |
8553 | ||
8554 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8555 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8556 | frame. */ | |
c906108c | 8557 | |
454dafbd | 8558 | breakpoint_up |
a6d9a66e UW |
8559 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8560 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8561 | { |
52f0bd74 | 8562 | struct breakpoint *b; |
edb3359d | 8563 | |
193facb3 JK |
8564 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8565 | tail-called one. */ | |
8566 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8567 | |
06edf0c0 | 8568 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8569 | b->enable_state = bp_enabled; |
8570 | b->disposition = disp_donttouch; | |
818dd999 | 8571 | b->frame_id = frame_id; |
c906108c | 8572 | |
4a64f543 MS |
8573 | /* If we're debugging a multi-threaded program, then we want |
8574 | momentary breakpoints to be active in only a single thread of | |
8575 | control. */ | |
39f77062 | 8576 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8577 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8578 | |
44702360 | 8579 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8580 | |
454dafbd | 8581 | return breakpoint_up (b); |
c906108c | 8582 | } |
611c83ae | 8583 | |
06edf0c0 | 8584 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8585 | The new breakpoint will have type TYPE, use OPS as its |
8586 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8587 | |
06edf0c0 PA |
8588 | static struct breakpoint * |
8589 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8590 | enum bptype type, | |
a1aa2221 LM |
8591 | const struct breakpoint_ops *ops, |
8592 | int loc_enabled) | |
e58b0e63 PA |
8593 | { |
8594 | struct breakpoint *copy; | |
8595 | ||
06edf0c0 | 8596 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8597 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8598 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8599 | |
a6d9a66e | 8600 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8601 | copy->loc->requested_address = orig->loc->requested_address; |
8602 | copy->loc->address = orig->loc->address; | |
8603 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8604 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8605 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8606 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8607 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8608 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8609 | copy->frame_id = orig->frame_id; |
8610 | copy->thread = orig->thread; | |
6c95b8df | 8611 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8612 | |
8613 | copy->enable_state = bp_enabled; | |
8614 | copy->disposition = disp_donttouch; | |
8615 | copy->number = internal_breakpoint_number--; | |
8616 | ||
44702360 | 8617 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8618 | return copy; |
8619 | } | |
8620 | ||
06edf0c0 PA |
8621 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8622 | ORIG is NULL. */ | |
8623 | ||
8624 | struct breakpoint * | |
8625 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8626 | { | |
8627 | /* If there's nothing to clone, then return nothing. */ | |
8628 | if (orig == NULL) | |
8629 | return NULL; | |
8630 | ||
a1aa2221 | 8631 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8632 | } |
8633 | ||
454dafbd | 8634 | breakpoint_up |
a6d9a66e UW |
8635 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8636 | enum bptype type) | |
611c83ae PA |
8637 | { |
8638 | struct symtab_and_line sal; | |
8639 | ||
8640 | sal = find_pc_line (pc, 0); | |
8641 | sal.pc = pc; | |
8642 | sal.section = find_pc_overlay (pc); | |
8643 | sal.explicit_pc = 1; | |
8644 | ||
a6d9a66e | 8645 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8646 | } |
c906108c | 8647 | \f |
c5aa993b | 8648 | |
c906108c SS |
8649 | /* Tell the user we have just set a breakpoint B. */ |
8650 | ||
8651 | static void | |
fba45db2 | 8652 | mention (struct breakpoint *b) |
c906108c | 8653 | { |
348d480f | 8654 | b->ops->print_mention (b); |
112e8700 | 8655 | if (current_uiout->is_mi_like_p ()) |
fb40c209 | 8656 | return; |
c906108c SS |
8657 | printf_filtered ("\n"); |
8658 | } | |
c906108c | 8659 | \f |
c5aa993b | 8660 | |
1a853c52 PA |
8661 | static int bp_loc_is_permanent (struct bp_location *loc); |
8662 | ||
0d381245 | 8663 | static struct bp_location * |
39d61571 | 8664 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8665 | const struct symtab_and_line *sal) |
8666 | { | |
8667 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8668 | CORE_ADDR adjusted_address; |
8669 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8670 | ||
8671 | if (loc_gdbarch == NULL) | |
8672 | loc_gdbarch = b->gdbarch; | |
8673 | ||
8674 | /* Adjust the breakpoint's address prior to allocating a location. | |
8675 | Once we call allocate_bp_location(), that mostly uninitialized | |
8676 | location will be placed on the location chain. Adjustment of the | |
8677 | breakpoint may cause target_read_memory() to be called and we do | |
8678 | not want its scan of the location chain to find a breakpoint and | |
8679 | location that's only been partially initialized. */ | |
8680 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8681 | sal->pc, b->type); | |
0d381245 | 8682 | |
d30113d4 | 8683 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8684 | loc = allocate_bp_location (b); |
d30113d4 JK |
8685 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8686 | tmp = &((*tmp)->next)) | |
0d381245 | 8687 | ; |
d30113d4 | 8688 | loc->next = *tmp; |
0d381245 | 8689 | *tmp = loc; |
3742cc8b | 8690 | |
0d381245 | 8691 | loc->requested_address = sal->pc; |
3742cc8b | 8692 | loc->address = adjusted_address; |
6c95b8df | 8693 | loc->pspace = sal->pspace; |
935676c9 | 8694 | loc->probe.prob = sal->prob; |
729662a5 | 8695 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8696 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8697 | loc->section = sal->section; |
3742cc8b | 8698 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8699 | loc->line_number = sal->line; |
2f202fde | 8700 | loc->symtab = sal->symtab; |
4a27f119 | 8701 | loc->symbol = sal->symbol; |
f8eba3c6 | 8702 | |
0e30163f JK |
8703 | set_breakpoint_location_function (loc, |
8704 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 8705 | |
6ae88661 LM |
8706 | /* While by definition, permanent breakpoints are already present in the |
8707 | code, we don't mark the location as inserted. Normally one would expect | |
8708 | that GDB could rely on that breakpoint instruction to stop the program, | |
8709 | thus removing the need to insert its own breakpoint, except that executing | |
8710 | the breakpoint instruction can kill the target instead of reporting a | |
8711 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8712 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8713 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8714 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8715 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8716 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8717 | it manually increments the PC, thus avoiding executing the breakpoint | |
8718 | instruction.) */ | |
1a853c52 | 8719 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8720 | loc->permanent = 1; |
1a853c52 | 8721 | |
0d381245 VP |
8722 | return loc; |
8723 | } | |
514f746b AR |
8724 | \f |
8725 | ||
1cf4d951 | 8726 | /* See breakpoint.h. */ |
514f746b | 8727 | |
1cf4d951 PA |
8728 | int |
8729 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8730 | { |
8731 | int len; | |
8732 | CORE_ADDR addr; | |
1afeeb75 | 8733 | const gdb_byte *bpoint; |
514f746b AR |
8734 | gdb_byte *target_mem; |
8735 | ||
1cf4d951 PA |
8736 | addr = address; |
8737 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8738 | ||
8739 | /* Software breakpoints unsupported? */ | |
8740 | if (bpoint == NULL) | |
8741 | return 0; | |
8742 | ||
224c3ddb | 8743 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
8744 | |
8745 | /* Enable the automatic memory restoration from breakpoints while | |
8746 | we read the memory. Otherwise we could say about our temporary | |
8747 | breakpoints they are permanent. */ | |
cb85b21b TT |
8748 | scoped_restore restore_memory |
8749 | = make_scoped_restore_show_memory_breakpoints (0); | |
1cf4d951 PA |
8750 | |
8751 | if (target_read_memory (address, target_mem, len) == 0 | |
8752 | && memcmp (target_mem, bpoint, len) == 0) | |
cb85b21b | 8753 | return 1; |
1cf4d951 | 8754 | |
cb85b21b | 8755 | return 0; |
1cf4d951 PA |
8756 | } |
8757 | ||
8758 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8759 | return 0 otherwise. */ | |
8760 | ||
8761 | static int | |
8762 | bp_loc_is_permanent (struct bp_location *loc) | |
8763 | { | |
514f746b AR |
8764 | gdb_assert (loc != NULL); |
8765 | ||
244558af LM |
8766 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
8767 | attempt to read from the addresses the locations of these breakpoint types | |
8768 | point to. program_breakpoint_here_p, below, will attempt to read | |
8769 | memory. */ | |
8770 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
8771 | return 0; | |
8772 | ||
5ed8105e | 8773 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8774 | switch_to_program_space_and_thread (loc->pspace); |
5ed8105e | 8775 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8776 | } |
8777 | ||
e7e0cddf SS |
8778 | /* Build a command list for the dprintf corresponding to the current |
8779 | settings of the dprintf style options. */ | |
8780 | ||
8781 | static void | |
8782 | update_dprintf_command_list (struct breakpoint *b) | |
8783 | { | |
8784 | char *dprintf_args = b->extra_string; | |
8785 | char *printf_line = NULL; | |
8786 | ||
8787 | if (!dprintf_args) | |
8788 | return; | |
8789 | ||
8790 | dprintf_args = skip_spaces (dprintf_args); | |
8791 | ||
8792 | /* Allow a comma, as it may have terminated a location, but don't | |
8793 | insist on it. */ | |
8794 | if (*dprintf_args == ',') | |
8795 | ++dprintf_args; | |
8796 | dprintf_args = skip_spaces (dprintf_args); | |
8797 | ||
8798 | if (*dprintf_args != '"') | |
8799 | error (_("Bad format string, missing '\"'.")); | |
8800 | ||
d3ce09f5 | 8801 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8802 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8803 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8804 | { |
8805 | if (!dprintf_function) | |
8806 | error (_("No function supplied for dprintf call")); | |
8807 | ||
8808 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8809 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8810 | dprintf_function, | |
8811 | dprintf_channel, | |
8812 | dprintf_args); | |
8813 | else | |
8814 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8815 | dprintf_function, | |
8816 | dprintf_args); | |
8817 | } | |
d3ce09f5 SS |
8818 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8819 | { | |
8820 | if (target_can_run_breakpoint_commands ()) | |
8821 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8822 | else | |
8823 | { | |
8824 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8825 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8826 | } | |
8827 | } | |
e7e0cddf SS |
8828 | else |
8829 | internal_error (__FILE__, __LINE__, | |
8830 | _("Invalid dprintf style.")); | |
8831 | ||
f28045c2 | 8832 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 8833 | /* Manufacture a printf sequence. */ |
f28045c2 | 8834 | { |
8d749320 | 8835 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 8836 | |
f28045c2 YQ |
8837 | printf_cmd_line->control_type = simple_control; |
8838 | printf_cmd_line->body_count = 0; | |
8839 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 8840 | printf_cmd_line->next = NULL; |
f28045c2 | 8841 | printf_cmd_line->line = printf_line; |
e7e0cddf | 8842 | |
93921405 | 8843 | breakpoint_set_commands (b, command_line_up (printf_cmd_line)); |
f28045c2 | 8844 | } |
e7e0cddf SS |
8845 | } |
8846 | ||
8847 | /* Update all dprintf commands, making their command lists reflect | |
8848 | current style settings. */ | |
8849 | ||
8850 | static void | |
eb4c3f4a | 8851 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8852 | struct cmd_list_element *c) |
8853 | { | |
8854 | struct breakpoint *b; | |
8855 | ||
8856 | ALL_BREAKPOINTS (b) | |
8857 | { | |
8858 | if (b->type == bp_dprintf) | |
8859 | update_dprintf_command_list (b); | |
8860 | } | |
8861 | } | |
c3f6f71d | 8862 | |
f00aae0f KS |
8863 | /* Create a breakpoint with SAL as location. Use LOCATION |
8864 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8865 | as condition expression. If LOCATION is NULL then create an |
8866 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8867 | |
8868 | static void | |
d9b3f62e | 8869 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8870 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8871 | event_location_up &&location, |
e1e01040 PA |
8872 | gdb::unique_xmalloc_ptr<char> filter, |
8873 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8874 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8875 | enum bptype type, enum bpdisp disposition, |
8876 | int thread, int task, int ignore_count, | |
c0a91b2b | 8877 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8878 | int enabled, int internal, unsigned flags, |
8879 | int display_canonical) | |
018d34a4 | 8880 | { |
0d381245 | 8881 | int i; |
018d34a4 VP |
8882 | |
8883 | if (type == bp_hardware_breakpoint) | |
8884 | { | |
fbbd034e AS |
8885 | int target_resources_ok; |
8886 | ||
8887 | i = hw_breakpoint_used_count (); | |
8888 | target_resources_ok = | |
8889 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8890 | i + 1, 0); |
8891 | if (target_resources_ok == 0) | |
8892 | error (_("No hardware breakpoint support in the target.")); | |
8893 | else if (target_resources_ok < 0) | |
8894 | error (_("Hardware breakpoints used exceeds limit.")); | |
8895 | } | |
8896 | ||
6c5b2ebe | 8897 | gdb_assert (!sals.empty ()); |
6c95b8df | 8898 | |
6c5b2ebe | 8899 | for (const auto &sal : sals) |
0d381245 | 8900 | { |
0d381245 VP |
8901 | struct bp_location *loc; |
8902 | ||
8903 | if (from_tty) | |
5af949e3 UW |
8904 | { |
8905 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8906 | if (!loc_gdbarch) | |
8907 | loc_gdbarch = gdbarch; | |
8908 | ||
8909 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8910 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8911 | } |
0d381245 | 8912 | |
6c5b2ebe | 8913 | if (&sal == &sals[0]) |
0d381245 | 8914 | { |
d9b3f62e | 8915 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8916 | b->thread = thread; |
4a306c9a | 8917 | b->task = task; |
855a6e68 | 8918 | |
e1e01040 PA |
8919 | b->cond_string = cond_string.release (); |
8920 | b->extra_string = extra_string.release (); | |
0d381245 | 8921 | b->ignore_count = ignore_count; |
41447f92 | 8922 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8923 | b->disposition = disposition; |
6c95b8df | 8924 | |
44f238bb PA |
8925 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8926 | b->loc->inserted = 1; | |
8927 | ||
0fb4aa4b PA |
8928 | if (type == bp_static_tracepoint) |
8929 | { | |
d9b3f62e | 8930 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8931 | struct static_tracepoint_marker marker; |
8932 | ||
983af33b | 8933 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8934 | { |
8935 | /* We already know the marker exists, otherwise, we | |
8936 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8937 | const char *p |
8938 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8939 | const char *endp; |
0fb4aa4b | 8940 | char *marker_str; |
0fb4aa4b | 8941 | |
f1735a53 | 8942 | p = skip_spaces (p); |
0fb4aa4b | 8943 | |
f1735a53 | 8944 | endp = skip_to_space (p); |
0fb4aa4b PA |
8945 | |
8946 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 8947 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 8948 | |
3e43a32a MS |
8949 | printf_filtered (_("Probed static tracepoint " |
8950 | "marker \"%s\"\n"), | |
d9b3f62e | 8951 | t->static_trace_marker_id); |
0fb4aa4b PA |
8952 | } |
8953 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8954 | { | |
d9b3f62e | 8955 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
8956 | release_static_tracepoint_marker (&marker); |
8957 | ||
3e43a32a MS |
8958 | printf_filtered (_("Probed static tracepoint " |
8959 | "marker \"%s\"\n"), | |
d9b3f62e | 8960 | t->static_trace_marker_id); |
0fb4aa4b PA |
8961 | } |
8962 | else | |
3e43a32a MS |
8963 | warning (_("Couldn't determine the static " |
8964 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8965 | } |
8966 | ||
0d381245 VP |
8967 | loc = b->loc; |
8968 | } | |
8969 | else | |
018d34a4 | 8970 | { |
39d61571 | 8971 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8972 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8973 | loc->inserted = 1; | |
0d381245 VP |
8974 | } |
8975 | ||
8976 | if (b->cond_string) | |
8977 | { | |
bbc13ae3 KS |
8978 | const char *arg = b->cond_string; |
8979 | ||
1bb9788d TT |
8980 | loc->cond = parse_exp_1 (&arg, loc->address, |
8981 | block_for_pc (loc->address), 0); | |
0d381245 | 8982 | if (*arg) |
588ae58c | 8983 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 8984 | } |
e7e0cddf SS |
8985 | |
8986 | /* Dynamic printf requires and uses additional arguments on the | |
8987 | command line, otherwise it's an error. */ | |
8988 | if (type == bp_dprintf) | |
8989 | { | |
8990 | if (b->extra_string) | |
8991 | update_dprintf_command_list (b); | |
8992 | else | |
8993 | error (_("Format string required")); | |
8994 | } | |
8995 | else if (b->extra_string) | |
588ae58c | 8996 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 8997 | } |
018d34a4 | 8998 | |
56435ebe | 8999 | b->display_canonical = display_canonical; |
f00aae0f | 9000 | if (location != NULL) |
d28cd78a | 9001 | b->location = std::move (location); |
018d34a4 | 9002 | else |
d28cd78a | 9003 | b->location = new_address_location (b->loc->address, NULL, 0); |
e1e01040 | 9004 | b->filter = filter.release (); |
d9b3f62e | 9005 | } |
018d34a4 | 9006 | |
d9b3f62e PA |
9007 | static void |
9008 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 9009 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9010 | event_location_up &&location, |
e1e01040 PA |
9011 | gdb::unique_xmalloc_ptr<char> filter, |
9012 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9013 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9014 | enum bptype type, enum bpdisp disposition, |
9015 | int thread, int task, int ignore_count, | |
c0a91b2b | 9016 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9017 | int enabled, int internal, unsigned flags, |
9018 | int display_canonical) | |
d9b3f62e | 9019 | { |
a5e364af | 9020 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 9021 | |
a5e364af | 9022 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 9023 | sals, std::move (location), |
e1e01040 PA |
9024 | std::move (filter), |
9025 | std::move (cond_string), | |
9026 | std::move (extra_string), | |
d9b3f62e PA |
9027 | type, disposition, |
9028 | thread, task, ignore_count, | |
9029 | ops, from_tty, | |
44f238bb PA |
9030 | enabled, internal, flags, |
9031 | display_canonical); | |
d9b3f62e | 9032 | |
b270e6f9 | 9033 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
9034 | } |
9035 | ||
9036 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9037 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9038 | value. COND_STRING, if not NULL, specified the condition to be | |
9039 | used for all breakpoints. Essentially the only case where | |
9040 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9041 | function. In that case, it's still not possible to specify | |
9042 | separate conditions for different overloaded functions, so | |
9043 | we take just a single condition string. | |
9044 | ||
c3f6f71d | 9045 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9046 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9047 | array contents). If the function fails (error() is called), the |
9048 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9049 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9050 | |
9051 | static void | |
8cdf0e15 | 9052 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9053 | struct linespec_result *canonical, |
e1e01040 PA |
9054 | gdb::unique_xmalloc_ptr<char> cond_string, |
9055 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
9056 | enum bptype type, enum bpdisp disposition, |
9057 | int thread, int task, int ignore_count, | |
c0a91b2b | 9058 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9059 | int enabled, int internal, unsigned flags) |
c906108c | 9060 | { |
f8eba3c6 | 9061 | if (canonical->pre_expanded) |
6c5b2ebe | 9062 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 9063 | |
6c5b2ebe | 9064 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 9065 | { |
f00aae0f | 9066 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9067 | 'break', without arguments. */ |
ffc2605c | 9068 | event_location_up location |
f00aae0f | 9069 | = (canonical->location != NULL |
8e9e35b1 | 9070 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 9071 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 9072 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 9073 | |
6c5b2ebe | 9074 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 9075 | std::move (location), |
e1e01040 PA |
9076 | std::move (filter_string), |
9077 | std::move (cond_string), | |
9078 | std::move (extra_string), | |
e7e0cddf | 9079 | type, disposition, |
84f4c1fe | 9080 | thread, task, ignore_count, ops, |
44f238bb | 9081 | from_tty, enabled, internal, flags, |
56435ebe | 9082 | canonical->special_display); |
c3f6f71d | 9083 | } |
c3f6f71d | 9084 | } |
c906108c | 9085 | |
f00aae0f | 9086 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9087 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9088 | addresses found. LOCATION points to the end of the SAL (for |
9089 | linespec locations). | |
9998af43 TJB |
9090 | |
9091 | The array and the line spec strings are allocated on the heap, it is | |
9092 | the caller's responsibility to free them. */ | |
c906108c | 9093 | |
b9362cc7 | 9094 | static void |
f00aae0f | 9095 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9096 | struct linespec_result *canonical) |
c3f6f71d | 9097 | { |
f00aae0f KS |
9098 | struct symtab_and_line cursal; |
9099 | ||
9100 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9101 | { | |
a20714ff | 9102 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 9103 | |
a20714ff | 9104 | if (spec == NULL) |
f00aae0f KS |
9105 | { |
9106 | /* The last displayed codepoint, if it's valid, is our default | |
9107 | breakpoint address. */ | |
9108 | if (last_displayed_sal_is_valid ()) | |
9109 | { | |
f00aae0f KS |
9110 | /* Set sal's pspace, pc, symtab, and line to the values |
9111 | corresponding to the last call to print_frame_info. | |
9112 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9113 | as the breakpoint line number is inappropriate otherwise. | |
9114 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
9115 | symtab_and_line sal = get_last_displayed_sal (); |
9116 | CORE_ADDR pc = sal.pc; | |
9117 | ||
f00aae0f KS |
9118 | sal = find_pc_line (pc, 0); |
9119 | ||
9120 | /* "break" without arguments is equivalent to "break *PC" | |
9121 | where PC is the last displayed codepoint's address. So | |
9122 | make sure to set sal.explicit_pc to prevent GDB from | |
9123 | trying to expand the list of sals to include all other | |
9124 | instances with the same symtab and line. */ | |
9125 | sal.pc = pc; | |
9126 | sal.explicit_pc = 1; | |
9127 | ||
6c5b2ebe PA |
9128 | struct linespec_sals lsal; |
9129 | lsal.sals = {sal}; | |
f00aae0f KS |
9130 | lsal.canonical = NULL; |
9131 | ||
6c5b2ebe | 9132 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
9133 | return; |
9134 | } | |
9135 | else | |
9136 | error (_("No default breakpoint address now.")); | |
c906108c | 9137 | } |
c906108c | 9138 | } |
f00aae0f KS |
9139 | |
9140 | /* Force almost all breakpoints to be in terms of the | |
9141 | current_source_symtab (which is decode_line_1's default). | |
9142 | This should produce the results we want almost all of the | |
9143 | time while leaving default_breakpoint_* alone. | |
9144 | ||
9145 | ObjC: However, don't match an Objective-C method name which | |
9146 | may have a '+' or '-' succeeded by a '['. */ | |
9147 | cursal = get_current_source_symtab_and_line (); | |
9148 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9149 | { |
a20714ff | 9150 | const char *spec = NULL; |
cc80f267 | 9151 | |
f00aae0f | 9152 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 9153 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 9154 | |
f00aae0f | 9155 | if (!cursal.symtab |
a20714ff PA |
9156 | || (spec != NULL |
9157 | && strchr ("+-", spec[0]) != NULL | |
9158 | && spec[1] != '[')) | |
f00aae0f | 9159 | { |
c2f4122d | 9160 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9161 | get_last_displayed_symtab (), |
9162 | get_last_displayed_line (), | |
9163 | canonical, NULL, NULL); | |
9164 | return; | |
9165 | } | |
c906108c | 9166 | } |
f00aae0f | 9167 | |
c2f4122d | 9168 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9169 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9170 | } |
c906108c | 9171 | |
c906108c | 9172 | |
c3f6f71d | 9173 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9174 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9175 | |
b9362cc7 | 9176 | static void |
6c5b2ebe | 9177 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9178 | { |
6c5b2ebe PA |
9179 | for (auto &sal : sals) |
9180 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9181 | } |
9182 | ||
7a697b8d SS |
9183 | /* Fast tracepoints may have restrictions on valid locations. For |
9184 | instance, a fast tracepoint using a jump instead of a trap will | |
9185 | likely have to overwrite more bytes than a trap would, and so can | |
9186 | only be placed where the instruction is longer than the jump, or a | |
9187 | multi-instruction sequence does not have a jump into the middle of | |
9188 | it, etc. */ | |
9189 | ||
9190 | static void | |
9191 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9192 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9193 | { |
6c5b2ebe | 9194 | int rslt; |
7a697b8d SS |
9195 | char *msg; |
9196 | struct cleanup *old_chain; | |
9197 | ||
6c5b2ebe | 9198 | for (const auto &sal : sals) |
7a697b8d | 9199 | { |
f8eba3c6 TT |
9200 | struct gdbarch *sarch; |
9201 | ||
6c5b2ebe | 9202 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9203 | /* We fall back to GDBARCH if there is no architecture |
9204 | associated with SAL. */ | |
9205 | if (sarch == NULL) | |
9206 | sarch = gdbarch; | |
6c5b2ebe | 9207 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg); |
7a697b8d SS |
9208 | old_chain = make_cleanup (xfree, msg); |
9209 | ||
9210 | if (!rslt) | |
53c3572a | 9211 | error (_("May not have a fast tracepoint at %s%s"), |
6c5b2ebe | 9212 | paddress (sarch, sal.pc), (msg ? msg : "")); |
7a697b8d SS |
9213 | |
9214 | do_cleanups (old_chain); | |
9215 | } | |
9216 | } | |
9217 | ||
018d34a4 VP |
9218 | /* Given TOK, a string specification of condition and thread, as |
9219 | accepted by the 'break' command, extract the condition | |
9220 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9221 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9222 | If no condition is found, *COND_STRING is set to NULL. |
9223 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9224 | |
9225 | static void | |
bbc13ae3 | 9226 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9227 | char **cond_string, int *thread, int *task, |
9228 | char **rest) | |
018d34a4 VP |
9229 | { |
9230 | *cond_string = NULL; | |
9231 | *thread = -1; | |
ed1d1739 KS |
9232 | *task = 0; |
9233 | *rest = NULL; | |
9234 | ||
018d34a4 VP |
9235 | while (tok && *tok) |
9236 | { | |
bbc13ae3 | 9237 | const char *end_tok; |
018d34a4 | 9238 | int toklen; |
bbc13ae3 KS |
9239 | const char *cond_start = NULL; |
9240 | const char *cond_end = NULL; | |
cc59ec59 | 9241 | |
f1735a53 | 9242 | tok = skip_spaces (tok); |
e7e0cddf SS |
9243 | |
9244 | if ((*tok == '"' || *tok == ',') && rest) | |
9245 | { | |
9246 | *rest = savestring (tok, strlen (tok)); | |
9247 | return; | |
9248 | } | |
9249 | ||
f1735a53 | 9250 | end_tok = skip_to_space (tok); |
d634f2de | 9251 | |
018d34a4 | 9252 | toklen = end_tok - tok; |
d634f2de | 9253 | |
018d34a4 VP |
9254 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9255 | { | |
9256 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9257 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9258 | cond_end = tok; |
d634f2de | 9259 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9260 | } |
9261 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9262 | { | |
5d5658a1 PA |
9263 | const char *tmptok; |
9264 | struct thread_info *thr; | |
d634f2de | 9265 | |
018d34a4 | 9266 | tok = end_tok + 1; |
5d5658a1 | 9267 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9268 | if (tok == tmptok) |
9269 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9270 | *thread = thr->global_num; |
bbc13ae3 | 9271 | tok = tmptok; |
018d34a4 | 9272 | } |
4a306c9a JB |
9273 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9274 | { | |
9275 | char *tmptok; | |
9276 | ||
9277 | tok = end_tok + 1; | |
bbc13ae3 | 9278 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9279 | if (tok == tmptok) |
9280 | error (_("Junk after task keyword.")); | |
9281 | if (!valid_task_id (*task)) | |
b6199126 | 9282 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9283 | tok = tmptok; |
4a306c9a | 9284 | } |
e7e0cddf SS |
9285 | else if (rest) |
9286 | { | |
9287 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9288 | return; |
e7e0cddf | 9289 | } |
018d34a4 VP |
9290 | else |
9291 | error (_("Junk at end of arguments.")); | |
9292 | } | |
9293 | } | |
9294 | ||
0fb4aa4b PA |
9295 | /* Decode a static tracepoint marker spec. */ |
9296 | ||
6c5b2ebe | 9297 | static std::vector<symtab_and_line> |
f00aae0f | 9298 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9299 | { |
9300 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
f00aae0f KS |
9301 | const char *p = &(*arg_p)[3]; |
9302 | const char *endp; | |
0fb4aa4b PA |
9303 | int i; |
9304 | ||
f1735a53 | 9305 | p = skip_spaces (p); |
0fb4aa4b | 9306 | |
f1735a53 | 9307 | endp = skip_to_space (p); |
0fb4aa4b | 9308 | |
81b1e71c | 9309 | std::string marker_str (p, endp - p); |
0fb4aa4b | 9310 | |
81b1e71c | 9311 | markers = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); |
0fb4aa4b | 9312 | if (VEC_empty(static_tracepoint_marker_p, markers)) |
81b1e71c TT |
9313 | error (_("No known static tracepoint marker named %s"), |
9314 | marker_str.c_str ()); | |
0fb4aa4b | 9315 | |
6c5b2ebe PA |
9316 | std::vector<symtab_and_line> sals; |
9317 | sals.reserve (VEC_length(static_tracepoint_marker_p, markers)); | |
0fb4aa4b | 9318 | |
6c5b2ebe | 9319 | for (i = 0; i < VEC_length(static_tracepoint_marker_p, markers); i++) |
0fb4aa4b PA |
9320 | { |
9321 | struct static_tracepoint_marker *marker; | |
9322 | ||
9323 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9324 | ||
51abb421 | 9325 | symtab_and_line sal = find_pc_line (marker->address, 0); |
6c5b2ebe PA |
9326 | sal.pc = marker->address; |
9327 | sals.push_back (sal); | |
0fb4aa4b PA |
9328 | |
9329 | release_static_tracepoint_marker (marker); | |
9330 | } | |
9331 | ||
0fb4aa4b PA |
9332 | *arg_p = endp; |
9333 | return sals; | |
9334 | } | |
9335 | ||
f00aae0f | 9336 | /* See breakpoint.h. */ |
0101ce28 | 9337 | |
8cdf0e15 VP |
9338 | int |
9339 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9340 | const struct event_location *location, |
9341 | const char *cond_string, | |
9342 | int thread, const char *extra_string, | |
f00aae0f | 9343 | int parse_extra, |
0fb4aa4b | 9344 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9345 | int ignore_count, |
9346 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9347 | const struct breakpoint_ops *ops, |
44f238bb PA |
9348 | int from_tty, int enabled, int internal, |
9349 | unsigned flags) | |
c3f6f71d | 9350 | { |
7efd8fc2 | 9351 | struct linespec_result canonical; |
80c99de1 | 9352 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9353 | int pending = 0; |
4a306c9a | 9354 | int task = 0; |
86b17b60 | 9355 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9356 | |
348d480f PA |
9357 | gdb_assert (ops != NULL); |
9358 | ||
f00aae0f KS |
9359 | /* If extra_string isn't useful, set it to NULL. */ |
9360 | if (extra_string != NULL && *extra_string == '\0') | |
9361 | extra_string = NULL; | |
9362 | ||
492d29ea | 9363 | TRY |
b78a6381 | 9364 | { |
f00aae0f | 9365 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9366 | } |
492d29ea | 9367 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9368 | { |
492d29ea PA |
9369 | /* If caller is interested in rc value from parse, set |
9370 | value. */ | |
9371 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9372 | { |
05ff989b AC |
9373 | /* If pending breakpoint support is turned off, throw |
9374 | error. */ | |
fa8d40ab JJ |
9375 | |
9376 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9377 | throw_exception (e); |
9378 | ||
9379 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9380 | |
05ff989b AC |
9381 | /* If pending breakpoint support is auto query and the user |
9382 | selects no, then simply return the error code. */ | |
059fb39f | 9383 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9384 | && !nquery (_("Make %s pending on future shared library load? "), |
9385 | bptype_string (type_wanted))) | |
fd9b8c24 | 9386 | return 0; |
fa8d40ab | 9387 | |
05ff989b AC |
9388 | /* At this point, either the user was queried about setting |
9389 | a pending breakpoint and selected yes, or pending | |
9390 | breakpoint behavior is on and thus a pending breakpoint | |
9391 | is defaulted on behalf of the user. */ | |
f00aae0f | 9392 | pending = 1; |
0101ce28 | 9393 | } |
492d29ea PA |
9394 | else |
9395 | throw_exception (e); | |
0101ce28 | 9396 | } |
492d29ea PA |
9397 | END_CATCH |
9398 | ||
6c5b2ebe | 9399 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9400 | return 0; |
c3f6f71d | 9401 | |
c3f6f71d JM |
9402 | /* ----------------------------- SNIP ----------------------------- |
9403 | Anything added to the cleanup chain beyond this point is assumed | |
9404 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9405 | then the memory is not reclaimed. */ |
9406 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9407 | |
c3f6f71d JM |
9408 | /* Resolve all line numbers to PC's and verify that the addresses |
9409 | are ok for the target. */ | |
0101ce28 | 9410 | if (!pending) |
f8eba3c6 | 9411 | { |
6c5b2ebe PA |
9412 | for (auto &lsal : canonical.lsals) |
9413 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9414 | } |
c3f6f71d | 9415 | |
7a697b8d | 9416 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9417 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9418 | { |
6c5b2ebe PA |
9419 | for (const auto &lsal : canonical.lsals) |
9420 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9421 | } |
7a697b8d | 9422 | |
c3f6f71d JM |
9423 | /* Verify that condition can be parsed, before setting any |
9424 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9425 | breakpoint. */ |
0101ce28 | 9426 | if (!pending) |
c3f6f71d | 9427 | { |
e1e01040 PA |
9428 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9429 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9430 | ||
f00aae0f | 9431 | if (parse_extra) |
72b2ff0e | 9432 | { |
0878d0fa | 9433 | char *rest; |
e1e01040 | 9434 | char *cond; |
52d361e1 | 9435 | |
6c5b2ebe | 9436 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9437 | |
0878d0fa YQ |
9438 | /* Here we only parse 'arg' to separate condition |
9439 | from thread number, so parsing in context of first | |
9440 | sal is OK. When setting the breakpoint we'll | |
9441 | re-parse it in context of each sal. */ | |
9442 | ||
6c5b2ebe | 9443 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9444 | &cond, &thread, &task, &rest); |
9445 | cond_string_copy.reset (cond); | |
9446 | extra_string_copy.reset (rest); | |
72b2ff0e | 9447 | } |
2f069f6f | 9448 | else |
72b2ff0e | 9449 | { |
f00aae0f KS |
9450 | if (type_wanted != bp_dprintf |
9451 | && extra_string != NULL && *extra_string != '\0') | |
9452 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9453 | |
9454 | /* Create a private copy of condition string. */ | |
9455 | if (cond_string) | |
e1e01040 | 9456 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9457 | /* Create a private copy of any extra string. */ |
9458 | if (extra_string) | |
e1e01040 | 9459 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9460 | } |
0fb4aa4b | 9461 | |
52d361e1 | 9462 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9463 | std::move (cond_string_copy), |
9464 | std::move (extra_string_copy), | |
9465 | type_wanted, | |
d9b3f62e PA |
9466 | tempflag ? disp_del : disp_donttouch, |
9467 | thread, task, ignore_count, ops, | |
44f238bb | 9468 | from_tty, enabled, internal, flags); |
c906108c | 9469 | } |
0101ce28 JJ |
9470 | else |
9471 | { | |
a5e364af | 9472 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9473 | |
a5e364af | 9474 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9475 | b->location = copy_event_location (location); |
bfccc43c | 9476 | |
f00aae0f KS |
9477 | if (parse_extra) |
9478 | b->cond_string = NULL; | |
e12c7713 MK |
9479 | else |
9480 | { | |
9481 | /* Create a private copy of condition string. */ | |
e1e01040 | 9482 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9483 | b->thread = thread; |
e12c7713 | 9484 | } |
f00aae0f KS |
9485 | |
9486 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9487 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9488 | b->ignore_count = ignore_count; |
0101ce28 | 9489 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9490 | b->condition_not_parsed = 1; |
41447f92 | 9491 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9492 | if ((type_wanted != bp_breakpoint |
9493 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9494 | b->pspace = current_program_space; |
8bea4e01 | 9495 | |
b270e6f9 | 9496 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9497 | } |
9498 | ||
6c5b2ebe | 9499 | if (canonical.lsals.size () > 1) |
95a42b64 | 9500 | { |
3e43a32a MS |
9501 | warning (_("Multiple breakpoints were set.\nUse the " |
9502 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9503 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9504 | } |
9505 | ||
80c99de1 PA |
9506 | /* That's it. Discard the cleanups for data inserted into the |
9507 | breakpoint. */ | |
9508 | discard_cleanups (bkpt_chain); | |
217dc9e2 | 9509 | |
80c99de1 | 9510 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9511 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9512 | |
9513 | return 1; | |
c3f6f71d | 9514 | } |
c906108c | 9515 | |
348d480f | 9516 | /* Set a breakpoint. |
72b2ff0e VP |
9517 | ARG is a string describing breakpoint address, |
9518 | condition, and thread. | |
9519 | FLAG specifies if a breakpoint is hardware on, | |
9520 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9521 | and BP_TEMPFLAG. */ | |
348d480f | 9522 | |
98deb0da | 9523 | static void |
f2fc3015 | 9524 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9525 | { |
72b2ff0e | 9526 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9527 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9528 | ? bp_hardware_breakpoint | |
9529 | : bp_breakpoint); | |
55aa24fb | 9530 | struct breakpoint_ops *ops; |
f00aae0f | 9531 | |
ffc2605c | 9532 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9533 | |
9534 | /* Matching breakpoints on probes. */ | |
5b56227b | 9535 | if (location != NULL |
ffc2605c | 9536 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9537 | ops = &bkpt_probe_breakpoint_ops; |
9538 | else | |
9539 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9540 | |
8cdf0e15 | 9541 | create_breakpoint (get_current_arch (), |
ffc2605c | 9542 | location.get (), |
f00aae0f | 9543 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9544 | tempflag, type_wanted, |
8cdf0e15 VP |
9545 | 0 /* Ignore count */, |
9546 | pending_break_support, | |
55aa24fb | 9547 | ops, |
8cdf0e15 | 9548 | from_tty, |
84f4c1fe | 9549 | 1 /* enabled */, |
44f238bb PA |
9550 | 0 /* internal */, |
9551 | 0); | |
c906108c SS |
9552 | } |
9553 | ||
c906108c SS |
9554 | /* Helper function for break_command_1 and disassemble_command. */ |
9555 | ||
9556 | void | |
fba45db2 | 9557 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9558 | { |
9559 | CORE_ADDR pc; | |
9560 | ||
9561 | if (sal->pc == 0 && sal->symtab != NULL) | |
9562 | { | |
9563 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9564 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9565 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9566 | sal->pc = pc; |
6a048695 | 9567 | |
4a64f543 MS |
9568 | /* If this SAL corresponds to a breakpoint inserted using a line |
9569 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9570 | if (sal->explicit_line) |
059acae7 | 9571 | skip_prologue_sal (sal); |
c906108c SS |
9572 | } |
9573 | ||
9574 | if (sal->section == 0 && sal->symtab != NULL) | |
9575 | { | |
346d1dfe | 9576 | const struct blockvector *bv; |
3977b71f | 9577 | const struct block *b; |
c5aa993b | 9578 | struct symbol *sym; |
c906108c | 9579 | |
43f3e411 DE |
9580 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9581 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9582 | if (bv != NULL) |
9583 | { | |
7f0df278 | 9584 | sym = block_linkage_function (b); |
c906108c SS |
9585 | if (sym != NULL) |
9586 | { | |
eb822aa6 DE |
9587 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9588 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9589 | sym); | |
c906108c SS |
9590 | } |
9591 | else | |
9592 | { | |
4a64f543 MS |
9593 | /* It really is worthwhile to have the section, so we'll |
9594 | just have to look harder. This case can be executed | |
9595 | if we have line numbers but no functions (as can | |
9596 | happen in assembly source). */ | |
c906108c | 9597 | |
5ed8105e | 9598 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9599 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9600 | |
5ed8105e | 9601 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9602 | if (msym.minsym) |
efd66ac6 | 9603 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9604 | } |
9605 | } | |
9606 | } | |
9607 | } | |
9608 | ||
9609 | void | |
0b39b52e | 9610 | break_command (const char *arg, int from_tty) |
c906108c | 9611 | { |
db107f19 | 9612 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9613 | } |
9614 | ||
c906108c | 9615 | void |
0b39b52e | 9616 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9617 | { |
db107f19 | 9618 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9619 | } |
9620 | ||
c906108c | 9621 | static void |
0b39b52e | 9622 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9623 | { |
db107f19 | 9624 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9625 | } |
9626 | ||
9627 | static void | |
0b39b52e | 9628 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9629 | { |
db107f19 | 9630 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9631 | } |
9632 | ||
9633 | static void | |
ee7ddd71 | 9634 | stop_command (const char *arg, int from_tty) |
c906108c | 9635 | { |
a3f17187 | 9636 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9637 | Usage: stop in <function | address>\n\ |
a3f17187 | 9638 | stop at <line>\n")); |
c906108c SS |
9639 | } |
9640 | ||
9641 | static void | |
4495129a | 9642 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9643 | { |
9644 | int badInput = 0; | |
9645 | ||
c5aa993b | 9646 | if (arg == (char *) NULL) |
c906108c SS |
9647 | badInput = 1; |
9648 | else if (*arg != '*') | |
9649 | { | |
4495129a | 9650 | const char *argptr = arg; |
c906108c SS |
9651 | int hasColon = 0; |
9652 | ||
4a64f543 | 9653 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9654 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9655 | function/method name. */ |
c906108c | 9656 | while (*argptr && !hasColon) |
c5aa993b JM |
9657 | { |
9658 | hasColon = (*argptr == ':'); | |
9659 | argptr++; | |
9660 | } | |
c906108c SS |
9661 | |
9662 | if (hasColon) | |
c5aa993b | 9663 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9664 | else |
c5aa993b | 9665 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9666 | } |
9667 | ||
9668 | if (badInput) | |
a3f17187 | 9669 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9670 | else |
db107f19 | 9671 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9672 | } |
9673 | ||
9674 | static void | |
4495129a | 9675 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9676 | { |
9677 | int badInput = 0; | |
9678 | ||
c5aa993b | 9679 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9680 | badInput = 1; |
9681 | else | |
9682 | { | |
4495129a | 9683 | const char *argptr = arg; |
c906108c SS |
9684 | int hasColon = 0; |
9685 | ||
4a64f543 MS |
9686 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9687 | it is probably a line number. */ | |
c906108c | 9688 | while (*argptr && !hasColon) |
c5aa993b JM |
9689 | { |
9690 | hasColon = (*argptr == ':'); | |
9691 | argptr++; | |
9692 | } | |
c906108c SS |
9693 | |
9694 | if (hasColon) | |
c5aa993b | 9695 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9696 | else |
c5aa993b | 9697 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9698 | } |
9699 | ||
9700 | if (badInput) | |
a3f17187 | 9701 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9702 | else |
db107f19 | 9703 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9704 | } |
9705 | ||
e7e0cddf SS |
9706 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9707 | with a prewired command list consisting of a single output command, | |
9708 | built from extra arguments supplied on the dprintf command | |
9709 | line. */ | |
9710 | ||
da821c7b | 9711 | static void |
0b39b52e | 9712 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9713 | { |
ffc2605c | 9714 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9715 | |
9716 | /* If non-NULL, ARG should have been advanced past the location; | |
9717 | the next character must be ','. */ | |
9718 | if (arg != NULL) | |
9719 | { | |
9720 | if (arg[0] != ',' || arg[1] == '\0') | |
9721 | error (_("Format string required")); | |
9722 | else | |
9723 | { | |
9724 | /* Skip the comma. */ | |
9725 | ++arg; | |
9726 | } | |
9727 | } | |
9728 | ||
e7e0cddf | 9729 | create_breakpoint (get_current_arch (), |
ffc2605c | 9730 | location.get (), |
f00aae0f | 9731 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9732 | 0, bp_dprintf, |
9733 | 0 /* Ignore count */, | |
9734 | pending_break_support, | |
9735 | &dprintf_breakpoint_ops, | |
9736 | from_tty, | |
9737 | 1 /* enabled */, | |
9738 | 0 /* internal */, | |
9739 | 0); | |
9740 | } | |
9741 | ||
d3ce09f5 | 9742 | static void |
0b39b52e | 9743 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9744 | { |
9745 | error (_("May only run agent-printf on the target")); | |
9746 | } | |
9747 | ||
f1310107 TJB |
9748 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9749 | ranged breakpoints. */ | |
9750 | ||
9751 | static int | |
9752 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
bd522513 | 9753 | const address_space *aspace, |
09ac7c10 TT |
9754 | CORE_ADDR bp_addr, |
9755 | const struct target_waitstatus *ws) | |
f1310107 | 9756 | { |
09ac7c10 | 9757 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9758 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9759 | return 0; |
9760 | ||
f1310107 TJB |
9761 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9762 | bl->length, aspace, bp_addr); | |
9763 | } | |
9764 | ||
9765 | /* Implement the "resources_needed" breakpoint_ops method for | |
9766 | ranged breakpoints. */ | |
9767 | ||
9768 | static int | |
9769 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9770 | { | |
9771 | return target_ranged_break_num_registers (); | |
9772 | } | |
9773 | ||
9774 | /* Implement the "print_it" breakpoint_ops method for | |
9775 | ranged breakpoints. */ | |
9776 | ||
9777 | static enum print_stop_action | |
348d480f | 9778 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9779 | { |
348d480f | 9780 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9781 | struct bp_location *bl = b->loc; |
79a45e25 | 9782 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9783 | |
9784 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9785 | ||
9786 | /* Ranged breakpoints have only one location. */ | |
9787 | gdb_assert (bl && bl->next == NULL); | |
9788 | ||
9789 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9790 | |
9791 | maybe_print_thread_hit_breakpoint (uiout); | |
9792 | ||
f1310107 | 9793 | if (b->disposition == disp_del) |
112e8700 | 9794 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9795 | else |
112e8700 SM |
9796 | uiout->text ("Ranged breakpoint "); |
9797 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9798 | { |
112e8700 | 9799 | uiout->field_string ("reason", |
f1310107 | 9800 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9801 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9802 | } |
112e8700 SM |
9803 | uiout->field_int ("bkptno", b->number); |
9804 | uiout->text (", "); | |
f1310107 TJB |
9805 | |
9806 | return PRINT_SRC_AND_LOC; | |
9807 | } | |
9808 | ||
9809 | /* Implement the "print_one" breakpoint_ops method for | |
9810 | ranged breakpoints. */ | |
9811 | ||
9812 | static void | |
9813 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9814 | struct bp_location **last_loc) | |
9815 | { | |
9816 | struct bp_location *bl = b->loc; | |
9817 | struct value_print_options opts; | |
79a45e25 | 9818 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9819 | |
9820 | /* Ranged breakpoints have only one location. */ | |
9821 | gdb_assert (bl && bl->next == NULL); | |
9822 | ||
9823 | get_user_print_options (&opts); | |
9824 | ||
9825 | if (opts.addressprint) | |
9826 | /* We don't print the address range here, it will be printed later | |
9827 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9828 | uiout->field_skip ("addr"); |
f1310107 TJB |
9829 | annotate_field (5); |
9830 | print_breakpoint_location (b, bl); | |
9831 | *last_loc = bl; | |
9832 | } | |
9833 | ||
9834 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9835 | ranged breakpoints. */ | |
9836 | ||
9837 | static void | |
9838 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9839 | struct ui_out *uiout) | |
9840 | { | |
9841 | CORE_ADDR address_start, address_end; | |
9842 | struct bp_location *bl = b->loc; | |
d7e74731 | 9843 | string_file stb; |
f1310107 TJB |
9844 | |
9845 | gdb_assert (bl); | |
9846 | ||
9847 | address_start = bl->address; | |
9848 | address_end = address_start + bl->length - 1; | |
9849 | ||
112e8700 | 9850 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9851 | stb.printf ("[%s, %s]", |
9852 | print_core_address (bl->gdbarch, address_start), | |
9853 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9854 | uiout->field_stream ("addr", stb); |
9855 | uiout->text ("\n"); | |
f1310107 TJB |
9856 | } |
9857 | ||
9858 | /* Implement the "print_mention" breakpoint_ops method for | |
9859 | ranged breakpoints. */ | |
9860 | ||
9861 | static void | |
9862 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9863 | { | |
9864 | struct bp_location *bl = b->loc; | |
79a45e25 | 9865 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9866 | |
9867 | gdb_assert (bl); | |
9868 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9869 | ||
112e8700 | 9870 | if (uiout->is_mi_like_p ()) |
f1310107 TJB |
9871 | return; |
9872 | ||
9873 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
9874 | b->number, paddress (bl->gdbarch, bl->address), | |
9875 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
9876 | } | |
9877 | ||
9878 | /* Implement the "print_recreate" breakpoint_ops method for | |
9879 | ranged breakpoints. */ | |
9880 | ||
9881 | static void | |
9882 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9883 | { | |
f00aae0f | 9884 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9885 | event_location_to_string (b->location.get ()), |
9886 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9887 | print_recreate_thread (b, fp); |
f1310107 TJB |
9888 | } |
9889 | ||
9890 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9891 | ||
2060206e | 9892 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9893 | |
9894 | /* Find the address where the end of the breakpoint range should be | |
9895 | placed, given the SAL of the end of the range. This is so that if | |
9896 | the user provides a line number, the end of the range is set to the | |
9897 | last instruction of the given line. */ | |
9898 | ||
9899 | static CORE_ADDR | |
9900 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9901 | { | |
9902 | CORE_ADDR end; | |
9903 | ||
9904 | /* If the user provided a PC value, use it. Otherwise, | |
9905 | find the address of the end of the given location. */ | |
9906 | if (sal.explicit_pc) | |
9907 | end = sal.pc; | |
9908 | else | |
9909 | { | |
9910 | int ret; | |
9911 | CORE_ADDR start; | |
9912 | ||
9913 | ret = find_line_pc_range (sal, &start, &end); | |
9914 | if (!ret) | |
9915 | error (_("Could not find location of the end of the range.")); | |
9916 | ||
9917 | /* find_line_pc_range returns the start of the next line. */ | |
9918 | end--; | |
9919 | } | |
9920 | ||
9921 | return end; | |
9922 | } | |
9923 | ||
9924 | /* Implement the "break-range" CLI command. */ | |
9925 | ||
9926 | static void | |
0b39b52e | 9927 | break_range_command (const char *arg, int from_tty) |
f1310107 | 9928 | { |
f2fc3015 | 9929 | const char *arg_start; |
f1310107 TJB |
9930 | struct linespec_result canonical_start, canonical_end; |
9931 | int bp_count, can_use_bp, length; | |
9932 | CORE_ADDR end; | |
9933 | struct breakpoint *b; | |
f1310107 TJB |
9934 | |
9935 | /* We don't support software ranged breakpoints. */ | |
9936 | if (target_ranged_break_num_registers () < 0) | |
9937 | error (_("This target does not support hardware ranged breakpoints.")); | |
9938 | ||
9939 | bp_count = hw_breakpoint_used_count (); | |
9940 | bp_count += target_ranged_break_num_registers (); | |
9941 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9942 | bp_count, 0); | |
9943 | if (can_use_bp < 0) | |
9944 | error (_("Hardware breakpoints used exceeds limit.")); | |
9945 | ||
f8eba3c6 | 9946 | arg = skip_spaces (arg); |
f1310107 TJB |
9947 | if (arg == NULL || arg[0] == '\0') |
9948 | error(_("No address range specified.")); | |
9949 | ||
f8eba3c6 | 9950 | arg_start = arg; |
ffc2605c TT |
9951 | event_location_up start_location = string_to_event_location (&arg, |
9952 | current_language); | |
9953 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
9954 | |
9955 | if (arg[0] != ',') | |
9956 | error (_("Too few arguments.")); | |
6c5b2ebe | 9957 | else if (canonical_start.lsals.empty ()) |
f1310107 | 9958 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 9959 | |
6c5b2ebe | 9960 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 9961 | |
6c5b2ebe PA |
9962 | if (canonical_start.lsals.size () > 1 |
9963 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
9964 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9965 | ||
6c5b2ebe | 9966 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 9967 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
9968 | |
9969 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9970 | arg = skip_spaces (arg); |
f1310107 TJB |
9971 | |
9972 | /* Parse the end location. */ | |
9973 | ||
f1310107 TJB |
9974 | arg_start = arg; |
9975 | ||
f8eba3c6 | 9976 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9977 | parse_breakpoint_sals because we need to specify the start location's |
9978 | symtab and line as the default symtab and line for the end of the | |
9979 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9980 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
9981 | event_location_up end_location = string_to_event_location (&arg, |
9982 | current_language); | |
9983 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
9984 | sal_start.symtab, sal_start.line, |
9985 | &canonical_end, NULL, NULL); | |
9986 | ||
6c5b2ebe | 9987 | if (canonical_end.lsals.empty ()) |
f1310107 | 9988 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 9989 | |
6c5b2ebe PA |
9990 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
9991 | if (canonical_end.lsals.size () > 1 | |
9992 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
9993 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9994 | ||
6c5b2ebe | 9995 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
9996 | |
9997 | end = find_breakpoint_range_end (sal_end); | |
9998 | if (sal_start.pc > end) | |
177b42fe | 9999 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10000 | |
10001 | length = end - sal_start.pc + 1; | |
10002 | if (length < 0) | |
10003 | /* Length overflowed. */ | |
10004 | error (_("Address range too large.")); | |
10005 | else if (length == 1) | |
10006 | { | |
10007 | /* This range is simple enough to be handled by | |
10008 | the `hbreak' command. */ | |
81b1e71c | 10009 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
10010 | |
10011 | return; | |
10012 | } | |
10013 | ||
10014 | /* Now set up the breakpoint. */ | |
10015 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10016 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10017 | set_breakpoint_count (breakpoint_count + 1); |
10018 | b->number = breakpoint_count; | |
10019 | b->disposition = disp_donttouch; | |
d28cd78a TT |
10020 | b->location = std::move (start_location); |
10021 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
10022 | b->loc->length = length; |
10023 | ||
f1310107 | 10024 | mention (b); |
8d3788bd | 10025 | observer_notify_breakpoint_created (b); |
44702360 | 10026 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10027 | } |
10028 | ||
4a64f543 MS |
10029 | /* Return non-zero if EXP is verified as constant. Returned zero |
10030 | means EXP is variable. Also the constant detection may fail for | |
10031 | some constant expressions and in such case still falsely return | |
10032 | zero. */ | |
2e6e3d9c | 10033 | |
65d79d4b SDJ |
10034 | static int |
10035 | watchpoint_exp_is_const (const struct expression *exp) | |
10036 | { | |
10037 | int i = exp->nelts; | |
10038 | ||
10039 | while (i > 0) | |
10040 | { | |
10041 | int oplenp, argsp; | |
10042 | ||
10043 | /* We are only interested in the descriptor of each element. */ | |
10044 | operator_length (exp, i, &oplenp, &argsp); | |
10045 | i -= oplenp; | |
10046 | ||
10047 | switch (exp->elts[i].opcode) | |
10048 | { | |
10049 | case BINOP_ADD: | |
10050 | case BINOP_SUB: | |
10051 | case BINOP_MUL: | |
10052 | case BINOP_DIV: | |
10053 | case BINOP_REM: | |
10054 | case BINOP_MOD: | |
10055 | case BINOP_LSH: | |
10056 | case BINOP_RSH: | |
10057 | case BINOP_LOGICAL_AND: | |
10058 | case BINOP_LOGICAL_OR: | |
10059 | case BINOP_BITWISE_AND: | |
10060 | case BINOP_BITWISE_IOR: | |
10061 | case BINOP_BITWISE_XOR: | |
10062 | case BINOP_EQUAL: | |
10063 | case BINOP_NOTEQUAL: | |
10064 | case BINOP_LESS: | |
10065 | case BINOP_GTR: | |
10066 | case BINOP_LEQ: | |
10067 | case BINOP_GEQ: | |
10068 | case BINOP_REPEAT: | |
10069 | case BINOP_COMMA: | |
10070 | case BINOP_EXP: | |
10071 | case BINOP_MIN: | |
10072 | case BINOP_MAX: | |
10073 | case BINOP_INTDIV: | |
10074 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10075 | case TERNOP_COND: |
10076 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10077 | |
10078 | case OP_LONG: | |
edd079d9 | 10079 | case OP_FLOAT: |
65d79d4b SDJ |
10080 | case OP_LAST: |
10081 | case OP_COMPLEX: | |
10082 | case OP_STRING: | |
65d79d4b SDJ |
10083 | case OP_ARRAY: |
10084 | case OP_TYPE: | |
608b4967 TT |
10085 | case OP_TYPEOF: |
10086 | case OP_DECLTYPE: | |
6e72ca20 | 10087 | case OP_TYPEID: |
65d79d4b SDJ |
10088 | case OP_NAME: |
10089 | case OP_OBJC_NSSTRING: | |
10090 | ||
10091 | case UNOP_NEG: | |
10092 | case UNOP_LOGICAL_NOT: | |
10093 | case UNOP_COMPLEMENT: | |
10094 | case UNOP_ADDR: | |
10095 | case UNOP_HIGH: | |
aeaa2474 | 10096 | case UNOP_CAST: |
9eaf6705 TT |
10097 | |
10098 | case UNOP_CAST_TYPE: | |
10099 | case UNOP_REINTERPRET_CAST: | |
10100 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10101 | /* Unary, binary and ternary operators: We have to check |
10102 | their operands. If they are constant, then so is the | |
10103 | result of that operation. For instance, if A and B are | |
10104 | determined to be constants, then so is "A + B". | |
10105 | ||
10106 | UNOP_IND is one exception to the rule above, because the | |
10107 | value of *ADDR is not necessarily a constant, even when | |
10108 | ADDR is. */ | |
65d79d4b SDJ |
10109 | break; |
10110 | ||
10111 | case OP_VAR_VALUE: | |
10112 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10113 | |
65d79d4b | 10114 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10115 | possible that a buggy compiler could mark a variable as |
10116 | constant even when it is not, and TYPE_CONST would return | |
10117 | true in this case, while SYMBOL_CLASS wouldn't. | |
10118 | ||
10119 | We also have to check for function symbols because they | |
10120 | are always constant. */ | |
65d79d4b SDJ |
10121 | { |
10122 | struct symbol *s = exp->elts[i + 2].symbol; | |
10123 | ||
10124 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10125 | && SYMBOL_CLASS (s) != LOC_CONST | |
10126 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10127 | return 0; | |
10128 | break; | |
10129 | } | |
10130 | ||
10131 | /* The default action is to return 0 because we are using | |
10132 | the optimistic approach here: If we don't know something, | |
10133 | then it is not a constant. */ | |
10134 | default: | |
10135 | return 0; | |
10136 | } | |
10137 | } | |
10138 | ||
10139 | return 1; | |
10140 | } | |
10141 | ||
c1fc2657 | 10142 | /* Watchpoint destructor. */ |
3a5c3e22 | 10143 | |
c1fc2657 | 10144 | watchpoint::~watchpoint () |
3a5c3e22 | 10145 | { |
c1fc2657 SM |
10146 | xfree (this->exp_string); |
10147 | xfree (this->exp_string_reparse); | |
10148 | value_free (this->val); | |
3a5c3e22 PA |
10149 | } |
10150 | ||
348d480f PA |
10151 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10152 | ||
10153 | static void | |
10154 | re_set_watchpoint (struct breakpoint *b) | |
10155 | { | |
3a5c3e22 PA |
10156 | struct watchpoint *w = (struct watchpoint *) b; |
10157 | ||
348d480f PA |
10158 | /* Watchpoint can be either on expression using entirely global |
10159 | variables, or it can be on local variables. | |
10160 | ||
10161 | Watchpoints of the first kind are never auto-deleted, and even | |
10162 | persist across program restarts. Since they can use variables | |
10163 | from shared libraries, we need to reparse expression as libraries | |
10164 | are loaded and unloaded. | |
10165 | ||
10166 | Watchpoints on local variables can also change meaning as result | |
10167 | of solib event. For example, if a watchpoint uses both a local | |
10168 | and a global variables in expression, it's a local watchpoint, | |
10169 | but unloading of a shared library will make the expression | |
10170 | invalid. This is not a very common use case, but we still | |
10171 | re-evaluate expression, to avoid surprises to the user. | |
10172 | ||
10173 | Note that for local watchpoints, we re-evaluate it only if | |
10174 | watchpoints frame id is still valid. If it's not, it means the | |
10175 | watchpoint is out of scope and will be deleted soon. In fact, | |
10176 | I'm not sure we'll ever be called in this case. | |
10177 | ||
10178 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10179 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10180 | |
3a5c3e22 PA |
10181 | Don't do anything about disabled watchpoints, since they will be |
10182 | reevaluated again when enabled. */ | |
10183 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10184 | } |
10185 | ||
77b06cd7 TJB |
10186 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10187 | ||
10188 | static int | |
10189 | insert_watchpoint (struct bp_location *bl) | |
10190 | { | |
3a5c3e22 PA |
10191 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10192 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10193 | |
10194 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10195 | w->cond_exp.get ()); |
77b06cd7 TJB |
10196 | } |
10197 | ||
10198 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10199 | ||
10200 | static int | |
73971819 | 10201 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10202 | { |
3a5c3e22 PA |
10203 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10204 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10205 | |
10206 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10207 | w->cond_exp.get ()); |
e09342b5 TJB |
10208 | } |
10209 | ||
e09342b5 | 10210 | static int |
348d480f | 10211 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
bd522513 | 10212 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 10213 | const struct target_waitstatus *ws) |
e09342b5 | 10214 | { |
348d480f | 10215 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10216 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10217 | |
348d480f PA |
10218 | /* Continuable hardware watchpoints are treated as non-existent if the |
10219 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10220 | some data address). Otherwise gdb won't stop on a break instruction | |
10221 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10222 | been defined. Also skip watchpoints which we know did not trigger | |
10223 | (did not match the data address). */ | |
10224 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10225 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10226 | return 0; |
9c06b0b4 | 10227 | |
348d480f | 10228 | return 1; |
9c06b0b4 TJB |
10229 | } |
10230 | ||
348d480f PA |
10231 | static void |
10232 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10233 | { |
348d480f | 10234 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10235 | |
348d480f | 10236 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10237 | } |
10238 | ||
10239 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10240 | hardware watchpoints. */ |
9c06b0b4 TJB |
10241 | |
10242 | static int | |
348d480f | 10243 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10244 | { |
3a5c3e22 PA |
10245 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10246 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10247 | |
10248 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10249 | } |
10250 | ||
10251 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10252 | hardware watchpoints. */ |
9c06b0b4 TJB |
10253 | |
10254 | static int | |
348d480f | 10255 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10256 | { |
efa80663 PA |
10257 | /* Read and access watchpoints only work with hardware support. */ |
10258 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10259 | } |
10260 | ||
9c06b0b4 | 10261 | static enum print_stop_action |
348d480f | 10262 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10263 | { |
348d480f | 10264 | struct breakpoint *b; |
348d480f | 10265 | enum print_stop_action result; |
3a5c3e22 | 10266 | struct watchpoint *w; |
79a45e25 | 10267 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10268 | |
10269 | gdb_assert (bs->bp_location_at != NULL); | |
10270 | ||
348d480f | 10271 | b = bs->breakpoint_at; |
3a5c3e22 | 10272 | w = (struct watchpoint *) b; |
348d480f | 10273 | |
f303dbd6 PA |
10274 | annotate_watchpoint (b->number); |
10275 | maybe_print_thread_hit_breakpoint (uiout); | |
10276 | ||
d7e74731 PA |
10277 | string_file stb; |
10278 | ||
76f9c9cf | 10279 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10280 | switch (b->type) |
10281 | { | |
348d480f | 10282 | case bp_watchpoint: |
9c06b0b4 | 10283 | case bp_hardware_watchpoint: |
112e8700 SM |
10284 | if (uiout->is_mi_like_p ()) |
10285 | uiout->field_string | |
10286 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10287 | mention (b); |
76f9c9cf | 10288 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10289 | uiout->text ("\nOld value = "); |
d7e74731 | 10290 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10291 | uiout->field_stream ("old", stb); |
10292 | uiout->text ("\nNew value = "); | |
d7e74731 | 10293 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10294 | uiout->field_stream ("new", stb); |
10295 | uiout->text ("\n"); | |
348d480f PA |
10296 | /* More than one watchpoint may have been triggered. */ |
10297 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10298 | break; |
10299 | ||
10300 | case bp_read_watchpoint: | |
112e8700 SM |
10301 | if (uiout->is_mi_like_p ()) |
10302 | uiout->field_string | |
10303 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10304 | mention (b); |
76f9c9cf | 10305 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10306 | uiout->text ("\nValue = "); |
d7e74731 | 10307 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10308 | uiout->field_stream ("value", stb); |
10309 | uiout->text ("\n"); | |
348d480f | 10310 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10311 | break; |
10312 | ||
10313 | case bp_access_watchpoint: | |
348d480f PA |
10314 | if (bs->old_val != NULL) |
10315 | { | |
112e8700 SM |
10316 | if (uiout->is_mi_like_p ()) |
10317 | uiout->field_string | |
10318 | ("reason", | |
348d480f PA |
10319 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10320 | mention (b); | |
76f9c9cf | 10321 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10322 | uiout->text ("\nOld value = "); |
d7e74731 | 10323 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10324 | uiout->field_stream ("old", stb); |
10325 | uiout->text ("\nNew value = "); | |
348d480f PA |
10326 | } |
10327 | else | |
10328 | { | |
10329 | mention (b); | |
112e8700 SM |
10330 | if (uiout->is_mi_like_p ()) |
10331 | uiout->field_string | |
10332 | ("reason", | |
348d480f | 10333 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10334 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10335 | uiout->text ("\nValue = "); |
348d480f | 10336 | } |
d7e74731 | 10337 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10338 | uiout->field_stream ("new", stb); |
10339 | uiout->text ("\n"); | |
348d480f | 10340 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10341 | break; |
10342 | default: | |
348d480f | 10343 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10344 | } |
10345 | ||
348d480f PA |
10346 | return result; |
10347 | } | |
10348 | ||
10349 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10350 | watchpoints. */ | |
10351 | ||
10352 | static void | |
10353 | print_mention_watchpoint (struct breakpoint *b) | |
10354 | { | |
3a5c3e22 | 10355 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10356 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10357 | const char *tuple_name; |
348d480f PA |
10358 | |
10359 | switch (b->type) | |
10360 | { | |
10361 | case bp_watchpoint: | |
112e8700 | 10362 | uiout->text ("Watchpoint "); |
46b9c129 | 10363 | tuple_name = "wpt"; |
348d480f PA |
10364 | break; |
10365 | case bp_hardware_watchpoint: | |
112e8700 | 10366 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10367 | tuple_name = "wpt"; |
348d480f PA |
10368 | break; |
10369 | case bp_read_watchpoint: | |
112e8700 | 10370 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10371 | tuple_name = "hw-rwpt"; |
348d480f PA |
10372 | break; |
10373 | case bp_access_watchpoint: | |
112e8700 | 10374 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10375 | tuple_name = "hw-awpt"; |
348d480f PA |
10376 | break; |
10377 | default: | |
10378 | internal_error (__FILE__, __LINE__, | |
10379 | _("Invalid hardware watchpoint type.")); | |
10380 | } | |
10381 | ||
46b9c129 | 10382 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10383 | uiout->field_int ("number", b->number); |
10384 | uiout->text (": "); | |
10385 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10386 | } |
10387 | ||
10388 | /* Implement the "print_recreate" breakpoint_ops method for | |
10389 | watchpoints. */ | |
10390 | ||
10391 | static void | |
10392 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10393 | { | |
3a5c3e22 PA |
10394 | struct watchpoint *w = (struct watchpoint *) b; |
10395 | ||
348d480f PA |
10396 | switch (b->type) |
10397 | { | |
10398 | case bp_watchpoint: | |
10399 | case bp_hardware_watchpoint: | |
10400 | fprintf_unfiltered (fp, "watch"); | |
10401 | break; | |
10402 | case bp_read_watchpoint: | |
10403 | fprintf_unfiltered (fp, "rwatch"); | |
10404 | break; | |
10405 | case bp_access_watchpoint: | |
10406 | fprintf_unfiltered (fp, "awatch"); | |
10407 | break; | |
10408 | default: | |
10409 | internal_error (__FILE__, __LINE__, | |
10410 | _("Invalid watchpoint type.")); | |
10411 | } | |
10412 | ||
3a5c3e22 | 10413 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10414 | print_recreate_thread (b, fp); |
348d480f PA |
10415 | } |
10416 | ||
427cd150 TT |
10417 | /* Implement the "explains_signal" breakpoint_ops method for |
10418 | watchpoints. */ | |
10419 | ||
47591c29 | 10420 | static int |
427cd150 TT |
10421 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10422 | { | |
10423 | /* A software watchpoint cannot cause a signal other than | |
10424 | GDB_SIGNAL_TRAP. */ | |
10425 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10426 | return 0; |
427cd150 | 10427 | |
47591c29 | 10428 | return 1; |
427cd150 TT |
10429 | } |
10430 | ||
348d480f PA |
10431 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10432 | ||
2060206e | 10433 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10434 | |
10435 | /* Implement the "insert" breakpoint_ops method for | |
10436 | masked hardware watchpoints. */ | |
10437 | ||
10438 | static int | |
10439 | insert_masked_watchpoint (struct bp_location *bl) | |
10440 | { | |
3a5c3e22 PA |
10441 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10442 | ||
10443 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10444 | bl->watchpoint_type); |
10445 | } | |
10446 | ||
10447 | /* Implement the "remove" breakpoint_ops method for | |
10448 | masked hardware watchpoints. */ | |
10449 | ||
10450 | static int | |
73971819 | 10451 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10452 | { |
3a5c3e22 PA |
10453 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10454 | ||
10455 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10456 | bl->watchpoint_type); |
10457 | } | |
10458 | ||
10459 | /* Implement the "resources_needed" breakpoint_ops method for | |
10460 | masked hardware watchpoints. */ | |
10461 | ||
10462 | static int | |
10463 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10464 | { | |
3a5c3e22 PA |
10465 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10466 | ||
10467 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10468 | } |
10469 | ||
10470 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10471 | masked hardware watchpoints. */ | |
10472 | ||
10473 | static int | |
10474 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10475 | { | |
10476 | return 0; | |
10477 | } | |
10478 | ||
10479 | /* Implement the "print_it" breakpoint_ops method for | |
10480 | masked hardware watchpoints. */ | |
10481 | ||
10482 | static enum print_stop_action | |
10483 | print_it_masked_watchpoint (bpstat bs) | |
10484 | { | |
10485 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10486 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10487 | |
10488 | /* Masked watchpoints have only one location. */ | |
10489 | gdb_assert (b->loc && b->loc->next == NULL); | |
10490 | ||
f303dbd6 PA |
10491 | annotate_watchpoint (b->number); |
10492 | maybe_print_thread_hit_breakpoint (uiout); | |
10493 | ||
348d480f PA |
10494 | switch (b->type) |
10495 | { | |
10496 | case bp_hardware_watchpoint: | |
112e8700 SM |
10497 | if (uiout->is_mi_like_p ()) |
10498 | uiout->field_string | |
10499 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10500 | break; |
10501 | ||
10502 | case bp_read_watchpoint: | |
112e8700 SM |
10503 | if (uiout->is_mi_like_p ()) |
10504 | uiout->field_string | |
10505 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10506 | break; |
10507 | ||
10508 | case bp_access_watchpoint: | |
112e8700 SM |
10509 | if (uiout->is_mi_like_p ()) |
10510 | uiout->field_string | |
10511 | ("reason", | |
348d480f PA |
10512 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10513 | break; | |
10514 | default: | |
10515 | internal_error (__FILE__, __LINE__, | |
10516 | _("Invalid hardware watchpoint type.")); | |
10517 | } | |
10518 | ||
10519 | mention (b); | |
112e8700 | 10520 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10521 | Check the underlying instruction at PC for the memory\n\ |
10522 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10523 | uiout->text ("\n"); |
9c06b0b4 TJB |
10524 | |
10525 | /* More than one watchpoint may have been triggered. */ | |
10526 | return PRINT_UNKNOWN; | |
10527 | } | |
10528 | ||
10529 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10530 | masked hardware watchpoints. */ | |
10531 | ||
10532 | static void | |
10533 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10534 | struct ui_out *uiout) | |
10535 | { | |
3a5c3e22 PA |
10536 | struct watchpoint *w = (struct watchpoint *) b; |
10537 | ||
9c06b0b4 TJB |
10538 | /* Masked watchpoints have only one location. */ |
10539 | gdb_assert (b->loc && b->loc->next == NULL); | |
10540 | ||
112e8700 SM |
10541 | uiout->text ("\tmask "); |
10542 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10543 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10544 | } |
10545 | ||
10546 | /* Implement the "print_mention" breakpoint_ops method for | |
10547 | masked hardware watchpoints. */ | |
10548 | ||
10549 | static void | |
10550 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10551 | { | |
3a5c3e22 | 10552 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10553 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10554 | const char *tuple_name; |
9c06b0b4 TJB |
10555 | |
10556 | switch (b->type) | |
10557 | { | |
10558 | case bp_hardware_watchpoint: | |
112e8700 | 10559 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10560 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10561 | break; |
10562 | case bp_read_watchpoint: | |
112e8700 | 10563 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10564 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10565 | break; |
10566 | case bp_access_watchpoint: | |
112e8700 | 10567 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10568 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10569 | break; |
10570 | default: | |
10571 | internal_error (__FILE__, __LINE__, | |
10572 | _("Invalid hardware watchpoint type.")); | |
10573 | } | |
10574 | ||
46b9c129 | 10575 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10576 | uiout->field_int ("number", b->number); |
10577 | uiout->text (": "); | |
10578 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10579 | } |
10580 | ||
10581 | /* Implement the "print_recreate" breakpoint_ops method for | |
10582 | masked hardware watchpoints. */ | |
10583 | ||
10584 | static void | |
10585 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10586 | { | |
3a5c3e22 | 10587 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10588 | char tmp[40]; |
10589 | ||
10590 | switch (b->type) | |
10591 | { | |
10592 | case bp_hardware_watchpoint: | |
10593 | fprintf_unfiltered (fp, "watch"); | |
10594 | break; | |
10595 | case bp_read_watchpoint: | |
10596 | fprintf_unfiltered (fp, "rwatch"); | |
10597 | break; | |
10598 | case bp_access_watchpoint: | |
10599 | fprintf_unfiltered (fp, "awatch"); | |
10600 | break; | |
10601 | default: | |
10602 | internal_error (__FILE__, __LINE__, | |
10603 | _("Invalid hardware watchpoint type.")); | |
10604 | } | |
10605 | ||
3a5c3e22 PA |
10606 | sprintf_vma (tmp, w->hw_wp_mask); |
10607 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10608 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10609 | } |
10610 | ||
10611 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10612 | ||
2060206e | 10613 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10614 | |
10615 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10616 | ||
10617 | static int | |
10618 | is_masked_watchpoint (const struct breakpoint *b) | |
10619 | { | |
10620 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10621 | } | |
10622 | ||
53a5351d JM |
10623 | /* accessflag: hw_write: watch write, |
10624 | hw_read: watch read, | |
10625 | hw_access: watch access (read or write) */ | |
c906108c | 10626 | static void |
bbc13ae3 | 10627 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10628 | int just_location, int internal) |
c906108c | 10629 | { |
c1fc2657 | 10630 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10631 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10632 | struct value *val, *mark, *result; |
bb9d5f81 | 10633 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10634 | const char *exp_start = NULL; |
10635 | const char *exp_end = NULL; | |
10636 | const char *tok, *end_tok; | |
9c06b0b4 | 10637 | int toklen = -1; |
bbc13ae3 KS |
10638 | const char *cond_start = NULL; |
10639 | const char *cond_end = NULL; | |
c906108c | 10640 | enum bptype bp_type; |
37e4754d | 10641 | int thread = -1; |
0cf6dd15 | 10642 | int pc = 0; |
9c06b0b4 TJB |
10643 | /* Flag to indicate whether we are going to use masks for |
10644 | the hardware watchpoint. */ | |
10645 | int use_mask = 0; | |
10646 | CORE_ADDR mask = 0; | |
c906108c | 10647 | |
37e4754d LM |
10648 | /* Make sure that we actually have parameters to parse. */ |
10649 | if (arg != NULL && arg[0] != '\0') | |
10650 | { | |
bbc13ae3 KS |
10651 | const char *value_start; |
10652 | ||
10653 | exp_end = arg + strlen (arg); | |
37e4754d | 10654 | |
9c06b0b4 TJB |
10655 | /* Look for "parameter value" pairs at the end |
10656 | of the arguments string. */ | |
bbc13ae3 | 10657 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10658 | { |
10659 | /* Skip whitespace at the end of the argument list. */ | |
10660 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10661 | tok--; | |
10662 | ||
10663 | /* Find the beginning of the last token. | |
10664 | This is the value of the parameter. */ | |
10665 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10666 | tok--; | |
10667 | value_start = tok + 1; | |
10668 | ||
10669 | /* Skip whitespace. */ | |
10670 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10671 | tok--; | |
10672 | ||
10673 | end_tok = tok; | |
10674 | ||
10675 | /* Find the beginning of the second to last token. | |
10676 | This is the parameter itself. */ | |
10677 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10678 | tok--; | |
10679 | tok++; | |
10680 | toklen = end_tok - tok + 1; | |
10681 | ||
61012eef | 10682 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10683 | { |
5d5658a1 | 10684 | struct thread_info *thr; |
9c06b0b4 TJB |
10685 | /* At this point we've found a "thread" token, which means |
10686 | the user is trying to set a watchpoint that triggers | |
10687 | only in a specific thread. */ | |
5d5658a1 | 10688 | const char *endp; |
37e4754d | 10689 | |
9c06b0b4 TJB |
10690 | if (thread != -1) |
10691 | error(_("You can specify only one thread.")); | |
37e4754d | 10692 | |
9c06b0b4 | 10693 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10694 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10695 | |
5d5658a1 | 10696 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10697 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10698 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10699 | |
5d5658a1 | 10700 | thread = thr->global_num; |
9c06b0b4 | 10701 | } |
61012eef | 10702 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10703 | { |
10704 | /* We've found a "mask" token, which means the user wants to | |
10705 | create a hardware watchpoint that is going to have the mask | |
10706 | facility. */ | |
10707 | struct value *mask_value, *mark; | |
37e4754d | 10708 | |
9c06b0b4 TJB |
10709 | if (use_mask) |
10710 | error(_("You can specify only one mask.")); | |
37e4754d | 10711 | |
9c06b0b4 | 10712 | use_mask = just_location = 1; |
37e4754d | 10713 | |
9c06b0b4 TJB |
10714 | mark = value_mark (); |
10715 | mask_value = parse_to_comma_and_eval (&value_start); | |
10716 | mask = value_as_address (mask_value); | |
10717 | value_free_to_mark (mark); | |
10718 | } | |
10719 | else | |
10720 | /* We didn't recognize what we found. We should stop here. */ | |
10721 | break; | |
37e4754d | 10722 | |
9c06b0b4 TJB |
10723 | /* Truncate the string and get rid of the "parameter value" pair before |
10724 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10725 | exp_end = tok; |
9c06b0b4 | 10726 | } |
37e4754d | 10727 | } |
bbc13ae3 KS |
10728 | else |
10729 | exp_end = arg; | |
37e4754d | 10730 | |
bbc13ae3 KS |
10731 | /* Parse the rest of the arguments. From here on out, everything |
10732 | is in terms of a newly allocated string instead of the original | |
10733 | ARG. */ | |
c906108c | 10734 | innermost_block = NULL; |
81b1e71c TT |
10735 | std::string expression (arg, exp_end - arg); |
10736 | exp_start = arg = expression.c_str (); | |
4d01a485 | 10737 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 10738 | exp_end = arg; |
fa8a61dc TT |
10739 | /* Remove trailing whitespace from the expression before saving it. |
10740 | This makes the eventual display of the expression string a bit | |
10741 | prettier. */ | |
10742 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10743 | --exp_end; | |
10744 | ||
65d79d4b | 10745 | /* Checking if the expression is not constant. */ |
4d01a485 | 10746 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10747 | { |
10748 | int len; | |
10749 | ||
10750 | len = exp_end - exp_start; | |
10751 | while (len > 0 && isspace (exp_start[len - 1])) | |
10752 | len--; | |
10753 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10754 | } | |
10755 | ||
c906108c SS |
10756 | exp_valid_block = innermost_block; |
10757 | mark = value_mark (); | |
4d01a485 | 10758 | fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location); |
06a64a0b | 10759 | |
bb9d5f81 PP |
10760 | if (val != NULL && just_location) |
10761 | { | |
10762 | saved_bitpos = value_bitpos (val); | |
10763 | saved_bitsize = value_bitsize (val); | |
10764 | } | |
10765 | ||
06a64a0b TT |
10766 | if (just_location) |
10767 | { | |
9c06b0b4 TJB |
10768 | int ret; |
10769 | ||
06a64a0b | 10770 | exp_valid_block = NULL; |
a1442452 | 10771 | val = value_addr (result); |
06a64a0b TT |
10772 | release_value (val); |
10773 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
10774 | |
10775 | if (use_mask) | |
10776 | { | |
10777 | ret = target_masked_watch_num_registers (value_as_address (val), | |
10778 | mask); | |
10779 | if (ret == -1) | |
10780 | error (_("This target does not support masked watchpoints.")); | |
10781 | else if (ret == -2) | |
10782 | error (_("Invalid mask or memory region.")); | |
10783 | } | |
06a64a0b TT |
10784 | } |
10785 | else if (val != NULL) | |
fa4727a6 | 10786 | release_value (val); |
c906108c | 10787 | |
f1735a53 TT |
10788 | tok = skip_spaces (arg); |
10789 | end_tok = skip_to_space (tok); | |
c906108c SS |
10790 | |
10791 | toklen = end_tok - tok; | |
10792 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10793 | { | |
60e1c644 | 10794 | innermost_block = NULL; |
c906108c | 10795 | tok = cond_start = end_tok + 1; |
4d01a485 | 10796 | parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
10797 | |
10798 | /* The watchpoint expression may not be local, but the condition | |
10799 | may still be. E.g.: `watch global if local > 0'. */ | |
10800 | cond_exp_valid_block = innermost_block; | |
10801 | ||
c906108c SS |
10802 | cond_end = tok; |
10803 | } | |
10804 | if (*tok) | |
8a3fe4f8 | 10805 | error (_("Junk at end of command.")); |
c906108c | 10806 | |
441d7c93 PA |
10807 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10808 | ||
10809 | /* Save this because create_internal_breakpoint below invalidates | |
10810 | 'wp_frame'. */ | |
10811 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10812 | |
10813 | /* If the expression is "local", then set up a "watchpoint scope" | |
10814 | breakpoint at the point where we've left the scope of the watchpoint | |
10815 | expression. Create the scope breakpoint before the watchpoint, so | |
10816 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10817 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10818 | { |
441d7c93 PA |
10819 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10820 | ||
10821 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10822 | { |
441d7c93 PA |
10823 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10824 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10825 | ||
edb3359d | 10826 | scope_breakpoint |
441d7c93 | 10827 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10828 | bp_watchpoint_scope, |
10829 | &momentary_breakpoint_ops); | |
d983da9c | 10830 | |
441d7c93 PA |
10831 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10832 | wp_frame = NULL; | |
10833 | ||
edb3359d | 10834 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10835 | |
edb3359d DJ |
10836 | /* Automatically delete the breakpoint when it hits. */ |
10837 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10838 | |
edb3359d | 10839 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10840 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10841 | |
edb3359d | 10842 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10843 | scope_breakpoint->loc->gdbarch = caller_arch; |
10844 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10845 | scope_breakpoint->loc->address |
a6d9a66e UW |
10846 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10847 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10848 | scope_breakpoint->type); |
10849 | } | |
d983da9c DJ |
10850 | } |
10851 | ||
e8369a73 AB |
10852 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10853 | watchpoints here even if hardware watchpoints are turned off, a call | |
10854 | to update_watchpoint later in this function will cause the type to | |
10855 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10856 | ||
10857 | if (accessflag == hw_read) | |
10858 | bp_type = bp_read_watchpoint; | |
10859 | else if (accessflag == hw_access) | |
10860 | bp_type = bp_access_watchpoint; | |
10861 | else | |
10862 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10863 | |
b270e6f9 | 10864 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10865 | |
348d480f | 10866 | if (use_mask) |
b270e6f9 | 10867 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10868 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10869 | else |
b270e6f9 | 10870 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10871 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
10872 | w->thread = thread; |
10873 | w->disposition = disp_donttouch; | |
10874 | w->pspace = current_program_space; | |
b22e99fd | 10875 | w->exp = std::move (exp); |
3a5c3e22 PA |
10876 | w->exp_valid_block = exp_valid_block; |
10877 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10878 | if (just_location) |
10879 | { | |
10880 | struct type *t = value_type (val); | |
10881 | CORE_ADDR addr = value_as_address (val); | |
06a64a0b | 10882 | |
43cc5389 TT |
10883 | w->exp_string_reparse |
10884 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 10885 | |
3a5c3e22 | 10886 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 10887 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
10888 | } |
10889 | else | |
3a5c3e22 | 10890 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10891 | |
10892 | if (use_mask) | |
10893 | { | |
3a5c3e22 | 10894 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10895 | } |
10896 | else | |
10897 | { | |
3a5c3e22 | 10898 | w->val = val; |
bb9d5f81 PP |
10899 | w->val_bitpos = saved_bitpos; |
10900 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 10901 | w->val_valid = 1; |
9c06b0b4 | 10902 | } |
77b06cd7 | 10903 | |
c906108c | 10904 | if (cond_start) |
c1fc2657 | 10905 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 10906 | else |
c1fc2657 | 10907 | w->cond_string = 0; |
c5aa993b | 10908 | |
441d7c93 | 10909 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 10910 | { |
441d7c93 | 10911 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 10912 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 10913 | } |
c906108c | 10914 | else |
f6bc2008 | 10915 | { |
3a5c3e22 PA |
10916 | w->watchpoint_frame = null_frame_id; |
10917 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10918 | } |
c906108c | 10919 | |
d983da9c | 10920 | if (scope_breakpoint != NULL) |
c906108c | 10921 | { |
d983da9c DJ |
10922 | /* The scope breakpoint is related to the watchpoint. We will |
10923 | need to act on them together. */ | |
c1fc2657 | 10924 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 10925 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 10926 | } |
d983da9c | 10927 | |
06a64a0b TT |
10928 | if (!just_location) |
10929 | value_free_to_mark (mark); | |
2d134ed3 | 10930 | |
b270e6f9 TT |
10931 | /* Finally update the new watchpoint. This creates the locations |
10932 | that should be inserted. */ | |
10933 | update_watchpoint (w.get (), 1); | |
a9634178 | 10934 | |
b270e6f9 | 10935 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
10936 | } |
10937 | ||
e09342b5 | 10938 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10939 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10940 | |
c906108c | 10941 | static int |
a9634178 | 10942 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
10943 | { |
10944 | int found_memory_cnt = 0; | |
2e70b7b9 | 10945 | struct value *head = v; |
c906108c SS |
10946 | |
10947 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10948 | if (!can_use_hw_watchpoints) |
c906108c | 10949 | return 0; |
c5aa993b | 10950 | |
5c44784c JM |
10951 | /* Make sure that the value of the expression depends only upon |
10952 | memory contents, and values computed from them within GDB. If we | |
10953 | find any register references or function calls, we can't use a | |
10954 | hardware watchpoint. | |
10955 | ||
10956 | The idea here is that evaluating an expression generates a series | |
10957 | of values, one holding the value of every subexpression. (The | |
10958 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10959 | a*b+c.) GDB's values hold almost enough information to establish | |
10960 | the criteria given above --- they identify memory lvalues, | |
10961 | register lvalues, computed values, etcetera. So we can evaluate | |
10962 | the expression, and then scan the chain of values that leaves | |
10963 | behind to decide whether we can detect any possible change to the | |
10964 | expression's final value using only hardware watchpoints. | |
10965 | ||
10966 | However, I don't think that the values returned by inferior | |
10967 | function calls are special in any way. So this function may not | |
10968 | notice that an expression involving an inferior function call | |
10969 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 10970 | for (; v; v = value_next (v)) |
c906108c | 10971 | { |
5c44784c | 10972 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10973 | { |
8464be76 DJ |
10974 | if (v != head && value_lazy (v)) |
10975 | /* A lazy memory lvalue in the chain is one that GDB never | |
10976 | needed to fetch; we either just used its address (e.g., | |
10977 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10978 | in `a,b'). This doesn't apply to HEAD; if that is | |
10979 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10980 | ; |
53a5351d | 10981 | else |
5c44784c JM |
10982 | { |
10983 | /* Ahh, memory we actually used! Check if we can cover | |
10984 | it with hardware watchpoints. */ | |
df407dfe | 10985 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10986 | |
10987 | /* We only watch structs and arrays if user asked for it | |
10988 | explicitly, never if they just happen to appear in a | |
10989 | middle of some value chain. */ | |
10990 | if (v == head | |
10991 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
10992 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
10993 | { | |
42ae5230 | 10994 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10995 | int len; |
10996 | int num_regs; | |
10997 | ||
a9634178 | 10998 | len = (target_exact_watchpoints |
e09342b5 TJB |
10999 | && is_scalar_type_recursive (vtype))? |
11000 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11001 | |
e09342b5 TJB |
11002 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11003 | if (!num_regs) | |
2e70b7b9 MS |
11004 | return 0; |
11005 | else | |
e09342b5 | 11006 | found_memory_cnt += num_regs; |
2e70b7b9 | 11007 | } |
5c44784c | 11008 | } |
c5aa993b | 11009 | } |
5086187c AC |
11010 | else if (VALUE_LVAL (v) != not_lval |
11011 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11012 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11013 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11014 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11015 | } |
11016 | ||
11017 | /* The expression itself looks suitable for using a hardware | |
11018 | watchpoint, but give the target machine a chance to reject it. */ | |
11019 | return found_memory_cnt; | |
11020 | } | |
11021 | ||
8b93c638 | 11022 | void |
f2fc3015 | 11023 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 11024 | { |
84f4c1fe | 11025 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11026 | } |
11027 | ||
06a64a0b TT |
11028 | /* A helper function that looks for the "-location" argument and then |
11029 | calls watch_command_1. */ | |
11030 | ||
11031 | static void | |
0b39b52e | 11032 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b TT |
11033 | { |
11034 | int just_location = 0; | |
11035 | ||
11036 | if (arg | |
11037 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11038 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11039 | { | |
e9cafbcc | 11040 | arg = skip_spaces (arg); |
06a64a0b TT |
11041 | just_location = 1; |
11042 | } | |
11043 | ||
84f4c1fe | 11044 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11045 | } |
8926118c | 11046 | |
c5aa993b | 11047 | static void |
0b39b52e | 11048 | watch_command (const char *arg, int from_tty) |
c906108c | 11049 | { |
06a64a0b | 11050 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11051 | } |
11052 | ||
8b93c638 | 11053 | void |
f2fc3015 | 11054 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 11055 | { |
84f4c1fe | 11056 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11057 | } |
8926118c | 11058 | |
c5aa993b | 11059 | static void |
0b39b52e | 11060 | rwatch_command (const char *arg, int from_tty) |
c906108c | 11061 | { |
06a64a0b | 11062 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11063 | } |
11064 | ||
8b93c638 | 11065 | void |
f2fc3015 | 11066 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 11067 | { |
84f4c1fe | 11068 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11069 | } |
8926118c | 11070 | |
c5aa993b | 11071 | static void |
0b39b52e | 11072 | awatch_command (const char *arg, int from_tty) |
c906108c | 11073 | { |
06a64a0b | 11074 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11075 | } |
c906108c | 11076 | \f |
c5aa993b | 11077 | |
cfc31633 PA |
11078 | /* Data for the FSM that manages the until(location)/advance commands |
11079 | in infcmd.c. Here because it uses the mechanisms of | |
11080 | breakpoints. */ | |
c906108c | 11081 | |
cfc31633 | 11082 | struct until_break_fsm |
bfec99b2 | 11083 | { |
cfc31633 PA |
11084 | /* The base class. */ |
11085 | struct thread_fsm thread_fsm; | |
11086 | ||
11087 | /* The thread that as current when the command was executed. */ | |
11088 | int thread; | |
11089 | ||
11090 | /* The breakpoint set at the destination location. */ | |
11091 | struct breakpoint *location_breakpoint; | |
11092 | ||
11093 | /* Breakpoint set at the return address in the caller frame. May be | |
11094 | NULL. */ | |
11095 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11096 | }; |
11097 | ||
8980e177 PA |
11098 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11099 | struct thread_info *thread); | |
11100 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11101 | struct thread_info *thread); | |
cfc31633 PA |
11102 | static enum async_reply_reason |
11103 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11104 | ||
11105 | /* until_break_fsm's vtable. */ | |
11106 | ||
11107 | static struct thread_fsm_ops until_break_fsm_ops = | |
11108 | { | |
11109 | NULL, /* dtor */ | |
11110 | until_break_fsm_clean_up, | |
11111 | until_break_fsm_should_stop, | |
11112 | NULL, /* return_value */ | |
11113 | until_break_fsm_async_reply_reason, | |
11114 | }; | |
11115 | ||
11116 | /* Allocate a new until_break_command_fsm. */ | |
11117 | ||
11118 | static struct until_break_fsm * | |
8980e177 | 11119 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
454dafbd TT |
11120 | breakpoint_up &&location_breakpoint, |
11121 | breakpoint_up &&caller_breakpoint) | |
cfc31633 PA |
11122 | { |
11123 | struct until_break_fsm *sm; | |
11124 | ||
11125 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11126 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11127 | |
11128 | sm->thread = thread; | |
454dafbd TT |
11129 | sm->location_breakpoint = location_breakpoint.release (); |
11130 | sm->caller_breakpoint = caller_breakpoint.release (); | |
cfc31633 PA |
11131 | |
11132 | return sm; | |
11133 | } | |
11134 | ||
11135 | /* Implementation of the 'should_stop' FSM method for the | |
11136 | until(location)/advance commands. */ | |
11137 | ||
11138 | static int | |
8980e177 PA |
11139 | until_break_fsm_should_stop (struct thread_fsm *self, |
11140 | struct thread_info *tp) | |
cfc31633 PA |
11141 | { |
11142 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11143 | |
11144 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11145 | sm->location_breakpoint) != NULL | |
11146 | || (sm->caller_breakpoint != NULL | |
11147 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11148 | sm->caller_breakpoint) != NULL)) | |
11149 | thread_fsm_set_finished (self); | |
11150 | ||
11151 | return 1; | |
11152 | } | |
11153 | ||
11154 | /* Implementation of the 'clean_up' FSM method for the | |
11155 | until(location)/advance commands. */ | |
11156 | ||
c2c6d25f | 11157 | static void |
8980e177 PA |
11158 | until_break_fsm_clean_up (struct thread_fsm *self, |
11159 | struct thread_info *thread) | |
43ff13b4 | 11160 | { |
cfc31633 | 11161 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11162 | |
cfc31633 PA |
11163 | /* Clean up our temporary breakpoints. */ |
11164 | if (sm->location_breakpoint != NULL) | |
11165 | { | |
11166 | delete_breakpoint (sm->location_breakpoint); | |
11167 | sm->location_breakpoint = NULL; | |
11168 | } | |
11169 | if (sm->caller_breakpoint != NULL) | |
11170 | { | |
11171 | delete_breakpoint (sm->caller_breakpoint); | |
11172 | sm->caller_breakpoint = NULL; | |
11173 | } | |
11174 | delete_longjmp_breakpoint (sm->thread); | |
11175 | } | |
11176 | ||
11177 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11178 | until(location)/advance commands. */ | |
11179 | ||
11180 | static enum async_reply_reason | |
11181 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11182 | { | |
11183 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11184 | } |
11185 | ||
c906108c | 11186 | void |
f2fc3015 | 11187 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 11188 | { |
8556afb4 PA |
11189 | struct frame_info *frame; |
11190 | struct gdbarch *frame_gdbarch; | |
11191 | struct frame_id stack_frame_id; | |
11192 | struct frame_id caller_frame_id; | |
ffc2605c | 11193 | struct cleanup *old_chain; |
186c406b TT |
11194 | int thread; |
11195 | struct thread_info *tp; | |
cfc31633 | 11196 | struct until_break_fsm *sm; |
c906108c | 11197 | |
70509625 | 11198 | clear_proceed_status (0); |
c906108c SS |
11199 | |
11200 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11201 | this function. */ |
c5aa993b | 11202 | |
ffc2605c | 11203 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11204 | |
6c5b2ebe PA |
11205 | std::vector<symtab_and_line> sals |
11206 | = (last_displayed_sal_is_valid () | |
11207 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
11208 | get_last_displayed_symtab (), | |
11209 | get_last_displayed_line ()) | |
11210 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
11211 | NULL, (struct symtab *) NULL, 0)); | |
c5aa993b | 11212 | |
6c5b2ebe | 11213 | if (sals.size () != 1) |
8a3fe4f8 | 11214 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11215 | |
6c5b2ebe | 11216 | symtab_and_line &sal = sals[0]; |
c5aa993b | 11217 | |
c906108c | 11218 | if (*arg) |
8a3fe4f8 | 11219 | error (_("Junk at end of arguments.")); |
c5aa993b | 11220 | |
c906108c | 11221 | resolve_sal_pc (&sal); |
c5aa993b | 11222 | |
186c406b | 11223 | tp = inferior_thread (); |
5d5658a1 | 11224 | thread = tp->global_num; |
186c406b | 11225 | |
883bc8d1 PA |
11226 | old_chain = make_cleanup (null_cleanup, NULL); |
11227 | ||
8556afb4 PA |
11228 | /* Note linespec handling above invalidates the frame chain. |
11229 | Installing a breakpoint also invalidates the frame chain (as it | |
11230 | may need to switch threads), so do any frame handling before | |
11231 | that. */ | |
11232 | ||
11233 | frame = get_selected_frame (NULL); | |
11234 | frame_gdbarch = get_frame_arch (frame); | |
11235 | stack_frame_id = get_stack_frame_id (frame); | |
11236 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11237 | |
ae66c1fc EZ |
11238 | /* Keep within the current frame, or in frames called by the current |
11239 | one. */ | |
edb3359d | 11240 | |
454dafbd | 11241 | breakpoint_up caller_breakpoint; |
883bc8d1 | 11242 | if (frame_id_p (caller_frame_id)) |
c906108c | 11243 | { |
883bc8d1 | 11244 | struct symtab_and_line sal2; |
cfc31633 | 11245 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11246 | |
11247 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11248 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11249 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11250 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11251 | sal2, | |
11252 | caller_frame_id, | |
11253 | bp_until); | |
186c406b | 11254 | |
883bc8d1 | 11255 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11256 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11257 | } |
c5aa993b | 11258 | |
c70a6932 JK |
11259 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11260 | frame = NULL; | |
11261 | ||
454dafbd | 11262 | breakpoint_up location_breakpoint; |
883bc8d1 PA |
11263 | if (anywhere) |
11264 | /* If the user told us to continue until a specified location, | |
11265 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11266 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11267 | null_frame_id, bp_until); | |
883bc8d1 PA |
11268 | else |
11269 | /* Otherwise, specify the selected frame, because we want to stop | |
11270 | only at the very same frame. */ | |
cfc31633 PA |
11271 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11272 | stack_frame_id, bp_until); | |
883bc8d1 | 11273 | |
8980e177 | 11274 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
454dafbd TT |
11275 | std::move (location_breakpoint), |
11276 | std::move (caller_breakpoint)); | |
cfc31633 | 11277 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11278 | |
cfc31633 | 11279 | discard_cleanups (old_chain); |
f107f563 | 11280 | |
cfc31633 | 11281 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11282 | } |
ae66c1fc | 11283 | |
c906108c SS |
11284 | /* This function attempts to parse an optional "if <cond>" clause |
11285 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11286 | |
c906108c SS |
11287 | Else, it returns a pointer to the condition string. (It does not |
11288 | attempt to evaluate the string against a particular block.) And, | |
11289 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11290 | if clause in the arg string. */ |
53a5351d | 11291 | |
63160a43 PA |
11292 | const char * |
11293 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11294 | { |
63160a43 | 11295 | const char *cond_string; |
c5aa993b JM |
11296 | |
11297 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11298 | return NULL; |
c5aa993b | 11299 | |
4a64f543 | 11300 | /* Skip the "if" keyword. */ |
c906108c | 11301 | (*arg) += 2; |
c5aa993b | 11302 | |
c906108c | 11303 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11304 | condition string. */ |
f1735a53 | 11305 | *arg = skip_spaces (*arg); |
c906108c | 11306 | cond_string = *arg; |
c5aa993b | 11307 | |
4a64f543 MS |
11308 | /* Assume that the condition occupies the remainder of the arg |
11309 | string. */ | |
c906108c | 11310 | (*arg) += strlen (cond_string); |
c5aa993b | 11311 | |
c906108c SS |
11312 | return cond_string; |
11313 | } | |
c5aa993b | 11314 | |
c906108c SS |
11315 | /* Commands to deal with catching events, such as signals, exceptions, |
11316 | process start/exit, etc. */ | |
c5aa993b JM |
11317 | |
11318 | typedef enum | |
11319 | { | |
44feb3ce TT |
11320 | catch_fork_temporary, catch_vfork_temporary, |
11321 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11322 | } |
11323 | catch_fork_kind; | |
11324 | ||
c906108c | 11325 | static void |
eb4c3f4a | 11326 | catch_fork_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11327 | struct cmd_list_element *command) |
c906108c | 11328 | { |
a6d9a66e | 11329 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11330 | const char *cond_string = NULL; |
44feb3ce TT |
11331 | catch_fork_kind fork_kind; |
11332 | int tempflag; | |
11333 | ||
11334 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11335 | tempflag = (fork_kind == catch_fork_temporary | |
11336 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11337 | |
44feb3ce TT |
11338 | if (!arg) |
11339 | arg = ""; | |
f1735a53 | 11340 | arg = skip_spaces (arg); |
c5aa993b | 11341 | |
c906108c | 11342 | /* The allowed syntax is: |
c5aa993b JM |
11343 | catch [v]fork |
11344 | catch [v]fork if <cond> | |
11345 | ||
4a64f543 | 11346 | First, check if there's an if clause. */ |
c906108c | 11347 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11348 | |
c906108c | 11349 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11350 | error (_("Junk at end of arguments.")); |
c5aa993b | 11351 | |
c906108c | 11352 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11353 | and enable reporting of such events. */ |
c5aa993b JM |
11354 | switch (fork_kind) |
11355 | { | |
44feb3ce TT |
11356 | case catch_fork_temporary: |
11357 | case catch_fork_permanent: | |
a6d9a66e | 11358 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11359 | &catch_fork_breakpoint_ops); |
c906108c | 11360 | break; |
44feb3ce TT |
11361 | case catch_vfork_temporary: |
11362 | case catch_vfork_permanent: | |
a6d9a66e | 11363 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11364 | &catch_vfork_breakpoint_ops); |
c906108c | 11365 | break; |
c5aa993b | 11366 | default: |
8a3fe4f8 | 11367 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11368 | break; |
c5aa993b | 11369 | } |
c906108c SS |
11370 | } |
11371 | ||
11372 | static void | |
eb4c3f4a | 11373 | catch_exec_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11374 | struct cmd_list_element *command) |
c906108c | 11375 | { |
a6d9a66e | 11376 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11377 | int tempflag; |
63160a43 | 11378 | const char *cond_string = NULL; |
c906108c | 11379 | |
44feb3ce TT |
11380 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11381 | ||
11382 | if (!arg) | |
11383 | arg = ""; | |
f1735a53 | 11384 | arg = skip_spaces (arg); |
c906108c SS |
11385 | |
11386 | /* The allowed syntax is: | |
c5aa993b JM |
11387 | catch exec |
11388 | catch exec if <cond> | |
c906108c | 11389 | |
4a64f543 | 11390 | First, check if there's an if clause. */ |
c906108c SS |
11391 | cond_string = ep_parse_optional_if_clause (&arg); |
11392 | ||
11393 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11394 | error (_("Junk at end of arguments.")); |
c906108c | 11395 | |
b270e6f9 TT |
11396 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11397 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11398 | &catch_exec_breakpoint_ops); |
11399 | c->exec_pathname = NULL; | |
11400 | ||
b270e6f9 | 11401 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11402 | } |
c5aa993b | 11403 | |
9ac4176b | 11404 | void |
28010a5d PA |
11405 | init_ada_exception_breakpoint (struct breakpoint *b, |
11406 | struct gdbarch *gdbarch, | |
11407 | struct symtab_and_line sal, | |
f2fc3015 | 11408 | const char *addr_string, |
c0a91b2b | 11409 | const struct breakpoint_ops *ops, |
28010a5d | 11410 | int tempflag, |
349774ef | 11411 | int enabled, |
28010a5d | 11412 | int from_tty) |
f7f9143b | 11413 | { |
f7f9143b JB |
11414 | if (from_tty) |
11415 | { | |
5af949e3 UW |
11416 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11417 | if (!loc_gdbarch) | |
11418 | loc_gdbarch = gdbarch; | |
11419 | ||
6c95b8df PA |
11420 | describe_other_breakpoints (loc_gdbarch, |
11421 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11422 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11423 | version for exception catchpoints, because two catchpoints | |
11424 | used for different exception names will use the same address. | |
11425 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11426 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11427 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11428 | the user what type of catchpoint it is. The above is good |
11429 | enough for now, though. */ | |
11430 | } | |
11431 | ||
28010a5d | 11432 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11433 | |
349774ef | 11434 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11435 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11436 | b->location = string_to_event_location (&addr_string, |
11437 | language_def (language_ada)); | |
f7f9143b | 11438 | b->language = language_ada; |
f7f9143b JB |
11439 | } |
11440 | ||
c906108c | 11441 | static void |
981a3fb3 | 11442 | catch_command (const char *arg, int from_tty) |
c906108c | 11443 | { |
44feb3ce | 11444 | error (_("Catch requires an event name.")); |
c906108c SS |
11445 | } |
11446 | \f | |
11447 | ||
11448 | static void | |
981a3fb3 | 11449 | tcatch_command (const char *arg, int from_tty) |
c906108c | 11450 | { |
44feb3ce | 11451 | error (_("Catch requires an event name.")); |
c906108c SS |
11452 | } |
11453 | ||
81b1e71c | 11454 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
11455 | |
11456 | static int | |
81b1e71c | 11457 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 11458 | { |
81b1e71c TT |
11459 | uintptr_t ua = (uintptr_t) a; |
11460 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 11461 | |
81b1e71c | 11462 | if (a->number < b->number) |
8a2c437b | 11463 | return -1; |
81b1e71c | 11464 | else if (a->number > b->number) |
8a2c437b TT |
11465 | return 1; |
11466 | ||
11467 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11468 | the number 0. */ | |
11469 | if (ua < ub) | |
11470 | return -1; | |
94b0e70d | 11471 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11472 | } |
11473 | ||
80f8a6eb | 11474 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11475 | |
11476 | static void | |
0b39b52e | 11477 | clear_command (const char *arg, int from_tty) |
c906108c | 11478 | { |
81b1e71c | 11479 | struct breakpoint *b; |
c906108c | 11480 | int default_match; |
c906108c | 11481 | |
6c5b2ebe PA |
11482 | std::vector<symtab_and_line> decoded_sals; |
11483 | symtab_and_line last_sal; | |
11484 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11485 | if (arg) |
11486 | { | |
6c5b2ebe PA |
11487 | decoded_sals |
11488 | = decode_line_with_current_source (arg, | |
11489 | (DECODE_LINE_FUNFIRSTLINE | |
11490 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11491 | default_match = 0; |
6c5b2ebe | 11492 | sals = decoded_sals; |
c906108c SS |
11493 | } |
11494 | else | |
11495 | { | |
1bfeeb0f JL |
11496 | /* Set sal's line, symtab, pc, and pspace to the values |
11497 | corresponding to the last call to print_frame_info. If the | |
11498 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11499 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11500 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11501 | error (_("No source file specified.")); |
c906108c | 11502 | |
c906108c | 11503 | default_match = 1; |
6c5b2ebe | 11504 | sals = last_sal; |
c906108c SS |
11505 | } |
11506 | ||
4a64f543 MS |
11507 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11508 | seems, because all existing breakpoints typically have both | |
11509 | file/line and pc set. So, if clear is given file/line, we can | |
11510 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11511 | |
11512 | We only support clearing given the address explicitly | |
11513 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11514 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11515 | due to optimization, all in one block. |
4a64f543 MS |
11516 | |
11517 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11518 | PC corresponding to the same file:line, the breakpoint won't |
11519 | be cleared. We probably can still clear the breakpoint, but | |
11520 | since the other PC value is never presented to user, user | |
11521 | can only find it by guessing, and it does not seem important | |
11522 | to support that. */ | |
11523 | ||
4a64f543 MS |
11524 | /* For each line spec given, delete bps which correspond to it. Do |
11525 | it in two passes, solely to preserve the current behavior that | |
11526 | from_tty is forced true if we delete more than one | |
11527 | breakpoint. */ | |
c906108c | 11528 | |
81b1e71c | 11529 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 11530 | for (const auto &sal : sals) |
c906108c | 11531 | { |
05cba821 JK |
11532 | const char *sal_fullname; |
11533 | ||
c906108c | 11534 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11535 | If line given (pc == 0), clear all bpts on specified line. |
11536 | If defaulting, clear all bpts on default line | |
c906108c | 11537 | or at default pc. |
c5aa993b JM |
11538 | |
11539 | defaulting sal.pc != 0 tests to do | |
11540 | ||
11541 | 0 1 pc | |
11542 | 1 1 pc _and_ line | |
11543 | 0 0 line | |
11544 | 1 0 <can't happen> */ | |
c906108c | 11545 | |
05cba821 JK |
11546 | sal_fullname = (sal.symtab == NULL |
11547 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11548 | |
4a64f543 | 11549 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11550 | ALL_BREAKPOINTS (b) |
c5aa993b | 11551 | { |
0d381245 | 11552 | int match = 0; |
4a64f543 | 11553 | /* Are we going to delete b? */ |
cc60f2e3 | 11554 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11555 | { |
11556 | struct bp_location *loc = b->loc; | |
11557 | for (; loc; loc = loc->next) | |
11558 | { | |
f8eba3c6 TT |
11559 | /* If the user specified file:line, don't allow a PC |
11560 | match. This matches historical gdb behavior. */ | |
11561 | int pc_match = (!sal.explicit_line | |
11562 | && sal.pc | |
11563 | && (loc->pspace == sal.pspace) | |
11564 | && (loc->address == sal.pc) | |
11565 | && (!section_is_overlay (loc->section) | |
11566 | || loc->section == sal.section)); | |
4aac40c8 TT |
11567 | int line_match = 0; |
11568 | ||
11569 | if ((default_match || sal.explicit_line) | |
2f202fde | 11570 | && loc->symtab != NULL |
05cba821 | 11571 | && sal_fullname != NULL |
4aac40c8 | 11572 | && sal.pspace == loc->pspace |
05cba821 JK |
11573 | && loc->line_number == sal.line |
11574 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11575 | sal_fullname) == 0) | |
11576 | line_match = 1; | |
4aac40c8 | 11577 | |
0d381245 VP |
11578 | if (pc_match || line_match) |
11579 | { | |
11580 | match = 1; | |
11581 | break; | |
11582 | } | |
11583 | } | |
11584 | } | |
11585 | ||
11586 | if (match) | |
81b1e71c | 11587 | found.push_back (b); |
c906108c | 11588 | } |
80f8a6eb | 11589 | } |
8a2c437b | 11590 | |
80f8a6eb | 11591 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 11592 | if (found.empty ()) |
80f8a6eb MS |
11593 | { |
11594 | if (arg) | |
8a3fe4f8 | 11595 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11596 | else |
8a3fe4f8 | 11597 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11598 | } |
c906108c | 11599 | |
8a2c437b | 11600 | /* Remove duplicates from the vec. */ |
81b1e71c TT |
11601 | std::sort (found.begin (), found.end (), |
11602 | [] (const breakpoint *a, const breakpoint *b) | |
11603 | { | |
11604 | return compare_breakpoints (a, b) < 0; | |
11605 | }); | |
11606 | found.erase (std::unique (found.begin (), found.end (), | |
11607 | [] (const breakpoint *a, const breakpoint *b) | |
11608 | { | |
11609 | return compare_breakpoints (a, b) == 0; | |
11610 | }), | |
11611 | found.end ()); | |
8a2c437b | 11612 | |
81b1e71c | 11613 | if (found.size () > 1) |
4a64f543 | 11614 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11615 | if (from_tty) |
a3f17187 | 11616 | { |
81b1e71c | 11617 | if (found.size () == 1) |
a3f17187 AC |
11618 | printf_unfiltered (_("Deleted breakpoint ")); |
11619 | else | |
11620 | printf_unfiltered (_("Deleted breakpoints ")); | |
11621 | } | |
d6e956e5 | 11622 | |
81b1e71c | 11623 | for (breakpoint *iter : found) |
80f8a6eb | 11624 | { |
c5aa993b | 11625 | if (from_tty) |
81b1e71c TT |
11626 | printf_unfiltered ("%d ", iter->number); |
11627 | delete_breakpoint (iter); | |
c906108c | 11628 | } |
80f8a6eb MS |
11629 | if (from_tty) |
11630 | putchar_unfiltered ('\n'); | |
c906108c SS |
11631 | } |
11632 | \f | |
11633 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11634 | all breakpoints that are marked for deletion, whether hit or not. | |
11635 | This is called after any breakpoint is hit, or after errors. */ | |
11636 | ||
11637 | void | |
fba45db2 | 11638 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11639 | { |
35df4500 | 11640 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11641 | |
11642 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11643 | if (bs->breakpoint_at |
11644 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11645 | && bs->stop) |
f431efe5 | 11646 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11647 | |
35df4500 | 11648 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11649 | { |
b5de0fa7 | 11650 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11651 | delete_breakpoint (b); |
11652 | } | |
c906108c SS |
11653 | } |
11654 | ||
4a64f543 MS |
11655 | /* A comparison function for bp_location AP and BP being interfaced to |
11656 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11657 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 11658 | secondarily by ordering first permanent elements and |
4a64f543 | 11659 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 11660 | qsort being an unstable algorithm. */ |
876fa593 JK |
11661 | |
11662 | static int | |
f5336ca5 | 11663 | bp_locations_compare (const void *ap, const void *bp) |
876fa593 | 11664 | { |
9a3c8263 SM |
11665 | const struct bp_location *a = *(const struct bp_location **) ap; |
11666 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
11667 | |
11668 | if (a->address != b->address) | |
11669 | return (a->address > b->address) - (a->address < b->address); | |
11670 | ||
dea2aa5f LM |
11671 | /* Sort locations at the same address by their pspace number, keeping |
11672 | locations of the same inferior (in a multi-inferior environment) | |
11673 | grouped. */ | |
11674 | ||
11675 | if (a->pspace->num != b->pspace->num) | |
11676 | return ((a->pspace->num > b->pspace->num) | |
11677 | - (a->pspace->num < b->pspace->num)); | |
11678 | ||
876fa593 | 11679 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
11680 | if (a->permanent != b->permanent) |
11681 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 11682 | |
c56a97f9 JK |
11683 | /* Make the internal GDB representation stable across GDB runs |
11684 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11685 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11686 | |
11687 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11688 | return ((a->owner->number > b->owner->number) |
11689 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11690 | |
11691 | return (a > b) - (a < b); | |
11692 | } | |
11693 | ||
f5336ca5 PA |
11694 | /* Set bp_locations_placed_address_before_address_max and |
11695 | bp_locations_shadow_len_after_address_max according to the current | |
11696 | content of the bp_locations array. */ | |
f7545552 TT |
11697 | |
11698 | static void | |
f5336ca5 | 11699 | bp_locations_target_extensions_update (void) |
f7545552 | 11700 | { |
876fa593 JK |
11701 | struct bp_location *bl, **blp_tmp; |
11702 | ||
f5336ca5 PA |
11703 | bp_locations_placed_address_before_address_max = 0; |
11704 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11705 | |
11706 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11707 | { | |
11708 | CORE_ADDR start, end, addr; | |
11709 | ||
11710 | if (!bp_location_has_shadow (bl)) | |
11711 | continue; | |
11712 | ||
11713 | start = bl->target_info.placed_address; | |
11714 | end = start + bl->target_info.shadow_len; | |
11715 | ||
11716 | gdb_assert (bl->address >= start); | |
11717 | addr = bl->address - start; | |
f5336ca5 PA |
11718 | if (addr > bp_locations_placed_address_before_address_max) |
11719 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11720 | |
11721 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11722 | ||
11723 | gdb_assert (bl->address < end); | |
11724 | addr = end - bl->address; | |
f5336ca5 PA |
11725 | if (addr > bp_locations_shadow_len_after_address_max) |
11726 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11727 | } |
f7545552 TT |
11728 | } |
11729 | ||
1e4d1764 YQ |
11730 | /* Download tracepoint locations if they haven't been. */ |
11731 | ||
11732 | static void | |
11733 | download_tracepoint_locations (void) | |
11734 | { | |
7ed2c994 | 11735 | struct breakpoint *b; |
dd2e65cc | 11736 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11737 | |
5ed8105e | 11738 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11739 | |
7ed2c994 | 11740 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11741 | { |
7ed2c994 | 11742 | struct bp_location *bl; |
1e4d1764 | 11743 | struct tracepoint *t; |
f2a8bc8a | 11744 | int bp_location_downloaded = 0; |
1e4d1764 | 11745 | |
7ed2c994 | 11746 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11747 | ? !may_insert_fast_tracepoints |
11748 | : !may_insert_tracepoints)) | |
11749 | continue; | |
11750 | ||
dd2e65cc YQ |
11751 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11752 | { | |
11753 | if (target_can_download_tracepoint ()) | |
11754 | can_download_tracepoint = TRIBOOL_TRUE; | |
11755 | else | |
11756 | can_download_tracepoint = TRIBOOL_FALSE; | |
11757 | } | |
11758 | ||
11759 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11760 | break; | |
11761 | ||
7ed2c994 YQ |
11762 | for (bl = b->loc; bl; bl = bl->next) |
11763 | { | |
11764 | /* In tracepoint, locations are _never_ duplicated, so | |
11765 | should_be_inserted is equivalent to | |
11766 | unduplicated_should_be_inserted. */ | |
11767 | if (!should_be_inserted (bl) || bl->inserted) | |
11768 | continue; | |
1e4d1764 | 11769 | |
7ed2c994 | 11770 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11771 | |
7ed2c994 | 11772 | target_download_tracepoint (bl); |
1e4d1764 | 11773 | |
7ed2c994 | 11774 | bl->inserted = 1; |
f2a8bc8a | 11775 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11776 | } |
11777 | t = (struct tracepoint *) b; | |
11778 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
11779 | if (bp_location_downloaded) |
11780 | observer_notify_breakpoint_modified (b); | |
1e4d1764 | 11781 | } |
1e4d1764 YQ |
11782 | } |
11783 | ||
934709f0 PW |
11784 | /* Swap the insertion/duplication state between two locations. */ |
11785 | ||
11786 | static void | |
11787 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11788 | { | |
11789 | const int left_inserted = left->inserted; | |
11790 | const int left_duplicate = left->duplicate; | |
b775012e | 11791 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11792 | const struct bp_target_info left_target_info = left->target_info; |
11793 | ||
1e4d1764 YQ |
11794 | /* Locations of tracepoints can never be duplicated. */ |
11795 | if (is_tracepoint (left->owner)) | |
11796 | gdb_assert (!left->duplicate); | |
11797 | if (is_tracepoint (right->owner)) | |
11798 | gdb_assert (!right->duplicate); | |
11799 | ||
934709f0 PW |
11800 | left->inserted = right->inserted; |
11801 | left->duplicate = right->duplicate; | |
b775012e | 11802 | left->needs_update = right->needs_update; |
934709f0 PW |
11803 | left->target_info = right->target_info; |
11804 | right->inserted = left_inserted; | |
11805 | right->duplicate = left_duplicate; | |
b775012e | 11806 | right->needs_update = left_needs_update; |
934709f0 PW |
11807 | right->target_info = left_target_info; |
11808 | } | |
11809 | ||
b775012e LM |
11810 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11811 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11812 | conditions on the target's side. Such conditions need to be updated on | |
11813 | the target. */ | |
11814 | ||
11815 | static void | |
11816 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11817 | { | |
11818 | struct bp_location **locp = NULL, **loc2p; | |
11819 | struct bp_location *loc; | |
11820 | CORE_ADDR address = 0; | |
11821 | int pspace_num; | |
11822 | ||
11823 | address = bl->address; | |
11824 | pspace_num = bl->pspace->num; | |
11825 | ||
11826 | /* This is only meaningful if the target is | |
11827 | evaluating conditions and if the user has | |
11828 | opted for condition evaluation on the target's | |
11829 | side. */ | |
11830 | if (gdb_evaluates_breakpoint_condition_p () | |
11831 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11832 | return; | |
11833 | ||
11834 | /* Flag all breakpoint locations with this address and | |
11835 | the same program space as the location | |
11836 | as "its condition has changed". We need to | |
11837 | update the conditions on the target's side. */ | |
11838 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11839 | { | |
11840 | loc = *loc2p; | |
11841 | ||
11842 | if (!is_breakpoint (loc->owner) | |
11843 | || pspace_num != loc->pspace->num) | |
11844 | continue; | |
11845 | ||
11846 | /* Flag the location appropriately. We use a different state to | |
11847 | let everyone know that we already updated the set of locations | |
11848 | with addr bl->address and program space bl->pspace. This is so | |
11849 | we don't have to keep calling these functions just to mark locations | |
11850 | that have already been marked. */ | |
11851 | loc->condition_changed = condition_updated; | |
11852 | ||
11853 | /* Free the agent expression bytecode as well. We will compute | |
11854 | it later on. */ | |
833177a4 | 11855 | loc->cond_bytecode.reset (); |
b775012e LM |
11856 | } |
11857 | } | |
44702360 PA |
11858 | /* Called whether new breakpoints are created, or existing breakpoints |
11859 | deleted, to update the global location list and recompute which | |
11860 | locations are duplicate of which. | |
b775012e | 11861 | |
04086b45 PA |
11862 | The INSERT_MODE flag determines whether locations may not, may, or |
11863 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11864 | info. */ | |
b60e7edf | 11865 | |
0d381245 | 11866 | static void |
44702360 | 11867 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11868 | { |
74960c60 | 11869 | struct breakpoint *b; |
876fa593 | 11870 | struct bp_location **locp, *loc; |
b775012e LM |
11871 | /* Last breakpoint location address that was marked for update. */ |
11872 | CORE_ADDR last_addr = 0; | |
11873 | /* Last breakpoint location program space that was marked for update. */ | |
11874 | int last_pspace_num = -1; | |
f7545552 | 11875 | |
2d134ed3 PA |
11876 | /* Used in the duplicates detection below. When iterating over all |
11877 | bp_locations, points to the first bp_location of a given address. | |
11878 | Breakpoints and watchpoints of different types are never | |
11879 | duplicates of each other. Keep one pointer for each type of | |
11880 | breakpoint/watchpoint, so we only need to loop over all locations | |
11881 | once. */ | |
11882 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11883 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11884 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11885 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11886 | |
f5336ca5 PA |
11887 | /* Saved former bp_locations array which we compare against the newly |
11888 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
81b1e71c | 11889 | struct bp_location **old_locp; |
f5336ca5 | 11890 | unsigned old_locations_count; |
81b1e71c | 11891 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
876fa593 | 11892 | |
f5336ca5 PA |
11893 | old_locations_count = bp_locations_count; |
11894 | bp_locations = NULL; | |
11895 | bp_locations_count = 0; | |
0d381245 | 11896 | |
74960c60 | 11897 | ALL_BREAKPOINTS (b) |
876fa593 | 11898 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 11899 | bp_locations_count++; |
876fa593 | 11900 | |
f5336ca5 PA |
11901 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
11902 | locp = bp_locations; | |
876fa593 JK |
11903 | ALL_BREAKPOINTS (b) |
11904 | for (loc = b->loc; loc; loc = loc->next) | |
11905 | *locp++ = loc; | |
f5336ca5 PA |
11906 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
11907 | bp_locations_compare); | |
876fa593 | 11908 | |
f5336ca5 | 11909 | bp_locations_target_extensions_update (); |
74960c60 | 11910 | |
4a64f543 MS |
11911 | /* Identify bp_location instances that are no longer present in the |
11912 | new list, and therefore should be freed. Note that it's not | |
11913 | necessary that those locations should be removed from inferior -- | |
11914 | if there's another location at the same address (previously | |
11915 | marked as duplicate), we don't need to remove/insert the | |
11916 | location. | |
876fa593 | 11917 | |
4a64f543 MS |
11918 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11919 | and former bp_location array state respectively. */ | |
876fa593 | 11920 | |
f5336ca5 | 11921 | locp = bp_locations; |
81b1e71c TT |
11922 | for (old_locp = old_locations.get (); |
11923 | old_locp < old_locations.get () + old_locations_count; | |
876fa593 | 11924 | old_locp++) |
74960c60 | 11925 | { |
876fa593 | 11926 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11927 | struct bp_location **loc2p; |
876fa593 | 11928 | |
e5dd4106 | 11929 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11930 | not, we have to free it. */ |
c7d46a38 | 11931 | int found_object = 0; |
20874c92 VP |
11932 | /* Tells if the location should remain inserted in the target. */ |
11933 | int keep_in_target = 0; | |
11934 | int removed = 0; | |
876fa593 | 11935 | |
4a64f543 MS |
11936 | /* Skip LOCP entries which will definitely never be needed. |
11937 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 11938 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 11939 | && (*locp)->address < old_loc->address) |
876fa593 | 11940 | locp++; |
c7d46a38 PA |
11941 | |
11942 | for (loc2p = locp; | |
f5336ca5 | 11943 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
11944 | && (*loc2p)->address == old_loc->address); |
11945 | loc2p++) | |
11946 | { | |
b775012e LM |
11947 | /* Check if this is a new/duplicated location or a duplicated |
11948 | location that had its condition modified. If so, we want to send | |
11949 | its condition to the target if evaluation of conditions is taking | |
11950 | place there. */ | |
11951 | if ((*loc2p)->condition_changed == condition_modified | |
11952 | && (last_addr != old_loc->address | |
11953 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11954 | { |
b775012e LM |
11955 | force_breakpoint_reinsertion (*loc2p); |
11956 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11957 | } |
b775012e LM |
11958 | |
11959 | if (*loc2p == old_loc) | |
11960 | found_object = 1; | |
c7d46a38 | 11961 | } |
74960c60 | 11962 | |
b775012e LM |
11963 | /* We have already handled this address, update it so that we don't |
11964 | have to go through updates again. */ | |
11965 | last_addr = old_loc->address; | |
11966 | ||
11967 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11968 | if (!found_object) | |
11969 | force_breakpoint_reinsertion (old_loc); | |
11970 | ||
4a64f543 MS |
11971 | /* If this location is no longer present, and inserted, look if |
11972 | there's maybe a new location at the same address. If so, | |
11973 | mark that one inserted, and don't remove this one. This is | |
11974 | needed so that we don't have a time window where a breakpoint | |
11975 | at certain location is not inserted. */ | |
74960c60 | 11976 | |
876fa593 | 11977 | if (old_loc->inserted) |
0d381245 | 11978 | { |
4a64f543 MS |
11979 | /* If the location is inserted now, we might have to remove |
11980 | it. */ | |
74960c60 | 11981 | |
876fa593 | 11982 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11983 | { |
4a64f543 MS |
11984 | /* The location is still present in the location list, |
11985 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11986 | keep_in_target = 1; |
74960c60 VP |
11987 | } |
11988 | else | |
11989 | { | |
b775012e LM |
11990 | /* This location still exists, but it won't be kept in the |
11991 | target since it may have been disabled. We proceed to | |
11992 | remove its target-side condition. */ | |
11993 | ||
4a64f543 MS |
11994 | /* The location is either no longer present, or got |
11995 | disabled. See if there's another location at the | |
11996 | same address, in which case we don't need to remove | |
11997 | this one from the target. */ | |
876fa593 | 11998 | |
2bdf28a0 | 11999 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12000 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12001 | { | |
876fa593 | 12002 | for (loc2p = locp; |
f5336ca5 | 12003 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 12004 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
12005 | loc2p++) |
12006 | { | |
12007 | struct bp_location *loc2 = *loc2p; | |
12008 | ||
2d134ed3 | 12009 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12010 | { |
85d721b8 PA |
12011 | /* Read watchpoint locations are switched to |
12012 | access watchpoints, if the former are not | |
12013 | supported, but the latter are. */ | |
12014 | if (is_hardware_watchpoint (old_loc->owner)) | |
12015 | { | |
12016 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12017 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12018 | } | |
12019 | ||
934709f0 PW |
12020 | /* loc2 is a duplicated location. We need to check |
12021 | if it should be inserted in case it will be | |
12022 | unduplicated. */ | |
12023 | if (loc2 != old_loc | |
12024 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12025 | { |
934709f0 | 12026 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12027 | keep_in_target = 1; |
12028 | break; | |
12029 | } | |
876fa593 JK |
12030 | } |
12031 | } | |
12032 | } | |
74960c60 VP |
12033 | } |
12034 | ||
20874c92 VP |
12035 | if (!keep_in_target) |
12036 | { | |
834c0d03 | 12037 | if (remove_breakpoint (old_loc)) |
20874c92 | 12038 | { |
4a64f543 MS |
12039 | /* This is just about all we can do. We could keep |
12040 | this location on the global list, and try to | |
12041 | remove it next time, but there's no particular | |
12042 | reason why we will succeed next time. | |
20874c92 | 12043 | |
4a64f543 MS |
12044 | Note that at this point, old_loc->owner is still |
12045 | valid, as delete_breakpoint frees the breakpoint | |
12046 | only after calling us. */ | |
3e43a32a MS |
12047 | printf_filtered (_("warning: Error removing " |
12048 | "breakpoint %d\n"), | |
876fa593 | 12049 | old_loc->owner->number); |
20874c92 VP |
12050 | } |
12051 | removed = 1; | |
12052 | } | |
0d381245 | 12053 | } |
74960c60 VP |
12054 | |
12055 | if (!found_object) | |
1c5cfe86 | 12056 | { |
fbea99ea | 12057 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12058 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12059 | { |
db82e815 PA |
12060 | /* This location was removed from the target. In |
12061 | non-stop mode, a race condition is possible where | |
12062 | we've removed a breakpoint, but stop events for that | |
12063 | breakpoint are already queued and will arrive later. | |
12064 | We apply an heuristic to be able to distinguish such | |
12065 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12066 | breakpoint location for a bit, and will retire it | |
12067 | after we see some number of events. The theory here | |
12068 | is that reporting of events should, "on the average", | |
12069 | be fair, so after a while we'll see events from all | |
12070 | threads that have anything of interest, and no longer | |
12071 | need to keep this breakpoint location around. We | |
12072 | don't hold locations forever so to reduce chances of | |
12073 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12074 | SIGTRAP. | |
12075 | ||
12076 | The heuristic failing can be disastrous on | |
12077 | decr_pc_after_break targets. | |
12078 | ||
12079 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12080 | if we fail to recognize a late breakpoint SIGTRAP, | |
12081 | because events_till_retirement has reached 0 too | |
12082 | soon, we'll fail to do the PC adjustment, and report | |
12083 | a random SIGTRAP to the user. When the user resumes | |
12084 | the inferior, it will most likely immediately crash | |
2dec564e | 12085 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12086 | corrupted, because of being resumed e.g., in the |
12087 | middle of a multi-byte instruction, or skipped a | |
12088 | one-byte instruction. This was actually seen happen | |
12089 | on native x86-linux, and should be less rare on | |
12090 | targets that do not support new thread events, like | |
12091 | remote, due to the heuristic depending on | |
12092 | thread_count. | |
12093 | ||
12094 | Mistaking a random SIGTRAP for a breakpoint trap | |
12095 | causes similar symptoms (PC adjustment applied when | |
12096 | it shouldn't), but then again, playing with SIGTRAPs | |
12097 | behind the debugger's back is asking for trouble. | |
12098 | ||
12099 | Since hardware watchpoint traps are always | |
12100 | distinguishable from other traps, so we don't need to | |
12101 | apply keep hardware watchpoint moribund locations | |
12102 | around. We simply always ignore hardware watchpoint | |
12103 | traps we can no longer explain. */ | |
12104 | ||
876fa593 JK |
12105 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12106 | old_loc->owner = NULL; | |
20874c92 | 12107 | |
876fa593 | 12108 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12109 | } |
12110 | else | |
f431efe5 PA |
12111 | { |
12112 | old_loc->owner = NULL; | |
12113 | decref_bp_location (&old_loc); | |
12114 | } | |
20874c92 | 12115 | } |
74960c60 | 12116 | } |
1c5cfe86 | 12117 | |
348d480f PA |
12118 | /* Rescan breakpoints at the same address and section, marking the |
12119 | first one as "first" and any others as "duplicates". This is so | |
12120 | that the bpt instruction is only inserted once. If we have a | |
12121 | permanent breakpoint at the same place as BPT, make that one the | |
12122 | official one, and the rest as duplicates. Permanent breakpoints | |
12123 | are sorted first for the same address. | |
12124 | ||
12125 | Do the same for hardware watchpoints, but also considering the | |
12126 | watchpoint's type (regular/access/read) and length. */ | |
12127 | ||
12128 | bp_loc_first = NULL; | |
12129 | wp_loc_first = NULL; | |
12130 | awp_loc_first = NULL; | |
12131 | rwp_loc_first = NULL; | |
12132 | ALL_BP_LOCATIONS (loc, locp) | |
12133 | { | |
12134 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12135 | non-NULL. */ | |
348d480f | 12136 | struct bp_location **loc_first_p; |
d3fbdd86 | 12137 | b = loc->owner; |
348d480f | 12138 | |
6f380991 | 12139 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12140 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12141 | /* Don't detect duplicate for tracepoint locations because they are |
12142 | never duplicated. See the comments in field `duplicate' of | |
12143 | `struct bp_location'. */ | |
348d480f | 12144 | || is_tracepoint (b)) |
b775012e LM |
12145 | { |
12146 | /* Clear the condition modification flag. */ | |
12147 | loc->condition_changed = condition_unchanged; | |
12148 | continue; | |
12149 | } | |
348d480f | 12150 | |
348d480f PA |
12151 | if (b->type == bp_hardware_watchpoint) |
12152 | loc_first_p = &wp_loc_first; | |
12153 | else if (b->type == bp_read_watchpoint) | |
12154 | loc_first_p = &rwp_loc_first; | |
12155 | else if (b->type == bp_access_watchpoint) | |
12156 | loc_first_p = &awp_loc_first; | |
12157 | else | |
12158 | loc_first_p = &bp_loc_first; | |
12159 | ||
12160 | if (*loc_first_p == NULL | |
12161 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12162 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12163 | { | |
12164 | *loc_first_p = loc; | |
12165 | loc->duplicate = 0; | |
b775012e LM |
12166 | |
12167 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12168 | { | |
12169 | loc->needs_update = 1; | |
12170 | /* Clear the condition modification flag. */ | |
12171 | loc->condition_changed = condition_unchanged; | |
12172 | } | |
348d480f PA |
12173 | continue; |
12174 | } | |
12175 | ||
934709f0 PW |
12176 | |
12177 | /* This and the above ensure the invariant that the first location | |
12178 | is not duplicated, and is the inserted one. | |
12179 | All following are marked as duplicated, and are not inserted. */ | |
12180 | if (loc->inserted) | |
12181 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12182 | loc->duplicate = 1; |
12183 | ||
b775012e LM |
12184 | /* Clear the condition modification flag. */ |
12185 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12186 | } |
12187 | ||
a25a5a45 | 12188 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12189 | { |
04086b45 | 12190 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12191 | insert_breakpoint_locations (); |
12192 | else | |
12193 | { | |
44702360 PA |
12194 | /* Even though the caller told us to not insert new |
12195 | locations, we may still need to update conditions on the | |
12196 | target's side of breakpoints that were already inserted | |
12197 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12198 | only update conditions for locations that are marked |
12199 | "needs_update". */ | |
12200 | update_inserted_breakpoint_locations (); | |
12201 | } | |
12202 | } | |
348d480f | 12203 | |
04086b45 | 12204 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 12205 | download_tracepoint_locations (); |
348d480f PA |
12206 | } |
12207 | ||
12208 | void | |
12209 | breakpoint_retire_moribund (void) | |
12210 | { | |
12211 | struct bp_location *loc; | |
12212 | int ix; | |
12213 | ||
12214 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12215 | if (--(loc->events_till_retirement) == 0) | |
12216 | { | |
12217 | decref_bp_location (&loc); | |
12218 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12219 | --ix; | |
12220 | } | |
12221 | } | |
12222 | ||
12223 | static void | |
44702360 | 12224 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12225 | { |
348d480f | 12226 | |
492d29ea PA |
12227 | TRY |
12228 | { | |
12229 | update_global_location_list (insert_mode); | |
12230 | } | |
12231 | CATCH (e, RETURN_MASK_ERROR) | |
12232 | { | |
12233 | } | |
12234 | END_CATCH | |
348d480f PA |
12235 | } |
12236 | ||
12237 | /* Clear BKP from a BPS. */ | |
12238 | ||
12239 | static void | |
12240 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12241 | { | |
12242 | bpstat bs; | |
12243 | ||
12244 | for (bs = bps; bs; bs = bs->next) | |
12245 | if (bs->breakpoint_at == bpt) | |
12246 | { | |
12247 | bs->breakpoint_at = NULL; | |
12248 | bs->old_val = NULL; | |
12249 | /* bs->commands will be freed later. */ | |
12250 | } | |
12251 | } | |
12252 | ||
12253 | /* Callback for iterate_over_threads. */ | |
12254 | static int | |
12255 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12256 | { | |
9a3c8263 | 12257 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12258 | |
12259 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12260 | return 0; | |
12261 | } | |
12262 | ||
12263 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12264 | callbacks. */ | |
12265 | ||
12266 | static void | |
12267 | say_where (struct breakpoint *b) | |
12268 | { | |
12269 | struct value_print_options opts; | |
12270 | ||
12271 | get_user_print_options (&opts); | |
12272 | ||
12273 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12274 | single string. */ | |
12275 | if (b->loc == NULL) | |
12276 | { | |
f00aae0f KS |
12277 | /* For pending locations, the output differs slightly based |
12278 | on b->extra_string. If this is non-NULL, it contains either | |
12279 | a condition or dprintf arguments. */ | |
12280 | if (b->extra_string == NULL) | |
12281 | { | |
12282 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12283 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12284 | } |
12285 | else if (b->type == bp_dprintf) | |
12286 | { | |
12287 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12288 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12289 | b->extra_string); |
12290 | } | |
12291 | else | |
12292 | { | |
12293 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12294 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12295 | b->extra_string); |
12296 | } | |
348d480f PA |
12297 | } |
12298 | else | |
12299 | { | |
2f202fde | 12300 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12301 | { |
12302 | printf_filtered (" at "); | |
12303 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12304 | gdb_stdout); | |
12305 | } | |
2f202fde | 12306 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12307 | { |
12308 | /* If there is a single location, we can print the location | |
12309 | more nicely. */ | |
12310 | if (b->loc->next == NULL) | |
12311 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12312 | symtab_to_filename_for_display (b->loc->symtab), |
12313 | b->loc->line_number); | |
f8eba3c6 TT |
12314 | else |
12315 | /* This is not ideal, but each location may have a | |
12316 | different file name, and this at least reflects the | |
12317 | real situation somewhat. */ | |
f00aae0f | 12318 | printf_filtered (": %s.", |
d28cd78a | 12319 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12320 | } |
348d480f PA |
12321 | |
12322 | if (b->loc->next) | |
12323 | { | |
12324 | struct bp_location *loc = b->loc; | |
12325 | int n = 0; | |
12326 | for (; loc; loc = loc->next) | |
12327 | ++n; | |
12328 | printf_filtered (" (%d locations)", n); | |
12329 | } | |
12330 | } | |
12331 | } | |
12332 | ||
348d480f PA |
12333 | /* Default bp_location_ops methods. */ |
12334 | ||
12335 | static void | |
12336 | bp_location_dtor (struct bp_location *self) | |
12337 | { | |
348d480f PA |
12338 | xfree (self->function_name); |
12339 | } | |
12340 | ||
12341 | static const struct bp_location_ops bp_location_ops = | |
12342 | { | |
12343 | bp_location_dtor | |
12344 | }; | |
12345 | ||
c1fc2657 | 12346 | /* Destructor for the breakpoint base class. */ |
348d480f | 12347 | |
c1fc2657 | 12348 | breakpoint::~breakpoint () |
348d480f | 12349 | { |
c1fc2657 SM |
12350 | xfree (this->cond_string); |
12351 | xfree (this->extra_string); | |
12352 | xfree (this->filter); | |
348d480f PA |
12353 | } |
12354 | ||
2060206e PA |
12355 | static struct bp_location * |
12356 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12357 | { |
5625a286 | 12358 | return new bp_location (&bp_location_ops, self); |
348d480f PA |
12359 | } |
12360 | ||
2060206e PA |
12361 | static void |
12362 | base_breakpoint_re_set (struct breakpoint *b) | |
12363 | { | |
12364 | /* Nothing to re-set. */ | |
12365 | } | |
12366 | ||
12367 | #define internal_error_pure_virtual_called() \ | |
12368 | gdb_assert_not_reached ("pure virtual function called") | |
12369 | ||
12370 | static int | |
12371 | base_breakpoint_insert_location (struct bp_location *bl) | |
12372 | { | |
12373 | internal_error_pure_virtual_called (); | |
12374 | } | |
12375 | ||
12376 | static int | |
73971819 PA |
12377 | base_breakpoint_remove_location (struct bp_location *bl, |
12378 | enum remove_bp_reason reason) | |
2060206e PA |
12379 | { |
12380 | internal_error_pure_virtual_called (); | |
12381 | } | |
12382 | ||
12383 | static int | |
12384 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12385 | const address_space *aspace, |
09ac7c10 TT |
12386 | CORE_ADDR bp_addr, |
12387 | const struct target_waitstatus *ws) | |
2060206e PA |
12388 | { |
12389 | internal_error_pure_virtual_called (); | |
12390 | } | |
12391 | ||
12392 | static void | |
12393 | base_breakpoint_check_status (bpstat bs) | |
12394 | { | |
12395 | /* Always stop. */ | |
12396 | } | |
12397 | ||
12398 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12399 | errors. */ | |
12400 | ||
12401 | static int | |
12402 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12403 | { | |
12404 | internal_error_pure_virtual_called (); | |
12405 | } | |
12406 | ||
12407 | /* A "resources_needed" breakpoint_ops method that just internal | |
12408 | errors. */ | |
12409 | ||
12410 | static int | |
12411 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12412 | { | |
12413 | internal_error_pure_virtual_called (); | |
12414 | } | |
12415 | ||
12416 | static enum print_stop_action | |
12417 | base_breakpoint_print_it (bpstat bs) | |
12418 | { | |
12419 | internal_error_pure_virtual_called (); | |
12420 | } | |
12421 | ||
12422 | static void | |
12423 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12424 | struct ui_out *uiout) | |
12425 | { | |
12426 | /* nothing */ | |
12427 | } | |
12428 | ||
12429 | static void | |
12430 | base_breakpoint_print_mention (struct breakpoint *b) | |
12431 | { | |
12432 | internal_error_pure_virtual_called (); | |
12433 | } | |
12434 | ||
12435 | static void | |
12436 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12437 | { | |
12438 | internal_error_pure_virtual_called (); | |
12439 | } | |
12440 | ||
983af33b | 12441 | static void |
f00aae0f KS |
12442 | base_breakpoint_create_sals_from_location |
12443 | (const struct event_location *location, | |
12444 | struct linespec_result *canonical, | |
12445 | enum bptype type_wanted) | |
983af33b SDJ |
12446 | { |
12447 | internal_error_pure_virtual_called (); | |
12448 | } | |
12449 | ||
12450 | static void | |
12451 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12452 | struct linespec_result *c, | |
e1e01040 PA |
12453 | gdb::unique_xmalloc_ptr<char> cond_string, |
12454 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12455 | enum bptype type_wanted, |
12456 | enum bpdisp disposition, | |
12457 | int thread, | |
12458 | int task, int ignore_count, | |
12459 | const struct breakpoint_ops *o, | |
12460 | int from_tty, int enabled, | |
44f238bb | 12461 | int internal, unsigned flags) |
983af33b SDJ |
12462 | { |
12463 | internal_error_pure_virtual_called (); | |
12464 | } | |
12465 | ||
6c5b2ebe | 12466 | static std::vector<symtab_and_line> |
f00aae0f KS |
12467 | base_breakpoint_decode_location (struct breakpoint *b, |
12468 | const struct event_location *location, | |
6c5b2ebe | 12469 | struct program_space *search_pspace) |
983af33b SDJ |
12470 | { |
12471 | internal_error_pure_virtual_called (); | |
12472 | } | |
12473 | ||
ab04a2af TT |
12474 | /* The default 'explains_signal' method. */ |
12475 | ||
47591c29 | 12476 | static int |
427cd150 | 12477 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12478 | { |
47591c29 | 12479 | return 1; |
ab04a2af TT |
12480 | } |
12481 | ||
9d6e6e84 HZ |
12482 | /* The default "after_condition_true" method. */ |
12483 | ||
12484 | static void | |
12485 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12486 | { | |
12487 | /* Nothing to do. */ | |
12488 | } | |
12489 | ||
ab04a2af | 12490 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12491 | { |
2060206e PA |
12492 | base_breakpoint_allocate_location, |
12493 | base_breakpoint_re_set, | |
12494 | base_breakpoint_insert_location, | |
12495 | base_breakpoint_remove_location, | |
12496 | base_breakpoint_breakpoint_hit, | |
12497 | base_breakpoint_check_status, | |
12498 | base_breakpoint_resources_needed, | |
12499 | base_breakpoint_works_in_software_mode, | |
12500 | base_breakpoint_print_it, | |
12501 | NULL, | |
12502 | base_breakpoint_print_one_detail, | |
12503 | base_breakpoint_print_mention, | |
983af33b | 12504 | base_breakpoint_print_recreate, |
5f700d83 | 12505 | base_breakpoint_create_sals_from_location, |
983af33b | 12506 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12507 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12508 | base_breakpoint_explains_signal, |
12509 | base_breakpoint_after_condition_true, | |
2060206e PA |
12510 | }; |
12511 | ||
12512 | /* Default breakpoint_ops methods. */ | |
12513 | ||
12514 | static void | |
348d480f PA |
12515 | bkpt_re_set (struct breakpoint *b) |
12516 | { | |
06edf0c0 | 12517 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12518 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12519 | { |
f00aae0f | 12520 | /* Anything without a location can't be re-set. */ |
348d480f | 12521 | delete_breakpoint (b); |
06edf0c0 | 12522 | return; |
348d480f | 12523 | } |
06edf0c0 PA |
12524 | |
12525 | breakpoint_re_set_default (b); | |
348d480f PA |
12526 | } |
12527 | ||
2060206e | 12528 | static int |
348d480f PA |
12529 | bkpt_insert_location (struct bp_location *bl) |
12530 | { | |
cd6c3b4f YQ |
12531 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12532 | ||
579c6ad9 | 12533 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12534 | bl->target_info.placed_address = addr; |
12535 | ||
348d480f | 12536 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12537 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12538 | else |
7c16b83e | 12539 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12540 | } |
12541 | ||
2060206e | 12542 | static int |
73971819 | 12543 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12544 | { |
12545 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12546 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12547 | else | |
73971819 | 12548 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12549 | } |
12550 | ||
2060206e | 12551 | static int |
348d480f | 12552 | bkpt_breakpoint_hit (const struct bp_location *bl, |
bd522513 | 12553 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12554 | const struct target_waitstatus *ws) |
348d480f | 12555 | { |
09ac7c10 | 12556 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12557 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12558 | return 0; |
12559 | ||
348d480f PA |
12560 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12561 | aspace, bp_addr)) | |
12562 | return 0; | |
12563 | ||
12564 | if (overlay_debugging /* unmapped overlay section */ | |
12565 | && section_is_overlay (bl->section) | |
12566 | && !section_is_mapped (bl->section)) | |
12567 | return 0; | |
12568 | ||
12569 | return 1; | |
12570 | } | |
12571 | ||
cd1608cc PA |
12572 | static int |
12573 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12574 | const address_space *aspace, CORE_ADDR bp_addr, |
cd1608cc PA |
12575 | const struct target_waitstatus *ws) |
12576 | { | |
12577 | if (dprintf_style == dprintf_style_agent | |
12578 | && target_can_run_breakpoint_commands ()) | |
12579 | { | |
12580 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12581 | for this address it must be for a breakpoint that happens to | |
12582 | be set at the same address. */ | |
12583 | return 0; | |
12584 | } | |
12585 | ||
12586 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12587 | } | |
12588 | ||
2060206e | 12589 | static int |
348d480f PA |
12590 | bkpt_resources_needed (const struct bp_location *bl) |
12591 | { | |
12592 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12593 | ||
12594 | return 1; | |
12595 | } | |
12596 | ||
2060206e | 12597 | static enum print_stop_action |
348d480f PA |
12598 | bkpt_print_it (bpstat bs) |
12599 | { | |
348d480f PA |
12600 | struct breakpoint *b; |
12601 | const struct bp_location *bl; | |
001c8c33 | 12602 | int bp_temp; |
79a45e25 | 12603 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12604 | |
12605 | gdb_assert (bs->bp_location_at != NULL); | |
12606 | ||
12607 | bl = bs->bp_location_at; | |
12608 | b = bs->breakpoint_at; | |
12609 | ||
001c8c33 PA |
12610 | bp_temp = b->disposition == disp_del; |
12611 | if (bl->address != bl->requested_address) | |
12612 | breakpoint_adjustment_warning (bl->requested_address, | |
12613 | bl->address, | |
12614 | b->number, 1); | |
12615 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12616 | maybe_print_thread_hit_breakpoint (uiout); |
12617 | ||
001c8c33 | 12618 | if (bp_temp) |
112e8700 | 12619 | uiout->text ("Temporary breakpoint "); |
001c8c33 | 12620 | else |
112e8700 SM |
12621 | uiout->text ("Breakpoint "); |
12622 | if (uiout->is_mi_like_p ()) | |
348d480f | 12623 | { |
112e8700 | 12624 | uiout->field_string ("reason", |
001c8c33 | 12625 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12626 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12627 | } |
112e8700 SM |
12628 | uiout->field_int ("bkptno", b->number); |
12629 | uiout->text (", "); | |
06edf0c0 | 12630 | |
001c8c33 | 12631 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12632 | } |
12633 | ||
2060206e | 12634 | static void |
06edf0c0 PA |
12635 | bkpt_print_mention (struct breakpoint *b) |
12636 | { | |
112e8700 | 12637 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12638 | return; |
12639 | ||
12640 | switch (b->type) | |
12641 | { | |
12642 | case bp_breakpoint: | |
12643 | case bp_gnu_ifunc_resolver: | |
12644 | if (b->disposition == disp_del) | |
12645 | printf_filtered (_("Temporary breakpoint")); | |
12646 | else | |
12647 | printf_filtered (_("Breakpoint")); | |
12648 | printf_filtered (_(" %d"), b->number); | |
12649 | if (b->type == bp_gnu_ifunc_resolver) | |
12650 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12651 | break; | |
12652 | case bp_hardware_breakpoint: | |
12653 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12654 | break; | |
e7e0cddf SS |
12655 | case bp_dprintf: |
12656 | printf_filtered (_("Dprintf %d"), b->number); | |
12657 | break; | |
06edf0c0 PA |
12658 | } |
12659 | ||
12660 | say_where (b); | |
12661 | } | |
12662 | ||
2060206e | 12663 | static void |
06edf0c0 PA |
12664 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12665 | { | |
12666 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12667 | fprintf_unfiltered (fp, "tbreak"); | |
12668 | else if (tp->type == bp_breakpoint) | |
12669 | fprintf_unfiltered (fp, "break"); | |
12670 | else if (tp->type == bp_hardware_breakpoint | |
12671 | && tp->disposition == disp_del) | |
12672 | fprintf_unfiltered (fp, "thbreak"); | |
12673 | else if (tp->type == bp_hardware_breakpoint) | |
12674 | fprintf_unfiltered (fp, "hbreak"); | |
12675 | else | |
12676 | internal_error (__FILE__, __LINE__, | |
12677 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12678 | ||
f00aae0f | 12679 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12680 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12681 | |
12682 | /* Print out extra_string if this breakpoint is pending. It might | |
12683 | contain, for example, conditions that were set by the user. */ | |
12684 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12685 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12686 | ||
dd11a36c | 12687 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12688 | } |
12689 | ||
983af33b | 12690 | static void |
f00aae0f KS |
12691 | bkpt_create_sals_from_location (const struct event_location *location, |
12692 | struct linespec_result *canonical, | |
12693 | enum bptype type_wanted) | |
983af33b | 12694 | { |
f00aae0f | 12695 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12696 | } |
12697 | ||
12698 | static void | |
12699 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12700 | struct linespec_result *canonical, | |
e1e01040 PA |
12701 | gdb::unique_xmalloc_ptr<char> cond_string, |
12702 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12703 | enum bptype type_wanted, |
12704 | enum bpdisp disposition, | |
12705 | int thread, | |
12706 | int task, int ignore_count, | |
12707 | const struct breakpoint_ops *ops, | |
12708 | int from_tty, int enabled, | |
44f238bb | 12709 | int internal, unsigned flags) |
983af33b | 12710 | { |
023fa29b | 12711 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12712 | std::move (cond_string), |
12713 | std::move (extra_string), | |
e7e0cddf | 12714 | type_wanted, |
983af33b SDJ |
12715 | disposition, thread, task, |
12716 | ignore_count, ops, from_tty, | |
44f238bb | 12717 | enabled, internal, flags); |
983af33b SDJ |
12718 | } |
12719 | ||
6c5b2ebe | 12720 | static std::vector<symtab_and_line> |
f00aae0f KS |
12721 | bkpt_decode_location (struct breakpoint *b, |
12722 | const struct event_location *location, | |
6c5b2ebe | 12723 | struct program_space *search_pspace) |
983af33b | 12724 | { |
6c5b2ebe | 12725 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12726 | } |
12727 | ||
06edf0c0 PA |
12728 | /* Virtual table for internal breakpoints. */ |
12729 | ||
12730 | static void | |
12731 | internal_bkpt_re_set (struct breakpoint *b) | |
12732 | { | |
12733 | switch (b->type) | |
12734 | { | |
12735 | /* Delete overlay event and longjmp master breakpoints; they | |
12736 | will be reset later by breakpoint_re_set. */ | |
12737 | case bp_overlay_event: | |
12738 | case bp_longjmp_master: | |
12739 | case bp_std_terminate_master: | |
12740 | case bp_exception_master: | |
12741 | delete_breakpoint (b); | |
12742 | break; | |
12743 | ||
12744 | /* This breakpoint is special, it's set up when the inferior | |
12745 | starts and we really don't want to touch it. */ | |
12746 | case bp_shlib_event: | |
12747 | ||
12748 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12749 | it is set up, we do not want to touch it. */ | |
12750 | case bp_thread_event: | |
12751 | break; | |
12752 | } | |
12753 | } | |
12754 | ||
12755 | static void | |
12756 | internal_bkpt_check_status (bpstat bs) | |
12757 | { | |
a9b3a50f PA |
12758 | if (bs->breakpoint_at->type == bp_shlib_event) |
12759 | { | |
12760 | /* If requested, stop when the dynamic linker notifies GDB of | |
12761 | events. This allows the user to get control and place | |
12762 | breakpoints in initializer routines for dynamically loaded | |
12763 | objects (among other things). */ | |
12764 | bs->stop = stop_on_solib_events; | |
12765 | bs->print = stop_on_solib_events; | |
12766 | } | |
12767 | else | |
12768 | bs->stop = 0; | |
06edf0c0 PA |
12769 | } |
12770 | ||
12771 | static enum print_stop_action | |
12772 | internal_bkpt_print_it (bpstat bs) | |
12773 | { | |
06edf0c0 | 12774 | struct breakpoint *b; |
06edf0c0 | 12775 | |
06edf0c0 PA |
12776 | b = bs->breakpoint_at; |
12777 | ||
06edf0c0 PA |
12778 | switch (b->type) |
12779 | { | |
348d480f PA |
12780 | case bp_shlib_event: |
12781 | /* Did we stop because the user set the stop_on_solib_events | |
12782 | variable? (If so, we report this as a generic, "Stopped due | |
12783 | to shlib event" message.) */ | |
edcc5120 | 12784 | print_solib_event (0); |
348d480f PA |
12785 | break; |
12786 | ||
12787 | case bp_thread_event: | |
12788 | /* Not sure how we will get here. | |
12789 | GDB should not stop for these breakpoints. */ | |
12790 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12791 | break; |
12792 | ||
12793 | case bp_overlay_event: | |
12794 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12795 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12796 | break; |
12797 | ||
12798 | case bp_longjmp_master: | |
12799 | /* These should never be enabled. */ | |
12800 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12801 | break; |
12802 | ||
12803 | case bp_std_terminate_master: | |
12804 | /* These should never be enabled. */ | |
12805 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12806 | "gdb should not stop!\n")); | |
348d480f PA |
12807 | break; |
12808 | ||
12809 | case bp_exception_master: | |
12810 | /* These should never be enabled. */ | |
12811 | printf_filtered (_("Exception Master Breakpoint: " | |
12812 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12813 | break; |
12814 | } | |
12815 | ||
001c8c33 | 12816 | return PRINT_NOTHING; |
06edf0c0 PA |
12817 | } |
12818 | ||
12819 | static void | |
12820 | internal_bkpt_print_mention (struct breakpoint *b) | |
12821 | { | |
12822 | /* Nothing to mention. These breakpoints are internal. */ | |
12823 | } | |
12824 | ||
06edf0c0 PA |
12825 | /* Virtual table for momentary breakpoints */ |
12826 | ||
12827 | static void | |
12828 | momentary_bkpt_re_set (struct breakpoint *b) | |
12829 | { | |
12830 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12831 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12832 | Otherwise these should have been blown away via the cleanup chain |
12833 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12834 | } | |
12835 | ||
12836 | static void | |
12837 | momentary_bkpt_check_status (bpstat bs) | |
12838 | { | |
12839 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12840 | } | |
12841 | ||
12842 | static enum print_stop_action | |
12843 | momentary_bkpt_print_it (bpstat bs) | |
12844 | { | |
001c8c33 | 12845 | return PRINT_UNKNOWN; |
348d480f PA |
12846 | } |
12847 | ||
06edf0c0 PA |
12848 | static void |
12849 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12850 | { |
06edf0c0 | 12851 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12852 | } |
12853 | ||
e2e4d78b JK |
12854 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12855 | ||
12856 | It gets cleared already on the removal of the first one of such placed | |
12857 | breakpoints. This is OK as they get all removed altogether. */ | |
12858 | ||
c1fc2657 | 12859 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 12860 | { |
c1fc2657 | 12861 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 12862 | |
c1fc2657 | 12863 | if (tp != NULL) |
e2e4d78b | 12864 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
12865 | } |
12866 | ||
55aa24fb SDJ |
12867 | /* Specific methods for probe breakpoints. */ |
12868 | ||
12869 | static int | |
12870 | bkpt_probe_insert_location (struct bp_location *bl) | |
12871 | { | |
12872 | int v = bkpt_insert_location (bl); | |
12873 | ||
12874 | if (v == 0) | |
12875 | { | |
12876 | /* The insertion was successful, now let's set the probe's semaphore | |
12877 | if needed. */ | |
935676c9 | 12878 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb SDJ |
12879 | } |
12880 | ||
12881 | return v; | |
12882 | } | |
12883 | ||
12884 | static int | |
73971819 PA |
12885 | bkpt_probe_remove_location (struct bp_location *bl, |
12886 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
12887 | { |
12888 | /* Let's clear the semaphore before removing the location. */ | |
935676c9 | 12889 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb | 12890 | |
73971819 | 12891 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
12892 | } |
12893 | ||
12894 | static void | |
f00aae0f | 12895 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12896 | struct linespec_result *canonical, |
f00aae0f | 12897 | enum bptype type_wanted) |
55aa24fb SDJ |
12898 | { |
12899 | struct linespec_sals lsal; | |
12900 | ||
c2f4122d | 12901 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
12902 | lsal.canonical |
12903 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12904 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
12905 | } |
12906 | ||
6c5b2ebe | 12907 | static std::vector<symtab_and_line> |
f00aae0f KS |
12908 | bkpt_probe_decode_location (struct breakpoint *b, |
12909 | const struct event_location *location, | |
6c5b2ebe | 12910 | struct program_space *search_pspace) |
55aa24fb | 12911 | { |
6c5b2ebe PA |
12912 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
12913 | if (sals.empty ()) | |
55aa24fb | 12914 | error (_("probe not found")); |
6c5b2ebe | 12915 | return sals; |
55aa24fb SDJ |
12916 | } |
12917 | ||
348d480f | 12918 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12919 | |
348d480f PA |
12920 | static void |
12921 | tracepoint_re_set (struct breakpoint *b) | |
12922 | { | |
12923 | breakpoint_re_set_default (b); | |
12924 | } | |
876fa593 | 12925 | |
348d480f PA |
12926 | static int |
12927 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12928 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12929 | const struct target_waitstatus *ws) |
348d480f PA |
12930 | { |
12931 | /* By definition, the inferior does not report stops at | |
12932 | tracepoints. */ | |
12933 | return 0; | |
74960c60 VP |
12934 | } |
12935 | ||
12936 | static void | |
348d480f PA |
12937 | tracepoint_print_one_detail (const struct breakpoint *self, |
12938 | struct ui_out *uiout) | |
74960c60 | 12939 | { |
d9b3f62e PA |
12940 | struct tracepoint *tp = (struct tracepoint *) self; |
12941 | if (tp->static_trace_marker_id) | |
348d480f PA |
12942 | { |
12943 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12944 | |
112e8700 SM |
12945 | uiout->text ("\tmarker id is "); |
12946 | uiout->field_string ("static-tracepoint-marker-string-id", | |
d9b3f62e | 12947 | tp->static_trace_marker_id); |
112e8700 | 12948 | uiout->text ("\n"); |
348d480f | 12949 | } |
0d381245 VP |
12950 | } |
12951 | ||
a474d7c2 | 12952 | static void |
348d480f | 12953 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12954 | { |
112e8700 | 12955 | if (current_uiout->is_mi_like_p ()) |
348d480f | 12956 | return; |
cc59ec59 | 12957 | |
348d480f PA |
12958 | switch (b->type) |
12959 | { | |
12960 | case bp_tracepoint: | |
12961 | printf_filtered (_("Tracepoint")); | |
12962 | printf_filtered (_(" %d"), b->number); | |
12963 | break; | |
12964 | case bp_fast_tracepoint: | |
12965 | printf_filtered (_("Fast tracepoint")); | |
12966 | printf_filtered (_(" %d"), b->number); | |
12967 | break; | |
12968 | case bp_static_tracepoint: | |
12969 | printf_filtered (_("Static tracepoint")); | |
12970 | printf_filtered (_(" %d"), b->number); | |
12971 | break; | |
12972 | default: | |
12973 | internal_error (__FILE__, __LINE__, | |
12974 | _("unhandled tracepoint type %d"), (int) b->type); | |
12975 | } | |
12976 | ||
12977 | say_where (b); | |
a474d7c2 PA |
12978 | } |
12979 | ||
348d480f | 12980 | static void |
d9b3f62e | 12981 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12982 | { |
d9b3f62e PA |
12983 | struct tracepoint *tp = (struct tracepoint *) self; |
12984 | ||
12985 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12986 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 12987 | else if (self->type == bp_static_tracepoint) |
348d480f | 12988 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12989 | else if (self->type == bp_tracepoint) |
348d480f PA |
12990 | fprintf_unfiltered (fp, "trace"); |
12991 | else | |
12992 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12993 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12994 | |
f00aae0f | 12995 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12996 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
12997 | print_recreate_thread (self, fp); |
12998 | ||
12999 | if (tp->pass_count) | |
13000 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13001 | } |
13002 | ||
983af33b | 13003 | static void |
f00aae0f KS |
13004 | tracepoint_create_sals_from_location (const struct event_location *location, |
13005 | struct linespec_result *canonical, | |
13006 | enum bptype type_wanted) | |
983af33b | 13007 | { |
f00aae0f | 13008 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13009 | } |
13010 | ||
13011 | static void | |
13012 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13013 | struct linespec_result *canonical, | |
e1e01040 PA |
13014 | gdb::unique_xmalloc_ptr<char> cond_string, |
13015 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13016 | enum bptype type_wanted, |
13017 | enum bpdisp disposition, | |
13018 | int thread, | |
13019 | int task, int ignore_count, | |
13020 | const struct breakpoint_ops *ops, | |
13021 | int from_tty, int enabled, | |
44f238bb | 13022 | int internal, unsigned flags) |
983af33b | 13023 | { |
023fa29b | 13024 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13025 | std::move (cond_string), |
13026 | std::move (extra_string), | |
e7e0cddf | 13027 | type_wanted, |
983af33b SDJ |
13028 | disposition, thread, task, |
13029 | ignore_count, ops, from_tty, | |
44f238bb | 13030 | enabled, internal, flags); |
983af33b SDJ |
13031 | } |
13032 | ||
6c5b2ebe | 13033 | static std::vector<symtab_and_line> |
f00aae0f KS |
13034 | tracepoint_decode_location (struct breakpoint *b, |
13035 | const struct event_location *location, | |
6c5b2ebe | 13036 | struct program_space *search_pspace) |
983af33b | 13037 | { |
6c5b2ebe | 13038 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
13039 | } |
13040 | ||
2060206e | 13041 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13042 | |
55aa24fb SDJ |
13043 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13044 | static probe. */ | |
13045 | ||
13046 | static void | |
f00aae0f KS |
13047 | tracepoint_probe_create_sals_from_location |
13048 | (const struct event_location *location, | |
13049 | struct linespec_result *canonical, | |
13050 | enum bptype type_wanted) | |
55aa24fb SDJ |
13051 | { |
13052 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13053 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13054 | } |
13055 | ||
6c5b2ebe | 13056 | static std::vector<symtab_and_line> |
f00aae0f KS |
13057 | tracepoint_probe_decode_location (struct breakpoint *b, |
13058 | const struct event_location *location, | |
6c5b2ebe | 13059 | struct program_space *search_pspace) |
55aa24fb SDJ |
13060 | { |
13061 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 13062 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
13063 | } |
13064 | ||
13065 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13066 | ||
5c2b4418 HZ |
13067 | /* Dprintf breakpoint_ops methods. */ |
13068 | ||
13069 | static void | |
13070 | dprintf_re_set (struct breakpoint *b) | |
13071 | { | |
13072 | breakpoint_re_set_default (b); | |
13073 | ||
f00aae0f KS |
13074 | /* extra_string should never be non-NULL for dprintf. */ |
13075 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13076 | |
13077 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13078 | 2 - create a dprintf, which resolves fine. | |
13079 | 3 - disconnect from target 1 | |
13080 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13081 | ||
13082 | After steps #3/#4, you'll want the dprintf command list to | |
13083 | be updated, because target 1 and 2 may well return different | |
13084 | answers for target_can_run_breakpoint_commands(). | |
13085 | Given absence of finer grained resetting, we get to do | |
13086 | it all the time. */ | |
13087 | if (b->extra_string != NULL) | |
13088 | update_dprintf_command_list (b); | |
13089 | } | |
13090 | ||
2d9442cc HZ |
13091 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13092 | ||
13093 | static void | |
13094 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13095 | { | |
f00aae0f | 13096 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 13097 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
13098 | tp->extra_string); |
13099 | print_recreate_thread (tp, fp); | |
13100 | } | |
13101 | ||
9d6e6e84 HZ |
13102 | /* Implement the "after_condition_true" breakpoint_ops method for |
13103 | dprintf. | |
13104 | ||
13105 | dprintf's are implemented with regular commands in their command | |
13106 | list, but we run the commands here instead of before presenting the | |
13107 | stop to the user, as dprintf's don't actually cause a stop. This | |
13108 | also makes it so that the commands of multiple dprintfs at the same | |
13109 | address are all handled. */ | |
13110 | ||
13111 | static void | |
13112 | dprintf_after_condition_true (struct bpstats *bs) | |
13113 | { | |
04afa70c | 13114 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
13115 | struct bpstats *tmp_bs_p = &tmp_bs; |
13116 | ||
13117 | /* dprintf's never cause a stop. This wasn't set in the | |
13118 | check_status hook instead because that would make the dprintf's | |
13119 | condition not be evaluated. */ | |
13120 | bs->stop = 0; | |
13121 | ||
13122 | /* Run the command list here. Take ownership of it instead of | |
13123 | copying. We never want these commands to run later in | |
13124 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13125 | be set at same address as this dprintf, or even if running the | |
13126 | commands here throws. */ | |
13127 | tmp_bs.commands = bs->commands; | |
13128 | bs->commands = NULL; | |
9d6e6e84 HZ |
13129 | |
13130 | bpstat_do_actions_1 (&tmp_bs_p); | |
13131 | ||
13132 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13133 | bpstat_do_actions_1 may return early without processing the whole | |
13134 | list. */ | |
9d6e6e84 HZ |
13135 | } |
13136 | ||
983af33b SDJ |
13137 | /* The breakpoint_ops structure to be used on static tracepoints with |
13138 | markers (`-m'). */ | |
13139 | ||
13140 | static void | |
f00aae0f | 13141 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13142 | struct linespec_result *canonical, |
f00aae0f | 13143 | enum bptype type_wanted) |
983af33b SDJ |
13144 | { |
13145 | struct linespec_sals lsal; | |
f00aae0f | 13146 | const char *arg_start, *arg; |
983af33b | 13147 | |
a20714ff | 13148 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 13149 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 13150 | |
f2fc3015 TT |
13151 | std::string str (arg_start, arg - arg_start); |
13152 | const char *ptr = str.c_str (); | |
a20714ff PA |
13153 | canonical->location |
13154 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 13155 | |
8e9e35b1 TT |
13156 | lsal.canonical |
13157 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13158 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
13159 | } |
13160 | ||
13161 | static void | |
13162 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13163 | struct linespec_result *canonical, | |
e1e01040 PA |
13164 | gdb::unique_xmalloc_ptr<char> cond_string, |
13165 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13166 | enum bptype type_wanted, |
13167 | enum bpdisp disposition, | |
13168 | int thread, | |
13169 | int task, int ignore_count, | |
13170 | const struct breakpoint_ops *ops, | |
13171 | int from_tty, int enabled, | |
44f238bb | 13172 | int internal, unsigned flags) |
983af33b | 13173 | { |
6c5b2ebe | 13174 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
13175 | |
13176 | /* If the user is creating a static tracepoint by marker id | |
13177 | (strace -m MARKER_ID), then store the sals index, so that | |
13178 | breakpoint_re_set can try to match up which of the newly | |
13179 | found markers corresponds to this one, and, don't try to | |
13180 | expand multiple locations for each sal, given than SALS | |
13181 | already should contain all sals for MARKER_ID. */ | |
13182 | ||
6c5b2ebe | 13183 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 13184 | { |
6c5b2ebe PA |
13185 | event_location_up location |
13186 | = copy_event_location (canonical->location.get ()); | |
983af33b | 13187 | |
b270e6f9 | 13188 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 13189 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 13190 | std::move (location), NULL, |
e1e01040 PA |
13191 | std::move (cond_string), |
13192 | std::move (extra_string), | |
e7e0cddf | 13193 | type_wanted, disposition, |
983af33b | 13194 | thread, task, ignore_count, ops, |
44f238bb | 13195 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13196 | canonical->special_display); |
13197 | /* Given that its possible to have multiple markers with | |
13198 | the same string id, if the user is creating a static | |
13199 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13200 | store the sals index, so that breakpoint_re_set can | |
13201 | try to match up which of the newly found markers | |
13202 | corresponds to this one */ | |
13203 | tp->static_trace_marker_id_idx = i; | |
13204 | ||
b270e6f9 | 13205 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
13206 | } |
13207 | } | |
13208 | ||
6c5b2ebe | 13209 | static std::vector<symtab_and_line> |
f00aae0f KS |
13210 | strace_marker_decode_location (struct breakpoint *b, |
13211 | const struct event_location *location, | |
6c5b2ebe | 13212 | struct program_space *search_pspace) |
983af33b SDJ |
13213 | { |
13214 | struct tracepoint *tp = (struct tracepoint *) b; | |
a20714ff | 13215 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 13216 | |
6c5b2ebe PA |
13217 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
13218 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 13219 | { |
6c5b2ebe PA |
13220 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
13221 | sals.resize (1); | |
13222 | return sals; | |
983af33b SDJ |
13223 | } |
13224 | else | |
13225 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13226 | } | |
13227 | ||
13228 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13229 | ||
13230 | static int | |
13231 | strace_marker_p (struct breakpoint *b) | |
13232 | { | |
13233 | return b->ops == &strace_marker_breakpoint_ops; | |
13234 | } | |
13235 | ||
53a5351d | 13236 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13237 | structures. */ |
c906108c SS |
13238 | |
13239 | void | |
fba45db2 | 13240 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13241 | { |
52f0bd74 | 13242 | struct breakpoint *b; |
c906108c | 13243 | |
8a3fe4f8 | 13244 | gdb_assert (bpt != NULL); |
c906108c | 13245 | |
4a64f543 MS |
13246 | /* Has this bp already been deleted? This can happen because |
13247 | multiple lists can hold pointers to bp's. bpstat lists are | |
13248 | especial culprits. | |
13249 | ||
13250 | One example of this happening is a watchpoint's scope bp. When | |
13251 | the scope bp triggers, we notice that the watchpoint is out of | |
13252 | scope, and delete it. We also delete its scope bp. But the | |
13253 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13254 | That bpstat is then checked for auto-deleting bp's, which are | |
13255 | deleted. | |
13256 | ||
13257 | A real solution to this problem might involve reference counts in | |
13258 | bp's, and/or giving them pointers back to their referencing | |
13259 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13260 | storage when no more references were extent. A cheaper bandaid | |
13261 | was chosen. */ | |
c906108c SS |
13262 | if (bpt->type == bp_none) |
13263 | return; | |
13264 | ||
4a64f543 MS |
13265 | /* At least avoid this stale reference until the reference counting |
13266 | of breakpoints gets resolved. */ | |
d0fb5eae | 13267 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13268 | { |
d0fb5eae | 13269 | struct breakpoint *related; |
3a5c3e22 | 13270 | struct watchpoint *w; |
d0fb5eae JK |
13271 | |
13272 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13273 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13274 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13275 | w = (struct watchpoint *) bpt; |
13276 | else | |
13277 | w = NULL; | |
13278 | if (w != NULL) | |
13279 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13280 | |
13281 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13282 | for (related = bpt; related->related_breakpoint != bpt; | |
13283 | related = related->related_breakpoint); | |
13284 | related->related_breakpoint = bpt->related_breakpoint; | |
13285 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13286 | } |
13287 | ||
a9634178 TJB |
13288 | /* watch_command_1 creates a watchpoint but only sets its number if |
13289 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13290 | a problem in that process, we'll be asked to delete the half-created | |
13291 | watchpoint. In that case, don't announce the deletion. */ | |
13292 | if (bpt->number) | |
13293 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13294 | |
c906108c SS |
13295 | if (breakpoint_chain == bpt) |
13296 | breakpoint_chain = bpt->next; | |
13297 | ||
c906108c SS |
13298 | ALL_BREAKPOINTS (b) |
13299 | if (b->next == bpt) | |
c5aa993b JM |
13300 | { |
13301 | b->next = bpt->next; | |
13302 | break; | |
13303 | } | |
c906108c | 13304 | |
f431efe5 PA |
13305 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13306 | been freed. */ | |
13307 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13308 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13309 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13310 | commands are associated with the bpstat; if we remove it here, | |
13311 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13312 | event-top.c won't do anything, and temporary breakpoints with | |
13313 | commands won't work. */ | |
13314 | ||
13315 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13316 | ||
4a64f543 MS |
13317 | /* Now that breakpoint is removed from breakpoint list, update the |
13318 | global location list. This will remove locations that used to | |
13319 | belong to this breakpoint. Do this before freeing the breakpoint | |
13320 | itself, since remove_breakpoint looks at location's owner. It | |
13321 | might be better design to have location completely | |
13322 | self-contained, but it's not the case now. */ | |
44702360 | 13323 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13324 | |
4a64f543 MS |
13325 | /* On the chance that someone will soon try again to delete this |
13326 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13327 | bpt->type = bp_none; |
4d01a485 | 13328 | delete bpt; |
c906108c SS |
13329 | } |
13330 | ||
51be5b68 PA |
13331 | /* Iterator function to call a user-provided callback function once |
13332 | for each of B and its related breakpoints. */ | |
13333 | ||
13334 | static void | |
13335 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13336 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13337 | { |
13338 | struct breakpoint *related; | |
13339 | ||
13340 | related = b; | |
13341 | do | |
13342 | { | |
13343 | struct breakpoint *next; | |
13344 | ||
13345 | /* FUNCTION may delete RELATED. */ | |
13346 | next = related->related_breakpoint; | |
13347 | ||
13348 | if (next == related) | |
13349 | { | |
13350 | /* RELATED is the last ring entry. */ | |
48649e1b | 13351 | function (related); |
51be5b68 PA |
13352 | |
13353 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13354 | B. There's nothing left to do anyway, so just break | |
13355 | out. */ | |
13356 | break; | |
13357 | } | |
13358 | else | |
48649e1b | 13359 | function (related); |
51be5b68 PA |
13360 | |
13361 | related = next; | |
13362 | } | |
13363 | while (related != b); | |
13364 | } | |
95a42b64 | 13365 | |
4495129a | 13366 | static void |
981a3fb3 | 13367 | delete_command (const char *arg, int from_tty) |
c906108c | 13368 | { |
35df4500 | 13369 | struct breakpoint *b, *b_tmp; |
c906108c | 13370 | |
ea9365bb TT |
13371 | dont_repeat (); |
13372 | ||
c906108c SS |
13373 | if (arg == 0) |
13374 | { | |
13375 | int breaks_to_delete = 0; | |
13376 | ||
46c6471b PA |
13377 | /* Delete all breakpoints if no argument. Do not delete |
13378 | internal breakpoints, these have to be deleted with an | |
13379 | explicit breakpoint number argument. */ | |
c5aa993b | 13380 | ALL_BREAKPOINTS (b) |
46c6471b | 13381 | if (user_breakpoint_p (b)) |
973d738b DJ |
13382 | { |
13383 | breaks_to_delete = 1; | |
13384 | break; | |
13385 | } | |
c906108c SS |
13386 | |
13387 | /* Ask user only if there are some breakpoints to delete. */ | |
13388 | if (!from_tty | |
e2e0b3e5 | 13389 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13390 | { |
35df4500 | 13391 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13392 | if (user_breakpoint_p (b)) |
c5aa993b | 13393 | delete_breakpoint (b); |
c906108c SS |
13394 | } |
13395 | } | |
13396 | else | |
48649e1b TT |
13397 | map_breakpoint_numbers |
13398 | (arg, [&] (breakpoint *b) | |
13399 | { | |
13400 | iterate_over_related_breakpoints (b, delete_breakpoint); | |
13401 | }); | |
c906108c SS |
13402 | } |
13403 | ||
c2f4122d PA |
13404 | /* Return true if all locations of B bound to PSPACE are pending. If |
13405 | PSPACE is NULL, all locations of all program spaces are | |
13406 | considered. */ | |
13407 | ||
0d381245 | 13408 | static int |
c2f4122d | 13409 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13410 | { |
c2f4122d PA |
13411 | struct bp_location *loc; |
13412 | ||
13413 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13414 | if ((pspace == NULL | |
13415 | || loc->pspace == pspace) | |
13416 | && !loc->shlib_disabled | |
8645ff69 | 13417 | && !loc->pspace->executing_startup) |
0d381245 VP |
13418 | return 0; |
13419 | return 1; | |
fe3f5fa8 VP |
13420 | } |
13421 | ||
776592bf DE |
13422 | /* Subroutine of update_breakpoint_locations to simplify it. |
13423 | Return non-zero if multiple fns in list LOC have the same name. | |
13424 | Null names are ignored. */ | |
13425 | ||
13426 | static int | |
13427 | ambiguous_names_p (struct bp_location *loc) | |
13428 | { | |
13429 | struct bp_location *l; | |
13430 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13431 | (int (*) (const void *, |
13432 | const void *)) streq, | |
776592bf DE |
13433 | NULL, xcalloc, xfree); |
13434 | ||
13435 | for (l = loc; l != NULL; l = l->next) | |
13436 | { | |
13437 | const char **slot; | |
13438 | const char *name = l->function_name; | |
13439 | ||
13440 | /* Allow for some names to be NULL, ignore them. */ | |
13441 | if (name == NULL) | |
13442 | continue; | |
13443 | ||
13444 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13445 | INSERT); | |
4a64f543 MS |
13446 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13447 | returns NULL. */ | |
776592bf DE |
13448 | if (*slot != NULL) |
13449 | { | |
13450 | htab_delete (htab); | |
13451 | return 1; | |
13452 | } | |
13453 | *slot = name; | |
13454 | } | |
13455 | ||
13456 | htab_delete (htab); | |
13457 | return 0; | |
13458 | } | |
13459 | ||
0fb4aa4b PA |
13460 | /* When symbols change, it probably means the sources changed as well, |
13461 | and it might mean the static tracepoint markers are no longer at | |
13462 | the same address or line numbers they used to be at last we | |
13463 | checked. Losing your static tracepoints whenever you rebuild is | |
13464 | undesirable. This function tries to resync/rematch gdb static | |
13465 | tracepoints with the markers on the target, for static tracepoints | |
13466 | that have not been set by marker id. Static tracepoint that have | |
13467 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13468 | The heuristic is: | |
13469 | ||
13470 | 1) For a tracepoint set at a specific address, look for a marker at | |
13471 | the old PC. If one is found there, assume to be the same marker. | |
13472 | If the name / string id of the marker found is different from the | |
13473 | previous known name, assume that means the user renamed the marker | |
13474 | in the sources, and output a warning. | |
13475 | ||
13476 | 2) For a tracepoint set at a given line number, look for a marker | |
13477 | at the new address of the old line number. If one is found there, | |
13478 | assume to be the same marker. If the name / string id of the | |
13479 | marker found is different from the previous known name, assume that | |
13480 | means the user renamed the marker in the sources, and output a | |
13481 | warning. | |
13482 | ||
13483 | 3) If a marker is no longer found at the same address or line, it | |
13484 | may mean the marker no longer exists. But it may also just mean | |
13485 | the code changed a bit. Maybe the user added a few lines of code | |
13486 | that made the marker move up or down (in line number terms). Ask | |
13487 | the target for info about the marker with the string id as we knew | |
13488 | it. If found, update line number and address in the matching | |
13489 | static tracepoint. This will get confused if there's more than one | |
13490 | marker with the same ID (possible in UST, although unadvised | |
13491 | precisely because it confuses tools). */ | |
13492 | ||
13493 | static struct symtab_and_line | |
13494 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13495 | { | |
d9b3f62e | 13496 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13497 | struct static_tracepoint_marker marker; |
13498 | CORE_ADDR pc; | |
0fb4aa4b PA |
13499 | |
13500 | pc = sal.pc; | |
13501 | if (sal.line) | |
13502 | find_line_pc (sal.symtab, sal.line, &pc); | |
13503 | ||
13504 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13505 | { | |
d9b3f62e | 13506 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13507 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13508 | b->number, | |
d9b3f62e | 13509 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13510 | |
d9b3f62e PA |
13511 | xfree (tp->static_trace_marker_id); |
13512 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13513 | release_static_tracepoint_marker (&marker); |
13514 | ||
13515 | return sal; | |
13516 | } | |
13517 | ||
13518 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13519 | by string ID. */ | |
13520 | if (!sal.explicit_pc | |
13521 | && sal.line != 0 | |
13522 | && sal.symtab != NULL | |
d9b3f62e | 13523 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13524 | { |
13525 | VEC(static_tracepoint_marker_p) *markers; | |
13526 | ||
13527 | markers | |
d9b3f62e | 13528 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13529 | |
13530 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13531 | { | |
0fb4aa4b | 13532 | struct symbol *sym; |
80e1d417 | 13533 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13534 | struct ui_out *uiout = current_uiout; |
67994074 | 13535 | struct explicit_location explicit_loc; |
0fb4aa4b | 13536 | |
80e1d417 | 13537 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13538 | |
d9b3f62e | 13539 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13540 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13541 | |
13542 | warning (_("marker for static tracepoint %d (%s) not " | |
13543 | "found at previous line number"), | |
d9b3f62e | 13544 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13545 | |
51abb421 | 13546 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13547 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13548 | uiout->text ("Now in "); |
0fb4aa4b PA |
13549 | if (sym) |
13550 | { | |
112e8700 SM |
13551 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); |
13552 | uiout->text (" at "); | |
0fb4aa4b | 13553 | } |
112e8700 | 13554 | uiout->field_string ("file", |
05cba821 | 13555 | symtab_to_filename_for_display (sal2.symtab)); |
112e8700 | 13556 | uiout->text (":"); |
0fb4aa4b | 13557 | |
112e8700 | 13558 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13559 | { |
0b0865da | 13560 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13561 | |
112e8700 | 13562 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13563 | } |
13564 | ||
112e8700 SM |
13565 | uiout->field_int ("line", sal2.line); |
13566 | uiout->text ("\n"); | |
0fb4aa4b | 13567 | |
80e1d417 | 13568 | b->loc->line_number = sal2.line; |
2f202fde | 13569 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13570 | |
d28cd78a | 13571 | b->location.reset (NULL); |
67994074 KS |
13572 | initialize_explicit_location (&explicit_loc); |
13573 | explicit_loc.source_filename | |
00e52e53 | 13574 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13575 | explicit_loc.line_offset.offset = b->loc->line_number; |
13576 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13577 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13578 | |
13579 | /* Might be nice to check if function changed, and warn if | |
13580 | so. */ | |
13581 | ||
80e1d417 | 13582 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
13583 | } |
13584 | } | |
13585 | return sal; | |
13586 | } | |
13587 | ||
8d3788bd VP |
13588 | /* Returns 1 iff locations A and B are sufficiently same that |
13589 | we don't need to report breakpoint as changed. */ | |
13590 | ||
13591 | static int | |
13592 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13593 | { | |
13594 | while (a && b) | |
13595 | { | |
13596 | if (a->address != b->address) | |
13597 | return 0; | |
13598 | ||
13599 | if (a->shlib_disabled != b->shlib_disabled) | |
13600 | return 0; | |
13601 | ||
13602 | if (a->enabled != b->enabled) | |
13603 | return 0; | |
13604 | ||
13605 | a = a->next; | |
13606 | b = b->next; | |
13607 | } | |
13608 | ||
13609 | if ((a == NULL) != (b == NULL)) | |
13610 | return 0; | |
13611 | ||
13612 | return 1; | |
13613 | } | |
13614 | ||
c2f4122d PA |
13615 | /* Split all locations of B that are bound to PSPACE out of B's |
13616 | location list to a separate list and return that list's head. If | |
13617 | PSPACE is NULL, hoist out all locations of B. */ | |
13618 | ||
13619 | static struct bp_location * | |
13620 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13621 | { | |
13622 | struct bp_location head; | |
13623 | struct bp_location *i = b->loc; | |
13624 | struct bp_location **i_link = &b->loc; | |
13625 | struct bp_location *hoisted = &head; | |
13626 | ||
13627 | if (pspace == NULL) | |
13628 | { | |
13629 | i = b->loc; | |
13630 | b->loc = NULL; | |
13631 | return i; | |
13632 | } | |
13633 | ||
13634 | head.next = NULL; | |
13635 | ||
13636 | while (i != NULL) | |
13637 | { | |
13638 | if (i->pspace == pspace) | |
13639 | { | |
13640 | *i_link = i->next; | |
13641 | i->next = NULL; | |
13642 | hoisted->next = i; | |
13643 | hoisted = i; | |
13644 | } | |
13645 | else | |
13646 | i_link = &i->next; | |
13647 | i = *i_link; | |
13648 | } | |
13649 | ||
13650 | return head.next; | |
13651 | } | |
13652 | ||
13653 | /* Create new breakpoint locations for B (a hardware or software | |
13654 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13655 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13656 | FILTER_PSPACE. Locations of other program spaces are left | |
13657 | untouched. */ | |
f1310107 | 13658 | |
0e30163f | 13659 | void |
0d381245 | 13660 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13661 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13662 | gdb::array_view<const symtab_and_line> sals, |
13663 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 13664 | { |
c2f4122d | 13665 | struct bp_location *existing_locations; |
0d381245 | 13666 | |
6c5b2ebe | 13667 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13668 | { |
13669 | /* Ranged breakpoints have only one start location and one end | |
13670 | location. */ | |
13671 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13672 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13673 | "multiple locations found\n"), | |
13674 | b->number); | |
13675 | return; | |
13676 | } | |
f1310107 | 13677 | |
4a64f543 MS |
13678 | /* If there's no new locations, and all existing locations are |
13679 | pending, don't do anything. This optimizes the common case where | |
13680 | all locations are in the same shared library, that was unloaded. | |
13681 | We'd like to retain the location, so that when the library is | |
13682 | loaded again, we don't loose the enabled/disabled status of the | |
13683 | individual locations. */ | |
6c5b2ebe | 13684 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13685 | return; |
13686 | ||
c2f4122d | 13687 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13688 | |
6c5b2ebe | 13689 | for (const auto &sal : sals) |
fe3f5fa8 | 13690 | { |
f8eba3c6 TT |
13691 | struct bp_location *new_loc; |
13692 | ||
6c5b2ebe | 13693 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13694 | |
6c5b2ebe | 13695 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13696 | |
0d381245 VP |
13697 | /* Reparse conditions, they might contain references to the |
13698 | old symtab. */ | |
13699 | if (b->cond_string != NULL) | |
13700 | { | |
bbc13ae3 | 13701 | const char *s; |
fe3f5fa8 | 13702 | |
0d381245 | 13703 | s = b->cond_string; |
492d29ea | 13704 | TRY |
0d381245 | 13705 | { |
6c5b2ebe PA |
13706 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13707 | block_for_pc (sal.pc), | |
0d381245 VP |
13708 | 0); |
13709 | } | |
492d29ea | 13710 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 13711 | { |
3e43a32a MS |
13712 | warning (_("failed to reevaluate condition " |
13713 | "for breakpoint %d: %s"), | |
0d381245 VP |
13714 | b->number, e.message); |
13715 | new_loc->enabled = 0; | |
13716 | } | |
492d29ea | 13717 | END_CATCH |
0d381245 | 13718 | } |
fe3f5fa8 | 13719 | |
6c5b2ebe | 13720 | if (!sals_end.empty ()) |
f1310107 | 13721 | { |
6c5b2ebe | 13722 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13723 | |
6c5b2ebe | 13724 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13725 | } |
0d381245 | 13726 | } |
fe3f5fa8 | 13727 | |
4a64f543 MS |
13728 | /* If possible, carry over 'disable' status from existing |
13729 | breakpoints. */ | |
0d381245 VP |
13730 | { |
13731 | struct bp_location *e = existing_locations; | |
776592bf DE |
13732 | /* If there are multiple breakpoints with the same function name, |
13733 | e.g. for inline functions, comparing function names won't work. | |
13734 | Instead compare pc addresses; this is just a heuristic as things | |
13735 | may have moved, but in practice it gives the correct answer | |
13736 | often enough until a better solution is found. */ | |
13737 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13738 | ||
0d381245 VP |
13739 | for (; e; e = e->next) |
13740 | { | |
13741 | if (!e->enabled && e->function_name) | |
13742 | { | |
13743 | struct bp_location *l = b->loc; | |
776592bf DE |
13744 | if (have_ambiguous_names) |
13745 | { | |
13746 | for (; l; l = l->next) | |
f1310107 | 13747 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13748 | { |
13749 | l->enabled = 0; | |
13750 | break; | |
13751 | } | |
13752 | } | |
13753 | else | |
13754 | { | |
13755 | for (; l; l = l->next) | |
13756 | if (l->function_name | |
13757 | && strcmp (e->function_name, l->function_name) == 0) | |
13758 | { | |
13759 | l->enabled = 0; | |
13760 | break; | |
13761 | } | |
13762 | } | |
0d381245 VP |
13763 | } |
13764 | } | |
13765 | } | |
fe3f5fa8 | 13766 | |
8d3788bd VP |
13767 | if (!locations_are_equal (existing_locations, b->loc)) |
13768 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
13769 | } |
13770 | ||
f00aae0f | 13771 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13772 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13773 | ||
6c5b2ebe | 13774 | static std::vector<symtab_and_line> |
f00aae0f | 13775 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13776 | struct program_space *search_pspace, int *found) |
ef23e705 | 13777 | { |
492d29ea | 13778 | struct gdb_exception exception = exception_none; |
ef23e705 | 13779 | |
983af33b | 13780 | gdb_assert (b->ops != NULL); |
ef23e705 | 13781 | |
6c5b2ebe PA |
13782 | std::vector<symtab_and_line> sals; |
13783 | ||
492d29ea | 13784 | TRY |
ef23e705 | 13785 | { |
6c5b2ebe | 13786 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13787 | } |
492d29ea | 13788 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
13789 | { |
13790 | int not_found_and_ok = 0; | |
492d29ea PA |
13791 | |
13792 | exception = e; | |
13793 | ||
ef23e705 TJB |
13794 | /* For pending breakpoints, it's expected that parsing will |
13795 | fail until the right shared library is loaded. User has | |
13796 | already told to create pending breakpoints and don't need | |
13797 | extra messages. If breakpoint is in bp_shlib_disabled | |
13798 | state, then user already saw the message about that | |
13799 | breakpoint being disabled, and don't want to see more | |
13800 | errors. */ | |
58438ac1 | 13801 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13802 | && (b->condition_not_parsed |
13803 | || (b->loc != NULL | |
13804 | && search_pspace != NULL | |
13805 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13806 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13807 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13808 | || b->enable_state == bp_disabled)) |
13809 | not_found_and_ok = 1; | |
13810 | ||
13811 | if (!not_found_and_ok) | |
13812 | { | |
13813 | /* We surely don't want to warn about the same breakpoint | |
13814 | 10 times. One solution, implemented here, is disable | |
13815 | the breakpoint on error. Another solution would be to | |
13816 | have separate 'warning emitted' flag. Since this | |
13817 | happens only when a binary has changed, I don't know | |
13818 | which approach is better. */ | |
13819 | b->enable_state = bp_disabled; | |
13820 | throw_exception (e); | |
13821 | } | |
13822 | } | |
492d29ea | 13823 | END_CATCH |
ef23e705 | 13824 | |
492d29ea | 13825 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13826 | { |
6c5b2ebe PA |
13827 | for (auto &sal : sals) |
13828 | resolve_sal_pc (&sal); | |
f00aae0f | 13829 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13830 | { |
ed1d1739 KS |
13831 | char *cond_string, *extra_string; |
13832 | int thread, task; | |
ef23e705 | 13833 | |
6c5b2ebe | 13834 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
13835 | &cond_string, &thread, &task, |
13836 | &extra_string); | |
f00aae0f | 13837 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
13838 | if (cond_string) |
13839 | b->cond_string = cond_string; | |
13840 | b->thread = thread; | |
13841 | b->task = task; | |
e7e0cddf | 13842 | if (extra_string) |
f00aae0f KS |
13843 | { |
13844 | xfree (b->extra_string); | |
13845 | b->extra_string = extra_string; | |
13846 | } | |
ef23e705 TJB |
13847 | b->condition_not_parsed = 0; |
13848 | } | |
13849 | ||
983af33b | 13850 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 13851 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 13852 | |
58438ac1 TT |
13853 | *found = 1; |
13854 | } | |
13855 | else | |
13856 | *found = 0; | |
ef23e705 TJB |
13857 | |
13858 | return sals; | |
13859 | } | |
13860 | ||
348d480f PA |
13861 | /* The default re_set method, for typical hardware or software |
13862 | breakpoints. Reevaluate the breakpoint and recreate its | |
13863 | locations. */ | |
13864 | ||
13865 | static void | |
28010a5d | 13866 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 13867 | { |
c2f4122d | 13868 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 13869 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 13870 | |
6c5b2ebe PA |
13871 | int found; |
13872 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
13873 | filter_pspace, &found); | |
ef23e705 | 13874 | if (found) |
6c5b2ebe | 13875 | expanded = std::move (sals); |
ef23e705 | 13876 | |
f00aae0f | 13877 | if (b->location_range_end != NULL) |
f1310107 | 13878 | { |
6c5b2ebe PA |
13879 | std::vector<symtab_and_line> sals_end |
13880 | = location_to_sals (b, b->location_range_end.get (), | |
13881 | filter_pspace, &found); | |
f1310107 | 13882 | if (found) |
6c5b2ebe | 13883 | expanded_end = std::move (sals_end); |
f1310107 TJB |
13884 | } |
13885 | ||
c2f4122d | 13886 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
13887 | } |
13888 | ||
983af33b SDJ |
13889 | /* Default method for creating SALs from an address string. It basically |
13890 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13891 | ||
13892 | static void | |
f00aae0f KS |
13893 | create_sals_from_location_default (const struct event_location *location, |
13894 | struct linespec_result *canonical, | |
13895 | enum bptype type_wanted) | |
983af33b | 13896 | { |
f00aae0f | 13897 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
13898 | } |
13899 | ||
13900 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13901 | function for the `create_breakpoints_sal' method of | |
13902 | breakpoint_ops. */ | |
13903 | ||
13904 | static void | |
13905 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13906 | struct linespec_result *canonical, | |
e1e01040 PA |
13907 | gdb::unique_xmalloc_ptr<char> cond_string, |
13908 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13909 | enum bptype type_wanted, |
13910 | enum bpdisp disposition, | |
13911 | int thread, | |
13912 | int task, int ignore_count, | |
13913 | const struct breakpoint_ops *ops, | |
13914 | int from_tty, int enabled, | |
44f238bb | 13915 | int internal, unsigned flags) |
983af33b | 13916 | { |
e1e01040 PA |
13917 | create_breakpoints_sal (gdbarch, canonical, |
13918 | std::move (cond_string), | |
13919 | std::move (extra_string), | |
983af33b SDJ |
13920 | type_wanted, disposition, |
13921 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13922 | enabled, internal, flags); |
983af33b SDJ |
13923 | } |
13924 | ||
13925 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 13926 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 13927 | |
6c5b2ebe | 13928 | static std::vector<symtab_and_line> |
f00aae0f KS |
13929 | decode_location_default (struct breakpoint *b, |
13930 | const struct event_location *location, | |
6c5b2ebe | 13931 | struct program_space *search_pspace) |
983af33b SDJ |
13932 | { |
13933 | struct linespec_result canonical; | |
13934 | ||
c2f4122d | 13935 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
13936 | (struct symtab *) NULL, 0, |
13937 | &canonical, multiple_symbols_all, | |
13938 | b->filter); | |
13939 | ||
13940 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 13941 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 13942 | |
6c5b2ebe | 13943 | if (!canonical.lsals.empty ()) |
983af33b | 13944 | { |
6c5b2ebe PA |
13945 | const linespec_sals &lsal = canonical.lsals[0]; |
13946 | return std::move (lsal.sals); | |
983af33b | 13947 | } |
6c5b2ebe | 13948 | return {}; |
983af33b SDJ |
13949 | } |
13950 | ||
bf469271 | 13951 | /* Reset a breakpoint. */ |
c906108c | 13952 | |
bf469271 PA |
13953 | static void |
13954 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 13955 | { |
fdf44873 TT |
13956 | input_radix = b->input_radix; |
13957 | set_language (b->language); | |
c906108c | 13958 | |
348d480f | 13959 | b->ops->re_set (b); |
c906108c SS |
13960 | } |
13961 | ||
c2f4122d PA |
13962 | /* Re-set breakpoint locations for the current program space. |
13963 | Locations bound to other program spaces are left untouched. */ | |
13964 | ||
c906108c | 13965 | void |
69de3c6a | 13966 | breakpoint_re_set (void) |
c906108c | 13967 | { |
35df4500 | 13968 | struct breakpoint *b, *b_tmp; |
2a7f3dff | 13969 | |
c5aa993b | 13970 | { |
fdf44873 TT |
13971 | scoped_restore_current_language save_language; |
13972 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 13973 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 13974 | |
5ed8105e PA |
13975 | /* Note: we must not try to insert locations until after all |
13976 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
13977 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
13978 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 13979 | |
5ed8105e PA |
13980 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
13981 | { | |
bf469271 PA |
13982 | TRY |
13983 | { | |
13984 | breakpoint_re_set_one (b); | |
13985 | } | |
13986 | CATCH (ex, RETURN_MASK_ALL) | |
13987 | { | |
13988 | exception_fprintf (gdb_stderr, ex, | |
13989 | "Error in re-setting breakpoint %d: ", | |
13990 | b->number); | |
13991 | } | |
13992 | END_CATCH | |
5ed8105e | 13993 | } |
5ed8105e PA |
13994 | |
13995 | jit_breakpoint_re_set (); | |
13996 | } | |
6c95b8df | 13997 | |
af02033e PP |
13998 | create_overlay_event_breakpoint (); |
13999 | create_longjmp_master_breakpoint (); | |
14000 | create_std_terminate_master_breakpoint (); | |
186c406b | 14001 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14002 | |
14003 | /* Now we can insert. */ | |
14004 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14005 | } |
14006 | \f | |
c906108c SS |
14007 | /* Reset the thread number of this breakpoint: |
14008 | ||
14009 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14010 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14011 | void |
fba45db2 | 14012 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14013 | { |
14014 | if (b->thread != -1) | |
14015 | { | |
39f77062 | 14016 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14017 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14018 | |
14019 | /* We're being called after following a fork. The new fork is | |
14020 | selected as current, and unless this was a vfork will have a | |
14021 | different program space from the original thread. Reset that | |
14022 | as well. */ | |
14023 | b->loc->pspace = current_program_space; | |
c906108c SS |
14024 | } |
14025 | } | |
14026 | ||
03ac34d5 MS |
14027 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14028 | If from_tty is nonzero, it prints a message to that effect, | |
14029 | which ends with a period (no newline). */ | |
14030 | ||
c906108c | 14031 | void |
fba45db2 | 14032 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14033 | { |
52f0bd74 | 14034 | struct breakpoint *b; |
c906108c SS |
14035 | |
14036 | if (count < 0) | |
14037 | count = 0; | |
14038 | ||
14039 | ALL_BREAKPOINTS (b) | |
14040 | if (b->number == bptnum) | |
c5aa993b | 14041 | { |
d77f58be SS |
14042 | if (is_tracepoint (b)) |
14043 | { | |
14044 | if (from_tty && count != 0) | |
14045 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14046 | bptnum); | |
14047 | return; | |
14048 | } | |
14049 | ||
c5aa993b | 14050 | b->ignore_count = count; |
221ea385 KS |
14051 | if (from_tty) |
14052 | { | |
14053 | if (count == 0) | |
3e43a32a MS |
14054 | printf_filtered (_("Will stop next time " |
14055 | "breakpoint %d is reached."), | |
221ea385 KS |
14056 | bptnum); |
14057 | else if (count == 1) | |
a3f17187 | 14058 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14059 | bptnum); |
14060 | else | |
3e43a32a MS |
14061 | printf_filtered (_("Will ignore next %d " |
14062 | "crossings of breakpoint %d."), | |
221ea385 KS |
14063 | count, bptnum); |
14064 | } | |
8d3788bd | 14065 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14066 | return; |
14067 | } | |
c906108c | 14068 | |
8a3fe4f8 | 14069 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14070 | } |
14071 | ||
c906108c SS |
14072 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14073 | ||
14074 | static void | |
0b39b52e | 14075 | ignore_command (const char *args, int from_tty) |
c906108c | 14076 | { |
0b39b52e | 14077 | const char *p = args; |
52f0bd74 | 14078 | int num; |
c906108c SS |
14079 | |
14080 | if (p == 0) | |
e2e0b3e5 | 14081 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14082 | |
c906108c | 14083 | num = get_number (&p); |
5c44784c | 14084 | if (num == 0) |
8a3fe4f8 | 14085 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14086 | if (*p == 0) |
8a3fe4f8 | 14087 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14088 | |
14089 | set_ignore_count (num, | |
14090 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14091 | from_tty); | |
221ea385 KS |
14092 | if (from_tty) |
14093 | printf_filtered ("\n"); | |
c906108c SS |
14094 | } |
14095 | \f | |
d0fe4701 XR |
14096 | |
14097 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
14098 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
14099 | |
14100 | static void | |
d0fe4701 XR |
14101 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
14102 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 14103 | { |
d0fe4701 XR |
14104 | if (bp_num_range.first == 0) |
14105 | { | |
14106 | warning (_("bad breakpoint number at or near '%d'"), | |
14107 | bp_num_range.first); | |
14108 | } | |
14109 | else | |
c906108c | 14110 | { |
d0fe4701 | 14111 | struct breakpoint *b, *tmp; |
197f0a60 | 14112 | |
d0fe4701 | 14113 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 14114 | { |
d0fe4701 XR |
14115 | bool match = false; |
14116 | ||
5c44784c | 14117 | ALL_BREAKPOINTS_SAFE (b, tmp) |
d0fe4701 | 14118 | if (b->number == i) |
5c44784c | 14119 | { |
bfd28288 | 14120 | match = true; |
48649e1b | 14121 | function (b); |
11cf8741 | 14122 | break; |
5c44784c | 14123 | } |
bfd28288 | 14124 | if (!match) |
d0fe4701 | 14125 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
c5aa993b | 14126 | } |
c906108c SS |
14127 | } |
14128 | } | |
14129 | ||
d0fe4701 XR |
14130 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
14131 | ARGS. */ | |
14132 | ||
14133 | static void | |
14134 | map_breakpoint_numbers (const char *args, | |
14135 | gdb::function_view<void (breakpoint *)> function) | |
14136 | { | |
14137 | if (args == NULL || *args == '\0') | |
14138 | error_no_arg (_("one or more breakpoint numbers")); | |
14139 | ||
14140 | number_or_range_parser parser (args); | |
14141 | ||
14142 | while (!parser.finished ()) | |
14143 | { | |
14144 | int num = parser.get_number (); | |
14145 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
14146 | } | |
14147 | } | |
14148 | ||
14149 | /* Return the breakpoint location structure corresponding to the | |
14150 | BP_NUM and LOC_NUM values. */ | |
14151 | ||
0d381245 | 14152 | static struct bp_location * |
d0fe4701 | 14153 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 14154 | { |
0d381245 | 14155 | struct breakpoint *b; |
0d381245 VP |
14156 | |
14157 | ALL_BREAKPOINTS (b) | |
14158 | if (b->number == bp_num) | |
14159 | { | |
14160 | break; | |
14161 | } | |
14162 | ||
14163 | if (!b || b->number != bp_num) | |
d0fe4701 | 14164 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 14165 | |
0d381245 | 14166 | if (loc_num == 0) |
d0fe4701 | 14167 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 14168 | |
d0fe4701 XR |
14169 | int n = 0; |
14170 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
14171 | if (++n == loc_num) | |
14172 | return loc; | |
14173 | ||
14174 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
14175 | } |
14176 | ||
95e95a6d PA |
14177 | /* Modes of operation for extract_bp_num. */ |
14178 | enum class extract_bp_kind | |
14179 | { | |
14180 | /* Extracting a breakpoint number. */ | |
14181 | bp, | |
14182 | ||
14183 | /* Extracting a location number. */ | |
14184 | loc, | |
14185 | }; | |
14186 | ||
14187 | /* Extract a breakpoint or location number (as determined by KIND) | |
14188 | from the string starting at START. TRAILER is a character which | |
14189 | can be found after the number. If you don't want a trailer, use | |
14190 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
14191 | string. This always returns a positive integer. */ | |
14192 | ||
14193 | static int | |
14194 | extract_bp_num (extract_bp_kind kind, const char *start, | |
14195 | int trailer, const char **end_out = NULL) | |
14196 | { | |
14197 | const char *end = start; | |
14198 | int num = get_number_trailer (&end, trailer); | |
14199 | if (num < 0) | |
14200 | error (kind == extract_bp_kind::bp | |
14201 | ? _("Negative breakpoint number '%.*s'") | |
14202 | : _("Negative breakpoint location number '%.*s'"), | |
14203 | int (end - start), start); | |
14204 | if (num == 0) | |
14205 | error (kind == extract_bp_kind::bp | |
14206 | ? _("Bad breakpoint number '%.*s'") | |
14207 | : _("Bad breakpoint location number '%.*s'"), | |
14208 | int (end - start), start); | |
14209 | ||
14210 | if (end_out != NULL) | |
14211 | *end_out = end; | |
14212 | return num; | |
14213 | } | |
14214 | ||
14215 | /* Extract a breakpoint or location range (as determined by KIND) in | |
14216 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
14217 | representing the (inclusive) range. The returned pair's elements | |
14218 | are always positive integers. */ | |
14219 | ||
14220 | static std::pair<int, int> | |
14221 | extract_bp_or_bp_range (extract_bp_kind kind, | |
14222 | const std::string &arg, | |
14223 | std::string::size_type arg_offset) | |
14224 | { | |
14225 | std::pair<int, int> range; | |
14226 | const char *bp_loc = &arg[arg_offset]; | |
14227 | std::string::size_type dash = arg.find ('-', arg_offset); | |
14228 | if (dash != std::string::npos) | |
14229 | { | |
14230 | /* bp_loc is a range (x-z). */ | |
14231 | if (arg.length () == dash + 1) | |
14232 | error (kind == extract_bp_kind::bp | |
14233 | ? _("Bad breakpoint number at or near: '%s'") | |
14234 | : _("Bad breakpoint location number at or near: '%s'"), | |
14235 | bp_loc); | |
14236 | ||
14237 | const char *end; | |
14238 | const char *start_first = bp_loc; | |
14239 | const char *start_second = &arg[dash + 1]; | |
14240 | range.first = extract_bp_num (kind, start_first, '-'); | |
14241 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
14242 | ||
14243 | if (range.first > range.second) | |
14244 | error (kind == extract_bp_kind::bp | |
14245 | ? _("Inverted breakpoint range at '%.*s'") | |
14246 | : _("Inverted breakpoint location range at '%.*s'"), | |
14247 | int (end - start_first), start_first); | |
14248 | } | |
14249 | else | |
14250 | { | |
14251 | /* bp_loc is a single value. */ | |
14252 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
14253 | range.second = range.first; | |
14254 | } | |
14255 | return range; | |
14256 | } | |
14257 | ||
d0fe4701 XR |
14258 | /* Extract the breakpoint/location range specified by ARG. Returns |
14259 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
14260 | BP_LOC_RANGE. | |
14261 | ||
14262 | ARG may be in any of the following forms: | |
14263 | ||
14264 | x where 'x' is a breakpoint number. | |
14265 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
14266 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
14267 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
14268 | location number range. | |
14269 | */ | |
14270 | ||
cc638e86 | 14271 | static void |
d0fe4701 XR |
14272 | extract_bp_number_and_location (const std::string &arg, |
14273 | std::pair<int, int> &bp_num_range, | |
14274 | std::pair<int, int> &bp_loc_range) | |
14275 | { | |
14276 | std::string::size_type dot = arg.find ('.'); | |
14277 | ||
14278 | if (dot != std::string::npos) | |
14279 | { | |
14280 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
14281 | ||
14282 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 14283 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 14284 | |
95e95a6d PA |
14285 | bp_num_range.first |
14286 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
14287 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 14288 | |
95e95a6d PA |
14289 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
14290 | arg, dot + 1); | |
d0fe4701 XR |
14291 | } |
14292 | else | |
14293 | { | |
14294 | /* Handle x and x-y cases. */ | |
d0fe4701 | 14295 | |
95e95a6d | 14296 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
14297 | bp_loc_range.first = 0; |
14298 | bp_loc_range.second = 0; | |
14299 | } | |
d0fe4701 XR |
14300 | } |
14301 | ||
14302 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
14303 | specifies whether to enable or disable. */ | |
14304 | ||
14305 | static void | |
14306 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
14307 | { | |
14308 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
14309 | if (loc != NULL) | |
14310 | { | |
14311 | if (loc->enabled != enable) | |
14312 | { | |
14313 | loc->enabled = enable; | |
14314 | mark_breakpoint_location_modified (loc); | |
14315 | } | |
14316 | if (target_supports_enable_disable_tracepoint () | |
14317 | && current_trace_status ()->running && loc->owner | |
14318 | && is_tracepoint (loc->owner)) | |
14319 | target_disable_tracepoint (loc); | |
14320 | } | |
14321 | update_global_location_list (UGLL_DONT_INSERT); | |
14322 | } | |
14323 | ||
14324 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
14325 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
14326 | (inclusive) range of location numbers of that breakpoint to | |
14327 | enable/disable. ENABLE specifies whether to enable or disable the | |
14328 | location. */ | |
14329 | ||
14330 | static void | |
14331 | enable_disable_breakpoint_location_range (int bp_num, | |
14332 | std::pair<int, int> &bp_loc_range, | |
14333 | bool enable) | |
14334 | { | |
14335 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
14336 | enable_disable_bp_num_loc (bp_num, i, enable); | |
14337 | } | |
0d381245 | 14338 | |
1900040c MS |
14339 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14340 | If from_tty is nonzero, it prints a message to that effect, | |
14341 | which ends with a period (no newline). */ | |
14342 | ||
c906108c | 14343 | void |
fba45db2 | 14344 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14345 | { |
14346 | /* Never disable a watchpoint scope breakpoint; we want to | |
14347 | hit them when we leave scope so we can delete both the | |
14348 | watchpoint and its scope breakpoint at that time. */ | |
14349 | if (bpt->type == bp_watchpoint_scope) | |
14350 | return; | |
14351 | ||
b5de0fa7 | 14352 | bpt->enable_state = bp_disabled; |
c906108c | 14353 | |
b775012e LM |
14354 | /* Mark breakpoint locations modified. */ |
14355 | mark_breakpoint_modified (bpt); | |
14356 | ||
d248b706 KY |
14357 | if (target_supports_enable_disable_tracepoint () |
14358 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14359 | { | |
14360 | struct bp_location *location; | |
14361 | ||
14362 | for (location = bpt->loc; location; location = location->next) | |
14363 | target_disable_tracepoint (location); | |
14364 | } | |
14365 | ||
44702360 | 14366 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14367 | |
8d3788bd | 14368 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14369 | } |
14370 | ||
d0fe4701 XR |
14371 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
14372 | specified in ARGS. ARGS may be in any of the formats handled by | |
14373 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
14374 | or disable the breakpoints/locations. */ | |
14375 | ||
c906108c | 14376 | static void |
d0fe4701 | 14377 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 14378 | { |
c906108c | 14379 | if (args == 0) |
46c6471b PA |
14380 | { |
14381 | struct breakpoint *bpt; | |
14382 | ||
14383 | ALL_BREAKPOINTS (bpt) | |
14384 | if (user_breakpoint_p (bpt)) | |
d0fe4701 XR |
14385 | { |
14386 | if (enable) | |
14387 | enable_breakpoint (bpt); | |
14388 | else | |
14389 | disable_breakpoint (bpt); | |
14390 | } | |
46c6471b | 14391 | } |
9eaabc75 | 14392 | else |
0d381245 | 14393 | { |
cb791d59 | 14394 | std::string num = extract_arg (&args); |
9eaabc75 | 14395 | |
cb791d59 | 14396 | while (!num.empty ()) |
d248b706 | 14397 | { |
d0fe4701 | 14398 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 14399 | |
cc638e86 PA |
14400 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
14401 | ||
14402 | if (bp_loc_range.first == bp_loc_range.second | |
14403 | && bp_loc_range.first == 0) | |
d0fe4701 | 14404 | { |
cc638e86 PA |
14405 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
14406 | map_breakpoint_number_range (bp_num_range, | |
14407 | enable | |
14408 | ? enable_breakpoint | |
14409 | : disable_breakpoint); | |
14410 | } | |
14411 | else | |
14412 | { | |
14413 | /* Handle breakpoint ids with formats 'x.y' or | |
14414 | 'x.y-z'. */ | |
14415 | enable_disable_breakpoint_location_range | |
14416 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 14417 | } |
9eaabc75 | 14418 | num = extract_arg (&args); |
d248b706 | 14419 | } |
0d381245 | 14420 | } |
c906108c SS |
14421 | } |
14422 | ||
d0fe4701 XR |
14423 | /* The disable command disables the specified breakpoints/locations |
14424 | (or all defined breakpoints) so they're no longer effective in | |
14425 | stopping the inferior. ARGS may be in any of the forms defined in | |
14426 | extract_bp_number_and_location. */ | |
14427 | ||
14428 | static void | |
14429 | disable_command (const char *args, int from_tty) | |
14430 | { | |
14431 | enable_disable_command (args, from_tty, false); | |
14432 | } | |
14433 | ||
c906108c | 14434 | static void |
816338b5 SS |
14435 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14436 | int count) | |
c906108c | 14437 | { |
afe38095 | 14438 | int target_resources_ok; |
c906108c SS |
14439 | |
14440 | if (bpt->type == bp_hardware_breakpoint) | |
14441 | { | |
14442 | int i; | |
c5aa993b | 14443 | i = hw_breakpoint_used_count (); |
53a5351d | 14444 | target_resources_ok = |
d92524f1 | 14445 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14446 | i + 1, 0); |
c906108c | 14447 | if (target_resources_ok == 0) |
8a3fe4f8 | 14448 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14449 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14450 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14451 | } |
14452 | ||
cc60f2e3 | 14453 | if (is_watchpoint (bpt)) |
c906108c | 14454 | { |
d07205c2 | 14455 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14456 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14457 | |
492d29ea | 14458 | TRY |
c906108c | 14459 | { |
3a5c3e22 PA |
14460 | struct watchpoint *w = (struct watchpoint *) bpt; |
14461 | ||
1e718ff1 TJB |
14462 | orig_enable_state = bpt->enable_state; |
14463 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14464 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14465 | } |
492d29ea | 14466 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14467 | { |
1e718ff1 | 14468 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14469 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14470 | bpt->number); | |
14471 | return; | |
c5aa993b | 14472 | } |
492d29ea | 14473 | END_CATCH |
c906108c | 14474 | } |
0101ce28 | 14475 | |
b775012e LM |
14476 | bpt->enable_state = bp_enabled; |
14477 | ||
14478 | /* Mark breakpoint locations modified. */ | |
14479 | mark_breakpoint_modified (bpt); | |
14480 | ||
d248b706 KY |
14481 | if (target_supports_enable_disable_tracepoint () |
14482 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14483 | { | |
14484 | struct bp_location *location; | |
14485 | ||
14486 | for (location = bpt->loc; location; location = location->next) | |
14487 | target_enable_tracepoint (location); | |
14488 | } | |
14489 | ||
b4c291bb | 14490 | bpt->disposition = disposition; |
816338b5 | 14491 | bpt->enable_count = count; |
44702360 | 14492 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14493 | |
8d3788bd | 14494 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14495 | } |
14496 | ||
fe3f5fa8 | 14497 | |
c906108c | 14498 | void |
fba45db2 | 14499 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14500 | { |
816338b5 | 14501 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14502 | } |
14503 | ||
d0fe4701 XR |
14504 | /* The enable command enables the specified breakpoints/locations (or |
14505 | all defined breakpoints) so they once again become (or continue to | |
14506 | be) effective in stopping the inferior. ARGS may be in any of the | |
14507 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 14508 | |
c906108c | 14509 | static void |
981a3fb3 | 14510 | enable_command (const char *args, int from_tty) |
c906108c | 14511 | { |
d0fe4701 | 14512 | enable_disable_command (args, from_tty, true); |
c906108c SS |
14513 | } |
14514 | ||
c906108c | 14515 | static void |
4495129a | 14516 | enable_once_command (const char *args, int from_tty) |
c906108c | 14517 | { |
48649e1b TT |
14518 | map_breakpoint_numbers |
14519 | (args, [&] (breakpoint *b) | |
14520 | { | |
14521 | iterate_over_related_breakpoints | |
14522 | (b, [&] (breakpoint *bpt) | |
14523 | { | |
14524 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14525 | }); | |
14526 | }); | |
816338b5 SS |
14527 | } |
14528 | ||
14529 | static void | |
4495129a | 14530 | enable_count_command (const char *args, int from_tty) |
816338b5 | 14531 | { |
b9d61307 SM |
14532 | int count; |
14533 | ||
14534 | if (args == NULL) | |
14535 | error_no_arg (_("hit count")); | |
14536 | ||
14537 | count = get_number (&args); | |
816338b5 | 14538 | |
48649e1b TT |
14539 | map_breakpoint_numbers |
14540 | (args, [&] (breakpoint *b) | |
14541 | { | |
14542 | iterate_over_related_breakpoints | |
14543 | (b, [&] (breakpoint *bpt) | |
14544 | { | |
14545 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14546 | }); | |
14547 | }); | |
c906108c SS |
14548 | } |
14549 | ||
c906108c | 14550 | static void |
4495129a | 14551 | enable_delete_command (const char *args, int from_tty) |
c906108c | 14552 | { |
48649e1b TT |
14553 | map_breakpoint_numbers |
14554 | (args, [&] (breakpoint *b) | |
14555 | { | |
14556 | iterate_over_related_breakpoints | |
14557 | (b, [&] (breakpoint *bpt) | |
14558 | { | |
14559 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14560 | }); | |
14561 | }); | |
c906108c SS |
14562 | } |
14563 | \f | |
fa8d40ab | 14564 | static void |
981a3fb3 | 14565 | set_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14566 | { |
14567 | } | |
14568 | ||
14569 | static void | |
981a3fb3 | 14570 | show_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14571 | { |
14572 | } | |
14573 | ||
1f3b5d1b PP |
14574 | /* Invalidate last known value of any hardware watchpoint if |
14575 | the memory which that value represents has been written to by | |
14576 | GDB itself. */ | |
14577 | ||
14578 | static void | |
8de0566d YQ |
14579 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14580 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14581 | const bfd_byte *data) |
14582 | { | |
14583 | struct breakpoint *bp; | |
14584 | ||
14585 | ALL_BREAKPOINTS (bp) | |
14586 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14587 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14588 | { |
3a5c3e22 | 14589 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14590 | |
3a5c3e22 PA |
14591 | if (wp->val_valid && wp->val) |
14592 | { | |
14593 | struct bp_location *loc; | |
14594 | ||
14595 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14596 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14597 | && loc->address + loc->length > addr | |
14598 | && addr + len > loc->address) | |
14599 | { | |
14600 | value_free (wp->val); | |
14601 | wp->val = NULL; | |
14602 | wp->val_valid = 0; | |
14603 | } | |
14604 | } | |
1f3b5d1b PP |
14605 | } |
14606 | } | |
14607 | ||
8181d85f DJ |
14608 | /* Create and insert a breakpoint for software single step. */ |
14609 | ||
14610 | void | |
6c95b8df | 14611 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 14612 | const address_space *aspace, |
4a64f543 | 14613 | CORE_ADDR next_pc) |
8181d85f | 14614 | { |
7c16b83e PA |
14615 | struct thread_info *tp = inferior_thread (); |
14616 | struct symtab_and_line sal; | |
14617 | CORE_ADDR pc = next_pc; | |
8181d85f | 14618 | |
34b7e8a6 PA |
14619 | if (tp->control.single_step_breakpoints == NULL) |
14620 | { | |
14621 | tp->control.single_step_breakpoints | |
5d5658a1 | 14622 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14623 | } |
8181d85f | 14624 | |
7c16b83e PA |
14625 | sal = find_pc_line (pc, 0); |
14626 | sal.pc = pc; | |
14627 | sal.section = find_pc_overlay (pc); | |
14628 | sal.explicit_pc = 1; | |
34b7e8a6 | 14629 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14630 | |
7c16b83e | 14631 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14632 | } |
14633 | ||
93f9a11f YQ |
14634 | /* Insert single step breakpoints according to the current state. */ |
14635 | ||
14636 | int | |
14637 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14638 | { | |
f5ea389a | 14639 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14640 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14641 | |
f5ea389a | 14642 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14643 | |
a0ff9e1a | 14644 | if (!next_pcs.empty ()) |
93f9a11f | 14645 | { |
f5ea389a | 14646 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 14647 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 14648 | |
a0ff9e1a | 14649 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14650 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14651 | ||
93f9a11f YQ |
14652 | return 1; |
14653 | } | |
14654 | else | |
14655 | return 0; | |
14656 | } | |
14657 | ||
34b7e8a6 | 14658 | /* See breakpoint.h. */ |
f02253f1 HZ |
14659 | |
14660 | int | |
7c16b83e | 14661 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 14662 | const address_space *aspace, |
7c16b83e | 14663 | CORE_ADDR pc) |
1aafd4da | 14664 | { |
7c16b83e | 14665 | struct bp_location *loc; |
1aafd4da | 14666 | |
7c16b83e PA |
14667 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14668 | if (loc->inserted | |
14669 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14670 | return 1; | |
1aafd4da | 14671 | |
7c16b83e | 14672 | return 0; |
ef370185 JB |
14673 | } |
14674 | ||
14675 | /* Check whether a software single-step breakpoint is inserted at | |
14676 | PC. */ | |
14677 | ||
14678 | int | |
accd0bcd | 14679 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
14680 | CORE_ADDR pc) |
14681 | { | |
34b7e8a6 PA |
14682 | struct breakpoint *bpt; |
14683 | ||
14684 | ALL_BREAKPOINTS (bpt) | |
14685 | { | |
14686 | if (bpt->type == bp_single_step | |
14687 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14688 | return 1; | |
14689 | } | |
14690 | return 0; | |
1aafd4da UW |
14691 | } |
14692 | ||
1042e4c0 SS |
14693 | /* Tracepoint-specific operations. */ |
14694 | ||
14695 | /* Set tracepoint count to NUM. */ | |
14696 | static void | |
14697 | set_tracepoint_count (int num) | |
14698 | { | |
14699 | tracepoint_count = num; | |
4fa62494 | 14700 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14701 | } |
14702 | ||
70221824 | 14703 | static void |
0b39b52e | 14704 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 14705 | { |
55aa24fb | 14706 | struct breakpoint_ops *ops; |
55aa24fb | 14707 | |
ffc2605c TT |
14708 | event_location_up location = string_to_event_location (&arg, |
14709 | current_language); | |
5b56227b | 14710 | if (location != NULL |
ffc2605c | 14711 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
14712 | ops = &tracepoint_probe_breakpoint_ops; |
14713 | else | |
14714 | ops = &tracepoint_breakpoint_ops; | |
14715 | ||
558a9d82 | 14716 | create_breakpoint (get_current_arch (), |
ffc2605c | 14717 | location.get (), |
f00aae0f | 14718 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14719 | 0 /* tempflag */, |
14720 | bp_tracepoint /* type_wanted */, | |
14721 | 0 /* Ignore count */, | |
14722 | pending_break_support, | |
14723 | ops, | |
14724 | from_tty, | |
14725 | 1 /* enabled */, | |
14726 | 0 /* internal */, 0); | |
1042e4c0 SS |
14727 | } |
14728 | ||
70221824 | 14729 | static void |
0b39b52e | 14730 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 14731 | { |
ffc2605c TT |
14732 | event_location_up location = string_to_event_location (&arg, |
14733 | current_language); | |
558a9d82 | 14734 | create_breakpoint (get_current_arch (), |
ffc2605c | 14735 | location.get (), |
f00aae0f | 14736 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14737 | 0 /* tempflag */, |
14738 | bp_fast_tracepoint /* type_wanted */, | |
14739 | 0 /* Ignore count */, | |
14740 | pending_break_support, | |
14741 | &tracepoint_breakpoint_ops, | |
14742 | from_tty, | |
14743 | 1 /* enabled */, | |
14744 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14745 | } |
14746 | ||
14747 | /* strace command implementation. Creates a static tracepoint. */ | |
14748 | ||
70221824 | 14749 | static void |
0b39b52e | 14750 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 14751 | { |
983af33b | 14752 | struct breakpoint_ops *ops; |
ffc2605c | 14753 | event_location_up location; |
983af33b SDJ |
14754 | |
14755 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14756 | or with a normal static tracepoint. */ | |
61012eef | 14757 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14758 | { |
14759 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 14760 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
f00aae0f | 14761 | } |
983af33b | 14762 | else |
f00aae0f KS |
14763 | { |
14764 | ops = &tracepoint_breakpoint_ops; | |
14765 | location = string_to_event_location (&arg, current_language); | |
14766 | } | |
983af33b | 14767 | |
558a9d82 | 14768 | create_breakpoint (get_current_arch (), |
ffc2605c | 14769 | location.get (), |
f00aae0f | 14770 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14771 | 0 /* tempflag */, |
14772 | bp_static_tracepoint /* type_wanted */, | |
14773 | 0 /* Ignore count */, | |
14774 | pending_break_support, | |
14775 | ops, | |
14776 | from_tty, | |
14777 | 1 /* enabled */, | |
14778 | 0 /* internal */, 0); | |
7a697b8d SS |
14779 | } |
14780 | ||
409873ef SS |
14781 | /* Set up a fake reader function that gets command lines from a linked |
14782 | list that was acquired during tracepoint uploading. */ | |
14783 | ||
14784 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14785 | static int next_cmd; |
409873ef SS |
14786 | |
14787 | static char * | |
14788 | read_uploaded_action (void) | |
14789 | { | |
14790 | char *rslt; | |
14791 | ||
3149d8c1 | 14792 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 14793 | |
3149d8c1 | 14794 | next_cmd++; |
409873ef SS |
14795 | |
14796 | return rslt; | |
14797 | } | |
14798 | ||
00bf0b85 SS |
14799 | /* Given information about a tracepoint as recorded on a target (which |
14800 | can be either a live system or a trace file), attempt to create an | |
14801 | equivalent GDB tracepoint. This is not a reliable process, since | |
14802 | the target does not necessarily have all the information used when | |
14803 | the tracepoint was originally defined. */ | |
14804 | ||
d9b3f62e | 14805 | struct tracepoint * |
00bf0b85 | 14806 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14807 | { |
f2fc3015 TT |
14808 | const char *addr_str; |
14809 | char small_buf[100]; | |
d9b3f62e | 14810 | struct tracepoint *tp; |
fd9b8c24 | 14811 | |
409873ef SS |
14812 | if (utp->at_string) |
14813 | addr_str = utp->at_string; | |
14814 | else | |
14815 | { | |
14816 | /* In the absence of a source location, fall back to raw | |
14817 | address. Since there is no way to confirm that the address | |
14818 | means the same thing as when the trace was started, warn the | |
14819 | user. */ | |
3e43a32a MS |
14820 | warning (_("Uploaded tracepoint %d has no " |
14821 | "source location, using raw address"), | |
409873ef | 14822 | utp->number); |
8c042590 | 14823 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14824 | addr_str = small_buf; |
14825 | } | |
14826 | ||
14827 | /* There's not much we can do with a sequence of bytecodes. */ | |
14828 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14829 | warning (_("Uploaded tracepoint %d condition " |
14830 | "has no source form, ignoring it"), | |
409873ef | 14831 | utp->number); |
d5551862 | 14832 | |
ffc2605c TT |
14833 | event_location_up location = string_to_event_location (&addr_str, |
14834 | current_language); | |
8cdf0e15 | 14835 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14836 | location.get (), |
f00aae0f | 14837 | utp->cond_string, -1, addr_str, |
e7e0cddf | 14838 | 0 /* parse cond/thread */, |
8cdf0e15 | 14839 | 0 /* tempflag */, |
0fb4aa4b | 14840 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14841 | 0 /* Ignore count */, |
14842 | pending_break_support, | |
348d480f | 14843 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14844 | 0 /* from_tty */, |
84f4c1fe | 14845 | utp->enabled /* enabled */, |
44f238bb PA |
14846 | 0 /* internal */, |
14847 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14848 | return NULL; |
fd9b8c24 | 14849 | |
409873ef | 14850 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14851 | tp = get_tracepoint (tracepoint_count); |
14852 | gdb_assert (tp != NULL); | |
d5551862 | 14853 | |
00bf0b85 SS |
14854 | if (utp->pass > 0) |
14855 | { | |
8c042590 | 14856 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14857 | tp->number); |
00bf0b85 | 14858 | |
409873ef | 14859 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14860 | } |
14861 | ||
409873ef SS |
14862 | /* If we have uploaded versions of the original commands, set up a |
14863 | special-purpose "reader" function and call the usual command line | |
14864 | reader, then pass the result to the breakpoint command-setting | |
14865 | function. */ | |
3149d8c1 | 14866 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 14867 | { |
93921405 | 14868 | command_line_up cmd_list; |
00bf0b85 | 14869 | |
409873ef | 14870 | this_utp = utp; |
3149d8c1 | 14871 | next_cmd = 0; |
d5551862 | 14872 | |
409873ef SS |
14873 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
14874 | ||
c1fc2657 | 14875 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14876 | } |
3149d8c1 SS |
14877 | else if (!VEC_empty (char_ptr, utp->actions) |
14878 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
14879 | warning (_("Uploaded tracepoint %d actions " |
14880 | "have no source form, ignoring them"), | |
409873ef | 14881 | utp->number); |
00bf0b85 | 14882 | |
f196051f | 14883 | /* Copy any status information that might be available. */ |
c1fc2657 | 14884 | tp->hit_count = utp->hit_count; |
f196051f SS |
14885 | tp->traceframe_usage = utp->traceframe_usage; |
14886 | ||
00bf0b85 | 14887 | return tp; |
d9b3f62e | 14888 | } |
00bf0b85 | 14889 | |
1042e4c0 SS |
14890 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14891 | omitted. */ | |
14892 | ||
14893 | static void | |
1d12d88f | 14894 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 14895 | { |
79a45e25 | 14896 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14897 | int num_printed; |
1042e4c0 | 14898 | |
e5a67952 | 14899 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
14900 | |
14901 | if (num_printed == 0) | |
1042e4c0 | 14902 | { |
e5a67952 | 14903 | if (args == NULL || *args == '\0') |
112e8700 | 14904 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14905 | else |
112e8700 | 14906 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14907 | } |
ad443146 SS |
14908 | |
14909 | default_collect_info (); | |
1042e4c0 SS |
14910 | } |
14911 | ||
4a64f543 | 14912 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14913 | Not supported by all targets. */ |
14914 | static void | |
5fed81ff | 14915 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14916 | { |
14917 | enable_command (args, from_tty); | |
14918 | } | |
14919 | ||
4a64f543 | 14920 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14921 | Not supported by all targets. */ |
14922 | static void | |
5fed81ff | 14923 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14924 | { |
14925 | disable_command (args, from_tty); | |
14926 | } | |
14927 | ||
4a64f543 | 14928 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 14929 | static void |
4495129a | 14930 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 14931 | { |
35df4500 | 14932 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14933 | |
14934 | dont_repeat (); | |
14935 | ||
14936 | if (arg == 0) | |
14937 | { | |
14938 | int breaks_to_delete = 0; | |
14939 | ||
14940 | /* Delete all breakpoints if no argument. | |
14941 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14942 | have to be deleted with an explicit breakpoint number |
14943 | argument. */ | |
1042e4c0 | 14944 | ALL_TRACEPOINTS (b) |
46c6471b | 14945 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14946 | { |
14947 | breaks_to_delete = 1; | |
14948 | break; | |
14949 | } | |
1042e4c0 SS |
14950 | |
14951 | /* Ask user only if there are some breakpoints to delete. */ | |
14952 | if (!from_tty | |
14953 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14954 | { | |
35df4500 | 14955 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14956 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14957 | delete_breakpoint (b); |
1042e4c0 SS |
14958 | } |
14959 | } | |
14960 | else | |
48649e1b TT |
14961 | map_breakpoint_numbers |
14962 | (arg, [&] (breakpoint *b) | |
14963 | { | |
14964 | iterate_over_related_breakpoints (b, delete_breakpoint); | |
14965 | }); | |
1042e4c0 SS |
14966 | } |
14967 | ||
197f0a60 TT |
14968 | /* Helper function for trace_pass_command. */ |
14969 | ||
14970 | static void | |
d9b3f62e | 14971 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14972 | { |
d9b3f62e | 14973 | tp->pass_count = count; |
c1fc2657 | 14974 | observer_notify_breakpoint_modified (tp); |
197f0a60 TT |
14975 | if (from_tty) |
14976 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 14977 | tp->number, count); |
197f0a60 TT |
14978 | } |
14979 | ||
1042e4c0 SS |
14980 | /* Set passcount for tracepoint. |
14981 | ||
14982 | First command argument is passcount, second is tracepoint number. | |
14983 | If tracepoint number omitted, apply to most recently defined. | |
14984 | Also accepts special argument "all". */ | |
14985 | ||
14986 | static void | |
0b39b52e | 14987 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 14988 | { |
d9b3f62e | 14989 | struct tracepoint *t1; |
0b39b52e | 14990 | ULONGEST count; |
1042e4c0 SS |
14991 | |
14992 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14993 | error (_("passcount command requires an " |
14994 | "argument (count + optional TP num)")); | |
1042e4c0 | 14995 | |
0b39b52e | 14996 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 14997 | |
529480d0 | 14998 | args = skip_spaces (args); |
1042e4c0 SS |
14999 | if (*args && strncasecmp (args, "all", 3) == 0) |
15000 | { | |
d9b3f62e PA |
15001 | struct breakpoint *b; |
15002 | ||
1042e4c0 | 15003 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15004 | if (*args) |
15005 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15006 | |
d9b3f62e | 15007 | ALL_TRACEPOINTS (b) |
197f0a60 | 15008 | { |
d9b3f62e | 15009 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15010 | trace_pass_set_count (t1, count, from_tty); |
15011 | } | |
15012 | } | |
15013 | else if (*args == '\0') | |
1042e4c0 | 15014 | { |
5fa1d40e | 15015 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15016 | if (t1) |
197f0a60 TT |
15017 | trace_pass_set_count (t1, count, from_tty); |
15018 | } | |
15019 | else | |
15020 | { | |
bfd28288 PA |
15021 | number_or_range_parser parser (args); |
15022 | while (!parser.finished ()) | |
1042e4c0 | 15023 | { |
bfd28288 | 15024 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15025 | if (t1) |
15026 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15027 | } |
15028 | } | |
1042e4c0 SS |
15029 | } |
15030 | ||
d9b3f62e | 15031 | struct tracepoint * |
1042e4c0 SS |
15032 | get_tracepoint (int num) |
15033 | { | |
15034 | struct breakpoint *t; | |
15035 | ||
15036 | ALL_TRACEPOINTS (t) | |
15037 | if (t->number == num) | |
d9b3f62e | 15038 | return (struct tracepoint *) t; |
1042e4c0 SS |
15039 | |
15040 | return NULL; | |
15041 | } | |
15042 | ||
d5551862 SS |
15043 | /* Find the tracepoint with the given target-side number (which may be |
15044 | different from the tracepoint number after disconnecting and | |
15045 | reconnecting). */ | |
15046 | ||
d9b3f62e | 15047 | struct tracepoint * |
d5551862 SS |
15048 | get_tracepoint_by_number_on_target (int num) |
15049 | { | |
d9b3f62e | 15050 | struct breakpoint *b; |
d5551862 | 15051 | |
d9b3f62e PA |
15052 | ALL_TRACEPOINTS (b) |
15053 | { | |
15054 | struct tracepoint *t = (struct tracepoint *) b; | |
15055 | ||
15056 | if (t->number_on_target == num) | |
15057 | return t; | |
15058 | } | |
d5551862 SS |
15059 | |
15060 | return NULL; | |
15061 | } | |
15062 | ||
1042e4c0 | 15063 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15064 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15065 | If the argument is missing, the most recent tracepoint |
15066 | (tracepoint_count) is returned. */ | |
15067 | ||
d9b3f62e | 15068 | struct tracepoint * |
0b39b52e | 15069 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 15070 | number_or_range_parser *parser) |
1042e4c0 | 15071 | { |
1042e4c0 SS |
15072 | struct breakpoint *t; |
15073 | int tpnum; | |
0b39b52e | 15074 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 15075 | |
bfd28288 | 15076 | if (parser != NULL) |
197f0a60 | 15077 | { |
bfd28288 PA |
15078 | gdb_assert (!parser->finished ()); |
15079 | tpnum = parser->get_number (); | |
197f0a60 TT |
15080 | } |
15081 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15082 | tpnum = tracepoint_count; |
1042e4c0 | 15083 | else |
197f0a60 | 15084 | tpnum = get_number (arg); |
1042e4c0 SS |
15085 | |
15086 | if (tpnum <= 0) | |
15087 | { | |
15088 | if (instring && *instring) | |
15089 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15090 | instring); | |
15091 | else | |
5fa1d40e | 15092 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15093 | return NULL; |
15094 | } | |
15095 | ||
15096 | ALL_TRACEPOINTS (t) | |
15097 | if (t->number == tpnum) | |
15098 | { | |
d9b3f62e | 15099 | return (struct tracepoint *) t; |
1042e4c0 SS |
15100 | } |
15101 | ||
1042e4c0 SS |
15102 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15103 | return NULL; | |
15104 | } | |
15105 | ||
d9b3f62e PA |
15106 | void |
15107 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15108 | { | |
15109 | if (b->thread != -1) | |
15110 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15111 | ||
15112 | if (b->task != 0) | |
15113 | fprintf_unfiltered (fp, " task %d", b->task); | |
15114 | ||
15115 | fprintf_unfiltered (fp, "\n"); | |
15116 | } | |
15117 | ||
6149aea9 PA |
15118 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15119 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15120 | on each breakpoint and only include the ones for which it returns | |
15121 | non-zero. */ | |
15122 | ||
1042e4c0 | 15123 | static void |
4495129a | 15124 | save_breakpoints (const char *filename, int from_tty, |
6149aea9 | 15125 | int (*filter) (const struct breakpoint *)) |
1042e4c0 SS |
15126 | { |
15127 | struct breakpoint *tp; | |
6149aea9 | 15128 | int any = 0; |
6149aea9 | 15129 | int extra_trace_bits = 0; |
1042e4c0 | 15130 | |
6149aea9 PA |
15131 | if (filename == 0 || *filename == 0) |
15132 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15133 | |
15134 | /* See if we have anything to save. */ | |
6149aea9 | 15135 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15136 | { |
6149aea9 | 15137 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15138 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15139 | continue; |
15140 | ||
15141 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15142 | if (filter && !filter (tp)) | |
15143 | continue; | |
15144 | ||
15145 | any = 1; | |
15146 | ||
15147 | if (is_tracepoint (tp)) | |
15148 | { | |
15149 | extra_trace_bits = 1; | |
15150 | ||
15151 | /* We can stop searching. */ | |
15152 | break; | |
15153 | } | |
1042e4c0 | 15154 | } |
6149aea9 PA |
15155 | |
15156 | if (!any) | |
1042e4c0 | 15157 | { |
6149aea9 | 15158 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15159 | return; |
15160 | } | |
15161 | ||
ee0c3293 | 15162 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
15163 | |
15164 | stdio_file fp; | |
15165 | ||
ee0c3293 | 15166 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 15167 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 15168 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 15169 | |
6149aea9 | 15170 | if (extra_trace_bits) |
d7e74731 | 15171 | save_trace_state_variables (&fp); |
8bf6485c | 15172 | |
6149aea9 | 15173 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15174 | { |
6149aea9 | 15175 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15176 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15177 | continue; |
8bf6485c | 15178 | |
6149aea9 PA |
15179 | /* If we have a filter, only save the breakpoints it accepts. */ |
15180 | if (filter && !filter (tp)) | |
15181 | continue; | |
15182 | ||
d7e74731 | 15183 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15184 | |
6149aea9 PA |
15185 | /* Note, we can't rely on tp->number for anything, as we can't |
15186 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15187 | instead. */ | |
15188 | ||
15189 | if (tp->cond_string) | |
d7e74731 | 15190 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15191 | |
15192 | if (tp->ignore_count) | |
d7e74731 | 15193 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15194 | |
2d9442cc | 15195 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15196 | { |
d7e74731 | 15197 | fp.puts (" commands\n"); |
a7bdde9e | 15198 | |
d7e74731 | 15199 | current_uiout->redirect (&fp); |
492d29ea | 15200 | TRY |
1042e4c0 | 15201 | { |
d1b0a7bf | 15202 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 15203 | } |
492d29ea PA |
15204 | CATCH (ex, RETURN_MASK_ALL) |
15205 | { | |
112e8700 | 15206 | current_uiout->redirect (NULL); |
492d29ea PA |
15207 | throw_exception (ex); |
15208 | } | |
15209 | END_CATCH | |
1042e4c0 | 15210 | |
112e8700 | 15211 | current_uiout->redirect (NULL); |
d7e74731 | 15212 | fp.puts (" end\n"); |
1042e4c0 | 15213 | } |
6149aea9 PA |
15214 | |
15215 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15216 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15217 | |
15218 | /* If this is a multi-location breakpoint, check if the locations | |
15219 | should be individually disabled. Watchpoint locations are | |
15220 | special, and not user visible. */ | |
15221 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15222 | { | |
15223 | struct bp_location *loc; | |
15224 | int n = 1; | |
15225 | ||
15226 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15227 | if (!loc->enabled) | |
d7e74731 | 15228 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15229 | } |
1042e4c0 | 15230 | } |
8bf6485c | 15231 | |
6149aea9 | 15232 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15233 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15234 | |
1042e4c0 | 15235 | if (from_tty) |
ee0c3293 | 15236 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15237 | } |
15238 | ||
15239 | /* The `save breakpoints' command. */ | |
15240 | ||
15241 | static void | |
4495129a | 15242 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
15243 | { |
15244 | save_breakpoints (args, from_tty, NULL); | |
15245 | } | |
15246 | ||
15247 | /* The `save tracepoints' command. */ | |
15248 | ||
15249 | static void | |
4495129a | 15250 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
15251 | { |
15252 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15253 | } |
15254 | ||
15255 | /* Create a vector of all tracepoints. */ | |
15256 | ||
15257 | VEC(breakpoint_p) * | |
eeae04df | 15258 | all_tracepoints (void) |
1042e4c0 SS |
15259 | { |
15260 | VEC(breakpoint_p) *tp_vec = 0; | |
15261 | struct breakpoint *tp; | |
15262 | ||
15263 | ALL_TRACEPOINTS (tp) | |
15264 | { | |
15265 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15266 | } | |
15267 | ||
15268 | return tp_vec; | |
15269 | } | |
15270 | ||
c906108c | 15271 | \f |
629500fa KS |
15272 | /* This help string is used to consolidate all the help string for specifying |
15273 | locations used by several commands. */ | |
15274 | ||
15275 | #define LOCATION_HELP_STRING \ | |
15276 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15277 | source filename, function name, label name, and line number.\n\ | |
15278 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15279 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15280 | \"factorial.c:fact:the_top\".\n\ | |
15281 | \n\ | |
15282 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15283 | program. Example: To specify the fourth byte past the start function\n\ | |
15284 | \"main\", use \"*main + 4\".\n\ | |
15285 | \n\ | |
15286 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15287 | syntax to specify location parameters.\n\ | |
15288 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15289 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
15290 | -function fact -label the_top\".\n\ |
15291 | \n\ | |
15292 | By default, a specified function is matched against the program's\n\ | |
15293 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
15294 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
15295 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
15296 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
15297 | specified name as a complete fully-qualified name instead.\n" | |
629500fa | 15298 | |
4a64f543 MS |
15299 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15300 | commands. It is defined as a macro to prevent duplication. | |
15301 | COMMAND should be a string constant containing the name of the | |
15302 | command. */ | |
629500fa | 15303 | |
31e2b00f | 15304 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15305 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15306 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15307 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15308 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15309 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15310 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15311 | below.\n\ | |
15312 | \n\ | |
dc10affe PA |
15313 | With no LOCATION, uses current execution address of the selected\n\ |
15314 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15315 | \n\ |
15316 | THREADNUM is the number from \"info threads\".\n\ | |
15317 | CONDITION is a boolean expression.\n\ | |
629500fa | 15318 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15319 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15320 | conditions are different.\n\ | |
31e2b00f AS |
15321 | \n\ |
15322 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15323 | ||
44feb3ce TT |
15324 | /* List of subcommands for "catch". */ |
15325 | static struct cmd_list_element *catch_cmdlist; | |
15326 | ||
15327 | /* List of subcommands for "tcatch". */ | |
15328 | static struct cmd_list_element *tcatch_cmdlist; | |
15329 | ||
9ac4176b | 15330 | void |
a121b7c1 | 15331 | add_catch_command (const char *name, const char *docstring, |
eb4c3f4a | 15332 | cmd_const_sfunc_ftype *sfunc, |
625e8578 | 15333 | completer_ftype *completer, |
44feb3ce TT |
15334 | void *user_data_catch, |
15335 | void *user_data_tcatch) | |
15336 | { | |
15337 | struct cmd_list_element *command; | |
15338 | ||
0450cc4c | 15339 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15340 | &catch_cmdlist); |
15341 | set_cmd_sfunc (command, sfunc); | |
15342 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15343 | set_cmd_completer (command, completer); |
44feb3ce | 15344 | |
0450cc4c | 15345 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15346 | &tcatch_cmdlist); |
15347 | set_cmd_sfunc (command, sfunc); | |
15348 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15349 | set_cmd_completer (command, completer); |
44feb3ce TT |
15350 | } |
15351 | ||
6149aea9 | 15352 | static void |
981a3fb3 | 15353 | save_command (const char *arg, int from_tty) |
6149aea9 | 15354 | { |
3e43a32a MS |
15355 | printf_unfiltered (_("\"save\" must be followed by " |
15356 | "the name of a save subcommand.\n")); | |
635c7e8a | 15357 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15358 | } |
15359 | ||
84f4c1fe PM |
15360 | struct breakpoint * |
15361 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15362 | void *data) | |
15363 | { | |
35df4500 | 15364 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15365 | |
35df4500 | 15366 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15367 | { |
15368 | if ((*callback) (b, data)) | |
15369 | return b; | |
15370 | } | |
15371 | ||
15372 | return NULL; | |
15373 | } | |
15374 | ||
0574c78f GB |
15375 | /* Zero if any of the breakpoint's locations could be a location where |
15376 | functions have been inlined, nonzero otherwise. */ | |
15377 | ||
15378 | static int | |
15379 | is_non_inline_function (struct breakpoint *b) | |
15380 | { | |
15381 | /* The shared library event breakpoint is set on the address of a | |
15382 | non-inline function. */ | |
15383 | if (b->type == bp_shlib_event) | |
15384 | return 1; | |
15385 | ||
15386 | return 0; | |
15387 | } | |
15388 | ||
15389 | /* Nonzero if the specified PC cannot be a location where functions | |
15390 | have been inlined. */ | |
15391 | ||
15392 | int | |
accd0bcd | 15393 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
09ac7c10 | 15394 | const struct target_waitstatus *ws) |
0574c78f GB |
15395 | { |
15396 | struct breakpoint *b; | |
15397 | struct bp_location *bl; | |
15398 | ||
15399 | ALL_BREAKPOINTS (b) | |
15400 | { | |
15401 | if (!is_non_inline_function (b)) | |
15402 | continue; | |
15403 | ||
15404 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15405 | { | |
15406 | if (!bl->shlib_disabled | |
09ac7c10 | 15407 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15408 | return 1; |
15409 | } | |
15410 | } | |
15411 | ||
15412 | return 0; | |
15413 | } | |
15414 | ||
2f202fde JK |
15415 | /* Remove any references to OBJFILE which is going to be freed. */ |
15416 | ||
15417 | void | |
15418 | breakpoint_free_objfile (struct objfile *objfile) | |
15419 | { | |
15420 | struct bp_location **locp, *loc; | |
15421 | ||
15422 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15423 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15424 | loc->symtab = NULL; |
15425 | } | |
15426 | ||
2060206e PA |
15427 | void |
15428 | initialize_breakpoint_ops (void) | |
15429 | { | |
15430 | static int initialized = 0; | |
15431 | ||
15432 | struct breakpoint_ops *ops; | |
15433 | ||
15434 | if (initialized) | |
15435 | return; | |
15436 | initialized = 1; | |
15437 | ||
15438 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15439 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15440 | internal and momentary breakpoints, etc.). */ | |
15441 | ops = &bkpt_base_breakpoint_ops; | |
15442 | *ops = base_breakpoint_ops; | |
15443 | ops->re_set = bkpt_re_set; | |
15444 | ops->insert_location = bkpt_insert_location; | |
15445 | ops->remove_location = bkpt_remove_location; | |
15446 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15447 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15448 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15449 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15450 | |
15451 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15452 | ops = &bkpt_breakpoint_ops; | |
15453 | *ops = bkpt_base_breakpoint_ops; | |
15454 | ops->re_set = bkpt_re_set; | |
15455 | ops->resources_needed = bkpt_resources_needed; | |
15456 | ops->print_it = bkpt_print_it; | |
15457 | ops->print_mention = bkpt_print_mention; | |
15458 | ops->print_recreate = bkpt_print_recreate; | |
15459 | ||
15460 | /* Ranged breakpoints. */ | |
15461 | ops = &ranged_breakpoint_ops; | |
15462 | *ops = bkpt_breakpoint_ops; | |
15463 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15464 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15465 | ops->print_it = print_it_ranged_breakpoint; | |
15466 | ops->print_one = print_one_ranged_breakpoint; | |
15467 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15468 | ops->print_mention = print_mention_ranged_breakpoint; | |
15469 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15470 | ||
15471 | /* Internal breakpoints. */ | |
15472 | ops = &internal_breakpoint_ops; | |
15473 | *ops = bkpt_base_breakpoint_ops; | |
15474 | ops->re_set = internal_bkpt_re_set; | |
15475 | ops->check_status = internal_bkpt_check_status; | |
15476 | ops->print_it = internal_bkpt_print_it; | |
15477 | ops->print_mention = internal_bkpt_print_mention; | |
15478 | ||
15479 | /* Momentary breakpoints. */ | |
15480 | ops = &momentary_breakpoint_ops; | |
15481 | *ops = bkpt_base_breakpoint_ops; | |
15482 | ops->re_set = momentary_bkpt_re_set; | |
15483 | ops->check_status = momentary_bkpt_check_status; | |
15484 | ops->print_it = momentary_bkpt_print_it; | |
15485 | ops->print_mention = momentary_bkpt_print_mention; | |
15486 | ||
55aa24fb SDJ |
15487 | /* Probe breakpoints. */ |
15488 | ops = &bkpt_probe_breakpoint_ops; | |
15489 | *ops = bkpt_breakpoint_ops; | |
15490 | ops->insert_location = bkpt_probe_insert_location; | |
15491 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15492 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15493 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15494 | |
2060206e PA |
15495 | /* Watchpoints. */ |
15496 | ops = &watchpoint_breakpoint_ops; | |
15497 | *ops = base_breakpoint_ops; | |
15498 | ops->re_set = re_set_watchpoint; | |
15499 | ops->insert_location = insert_watchpoint; | |
15500 | ops->remove_location = remove_watchpoint; | |
15501 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15502 | ops->check_status = check_status_watchpoint; | |
15503 | ops->resources_needed = resources_needed_watchpoint; | |
15504 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15505 | ops->print_it = print_it_watchpoint; | |
15506 | ops->print_mention = print_mention_watchpoint; | |
15507 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15508 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15509 | |
15510 | /* Masked watchpoints. */ | |
15511 | ops = &masked_watchpoint_breakpoint_ops; | |
15512 | *ops = watchpoint_breakpoint_ops; | |
15513 | ops->insert_location = insert_masked_watchpoint; | |
15514 | ops->remove_location = remove_masked_watchpoint; | |
15515 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15516 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15517 | ops->print_it = print_it_masked_watchpoint; | |
15518 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15519 | ops->print_mention = print_mention_masked_watchpoint; | |
15520 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15521 | ||
15522 | /* Tracepoints. */ | |
15523 | ops = &tracepoint_breakpoint_ops; | |
15524 | *ops = base_breakpoint_ops; | |
15525 | ops->re_set = tracepoint_re_set; | |
15526 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15527 | ops->print_one_detail = tracepoint_print_one_detail; | |
15528 | ops->print_mention = tracepoint_print_mention; | |
15529 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15530 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15531 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15532 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15533 | |
55aa24fb SDJ |
15534 | /* Probe tracepoints. */ |
15535 | ops = &tracepoint_probe_breakpoint_ops; | |
15536 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15537 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15538 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15539 | |
983af33b SDJ |
15540 | /* Static tracepoints with marker (`-m'). */ |
15541 | ops = &strace_marker_breakpoint_ops; | |
15542 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15543 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15544 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15545 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15546 | |
15547 | /* Fork catchpoints. */ | |
15548 | ops = &catch_fork_breakpoint_ops; | |
15549 | *ops = base_breakpoint_ops; | |
15550 | ops->insert_location = insert_catch_fork; | |
15551 | ops->remove_location = remove_catch_fork; | |
15552 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15553 | ops->print_it = print_it_catch_fork; | |
15554 | ops->print_one = print_one_catch_fork; | |
15555 | ops->print_mention = print_mention_catch_fork; | |
15556 | ops->print_recreate = print_recreate_catch_fork; | |
15557 | ||
15558 | /* Vfork catchpoints. */ | |
15559 | ops = &catch_vfork_breakpoint_ops; | |
15560 | *ops = base_breakpoint_ops; | |
15561 | ops->insert_location = insert_catch_vfork; | |
15562 | ops->remove_location = remove_catch_vfork; | |
15563 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15564 | ops->print_it = print_it_catch_vfork; | |
15565 | ops->print_one = print_one_catch_vfork; | |
15566 | ops->print_mention = print_mention_catch_vfork; | |
15567 | ops->print_recreate = print_recreate_catch_vfork; | |
15568 | ||
15569 | /* Exec catchpoints. */ | |
15570 | ops = &catch_exec_breakpoint_ops; | |
15571 | *ops = base_breakpoint_ops; | |
2060206e PA |
15572 | ops->insert_location = insert_catch_exec; |
15573 | ops->remove_location = remove_catch_exec; | |
15574 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15575 | ops->print_it = print_it_catch_exec; | |
15576 | ops->print_one = print_one_catch_exec; | |
15577 | ops->print_mention = print_mention_catch_exec; | |
15578 | ops->print_recreate = print_recreate_catch_exec; | |
15579 | ||
edcc5120 TT |
15580 | /* Solib-related catchpoints. */ |
15581 | ops = &catch_solib_breakpoint_ops; | |
15582 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15583 | ops->insert_location = insert_catch_solib; |
15584 | ops->remove_location = remove_catch_solib; | |
15585 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15586 | ops->check_status = check_status_catch_solib; | |
15587 | ops->print_it = print_it_catch_solib; | |
15588 | ops->print_one = print_one_catch_solib; | |
15589 | ops->print_mention = print_mention_catch_solib; | |
15590 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15591 | |
15592 | ops = &dprintf_breakpoint_ops; | |
15593 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15594 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15595 | ops->resources_needed = bkpt_resources_needed; |
15596 | ops->print_it = bkpt_print_it; | |
15597 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15598 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15599 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15600 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15601 | } |
15602 | ||
8bfd80db YQ |
15603 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15604 | ||
15605 | static struct cmd_list_element *enablebreaklist = NULL; | |
15606 | ||
c906108c | 15607 | void |
fba45db2 | 15608 | _initialize_breakpoint (void) |
c906108c SS |
15609 | { |
15610 | struct cmd_list_element *c; | |
15611 | ||
2060206e PA |
15612 | initialize_breakpoint_ops (); |
15613 | ||
84acb35a | 15614 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 15615 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 15616 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15617 | |
55aa24fb | 15618 | breakpoint_objfile_key |
43dce439 | 15619 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_objfile_data); |
17450429 | 15620 | |
c906108c SS |
15621 | breakpoint_chain = 0; |
15622 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15623 | before a breakpoint is set. */ | |
15624 | breakpoint_count = 0; | |
15625 | ||
1042e4c0 SS |
15626 | tracepoint_count = 0; |
15627 | ||
1bedd215 AC |
15628 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15629 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15630 | Usage is `ignore N COUNT'.")); | |
c906108c | 15631 | |
1bedd215 | 15632 | add_com ("commands", class_breakpoint, commands_command, _("\ |
18da0c51 MG |
15633 | Set commands to be executed when the given breakpoints are hit.\n\ |
15634 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15635 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15636 | (e.g. `5-7').\n\ | |
c906108c SS |
15637 | With no argument, the targeted breakpoint is the last one set.\n\ |
15638 | The commands themselves follow starting on the next line.\n\ | |
15639 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15640 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15641 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15642 | |
d55637df | 15643 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15644 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15645 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15646 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15647 | set_cmd_completer (c, condition_completer); |
c906108c | 15648 | |
1bedd215 | 15649 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15650 | Set a temporary breakpoint.\n\ |
c906108c SS |
15651 | Like \"break\" except the breakpoint is only temporary,\n\ |
15652 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15653 | by using \"enable delete\" on the breakpoint number.\n\ |
15654 | \n" | |
15655 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15656 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15657 | |
1bedd215 | 15658 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15659 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15660 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15661 | some target hardware may not have this support.\n\ |
15662 | \n" | |
15663 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15664 | set_cmd_completer (c, location_completer); |
c906108c | 15665 | |
1bedd215 | 15666 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15667 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15668 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15669 | so it will be deleted when hit.\n\ |
15670 | \n" | |
15671 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15672 | set_cmd_completer (c, location_completer); |
c906108c | 15673 | |
1bedd215 AC |
15674 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15675 | Enable some breakpoints.\n\ | |
c906108c SS |
15676 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15677 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15678 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15679 | With a subcommand you can enable temporarily."), |
c906108c | 15680 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15681 | |
15682 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15683 | ||
84951ab5 | 15684 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15685 | Enable some breakpoints.\n\ |
c906108c SS |
15686 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15687 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15688 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15689 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15690 | |
1a966eab AC |
15691 | add_cmd ("once", no_class, enable_once_command, _("\ |
15692 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15693 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15694 | &enablebreaklist); |
15695 | ||
1a966eab AC |
15696 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15697 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15698 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15699 | &enablebreaklist); |
15700 | ||
816338b5 SS |
15701 | add_cmd ("count", no_class, enable_count_command, _("\ |
15702 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15703 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15704 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15705 | &enablebreaklist); | |
15706 | ||
1a966eab AC |
15707 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15708 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15709 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15710 | &enablelist); |
15711 | ||
1a966eab AC |
15712 | add_cmd ("once", no_class, enable_once_command, _("\ |
15713 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15714 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15715 | &enablelist); |
15716 | ||
15717 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15718 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15719 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15720 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15721 | &enablelist); |
15722 | ||
1bedd215 AC |
15723 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15724 | Disable some breakpoints.\n\ | |
c906108c SS |
15725 | Arguments are breakpoint numbers with spaces in between.\n\ |
15726 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15727 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15728 | &disablelist, "disable ", 1, &cmdlist); |
15729 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15730 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15731 | |
1a966eab AC |
15732 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15733 | Disable some breakpoints.\n\ | |
c906108c SS |
15734 | Arguments are breakpoint numbers with spaces in between.\n\ |
15735 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15736 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15737 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15738 | &disablelist); |
15739 | ||
1bedd215 AC |
15740 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15741 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15742 | Arguments are breakpoint numbers with spaces in between.\n\ |
15743 | To delete all breakpoints, give no argument.\n\ | |
15744 | \n\ | |
15745 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15746 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15747 | &deletelist, "delete ", 1, &cmdlist); |
15748 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15749 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15750 | |
1a966eab AC |
15751 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15752 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15753 | Arguments are breakpoint numbers with spaces in between.\n\ |
15754 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15755 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15756 | &deletelist); |
15757 | ||
1bedd215 | 15758 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15759 | Clear breakpoint at specified location.\n\ |
15760 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15761 | \n\ |
15762 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
15763 | is executing in.\n" |
15764 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 15765 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15766 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15767 | |
1bedd215 | 15768 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15769 | Set breakpoint at specified location.\n" |
31e2b00f | 15770 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15771 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15772 | |
c906108c SS |
15773 | add_com_alias ("b", "break", class_run, 1); |
15774 | add_com_alias ("br", "break", class_run, 1); | |
15775 | add_com_alias ("bre", "break", class_run, 1); | |
15776 | add_com_alias ("brea", "break", class_run, 1); | |
15777 | ||
c906108c SS |
15778 | if (dbx_commands) |
15779 | { | |
1bedd215 AC |
15780 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15781 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15782 | &stoplist, "stop ", 1, &cmdlist); |
15783 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15784 | _("Break in function or address."), &stoplist); |
c5aa993b | 15785 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15786 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15787 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15788 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15789 | The \"Type\" column indicates one of:\n\ |
15790 | \tbreakpoint - normal breakpoint\n\ | |
15791 | \twatchpoint - watchpoint\n\ | |
15792 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15793 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15794 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15795 | address and file/line number respectively.\n\ |
15796 | \n\ | |
15797 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15798 | are set to the address of the last breakpoint listed unless the command\n\ |
15799 | is prefixed with \"server \".\n\n\ | |
c906108c | 15800 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15801 | breakpoint set.")); |
c906108c SS |
15802 | } |
15803 | ||
11db9430 | 15804 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15805 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15806 | The \"Type\" column indicates one of:\n\ |
15807 | \tbreakpoint - normal breakpoint\n\ | |
15808 | \twatchpoint - watchpoint\n\ | |
15809 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15810 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15811 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15812 | address and file/line number respectively.\n\ |
15813 | \n\ | |
15814 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15815 | are set to the address of the last breakpoint listed unless the command\n\ |
15816 | is prefixed with \"server \".\n\n\ | |
c906108c | 15817 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15818 | breakpoint set.")); |
c906108c | 15819 | |
6b04bdb7 MS |
15820 | add_info_alias ("b", "breakpoints", 1); |
15821 | ||
1a966eab AC |
15822 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15823 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15824 | The \"Type\" column indicates one of:\n\ |
15825 | \tbreakpoint - normal breakpoint\n\ | |
15826 | \twatchpoint - watchpoint\n\ | |
15827 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15828 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15829 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15830 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15831 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15832 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15833 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15834 | address and file/line number respectively.\n\ |
15835 | \n\ | |
15836 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15837 | are set to the address of the last breakpoint listed unless the command\n\ |
15838 | is prefixed with \"server \".\n\n\ | |
c906108c | 15839 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15840 | breakpoint set."), |
c906108c SS |
15841 | &maintenanceinfolist); |
15842 | ||
44feb3ce TT |
15843 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15844 | Set catchpoints to catch events."), | |
15845 | &catch_cmdlist, "catch ", | |
15846 | 0/*allow-unknown*/, &cmdlist); | |
15847 | ||
15848 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15849 | Set temporary catchpoints to catch events."), | |
15850 | &tcatch_cmdlist, "tcatch ", | |
15851 | 0/*allow-unknown*/, &cmdlist); | |
15852 | ||
44feb3ce TT |
15853 | add_catch_command ("fork", _("Catch calls to fork."), |
15854 | catch_fork_command_1, | |
a96d9b2e | 15855 | NULL, |
44feb3ce TT |
15856 | (void *) (uintptr_t) catch_fork_permanent, |
15857 | (void *) (uintptr_t) catch_fork_temporary); | |
15858 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15859 | catch_fork_command_1, | |
a96d9b2e | 15860 | NULL, |
44feb3ce TT |
15861 | (void *) (uintptr_t) catch_vfork_permanent, |
15862 | (void *) (uintptr_t) catch_vfork_temporary); | |
15863 | add_catch_command ("exec", _("Catch calls to exec."), | |
15864 | catch_exec_command_1, | |
a96d9b2e SDJ |
15865 | NULL, |
15866 | CATCH_PERMANENT, | |
15867 | CATCH_TEMPORARY); | |
edcc5120 TT |
15868 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15869 | Usage: catch load [REGEX]\n\ | |
15870 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15871 | catch_load_command_1, | |
15872 | NULL, | |
15873 | CATCH_PERMANENT, | |
15874 | CATCH_TEMPORARY); | |
15875 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15876 | Usage: catch unload [REGEX]\n\ | |
15877 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15878 | catch_unload_command_1, | |
15879 | NULL, | |
15880 | CATCH_PERMANENT, | |
15881 | CATCH_TEMPORARY); | |
c5aa993b | 15882 | |
1bedd215 AC |
15883 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15884 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15885 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15886 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15887 | an expression changes.\n\ |
15888 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15889 | the memory to which it refers.")); | |
65d12d83 | 15890 | set_cmd_completer (c, expression_completer); |
c906108c | 15891 | |
1bedd215 AC |
15892 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15893 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15894 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15895 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15896 | an expression is read.\n\ |
15897 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15898 | the memory to which it refers.")); | |
65d12d83 | 15899 | set_cmd_completer (c, expression_completer); |
c906108c | 15900 | |
1bedd215 AC |
15901 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15902 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15903 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15904 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15905 | an expression is either read or written.\n\ |
15906 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15907 | the memory to which it refers.")); | |
65d12d83 | 15908 | set_cmd_completer (c, expression_completer); |
c906108c | 15909 | |
11db9430 | 15910 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15911 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15912 | |
920d2a44 AC |
15913 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15914 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15915 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15916 | &can_use_hw_watchpoints, _("\ | |
15917 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15918 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15919 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15920 | such is available. (However, any hardware watchpoints that were\n\ | |
15921 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15922 | hardware.)"), |
15923 | NULL, | |
920d2a44 | 15924 | show_can_use_hw_watchpoints, |
85c07804 | 15925 | &setlist, &showlist); |
c906108c SS |
15926 | |
15927 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15928 | |
1042e4c0 SS |
15929 | /* Tracepoint manipulation commands. */ |
15930 | ||
15931 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 15932 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
15933 | \n" |
15934 | BREAK_ARGS_HELP ("trace") "\n\ | |
15935 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15936 | set_cmd_completer (c, location_completer); | |
15937 | ||
15938 | add_com_alias ("tp", "trace", class_alias, 0); | |
15939 | add_com_alias ("tr", "trace", class_alias, 1); | |
15940 | add_com_alias ("tra", "trace", class_alias, 1); | |
15941 | add_com_alias ("trac", "trace", class_alias, 1); | |
15942 | ||
7a697b8d | 15943 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 15944 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
15945 | \n" |
15946 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15947 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15948 | set_cmd_completer (c, location_completer); | |
15949 | ||
0fb4aa4b | 15950 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 15951 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
15952 | \n\ |
15953 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
15954 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
15955 | or -m MARKER_ID.\n\n\ | |
15956 | If a marker id is specified, probe the marker with that name. With\n\ | |
15957 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
15958 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
15959 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15960 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15961 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15962 | \n\ | |
15963 | CONDITION is a boolean expression.\n\ | |
629500fa | 15964 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15965 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15966 | conditions are different.\n\ | |
0fb4aa4b PA |
15967 | \n\ |
15968 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15969 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15970 | set_cmd_completer (c, location_completer); | |
15971 | ||
11db9430 | 15972 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 15973 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15974 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15975 | last tracepoint set.")); | |
15976 | ||
15977 | add_info_alias ("tp", "tracepoints", 1); | |
15978 | ||
15979 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
15980 | Delete specified tracepoints.\n\ | |
15981 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15982 | No argument means delete all tracepoints."), | |
15983 | &deletelist); | |
7e20dfcd | 15984 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
15985 | |
15986 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15987 | Disable specified tracepoints.\n\ | |
15988 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15989 | No argument means disable all tracepoints."), | |
15990 | &disablelist); | |
15991 | deprecate_cmd (c, "disable"); | |
15992 | ||
15993 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15994 | Enable specified tracepoints.\n\ | |
15995 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15996 | No argument means enable all tracepoints."), | |
15997 | &enablelist); | |
15998 | deprecate_cmd (c, "enable"); | |
15999 | ||
16000 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16001 | Set the passcount for a tracepoint.\n\ | |
16002 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16003 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16004 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16005 | ||
6149aea9 PA |
16006 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16007 | _("Save breakpoint definitions as a script."), | |
16008 | &save_cmdlist, "save ", | |
16009 | 0/*allow-unknown*/, &cmdlist); | |
16010 | ||
16011 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16012 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16013 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16014 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16015 | session to restore them."), | |
16016 | &save_cmdlist); | |
16017 | set_cmd_completer (c, filename_completer); | |
16018 | ||
16019 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16020 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16021 | Use the 'source' command in another debug session to restore them."), |
16022 | &save_cmdlist); | |
1042e4c0 SS |
16023 | set_cmd_completer (c, filename_completer); |
16024 | ||
6149aea9 PA |
16025 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16026 | deprecate_cmd (c, "save tracepoints"); | |
16027 | ||
1bedd215 | 16028 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16029 | Breakpoint specific settings\n\ |
16030 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16031 | pending breakpoint behavior"), |
fa8d40ab JJ |
16032 | &breakpoint_set_cmdlist, "set breakpoint ", |
16033 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16034 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16035 | Breakpoint specific settings\n\ |
16036 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16037 | pending breakpoint behavior"), |
fa8d40ab JJ |
16038 | &breakpoint_show_cmdlist, "show breakpoint ", |
16039 | 0/*allow-unknown*/, &showlist); | |
16040 | ||
7915a72c AC |
16041 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16042 | &pending_break_support, _("\ | |
16043 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16044 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16045 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16046 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16047 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16048 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16049 | NULL, |
920d2a44 | 16050 | show_pending_break_support, |
6e1d7d6c AC |
16051 | &breakpoint_set_cmdlist, |
16052 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16053 | |
16054 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16055 | |
16056 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16057 | &automatic_hardware_breakpoints, _("\ | |
16058 | Set automatic usage of hardware breakpoints."), _("\ | |
16059 | Show automatic usage of hardware breakpoints."), _("\ | |
16060 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16061 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16062 | a warning will be emitted for such breakpoints."), | |
16063 | NULL, | |
16064 | show_automatic_hardware_breakpoints, | |
16065 | &breakpoint_set_cmdlist, | |
16066 | &breakpoint_show_cmdlist); | |
74960c60 | 16067 | |
a25a5a45 PA |
16068 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16069 | &always_inserted_mode, _("\ | |
74960c60 VP |
16070 | Set mode for inserting breakpoints."), _("\ |
16071 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16072 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16073 | they're created, kept inserted even when execution stops, and removed\n\ | |
16074 | only when the user deletes them. When this mode is off (the default),\n\ | |
16075 | breakpoints are inserted only when execution continues, and removed\n\ | |
16076 | when execution stops."), | |
72d0e2c5 YQ |
16077 | NULL, |
16078 | &show_always_inserted_mode, | |
16079 | &breakpoint_set_cmdlist, | |
16080 | &breakpoint_show_cmdlist); | |
f1310107 | 16081 | |
b775012e LM |
16082 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16083 | condition_evaluation_enums, | |
16084 | &condition_evaluation_mode_1, _("\ | |
16085 | Set mode of breakpoint condition evaluation."), _("\ | |
16086 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16087 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16088 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16089 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16090 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16091 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16092 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16093 | be set to \"gdb\""), | |
16094 | &set_condition_evaluation_mode, | |
16095 | &show_condition_evaluation_mode, | |
16096 | &breakpoint_set_cmdlist, | |
16097 | &breakpoint_show_cmdlist); | |
16098 | ||
f1310107 TJB |
16099 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16100 | Set a breakpoint for an address range.\n\ | |
16101 | break-range START-LOCATION, END-LOCATION\n\ | |
16102 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16103 | LINENUM, for that line in the current file,\n\ | |
16104 | FILE:LINENUM, for that line in that file,\n\ | |
16105 | +OFFSET, for that number of lines after the current line\n\ | |
16106 | or the start of the range\n\ | |
16107 | FUNCTION, for the first line in that function,\n\ | |
16108 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16109 | *ADDRESS, for the instruction at that address.\n\ | |
16110 | \n\ | |
16111 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16112 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16113 | range (including START-LOCATION and END-LOCATION).")); | |
16114 | ||
e7e0cddf | 16115 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16116 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16117 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16118 | location may be a linespec, explicit, or address location.\n" |
16119 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16120 | set_cmd_completer (c, location_completer); |
16121 | ||
16122 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16123 | dprintf_style_enums, &dprintf_style, _("\ | |
16124 | Set the style of usage for dynamic printf."), _("\ | |
16125 | Show the style of usage for dynamic printf."), _("\ | |
16126 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16127 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16128 | console, as with the \"printf\" command.\n\ | |
16129 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16130 | program; by default printf(), but you can choose a different function or\n\ | |
16131 | output stream by setting dprintf-function and dprintf-channel."), | |
16132 | update_dprintf_commands, NULL, | |
16133 | &setlist, &showlist); | |
16134 | ||
16135 | dprintf_function = xstrdup ("printf"); | |
16136 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16137 | &dprintf_function, _("\ | |
16138 | Set the function to use for dynamic printf"), _("\ | |
16139 | Show the function to use for dynamic printf"), NULL, | |
16140 | update_dprintf_commands, NULL, | |
16141 | &setlist, &showlist); | |
16142 | ||
16143 | dprintf_channel = xstrdup (""); | |
16144 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16145 | &dprintf_channel, _("\ | |
16146 | Set the channel to use for dynamic printf"), _("\ | |
16147 | Show the channel to use for dynamic printf"), NULL, | |
16148 | update_dprintf_commands, NULL, | |
16149 | &setlist, &showlist); | |
16150 | ||
d3ce09f5 SS |
16151 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16152 | &disconnected_dprintf, _("\ | |
16153 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16154 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16155 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16156 | even if GDB disconnects or detaches from the target."), | |
16157 | NULL, | |
16158 | NULL, | |
16159 | &setlist, &showlist); | |
16160 | ||
16161 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16162 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16163 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16164 | ||
765dc015 | 16165 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16166 | |
16167 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16168 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16169 | } |