Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
42a4f53d | 3 | Copyright (C) 1986-2019 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" | |
d55e5aa6 | 21 | #include "arch-utils.h" |
4de283e4 TT |
22 | #include <ctype.h> |
23 | #include "hashtab.h" | |
24 | #include "symtab.h" | |
25 | #include "frame.h" | |
c906108c | 26 | #include "breakpoint.h" |
4de283e4 TT |
27 | #include "tracepoint.h" |
28 | #include "gdbtypes.h" | |
c906108c | 29 | #include "expression.h" |
d55e5aa6 | 30 | #include "gdbcore.h" |
4de283e4 TT |
31 | #include "gdbcmd.h" |
32 | #include "value.h" | |
33 | #include "command.h" | |
c906108c | 34 | #include "inferior.h" |
45741a9c | 35 | #include "infrun.h" |
4de283e4 TT |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
c906108c | 38 | #include "language.h" |
4de283e4 TT |
39 | #include "gdb-demangle.h" |
40 | #include "filenames.h" | |
41 | #include "annotate.h" | |
42 | #include "symfile.h" | |
d55e5aa6 | 43 | #include "objfiles.h" |
4de283e4 TT |
44 | #include "source.h" |
45 | #include "linespec.h" | |
46 | #include "completer.h" | |
47 | #include "ui-out.h" | |
48 | #include "cli/cli-script.h" | |
49 | #include "block.h" | |
50 | #include "solib.h" | |
51 | #include "solist.h" | |
d55e5aa6 | 52 | #include "observable.h" |
4de283e4 TT |
53 | #include "memattr.h" |
54 | #include "ada-lang.h" | |
55 | #include "top.h" | |
56 | #include "valprint.h" | |
57 | #include "jit.h" | |
65d79d4b | 58 | #include "parser-defs.h" |
4de283e4 | 59 | #include "gdb_regex.h" |
55aa24fb | 60 | #include "probe.h" |
4de283e4 TT |
61 | #include "cli/cli-utils.h" |
62 | #include "continuations.h" | |
d55e5aa6 | 63 | #include "stack.h" |
4de283e4 TT |
64 | #include "skip.h" |
65 | #include "ax-gdb.h" | |
66 | #include "dummy-frame.h" | |
67 | #include "interps.h" | |
268a13a5 | 68 | #include "gdbsupport/format.h" |
cfc31633 | 69 | #include "thread-fsm.h" |
5d5658a1 | 70 | #include "tid-parse.h" |
4de283e4 TT |
71 | #include "cli/cli-style.h" |
72 | #include "mi/mi-main.h" | |
d3ce09f5 | 73 | |
1042e4c0 SS |
74 | /* readline include files */ |
75 | #include "readline/readline.h" | |
76 | #include "readline/history.h" | |
77 | ||
78 | /* readline defines this. */ | |
79 | #undef savestring | |
80 | ||
034dad6f | 81 | #include "mi/mi-common.h" |
6dddc817 | 82 | #include "extension.h" |
325fac50 | 83 | #include <algorithm> |
5ed8105e | 84 | #include "progspace-and-thread.h" |
268a13a5 TT |
85 | #include "gdbsupport/array-view.h" |
86 | #include "gdbsupport/gdb_optional.h" | |
104c1213 | 87 | |
4a64f543 | 88 | /* Prototypes for local functions. */ |
c906108c | 89 | |
896b6bda | 90 | static void map_breakpoint_numbers (const char *, |
48649e1b | 91 | gdb::function_view<void (breakpoint *)>); |
c906108c | 92 | |
348d480f PA |
93 | static void breakpoint_re_set_default (struct breakpoint *); |
94 | ||
f00aae0f KS |
95 | static void |
96 | create_sals_from_location_default (const struct event_location *location, | |
97 | struct linespec_result *canonical, | |
98 | enum bptype type_wanted); | |
983af33b SDJ |
99 | |
100 | static void create_breakpoints_sal_default (struct gdbarch *, | |
101 | struct linespec_result *, | |
e1e01040 PA |
102 | gdb::unique_xmalloc_ptr<char>, |
103 | gdb::unique_xmalloc_ptr<char>, | |
104 | enum bptype, | |
983af33b SDJ |
105 | enum bpdisp, int, int, |
106 | int, | |
107 | const struct breakpoint_ops *, | |
44f238bb | 108 | int, int, int, unsigned); |
983af33b | 109 | |
6c5b2ebe PA |
110 | static std::vector<symtab_and_line> decode_location_default |
111 | (struct breakpoint *b, const struct event_location *location, | |
112 | struct program_space *search_pspace); | |
983af33b | 113 | |
a6535de1 TT |
114 | static int can_use_hardware_watchpoint |
115 | (const std::vector<value_ref_ptr> &vals); | |
c906108c | 116 | |
a14ed312 | 117 | static void mention (struct breakpoint *); |
c906108c | 118 | |
348d480f PA |
119 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
120 | enum bptype, | |
c0a91b2b | 121 | const struct breakpoint_ops *); |
3742cc8b YQ |
122 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
123 | const struct symtab_and_line *); | |
124 | ||
4a64f543 MS |
125 | /* This function is used in gdbtk sources and thus can not be made |
126 | static. */ | |
63c252f8 | 127 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 128 | struct symtab_and_line, |
c0a91b2b TT |
129 | enum bptype, |
130 | const struct breakpoint_ops *); | |
c906108c | 131 | |
06edf0c0 PA |
132 | static struct breakpoint * |
133 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
134 | enum bptype type, | |
a1aa2221 LM |
135 | const struct breakpoint_ops *ops, |
136 | int loc_enabled); | |
06edf0c0 | 137 | |
76897487 KB |
138 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
139 | ||
a6d9a66e UW |
140 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
141 | CORE_ADDR bpaddr, | |
88f7da05 | 142 | enum bptype bptype); |
76897487 | 143 | |
6c95b8df PA |
144 | static void describe_other_breakpoints (struct gdbarch *, |
145 | struct program_space *, CORE_ADDR, | |
5af949e3 | 146 | struct obj_section *, int); |
c906108c | 147 | |
85d721b8 PA |
148 | static int watchpoint_locations_match (struct bp_location *loc1, |
149 | struct bp_location *loc2); | |
150 | ||
f1310107 | 151 | static int breakpoint_location_address_match (struct bp_location *bl, |
accd0bcd | 152 | const struct address_space *aspace, |
f1310107 TJB |
153 | CORE_ADDR addr); |
154 | ||
d35ae833 | 155 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
accd0bcd | 156 | const address_space *, |
d35ae833 PA |
157 | CORE_ADDR, int); |
158 | ||
834c0d03 | 159 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 160 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 161 | |
e514a9d6 | 162 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 163 | |
a14ed312 | 164 | static int hw_breakpoint_used_count (void); |
c906108c | 165 | |
a1398e0c PA |
166 | static int hw_watchpoint_use_count (struct breakpoint *); |
167 | ||
168 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
169 | enum bptype type, | |
170 | int *other_type_used); | |
c906108c | 171 | |
816338b5 SS |
172 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
173 | int count); | |
c906108c | 174 | |
fe3f5fa8 | 175 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
176 | static void incref_bp_location (struct bp_location *loc); |
177 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 178 | |
39d61571 | 179 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 180 | |
44702360 PA |
181 | /* update_global_location_list's modes of operation wrt to whether to |
182 | insert locations now. */ | |
183 | enum ugll_insert_mode | |
184 | { | |
185 | /* Don't insert any breakpoint locations into the inferior, only | |
186 | remove already-inserted locations that no longer should be | |
187 | inserted. Functions that delete a breakpoint or breakpoints | |
188 | should specify this mode, so that deleting a breakpoint doesn't | |
189 | have the side effect of inserting the locations of other | |
190 | breakpoints that are marked not-inserted, but should_be_inserted | |
191 | returns true on them. | |
192 | ||
193 | This behavior is useful is situations close to tear-down -- e.g., | |
194 | after an exec, while the target still has execution, but | |
195 | breakpoint shadows of the previous executable image should *NOT* | |
196 | be restored to the new image; or before detaching, where the | |
197 | target still has execution and wants to delete breakpoints from | |
198 | GDB's lists, and all breakpoints had already been removed from | |
199 | the inferior. */ | |
200 | UGLL_DONT_INSERT, | |
201 | ||
a25a5a45 PA |
202 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
203 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
204 | UGLL_MAY_INSERT, |
205 | ||
a25a5a45 PA |
206 | /* Insert locations now, irrespective of |
207 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
208 | stopped right now, and the user did "continue". We need to | |
209 | insert breakpoints _before_ resuming the target, but | |
210 | UGLL_MAY_INSERT wouldn't insert them, because | |
211 | breakpoints_should_be_inserted_now returns false at that point, | |
212 | as no thread is running yet. */ | |
04086b45 | 213 | UGLL_INSERT |
44702360 PA |
214 | }; |
215 | ||
216 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 217 | |
44702360 | 218 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 219 | |
74960c60 | 220 | static void insert_breakpoint_locations (void); |
a5606eee | 221 | |
0b39b52e | 222 | static void trace_pass_command (const char *, int); |
1042e4c0 | 223 | |
558a9d82 YQ |
224 | static void set_tracepoint_count (int num); |
225 | ||
f2478a7e | 226 | static bool is_masked_watchpoint (const struct breakpoint *b); |
9c06b0b4 | 227 | |
b775012e LM |
228 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
229 | ||
983af33b SDJ |
230 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
231 | otherwise. */ | |
232 | ||
233 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 234 | |
2060206e PA |
235 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
236 | that are implemented on top of software or hardware breakpoints | |
237 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
238 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
239 | ||
240 | /* Internal breakpoints class type. */ | |
06edf0c0 | 241 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
242 | |
243 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
244 | static struct breakpoint_ops momentary_breakpoint_ops; |
245 | ||
2060206e PA |
246 | /* The breakpoint_ops structure to be used in regular user created |
247 | breakpoints. */ | |
248 | struct breakpoint_ops bkpt_breakpoint_ops; | |
249 | ||
55aa24fb SDJ |
250 | /* Breakpoints set on probes. */ |
251 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
252 | ||
e7e0cddf | 253 | /* Dynamic printf class type. */ |
c5867ab6 | 254 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 255 | |
d3ce09f5 SS |
256 | /* The style in which to perform a dynamic printf. This is a user |
257 | option because different output options have different tradeoffs; | |
258 | if GDB does the printing, there is better error handling if there | |
259 | is a problem with any of the arguments, but using an inferior | |
260 | function lets you have special-purpose printers and sending of | |
261 | output to the same place as compiled-in print functions. */ | |
262 | ||
263 | static const char dprintf_style_gdb[] = "gdb"; | |
264 | static const char dprintf_style_call[] = "call"; | |
265 | static const char dprintf_style_agent[] = "agent"; | |
266 | static const char *const dprintf_style_enums[] = { | |
267 | dprintf_style_gdb, | |
268 | dprintf_style_call, | |
269 | dprintf_style_agent, | |
270 | NULL | |
271 | }; | |
272 | static const char *dprintf_style = dprintf_style_gdb; | |
273 | ||
274 | /* The function to use for dynamic printf if the preferred style is to | |
275 | call into the inferior. The value is simply a string that is | |
276 | copied into the command, so it can be anything that GDB can | |
277 | evaluate to a callable address, not necessarily a function name. */ | |
278 | ||
bde6261a | 279 | static char *dprintf_function; |
d3ce09f5 SS |
280 | |
281 | /* The channel to use for dynamic printf if the preferred style is to | |
282 | call into the inferior; if a nonempty string, it will be passed to | |
283 | the call as the first argument, with the format string as the | |
284 | second. As with the dprintf function, this can be anything that | |
285 | GDB knows how to evaluate, so in addition to common choices like | |
286 | "stderr", this could be an app-specific expression like | |
287 | "mystreams[curlogger]". */ | |
288 | ||
bde6261a | 289 | static char *dprintf_channel; |
d3ce09f5 SS |
290 | |
291 | /* True if dprintf commands should continue to operate even if GDB | |
292 | has disconnected. */ | |
491144b5 | 293 | static bool disconnected_dprintf = true; |
d3ce09f5 | 294 | |
5cea2a26 PA |
295 | struct command_line * |
296 | breakpoint_commands (struct breakpoint *b) | |
297 | { | |
d1b0a7bf | 298 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 299 | } |
3daf8fe5 | 300 | |
f3b1572e PA |
301 | /* Flag indicating that a command has proceeded the inferior past the |
302 | current breakpoint. */ | |
303 | ||
491144b5 | 304 | static bool breakpoint_proceeded; |
f3b1572e | 305 | |
956a9fb9 | 306 | const char * |
2cec12e5 AR |
307 | bpdisp_text (enum bpdisp disp) |
308 | { | |
4a64f543 MS |
309 | /* NOTE: the following values are a part of MI protocol and |
310 | represent values of 'disp' field returned when inferior stops at | |
311 | a breakpoint. */ | |
bc043ef3 | 312 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 313 | |
2cec12e5 AR |
314 | return bpdisps[(int) disp]; |
315 | } | |
c906108c | 316 | |
4a64f543 | 317 | /* Prototypes for exported functions. */ |
c906108c | 318 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 319 | if such is available. */ |
c906108c SS |
320 | static int can_use_hw_watchpoints; |
321 | ||
920d2a44 AC |
322 | static void |
323 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
324 | struct cmd_list_element *c, | |
325 | const char *value) | |
326 | { | |
3e43a32a MS |
327 | fprintf_filtered (file, |
328 | _("Debugger's willingness to use " | |
329 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
330 | value); |
331 | } | |
332 | ||
fa8d40ab JJ |
333 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
334 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 335 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
336 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
337 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
338 | static void |
339 | show_pending_break_support (struct ui_file *file, int from_tty, | |
340 | struct cmd_list_element *c, | |
341 | const char *value) | |
342 | { | |
3e43a32a MS |
343 | fprintf_filtered (file, |
344 | _("Debugger's behavior regarding " | |
345 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
346 | value); |
347 | } | |
fa8d40ab | 348 | |
491144b5 | 349 | /* If true, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 350 | set with "break" but falling in read-only memory. |
491144b5 | 351 | If false, gdb will warn about such breakpoints, but won't automatically |
765dc015 | 352 | use hardware breakpoints. */ |
491144b5 | 353 | static bool automatic_hardware_breakpoints; |
765dc015 VP |
354 | static void |
355 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
356 | struct cmd_list_element *c, | |
357 | const char *value) | |
358 | { | |
3e43a32a MS |
359 | fprintf_filtered (file, |
360 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
361 | value); |
362 | } | |
363 | ||
a25a5a45 PA |
364 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
365 | stopped, and immediately inserts any new breakpoints as soon as | |
366 | they're created. If off (default), GDB keeps breakpoints off of | |
367 | the target as long as possible. That is, it delays inserting | |
368 | breakpoints until the next resume, and removes them again when the | |
369 | target fully stops. This is a bit safer in case GDB crashes while | |
370 | processing user input. */ | |
491144b5 | 371 | static bool always_inserted_mode = false; |
72d0e2c5 | 372 | |
33e5cbd6 | 373 | static void |
74960c60 | 374 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 375 | struct cmd_list_element *c, const char *value) |
74960c60 | 376 | { |
a25a5a45 PA |
377 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
378 | value); | |
74960c60 VP |
379 | } |
380 | ||
b57bacec PA |
381 | /* See breakpoint.h. */ |
382 | ||
33e5cbd6 | 383 | int |
a25a5a45 | 384 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 385 | { |
a25a5a45 PA |
386 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
387 | { | |
388 | /* If breakpoints are global, they should be inserted even if no | |
389 | thread under gdb's control is running, or even if there are | |
390 | no threads under GDB's control yet. */ | |
391 | return 1; | |
392 | } | |
393 | else if (target_has_execution) | |
394 | { | |
a25a5a45 PA |
395 | if (always_inserted_mode) |
396 | { | |
397 | /* The user wants breakpoints inserted even if all threads | |
398 | are stopped. */ | |
399 | return 1; | |
400 | } | |
401 | ||
b57bacec PA |
402 | if (threads_are_executing ()) |
403 | return 1; | |
372316f1 PA |
404 | |
405 | /* Don't remove breakpoints yet if, even though all threads are | |
406 | stopped, we still have events to process. */ | |
08036331 | 407 | for (thread_info *tp : all_non_exited_threads ()) |
372316f1 PA |
408 | if (tp->resumed |
409 | && tp->suspend.waitstatus_pending_p) | |
410 | return 1; | |
a25a5a45 PA |
411 | } |
412 | return 0; | |
33e5cbd6 | 413 | } |
765dc015 | 414 | |
b775012e LM |
415 | static const char condition_evaluation_both[] = "host or target"; |
416 | ||
417 | /* Modes for breakpoint condition evaluation. */ | |
418 | static const char condition_evaluation_auto[] = "auto"; | |
419 | static const char condition_evaluation_host[] = "host"; | |
420 | static const char condition_evaluation_target[] = "target"; | |
421 | static const char *const condition_evaluation_enums[] = { | |
422 | condition_evaluation_auto, | |
423 | condition_evaluation_host, | |
424 | condition_evaluation_target, | |
425 | NULL | |
426 | }; | |
427 | ||
428 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
429 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
430 | ||
431 | /* Global that we use to display information to the user (gets its value from | |
432 | condition_evaluation_mode_1. */ | |
433 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
434 | ||
435 | /* Translate a condition evaluation mode MODE into either "host" | |
436 | or "target". This is used mostly to translate from "auto" to the | |
437 | real setting that is being used. It returns the translated | |
438 | evaluation mode. */ | |
439 | ||
440 | static const char * | |
441 | translate_condition_evaluation_mode (const char *mode) | |
442 | { | |
443 | if (mode == condition_evaluation_auto) | |
444 | { | |
445 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
446 | return condition_evaluation_target; | |
447 | else | |
448 | return condition_evaluation_host; | |
449 | } | |
450 | else | |
451 | return mode; | |
452 | } | |
453 | ||
454 | /* Discovers what condition_evaluation_auto translates to. */ | |
455 | ||
456 | static const char * | |
457 | breakpoint_condition_evaluation_mode (void) | |
458 | { | |
459 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
460 | } | |
461 | ||
462 | /* Return true if GDB should evaluate breakpoint conditions or false | |
463 | otherwise. */ | |
464 | ||
465 | static int | |
466 | gdb_evaluates_breakpoint_condition_p (void) | |
467 | { | |
468 | const char *mode = breakpoint_condition_evaluation_mode (); | |
469 | ||
470 | return (mode == condition_evaluation_host); | |
471 | } | |
472 | ||
c906108c SS |
473 | /* Are we executing breakpoint commands? */ |
474 | static int executing_breakpoint_commands; | |
475 | ||
c02f5703 MS |
476 | /* Are overlay event breakpoints enabled? */ |
477 | static int overlay_events_enabled; | |
478 | ||
e09342b5 | 479 | /* See description in breakpoint.h. */ |
491144b5 | 480 | bool target_exact_watchpoints = false; |
e09342b5 | 481 | |
c906108c | 482 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 483 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 484 | current breakpoint. */ |
c906108c | 485 | |
5c44784c | 486 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 487 | |
5c44784c JM |
488 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
489 | for (B = breakpoint_chain; \ | |
490 | B ? (TMP=B->next, 1): 0; \ | |
491 | B = TMP) | |
c906108c | 492 | |
4a64f543 MS |
493 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
494 | not provided so update_global_location_list must not be called | |
495 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 496 | |
876fa593 | 497 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
498 | for (BP_TMP = bp_locations; \ |
499 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 500 | BP_TMP++) |
7cc221ef | 501 | |
b775012e LM |
502 | /* Iterates through locations with address ADDRESS for the currently selected |
503 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
504 | to where the loop should start from. | |
505 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
506 | appropriate location to start with. */ | |
507 | ||
508 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
509 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
510 | BP_LOCP_TMP = BP_LOCP_START; \ | |
511 | BP_LOCP_START \ | |
f5336ca5 | 512 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
513 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
514 | BP_LOCP_TMP++) | |
515 | ||
1042e4c0 SS |
516 | /* Iterator for tracepoints only. */ |
517 | ||
518 | #define ALL_TRACEPOINTS(B) \ | |
519 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 520 | if (is_tracepoint (B)) |
1042e4c0 | 521 | |
7cc221ef | 522 | /* Chains of all breakpoints defined. */ |
c906108c SS |
523 | |
524 | struct breakpoint *breakpoint_chain; | |
525 | ||
f5336ca5 | 526 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
876fa593 | 527 | |
f5336ca5 | 528 | static struct bp_location **bp_locations; |
876fa593 | 529 | |
f5336ca5 | 530 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 531 | |
f5336ca5 | 532 | static unsigned bp_locations_count; |
876fa593 | 533 | |
4a64f543 | 534 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 535 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 536 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 537 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 538 | an address you need to read. */ |
876fa593 | 539 | |
f5336ca5 | 540 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 541 | |
4a64f543 MS |
542 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
543 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
544 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
545 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 546 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 547 | |
f5336ca5 | 548 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 549 | |
4a64f543 | 550 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
551 | from the bp_locations array, but for which a hit may still be |
552 | reported by a target. */ | |
1123588c | 553 | static std::vector<bp_location *> moribund_locations; |
20874c92 | 554 | |
c906108c SS |
555 | /* Number of last breakpoint made. */ |
556 | ||
95a42b64 TT |
557 | static int breakpoint_count; |
558 | ||
86b17b60 PA |
559 | /* The value of `breakpoint_count' before the last command that |
560 | created breakpoints. If the last (break-like) command created more | |
561 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
562 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
563 | static int prev_breakpoint_count; | |
c906108c | 564 | |
1042e4c0 SS |
565 | /* Number of last tracepoint made. */ |
566 | ||
95a42b64 | 567 | static int tracepoint_count; |
1042e4c0 | 568 | |
6149aea9 PA |
569 | static struct cmd_list_element *breakpoint_set_cmdlist; |
570 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 571 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 572 | |
badd37ce SDJ |
573 | /* See declaration at breakpoint.h. */ |
574 | ||
575 | struct breakpoint * | |
576 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
577 | void *user_data) | |
578 | { | |
579 | struct breakpoint *b = NULL; | |
580 | ||
581 | ALL_BREAKPOINTS (b) | |
582 | { | |
583 | if (func (b, user_data) != 0) | |
584 | break; | |
585 | } | |
586 | ||
587 | return b; | |
588 | } | |
589 | ||
468d015d JJ |
590 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
591 | static int | |
592 | breakpoint_enabled (struct breakpoint *b) | |
593 | { | |
0d381245 | 594 | return (b->enable_state == bp_enabled); |
468d015d JJ |
595 | } |
596 | ||
c906108c SS |
597 | /* Set breakpoint count to NUM. */ |
598 | ||
95a42b64 | 599 | static void |
fba45db2 | 600 | set_breakpoint_count (int num) |
c906108c | 601 | { |
86b17b60 | 602 | prev_breakpoint_count = breakpoint_count; |
c906108c | 603 | breakpoint_count = num; |
4fa62494 | 604 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
605 | } |
606 | ||
86b17b60 PA |
607 | /* Used by `start_rbreak_breakpoints' below, to record the current |
608 | breakpoint count before "rbreak" creates any breakpoint. */ | |
609 | static int rbreak_start_breakpoint_count; | |
610 | ||
95a42b64 TT |
611 | /* Called at the start an "rbreak" command to record the first |
612 | breakpoint made. */ | |
86b17b60 | 613 | |
c80049d3 | 614 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
95a42b64 | 615 | { |
86b17b60 | 616 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
617 | } |
618 | ||
619 | /* Called at the end of an "rbreak" command to record the last | |
620 | breakpoint made. */ | |
86b17b60 | 621 | |
c80049d3 | 622 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
95a42b64 | 623 | { |
86b17b60 | 624 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
625 | } |
626 | ||
4a64f543 | 627 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
628 | |
629 | void | |
fba45db2 | 630 | clear_breakpoint_hit_counts (void) |
c906108c SS |
631 | { |
632 | struct breakpoint *b; | |
633 | ||
634 | ALL_BREAKPOINTS (b) | |
635 | b->hit_count = 0; | |
636 | } | |
637 | ||
c906108c | 638 | \f |
48cb2d85 VP |
639 | /* Return the breakpoint with the specified number, or NULL |
640 | if the number does not refer to an existing breakpoint. */ | |
641 | ||
642 | struct breakpoint * | |
643 | get_breakpoint (int num) | |
644 | { | |
645 | struct breakpoint *b; | |
646 | ||
647 | ALL_BREAKPOINTS (b) | |
648 | if (b->number == num) | |
649 | return b; | |
650 | ||
651 | return NULL; | |
652 | } | |
5c44784c | 653 | |
c906108c | 654 | \f |
adc36818 | 655 | |
b775012e LM |
656 | /* Mark locations as "conditions have changed" in case the target supports |
657 | evaluating conditions on its side. */ | |
658 | ||
659 | static void | |
660 | mark_breakpoint_modified (struct breakpoint *b) | |
661 | { | |
662 | struct bp_location *loc; | |
663 | ||
664 | /* This is only meaningful if the target is | |
665 | evaluating conditions and if the user has | |
666 | opted for condition evaluation on the target's | |
667 | side. */ | |
668 | if (gdb_evaluates_breakpoint_condition_p () | |
669 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
670 | return; | |
671 | ||
672 | if (!is_breakpoint (b)) | |
673 | return; | |
674 | ||
675 | for (loc = b->loc; loc; loc = loc->next) | |
676 | loc->condition_changed = condition_modified; | |
677 | } | |
678 | ||
679 | /* Mark location as "conditions have changed" in case the target supports | |
680 | evaluating conditions on its side. */ | |
681 | ||
682 | static void | |
683 | mark_breakpoint_location_modified (struct bp_location *loc) | |
684 | { | |
685 | /* This is only meaningful if the target is | |
686 | evaluating conditions and if the user has | |
687 | opted for condition evaluation on the target's | |
688 | side. */ | |
689 | if (gdb_evaluates_breakpoint_condition_p () | |
690 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
691 | ||
692 | return; | |
693 | ||
694 | if (!is_breakpoint (loc->owner)) | |
695 | return; | |
696 | ||
697 | loc->condition_changed = condition_modified; | |
698 | } | |
699 | ||
700 | /* Sets the condition-evaluation mode using the static global | |
701 | condition_evaluation_mode. */ | |
702 | ||
703 | static void | |
eb4c3f4a | 704 | set_condition_evaluation_mode (const char *args, int from_tty, |
b775012e LM |
705 | struct cmd_list_element *c) |
706 | { | |
b775012e LM |
707 | const char *old_mode, *new_mode; |
708 | ||
709 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
710 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
711 | { | |
712 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
713 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
714 | "Using host evaluation mode instead.")); | |
715 | return; | |
716 | } | |
717 | ||
718 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
719 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
720 | ||
abf1152a JK |
721 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
722 | settings was "auto". */ | |
723 | condition_evaluation_mode = condition_evaluation_mode_1; | |
724 | ||
b775012e LM |
725 | /* Only update the mode if the user picked a different one. */ |
726 | if (new_mode != old_mode) | |
727 | { | |
728 | struct bp_location *loc, **loc_tmp; | |
729 | /* If the user switched to a different evaluation mode, we | |
730 | need to synch the changes with the target as follows: | |
731 | ||
732 | "host" -> "target": Send all (valid) conditions to the target. | |
733 | "target" -> "host": Remove all the conditions from the target. | |
734 | */ | |
735 | ||
b775012e LM |
736 | if (new_mode == condition_evaluation_target) |
737 | { | |
738 | /* Mark everything modified and synch conditions with the | |
739 | target. */ | |
740 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
741 | mark_breakpoint_location_modified (loc); | |
742 | } | |
743 | else | |
744 | { | |
745 | /* Manually mark non-duplicate locations to synch conditions | |
746 | with the target. We do this to remove all the conditions the | |
747 | target knows about. */ | |
748 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
749 | if (is_breakpoint (loc->owner) && loc->inserted) | |
750 | loc->needs_update = 1; | |
751 | } | |
752 | ||
753 | /* Do the update. */ | |
44702360 | 754 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
755 | } |
756 | ||
757 | return; | |
758 | } | |
759 | ||
760 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
761 | what "auto" is translating to. */ | |
762 | ||
763 | static void | |
764 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
765 | struct cmd_list_element *c, const char *value) | |
766 | { | |
767 | if (condition_evaluation_mode == condition_evaluation_auto) | |
768 | fprintf_filtered (file, | |
769 | _("Breakpoint condition evaluation " | |
770 | "mode is %s (currently %s).\n"), | |
771 | value, | |
772 | breakpoint_condition_evaluation_mode ()); | |
773 | else | |
774 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
775 | value); | |
776 | } | |
777 | ||
778 | /* A comparison function for bp_location AP and BP that is used by | |
779 | bsearch. This comparison function only cares about addresses, unlike | |
f5336ca5 | 780 | the more general bp_locations_compare function. */ |
b775012e LM |
781 | |
782 | static int | |
f5336ca5 | 783 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 784 | { |
9a3c8263 SM |
785 | const struct bp_location *a = *(const struct bp_location **) ap; |
786 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
787 | |
788 | if (a->address == b->address) | |
789 | return 0; | |
790 | else | |
791 | return ((a->address > b->address) - (a->address < b->address)); | |
792 | } | |
793 | ||
794 | /* Helper function to skip all bp_locations with addresses | |
795 | less than ADDRESS. It returns the first bp_location that | |
796 | is greater than or equal to ADDRESS. If none is found, just | |
797 | return NULL. */ | |
798 | ||
799 | static struct bp_location ** | |
800 | get_first_locp_gte_addr (CORE_ADDR address) | |
801 | { | |
802 | struct bp_location dummy_loc; | |
803 | struct bp_location *dummy_locp = &dummy_loc; | |
804 | struct bp_location **locp_found = NULL; | |
805 | ||
806 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
807 | dummy_loc.address = address; |
808 | ||
809 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 810 | locp_found = ((struct bp_location **) |
f5336ca5 | 811 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 812 | sizeof (struct bp_location **), |
f5336ca5 | 813 | bp_locations_compare_addrs)); |
b775012e LM |
814 | |
815 | /* Nothing was found, nothing left to do. */ | |
816 | if (locp_found == NULL) | |
817 | return NULL; | |
818 | ||
819 | /* We may have found a location that is at ADDRESS but is not the first in the | |
820 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 821 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
822 | && (*(locp_found - 1))->address == address) |
823 | locp_found--; | |
824 | ||
825 | return locp_found; | |
826 | } | |
827 | ||
adc36818 | 828 | void |
7a26bd4d | 829 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
830 | int from_tty) |
831 | { | |
3a5c3e22 PA |
832 | xfree (b->cond_string); |
833 | b->cond_string = NULL; | |
adc36818 | 834 | |
3a5c3e22 | 835 | if (is_watchpoint (b)) |
adc36818 | 836 | { |
3a5c3e22 PA |
837 | struct watchpoint *w = (struct watchpoint *) b; |
838 | ||
4d01a485 | 839 | w->cond_exp.reset (); |
3a5c3e22 PA |
840 | } |
841 | else | |
842 | { | |
843 | struct bp_location *loc; | |
844 | ||
845 | for (loc = b->loc; loc; loc = loc->next) | |
846 | { | |
4d01a485 | 847 | loc->cond.reset (); |
b775012e LM |
848 | |
849 | /* No need to free the condition agent expression | |
850 | bytecode (if we have one). We will handle this | |
851 | when we go through update_global_location_list. */ | |
3a5c3e22 | 852 | } |
adc36818 | 853 | } |
adc36818 PM |
854 | |
855 | if (*exp == 0) | |
856 | { | |
857 | if (from_tty) | |
858 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
859 | } | |
860 | else | |
861 | { | |
bbc13ae3 | 862 | const char *arg = exp; |
cc59ec59 | 863 | |
adc36818 PM |
864 | /* I don't know if it matters whether this is the string the user |
865 | typed in or the decompiled expression. */ | |
866 | b->cond_string = xstrdup (arg); | |
867 | b->condition_not_parsed = 0; | |
868 | ||
869 | if (is_watchpoint (b)) | |
870 | { | |
3a5c3e22 PA |
871 | struct watchpoint *w = (struct watchpoint *) b; |
872 | ||
699bd4cf | 873 | innermost_block_tracker tracker; |
adc36818 | 874 | arg = exp; |
699bd4cf | 875 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
adc36818 PM |
876 | if (*arg) |
877 | error (_("Junk at end of expression")); | |
699bd4cf | 878 | w->cond_exp_valid_block = tracker.block (); |
adc36818 PM |
879 | } |
880 | else | |
881 | { | |
3a5c3e22 PA |
882 | struct bp_location *loc; |
883 | ||
adc36818 PM |
884 | for (loc = b->loc; loc; loc = loc->next) |
885 | { | |
886 | arg = exp; | |
887 | loc->cond = | |
1bb9788d TT |
888 | parse_exp_1 (&arg, loc->address, |
889 | block_for_pc (loc->address), 0); | |
adc36818 PM |
890 | if (*arg) |
891 | error (_("Junk at end of expression")); | |
892 | } | |
893 | } | |
894 | } | |
b775012e LM |
895 | mark_breakpoint_modified (b); |
896 | ||
76727919 | 897 | gdb::observers::breakpoint_modified.notify (b); |
adc36818 PM |
898 | } |
899 | ||
d55637df TT |
900 | /* Completion for the "condition" command. */ |
901 | ||
eb3ff9a5 | 902 | static void |
6f937416 | 903 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 904 | completion_tracker &tracker, |
6f937416 | 905 | const char *text, const char *word) |
d55637df | 906 | { |
6f937416 | 907 | const char *space; |
d55637df | 908 | |
f1735a53 TT |
909 | text = skip_spaces (text); |
910 | space = skip_to_space (text); | |
d55637df TT |
911 | if (*space == '\0') |
912 | { | |
913 | int len; | |
914 | struct breakpoint *b; | |
d55637df TT |
915 | |
916 | if (text[0] == '$') | |
917 | { | |
918 | /* We don't support completion of history indices. */ | |
eb3ff9a5 PA |
919 | if (!isdigit (text[1])) |
920 | complete_internalvar (tracker, &text[1]); | |
921 | return; | |
d55637df TT |
922 | } |
923 | ||
924 | /* We're completing the breakpoint number. */ | |
925 | len = strlen (text); | |
926 | ||
927 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
928 | { |
929 | char number[50]; | |
930 | ||
931 | xsnprintf (number, sizeof (number), "%d", b->number); | |
932 | ||
933 | if (strncmp (number, text, len) == 0) | |
b02f78f9 | 934 | tracker.add_completion (make_unique_xstrdup (number)); |
58ce7251 | 935 | } |
d55637df | 936 | |
eb3ff9a5 | 937 | return; |
d55637df TT |
938 | } |
939 | ||
940 | /* We're completing the expression part. */ | |
f1735a53 | 941 | text = skip_spaces (space); |
eb3ff9a5 | 942 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
943 | } |
944 | ||
c906108c SS |
945 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
946 | ||
947 | static void | |
0b39b52e | 948 | condition_command (const char *arg, int from_tty) |
c906108c | 949 | { |
52f0bd74 | 950 | struct breakpoint *b; |
0b39b52e | 951 | const char *p; |
52f0bd74 | 952 | int bnum; |
c906108c SS |
953 | |
954 | if (arg == 0) | |
e2e0b3e5 | 955 | error_no_arg (_("breakpoint number")); |
c906108c SS |
956 | |
957 | p = arg; | |
958 | bnum = get_number (&p); | |
5c44784c | 959 | if (bnum == 0) |
8a3fe4f8 | 960 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
961 | |
962 | ALL_BREAKPOINTS (b) | |
963 | if (b->number == bnum) | |
2f069f6f | 964 | { |
6dddc817 DE |
965 | /* Check if this breakpoint has a "stop" method implemented in an |
966 | extension language. This method and conditions entered into GDB | |
967 | from the CLI are mutually exclusive. */ | |
968 | const struct extension_language_defn *extlang | |
969 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
970 | ||
971 | if (extlang != NULL) | |
972 | { | |
973 | error (_("Only one stop condition allowed. There is currently" | |
974 | " a %s stop condition defined for this breakpoint."), | |
975 | ext_lang_capitalized_name (extlang)); | |
976 | } | |
2566ad2d | 977 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
978 | |
979 | if (is_breakpoint (b)) | |
44702360 | 980 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 981 | |
2f069f6f JB |
982 | return; |
983 | } | |
c906108c | 984 | |
8a3fe4f8 | 985 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
986 | } |
987 | ||
a7bdde9e VP |
988 | /* Check that COMMAND do not contain commands that are suitable |
989 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
990 | Throw if any such commands is found. */ |
991 | ||
a7bdde9e VP |
992 | static void |
993 | check_no_tracepoint_commands (struct command_line *commands) | |
994 | { | |
995 | struct command_line *c; | |
cc59ec59 | 996 | |
a7bdde9e VP |
997 | for (c = commands; c; c = c->next) |
998 | { | |
a7bdde9e | 999 | if (c->control_type == while_stepping_control) |
3e43a32a MS |
1000 | error (_("The 'while-stepping' command can " |
1001 | "only be used for tracepoints")); | |
a7bdde9e | 1002 | |
12973681 TT |
1003 | check_no_tracepoint_commands (c->body_list_0.get ()); |
1004 | check_no_tracepoint_commands (c->body_list_1.get ()); | |
a7bdde9e VP |
1005 | |
1006 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1007 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1008 | command directly. */ |
1009 | if (strstr (c->line, "collect ") == c->line) | |
1010 | error (_("The 'collect' command can only be used for tracepoints")); | |
1011 | ||
51661e93 VP |
1012 | if (strstr (c->line, "teval ") == c->line) |
1013 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1014 | } |
1015 | } | |
1016 | ||
c1fc2657 | 1017 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1018 | { |
c1fc2657 | 1019 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1020 | }; |
1021 | ||
d77f58be SS |
1022 | /* Encapsulate tests for different types of tracepoints. */ |
1023 | ||
3b0871f4 SM |
1024 | static bool |
1025 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1026 | { |
1027 | return (type == bp_tracepoint | |
1028 | || type == bp_fast_tracepoint | |
1029 | || type == bp_static_tracepoint); | |
1030 | } | |
1031 | ||
3b0871f4 SM |
1032 | static bool |
1033 | is_longjmp_type (bptype type) | |
1034 | { | |
1035 | return type == bp_longjmp || type == bp_exception; | |
1036 | } | |
1037 | ||
f2478a7e SM |
1038 | /* See breakpoint.h. */ |
1039 | ||
1040 | bool | |
d77f58be | 1041 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1042 | { |
d9b3f62e | 1043 | return is_tracepoint_type (b->type); |
a7bdde9e | 1044 | } |
d9b3f62e | 1045 | |
a5e364af SM |
1046 | /* Factory function to create an appropriate instance of breakpoint given |
1047 | TYPE. */ | |
1048 | ||
1049 | static std::unique_ptr<breakpoint> | |
1050 | new_breakpoint_from_type (bptype type) | |
1051 | { | |
1052 | breakpoint *b; | |
1053 | ||
1054 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1055 | b = new tracepoint (); |
3b0871f4 | 1056 | else if (is_longjmp_type (type)) |
c1fc2657 | 1057 | b = new longjmp_breakpoint (); |
a5e364af SM |
1058 | else |
1059 | b = new breakpoint (); | |
1060 | ||
1061 | return std::unique_ptr<breakpoint> (b); | |
1062 | } | |
1063 | ||
e5dd4106 | 1064 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1065 | breakpoint. This function will throw an exception if a problem is |
1066 | found. */ | |
48cb2d85 | 1067 | |
95a42b64 TT |
1068 | static void |
1069 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1070 | struct command_line *commands) | |
48cb2d85 | 1071 | { |
d77f58be | 1072 | if (is_tracepoint (b)) |
a7bdde9e | 1073 | { |
c9a6ce02 | 1074 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1075 | struct command_line *c; |
1076 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1077 | |
1078 | /* Reset the while-stepping step count. The previous commands | |
1079 | might have included a while-stepping action, while the new | |
1080 | ones might not. */ | |
1081 | t->step_count = 0; | |
1082 | ||
1083 | /* We need to verify that each top-level element of commands is | |
1084 | valid for tracepoints, that there's at most one | |
1085 | while-stepping element, and that the while-stepping's body | |
1086 | has valid tracing commands excluding nested while-stepping. | |
1087 | We also need to validate the tracepoint action line in the | |
1088 | context of the tracepoint --- validate_actionline actually | |
1089 | has side effects, like setting the tracepoint's | |
1090 | while-stepping STEP_COUNT, in addition to checking if the | |
1091 | collect/teval actions parse and make sense in the | |
1092 | tracepoint's context. */ | |
a7bdde9e VP |
1093 | for (c = commands; c; c = c->next) |
1094 | { | |
a7bdde9e VP |
1095 | if (c->control_type == while_stepping_control) |
1096 | { | |
1097 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1098 | error (_("The 'while-stepping' command " |
1099 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1100 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1101 | error (_("The 'while-stepping' command " |
1102 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1103 | |
1104 | if (while_stepping) | |
3e43a32a MS |
1105 | error (_("The 'while-stepping' command " |
1106 | "can be used only once")); | |
a7bdde9e VP |
1107 | else |
1108 | while_stepping = c; | |
1109 | } | |
c9a6ce02 PA |
1110 | |
1111 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1112 | } |
1113 | if (while_stepping) | |
1114 | { | |
1115 | struct command_line *c2; | |
1116 | ||
12973681 TT |
1117 | gdb_assert (while_stepping->body_list_1 == nullptr); |
1118 | c2 = while_stepping->body_list_0.get (); | |
a7bdde9e VP |
1119 | for (; c2; c2 = c2->next) |
1120 | { | |
a7bdde9e VP |
1121 | if (c2->control_type == while_stepping_control) |
1122 | error (_("The 'while-stepping' command cannot be nested")); | |
1123 | } | |
1124 | } | |
1125 | } | |
1126 | else | |
1127 | { | |
1128 | check_no_tracepoint_commands (commands); | |
1129 | } | |
95a42b64 TT |
1130 | } |
1131 | ||
0fb4aa4b PA |
1132 | /* Return a vector of all the static tracepoints set at ADDR. The |
1133 | caller is responsible for releasing the vector. */ | |
1134 | ||
f51e0e20 | 1135 | std::vector<breakpoint *> |
0fb4aa4b PA |
1136 | static_tracepoints_here (CORE_ADDR addr) |
1137 | { | |
1138 | struct breakpoint *b; | |
f51e0e20 | 1139 | std::vector<breakpoint *> found; |
0fb4aa4b PA |
1140 | struct bp_location *loc; |
1141 | ||
1142 | ALL_BREAKPOINTS (b) | |
1143 | if (b->type == bp_static_tracepoint) | |
1144 | { | |
1145 | for (loc = b->loc; loc; loc = loc->next) | |
1146 | if (loc->address == addr) | |
f51e0e20 | 1147 | found.push_back (b); |
0fb4aa4b PA |
1148 | } |
1149 | ||
1150 | return found; | |
1151 | } | |
1152 | ||
95a42b64 | 1153 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1154 | validate that only allowed commands are included. */ |
95a42b64 TT |
1155 | |
1156 | void | |
4a64f543 | 1157 | breakpoint_set_commands (struct breakpoint *b, |
12973681 | 1158 | counted_command_line &&commands) |
95a42b64 | 1159 | { |
93921405 | 1160 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1161 | |
d1b0a7bf | 1162 | b->commands = std::move (commands); |
76727919 | 1163 | gdb::observers::breakpoint_modified.notify (b); |
48cb2d85 VP |
1164 | } |
1165 | ||
45a43567 TT |
1166 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1167 | is not the same as the "silent" that may appear in the breakpoint's | |
1168 | commands. */ | |
1169 | ||
1170 | void | |
1171 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1172 | { | |
1173 | int old_silent = b->silent; | |
1174 | ||
1175 | b->silent = silent; | |
1176 | if (old_silent != silent) | |
76727919 | 1177 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1178 | } |
1179 | ||
1180 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1181 | breakpoint work for any thread. */ | |
1182 | ||
1183 | void | |
1184 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1185 | { | |
1186 | int old_thread = b->thread; | |
1187 | ||
1188 | b->thread = thread; | |
1189 | if (old_thread != thread) | |
76727919 | 1190 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1191 | } |
1192 | ||
1193 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1194 | breakpoint work for any task. */ | |
1195 | ||
1196 | void | |
1197 | breakpoint_set_task (struct breakpoint *b, int task) | |
1198 | { | |
1199 | int old_task = b->task; | |
1200 | ||
1201 | b->task = task; | |
1202 | if (old_task != task) | |
76727919 | 1203 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1204 | } |
1205 | ||
95a42b64 | 1206 | static void |
896b6bda | 1207 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1208 | struct command_line *control) |
95a42b64 | 1209 | { |
d1b0a7bf | 1210 | counted_command_line cmd; |
999700cd PW |
1211 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
1212 | NULL after the call to read_command_lines if the user provides an empty | |
1213 | list of command by just typing "end". */ | |
1214 | bool cmd_read = false; | |
95a42b64 | 1215 | |
896b6bda PA |
1216 | std::string new_arg; |
1217 | ||
95a42b64 TT |
1218 | if (arg == NULL || !*arg) |
1219 | { | |
86b17b60 | 1220 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1221 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1222 | breakpoint_count); | |
95a42b64 | 1223 | else if (breakpoint_count > 0) |
896b6bda | 1224 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b TT |
1225 | arg = new_arg.c_str (); |
1226 | } | |
1227 | ||
1228 | map_breakpoint_numbers | |
1229 | (arg, [&] (breakpoint *b) | |
1230 | { | |
999700cd | 1231 | if (!cmd_read) |
48649e1b | 1232 | { |
999700cd | 1233 | gdb_assert (cmd == NULL); |
48649e1b | 1234 | if (control != NULL) |
12973681 | 1235 | cmd = control->body_list_0; |
48649e1b TT |
1236 | else |
1237 | { | |
81b1e71c TT |
1238 | std::string str |
1239 | = string_printf (_("Type commands for breakpoint(s) " | |
1240 | "%s, one per line."), | |
1241 | arg); | |
48649e1b | 1242 | |
60b3cef2 TT |
1243 | auto do_validate = [=] (const char *line) |
1244 | { | |
1245 | validate_actionline (line, b); | |
1246 | }; | |
1247 | gdb::function_view<void (const char *)> validator; | |
1248 | if (is_tracepoint (b)) | |
1249 | validator = do_validate; | |
1250 | ||
1251 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); | |
48649e1b | 1252 | } |
999700cd | 1253 | cmd_read = true; |
48649e1b TT |
1254 | } |
1255 | ||
1256 | /* If a breakpoint was on the list more than once, we don't need to | |
1257 | do anything. */ | |
1258 | if (b->commands != cmd) | |
1259 | { | |
d1b0a7bf | 1260 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b | 1261 | b->commands = cmd; |
76727919 | 1262 | gdb::observers::breakpoint_modified.notify (b); |
48649e1b TT |
1263 | } |
1264 | }); | |
95a42b64 TT |
1265 | } |
1266 | ||
1267 | static void | |
0b39b52e | 1268 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1269 | { |
1270 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1271 | } |
40c03ae8 EZ |
1272 | |
1273 | /* Like commands_command, but instead of reading the commands from | |
1274 | input stream, takes them from an already parsed command structure. | |
1275 | ||
1276 | This is used by cli-script.c to DTRT with breakpoint commands | |
1277 | that are part of if and while bodies. */ | |
1278 | enum command_control_type | |
896b6bda | 1279 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1280 | { |
95a42b64 TT |
1281 | commands_command_1 (arg, 0, cmd); |
1282 | return simple_control; | |
40c03ae8 | 1283 | } |
876fa593 JK |
1284 | |
1285 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1286 | ||
1287 | static int | |
1288 | bp_location_has_shadow (struct bp_location *bl) | |
1289 | { | |
1290 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1291 | return 0; | |
1292 | if (!bl->inserted) | |
1293 | return 0; | |
1294 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1295 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1296 | return 0; |
1297 | return 1; | |
1298 | } | |
1299 | ||
9d497a19 PA |
1300 | /* Update BUF, which is LEN bytes read from the target address |
1301 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1302 | contents. | |
1303 | ||
1304 | If READBUF is not NULL, this buffer must not overlap with the of | |
1305 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1306 | failed assertion internal error will be raised. */ | |
1307 | ||
1308 | static void | |
1309 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1310 | const gdb_byte *writebuf_org, | |
1311 | ULONGEST memaddr, LONGEST len, | |
1312 | struct bp_target_info *target_info, | |
1313 | struct gdbarch *gdbarch) | |
1314 | { | |
1315 | /* Now do full processing of the found relevant range of elements. */ | |
1316 | CORE_ADDR bp_addr = 0; | |
1317 | int bp_size = 0; | |
1318 | int bptoffset = 0; | |
1319 | ||
1320 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1321 | current_program_space->aspace, 0)) | |
1322 | { | |
1323 | /* The breakpoint is inserted in a different address space. */ | |
1324 | return; | |
1325 | } | |
1326 | ||
1327 | /* Addresses and length of the part of the breakpoint that | |
1328 | we need to copy. */ | |
1329 | bp_addr = target_info->placed_address; | |
1330 | bp_size = target_info->shadow_len; | |
1331 | ||
1332 | if (bp_addr + bp_size <= memaddr) | |
1333 | { | |
1334 | /* The breakpoint is entirely before the chunk of memory we are | |
1335 | reading. */ | |
1336 | return; | |
1337 | } | |
1338 | ||
1339 | if (bp_addr >= memaddr + len) | |
1340 | { | |
1341 | /* The breakpoint is entirely after the chunk of memory we are | |
1342 | reading. */ | |
1343 | return; | |
1344 | } | |
1345 | ||
1346 | /* Offset within shadow_contents. */ | |
1347 | if (bp_addr < memaddr) | |
1348 | { | |
1349 | /* Only copy the second part of the breakpoint. */ | |
1350 | bp_size -= memaddr - bp_addr; | |
1351 | bptoffset = memaddr - bp_addr; | |
1352 | bp_addr = memaddr; | |
1353 | } | |
1354 | ||
1355 | if (bp_addr + bp_size > memaddr + len) | |
1356 | { | |
1357 | /* Only copy the first part of the breakpoint. */ | |
1358 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1359 | } | |
1360 | ||
1361 | if (readbuf != NULL) | |
1362 | { | |
1363 | /* Verify that the readbuf buffer does not overlap with the | |
1364 | shadow_contents buffer. */ | |
1365 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1366 | || readbuf >= (target_info->shadow_contents | |
1367 | + target_info->shadow_len)); | |
1368 | ||
1369 | /* Update the read buffer with this inserted breakpoint's | |
1370 | shadow. */ | |
1371 | memcpy (readbuf + bp_addr - memaddr, | |
1372 | target_info->shadow_contents + bptoffset, bp_size); | |
1373 | } | |
1374 | else | |
1375 | { | |
1376 | const unsigned char *bp; | |
0d5ed153 MR |
1377 | CORE_ADDR addr = target_info->reqstd_address; |
1378 | int placed_size; | |
9d497a19 PA |
1379 | |
1380 | /* Update the shadow with what we want to write to memory. */ | |
1381 | memcpy (target_info->shadow_contents + bptoffset, | |
1382 | writebuf_org + bp_addr - memaddr, bp_size); | |
1383 | ||
1384 | /* Determine appropriate breakpoint contents and size for this | |
1385 | address. */ | |
0d5ed153 | 1386 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1387 | |
1388 | /* Update the final write buffer with this inserted | |
1389 | breakpoint's INSN. */ | |
1390 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1391 | } | |
1392 | } | |
1393 | ||
8defab1a | 1394 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1395 | by replacing any memory breakpoints with their shadowed contents. |
1396 | ||
35c63cd8 JB |
1397 | If READBUF is not NULL, this buffer must not overlap with any of |
1398 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1399 | a failed assertion internal error will be raised. | |
1400 | ||
876fa593 | 1401 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1402 | bl->address - bp_locations_placed_address_before_address_max |
1403 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1404 | The range we were requested to resolve shadows for is: |
1405 | memaddr ... memaddr + len | |
1406 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1407 | memaddr + len <= (bl->address |
f5336ca5 | 1408 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1409 | and: |
f5336ca5 | 1410 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1411 | |
8defab1a | 1412 | void |
f0ba3972 PA |
1413 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1414 | const gdb_byte *writebuf_org, | |
1415 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1416 | { |
4a64f543 MS |
1417 | /* Left boundary, right boundary and median element of our binary |
1418 | search. */ | |
876fa593 JK |
1419 | unsigned bc_l, bc_r, bc; |
1420 | ||
4a64f543 MS |
1421 | /* Find BC_L which is a leftmost element which may affect BUF |
1422 | content. It is safe to report lower value but a failure to | |
1423 | report higher one. */ | |
876fa593 JK |
1424 | |
1425 | bc_l = 0; | |
f5336ca5 | 1426 | bc_r = bp_locations_count; |
876fa593 JK |
1427 | while (bc_l + 1 < bc_r) |
1428 | { | |
35df4500 | 1429 | struct bp_location *bl; |
876fa593 JK |
1430 | |
1431 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1432 | bl = bp_locations[bc]; |
876fa593 | 1433 | |
4a64f543 MS |
1434 | /* Check first BL->ADDRESS will not overflow due to the added |
1435 | constant. Then advance the left boundary only if we are sure | |
1436 | the BC element can in no way affect the BUF content (MEMADDR | |
1437 | to MEMADDR + LEN range). | |
876fa593 | 1438 | |
f5336ca5 | 1439 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1440 | offset so that we cannot miss a breakpoint with its shadow |
1441 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1442 | |
f5336ca5 | 1443 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1444 | >= bl->address) |
f5336ca5 | 1445 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1446 | <= memaddr)) |
876fa593 JK |
1447 | bc_l = bc; |
1448 | else | |
1449 | bc_r = bc; | |
1450 | } | |
1451 | ||
128070bb PA |
1452 | /* Due to the binary search above, we need to make sure we pick the |
1453 | first location that's at BC_L's address. E.g., if there are | |
1454 | multiple locations at the same address, BC_L may end up pointing | |
1455 | at a duplicate location, and miss the "master"/"inserted" | |
1456 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1457 | B: | |
1458 | ||
1459 | L1@A, L2@A, L3@B, ... | |
1460 | ||
1461 | BC_L could end up pointing at location L2, while the "master" | |
1462 | location could be L1. Since the `loc->inserted' flag is only set | |
1463 | on "master" locations, we'd forget to restore the shadow of L1 | |
1464 | and L2. */ | |
1465 | while (bc_l > 0 | |
f5336ca5 | 1466 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1467 | bc_l--; |
1468 | ||
876fa593 JK |
1469 | /* Now do full processing of the found relevant range of elements. */ |
1470 | ||
f5336ca5 | 1471 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1472 | { |
f5336ca5 | 1473 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1474 | |
35df4500 TJB |
1475 | /* bp_location array has BL->OWNER always non-NULL. */ |
1476 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1477 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1478 | bl->owner->number); |
ffce0d52 | 1479 | |
e5dd4106 | 1480 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1481 | content. */ |
1482 | ||
f5336ca5 PA |
1483 | if (bl->address >= bp_locations_placed_address_before_address_max |
1484 | && memaddr + len <= (bl->address | |
1485 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1486 | break; |
1487 | ||
35df4500 | 1488 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1489 | continue; |
6c95b8df | 1490 | |
9d497a19 PA |
1491 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1492 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1493 | } | |
c906108c | 1494 | } |
9d497a19 | 1495 | |
f2478a7e | 1496 | /* See breakpoint.h. */ |
b775012e | 1497 | |
f2478a7e | 1498 | bool |
b775012e LM |
1499 | is_breakpoint (const struct breakpoint *bpt) |
1500 | { | |
1501 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1502 | || bpt->type == bp_hardware_breakpoint |
1503 | || bpt->type == bp_dprintf); | |
b775012e LM |
1504 | } |
1505 | ||
60e1c644 PA |
1506 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1507 | ||
f2478a7e | 1508 | static bool |
d77f58be | 1509 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1510 | { |
1511 | return (bpt->type == bp_hardware_watchpoint | |
1512 | || bpt->type == bp_read_watchpoint | |
1513 | || bpt->type == bp_access_watchpoint); | |
1514 | } | |
7270d8f2 | 1515 | |
f2478a7e | 1516 | /* See breakpoint.h. */ |
60e1c644 | 1517 | |
f2478a7e | 1518 | bool |
d77f58be | 1519 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1520 | { |
1521 | return (is_hardware_watchpoint (bpt) | |
1522 | || bpt->type == bp_watchpoint); | |
1523 | } | |
1524 | ||
3a5c3e22 PA |
1525 | /* Returns true if the current thread and its running state are safe |
1526 | to evaluate or update watchpoint B. Watchpoints on local | |
1527 | expressions need to be evaluated in the context of the thread that | |
1528 | was current when the watchpoint was created, and, that thread needs | |
1529 | to be stopped to be able to select the correct frame context. | |
1530 | Watchpoints on global expressions can be evaluated on any thread, | |
1531 | and in any state. It is presently left to the target allowing | |
1532 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1533 | |
1534 | static int | |
3a5c3e22 | 1535 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1536 | { |
c1fc2657 | 1537 | return (b->pspace == current_program_space |
d7e15655 TT |
1538 | && (b->watchpoint_thread == null_ptid |
1539 | || (inferior_ptid == b->watchpoint_thread | |
00431a78 | 1540 | && !inferior_thread ()->executing))); |
f6bc2008 PA |
1541 | } |
1542 | ||
d0fb5eae JK |
1543 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1544 | associated bp_watchpoint_scope breakpoint. */ | |
1545 | ||
1546 | static void | |
3a5c3e22 | 1547 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1548 | { |
c1fc2657 | 1549 | if (w->related_breakpoint != w) |
d0fb5eae | 1550 | { |
c1fc2657 SM |
1551 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1552 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1553 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1554 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1555 | w->related_breakpoint = w; | |
d0fb5eae | 1556 | } |
c1fc2657 | 1557 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1558 | } |
1559 | ||
bb9d5f81 PP |
1560 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1561 | watchpoint W. */ | |
1562 | ||
1563 | static struct value * | |
1564 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1565 | { | |
1566 | struct value *bit_val; | |
1567 | ||
1568 | if (val == NULL) | |
1569 | return NULL; | |
1570 | ||
1571 | bit_val = allocate_value (value_type (val)); | |
1572 | ||
1573 | unpack_value_bitfield (bit_val, | |
1574 | w->val_bitpos, | |
1575 | w->val_bitsize, | |
1576 | value_contents_for_printing (val), | |
1577 | value_offset (val), | |
1578 | val); | |
1579 | ||
1580 | return bit_val; | |
1581 | } | |
1582 | ||
c6d81124 PA |
1583 | /* Allocate a dummy location and add it to B, which must be a software |
1584 | watchpoint. This is required because even if a software watchpoint | |
1585 | is not watching any memory, bpstat_stop_status requires a location | |
1586 | to be able to report stops. */ | |
1587 | ||
1588 | static void | |
1589 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1590 | struct program_space *pspace) | |
1591 | { | |
1592 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1593 | ||
1594 | b->loc = allocate_bp_location (b); | |
1595 | b->loc->pspace = pspace; | |
1596 | b->loc->address = -1; | |
1597 | b->loc->length = -1; | |
1598 | } | |
1599 | ||
1600 | /* Returns true if B is a software watchpoint that is not watching any | |
1601 | memory (e.g., "watch $pc"). */ | |
1602 | ||
f2478a7e | 1603 | static bool |
c6d81124 PA |
1604 | is_no_memory_software_watchpoint (struct breakpoint *b) |
1605 | { | |
1606 | return (b->type == bp_watchpoint | |
1607 | && b->loc != NULL | |
1608 | && b->loc->next == NULL | |
1609 | && b->loc->address == -1 | |
1610 | && b->loc->length == -1); | |
1611 | } | |
1612 | ||
567e1b4e JB |
1613 | /* Assuming that B is a watchpoint: |
1614 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1615 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1616 | - Evaluate the condition if there is one, and store the result |
1617 | in b->loc->cond. | |
a5606eee VP |
1618 | - Update the list of values that must be watched in B->loc. |
1619 | ||
4a64f543 MS |
1620 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1621 | nothing. If this is local watchpoint that is out of scope, delete | |
1622 | it. | |
1623 | ||
1624 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1625 | removed + inserted on each stop here. Normal breakpoints must | |
1626 | never be removed because they might be missed by a running thread | |
1627 | when debugging in non-stop mode. On the other hand, hardware | |
1628 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1629 | to each LWP since they are stored in each LWP's hardware debug | |
1630 | registers. Therefore, such LWP must be stopped first in order to | |
1631 | be able to modify its hardware watchpoints. | |
1632 | ||
1633 | Hardware watchpoints must be reset exactly once after being | |
1634 | presented to the user. It cannot be done sooner, because it would | |
1635 | reset the data used to present the watchpoint hit to the user. And | |
1636 | it must not be done later because it could display the same single | |
1637 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1638 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1639 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1640 | not user-visible - its hit is suppressed if the memory content has | |
1641 | not changed. | |
1642 | ||
1643 | The following constraints influence the location where we can reset | |
1644 | hardware watchpoints: | |
1645 | ||
1646 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1647 | called several times when GDB stops. | |
1648 | ||
1649 | [linux] | |
1650 | * Multiple hardware watchpoints can be hit at the same time, | |
1651 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1652 | hit at a time as the reason for stopping, and all the other hits | |
1653 | are presented later, one after the other, each time the user | |
1654 | requests the execution to be resumed. Execution is not resumed | |
1655 | for the threads still having pending hit event stored in | |
1656 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1657 | the inferior on the first stop the thread hit event is kept being | |
1658 | reported from its cached value by linux_nat_stopped_data_address | |
1659 | until the real thread resume happens after the watchpoint gets | |
1660 | presented and thus its LWP_INFO->STATUS gets reset. | |
1661 | ||
1662 | Therefore the hardware watchpoint hit can get safely reset on the | |
1663 | watchpoint removal from inferior. */ | |
a79d3c27 | 1664 | |
b40ce68a | 1665 | static void |
3a5c3e22 | 1666 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1667 | { |
a5606eee | 1668 | int within_current_scope; |
a5606eee | 1669 | struct frame_id saved_frame_id; |
66076460 | 1670 | int frame_saved; |
a5606eee | 1671 | |
f6bc2008 PA |
1672 | /* If this is a local watchpoint, we only want to check if the |
1673 | watchpoint frame is in scope if the current thread is the thread | |
1674 | that was used to create the watchpoint. */ | |
1675 | if (!watchpoint_in_thread_scope (b)) | |
1676 | return; | |
1677 | ||
c1fc2657 | 1678 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1679 | return; |
1680 | ||
66076460 | 1681 | frame_saved = 0; |
a5606eee VP |
1682 | |
1683 | /* Determine if the watchpoint is within scope. */ | |
1684 | if (b->exp_valid_block == NULL) | |
1685 | within_current_scope = 1; | |
1686 | else | |
1687 | { | |
b5db5dfc UW |
1688 | struct frame_info *fi = get_current_frame (); |
1689 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1690 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1691 | ||
c9cf6e20 MG |
1692 | /* If we're at a point where the stack has been destroyed |
1693 | (e.g. in a function epilogue), unwinding may not work | |
1694 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1695 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1696 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1697 | return; |
66076460 DJ |
1698 | |
1699 | /* Save the current frame's ID so we can restore it after | |
1700 | evaluating the watchpoint expression on its own frame. */ | |
1701 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1702 | took a frame parameter, so that we didn't have to change the | |
1703 | selected frame. */ | |
1704 | frame_saved = 1; | |
1705 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1706 | ||
a5606eee VP |
1707 | fi = frame_find_by_id (b->watchpoint_frame); |
1708 | within_current_scope = (fi != NULL); | |
1709 | if (within_current_scope) | |
1710 | select_frame (fi); | |
1711 | } | |
1712 | ||
b5db5dfc UW |
1713 | /* We don't free locations. They are stored in the bp_location array |
1714 | and update_global_location_list will eventually delete them and | |
1715 | remove breakpoints if needed. */ | |
c1fc2657 | 1716 | b->loc = NULL; |
b5db5dfc | 1717 | |
a5606eee VP |
1718 | if (within_current_scope && reparse) |
1719 | { | |
bbc13ae3 | 1720 | const char *s; |
d63d0675 | 1721 | |
4d01a485 | 1722 | b->exp.reset (); |
d63d0675 | 1723 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1724 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1725 | /* If the meaning of expression itself changed, the old value is |
1726 | no longer relevant. We don't want to report a watchpoint hit | |
1727 | to the user when the old value and the new value may actually | |
1728 | be completely different objects. */ | |
fa4727a6 | 1729 | b->val = NULL; |
4c1d86d9 | 1730 | b->val_valid = false; |
60e1c644 PA |
1731 | |
1732 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1733 | expression is stored in the breakpoint object, not in the | |
1734 | locations (re)created below. */ | |
c1fc2657 | 1735 | if (b->cond_string != NULL) |
60e1c644 | 1736 | { |
4d01a485 | 1737 | b->cond_exp.reset (); |
60e1c644 | 1738 | |
c1fc2657 | 1739 | s = b->cond_string; |
1bb9788d | 1740 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1741 | } |
a5606eee | 1742 | } |
a5606eee VP |
1743 | |
1744 | /* If we failed to parse the expression, for example because | |
1745 | it refers to a global variable in a not-yet-loaded shared library, | |
1746 | don't try to insert watchpoint. We don't automatically delete | |
1747 | such watchpoint, though, since failure to parse expression | |
1748 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1749 | if (!target_has_execution) |
2d134ed3 PA |
1750 | { |
1751 | /* Without execution, memory can't change. No use to try and | |
1752 | set watchpoint locations. The watchpoint will be reset when | |
1753 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1754 | if (!can_use_hw_watchpoints) |
1755 | { | |
c1fc2657 SM |
1756 | if (b->ops->works_in_software_mode (b)) |
1757 | b->type = bp_watchpoint; | |
e8369a73 | 1758 | else |
638aa5a1 AB |
1759 | error (_("Can't set read/access watchpoint when " |
1760 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1761 | } |
2d134ed3 PA |
1762 | } |
1763 | else if (within_current_scope && b->exp) | |
a5606eee | 1764 | { |
0cf6dd15 | 1765 | int pc = 0; |
a6535de1 | 1766 | std::vector<value_ref_ptr> val_chain; |
8d49165d | 1767 | struct value *v, *result; |
2d134ed3 | 1768 | struct program_space *frame_pspace; |
a5606eee | 1769 | |
4d01a485 | 1770 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1771 | |
a5606eee VP |
1772 | /* Avoid setting b->val if it's already set. The meaning of |
1773 | b->val is 'the last value' user saw, and we should update | |
1774 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1775 | happens, the code that reports it updates b->val directly. |
1776 | We don't keep track of the memory value for masked | |
1777 | watchpoints. */ | |
c1fc2657 | 1778 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1779 | { |
bb9d5f81 | 1780 | if (b->val_bitsize != 0) |
850645cf TT |
1781 | v = extract_bitfield_from_watchpoint_value (b, v); |
1782 | b->val = release_value (v); | |
4c1d86d9 | 1783 | b->val_valid = true; |
fa4727a6 | 1784 | } |
a5606eee | 1785 | |
2d134ed3 PA |
1786 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1787 | ||
a5606eee | 1788 | /* Look at each value on the value chain. */ |
a6535de1 TT |
1789 | gdb_assert (!val_chain.empty ()); |
1790 | for (const value_ref_ptr &iter : val_chain) | |
a5606eee | 1791 | { |
a6535de1 TT |
1792 | v = iter.get (); |
1793 | ||
a5606eee VP |
1794 | /* If it's a memory location, and GDB actually needed |
1795 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1796 | must watch it. If the first value returned is |
1797 | still lazy, that means an error occurred reading it; | |
1798 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1799 | if (VALUE_LVAL (v) == lval_memory |
a6535de1 | 1800 | && (v == val_chain[0] || ! value_lazy (v))) |
a5606eee VP |
1801 | { |
1802 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1803 | |
a5606eee VP |
1804 | /* We only watch structs and arrays if user asked |
1805 | for it explicitly, never if they just happen to | |
1806 | appear in the middle of some value chain. */ | |
fa4727a6 | 1807 | if (v == result |
a5606eee VP |
1808 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1809 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1810 | { | |
1811 | CORE_ADDR addr; | |
f486487f | 1812 | enum target_hw_bp_type type; |
a5606eee | 1813 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1814 | int bitpos = 0, bitsize = 0; |
1815 | ||
1816 | if (value_bitsize (v) != 0) | |
1817 | { | |
1818 | /* Extract the bit parameters out from the bitfield | |
1819 | sub-expression. */ | |
1820 | bitpos = value_bitpos (v); | |
1821 | bitsize = value_bitsize (v); | |
1822 | } | |
1823 | else if (v == result && b->val_bitsize != 0) | |
1824 | { | |
1825 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1826 | lvalue whose bit parameters are saved in the fields | |
1827 | VAL_BITPOS and VAL_BITSIZE. */ | |
1828 | bitpos = b->val_bitpos; | |
1829 | bitsize = b->val_bitsize; | |
1830 | } | |
a5606eee | 1831 | |
42ae5230 | 1832 | addr = value_address (v); |
bb9d5f81 PP |
1833 | if (bitsize != 0) |
1834 | { | |
1835 | /* Skip the bytes that don't contain the bitfield. */ | |
1836 | addr += bitpos / 8; | |
1837 | } | |
1838 | ||
a5606eee | 1839 | type = hw_write; |
c1fc2657 | 1840 | if (b->type == bp_read_watchpoint) |
a5606eee | 1841 | type = hw_read; |
c1fc2657 | 1842 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1843 | type = hw_access; |
3a5c3e22 | 1844 | |
c1fc2657 SM |
1845 | loc = allocate_bp_location (b); |
1846 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1847 | ; |
1848 | *tmp = loc; | |
a6d9a66e | 1849 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1850 | |
1851 | loc->pspace = frame_pspace; | |
f17d9474 | 1852 | loc->address = address_significant (loc->gdbarch, addr); |
bb9d5f81 PP |
1853 | |
1854 | if (bitsize != 0) | |
1855 | { | |
1856 | /* Just cover the bytes that make up the bitfield. */ | |
1857 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1858 | } | |
1859 | else | |
1860 | loc->length = TYPE_LENGTH (value_type (v)); | |
1861 | ||
a5606eee VP |
1862 | loc->watchpoint_type = type; |
1863 | } | |
1864 | } | |
9fa40276 TJB |
1865 | } |
1866 | ||
1867 | /* Change the type of breakpoint between hardware assisted or | |
1868 | an ordinary watchpoint depending on the hardware support | |
1869 | and free hardware slots. REPARSE is set when the inferior | |
1870 | is started. */ | |
a9634178 | 1871 | if (reparse) |
9fa40276 | 1872 | { |
e09342b5 | 1873 | int reg_cnt; |
9fa40276 TJB |
1874 | enum bp_loc_type loc_type; |
1875 | struct bp_location *bl; | |
a5606eee | 1876 | |
a9634178 | 1877 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1878 | |
1879 | if (reg_cnt) | |
9fa40276 TJB |
1880 | { |
1881 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1882 | enum bptype type; |
9fa40276 | 1883 | |
a9634178 TJB |
1884 | /* Use an exact watchpoint when there's only one memory region to be |
1885 | watched, and only one debug register is needed to watch it. */ | |
1886 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1887 | ||
9fa40276 | 1888 | /* We need to determine how many resources are already |
e09342b5 TJB |
1889 | used for all other hardware watchpoints plus this one |
1890 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1891 | this watchpoint in as well. */ |
1892 | ||
1893 | /* If this is a software watchpoint, we try to turn it | |
1894 | to a hardware one -- count resources as if B was of | |
1895 | hardware watchpoint type. */ | |
c1fc2657 | 1896 | type = b->type; |
a1398e0c PA |
1897 | if (type == bp_watchpoint) |
1898 | type = bp_hardware_watchpoint; | |
1899 | ||
1900 | /* This watchpoint may or may not have been placed on | |
1901 | the list yet at this point (it won't be in the list | |
1902 | if we're trying to create it for the first time, | |
1903 | through watch_command), so always account for it | |
1904 | manually. */ | |
1905 | ||
1906 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 1907 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
1908 | |
1909 | /* Add in the resources needed for B. */ | |
c1fc2657 | 1910 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
1911 | |
1912 | target_resources_ok | |
1913 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1914 | if (target_resources_ok <= 0) |
a9634178 | 1915 | { |
c1fc2657 | 1916 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
1917 | |
1918 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1919 | error (_("Target does not support this type of " |
1920 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1921 | else if (target_resources_ok < 0 && !sw_mode) |
1922 | error (_("There are not enough available hardware " | |
1923 | "resources for this watchpoint.")); | |
a1398e0c PA |
1924 | |
1925 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 1926 | b->type = bp_watchpoint; |
a1398e0c PA |
1927 | } |
1928 | else | |
1929 | { | |
1930 | /* If this was a software watchpoint, we've just | |
1931 | found we have enough resources to turn it to a | |
1932 | hardware watchpoint. Otherwise, this is a | |
1933 | nop. */ | |
c1fc2657 | 1934 | b->type = type; |
a9634178 | 1935 | } |
9fa40276 | 1936 | } |
c1fc2657 | 1937 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
1938 | { |
1939 | if (!can_use_hw_watchpoints) | |
1940 | error (_("Can't set read/access watchpoint when " | |
1941 | "hardware watchpoints are disabled.")); | |
1942 | else | |
1943 | error (_("Expression cannot be implemented with " | |
1944 | "read/access watchpoint.")); | |
1945 | } | |
9fa40276 | 1946 | else |
c1fc2657 | 1947 | b->type = bp_watchpoint; |
9fa40276 | 1948 | |
c1fc2657 | 1949 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 1950 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 1951 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
1952 | bl->loc_type = loc_type; |
1953 | } | |
1954 | ||
c7437ca6 PA |
1955 | /* If a software watchpoint is not watching any memory, then the |
1956 | above left it without any location set up. But, | |
1957 | bpstat_stop_status requires a location to be able to report | |
1958 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
1959 | if (b->type == bp_watchpoint && b->loc == NULL) |
1960 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
1961 | } |
1962 | else if (!within_current_scope) | |
7270d8f2 | 1963 | { |
ac74f770 MS |
1964 | printf_filtered (_("\ |
1965 | Watchpoint %d deleted because the program has left the block\n\ | |
1966 | in which its expression is valid.\n"), | |
c1fc2657 | 1967 | b->number); |
d0fb5eae | 1968 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1969 | } |
a5606eee VP |
1970 | |
1971 | /* Restore the selected frame. */ | |
66076460 DJ |
1972 | if (frame_saved) |
1973 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1974 | } |
1975 | ||
a5606eee | 1976 | |
74960c60 | 1977 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1978 | inserted in the inferior. We don't differentiate the type of BL's owner |
1979 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1980 | breakpoint_ops is not defined, because in insert_bp_location, | |
1981 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1982 | static int |
35df4500 | 1983 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1984 | { |
35df4500 | 1985 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1986 | return 0; |
1987 | ||
35df4500 | 1988 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1989 | return 0; |
1990 | ||
35df4500 | 1991 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1992 | return 0; |
1993 | ||
f8eba3c6 TT |
1994 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
1995 | return 0; | |
1996 | ||
56710373 PA |
1997 | /* This is set for example, when we're attached to the parent of a |
1998 | vfork, and have detached from the child. The child is running | |
1999 | free, and we expect it to do an exec or exit, at which point the | |
2000 | OS makes the parent schedulable again (and the target reports | |
2001 | that the vfork is done). Until the child is done with the shared | |
2002 | memory region, do not insert breakpoints in the parent, otherwise | |
2003 | the child could still trip on the parent's breakpoints. Since | |
2004 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2005 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2006 | return 0; |
2007 | ||
31e77af2 | 2008 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2009 | location, except if the breakpoint is a single-step breakpoint, |
2010 | and the breakpoint's thread is the thread which is stepping past | |
2011 | a breakpoint. */ | |
31e77af2 PA |
2012 | if ((bl->loc_type == bp_loc_software_breakpoint |
2013 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2014 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2015 | bl->address) |
2016 | /* The single-step breakpoint may be inserted at the location | |
2017 | we're trying to step if the instruction branches to itself. | |
2018 | However, the instruction won't be executed at all and it may | |
2019 | break the semantics of the instruction, for example, the | |
2020 | instruction is a conditional branch or updates some flags. | |
2021 | We can't fix it unless GDB is able to emulate the instruction | |
2022 | or switch to displaced stepping. */ | |
2023 | && !(bl->owner->type == bp_single_step | |
2024 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2025 | { |
2026 | if (debug_infrun) | |
2027 | { | |
2028 | fprintf_unfiltered (gdb_stdlog, | |
2029 | "infrun: skipping breakpoint: " | |
2030 | "stepping past insn at: %s\n", | |
2031 | paddress (bl->gdbarch, bl->address)); | |
2032 | } | |
2033 | return 0; | |
2034 | } | |
31e77af2 | 2035 | |
963f9c80 PA |
2036 | /* Don't insert watchpoints if we're trying to step past the |
2037 | instruction that triggered one. */ | |
2038 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2039 | && stepping_past_nonsteppable_watchpoint ()) | |
2040 | { | |
2041 | if (debug_infrun) | |
2042 | { | |
2043 | fprintf_unfiltered (gdb_stdlog, | |
2044 | "infrun: stepping past non-steppable watchpoint. " | |
2045 | "skipping watchpoint at %s:%d\n", | |
2046 | paddress (bl->gdbarch, bl->address), | |
2047 | bl->length); | |
2048 | } | |
2049 | return 0; | |
2050 | } | |
2051 | ||
74960c60 VP |
2052 | return 1; |
2053 | } | |
2054 | ||
934709f0 PW |
2055 | /* Same as should_be_inserted but does the check assuming |
2056 | that the location is not duplicated. */ | |
2057 | ||
2058 | static int | |
2059 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2060 | { | |
2061 | int result; | |
2062 | const int save_duplicate = bl->duplicate; | |
2063 | ||
2064 | bl->duplicate = 0; | |
2065 | result = should_be_inserted (bl); | |
2066 | bl->duplicate = save_duplicate; | |
2067 | return result; | |
2068 | } | |
2069 | ||
b775012e LM |
2070 | /* Parses a conditional described by an expression COND into an |
2071 | agent expression bytecode suitable for evaluation | |
2072 | by the bytecode interpreter. Return NULL if there was | |
2073 | any error during parsing. */ | |
2074 | ||
833177a4 | 2075 | static agent_expr_up |
b775012e LM |
2076 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2077 | { | |
833177a4 | 2078 | if (cond == NULL) |
b775012e LM |
2079 | return NULL; |
2080 | ||
833177a4 PA |
2081 | agent_expr_up aexpr; |
2082 | ||
b775012e LM |
2083 | /* We don't want to stop processing, so catch any errors |
2084 | that may show up. */ | |
a70b8144 | 2085 | try |
b775012e | 2086 | { |
036e657b | 2087 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2088 | } |
2089 | ||
230d2906 | 2090 | catch (const gdb_exception_error &ex) |
b775012e LM |
2091 | { |
2092 | /* If we got here, it means the condition could not be parsed to a valid | |
2093 | bytecode expression and thus can't be evaluated on the target's side. | |
2094 | It's no use iterating through the conditions. */ | |
b775012e LM |
2095 | } |
2096 | ||
2097 | /* We have a valid agent expression. */ | |
2098 | return aexpr; | |
2099 | } | |
2100 | ||
2101 | /* Based on location BL, create a list of breakpoint conditions to be | |
2102 | passed on to the target. If we have duplicated locations with different | |
2103 | conditions, we will add such conditions to the list. The idea is that the | |
2104 | target will evaluate the list of conditions and will only notify GDB when | |
2105 | one of them is true. */ | |
2106 | ||
2107 | static void | |
2108 | build_target_condition_list (struct bp_location *bl) | |
2109 | { | |
2110 | struct bp_location **locp = NULL, **loc2p; | |
2111 | int null_condition_or_parse_error = 0; | |
2112 | int modified = bl->needs_update; | |
2113 | struct bp_location *loc; | |
2114 | ||
8b4f3082 | 2115 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2116 | bl->target_info.conditions.clear (); |
8b4f3082 | 2117 | |
b775012e LM |
2118 | /* This is only meaningful if the target is |
2119 | evaluating conditions and if the user has | |
2120 | opted for condition evaluation on the target's | |
2121 | side. */ | |
2122 | if (gdb_evaluates_breakpoint_condition_p () | |
2123 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2124 | return; | |
2125 | ||
2126 | /* Do a first pass to check for locations with no assigned | |
2127 | conditions or conditions that fail to parse to a valid agent expression | |
2128 | bytecode. If any of these happen, then it's no use to send conditions | |
2129 | to the target since this location will always trigger and generate a | |
2130 | response back to GDB. */ | |
2131 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2132 | { | |
2133 | loc = (*loc2p); | |
2134 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2135 | { | |
2136 | if (modified) | |
2137 | { | |
b775012e LM |
2138 | /* Re-parse the conditions since something changed. In that |
2139 | case we already freed the condition bytecodes (see | |
2140 | force_breakpoint_reinsertion). We just | |
2141 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2142 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2143 | loc->cond.get ()); | |
b775012e LM |
2144 | } |
2145 | ||
2146 | /* If we have a NULL bytecode expression, it means something | |
2147 | went wrong or we have a null condition expression. */ | |
2148 | if (!loc->cond_bytecode) | |
2149 | { | |
2150 | null_condition_or_parse_error = 1; | |
2151 | break; | |
2152 | } | |
2153 | } | |
2154 | } | |
2155 | ||
2156 | /* If any of these happened, it means we will have to evaluate the conditions | |
2157 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2158 | for all the other duplicate locations, thus we free all of them here. | |
2159 | ||
2160 | This is so we have a finer control over which locations' conditions are | |
2161 | being evaluated by GDB or the remote stub. */ | |
2162 | if (null_condition_or_parse_error) | |
2163 | { | |
2164 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2165 | { | |
2166 | loc = (*loc2p); | |
2167 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2168 | { | |
2169 | /* Only go as far as the first NULL bytecode is | |
2170 | located. */ | |
2171 | if (!loc->cond_bytecode) | |
2172 | return; | |
2173 | ||
833177a4 | 2174 | loc->cond_bytecode.reset (); |
b775012e LM |
2175 | } |
2176 | } | |
2177 | } | |
2178 | ||
2179 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2180 | for this location's address. */ | |
2181 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2182 | { | |
2183 | loc = (*loc2p); | |
2184 | if (loc->cond | |
2185 | && is_breakpoint (loc->owner) | |
2186 | && loc->pspace->num == bl->pspace->num | |
2187 | && loc->owner->enable_state == bp_enabled | |
2188 | && loc->enabled) | |
3cde5c42 PA |
2189 | { |
2190 | /* Add the condition to the vector. This will be used later | |
2191 | to send the conditions to the target. */ | |
2192 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2193 | } | |
b775012e LM |
2194 | } |
2195 | ||
2196 | return; | |
2197 | } | |
2198 | ||
d3ce09f5 SS |
2199 | /* Parses a command described by string CMD into an agent expression |
2200 | bytecode suitable for evaluation by the bytecode interpreter. | |
2201 | Return NULL if there was any error during parsing. */ | |
2202 | ||
833177a4 | 2203 | static agent_expr_up |
d3ce09f5 SS |
2204 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2205 | { | |
bbc13ae3 KS |
2206 | const char *cmdrest; |
2207 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2208 | struct gdbarch *gdbarch = get_current_arch (); |
2209 | ||
833177a4 | 2210 | if (cmd == NULL) |
d3ce09f5 SS |
2211 | return NULL; |
2212 | ||
2213 | cmdrest = cmd; | |
2214 | ||
2215 | if (*cmdrest == ',') | |
2216 | ++cmdrest; | |
f1735a53 | 2217 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2218 | |
2219 | if (*cmdrest++ != '"') | |
2220 | error (_("No format string following the location")); | |
2221 | ||
2222 | format_start = cmdrest; | |
2223 | ||
8e481c3b | 2224 | format_pieces fpieces (&cmdrest); |
d3ce09f5 SS |
2225 | |
2226 | format_end = cmdrest; | |
2227 | ||
2228 | if (*cmdrest++ != '"') | |
2229 | error (_("Bad format string, non-terminated '\"'.")); | |
2230 | ||
f1735a53 | 2231 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2232 | |
2233 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2234 | error (_("Invalid argument syntax")); | |
2235 | ||
2236 | if (*cmdrest == ',') | |
2237 | cmdrest++; | |
f1735a53 | 2238 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2239 | |
2240 | /* For each argument, make an expression. */ | |
2241 | ||
8e481c3b | 2242 | std::vector<struct expression *> argvec; |
d3ce09f5 SS |
2243 | while (*cmdrest != '\0') |
2244 | { | |
bbc13ae3 | 2245 | const char *cmd1; |
d3ce09f5 SS |
2246 | |
2247 | cmd1 = cmdrest; | |
4d01a485 | 2248 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
8e481c3b | 2249 | argvec.push_back (expr.release ()); |
d3ce09f5 SS |
2250 | cmdrest = cmd1; |
2251 | if (*cmdrest == ',') | |
2252 | ++cmdrest; | |
2253 | } | |
2254 | ||
833177a4 PA |
2255 | agent_expr_up aexpr; |
2256 | ||
d3ce09f5 SS |
2257 | /* We don't want to stop processing, so catch any errors |
2258 | that may show up. */ | |
a70b8144 | 2259 | try |
d3ce09f5 | 2260 | { |
036e657b JB |
2261 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2262 | format_start, format_end - format_start, | |
8e481c3b | 2263 | argvec.size (), argvec.data ()); |
d3ce09f5 | 2264 | } |
230d2906 | 2265 | catch (const gdb_exception_error &ex) |
d3ce09f5 SS |
2266 | { |
2267 | /* If we got here, it means the command could not be parsed to a valid | |
2268 | bytecode expression and thus can't be evaluated on the target's side. | |
2269 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2270 | } |
492d29ea | 2271 | |
d3ce09f5 SS |
2272 | /* We have a valid agent expression, return it. */ |
2273 | return aexpr; | |
2274 | } | |
2275 | ||
2276 | /* Based on location BL, create a list of breakpoint commands to be | |
2277 | passed on to the target. If we have duplicated locations with | |
2278 | different commands, we will add any such to the list. */ | |
2279 | ||
2280 | static void | |
2281 | build_target_command_list (struct bp_location *bl) | |
2282 | { | |
2283 | struct bp_location **locp = NULL, **loc2p; | |
2284 | int null_command_or_parse_error = 0; | |
2285 | int modified = bl->needs_update; | |
2286 | struct bp_location *loc; | |
2287 | ||
3cde5c42 PA |
2288 | /* Clear commands left over from a previous insert. */ |
2289 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2290 | |
41fac0cf | 2291 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2292 | return; |
2293 | ||
41fac0cf PA |
2294 | /* For now, limit to agent-style dprintf breakpoints. */ |
2295 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2296 | return; |
2297 | ||
41fac0cf PA |
2298 | /* For now, if we have any duplicate location that isn't a dprintf, |
2299 | don't install the target-side commands, as that would make the | |
2300 | breakpoint not be reported to the core, and we'd lose | |
2301 | control. */ | |
2302 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2303 | { | |
2304 | loc = (*loc2p); | |
2305 | if (is_breakpoint (loc->owner) | |
2306 | && loc->pspace->num == bl->pspace->num | |
2307 | && loc->owner->type != bp_dprintf) | |
2308 | return; | |
2309 | } | |
2310 | ||
d3ce09f5 SS |
2311 | /* Do a first pass to check for locations with no assigned |
2312 | conditions or conditions that fail to parse to a valid agent expression | |
2313 | bytecode. If any of these happen, then it's no use to send conditions | |
2314 | to the target since this location will always trigger and generate a | |
2315 | response back to GDB. */ | |
2316 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2317 | { | |
2318 | loc = (*loc2p); | |
2319 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2320 | { | |
2321 | if (modified) | |
2322 | { | |
d3ce09f5 SS |
2323 | /* Re-parse the commands since something changed. In that |
2324 | case we already freed the command bytecodes (see | |
2325 | force_breakpoint_reinsertion). We just | |
2326 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2327 | loc->cmd_bytecode |
2328 | = parse_cmd_to_aexpr (bl->address, | |
2329 | loc->owner->extra_string); | |
d3ce09f5 SS |
2330 | } |
2331 | ||
2332 | /* If we have a NULL bytecode expression, it means something | |
2333 | went wrong or we have a null command expression. */ | |
2334 | if (!loc->cmd_bytecode) | |
2335 | { | |
2336 | null_command_or_parse_error = 1; | |
2337 | break; | |
2338 | } | |
2339 | } | |
2340 | } | |
2341 | ||
2342 | /* If anything failed, then we're not doing target-side commands, | |
2343 | and so clean up. */ | |
2344 | if (null_command_or_parse_error) | |
2345 | { | |
2346 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2347 | { | |
2348 | loc = (*loc2p); | |
2349 | if (is_breakpoint (loc->owner) | |
2350 | && loc->pspace->num == bl->pspace->num) | |
2351 | { | |
2352 | /* Only go as far as the first NULL bytecode is | |
2353 | located. */ | |
40fb6c5e | 2354 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2355 | return; |
2356 | ||
833177a4 | 2357 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2358 | } |
2359 | } | |
2360 | } | |
2361 | ||
2362 | /* No NULL commands or failed bytecode generation. Build a command list | |
2363 | for this location's address. */ | |
2364 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2365 | { | |
2366 | loc = (*loc2p); | |
2367 | if (loc->owner->extra_string | |
2368 | && is_breakpoint (loc->owner) | |
2369 | && loc->pspace->num == bl->pspace->num | |
2370 | && loc->owner->enable_state == bp_enabled | |
2371 | && loc->enabled) | |
3cde5c42 PA |
2372 | { |
2373 | /* Add the command to the vector. This will be used later | |
2374 | to send the commands to the target. */ | |
2375 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2376 | } | |
d3ce09f5 SS |
2377 | } |
2378 | ||
2379 | bl->target_info.persist = 0; | |
2380 | /* Maybe flag this location as persistent. */ | |
2381 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2382 | bl->target_info.persist = 1; | |
2383 | } | |
2384 | ||
833b7ab5 YQ |
2385 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2386 | of breakpoint according to ADDR except single-step breakpoint. | |
2387 | Get the kind of single-step breakpoint according to the current | |
2388 | registers state. */ | |
cd6c3b4f YQ |
2389 | |
2390 | static int | |
2391 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2392 | { | |
833b7ab5 YQ |
2393 | if (bl->owner->type == bp_single_step) |
2394 | { | |
2395 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2396 | struct regcache *regcache; | |
2397 | ||
00431a78 | 2398 | regcache = get_thread_regcache (thr); |
833b7ab5 YQ |
2399 | |
2400 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2401 | regcache, addr); | |
2402 | } | |
2403 | else | |
2404 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2405 | } |
2406 | ||
35df4500 TJB |
2407 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2408 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2409 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2410 | Returns 0 for success, 1 if the bp_location type is not supported or |
2411 | -1 for failure. | |
879bfdc2 | 2412 | |
4a64f543 MS |
2413 | NOTE drow/2003-09-09: This routine could be broken down to an |
2414 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2415 | static int |
35df4500 | 2416 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2417 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2418 | int *disabled_breaks, |
dd61ec5c MW |
2419 | int *hw_breakpoint_error, |
2420 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2421 | { |
cc06b668 | 2422 | gdb_exception bp_excpt; |
879bfdc2 | 2423 | |
b775012e | 2424 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2425 | return 0; |
2426 | ||
35c63cd8 JB |
2427 | /* Note we don't initialize bl->target_info, as that wipes out |
2428 | the breakpoint location's shadow_contents if the breakpoint | |
2429 | is still inserted at that location. This in turn breaks | |
2430 | target_read_memory which depends on these buffers when | |
2431 | a memory read is requested at the breakpoint location: | |
2432 | Once the target_info has been wiped, we fail to see that | |
2433 | we have a breakpoint inserted at that address and thus | |
2434 | read the breakpoint instead of returning the data saved in | |
2435 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2436 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2437 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2438 | bl->target_info.length = bl->length; |
8181d85f | 2439 | |
b775012e LM |
2440 | /* When working with target-side conditions, we must pass all the conditions |
2441 | for the same breakpoint address down to the target since GDB will not | |
2442 | insert those locations. With a list of breakpoint conditions, the target | |
2443 | can decide when to stop and notify GDB. */ | |
2444 | ||
2445 | if (is_breakpoint (bl->owner)) | |
2446 | { | |
2447 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2448 | build_target_command_list (bl); |
2449 | /* Reset the modification marker. */ | |
b775012e LM |
2450 | bl->needs_update = 0; |
2451 | } | |
2452 | ||
35df4500 TJB |
2453 | if (bl->loc_type == bp_loc_software_breakpoint |
2454 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2455 | { |
35df4500 | 2456 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2457 | { |
2458 | /* If the explicitly specified breakpoint type | |
2459 | is not hardware breakpoint, check the memory map to see | |
2460 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2461 | |
765dc015 VP |
2462 | Two important cases are: |
2463 | - location type is not hardware breakpoint, memory | |
2464 | is readonly. We change the type of the location to | |
2465 | hardware breakpoint. | |
4a64f543 MS |
2466 | - location type is hardware breakpoint, memory is |
2467 | read-write. This means we've previously made the | |
2468 | location hardware one, but then the memory map changed, | |
2469 | so we undo. | |
765dc015 | 2470 | |
4a64f543 MS |
2471 | When breakpoints are removed, remove_breakpoints will use |
2472 | location types we've just set here, the only possible | |
2473 | problem is that memory map has changed during running | |
2474 | program, but it's not going to work anyway with current | |
2475 | gdb. */ | |
765dc015 | 2476 | struct mem_region *mr |
0d5ed153 | 2477 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2478 | |
2479 | if (mr) | |
2480 | { | |
2481 | if (automatic_hardware_breakpoints) | |
2482 | { | |
765dc015 VP |
2483 | enum bp_loc_type new_type; |
2484 | ||
2485 | if (mr->attrib.mode != MEM_RW) | |
2486 | new_type = bp_loc_hardware_breakpoint; | |
2487 | else | |
2488 | new_type = bp_loc_software_breakpoint; | |
2489 | ||
35df4500 | 2490 | if (new_type != bl->loc_type) |
765dc015 VP |
2491 | { |
2492 | static int said = 0; | |
cc59ec59 | 2493 | |
35df4500 | 2494 | bl->loc_type = new_type; |
765dc015 VP |
2495 | if (!said) |
2496 | { | |
3e43a32a MS |
2497 | fprintf_filtered (gdb_stdout, |
2498 | _("Note: automatically using " | |
2499 | "hardware breakpoints for " | |
2500 | "read-only addresses.\n")); | |
765dc015 VP |
2501 | said = 1; |
2502 | } | |
2503 | } | |
2504 | } | |
35df4500 | 2505 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2506 | && mr->attrib.mode != MEM_RW) |
2507 | { | |
2508 | fprintf_unfiltered (tmp_error_stream, | |
2509 | _("Cannot insert breakpoint %d.\n" | |
2510 | "Cannot set software breakpoint " | |
2511 | "at read-only address %s\n"), | |
2512 | bl->owner->number, | |
2513 | paddress (bl->gdbarch, bl->address)); | |
2514 | return 1; | |
2515 | } | |
765dc015 VP |
2516 | } |
2517 | } | |
2518 | ||
879bfdc2 DJ |
2519 | /* First check to see if we have to handle an overlay. */ |
2520 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2521 | || bl->section == NULL |
2522 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2523 | { |
2524 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2525 | try |
dd61ec5c | 2526 | { |
0000e5cc PA |
2527 | int val; |
2528 | ||
dd61ec5c | 2529 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2530 | if (val) |
688fca4f | 2531 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2532 | } |
94aeb44b | 2533 | catch (gdb_exception &e) |
dd61ec5c | 2534 | { |
94aeb44b | 2535 | bp_excpt = std::move (e); |
dd61ec5c | 2536 | } |
879bfdc2 DJ |
2537 | } |
2538 | else | |
2539 | { | |
4a64f543 | 2540 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2541 | Shall we set a breakpoint at the LMA? */ |
2542 | if (!overlay_events_enabled) | |
2543 | { | |
2544 | /* Yes -- overlay event support is not active, | |
2545 | so we must try to set a breakpoint at the LMA. | |
2546 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2547 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2548 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2549 | bl->owner->number); |
879bfdc2 DJ |
2550 | else |
2551 | { | |
35df4500 TJB |
2552 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2553 | bl->section); | |
879bfdc2 | 2554 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2555 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2556 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2557 | |
2558 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2559 | try |
0000e5cc PA |
2560 | { |
2561 | int val; | |
2562 | ||
579c6ad9 | 2563 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2564 | = breakpoint_kind (bl, &addr); |
2565 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2566 | val = target_insert_breakpoint (bl->gdbarch, |
2567 | &bl->overlay_target_info); | |
2568 | if (val) | |
688fca4f PA |
2569 | bp_excpt |
2570 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2571 | } |
94aeb44b | 2572 | catch (gdb_exception &e) |
0000e5cc | 2573 | { |
94aeb44b | 2574 | bp_excpt = std::move (e); |
0000e5cc PA |
2575 | } |
2576 | ||
688fca4f | 2577 | if (bp_excpt.reason != 0) |
99361f52 | 2578 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2579 | "Overlay breakpoint %d " |
2580 | "failed: in ROM?\n", | |
35df4500 | 2581 | bl->owner->number); |
879bfdc2 DJ |
2582 | } |
2583 | } | |
2584 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2585 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2586 | { |
2587 | /* Yes. This overlay section is mapped into memory. */ | |
a70b8144 | 2588 | try |
dd61ec5c | 2589 | { |
0000e5cc PA |
2590 | int val; |
2591 | ||
dd61ec5c | 2592 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2593 | if (val) |
688fca4f | 2594 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2595 | } |
94aeb44b | 2596 | catch (gdb_exception &e) |
dd61ec5c | 2597 | { |
94aeb44b | 2598 | bp_excpt = std::move (e); |
dd61ec5c | 2599 | } |
879bfdc2 DJ |
2600 | } |
2601 | else | |
2602 | { | |
2603 | /* No. This breakpoint will not be inserted. | |
2604 | No error, but do not mark the bp as 'inserted'. */ | |
2605 | return 0; | |
2606 | } | |
2607 | } | |
2608 | ||
688fca4f | 2609 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2610 | { |
2611 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2612 | |
2613 | /* In some cases, we might not be able to insert a | |
2614 | breakpoint in a shared library that has already been | |
2615 | removed, but we have not yet processed the shlib unload | |
2616 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2617 | breakpoint insertion themselves can't tell why the |
2618 | breakpoint insertion failed (e.g., the remote target | |
2619 | doesn't define error codes), so we must treat generic | |
2620 | errors as memory errors. */ | |
688fca4f PA |
2621 | if (bp_excpt.reason == RETURN_ERROR |
2622 | && (bp_excpt.error == GENERIC_ERROR | |
2623 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2624 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2625 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2626 | || shared_objfile_contains_address_p (bl->pspace, |
2627 | bl->address))) | |
879bfdc2 | 2628 | { |
4a64f543 | 2629 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2630 | bl->shlib_disabled = 1; |
76727919 | 2631 | gdb::observers::breakpoint_modified.notify (bl->owner); |
3fbb6ffa TJB |
2632 | if (!*disabled_breaks) |
2633 | { | |
2634 | fprintf_unfiltered (tmp_error_stream, | |
2635 | "Cannot insert breakpoint %d.\n", | |
2636 | bl->owner->number); | |
2637 | fprintf_unfiltered (tmp_error_stream, | |
2638 | "Temporarily disabling shared " | |
2639 | "library breakpoints:\n"); | |
2640 | } | |
2641 | *disabled_breaks = 1; | |
879bfdc2 | 2642 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2643 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2644 | return 0; |
879bfdc2 DJ |
2645 | } |
2646 | else | |
879bfdc2 | 2647 | { |
35df4500 | 2648 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2649 | { |
0000e5cc | 2650 | *hw_breakpoint_error = 1; |
688fca4f | 2651 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
dd61ec5c MW |
2652 | fprintf_unfiltered (tmp_error_stream, |
2653 | "Cannot insert hardware breakpoint %d%s", | |
688fca4f PA |
2654 | bl->owner->number, |
2655 | bp_excpt.message ? ":" : ".\n"); | |
2656 | if (bp_excpt.message != NULL) | |
2657 | fprintf_unfiltered (tmp_error_stream, "%s.\n", | |
3d6e9d23 | 2658 | bp_excpt.what ()); |
879bfdc2 DJ |
2659 | } |
2660 | else | |
2661 | { | |
688fca4f | 2662 | if (bp_excpt.message == NULL) |
0000e5cc | 2663 | { |
1ccbe998 | 2664 | std::string message |
0000e5cc PA |
2665 | = memory_error_message (TARGET_XFER_E_IO, |
2666 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2667 | |
2668 | fprintf_unfiltered (tmp_error_stream, | |
2669 | "Cannot insert breakpoint %d.\n" | |
2670 | "%s\n", | |
1ccbe998 | 2671 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2672 | } |
2673 | else | |
2674 | { | |
2675 | fprintf_unfiltered (tmp_error_stream, | |
2676 | "Cannot insert breakpoint %d: %s\n", | |
2677 | bl->owner->number, | |
3d6e9d23 | 2678 | bp_excpt.what ()); |
0000e5cc | 2679 | } |
879bfdc2 | 2680 | } |
0000e5cc | 2681 | return 1; |
879bfdc2 DJ |
2682 | |
2683 | } | |
2684 | } | |
2685 | else | |
35df4500 | 2686 | bl->inserted = 1; |
879bfdc2 | 2687 | |
0000e5cc | 2688 | return 0; |
879bfdc2 DJ |
2689 | } |
2690 | ||
35df4500 | 2691 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2692 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2693 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2694 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2695 | { |
0000e5cc PA |
2696 | int val; |
2697 | ||
77b06cd7 TJB |
2698 | gdb_assert (bl->owner->ops != NULL |
2699 | && bl->owner->ops->insert_location != NULL); | |
2700 | ||
2701 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2702 | |
2703 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2704 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2705 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2706 | { |
2707 | struct bp_location *loc, **loc_temp; | |
2708 | ||
2709 | /* But don't try to insert it, if there's already another | |
2710 | hw_access location that would be considered a duplicate | |
2711 | of this one. */ | |
2712 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2713 | if (loc != bl |
85d721b8 | 2714 | && loc->watchpoint_type == hw_access |
35df4500 | 2715 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2716 | { |
35df4500 TJB |
2717 | bl->duplicate = 1; |
2718 | bl->inserted = 1; | |
2719 | bl->target_info = loc->target_info; | |
2720 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2721 | val = 0; |
2722 | break; | |
2723 | } | |
2724 | ||
2725 | if (val == 1) | |
2726 | { | |
77b06cd7 TJB |
2727 | bl->watchpoint_type = hw_access; |
2728 | val = bl->owner->ops->insert_location (bl); | |
2729 | ||
2730 | if (val) | |
2731 | /* Back to the original value. */ | |
2732 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2733 | } |
2734 | } | |
2735 | ||
35df4500 | 2736 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2737 | } |
2738 | ||
35df4500 | 2739 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2740 | { |
0000e5cc PA |
2741 | int val; |
2742 | ||
77b06cd7 TJB |
2743 | gdb_assert (bl->owner->ops != NULL |
2744 | && bl->owner->ops->insert_location != NULL); | |
2745 | ||
2746 | val = bl->owner->ops->insert_location (bl); | |
2747 | if (val) | |
2748 | { | |
2749 | bl->owner->enable_state = bp_disabled; | |
2750 | ||
2751 | if (val == 1) | |
2752 | warning (_("\ | |
2753 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2754 | of catchpoint."), bl->owner->number); | |
2755 | else | |
2756 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2757 | } | |
2758 | ||
2759 | bl->inserted = (val == 0); | |
1640b821 DJ |
2760 | |
2761 | /* We've already printed an error message if there was a problem | |
2762 | inserting this catchpoint, and we've disabled the catchpoint, | |
2763 | so just return success. */ | |
2764 | return 0; | |
879bfdc2 DJ |
2765 | } |
2766 | ||
2767 | return 0; | |
2768 | } | |
2769 | ||
6c95b8df PA |
2770 | /* This function is called when program space PSPACE is about to be |
2771 | deleted. It takes care of updating breakpoints to not reference | |
2772 | PSPACE anymore. */ | |
2773 | ||
2774 | void | |
2775 | breakpoint_program_space_exit (struct program_space *pspace) | |
2776 | { | |
2777 | struct breakpoint *b, *b_temp; | |
876fa593 | 2778 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2779 | |
2780 | /* Remove any breakpoint that was set through this program space. */ | |
2781 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2782 | { | |
2783 | if (b->pspace == pspace) | |
2784 | delete_breakpoint (b); | |
2785 | } | |
2786 | ||
2787 | /* Breakpoints set through other program spaces could have locations | |
2788 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2789 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2790 | { |
2791 | struct bp_location *tmp; | |
2792 | ||
2793 | if (loc->pspace == pspace) | |
2794 | { | |
2bdf28a0 | 2795 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2796 | if (loc->owner->loc == loc) |
2797 | loc->owner->loc = loc->next; | |
2798 | else | |
2799 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2800 | if (tmp->next == loc) | |
2801 | { | |
2802 | tmp->next = loc->next; | |
2803 | break; | |
2804 | } | |
2805 | } | |
2806 | } | |
2807 | ||
2808 | /* Now update the global location list to permanently delete the | |
2809 | removed locations above. */ | |
44702360 | 2810 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2811 | } |
2812 | ||
74960c60 VP |
2813 | /* Make sure all breakpoints are inserted in inferior. |
2814 | Throws exception on any error. | |
2815 | A breakpoint that is already inserted won't be inserted | |
2816 | again, so calling this function twice is safe. */ | |
2817 | void | |
2818 | insert_breakpoints (void) | |
2819 | { | |
2820 | struct breakpoint *bpt; | |
2821 | ||
2822 | ALL_BREAKPOINTS (bpt) | |
2823 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2824 | { |
2825 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2826 | ||
2827 | update_watchpoint (w, 0 /* don't reparse. */); | |
2828 | } | |
74960c60 | 2829 | |
04086b45 PA |
2830 | /* Updating watchpoints creates new locations, so update the global |
2831 | location list. Explicitly tell ugll to insert locations and | |
2832 | ignore breakpoints_always_inserted_mode. */ | |
2833 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
2834 | } |
2835 | ||
20388dd6 YQ |
2836 | /* Invoke CALLBACK for each of bp_location. */ |
2837 | ||
2838 | void | |
2839 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2840 | { | |
2841 | struct bp_location *loc, **loc_tmp; | |
2842 | ||
2843 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2844 | { | |
2845 | callback (loc, NULL); | |
2846 | } | |
2847 | } | |
2848 | ||
b775012e LM |
2849 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2850 | target. It is the case with deleting and disabling of breakpoints when using | |
2851 | always-inserted mode. */ | |
2852 | ||
2853 | static void | |
2854 | update_inserted_breakpoint_locations (void) | |
2855 | { | |
2856 | struct bp_location *bl, **blp_tmp; | |
2857 | int error_flag = 0; | |
2858 | int val = 0; | |
2859 | int disabled_breaks = 0; | |
2860 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2861 | int hw_bp_details_reported = 0; |
b775012e | 2862 | |
d7e74731 | 2863 | string_file tmp_error_stream; |
b775012e LM |
2864 | |
2865 | /* Explicitly mark the warning -- this will only be printed if | |
2866 | there was an error. */ | |
d7e74731 | 2867 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2868 | |
5ed8105e | 2869 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2870 | |
2871 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2872 | { | |
2873 | /* We only want to update software breakpoints and hardware | |
2874 | breakpoints. */ | |
2875 | if (!is_breakpoint (bl->owner)) | |
2876 | continue; | |
2877 | ||
2878 | /* We only want to update locations that are already inserted | |
2879 | and need updating. This is to avoid unwanted insertion during | |
2880 | deletion of breakpoints. */ | |
4daf1902 | 2881 | if (!bl->inserted || !bl->needs_update) |
b775012e LM |
2882 | continue; |
2883 | ||
2884 | switch_to_program_space_and_thread (bl->pspace); | |
2885 | ||
2886 | /* For targets that support global breakpoints, there's no need | |
2887 | to select an inferior to insert breakpoint to. In fact, even | |
2888 | if we aren't attached to any process yet, we should still | |
2889 | insert breakpoints. */ | |
f5656ead | 2890 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
d7e15655 | 2891 | && inferior_ptid == null_ptid) |
b775012e LM |
2892 | continue; |
2893 | ||
d7e74731 | 2894 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2895 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2896 | if (val) |
2897 | error_flag = val; | |
2898 | } | |
2899 | ||
2900 | if (error_flag) | |
2901 | { | |
223ffa71 | 2902 | target_terminal::ours_for_output (); |
b775012e LM |
2903 | error_stream (tmp_error_stream); |
2904 | } | |
b775012e LM |
2905 | } |
2906 | ||
c30eee59 | 2907 | /* Used when starting or continuing the program. */ |
c906108c | 2908 | |
74960c60 VP |
2909 | static void |
2910 | insert_breakpoint_locations (void) | |
c906108c | 2911 | { |
a5606eee | 2912 | struct breakpoint *bpt; |
35df4500 | 2913 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2914 | int error_flag = 0; |
c906108c | 2915 | int val = 0; |
3fbb6ffa | 2916 | int disabled_breaks = 0; |
81d0cc19 | 2917 | int hw_breakpoint_error = 0; |
dd61ec5c | 2918 | int hw_bp_error_explained_already = 0; |
c906108c | 2919 | |
d7e74731 PA |
2920 | string_file tmp_error_stream; |
2921 | ||
81d0cc19 GS |
2922 | /* Explicitly mark the warning -- this will only be printed if |
2923 | there was an error. */ | |
d7e74731 | 2924 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 2925 | |
5ed8105e | 2926 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 2927 | |
35df4500 | 2928 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2929 | { |
b775012e | 2930 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2931 | continue; |
2932 | ||
4a64f543 MS |
2933 | /* There is no point inserting thread-specific breakpoints if |
2934 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2935 | has BL->OWNER always non-NULL. */ | |
35df4500 | 2936 | if (bl->owner->thread != -1 |
5d5658a1 | 2937 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
2938 | continue; |
2939 | ||
35df4500 | 2940 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2941 | |
2942 | /* For targets that support global breakpoints, there's no need | |
2943 | to select an inferior to insert breakpoint to. In fact, even | |
2944 | if we aren't attached to any process yet, we should still | |
2945 | insert breakpoints. */ | |
f5656ead | 2946 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
d7e15655 | 2947 | && inferior_ptid == null_ptid) |
6c95b8df PA |
2948 | continue; |
2949 | ||
d7e74731 | 2950 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2951 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2952 | if (val) |
eacd795a | 2953 | error_flag = val; |
879bfdc2 | 2954 | } |
c906108c | 2955 | |
4a64f543 MS |
2956 | /* If we failed to insert all locations of a watchpoint, remove |
2957 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2958 | ALL_BREAKPOINTS (bpt) |
2959 | { | |
2960 | int some_failed = 0; | |
2961 | struct bp_location *loc; | |
2962 | ||
2963 | if (!is_hardware_watchpoint (bpt)) | |
2964 | continue; | |
2965 | ||
d6b74ac4 | 2966 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2967 | continue; |
74960c60 VP |
2968 | |
2969 | if (bpt->disposition == disp_del_at_next_stop) | |
2970 | continue; | |
a5606eee VP |
2971 | |
2972 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2973 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2974 | { |
2975 | some_failed = 1; | |
2976 | break; | |
2977 | } | |
2978 | if (some_failed) | |
2979 | { | |
2980 | for (loc = bpt->loc; loc; loc = loc->next) | |
2981 | if (loc->inserted) | |
834c0d03 | 2982 | remove_breakpoint (loc); |
a5606eee VP |
2983 | |
2984 | hw_breakpoint_error = 1; | |
d7e74731 PA |
2985 | tmp_error_stream.printf ("Could not insert " |
2986 | "hardware watchpoint %d.\n", | |
2987 | bpt->number); | |
eacd795a | 2988 | error_flag = -1; |
a5606eee VP |
2989 | } |
2990 | } | |
2991 | ||
eacd795a | 2992 | if (error_flag) |
81d0cc19 GS |
2993 | { |
2994 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2995 | message about possibly exhausted resources. */ | |
dd61ec5c | 2996 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2997 | { |
d7e74731 | 2998 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 2999 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3000 | } |
223ffa71 | 3001 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3002 | error_stream (tmp_error_stream); |
3003 | } | |
c906108c SS |
3004 | } |
3005 | ||
c30eee59 TJB |
3006 | /* Used when the program stops. |
3007 | Returns zero if successful, or non-zero if there was a problem | |
3008 | removing a breakpoint location. */ | |
3009 | ||
c906108c | 3010 | int |
fba45db2 | 3011 | remove_breakpoints (void) |
c906108c | 3012 | { |
35df4500 | 3013 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3014 | int val = 0; |
c906108c | 3015 | |
35df4500 | 3016 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3017 | { |
1e4d1764 | 3018 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3019 | val |= remove_breakpoint (bl); |
c5aa993b | 3020 | } |
3a1bae8e | 3021 | return val; |
c906108c SS |
3022 | } |
3023 | ||
49fa26b0 PA |
3024 | /* When a thread exits, remove breakpoints that are related to |
3025 | that thread. */ | |
3026 | ||
3027 | static void | |
3028 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3029 | { | |
3030 | struct breakpoint *b, *b_tmp; | |
3031 | ||
3032 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3033 | { | |
5d5658a1 | 3034 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3035 | { |
3036 | b->disposition = disp_del_at_next_stop; | |
3037 | ||
3038 | printf_filtered (_("\ | |
43792cf0 PA |
3039 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3040 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3041 | |
3042 | /* Hide it from the user. */ | |
3043 | b->number = 0; | |
3044 | } | |
3045 | } | |
3046 | } | |
3047 | ||
f3869b1a | 3048 | /* See breakpoint.h. */ |
6c95b8df | 3049 | |
f3869b1a | 3050 | void |
00431a78 | 3051 | remove_breakpoints_inf (inferior *inf) |
6c95b8df | 3052 | { |
35df4500 | 3053 | struct bp_location *bl, **blp_tmp; |
6c95b8df | 3054 | int val; |
6c95b8df | 3055 | |
35df4500 | 3056 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3057 | { |
35df4500 | 3058 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3059 | continue; |
3060 | ||
fc126975 | 3061 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3062 | { |
834c0d03 | 3063 | val = remove_breakpoint (bl); |
6c95b8df | 3064 | if (val != 0) |
f3869b1a | 3065 | return; |
6c95b8df PA |
3066 | } |
3067 | } | |
6c95b8df PA |
3068 | } |
3069 | ||
e58b0e63 PA |
3070 | static int internal_breakpoint_number = -1; |
3071 | ||
84f4c1fe PM |
3072 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3073 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3074 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3075 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3076 | breakpoint_count and that value incremented. Internal breakpoints |
3077 | do not set the internal var bpnum. */ | |
3078 | static void | |
3079 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3080 | { | |
3081 | if (internal) | |
3082 | b->number = internal_breakpoint_number--; | |
3083 | else | |
3084 | { | |
3085 | set_breakpoint_count (breakpoint_count + 1); | |
3086 | b->number = breakpoint_count; | |
3087 | } | |
3088 | } | |
3089 | ||
e62c965a | 3090 | static struct breakpoint * |
a6d9a66e | 3091 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3092 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3093 | const struct breakpoint_ops *ops) |
e62c965a | 3094 | { |
51abb421 | 3095 | symtab_and_line sal; |
e62c965a PP |
3096 | sal.pc = address; |
3097 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3098 | sal.pspace = current_program_space; |
e62c965a | 3099 | |
51abb421 | 3100 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3101 | b->number = internal_breakpoint_number--; |
3102 | b->disposition = disp_donttouch; | |
3103 | ||
3104 | return b; | |
3105 | } | |
3106 | ||
17450429 PP |
3107 | static const char *const longjmp_names[] = |
3108 | { | |
3109 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3110 | }; | |
3111 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3112 | ||
3113 | /* Per-objfile data private to breakpoint.c. */ | |
3114 | struct breakpoint_objfile_data | |
3115 | { | |
3116 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
43dce439 | 3117 | struct bound_minimal_symbol overlay_msym {}; |
17450429 PP |
3118 | |
3119 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
43dce439 | 3120 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
17450429 | 3121 | |
28106bc2 | 3122 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3123 | int longjmp_searched = 0; |
28106bc2 | 3124 | |
45461e0d SM |
3125 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3126 | references. */ | |
3127 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3128 | |
17450429 | 3129 | /* Minimal symbol for "std::terminate()" (if any). */ |
43dce439 | 3130 | struct bound_minimal_symbol terminate_msym {}; |
17450429 PP |
3131 | |
3132 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
43dce439 | 3133 | struct bound_minimal_symbol exception_msym {}; |
28106bc2 SDJ |
3134 | |
3135 | /* True if we have looked for exception probes. */ | |
43dce439 | 3136 | int exception_searched = 0; |
28106bc2 | 3137 | |
45461e0d SM |
3138 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3139 | references. */ | |
3140 | std::vector<probe *> exception_probes; | |
17450429 PP |
3141 | }; |
3142 | ||
51d3063a TT |
3143 | static const struct objfile_key<breakpoint_objfile_data> |
3144 | breakpoint_objfile_key; | |
17450429 PP |
3145 | |
3146 | /* Minimal symbol not found sentinel. */ | |
3147 | static struct minimal_symbol msym_not_found; | |
3148 | ||
3149 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3150 | ||
3151 | static int | |
3152 | msym_not_found_p (const struct minimal_symbol *msym) | |
3153 | { | |
3154 | return msym == &msym_not_found; | |
3155 | } | |
3156 | ||
3157 | /* Return per-objfile data needed by breakpoint.c. | |
3158 | Allocate the data if necessary. */ | |
3159 | ||
3160 | static struct breakpoint_objfile_data * | |
3161 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3162 | { | |
3163 | struct breakpoint_objfile_data *bp_objfile_data; | |
3164 | ||
51d3063a | 3165 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
17450429 | 3166 | if (bp_objfile_data == NULL) |
51d3063a | 3167 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
17450429 PP |
3168 | return bp_objfile_data; |
3169 | } | |
3170 | ||
e62c965a | 3171 | static void |
af02033e | 3172 | create_overlay_event_breakpoint (void) |
e62c965a | 3173 | { |
af02033e | 3174 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3175 | |
2030c079 | 3176 | for (objfile *objfile : current_program_space->objfiles ()) |
69de3c6a PP |
3177 | { |
3178 | struct breakpoint *b; | |
17450429 PP |
3179 | struct breakpoint_objfile_data *bp_objfile_data; |
3180 | CORE_ADDR addr; | |
67994074 | 3181 | struct explicit_location explicit_loc; |
69de3c6a | 3182 | |
17450429 PP |
3183 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3184 | ||
3b7344d5 | 3185 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3186 | continue; |
3187 | ||
3b7344d5 | 3188 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3189 | { |
3b7344d5 | 3190 | struct bound_minimal_symbol m; |
17450429 PP |
3191 | |
3192 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3193 | if (m.minsym == NULL) |
17450429 PP |
3194 | { |
3195 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3196 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3197 | continue; |
3198 | } | |
3199 | bp_objfile_data->overlay_msym = m; | |
3200 | } | |
e62c965a | 3201 | |
77e371c0 | 3202 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3203 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3204 | bp_overlay_event, |
3205 | &internal_breakpoint_ops); | |
67994074 KS |
3206 | initialize_explicit_location (&explicit_loc); |
3207 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3208 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3209 | |
69de3c6a PP |
3210 | if (overlay_debugging == ovly_auto) |
3211 | { | |
3212 | b->enable_state = bp_enabled; | |
3213 | overlay_events_enabled = 1; | |
3214 | } | |
3215 | else | |
3216 | { | |
3217 | b->enable_state = bp_disabled; | |
3218 | overlay_events_enabled = 0; | |
3219 | } | |
e62c965a | 3220 | } |
e62c965a PP |
3221 | } |
3222 | ||
0fd8e87f | 3223 | static void |
af02033e | 3224 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3225 | { |
6c95b8df | 3226 | struct program_space *pspace; |
6c95b8df | 3227 | |
5ed8105e | 3228 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3229 | |
6c95b8df | 3230 | ALL_PSPACES (pspace) |
af02033e | 3231 | { |
af02033e PP |
3232 | set_current_program_space (pspace); |
3233 | ||
2030c079 | 3234 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
3235 | { |
3236 | int i; | |
3237 | struct gdbarch *gdbarch; | |
3238 | struct breakpoint_objfile_data *bp_objfile_data; | |
0fd8e87f | 3239 | |
aed57c53 | 3240 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3241 | |
aed57c53 | 3242 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
17450429 | 3243 | |
aed57c53 TT |
3244 | if (!bp_objfile_data->longjmp_searched) |
3245 | { | |
3246 | std::vector<probe *> ret | |
3247 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
25f9533e | 3248 | |
aed57c53 TT |
3249 | if (!ret.empty ()) |
3250 | { | |
3251 | /* We are only interested in checking one element. */ | |
3252 | probe *p = ret[0]; | |
3253 | ||
3254 | if (!p->can_evaluate_arguments ()) | |
3255 | { | |
3256 | /* We cannot use the probe interface here, because it does | |
3257 | not know how to evaluate arguments. */ | |
3258 | ret.clear (); | |
3259 | } | |
3260 | } | |
3261 | bp_objfile_data->longjmp_probes = ret; | |
3262 | bp_objfile_data->longjmp_searched = 1; | |
3263 | } | |
25f9533e | 3264 | |
aed57c53 TT |
3265 | if (!bp_objfile_data->longjmp_probes.empty ()) |
3266 | { | |
3267 | for (probe *p : bp_objfile_data->longjmp_probes) | |
3268 | { | |
3269 | struct breakpoint *b; | |
3270 | ||
3271 | b = create_internal_breakpoint (gdbarch, | |
3272 | p->get_relocated_address (objfile), | |
3273 | bp_longjmp_master, | |
3274 | &internal_breakpoint_ops); | |
3275 | b->location = new_probe_location ("-probe-stap libc:longjmp"); | |
3276 | b->enable_state = bp_disabled; | |
3277 | } | |
28106bc2 | 3278 | |
aed57c53 TT |
3279 | continue; |
3280 | } | |
28106bc2 | 3281 | |
aed57c53 | 3282 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
28106bc2 | 3283 | continue; |
28106bc2 | 3284 | |
aed57c53 TT |
3285 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
3286 | { | |
3287 | struct breakpoint *b; | |
3288 | const char *func_name; | |
3289 | CORE_ADDR addr; | |
3290 | struct explicit_location explicit_loc; | |
0fd8e87f | 3291 | |
aed57c53 TT |
3292 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
3293 | continue; | |
17450429 | 3294 | |
aed57c53 TT |
3295 | func_name = longjmp_names[i]; |
3296 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) | |
3297 | { | |
3298 | struct bound_minimal_symbol m; | |
3299 | ||
3300 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3301 | if (m.minsym == NULL) | |
3302 | { | |
3303 | /* Prevent future lookups in this objfile. */ | |
3304 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; | |
3305 | continue; | |
3306 | } | |
3307 | bp_objfile_data->longjmp_msym[i] = m; | |
3308 | } | |
17450429 | 3309 | |
aed57c53 TT |
3310 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
3311 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, | |
3312 | &internal_breakpoint_ops); | |
3313 | initialize_explicit_location (&explicit_loc); | |
3314 | explicit_loc.function_name = ASTRDUP (func_name); | |
3315 | b->location = new_explicit_location (&explicit_loc); | |
3316 | b->enable_state = bp_disabled; | |
3317 | } | |
3318 | } | |
af02033e | 3319 | } |
0fd8e87f UW |
3320 | } |
3321 | ||
af02033e | 3322 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3323 | static void |
af02033e | 3324 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3325 | { |
3326 | struct program_space *pspace; | |
af02033e | 3327 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3328 | |
5ed8105e | 3329 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3330 | |
3331 | ALL_PSPACES (pspace) | |
17450429 | 3332 | { |
17450429 PP |
3333 | CORE_ADDR addr; |
3334 | ||
3335 | set_current_program_space (pspace); | |
3336 | ||
2030c079 | 3337 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
3338 | { |
3339 | struct breakpoint *b; | |
3340 | struct breakpoint_objfile_data *bp_objfile_data; | |
3341 | struct explicit_location explicit_loc; | |
aa7d318d | 3342 | |
aed57c53 | 3343 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3344 | |
aed57c53 TT |
3345 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
3346 | continue; | |
17450429 | 3347 | |
aed57c53 TT |
3348 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
3349 | { | |
3350 | struct bound_minimal_symbol m; | |
17450429 | 3351 | |
aed57c53 TT |
3352 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
3353 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text | |
3354 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
3355 | { | |
3356 | /* Prevent future lookups in this objfile. */ | |
3357 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; | |
3358 | continue; | |
3359 | } | |
3360 | bp_objfile_data->terminate_msym = m; | |
3361 | } | |
aa7d318d | 3362 | |
aed57c53 TT |
3363 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3364 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
3365 | bp_std_terminate_master, | |
3366 | &internal_breakpoint_ops); | |
3367 | initialize_explicit_location (&explicit_loc); | |
3368 | explicit_loc.function_name = ASTRDUP (func_name); | |
3369 | b->location = new_explicit_location (&explicit_loc); | |
3370 | b->enable_state = bp_disabled; | |
3371 | } | |
17450429 | 3372 | } |
aa7d318d TT |
3373 | } |
3374 | ||
186c406b TT |
3375 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3376 | ||
70221824 | 3377 | static void |
186c406b TT |
3378 | create_exception_master_breakpoint (void) |
3379 | { | |
17450429 | 3380 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b | 3381 | |
2030c079 | 3382 | for (objfile *objfile : current_program_space->objfiles ()) |
186c406b | 3383 | { |
17450429 PP |
3384 | struct breakpoint *b; |
3385 | struct gdbarch *gdbarch; | |
3386 | struct breakpoint_objfile_data *bp_objfile_data; | |
3387 | CORE_ADDR addr; | |
67994074 | 3388 | struct explicit_location explicit_loc; |
17450429 PP |
3389 | |
3390 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3391 | ||
28106bc2 SDJ |
3392 | /* We prefer the SystemTap probe point if it exists. */ |
3393 | if (!bp_objfile_data->exception_searched) | |
3394 | { | |
45461e0d SM |
3395 | std::vector<probe *> ret |
3396 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
25f9533e | 3397 | |
45461e0d | 3398 | if (!ret.empty ()) |
25f9533e SDJ |
3399 | { |
3400 | /* We are only interested in checking one element. */ | |
45461e0d | 3401 | probe *p = ret[0]; |
25f9533e | 3402 | |
935676c9 | 3403 | if (!p->can_evaluate_arguments ()) |
25f9533e SDJ |
3404 | { |
3405 | /* We cannot use the probe interface here, because it does | |
3406 | not know how to evaluate arguments. */ | |
45461e0d | 3407 | ret.clear (); |
25f9533e SDJ |
3408 | } |
3409 | } | |
3410 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3411 | bp_objfile_data->exception_searched = 1; |
3412 | } | |
3413 | ||
45461e0d | 3414 | if (!bp_objfile_data->exception_probes.empty ()) |
28106bc2 | 3415 | { |
b926417a | 3416 | gdbarch = get_objfile_arch (objfile); |
45461e0d SM |
3417 | |
3418 | for (probe *p : bp_objfile_data->exception_probes) | |
28106bc2 | 3419 | { |
729662a5 | 3420 | b = create_internal_breakpoint (gdbarch, |
935676c9 | 3421 | p->get_relocated_address (objfile), |
28106bc2 SDJ |
3422 | bp_exception_master, |
3423 | &internal_breakpoint_ops); | |
d28cd78a | 3424 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3425 | b->enable_state = bp_disabled; |
3426 | } | |
3427 | ||
3428 | continue; | |
3429 | } | |
3430 | ||
3431 | /* Otherwise, try the hook function. */ | |
3432 | ||
3b7344d5 | 3433 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3434 | continue; |
3435 | ||
3436 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3437 | |
3b7344d5 | 3438 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3439 | { |
3b7344d5 | 3440 | struct bound_minimal_symbol debug_hook; |
186c406b | 3441 | |
17450429 | 3442 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3443 | if (debug_hook.minsym == NULL) |
17450429 | 3444 | { |
3b7344d5 | 3445 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3446 | continue; |
3447 | } | |
3448 | ||
3449 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3450 | } |
17450429 | 3451 | |
77e371c0 | 3452 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
8b88a78e PA |
3453 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3454 | current_top_target ()); | |
06edf0c0 PA |
3455 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3456 | &internal_breakpoint_ops); | |
67994074 KS |
3457 | initialize_explicit_location (&explicit_loc); |
3458 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3459 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3460 | b->enable_state = bp_disabled; |
186c406b | 3461 | } |
186c406b TT |
3462 | } |
3463 | ||
9ef9e6a6 KS |
3464 | /* Does B have a location spec? */ |
3465 | ||
3466 | static int | |
3467 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3468 | { | |
d28cd78a | 3469 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3470 | } |
3471 | ||
c906108c | 3472 | void |
fba45db2 | 3473 | update_breakpoints_after_exec (void) |
c906108c | 3474 | { |
35df4500 | 3475 | struct breakpoint *b, *b_tmp; |
876fa593 | 3476 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3477 | |
25b22b0a PA |
3478 | /* We're about to delete breakpoints from GDB's lists. If the |
3479 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3480 | writing the breakpoints' "shadow contents" back into memory. The | |
3481 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3482 | do that. Instead, the target is responsible from marking | |
3483 | breakpoints out as soon as it detects an exec. We don't do that | |
3484 | here instead, because there may be other attempts to delete | |
3485 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3486 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3487 | if (bploc->pspace == current_program_space) |
3488 | gdb_assert (!bploc->inserted); | |
c906108c | 3489 | |
35df4500 | 3490 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3491 | { |
6c95b8df PA |
3492 | if (b->pspace != current_program_space) |
3493 | continue; | |
3494 | ||
4a64f543 | 3495 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3496 | if (b->type == bp_shlib_event) |
3497 | { | |
3498 | delete_breakpoint (b); | |
3499 | continue; | |
3500 | } | |
c906108c | 3501 | |
4a64f543 | 3502 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3503 | if (b->type == bp_jit_event) |
3504 | { | |
3505 | delete_breakpoint (b); | |
3506 | continue; | |
3507 | } | |
3508 | ||
1900040c | 3509 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3510 | as must overlay event and longjmp master breakpoints. */ |
3511 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3512 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3513 | || b->type == bp_exception_master) | |
c4093a6a JM |
3514 | { |
3515 | delete_breakpoint (b); | |
3516 | continue; | |
3517 | } | |
3518 | ||
4a64f543 | 3519 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3520 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3521 | { |
3522 | delete_breakpoint (b); | |
3523 | continue; | |
3524 | } | |
3525 | ||
7c16b83e PA |
3526 | /* Just like single-step breakpoints. */ |
3527 | if (b->type == bp_single_step) | |
3528 | { | |
3529 | delete_breakpoint (b); | |
3530 | continue; | |
3531 | } | |
3532 | ||
611c83ae PA |
3533 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3534 | after an exec. */ | |
186c406b | 3535 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3536 | || b->type == bp_longjmp_call_dummy |
186c406b | 3537 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3538 | { |
3539 | delete_breakpoint (b); | |
3540 | continue; | |
3541 | } | |
3542 | ||
ce78b96d JB |
3543 | if (b->type == bp_catchpoint) |
3544 | { | |
3545 | /* For now, none of the bp_catchpoint breakpoints need to | |
3546 | do anything at this point. In the future, if some of | |
3547 | the catchpoints need to something, we will need to add | |
3548 | a new method, and call this method from here. */ | |
3549 | continue; | |
3550 | } | |
3551 | ||
c5aa993b JM |
3552 | /* bp_finish is a special case. The only way we ought to be able |
3553 | to see one of these when an exec() has happened, is if the user | |
3554 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3555 | carries them to the call-site of the current callee, by setting | |
3556 | a temporary bp there and resuming. But in this case, the finish | |
3557 | will carry them entirely through the vfork & exec. | |
3558 | ||
3559 | We don't want to allow a bp_finish to remain inserted now. But | |
3560 | we can't safely delete it, 'cause finish_command has a handle to | |
3561 | the bp on a bpstat, and will later want to delete it. There's a | |
3562 | chance (and I've seen it happen) that if we delete the bp_finish | |
3563 | here, that its storage will get reused by the time finish_command | |
3564 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3565 | We really must allow finish_command to delete a bp_finish. | |
3566 | ||
e5dd4106 | 3567 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3568 | it's safe to delete something others may have handles to?" |
3569 | problem, what we'll do here is just uninsert the bp_finish, and | |
3570 | let finish_command delete it. | |
3571 | ||
3572 | (We know the bp_finish is "doomed" in the sense that it's | |
3573 | momentary, and will be deleted as soon as finish_command sees | |
3574 | the inferior stopped. So it doesn't matter that the bp's | |
3575 | address is probably bogus in the new a.out, unlike e.g., the | |
3576 | solib breakpoints.) */ | |
c5aa993b | 3577 | |
c5aa993b JM |
3578 | if (b->type == bp_finish) |
3579 | { | |
3580 | continue; | |
3581 | } | |
3582 | ||
3583 | /* Without a symbolic address, we have little hope of the | |
3584 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3585 | a.out. */ |
9ef9e6a6 | 3586 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3587 | { |
3588 | delete_breakpoint (b); | |
3589 | continue; | |
3590 | } | |
c5aa993b | 3591 | } |
c906108c SS |
3592 | } |
3593 | ||
3594 | int | |
d80ee84f | 3595 | detach_breakpoints (ptid_t ptid) |
c906108c | 3596 | { |
35df4500 | 3597 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3598 | int val = 0; |
2989a365 | 3599 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3600 | struct inferior *inf = current_inferior (); |
c5aa993b | 3601 | |
e99b03dc | 3602 | if (ptid.pid () == inferior_ptid.pid ()) |
8a3fe4f8 | 3603 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3604 | |
6c95b8df | 3605 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3606 | inferior_ptid = ptid; |
35df4500 | 3607 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3608 | { |
35df4500 | 3609 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3610 | continue; |
3611 | ||
bd9673a4 PW |
3612 | /* This function must physically remove breakpoints locations |
3613 | from the specified ptid, without modifying the breakpoint | |
3614 | package's state. Locations of type bp_loc_other are only | |
3615 | maintained at GDB side. So, there is no need to remove | |
3616 | these bp_loc_other locations. Moreover, removing these | |
3617 | would modify the breakpoint package's state. */ | |
3618 | if (bl->loc_type == bp_loc_other) | |
3619 | continue; | |
3620 | ||
35df4500 | 3621 | if (bl->inserted) |
b2b6a7da | 3622 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3623 | } |
d03285ec | 3624 | |
3a1bae8e | 3625 | return val; |
c906108c SS |
3626 | } |
3627 | ||
35df4500 | 3628 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3629 | Note that this is used to detach breakpoints from a child fork. |
3630 | When we get here, the child isn't in the inferior list, and neither | |
3631 | do we have objects to represent its address space --- we should | |
35df4500 | 3632 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3633 | |
c906108c | 3634 | static int |
b2b6a7da | 3635 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3636 | { |
3637 | int val; | |
c5aa993b | 3638 | |
35df4500 TJB |
3639 | /* BL is never in moribund_locations by our callers. */ |
3640 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3641 | |
74960c60 VP |
3642 | /* The type of none suggests that owner is actually deleted. |
3643 | This should not ever happen. */ | |
35df4500 | 3644 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3645 | |
35df4500 TJB |
3646 | if (bl->loc_type == bp_loc_software_breakpoint |
3647 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3648 | { |
c02f5703 MS |
3649 | /* "Normal" instruction breakpoint: either the standard |
3650 | trap-instruction bp (bp_breakpoint), or a | |
3651 | bp_hardware_breakpoint. */ | |
3652 | ||
3653 | /* First check to see if we have to handle an overlay. */ | |
3654 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3655 | || bl->section == NULL |
3656 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3657 | { |
3658 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3659 | |
3660 | /* If we're trying to uninsert a memory breakpoint that we | |
3661 | know is set in a dynamic object that is marked | |
3662 | shlib_disabled, then either the dynamic object was | |
3663 | removed with "remove-symbol-file" or with | |
3664 | "nosharedlibrary". In the former case, we don't know | |
3665 | whether another dynamic object might have loaded over the | |
3666 | breakpoint's address -- the user might well let us know | |
3667 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3668 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3669 | list of dynamically loaded objects). If we have the |
3670 | breakpoint's shadow memory, that is, this is a software | |
3671 | breakpoint managed by GDB, check whether the breakpoint | |
3672 | is still inserted in memory, to avoid overwriting wrong | |
3673 | code with stale saved shadow contents. Note that HW | |
3674 | breakpoints don't have shadow memory, as they're | |
3675 | implemented using a mechanism that is not dependent on | |
3676 | being able to modify the target's memory, and as such | |
3677 | they should always be removed. */ | |
3678 | if (bl->shlib_disabled | |
3679 | && bl->target_info.shadow_len != 0 | |
3680 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3681 | val = 0; | |
3682 | else | |
73971819 | 3683 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3684 | } |
c906108c SS |
3685 | else |
3686 | { | |
4a64f543 | 3687 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3688 | Did we set a breakpoint at the LMA? */ |
3689 | if (!overlay_events_enabled) | |
3690 | { | |
3691 | /* Yes -- overlay event support is not active, so we | |
3692 | should have set a breakpoint at the LMA. Remove it. | |
3693 | */ | |
c02f5703 MS |
3694 | /* Ignore any failures: if the LMA is in ROM, we will |
3695 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3696 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3697 | target_remove_hw_breakpoint (bl->gdbarch, | |
3698 | &bl->overlay_target_info); | |
c02f5703 | 3699 | else |
35df4500 | 3700 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3701 | &bl->overlay_target_info, |
3702 | reason); | |
c02f5703 MS |
3703 | } |
3704 | /* Did we set a breakpoint at the VMA? | |
3705 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3706 | if (bl->inserted) |
c906108c | 3707 | { |
c02f5703 MS |
3708 | /* Yes -- remove it. Previously we did not bother to |
3709 | remove the breakpoint if the section had been | |
3710 | unmapped, but let's not rely on that being safe. We | |
3711 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3712 | |
3713 | /* However, we should remove *software* breakpoints only | |
3714 | if the section is still mapped, or else we overwrite | |
3715 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3716 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3717 | || section_is_mapped (bl->section)) | |
73971819 | 3718 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3719 | else |
3720 | val = 0; | |
c906108c | 3721 | } |
c02f5703 MS |
3722 | else |
3723 | { | |
3724 | /* No -- not inserted, so no need to remove. No error. */ | |
3725 | val = 0; | |
3726 | } | |
c906108c | 3727 | } |
879d1e6b | 3728 | |
08351840 PA |
3729 | /* In some cases, we might not be able to remove a breakpoint in |
3730 | a shared library that has already been removed, but we have | |
3731 | not yet processed the shlib unload event. Similarly for an | |
3732 | unloaded add-symbol-file object - the user might not yet have | |
3733 | had the chance to remove-symbol-file it. shlib_disabled will | |
3734 | be set if the library/object has already been removed, but | |
3735 | the breakpoint hasn't been uninserted yet, e.g., after | |
3736 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3737 | always-inserted mode. */ | |
076855f9 | 3738 | if (val |
08351840 PA |
3739 | && (bl->loc_type == bp_loc_software_breakpoint |
3740 | && (bl->shlib_disabled | |
3741 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3742 | || shared_objfile_contains_address_p (bl->pspace, |
3743 | bl->address)))) | |
879d1e6b UW |
3744 | val = 0; |
3745 | ||
c906108c SS |
3746 | if (val) |
3747 | return val; | |
b2b6a7da | 3748 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3749 | } |
35df4500 | 3750 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3751 | { |
77b06cd7 TJB |
3752 | gdb_assert (bl->owner->ops != NULL |
3753 | && bl->owner->ops->remove_location != NULL); | |
3754 | ||
b2b6a7da | 3755 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3756 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3757 | |
c906108c | 3758 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3759 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3760 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3761 | bl->owner->number); |
c906108c | 3762 | } |
35df4500 TJB |
3763 | else if (bl->owner->type == bp_catchpoint |
3764 | && breakpoint_enabled (bl->owner) | |
3765 | && !bl->duplicate) | |
ce78b96d | 3766 | { |
77b06cd7 TJB |
3767 | gdb_assert (bl->owner->ops != NULL |
3768 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3769 | |
73971819 | 3770 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3771 | if (val) |
3772 | return val; | |
77b06cd7 | 3773 | |
b2b6a7da | 3774 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3775 | } |
c906108c SS |
3776 | |
3777 | return 0; | |
3778 | } | |
3779 | ||
6c95b8df | 3780 | static int |
834c0d03 | 3781 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3782 | { |
35df4500 TJB |
3783 | /* BL is never in moribund_locations by our callers. */ |
3784 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3785 | |
6c95b8df PA |
3786 | /* The type of none suggests that owner is actually deleted. |
3787 | This should not ever happen. */ | |
35df4500 | 3788 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3789 | |
5ed8105e | 3790 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3791 | |
35df4500 | 3792 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3793 | |
5ed8105e | 3794 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3795 | } |
3796 | ||
c906108c SS |
3797 | /* Clear the "inserted" flag in all breakpoints. */ |
3798 | ||
25b22b0a | 3799 | void |
fba45db2 | 3800 | mark_breakpoints_out (void) |
c906108c | 3801 | { |
35df4500 | 3802 | struct bp_location *bl, **blp_tmp; |
c906108c | 3803 | |
35df4500 | 3804 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3805 | if (bl->pspace == current_program_space) |
35df4500 | 3806 | bl->inserted = 0; |
c906108c SS |
3807 | } |
3808 | ||
53a5351d JM |
3809 | /* Clear the "inserted" flag in all breakpoints and delete any |
3810 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3811 | |
3812 | Plus other such housekeeping that has to be done for breakpoints | |
3813 | between runs. | |
3814 | ||
53a5351d JM |
3815 | Note: this function gets called at the end of a run (by |
3816 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3817 | init_wait_for_inferior). */ |
c906108c SS |
3818 | |
3819 | ||
3820 | ||
3821 | void | |
fba45db2 | 3822 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3823 | { |
35df4500 | 3824 | struct breakpoint *b, *b_tmp; |
6c95b8df | 3825 | struct program_space *pspace = current_program_space; |
c906108c | 3826 | |
50c71eaf PA |
3827 | /* If breakpoint locations are shared across processes, then there's |
3828 | nothing to do. */ | |
f5656ead | 3829 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3830 | return; |
3831 | ||
1a853c52 | 3832 | mark_breakpoints_out (); |
075f6582 | 3833 | |
35df4500 | 3834 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3835 | { |
6c95b8df PA |
3836 | if (b->loc && b->loc->pspace != pspace) |
3837 | continue; | |
3838 | ||
c5aa993b JM |
3839 | switch (b->type) |
3840 | { | |
3841 | case bp_call_dummy: | |
e2e4d78b | 3842 | case bp_longjmp_call_dummy: |
c906108c | 3843 | |
c5aa993b | 3844 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3845 | cause problems when the inferior is rerun, so we better get |
3846 | rid of it. */ | |
3847 | ||
3848 | case bp_watchpoint_scope: | |
3849 | ||
3850 | /* Also get rid of scope breakpoints. */ | |
3851 | ||
3852 | case bp_shlib_event: | |
3853 | ||
3854 | /* Also remove solib event breakpoints. Their addresses may | |
3855 | have changed since the last time we ran the program. | |
3856 | Actually we may now be debugging against different target; | |
3857 | and so the solib backend that installed this breakpoint may | |
3858 | not be used in by the target. E.g., | |
3859 | ||
3860 | (gdb) file prog-linux | |
3861 | (gdb) run # native linux target | |
3862 | ... | |
3863 | (gdb) kill | |
3864 | (gdb) file prog-win.exe | |
3865 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3866 | */ | |
c906108c | 3867 | |
f59f708a PA |
3868 | case bp_step_resume: |
3869 | ||
3870 | /* Also remove step-resume breakpoints. */ | |
3871 | ||
7c16b83e PA |
3872 | case bp_single_step: |
3873 | ||
3874 | /* Also remove single-step breakpoints. */ | |
3875 | ||
c5aa993b JM |
3876 | delete_breakpoint (b); |
3877 | break; | |
c906108c | 3878 | |
c5aa993b JM |
3879 | case bp_watchpoint: |
3880 | case bp_hardware_watchpoint: | |
3881 | case bp_read_watchpoint: | |
3882 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3883 | { |
3884 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3885 | |
3a5c3e22 PA |
3886 | /* Likewise for watchpoints on local expressions. */ |
3887 | if (w->exp_valid_block != NULL) | |
3888 | delete_breakpoint (b); | |
63000888 | 3889 | else |
3a5c3e22 | 3890 | { |
63000888 PA |
3891 | /* Get rid of existing locations, which are no longer |
3892 | valid. New ones will be created in | |
3893 | update_watchpoint, when the inferior is restarted. | |
3894 | The next update_global_location_list call will | |
3895 | garbage collect them. */ | |
3896 | b->loc = NULL; | |
3897 | ||
3898 | if (context == inf_starting) | |
3899 | { | |
3900 | /* Reset val field to force reread of starting value in | |
3901 | insert_breakpoints. */ | |
850645cf | 3902 | w->val.reset (nullptr); |
4c1d86d9 | 3903 | w->val_valid = false; |
63000888 PA |
3904 | } |
3905 | } | |
3a5c3e22 | 3906 | } |
c5aa993b JM |
3907 | break; |
3908 | default: | |
c5aa993b JM |
3909 | break; |
3910 | } | |
3911 | } | |
1c5cfe86 PA |
3912 | |
3913 | /* Get rid of the moribund locations. */ | |
1123588c | 3914 | for (bp_location *bl : moribund_locations) |
35df4500 | 3915 | decref_bp_location (&bl); |
1123588c | 3916 | moribund_locations.clear (); |
c906108c SS |
3917 | } |
3918 | ||
6c95b8df PA |
3919 | /* These functions concern about actual breakpoints inserted in the |
3920 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3921 | we need to hop over the bkpt --- so we check for address space | |
3922 | match, not program space. */ | |
3923 | ||
c2c6d25f JM |
3924 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3925 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3926 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3927 | permanent breakpoint. | |
3928 | - When continuing from a location with an ordinary breakpoint, we | |
3929 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3930 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3931 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3932 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3933 | |
c2c6d25f | 3934 | enum breakpoint_here |
accd0bcd | 3935 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 3936 | { |
35df4500 | 3937 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3938 | int any_breakpoint_here = 0; |
c906108c | 3939 | |
35df4500 | 3940 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3941 | { |
35df4500 TJB |
3942 | if (bl->loc_type != bp_loc_software_breakpoint |
3943 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3944 | continue; |
3945 | ||
f1310107 | 3946 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 3947 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 3948 | || bl->permanent) |
f1310107 | 3949 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3950 | { |
3951 | if (overlay_debugging | |
35df4500 TJB |
3952 | && section_is_overlay (bl->section) |
3953 | && !section_is_mapped (bl->section)) | |
075f6582 | 3954 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 3955 | else if (bl->permanent) |
075f6582 DJ |
3956 | return permanent_breakpoint_here; |
3957 | else | |
3958 | any_breakpoint_here = 1; | |
3959 | } | |
3960 | } | |
c906108c | 3961 | |
f486487f | 3962 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
3963 | } |
3964 | ||
d35ae833 PA |
3965 | /* See breakpoint.h. */ |
3966 | ||
3967 | int | |
accd0bcd | 3968 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
3969 | CORE_ADDR addr, ULONGEST len) |
3970 | { | |
3971 | struct bp_location *bl, **blp_tmp; | |
3972 | ||
3973 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3974 | { | |
3975 | if (bl->loc_type != bp_loc_software_breakpoint | |
3976 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
3977 | continue; | |
3978 | ||
3979 | if ((breakpoint_enabled (bl->owner) | |
3980 | || bl->permanent) | |
3981 | && breakpoint_location_address_range_overlap (bl, aspace, | |
3982 | addr, len)) | |
3983 | { | |
3984 | if (overlay_debugging | |
3985 | && section_is_overlay (bl->section) | |
3986 | && !section_is_mapped (bl->section)) | |
3987 | { | |
3988 | /* Unmapped overlay -- can't be a match. */ | |
3989 | continue; | |
3990 | } | |
3991 | ||
3992 | return 1; | |
3993 | } | |
3994 | } | |
3995 | ||
3996 | return 0; | |
3997 | } | |
3998 | ||
1c5cfe86 PA |
3999 | /* Return true if there's a moribund breakpoint at PC. */ |
4000 | ||
4001 | int | |
accd0bcd | 4002 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 | 4003 | { |
1123588c | 4004 | for (bp_location *loc : moribund_locations) |
f1310107 | 4005 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4006 | return 1; |
4007 | ||
4008 | return 0; | |
4009 | } | |
c2c6d25f | 4010 | |
f7ce857f PA |
4011 | /* Returns non-zero iff BL is inserted at PC, in address space |
4012 | ASPACE. */ | |
4013 | ||
4014 | static int | |
4015 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 4016 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
4017 | { |
4018 | if (bl->inserted | |
4019 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4020 | aspace, pc)) | |
4021 | { | |
4022 | if (overlay_debugging | |
4023 | && section_is_overlay (bl->section) | |
4024 | && !section_is_mapped (bl->section)) | |
4025 | return 0; /* unmapped overlay -- can't be a match */ | |
4026 | else | |
4027 | return 1; | |
4028 | } | |
4029 | return 0; | |
4030 | } | |
4031 | ||
a1fd2fa5 | 4032 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4033 | |
4034 | int | |
accd0bcd | 4035 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4036 | { |
f7ce857f | 4037 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4038 | |
f7ce857f | 4039 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4040 | { |
f7ce857f PA |
4041 | struct bp_location *bl = *blp; |
4042 | ||
35df4500 TJB |
4043 | if (bl->loc_type != bp_loc_software_breakpoint |
4044 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4045 | continue; |
4046 | ||
f7ce857f PA |
4047 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4048 | return 1; | |
c5aa993b | 4049 | } |
c36b740a VP |
4050 | return 0; |
4051 | } | |
4052 | ||
a1fd2fa5 PA |
4053 | /* This function returns non-zero iff there is a software breakpoint |
4054 | inserted at PC. */ | |
c36b740a VP |
4055 | |
4056 | int | |
accd0bcd | 4057 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4058 | CORE_ADDR pc) |
4fa8626c | 4059 | { |
f7ce857f | 4060 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4061 | |
f7ce857f | 4062 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4063 | { |
f7ce857f PA |
4064 | struct bp_location *bl = *blp; |
4065 | ||
35df4500 | 4066 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4067 | continue; |
4068 | ||
f7ce857f PA |
4069 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4070 | return 1; | |
4fa8626c DJ |
4071 | } |
4072 | ||
4073 | return 0; | |
9c02b525 PA |
4074 | } |
4075 | ||
4076 | /* See breakpoint.h. */ | |
4077 | ||
4078 | int | |
accd0bcd | 4079 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4080 | CORE_ADDR pc) |
4081 | { | |
4082 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4083 | |
4084 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4085 | { | |
4086 | struct bp_location *bl = *blp; | |
4087 | ||
4088 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4089 | continue; | |
4090 | ||
4091 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4092 | return 1; | |
4093 | } | |
4094 | ||
4095 | return 0; | |
4fa8626c DJ |
4096 | } |
4097 | ||
9093389c | 4098 | int |
accd0bcd | 4099 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4100 | CORE_ADDR addr, ULONGEST len) |
4101 | { | |
4102 | struct breakpoint *bpt; | |
4103 | ||
4104 | ALL_BREAKPOINTS (bpt) | |
4105 | { | |
4106 | struct bp_location *loc; | |
4107 | ||
4108 | if (bpt->type != bp_hardware_watchpoint | |
4109 | && bpt->type != bp_access_watchpoint) | |
4110 | continue; | |
4111 | ||
4112 | if (!breakpoint_enabled (bpt)) | |
4113 | continue; | |
4114 | ||
4115 | for (loc = bpt->loc; loc; loc = loc->next) | |
4116 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4117 | { | |
4118 | CORE_ADDR l, h; | |
4119 | ||
4120 | /* Check for intersection. */ | |
768adc05 PA |
4121 | l = std::max<CORE_ADDR> (loc->address, addr); |
4122 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4123 | if (l < h) |
4124 | return 1; | |
4125 | } | |
4126 | } | |
4127 | return 0; | |
4128 | } | |
c5aa993b | 4129 | |
f2478a7e | 4130 | /* See breakpoint.h. */ |
c906108c | 4131 | |
f2478a7e SM |
4132 | bool |
4133 | is_catchpoint (struct breakpoint *b) | |
c906108c | 4134 | { |
f2478a7e | 4135 | return (b->type == bp_catchpoint); |
c906108c SS |
4136 | } |
4137 | ||
f431efe5 PA |
4138 | /* Frees any storage that is part of a bpstat. Does not walk the |
4139 | 'next' chain. */ | |
4140 | ||
04afa70c | 4141 | bpstats::~bpstats () |
198757a8 | 4142 | { |
04afa70c TT |
4143 | if (bp_location_at != NULL) |
4144 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4145 | } |
4146 | ||
c906108c SS |
4147 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4148 | Also free any storage that is part of a bpstat. */ | |
4149 | ||
4150 | void | |
fba45db2 | 4151 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4152 | { |
4153 | bpstat p; | |
4154 | bpstat q; | |
4155 | ||
4156 | if (bsp == 0) | |
4157 | return; | |
4158 | p = *bsp; | |
4159 | while (p != NULL) | |
4160 | { | |
4161 | q = p->next; | |
04afa70c | 4162 | delete p; |
c906108c SS |
4163 | p = q; |
4164 | } | |
4165 | *bsp = NULL; | |
4166 | } | |
4167 | ||
04afa70c TT |
4168 | bpstats::bpstats (const bpstats &other) |
4169 | : next (NULL), | |
4170 | bp_location_at (other.bp_location_at), | |
4171 | breakpoint_at (other.breakpoint_at), | |
4172 | commands (other.commands), | |
04afa70c TT |
4173 | print (other.print), |
4174 | stop (other.stop), | |
4175 | print_it (other.print_it) | |
4176 | { | |
850645cf TT |
4177 | if (other.old_val != NULL) |
4178 | old_val = release_value (value_copy (other.old_val.get ())); | |
04afa70c | 4179 | incref_bp_location (bp_location_at); |
04afa70c TT |
4180 | } |
4181 | ||
c906108c SS |
4182 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4183 | is part of the bpstat is copied as well. */ | |
4184 | ||
4185 | bpstat | |
fba45db2 | 4186 | bpstat_copy (bpstat bs) |
c906108c SS |
4187 | { |
4188 | bpstat p = NULL; | |
4189 | bpstat tmp; | |
4190 | bpstat retval = NULL; | |
4191 | ||
4192 | if (bs == NULL) | |
4193 | return bs; | |
4194 | ||
4195 | for (; bs != NULL; bs = bs->next) | |
4196 | { | |
04afa70c | 4197 | tmp = new bpstats (*bs); |
31cc81e9 | 4198 | |
c906108c SS |
4199 | if (p == NULL) |
4200 | /* This is the first thing in the chain. */ | |
4201 | retval = tmp; | |
4202 | else | |
4203 | p->next = tmp; | |
4204 | p = tmp; | |
4205 | } | |
4206 | p->next = NULL; | |
4207 | return retval; | |
4208 | } | |
4209 | ||
4a64f543 | 4210 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4211 | |
4212 | bpstat | |
fba45db2 | 4213 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4214 | { |
c5aa993b JM |
4215 | if (bsp == NULL) |
4216 | return NULL; | |
c906108c | 4217 | |
c5aa993b JM |
4218 | for (; bsp != NULL; bsp = bsp->next) |
4219 | { | |
f431efe5 | 4220 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4221 | return bsp; |
4222 | } | |
c906108c SS |
4223 | return NULL; |
4224 | } | |
4225 | ||
ab04a2af TT |
4226 | /* See breakpoint.h. */ |
4227 | ||
4c462cb0 | 4228 | bool |
427cd150 | 4229 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4230 | { |
ab04a2af TT |
4231 | for (; bsp != NULL; bsp = bsp->next) |
4232 | { | |
427cd150 TT |
4233 | if (bsp->breakpoint_at == NULL) |
4234 | { | |
4235 | /* A moribund location can never explain a signal other than | |
4236 | GDB_SIGNAL_TRAP. */ | |
4237 | if (sig == GDB_SIGNAL_TRAP) | |
4c462cb0 | 4238 | return true; |
427cd150 TT |
4239 | } |
4240 | else | |
47591c29 PA |
4241 | { |
4242 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4243 | sig)) | |
4c462cb0 | 4244 | return true; |
47591c29 | 4245 | } |
ab04a2af TT |
4246 | } |
4247 | ||
4c462cb0 | 4248 | return false; |
ab04a2af TT |
4249 | } |
4250 | ||
4a64f543 MS |
4251 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4252 | stopped at. *BSP upon return is a bpstat which points to the | |
4253 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4254 | good for anything but further calls to bpstat_num). | |
4255 | ||
8671a17b PA |
4256 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4257 | Return -1 if stopped at a breakpoint that has been deleted since | |
4258 | we set it. | |
4259 | Return 1 otherwise. */ | |
c906108c SS |
4260 | |
4261 | int | |
8671a17b | 4262 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4263 | { |
4264 | struct breakpoint *b; | |
4265 | ||
4266 | if ((*bsp) == NULL) | |
4267 | return 0; /* No more breakpoint values */ | |
8671a17b | 4268 | |
4a64f543 MS |
4269 | /* We assume we'll never have several bpstats that correspond to a |
4270 | single breakpoint -- otherwise, this function might return the | |
4271 | same number more than once and this will look ugly. */ | |
f431efe5 | 4272 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4273 | *bsp = (*bsp)->next; |
4274 | if (b == NULL) | |
4275 | return -1; /* breakpoint that's been deleted since */ | |
4276 | ||
4277 | *num = b->number; /* We have its number */ | |
4278 | return 1; | |
c906108c SS |
4279 | } |
4280 | ||
e93ca019 | 4281 | /* See breakpoint.h. */ |
c906108c SS |
4282 | |
4283 | void | |
e93ca019 | 4284 | bpstat_clear_actions (void) |
c906108c | 4285 | { |
e93ca019 JK |
4286 | bpstat bs; |
4287 | ||
00431a78 | 4288 | if (inferior_ptid == null_ptid) |
e93ca019 JK |
4289 | return; |
4290 | ||
00431a78 | 4291 | thread_info *tp = inferior_thread (); |
e93ca019 | 4292 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
c906108c | 4293 | { |
d1b0a7bf | 4294 | bs->commands = NULL; |
850645cf | 4295 | bs->old_val.reset (nullptr); |
c906108c SS |
4296 | } |
4297 | } | |
4298 | ||
f3b1572e PA |
4299 | /* Called when a command is about to proceed the inferior. */ |
4300 | ||
4301 | static void | |
4302 | breakpoint_about_to_proceed (void) | |
4303 | { | |
d7e15655 | 4304 | if (inferior_ptid != null_ptid) |
f3b1572e PA |
4305 | { |
4306 | struct thread_info *tp = inferior_thread (); | |
4307 | ||
4308 | /* Allow inferior function calls in breakpoint commands to not | |
4309 | interrupt the command list. When the call finishes | |
4310 | successfully, the inferior will be standing at the same | |
4311 | breakpoint as if nothing happened. */ | |
16c381f0 | 4312 | if (tp->control.in_infcall) |
f3b1572e PA |
4313 | return; |
4314 | } | |
4315 | ||
4316 | breakpoint_proceeded = 1; | |
4317 | } | |
4318 | ||
abf85f46 JK |
4319 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4320 | or its equivalent. */ | |
4321 | ||
4322 | static int | |
4323 | command_line_is_silent (struct command_line *cmd) | |
4324 | { | |
4f45d445 | 4325 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4326 | } |
4327 | ||
4a64f543 MS |
4328 | /* Execute all the commands associated with all the breakpoints at |
4329 | this location. Any of these commands could cause the process to | |
4330 | proceed beyond this point, etc. We look out for such changes by | |
4331 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4332 | |
347bddb7 PA |
4333 | Returns true if a breakpoint command resumed the inferior. In that |
4334 | case, it is the caller's responsibility to recall it again with the | |
4335 | bpstat of the current thread. */ | |
4336 | ||
4337 | static int | |
4338 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4339 | { |
4340 | bpstat bs; | |
347bddb7 | 4341 | int again = 0; |
c906108c SS |
4342 | |
4343 | /* Avoid endless recursion if a `source' command is contained | |
4344 | in bs->commands. */ | |
4345 | if (executing_breakpoint_commands) | |
347bddb7 | 4346 | return 0; |
c906108c | 4347 | |
81b1e71c TT |
4348 | scoped_restore save_executing |
4349 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4350 | |
1ac32117 | 4351 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4352 | |
4a64f543 | 4353 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4354 | bs = *bsp; |
4355 | ||
4356 | breakpoint_proceeded = 0; | |
4357 | for (; bs != NULL; bs = bs->next) | |
4358 | { | |
d1b0a7bf | 4359 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4360 | |
4361 | /* Take ownership of the BSP's command tree, if it has one. | |
4362 | ||
4363 | The command tree could legitimately contain commands like | |
4364 | 'step' and 'next', which call clear_proceed_status, which | |
4365 | frees stop_bpstat's command tree. To make sure this doesn't | |
4366 | free the tree we're executing out from under us, we need to | |
4367 | take ownership of the tree ourselves. Since a given bpstat's | |
4368 | commands are only executed once, we don't need to copy it; we | |
4369 | can clear the pointer in the bpstat, and make sure we free | |
4370 | the tree when we're done. */ | |
d1b0a7bf | 4371 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4372 | bs->commands = NULL; |
d1b0a7bf TT |
4373 | if (ccmd != NULL) |
4374 | cmd = ccmd.get (); | |
abf85f46 JK |
4375 | if (command_line_is_silent (cmd)) |
4376 | { | |
4377 | /* The action has been already done by bpstat_stop_status. */ | |
4378 | cmd = cmd->next; | |
4379 | } | |
6c50ab1c | 4380 | |
c906108c SS |
4381 | while (cmd != NULL) |
4382 | { | |
4383 | execute_control_command (cmd); | |
4384 | ||
4385 | if (breakpoint_proceeded) | |
4386 | break; | |
4387 | else | |
4388 | cmd = cmd->next; | |
4389 | } | |
6c50ab1c | 4390 | |
c906108c | 4391 | if (breakpoint_proceeded) |
32c1e744 | 4392 | { |
cb814510 | 4393 | if (current_ui->async) |
347bddb7 PA |
4394 | /* If we are in async mode, then the target might be still |
4395 | running, not stopped at any breakpoint, so nothing for | |
4396 | us to do here -- just return to the event loop. */ | |
4397 | ; | |
32c1e744 VP |
4398 | else |
4399 | /* In sync mode, when execute_control_command returns | |
4400 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4401 | Breakpoint commands for that stop were not run, since |
4402 | execute_command does not run breakpoint commands -- | |
4403 | only command_line_handler does, but that one is not | |
4404 | involved in execution of breakpoint commands. So, we | |
4405 | can now execute breakpoint commands. It should be | |
4406 | noted that making execute_command do bpstat actions is | |
4407 | not an option -- in this case we'll have recursive | |
4408 | invocation of bpstat for each breakpoint with a | |
4409 | command, and can easily blow up GDB stack. Instead, we | |
4410 | return true, which will trigger the caller to recall us | |
4411 | with the new stop_bpstat. */ | |
4412 | again = 1; | |
4413 | break; | |
32c1e744 | 4414 | } |
c906108c | 4415 | } |
347bddb7 PA |
4416 | return again; |
4417 | } | |
4418 | ||
00431a78 PA |
4419 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
4420 | one, is alive and has execution. Return NULL otherwise. */ | |
4421 | ||
4422 | static thread_info * | |
4423 | get_bpstat_thread () | |
4424 | { | |
4425 | if (inferior_ptid == null_ptid || !target_has_execution) | |
4426 | return NULL; | |
4427 | ||
4428 | thread_info *tp = inferior_thread (); | |
4429 | if (tp->state == THREAD_EXITED || tp->executing) | |
4430 | return NULL; | |
4431 | return tp; | |
4432 | } | |
4433 | ||
347bddb7 PA |
4434 | void |
4435 | bpstat_do_actions (void) | |
4436 | { | |
694c6bf5 | 4437 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
00431a78 | 4438 | thread_info *tp; |
353d1d73 | 4439 | |
347bddb7 | 4440 | /* Do any commands attached to breakpoint we are stopped at. */ |
00431a78 PA |
4441 | while ((tp = get_bpstat_thread ()) != NULL) |
4442 | { | |
4443 | /* Since in sync mode, bpstat_do_actions may resume the | |
4444 | inferior, and only return when it is stopped at the next | |
4445 | breakpoint, we keep doing breakpoint actions until it returns | |
4446 | false to indicate the inferior was not resumed. */ | |
4447 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) | |
4448 | break; | |
4449 | } | |
353d1d73 | 4450 | |
694c6bf5 | 4451 | cleanup_if_error.release (); |
c906108c SS |
4452 | } |
4453 | ||
fa4727a6 DJ |
4454 | /* Print out the (old or new) value associated with a watchpoint. */ |
4455 | ||
4456 | static void | |
4457 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4458 | { | |
4459 | if (val == NULL) | |
7f6aba03 | 4460 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
fa4727a6 | 4461 | else |
79a45b7d TT |
4462 | { |
4463 | struct value_print_options opts; | |
4464 | get_user_print_options (&opts); | |
4465 | value_print (val, stream, &opts); | |
4466 | } | |
fa4727a6 DJ |
4467 | } |
4468 | ||
f303dbd6 PA |
4469 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4470 | debugging multiple threads. */ | |
4471 | ||
4472 | void | |
4473 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4474 | { | |
112e8700 | 4475 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4476 | return; |
4477 | ||
112e8700 | 4478 | uiout->text ("\n"); |
f303dbd6 PA |
4479 | |
4480 | if (show_thread_that_caused_stop ()) | |
4481 | { | |
4482 | const char *name; | |
4483 | struct thread_info *thr = inferior_thread (); | |
4484 | ||
112e8700 | 4485 | uiout->text ("Thread "); |
33eca680 | 4486 | uiout->field_string ("thread-id", print_thread_id (thr)); |
f303dbd6 PA |
4487 | |
4488 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4489 | if (name != NULL) | |
4490 | { | |
112e8700 | 4491 | uiout->text (" \""); |
33eca680 | 4492 | uiout->field_string ("name", name); |
112e8700 | 4493 | uiout->text ("\""); |
f303dbd6 PA |
4494 | } |
4495 | ||
112e8700 | 4496 | uiout->text (" hit "); |
f303dbd6 PA |
4497 | } |
4498 | } | |
4499 | ||
e514a9d6 | 4500 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4501 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4502 | 'print_it' in the bpstat structure. Under some circumstances we |
4503 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4504 | normal_stop(). */ |
e514a9d6 JM |
4505 | |
4506 | static enum print_stop_action | |
4507 | print_bp_stop_message (bpstat bs) | |
4508 | { | |
4509 | switch (bs->print_it) | |
4510 | { | |
4511 | case print_it_noop: | |
4a64f543 | 4512 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4513 | return PRINT_UNKNOWN; |
4514 | break; | |
4515 | ||
4516 | case print_it_done: | |
4517 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4518 | relevant messages. */ |
e514a9d6 JM |
4519 | return PRINT_SRC_AND_LOC; |
4520 | break; | |
4521 | ||
4522 | case print_it_normal: | |
4f8d1dc6 | 4523 | { |
f431efe5 PA |
4524 | struct breakpoint *b = bs->breakpoint_at; |
4525 | ||
1a6a67de TJB |
4526 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4527 | which has since been deleted. */ | |
4528 | if (b == NULL) | |
4529 | return PRINT_UNKNOWN; | |
4530 | ||
348d480f PA |
4531 | /* Normal case. Call the breakpoint's print_it method. */ |
4532 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4533 | } |
348d480f | 4534 | break; |
3086aeae | 4535 | |
e514a9d6 | 4536 | default: |
8e65ff28 | 4537 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4538 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4539 | break; |
c906108c | 4540 | } |
c906108c SS |
4541 | } |
4542 | ||
edcc5120 TT |
4543 | /* A helper function that prints a shared library stopped event. */ |
4544 | ||
4545 | static void | |
4546 | print_solib_event (int is_catchpoint) | |
4547 | { | |
6fb16ce6 | 4548 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
bcb430e4 | 4549 | bool any_added = !current_program_space->added_solibs.empty (); |
edcc5120 TT |
4550 | |
4551 | if (!is_catchpoint) | |
4552 | { | |
4553 | if (any_added || any_deleted) | |
112e8700 | 4554 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4555 | else |
112e8700 SM |
4556 | current_uiout->text (_("Stopped due to shared library event (no " |
4557 | "libraries added or removed)\n")); | |
edcc5120 TT |
4558 | } |
4559 | ||
112e8700 SM |
4560 | if (current_uiout->is_mi_like_p ()) |
4561 | current_uiout->field_string ("reason", | |
4562 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4563 | |
4564 | if (any_deleted) | |
4565 | { | |
112e8700 | 4566 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4567 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
6fb16ce6 | 4568 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
edcc5120 | 4569 | { |
6fb16ce6 SM |
4570 | const std::string &name = current_program_space->deleted_solibs[ix]; |
4571 | ||
edcc5120 | 4572 | if (ix > 0) |
112e8700 SM |
4573 | current_uiout->text (" "); |
4574 | current_uiout->field_string ("library", name); | |
4575 | current_uiout->text ("\n"); | |
edcc5120 | 4576 | } |
edcc5120 TT |
4577 | } |
4578 | ||
4579 | if (any_added) | |
4580 | { | |
112e8700 | 4581 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4582 | ui_out_emit_list list_emitter (current_uiout, "added"); |
bcb430e4 | 4583 | bool first = true; |
52941706 | 4584 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 | 4585 | { |
bcb430e4 | 4586 | if (!first) |
112e8700 | 4587 | current_uiout->text (" "); |
bcb430e4 | 4588 | first = false; |
112e8700 SM |
4589 | current_uiout->field_string ("library", iter->so_name); |
4590 | current_uiout->text ("\n"); | |
edcc5120 | 4591 | } |
edcc5120 TT |
4592 | } |
4593 | } | |
4594 | ||
e514a9d6 JM |
4595 | /* Print a message indicating what happened. This is called from |
4596 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4597 | list - a list of the eventpoints that caused this stop. KIND is |
4598 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4599 | routine calls the generic print routine for printing a message |
4600 | about reasons for stopping. This will print (for example) the | |
4601 | "Breakpoint n," part of the output. The return value of this | |
4602 | routine is one of: | |
c906108c | 4603 | |
4a64f543 | 4604 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4605 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4606 | code to print the location. An example is |
c5aa993b JM |
4607 | "Breakpoint 1, " which should be followed by |
4608 | the location. | |
917317f4 | 4609 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4610 | to also print the location part of the message. |
4611 | An example is the catch/throw messages, which | |
4a64f543 | 4612 | don't require a location appended to the end. |
917317f4 | 4613 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4614 | further info to be printed. */ |
c906108c | 4615 | |
917317f4 | 4616 | enum print_stop_action |
36dfb11c | 4617 | bpstat_print (bpstat bs, int kind) |
c906108c | 4618 | { |
f486487f | 4619 | enum print_stop_action val; |
c5aa993b | 4620 | |
c906108c | 4621 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4622 | (Currently all watchpoints go on the bpstat whether hit or not. |
4623 | That probably could (should) be changed, provided care is taken | |
c906108c | 4624 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4625 | for (; bs; bs = bs->next) |
4626 | { | |
4627 | val = print_bp_stop_message (bs); | |
4628 | if (val == PRINT_SRC_ONLY | |
4629 | || val == PRINT_SRC_AND_LOC | |
4630 | || val == PRINT_NOTHING) | |
4631 | return val; | |
4632 | } | |
c906108c | 4633 | |
36dfb11c TT |
4634 | /* If we had hit a shared library event breakpoint, |
4635 | print_bp_stop_message would print out this message. If we hit an | |
4636 | OS-level shared library event, do the same thing. */ | |
4637 | if (kind == TARGET_WAITKIND_LOADED) | |
4638 | { | |
edcc5120 | 4639 | print_solib_event (0); |
36dfb11c TT |
4640 | return PRINT_NOTHING; |
4641 | } | |
4642 | ||
e514a9d6 | 4643 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4644 | with and nothing was printed. */ |
917317f4 | 4645 | return PRINT_UNKNOWN; |
c906108c SS |
4646 | } |
4647 | ||
bf469271 | 4648 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4649 | |
bf469271 PA |
4650 | static bool |
4651 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4652 | { |
278cd55f | 4653 | struct value *mark = value_mark (); |
bf469271 | 4654 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4655 | |
c906108c | 4656 | value_free_to_mark (mark); |
bf469271 | 4657 | return res; |
c906108c SS |
4658 | } |
4659 | ||
5760d0ab | 4660 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4661 | |
04afa70c TT |
4662 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4663 | : next (NULL), | |
4664 | bp_location_at (bl), | |
4665 | breakpoint_at (bl->owner), | |
4666 | commands (NULL), | |
04afa70c TT |
4667 | print (0), |
4668 | stop (0), | |
4669 | print_it (print_it_normal) | |
c906108c | 4670 | { |
f431efe5 | 4671 | incref_bp_location (bl); |
04afa70c TT |
4672 | **bs_link_pointer = this; |
4673 | *bs_link_pointer = &next; | |
4674 | } | |
4675 | ||
4676 | bpstats::bpstats () | |
4677 | : next (NULL), | |
4678 | bp_location_at (NULL), | |
4679 | breakpoint_at (NULL), | |
4680 | commands (NULL), | |
04afa70c TT |
4681 | print (0), |
4682 | stop (0), | |
4683 | print_it (print_it_normal) | |
4684 | { | |
c906108c SS |
4685 | } |
4686 | \f | |
d983da9c DJ |
4687 | /* The target has stopped with waitstatus WS. Check if any hardware |
4688 | watchpoints have triggered, according to the target. */ | |
4689 | ||
4690 | int | |
4691 | watchpoints_triggered (struct target_waitstatus *ws) | |
4692 | { | |
57810aa7 | 4693 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4694 | CORE_ADDR addr; |
4695 | struct breakpoint *b; | |
4696 | ||
4697 | if (!stopped_by_watchpoint) | |
4698 | { | |
4699 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4700 | as not triggered. */ | |
4701 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4702 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4703 | { |
4704 | struct watchpoint *w = (struct watchpoint *) b; | |
4705 | ||
4706 | w->watchpoint_triggered = watch_triggered_no; | |
4707 | } | |
d983da9c DJ |
4708 | |
4709 | return 0; | |
4710 | } | |
4711 | ||
8b88a78e | 4712 | if (!target_stopped_data_address (current_top_target (), &addr)) |
d983da9c DJ |
4713 | { |
4714 | /* We were stopped by a watchpoint, but we don't know where. | |
4715 | Mark all watchpoints as unknown. */ | |
4716 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4717 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4718 | { |
4719 | struct watchpoint *w = (struct watchpoint *) b; | |
4720 | ||
4721 | w->watchpoint_triggered = watch_triggered_unknown; | |
4722 | } | |
d983da9c | 4723 | |
3c4797ba | 4724 | return 1; |
d983da9c DJ |
4725 | } |
4726 | ||
4727 | /* The target could report the data address. Mark watchpoints | |
4728 | affected by this data address as triggered, and all others as not | |
4729 | triggered. */ | |
4730 | ||
4731 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4732 | if (is_hardware_watchpoint (b)) |
d983da9c | 4733 | { |
3a5c3e22 | 4734 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4735 | struct bp_location *loc; |
d983da9c | 4736 | |
3a5c3e22 | 4737 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4738 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4739 | { |
3a5c3e22 | 4740 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4741 | { |
3a5c3e22 PA |
4742 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4743 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4744 | |
4745 | if (newaddr == start) | |
4746 | { | |
3a5c3e22 | 4747 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4748 | break; |
4749 | } | |
4750 | } | |
4751 | /* Exact match not required. Within range is sufficient. */ | |
8b88a78e | 4752 | else if (target_watchpoint_addr_within_range (current_top_target (), |
9c06b0b4 TJB |
4753 | addr, loc->address, |
4754 | loc->length)) | |
4755 | { | |
3a5c3e22 | 4756 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4757 | break; |
4758 | } | |
4759 | } | |
d983da9c DJ |
4760 | } |
4761 | ||
4762 | return 1; | |
4763 | } | |
4764 | ||
bf469271 PA |
4765 | /* Possible return values for watchpoint_check. */ |
4766 | enum wp_check_result | |
4767 | { | |
4768 | /* The watchpoint has been deleted. */ | |
4769 | WP_DELETED = 1, | |
4770 | ||
4771 | /* The value has changed. */ | |
4772 | WP_VALUE_CHANGED = 2, | |
4773 | ||
4774 | /* The value has not changed. */ | |
4775 | WP_VALUE_NOT_CHANGED = 3, | |
4776 | ||
4777 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4778 | WP_IGNORE = 4, | |
4779 | }; | |
c906108c SS |
4780 | |
4781 | #define BP_TEMPFLAG 1 | |
4782 | #define BP_HARDWAREFLAG 2 | |
4783 | ||
4a64f543 | 4784 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4785 | changed. */ |
553e4c11 | 4786 | |
bf469271 PA |
4787 | static wp_check_result |
4788 | watchpoint_check (bpstat bs) | |
c906108c | 4789 | { |
3a5c3e22 | 4790 | struct watchpoint *b; |
c906108c SS |
4791 | struct frame_info *fr; |
4792 | int within_current_scope; | |
4793 | ||
f431efe5 | 4794 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4795 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4796 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4797 | |
f6bc2008 PA |
4798 | /* If this is a local watchpoint, we only want to check if the |
4799 | watchpoint frame is in scope if the current thread is the thread | |
4800 | that was used to create the watchpoint. */ | |
4801 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4802 | return WP_IGNORE; |
f6bc2008 | 4803 | |
c906108c SS |
4804 | if (b->exp_valid_block == NULL) |
4805 | within_current_scope = 1; | |
4806 | else | |
4807 | { | |
edb3359d DJ |
4808 | struct frame_info *frame = get_current_frame (); |
4809 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4810 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4811 | ||
c9cf6e20 | 4812 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4813 | still in the function but the stack frame has already been |
4814 | invalidated. Since we can't rely on the values of local | |
4815 | variables after the stack has been destroyed, we are treating | |
4816 | the watchpoint in that state as `not changed' without further | |
4817 | checking. Don't mark watchpoints as changed if the current | |
4818 | frame is in an epilogue - even if they are in some other | |
4819 | frame, our view of the stack is likely to be wrong and | |
4820 | frame_find_by_id could error out. */ | |
c9cf6e20 | 4821 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 4822 | return WP_IGNORE; |
a0f49112 | 4823 | |
101dcfbe | 4824 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4825 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4826 | |
4827 | /* If we've gotten confused in the unwinder, we might have | |
4828 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4829 | if (within_current_scope) |
4830 | { | |
4831 | struct symbol *function; | |
4832 | ||
4833 | function = get_frame_function (fr); | |
4834 | if (function == NULL | |
4835 | || !contained_in (b->exp_valid_block, | |
4836 | SYMBOL_BLOCK_VALUE (function))) | |
4837 | within_current_scope = 0; | |
4838 | } | |
69fbadd5 | 4839 | |
edb3359d | 4840 | if (within_current_scope) |
c906108c SS |
4841 | /* If we end up stopping, the current frame will get selected |
4842 | in normal_stop. So this call to select_frame won't affect | |
4843 | the user. */ | |
0f7d239c | 4844 | select_frame (fr); |
c906108c | 4845 | } |
c5aa993b | 4846 | |
c906108c SS |
4847 | if (within_current_scope) |
4848 | { | |
4a64f543 MS |
4849 | /* We use value_{,free_to_}mark because it could be a *long* |
4850 | time before we return to the command level and call | |
4851 | free_all_values. We can't call free_all_values because we | |
4852 | might be in the middle of evaluating a function call. */ | |
c906108c | 4853 | |
0cf6dd15 | 4854 | int pc = 0; |
9c06b0b4 | 4855 | struct value *mark; |
fa4727a6 DJ |
4856 | struct value *new_val; |
4857 | ||
c1fc2657 | 4858 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
4859 | /* Since we don't know the exact trigger address (from |
4860 | stopped_data_address), just tell the user we've triggered | |
4861 | a mask watchpoint. */ | |
4862 | return WP_VALUE_CHANGED; | |
4863 | ||
4864 | mark = value_mark (); | |
4d01a485 | 4865 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4866 | |
bb9d5f81 PP |
4867 | if (b->val_bitsize != 0) |
4868 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
4869 | ||
4a64f543 MS |
4870 | /* We use value_equal_contents instead of value_equal because |
4871 | the latter coerces an array to a pointer, thus comparing just | |
4872 | the address of the array instead of its contents. This is | |
4873 | not what we want. */ | |
fa4727a6 | 4874 | if ((b->val != NULL) != (new_val != NULL) |
850645cf TT |
4875 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
4876 | new_val))) | |
c906108c | 4877 | { |
c906108c | 4878 | bs->old_val = b->val; |
850645cf | 4879 | b->val = release_value (new_val); |
4c1d86d9 | 4880 | b->val_valid = true; |
850645cf TT |
4881 | if (new_val != NULL) |
4882 | value_free_to_mark (mark); | |
c906108c SS |
4883 | return WP_VALUE_CHANGED; |
4884 | } | |
4885 | else | |
4886 | { | |
60e1c644 | 4887 | /* Nothing changed. */ |
c906108c | 4888 | value_free_to_mark (mark); |
c906108c SS |
4889 | return WP_VALUE_NOT_CHANGED; |
4890 | } | |
4891 | } | |
4892 | else | |
4893 | { | |
4894 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
4895 | if we temporarily ignored the watchpoint, then when |
4896 | we reenter the block in which it is valid it contains | |
4897 | garbage (in the case of a function, it may have two | |
4898 | garbage values, one before and one after the prologue). | |
4899 | So we can't even detect the first assignment to it and | |
4900 | watch after that (since the garbage may or may not equal | |
4901 | the first value assigned). */ | |
348d480f PA |
4902 | /* We print all the stop information in |
4903 | breakpoint_ops->print_it, but in this case, by the time we | |
4904 | call breakpoint_ops->print_it this bp will be deleted | |
4905 | already. So we have no choice but print the information | |
4906 | here. */ | |
468afe6c | 4907 | |
0e454242 | 4908 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
4909 | { |
4910 | struct ui_out *uiout = current_uiout; | |
4911 | ||
112e8700 SM |
4912 | if (uiout->is_mi_like_p ()) |
4913 | uiout->field_string | |
4914 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
6a831f06 PA |
4915 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
4916 | "left the block in\n" | |
4917 | "which its expression is valid.\n", | |
4918 | signed_field ("wpnum", b->number)); | |
468afe6c | 4919 | } |
4ce44c66 | 4920 | |
cdac0397 | 4921 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 4922 | b->commands = NULL; |
d0fb5eae | 4923 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4924 | |
4925 | return WP_DELETED; | |
4926 | } | |
4927 | } | |
4928 | ||
18a18393 | 4929 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4930 | breakpoint location BL. This function does not check if we should |
4931 | stop, only if BL explains the stop. */ | |
4932 | ||
18a18393 | 4933 | static int |
6c95b8df | 4934 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 4935 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 4936 | const struct target_waitstatus *ws) |
18a18393 VP |
4937 | { |
4938 | struct breakpoint *b = bl->owner; | |
4939 | ||
348d480f | 4940 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4941 | gdb_assert (b != NULL); |
4942 | ||
bd522513 | 4943 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4944 | } |
4945 | ||
3a5c3e22 PA |
4946 | /* Determine if the watched values have actually changed, and we |
4947 | should stop. If not, set BS->stop to 0. */ | |
4948 | ||
18a18393 VP |
4949 | static void |
4950 | bpstat_check_watchpoint (bpstat bs) | |
4951 | { | |
2bdf28a0 | 4952 | const struct bp_location *bl; |
3a5c3e22 | 4953 | struct watchpoint *b; |
2bdf28a0 JK |
4954 | |
4955 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4956 | bl = bs->bp_location_at; |
2bdf28a0 | 4957 | gdb_assert (bl != NULL); |
3a5c3e22 | 4958 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4959 | gdb_assert (b != NULL); |
18a18393 | 4960 | |
18a18393 | 4961 | { |
18a18393 VP |
4962 | int must_check_value = 0; |
4963 | ||
c1fc2657 | 4964 | if (b->type == bp_watchpoint) |
18a18393 VP |
4965 | /* For a software watchpoint, we must always check the |
4966 | watched value. */ | |
4967 | must_check_value = 1; | |
4968 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4969 | /* We have a hardware watchpoint (read, write, or access) | |
4970 | and the target earlier reported an address watched by | |
4971 | this watchpoint. */ | |
4972 | must_check_value = 1; | |
4973 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 4974 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
4975 | /* We were stopped by a hardware watchpoint, but the target could |
4976 | not report the data address. We must check the watchpoint's | |
4977 | value. Access and read watchpoints are out of luck; without | |
4978 | a data address, we can't figure it out. */ | |
4979 | must_check_value = 1; | |
3a5c3e22 | 4980 | |
18a18393 VP |
4981 | if (must_check_value) |
4982 | { | |
bf469271 PA |
4983 | wp_check_result e; |
4984 | ||
a70b8144 | 4985 | try |
bf469271 PA |
4986 | { |
4987 | e = watchpoint_check (bs); | |
4988 | } | |
230d2906 | 4989 | catch (const gdb_exception &ex) |
bf469271 PA |
4990 | { |
4991 | exception_fprintf (gdb_stderr, ex, | |
4992 | "Error evaluating expression " | |
4993 | "for watchpoint %d\n", | |
4994 | b->number); | |
4995 | ||
4996 | SWITCH_THRU_ALL_UIS () | |
4997 | { | |
4998 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
4999 | b->number); | |
5000 | } | |
5001 | watchpoint_del_at_next_stop (b); | |
5002 | e = WP_DELETED; | |
5003 | } | |
bf469271 | 5004 | |
18a18393 VP |
5005 | switch (e) |
5006 | { | |
5007 | case WP_DELETED: | |
5008 | /* We've already printed what needs to be printed. */ | |
5009 | bs->print_it = print_it_done; | |
5010 | /* Stop. */ | |
5011 | break; | |
60e1c644 PA |
5012 | case WP_IGNORE: |
5013 | bs->print_it = print_it_noop; | |
5014 | bs->stop = 0; | |
5015 | break; | |
18a18393 | 5016 | case WP_VALUE_CHANGED: |
c1fc2657 | 5017 | if (b->type == bp_read_watchpoint) |
18a18393 | 5018 | { |
85d721b8 PA |
5019 | /* There are two cases to consider here: |
5020 | ||
4a64f543 | 5021 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5022 | In that case, trust the target, and always report |
5023 | the watchpoint hit to the user. Even though | |
5024 | reads don't cause value changes, the value may | |
5025 | have changed since the last time it was read, and | |
5026 | since we're not trapping writes, we will not see | |
5027 | those, and as such we should ignore our notion of | |
5028 | old value. | |
5029 | ||
4a64f543 | 5030 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5031 | reads and writes. There are two ways this may |
5032 | happen: | |
5033 | ||
4a64f543 | 5034 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5035 | reads only, but can break on accesses (reads or |
5036 | writes), such as e.g., x86. We detect this case | |
5037 | at the time we try to insert read watchpoints. | |
5038 | ||
4a64f543 | 5039 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5040 | watchpoints, but, the user set an access or write |
5041 | watchpoint watching the same memory as this read | |
5042 | watchpoint. | |
5043 | ||
5044 | If we're watching memory writes as well as reads, | |
5045 | ignore watchpoint hits when we find that the | |
5046 | value hasn't changed, as reads don't cause | |
5047 | changes. This still gives false positives when | |
5048 | the program writes the same value to memory as | |
5049 | what there was already in memory (we will confuse | |
5050 | it for a read), but it's much better than | |
5051 | nothing. */ | |
5052 | ||
5053 | int other_write_watchpoint = 0; | |
5054 | ||
5055 | if (bl->watchpoint_type == hw_read) | |
5056 | { | |
5057 | struct breakpoint *other_b; | |
5058 | ||
5059 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5060 | if (other_b->type == bp_hardware_watchpoint |
5061 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5062 | { |
3a5c3e22 PA |
5063 | struct watchpoint *other_w = |
5064 | (struct watchpoint *) other_b; | |
5065 | ||
5066 | if (other_w->watchpoint_triggered | |
5067 | == watch_triggered_yes) | |
5068 | { | |
5069 | other_write_watchpoint = 1; | |
5070 | break; | |
5071 | } | |
85d721b8 PA |
5072 | } |
5073 | } | |
5074 | ||
5075 | if (other_write_watchpoint | |
5076 | || bl->watchpoint_type == hw_access) | |
5077 | { | |
5078 | /* We're watching the same memory for writes, | |
5079 | and the value changed since the last time we | |
5080 | updated it, so this trap must be for a write. | |
5081 | Ignore it. */ | |
5082 | bs->print_it = print_it_noop; | |
5083 | bs->stop = 0; | |
5084 | } | |
18a18393 VP |
5085 | } |
5086 | break; | |
5087 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5088 | if (b->type == bp_hardware_watchpoint |
5089 | || b->type == bp_watchpoint) | |
18a18393 VP |
5090 | { |
5091 | /* Don't stop: write watchpoints shouldn't fire if | |
5092 | the value hasn't changed. */ | |
5093 | bs->print_it = print_it_noop; | |
5094 | bs->stop = 0; | |
5095 | } | |
5096 | /* Stop. */ | |
5097 | break; | |
5098 | default: | |
5099 | /* Can't happen. */ | |
18a18393 VP |
5100 | break; |
5101 | } | |
5102 | } | |
5103 | else /* must_check_value == 0 */ | |
5104 | { | |
5105 | /* This is a case where some watchpoint(s) triggered, but | |
5106 | not at the address of this watchpoint, or else no | |
5107 | watchpoint triggered after all. So don't print | |
5108 | anything for this watchpoint. */ | |
5109 | bs->print_it = print_it_noop; | |
5110 | bs->stop = 0; | |
5111 | } | |
5112 | } | |
5113 | } | |
5114 | ||
7d4df6a4 DE |
5115 | /* For breakpoints that are currently marked as telling gdb to stop, |
5116 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5117 | of breakpoint referred to by BS. If we should not stop for this |
5118 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5119 | |
18a18393 | 5120 | static void |
00431a78 | 5121 | bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread) |
18a18393 | 5122 | { |
2bdf28a0 JK |
5123 | const struct bp_location *bl; |
5124 | struct breakpoint *b; | |
bf469271 PA |
5125 | /* Assume stop. */ |
5126 | bool condition_result = true; | |
7d4df6a4 DE |
5127 | struct expression *cond; |
5128 | ||
5129 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5130 | |
5131 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5132 | bl = bs->bp_location_at; |
2bdf28a0 | 5133 | gdb_assert (bl != NULL); |
f431efe5 | 5134 | b = bs->breakpoint_at; |
2bdf28a0 | 5135 | gdb_assert (b != NULL); |
18a18393 | 5136 | |
b775012e LM |
5137 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5138 | need to do so again since GDB does not know if we stopped due to a | |
5139 | breakpoint or a single step breakpoint. */ | |
5140 | ||
18a18393 | 5141 | if (frame_id_p (b->frame_id) |
edb3359d | 5142 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5143 | { |
7d4df6a4 DE |
5144 | bs->stop = 0; |
5145 | return; | |
5146 | } | |
60e1c644 | 5147 | |
12ab52e9 PA |
5148 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5149 | evaluating the condition if this isn't the specified | |
5150 | thread/task. */ | |
00431a78 PA |
5151 | if ((b->thread != -1 && b->thread != thread->global_num) |
5152 | || (b->task != 0 && b->task != ada_get_task_number (thread))) | |
6c1b0f7b DE |
5153 | { |
5154 | bs->stop = 0; | |
5155 | return; | |
5156 | } | |
5157 | ||
6dddc817 DE |
5158 | /* Evaluate extension language breakpoints that have a "stop" method |
5159 | implemented. */ | |
5160 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5161 | |
7d4df6a4 DE |
5162 | if (is_watchpoint (b)) |
5163 | { | |
5164 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5165 | |
4d01a485 | 5166 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5167 | } |
5168 | else | |
4d01a485 | 5169 | cond = bl->cond.get (); |
60e1c644 | 5170 | |
7d4df6a4 DE |
5171 | if (cond && b->disposition != disp_del_at_next_stop) |
5172 | { | |
5173 | int within_current_scope = 1; | |
5174 | struct watchpoint * w; | |
60e1c644 | 5175 | |
7d4df6a4 DE |
5176 | /* We use value_mark and value_free_to_mark because it could |
5177 | be a long time before we return to the command level and | |
5178 | call free_all_values. We can't call free_all_values | |
5179 | because we might be in the middle of evaluating a | |
5180 | function call. */ | |
5181 | struct value *mark = value_mark (); | |
5182 | ||
5183 | if (is_watchpoint (b)) | |
5184 | w = (struct watchpoint *) b; | |
5185 | else | |
5186 | w = NULL; | |
5187 | ||
5188 | /* Need to select the frame, with all that implies so that | |
5189 | the conditions will have the right context. Because we | |
5190 | use the frame, we will not see an inlined function's | |
5191 | variables when we arrive at a breakpoint at the start | |
5192 | of the inlined function; the current frame will be the | |
5193 | call site. */ | |
5194 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5195 | select_frame (get_current_frame ()); | |
5196 | else | |
18a18393 | 5197 | { |
7d4df6a4 DE |
5198 | struct frame_info *frame; |
5199 | ||
5200 | /* For local watchpoint expressions, which particular | |
5201 | instance of a local is being watched matters, so we | |
5202 | keep track of the frame to evaluate the expression | |
5203 | in. To evaluate the condition however, it doesn't | |
5204 | really matter which instantiation of the function | |
5205 | where the condition makes sense triggers the | |
5206 | watchpoint. This allows an expression like "watch | |
5207 | global if q > 10" set in `func', catch writes to | |
5208 | global on all threads that call `func', or catch | |
5209 | writes on all recursive calls of `func' by a single | |
5210 | thread. We simply always evaluate the condition in | |
5211 | the innermost frame that's executing where it makes | |
5212 | sense to evaluate the condition. It seems | |
5213 | intuitive. */ | |
5214 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5215 | if (frame != NULL) | |
5216 | select_frame (frame); | |
5217 | else | |
5218 | within_current_scope = 0; | |
18a18393 | 5219 | } |
7d4df6a4 | 5220 | if (within_current_scope) |
bf469271 | 5221 | { |
a70b8144 | 5222 | try |
bf469271 PA |
5223 | { |
5224 | condition_result = breakpoint_cond_eval (cond); | |
5225 | } | |
230d2906 | 5226 | catch (const gdb_exception &ex) |
bf469271 PA |
5227 | { |
5228 | exception_fprintf (gdb_stderr, ex, | |
5229 | "Error in testing breakpoint condition:\n"); | |
5230 | } | |
bf469271 | 5231 | } |
7d4df6a4 | 5232 | else |
18a18393 | 5233 | { |
7d4df6a4 DE |
5234 | warning (_("Watchpoint condition cannot be tested " |
5235 | "in the current scope")); | |
5236 | /* If we failed to set the right context for this | |
5237 | watchpoint, unconditionally report it. */ | |
18a18393 | 5238 | } |
7d4df6a4 DE |
5239 | /* FIXME-someday, should give breakpoint #. */ |
5240 | value_free_to_mark (mark); | |
18a18393 | 5241 | } |
7d4df6a4 | 5242 | |
bf469271 | 5243 | if (cond && !condition_result) |
7d4df6a4 DE |
5244 | { |
5245 | bs->stop = 0; | |
5246 | } | |
7d4df6a4 DE |
5247 | else if (b->ignore_count > 0) |
5248 | { | |
5249 | b->ignore_count--; | |
5250 | bs->stop = 0; | |
5251 | /* Increase the hit count even though we don't stop. */ | |
5252 | ++(b->hit_count); | |
76727919 | 5253 | gdb::observers::breakpoint_modified.notify (b); |
7d4df6a4 | 5254 | } |
18a18393 VP |
5255 | } |
5256 | ||
1cf4d951 PA |
5257 | /* Returns true if we need to track moribund locations of LOC's type |
5258 | on the current target. */ | |
5259 | ||
5260 | static int | |
5261 | need_moribund_for_location_type (struct bp_location *loc) | |
5262 | { | |
5263 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5264 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5265 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5266 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5267 | } | |
5268 | ||
ddfe970e | 5269 | /* See breakpoint.h. */ |
c906108c SS |
5270 | |
5271 | bpstat | |
ddfe970e | 5272 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5273 | const struct target_waitstatus *ws) |
c906108c | 5274 | { |
ddfe970e | 5275 | struct breakpoint *b; |
5760d0ab | 5276 | bpstat bs_head = NULL, *bs_link = &bs_head; |
c5aa993b | 5277 | |
429374b8 JK |
5278 | ALL_BREAKPOINTS (b) |
5279 | { | |
1a853c52 | 5280 | if (!breakpoint_enabled (b)) |
429374b8 | 5281 | continue; |
a5606eee | 5282 | |
ddfe970e | 5283 | for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) |
429374b8 | 5284 | { |
4a64f543 MS |
5285 | /* For hardware watchpoints, we look only at the first |
5286 | location. The watchpoint_check function will work on the | |
5287 | entire expression, not the individual locations. For | |
5288 | read watchpoints, the watchpoints_triggered function has | |
5289 | checked all locations already. */ | |
429374b8 JK |
5290 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5291 | break; | |
18a18393 | 5292 | |
f6592439 | 5293 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5294 | continue; |
c5aa993b | 5295 | |
09ac7c10 | 5296 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5297 | continue; |
c5aa993b | 5298 | |
4a64f543 MS |
5299 | /* Come here if it's a watchpoint, or if the break address |
5300 | matches. */ | |
c5aa993b | 5301 | |
ddfe970e KS |
5302 | bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
5303 | explain stop. */ | |
c5aa993b | 5304 | |
f431efe5 PA |
5305 | /* Assume we stop. Should we find a watchpoint that is not |
5306 | actually triggered, or if the condition of the breakpoint | |
5307 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5308 | bs->stop = 1; |
5309 | bs->print = 1; | |
d983da9c | 5310 | |
f431efe5 PA |
5311 | /* If this is a scope breakpoint, mark the associated |
5312 | watchpoint as triggered so that we will handle the | |
5313 | out-of-scope event. We'll get to the watchpoint next | |
5314 | iteration. */ | |
d0fb5eae | 5315 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5316 | { |
5317 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5318 | ||
5319 | w->watchpoint_triggered = watch_triggered_yes; | |
5320 | } | |
f431efe5 PA |
5321 | } |
5322 | } | |
5323 | ||
7c16b83e | 5324 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5325 | if (!target_supports_stopped_by_sw_breakpoint () |
5326 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5327 | { |
1123588c | 5328 | for (bp_location *loc : moribund_locations) |
f431efe5 | 5329 | { |
1cf4d951 PA |
5330 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5331 | && need_moribund_for_location_type (loc)) | |
5332 | { | |
ddfe970e | 5333 | bpstat bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5334 | /* For hits of moribund locations, we should just proceed. */ |
5335 | bs->stop = 0; | |
5336 | bs->print = 0; | |
5337 | bs->print_it = print_it_noop; | |
5338 | } | |
f431efe5 PA |
5339 | } |
5340 | } | |
5341 | ||
ddfe970e KS |
5342 | return bs_head; |
5343 | } | |
5344 | ||
5345 | /* See breakpoint.h. */ | |
5346 | ||
5347 | bpstat | |
5348 | bpstat_stop_status (const address_space *aspace, | |
00431a78 | 5349 | CORE_ADDR bp_addr, thread_info *thread, |
ddfe970e KS |
5350 | const struct target_waitstatus *ws, |
5351 | bpstat stop_chain) | |
5352 | { | |
5353 | struct breakpoint *b = NULL; | |
5354 | /* First item of allocated bpstat's. */ | |
5355 | bpstat bs_head = stop_chain; | |
5356 | bpstat bs; | |
5357 | int need_remove_insert; | |
5358 | int removed_any; | |
5359 | ||
5360 | /* First, build the bpstat chain with locations that explain a | |
5361 | target stop, while being careful to not set the target running, | |
5362 | as that may invalidate locations (in particular watchpoint | |
5363 | locations are recreated). Resuming will happen here with | |
5364 | breakpoint conditions or watchpoint expressions that include | |
5365 | inferior function calls. */ | |
5366 | if (bs_head == NULL) | |
5367 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); | |
5368 | ||
edcc5120 TT |
5369 | /* A bit of special processing for shlib breakpoints. We need to |
5370 | process solib loading here, so that the lists of loaded and | |
5371 | unloaded libraries are correct before we handle "catch load" and | |
5372 | "catch unload". */ | |
5373 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5374 | { | |
5d268276 | 5375 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5376 | { |
5377 | handle_solib_event (); | |
5378 | break; | |
5379 | } | |
5380 | } | |
5381 | ||
f431efe5 PA |
5382 | /* Now go through the locations that caused the target to stop, and |
5383 | check whether we're interested in reporting this stop to higher | |
5384 | layers, or whether we should resume the target transparently. */ | |
5385 | ||
5386 | removed_any = 0; | |
5387 | ||
5760d0ab | 5388 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5389 | { |
5390 | if (!bs->stop) | |
5391 | continue; | |
5392 | ||
f431efe5 | 5393 | b = bs->breakpoint_at; |
348d480f PA |
5394 | b->ops->check_status (bs); |
5395 | if (bs->stop) | |
28010a5d | 5396 | { |
00431a78 | 5397 | bpstat_check_breakpoint_conditions (bs, thread); |
f431efe5 | 5398 | |
429374b8 JK |
5399 | if (bs->stop) |
5400 | { | |
5401 | ++(b->hit_count); | |
76727919 | 5402 | gdb::observers::breakpoint_modified.notify (b); |
c906108c | 5403 | |
4a64f543 | 5404 | /* We will stop here. */ |
429374b8 JK |
5405 | if (b->disposition == disp_disable) |
5406 | { | |
816338b5 | 5407 | --(b->enable_count); |
1a853c52 | 5408 | if (b->enable_count <= 0) |
429374b8 | 5409 | b->enable_state = bp_disabled; |
f431efe5 | 5410 | removed_any = 1; |
429374b8 JK |
5411 | } |
5412 | if (b->silent) | |
5413 | bs->print = 0; | |
5414 | bs->commands = b->commands; | |
abf85f46 | 5415 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5416 | ? bs->commands.get () : NULL)) |
abf85f46 | 5417 | bs->print = 0; |
9d6e6e84 HZ |
5418 | |
5419 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5420 | } |
5421 | ||
348d480f | 5422 | } |
a9b3a50f PA |
5423 | |
5424 | /* Print nothing for this entry if we don't stop or don't | |
5425 | print. */ | |
5426 | if (!bs->stop || !bs->print) | |
5427 | bs->print_it = print_it_noop; | |
429374b8 | 5428 | } |
876fa593 | 5429 | |
d983da9c DJ |
5430 | /* If we aren't stopping, the value of some hardware watchpoint may |
5431 | not have changed, but the intermediate memory locations we are | |
5432 | watching may have. Don't bother if we're stopping; this will get | |
5433 | done later. */ | |
d832cb68 | 5434 | need_remove_insert = 0; |
5760d0ab JK |
5435 | if (! bpstat_causes_stop (bs_head)) |
5436 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5437 | if (!bs->stop |
f431efe5 PA |
5438 | && bs->breakpoint_at |
5439 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5440 | { |
3a5c3e22 PA |
5441 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5442 | ||
5443 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5444 | need_remove_insert = 1; |
d983da9c DJ |
5445 | } |
5446 | ||
d832cb68 | 5447 | if (need_remove_insert) |
44702360 | 5448 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5449 | else if (removed_any) |
44702360 | 5450 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5451 | |
5760d0ab | 5452 | return bs_head; |
c906108c | 5453 | } |
628fe4e4 JK |
5454 | |
5455 | static void | |
5456 | handle_jit_event (void) | |
5457 | { | |
5458 | struct frame_info *frame; | |
5459 | struct gdbarch *gdbarch; | |
5460 | ||
243a9253 PA |
5461 | if (debug_infrun) |
5462 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5463 | ||
628fe4e4 JK |
5464 | /* Switch terminal for any messages produced by |
5465 | breakpoint_re_set. */ | |
223ffa71 | 5466 | target_terminal::ours_for_output (); |
628fe4e4 JK |
5467 | |
5468 | frame = get_current_frame (); | |
5469 | gdbarch = get_frame_arch (frame); | |
5470 | ||
5471 | jit_event_handler (gdbarch); | |
5472 | ||
223ffa71 | 5473 | target_terminal::inferior (); |
628fe4e4 JK |
5474 | } |
5475 | ||
5476 | /* Prepare WHAT final decision for infrun. */ | |
5477 | ||
5478 | /* Decide what infrun needs to do with this bpstat. */ | |
5479 | ||
c906108c | 5480 | struct bpstat_what |
0e30163f | 5481 | bpstat_what (bpstat bs_head) |
c906108c | 5482 | { |
c906108c | 5483 | struct bpstat_what retval; |
0e30163f | 5484 | bpstat bs; |
c906108c | 5485 | |
628fe4e4 | 5486 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5487 | retval.call_dummy = STOP_NONE; |
e2d0f980 | 5488 | retval.is_longjmp = false; |
628fe4e4 | 5489 | |
0e30163f | 5490 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5491 | { |
628fe4e4 JK |
5492 | /* Extract this BS's action. After processing each BS, we check |
5493 | if its action overrides all we've seem so far. */ | |
5494 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5495 | enum bptype bptype; | |
5496 | ||
c906108c | 5497 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5498 | { |
5499 | /* I suspect this can happen if it was a momentary | |
5500 | breakpoint which has since been deleted. */ | |
5501 | bptype = bp_none; | |
5502 | } | |
20874c92 | 5503 | else |
f431efe5 | 5504 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5505 | |
5506 | switch (bptype) | |
c906108c SS |
5507 | { |
5508 | case bp_none: | |
628fe4e4 | 5509 | break; |
c906108c SS |
5510 | case bp_breakpoint: |
5511 | case bp_hardware_breakpoint: | |
7c16b83e | 5512 | case bp_single_step: |
c906108c SS |
5513 | case bp_until: |
5514 | case bp_finish: | |
a9b3a50f | 5515 | case bp_shlib_event: |
c906108c SS |
5516 | if (bs->stop) |
5517 | { | |
5518 | if (bs->print) | |
628fe4e4 | 5519 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5520 | else |
628fe4e4 | 5521 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5522 | } |
5523 | else | |
628fe4e4 | 5524 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5525 | break; |
5526 | case bp_watchpoint: | |
5527 | case bp_hardware_watchpoint: | |
5528 | case bp_read_watchpoint: | |
5529 | case bp_access_watchpoint: | |
5530 | if (bs->stop) | |
5531 | { | |
5532 | if (bs->print) | |
628fe4e4 | 5533 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5534 | else |
628fe4e4 | 5535 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5536 | } |
5537 | else | |
628fe4e4 JK |
5538 | { |
5539 | /* There was a watchpoint, but we're not stopping. | |
5540 | This requires no further action. */ | |
5541 | } | |
c906108c SS |
5542 | break; |
5543 | case bp_longjmp: | |
e2e4d78b | 5544 | case bp_longjmp_call_dummy: |
186c406b | 5545 | case bp_exception: |
0a39bb32 PA |
5546 | if (bs->stop) |
5547 | { | |
5548 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5549 | retval.is_longjmp = bptype != bp_exception; | |
5550 | } | |
5551 | else | |
5552 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5553 | break; |
5554 | case bp_longjmp_resume: | |
186c406b | 5555 | case bp_exception_resume: |
0a39bb32 PA |
5556 | if (bs->stop) |
5557 | { | |
5558 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5559 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5560 | } | |
5561 | else | |
5562 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5563 | break; |
5564 | case bp_step_resume: | |
5565 | if (bs->stop) | |
628fe4e4 JK |
5566 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5567 | else | |
c906108c | 5568 | { |
628fe4e4 JK |
5569 | /* It is for the wrong frame. */ |
5570 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5571 | } |
c906108c | 5572 | break; |
2c03e5be PA |
5573 | case bp_hp_step_resume: |
5574 | if (bs->stop) | |
5575 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5576 | else | |
5577 | { | |
5578 | /* It is for the wrong frame. */ | |
5579 | this_action = BPSTAT_WHAT_SINGLE; | |
5580 | } | |
5581 | break; | |
c906108c | 5582 | case bp_watchpoint_scope: |
c4093a6a | 5583 | case bp_thread_event: |
1900040c | 5584 | case bp_overlay_event: |
0fd8e87f | 5585 | case bp_longjmp_master: |
aa7d318d | 5586 | case bp_std_terminate_master: |
186c406b | 5587 | case bp_exception_master: |
628fe4e4 | 5588 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5589 | break; |
ce78b96d | 5590 | case bp_catchpoint: |
c5aa993b JM |
5591 | if (bs->stop) |
5592 | { | |
5593 | if (bs->print) | |
628fe4e4 | 5594 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5595 | else |
628fe4e4 | 5596 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5597 | } |
5598 | else | |
628fe4e4 | 5599 | { |
cb1e4e32 PA |
5600 | /* Some catchpoints are implemented with breakpoints. |
5601 | For those, we need to step over the breakpoint. */ | |
5602 | if (bs->bp_location_at->loc_type != bp_loc_other) | |
5603 | this_action = BPSTAT_WHAT_SINGLE; | |
628fe4e4 JK |
5604 | } |
5605 | break; | |
628fe4e4 | 5606 | case bp_jit_event: |
628fe4e4 | 5607 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5608 | break; |
c906108c | 5609 | case bp_call_dummy: |
53a5351d JM |
5610 | /* Make sure the action is stop (silent or noisy), |
5611 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5612 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5613 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5614 | break; |
5615 | case bp_std_terminate: | |
5616 | /* Make sure the action is stop (silent or noisy), | |
5617 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5618 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5619 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5620 | break; |
1042e4c0 | 5621 | case bp_tracepoint: |
7a697b8d | 5622 | case bp_fast_tracepoint: |
0fb4aa4b | 5623 | case bp_static_tracepoint: |
1042e4c0 SS |
5624 | /* Tracepoint hits should not be reported back to GDB, and |
5625 | if one got through somehow, it should have been filtered | |
5626 | out already. */ | |
5627 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5628 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5629 | break; |
5630 | case bp_gnu_ifunc_resolver: | |
5631 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5632 | this_action = BPSTAT_WHAT_SINGLE; | |
5633 | break; | |
5634 | case bp_gnu_ifunc_resolver_return: | |
5635 | /* The breakpoint will be removed, execution will restart from the | |
5636 | PC of the former breakpoint. */ | |
5637 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5638 | break; | |
e7e0cddf SS |
5639 | |
5640 | case bp_dprintf: | |
a11cfd87 HZ |
5641 | if (bs->stop) |
5642 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5643 | else | |
5644 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5645 | break; |
5646 | ||
628fe4e4 JK |
5647 | default: |
5648 | internal_error (__FILE__, __LINE__, | |
5649 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5650 | } |
628fe4e4 | 5651 | |
325fac50 | 5652 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5653 | } |
628fe4e4 | 5654 | |
243a9253 PA |
5655 | return retval; |
5656 | } | |
628fe4e4 | 5657 | |
243a9253 PA |
5658 | void |
5659 | bpstat_run_callbacks (bpstat bs_head) | |
5660 | { | |
5661 | bpstat bs; | |
628fe4e4 | 5662 | |
0e30163f JK |
5663 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5664 | { | |
5665 | struct breakpoint *b = bs->breakpoint_at; | |
5666 | ||
5667 | if (b == NULL) | |
5668 | continue; | |
5669 | switch (b->type) | |
5670 | { | |
243a9253 PA |
5671 | case bp_jit_event: |
5672 | handle_jit_event (); | |
5673 | break; | |
0e30163f JK |
5674 | case bp_gnu_ifunc_resolver: |
5675 | gnu_ifunc_resolver_stop (b); | |
5676 | break; | |
5677 | case bp_gnu_ifunc_resolver_return: | |
5678 | gnu_ifunc_resolver_return_stop (b); | |
5679 | break; | |
5680 | } | |
5681 | } | |
c906108c SS |
5682 | } |
5683 | ||
4c462cb0 | 5684 | /* See breakpoint.h. */ |
c906108c | 5685 | |
4c462cb0 SM |
5686 | bool |
5687 | bpstat_should_step () | |
c906108c SS |
5688 | { |
5689 | struct breakpoint *b; | |
cc59ec59 | 5690 | |
c906108c | 5691 | ALL_BREAKPOINTS (b) |
717a8278 | 5692 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
4c462cb0 SM |
5693 | return true; |
5694 | return false; | |
c906108c SS |
5695 | } |
5696 | ||
4c462cb0 SM |
5697 | /* See breakpoint.h. */ |
5698 | ||
5699 | bool | |
67822962 PA |
5700 | bpstat_causes_stop (bpstat bs) |
5701 | { | |
5702 | for (; bs != NULL; bs = bs->next) | |
5703 | if (bs->stop) | |
4c462cb0 | 5704 | return true; |
67822962 | 5705 | |
4c462cb0 | 5706 | return false; |
67822962 PA |
5707 | } |
5708 | ||
c906108c | 5709 | \f |
c5aa993b | 5710 | |
170b53b2 UW |
5711 | /* Compute a string of spaces suitable to indent the next line |
5712 | so it starts at the position corresponding to the table column | |
5713 | named COL_NAME in the currently active table of UIOUT. */ | |
5714 | ||
5715 | static char * | |
5716 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5717 | { | |
5718 | static char wrap_indent[80]; | |
5719 | int i, total_width, width, align; | |
c5209615 | 5720 | const char *text; |
170b53b2 UW |
5721 | |
5722 | total_width = 0; | |
112e8700 | 5723 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5724 | { |
5725 | if (strcmp (text, col_name) == 0) | |
5726 | { | |
5727 | gdb_assert (total_width < sizeof wrap_indent); | |
5728 | memset (wrap_indent, ' ', total_width); | |
5729 | wrap_indent[total_width] = 0; | |
5730 | ||
5731 | return wrap_indent; | |
5732 | } | |
5733 | ||
5734 | total_width += width + 1; | |
5735 | } | |
5736 | ||
5737 | return NULL; | |
5738 | } | |
5739 | ||
b775012e LM |
5740 | /* Determine if the locations of this breakpoint will have their conditions |
5741 | evaluated by the target, host or a mix of both. Returns the following: | |
5742 | ||
5743 | "host": Host evals condition. | |
5744 | "host or target": Host or Target evals condition. | |
5745 | "target": Target evals condition. | |
5746 | */ | |
5747 | ||
5748 | static const char * | |
5749 | bp_condition_evaluator (struct breakpoint *b) | |
5750 | { | |
5751 | struct bp_location *bl; | |
5752 | char host_evals = 0; | |
5753 | char target_evals = 0; | |
5754 | ||
5755 | if (!b) | |
5756 | return NULL; | |
5757 | ||
5758 | if (!is_breakpoint (b)) | |
5759 | return NULL; | |
5760 | ||
5761 | if (gdb_evaluates_breakpoint_condition_p () | |
5762 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5763 | return condition_evaluation_host; | |
5764 | ||
5765 | for (bl = b->loc; bl; bl = bl->next) | |
5766 | { | |
5767 | if (bl->cond_bytecode) | |
5768 | target_evals++; | |
5769 | else | |
5770 | host_evals++; | |
5771 | } | |
5772 | ||
5773 | if (host_evals && target_evals) | |
5774 | return condition_evaluation_both; | |
5775 | else if (target_evals) | |
5776 | return condition_evaluation_target; | |
5777 | else | |
5778 | return condition_evaluation_host; | |
5779 | } | |
5780 | ||
5781 | /* Determine the breakpoint location's condition evaluator. This is | |
5782 | similar to bp_condition_evaluator, but for locations. */ | |
5783 | ||
5784 | static const char * | |
5785 | bp_location_condition_evaluator (struct bp_location *bl) | |
5786 | { | |
5787 | if (bl && !is_breakpoint (bl->owner)) | |
5788 | return NULL; | |
5789 | ||
5790 | if (gdb_evaluates_breakpoint_condition_p () | |
5791 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5792 | return condition_evaluation_host; | |
5793 | ||
5794 | if (bl && bl->cond_bytecode) | |
5795 | return condition_evaluation_target; | |
5796 | else | |
5797 | return condition_evaluation_host; | |
5798 | } | |
5799 | ||
859825b8 JK |
5800 | /* Print the LOC location out of the list of B->LOC locations. */ |
5801 | ||
170b53b2 UW |
5802 | static void |
5803 | print_breakpoint_location (struct breakpoint *b, | |
5804 | struct bp_location *loc) | |
0d381245 | 5805 | { |
79a45e25 | 5806 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5807 | |
5808 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5809 | |
859825b8 JK |
5810 | if (loc != NULL && loc->shlib_disabled) |
5811 | loc = NULL; | |
5812 | ||
6c95b8df PA |
5813 | if (loc != NULL) |
5814 | set_current_program_space (loc->pspace); | |
5815 | ||
56435ebe | 5816 | if (b->display_canonical) |
d28cd78a | 5817 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 5818 | else if (loc && loc->symtab) |
0d381245 | 5819 | { |
4a27f119 KS |
5820 | const struct symbol *sym = loc->symbol; |
5821 | ||
0d381245 VP |
5822 | if (sym) |
5823 | { | |
112e8700 | 5824 | uiout->text ("in "); |
cbe56571 | 5825 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym), |
e43b10e1 | 5826 | function_name_style.style ()); |
112e8700 SM |
5827 | uiout->text (" "); |
5828 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
5829 | uiout->text ("at "); | |
0d381245 | 5830 | } |
112e8700 | 5831 | uiout->field_string ("file", |
cbe56571 | 5832 | symtab_to_filename_for_display (loc->symtab), |
e43b10e1 | 5833 | file_name_style.style ()); |
112e8700 | 5834 | uiout->text (":"); |
05cba821 | 5835 | |
112e8700 SM |
5836 | if (uiout->is_mi_like_p ()) |
5837 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 5838 | |
381befee | 5839 | uiout->field_signed ("line", loc->line_number); |
0d381245 | 5840 | } |
859825b8 | 5841 | else if (loc) |
0d381245 | 5842 | { |
d7e74731 | 5843 | string_file stb; |
170b53b2 | 5844 | |
d7e74731 | 5845 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 5846 | demangle, ""); |
112e8700 | 5847 | uiout->field_stream ("at", stb); |
0d381245 | 5848 | } |
859825b8 | 5849 | else |
f00aae0f | 5850 | { |
d28cd78a TT |
5851 | uiout->field_string ("pending", |
5852 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
5853 | /* If extra_string is available, it could be holding a condition |
5854 | or dprintf arguments. In either case, make sure it is printed, | |
5855 | too, but only for non-MI streams. */ | |
112e8700 | 5856 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
5857 | { |
5858 | if (b->type == bp_dprintf) | |
112e8700 | 5859 | uiout->text (","); |
f00aae0f | 5860 | else |
112e8700 SM |
5861 | uiout->text (" "); |
5862 | uiout->text (b->extra_string); | |
f00aae0f KS |
5863 | } |
5864 | } | |
6c95b8df | 5865 | |
b775012e LM |
5866 | if (loc && is_breakpoint (b) |
5867 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5868 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5869 | { | |
112e8700 SM |
5870 | uiout->text (" ("); |
5871 | uiout->field_string ("evaluated-by", | |
b775012e | 5872 | bp_location_condition_evaluator (loc)); |
112e8700 | 5873 | uiout->text (")"); |
b775012e | 5874 | } |
0d381245 VP |
5875 | } |
5876 | ||
269b11a2 PA |
5877 | static const char * |
5878 | bptype_string (enum bptype type) | |
c906108c | 5879 | { |
c4093a6a JM |
5880 | struct ep_type_description |
5881 | { | |
5882 | enum bptype type; | |
a121b7c1 | 5883 | const char *description; |
c4093a6a JM |
5884 | }; |
5885 | static struct ep_type_description bptypes[] = | |
c906108c | 5886 | { |
c5aa993b JM |
5887 | {bp_none, "?deleted?"}, |
5888 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5889 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 5890 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
5891 | {bp_until, "until"}, |
5892 | {bp_finish, "finish"}, | |
5893 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5894 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5895 | {bp_read_watchpoint, "read watchpoint"}, |
5896 | {bp_access_watchpoint, "acc watchpoint"}, | |
5897 | {bp_longjmp, "longjmp"}, | |
5898 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5899 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5900 | {bp_exception, "exception"}, |
5901 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5902 | {bp_step_resume, "step resume"}, |
2c03e5be | 5903 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5904 | {bp_watchpoint_scope, "watchpoint scope"}, |
5905 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5906 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5907 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5908 | {bp_thread_event, "thread events"}, |
1900040c | 5909 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5910 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5911 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5912 | {bp_exception_master, "exception master"}, |
ce78b96d | 5913 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5914 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5915 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5916 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5917 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5918 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5919 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5920 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5921 | }; |
269b11a2 PA |
5922 | |
5923 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5924 | || ((int) type != bptypes[(int) type].type)) | |
5925 | internal_error (__FILE__, __LINE__, | |
5926 | _("bptypes table does not describe type #%d."), | |
5927 | (int) type); | |
5928 | ||
5929 | return bptypes[(int) type].description; | |
5930 | } | |
5931 | ||
998580f1 MK |
5932 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5933 | For CLI, prefix the list with the string 'inf'. */ | |
5934 | ||
5935 | static void | |
5936 | output_thread_groups (struct ui_out *uiout, | |
5937 | const char *field_name, | |
5c632425 | 5938 | const std::vector<int> &inf_nums, |
998580f1 MK |
5939 | int mi_only) |
5940 | { | |
112e8700 | 5941 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
5942 | |
5943 | /* For backward compatibility, don't display inferiors in CLI unless | |
5944 | there are several. Always display them for MI. */ | |
5945 | if (!is_mi && mi_only) | |
5946 | return; | |
5947 | ||
10f489e5 | 5948 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 5949 | |
5c632425 | 5950 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
5951 | { |
5952 | if (is_mi) | |
5953 | { | |
5954 | char mi_group[10]; | |
5955 | ||
5c632425 | 5956 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 5957 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
5958 | } |
5959 | else | |
5960 | { | |
5961 | if (i == 0) | |
112e8700 | 5962 | uiout->text (" inf "); |
998580f1 | 5963 | else |
112e8700 | 5964 | uiout->text (", "); |
998580f1 | 5965 | |
5c632425 | 5966 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
5967 | } |
5968 | } | |
998580f1 MK |
5969 | } |
5970 | ||
a38118e5 PA |
5971 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
5972 | instead of going via breakpoint_ops::print_one. This makes "maint | |
5973 | info breakpoints" show the software breakpoint locations of | |
5974 | catchpoints, which are considered internal implementation | |
5975 | detail. */ | |
269b11a2 PA |
5976 | |
5977 | static void | |
5978 | print_one_breakpoint_location (struct breakpoint *b, | |
5979 | struct bp_location *loc, | |
5980 | int loc_number, | |
5981 | struct bp_location **last_loc, | |
a38118e5 | 5982 | int allflag, bool raw_loc) |
269b11a2 PA |
5983 | { |
5984 | struct command_line *l; | |
c2c6d25f | 5985 | static char bpenables[] = "nynny"; |
c906108c | 5986 | |
79a45e25 | 5987 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5988 | int header_of_multiple = 0; |
5989 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5990 | struct value_print_options opts; |
5991 | ||
5992 | get_user_print_options (&opts); | |
0d381245 VP |
5993 | |
5994 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5995 | /* See comment in print_one_breakpoint concerning treatment of |
5996 | breakpoints with single disabled location. */ | |
0d381245 VP |
5997 | if (loc == NULL |
5998 | && (b->loc != NULL | |
5999 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6000 | header_of_multiple = 1; | |
6001 | if (loc == NULL) | |
6002 | loc = b->loc; | |
6003 | ||
c4093a6a JM |
6004 | annotate_record (); |
6005 | ||
6006 | /* 1 */ | |
6007 | annotate_field (0); | |
0d381245 | 6008 | if (part_of_multiple) |
528e1572 | 6009 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
0d381245 | 6010 | else |
381befee | 6011 | uiout->field_signed ("number", b->number); |
c4093a6a JM |
6012 | |
6013 | /* 2 */ | |
6014 | annotate_field (1); | |
0d381245 | 6015 | if (part_of_multiple) |
112e8700 | 6016 | uiout->field_skip ("type"); |
269b11a2 | 6017 | else |
112e8700 | 6018 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6019 | |
6020 | /* 3 */ | |
6021 | annotate_field (2); | |
0d381245 | 6022 | if (part_of_multiple) |
112e8700 | 6023 | uiout->field_skip ("disp"); |
0d381245 | 6024 | else |
112e8700 | 6025 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6026 | |
c4093a6a JM |
6027 | /* 4 */ |
6028 | annotate_field (3); | |
0d381245 | 6029 | if (part_of_multiple) |
112e8700 | 6030 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6031 | else |
112e8700 | 6032 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
0d381245 | 6033 | |
c4093a6a | 6034 | /* 5 and 6 */ |
a38118e5 | 6035 | if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL) |
b58a68fe | 6036 | b->ops->print_one (b, last_loc); |
3086aeae | 6037 | else |
a38118e5 PA |
6038 | { |
6039 | if (is_watchpoint (b)) | |
3a5c3e22 PA |
6040 | { |
6041 | struct watchpoint *w = (struct watchpoint *) b; | |
6042 | ||
6043 | /* Field 4, the address, is omitted (which makes the columns | |
6044 | not line up too nicely with the headers, but the effect | |
6045 | is relatively readable). */ | |
6046 | if (opts.addressprint) | |
112e8700 | 6047 | uiout->field_skip ("addr"); |
3a5c3e22 | 6048 | annotate_field (5); |
112e8700 | 6049 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6050 | } |
f06f1252 TT |
6051 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
6052 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6053 | { |
6054 | if (opts.addressprint) | |
6055 | { | |
6056 | annotate_field (4); | |
6057 | if (header_of_multiple) | |
7f6aba03 TT |
6058 | uiout->field_string ("addr", "<MULTIPLE>", |
6059 | metadata_style.style ()); | |
a38118e5 | 6060 | else if (b->loc == NULL || loc->shlib_disabled) |
7f6aba03 TT |
6061 | uiout->field_string ("addr", "<PENDING>", |
6062 | metadata_style.style ()); | |
a38118e5 PA |
6063 | else |
6064 | uiout->field_core_addr ("addr", | |
6065 | loc->gdbarch, loc->address); | |
6066 | } | |
6067 | annotate_field (5); | |
6068 | if (!header_of_multiple) | |
6069 | print_breakpoint_location (b, loc); | |
6070 | if (b->loc) | |
6071 | *last_loc = b->loc; | |
6072 | } | |
6073 | } | |
6c95b8df | 6074 | |
998580f1 | 6075 | if (loc != NULL && !header_of_multiple) |
6c95b8df | 6076 | { |
5c632425 | 6077 | std::vector<int> inf_nums; |
998580f1 | 6078 | int mi_only = 1; |
6c95b8df | 6079 | |
08036331 | 6080 | for (inferior *inf : all_inferiors ()) |
6c95b8df PA |
6081 | { |
6082 | if (inf->pspace == loc->pspace) | |
5c632425 | 6083 | inf_nums.push_back (inf->num); |
6c95b8df | 6084 | } |
998580f1 MK |
6085 | |
6086 | /* For backward compatibility, don't display inferiors in CLI unless | |
6087 | there are several. Always display for MI. */ | |
6088 | if (allflag | |
6089 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6090 | && (number_of_program_spaces () > 1 | |
6091 | || number_of_inferiors () > 1) | |
6092 | /* LOC is for existing B, it cannot be in | |
6093 | moribund_locations and thus having NULL OWNER. */ | |
6094 | && loc->owner->type != bp_catchpoint)) | |
6095 | mi_only = 0; | |
5c632425 | 6096 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6097 | } |
6098 | ||
4a306c9a | 6099 | if (!part_of_multiple) |
c4093a6a | 6100 | { |
4a306c9a JB |
6101 | if (b->thread != -1) |
6102 | { | |
6103 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6104 | "stop only in" line a little further down. */ |
112e8700 | 6105 | uiout->text (" thread "); |
381befee | 6106 | uiout->field_signed ("thread", b->thread); |
4a306c9a JB |
6107 | } |
6108 | else if (b->task != 0) | |
6109 | { | |
112e8700 | 6110 | uiout->text (" task "); |
381befee | 6111 | uiout->field_signed ("task", b->task); |
4a306c9a | 6112 | } |
c4093a6a | 6113 | } |
f1310107 | 6114 | |
112e8700 | 6115 | uiout->text ("\n"); |
f1310107 | 6116 | |
348d480f | 6117 | if (!part_of_multiple) |
f1310107 TJB |
6118 | b->ops->print_one_detail (b, uiout); |
6119 | ||
0d381245 | 6120 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6121 | { |
6122 | annotate_field (6); | |
112e8700 | 6123 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6124 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6125 | the frame ID. */ |
112e8700 | 6126 | uiout->field_core_addr ("frame", |
5af949e3 | 6127 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6128 | uiout->text ("\n"); |
c4093a6a JM |
6129 | } |
6130 | ||
28010a5d | 6131 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6132 | { |
6133 | annotate_field (7); | |
d77f58be | 6134 | if (is_tracepoint (b)) |
112e8700 | 6135 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6136 | else |
112e8700 SM |
6137 | uiout->text ("\tstop only if "); |
6138 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6139 | |
6140 | /* Print whether the target is doing the breakpoint's condition | |
6141 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6142 | if (is_breakpoint (b) | |
6143 | && breakpoint_condition_evaluation_mode () | |
6144 | == condition_evaluation_target) | |
6145 | { | |
6a831f06 PA |
6146 | uiout->message (" (%pF evals)", |
6147 | string_field ("evaluated-by", | |
6148 | bp_condition_evaluator (b))); | |
b775012e | 6149 | } |
112e8700 | 6150 | uiout->text ("\n"); |
0101ce28 JJ |
6151 | } |
6152 | ||
0d381245 | 6153 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6154 | { |
4a64f543 | 6155 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6156 | uiout->text ("\tstop only in thread "); |
6157 | if (uiout->is_mi_like_p ()) | |
381befee | 6158 | uiout->field_signed ("thread", b->thread); |
5d5658a1 PA |
6159 | else |
6160 | { | |
6161 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6162 | ||
112e8700 | 6163 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6164 | } |
112e8700 | 6165 | uiout->text ("\n"); |
c4093a6a JM |
6166 | } |
6167 | ||
556ec64d YQ |
6168 | if (!part_of_multiple) |
6169 | { | |
6170 | if (b->hit_count) | |
31f56a27 YQ |
6171 | { |
6172 | /* FIXME should make an annotation for this. */ | |
6173 | if (is_catchpoint (b)) | |
112e8700 | 6174 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6175 | else if (is_tracepoint (b)) |
112e8700 | 6176 | uiout->text ("\ttracepoint"); |
31f56a27 | 6177 | else |
112e8700 SM |
6178 | uiout->text ("\tbreakpoint"); |
6179 | uiout->text (" already hit "); | |
381befee | 6180 | uiout->field_signed ("times", b->hit_count); |
31f56a27 | 6181 | if (b->hit_count == 1) |
112e8700 | 6182 | uiout->text (" time\n"); |
31f56a27 | 6183 | else |
112e8700 | 6184 | uiout->text (" times\n"); |
31f56a27 | 6185 | } |
556ec64d YQ |
6186 | else |
6187 | { | |
31f56a27 | 6188 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 | 6189 | if (uiout->is_mi_like_p ()) |
381befee | 6190 | uiout->field_signed ("times", b->hit_count); |
556ec64d YQ |
6191 | } |
6192 | } | |
8b93c638 | 6193 | |
0d381245 | 6194 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6195 | { |
6196 | annotate_field (8); | |
6a831f06 PA |
6197 | uiout->message ("\tignore next %pF hits\n", |
6198 | signed_field ("ignore", b->ignore_count)); | |
c4093a6a | 6199 | } |
059fb39f | 6200 | |
816338b5 SS |
6201 | /* Note that an enable count of 1 corresponds to "enable once" |
6202 | behavior, which is reported by the combination of enablement and | |
6203 | disposition, so we don't need to mention it here. */ | |
6204 | if (!part_of_multiple && b->enable_count > 1) | |
6205 | { | |
6206 | annotate_field (8); | |
112e8700 | 6207 | uiout->text ("\tdisable after "); |
816338b5 SS |
6208 | /* Tweak the wording to clarify that ignore and enable counts |
6209 | are distinct, and have additive effect. */ | |
6210 | if (b->ignore_count) | |
112e8700 | 6211 | uiout->text ("additional "); |
816338b5 | 6212 | else |
112e8700 | 6213 | uiout->text ("next "); |
381befee | 6214 | uiout->field_signed ("enable", b->enable_count); |
112e8700 | 6215 | uiout->text (" hits\n"); |
816338b5 SS |
6216 | } |
6217 | ||
f196051f SS |
6218 | if (!part_of_multiple && is_tracepoint (b)) |
6219 | { | |
6220 | struct tracepoint *tp = (struct tracepoint *) b; | |
6221 | ||
6222 | if (tp->traceframe_usage) | |
6223 | { | |
112e8700 | 6224 | uiout->text ("\ttrace buffer usage "); |
381befee | 6225 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
112e8700 | 6226 | uiout->text (" bytes\n"); |
f196051f SS |
6227 | } |
6228 | } | |
d3ce09f5 | 6229 | |
d1b0a7bf | 6230 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6231 | if (!part_of_multiple && l) |
c4093a6a JM |
6232 | { |
6233 | annotate_field (9); | |
2e783024 | 6234 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6235 | print_command_lines (uiout, l, 4); |
c4093a6a | 6236 | } |
d24317b4 | 6237 | |
d9b3f62e | 6238 | if (is_tracepoint (b)) |
1042e4c0 | 6239 | { |
d9b3f62e PA |
6240 | struct tracepoint *t = (struct tracepoint *) b; |
6241 | ||
6242 | if (!part_of_multiple && t->pass_count) | |
6243 | { | |
6244 | annotate_field (10); | |
112e8700 | 6245 | uiout->text ("\tpass count "); |
381befee | 6246 | uiout->field_signed ("pass", t->pass_count); |
112e8700 | 6247 | uiout->text (" \n"); |
d9b3f62e | 6248 | } |
f2a8bc8a YQ |
6249 | |
6250 | /* Don't display it when tracepoint or tracepoint location is | |
6251 | pending. */ | |
6252 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6253 | { | |
6254 | annotate_field (11); | |
6255 | ||
112e8700 SM |
6256 | if (uiout->is_mi_like_p ()) |
6257 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6258 | loc->inserted ? "y" : "n"); |
6259 | else | |
6260 | { | |
6261 | if (loc->inserted) | |
112e8700 | 6262 | uiout->text ("\t"); |
f2a8bc8a | 6263 | else |
112e8700 SM |
6264 | uiout->text ("\tnot "); |
6265 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6266 | } |
6267 | } | |
1042e4c0 SS |
6268 | } |
6269 | ||
112e8700 | 6270 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6271 | { |
3a5c3e22 PA |
6272 | if (is_watchpoint (b)) |
6273 | { | |
6274 | struct watchpoint *w = (struct watchpoint *) b; | |
6275 | ||
112e8700 | 6276 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6277 | } |
f00aae0f | 6278 | else if (b->location != NULL |
d28cd78a | 6279 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6280 | uiout->field_string ("original-location", |
d28cd78a | 6281 | event_location_to_string (b->location.get ())); |
d24317b4 | 6282 | } |
c4093a6a | 6283 | } |
c5aa993b | 6284 | |
13674803 SM |
6285 | /* See breakpoint.h. */ |
6286 | ||
6287 | bool fix_multi_location_breakpoint_output_globally = false; | |
6288 | ||
0d381245 VP |
6289 | static void |
6290 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6291 | struct bp_location **last_loc, |
6c95b8df | 6292 | int allflag) |
0d381245 | 6293 | { |
79a45e25 | 6294 | struct ui_out *uiout = current_uiout; |
13674803 SM |
6295 | bool use_fixed_output |
6296 | = (uiout->test_flags (fix_multi_location_breakpoint_output) | |
6297 | || fix_multi_location_breakpoint_output_globally); | |
8d3788bd | 6298 | |
b4be1b06 | 6299 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
a38118e5 | 6300 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false); |
8d3788bd | 6301 | |
b4be1b06 SM |
6302 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
6303 | are outside. */ | |
6304 | if (!use_fixed_output) | |
6305 | bkpt_tuple_emitter.reset (); | |
0d381245 VP |
6306 | |
6307 | /* If this breakpoint has custom print function, | |
6308 | it's already printed. Otherwise, print individual | |
6309 | locations, if any. */ | |
a38118e5 PA |
6310 | if (b->ops == NULL |
6311 | || b->ops->print_one == NULL | |
6312 | || allflag) | |
0d381245 | 6313 | { |
4a64f543 MS |
6314 | /* If breakpoint has a single location that is disabled, we |
6315 | print it as if it had several locations, since otherwise it's | |
6316 | hard to represent "breakpoint enabled, location disabled" | |
6317 | situation. | |
6318 | ||
6319 | Note that while hardware watchpoints have several locations | |
a38118e5 PA |
6320 | internally, that's not a property exposed to users. |
6321 | ||
6322 | Likewise, while catchpoints may be implemented with | |
6323 | breakpoints (e.g., catch throw), that's not a property | |
6324 | exposed to users. We do however display the internal | |
6325 | breakpoint locations with "maint info breakpoints". */ | |
6326 | if (!is_hardware_watchpoint (b) | |
f06f1252 TT |
6327 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
6328 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6329 | && (allflag |
6330 | || (b->loc && (b->loc->next || !b->loc->enabled)))) | |
0d381245 | 6331 | { |
b4be1b06 SM |
6332 | gdb::optional<ui_out_emit_list> locations_list; |
6333 | ||
6334 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid | |
6335 | MI record. For later versions, place breakpoint locations in a | |
6336 | list. */ | |
6337 | if (uiout->is_mi_like_p () && use_fixed_output) | |
6338 | locations_list.emplace (uiout, "locations"); | |
8d3788bd | 6339 | |
b4be1b06 SM |
6340 | int n = 1; |
6341 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) | |
8d3788bd | 6342 | { |
b4be1b06 | 6343 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
a38118e5 PA |
6344 | print_one_breakpoint_location (b, loc, n, last_loc, |
6345 | allflag, allflag); | |
8d3788bd | 6346 | } |
0d381245 VP |
6347 | } |
6348 | } | |
6349 | } | |
6350 | ||
a6d9a66e UW |
6351 | static int |
6352 | breakpoint_address_bits (struct breakpoint *b) | |
6353 | { | |
6354 | int print_address_bits = 0; | |
6355 | struct bp_location *loc; | |
6356 | ||
c6d81124 PA |
6357 | /* Software watchpoints that aren't watching memory don't have an |
6358 | address to print. */ | |
6359 | if (is_no_memory_software_watchpoint (b)) | |
6360 | return 0; | |
6361 | ||
a6d9a66e UW |
6362 | for (loc = b->loc; loc; loc = loc->next) |
6363 | { | |
c7437ca6 PA |
6364 | int addr_bit; |
6365 | ||
c7437ca6 | 6366 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6367 | if (addr_bit > print_address_bits) |
6368 | print_address_bits = addr_bit; | |
6369 | } | |
6370 | ||
6371 | return print_address_bits; | |
6372 | } | |
0d381245 | 6373 | |
65630365 | 6374 | /* See breakpoint.h. */ |
c5aa993b | 6375 | |
65630365 PA |
6376 | void |
6377 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6378 | { |
a6d9a66e | 6379 | struct bp_location *dummy_loc = NULL; |
65630365 | 6380 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6381 | } |
c5aa993b | 6382 | |
09d682a4 TT |
6383 | /* Return true if this breakpoint was set by the user, false if it is |
6384 | internal or momentary. */ | |
6385 | ||
6386 | int | |
6387 | user_breakpoint_p (struct breakpoint *b) | |
6388 | { | |
46c6471b | 6389 | return b->number > 0; |
09d682a4 TT |
6390 | } |
6391 | ||
93daf339 TT |
6392 | /* See breakpoint.h. */ |
6393 | ||
6394 | int | |
6395 | pending_breakpoint_p (struct breakpoint *b) | |
6396 | { | |
6397 | return b->loc == NULL; | |
6398 | } | |
6399 | ||
5c458ae8 SM |
6400 | /* Print information on breakpoints (including watchpoints and tracepoints). |
6401 | ||
6402 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as | |
6403 | understood by number_or_range_parser. Only breakpoints included in this | |
6404 | list are then printed. | |
6405 | ||
6406 | If SHOW_INTERNAL is true, print internal breakpoints. | |
6407 | ||
6408 | If FILTER is non-NULL, call it on each breakpoint and only include the | |
6409 | ones for which it returns true. | |
6410 | ||
6411 | Return the total number of breakpoints listed. */ | |
c906108c | 6412 | |
d77f58be | 6413 | static int |
5c458ae8 | 6414 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
f2478a7e | 6415 | bool (*filter) (const struct breakpoint *)) |
c4093a6a | 6416 | { |
52f0bd74 | 6417 | struct breakpoint *b; |
a6d9a66e | 6418 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6419 | int nr_printable_breakpoints; |
79a45b7d | 6420 | struct value_print_options opts; |
a6d9a66e | 6421 | int print_address_bits = 0; |
269b11a2 | 6422 | int print_type_col_width = 14; |
79a45e25 | 6423 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6424 | |
79a45b7d TT |
6425 | get_user_print_options (&opts); |
6426 | ||
4a64f543 MS |
6427 | /* Compute the number of rows in the table, as well as the size |
6428 | required for address fields. */ | |
7f3b0473 AC |
6429 | nr_printable_breakpoints = 0; |
6430 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6431 | { |
6432 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6433 | if (filter && !filter (b)) | |
6434 | continue; | |
6435 | ||
5c458ae8 | 6436 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
e5a67952 | 6437 | accept. Skip the others. */ |
5c458ae8 | 6438 | if (bp_num_list != NULL && *bp_num_list != '\0') |
e5a67952 | 6439 | { |
5c458ae8 | 6440 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
e5a67952 | 6441 | continue; |
5c458ae8 | 6442 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
e5a67952 MS |
6443 | continue; |
6444 | } | |
269b11a2 | 6445 | |
5c458ae8 | 6446 | if (show_internal || user_breakpoint_p (b)) |
e5a67952 MS |
6447 | { |
6448 | int addr_bit, type_len; | |
a6d9a66e | 6449 | |
e5a67952 MS |
6450 | addr_bit = breakpoint_address_bits (b); |
6451 | if (addr_bit > print_address_bits) | |
6452 | print_address_bits = addr_bit; | |
269b11a2 | 6453 | |
e5a67952 MS |
6454 | type_len = strlen (bptype_string (b->type)); |
6455 | if (type_len > print_type_col_width) | |
6456 | print_type_col_width = type_len; | |
6457 | ||
6458 | nr_printable_breakpoints++; | |
6459 | } | |
6460 | } | |
7f3b0473 | 6461 | |
4a2b031d TT |
6462 | { |
6463 | ui_out_emit_table table_emitter (uiout, | |
6464 | opts.addressprint ? 6 : 5, | |
6465 | nr_printable_breakpoints, | |
6466 | "BreakpointTable"); | |
6467 | ||
6468 | if (nr_printable_breakpoints > 0) | |
6469 | annotate_breakpoints_headers (); | |
6470 | if (nr_printable_breakpoints > 0) | |
6471 | annotate_field (0); | |
6472 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6473 | if (nr_printable_breakpoints > 0) | |
6474 | annotate_field (1); | |
6475 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6476 | if (nr_printable_breakpoints > 0) | |
6477 | annotate_field (2); | |
6478 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6479 | if (nr_printable_breakpoints > 0) | |
6480 | annotate_field (3); | |
6481 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6482 | if (opts.addressprint) | |
6483 | { | |
6484 | if (nr_printable_breakpoints > 0) | |
6485 | annotate_field (4); | |
6486 | if (print_address_bits <= 32) | |
6487 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6488 | else | |
6489 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6490 | } | |
6491 | if (nr_printable_breakpoints > 0) | |
6492 | annotate_field (5); | |
6493 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6494 | uiout->table_body (); | |
6495 | if (nr_printable_breakpoints > 0) | |
6496 | annotate_breakpoints_table (); | |
6497 | ||
6498 | ALL_BREAKPOINTS (b) | |
6499 | { | |
6500 | QUIT; | |
6501 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6502 | if (filter && !filter (b)) | |
6503 | continue; | |
e5a67952 | 6504 | |
5c458ae8 | 6505 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
4a2b031d | 6506 | accept. Skip the others. */ |
e5a67952 | 6507 | |
5c458ae8 | 6508 | if (bp_num_list != NULL && *bp_num_list != '\0') |
4a2b031d | 6509 | { |
5c458ae8 | 6510 | if (show_internal) /* maintenance info breakpoint */ |
4a2b031d | 6511 | { |
5c458ae8 | 6512 | if (parse_and_eval_long (bp_num_list) != b->number) |
4a2b031d TT |
6513 | continue; |
6514 | } | |
6515 | else /* all others */ | |
6516 | { | |
5c458ae8 | 6517 | if (!number_is_in_list (bp_num_list, b->number)) |
4a2b031d TT |
6518 | continue; |
6519 | } | |
6520 | } | |
6521 | /* We only print out user settable breakpoints unless the | |
5c458ae8 SM |
6522 | show_internal is set. */ |
6523 | if (show_internal || user_breakpoint_p (b)) | |
6524 | print_one_breakpoint (b, &last_loc, show_internal); | |
4a2b031d TT |
6525 | } |
6526 | } | |
698384cd | 6527 | |
7f3b0473 | 6528 | if (nr_printable_breakpoints == 0) |
c906108c | 6529 | { |
4a64f543 MS |
6530 | /* If there's a filter, let the caller decide how to report |
6531 | empty list. */ | |
d77f58be SS |
6532 | if (!filter) |
6533 | { | |
5c458ae8 | 6534 | if (bp_num_list == NULL || *bp_num_list == '\0') |
112e8700 | 6535 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6536 | else |
112e8700 | 6537 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
5c458ae8 | 6538 | bp_num_list); |
d77f58be | 6539 | } |
c906108c SS |
6540 | } |
6541 | else | |
c4093a6a | 6542 | { |
a6d9a66e UW |
6543 | if (last_loc && !server_command) |
6544 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6545 | } |
c906108c | 6546 | |
4a64f543 | 6547 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6548 | there have been breakpoints? */ |
c906108c | 6549 | annotate_breakpoints_table_end (); |
d77f58be SS |
6550 | |
6551 | return nr_printable_breakpoints; | |
c906108c SS |
6552 | } |
6553 | ||
ad443146 SS |
6554 | /* Display the value of default-collect in a way that is generally |
6555 | compatible with the breakpoint list. */ | |
6556 | ||
6557 | static void | |
6558 | default_collect_info (void) | |
6559 | { | |
79a45e25 PA |
6560 | struct ui_out *uiout = current_uiout; |
6561 | ||
ad443146 SS |
6562 | /* If it has no value (which is frequently the case), say nothing; a |
6563 | message like "No default-collect." gets in user's face when it's | |
6564 | not wanted. */ | |
6565 | if (!*default_collect) | |
6566 | return; | |
6567 | ||
6568 | /* The following phrase lines up nicely with per-tracepoint collect | |
6569 | actions. */ | |
112e8700 SM |
6570 | uiout->text ("default collect "); |
6571 | uiout->field_string ("default-collect", default_collect); | |
6572 | uiout->text (" \n"); | |
ad443146 SS |
6573 | } |
6574 | ||
c906108c | 6575 | static void |
0b39b52e | 6576 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6577 | { |
5c458ae8 | 6578 | breakpoint_1 (args, false, NULL); |
ad443146 SS |
6579 | |
6580 | default_collect_info (); | |
d77f58be SS |
6581 | } |
6582 | ||
6583 | static void | |
1d12d88f | 6584 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6585 | { |
5c458ae8 | 6586 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
79a45e25 | 6587 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6588 | |
6589 | if (num_printed == 0) | |
6590 | { | |
e5a67952 | 6591 | if (args == NULL || *args == '\0') |
112e8700 | 6592 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6593 | else |
112e8700 | 6594 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6595 | } |
c906108c SS |
6596 | } |
6597 | ||
7a292a7a | 6598 | static void |
4495129a | 6599 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6600 | { |
5c458ae8 | 6601 | breakpoint_1 (args, true, NULL); |
ad443146 SS |
6602 | |
6603 | default_collect_info (); | |
c906108c SS |
6604 | } |
6605 | ||
0d381245 | 6606 | static int |
714835d5 | 6607 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6608 | struct program_space *pspace, |
714835d5 | 6609 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6610 | { |
6611 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6612 | |
0d381245 VP |
6613 | for (; bl; bl = bl->next) |
6614 | { | |
6c95b8df PA |
6615 | if (bl->pspace == pspace |
6616 | && bl->address == pc | |
0d381245 VP |
6617 | && (!overlay_debugging || bl->section == section)) |
6618 | return 1; | |
6619 | } | |
6620 | return 0; | |
6621 | } | |
6622 | ||
672f9b60 | 6623 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6624 | concerns with logical breakpoints, so we match program spaces, not |
6625 | address spaces. */ | |
c906108c SS |
6626 | |
6627 | static void | |
6c95b8df PA |
6628 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6629 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6630 | struct obj_section *section, int thread) |
c906108c | 6631 | { |
52f0bd74 AC |
6632 | int others = 0; |
6633 | struct breakpoint *b; | |
c906108c SS |
6634 | |
6635 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6636 | others += (user_breakpoint_p (b) |
6637 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6638 | if (others > 0) |
6639 | { | |
a3f17187 AC |
6640 | if (others == 1) |
6641 | printf_filtered (_("Note: breakpoint ")); | |
6642 | else /* if (others == ???) */ | |
6643 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6644 | ALL_BREAKPOINTS (b) |
672f9b60 | 6645 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6646 | { |
6647 | others--; | |
6648 | printf_filtered ("%d", b->number); | |
6649 | if (b->thread == -1 && thread != -1) | |
6650 | printf_filtered (" (all threads)"); | |
6651 | else if (b->thread != -1) | |
6652 | printf_filtered (" (thread %d)", b->thread); | |
6653 | printf_filtered ("%s%s ", | |
059fb39f | 6654 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6655 | || b->enable_state == bp_call_disabled) |
0d381245 | 6656 | ? " (disabled)" |
0d381245 VP |
6657 | : ""), |
6658 | (others > 1) ? "," | |
6659 | : ((others == 1) ? " and" : "")); | |
6660 | } | |
6a831f06 PA |
6661 | current_uiout->message (_("also set at pc %ps.\n"), |
6662 | styled_string (address_style.style (), | |
6663 | paddress (gdbarch, pc))); | |
c906108c SS |
6664 | } |
6665 | } | |
6666 | \f | |
c906108c | 6667 | |
cb1e4e32 PA |
6668 | /* Return true iff it is meaningful to use the address member of LOC. |
6669 | For some breakpoint types, the locations' address members are | |
6670 | irrelevant and it makes no sense to attempt to compare them to | |
6671 | other addresses (or use them for any other purpose either). | |
2d134ed3 | 6672 | |
cb1e4e32 PA |
6673 | More specifically, software watchpoints and catchpoints that are |
6674 | not backed by breakpoints always have a zero valued location | |
6675 | address and we don't want to mark breakpoints of any of these types | |
6676 | to be a duplicate of an actual breakpoint location at address | |
6677 | zero. */ | |
e4f237da | 6678 | |
cb1e4e32 PA |
6679 | static bool |
6680 | bl_address_is_meaningful (bp_location *loc) | |
e4f237da | 6681 | { |
cb1e4e32 | 6682 | return loc->loc_type != bp_loc_other; |
2d134ed3 PA |
6683 | } |
6684 | ||
6685 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6686 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6687 | ||
6688 | static int | |
4a64f543 MS |
6689 | watchpoint_locations_match (struct bp_location *loc1, |
6690 | struct bp_location *loc2) | |
2d134ed3 | 6691 | { |
3a5c3e22 PA |
6692 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6693 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6694 | ||
6695 | /* Both of them must exist. */ | |
6696 | gdb_assert (w1 != NULL); | |
6697 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6698 | |
4a64f543 MS |
6699 | /* If the target can evaluate the condition expression in hardware, |
6700 | then we we need to insert both watchpoints even if they are at | |
6701 | the same place. Otherwise the watchpoint will only trigger when | |
6702 | the condition of whichever watchpoint was inserted evaluates to | |
6703 | true, not giving a chance for GDB to check the condition of the | |
6704 | other watchpoint. */ | |
3a5c3e22 | 6705 | if ((w1->cond_exp |
4a64f543 MS |
6706 | && target_can_accel_watchpoint_condition (loc1->address, |
6707 | loc1->length, | |
0cf6dd15 | 6708 | loc1->watchpoint_type, |
4d01a485 | 6709 | w1->cond_exp.get ())) |
3a5c3e22 | 6710 | || (w2->cond_exp |
4a64f543 MS |
6711 | && target_can_accel_watchpoint_condition (loc2->address, |
6712 | loc2->length, | |
0cf6dd15 | 6713 | loc2->watchpoint_type, |
4d01a485 | 6714 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6715 | return 0; |
6716 | ||
85d721b8 PA |
6717 | /* Note that this checks the owner's type, not the location's. In |
6718 | case the target does not support read watchpoints, but does | |
6719 | support access watchpoints, we'll have bp_read_watchpoint | |
6720 | watchpoints with hw_access locations. Those should be considered | |
6721 | duplicates of hw_read locations. The hw_read locations will | |
6722 | become hw_access locations later. */ | |
2d134ed3 PA |
6723 | return (loc1->owner->type == loc2->owner->type |
6724 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6725 | && loc1->address == loc2->address | |
6726 | && loc1->length == loc2->length); | |
e4f237da KB |
6727 | } |
6728 | ||
31e77af2 | 6729 | /* See breakpoint.h. */ |
6c95b8df | 6730 | |
31e77af2 | 6731 | int |
accd0bcd YQ |
6732 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6733 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6734 | { |
f5656ead | 6735 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6736 | || aspace1 == aspace2) |
6737 | && addr1 == addr2); | |
6738 | } | |
6739 | ||
f1310107 TJB |
6740 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6741 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6742 | matches ASPACE2. On targets that have global breakpoints, the address | |
6743 | space doesn't really matter. */ | |
6744 | ||
6745 | static int | |
accd0bcd YQ |
6746 | breakpoint_address_match_range (const address_space *aspace1, |
6747 | CORE_ADDR addr1, | |
6748 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6749 | CORE_ADDR addr2) |
6750 | { | |
f5656ead | 6751 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6752 | || aspace1 == aspace2) |
6753 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6754 | } | |
6755 | ||
6756 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6757 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6758 | matches the breakpoint's address space. On targets that have global | |
6759 | breakpoints, the address space doesn't really matter. */ | |
6760 | ||
6761 | static int | |
6762 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6763 | const address_space *aspace, |
f1310107 TJB |
6764 | CORE_ADDR addr) |
6765 | { | |
6766 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6767 | aspace, addr) | |
6768 | || (bl->length | |
6769 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6770 | bl->address, bl->length, | |
6771 | aspace, addr))); | |
6772 | } | |
6773 | ||
d35ae833 PA |
6774 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6775 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6776 | match happens only if ASPACE matches the breakpoint's address | |
6777 | space. On targets that have global breakpoints, the address space | |
6778 | doesn't really matter. */ | |
6779 | ||
6780 | static int | |
6781 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6782 | const address_space *aspace, |
d35ae833 PA |
6783 | CORE_ADDR addr, int len) |
6784 | { | |
6785 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6786 | || bl->pspace->aspace == aspace) | |
6787 | { | |
6788 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6789 | ||
6790 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
6791 | return 1; | |
6792 | } | |
6793 | return 0; | |
6794 | } | |
6795 | ||
1e4d1764 YQ |
6796 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6797 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6798 | true, otherwise returns false. */ | |
6799 | ||
6800 | static int | |
6801 | tracepoint_locations_match (struct bp_location *loc1, | |
6802 | struct bp_location *loc2) | |
6803 | { | |
6804 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6805 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6806 | locations at the same address of different tracepoints are regarded as | |
6807 | different locations. */ | |
6808 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6809 | else | |
6810 | return 0; | |
6811 | } | |
6812 | ||
2d134ed3 | 6813 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
cb1e4e32 PA |
6814 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
6815 | the same location. */ | |
2d134ed3 PA |
6816 | |
6817 | static int | |
4a64f543 MS |
6818 | breakpoint_locations_match (struct bp_location *loc1, |
6819 | struct bp_location *loc2) | |
2d134ed3 | 6820 | { |
2bdf28a0 JK |
6821 | int hw_point1, hw_point2; |
6822 | ||
6823 | /* Both of them must not be in moribund_locations. */ | |
6824 | gdb_assert (loc1->owner != NULL); | |
6825 | gdb_assert (loc2->owner != NULL); | |
6826 | ||
6827 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6828 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6829 | |
6830 | if (hw_point1 != hw_point2) | |
6831 | return 0; | |
6832 | else if (hw_point1) | |
6833 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6834 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6835 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6836 | else |
f1310107 TJB |
6837 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6838 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6839 | loc2->pspace->aspace, loc2->address) | |
6840 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6841 | } |
6842 | ||
76897487 KB |
6843 | static void |
6844 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6845 | int bnum, int have_bnum) | |
6846 | { | |
f63fbe86 MS |
6847 | /* The longest string possibly returned by hex_string_custom |
6848 | is 50 chars. These must be at least that big for safety. */ | |
6849 | char astr1[64]; | |
6850 | char astr2[64]; | |
76897487 | 6851 | |
bb599908 PH |
6852 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6853 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6854 | if (have_bnum) |
8a3fe4f8 | 6855 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6856 | bnum, astr1, astr2); |
6857 | else | |
8a3fe4f8 | 6858 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6859 | } |
6860 | ||
4a64f543 MS |
6861 | /* Adjust a breakpoint's address to account for architectural |
6862 | constraints on breakpoint placement. Return the adjusted address. | |
6863 | Note: Very few targets require this kind of adjustment. For most | |
6864 | targets, this function is simply the identity function. */ | |
76897487 KB |
6865 | |
6866 | static CORE_ADDR | |
a6d9a66e UW |
6867 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6868 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6869 | { |
a0de8c21 YQ |
6870 | if (bptype == bp_watchpoint |
6871 | || bptype == bp_hardware_watchpoint | |
6872 | || bptype == bp_read_watchpoint | |
6873 | || bptype == bp_access_watchpoint | |
6874 | || bptype == bp_catchpoint) | |
88f7da05 KB |
6875 | { |
6876 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6877 | have their addresses modified. */ | |
6878 | return bpaddr; | |
6879 | } | |
7c16b83e PA |
6880 | else if (bptype == bp_single_step) |
6881 | { | |
6882 | /* Single-step breakpoints should not have their addresses | |
6883 | modified. If there's any architectural constrain that | |
6884 | applies to this address, then it should have already been | |
6885 | taken into account when the breakpoint was created in the | |
6886 | first place. If we didn't do this, stepping through e.g., | |
6887 | Thumb-2 IT blocks would break. */ | |
6888 | return bpaddr; | |
6889 | } | |
76897487 KB |
6890 | else |
6891 | { | |
a0de8c21 YQ |
6892 | CORE_ADDR adjusted_bpaddr = bpaddr; |
6893 | ||
6894 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) | |
6895 | { | |
6896 | /* Some targets have architectural constraints on the placement | |
6897 | of breakpoint instructions. Obtain the adjusted address. */ | |
6898 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); | |
6899 | } | |
76897487 | 6900 | |
a0de8c21 | 6901 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
76897487 KB |
6902 | |
6903 | /* An adjusted breakpoint address can significantly alter | |
6904 | a user's expectations. Print a warning if an adjustment | |
6905 | is required. */ | |
6906 | if (adjusted_bpaddr != bpaddr) | |
6907 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6908 | ||
6909 | return adjusted_bpaddr; | |
6910 | } | |
6911 | } | |
6912 | ||
cb1e4e32 PA |
6913 | static bp_loc_type |
6914 | bp_location_from_bp_type (bptype type) | |
7cc221ef | 6915 | { |
cb1e4e32 | 6916 | switch (type) |
e049a4b5 DJ |
6917 | { |
6918 | case bp_breakpoint: | |
7c16b83e | 6919 | case bp_single_step: |
e049a4b5 DJ |
6920 | case bp_until: |
6921 | case bp_finish: | |
6922 | case bp_longjmp: | |
6923 | case bp_longjmp_resume: | |
e2e4d78b | 6924 | case bp_longjmp_call_dummy: |
186c406b TT |
6925 | case bp_exception: |
6926 | case bp_exception_resume: | |
e049a4b5 | 6927 | case bp_step_resume: |
2c03e5be | 6928 | case bp_hp_step_resume: |
e049a4b5 DJ |
6929 | case bp_watchpoint_scope: |
6930 | case bp_call_dummy: | |
aa7d318d | 6931 | case bp_std_terminate: |
e049a4b5 DJ |
6932 | case bp_shlib_event: |
6933 | case bp_thread_event: | |
6934 | case bp_overlay_event: | |
4efc6507 | 6935 | case bp_jit_event: |
0fd8e87f | 6936 | case bp_longjmp_master: |
aa7d318d | 6937 | case bp_std_terminate_master: |
186c406b | 6938 | case bp_exception_master: |
0e30163f JK |
6939 | case bp_gnu_ifunc_resolver: |
6940 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6941 | case bp_dprintf: |
cb1e4e32 | 6942 | return bp_loc_software_breakpoint; |
e049a4b5 | 6943 | case bp_hardware_breakpoint: |
cb1e4e32 | 6944 | return bp_loc_hardware_breakpoint; |
e049a4b5 DJ |
6945 | case bp_hardware_watchpoint: |
6946 | case bp_read_watchpoint: | |
6947 | case bp_access_watchpoint: | |
cb1e4e32 | 6948 | return bp_loc_hardware_watchpoint; |
e049a4b5 | 6949 | case bp_watchpoint: |
ce78b96d | 6950 | case bp_catchpoint: |
15c3d785 PA |
6951 | case bp_tracepoint: |
6952 | case bp_fast_tracepoint: | |
0fb4aa4b | 6953 | case bp_static_tracepoint: |
cb1e4e32 | 6954 | return bp_loc_other; |
e049a4b5 | 6955 | default: |
e2e0b3e5 | 6956 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 | 6957 | } |
cb1e4e32 PA |
6958 | } |
6959 | ||
6960 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) | |
6961 | { | |
6962 | this->owner = owner; | |
6963 | this->cond_bytecode = NULL; | |
6964 | this->shlib_disabled = 0; | |
6965 | this->enabled = 1; | |
6966 | ||
6967 | this->loc_type = type; | |
e049a4b5 | 6968 | |
cb1e4e32 PA |
6969 | if (this->loc_type == bp_loc_software_breakpoint |
6970 | || this->loc_type == bp_loc_hardware_breakpoint) | |
6971 | mark_breakpoint_location_modified (this); | |
6972 | ||
6973 | this->refc = 1; | |
6974 | } | |
6975 | ||
6976 | bp_location::bp_location (breakpoint *owner) | |
6977 | : bp_location::bp_location (owner, | |
6978 | bp_location_from_bp_type (owner->type)) | |
6979 | { | |
28010a5d PA |
6980 | } |
6981 | ||
6982 | /* Allocate a struct bp_location. */ | |
6983 | ||
6984 | static struct bp_location * | |
6985 | allocate_bp_location (struct breakpoint *bpt) | |
6986 | { | |
348d480f PA |
6987 | return bpt->ops->allocate_location (bpt); |
6988 | } | |
7cc221ef | 6989 | |
f431efe5 PA |
6990 | static void |
6991 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6992 | { |
4d01a485 | 6993 | delete loc; |
fe3f5fa8 VP |
6994 | } |
6995 | ||
f431efe5 PA |
6996 | /* Increment reference count. */ |
6997 | ||
6998 | static void | |
6999 | incref_bp_location (struct bp_location *bl) | |
7000 | { | |
7001 | ++bl->refc; | |
7002 | } | |
7003 | ||
7004 | /* Decrement reference count. If the reference count reaches 0, | |
7005 | destroy the bp_location. Sets *BLP to NULL. */ | |
7006 | ||
7007 | static void | |
7008 | decref_bp_location (struct bp_location **blp) | |
7009 | { | |
0807b50c PA |
7010 | gdb_assert ((*blp)->refc > 0); |
7011 | ||
f431efe5 PA |
7012 | if (--(*blp)->refc == 0) |
7013 | free_bp_location (*blp); | |
7014 | *blp = NULL; | |
7015 | } | |
7016 | ||
346774a9 | 7017 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7018 | |
b270e6f9 TT |
7019 | static breakpoint * |
7020 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7021 | { |
346774a9 | 7022 | struct breakpoint *b1; |
b270e6f9 | 7023 | struct breakpoint *result = b.get (); |
c906108c | 7024 | |
346774a9 PA |
7025 | /* Add this breakpoint to the end of the chain so that a list of |
7026 | breakpoints will come out in order of increasing numbers. */ | |
7027 | ||
7028 | b1 = breakpoint_chain; | |
7029 | if (b1 == 0) | |
b270e6f9 | 7030 | breakpoint_chain = b.release (); |
346774a9 PA |
7031 | else |
7032 | { | |
7033 | while (b1->next) | |
7034 | b1 = b1->next; | |
b270e6f9 | 7035 | b1->next = b.release (); |
346774a9 | 7036 | } |
b270e6f9 TT |
7037 | |
7038 | return result; | |
346774a9 PA |
7039 | } |
7040 | ||
7041 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7042 | ||
7043 | static void | |
7044 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7045 | struct gdbarch *gdbarch, | |
28010a5d | 7046 | enum bptype bptype, |
c0a91b2b | 7047 | const struct breakpoint_ops *ops) |
346774a9 | 7048 | { |
348d480f PA |
7049 | gdb_assert (ops != NULL); |
7050 | ||
28010a5d | 7051 | b->ops = ops; |
4d28f7a8 | 7052 | b->type = bptype; |
a6d9a66e | 7053 | b->gdbarch = gdbarch; |
c906108c SS |
7054 | b->language = current_language->la_language; |
7055 | b->input_radix = input_radix; | |
d0fb5eae | 7056 | b->related_breakpoint = b; |
346774a9 PA |
7057 | } |
7058 | ||
7059 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7060 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7061 | |
7062 | static struct breakpoint * | |
7063 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7064 | enum bptype bptype, |
c0a91b2b | 7065 | const struct breakpoint_ops *ops) |
346774a9 | 7066 | { |
3b0871f4 | 7067 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7068 | |
3b0871f4 | 7069 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7070 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7071 | } |
7072 | ||
0ba852ab | 7073 | /* Initialize loc->function_name. */ |
0e30163f | 7074 | |
0d381245 | 7075 | static void |
0ba852ab | 7076 | set_breakpoint_location_function (struct bp_location *loc) |
0d381245 | 7077 | { |
2bdf28a0 JK |
7078 | gdb_assert (loc->owner != NULL); |
7079 | ||
0d381245 | 7080 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7081 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7082 | || is_tracepoint (loc->owner)) |
0d381245 | 7083 | { |
2c02bd72 | 7084 | const char *function_name; |
0e30163f | 7085 | |
3467ec66 | 7086 | if (loc->msymbol != NULL |
f50776aa | 7087 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
0ba852ab | 7088 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)) |
0e30163f JK |
7089 | { |
7090 | struct breakpoint *b = loc->owner; | |
7091 | ||
3467ec66 PA |
7092 | function_name = MSYMBOL_LINKAGE_NAME (loc->msymbol); |
7093 | ||
7094 | if (b->type == bp_breakpoint && b->loc == loc | |
7095 | && loc->next == NULL && b->related_breakpoint == b) | |
0e30163f JK |
7096 | { |
7097 | /* Create only the whole new breakpoint of this type but do not | |
7098 | mess more complicated breakpoints with multiple locations. */ | |
7099 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7100 | /* Remember the resolver's address for use by the return |
7101 | breakpoint. */ | |
3467ec66 | 7102 | loc->related_address = loc->address; |
0e30163f JK |
7103 | } |
7104 | } | |
3467ec66 PA |
7105 | else |
7106 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); | |
0e30163f | 7107 | |
2c02bd72 DE |
7108 | if (function_name) |
7109 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7110 | } |
7111 | } | |
7112 | ||
a6d9a66e | 7113 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7114 | struct gdbarch * |
a6d9a66e UW |
7115 | get_sal_arch (struct symtab_and_line sal) |
7116 | { | |
7117 | if (sal.section) | |
7118 | return get_objfile_arch (sal.section->objfile); | |
7119 | if (sal.symtab) | |
eb822aa6 | 7120 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7121 | |
7122 | return NULL; | |
7123 | } | |
7124 | ||
346774a9 PA |
7125 | /* Low level routine for partially initializing a breakpoint of type |
7126 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7127 | file name, and line number are provided by SAL. |
0d381245 VP |
7128 | |
7129 | It is expected that the caller will complete the initialization of | |
7130 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7131 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7132 | |
346774a9 PA |
7133 | static void |
7134 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7135 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7136 | const struct breakpoint_ops *ops) |
0d381245 | 7137 | { |
28010a5d | 7138 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7139 | |
3742cc8b | 7140 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7141 | |
6c95b8df PA |
7142 | if (bptype != bp_catchpoint) |
7143 | gdb_assert (sal.pspace != NULL); | |
7144 | ||
f8eba3c6 TT |
7145 | /* Store the program space that was used to set the breakpoint, |
7146 | except for ordinary breakpoints, which are independent of the | |
7147 | program space. */ | |
7148 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7149 | b->pspace = sal.pspace; | |
346774a9 | 7150 | } |
c906108c | 7151 | |
346774a9 PA |
7152 | /* set_raw_breakpoint is a low level routine for allocating and |
7153 | partially initializing a breakpoint of type BPTYPE. The newly | |
7154 | created breakpoint's address, section, source file name, and line | |
7155 | number are provided by SAL. The newly created and partially | |
7156 | initialized breakpoint is added to the breakpoint chain and | |
7157 | is also returned as the value of this function. | |
7158 | ||
7159 | It is expected that the caller will complete the initialization of | |
7160 | the newly created breakpoint struct as well as output any status | |
7161 | information regarding the creation of a new breakpoint. In | |
7162 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7163 | number! Care should be taken to not allow an error to occur | |
7164 | prior to completing the initialization of the breakpoint. If this | |
7165 | should happen, a bogus breakpoint will be left on the chain. */ | |
7166 | ||
7167 | struct breakpoint * | |
7168 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7169 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7170 | const struct breakpoint_ops *ops) |
346774a9 | 7171 | { |
3b0871f4 | 7172 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7173 | |
3b0871f4 | 7174 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7175 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7176 | } |
7177 | ||
53a5351d | 7178 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7179 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7180 | initiated the operation. */ | |
c906108c SS |
7181 | |
7182 | void | |
186c406b | 7183 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7184 | { |
35df4500 | 7185 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7186 | int thread = tp->global_num; |
0fd8e87f UW |
7187 | |
7188 | /* To avoid having to rescan all objfile symbols at every step, | |
7189 | we maintain a list of continually-inserted but always disabled | |
7190 | longjmp "master" breakpoints. Here, we simply create momentary | |
7191 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7192 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7193 | if (b->pspace == current_program_space |
186c406b TT |
7194 | && (b->type == bp_longjmp_master |
7195 | || b->type == bp_exception_master)) | |
0fd8e87f | 7196 | { |
06edf0c0 PA |
7197 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7198 | struct breakpoint *clone; | |
cc59ec59 | 7199 | |
e2e4d78b JK |
7200 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7201 | after their removal. */ | |
06edf0c0 | 7202 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7203 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7204 | clone->thread = thread; |
7205 | } | |
186c406b TT |
7206 | |
7207 | tp->initiating_frame = frame; | |
c906108c SS |
7208 | } |
7209 | ||
611c83ae | 7210 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7211 | void |
611c83ae | 7212 | delete_longjmp_breakpoint (int thread) |
c906108c | 7213 | { |
35df4500 | 7214 | struct breakpoint *b, *b_tmp; |
c906108c | 7215 | |
35df4500 | 7216 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7217 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7218 | { |
7219 | if (b->thread == thread) | |
7220 | delete_breakpoint (b); | |
7221 | } | |
c906108c SS |
7222 | } |
7223 | ||
f59f708a PA |
7224 | void |
7225 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7226 | { | |
7227 | struct breakpoint *b, *b_tmp; | |
7228 | ||
7229 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7230 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7231 | { | |
7232 | if (b->thread == thread) | |
7233 | b->disposition = disp_del_at_next_stop; | |
7234 | } | |
7235 | } | |
7236 | ||
e2e4d78b JK |
7237 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7238 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7239 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7240 | breakpoints. */ | |
7241 | ||
7242 | struct breakpoint * | |
7243 | set_longjmp_breakpoint_for_call_dummy (void) | |
7244 | { | |
7245 | struct breakpoint *b, *retval = NULL; | |
7246 | ||
7247 | ALL_BREAKPOINTS (b) | |
7248 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7249 | { | |
7250 | struct breakpoint *new_b; | |
7251 | ||
7252 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7253 | &momentary_breakpoint_ops, |
7254 | 1); | |
00431a78 | 7255 | new_b->thread = inferior_thread ()->global_num; |
e2e4d78b JK |
7256 | |
7257 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7258 | ||
7259 | gdb_assert (new_b->related_breakpoint == new_b); | |
7260 | if (retval == NULL) | |
7261 | retval = new_b; | |
7262 | new_b->related_breakpoint = retval; | |
7263 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7264 | retval = retval->related_breakpoint; | |
7265 | retval->related_breakpoint = new_b; | |
7266 | } | |
7267 | ||
7268 | return retval; | |
7269 | } | |
7270 | ||
7271 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7272 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7273 | stack. |
7274 | ||
7275 | You should call this function only at places where it is safe to currently | |
7276 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7277 | frames. */ | |
7278 | ||
7279 | void | |
b67a2c6f | 7280 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7281 | { |
7282 | struct breakpoint *b, *b_tmp; | |
7283 | ||
7284 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7285 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7286 | { |
7287 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7288 | ||
7289 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7290 | dummy_b = dummy_b->related_breakpoint; | |
7291 | if (dummy_b->type != bp_call_dummy | |
7292 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7293 | continue; | |
7294 | ||
00431a78 | 7295 | dummy_frame_discard (dummy_b->frame_id, tp); |
e2e4d78b JK |
7296 | |
7297 | while (b->related_breakpoint != b) | |
7298 | { | |
7299 | if (b_tmp == b->related_breakpoint) | |
7300 | b_tmp = b->related_breakpoint->next; | |
7301 | delete_breakpoint (b->related_breakpoint); | |
7302 | } | |
7303 | delete_breakpoint (b); | |
7304 | } | |
7305 | } | |
7306 | ||
1900040c MS |
7307 | void |
7308 | enable_overlay_breakpoints (void) | |
7309 | { | |
52f0bd74 | 7310 | struct breakpoint *b; |
1900040c MS |
7311 | |
7312 | ALL_BREAKPOINTS (b) | |
7313 | if (b->type == bp_overlay_event) | |
7314 | { | |
7315 | b->enable_state = bp_enabled; | |
44702360 | 7316 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7317 | overlay_events_enabled = 1; |
1900040c MS |
7318 | } |
7319 | } | |
7320 | ||
7321 | void | |
7322 | disable_overlay_breakpoints (void) | |
7323 | { | |
52f0bd74 | 7324 | struct breakpoint *b; |
1900040c MS |
7325 | |
7326 | ALL_BREAKPOINTS (b) | |
7327 | if (b->type == bp_overlay_event) | |
7328 | { | |
7329 | b->enable_state = bp_disabled; | |
44702360 | 7330 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7331 | overlay_events_enabled = 0; |
1900040c MS |
7332 | } |
7333 | } | |
7334 | ||
aa7d318d TT |
7335 | /* Set an active std::terminate breakpoint for each std::terminate |
7336 | master breakpoint. */ | |
7337 | void | |
7338 | set_std_terminate_breakpoint (void) | |
7339 | { | |
35df4500 | 7340 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7341 | |
35df4500 | 7342 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7343 | if (b->pspace == current_program_space |
7344 | && b->type == bp_std_terminate_master) | |
7345 | { | |
06edf0c0 | 7346 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7347 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7348 | } |
7349 | } | |
7350 | ||
7351 | /* Delete all the std::terminate breakpoints. */ | |
7352 | void | |
7353 | delete_std_terminate_breakpoint (void) | |
7354 | { | |
35df4500 | 7355 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7356 | |
35df4500 | 7357 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7358 | if (b->type == bp_std_terminate) |
7359 | delete_breakpoint (b); | |
7360 | } | |
7361 | ||
c4093a6a | 7362 | struct breakpoint * |
a6d9a66e | 7363 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7364 | { |
7365 | struct breakpoint *b; | |
c4093a6a | 7366 | |
06edf0c0 PA |
7367 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7368 | &internal_breakpoint_ops); | |
7369 | ||
b5de0fa7 | 7370 | b->enable_state = bp_enabled; |
f00aae0f | 7371 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7372 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7373 | |
44702360 | 7374 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7375 | |
c4093a6a JM |
7376 | return b; |
7377 | } | |
7378 | ||
0101ce28 JJ |
7379 | struct lang_and_radix |
7380 | { | |
7381 | enum language lang; | |
7382 | int radix; | |
7383 | }; | |
7384 | ||
4efc6507 DE |
7385 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7386 | ||
7387 | struct breakpoint * | |
7388 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7389 | { | |
2a7f3dff PA |
7390 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7391 | &internal_breakpoint_ops); | |
4efc6507 | 7392 | } |
0101ce28 | 7393 | |
03673fc7 PP |
7394 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7395 | ||
7396 | void | |
7397 | remove_jit_event_breakpoints (void) | |
7398 | { | |
7399 | struct breakpoint *b, *b_tmp; | |
7400 | ||
7401 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7402 | if (b->type == bp_jit_event | |
7403 | && b->loc->pspace == current_program_space) | |
7404 | delete_breakpoint (b); | |
7405 | } | |
7406 | ||
cae688ec JJ |
7407 | void |
7408 | remove_solib_event_breakpoints (void) | |
7409 | { | |
35df4500 | 7410 | struct breakpoint *b, *b_tmp; |
cae688ec | 7411 | |
35df4500 | 7412 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7413 | if (b->type == bp_shlib_event |
7414 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7415 | delete_breakpoint (b); |
7416 | } | |
7417 | ||
f37f681c PA |
7418 | /* See breakpoint.h. */ |
7419 | ||
7420 | void | |
7421 | remove_solib_event_breakpoints_at_next_stop (void) | |
7422 | { | |
7423 | struct breakpoint *b, *b_tmp; | |
7424 | ||
7425 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7426 | if (b->type == bp_shlib_event | |
7427 | && b->loc->pspace == current_program_space) | |
7428 | b->disposition = disp_del_at_next_stop; | |
7429 | } | |
7430 | ||
04086b45 PA |
7431 | /* Helper for create_solib_event_breakpoint / |
7432 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7433 | INSERT_MODE to pass through to update_global_location_list. */ | |
7434 | ||
7435 | static struct breakpoint * | |
7436 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7437 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7438 | { |
7439 | struct breakpoint *b; | |
7440 | ||
06edf0c0 PA |
7441 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7442 | &internal_breakpoint_ops); | |
04086b45 | 7443 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7444 | return b; |
7445 | } | |
7446 | ||
04086b45 PA |
7447 | struct breakpoint * |
7448 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7449 | { | |
7450 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7451 | } | |
7452 | ||
f37f681c PA |
7453 | /* See breakpoint.h. */ |
7454 | ||
7455 | struct breakpoint * | |
7456 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7457 | { | |
7458 | struct breakpoint *b; | |
7459 | ||
04086b45 PA |
7460 | /* Explicitly tell update_global_location_list to insert |
7461 | locations. */ | |
7462 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7463 | if (!b->loc->inserted) |
7464 | { | |
7465 | delete_breakpoint (b); | |
7466 | return NULL; | |
7467 | } | |
7468 | return b; | |
7469 | } | |
7470 | ||
cae688ec JJ |
7471 | /* Disable any breakpoints that are on code in shared libraries. Only |
7472 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7473 | ||
7474 | void | |
cb851954 | 7475 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7476 | { |
876fa593 | 7477 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7478 | |
876fa593 | 7479 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7480 | { |
2bdf28a0 | 7481 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7482 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7483 | |
4a64f543 MS |
7484 | /* We apply the check to all breakpoints, including disabled for |
7485 | those with loc->duplicate set. This is so that when breakpoint | |
7486 | becomes enabled, or the duplicate is removed, gdb will try to | |
7487 | insert all breakpoints. If we don't set shlib_disabled here, | |
7488 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7489 | if (((b->type == bp_breakpoint) |
508ccb1f | 7490 | || (b->type == bp_jit_event) |
1042e4c0 | 7491 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7492 | || (is_tracepoint (b))) |
6c95b8df | 7493 | && loc->pspace == current_program_space |
0d381245 | 7494 | && !loc->shlib_disabled |
6c95b8df | 7495 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7496 | ) |
0d381245 VP |
7497 | { |
7498 | loc->shlib_disabled = 1; | |
7499 | } | |
cae688ec JJ |
7500 | } |
7501 | } | |
7502 | ||
63644780 NB |
7503 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7504 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7505 | disabled ones can just stay disabled. */ | |
84acb35a | 7506 | |
75149521 | 7507 | static void |
84acb35a JJ |
7508 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7509 | { | |
876fa593 | 7510 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7511 | int disabled_shlib_breaks = 0; |
7512 | ||
876fa593 | 7513 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7514 | { |
2bdf28a0 | 7515 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7516 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7517 | |
1e4d1764 | 7518 | if (solib->pspace == loc->pspace |
e2dd7057 | 7519 | && !loc->shlib_disabled |
1e4d1764 YQ |
7520 | && (((b->type == bp_breakpoint |
7521 | || b->type == bp_jit_event | |
7522 | || b->type == bp_hardware_breakpoint) | |
7523 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7524 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7525 | || is_tracepoint (b)) | |
e2dd7057 | 7526 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7527 | { |
e2dd7057 PP |
7528 | loc->shlib_disabled = 1; |
7529 | /* At this point, we cannot rely on remove_breakpoint | |
7530 | succeeding so we must mark the breakpoint as not inserted | |
7531 | to prevent future errors occurring in remove_breakpoints. */ | |
7532 | loc->inserted = 0; | |
8d3788bd VP |
7533 | |
7534 | /* This may cause duplicate notifications for the same breakpoint. */ | |
76727919 | 7535 | gdb::observers::breakpoint_modified.notify (b); |
8d3788bd | 7536 | |
e2dd7057 PP |
7537 | if (!disabled_shlib_breaks) |
7538 | { | |
223ffa71 | 7539 | target_terminal::ours_for_output (); |
3e43a32a MS |
7540 | warning (_("Temporarily disabling breakpoints " |
7541 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7542 | solib->so_name); |
84acb35a | 7543 | } |
e2dd7057 | 7544 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7545 | } |
7546 | } | |
84acb35a JJ |
7547 | } |
7548 | ||
63644780 NB |
7549 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7550 | notification of free_objfile. Only apply to enabled breakpoints, | |
7551 | disabled ones can just stay disabled. */ | |
7552 | ||
7553 | static void | |
7554 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7555 | { | |
7556 | struct breakpoint *b; | |
7557 | ||
7558 | if (objfile == NULL) | |
7559 | return; | |
7560 | ||
d03de421 PA |
7561 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7562 | managed by the user with add-symbol-file/remove-symbol-file. | |
7563 | Similarly to how breakpoints in shared libraries are handled in | |
7564 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7565 | shlib_disabled so they end up uninserted on the next global |
7566 | location list update. Shared libraries not loaded by the user | |
7567 | aren't handled here -- they're already handled in | |
7568 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7569 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7570 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7571 | main objfile). */ | |
7572 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7573 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7574 | return; |
7575 | ||
7576 | ALL_BREAKPOINTS (b) | |
7577 | { | |
7578 | struct bp_location *loc; | |
7579 | int bp_modified = 0; | |
7580 | ||
7581 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7582 | continue; | |
7583 | ||
7584 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7585 | { | |
7586 | CORE_ADDR loc_addr = loc->address; | |
7587 | ||
7588 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7589 | && loc->loc_type != bp_loc_software_breakpoint) | |
7590 | continue; | |
7591 | ||
7592 | if (loc->shlib_disabled != 0) | |
7593 | continue; | |
7594 | ||
7595 | if (objfile->pspace != loc->pspace) | |
7596 | continue; | |
7597 | ||
7598 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7599 | && loc->loc_type != bp_loc_software_breakpoint) | |
7600 | continue; | |
7601 | ||
7602 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7603 | { | |
7604 | loc->shlib_disabled = 1; | |
08351840 PA |
7605 | /* At this point, we don't know whether the object was |
7606 | unmapped from the inferior or not, so leave the | |
7607 | inserted flag alone. We'll handle failure to | |
7608 | uninsert quietly, in case the object was indeed | |
7609 | unmapped. */ | |
63644780 NB |
7610 | |
7611 | mark_breakpoint_location_modified (loc); | |
7612 | ||
7613 | bp_modified = 1; | |
7614 | } | |
7615 | } | |
7616 | ||
7617 | if (bp_modified) | |
76727919 | 7618 | gdb::observers::breakpoint_modified.notify (b); |
63644780 NB |
7619 | } |
7620 | } | |
7621 | ||
ce78b96d JB |
7622 | /* FORK & VFORK catchpoints. */ |
7623 | ||
e29a4733 | 7624 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7625 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7626 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7627 | |
c1fc2657 | 7628 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7629 | { |
e29a4733 PA |
7630 | /* Process id of a child process whose forking triggered this |
7631 | catchpoint. This field is only valid immediately after this | |
7632 | catchpoint has triggered. */ | |
7633 | ptid_t forked_inferior_pid; | |
7634 | }; | |
7635 | ||
4a64f543 MS |
7636 | /* Implement the "insert" breakpoint_ops method for fork |
7637 | catchpoints. */ | |
ce78b96d | 7638 | |
77b06cd7 TJB |
7639 | static int |
7640 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7641 | { |
e99b03dc | 7642 | return target_insert_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7643 | } |
7644 | ||
4a64f543 MS |
7645 | /* Implement the "remove" breakpoint_ops method for fork |
7646 | catchpoints. */ | |
ce78b96d JB |
7647 | |
7648 | static int | |
73971819 | 7649 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7650 | { |
e99b03dc | 7651 | return target_remove_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7652 | } |
7653 | ||
7654 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7655 | catchpoints. */ | |
7656 | ||
7657 | static int | |
f1310107 | 7658 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
bd522513 | 7659 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7660 | const struct target_waitstatus *ws) |
ce78b96d | 7661 | { |
e29a4733 PA |
7662 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7663 | ||
f90263c1 TT |
7664 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7665 | return 0; | |
7666 | ||
7667 | c->forked_inferior_pid = ws->value.related_pid; | |
7668 | return 1; | |
ce78b96d JB |
7669 | } |
7670 | ||
4a64f543 MS |
7671 | /* Implement the "print_it" breakpoint_ops method for fork |
7672 | catchpoints. */ | |
ce78b96d JB |
7673 | |
7674 | static enum print_stop_action | |
348d480f | 7675 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7676 | { |
36dfb11c | 7677 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7678 | struct breakpoint *b = bs->breakpoint_at; |
7679 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7680 | |
ce78b96d | 7681 | annotate_catchpoint (b->number); |
f303dbd6 | 7682 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7683 | if (b->disposition == disp_del) |
112e8700 | 7684 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7685 | else |
112e8700 SM |
7686 | uiout->text ("Catchpoint "); |
7687 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7688 | { |
112e8700 SM |
7689 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7690 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7691 | } |
381befee | 7692 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7693 | uiout->text (" (forked process "); |
381befee | 7694 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7695 | uiout->text ("), "); |
ce78b96d JB |
7696 | return PRINT_SRC_AND_LOC; |
7697 | } | |
7698 | ||
4a64f543 MS |
7699 | /* Implement the "print_one" breakpoint_ops method for fork |
7700 | catchpoints. */ | |
ce78b96d JB |
7701 | |
7702 | static void | |
a6d9a66e | 7703 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7704 | { |
e29a4733 | 7705 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7706 | struct value_print_options opts; |
79a45e25 | 7707 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7708 | |
7709 | get_user_print_options (&opts); | |
7710 | ||
4a64f543 MS |
7711 | /* Field 4, the address, is omitted (which makes the columns not |
7712 | line up too nicely with the headers, but the effect is relatively | |
7713 | readable). */ | |
79a45b7d | 7714 | if (opts.addressprint) |
112e8700 | 7715 | uiout->field_skip ("addr"); |
ce78b96d | 7716 | annotate_field (5); |
112e8700 | 7717 | uiout->text ("fork"); |
d7e15655 | 7718 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7719 | { |
112e8700 | 7720 | uiout->text (", process "); |
381befee | 7721 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7722 | uiout->spaces (1); |
ce78b96d | 7723 | } |
8ac3646f | 7724 | |
112e8700 SM |
7725 | if (uiout->is_mi_like_p ()) |
7726 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
7727 | } |
7728 | ||
7729 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7730 | catchpoints. */ | |
7731 | ||
7732 | static void | |
7733 | print_mention_catch_fork (struct breakpoint *b) | |
7734 | { | |
7735 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7736 | } | |
7737 | ||
6149aea9 PA |
7738 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7739 | catchpoints. */ | |
7740 | ||
7741 | static void | |
7742 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7743 | { | |
7744 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7745 | print_recreate_thread (b, fp); |
6149aea9 PA |
7746 | } |
7747 | ||
ce78b96d JB |
7748 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7749 | ||
2060206e | 7750 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7751 | |
4a64f543 MS |
7752 | /* Implement the "insert" breakpoint_ops method for vfork |
7753 | catchpoints. */ | |
ce78b96d | 7754 | |
77b06cd7 TJB |
7755 | static int |
7756 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7757 | { |
e99b03dc | 7758 | return target_insert_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7759 | } |
7760 | ||
4a64f543 MS |
7761 | /* Implement the "remove" breakpoint_ops method for vfork |
7762 | catchpoints. */ | |
ce78b96d JB |
7763 | |
7764 | static int | |
73971819 | 7765 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7766 | { |
e99b03dc | 7767 | return target_remove_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7768 | } |
7769 | ||
7770 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7771 | catchpoints. */ | |
7772 | ||
7773 | static int | |
f1310107 | 7774 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
bd522513 | 7775 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7776 | const struct target_waitstatus *ws) |
ce78b96d | 7777 | { |
e29a4733 PA |
7778 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7779 | ||
f90263c1 TT |
7780 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7781 | return 0; | |
7782 | ||
7783 | c->forked_inferior_pid = ws->value.related_pid; | |
7784 | return 1; | |
ce78b96d JB |
7785 | } |
7786 | ||
4a64f543 MS |
7787 | /* Implement the "print_it" breakpoint_ops method for vfork |
7788 | catchpoints. */ | |
ce78b96d JB |
7789 | |
7790 | static enum print_stop_action | |
348d480f | 7791 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7792 | { |
36dfb11c | 7793 | struct ui_out *uiout = current_uiout; |
348d480f | 7794 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7795 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7796 | ||
ce78b96d | 7797 | annotate_catchpoint (b->number); |
f303dbd6 | 7798 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7799 | if (b->disposition == disp_del) |
112e8700 | 7800 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7801 | else |
112e8700 SM |
7802 | uiout->text ("Catchpoint "); |
7803 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7804 | { |
112e8700 SM |
7805 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
7806 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7807 | } |
381befee | 7808 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7809 | uiout->text (" (vforked process "); |
381befee | 7810 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7811 | uiout->text ("), "); |
ce78b96d JB |
7812 | return PRINT_SRC_AND_LOC; |
7813 | } | |
7814 | ||
4a64f543 MS |
7815 | /* Implement the "print_one" breakpoint_ops method for vfork |
7816 | catchpoints. */ | |
ce78b96d JB |
7817 | |
7818 | static void | |
a6d9a66e | 7819 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7820 | { |
e29a4733 | 7821 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7822 | struct value_print_options opts; |
79a45e25 | 7823 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7824 | |
7825 | get_user_print_options (&opts); | |
4a64f543 MS |
7826 | /* Field 4, the address, is omitted (which makes the columns not |
7827 | line up too nicely with the headers, but the effect is relatively | |
7828 | readable). */ | |
79a45b7d | 7829 | if (opts.addressprint) |
112e8700 | 7830 | uiout->field_skip ("addr"); |
ce78b96d | 7831 | annotate_field (5); |
112e8700 | 7832 | uiout->text ("vfork"); |
d7e15655 | 7833 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7834 | { |
112e8700 | 7835 | uiout->text (", process "); |
381befee | 7836 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7837 | uiout->spaces (1); |
ce78b96d | 7838 | } |
8ac3646f | 7839 | |
112e8700 SM |
7840 | if (uiout->is_mi_like_p ()) |
7841 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
7842 | } |
7843 | ||
7844 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7845 | catchpoints. */ | |
7846 | ||
7847 | static void | |
7848 | print_mention_catch_vfork (struct breakpoint *b) | |
7849 | { | |
7850 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7851 | } | |
7852 | ||
6149aea9 PA |
7853 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7854 | catchpoints. */ | |
7855 | ||
7856 | static void | |
7857 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7858 | { | |
7859 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7860 | print_recreate_thread (b, fp); |
6149aea9 PA |
7861 | } |
7862 | ||
ce78b96d JB |
7863 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7864 | ||
2060206e | 7865 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7866 | |
edcc5120 | 7867 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 7868 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
7869 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
7870 | ||
c1fc2657 | 7871 | struct solib_catchpoint : public breakpoint |
edcc5120 | 7872 | { |
c1fc2657 | 7873 | ~solib_catchpoint () override; |
edcc5120 TT |
7874 | |
7875 | /* True for "catch load", false for "catch unload". */ | |
7876 | unsigned char is_load; | |
7877 | ||
7878 | /* Regular expression to match, if any. COMPILED is only valid when | |
7879 | REGEX is non-NULL. */ | |
7880 | char *regex; | |
2d7cc5c7 | 7881 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
7882 | }; |
7883 | ||
c1fc2657 | 7884 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 7885 | { |
c1fc2657 | 7886 | xfree (this->regex); |
edcc5120 TT |
7887 | } |
7888 | ||
7889 | static int | |
7890 | insert_catch_solib (struct bp_location *ignore) | |
7891 | { | |
7892 | return 0; | |
7893 | } | |
7894 | ||
7895 | static int | |
73971819 | 7896 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
7897 | { |
7898 | return 0; | |
7899 | } | |
7900 | ||
7901 | static int | |
7902 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
bd522513 | 7903 | const address_space *aspace, |
edcc5120 TT |
7904 | CORE_ADDR bp_addr, |
7905 | const struct target_waitstatus *ws) | |
7906 | { | |
7907 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7908 | struct breakpoint *other; | |
7909 | ||
7910 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7911 | return 1; | |
7912 | ||
7913 | ALL_BREAKPOINTS (other) | |
7914 | { | |
7915 | struct bp_location *other_bl; | |
7916 | ||
7917 | if (other == bl->owner) | |
7918 | continue; | |
7919 | ||
7920 | if (other->type != bp_shlib_event) | |
7921 | continue; | |
7922 | ||
c1fc2657 | 7923 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
7924 | continue; |
7925 | ||
7926 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7927 | { | |
7928 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7929 | return 1; | |
7930 | } | |
7931 | } | |
7932 | ||
7933 | return 0; | |
7934 | } | |
7935 | ||
7936 | static void | |
7937 | check_status_catch_solib (struct bpstats *bs) | |
7938 | { | |
7939 | struct solib_catchpoint *self | |
7940 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
edcc5120 TT |
7941 | |
7942 | if (self->is_load) | |
7943 | { | |
52941706 | 7944 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 TT |
7945 | { |
7946 | if (!self->regex | |
2d7cc5c7 | 7947 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
7948 | return; |
7949 | } | |
7950 | } | |
7951 | else | |
7952 | { | |
6fb16ce6 | 7953 | for (const std::string &iter : current_program_space->deleted_solibs) |
edcc5120 TT |
7954 | { |
7955 | if (!self->regex | |
6fb16ce6 | 7956 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
edcc5120 TT |
7957 | return; |
7958 | } | |
7959 | } | |
7960 | ||
7961 | bs->stop = 0; | |
7962 | bs->print_it = print_it_noop; | |
7963 | } | |
7964 | ||
7965 | static enum print_stop_action | |
7966 | print_it_catch_solib (bpstat bs) | |
7967 | { | |
7968 | struct breakpoint *b = bs->breakpoint_at; | |
7969 | struct ui_out *uiout = current_uiout; | |
7970 | ||
7971 | annotate_catchpoint (b->number); | |
f303dbd6 | 7972 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 7973 | if (b->disposition == disp_del) |
112e8700 | 7974 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 7975 | else |
112e8700 | 7976 | uiout->text ("Catchpoint "); |
381befee | 7977 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
7978 | uiout->text ("\n"); |
7979 | if (uiout->is_mi_like_p ()) | |
7980 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
7981 | print_solib_event (1); |
7982 | return PRINT_SRC_AND_LOC; | |
7983 | } | |
7984 | ||
7985 | static void | |
7986 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7987 | { | |
7988 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7989 | struct value_print_options opts; | |
7990 | struct ui_out *uiout = current_uiout; | |
edcc5120 TT |
7991 | |
7992 | get_user_print_options (&opts); | |
7993 | /* Field 4, the address, is omitted (which makes the columns not | |
7994 | line up too nicely with the headers, but the effect is relatively | |
7995 | readable). */ | |
7996 | if (opts.addressprint) | |
7997 | { | |
7998 | annotate_field (4); | |
112e8700 | 7999 | uiout->field_skip ("addr"); |
edcc5120 TT |
8000 | } |
8001 | ||
528e1572 | 8002 | std::string msg; |
edcc5120 TT |
8003 | annotate_field (5); |
8004 | if (self->is_load) | |
8005 | { | |
8006 | if (self->regex) | |
528e1572 | 8007 | msg = string_printf (_("load of library matching %s"), self->regex); |
edcc5120 | 8008 | else |
528e1572 | 8009 | msg = _("load of library"); |
edcc5120 TT |
8010 | } |
8011 | else | |
8012 | { | |
8013 | if (self->regex) | |
528e1572 | 8014 | msg = string_printf (_("unload of library matching %s"), self->regex); |
edcc5120 | 8015 | else |
528e1572 | 8016 | msg = _("unload of library"); |
edcc5120 | 8017 | } |
112e8700 | 8018 | uiout->field_string ("what", msg); |
8ac3646f | 8019 | |
112e8700 SM |
8020 | if (uiout->is_mi_like_p ()) |
8021 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8022 | } |
8023 | ||
8024 | static void | |
8025 | print_mention_catch_solib (struct breakpoint *b) | |
8026 | { | |
8027 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8028 | ||
8029 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8030 | self->is_load ? "load" : "unload"); | |
8031 | } | |
8032 | ||
8033 | static void | |
8034 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8035 | { | |
8036 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8037 | ||
8038 | fprintf_unfiltered (fp, "%s %s", | |
8039 | b->disposition == disp_del ? "tcatch" : "catch", | |
8040 | self->is_load ? "load" : "unload"); | |
8041 | if (self->regex) | |
8042 | fprintf_unfiltered (fp, " %s", self->regex); | |
8043 | fprintf_unfiltered (fp, "\n"); | |
8044 | } | |
8045 | ||
8046 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8047 | ||
91985142 MG |
8048 | /* Shared helper function (MI and CLI) for creating and installing |
8049 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8050 | the events to be caught are load events, otherwise they are | |
8051 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8052 | temporary one. If ENABLED is non-zero the catchpoint is | |
8053 | created in an enabled state. */ | |
edcc5120 | 8054 | |
91985142 | 8055 | void |
a121b7c1 | 8056 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8057 | { |
edcc5120 | 8058 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8059 | |
edcc5120 TT |
8060 | if (!arg) |
8061 | arg = ""; | |
f1735a53 | 8062 | arg = skip_spaces (arg); |
edcc5120 | 8063 | |
36bd8eaa | 8064 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8065 | |
8066 | if (*arg != '\0') | |
8067 | { | |
2d7cc5c7 PA |
8068 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8069 | _("Invalid regexp"))); | |
edcc5120 TT |
8070 | c->regex = xstrdup (arg); |
8071 | } | |
8072 | ||
8073 | c->is_load = is_load; | |
36bd8eaa | 8074 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8075 | &catch_solib_breakpoint_ops); |
8076 | ||
c1fc2657 | 8077 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8078 | |
b270e6f9 | 8079 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8080 | } |
8081 | ||
91985142 MG |
8082 | /* A helper function that does all the work for "catch load" and |
8083 | "catch unload". */ | |
8084 | ||
8085 | static void | |
eb4c3f4a | 8086 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
91985142 MG |
8087 | struct cmd_list_element *command) |
8088 | { | |
8089 | int tempflag; | |
8090 | const int enabled = 1; | |
8091 | ||
8092 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8093 | ||
8094 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8095 | } | |
8096 | ||
edcc5120 | 8097 | static void |
eb4c3f4a | 8098 | catch_load_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8099 | struct cmd_list_element *command) |
8100 | { | |
8101 | catch_load_or_unload (arg, from_tty, 1, command); | |
8102 | } | |
8103 | ||
8104 | static void | |
eb4c3f4a | 8105 | catch_unload_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8106 | struct cmd_list_element *command) |
8107 | { | |
8108 | catch_load_or_unload (arg, from_tty, 0, command); | |
8109 | } | |
8110 | ||
346774a9 PA |
8111 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8112 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8113 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8114 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8115 | |
ab04a2af | 8116 | void |
346774a9 PA |
8117 | init_catchpoint (struct breakpoint *b, |
8118 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8119 | const char *cond_string, |
c0a91b2b | 8120 | const struct breakpoint_ops *ops) |
c906108c | 8121 | { |
51abb421 | 8122 | symtab_and_line sal; |
6c95b8df | 8123 | sal.pspace = current_program_space; |
c5aa993b | 8124 | |
28010a5d | 8125 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8126 | |
1b36a34b | 8127 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8128 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8129 | } |
8130 | ||
28010a5d | 8131 | void |
b270e6f9 | 8132 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8133 | { |
b270e6f9 | 8134 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8135 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8136 | if (is_tracepoint (b)) |
8137 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8138 | if (!internal) |
8139 | mention (b); | |
76727919 | 8140 | gdb::observers::breakpoint_created.notify (b); |
3ea46bff YQ |
8141 | |
8142 | if (update_gll) | |
44702360 | 8143 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8144 | } |
8145 | ||
9b70b993 | 8146 | static void |
a6d9a66e | 8147 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8148 | int tempflag, const char *cond_string, |
c0a91b2b | 8149 | const struct breakpoint_ops *ops) |
c906108c | 8150 | { |
b270e6f9 | 8151 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8152 | |
b270e6f9 | 8153 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8154 | |
8155 | c->forked_inferior_pid = null_ptid; | |
8156 | ||
b270e6f9 | 8157 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8158 | } |
8159 | ||
fe798b75 JB |
8160 | /* Exec catchpoints. */ |
8161 | ||
b4d90040 | 8162 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8163 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8164 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8165 | ||
c1fc2657 | 8166 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8167 | { |
c1fc2657 | 8168 | ~exec_catchpoint () override; |
b4d90040 PA |
8169 | |
8170 | /* Filename of a program whose exec triggered this catchpoint. | |
8171 | This field is only valid immediately after this catchpoint has | |
8172 | triggered. */ | |
8173 | char *exec_pathname; | |
8174 | }; | |
8175 | ||
c1fc2657 | 8176 | /* Exec catchpoint destructor. */ |
b4d90040 | 8177 | |
c1fc2657 | 8178 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8179 | { |
c1fc2657 | 8180 | xfree (this->exec_pathname); |
b4d90040 PA |
8181 | } |
8182 | ||
77b06cd7 TJB |
8183 | static int |
8184 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8185 | { |
e99b03dc | 8186 | return target_insert_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8187 | } |
c906108c | 8188 | |
fe798b75 | 8189 | static int |
73971819 | 8190 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8191 | { |
e99b03dc | 8192 | return target_remove_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8193 | } |
c906108c | 8194 | |
fe798b75 | 8195 | static int |
f1310107 | 8196 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
bd522513 | 8197 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 8198 | const struct target_waitstatus *ws) |
fe798b75 | 8199 | { |
b4d90040 PA |
8200 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8201 | ||
f90263c1 TT |
8202 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8203 | return 0; | |
8204 | ||
8205 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8206 | return 1; | |
fe798b75 | 8207 | } |
c906108c | 8208 | |
fe798b75 | 8209 | static enum print_stop_action |
348d480f | 8210 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8211 | { |
36dfb11c | 8212 | struct ui_out *uiout = current_uiout; |
348d480f | 8213 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8214 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8215 | ||
fe798b75 | 8216 | annotate_catchpoint (b->number); |
f303dbd6 | 8217 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8218 | if (b->disposition == disp_del) |
112e8700 | 8219 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8220 | else |
112e8700 SM |
8221 | uiout->text ("Catchpoint "); |
8222 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8223 | { |
112e8700 SM |
8224 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8225 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8226 | } |
381befee | 8227 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
8228 | uiout->text (" (exec'd "); |
8229 | uiout->field_string ("new-exec", c->exec_pathname); | |
8230 | uiout->text ("), "); | |
36dfb11c | 8231 | |
fe798b75 | 8232 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8233 | } |
8234 | ||
fe798b75 | 8235 | static void |
a6d9a66e | 8236 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8237 | { |
b4d90040 | 8238 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8239 | struct value_print_options opts; |
79a45e25 | 8240 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8241 | |
8242 | get_user_print_options (&opts); | |
8243 | ||
8244 | /* Field 4, the address, is omitted (which makes the columns | |
8245 | not line up too nicely with the headers, but the effect | |
8246 | is relatively readable). */ | |
8247 | if (opts.addressprint) | |
112e8700 | 8248 | uiout->field_skip ("addr"); |
fe798b75 | 8249 | annotate_field (5); |
112e8700 | 8250 | uiout->text ("exec"); |
b4d90040 | 8251 | if (c->exec_pathname != NULL) |
fe798b75 | 8252 | { |
112e8700 SM |
8253 | uiout->text (", program \""); |
8254 | uiout->field_string ("what", c->exec_pathname); | |
8255 | uiout->text ("\" "); | |
fe798b75 | 8256 | } |
8ac3646f | 8257 | |
112e8700 SM |
8258 | if (uiout->is_mi_like_p ()) |
8259 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8260 | } |
8261 | ||
8262 | static void | |
8263 | print_mention_catch_exec (struct breakpoint *b) | |
8264 | { | |
8265 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8266 | } | |
8267 | ||
6149aea9 PA |
8268 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8269 | catchpoints. */ | |
8270 | ||
8271 | static void | |
8272 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8273 | { | |
8274 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8275 | print_recreate_thread (b, fp); |
6149aea9 PA |
8276 | } |
8277 | ||
2060206e | 8278 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8279 | |
c906108c | 8280 | static int |
fba45db2 | 8281 | hw_breakpoint_used_count (void) |
c906108c | 8282 | { |
c906108c | 8283 | int i = 0; |
f1310107 TJB |
8284 | struct breakpoint *b; |
8285 | struct bp_location *bl; | |
c906108c SS |
8286 | |
8287 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8288 | { |
d6b74ac4 | 8289 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8290 | for (bl = b->loc; bl; bl = bl->next) |
8291 | { | |
8292 | /* Special types of hardware breakpoints may use more than | |
8293 | one register. */ | |
348d480f | 8294 | i += b->ops->resources_needed (bl); |
f1310107 | 8295 | } |
c5aa993b | 8296 | } |
c906108c SS |
8297 | |
8298 | return i; | |
8299 | } | |
8300 | ||
a1398e0c PA |
8301 | /* Returns the resources B would use if it were a hardware |
8302 | watchpoint. */ | |
8303 | ||
c906108c | 8304 | static int |
a1398e0c | 8305 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8306 | { |
c906108c | 8307 | int i = 0; |
e09342b5 | 8308 | struct bp_location *bl; |
c906108c | 8309 | |
a1398e0c PA |
8310 | if (!breakpoint_enabled (b)) |
8311 | return 0; | |
8312 | ||
8313 | for (bl = b->loc; bl; bl = bl->next) | |
8314 | { | |
8315 | /* Special types of hardware watchpoints may use more than | |
8316 | one register. */ | |
8317 | i += b->ops->resources_needed (bl); | |
8318 | } | |
8319 | ||
8320 | return i; | |
8321 | } | |
8322 | ||
8323 | /* Returns the sum the used resources of all hardware watchpoints of | |
8324 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8325 | the sum of the used resources of all hardware watchpoints of other | |
8326 | types _not_ TYPE. */ | |
8327 | ||
8328 | static int | |
8329 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8330 | enum bptype type, int *other_type_used) | |
8331 | { | |
8332 | int i = 0; | |
8333 | struct breakpoint *b; | |
8334 | ||
c906108c SS |
8335 | *other_type_used = 0; |
8336 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8337 | { |
a1398e0c PA |
8338 | if (b == except) |
8339 | continue; | |
e09342b5 TJB |
8340 | if (!breakpoint_enabled (b)) |
8341 | continue; | |
8342 | ||
a1398e0c PA |
8343 | if (b->type == type) |
8344 | i += hw_watchpoint_use_count (b); | |
8345 | else if (is_hardware_watchpoint (b)) | |
8346 | *other_type_used = 1; | |
e09342b5 TJB |
8347 | } |
8348 | ||
c906108c SS |
8349 | return i; |
8350 | } | |
8351 | ||
c906108c | 8352 | void |
fba45db2 | 8353 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8354 | { |
c5aa993b | 8355 | struct breakpoint *b; |
c906108c SS |
8356 | |
8357 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8358 | { |
cc60f2e3 | 8359 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8360 | { |
b5de0fa7 | 8361 | b->enable_state = bp_call_disabled; |
44702360 | 8362 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8363 | } |
8364 | } | |
c906108c SS |
8365 | } |
8366 | ||
8367 | void | |
fba45db2 | 8368 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8369 | { |
c5aa993b | 8370 | struct breakpoint *b; |
c906108c SS |
8371 | |
8372 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8373 | { |
cc60f2e3 | 8374 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8375 | { |
b5de0fa7 | 8376 | b->enable_state = bp_enabled; |
44702360 | 8377 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8378 | } |
8379 | } | |
c906108c SS |
8380 | } |
8381 | ||
8bea4e01 UW |
8382 | void |
8383 | disable_breakpoints_before_startup (void) | |
8384 | { | |
6c95b8df | 8385 | current_program_space->executing_startup = 1; |
44702360 | 8386 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8387 | } |
8388 | ||
8389 | void | |
8390 | enable_breakpoints_after_startup (void) | |
8391 | { | |
6c95b8df | 8392 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8393 | breakpoint_re_set (); |
8bea4e01 UW |
8394 | } |
8395 | ||
7c16b83e PA |
8396 | /* Create a new single-step breakpoint for thread THREAD, with no |
8397 | locations. */ | |
c906108c | 8398 | |
7c16b83e PA |
8399 | static struct breakpoint * |
8400 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8401 | { | |
b270e6f9 | 8402 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8403 | |
b270e6f9 | 8404 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8405 | &momentary_breakpoint_ops); |
8406 | ||
8407 | b->disposition = disp_donttouch; | |
8408 | b->frame_id = null_frame_id; | |
8409 | ||
8410 | b->thread = thread; | |
8411 | gdb_assert (b->thread != 0); | |
8412 | ||
b270e6f9 | 8413 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8414 | } |
8415 | ||
8416 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8417 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8418 | frame. */ | |
c906108c | 8419 | |
454dafbd | 8420 | breakpoint_up |
a6d9a66e UW |
8421 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8422 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8423 | { |
52f0bd74 | 8424 | struct breakpoint *b; |
edb3359d | 8425 | |
193facb3 JK |
8426 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8427 | tail-called one. */ | |
8428 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8429 | |
06edf0c0 | 8430 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8431 | b->enable_state = bp_enabled; |
8432 | b->disposition = disp_donttouch; | |
818dd999 | 8433 | b->frame_id = frame_id; |
c906108c | 8434 | |
00431a78 | 8435 | b->thread = inferior_thread ()->global_num; |
c906108c | 8436 | |
44702360 | 8437 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8438 | |
454dafbd | 8439 | return breakpoint_up (b); |
c906108c | 8440 | } |
611c83ae | 8441 | |
06edf0c0 | 8442 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8443 | The new breakpoint will have type TYPE, use OPS as its |
8444 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8445 | |
06edf0c0 PA |
8446 | static struct breakpoint * |
8447 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8448 | enum bptype type, | |
a1aa2221 LM |
8449 | const struct breakpoint_ops *ops, |
8450 | int loc_enabled) | |
e58b0e63 PA |
8451 | { |
8452 | struct breakpoint *copy; | |
8453 | ||
06edf0c0 | 8454 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8455 | copy->loc = allocate_bp_location (copy); |
0ba852ab | 8456 | set_breakpoint_location_function (copy->loc); |
e58b0e63 | 8457 | |
a6d9a66e | 8458 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8459 | copy->loc->requested_address = orig->loc->requested_address; |
8460 | copy->loc->address = orig->loc->address; | |
8461 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8462 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8463 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8464 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8465 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8466 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8467 | copy->frame_id = orig->frame_id; |
8468 | copy->thread = orig->thread; | |
6c95b8df | 8469 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8470 | |
8471 | copy->enable_state = bp_enabled; | |
8472 | copy->disposition = disp_donttouch; | |
8473 | copy->number = internal_breakpoint_number--; | |
8474 | ||
44702360 | 8475 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8476 | return copy; |
8477 | } | |
8478 | ||
06edf0c0 PA |
8479 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8480 | ORIG is NULL. */ | |
8481 | ||
8482 | struct breakpoint * | |
8483 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8484 | { | |
8485 | /* If there's nothing to clone, then return nothing. */ | |
8486 | if (orig == NULL) | |
8487 | return NULL; | |
8488 | ||
a1aa2221 | 8489 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8490 | } |
8491 | ||
454dafbd | 8492 | breakpoint_up |
a6d9a66e UW |
8493 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8494 | enum bptype type) | |
611c83ae PA |
8495 | { |
8496 | struct symtab_and_line sal; | |
8497 | ||
8498 | sal = find_pc_line (pc, 0); | |
8499 | sal.pc = pc; | |
8500 | sal.section = find_pc_overlay (pc); | |
8501 | sal.explicit_pc = 1; | |
8502 | ||
a6d9a66e | 8503 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8504 | } |
c906108c | 8505 | \f |
c5aa993b | 8506 | |
c906108c SS |
8507 | /* Tell the user we have just set a breakpoint B. */ |
8508 | ||
8509 | static void | |
fba45db2 | 8510 | mention (struct breakpoint *b) |
c906108c | 8511 | { |
348d480f | 8512 | b->ops->print_mention (b); |
2d33446d | 8513 | current_uiout->text ("\n"); |
c906108c | 8514 | } |
c906108c | 8515 | \f |
c5aa993b | 8516 | |
1a853c52 PA |
8517 | static int bp_loc_is_permanent (struct bp_location *loc); |
8518 | ||
0d381245 | 8519 | static struct bp_location * |
39d61571 | 8520 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8521 | const struct symtab_and_line *sal) |
8522 | { | |
8523 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8524 | CORE_ADDR adjusted_address; |
8525 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8526 | ||
8527 | if (loc_gdbarch == NULL) | |
8528 | loc_gdbarch = b->gdbarch; | |
8529 | ||
8530 | /* Adjust the breakpoint's address prior to allocating a location. | |
8531 | Once we call allocate_bp_location(), that mostly uninitialized | |
8532 | location will be placed on the location chain. Adjustment of the | |
8533 | breakpoint may cause target_read_memory() to be called and we do | |
8534 | not want its scan of the location chain to find a breakpoint and | |
8535 | location that's only been partially initialized. */ | |
8536 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8537 | sal->pc, b->type); | |
0d381245 | 8538 | |
d30113d4 | 8539 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8540 | loc = allocate_bp_location (b); |
d30113d4 JK |
8541 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8542 | tmp = &((*tmp)->next)) | |
0d381245 | 8543 | ; |
d30113d4 | 8544 | loc->next = *tmp; |
0d381245 | 8545 | *tmp = loc; |
3742cc8b | 8546 | |
0d381245 | 8547 | loc->requested_address = sal->pc; |
3742cc8b | 8548 | loc->address = adjusted_address; |
6c95b8df | 8549 | loc->pspace = sal->pspace; |
935676c9 | 8550 | loc->probe.prob = sal->prob; |
729662a5 | 8551 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8552 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8553 | loc->section = sal->section; |
3742cc8b | 8554 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8555 | loc->line_number = sal->line; |
2f202fde | 8556 | loc->symtab = sal->symtab; |
4a27f119 | 8557 | loc->symbol = sal->symbol; |
3467ec66 PA |
8558 | loc->msymbol = sal->msymbol; |
8559 | loc->objfile = sal->objfile; | |
f8eba3c6 | 8560 | |
0ba852ab | 8561 | set_breakpoint_location_function (loc); |
1a853c52 | 8562 | |
6ae88661 LM |
8563 | /* While by definition, permanent breakpoints are already present in the |
8564 | code, we don't mark the location as inserted. Normally one would expect | |
8565 | that GDB could rely on that breakpoint instruction to stop the program, | |
8566 | thus removing the need to insert its own breakpoint, except that executing | |
8567 | the breakpoint instruction can kill the target instead of reporting a | |
8568 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8569 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8570 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8571 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8572 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8573 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8574 | it manually increments the PC, thus avoiding executing the breakpoint | |
8575 | instruction.) */ | |
1a853c52 | 8576 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8577 | loc->permanent = 1; |
1a853c52 | 8578 | |
0d381245 VP |
8579 | return loc; |
8580 | } | |
514f746b AR |
8581 | \f |
8582 | ||
1cf4d951 | 8583 | /* See breakpoint.h. */ |
514f746b | 8584 | |
1cf4d951 PA |
8585 | int |
8586 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8587 | { |
8588 | int len; | |
8589 | CORE_ADDR addr; | |
1afeeb75 | 8590 | const gdb_byte *bpoint; |
514f746b AR |
8591 | gdb_byte *target_mem; |
8592 | ||
1cf4d951 PA |
8593 | addr = address; |
8594 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8595 | ||
8596 | /* Software breakpoints unsupported? */ | |
8597 | if (bpoint == NULL) | |
8598 | return 0; | |
8599 | ||
224c3ddb | 8600 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
8601 | |
8602 | /* Enable the automatic memory restoration from breakpoints while | |
8603 | we read the memory. Otherwise we could say about our temporary | |
8604 | breakpoints they are permanent. */ | |
cb85b21b TT |
8605 | scoped_restore restore_memory |
8606 | = make_scoped_restore_show_memory_breakpoints (0); | |
1cf4d951 PA |
8607 | |
8608 | if (target_read_memory (address, target_mem, len) == 0 | |
8609 | && memcmp (target_mem, bpoint, len) == 0) | |
cb85b21b | 8610 | return 1; |
1cf4d951 | 8611 | |
cb85b21b | 8612 | return 0; |
1cf4d951 PA |
8613 | } |
8614 | ||
8615 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8616 | return 0 otherwise. */ | |
8617 | ||
8618 | static int | |
8619 | bp_loc_is_permanent (struct bp_location *loc) | |
8620 | { | |
514f746b AR |
8621 | gdb_assert (loc != NULL); |
8622 | ||
cb1e4e32 PA |
8623 | /* If we have a non-breakpoint-backed catchpoint or a software |
8624 | watchpoint, just return 0. We should not attempt to read from | |
8625 | the addresses the locations of these breakpoint types point to. | |
8626 | program_breakpoint_here_p, below, will attempt to read | |
244558af | 8627 | memory. */ |
cb1e4e32 | 8628 | if (!bl_address_is_meaningful (loc)) |
244558af LM |
8629 | return 0; |
8630 | ||
5ed8105e | 8631 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8632 | switch_to_program_space_and_thread (loc->pspace); |
5ed8105e | 8633 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8634 | } |
8635 | ||
e7e0cddf SS |
8636 | /* Build a command list for the dprintf corresponding to the current |
8637 | settings of the dprintf style options. */ | |
8638 | ||
8639 | static void | |
8640 | update_dprintf_command_list (struct breakpoint *b) | |
8641 | { | |
8642 | char *dprintf_args = b->extra_string; | |
8643 | char *printf_line = NULL; | |
8644 | ||
8645 | if (!dprintf_args) | |
8646 | return; | |
8647 | ||
8648 | dprintf_args = skip_spaces (dprintf_args); | |
8649 | ||
8650 | /* Allow a comma, as it may have terminated a location, but don't | |
8651 | insist on it. */ | |
8652 | if (*dprintf_args == ',') | |
8653 | ++dprintf_args; | |
8654 | dprintf_args = skip_spaces (dprintf_args); | |
8655 | ||
8656 | if (*dprintf_args != '"') | |
8657 | error (_("Bad format string, missing '\"'.")); | |
8658 | ||
d3ce09f5 | 8659 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8660 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8661 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8662 | { |
8663 | if (!dprintf_function) | |
8664 | error (_("No function supplied for dprintf call")); | |
8665 | ||
8666 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8667 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8668 | dprintf_function, | |
8669 | dprintf_channel, | |
8670 | dprintf_args); | |
8671 | else | |
8672 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8673 | dprintf_function, | |
8674 | dprintf_args); | |
8675 | } | |
d3ce09f5 SS |
8676 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8677 | { | |
8678 | if (target_can_run_breakpoint_commands ()) | |
8679 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8680 | else | |
8681 | { | |
8682 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8683 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8684 | } | |
8685 | } | |
e7e0cddf SS |
8686 | else |
8687 | internal_error (__FILE__, __LINE__, | |
8688 | _("Invalid dprintf style.")); | |
8689 | ||
f28045c2 | 8690 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8691 | |
12973681 TT |
8692 | /* Manufacture a printf sequence. */ |
8693 | struct command_line *printf_cmd_line | |
8694 | = new struct command_line (simple_control, printf_line); | |
8695 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, | |
8696 | command_lines_deleter ())); | |
e7e0cddf SS |
8697 | } |
8698 | ||
8699 | /* Update all dprintf commands, making their command lists reflect | |
8700 | current style settings. */ | |
8701 | ||
8702 | static void | |
eb4c3f4a | 8703 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8704 | struct cmd_list_element *c) |
8705 | { | |
8706 | struct breakpoint *b; | |
8707 | ||
8708 | ALL_BREAKPOINTS (b) | |
8709 | { | |
8710 | if (b->type == bp_dprintf) | |
8711 | update_dprintf_command_list (b); | |
8712 | } | |
8713 | } | |
c3f6f71d | 8714 | |
f00aae0f KS |
8715 | /* Create a breakpoint with SAL as location. Use LOCATION |
8716 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8717 | as condition expression. If LOCATION is NULL then create an |
8718 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8719 | |
8720 | static void | |
d9b3f62e | 8721 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8722 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8723 | event_location_up &&location, |
e1e01040 PA |
8724 | gdb::unique_xmalloc_ptr<char> filter, |
8725 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8726 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8727 | enum bptype type, enum bpdisp disposition, |
8728 | int thread, int task, int ignore_count, | |
c0a91b2b | 8729 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8730 | int enabled, int internal, unsigned flags, |
8731 | int display_canonical) | |
018d34a4 | 8732 | { |
0d381245 | 8733 | int i; |
018d34a4 VP |
8734 | |
8735 | if (type == bp_hardware_breakpoint) | |
8736 | { | |
fbbd034e AS |
8737 | int target_resources_ok; |
8738 | ||
8739 | i = hw_breakpoint_used_count (); | |
8740 | target_resources_ok = | |
8741 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8742 | i + 1, 0); |
8743 | if (target_resources_ok == 0) | |
8744 | error (_("No hardware breakpoint support in the target.")); | |
8745 | else if (target_resources_ok < 0) | |
8746 | error (_("Hardware breakpoints used exceeds limit.")); | |
8747 | } | |
8748 | ||
6c5b2ebe | 8749 | gdb_assert (!sals.empty ()); |
6c95b8df | 8750 | |
6c5b2ebe | 8751 | for (const auto &sal : sals) |
0d381245 | 8752 | { |
0d381245 VP |
8753 | struct bp_location *loc; |
8754 | ||
8755 | if (from_tty) | |
5af949e3 UW |
8756 | { |
8757 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8758 | if (!loc_gdbarch) | |
8759 | loc_gdbarch = gdbarch; | |
8760 | ||
8761 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8762 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8763 | } |
0d381245 | 8764 | |
6c5b2ebe | 8765 | if (&sal == &sals[0]) |
0d381245 | 8766 | { |
d9b3f62e | 8767 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8768 | b->thread = thread; |
4a306c9a | 8769 | b->task = task; |
855a6e68 | 8770 | |
e1e01040 PA |
8771 | b->cond_string = cond_string.release (); |
8772 | b->extra_string = extra_string.release (); | |
0d381245 | 8773 | b->ignore_count = ignore_count; |
41447f92 | 8774 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8775 | b->disposition = disposition; |
6c95b8df | 8776 | |
44f238bb PA |
8777 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8778 | b->loc->inserted = 1; | |
8779 | ||
0fb4aa4b PA |
8780 | if (type == bp_static_tracepoint) |
8781 | { | |
d9b3f62e | 8782 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8783 | struct static_tracepoint_marker marker; |
8784 | ||
983af33b | 8785 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8786 | { |
8787 | /* We already know the marker exists, otherwise, we | |
8788 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8789 | const char *p |
8790 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8791 | const char *endp; |
0fb4aa4b | 8792 | |
f1735a53 | 8793 | p = skip_spaces (p); |
0fb4aa4b | 8794 | |
f1735a53 | 8795 | endp = skip_to_space (p); |
0fb4aa4b | 8796 | |
5d9310c4 | 8797 | t->static_trace_marker_id.assign (p, endp - p); |
0fb4aa4b | 8798 | |
3e43a32a MS |
8799 | printf_filtered (_("Probed static tracepoint " |
8800 | "marker \"%s\"\n"), | |
5d9310c4 | 8801 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8802 | } |
8803 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8804 | { | |
5d9310c4 | 8805 | t->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b | 8806 | |
3e43a32a MS |
8807 | printf_filtered (_("Probed static tracepoint " |
8808 | "marker \"%s\"\n"), | |
5d9310c4 | 8809 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8810 | } |
8811 | else | |
3e43a32a MS |
8812 | warning (_("Couldn't determine the static " |
8813 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8814 | } |
8815 | ||
0d381245 VP |
8816 | loc = b->loc; |
8817 | } | |
8818 | else | |
018d34a4 | 8819 | { |
39d61571 | 8820 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8821 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8822 | loc->inserted = 1; | |
0d381245 VP |
8823 | } |
8824 | ||
8825 | if (b->cond_string) | |
8826 | { | |
bbc13ae3 KS |
8827 | const char *arg = b->cond_string; |
8828 | ||
1bb9788d TT |
8829 | loc->cond = parse_exp_1 (&arg, loc->address, |
8830 | block_for_pc (loc->address), 0); | |
0d381245 | 8831 | if (*arg) |
588ae58c | 8832 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 8833 | } |
e7e0cddf SS |
8834 | |
8835 | /* Dynamic printf requires and uses additional arguments on the | |
8836 | command line, otherwise it's an error. */ | |
8837 | if (type == bp_dprintf) | |
8838 | { | |
8839 | if (b->extra_string) | |
8840 | update_dprintf_command_list (b); | |
8841 | else | |
8842 | error (_("Format string required")); | |
8843 | } | |
8844 | else if (b->extra_string) | |
588ae58c | 8845 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 8846 | } |
018d34a4 | 8847 | |
56435ebe | 8848 | b->display_canonical = display_canonical; |
f00aae0f | 8849 | if (location != NULL) |
d28cd78a | 8850 | b->location = std::move (location); |
018d34a4 | 8851 | else |
d28cd78a | 8852 | b->location = new_address_location (b->loc->address, NULL, 0); |
c0e8dcd8 | 8853 | b->filter = std::move (filter); |
d9b3f62e | 8854 | } |
018d34a4 | 8855 | |
d9b3f62e PA |
8856 | static void |
8857 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 8858 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8859 | event_location_up &&location, |
e1e01040 PA |
8860 | gdb::unique_xmalloc_ptr<char> filter, |
8861 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8862 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8863 | enum bptype type, enum bpdisp disposition, |
8864 | int thread, int task, int ignore_count, | |
c0a91b2b | 8865 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8866 | int enabled, int internal, unsigned flags, |
8867 | int display_canonical) | |
d9b3f62e | 8868 | { |
a5e364af | 8869 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 8870 | |
a5e364af | 8871 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 8872 | sals, std::move (location), |
e1e01040 PA |
8873 | std::move (filter), |
8874 | std::move (cond_string), | |
8875 | std::move (extra_string), | |
d9b3f62e PA |
8876 | type, disposition, |
8877 | thread, task, ignore_count, | |
8878 | ops, from_tty, | |
44f238bb PA |
8879 | enabled, internal, flags, |
8880 | display_canonical); | |
d9b3f62e | 8881 | |
b270e6f9 | 8882 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
8883 | } |
8884 | ||
8885 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8886 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8887 | value. COND_STRING, if not NULL, specified the condition to be | |
8888 | used for all breakpoints. Essentially the only case where | |
8889 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8890 | function. In that case, it's still not possible to specify | |
8891 | separate conditions for different overloaded functions, so | |
8892 | we take just a single condition string. | |
8893 | ||
c3f6f71d | 8894 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8895 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8896 | array contents). If the function fails (error() is called), the |
8897 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8898 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8899 | |
8900 | static void | |
8cdf0e15 | 8901 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8902 | struct linespec_result *canonical, |
e1e01040 PA |
8903 | gdb::unique_xmalloc_ptr<char> cond_string, |
8904 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
8905 | enum bptype type, enum bpdisp disposition, |
8906 | int thread, int task, int ignore_count, | |
c0a91b2b | 8907 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 8908 | int enabled, int internal, unsigned flags) |
c906108c | 8909 | { |
f8eba3c6 | 8910 | if (canonical->pre_expanded) |
6c5b2ebe | 8911 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 8912 | |
6c5b2ebe | 8913 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 8914 | { |
f00aae0f | 8915 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 8916 | 'break', without arguments. */ |
ffc2605c | 8917 | event_location_up location |
f00aae0f | 8918 | = (canonical->location != NULL |
8e9e35b1 | 8919 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 8920 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 8921 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 8922 | |
6c5b2ebe | 8923 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 8924 | std::move (location), |
e1e01040 PA |
8925 | std::move (filter_string), |
8926 | std::move (cond_string), | |
8927 | std::move (extra_string), | |
e7e0cddf | 8928 | type, disposition, |
84f4c1fe | 8929 | thread, task, ignore_count, ops, |
44f238bb | 8930 | from_tty, enabled, internal, flags, |
56435ebe | 8931 | canonical->special_display); |
c3f6f71d | 8932 | } |
c3f6f71d | 8933 | } |
c906108c | 8934 | |
f00aae0f | 8935 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 8936 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
8937 | addresses found. LOCATION points to the end of the SAL (for |
8938 | linespec locations). | |
9998af43 TJB |
8939 | |
8940 | The array and the line spec strings are allocated on the heap, it is | |
8941 | the caller's responsibility to free them. */ | |
c906108c | 8942 | |
b9362cc7 | 8943 | static void |
f00aae0f | 8944 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 8945 | struct linespec_result *canonical) |
c3f6f71d | 8946 | { |
f00aae0f KS |
8947 | struct symtab_and_line cursal; |
8948 | ||
8949 | if (event_location_type (location) == LINESPEC_LOCATION) | |
8950 | { | |
a20714ff | 8951 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 8952 | |
a20714ff | 8953 | if (spec == NULL) |
f00aae0f KS |
8954 | { |
8955 | /* The last displayed codepoint, if it's valid, is our default | |
8956 | breakpoint address. */ | |
8957 | if (last_displayed_sal_is_valid ()) | |
8958 | { | |
f00aae0f KS |
8959 | /* Set sal's pspace, pc, symtab, and line to the values |
8960 | corresponding to the last call to print_frame_info. | |
8961 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
8962 | as the breakpoint line number is inappropriate otherwise. | |
8963 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
8964 | symtab_and_line sal = get_last_displayed_sal (); |
8965 | CORE_ADDR pc = sal.pc; | |
8966 | ||
f00aae0f KS |
8967 | sal = find_pc_line (pc, 0); |
8968 | ||
8969 | /* "break" without arguments is equivalent to "break *PC" | |
8970 | where PC is the last displayed codepoint's address. So | |
8971 | make sure to set sal.explicit_pc to prevent GDB from | |
8972 | trying to expand the list of sals to include all other | |
8973 | instances with the same symtab and line. */ | |
8974 | sal.pc = pc; | |
8975 | sal.explicit_pc = 1; | |
8976 | ||
6c5b2ebe PA |
8977 | struct linespec_sals lsal; |
8978 | lsal.sals = {sal}; | |
f00aae0f KS |
8979 | lsal.canonical = NULL; |
8980 | ||
6c5b2ebe | 8981 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
8982 | return; |
8983 | } | |
8984 | else | |
8985 | error (_("No default breakpoint address now.")); | |
c906108c | 8986 | } |
c906108c | 8987 | } |
f00aae0f KS |
8988 | |
8989 | /* Force almost all breakpoints to be in terms of the | |
8990 | current_source_symtab (which is decode_line_1's default). | |
8991 | This should produce the results we want almost all of the | |
8992 | time while leaving default_breakpoint_* alone. | |
8993 | ||
8994 | ObjC: However, don't match an Objective-C method name which | |
8995 | may have a '+' or '-' succeeded by a '['. */ | |
8996 | cursal = get_current_source_symtab_and_line (); | |
8997 | if (last_displayed_sal_is_valid ()) | |
c906108c | 8998 | { |
a20714ff | 8999 | const char *spec = NULL; |
cc80f267 | 9000 | |
f00aae0f | 9001 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 9002 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 9003 | |
f00aae0f | 9004 | if (!cursal.symtab |
a20714ff PA |
9005 | || (spec != NULL |
9006 | && strchr ("+-", spec[0]) != NULL | |
9007 | && spec[1] != '[')) | |
f00aae0f | 9008 | { |
c2f4122d | 9009 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9010 | get_last_displayed_symtab (), |
9011 | get_last_displayed_line (), | |
9012 | canonical, NULL, NULL); | |
9013 | return; | |
9014 | } | |
c906108c | 9015 | } |
f00aae0f | 9016 | |
c2f4122d | 9017 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9018 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9019 | } |
c906108c | 9020 | |
c906108c | 9021 | |
c3f6f71d | 9022 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9023 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9024 | |
b9362cc7 | 9025 | static void |
6c5b2ebe | 9026 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9027 | { |
6c5b2ebe PA |
9028 | for (auto &sal : sals) |
9029 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9030 | } |
9031 | ||
7a697b8d SS |
9032 | /* Fast tracepoints may have restrictions on valid locations. For |
9033 | instance, a fast tracepoint using a jump instead of a trap will | |
9034 | likely have to overwrite more bytes than a trap would, and so can | |
9035 | only be placed where the instruction is longer than the jump, or a | |
9036 | multi-instruction sequence does not have a jump into the middle of | |
9037 | it, etc. */ | |
9038 | ||
9039 | static void | |
9040 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9041 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9042 | { |
6c5b2ebe | 9043 | for (const auto &sal : sals) |
7a697b8d | 9044 | { |
f8eba3c6 TT |
9045 | struct gdbarch *sarch; |
9046 | ||
6c5b2ebe | 9047 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9048 | /* We fall back to GDBARCH if there is no architecture |
9049 | associated with SAL. */ | |
9050 | if (sarch == NULL) | |
9051 | sarch = gdbarch; | |
281d762b TT |
9052 | std::string msg; |
9053 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) | |
53c3572a | 9054 | error (_("May not have a fast tracepoint at %s%s"), |
281d762b | 9055 | paddress (sarch, sal.pc), msg.c_str ()); |
7a697b8d SS |
9056 | } |
9057 | } | |
9058 | ||
018d34a4 VP |
9059 | /* Given TOK, a string specification of condition and thread, as |
9060 | accepted by the 'break' command, extract the condition | |
9061 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9062 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9063 | If no condition is found, *COND_STRING is set to NULL. |
9064 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9065 | |
9066 | static void | |
bbc13ae3 | 9067 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9068 | char **cond_string, int *thread, int *task, |
9069 | char **rest) | |
018d34a4 VP |
9070 | { |
9071 | *cond_string = NULL; | |
9072 | *thread = -1; | |
ed1d1739 KS |
9073 | *task = 0; |
9074 | *rest = NULL; | |
9075 | ||
018d34a4 VP |
9076 | while (tok && *tok) |
9077 | { | |
bbc13ae3 | 9078 | const char *end_tok; |
018d34a4 | 9079 | int toklen; |
bbc13ae3 KS |
9080 | const char *cond_start = NULL; |
9081 | const char *cond_end = NULL; | |
cc59ec59 | 9082 | |
f1735a53 | 9083 | tok = skip_spaces (tok); |
e7e0cddf SS |
9084 | |
9085 | if ((*tok == '"' || *tok == ',') && rest) | |
9086 | { | |
9087 | *rest = savestring (tok, strlen (tok)); | |
9088 | return; | |
9089 | } | |
9090 | ||
f1735a53 | 9091 | end_tok = skip_to_space (tok); |
d634f2de | 9092 | |
018d34a4 | 9093 | toklen = end_tok - tok; |
d634f2de | 9094 | |
018d34a4 VP |
9095 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9096 | { | |
9097 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9098 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9099 | cond_end = tok; |
d634f2de | 9100 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9101 | } |
9102 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9103 | { | |
5d5658a1 PA |
9104 | const char *tmptok; |
9105 | struct thread_info *thr; | |
d634f2de | 9106 | |
018d34a4 | 9107 | tok = end_tok + 1; |
5d5658a1 | 9108 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9109 | if (tok == tmptok) |
9110 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9111 | *thread = thr->global_num; |
bbc13ae3 | 9112 | tok = tmptok; |
018d34a4 | 9113 | } |
4a306c9a JB |
9114 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9115 | { | |
9116 | char *tmptok; | |
9117 | ||
9118 | tok = end_tok + 1; | |
bbc13ae3 | 9119 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9120 | if (tok == tmptok) |
9121 | error (_("Junk after task keyword.")); | |
9122 | if (!valid_task_id (*task)) | |
b6199126 | 9123 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9124 | tok = tmptok; |
4a306c9a | 9125 | } |
e7e0cddf SS |
9126 | else if (rest) |
9127 | { | |
9128 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9129 | return; |
e7e0cddf | 9130 | } |
018d34a4 VP |
9131 | else |
9132 | error (_("Junk at end of arguments.")); | |
9133 | } | |
9134 | } | |
9135 | ||
0fb4aa4b PA |
9136 | /* Decode a static tracepoint marker spec. */ |
9137 | ||
6c5b2ebe | 9138 | static std::vector<symtab_and_line> |
f00aae0f | 9139 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b | 9140 | { |
f00aae0f KS |
9141 | const char *p = &(*arg_p)[3]; |
9142 | const char *endp; | |
0fb4aa4b | 9143 | |
f1735a53 | 9144 | p = skip_spaces (p); |
0fb4aa4b | 9145 | |
f1735a53 | 9146 | endp = skip_to_space (p); |
0fb4aa4b | 9147 | |
81b1e71c | 9148 | std::string marker_str (p, endp - p); |
0fb4aa4b | 9149 | |
5d9310c4 SM |
9150 | std::vector<static_tracepoint_marker> markers |
9151 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); | |
9152 | if (markers.empty ()) | |
81b1e71c TT |
9153 | error (_("No known static tracepoint marker named %s"), |
9154 | marker_str.c_str ()); | |
0fb4aa4b | 9155 | |
6c5b2ebe | 9156 | std::vector<symtab_and_line> sals; |
5d9310c4 | 9157 | sals.reserve (markers.size ()); |
0fb4aa4b | 9158 | |
5d9310c4 | 9159 | for (const static_tracepoint_marker &marker : markers) |
0fb4aa4b | 9160 | { |
5d9310c4 SM |
9161 | symtab_and_line sal = find_pc_line (marker.address, 0); |
9162 | sal.pc = marker.address; | |
6c5b2ebe | 9163 | sals.push_back (sal); |
5d9310c4 | 9164 | } |
0fb4aa4b | 9165 | |
0fb4aa4b PA |
9166 | *arg_p = endp; |
9167 | return sals; | |
9168 | } | |
9169 | ||
f00aae0f | 9170 | /* See breakpoint.h. */ |
0101ce28 | 9171 | |
8cdf0e15 VP |
9172 | int |
9173 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9174 | const struct event_location *location, |
9175 | const char *cond_string, | |
9176 | int thread, const char *extra_string, | |
f00aae0f | 9177 | int parse_extra, |
0fb4aa4b | 9178 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9179 | int ignore_count, |
9180 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9181 | const struct breakpoint_ops *ops, |
44f238bb PA |
9182 | int from_tty, int enabled, int internal, |
9183 | unsigned flags) | |
c3f6f71d | 9184 | { |
7efd8fc2 | 9185 | struct linespec_result canonical; |
0101ce28 | 9186 | int pending = 0; |
4a306c9a | 9187 | int task = 0; |
86b17b60 | 9188 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9189 | |
348d480f PA |
9190 | gdb_assert (ops != NULL); |
9191 | ||
f00aae0f KS |
9192 | /* If extra_string isn't useful, set it to NULL. */ |
9193 | if (extra_string != NULL && *extra_string == '\0') | |
9194 | extra_string = NULL; | |
9195 | ||
a70b8144 | 9196 | try |
b78a6381 | 9197 | { |
f00aae0f | 9198 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9199 | } |
230d2906 | 9200 | catch (const gdb_exception_error &e) |
0101ce28 | 9201 | { |
492d29ea PA |
9202 | /* If caller is interested in rc value from parse, set |
9203 | value. */ | |
9204 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9205 | { |
05ff989b AC |
9206 | /* If pending breakpoint support is turned off, throw |
9207 | error. */ | |
fa8d40ab JJ |
9208 | |
9209 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
eedc3f4f | 9210 | throw; |
723a2275 VP |
9211 | |
9212 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9213 | |
05ff989b AC |
9214 | /* If pending breakpoint support is auto query and the user |
9215 | selects no, then simply return the error code. */ | |
059fb39f | 9216 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9217 | && !nquery (_("Make %s pending on future shared library load? "), |
9218 | bptype_string (type_wanted))) | |
fd9b8c24 | 9219 | return 0; |
fa8d40ab | 9220 | |
05ff989b AC |
9221 | /* At this point, either the user was queried about setting |
9222 | a pending breakpoint and selected yes, or pending | |
9223 | breakpoint behavior is on and thus a pending breakpoint | |
9224 | is defaulted on behalf of the user. */ | |
f00aae0f | 9225 | pending = 1; |
0101ce28 | 9226 | } |
492d29ea | 9227 | else |
eedc3f4f | 9228 | throw; |
0101ce28 | 9229 | } |
492d29ea | 9230 | |
6c5b2ebe | 9231 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9232 | return 0; |
c3f6f71d | 9233 | |
c3f6f71d JM |
9234 | /* Resolve all line numbers to PC's and verify that the addresses |
9235 | are ok for the target. */ | |
0101ce28 | 9236 | if (!pending) |
f8eba3c6 | 9237 | { |
6c5b2ebe PA |
9238 | for (auto &lsal : canonical.lsals) |
9239 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9240 | } |
c3f6f71d | 9241 | |
7a697b8d | 9242 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9243 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9244 | { |
6c5b2ebe PA |
9245 | for (const auto &lsal : canonical.lsals) |
9246 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9247 | } |
7a697b8d | 9248 | |
c3f6f71d JM |
9249 | /* Verify that condition can be parsed, before setting any |
9250 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9251 | breakpoint. */ |
0101ce28 | 9252 | if (!pending) |
c3f6f71d | 9253 | { |
e1e01040 PA |
9254 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9255 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9256 | ||
f00aae0f | 9257 | if (parse_extra) |
72b2ff0e | 9258 | { |
0878d0fa | 9259 | char *rest; |
e1e01040 | 9260 | char *cond; |
52d361e1 | 9261 | |
6c5b2ebe | 9262 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9263 | |
0878d0fa YQ |
9264 | /* Here we only parse 'arg' to separate condition |
9265 | from thread number, so parsing in context of first | |
9266 | sal is OK. When setting the breakpoint we'll | |
9267 | re-parse it in context of each sal. */ | |
9268 | ||
6c5b2ebe | 9269 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9270 | &cond, &thread, &task, &rest); |
9271 | cond_string_copy.reset (cond); | |
9272 | extra_string_copy.reset (rest); | |
72b2ff0e | 9273 | } |
2f069f6f | 9274 | else |
72b2ff0e | 9275 | { |
f00aae0f KS |
9276 | if (type_wanted != bp_dprintf |
9277 | && extra_string != NULL && *extra_string != '\0') | |
9278 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9279 | |
9280 | /* Create a private copy of condition string. */ | |
9281 | if (cond_string) | |
e1e01040 | 9282 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9283 | /* Create a private copy of any extra string. */ |
9284 | if (extra_string) | |
e1e01040 | 9285 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9286 | } |
0fb4aa4b | 9287 | |
52d361e1 | 9288 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9289 | std::move (cond_string_copy), |
9290 | std::move (extra_string_copy), | |
9291 | type_wanted, | |
d9b3f62e PA |
9292 | tempflag ? disp_del : disp_donttouch, |
9293 | thread, task, ignore_count, ops, | |
44f238bb | 9294 | from_tty, enabled, internal, flags); |
c906108c | 9295 | } |
0101ce28 JJ |
9296 | else |
9297 | { | |
a5e364af | 9298 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9299 | |
a5e364af | 9300 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9301 | b->location = copy_event_location (location); |
bfccc43c | 9302 | |
f00aae0f KS |
9303 | if (parse_extra) |
9304 | b->cond_string = NULL; | |
e12c7713 MK |
9305 | else |
9306 | { | |
9307 | /* Create a private copy of condition string. */ | |
e1e01040 | 9308 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9309 | b->thread = thread; |
e12c7713 | 9310 | } |
f00aae0f KS |
9311 | |
9312 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9313 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9314 | b->ignore_count = ignore_count; |
0101ce28 | 9315 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9316 | b->condition_not_parsed = 1; |
41447f92 | 9317 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9318 | if ((type_wanted != bp_breakpoint |
9319 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9320 | b->pspace = current_program_space; |
8bea4e01 | 9321 | |
b270e6f9 | 9322 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9323 | } |
9324 | ||
6c5b2ebe | 9325 | if (canonical.lsals.size () > 1) |
95a42b64 | 9326 | { |
3e43a32a MS |
9327 | warning (_("Multiple breakpoints were set.\nUse the " |
9328 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9329 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9330 | } |
9331 | ||
44702360 | 9332 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9333 | |
9334 | return 1; | |
c3f6f71d | 9335 | } |
c906108c | 9336 | |
348d480f | 9337 | /* Set a breakpoint. |
72b2ff0e VP |
9338 | ARG is a string describing breakpoint address, |
9339 | condition, and thread. | |
9340 | FLAG specifies if a breakpoint is hardware on, | |
9341 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9342 | and BP_TEMPFLAG. */ | |
348d480f | 9343 | |
98deb0da | 9344 | static void |
f2fc3015 | 9345 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9346 | { |
72b2ff0e | 9347 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9348 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9349 | ? bp_hardware_breakpoint | |
9350 | : bp_breakpoint); | |
55aa24fb | 9351 | struct breakpoint_ops *ops; |
f00aae0f | 9352 | |
ffc2605c | 9353 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9354 | |
9355 | /* Matching breakpoints on probes. */ | |
5b56227b | 9356 | if (location != NULL |
ffc2605c | 9357 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9358 | ops = &bkpt_probe_breakpoint_ops; |
9359 | else | |
9360 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9361 | |
8cdf0e15 | 9362 | create_breakpoint (get_current_arch (), |
ffc2605c | 9363 | location.get (), |
f00aae0f | 9364 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9365 | tempflag, type_wanted, |
8cdf0e15 VP |
9366 | 0 /* Ignore count */, |
9367 | pending_break_support, | |
55aa24fb | 9368 | ops, |
8cdf0e15 | 9369 | from_tty, |
84f4c1fe | 9370 | 1 /* enabled */, |
44f238bb PA |
9371 | 0 /* internal */, |
9372 | 0); | |
c906108c SS |
9373 | } |
9374 | ||
c906108c SS |
9375 | /* Helper function for break_command_1 and disassemble_command. */ |
9376 | ||
9377 | void | |
fba45db2 | 9378 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9379 | { |
9380 | CORE_ADDR pc; | |
9381 | ||
9382 | if (sal->pc == 0 && sal->symtab != NULL) | |
9383 | { | |
9384 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9385 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9386 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9387 | sal->pc = pc; |
6a048695 | 9388 | |
4a64f543 MS |
9389 | /* If this SAL corresponds to a breakpoint inserted using a line |
9390 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9391 | if (sal->explicit_line) |
059acae7 | 9392 | skip_prologue_sal (sal); |
c906108c SS |
9393 | } |
9394 | ||
9395 | if (sal->section == 0 && sal->symtab != NULL) | |
9396 | { | |
346d1dfe | 9397 | const struct blockvector *bv; |
3977b71f | 9398 | const struct block *b; |
c5aa993b | 9399 | struct symbol *sym; |
c906108c | 9400 | |
43f3e411 DE |
9401 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9402 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9403 | if (bv != NULL) |
9404 | { | |
7f0df278 | 9405 | sym = block_linkage_function (b); |
c906108c SS |
9406 | if (sym != NULL) |
9407 | { | |
eb822aa6 DE |
9408 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9409 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9410 | sym); | |
c906108c SS |
9411 | } |
9412 | else | |
9413 | { | |
4a64f543 MS |
9414 | /* It really is worthwhile to have the section, so we'll |
9415 | just have to look harder. This case can be executed | |
9416 | if we have line numbers but no functions (as can | |
9417 | happen in assembly source). */ | |
c906108c | 9418 | |
5ed8105e | 9419 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9420 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9421 | |
5ed8105e | 9422 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9423 | if (msym.minsym) |
efd66ac6 | 9424 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9425 | } |
9426 | } | |
9427 | } | |
9428 | } | |
9429 | ||
9430 | void | |
0b39b52e | 9431 | break_command (const char *arg, int from_tty) |
c906108c | 9432 | { |
db107f19 | 9433 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9434 | } |
9435 | ||
c906108c | 9436 | void |
0b39b52e | 9437 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9438 | { |
db107f19 | 9439 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9440 | } |
9441 | ||
c906108c | 9442 | static void |
0b39b52e | 9443 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9444 | { |
db107f19 | 9445 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9446 | } |
9447 | ||
9448 | static void | |
0b39b52e | 9449 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9450 | { |
db107f19 | 9451 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9452 | } |
9453 | ||
9454 | static void | |
ee7ddd71 | 9455 | stop_command (const char *arg, int from_tty) |
c906108c | 9456 | { |
a3f17187 | 9457 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9458 | Usage: stop in <function | address>\n\ |
a3f17187 | 9459 | stop at <line>\n")); |
c906108c SS |
9460 | } |
9461 | ||
9462 | static void | |
4495129a | 9463 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9464 | { |
9465 | int badInput = 0; | |
9466 | ||
cafb3438 | 9467 | if (arg == NULL) |
c906108c SS |
9468 | badInput = 1; |
9469 | else if (*arg != '*') | |
9470 | { | |
4495129a | 9471 | const char *argptr = arg; |
c906108c SS |
9472 | int hasColon = 0; |
9473 | ||
4a64f543 | 9474 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9475 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9476 | function/method name. */ |
c906108c | 9477 | while (*argptr && !hasColon) |
c5aa993b JM |
9478 | { |
9479 | hasColon = (*argptr == ':'); | |
9480 | argptr++; | |
9481 | } | |
c906108c SS |
9482 | |
9483 | if (hasColon) | |
c5aa993b | 9484 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9485 | else |
c5aa993b | 9486 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9487 | } |
9488 | ||
9489 | if (badInput) | |
a3f17187 | 9490 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9491 | else |
db107f19 | 9492 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9493 | } |
9494 | ||
9495 | static void | |
4495129a | 9496 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9497 | { |
9498 | int badInput = 0; | |
9499 | ||
cafb3438 | 9500 | if (arg == NULL || *arg == '*') /* no line number */ |
c906108c SS |
9501 | badInput = 1; |
9502 | else | |
9503 | { | |
4495129a | 9504 | const char *argptr = arg; |
c906108c SS |
9505 | int hasColon = 0; |
9506 | ||
4a64f543 MS |
9507 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9508 | it is probably a line number. */ | |
c906108c | 9509 | while (*argptr && !hasColon) |
c5aa993b JM |
9510 | { |
9511 | hasColon = (*argptr == ':'); | |
9512 | argptr++; | |
9513 | } | |
c906108c SS |
9514 | |
9515 | if (hasColon) | |
c5aa993b | 9516 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9517 | else |
c5aa993b | 9518 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9519 | } |
9520 | ||
9521 | if (badInput) | |
65e65158 | 9522 | printf_filtered (_("Usage: stop at LINE\n")); |
c906108c | 9523 | else |
db107f19 | 9524 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9525 | } |
9526 | ||
e7e0cddf SS |
9527 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9528 | with a prewired command list consisting of a single output command, | |
9529 | built from extra arguments supplied on the dprintf command | |
9530 | line. */ | |
9531 | ||
da821c7b | 9532 | static void |
0b39b52e | 9533 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9534 | { |
ffc2605c | 9535 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9536 | |
9537 | /* If non-NULL, ARG should have been advanced past the location; | |
9538 | the next character must be ','. */ | |
9539 | if (arg != NULL) | |
9540 | { | |
9541 | if (arg[0] != ',' || arg[1] == '\0') | |
9542 | error (_("Format string required")); | |
9543 | else | |
9544 | { | |
9545 | /* Skip the comma. */ | |
9546 | ++arg; | |
9547 | } | |
9548 | } | |
9549 | ||
e7e0cddf | 9550 | create_breakpoint (get_current_arch (), |
ffc2605c | 9551 | location.get (), |
f00aae0f | 9552 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9553 | 0, bp_dprintf, |
9554 | 0 /* Ignore count */, | |
9555 | pending_break_support, | |
9556 | &dprintf_breakpoint_ops, | |
9557 | from_tty, | |
9558 | 1 /* enabled */, | |
9559 | 0 /* internal */, | |
9560 | 0); | |
9561 | } | |
9562 | ||
d3ce09f5 | 9563 | static void |
0b39b52e | 9564 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9565 | { |
9566 | error (_("May only run agent-printf on the target")); | |
9567 | } | |
9568 | ||
f1310107 TJB |
9569 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9570 | ranged breakpoints. */ | |
9571 | ||
9572 | static int | |
9573 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
bd522513 | 9574 | const address_space *aspace, |
09ac7c10 TT |
9575 | CORE_ADDR bp_addr, |
9576 | const struct target_waitstatus *ws) | |
f1310107 | 9577 | { |
09ac7c10 | 9578 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9579 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9580 | return 0; |
9581 | ||
f1310107 TJB |
9582 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9583 | bl->length, aspace, bp_addr); | |
9584 | } | |
9585 | ||
9586 | /* Implement the "resources_needed" breakpoint_ops method for | |
9587 | ranged breakpoints. */ | |
9588 | ||
9589 | static int | |
9590 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9591 | { | |
9592 | return target_ranged_break_num_registers (); | |
9593 | } | |
9594 | ||
9595 | /* Implement the "print_it" breakpoint_ops method for | |
9596 | ranged breakpoints. */ | |
9597 | ||
9598 | static enum print_stop_action | |
348d480f | 9599 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9600 | { |
348d480f | 9601 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9602 | struct bp_location *bl = b->loc; |
79a45e25 | 9603 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9604 | |
9605 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9606 | ||
9607 | /* Ranged breakpoints have only one location. */ | |
9608 | gdb_assert (bl && bl->next == NULL); | |
9609 | ||
9610 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9611 | |
9612 | maybe_print_thread_hit_breakpoint (uiout); | |
9613 | ||
f1310107 | 9614 | if (b->disposition == disp_del) |
112e8700 | 9615 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9616 | else |
112e8700 SM |
9617 | uiout->text ("Ranged breakpoint "); |
9618 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9619 | { |
112e8700 | 9620 | uiout->field_string ("reason", |
f1310107 | 9621 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9622 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9623 | } |
381befee | 9624 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 9625 | uiout->text (", "); |
f1310107 TJB |
9626 | |
9627 | return PRINT_SRC_AND_LOC; | |
9628 | } | |
9629 | ||
9630 | /* Implement the "print_one" breakpoint_ops method for | |
9631 | ranged breakpoints. */ | |
9632 | ||
9633 | static void | |
9634 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9635 | struct bp_location **last_loc) | |
9636 | { | |
9637 | struct bp_location *bl = b->loc; | |
9638 | struct value_print_options opts; | |
79a45e25 | 9639 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9640 | |
9641 | /* Ranged breakpoints have only one location. */ | |
9642 | gdb_assert (bl && bl->next == NULL); | |
9643 | ||
9644 | get_user_print_options (&opts); | |
9645 | ||
9646 | if (opts.addressprint) | |
9647 | /* We don't print the address range here, it will be printed later | |
9648 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9649 | uiout->field_skip ("addr"); |
f1310107 TJB |
9650 | annotate_field (5); |
9651 | print_breakpoint_location (b, bl); | |
9652 | *last_loc = bl; | |
9653 | } | |
9654 | ||
9655 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9656 | ranged breakpoints. */ | |
9657 | ||
9658 | static void | |
9659 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9660 | struct ui_out *uiout) | |
9661 | { | |
9662 | CORE_ADDR address_start, address_end; | |
9663 | struct bp_location *bl = b->loc; | |
d7e74731 | 9664 | string_file stb; |
f1310107 TJB |
9665 | |
9666 | gdb_assert (bl); | |
9667 | ||
9668 | address_start = bl->address; | |
9669 | address_end = address_start + bl->length - 1; | |
9670 | ||
112e8700 | 9671 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9672 | stb.printf ("[%s, %s]", |
9673 | print_core_address (bl->gdbarch, address_start), | |
9674 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9675 | uiout->field_stream ("addr", stb); |
9676 | uiout->text ("\n"); | |
f1310107 TJB |
9677 | } |
9678 | ||
9679 | /* Implement the "print_mention" breakpoint_ops method for | |
9680 | ranged breakpoints. */ | |
9681 | ||
9682 | static void | |
9683 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9684 | { | |
9685 | struct bp_location *bl = b->loc; | |
79a45e25 | 9686 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9687 | |
9688 | gdb_assert (bl); | |
9689 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9690 | ||
2d33446d TT |
9691 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
9692 | b->number, paddress (bl->gdbarch, bl->address), | |
9693 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
f1310107 TJB |
9694 | } |
9695 | ||
9696 | /* Implement the "print_recreate" breakpoint_ops method for | |
9697 | ranged breakpoints. */ | |
9698 | ||
9699 | static void | |
9700 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9701 | { | |
f00aae0f | 9702 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9703 | event_location_to_string (b->location.get ()), |
9704 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9705 | print_recreate_thread (b, fp); |
f1310107 TJB |
9706 | } |
9707 | ||
9708 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9709 | ||
2060206e | 9710 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9711 | |
9712 | /* Find the address where the end of the breakpoint range should be | |
9713 | placed, given the SAL of the end of the range. This is so that if | |
9714 | the user provides a line number, the end of the range is set to the | |
9715 | last instruction of the given line. */ | |
9716 | ||
9717 | static CORE_ADDR | |
9718 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9719 | { | |
9720 | CORE_ADDR end; | |
9721 | ||
9722 | /* If the user provided a PC value, use it. Otherwise, | |
9723 | find the address of the end of the given location. */ | |
9724 | if (sal.explicit_pc) | |
9725 | end = sal.pc; | |
9726 | else | |
9727 | { | |
9728 | int ret; | |
9729 | CORE_ADDR start; | |
9730 | ||
9731 | ret = find_line_pc_range (sal, &start, &end); | |
9732 | if (!ret) | |
9733 | error (_("Could not find location of the end of the range.")); | |
9734 | ||
9735 | /* find_line_pc_range returns the start of the next line. */ | |
9736 | end--; | |
9737 | } | |
9738 | ||
9739 | return end; | |
9740 | } | |
9741 | ||
9742 | /* Implement the "break-range" CLI command. */ | |
9743 | ||
9744 | static void | |
0b39b52e | 9745 | break_range_command (const char *arg, int from_tty) |
f1310107 | 9746 | { |
f2fc3015 | 9747 | const char *arg_start; |
f1310107 TJB |
9748 | struct linespec_result canonical_start, canonical_end; |
9749 | int bp_count, can_use_bp, length; | |
9750 | CORE_ADDR end; | |
9751 | struct breakpoint *b; | |
f1310107 TJB |
9752 | |
9753 | /* We don't support software ranged breakpoints. */ | |
9754 | if (target_ranged_break_num_registers () < 0) | |
9755 | error (_("This target does not support hardware ranged breakpoints.")); | |
9756 | ||
9757 | bp_count = hw_breakpoint_used_count (); | |
9758 | bp_count += target_ranged_break_num_registers (); | |
9759 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9760 | bp_count, 0); | |
9761 | if (can_use_bp < 0) | |
9762 | error (_("Hardware breakpoints used exceeds limit.")); | |
9763 | ||
f8eba3c6 | 9764 | arg = skip_spaces (arg); |
f1310107 TJB |
9765 | if (arg == NULL || arg[0] == '\0') |
9766 | error(_("No address range specified.")); | |
9767 | ||
f8eba3c6 | 9768 | arg_start = arg; |
ffc2605c TT |
9769 | event_location_up start_location = string_to_event_location (&arg, |
9770 | current_language); | |
9771 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
9772 | |
9773 | if (arg[0] != ',') | |
9774 | error (_("Too few arguments.")); | |
6c5b2ebe | 9775 | else if (canonical_start.lsals.empty ()) |
f1310107 | 9776 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 9777 | |
6c5b2ebe | 9778 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 9779 | |
6c5b2ebe PA |
9780 | if (canonical_start.lsals.size () > 1 |
9781 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
9782 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9783 | ||
6c5b2ebe | 9784 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 9785 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
9786 | |
9787 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9788 | arg = skip_spaces (arg); |
f1310107 TJB |
9789 | |
9790 | /* Parse the end location. */ | |
9791 | ||
f1310107 TJB |
9792 | arg_start = arg; |
9793 | ||
f8eba3c6 | 9794 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9795 | parse_breakpoint_sals because we need to specify the start location's |
9796 | symtab and line as the default symtab and line for the end of the | |
9797 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9798 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
9799 | event_location_up end_location = string_to_event_location (&arg, |
9800 | current_language); | |
9801 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
9802 | sal_start.symtab, sal_start.line, |
9803 | &canonical_end, NULL, NULL); | |
9804 | ||
6c5b2ebe | 9805 | if (canonical_end.lsals.empty ()) |
f1310107 | 9806 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 9807 | |
6c5b2ebe PA |
9808 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
9809 | if (canonical_end.lsals.size () > 1 | |
9810 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
9811 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9812 | ||
6c5b2ebe | 9813 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
9814 | |
9815 | end = find_breakpoint_range_end (sal_end); | |
9816 | if (sal_start.pc > end) | |
177b42fe | 9817 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9818 | |
9819 | length = end - sal_start.pc + 1; | |
9820 | if (length < 0) | |
9821 | /* Length overflowed. */ | |
9822 | error (_("Address range too large.")); | |
9823 | else if (length == 1) | |
9824 | { | |
9825 | /* This range is simple enough to be handled by | |
9826 | the `hbreak' command. */ | |
81b1e71c | 9827 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
9828 | |
9829 | return; | |
9830 | } | |
9831 | ||
9832 | /* Now set up the breakpoint. */ | |
9833 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 9834 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
9835 | set_breakpoint_count (breakpoint_count + 1); |
9836 | b->number = breakpoint_count; | |
9837 | b->disposition = disp_donttouch; | |
d28cd78a TT |
9838 | b->location = std::move (start_location); |
9839 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
9840 | b->loc->length = length; |
9841 | ||
f1310107 | 9842 | mention (b); |
76727919 | 9843 | gdb::observers::breakpoint_created.notify (b); |
44702360 | 9844 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
9845 | } |
9846 | ||
4a64f543 MS |
9847 | /* Return non-zero if EXP is verified as constant. Returned zero |
9848 | means EXP is variable. Also the constant detection may fail for | |
9849 | some constant expressions and in such case still falsely return | |
9850 | zero. */ | |
2e6e3d9c | 9851 | |
65d79d4b SDJ |
9852 | static int |
9853 | watchpoint_exp_is_const (const struct expression *exp) | |
9854 | { | |
9855 | int i = exp->nelts; | |
9856 | ||
9857 | while (i > 0) | |
9858 | { | |
9859 | int oplenp, argsp; | |
9860 | ||
9861 | /* We are only interested in the descriptor of each element. */ | |
9862 | operator_length (exp, i, &oplenp, &argsp); | |
9863 | i -= oplenp; | |
9864 | ||
9865 | switch (exp->elts[i].opcode) | |
9866 | { | |
9867 | case BINOP_ADD: | |
9868 | case BINOP_SUB: | |
9869 | case BINOP_MUL: | |
9870 | case BINOP_DIV: | |
9871 | case BINOP_REM: | |
9872 | case BINOP_MOD: | |
9873 | case BINOP_LSH: | |
9874 | case BINOP_RSH: | |
9875 | case BINOP_LOGICAL_AND: | |
9876 | case BINOP_LOGICAL_OR: | |
9877 | case BINOP_BITWISE_AND: | |
9878 | case BINOP_BITWISE_IOR: | |
9879 | case BINOP_BITWISE_XOR: | |
9880 | case BINOP_EQUAL: | |
9881 | case BINOP_NOTEQUAL: | |
9882 | case BINOP_LESS: | |
9883 | case BINOP_GTR: | |
9884 | case BINOP_LEQ: | |
9885 | case BINOP_GEQ: | |
9886 | case BINOP_REPEAT: | |
9887 | case BINOP_COMMA: | |
9888 | case BINOP_EXP: | |
9889 | case BINOP_MIN: | |
9890 | case BINOP_MAX: | |
9891 | case BINOP_INTDIV: | |
9892 | case BINOP_CONCAT: | |
65d79d4b SDJ |
9893 | case TERNOP_COND: |
9894 | case TERNOP_SLICE: | |
65d79d4b SDJ |
9895 | |
9896 | case OP_LONG: | |
edd079d9 | 9897 | case OP_FLOAT: |
65d79d4b SDJ |
9898 | case OP_LAST: |
9899 | case OP_COMPLEX: | |
9900 | case OP_STRING: | |
65d79d4b SDJ |
9901 | case OP_ARRAY: |
9902 | case OP_TYPE: | |
608b4967 TT |
9903 | case OP_TYPEOF: |
9904 | case OP_DECLTYPE: | |
6e72ca20 | 9905 | case OP_TYPEID: |
65d79d4b SDJ |
9906 | case OP_NAME: |
9907 | case OP_OBJC_NSSTRING: | |
9908 | ||
9909 | case UNOP_NEG: | |
9910 | case UNOP_LOGICAL_NOT: | |
9911 | case UNOP_COMPLEMENT: | |
9912 | case UNOP_ADDR: | |
9913 | case UNOP_HIGH: | |
aeaa2474 | 9914 | case UNOP_CAST: |
9eaf6705 TT |
9915 | |
9916 | case UNOP_CAST_TYPE: | |
9917 | case UNOP_REINTERPRET_CAST: | |
9918 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
9919 | /* Unary, binary and ternary operators: We have to check |
9920 | their operands. If they are constant, then so is the | |
9921 | result of that operation. For instance, if A and B are | |
9922 | determined to be constants, then so is "A + B". | |
9923 | ||
9924 | UNOP_IND is one exception to the rule above, because the | |
9925 | value of *ADDR is not necessarily a constant, even when | |
9926 | ADDR is. */ | |
65d79d4b SDJ |
9927 | break; |
9928 | ||
9929 | case OP_VAR_VALUE: | |
9930 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 9931 | |
65d79d4b | 9932 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
9933 | possible that a buggy compiler could mark a variable as |
9934 | constant even when it is not, and TYPE_CONST would return | |
9935 | true in this case, while SYMBOL_CLASS wouldn't. | |
9936 | ||
9937 | We also have to check for function symbols because they | |
9938 | are always constant. */ | |
65d79d4b SDJ |
9939 | { |
9940 | struct symbol *s = exp->elts[i + 2].symbol; | |
9941 | ||
9942 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
9943 | && SYMBOL_CLASS (s) != LOC_CONST | |
9944 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
9945 | return 0; | |
9946 | break; | |
9947 | } | |
9948 | ||
9949 | /* The default action is to return 0 because we are using | |
9950 | the optimistic approach here: If we don't know something, | |
9951 | then it is not a constant. */ | |
9952 | default: | |
9953 | return 0; | |
9954 | } | |
9955 | } | |
9956 | ||
9957 | return 1; | |
9958 | } | |
9959 | ||
c1fc2657 | 9960 | /* Watchpoint destructor. */ |
3a5c3e22 | 9961 | |
c1fc2657 | 9962 | watchpoint::~watchpoint () |
3a5c3e22 | 9963 | { |
c1fc2657 SM |
9964 | xfree (this->exp_string); |
9965 | xfree (this->exp_string_reparse); | |
3a5c3e22 PA |
9966 | } |
9967 | ||
348d480f PA |
9968 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
9969 | ||
9970 | static void | |
9971 | re_set_watchpoint (struct breakpoint *b) | |
9972 | { | |
3a5c3e22 PA |
9973 | struct watchpoint *w = (struct watchpoint *) b; |
9974 | ||
348d480f PA |
9975 | /* Watchpoint can be either on expression using entirely global |
9976 | variables, or it can be on local variables. | |
9977 | ||
9978 | Watchpoints of the first kind are never auto-deleted, and even | |
9979 | persist across program restarts. Since they can use variables | |
9980 | from shared libraries, we need to reparse expression as libraries | |
9981 | are loaded and unloaded. | |
9982 | ||
9983 | Watchpoints on local variables can also change meaning as result | |
9984 | of solib event. For example, if a watchpoint uses both a local | |
9985 | and a global variables in expression, it's a local watchpoint, | |
9986 | but unloading of a shared library will make the expression | |
9987 | invalid. This is not a very common use case, but we still | |
9988 | re-evaluate expression, to avoid surprises to the user. | |
9989 | ||
9990 | Note that for local watchpoints, we re-evaluate it only if | |
9991 | watchpoints frame id is still valid. If it's not, it means the | |
9992 | watchpoint is out of scope and will be deleted soon. In fact, | |
9993 | I'm not sure we'll ever be called in this case. | |
9994 | ||
9995 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 9996 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 9997 | |
3a5c3e22 PA |
9998 | Don't do anything about disabled watchpoints, since they will be |
9999 | reevaluated again when enabled. */ | |
10000 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10001 | } |
10002 | ||
77b06cd7 TJB |
10003 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10004 | ||
10005 | static int | |
10006 | insert_watchpoint (struct bp_location *bl) | |
10007 | { | |
3a5c3e22 PA |
10008 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10009 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10010 | |
10011 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10012 | w->cond_exp.get ()); |
77b06cd7 TJB |
10013 | } |
10014 | ||
10015 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10016 | ||
10017 | static int | |
73971819 | 10018 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10019 | { |
3a5c3e22 PA |
10020 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10021 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10022 | |
10023 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10024 | w->cond_exp.get ()); |
e09342b5 TJB |
10025 | } |
10026 | ||
e09342b5 | 10027 | static int |
348d480f | 10028 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
bd522513 | 10029 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 10030 | const struct target_waitstatus *ws) |
e09342b5 | 10031 | { |
348d480f | 10032 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10033 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10034 | |
348d480f PA |
10035 | /* Continuable hardware watchpoints are treated as non-existent if the |
10036 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10037 | some data address). Otherwise gdb won't stop on a break instruction | |
10038 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10039 | been defined. Also skip watchpoints which we know did not trigger | |
10040 | (did not match the data address). */ | |
10041 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10042 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10043 | return 0; |
9c06b0b4 | 10044 | |
348d480f | 10045 | return 1; |
9c06b0b4 TJB |
10046 | } |
10047 | ||
348d480f PA |
10048 | static void |
10049 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10050 | { |
348d480f | 10051 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10052 | |
348d480f | 10053 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10054 | } |
10055 | ||
10056 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10057 | hardware watchpoints. */ |
9c06b0b4 TJB |
10058 | |
10059 | static int | |
348d480f | 10060 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10061 | { |
3a5c3e22 PA |
10062 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10063 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10064 | |
10065 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10066 | } |
10067 | ||
10068 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10069 | hardware watchpoints. */ |
9c06b0b4 TJB |
10070 | |
10071 | static int | |
348d480f | 10072 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10073 | { |
efa80663 PA |
10074 | /* Read and access watchpoints only work with hardware support. */ |
10075 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10076 | } |
10077 | ||
9c06b0b4 | 10078 | static enum print_stop_action |
348d480f | 10079 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10080 | { |
348d480f | 10081 | struct breakpoint *b; |
348d480f | 10082 | enum print_stop_action result; |
3a5c3e22 | 10083 | struct watchpoint *w; |
79a45e25 | 10084 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10085 | |
10086 | gdb_assert (bs->bp_location_at != NULL); | |
10087 | ||
348d480f | 10088 | b = bs->breakpoint_at; |
3a5c3e22 | 10089 | w = (struct watchpoint *) b; |
348d480f | 10090 | |
f303dbd6 PA |
10091 | annotate_watchpoint (b->number); |
10092 | maybe_print_thread_hit_breakpoint (uiout); | |
10093 | ||
d7e74731 PA |
10094 | string_file stb; |
10095 | ||
76f9c9cf | 10096 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10097 | switch (b->type) |
10098 | { | |
348d480f | 10099 | case bp_watchpoint: |
9c06b0b4 | 10100 | case bp_hardware_watchpoint: |
112e8700 SM |
10101 | if (uiout->is_mi_like_p ()) |
10102 | uiout->field_string | |
10103 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10104 | mention (b); |
76f9c9cf | 10105 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10106 | uiout->text ("\nOld value = "); |
850645cf | 10107 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10108 | uiout->field_stream ("old", stb); |
10109 | uiout->text ("\nNew value = "); | |
850645cf | 10110 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10111 | uiout->field_stream ("new", stb); |
10112 | uiout->text ("\n"); | |
348d480f PA |
10113 | /* More than one watchpoint may have been triggered. */ |
10114 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10115 | break; |
10116 | ||
10117 | case bp_read_watchpoint: | |
112e8700 SM |
10118 | if (uiout->is_mi_like_p ()) |
10119 | uiout->field_string | |
10120 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10121 | mention (b); |
76f9c9cf | 10122 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10123 | uiout->text ("\nValue = "); |
850645cf | 10124 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10125 | uiout->field_stream ("value", stb); |
10126 | uiout->text ("\n"); | |
348d480f | 10127 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10128 | break; |
10129 | ||
10130 | case bp_access_watchpoint: | |
348d480f PA |
10131 | if (bs->old_val != NULL) |
10132 | { | |
112e8700 SM |
10133 | if (uiout->is_mi_like_p ()) |
10134 | uiout->field_string | |
10135 | ("reason", | |
348d480f PA |
10136 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10137 | mention (b); | |
76f9c9cf | 10138 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10139 | uiout->text ("\nOld value = "); |
850645cf | 10140 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10141 | uiout->field_stream ("old", stb); |
10142 | uiout->text ("\nNew value = "); | |
348d480f PA |
10143 | } |
10144 | else | |
10145 | { | |
10146 | mention (b); | |
112e8700 SM |
10147 | if (uiout->is_mi_like_p ()) |
10148 | uiout->field_string | |
10149 | ("reason", | |
348d480f | 10150 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10151 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10152 | uiout->text ("\nValue = "); |
348d480f | 10153 | } |
850645cf | 10154 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10155 | uiout->field_stream ("new", stb); |
10156 | uiout->text ("\n"); | |
348d480f | 10157 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10158 | break; |
10159 | default: | |
348d480f | 10160 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10161 | } |
10162 | ||
348d480f PA |
10163 | return result; |
10164 | } | |
10165 | ||
10166 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10167 | watchpoints. */ | |
10168 | ||
10169 | static void | |
10170 | print_mention_watchpoint (struct breakpoint *b) | |
10171 | { | |
3a5c3e22 | 10172 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10173 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10174 | const char *tuple_name; |
348d480f PA |
10175 | |
10176 | switch (b->type) | |
10177 | { | |
10178 | case bp_watchpoint: | |
112e8700 | 10179 | uiout->text ("Watchpoint "); |
46b9c129 | 10180 | tuple_name = "wpt"; |
348d480f PA |
10181 | break; |
10182 | case bp_hardware_watchpoint: | |
112e8700 | 10183 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10184 | tuple_name = "wpt"; |
348d480f PA |
10185 | break; |
10186 | case bp_read_watchpoint: | |
112e8700 | 10187 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10188 | tuple_name = "hw-rwpt"; |
348d480f PA |
10189 | break; |
10190 | case bp_access_watchpoint: | |
112e8700 | 10191 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10192 | tuple_name = "hw-awpt"; |
348d480f PA |
10193 | break; |
10194 | default: | |
10195 | internal_error (__FILE__, __LINE__, | |
10196 | _("Invalid hardware watchpoint type.")); | |
10197 | } | |
10198 | ||
46b9c129 | 10199 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10200 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10201 | uiout->text (": "); |
10202 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10203 | } |
10204 | ||
10205 | /* Implement the "print_recreate" breakpoint_ops method for | |
10206 | watchpoints. */ | |
10207 | ||
10208 | static void | |
10209 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10210 | { | |
3a5c3e22 PA |
10211 | struct watchpoint *w = (struct watchpoint *) b; |
10212 | ||
348d480f PA |
10213 | switch (b->type) |
10214 | { | |
10215 | case bp_watchpoint: | |
10216 | case bp_hardware_watchpoint: | |
10217 | fprintf_unfiltered (fp, "watch"); | |
10218 | break; | |
10219 | case bp_read_watchpoint: | |
10220 | fprintf_unfiltered (fp, "rwatch"); | |
10221 | break; | |
10222 | case bp_access_watchpoint: | |
10223 | fprintf_unfiltered (fp, "awatch"); | |
10224 | break; | |
10225 | default: | |
10226 | internal_error (__FILE__, __LINE__, | |
10227 | _("Invalid watchpoint type.")); | |
10228 | } | |
10229 | ||
3a5c3e22 | 10230 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10231 | print_recreate_thread (b, fp); |
348d480f PA |
10232 | } |
10233 | ||
427cd150 TT |
10234 | /* Implement the "explains_signal" breakpoint_ops method for |
10235 | watchpoints. */ | |
10236 | ||
47591c29 | 10237 | static int |
427cd150 TT |
10238 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10239 | { | |
10240 | /* A software watchpoint cannot cause a signal other than | |
10241 | GDB_SIGNAL_TRAP. */ | |
10242 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10243 | return 0; |
427cd150 | 10244 | |
47591c29 | 10245 | return 1; |
427cd150 TT |
10246 | } |
10247 | ||
348d480f PA |
10248 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10249 | ||
2060206e | 10250 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10251 | |
10252 | /* Implement the "insert" breakpoint_ops method for | |
10253 | masked hardware watchpoints. */ | |
10254 | ||
10255 | static int | |
10256 | insert_masked_watchpoint (struct bp_location *bl) | |
10257 | { | |
3a5c3e22 PA |
10258 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10259 | ||
10260 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10261 | bl->watchpoint_type); |
10262 | } | |
10263 | ||
10264 | /* Implement the "remove" breakpoint_ops method for | |
10265 | masked hardware watchpoints. */ | |
10266 | ||
10267 | static int | |
73971819 | 10268 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10269 | { |
3a5c3e22 PA |
10270 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10271 | ||
10272 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10273 | bl->watchpoint_type); |
10274 | } | |
10275 | ||
10276 | /* Implement the "resources_needed" breakpoint_ops method for | |
10277 | masked hardware watchpoints. */ | |
10278 | ||
10279 | static int | |
10280 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10281 | { | |
3a5c3e22 PA |
10282 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10283 | ||
10284 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10285 | } |
10286 | ||
10287 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10288 | masked hardware watchpoints. */ | |
10289 | ||
10290 | static int | |
10291 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10292 | { | |
10293 | return 0; | |
10294 | } | |
10295 | ||
10296 | /* Implement the "print_it" breakpoint_ops method for | |
10297 | masked hardware watchpoints. */ | |
10298 | ||
10299 | static enum print_stop_action | |
10300 | print_it_masked_watchpoint (bpstat bs) | |
10301 | { | |
10302 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10303 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10304 | |
10305 | /* Masked watchpoints have only one location. */ | |
10306 | gdb_assert (b->loc && b->loc->next == NULL); | |
10307 | ||
f303dbd6 PA |
10308 | annotate_watchpoint (b->number); |
10309 | maybe_print_thread_hit_breakpoint (uiout); | |
10310 | ||
348d480f PA |
10311 | switch (b->type) |
10312 | { | |
10313 | case bp_hardware_watchpoint: | |
112e8700 SM |
10314 | if (uiout->is_mi_like_p ()) |
10315 | uiout->field_string | |
10316 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10317 | break; |
10318 | ||
10319 | case bp_read_watchpoint: | |
112e8700 SM |
10320 | if (uiout->is_mi_like_p ()) |
10321 | uiout->field_string | |
10322 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10323 | break; |
10324 | ||
10325 | case bp_access_watchpoint: | |
112e8700 SM |
10326 | if (uiout->is_mi_like_p ()) |
10327 | uiout->field_string | |
10328 | ("reason", | |
348d480f PA |
10329 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10330 | break; | |
10331 | default: | |
10332 | internal_error (__FILE__, __LINE__, | |
10333 | _("Invalid hardware watchpoint type.")); | |
10334 | } | |
10335 | ||
10336 | mention (b); | |
112e8700 | 10337 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10338 | Check the underlying instruction at PC for the memory\n\ |
10339 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10340 | uiout->text ("\n"); |
9c06b0b4 TJB |
10341 | |
10342 | /* More than one watchpoint may have been triggered. */ | |
10343 | return PRINT_UNKNOWN; | |
10344 | } | |
10345 | ||
10346 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10347 | masked hardware watchpoints. */ | |
10348 | ||
10349 | static void | |
10350 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10351 | struct ui_out *uiout) | |
10352 | { | |
3a5c3e22 PA |
10353 | struct watchpoint *w = (struct watchpoint *) b; |
10354 | ||
9c06b0b4 TJB |
10355 | /* Masked watchpoints have only one location. */ |
10356 | gdb_assert (b->loc && b->loc->next == NULL); | |
10357 | ||
112e8700 SM |
10358 | uiout->text ("\tmask "); |
10359 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10360 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10361 | } |
10362 | ||
10363 | /* Implement the "print_mention" breakpoint_ops method for | |
10364 | masked hardware watchpoints. */ | |
10365 | ||
10366 | static void | |
10367 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10368 | { | |
3a5c3e22 | 10369 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10370 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10371 | const char *tuple_name; |
9c06b0b4 TJB |
10372 | |
10373 | switch (b->type) | |
10374 | { | |
10375 | case bp_hardware_watchpoint: | |
112e8700 | 10376 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10377 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10378 | break; |
10379 | case bp_read_watchpoint: | |
112e8700 | 10380 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10381 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10382 | break; |
10383 | case bp_access_watchpoint: | |
112e8700 | 10384 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10385 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10386 | break; |
10387 | default: | |
10388 | internal_error (__FILE__, __LINE__, | |
10389 | _("Invalid hardware watchpoint type.")); | |
10390 | } | |
10391 | ||
46b9c129 | 10392 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10393 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10394 | uiout->text (": "); |
10395 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10396 | } |
10397 | ||
10398 | /* Implement the "print_recreate" breakpoint_ops method for | |
10399 | masked hardware watchpoints. */ | |
10400 | ||
10401 | static void | |
10402 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10403 | { | |
3a5c3e22 | 10404 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10405 | char tmp[40]; |
10406 | ||
10407 | switch (b->type) | |
10408 | { | |
10409 | case bp_hardware_watchpoint: | |
10410 | fprintf_unfiltered (fp, "watch"); | |
10411 | break; | |
10412 | case bp_read_watchpoint: | |
10413 | fprintf_unfiltered (fp, "rwatch"); | |
10414 | break; | |
10415 | case bp_access_watchpoint: | |
10416 | fprintf_unfiltered (fp, "awatch"); | |
10417 | break; | |
10418 | default: | |
10419 | internal_error (__FILE__, __LINE__, | |
10420 | _("Invalid hardware watchpoint type.")); | |
10421 | } | |
10422 | ||
3a5c3e22 PA |
10423 | sprintf_vma (tmp, w->hw_wp_mask); |
10424 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10425 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10426 | } |
10427 | ||
10428 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10429 | ||
2060206e | 10430 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10431 | |
10432 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10433 | ||
f2478a7e | 10434 | static bool |
9c06b0b4 TJB |
10435 | is_masked_watchpoint (const struct breakpoint *b) |
10436 | { | |
10437 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10438 | } | |
10439 | ||
53a5351d JM |
10440 | /* accessflag: hw_write: watch write, |
10441 | hw_read: watch read, | |
10442 | hw_access: watch access (read or write) */ | |
c906108c | 10443 | static void |
bbc13ae3 | 10444 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10445 | int just_location, int internal) |
c906108c | 10446 | { |
c1fc2657 | 10447 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10448 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
b926417a | 10449 | struct value *result; |
bb9d5f81 | 10450 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10451 | const char *exp_start = NULL; |
10452 | const char *exp_end = NULL; | |
10453 | const char *tok, *end_tok; | |
9c06b0b4 | 10454 | int toklen = -1; |
bbc13ae3 KS |
10455 | const char *cond_start = NULL; |
10456 | const char *cond_end = NULL; | |
c906108c | 10457 | enum bptype bp_type; |
37e4754d | 10458 | int thread = -1; |
0cf6dd15 | 10459 | int pc = 0; |
9c06b0b4 TJB |
10460 | /* Flag to indicate whether we are going to use masks for |
10461 | the hardware watchpoint. */ | |
10462 | int use_mask = 0; | |
10463 | CORE_ADDR mask = 0; | |
c906108c | 10464 | |
37e4754d LM |
10465 | /* Make sure that we actually have parameters to parse. */ |
10466 | if (arg != NULL && arg[0] != '\0') | |
10467 | { | |
bbc13ae3 KS |
10468 | const char *value_start; |
10469 | ||
10470 | exp_end = arg + strlen (arg); | |
37e4754d | 10471 | |
9c06b0b4 TJB |
10472 | /* Look for "parameter value" pairs at the end |
10473 | of the arguments string. */ | |
bbc13ae3 | 10474 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10475 | { |
10476 | /* Skip whitespace at the end of the argument list. */ | |
10477 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10478 | tok--; | |
10479 | ||
10480 | /* Find the beginning of the last token. | |
10481 | This is the value of the parameter. */ | |
10482 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10483 | tok--; | |
10484 | value_start = tok + 1; | |
10485 | ||
10486 | /* Skip whitespace. */ | |
10487 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10488 | tok--; | |
10489 | ||
10490 | end_tok = tok; | |
10491 | ||
10492 | /* Find the beginning of the second to last token. | |
10493 | This is the parameter itself. */ | |
10494 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10495 | tok--; | |
10496 | tok++; | |
10497 | toklen = end_tok - tok + 1; | |
10498 | ||
61012eef | 10499 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10500 | { |
5d5658a1 | 10501 | struct thread_info *thr; |
9c06b0b4 TJB |
10502 | /* At this point we've found a "thread" token, which means |
10503 | the user is trying to set a watchpoint that triggers | |
10504 | only in a specific thread. */ | |
5d5658a1 | 10505 | const char *endp; |
37e4754d | 10506 | |
9c06b0b4 TJB |
10507 | if (thread != -1) |
10508 | error(_("You can specify only one thread.")); | |
37e4754d | 10509 | |
9c06b0b4 | 10510 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10511 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10512 | |
5d5658a1 | 10513 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10514 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10515 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10516 | |
5d5658a1 | 10517 | thread = thr->global_num; |
9c06b0b4 | 10518 | } |
61012eef | 10519 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10520 | { |
10521 | /* We've found a "mask" token, which means the user wants to | |
10522 | create a hardware watchpoint that is going to have the mask | |
10523 | facility. */ | |
10524 | struct value *mask_value, *mark; | |
37e4754d | 10525 | |
9c06b0b4 TJB |
10526 | if (use_mask) |
10527 | error(_("You can specify only one mask.")); | |
37e4754d | 10528 | |
9c06b0b4 | 10529 | use_mask = just_location = 1; |
37e4754d | 10530 | |
9c06b0b4 TJB |
10531 | mark = value_mark (); |
10532 | mask_value = parse_to_comma_and_eval (&value_start); | |
10533 | mask = value_as_address (mask_value); | |
10534 | value_free_to_mark (mark); | |
10535 | } | |
10536 | else | |
10537 | /* We didn't recognize what we found. We should stop here. */ | |
10538 | break; | |
37e4754d | 10539 | |
9c06b0b4 TJB |
10540 | /* Truncate the string and get rid of the "parameter value" pair before |
10541 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10542 | exp_end = tok; |
9c06b0b4 | 10543 | } |
37e4754d | 10544 | } |
bbc13ae3 KS |
10545 | else |
10546 | exp_end = arg; | |
37e4754d | 10547 | |
bbc13ae3 KS |
10548 | /* Parse the rest of the arguments. From here on out, everything |
10549 | is in terms of a newly allocated string instead of the original | |
10550 | ARG. */ | |
81b1e71c TT |
10551 | std::string expression (arg, exp_end - arg); |
10552 | exp_start = arg = expression.c_str (); | |
699bd4cf TT |
10553 | innermost_block_tracker tracker; |
10554 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); | |
c906108c | 10555 | exp_end = arg; |
fa8a61dc TT |
10556 | /* Remove trailing whitespace from the expression before saving it. |
10557 | This makes the eventual display of the expression string a bit | |
10558 | prettier. */ | |
10559 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10560 | --exp_end; | |
10561 | ||
65d79d4b | 10562 | /* Checking if the expression is not constant. */ |
4d01a485 | 10563 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10564 | { |
10565 | int len; | |
10566 | ||
10567 | len = exp_end - exp_start; | |
10568 | while (len > 0 && isspace (exp_start[len - 1])) | |
10569 | len--; | |
10570 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10571 | } | |
10572 | ||
699bd4cf | 10573 | exp_valid_block = tracker.block (); |
b926417a | 10574 | struct value *mark = value_mark (); |
850645cf TT |
10575 | struct value *val_as_value = nullptr; |
10576 | fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL, | |
10577 | just_location); | |
06a64a0b | 10578 | |
850645cf | 10579 | if (val_as_value != NULL && just_location) |
bb9d5f81 | 10580 | { |
850645cf TT |
10581 | saved_bitpos = value_bitpos (val_as_value); |
10582 | saved_bitsize = value_bitsize (val_as_value); | |
bb9d5f81 PP |
10583 | } |
10584 | ||
850645cf | 10585 | value_ref_ptr val; |
06a64a0b TT |
10586 | if (just_location) |
10587 | { | |
9c06b0b4 TJB |
10588 | int ret; |
10589 | ||
06a64a0b | 10590 | exp_valid_block = NULL; |
850645cf | 10591 | val = release_value (value_addr (result)); |
06a64a0b | 10592 | value_free_to_mark (mark); |
9c06b0b4 TJB |
10593 | |
10594 | if (use_mask) | |
10595 | { | |
850645cf | 10596 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
9c06b0b4 TJB |
10597 | mask); |
10598 | if (ret == -1) | |
10599 | error (_("This target does not support masked watchpoints.")); | |
10600 | else if (ret == -2) | |
10601 | error (_("Invalid mask or memory region.")); | |
10602 | } | |
06a64a0b | 10603 | } |
850645cf TT |
10604 | else if (val_as_value != NULL) |
10605 | val = release_value (val_as_value); | |
c906108c | 10606 | |
f1735a53 TT |
10607 | tok = skip_spaces (arg); |
10608 | end_tok = skip_to_space (tok); | |
c906108c SS |
10609 | |
10610 | toklen = end_tok - tok; | |
10611 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10612 | { | |
10613 | tok = cond_start = end_tok + 1; | |
699bd4cf TT |
10614 | innermost_block_tracker if_tracker; |
10615 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); | |
60e1c644 PA |
10616 | |
10617 | /* The watchpoint expression may not be local, but the condition | |
10618 | may still be. E.g.: `watch global if local > 0'. */ | |
699bd4cf | 10619 | cond_exp_valid_block = if_tracker.block (); |
60e1c644 | 10620 | |
c906108c SS |
10621 | cond_end = tok; |
10622 | } | |
10623 | if (*tok) | |
8a3fe4f8 | 10624 | error (_("Junk at end of command.")); |
c906108c | 10625 | |
441d7c93 PA |
10626 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10627 | ||
10628 | /* Save this because create_internal_breakpoint below invalidates | |
10629 | 'wp_frame'. */ | |
10630 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10631 | |
10632 | /* If the expression is "local", then set up a "watchpoint scope" | |
10633 | breakpoint at the point where we've left the scope of the watchpoint | |
10634 | expression. Create the scope breakpoint before the watchpoint, so | |
10635 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10636 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10637 | { |
441d7c93 PA |
10638 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10639 | ||
10640 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10641 | { |
441d7c93 PA |
10642 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10643 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10644 | ||
edb3359d | 10645 | scope_breakpoint |
441d7c93 | 10646 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10647 | bp_watchpoint_scope, |
10648 | &momentary_breakpoint_ops); | |
d983da9c | 10649 | |
441d7c93 PA |
10650 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10651 | wp_frame = NULL; | |
10652 | ||
edb3359d | 10653 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10654 | |
edb3359d DJ |
10655 | /* Automatically delete the breakpoint when it hits. */ |
10656 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10657 | |
edb3359d | 10658 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10659 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10660 | |
edb3359d | 10661 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10662 | scope_breakpoint->loc->gdbarch = caller_arch; |
10663 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10664 | scope_breakpoint->loc->address |
a6d9a66e UW |
10665 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10666 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10667 | scope_breakpoint->type); |
10668 | } | |
d983da9c DJ |
10669 | } |
10670 | ||
e8369a73 AB |
10671 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10672 | watchpoints here even if hardware watchpoints are turned off, a call | |
10673 | to update_watchpoint later in this function will cause the type to | |
10674 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10675 | ||
10676 | if (accessflag == hw_read) | |
10677 | bp_type = bp_read_watchpoint; | |
10678 | else if (accessflag == hw_access) | |
10679 | bp_type = bp_access_watchpoint; | |
10680 | else | |
10681 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10682 | |
b270e6f9 | 10683 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10684 | |
348d480f | 10685 | if (use_mask) |
b270e6f9 | 10686 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10687 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10688 | else |
b270e6f9 | 10689 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10690 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
10691 | w->thread = thread; |
10692 | w->disposition = disp_donttouch; | |
10693 | w->pspace = current_program_space; | |
b22e99fd | 10694 | w->exp = std::move (exp); |
3a5c3e22 PA |
10695 | w->exp_valid_block = exp_valid_block; |
10696 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10697 | if (just_location) |
10698 | { | |
850645cf TT |
10699 | struct type *t = value_type (val.get ()); |
10700 | CORE_ADDR addr = value_as_address (val.get ()); | |
06a64a0b | 10701 | |
43cc5389 TT |
10702 | w->exp_string_reparse |
10703 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 10704 | |
3a5c3e22 | 10705 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 10706 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
10707 | } |
10708 | else | |
3a5c3e22 | 10709 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10710 | |
10711 | if (use_mask) | |
10712 | { | |
3a5c3e22 | 10713 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10714 | } |
10715 | else | |
10716 | { | |
3a5c3e22 | 10717 | w->val = val; |
bb9d5f81 PP |
10718 | w->val_bitpos = saved_bitpos; |
10719 | w->val_bitsize = saved_bitsize; | |
4c1d86d9 | 10720 | w->val_valid = true; |
9c06b0b4 | 10721 | } |
77b06cd7 | 10722 | |
c906108c | 10723 | if (cond_start) |
c1fc2657 | 10724 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 10725 | else |
c1fc2657 | 10726 | w->cond_string = 0; |
c5aa993b | 10727 | |
441d7c93 | 10728 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 10729 | { |
441d7c93 | 10730 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 10731 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 10732 | } |
c906108c | 10733 | else |
f6bc2008 | 10734 | { |
3a5c3e22 PA |
10735 | w->watchpoint_frame = null_frame_id; |
10736 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10737 | } |
c906108c | 10738 | |
d983da9c | 10739 | if (scope_breakpoint != NULL) |
c906108c | 10740 | { |
d983da9c DJ |
10741 | /* The scope breakpoint is related to the watchpoint. We will |
10742 | need to act on them together. */ | |
c1fc2657 | 10743 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 10744 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 10745 | } |
d983da9c | 10746 | |
06a64a0b TT |
10747 | if (!just_location) |
10748 | value_free_to_mark (mark); | |
2d134ed3 | 10749 | |
b270e6f9 TT |
10750 | /* Finally update the new watchpoint. This creates the locations |
10751 | that should be inserted. */ | |
10752 | update_watchpoint (w.get (), 1); | |
a9634178 | 10753 | |
b270e6f9 | 10754 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
10755 | } |
10756 | ||
e09342b5 | 10757 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10758 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10759 | |
c906108c | 10760 | static int |
a6535de1 | 10761 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
c906108c SS |
10762 | { |
10763 | int found_memory_cnt = 0; | |
10764 | ||
10765 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10766 | if (!can_use_hw_watchpoints) |
c906108c | 10767 | return 0; |
c5aa993b | 10768 | |
a6535de1 TT |
10769 | gdb_assert (!vals.empty ()); |
10770 | struct value *head = vals[0].get (); | |
10771 | ||
5c44784c JM |
10772 | /* Make sure that the value of the expression depends only upon |
10773 | memory contents, and values computed from them within GDB. If we | |
10774 | find any register references or function calls, we can't use a | |
10775 | hardware watchpoint. | |
10776 | ||
10777 | The idea here is that evaluating an expression generates a series | |
10778 | of values, one holding the value of every subexpression. (The | |
10779 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10780 | a*b+c.) GDB's values hold almost enough information to establish | |
10781 | the criteria given above --- they identify memory lvalues, | |
10782 | register lvalues, computed values, etcetera. So we can evaluate | |
10783 | the expression, and then scan the chain of values that leaves | |
10784 | behind to decide whether we can detect any possible change to the | |
10785 | expression's final value using only hardware watchpoints. | |
10786 | ||
10787 | However, I don't think that the values returned by inferior | |
10788 | function calls are special in any way. So this function may not | |
10789 | notice that an expression involving an inferior function call | |
10790 | can't be watched with hardware watchpoints. FIXME. */ | |
a6535de1 | 10791 | for (const value_ref_ptr &iter : vals) |
c906108c | 10792 | { |
a6535de1 TT |
10793 | struct value *v = iter.get (); |
10794 | ||
5c44784c | 10795 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10796 | { |
8464be76 DJ |
10797 | if (v != head && value_lazy (v)) |
10798 | /* A lazy memory lvalue in the chain is one that GDB never | |
10799 | needed to fetch; we either just used its address (e.g., | |
10800 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10801 | in `a,b'). This doesn't apply to HEAD; if that is | |
10802 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10803 | ; |
53a5351d | 10804 | else |
5c44784c JM |
10805 | { |
10806 | /* Ahh, memory we actually used! Check if we can cover | |
10807 | it with hardware watchpoints. */ | |
df407dfe | 10808 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10809 | |
10810 | /* We only watch structs and arrays if user asked for it | |
10811 | explicitly, never if they just happen to appear in a | |
10812 | middle of some value chain. */ | |
10813 | if (v == head | |
10814 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
10815 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
10816 | { | |
42ae5230 | 10817 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10818 | int len; |
10819 | int num_regs; | |
10820 | ||
a9634178 | 10821 | len = (target_exact_watchpoints |
e09342b5 TJB |
10822 | && is_scalar_type_recursive (vtype))? |
10823 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10824 | |
e09342b5 TJB |
10825 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10826 | if (!num_regs) | |
2e70b7b9 MS |
10827 | return 0; |
10828 | else | |
e09342b5 | 10829 | found_memory_cnt += num_regs; |
2e70b7b9 | 10830 | } |
5c44784c | 10831 | } |
c5aa993b | 10832 | } |
5086187c AC |
10833 | else if (VALUE_LVAL (v) != not_lval |
10834 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10835 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10836 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10837 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10838 | } |
10839 | ||
10840 | /* The expression itself looks suitable for using a hardware | |
10841 | watchpoint, but give the target machine a chance to reject it. */ | |
10842 | return found_memory_cnt; | |
10843 | } | |
10844 | ||
8b93c638 | 10845 | void |
f2fc3015 | 10846 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10847 | { |
84f4c1fe | 10848 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10849 | } |
10850 | ||
06a64a0b TT |
10851 | /* A helper function that looks for the "-location" argument and then |
10852 | calls watch_command_1. */ | |
10853 | ||
10854 | static void | |
0b39b52e | 10855 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b TT |
10856 | { |
10857 | int just_location = 0; | |
10858 | ||
10859 | if (arg | |
10860 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
10861 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
cbba3ecd | 10862 | just_location = 1; |
06a64a0b | 10863 | |
84f4c1fe | 10864 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 10865 | } |
8926118c | 10866 | |
c5aa993b | 10867 | static void |
0b39b52e | 10868 | watch_command (const char *arg, int from_tty) |
c906108c | 10869 | { |
06a64a0b | 10870 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10871 | } |
10872 | ||
8b93c638 | 10873 | void |
f2fc3015 | 10874 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10875 | { |
84f4c1fe | 10876 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10877 | } |
8926118c | 10878 | |
c5aa993b | 10879 | static void |
0b39b52e | 10880 | rwatch_command (const char *arg, int from_tty) |
c906108c | 10881 | { |
06a64a0b | 10882 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10883 | } |
10884 | ||
8b93c638 | 10885 | void |
f2fc3015 | 10886 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10887 | { |
84f4c1fe | 10888 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10889 | } |
8926118c | 10890 | |
c5aa993b | 10891 | static void |
0b39b52e | 10892 | awatch_command (const char *arg, int from_tty) |
c906108c | 10893 | { |
06a64a0b | 10894 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10895 | } |
c906108c | 10896 | \f |
c5aa993b | 10897 | |
cfc31633 PA |
10898 | /* Data for the FSM that manages the until(location)/advance commands |
10899 | in infcmd.c. Here because it uses the mechanisms of | |
10900 | breakpoints. */ | |
c906108c | 10901 | |
46e3ed7f | 10902 | struct until_break_fsm : public thread_fsm |
bfec99b2 | 10903 | { |
46e3ed7f | 10904 | /* The thread that was current when the command was executed. */ |
cfc31633 PA |
10905 | int thread; |
10906 | ||
10907 | /* The breakpoint set at the destination location. */ | |
46e3ed7f | 10908 | breakpoint_up location_breakpoint; |
cfc31633 PA |
10909 | |
10910 | /* Breakpoint set at the return address in the caller frame. May be | |
10911 | NULL. */ | |
46e3ed7f | 10912 | breakpoint_up caller_breakpoint; |
cfc31633 | 10913 | |
46e3ed7f TT |
10914 | until_break_fsm (struct interp *cmd_interp, int thread, |
10915 | breakpoint_up &&location_breakpoint, | |
10916 | breakpoint_up &&caller_breakpoint) | |
10917 | : thread_fsm (cmd_interp), | |
10918 | thread (thread), | |
10919 | location_breakpoint (std::move (location_breakpoint)), | |
10920 | caller_breakpoint (std::move (caller_breakpoint)) | |
10921 | { | |
10922 | } | |
cfc31633 | 10923 | |
46e3ed7f TT |
10924 | void clean_up (struct thread_info *thread) override; |
10925 | bool should_stop (struct thread_info *thread) override; | |
10926 | enum async_reply_reason do_async_reply_reason () override; | |
cfc31633 PA |
10927 | }; |
10928 | ||
cfc31633 PA |
10929 | /* Implementation of the 'should_stop' FSM method for the |
10930 | until(location)/advance commands. */ | |
10931 | ||
46e3ed7f TT |
10932 | bool |
10933 | until_break_fsm::should_stop (struct thread_info *tp) | |
cfc31633 | 10934 | { |
cfc31633 | 10935 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10936 | location_breakpoint.get ()) != NULL |
10937 | || (caller_breakpoint != NULL | |
cfc31633 | 10938 | && bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10939 | caller_breakpoint.get ()) != NULL)) |
10940 | set_finished (); | |
cfc31633 | 10941 | |
46e3ed7f | 10942 | return true; |
cfc31633 PA |
10943 | } |
10944 | ||
10945 | /* Implementation of the 'clean_up' FSM method for the | |
10946 | until(location)/advance commands. */ | |
10947 | ||
46e3ed7f TT |
10948 | void |
10949 | until_break_fsm::clean_up (struct thread_info *) | |
43ff13b4 | 10950 | { |
cfc31633 | 10951 | /* Clean up our temporary breakpoints. */ |
46e3ed7f TT |
10952 | location_breakpoint.reset (); |
10953 | caller_breakpoint.reset (); | |
10954 | delete_longjmp_breakpoint (thread); | |
cfc31633 PA |
10955 | } |
10956 | ||
10957 | /* Implementation of the 'async_reply_reason' FSM method for the | |
10958 | until(location)/advance commands. */ | |
10959 | ||
46e3ed7f TT |
10960 | enum async_reply_reason |
10961 | until_break_fsm::do_async_reply_reason () | |
cfc31633 PA |
10962 | { |
10963 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
10964 | } |
10965 | ||
c906108c | 10966 | void |
f2fc3015 | 10967 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 10968 | { |
8556afb4 PA |
10969 | struct frame_info *frame; |
10970 | struct gdbarch *frame_gdbarch; | |
10971 | struct frame_id stack_frame_id; | |
10972 | struct frame_id caller_frame_id; | |
186c406b TT |
10973 | int thread; |
10974 | struct thread_info *tp; | |
c906108c | 10975 | |
70509625 | 10976 | clear_proceed_status (0); |
c906108c SS |
10977 | |
10978 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 10979 | this function. */ |
c5aa993b | 10980 | |
ffc2605c | 10981 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 10982 | |
6c5b2ebe PA |
10983 | std::vector<symtab_and_line> sals |
10984 | = (last_displayed_sal_is_valid () | |
10985 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
10986 | get_last_displayed_symtab (), | |
10987 | get_last_displayed_line ()) | |
10988 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
cafb3438 | 10989 | NULL, NULL, 0)); |
c5aa993b | 10990 | |
6c5b2ebe | 10991 | if (sals.size () != 1) |
8a3fe4f8 | 10992 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 10993 | |
6c5b2ebe | 10994 | symtab_and_line &sal = sals[0]; |
c5aa993b | 10995 | |
c906108c | 10996 | if (*arg) |
8a3fe4f8 | 10997 | error (_("Junk at end of arguments.")); |
c5aa993b | 10998 | |
c906108c | 10999 | resolve_sal_pc (&sal); |
c5aa993b | 11000 | |
186c406b | 11001 | tp = inferior_thread (); |
5d5658a1 | 11002 | thread = tp->global_num; |
186c406b | 11003 | |
8556afb4 PA |
11004 | /* Note linespec handling above invalidates the frame chain. |
11005 | Installing a breakpoint also invalidates the frame chain (as it | |
11006 | may need to switch threads), so do any frame handling before | |
11007 | that. */ | |
11008 | ||
11009 | frame = get_selected_frame (NULL); | |
11010 | frame_gdbarch = get_frame_arch (frame); | |
11011 | stack_frame_id = get_stack_frame_id (frame); | |
11012 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11013 | |
ae66c1fc EZ |
11014 | /* Keep within the current frame, or in frames called by the current |
11015 | one. */ | |
edb3359d | 11016 | |
454dafbd | 11017 | breakpoint_up caller_breakpoint; |
5419bdae TT |
11018 | |
11019 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; | |
11020 | ||
883bc8d1 | 11021 | if (frame_id_p (caller_frame_id)) |
c906108c | 11022 | { |
883bc8d1 | 11023 | struct symtab_and_line sal2; |
cfc31633 | 11024 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11025 | |
11026 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11027 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11028 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11029 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11030 | sal2, | |
11031 | caller_frame_id, | |
11032 | bp_until); | |
186c406b | 11033 | |
883bc8d1 | 11034 | set_longjmp_breakpoint (tp, caller_frame_id); |
5419bdae | 11035 | lj_deleter.emplace (thread); |
c906108c | 11036 | } |
c5aa993b | 11037 | |
c70a6932 JK |
11038 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11039 | frame = NULL; | |
11040 | ||
454dafbd | 11041 | breakpoint_up location_breakpoint; |
883bc8d1 PA |
11042 | if (anywhere) |
11043 | /* If the user told us to continue until a specified location, | |
11044 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11045 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11046 | null_frame_id, bp_until); | |
883bc8d1 PA |
11047 | else |
11048 | /* Otherwise, specify the selected frame, because we want to stop | |
11049 | only at the very same frame. */ | |
cfc31633 PA |
11050 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11051 | stack_frame_id, bp_until); | |
883bc8d1 | 11052 | |
46e3ed7f TT |
11053 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
11054 | std::move (location_breakpoint), | |
11055 | std::move (caller_breakpoint)); | |
f107f563 | 11056 | |
5419bdae TT |
11057 | if (lj_deleter) |
11058 | lj_deleter->release (); | |
f107f563 | 11059 | |
cfc31633 | 11060 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11061 | } |
ae66c1fc | 11062 | |
c906108c SS |
11063 | /* This function attempts to parse an optional "if <cond>" clause |
11064 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11065 | |
c906108c SS |
11066 | Else, it returns a pointer to the condition string. (It does not |
11067 | attempt to evaluate the string against a particular block.) And, | |
11068 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11069 | if clause in the arg string. */ |
53a5351d | 11070 | |
63160a43 PA |
11071 | const char * |
11072 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11073 | { |
63160a43 | 11074 | const char *cond_string; |
c5aa993b JM |
11075 | |
11076 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11077 | return NULL; |
c5aa993b | 11078 | |
4a64f543 | 11079 | /* Skip the "if" keyword. */ |
c906108c | 11080 | (*arg) += 2; |
c5aa993b | 11081 | |
c906108c | 11082 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11083 | condition string. */ |
f1735a53 | 11084 | *arg = skip_spaces (*arg); |
c906108c | 11085 | cond_string = *arg; |
c5aa993b | 11086 | |
4a64f543 MS |
11087 | /* Assume that the condition occupies the remainder of the arg |
11088 | string. */ | |
c906108c | 11089 | (*arg) += strlen (cond_string); |
c5aa993b | 11090 | |
c906108c SS |
11091 | return cond_string; |
11092 | } | |
c5aa993b | 11093 | |
c906108c SS |
11094 | /* Commands to deal with catching events, such as signals, exceptions, |
11095 | process start/exit, etc. */ | |
c5aa993b JM |
11096 | |
11097 | typedef enum | |
11098 | { | |
44feb3ce TT |
11099 | catch_fork_temporary, catch_vfork_temporary, |
11100 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11101 | } |
11102 | catch_fork_kind; | |
11103 | ||
c906108c | 11104 | static void |
eb4c3f4a | 11105 | catch_fork_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11106 | struct cmd_list_element *command) |
c906108c | 11107 | { |
a6d9a66e | 11108 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11109 | const char *cond_string = NULL; |
44feb3ce TT |
11110 | catch_fork_kind fork_kind; |
11111 | int tempflag; | |
11112 | ||
11113 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11114 | tempflag = (fork_kind == catch_fork_temporary | |
11115 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11116 | |
44feb3ce TT |
11117 | if (!arg) |
11118 | arg = ""; | |
f1735a53 | 11119 | arg = skip_spaces (arg); |
c5aa993b | 11120 | |
c906108c | 11121 | /* The allowed syntax is: |
c5aa993b JM |
11122 | catch [v]fork |
11123 | catch [v]fork if <cond> | |
11124 | ||
4a64f543 | 11125 | First, check if there's an if clause. */ |
c906108c | 11126 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11127 | |
c906108c | 11128 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11129 | error (_("Junk at end of arguments.")); |
c5aa993b | 11130 | |
c906108c | 11131 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11132 | and enable reporting of such events. */ |
c5aa993b JM |
11133 | switch (fork_kind) |
11134 | { | |
44feb3ce TT |
11135 | case catch_fork_temporary: |
11136 | case catch_fork_permanent: | |
a6d9a66e | 11137 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11138 | &catch_fork_breakpoint_ops); |
c906108c | 11139 | break; |
44feb3ce TT |
11140 | case catch_vfork_temporary: |
11141 | case catch_vfork_permanent: | |
a6d9a66e | 11142 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11143 | &catch_vfork_breakpoint_ops); |
c906108c | 11144 | break; |
c5aa993b | 11145 | default: |
8a3fe4f8 | 11146 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11147 | break; |
c5aa993b | 11148 | } |
c906108c SS |
11149 | } |
11150 | ||
11151 | static void | |
eb4c3f4a | 11152 | catch_exec_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11153 | struct cmd_list_element *command) |
c906108c | 11154 | { |
a6d9a66e | 11155 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11156 | int tempflag; |
63160a43 | 11157 | const char *cond_string = NULL; |
c906108c | 11158 | |
44feb3ce TT |
11159 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11160 | ||
11161 | if (!arg) | |
11162 | arg = ""; | |
f1735a53 | 11163 | arg = skip_spaces (arg); |
c906108c SS |
11164 | |
11165 | /* The allowed syntax is: | |
c5aa993b JM |
11166 | catch exec |
11167 | catch exec if <cond> | |
c906108c | 11168 | |
4a64f543 | 11169 | First, check if there's an if clause. */ |
c906108c SS |
11170 | cond_string = ep_parse_optional_if_clause (&arg); |
11171 | ||
11172 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11173 | error (_("Junk at end of arguments.")); |
c906108c | 11174 | |
b270e6f9 TT |
11175 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11176 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11177 | &catch_exec_breakpoint_ops); |
11178 | c->exec_pathname = NULL; | |
11179 | ||
b270e6f9 | 11180 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11181 | } |
c5aa993b | 11182 | |
9ac4176b | 11183 | void |
28010a5d PA |
11184 | init_ada_exception_breakpoint (struct breakpoint *b, |
11185 | struct gdbarch *gdbarch, | |
11186 | struct symtab_and_line sal, | |
f2fc3015 | 11187 | const char *addr_string, |
c0a91b2b | 11188 | const struct breakpoint_ops *ops, |
28010a5d | 11189 | int tempflag, |
349774ef | 11190 | int enabled, |
28010a5d | 11191 | int from_tty) |
f7f9143b | 11192 | { |
f7f9143b JB |
11193 | if (from_tty) |
11194 | { | |
5af949e3 UW |
11195 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11196 | if (!loc_gdbarch) | |
11197 | loc_gdbarch = gdbarch; | |
11198 | ||
6c95b8df PA |
11199 | describe_other_breakpoints (loc_gdbarch, |
11200 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11201 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11202 | version for exception catchpoints, because two catchpoints | |
11203 | used for different exception names will use the same address. | |
11204 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11205 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11206 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11207 | the user what type of catchpoint it is. The above is good |
11208 | enough for now, though. */ | |
11209 | } | |
11210 | ||
f06f1252 | 11211 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
f7f9143b | 11212 | |
349774ef | 11213 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11214 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11215 | b->location = string_to_event_location (&addr_string, |
11216 | language_def (language_ada)); | |
f7f9143b | 11217 | b->language = language_ada; |
f7f9143b JB |
11218 | } |
11219 | ||
c906108c | 11220 | static void |
981a3fb3 | 11221 | catch_command (const char *arg, int from_tty) |
c906108c | 11222 | { |
44feb3ce | 11223 | error (_("Catch requires an event name.")); |
c906108c SS |
11224 | } |
11225 | \f | |
11226 | ||
11227 | static void | |
981a3fb3 | 11228 | tcatch_command (const char *arg, int from_tty) |
c906108c | 11229 | { |
44feb3ce | 11230 | error (_("Catch requires an event name.")); |
c906108c SS |
11231 | } |
11232 | ||
81b1e71c | 11233 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
11234 | |
11235 | static int | |
81b1e71c | 11236 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 11237 | { |
81b1e71c TT |
11238 | uintptr_t ua = (uintptr_t) a; |
11239 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 11240 | |
81b1e71c | 11241 | if (a->number < b->number) |
8a2c437b | 11242 | return -1; |
81b1e71c | 11243 | else if (a->number > b->number) |
8a2c437b TT |
11244 | return 1; |
11245 | ||
11246 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11247 | the number 0. */ | |
11248 | if (ua < ub) | |
11249 | return -1; | |
94b0e70d | 11250 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11251 | } |
11252 | ||
80f8a6eb | 11253 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11254 | |
11255 | static void | |
0b39b52e | 11256 | clear_command (const char *arg, int from_tty) |
c906108c | 11257 | { |
81b1e71c | 11258 | struct breakpoint *b; |
c906108c | 11259 | int default_match; |
c906108c | 11260 | |
6c5b2ebe PA |
11261 | std::vector<symtab_and_line> decoded_sals; |
11262 | symtab_and_line last_sal; | |
11263 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11264 | if (arg) |
11265 | { | |
6c5b2ebe PA |
11266 | decoded_sals |
11267 | = decode_line_with_current_source (arg, | |
11268 | (DECODE_LINE_FUNFIRSTLINE | |
11269 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11270 | default_match = 0; |
6c5b2ebe | 11271 | sals = decoded_sals; |
c906108c SS |
11272 | } |
11273 | else | |
11274 | { | |
1bfeeb0f JL |
11275 | /* Set sal's line, symtab, pc, and pspace to the values |
11276 | corresponding to the last call to print_frame_info. If the | |
11277 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11278 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11279 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11280 | error (_("No source file specified.")); |
c906108c | 11281 | |
c906108c | 11282 | default_match = 1; |
6c5b2ebe | 11283 | sals = last_sal; |
c906108c SS |
11284 | } |
11285 | ||
4a64f543 MS |
11286 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11287 | seems, because all existing breakpoints typically have both | |
11288 | file/line and pc set. So, if clear is given file/line, we can | |
11289 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11290 | |
11291 | We only support clearing given the address explicitly | |
11292 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11293 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11294 | due to optimization, all in one block. |
4a64f543 MS |
11295 | |
11296 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11297 | PC corresponding to the same file:line, the breakpoint won't |
11298 | be cleared. We probably can still clear the breakpoint, but | |
11299 | since the other PC value is never presented to user, user | |
11300 | can only find it by guessing, and it does not seem important | |
11301 | to support that. */ | |
11302 | ||
4a64f543 MS |
11303 | /* For each line spec given, delete bps which correspond to it. Do |
11304 | it in two passes, solely to preserve the current behavior that | |
11305 | from_tty is forced true if we delete more than one | |
11306 | breakpoint. */ | |
c906108c | 11307 | |
81b1e71c | 11308 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 11309 | for (const auto &sal : sals) |
c906108c | 11310 | { |
05cba821 JK |
11311 | const char *sal_fullname; |
11312 | ||
c906108c | 11313 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11314 | If line given (pc == 0), clear all bpts on specified line. |
11315 | If defaulting, clear all bpts on default line | |
c906108c | 11316 | or at default pc. |
c5aa993b JM |
11317 | |
11318 | defaulting sal.pc != 0 tests to do | |
11319 | ||
11320 | 0 1 pc | |
11321 | 1 1 pc _and_ line | |
11322 | 0 0 line | |
11323 | 1 0 <can't happen> */ | |
c906108c | 11324 | |
05cba821 JK |
11325 | sal_fullname = (sal.symtab == NULL |
11326 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11327 | |
4a64f543 | 11328 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11329 | ALL_BREAKPOINTS (b) |
c5aa993b | 11330 | { |
0d381245 | 11331 | int match = 0; |
4a64f543 | 11332 | /* Are we going to delete b? */ |
cc60f2e3 | 11333 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11334 | { |
11335 | struct bp_location *loc = b->loc; | |
11336 | for (; loc; loc = loc->next) | |
11337 | { | |
f8eba3c6 TT |
11338 | /* If the user specified file:line, don't allow a PC |
11339 | match. This matches historical gdb behavior. */ | |
11340 | int pc_match = (!sal.explicit_line | |
11341 | && sal.pc | |
11342 | && (loc->pspace == sal.pspace) | |
11343 | && (loc->address == sal.pc) | |
11344 | && (!section_is_overlay (loc->section) | |
11345 | || loc->section == sal.section)); | |
4aac40c8 TT |
11346 | int line_match = 0; |
11347 | ||
11348 | if ((default_match || sal.explicit_line) | |
2f202fde | 11349 | && loc->symtab != NULL |
05cba821 | 11350 | && sal_fullname != NULL |
4aac40c8 | 11351 | && sal.pspace == loc->pspace |
05cba821 JK |
11352 | && loc->line_number == sal.line |
11353 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11354 | sal_fullname) == 0) | |
11355 | line_match = 1; | |
4aac40c8 | 11356 | |
0d381245 VP |
11357 | if (pc_match || line_match) |
11358 | { | |
11359 | match = 1; | |
11360 | break; | |
11361 | } | |
11362 | } | |
11363 | } | |
11364 | ||
11365 | if (match) | |
81b1e71c | 11366 | found.push_back (b); |
c906108c | 11367 | } |
80f8a6eb | 11368 | } |
8a2c437b | 11369 | |
80f8a6eb | 11370 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 11371 | if (found.empty ()) |
80f8a6eb MS |
11372 | { |
11373 | if (arg) | |
8a3fe4f8 | 11374 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11375 | else |
8a3fe4f8 | 11376 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11377 | } |
c906108c | 11378 | |
8a2c437b | 11379 | /* Remove duplicates from the vec. */ |
81b1e71c | 11380 | std::sort (found.begin (), found.end (), |
b926417a | 11381 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11382 | { |
b926417a | 11383 | return compare_breakpoints (bp_a, bp_b) < 0; |
81b1e71c TT |
11384 | }); |
11385 | found.erase (std::unique (found.begin (), found.end (), | |
b926417a | 11386 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11387 | { |
b926417a | 11388 | return compare_breakpoints (bp_a, bp_b) == 0; |
81b1e71c TT |
11389 | }), |
11390 | found.end ()); | |
8a2c437b | 11391 | |
81b1e71c | 11392 | if (found.size () > 1) |
4a64f543 | 11393 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11394 | if (from_tty) |
a3f17187 | 11395 | { |
81b1e71c | 11396 | if (found.size () == 1) |
a3f17187 AC |
11397 | printf_unfiltered (_("Deleted breakpoint ")); |
11398 | else | |
11399 | printf_unfiltered (_("Deleted breakpoints ")); | |
11400 | } | |
d6e956e5 | 11401 | |
81b1e71c | 11402 | for (breakpoint *iter : found) |
80f8a6eb | 11403 | { |
c5aa993b | 11404 | if (from_tty) |
81b1e71c TT |
11405 | printf_unfiltered ("%d ", iter->number); |
11406 | delete_breakpoint (iter); | |
c906108c | 11407 | } |
80f8a6eb MS |
11408 | if (from_tty) |
11409 | putchar_unfiltered ('\n'); | |
c906108c SS |
11410 | } |
11411 | \f | |
11412 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11413 | all breakpoints that are marked for deletion, whether hit or not. | |
11414 | This is called after any breakpoint is hit, or after errors. */ | |
11415 | ||
11416 | void | |
fba45db2 | 11417 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11418 | { |
35df4500 | 11419 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11420 | |
11421 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11422 | if (bs->breakpoint_at |
11423 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11424 | && bs->stop) |
f431efe5 | 11425 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11426 | |
35df4500 | 11427 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11428 | { |
b5de0fa7 | 11429 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11430 | delete_breakpoint (b); |
11431 | } | |
c906108c SS |
11432 | } |
11433 | ||
4a64f543 MS |
11434 | /* A comparison function for bp_location AP and BP being interfaced to |
11435 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
cb1e4e32 PA |
11436 | bl_address_is_meaningful says), secondarily by ordering first |
11437 | permanent elements and terciarily just ensuring the array is sorted | |
11438 | stable way despite qsort being an unstable algorithm. */ | |
876fa593 JK |
11439 | |
11440 | static int | |
f5336ca5 | 11441 | bp_locations_compare (const void *ap, const void *bp) |
876fa593 | 11442 | { |
9a3c8263 SM |
11443 | const struct bp_location *a = *(const struct bp_location **) ap; |
11444 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
11445 | |
11446 | if (a->address != b->address) | |
11447 | return (a->address > b->address) - (a->address < b->address); | |
11448 | ||
dea2aa5f LM |
11449 | /* Sort locations at the same address by their pspace number, keeping |
11450 | locations of the same inferior (in a multi-inferior environment) | |
11451 | grouped. */ | |
11452 | ||
11453 | if (a->pspace->num != b->pspace->num) | |
11454 | return ((a->pspace->num > b->pspace->num) | |
11455 | - (a->pspace->num < b->pspace->num)); | |
11456 | ||
876fa593 | 11457 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
11458 | if (a->permanent != b->permanent) |
11459 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 11460 | |
c56a97f9 JK |
11461 | /* Make the internal GDB representation stable across GDB runs |
11462 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11463 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11464 | |
11465 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11466 | return ((a->owner->number > b->owner->number) |
11467 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11468 | |
11469 | return (a > b) - (a < b); | |
11470 | } | |
11471 | ||
f5336ca5 PA |
11472 | /* Set bp_locations_placed_address_before_address_max and |
11473 | bp_locations_shadow_len_after_address_max according to the current | |
11474 | content of the bp_locations array. */ | |
f7545552 TT |
11475 | |
11476 | static void | |
f5336ca5 | 11477 | bp_locations_target_extensions_update (void) |
f7545552 | 11478 | { |
876fa593 JK |
11479 | struct bp_location *bl, **blp_tmp; |
11480 | ||
f5336ca5 PA |
11481 | bp_locations_placed_address_before_address_max = 0; |
11482 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11483 | |
11484 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11485 | { | |
11486 | CORE_ADDR start, end, addr; | |
11487 | ||
11488 | if (!bp_location_has_shadow (bl)) | |
11489 | continue; | |
11490 | ||
11491 | start = bl->target_info.placed_address; | |
11492 | end = start + bl->target_info.shadow_len; | |
11493 | ||
11494 | gdb_assert (bl->address >= start); | |
11495 | addr = bl->address - start; | |
f5336ca5 PA |
11496 | if (addr > bp_locations_placed_address_before_address_max) |
11497 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11498 | |
11499 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11500 | ||
11501 | gdb_assert (bl->address < end); | |
11502 | addr = end - bl->address; | |
f5336ca5 PA |
11503 | if (addr > bp_locations_shadow_len_after_address_max) |
11504 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11505 | } |
f7545552 TT |
11506 | } |
11507 | ||
1e4d1764 YQ |
11508 | /* Download tracepoint locations if they haven't been. */ |
11509 | ||
11510 | static void | |
11511 | download_tracepoint_locations (void) | |
11512 | { | |
7ed2c994 | 11513 | struct breakpoint *b; |
dd2e65cc | 11514 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11515 | |
5ed8105e | 11516 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11517 | |
7ed2c994 | 11518 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11519 | { |
7ed2c994 | 11520 | struct bp_location *bl; |
1e4d1764 | 11521 | struct tracepoint *t; |
f2a8bc8a | 11522 | int bp_location_downloaded = 0; |
1e4d1764 | 11523 | |
7ed2c994 | 11524 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11525 | ? !may_insert_fast_tracepoints |
11526 | : !may_insert_tracepoints)) | |
11527 | continue; | |
11528 | ||
dd2e65cc YQ |
11529 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11530 | { | |
11531 | if (target_can_download_tracepoint ()) | |
11532 | can_download_tracepoint = TRIBOOL_TRUE; | |
11533 | else | |
11534 | can_download_tracepoint = TRIBOOL_FALSE; | |
11535 | } | |
11536 | ||
11537 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11538 | break; | |
11539 | ||
7ed2c994 YQ |
11540 | for (bl = b->loc; bl; bl = bl->next) |
11541 | { | |
11542 | /* In tracepoint, locations are _never_ duplicated, so | |
11543 | should_be_inserted is equivalent to | |
11544 | unduplicated_should_be_inserted. */ | |
11545 | if (!should_be_inserted (bl) || bl->inserted) | |
11546 | continue; | |
1e4d1764 | 11547 | |
7ed2c994 | 11548 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11549 | |
7ed2c994 | 11550 | target_download_tracepoint (bl); |
1e4d1764 | 11551 | |
7ed2c994 | 11552 | bl->inserted = 1; |
f2a8bc8a | 11553 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11554 | } |
11555 | t = (struct tracepoint *) b; | |
11556 | t->number_on_target = b->number; | |
f2a8bc8a | 11557 | if (bp_location_downloaded) |
76727919 | 11558 | gdb::observers::breakpoint_modified.notify (b); |
1e4d1764 | 11559 | } |
1e4d1764 YQ |
11560 | } |
11561 | ||
934709f0 PW |
11562 | /* Swap the insertion/duplication state between two locations. */ |
11563 | ||
11564 | static void | |
11565 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11566 | { | |
11567 | const int left_inserted = left->inserted; | |
11568 | const int left_duplicate = left->duplicate; | |
b775012e | 11569 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11570 | const struct bp_target_info left_target_info = left->target_info; |
11571 | ||
1e4d1764 YQ |
11572 | /* Locations of tracepoints can never be duplicated. */ |
11573 | if (is_tracepoint (left->owner)) | |
11574 | gdb_assert (!left->duplicate); | |
11575 | if (is_tracepoint (right->owner)) | |
11576 | gdb_assert (!right->duplicate); | |
11577 | ||
934709f0 PW |
11578 | left->inserted = right->inserted; |
11579 | left->duplicate = right->duplicate; | |
b775012e | 11580 | left->needs_update = right->needs_update; |
934709f0 PW |
11581 | left->target_info = right->target_info; |
11582 | right->inserted = left_inserted; | |
11583 | right->duplicate = left_duplicate; | |
b775012e | 11584 | right->needs_update = left_needs_update; |
934709f0 PW |
11585 | right->target_info = left_target_info; |
11586 | } | |
11587 | ||
b775012e LM |
11588 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11589 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11590 | conditions on the target's side. Such conditions need to be updated on | |
11591 | the target. */ | |
11592 | ||
11593 | static void | |
11594 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11595 | { | |
11596 | struct bp_location **locp = NULL, **loc2p; | |
11597 | struct bp_location *loc; | |
11598 | CORE_ADDR address = 0; | |
11599 | int pspace_num; | |
11600 | ||
11601 | address = bl->address; | |
11602 | pspace_num = bl->pspace->num; | |
11603 | ||
11604 | /* This is only meaningful if the target is | |
11605 | evaluating conditions and if the user has | |
11606 | opted for condition evaluation on the target's | |
11607 | side. */ | |
11608 | if (gdb_evaluates_breakpoint_condition_p () | |
11609 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11610 | return; | |
11611 | ||
11612 | /* Flag all breakpoint locations with this address and | |
11613 | the same program space as the location | |
11614 | as "its condition has changed". We need to | |
11615 | update the conditions on the target's side. */ | |
11616 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11617 | { | |
11618 | loc = *loc2p; | |
11619 | ||
11620 | if (!is_breakpoint (loc->owner) | |
11621 | || pspace_num != loc->pspace->num) | |
11622 | continue; | |
11623 | ||
11624 | /* Flag the location appropriately. We use a different state to | |
11625 | let everyone know that we already updated the set of locations | |
11626 | with addr bl->address and program space bl->pspace. This is so | |
11627 | we don't have to keep calling these functions just to mark locations | |
11628 | that have already been marked. */ | |
11629 | loc->condition_changed = condition_updated; | |
11630 | ||
11631 | /* Free the agent expression bytecode as well. We will compute | |
11632 | it later on. */ | |
833177a4 | 11633 | loc->cond_bytecode.reset (); |
b775012e LM |
11634 | } |
11635 | } | |
44702360 PA |
11636 | /* Called whether new breakpoints are created, or existing breakpoints |
11637 | deleted, to update the global location list and recompute which | |
11638 | locations are duplicate of which. | |
b775012e | 11639 | |
04086b45 PA |
11640 | The INSERT_MODE flag determines whether locations may not, may, or |
11641 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11642 | info. */ | |
b60e7edf | 11643 | |
0d381245 | 11644 | static void |
44702360 | 11645 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11646 | { |
74960c60 | 11647 | struct breakpoint *b; |
876fa593 | 11648 | struct bp_location **locp, *loc; |
b775012e LM |
11649 | /* Last breakpoint location address that was marked for update. */ |
11650 | CORE_ADDR last_addr = 0; | |
11651 | /* Last breakpoint location program space that was marked for update. */ | |
11652 | int last_pspace_num = -1; | |
f7545552 | 11653 | |
2d134ed3 PA |
11654 | /* Used in the duplicates detection below. When iterating over all |
11655 | bp_locations, points to the first bp_location of a given address. | |
11656 | Breakpoints and watchpoints of different types are never | |
11657 | duplicates of each other. Keep one pointer for each type of | |
11658 | breakpoint/watchpoint, so we only need to loop over all locations | |
11659 | once. */ | |
11660 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11661 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11662 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11663 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11664 | |
f5336ca5 PA |
11665 | /* Saved former bp_locations array which we compare against the newly |
11666 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
81b1e71c | 11667 | struct bp_location **old_locp; |
f5336ca5 | 11668 | unsigned old_locations_count; |
81b1e71c | 11669 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
876fa593 | 11670 | |
f5336ca5 PA |
11671 | old_locations_count = bp_locations_count; |
11672 | bp_locations = NULL; | |
11673 | bp_locations_count = 0; | |
0d381245 | 11674 | |
74960c60 | 11675 | ALL_BREAKPOINTS (b) |
876fa593 | 11676 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 11677 | bp_locations_count++; |
876fa593 | 11678 | |
f5336ca5 PA |
11679 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
11680 | locp = bp_locations; | |
876fa593 JK |
11681 | ALL_BREAKPOINTS (b) |
11682 | for (loc = b->loc; loc; loc = loc->next) | |
11683 | *locp++ = loc; | |
f5336ca5 PA |
11684 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
11685 | bp_locations_compare); | |
876fa593 | 11686 | |
f5336ca5 | 11687 | bp_locations_target_extensions_update (); |
74960c60 | 11688 | |
4a64f543 MS |
11689 | /* Identify bp_location instances that are no longer present in the |
11690 | new list, and therefore should be freed. Note that it's not | |
11691 | necessary that those locations should be removed from inferior -- | |
11692 | if there's another location at the same address (previously | |
11693 | marked as duplicate), we don't need to remove/insert the | |
11694 | location. | |
876fa593 | 11695 | |
4a64f543 MS |
11696 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11697 | and former bp_location array state respectively. */ | |
876fa593 | 11698 | |
f5336ca5 | 11699 | locp = bp_locations; |
81b1e71c TT |
11700 | for (old_locp = old_locations.get (); |
11701 | old_locp < old_locations.get () + old_locations_count; | |
876fa593 | 11702 | old_locp++) |
74960c60 | 11703 | { |
876fa593 | 11704 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11705 | struct bp_location **loc2p; |
876fa593 | 11706 | |
e5dd4106 | 11707 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11708 | not, we have to free it. */ |
c7d46a38 | 11709 | int found_object = 0; |
20874c92 VP |
11710 | /* Tells if the location should remain inserted in the target. */ |
11711 | int keep_in_target = 0; | |
11712 | int removed = 0; | |
876fa593 | 11713 | |
4a64f543 MS |
11714 | /* Skip LOCP entries which will definitely never be needed. |
11715 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 11716 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 11717 | && (*locp)->address < old_loc->address) |
876fa593 | 11718 | locp++; |
c7d46a38 PA |
11719 | |
11720 | for (loc2p = locp; | |
f5336ca5 | 11721 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
11722 | && (*loc2p)->address == old_loc->address); |
11723 | loc2p++) | |
11724 | { | |
b775012e LM |
11725 | /* Check if this is a new/duplicated location or a duplicated |
11726 | location that had its condition modified. If so, we want to send | |
11727 | its condition to the target if evaluation of conditions is taking | |
11728 | place there. */ | |
11729 | if ((*loc2p)->condition_changed == condition_modified | |
11730 | && (last_addr != old_loc->address | |
11731 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11732 | { |
b775012e LM |
11733 | force_breakpoint_reinsertion (*loc2p); |
11734 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11735 | } |
b775012e LM |
11736 | |
11737 | if (*loc2p == old_loc) | |
11738 | found_object = 1; | |
c7d46a38 | 11739 | } |
74960c60 | 11740 | |
b775012e LM |
11741 | /* We have already handled this address, update it so that we don't |
11742 | have to go through updates again. */ | |
11743 | last_addr = old_loc->address; | |
11744 | ||
11745 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11746 | if (!found_object) | |
11747 | force_breakpoint_reinsertion (old_loc); | |
11748 | ||
4a64f543 MS |
11749 | /* If this location is no longer present, and inserted, look if |
11750 | there's maybe a new location at the same address. If so, | |
11751 | mark that one inserted, and don't remove this one. This is | |
11752 | needed so that we don't have a time window where a breakpoint | |
11753 | at certain location is not inserted. */ | |
74960c60 | 11754 | |
876fa593 | 11755 | if (old_loc->inserted) |
0d381245 | 11756 | { |
4a64f543 MS |
11757 | /* If the location is inserted now, we might have to remove |
11758 | it. */ | |
74960c60 | 11759 | |
876fa593 | 11760 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11761 | { |
4a64f543 MS |
11762 | /* The location is still present in the location list, |
11763 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11764 | keep_in_target = 1; |
74960c60 VP |
11765 | } |
11766 | else | |
11767 | { | |
b775012e LM |
11768 | /* This location still exists, but it won't be kept in the |
11769 | target since it may have been disabled. We proceed to | |
11770 | remove its target-side condition. */ | |
11771 | ||
4a64f543 MS |
11772 | /* The location is either no longer present, or got |
11773 | disabled. See if there's another location at the | |
11774 | same address, in which case we don't need to remove | |
11775 | this one from the target. */ | |
876fa593 | 11776 | |
2bdf28a0 | 11777 | /* OLD_LOC comes from existing struct breakpoint. */ |
cb1e4e32 | 11778 | if (bl_address_is_meaningful (old_loc)) |
876fa593 | 11779 | { |
876fa593 | 11780 | for (loc2p = locp; |
f5336ca5 | 11781 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 11782 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
11783 | loc2p++) |
11784 | { | |
11785 | struct bp_location *loc2 = *loc2p; | |
11786 | ||
2d134ed3 | 11787 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11788 | { |
85d721b8 PA |
11789 | /* Read watchpoint locations are switched to |
11790 | access watchpoints, if the former are not | |
11791 | supported, but the latter are. */ | |
11792 | if (is_hardware_watchpoint (old_loc->owner)) | |
11793 | { | |
11794 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11795 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11796 | } | |
11797 | ||
934709f0 PW |
11798 | /* loc2 is a duplicated location. We need to check |
11799 | if it should be inserted in case it will be | |
11800 | unduplicated. */ | |
11801 | if (loc2 != old_loc | |
11802 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 11803 | { |
934709f0 | 11804 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11805 | keep_in_target = 1; |
11806 | break; | |
11807 | } | |
876fa593 JK |
11808 | } |
11809 | } | |
11810 | } | |
74960c60 VP |
11811 | } |
11812 | ||
20874c92 VP |
11813 | if (!keep_in_target) |
11814 | { | |
834c0d03 | 11815 | if (remove_breakpoint (old_loc)) |
20874c92 | 11816 | { |
4a64f543 MS |
11817 | /* This is just about all we can do. We could keep |
11818 | this location on the global list, and try to | |
11819 | remove it next time, but there's no particular | |
11820 | reason why we will succeed next time. | |
20874c92 | 11821 | |
4a64f543 MS |
11822 | Note that at this point, old_loc->owner is still |
11823 | valid, as delete_breakpoint frees the breakpoint | |
11824 | only after calling us. */ | |
3e43a32a MS |
11825 | printf_filtered (_("warning: Error removing " |
11826 | "breakpoint %d\n"), | |
876fa593 | 11827 | old_loc->owner->number); |
20874c92 VP |
11828 | } |
11829 | removed = 1; | |
11830 | } | |
0d381245 | 11831 | } |
74960c60 VP |
11832 | |
11833 | if (!found_object) | |
1c5cfe86 | 11834 | { |
fbea99ea | 11835 | if (removed && target_is_non_stop_p () |
1cf4d951 | 11836 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 11837 | { |
db82e815 PA |
11838 | /* This location was removed from the target. In |
11839 | non-stop mode, a race condition is possible where | |
11840 | we've removed a breakpoint, but stop events for that | |
11841 | breakpoint are already queued and will arrive later. | |
11842 | We apply an heuristic to be able to distinguish such | |
11843 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11844 | breakpoint location for a bit, and will retire it | |
11845 | after we see some number of events. The theory here | |
11846 | is that reporting of events should, "on the average", | |
11847 | be fair, so after a while we'll see events from all | |
11848 | threads that have anything of interest, and no longer | |
11849 | need to keep this breakpoint location around. We | |
11850 | don't hold locations forever so to reduce chances of | |
11851 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11852 | SIGTRAP. | |
11853 | ||
11854 | The heuristic failing can be disastrous on | |
11855 | decr_pc_after_break targets. | |
11856 | ||
11857 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11858 | if we fail to recognize a late breakpoint SIGTRAP, | |
11859 | because events_till_retirement has reached 0 too | |
11860 | soon, we'll fail to do the PC adjustment, and report | |
11861 | a random SIGTRAP to the user. When the user resumes | |
11862 | the inferior, it will most likely immediately crash | |
2dec564e | 11863 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11864 | corrupted, because of being resumed e.g., in the |
11865 | middle of a multi-byte instruction, or skipped a | |
11866 | one-byte instruction. This was actually seen happen | |
11867 | on native x86-linux, and should be less rare on | |
11868 | targets that do not support new thread events, like | |
11869 | remote, due to the heuristic depending on | |
11870 | thread_count. | |
11871 | ||
11872 | Mistaking a random SIGTRAP for a breakpoint trap | |
11873 | causes similar symptoms (PC adjustment applied when | |
11874 | it shouldn't), but then again, playing with SIGTRAPs | |
11875 | behind the debugger's back is asking for trouble. | |
11876 | ||
11877 | Since hardware watchpoint traps are always | |
11878 | distinguishable from other traps, so we don't need to | |
11879 | apply keep hardware watchpoint moribund locations | |
11880 | around. We simply always ignore hardware watchpoint | |
11881 | traps we can no longer explain. */ | |
11882 | ||
876fa593 JK |
11883 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
11884 | old_loc->owner = NULL; | |
20874c92 | 11885 | |
1123588c | 11886 | moribund_locations.push_back (old_loc); |
1c5cfe86 PA |
11887 | } |
11888 | else | |
f431efe5 PA |
11889 | { |
11890 | old_loc->owner = NULL; | |
11891 | decref_bp_location (&old_loc); | |
11892 | } | |
20874c92 | 11893 | } |
74960c60 | 11894 | } |
1c5cfe86 | 11895 | |
348d480f PA |
11896 | /* Rescan breakpoints at the same address and section, marking the |
11897 | first one as "first" and any others as "duplicates". This is so | |
11898 | that the bpt instruction is only inserted once. If we have a | |
11899 | permanent breakpoint at the same place as BPT, make that one the | |
11900 | official one, and the rest as duplicates. Permanent breakpoints | |
11901 | are sorted first for the same address. | |
11902 | ||
11903 | Do the same for hardware watchpoints, but also considering the | |
11904 | watchpoint's type (regular/access/read) and length. */ | |
11905 | ||
11906 | bp_loc_first = NULL; | |
11907 | wp_loc_first = NULL; | |
11908 | awp_loc_first = NULL; | |
11909 | rwp_loc_first = NULL; | |
11910 | ALL_BP_LOCATIONS (loc, locp) | |
11911 | { | |
11912 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11913 | non-NULL. */ | |
348d480f | 11914 | struct bp_location **loc_first_p; |
d3fbdd86 | 11915 | b = loc->owner; |
348d480f | 11916 | |
6f380991 | 11917 | if (!unduplicated_should_be_inserted (loc) |
cb1e4e32 | 11918 | || !bl_address_is_meaningful (loc) |
1e4d1764 YQ |
11919 | /* Don't detect duplicate for tracepoint locations because they are |
11920 | never duplicated. See the comments in field `duplicate' of | |
11921 | `struct bp_location'. */ | |
348d480f | 11922 | || is_tracepoint (b)) |
b775012e LM |
11923 | { |
11924 | /* Clear the condition modification flag. */ | |
11925 | loc->condition_changed = condition_unchanged; | |
11926 | continue; | |
11927 | } | |
348d480f | 11928 | |
348d480f PA |
11929 | if (b->type == bp_hardware_watchpoint) |
11930 | loc_first_p = &wp_loc_first; | |
11931 | else if (b->type == bp_read_watchpoint) | |
11932 | loc_first_p = &rwp_loc_first; | |
11933 | else if (b->type == bp_access_watchpoint) | |
11934 | loc_first_p = &awp_loc_first; | |
11935 | else | |
11936 | loc_first_p = &bp_loc_first; | |
11937 | ||
11938 | if (*loc_first_p == NULL | |
11939 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
11940 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
11941 | { | |
11942 | *loc_first_p = loc; | |
11943 | loc->duplicate = 0; | |
b775012e LM |
11944 | |
11945 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
11946 | { | |
11947 | loc->needs_update = 1; | |
11948 | /* Clear the condition modification flag. */ | |
11949 | loc->condition_changed = condition_unchanged; | |
11950 | } | |
348d480f PA |
11951 | continue; |
11952 | } | |
11953 | ||
934709f0 PW |
11954 | |
11955 | /* This and the above ensure the invariant that the first location | |
11956 | is not duplicated, and is the inserted one. | |
11957 | All following are marked as duplicated, and are not inserted. */ | |
11958 | if (loc->inserted) | |
11959 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11960 | loc->duplicate = 1; |
11961 | ||
b775012e LM |
11962 | /* Clear the condition modification flag. */ |
11963 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
11964 | } |
11965 | ||
a25a5a45 | 11966 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 11967 | { |
04086b45 | 11968 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
11969 | insert_breakpoint_locations (); |
11970 | else | |
11971 | { | |
44702360 PA |
11972 | /* Even though the caller told us to not insert new |
11973 | locations, we may still need to update conditions on the | |
11974 | target's side of breakpoints that were already inserted | |
11975 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
11976 | only update conditions for locations that are marked |
11977 | "needs_update". */ | |
11978 | update_inserted_breakpoint_locations (); | |
11979 | } | |
11980 | } | |
348d480f | 11981 | |
04086b45 | 11982 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 11983 | download_tracepoint_locations (); |
348d480f PA |
11984 | } |
11985 | ||
11986 | void | |
11987 | breakpoint_retire_moribund (void) | |
11988 | { | |
1123588c TT |
11989 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
11990 | { | |
11991 | struct bp_location *loc = moribund_locations[ix]; | |
11992 | if (--(loc->events_till_retirement) == 0) | |
11993 | { | |
11994 | decref_bp_location (&loc); | |
11995 | unordered_remove (moribund_locations, ix); | |
11996 | --ix; | |
11997 | } | |
11998 | } | |
348d480f PA |
11999 | } |
12000 | ||
12001 | static void | |
44702360 | 12002 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12003 | { |
348d480f | 12004 | |
a70b8144 | 12005 | try |
492d29ea PA |
12006 | { |
12007 | update_global_location_list (insert_mode); | |
12008 | } | |
230d2906 | 12009 | catch (const gdb_exception_error &e) |
492d29ea PA |
12010 | { |
12011 | } | |
348d480f PA |
12012 | } |
12013 | ||
12014 | /* Clear BKP from a BPS. */ | |
12015 | ||
12016 | static void | |
12017 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12018 | { | |
12019 | bpstat bs; | |
12020 | ||
12021 | for (bs = bps; bs; bs = bs->next) | |
12022 | if (bs->breakpoint_at == bpt) | |
12023 | { | |
12024 | bs->breakpoint_at = NULL; | |
12025 | bs->old_val = NULL; | |
12026 | /* bs->commands will be freed later. */ | |
12027 | } | |
12028 | } | |
12029 | ||
12030 | /* Callback for iterate_over_threads. */ | |
12031 | static int | |
12032 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12033 | { | |
9a3c8263 | 12034 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12035 | |
12036 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12037 | return 0; | |
12038 | } | |
12039 | ||
12040 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12041 | callbacks. */ | |
12042 | ||
12043 | static void | |
12044 | say_where (struct breakpoint *b) | |
12045 | { | |
12046 | struct value_print_options opts; | |
12047 | ||
12048 | get_user_print_options (&opts); | |
12049 | ||
12050 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12051 | single string. */ | |
12052 | if (b->loc == NULL) | |
12053 | { | |
f00aae0f KS |
12054 | /* For pending locations, the output differs slightly based |
12055 | on b->extra_string. If this is non-NULL, it contains either | |
12056 | a condition or dprintf arguments. */ | |
12057 | if (b->extra_string == NULL) | |
12058 | { | |
12059 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12060 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12061 | } |
12062 | else if (b->type == bp_dprintf) | |
12063 | { | |
12064 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12065 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12066 | b->extra_string); |
12067 | } | |
12068 | else | |
12069 | { | |
12070 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12071 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12072 | b->extra_string); |
12073 | } | |
348d480f PA |
12074 | } |
12075 | else | |
12076 | { | |
2f202fde | 12077 | if (opts.addressprint || b->loc->symtab == NULL) |
6a831f06 PA |
12078 | printf_filtered (" at %ps", |
12079 | styled_string (address_style.style (), | |
12080 | paddress (b->loc->gdbarch, | |
12081 | b->loc->address))); | |
2f202fde | 12082 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12083 | { |
12084 | /* If there is a single location, we can print the location | |
12085 | more nicely. */ | |
12086 | if (b->loc->next == NULL) | |
0bb296cb | 12087 | { |
6a831f06 PA |
12088 | const char *filename |
12089 | = symtab_to_filename_for_display (b->loc->symtab); | |
12090 | printf_filtered (": file %ps, line %d.", | |
12091 | styled_string (file_name_style.style (), | |
12092 | filename), | |
0bb296cb TT |
12093 | b->loc->line_number); |
12094 | } | |
f8eba3c6 TT |
12095 | else |
12096 | /* This is not ideal, but each location may have a | |
12097 | different file name, and this at least reflects the | |
12098 | real situation somewhat. */ | |
f00aae0f | 12099 | printf_filtered (": %s.", |
d28cd78a | 12100 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12101 | } |
348d480f PA |
12102 | |
12103 | if (b->loc->next) | |
12104 | { | |
12105 | struct bp_location *loc = b->loc; | |
12106 | int n = 0; | |
12107 | for (; loc; loc = loc->next) | |
12108 | ++n; | |
12109 | printf_filtered (" (%d locations)", n); | |
12110 | } | |
12111 | } | |
12112 | } | |
12113 | ||
5f486660 | 12114 | bp_location::~bp_location () |
348d480f | 12115 | { |
5f486660 | 12116 | xfree (function_name); |
348d480f PA |
12117 | } |
12118 | ||
c1fc2657 | 12119 | /* Destructor for the breakpoint base class. */ |
348d480f | 12120 | |
c1fc2657 | 12121 | breakpoint::~breakpoint () |
348d480f | 12122 | { |
c1fc2657 SM |
12123 | xfree (this->cond_string); |
12124 | xfree (this->extra_string); | |
348d480f PA |
12125 | } |
12126 | ||
2060206e PA |
12127 | static struct bp_location * |
12128 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12129 | { |
5f486660 | 12130 | return new bp_location (self); |
348d480f PA |
12131 | } |
12132 | ||
2060206e PA |
12133 | static void |
12134 | base_breakpoint_re_set (struct breakpoint *b) | |
12135 | { | |
12136 | /* Nothing to re-set. */ | |
12137 | } | |
12138 | ||
12139 | #define internal_error_pure_virtual_called() \ | |
12140 | gdb_assert_not_reached ("pure virtual function called") | |
12141 | ||
12142 | static int | |
12143 | base_breakpoint_insert_location (struct bp_location *bl) | |
12144 | { | |
12145 | internal_error_pure_virtual_called (); | |
12146 | } | |
12147 | ||
12148 | static int | |
73971819 PA |
12149 | base_breakpoint_remove_location (struct bp_location *bl, |
12150 | enum remove_bp_reason reason) | |
2060206e PA |
12151 | { |
12152 | internal_error_pure_virtual_called (); | |
12153 | } | |
12154 | ||
12155 | static int | |
12156 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12157 | const address_space *aspace, |
09ac7c10 TT |
12158 | CORE_ADDR bp_addr, |
12159 | const struct target_waitstatus *ws) | |
2060206e PA |
12160 | { |
12161 | internal_error_pure_virtual_called (); | |
12162 | } | |
12163 | ||
12164 | static void | |
12165 | base_breakpoint_check_status (bpstat bs) | |
12166 | { | |
12167 | /* Always stop. */ | |
12168 | } | |
12169 | ||
12170 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12171 | errors. */ | |
12172 | ||
12173 | static int | |
12174 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12175 | { | |
12176 | internal_error_pure_virtual_called (); | |
12177 | } | |
12178 | ||
12179 | /* A "resources_needed" breakpoint_ops method that just internal | |
12180 | errors. */ | |
12181 | ||
12182 | static int | |
12183 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12184 | { | |
12185 | internal_error_pure_virtual_called (); | |
12186 | } | |
12187 | ||
12188 | static enum print_stop_action | |
12189 | base_breakpoint_print_it (bpstat bs) | |
12190 | { | |
12191 | internal_error_pure_virtual_called (); | |
12192 | } | |
12193 | ||
12194 | static void | |
12195 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12196 | struct ui_out *uiout) | |
12197 | { | |
12198 | /* nothing */ | |
12199 | } | |
12200 | ||
12201 | static void | |
12202 | base_breakpoint_print_mention (struct breakpoint *b) | |
12203 | { | |
12204 | internal_error_pure_virtual_called (); | |
12205 | } | |
12206 | ||
12207 | static void | |
12208 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12209 | { | |
12210 | internal_error_pure_virtual_called (); | |
12211 | } | |
12212 | ||
983af33b | 12213 | static void |
f00aae0f KS |
12214 | base_breakpoint_create_sals_from_location |
12215 | (const struct event_location *location, | |
12216 | struct linespec_result *canonical, | |
12217 | enum bptype type_wanted) | |
983af33b SDJ |
12218 | { |
12219 | internal_error_pure_virtual_called (); | |
12220 | } | |
12221 | ||
12222 | static void | |
12223 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12224 | struct linespec_result *c, | |
e1e01040 PA |
12225 | gdb::unique_xmalloc_ptr<char> cond_string, |
12226 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12227 | enum bptype type_wanted, |
12228 | enum bpdisp disposition, | |
12229 | int thread, | |
12230 | int task, int ignore_count, | |
12231 | const struct breakpoint_ops *o, | |
12232 | int from_tty, int enabled, | |
44f238bb | 12233 | int internal, unsigned flags) |
983af33b SDJ |
12234 | { |
12235 | internal_error_pure_virtual_called (); | |
12236 | } | |
12237 | ||
6c5b2ebe | 12238 | static std::vector<symtab_and_line> |
f00aae0f KS |
12239 | base_breakpoint_decode_location (struct breakpoint *b, |
12240 | const struct event_location *location, | |
6c5b2ebe | 12241 | struct program_space *search_pspace) |
983af33b SDJ |
12242 | { |
12243 | internal_error_pure_virtual_called (); | |
12244 | } | |
12245 | ||
ab04a2af TT |
12246 | /* The default 'explains_signal' method. */ |
12247 | ||
47591c29 | 12248 | static int |
427cd150 | 12249 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12250 | { |
47591c29 | 12251 | return 1; |
ab04a2af TT |
12252 | } |
12253 | ||
9d6e6e84 HZ |
12254 | /* The default "after_condition_true" method. */ |
12255 | ||
12256 | static void | |
12257 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12258 | { | |
12259 | /* Nothing to do. */ | |
12260 | } | |
12261 | ||
ab04a2af | 12262 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12263 | { |
2060206e PA |
12264 | base_breakpoint_allocate_location, |
12265 | base_breakpoint_re_set, | |
12266 | base_breakpoint_insert_location, | |
12267 | base_breakpoint_remove_location, | |
12268 | base_breakpoint_breakpoint_hit, | |
12269 | base_breakpoint_check_status, | |
12270 | base_breakpoint_resources_needed, | |
12271 | base_breakpoint_works_in_software_mode, | |
12272 | base_breakpoint_print_it, | |
12273 | NULL, | |
12274 | base_breakpoint_print_one_detail, | |
12275 | base_breakpoint_print_mention, | |
983af33b | 12276 | base_breakpoint_print_recreate, |
5f700d83 | 12277 | base_breakpoint_create_sals_from_location, |
983af33b | 12278 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12279 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12280 | base_breakpoint_explains_signal, |
12281 | base_breakpoint_after_condition_true, | |
2060206e PA |
12282 | }; |
12283 | ||
12284 | /* Default breakpoint_ops methods. */ | |
12285 | ||
12286 | static void | |
348d480f PA |
12287 | bkpt_re_set (struct breakpoint *b) |
12288 | { | |
06edf0c0 | 12289 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12290 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12291 | { |
f00aae0f | 12292 | /* Anything without a location can't be re-set. */ |
348d480f | 12293 | delete_breakpoint (b); |
06edf0c0 | 12294 | return; |
348d480f | 12295 | } |
06edf0c0 PA |
12296 | |
12297 | breakpoint_re_set_default (b); | |
348d480f PA |
12298 | } |
12299 | ||
2060206e | 12300 | static int |
348d480f PA |
12301 | bkpt_insert_location (struct bp_location *bl) |
12302 | { | |
cd6c3b4f YQ |
12303 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12304 | ||
579c6ad9 | 12305 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12306 | bl->target_info.placed_address = addr; |
12307 | ||
348d480f | 12308 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12309 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12310 | else |
7c16b83e | 12311 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12312 | } |
12313 | ||
2060206e | 12314 | static int |
73971819 | 12315 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12316 | { |
12317 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12318 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12319 | else | |
73971819 | 12320 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12321 | } |
12322 | ||
2060206e | 12323 | static int |
348d480f | 12324 | bkpt_breakpoint_hit (const struct bp_location *bl, |
bd522513 | 12325 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12326 | const struct target_waitstatus *ws) |
348d480f | 12327 | { |
09ac7c10 | 12328 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12329 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12330 | return 0; |
12331 | ||
348d480f PA |
12332 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12333 | aspace, bp_addr)) | |
12334 | return 0; | |
12335 | ||
12336 | if (overlay_debugging /* unmapped overlay section */ | |
12337 | && section_is_overlay (bl->section) | |
12338 | && !section_is_mapped (bl->section)) | |
12339 | return 0; | |
12340 | ||
12341 | return 1; | |
12342 | } | |
12343 | ||
cd1608cc PA |
12344 | static int |
12345 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12346 | const address_space *aspace, CORE_ADDR bp_addr, |
cd1608cc PA |
12347 | const struct target_waitstatus *ws) |
12348 | { | |
12349 | if (dprintf_style == dprintf_style_agent | |
12350 | && target_can_run_breakpoint_commands ()) | |
12351 | { | |
12352 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12353 | for this address it must be for a breakpoint that happens to | |
12354 | be set at the same address. */ | |
12355 | return 0; | |
12356 | } | |
12357 | ||
12358 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12359 | } | |
12360 | ||
2060206e | 12361 | static int |
348d480f PA |
12362 | bkpt_resources_needed (const struct bp_location *bl) |
12363 | { | |
12364 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12365 | ||
12366 | return 1; | |
12367 | } | |
12368 | ||
2060206e | 12369 | static enum print_stop_action |
348d480f PA |
12370 | bkpt_print_it (bpstat bs) |
12371 | { | |
348d480f PA |
12372 | struct breakpoint *b; |
12373 | const struct bp_location *bl; | |
001c8c33 | 12374 | int bp_temp; |
79a45e25 | 12375 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12376 | |
12377 | gdb_assert (bs->bp_location_at != NULL); | |
12378 | ||
12379 | bl = bs->bp_location_at; | |
12380 | b = bs->breakpoint_at; | |
12381 | ||
001c8c33 PA |
12382 | bp_temp = b->disposition == disp_del; |
12383 | if (bl->address != bl->requested_address) | |
12384 | breakpoint_adjustment_warning (bl->requested_address, | |
12385 | bl->address, | |
12386 | b->number, 1); | |
12387 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12388 | maybe_print_thread_hit_breakpoint (uiout); |
12389 | ||
112e8700 | 12390 | if (uiout->is_mi_like_p ()) |
348d480f | 12391 | { |
112e8700 | 12392 | uiout->field_string ("reason", |
001c8c33 | 12393 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12394 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12395 | } |
6a831f06 PA |
12396 | if (bp_temp) |
12397 | uiout->message ("Temporary breakpoint %pF, ", | |
12398 | signed_field ("bkptno", b->number)); | |
12399 | else | |
12400 | uiout->message ("Breakpoint %pF, ", | |
12401 | signed_field ("bkptno", b->number)); | |
06edf0c0 | 12402 | |
001c8c33 | 12403 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12404 | } |
12405 | ||
2060206e | 12406 | static void |
06edf0c0 PA |
12407 | bkpt_print_mention (struct breakpoint *b) |
12408 | { | |
112e8700 | 12409 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12410 | return; |
12411 | ||
12412 | switch (b->type) | |
12413 | { | |
12414 | case bp_breakpoint: | |
12415 | case bp_gnu_ifunc_resolver: | |
12416 | if (b->disposition == disp_del) | |
12417 | printf_filtered (_("Temporary breakpoint")); | |
12418 | else | |
12419 | printf_filtered (_("Breakpoint")); | |
12420 | printf_filtered (_(" %d"), b->number); | |
12421 | if (b->type == bp_gnu_ifunc_resolver) | |
12422 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12423 | break; | |
12424 | case bp_hardware_breakpoint: | |
12425 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12426 | break; | |
e7e0cddf SS |
12427 | case bp_dprintf: |
12428 | printf_filtered (_("Dprintf %d"), b->number); | |
12429 | break; | |
06edf0c0 PA |
12430 | } |
12431 | ||
12432 | say_where (b); | |
12433 | } | |
12434 | ||
2060206e | 12435 | static void |
06edf0c0 PA |
12436 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12437 | { | |
12438 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12439 | fprintf_unfiltered (fp, "tbreak"); | |
12440 | else if (tp->type == bp_breakpoint) | |
12441 | fprintf_unfiltered (fp, "break"); | |
12442 | else if (tp->type == bp_hardware_breakpoint | |
12443 | && tp->disposition == disp_del) | |
12444 | fprintf_unfiltered (fp, "thbreak"); | |
12445 | else if (tp->type == bp_hardware_breakpoint) | |
12446 | fprintf_unfiltered (fp, "hbreak"); | |
12447 | else | |
12448 | internal_error (__FILE__, __LINE__, | |
12449 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12450 | ||
f00aae0f | 12451 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12452 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12453 | |
12454 | /* Print out extra_string if this breakpoint is pending. It might | |
12455 | contain, for example, conditions that were set by the user. */ | |
12456 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12457 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12458 | ||
dd11a36c | 12459 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12460 | } |
12461 | ||
983af33b | 12462 | static void |
f00aae0f KS |
12463 | bkpt_create_sals_from_location (const struct event_location *location, |
12464 | struct linespec_result *canonical, | |
12465 | enum bptype type_wanted) | |
983af33b | 12466 | { |
f00aae0f | 12467 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12468 | } |
12469 | ||
12470 | static void | |
12471 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12472 | struct linespec_result *canonical, | |
e1e01040 PA |
12473 | gdb::unique_xmalloc_ptr<char> cond_string, |
12474 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12475 | enum bptype type_wanted, |
12476 | enum bpdisp disposition, | |
12477 | int thread, | |
12478 | int task, int ignore_count, | |
12479 | const struct breakpoint_ops *ops, | |
12480 | int from_tty, int enabled, | |
44f238bb | 12481 | int internal, unsigned flags) |
983af33b | 12482 | { |
023fa29b | 12483 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12484 | std::move (cond_string), |
12485 | std::move (extra_string), | |
e7e0cddf | 12486 | type_wanted, |
983af33b SDJ |
12487 | disposition, thread, task, |
12488 | ignore_count, ops, from_tty, | |
44f238bb | 12489 | enabled, internal, flags); |
983af33b SDJ |
12490 | } |
12491 | ||
6c5b2ebe | 12492 | static std::vector<symtab_and_line> |
f00aae0f KS |
12493 | bkpt_decode_location (struct breakpoint *b, |
12494 | const struct event_location *location, | |
6c5b2ebe | 12495 | struct program_space *search_pspace) |
983af33b | 12496 | { |
6c5b2ebe | 12497 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12498 | } |
12499 | ||
06edf0c0 PA |
12500 | /* Virtual table for internal breakpoints. */ |
12501 | ||
12502 | static void | |
12503 | internal_bkpt_re_set (struct breakpoint *b) | |
12504 | { | |
12505 | switch (b->type) | |
12506 | { | |
12507 | /* Delete overlay event and longjmp master breakpoints; they | |
12508 | will be reset later by breakpoint_re_set. */ | |
12509 | case bp_overlay_event: | |
12510 | case bp_longjmp_master: | |
12511 | case bp_std_terminate_master: | |
12512 | case bp_exception_master: | |
12513 | delete_breakpoint (b); | |
12514 | break; | |
12515 | ||
12516 | /* This breakpoint is special, it's set up when the inferior | |
12517 | starts and we really don't want to touch it. */ | |
12518 | case bp_shlib_event: | |
12519 | ||
12520 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12521 | it is set up, we do not want to touch it. */ | |
12522 | case bp_thread_event: | |
12523 | break; | |
12524 | } | |
12525 | } | |
12526 | ||
12527 | static void | |
12528 | internal_bkpt_check_status (bpstat bs) | |
12529 | { | |
a9b3a50f PA |
12530 | if (bs->breakpoint_at->type == bp_shlib_event) |
12531 | { | |
12532 | /* If requested, stop when the dynamic linker notifies GDB of | |
12533 | events. This allows the user to get control and place | |
12534 | breakpoints in initializer routines for dynamically loaded | |
12535 | objects (among other things). */ | |
12536 | bs->stop = stop_on_solib_events; | |
12537 | bs->print = stop_on_solib_events; | |
12538 | } | |
12539 | else | |
12540 | bs->stop = 0; | |
06edf0c0 PA |
12541 | } |
12542 | ||
12543 | static enum print_stop_action | |
12544 | internal_bkpt_print_it (bpstat bs) | |
12545 | { | |
06edf0c0 | 12546 | struct breakpoint *b; |
06edf0c0 | 12547 | |
06edf0c0 PA |
12548 | b = bs->breakpoint_at; |
12549 | ||
06edf0c0 PA |
12550 | switch (b->type) |
12551 | { | |
348d480f PA |
12552 | case bp_shlib_event: |
12553 | /* Did we stop because the user set the stop_on_solib_events | |
12554 | variable? (If so, we report this as a generic, "Stopped due | |
12555 | to shlib event" message.) */ | |
edcc5120 | 12556 | print_solib_event (0); |
348d480f PA |
12557 | break; |
12558 | ||
12559 | case bp_thread_event: | |
12560 | /* Not sure how we will get here. | |
12561 | GDB should not stop for these breakpoints. */ | |
12562 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12563 | break; |
12564 | ||
12565 | case bp_overlay_event: | |
12566 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12567 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12568 | break; |
12569 | ||
12570 | case bp_longjmp_master: | |
12571 | /* These should never be enabled. */ | |
12572 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12573 | break; |
12574 | ||
12575 | case bp_std_terminate_master: | |
12576 | /* These should never be enabled. */ | |
12577 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12578 | "gdb should not stop!\n")); | |
348d480f PA |
12579 | break; |
12580 | ||
12581 | case bp_exception_master: | |
12582 | /* These should never be enabled. */ | |
12583 | printf_filtered (_("Exception Master Breakpoint: " | |
12584 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12585 | break; |
12586 | } | |
12587 | ||
001c8c33 | 12588 | return PRINT_NOTHING; |
06edf0c0 PA |
12589 | } |
12590 | ||
12591 | static void | |
12592 | internal_bkpt_print_mention (struct breakpoint *b) | |
12593 | { | |
12594 | /* Nothing to mention. These breakpoints are internal. */ | |
12595 | } | |
12596 | ||
06edf0c0 PA |
12597 | /* Virtual table for momentary breakpoints */ |
12598 | ||
12599 | static void | |
12600 | momentary_bkpt_re_set (struct breakpoint *b) | |
12601 | { | |
12602 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12603 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12604 | Otherwise these should have been blown away via the cleanup chain |
12605 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12606 | } | |
12607 | ||
12608 | static void | |
12609 | momentary_bkpt_check_status (bpstat bs) | |
12610 | { | |
12611 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12612 | } | |
12613 | ||
12614 | static enum print_stop_action | |
12615 | momentary_bkpt_print_it (bpstat bs) | |
12616 | { | |
001c8c33 | 12617 | return PRINT_UNKNOWN; |
348d480f PA |
12618 | } |
12619 | ||
06edf0c0 PA |
12620 | static void |
12621 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12622 | { |
06edf0c0 | 12623 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12624 | } |
12625 | ||
e2e4d78b JK |
12626 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12627 | ||
12628 | It gets cleared already on the removal of the first one of such placed | |
12629 | breakpoints. This is OK as they get all removed altogether. */ | |
12630 | ||
c1fc2657 | 12631 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 12632 | { |
c1fc2657 | 12633 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 12634 | |
c1fc2657 | 12635 | if (tp != NULL) |
e2e4d78b | 12636 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
12637 | } |
12638 | ||
55aa24fb SDJ |
12639 | /* Specific methods for probe breakpoints. */ |
12640 | ||
12641 | static int | |
12642 | bkpt_probe_insert_location (struct bp_location *bl) | |
12643 | { | |
12644 | int v = bkpt_insert_location (bl); | |
12645 | ||
12646 | if (v == 0) | |
12647 | { | |
12648 | /* The insertion was successful, now let's set the probe's semaphore | |
12649 | if needed. */ | |
935676c9 | 12650 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb SDJ |
12651 | } |
12652 | ||
12653 | return v; | |
12654 | } | |
12655 | ||
12656 | static int | |
73971819 PA |
12657 | bkpt_probe_remove_location (struct bp_location *bl, |
12658 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
12659 | { |
12660 | /* Let's clear the semaphore before removing the location. */ | |
935676c9 | 12661 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb | 12662 | |
73971819 | 12663 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
12664 | } |
12665 | ||
12666 | static void | |
f00aae0f | 12667 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12668 | struct linespec_result *canonical, |
f00aae0f | 12669 | enum bptype type_wanted) |
55aa24fb SDJ |
12670 | { |
12671 | struct linespec_sals lsal; | |
12672 | ||
c2f4122d | 12673 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
12674 | lsal.canonical |
12675 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12676 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
12677 | } |
12678 | ||
6c5b2ebe | 12679 | static std::vector<symtab_and_line> |
f00aae0f KS |
12680 | bkpt_probe_decode_location (struct breakpoint *b, |
12681 | const struct event_location *location, | |
6c5b2ebe | 12682 | struct program_space *search_pspace) |
55aa24fb | 12683 | { |
6c5b2ebe PA |
12684 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
12685 | if (sals.empty ()) | |
55aa24fb | 12686 | error (_("probe not found")); |
6c5b2ebe | 12687 | return sals; |
55aa24fb SDJ |
12688 | } |
12689 | ||
348d480f | 12690 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12691 | |
348d480f PA |
12692 | static void |
12693 | tracepoint_re_set (struct breakpoint *b) | |
12694 | { | |
12695 | breakpoint_re_set_default (b); | |
12696 | } | |
876fa593 | 12697 | |
348d480f PA |
12698 | static int |
12699 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12700 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12701 | const struct target_waitstatus *ws) |
348d480f PA |
12702 | { |
12703 | /* By definition, the inferior does not report stops at | |
12704 | tracepoints. */ | |
12705 | return 0; | |
74960c60 VP |
12706 | } |
12707 | ||
12708 | static void | |
348d480f PA |
12709 | tracepoint_print_one_detail (const struct breakpoint *self, |
12710 | struct ui_out *uiout) | |
74960c60 | 12711 | { |
d9b3f62e | 12712 | struct tracepoint *tp = (struct tracepoint *) self; |
5d9310c4 | 12713 | if (!tp->static_trace_marker_id.empty ()) |
348d480f PA |
12714 | { |
12715 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12716 | |
6a831f06 PA |
12717 | uiout->message ("\tmarker id is %pF\n", |
12718 | string_field ("static-tracepoint-marker-string-id", | |
12719 | tp->static_trace_marker_id.c_str ())); | |
348d480f | 12720 | } |
0d381245 VP |
12721 | } |
12722 | ||
a474d7c2 | 12723 | static void |
348d480f | 12724 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12725 | { |
112e8700 | 12726 | if (current_uiout->is_mi_like_p ()) |
348d480f | 12727 | return; |
cc59ec59 | 12728 | |
348d480f PA |
12729 | switch (b->type) |
12730 | { | |
12731 | case bp_tracepoint: | |
12732 | printf_filtered (_("Tracepoint")); | |
12733 | printf_filtered (_(" %d"), b->number); | |
12734 | break; | |
12735 | case bp_fast_tracepoint: | |
12736 | printf_filtered (_("Fast tracepoint")); | |
12737 | printf_filtered (_(" %d"), b->number); | |
12738 | break; | |
12739 | case bp_static_tracepoint: | |
12740 | printf_filtered (_("Static tracepoint")); | |
12741 | printf_filtered (_(" %d"), b->number); | |
12742 | break; | |
12743 | default: | |
12744 | internal_error (__FILE__, __LINE__, | |
12745 | _("unhandled tracepoint type %d"), (int) b->type); | |
12746 | } | |
12747 | ||
12748 | say_where (b); | |
a474d7c2 PA |
12749 | } |
12750 | ||
348d480f | 12751 | static void |
d9b3f62e | 12752 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12753 | { |
d9b3f62e PA |
12754 | struct tracepoint *tp = (struct tracepoint *) self; |
12755 | ||
12756 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12757 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 12758 | else if (self->type == bp_static_tracepoint) |
348d480f | 12759 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12760 | else if (self->type == bp_tracepoint) |
348d480f PA |
12761 | fprintf_unfiltered (fp, "trace"); |
12762 | else | |
12763 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12764 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12765 | |
f00aae0f | 12766 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12767 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
12768 | print_recreate_thread (self, fp); |
12769 | ||
12770 | if (tp->pass_count) | |
12771 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
12772 | } |
12773 | ||
983af33b | 12774 | static void |
f00aae0f KS |
12775 | tracepoint_create_sals_from_location (const struct event_location *location, |
12776 | struct linespec_result *canonical, | |
12777 | enum bptype type_wanted) | |
983af33b | 12778 | { |
f00aae0f | 12779 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12780 | } |
12781 | ||
12782 | static void | |
12783 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12784 | struct linespec_result *canonical, | |
e1e01040 PA |
12785 | gdb::unique_xmalloc_ptr<char> cond_string, |
12786 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12787 | enum bptype type_wanted, |
12788 | enum bpdisp disposition, | |
12789 | int thread, | |
12790 | int task, int ignore_count, | |
12791 | const struct breakpoint_ops *ops, | |
12792 | int from_tty, int enabled, | |
44f238bb | 12793 | int internal, unsigned flags) |
983af33b | 12794 | { |
023fa29b | 12795 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12796 | std::move (cond_string), |
12797 | std::move (extra_string), | |
e7e0cddf | 12798 | type_wanted, |
983af33b SDJ |
12799 | disposition, thread, task, |
12800 | ignore_count, ops, from_tty, | |
44f238bb | 12801 | enabled, internal, flags); |
983af33b SDJ |
12802 | } |
12803 | ||
6c5b2ebe | 12804 | static std::vector<symtab_and_line> |
f00aae0f KS |
12805 | tracepoint_decode_location (struct breakpoint *b, |
12806 | const struct event_location *location, | |
6c5b2ebe | 12807 | struct program_space *search_pspace) |
983af33b | 12808 | { |
6c5b2ebe | 12809 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12810 | } |
12811 | ||
2060206e | 12812 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 12813 | |
55aa24fb SDJ |
12814 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
12815 | static probe. */ | |
12816 | ||
12817 | static void | |
f00aae0f KS |
12818 | tracepoint_probe_create_sals_from_location |
12819 | (const struct event_location *location, | |
12820 | struct linespec_result *canonical, | |
12821 | enum bptype type_wanted) | |
55aa24fb SDJ |
12822 | { |
12823 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 12824 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
12825 | } |
12826 | ||
6c5b2ebe | 12827 | static std::vector<symtab_and_line> |
f00aae0f KS |
12828 | tracepoint_probe_decode_location (struct breakpoint *b, |
12829 | const struct event_location *location, | |
6c5b2ebe | 12830 | struct program_space *search_pspace) |
55aa24fb SDJ |
12831 | { |
12832 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 12833 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
12834 | } |
12835 | ||
12836 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
12837 | ||
5c2b4418 HZ |
12838 | /* Dprintf breakpoint_ops methods. */ |
12839 | ||
12840 | static void | |
12841 | dprintf_re_set (struct breakpoint *b) | |
12842 | { | |
12843 | breakpoint_re_set_default (b); | |
12844 | ||
f00aae0f KS |
12845 | /* extra_string should never be non-NULL for dprintf. */ |
12846 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
12847 | |
12848 | /* 1 - connect to target 1, that can run breakpoint commands. | |
12849 | 2 - create a dprintf, which resolves fine. | |
12850 | 3 - disconnect from target 1 | |
12851 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
12852 | ||
12853 | After steps #3/#4, you'll want the dprintf command list to | |
12854 | be updated, because target 1 and 2 may well return different | |
12855 | answers for target_can_run_breakpoint_commands(). | |
12856 | Given absence of finer grained resetting, we get to do | |
12857 | it all the time. */ | |
12858 | if (b->extra_string != NULL) | |
12859 | update_dprintf_command_list (b); | |
12860 | } | |
12861 | ||
2d9442cc HZ |
12862 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
12863 | ||
12864 | static void | |
12865 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
12866 | { | |
f00aae0f | 12867 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 12868 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
12869 | tp->extra_string); |
12870 | print_recreate_thread (tp, fp); | |
12871 | } | |
12872 | ||
9d6e6e84 HZ |
12873 | /* Implement the "after_condition_true" breakpoint_ops method for |
12874 | dprintf. | |
12875 | ||
12876 | dprintf's are implemented with regular commands in their command | |
12877 | list, but we run the commands here instead of before presenting the | |
12878 | stop to the user, as dprintf's don't actually cause a stop. This | |
12879 | also makes it so that the commands of multiple dprintfs at the same | |
12880 | address are all handled. */ | |
12881 | ||
12882 | static void | |
12883 | dprintf_after_condition_true (struct bpstats *bs) | |
12884 | { | |
04afa70c | 12885 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
12886 | struct bpstats *tmp_bs_p = &tmp_bs; |
12887 | ||
12888 | /* dprintf's never cause a stop. This wasn't set in the | |
12889 | check_status hook instead because that would make the dprintf's | |
12890 | condition not be evaluated. */ | |
12891 | bs->stop = 0; | |
12892 | ||
12893 | /* Run the command list here. Take ownership of it instead of | |
12894 | copying. We never want these commands to run later in | |
12895 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
12896 | be set at same address as this dprintf, or even if running the | |
12897 | commands here throws. */ | |
12898 | tmp_bs.commands = bs->commands; | |
12899 | bs->commands = NULL; | |
9d6e6e84 HZ |
12900 | |
12901 | bpstat_do_actions_1 (&tmp_bs_p); | |
12902 | ||
12903 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
12904 | bpstat_do_actions_1 may return early without processing the whole | |
12905 | list. */ | |
9d6e6e84 HZ |
12906 | } |
12907 | ||
983af33b SDJ |
12908 | /* The breakpoint_ops structure to be used on static tracepoints with |
12909 | markers (`-m'). */ | |
12910 | ||
12911 | static void | |
f00aae0f | 12912 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12913 | struct linespec_result *canonical, |
f00aae0f | 12914 | enum bptype type_wanted) |
983af33b SDJ |
12915 | { |
12916 | struct linespec_sals lsal; | |
f00aae0f | 12917 | const char *arg_start, *arg; |
983af33b | 12918 | |
a20714ff | 12919 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 12920 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 12921 | |
f2fc3015 TT |
12922 | std::string str (arg_start, arg - arg_start); |
12923 | const char *ptr = str.c_str (); | |
a20714ff PA |
12924 | canonical->location |
12925 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 12926 | |
8e9e35b1 TT |
12927 | lsal.canonical |
12928 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12929 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
12930 | } |
12931 | ||
12932 | static void | |
12933 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12934 | struct linespec_result *canonical, | |
e1e01040 PA |
12935 | gdb::unique_xmalloc_ptr<char> cond_string, |
12936 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12937 | enum bptype type_wanted, |
12938 | enum bpdisp disposition, | |
12939 | int thread, | |
12940 | int task, int ignore_count, | |
12941 | const struct breakpoint_ops *ops, | |
12942 | int from_tty, int enabled, | |
44f238bb | 12943 | int internal, unsigned flags) |
983af33b | 12944 | { |
6c5b2ebe | 12945 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
12946 | |
12947 | /* If the user is creating a static tracepoint by marker id | |
12948 | (strace -m MARKER_ID), then store the sals index, so that | |
12949 | breakpoint_re_set can try to match up which of the newly | |
12950 | found markers corresponds to this one, and, don't try to | |
12951 | expand multiple locations for each sal, given than SALS | |
12952 | already should contain all sals for MARKER_ID. */ | |
12953 | ||
6c5b2ebe | 12954 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 12955 | { |
6c5b2ebe PA |
12956 | event_location_up location |
12957 | = copy_event_location (canonical->location.get ()); | |
983af33b | 12958 | |
b270e6f9 | 12959 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 12960 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 12961 | std::move (location), NULL, |
e1e01040 PA |
12962 | std::move (cond_string), |
12963 | std::move (extra_string), | |
e7e0cddf | 12964 | type_wanted, disposition, |
983af33b | 12965 | thread, task, ignore_count, ops, |
44f238bb | 12966 | from_tty, enabled, internal, flags, |
983af33b SDJ |
12967 | canonical->special_display); |
12968 | /* Given that its possible to have multiple markers with | |
12969 | the same string id, if the user is creating a static | |
12970 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
12971 | store the sals index, so that breakpoint_re_set can | |
12972 | try to match up which of the newly found markers | |
12973 | corresponds to this one */ | |
12974 | tp->static_trace_marker_id_idx = i; | |
12975 | ||
b270e6f9 | 12976 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
12977 | } |
12978 | } | |
12979 | ||
6c5b2ebe | 12980 | static std::vector<symtab_and_line> |
f00aae0f KS |
12981 | strace_marker_decode_location (struct breakpoint *b, |
12982 | const struct event_location *location, | |
6c5b2ebe | 12983 | struct program_space *search_pspace) |
983af33b SDJ |
12984 | { |
12985 | struct tracepoint *tp = (struct tracepoint *) b; | |
a20714ff | 12986 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 12987 | |
6c5b2ebe PA |
12988 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
12989 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 12990 | { |
6c5b2ebe PA |
12991 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
12992 | sals.resize (1); | |
12993 | return sals; | |
983af33b SDJ |
12994 | } |
12995 | else | |
5d9310c4 | 12996 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
983af33b SDJ |
12997 | } |
12998 | ||
12999 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13000 | ||
13001 | static int | |
13002 | strace_marker_p (struct breakpoint *b) | |
13003 | { | |
13004 | return b->ops == &strace_marker_breakpoint_ops; | |
13005 | } | |
13006 | ||
53a5351d | 13007 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13008 | structures. */ |
c906108c SS |
13009 | |
13010 | void | |
fba45db2 | 13011 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13012 | { |
52f0bd74 | 13013 | struct breakpoint *b; |
c906108c | 13014 | |
8a3fe4f8 | 13015 | gdb_assert (bpt != NULL); |
c906108c | 13016 | |
4a64f543 MS |
13017 | /* Has this bp already been deleted? This can happen because |
13018 | multiple lists can hold pointers to bp's. bpstat lists are | |
13019 | especial culprits. | |
13020 | ||
13021 | One example of this happening is a watchpoint's scope bp. When | |
13022 | the scope bp triggers, we notice that the watchpoint is out of | |
13023 | scope, and delete it. We also delete its scope bp. But the | |
13024 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13025 | That bpstat is then checked for auto-deleting bp's, which are | |
13026 | deleted. | |
13027 | ||
13028 | A real solution to this problem might involve reference counts in | |
13029 | bp's, and/or giving them pointers back to their referencing | |
13030 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13031 | storage when no more references were extent. A cheaper bandaid | |
13032 | was chosen. */ | |
c906108c SS |
13033 | if (bpt->type == bp_none) |
13034 | return; | |
13035 | ||
4a64f543 MS |
13036 | /* At least avoid this stale reference until the reference counting |
13037 | of breakpoints gets resolved. */ | |
d0fb5eae | 13038 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13039 | { |
d0fb5eae | 13040 | struct breakpoint *related; |
3a5c3e22 | 13041 | struct watchpoint *w; |
d0fb5eae JK |
13042 | |
13043 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13044 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13045 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13046 | w = (struct watchpoint *) bpt; |
13047 | else | |
13048 | w = NULL; | |
13049 | if (w != NULL) | |
13050 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13051 | |
13052 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13053 | for (related = bpt; related->related_breakpoint != bpt; | |
13054 | related = related->related_breakpoint); | |
13055 | related->related_breakpoint = bpt->related_breakpoint; | |
13056 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13057 | } |
13058 | ||
a9634178 TJB |
13059 | /* watch_command_1 creates a watchpoint but only sets its number if |
13060 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13061 | a problem in that process, we'll be asked to delete the half-created | |
13062 | watchpoint. In that case, don't announce the deletion. */ | |
13063 | if (bpt->number) | |
76727919 | 13064 | gdb::observers::breakpoint_deleted.notify (bpt); |
c906108c | 13065 | |
c906108c SS |
13066 | if (breakpoint_chain == bpt) |
13067 | breakpoint_chain = bpt->next; | |
13068 | ||
c906108c SS |
13069 | ALL_BREAKPOINTS (b) |
13070 | if (b->next == bpt) | |
c5aa993b JM |
13071 | { |
13072 | b->next = bpt->next; | |
13073 | break; | |
13074 | } | |
c906108c | 13075 | |
f431efe5 PA |
13076 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13077 | been freed. */ | |
13078 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13079 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13080 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13081 | commands are associated with the bpstat; if we remove it here, | |
13082 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13083 | event-top.c won't do anything, and temporary breakpoints with | |
13084 | commands won't work. */ | |
13085 | ||
13086 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13087 | ||
4a64f543 MS |
13088 | /* Now that breakpoint is removed from breakpoint list, update the |
13089 | global location list. This will remove locations that used to | |
13090 | belong to this breakpoint. Do this before freeing the breakpoint | |
13091 | itself, since remove_breakpoint looks at location's owner. It | |
13092 | might be better design to have location completely | |
13093 | self-contained, but it's not the case now. */ | |
44702360 | 13094 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13095 | |
4a64f543 MS |
13096 | /* On the chance that someone will soon try again to delete this |
13097 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13098 | bpt->type = bp_none; |
4d01a485 | 13099 | delete bpt; |
c906108c SS |
13100 | } |
13101 | ||
51be5b68 PA |
13102 | /* Iterator function to call a user-provided callback function once |
13103 | for each of B and its related breakpoints. */ | |
13104 | ||
13105 | static void | |
13106 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13107 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13108 | { |
13109 | struct breakpoint *related; | |
13110 | ||
13111 | related = b; | |
13112 | do | |
13113 | { | |
13114 | struct breakpoint *next; | |
13115 | ||
13116 | /* FUNCTION may delete RELATED. */ | |
13117 | next = related->related_breakpoint; | |
13118 | ||
13119 | if (next == related) | |
13120 | { | |
13121 | /* RELATED is the last ring entry. */ | |
48649e1b | 13122 | function (related); |
51be5b68 PA |
13123 | |
13124 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13125 | B. There's nothing left to do anyway, so just break | |
13126 | out. */ | |
13127 | break; | |
13128 | } | |
13129 | else | |
48649e1b | 13130 | function (related); |
51be5b68 PA |
13131 | |
13132 | related = next; | |
13133 | } | |
13134 | while (related != b); | |
13135 | } | |
95a42b64 | 13136 | |
4495129a | 13137 | static void |
981a3fb3 | 13138 | delete_command (const char *arg, int from_tty) |
c906108c | 13139 | { |
35df4500 | 13140 | struct breakpoint *b, *b_tmp; |
c906108c | 13141 | |
ea9365bb TT |
13142 | dont_repeat (); |
13143 | ||
c906108c SS |
13144 | if (arg == 0) |
13145 | { | |
13146 | int breaks_to_delete = 0; | |
13147 | ||
46c6471b PA |
13148 | /* Delete all breakpoints if no argument. Do not delete |
13149 | internal breakpoints, these have to be deleted with an | |
13150 | explicit breakpoint number argument. */ | |
c5aa993b | 13151 | ALL_BREAKPOINTS (b) |
46c6471b | 13152 | if (user_breakpoint_p (b)) |
973d738b DJ |
13153 | { |
13154 | breaks_to_delete = 1; | |
13155 | break; | |
13156 | } | |
c906108c SS |
13157 | |
13158 | /* Ask user only if there are some breakpoints to delete. */ | |
13159 | if (!from_tty | |
e2e0b3e5 | 13160 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13161 | { |
35df4500 | 13162 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13163 | if (user_breakpoint_p (b)) |
c5aa993b | 13164 | delete_breakpoint (b); |
c906108c SS |
13165 | } |
13166 | } | |
13167 | else | |
48649e1b | 13168 | map_breakpoint_numbers |
b926417a | 13169 | (arg, [&] (breakpoint *br) |
48649e1b | 13170 | { |
b926417a | 13171 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 13172 | }); |
c906108c SS |
13173 | } |
13174 | ||
c2f4122d PA |
13175 | /* Return true if all locations of B bound to PSPACE are pending. If |
13176 | PSPACE is NULL, all locations of all program spaces are | |
13177 | considered. */ | |
13178 | ||
0d381245 | 13179 | static int |
c2f4122d | 13180 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13181 | { |
c2f4122d PA |
13182 | struct bp_location *loc; |
13183 | ||
13184 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13185 | if ((pspace == NULL | |
13186 | || loc->pspace == pspace) | |
13187 | && !loc->shlib_disabled | |
8645ff69 | 13188 | && !loc->pspace->executing_startup) |
0d381245 VP |
13189 | return 0; |
13190 | return 1; | |
fe3f5fa8 VP |
13191 | } |
13192 | ||
776592bf DE |
13193 | /* Subroutine of update_breakpoint_locations to simplify it. |
13194 | Return non-zero if multiple fns in list LOC have the same name. | |
13195 | Null names are ignored. */ | |
13196 | ||
13197 | static int | |
13198 | ambiguous_names_p (struct bp_location *loc) | |
13199 | { | |
13200 | struct bp_location *l; | |
459a2e4c TT |
13201 | htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL, |
13202 | xcalloc, xfree); | |
776592bf DE |
13203 | |
13204 | for (l = loc; l != NULL; l = l->next) | |
13205 | { | |
13206 | const char **slot; | |
13207 | const char *name = l->function_name; | |
13208 | ||
13209 | /* Allow for some names to be NULL, ignore them. */ | |
13210 | if (name == NULL) | |
13211 | continue; | |
13212 | ||
13213 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13214 | INSERT); | |
4a64f543 MS |
13215 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13216 | returns NULL. */ | |
776592bf DE |
13217 | if (*slot != NULL) |
13218 | { | |
13219 | htab_delete (htab); | |
13220 | return 1; | |
13221 | } | |
13222 | *slot = name; | |
13223 | } | |
13224 | ||
13225 | htab_delete (htab); | |
13226 | return 0; | |
13227 | } | |
13228 | ||
0fb4aa4b PA |
13229 | /* When symbols change, it probably means the sources changed as well, |
13230 | and it might mean the static tracepoint markers are no longer at | |
13231 | the same address or line numbers they used to be at last we | |
13232 | checked. Losing your static tracepoints whenever you rebuild is | |
13233 | undesirable. This function tries to resync/rematch gdb static | |
13234 | tracepoints with the markers on the target, for static tracepoints | |
13235 | that have not been set by marker id. Static tracepoint that have | |
13236 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13237 | The heuristic is: | |
13238 | ||
13239 | 1) For a tracepoint set at a specific address, look for a marker at | |
13240 | the old PC. If one is found there, assume to be the same marker. | |
13241 | If the name / string id of the marker found is different from the | |
13242 | previous known name, assume that means the user renamed the marker | |
13243 | in the sources, and output a warning. | |
13244 | ||
13245 | 2) For a tracepoint set at a given line number, look for a marker | |
13246 | at the new address of the old line number. If one is found there, | |
13247 | assume to be the same marker. If the name / string id of the | |
13248 | marker found is different from the previous known name, assume that | |
13249 | means the user renamed the marker in the sources, and output a | |
13250 | warning. | |
13251 | ||
13252 | 3) If a marker is no longer found at the same address or line, it | |
13253 | may mean the marker no longer exists. But it may also just mean | |
13254 | the code changed a bit. Maybe the user added a few lines of code | |
13255 | that made the marker move up or down (in line number terms). Ask | |
13256 | the target for info about the marker with the string id as we knew | |
13257 | it. If found, update line number and address in the matching | |
13258 | static tracepoint. This will get confused if there's more than one | |
13259 | marker with the same ID (possible in UST, although unadvised | |
13260 | precisely because it confuses tools). */ | |
13261 | ||
13262 | static struct symtab_and_line | |
13263 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13264 | { | |
d9b3f62e | 13265 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13266 | struct static_tracepoint_marker marker; |
13267 | CORE_ADDR pc; | |
0fb4aa4b PA |
13268 | |
13269 | pc = sal.pc; | |
13270 | if (sal.line) | |
13271 | find_line_pc (sal.symtab, sal.line, &pc); | |
13272 | ||
13273 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13274 | { | |
5d9310c4 | 13275 | if (tp->static_trace_marker_id != marker.str_id) |
0fb4aa4b | 13276 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
5d9310c4 SM |
13277 | b->number, tp->static_trace_marker_id.c_str (), |
13278 | marker.str_id.c_str ()); | |
0fb4aa4b | 13279 | |
5d9310c4 | 13280 | tp->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b PA |
13281 | |
13282 | return sal; | |
13283 | } | |
13284 | ||
13285 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13286 | by string ID. */ | |
13287 | if (!sal.explicit_pc | |
13288 | && sal.line != 0 | |
13289 | && sal.symtab != NULL | |
5d9310c4 | 13290 | && !tp->static_trace_marker_id.empty ()) |
0fb4aa4b | 13291 | { |
5d9310c4 SM |
13292 | std::vector<static_tracepoint_marker> markers |
13293 | = target_static_tracepoint_markers_by_strid | |
13294 | (tp->static_trace_marker_id.c_str ()); | |
0fb4aa4b | 13295 | |
5d9310c4 | 13296 | if (!markers.empty ()) |
0fb4aa4b | 13297 | { |
0fb4aa4b | 13298 | struct symbol *sym; |
80e1d417 | 13299 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13300 | struct ui_out *uiout = current_uiout; |
67994074 | 13301 | struct explicit_location explicit_loc; |
0fb4aa4b | 13302 | |
5d9310c4 | 13303 | tpmarker = &markers[0]; |
0fb4aa4b | 13304 | |
5d9310c4 | 13305 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
0fb4aa4b PA |
13306 | |
13307 | warning (_("marker for static tracepoint %d (%s) not " | |
13308 | "found at previous line number"), | |
5d9310c4 | 13309 | b->number, tp->static_trace_marker_id.c_str ()); |
0fb4aa4b | 13310 | |
51abb421 | 13311 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13312 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13313 | uiout->text ("Now in "); |
0fb4aa4b PA |
13314 | if (sym) |
13315 | { | |
cbe56571 | 13316 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym), |
e43b10e1 | 13317 | function_name_style.style ()); |
112e8700 | 13318 | uiout->text (" at "); |
0fb4aa4b | 13319 | } |
112e8700 | 13320 | uiout->field_string ("file", |
cbe56571 | 13321 | symtab_to_filename_for_display (sal2.symtab), |
e43b10e1 | 13322 | file_name_style.style ()); |
112e8700 | 13323 | uiout->text (":"); |
0fb4aa4b | 13324 | |
112e8700 | 13325 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13326 | { |
0b0865da | 13327 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13328 | |
112e8700 | 13329 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13330 | } |
13331 | ||
381befee | 13332 | uiout->field_signed ("line", sal2.line); |
112e8700 | 13333 | uiout->text ("\n"); |
0fb4aa4b | 13334 | |
80e1d417 | 13335 | b->loc->line_number = sal2.line; |
2f202fde | 13336 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13337 | |
d28cd78a | 13338 | b->location.reset (NULL); |
67994074 KS |
13339 | initialize_explicit_location (&explicit_loc); |
13340 | explicit_loc.source_filename | |
00e52e53 | 13341 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13342 | explicit_loc.line_offset.offset = b->loc->line_number; |
13343 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13344 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13345 | |
13346 | /* Might be nice to check if function changed, and warn if | |
13347 | so. */ | |
0fb4aa4b PA |
13348 | } |
13349 | } | |
13350 | return sal; | |
13351 | } | |
13352 | ||
8d3788bd VP |
13353 | /* Returns 1 iff locations A and B are sufficiently same that |
13354 | we don't need to report breakpoint as changed. */ | |
13355 | ||
13356 | static int | |
13357 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13358 | { | |
13359 | while (a && b) | |
13360 | { | |
13361 | if (a->address != b->address) | |
13362 | return 0; | |
13363 | ||
13364 | if (a->shlib_disabled != b->shlib_disabled) | |
13365 | return 0; | |
13366 | ||
13367 | if (a->enabled != b->enabled) | |
13368 | return 0; | |
13369 | ||
13370 | a = a->next; | |
13371 | b = b->next; | |
13372 | } | |
13373 | ||
13374 | if ((a == NULL) != (b == NULL)) | |
13375 | return 0; | |
13376 | ||
13377 | return 1; | |
13378 | } | |
13379 | ||
c2f4122d PA |
13380 | /* Split all locations of B that are bound to PSPACE out of B's |
13381 | location list to a separate list and return that list's head. If | |
13382 | PSPACE is NULL, hoist out all locations of B. */ | |
13383 | ||
13384 | static struct bp_location * | |
13385 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13386 | { | |
13387 | struct bp_location head; | |
13388 | struct bp_location *i = b->loc; | |
13389 | struct bp_location **i_link = &b->loc; | |
13390 | struct bp_location *hoisted = &head; | |
13391 | ||
13392 | if (pspace == NULL) | |
13393 | { | |
13394 | i = b->loc; | |
13395 | b->loc = NULL; | |
13396 | return i; | |
13397 | } | |
13398 | ||
13399 | head.next = NULL; | |
13400 | ||
13401 | while (i != NULL) | |
13402 | { | |
13403 | if (i->pspace == pspace) | |
13404 | { | |
13405 | *i_link = i->next; | |
13406 | i->next = NULL; | |
13407 | hoisted->next = i; | |
13408 | hoisted = i; | |
13409 | } | |
13410 | else | |
13411 | i_link = &i->next; | |
13412 | i = *i_link; | |
13413 | } | |
13414 | ||
13415 | return head.next; | |
13416 | } | |
13417 | ||
13418 | /* Create new breakpoint locations for B (a hardware or software | |
13419 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13420 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13421 | FILTER_PSPACE. Locations of other program spaces are left | |
13422 | untouched. */ | |
f1310107 | 13423 | |
0e30163f | 13424 | void |
0d381245 | 13425 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13426 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13427 | gdb::array_view<const symtab_and_line> sals, |
13428 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 13429 | { |
c2f4122d | 13430 | struct bp_location *existing_locations; |
0d381245 | 13431 | |
6c5b2ebe | 13432 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13433 | { |
13434 | /* Ranged breakpoints have only one start location and one end | |
13435 | location. */ | |
13436 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13437 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13438 | "multiple locations found\n"), | |
13439 | b->number); | |
13440 | return; | |
13441 | } | |
f1310107 | 13442 | |
4a64f543 MS |
13443 | /* If there's no new locations, and all existing locations are |
13444 | pending, don't do anything. This optimizes the common case where | |
13445 | all locations are in the same shared library, that was unloaded. | |
13446 | We'd like to retain the location, so that when the library is | |
13447 | loaded again, we don't loose the enabled/disabled status of the | |
13448 | individual locations. */ | |
6c5b2ebe | 13449 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13450 | return; |
13451 | ||
c2f4122d | 13452 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13453 | |
6c5b2ebe | 13454 | for (const auto &sal : sals) |
fe3f5fa8 | 13455 | { |
f8eba3c6 TT |
13456 | struct bp_location *new_loc; |
13457 | ||
6c5b2ebe | 13458 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13459 | |
6c5b2ebe | 13460 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13461 | |
0d381245 VP |
13462 | /* Reparse conditions, they might contain references to the |
13463 | old symtab. */ | |
13464 | if (b->cond_string != NULL) | |
13465 | { | |
bbc13ae3 | 13466 | const char *s; |
fe3f5fa8 | 13467 | |
0d381245 | 13468 | s = b->cond_string; |
a70b8144 | 13469 | try |
0d381245 | 13470 | { |
6c5b2ebe PA |
13471 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13472 | block_for_pc (sal.pc), | |
0d381245 VP |
13473 | 0); |
13474 | } | |
230d2906 | 13475 | catch (const gdb_exception_error &e) |
0d381245 | 13476 | { |
3e43a32a MS |
13477 | warning (_("failed to reevaluate condition " |
13478 | "for breakpoint %d: %s"), | |
3d6e9d23 | 13479 | b->number, e.what ()); |
0d381245 VP |
13480 | new_loc->enabled = 0; |
13481 | } | |
13482 | } | |
fe3f5fa8 | 13483 | |
6c5b2ebe | 13484 | if (!sals_end.empty ()) |
f1310107 | 13485 | { |
6c5b2ebe | 13486 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13487 | |
6c5b2ebe | 13488 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13489 | } |
0d381245 | 13490 | } |
fe3f5fa8 | 13491 | |
4a64f543 MS |
13492 | /* If possible, carry over 'disable' status from existing |
13493 | breakpoints. */ | |
0d381245 VP |
13494 | { |
13495 | struct bp_location *e = existing_locations; | |
776592bf DE |
13496 | /* If there are multiple breakpoints with the same function name, |
13497 | e.g. for inline functions, comparing function names won't work. | |
13498 | Instead compare pc addresses; this is just a heuristic as things | |
13499 | may have moved, but in practice it gives the correct answer | |
13500 | often enough until a better solution is found. */ | |
13501 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13502 | ||
0d381245 VP |
13503 | for (; e; e = e->next) |
13504 | { | |
13505 | if (!e->enabled && e->function_name) | |
13506 | { | |
13507 | struct bp_location *l = b->loc; | |
776592bf DE |
13508 | if (have_ambiguous_names) |
13509 | { | |
13510 | for (; l; l = l->next) | |
f1310107 | 13511 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13512 | { |
13513 | l->enabled = 0; | |
13514 | break; | |
13515 | } | |
13516 | } | |
13517 | else | |
13518 | { | |
13519 | for (; l; l = l->next) | |
13520 | if (l->function_name | |
13521 | && strcmp (e->function_name, l->function_name) == 0) | |
13522 | { | |
13523 | l->enabled = 0; | |
13524 | break; | |
13525 | } | |
13526 | } | |
0d381245 VP |
13527 | } |
13528 | } | |
13529 | } | |
fe3f5fa8 | 13530 | |
8d3788bd | 13531 | if (!locations_are_equal (existing_locations, b->loc)) |
76727919 | 13532 | gdb::observers::breakpoint_modified.notify (b); |
fe3f5fa8 VP |
13533 | } |
13534 | ||
f00aae0f | 13535 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13536 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13537 | ||
6c5b2ebe | 13538 | static std::vector<symtab_and_line> |
f00aae0f | 13539 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13540 | struct program_space *search_pspace, int *found) |
ef23e705 | 13541 | { |
cc06b668 | 13542 | struct gdb_exception exception; |
ef23e705 | 13543 | |
983af33b | 13544 | gdb_assert (b->ops != NULL); |
ef23e705 | 13545 | |
6c5b2ebe PA |
13546 | std::vector<symtab_and_line> sals; |
13547 | ||
a70b8144 | 13548 | try |
ef23e705 | 13549 | { |
6c5b2ebe | 13550 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13551 | } |
94aeb44b | 13552 | catch (gdb_exception_error &e) |
ef23e705 TJB |
13553 | { |
13554 | int not_found_and_ok = 0; | |
492d29ea | 13555 | |
ef23e705 TJB |
13556 | /* For pending breakpoints, it's expected that parsing will |
13557 | fail until the right shared library is loaded. User has | |
13558 | already told to create pending breakpoints and don't need | |
13559 | extra messages. If breakpoint is in bp_shlib_disabled | |
13560 | state, then user already saw the message about that | |
13561 | breakpoint being disabled, and don't want to see more | |
13562 | errors. */ | |
58438ac1 | 13563 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13564 | && (b->condition_not_parsed |
13565 | || (b->loc != NULL | |
13566 | && search_pspace != NULL | |
13567 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13568 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13569 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13570 | || b->enable_state == bp_disabled)) |
13571 | not_found_and_ok = 1; | |
13572 | ||
13573 | if (!not_found_and_ok) | |
13574 | { | |
13575 | /* We surely don't want to warn about the same breakpoint | |
13576 | 10 times. One solution, implemented here, is disable | |
13577 | the breakpoint on error. Another solution would be to | |
13578 | have separate 'warning emitted' flag. Since this | |
13579 | happens only when a binary has changed, I don't know | |
13580 | which approach is better. */ | |
13581 | b->enable_state = bp_disabled; | |
eedc3f4f | 13582 | throw; |
ef23e705 | 13583 | } |
94aeb44b TT |
13584 | |
13585 | exception = std::move (e); | |
ef23e705 TJB |
13586 | } |
13587 | ||
492d29ea | 13588 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13589 | { |
6c5b2ebe PA |
13590 | for (auto &sal : sals) |
13591 | resolve_sal_pc (&sal); | |
f00aae0f | 13592 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13593 | { |
ed1d1739 KS |
13594 | char *cond_string, *extra_string; |
13595 | int thread, task; | |
ef23e705 | 13596 | |
6c5b2ebe | 13597 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
13598 | &cond_string, &thread, &task, |
13599 | &extra_string); | |
f00aae0f | 13600 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
13601 | if (cond_string) |
13602 | b->cond_string = cond_string; | |
13603 | b->thread = thread; | |
13604 | b->task = task; | |
e7e0cddf | 13605 | if (extra_string) |
f00aae0f KS |
13606 | { |
13607 | xfree (b->extra_string); | |
13608 | b->extra_string = extra_string; | |
13609 | } | |
ef23e705 TJB |
13610 | b->condition_not_parsed = 0; |
13611 | } | |
13612 | ||
983af33b | 13613 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 13614 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 13615 | |
58438ac1 TT |
13616 | *found = 1; |
13617 | } | |
13618 | else | |
13619 | *found = 0; | |
ef23e705 TJB |
13620 | |
13621 | return sals; | |
13622 | } | |
13623 | ||
348d480f PA |
13624 | /* The default re_set method, for typical hardware or software |
13625 | breakpoints. Reevaluate the breakpoint and recreate its | |
13626 | locations. */ | |
13627 | ||
13628 | static void | |
28010a5d | 13629 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 13630 | { |
c2f4122d | 13631 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 13632 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 13633 | |
6c5b2ebe PA |
13634 | int found; |
13635 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
13636 | filter_pspace, &found); | |
ef23e705 | 13637 | if (found) |
6c5b2ebe | 13638 | expanded = std::move (sals); |
ef23e705 | 13639 | |
f00aae0f | 13640 | if (b->location_range_end != NULL) |
f1310107 | 13641 | { |
6c5b2ebe PA |
13642 | std::vector<symtab_and_line> sals_end |
13643 | = location_to_sals (b, b->location_range_end.get (), | |
13644 | filter_pspace, &found); | |
f1310107 | 13645 | if (found) |
6c5b2ebe | 13646 | expanded_end = std::move (sals_end); |
f1310107 TJB |
13647 | } |
13648 | ||
c2f4122d | 13649 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
13650 | } |
13651 | ||
983af33b SDJ |
13652 | /* Default method for creating SALs from an address string. It basically |
13653 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13654 | ||
13655 | static void | |
f00aae0f KS |
13656 | create_sals_from_location_default (const struct event_location *location, |
13657 | struct linespec_result *canonical, | |
13658 | enum bptype type_wanted) | |
983af33b | 13659 | { |
f00aae0f | 13660 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
13661 | } |
13662 | ||
13663 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13664 | function for the `create_breakpoints_sal' method of | |
13665 | breakpoint_ops. */ | |
13666 | ||
13667 | static void | |
13668 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13669 | struct linespec_result *canonical, | |
e1e01040 PA |
13670 | gdb::unique_xmalloc_ptr<char> cond_string, |
13671 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13672 | enum bptype type_wanted, |
13673 | enum bpdisp disposition, | |
13674 | int thread, | |
13675 | int task, int ignore_count, | |
13676 | const struct breakpoint_ops *ops, | |
13677 | int from_tty, int enabled, | |
44f238bb | 13678 | int internal, unsigned flags) |
983af33b | 13679 | { |
e1e01040 PA |
13680 | create_breakpoints_sal (gdbarch, canonical, |
13681 | std::move (cond_string), | |
13682 | std::move (extra_string), | |
983af33b SDJ |
13683 | type_wanted, disposition, |
13684 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13685 | enabled, internal, flags); |
983af33b SDJ |
13686 | } |
13687 | ||
13688 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 13689 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 13690 | |
6c5b2ebe | 13691 | static std::vector<symtab_and_line> |
f00aae0f KS |
13692 | decode_location_default (struct breakpoint *b, |
13693 | const struct event_location *location, | |
6c5b2ebe | 13694 | struct program_space *search_pspace) |
983af33b SDJ |
13695 | { |
13696 | struct linespec_result canonical; | |
13697 | ||
c2f4122d | 13698 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
cafb3438 | 13699 | NULL, 0, &canonical, multiple_symbols_all, |
c0e8dcd8 | 13700 | b->filter.get ()); |
983af33b SDJ |
13701 | |
13702 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 13703 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 13704 | |
6c5b2ebe | 13705 | if (!canonical.lsals.empty ()) |
983af33b | 13706 | { |
6c5b2ebe PA |
13707 | const linespec_sals &lsal = canonical.lsals[0]; |
13708 | return std::move (lsal.sals); | |
983af33b | 13709 | } |
6c5b2ebe | 13710 | return {}; |
983af33b SDJ |
13711 | } |
13712 | ||
bf469271 | 13713 | /* Reset a breakpoint. */ |
c906108c | 13714 | |
bf469271 PA |
13715 | static void |
13716 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 13717 | { |
fdf44873 TT |
13718 | input_radix = b->input_radix; |
13719 | set_language (b->language); | |
c906108c | 13720 | |
348d480f | 13721 | b->ops->re_set (b); |
c906108c SS |
13722 | } |
13723 | ||
c2f4122d PA |
13724 | /* Re-set breakpoint locations for the current program space. |
13725 | Locations bound to other program spaces are left untouched. */ | |
13726 | ||
c906108c | 13727 | void |
69de3c6a | 13728 | breakpoint_re_set (void) |
c906108c | 13729 | { |
35df4500 | 13730 | struct breakpoint *b, *b_tmp; |
2a7f3dff | 13731 | |
c5aa993b | 13732 | { |
fdf44873 TT |
13733 | scoped_restore_current_language save_language; |
13734 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 13735 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 13736 | |
8e817061 JB |
13737 | /* breakpoint_re_set_one sets the current_language to the language |
13738 | of the breakpoint it is resetting (see prepare_re_set_context) | |
13739 | before re-evaluating the breakpoint's location. This change can | |
13740 | unfortunately get undone by accident if the language_mode is set | |
13741 | to auto, and we either switch frames, or more likely in this context, | |
13742 | we select the current frame. | |
13743 | ||
13744 | We prevent this by temporarily turning the language_mode to | |
13745 | language_mode_manual. We restore it once all breakpoints | |
13746 | have been reset. */ | |
13747 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); | |
13748 | language_mode = language_mode_manual; | |
13749 | ||
5ed8105e PA |
13750 | /* Note: we must not try to insert locations until after all |
13751 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
13752 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
13753 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 13754 | |
5ed8105e PA |
13755 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
13756 | { | |
a70b8144 | 13757 | try |
bf469271 PA |
13758 | { |
13759 | breakpoint_re_set_one (b); | |
13760 | } | |
230d2906 | 13761 | catch (const gdb_exception &ex) |
bf469271 PA |
13762 | { |
13763 | exception_fprintf (gdb_stderr, ex, | |
13764 | "Error in re-setting breakpoint %d: ", | |
13765 | b->number); | |
13766 | } | |
5ed8105e | 13767 | } |
5ed8105e PA |
13768 | |
13769 | jit_breakpoint_re_set (); | |
13770 | } | |
6c95b8df | 13771 | |
af02033e PP |
13772 | create_overlay_event_breakpoint (); |
13773 | create_longjmp_master_breakpoint (); | |
13774 | create_std_terminate_master_breakpoint (); | |
186c406b | 13775 | create_exception_master_breakpoint (); |
2a7f3dff PA |
13776 | |
13777 | /* Now we can insert. */ | |
13778 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
13779 | } |
13780 | \f | |
c906108c SS |
13781 | /* Reset the thread number of this breakpoint: |
13782 | ||
13783 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13784 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13785 | void |
fba45db2 | 13786 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13787 | { |
13788 | if (b->thread != -1) | |
13789 | { | |
00431a78 | 13790 | b->thread = inferior_thread ()->global_num; |
6c95b8df PA |
13791 | |
13792 | /* We're being called after following a fork. The new fork is | |
13793 | selected as current, and unless this was a vfork will have a | |
13794 | different program space from the original thread. Reset that | |
13795 | as well. */ | |
13796 | b->loc->pspace = current_program_space; | |
c906108c SS |
13797 | } |
13798 | } | |
13799 | ||
03ac34d5 MS |
13800 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13801 | If from_tty is nonzero, it prints a message to that effect, | |
13802 | which ends with a period (no newline). */ | |
13803 | ||
c906108c | 13804 | void |
fba45db2 | 13805 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13806 | { |
52f0bd74 | 13807 | struct breakpoint *b; |
c906108c SS |
13808 | |
13809 | if (count < 0) | |
13810 | count = 0; | |
13811 | ||
13812 | ALL_BREAKPOINTS (b) | |
13813 | if (b->number == bptnum) | |
c5aa993b | 13814 | { |
d77f58be SS |
13815 | if (is_tracepoint (b)) |
13816 | { | |
13817 | if (from_tty && count != 0) | |
13818 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
13819 | bptnum); | |
13820 | return; | |
13821 | } | |
13822 | ||
c5aa993b | 13823 | b->ignore_count = count; |
221ea385 KS |
13824 | if (from_tty) |
13825 | { | |
13826 | if (count == 0) | |
3e43a32a MS |
13827 | printf_filtered (_("Will stop next time " |
13828 | "breakpoint %d is reached."), | |
221ea385 KS |
13829 | bptnum); |
13830 | else if (count == 1) | |
a3f17187 | 13831 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
13832 | bptnum); |
13833 | else | |
3e43a32a MS |
13834 | printf_filtered (_("Will ignore next %d " |
13835 | "crossings of breakpoint %d."), | |
221ea385 KS |
13836 | count, bptnum); |
13837 | } | |
76727919 | 13838 | gdb::observers::breakpoint_modified.notify (b); |
c5aa993b JM |
13839 | return; |
13840 | } | |
c906108c | 13841 | |
8a3fe4f8 | 13842 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13843 | } |
13844 | ||
c906108c SS |
13845 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13846 | ||
13847 | static void | |
0b39b52e | 13848 | ignore_command (const char *args, int from_tty) |
c906108c | 13849 | { |
0b39b52e | 13850 | const char *p = args; |
52f0bd74 | 13851 | int num; |
c906108c SS |
13852 | |
13853 | if (p == 0) | |
e2e0b3e5 | 13854 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13855 | |
c906108c | 13856 | num = get_number (&p); |
5c44784c | 13857 | if (num == 0) |
8a3fe4f8 | 13858 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13859 | if (*p == 0) |
8a3fe4f8 | 13860 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13861 | |
13862 | set_ignore_count (num, | |
13863 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13864 | from_tty); | |
221ea385 KS |
13865 | if (from_tty) |
13866 | printf_filtered ("\n"); | |
c906108c SS |
13867 | } |
13868 | \f | |
d0fe4701 XR |
13869 | |
13870 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
13871 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
13872 | |
13873 | static void | |
d0fe4701 XR |
13874 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
13875 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 13876 | { |
d0fe4701 XR |
13877 | if (bp_num_range.first == 0) |
13878 | { | |
13879 | warning (_("bad breakpoint number at or near '%d'"), | |
13880 | bp_num_range.first); | |
13881 | } | |
13882 | else | |
c906108c | 13883 | { |
d0fe4701 | 13884 | struct breakpoint *b, *tmp; |
197f0a60 | 13885 | |
d0fe4701 | 13886 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 13887 | { |
d0fe4701 XR |
13888 | bool match = false; |
13889 | ||
5c44784c | 13890 | ALL_BREAKPOINTS_SAFE (b, tmp) |
d0fe4701 | 13891 | if (b->number == i) |
5c44784c | 13892 | { |
bfd28288 | 13893 | match = true; |
48649e1b | 13894 | function (b); |
11cf8741 | 13895 | break; |
5c44784c | 13896 | } |
bfd28288 | 13897 | if (!match) |
d0fe4701 | 13898 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
c5aa993b | 13899 | } |
c906108c SS |
13900 | } |
13901 | } | |
13902 | ||
d0fe4701 XR |
13903 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
13904 | ARGS. */ | |
13905 | ||
13906 | static void | |
13907 | map_breakpoint_numbers (const char *args, | |
13908 | gdb::function_view<void (breakpoint *)> function) | |
13909 | { | |
13910 | if (args == NULL || *args == '\0') | |
13911 | error_no_arg (_("one or more breakpoint numbers")); | |
13912 | ||
13913 | number_or_range_parser parser (args); | |
13914 | ||
13915 | while (!parser.finished ()) | |
13916 | { | |
13917 | int num = parser.get_number (); | |
13918 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
13919 | } | |
13920 | } | |
13921 | ||
13922 | /* Return the breakpoint location structure corresponding to the | |
13923 | BP_NUM and LOC_NUM values. */ | |
13924 | ||
0d381245 | 13925 | static struct bp_location * |
d0fe4701 | 13926 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 13927 | { |
0d381245 | 13928 | struct breakpoint *b; |
0d381245 VP |
13929 | |
13930 | ALL_BREAKPOINTS (b) | |
13931 | if (b->number == bp_num) | |
13932 | { | |
13933 | break; | |
13934 | } | |
13935 | ||
13936 | if (!b || b->number != bp_num) | |
d0fe4701 | 13937 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 13938 | |
0d381245 | 13939 | if (loc_num == 0) |
d0fe4701 | 13940 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 13941 | |
d0fe4701 XR |
13942 | int n = 0; |
13943 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
13944 | if (++n == loc_num) | |
13945 | return loc; | |
13946 | ||
13947 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
13948 | } |
13949 | ||
95e95a6d PA |
13950 | /* Modes of operation for extract_bp_num. */ |
13951 | enum class extract_bp_kind | |
13952 | { | |
13953 | /* Extracting a breakpoint number. */ | |
13954 | bp, | |
13955 | ||
13956 | /* Extracting a location number. */ | |
13957 | loc, | |
13958 | }; | |
13959 | ||
13960 | /* Extract a breakpoint or location number (as determined by KIND) | |
13961 | from the string starting at START. TRAILER is a character which | |
13962 | can be found after the number. If you don't want a trailer, use | |
13963 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
13964 | string. This always returns a positive integer. */ | |
13965 | ||
13966 | static int | |
13967 | extract_bp_num (extract_bp_kind kind, const char *start, | |
13968 | int trailer, const char **end_out = NULL) | |
13969 | { | |
13970 | const char *end = start; | |
13971 | int num = get_number_trailer (&end, trailer); | |
13972 | if (num < 0) | |
13973 | error (kind == extract_bp_kind::bp | |
13974 | ? _("Negative breakpoint number '%.*s'") | |
13975 | : _("Negative breakpoint location number '%.*s'"), | |
13976 | int (end - start), start); | |
13977 | if (num == 0) | |
13978 | error (kind == extract_bp_kind::bp | |
13979 | ? _("Bad breakpoint number '%.*s'") | |
13980 | : _("Bad breakpoint location number '%.*s'"), | |
13981 | int (end - start), start); | |
13982 | ||
13983 | if (end_out != NULL) | |
13984 | *end_out = end; | |
13985 | return num; | |
13986 | } | |
13987 | ||
13988 | /* Extract a breakpoint or location range (as determined by KIND) in | |
13989 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
13990 | representing the (inclusive) range. The returned pair's elements | |
13991 | are always positive integers. */ | |
13992 | ||
13993 | static std::pair<int, int> | |
13994 | extract_bp_or_bp_range (extract_bp_kind kind, | |
13995 | const std::string &arg, | |
13996 | std::string::size_type arg_offset) | |
13997 | { | |
13998 | std::pair<int, int> range; | |
13999 | const char *bp_loc = &arg[arg_offset]; | |
14000 | std::string::size_type dash = arg.find ('-', arg_offset); | |
14001 | if (dash != std::string::npos) | |
14002 | { | |
14003 | /* bp_loc is a range (x-z). */ | |
14004 | if (arg.length () == dash + 1) | |
14005 | error (kind == extract_bp_kind::bp | |
14006 | ? _("Bad breakpoint number at or near: '%s'") | |
14007 | : _("Bad breakpoint location number at or near: '%s'"), | |
14008 | bp_loc); | |
14009 | ||
14010 | const char *end; | |
14011 | const char *start_first = bp_loc; | |
14012 | const char *start_second = &arg[dash + 1]; | |
14013 | range.first = extract_bp_num (kind, start_first, '-'); | |
14014 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
14015 | ||
14016 | if (range.first > range.second) | |
14017 | error (kind == extract_bp_kind::bp | |
14018 | ? _("Inverted breakpoint range at '%.*s'") | |
14019 | : _("Inverted breakpoint location range at '%.*s'"), | |
14020 | int (end - start_first), start_first); | |
14021 | } | |
14022 | else | |
14023 | { | |
14024 | /* bp_loc is a single value. */ | |
14025 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
14026 | range.second = range.first; | |
14027 | } | |
14028 | return range; | |
14029 | } | |
14030 | ||
d0fe4701 XR |
14031 | /* Extract the breakpoint/location range specified by ARG. Returns |
14032 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
14033 | BP_LOC_RANGE. | |
14034 | ||
14035 | ARG may be in any of the following forms: | |
14036 | ||
14037 | x where 'x' is a breakpoint number. | |
14038 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
14039 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
14040 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
14041 | location number range. | |
14042 | */ | |
14043 | ||
cc638e86 | 14044 | static void |
d0fe4701 XR |
14045 | extract_bp_number_and_location (const std::string &arg, |
14046 | std::pair<int, int> &bp_num_range, | |
14047 | std::pair<int, int> &bp_loc_range) | |
14048 | { | |
14049 | std::string::size_type dot = arg.find ('.'); | |
14050 | ||
14051 | if (dot != std::string::npos) | |
14052 | { | |
14053 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
14054 | ||
14055 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 14056 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 14057 | |
95e95a6d PA |
14058 | bp_num_range.first |
14059 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
14060 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 14061 | |
95e95a6d PA |
14062 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
14063 | arg, dot + 1); | |
d0fe4701 XR |
14064 | } |
14065 | else | |
14066 | { | |
14067 | /* Handle x and x-y cases. */ | |
d0fe4701 | 14068 | |
95e95a6d | 14069 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
14070 | bp_loc_range.first = 0; |
14071 | bp_loc_range.second = 0; | |
14072 | } | |
d0fe4701 XR |
14073 | } |
14074 | ||
14075 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
14076 | specifies whether to enable or disable. */ | |
14077 | ||
14078 | static void | |
14079 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
14080 | { | |
14081 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
14082 | if (loc != NULL) | |
14083 | { | |
14084 | if (loc->enabled != enable) | |
14085 | { | |
14086 | loc->enabled = enable; | |
14087 | mark_breakpoint_location_modified (loc); | |
14088 | } | |
14089 | if (target_supports_enable_disable_tracepoint () | |
14090 | && current_trace_status ()->running && loc->owner | |
14091 | && is_tracepoint (loc->owner)) | |
14092 | target_disable_tracepoint (loc); | |
14093 | } | |
14094 | update_global_location_list (UGLL_DONT_INSERT); | |
d7154a8d JV |
14095 | |
14096 | gdb::observers::breakpoint_modified.notify (loc->owner); | |
d0fe4701 XR |
14097 | } |
14098 | ||
14099 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
14100 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
14101 | (inclusive) range of location numbers of that breakpoint to | |
14102 | enable/disable. ENABLE specifies whether to enable or disable the | |
14103 | location. */ | |
14104 | ||
14105 | static void | |
14106 | enable_disable_breakpoint_location_range (int bp_num, | |
14107 | std::pair<int, int> &bp_loc_range, | |
14108 | bool enable) | |
14109 | { | |
14110 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
14111 | enable_disable_bp_num_loc (bp_num, i, enable); | |
14112 | } | |
0d381245 | 14113 | |
1900040c MS |
14114 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14115 | If from_tty is nonzero, it prints a message to that effect, | |
14116 | which ends with a period (no newline). */ | |
14117 | ||
c906108c | 14118 | void |
fba45db2 | 14119 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14120 | { |
14121 | /* Never disable a watchpoint scope breakpoint; we want to | |
14122 | hit them when we leave scope so we can delete both the | |
14123 | watchpoint and its scope breakpoint at that time. */ | |
14124 | if (bpt->type == bp_watchpoint_scope) | |
14125 | return; | |
14126 | ||
b5de0fa7 | 14127 | bpt->enable_state = bp_disabled; |
c906108c | 14128 | |
b775012e LM |
14129 | /* Mark breakpoint locations modified. */ |
14130 | mark_breakpoint_modified (bpt); | |
14131 | ||
d248b706 KY |
14132 | if (target_supports_enable_disable_tracepoint () |
14133 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14134 | { | |
14135 | struct bp_location *location; | |
14136 | ||
14137 | for (location = bpt->loc; location; location = location->next) | |
14138 | target_disable_tracepoint (location); | |
14139 | } | |
14140 | ||
44702360 | 14141 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14142 | |
76727919 | 14143 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14144 | } |
14145 | ||
d0fe4701 XR |
14146 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
14147 | specified in ARGS. ARGS may be in any of the formats handled by | |
14148 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
14149 | or disable the breakpoints/locations. */ | |
14150 | ||
c906108c | 14151 | static void |
d0fe4701 | 14152 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 14153 | { |
c906108c | 14154 | if (args == 0) |
46c6471b PA |
14155 | { |
14156 | struct breakpoint *bpt; | |
14157 | ||
14158 | ALL_BREAKPOINTS (bpt) | |
14159 | if (user_breakpoint_p (bpt)) | |
d0fe4701 XR |
14160 | { |
14161 | if (enable) | |
14162 | enable_breakpoint (bpt); | |
14163 | else | |
14164 | disable_breakpoint (bpt); | |
14165 | } | |
46c6471b | 14166 | } |
9eaabc75 | 14167 | else |
0d381245 | 14168 | { |
cb791d59 | 14169 | std::string num = extract_arg (&args); |
9eaabc75 | 14170 | |
cb791d59 | 14171 | while (!num.empty ()) |
d248b706 | 14172 | { |
d0fe4701 | 14173 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 14174 | |
cc638e86 PA |
14175 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
14176 | ||
14177 | if (bp_loc_range.first == bp_loc_range.second | |
14178 | && bp_loc_range.first == 0) | |
d0fe4701 | 14179 | { |
cc638e86 PA |
14180 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
14181 | map_breakpoint_number_range (bp_num_range, | |
14182 | enable | |
14183 | ? enable_breakpoint | |
14184 | : disable_breakpoint); | |
14185 | } | |
14186 | else | |
14187 | { | |
14188 | /* Handle breakpoint ids with formats 'x.y' or | |
14189 | 'x.y-z'. */ | |
14190 | enable_disable_breakpoint_location_range | |
14191 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 14192 | } |
9eaabc75 | 14193 | num = extract_arg (&args); |
d248b706 | 14194 | } |
0d381245 | 14195 | } |
c906108c SS |
14196 | } |
14197 | ||
d0fe4701 XR |
14198 | /* The disable command disables the specified breakpoints/locations |
14199 | (or all defined breakpoints) so they're no longer effective in | |
14200 | stopping the inferior. ARGS may be in any of the forms defined in | |
14201 | extract_bp_number_and_location. */ | |
14202 | ||
14203 | static void | |
14204 | disable_command (const char *args, int from_tty) | |
14205 | { | |
14206 | enable_disable_command (args, from_tty, false); | |
14207 | } | |
14208 | ||
c906108c | 14209 | static void |
816338b5 SS |
14210 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14211 | int count) | |
c906108c | 14212 | { |
afe38095 | 14213 | int target_resources_ok; |
c906108c SS |
14214 | |
14215 | if (bpt->type == bp_hardware_breakpoint) | |
14216 | { | |
14217 | int i; | |
c5aa993b | 14218 | i = hw_breakpoint_used_count (); |
53a5351d | 14219 | target_resources_ok = |
d92524f1 | 14220 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14221 | i + 1, 0); |
c906108c | 14222 | if (target_resources_ok == 0) |
8a3fe4f8 | 14223 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14224 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14225 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14226 | } |
14227 | ||
cc60f2e3 | 14228 | if (is_watchpoint (bpt)) |
c906108c | 14229 | { |
d07205c2 | 14230 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14231 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14232 | |
a70b8144 | 14233 | try |
c906108c | 14234 | { |
3a5c3e22 PA |
14235 | struct watchpoint *w = (struct watchpoint *) bpt; |
14236 | ||
1e718ff1 TJB |
14237 | orig_enable_state = bpt->enable_state; |
14238 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14239 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14240 | } |
230d2906 | 14241 | catch (const gdb_exception &e) |
c5aa993b | 14242 | { |
1e718ff1 | 14243 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14244 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14245 | bpt->number); | |
14246 | return; | |
c5aa993b | 14247 | } |
c906108c | 14248 | } |
0101ce28 | 14249 | |
b775012e LM |
14250 | bpt->enable_state = bp_enabled; |
14251 | ||
14252 | /* Mark breakpoint locations modified. */ | |
14253 | mark_breakpoint_modified (bpt); | |
14254 | ||
d248b706 KY |
14255 | if (target_supports_enable_disable_tracepoint () |
14256 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14257 | { | |
14258 | struct bp_location *location; | |
14259 | ||
14260 | for (location = bpt->loc; location; location = location->next) | |
14261 | target_enable_tracepoint (location); | |
14262 | } | |
14263 | ||
b4c291bb | 14264 | bpt->disposition = disposition; |
816338b5 | 14265 | bpt->enable_count = count; |
44702360 | 14266 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14267 | |
76727919 | 14268 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14269 | } |
14270 | ||
fe3f5fa8 | 14271 | |
c906108c | 14272 | void |
fba45db2 | 14273 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14274 | { |
816338b5 | 14275 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14276 | } |
14277 | ||
d0fe4701 XR |
14278 | /* The enable command enables the specified breakpoints/locations (or |
14279 | all defined breakpoints) so they once again become (or continue to | |
14280 | be) effective in stopping the inferior. ARGS may be in any of the | |
14281 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 14282 | |
c906108c | 14283 | static void |
981a3fb3 | 14284 | enable_command (const char *args, int from_tty) |
c906108c | 14285 | { |
d0fe4701 | 14286 | enable_disable_command (args, from_tty, true); |
c906108c SS |
14287 | } |
14288 | ||
c906108c | 14289 | static void |
4495129a | 14290 | enable_once_command (const char *args, int from_tty) |
c906108c | 14291 | { |
48649e1b TT |
14292 | map_breakpoint_numbers |
14293 | (args, [&] (breakpoint *b) | |
14294 | { | |
14295 | iterate_over_related_breakpoints | |
14296 | (b, [&] (breakpoint *bpt) | |
14297 | { | |
14298 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14299 | }); | |
14300 | }); | |
816338b5 SS |
14301 | } |
14302 | ||
14303 | static void | |
4495129a | 14304 | enable_count_command (const char *args, int from_tty) |
816338b5 | 14305 | { |
b9d61307 SM |
14306 | int count; |
14307 | ||
14308 | if (args == NULL) | |
14309 | error_no_arg (_("hit count")); | |
14310 | ||
14311 | count = get_number (&args); | |
816338b5 | 14312 | |
48649e1b TT |
14313 | map_breakpoint_numbers |
14314 | (args, [&] (breakpoint *b) | |
14315 | { | |
14316 | iterate_over_related_breakpoints | |
14317 | (b, [&] (breakpoint *bpt) | |
14318 | { | |
14319 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14320 | }); | |
14321 | }); | |
c906108c SS |
14322 | } |
14323 | ||
c906108c | 14324 | static void |
4495129a | 14325 | enable_delete_command (const char *args, int from_tty) |
c906108c | 14326 | { |
48649e1b TT |
14327 | map_breakpoint_numbers |
14328 | (args, [&] (breakpoint *b) | |
14329 | { | |
14330 | iterate_over_related_breakpoints | |
14331 | (b, [&] (breakpoint *bpt) | |
14332 | { | |
14333 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14334 | }); | |
14335 | }); | |
c906108c SS |
14336 | } |
14337 | \f | |
fa8d40ab | 14338 | static void |
981a3fb3 | 14339 | set_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14340 | { |
14341 | } | |
14342 | ||
14343 | static void | |
981a3fb3 | 14344 | show_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14345 | { |
14346 | } | |
14347 | ||
1f3b5d1b PP |
14348 | /* Invalidate last known value of any hardware watchpoint if |
14349 | the memory which that value represents has been written to by | |
14350 | GDB itself. */ | |
14351 | ||
14352 | static void | |
8de0566d YQ |
14353 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14354 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14355 | const bfd_byte *data) |
14356 | { | |
14357 | struct breakpoint *bp; | |
14358 | ||
14359 | ALL_BREAKPOINTS (bp) | |
14360 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14361 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14362 | { |
3a5c3e22 | 14363 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14364 | |
850645cf | 14365 | if (wp->val_valid && wp->val != nullptr) |
3a5c3e22 PA |
14366 | { |
14367 | struct bp_location *loc; | |
14368 | ||
14369 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14370 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14371 | && loc->address + loc->length > addr | |
14372 | && addr + len > loc->address) | |
14373 | { | |
3a5c3e22 | 14374 | wp->val = NULL; |
4c1d86d9 | 14375 | wp->val_valid = false; |
3a5c3e22 PA |
14376 | } |
14377 | } | |
1f3b5d1b PP |
14378 | } |
14379 | } | |
14380 | ||
8181d85f DJ |
14381 | /* Create and insert a breakpoint for software single step. */ |
14382 | ||
14383 | void | |
6c95b8df | 14384 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 14385 | const address_space *aspace, |
4a64f543 | 14386 | CORE_ADDR next_pc) |
8181d85f | 14387 | { |
7c16b83e PA |
14388 | struct thread_info *tp = inferior_thread (); |
14389 | struct symtab_and_line sal; | |
14390 | CORE_ADDR pc = next_pc; | |
8181d85f | 14391 | |
34b7e8a6 PA |
14392 | if (tp->control.single_step_breakpoints == NULL) |
14393 | { | |
14394 | tp->control.single_step_breakpoints | |
5d5658a1 | 14395 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14396 | } |
8181d85f | 14397 | |
7c16b83e PA |
14398 | sal = find_pc_line (pc, 0); |
14399 | sal.pc = pc; | |
14400 | sal.section = find_pc_overlay (pc); | |
14401 | sal.explicit_pc = 1; | |
34b7e8a6 | 14402 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14403 | |
7c16b83e | 14404 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14405 | } |
14406 | ||
93f9a11f YQ |
14407 | /* Insert single step breakpoints according to the current state. */ |
14408 | ||
14409 | int | |
14410 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14411 | { | |
f5ea389a | 14412 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14413 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14414 | |
f5ea389a | 14415 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14416 | |
a0ff9e1a | 14417 | if (!next_pcs.empty ()) |
93f9a11f | 14418 | { |
f5ea389a | 14419 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 14420 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 14421 | |
a0ff9e1a | 14422 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14423 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14424 | ||
93f9a11f YQ |
14425 | return 1; |
14426 | } | |
14427 | else | |
14428 | return 0; | |
14429 | } | |
14430 | ||
34b7e8a6 | 14431 | /* See breakpoint.h. */ |
f02253f1 HZ |
14432 | |
14433 | int | |
7c16b83e | 14434 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 14435 | const address_space *aspace, |
7c16b83e | 14436 | CORE_ADDR pc) |
1aafd4da | 14437 | { |
7c16b83e | 14438 | struct bp_location *loc; |
1aafd4da | 14439 | |
7c16b83e PA |
14440 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14441 | if (loc->inserted | |
14442 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14443 | return 1; | |
1aafd4da | 14444 | |
7c16b83e | 14445 | return 0; |
ef370185 JB |
14446 | } |
14447 | ||
14448 | /* Check whether a software single-step breakpoint is inserted at | |
14449 | PC. */ | |
14450 | ||
14451 | int | |
accd0bcd | 14452 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
14453 | CORE_ADDR pc) |
14454 | { | |
34b7e8a6 PA |
14455 | struct breakpoint *bpt; |
14456 | ||
14457 | ALL_BREAKPOINTS (bpt) | |
14458 | { | |
14459 | if (bpt->type == bp_single_step | |
14460 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14461 | return 1; | |
14462 | } | |
14463 | return 0; | |
1aafd4da UW |
14464 | } |
14465 | ||
1042e4c0 SS |
14466 | /* Tracepoint-specific operations. */ |
14467 | ||
14468 | /* Set tracepoint count to NUM. */ | |
14469 | static void | |
14470 | set_tracepoint_count (int num) | |
14471 | { | |
14472 | tracepoint_count = num; | |
4fa62494 | 14473 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14474 | } |
14475 | ||
70221824 | 14476 | static void |
0b39b52e | 14477 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 14478 | { |
55aa24fb | 14479 | struct breakpoint_ops *ops; |
55aa24fb | 14480 | |
ffc2605c TT |
14481 | event_location_up location = string_to_event_location (&arg, |
14482 | current_language); | |
5b56227b | 14483 | if (location != NULL |
ffc2605c | 14484 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
14485 | ops = &tracepoint_probe_breakpoint_ops; |
14486 | else | |
14487 | ops = &tracepoint_breakpoint_ops; | |
14488 | ||
558a9d82 | 14489 | create_breakpoint (get_current_arch (), |
ffc2605c | 14490 | location.get (), |
f00aae0f | 14491 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14492 | 0 /* tempflag */, |
14493 | bp_tracepoint /* type_wanted */, | |
14494 | 0 /* Ignore count */, | |
14495 | pending_break_support, | |
14496 | ops, | |
14497 | from_tty, | |
14498 | 1 /* enabled */, | |
14499 | 0 /* internal */, 0); | |
1042e4c0 SS |
14500 | } |
14501 | ||
70221824 | 14502 | static void |
0b39b52e | 14503 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 14504 | { |
ffc2605c TT |
14505 | event_location_up location = string_to_event_location (&arg, |
14506 | current_language); | |
558a9d82 | 14507 | create_breakpoint (get_current_arch (), |
ffc2605c | 14508 | location.get (), |
f00aae0f | 14509 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14510 | 0 /* tempflag */, |
14511 | bp_fast_tracepoint /* type_wanted */, | |
14512 | 0 /* Ignore count */, | |
14513 | pending_break_support, | |
14514 | &tracepoint_breakpoint_ops, | |
14515 | from_tty, | |
14516 | 1 /* enabled */, | |
14517 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14518 | } |
14519 | ||
14520 | /* strace command implementation. Creates a static tracepoint. */ | |
14521 | ||
70221824 | 14522 | static void |
0b39b52e | 14523 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 14524 | { |
983af33b | 14525 | struct breakpoint_ops *ops; |
ffc2605c | 14526 | event_location_up location; |
983af33b SDJ |
14527 | |
14528 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14529 | or with a normal static tracepoint. */ | |
61012eef | 14530 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14531 | { |
14532 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 14533 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
f00aae0f | 14534 | } |
983af33b | 14535 | else |
f00aae0f KS |
14536 | { |
14537 | ops = &tracepoint_breakpoint_ops; | |
14538 | location = string_to_event_location (&arg, current_language); | |
14539 | } | |
983af33b | 14540 | |
558a9d82 | 14541 | create_breakpoint (get_current_arch (), |
ffc2605c | 14542 | location.get (), |
f00aae0f | 14543 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14544 | 0 /* tempflag */, |
14545 | bp_static_tracepoint /* type_wanted */, | |
14546 | 0 /* Ignore count */, | |
14547 | pending_break_support, | |
14548 | ops, | |
14549 | from_tty, | |
14550 | 1 /* enabled */, | |
14551 | 0 /* internal */, 0); | |
7a697b8d SS |
14552 | } |
14553 | ||
409873ef SS |
14554 | /* Set up a fake reader function that gets command lines from a linked |
14555 | list that was acquired during tracepoint uploading. */ | |
14556 | ||
14557 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14558 | static int next_cmd; |
409873ef SS |
14559 | |
14560 | static char * | |
14561 | read_uploaded_action (void) | |
14562 | { | |
a18ba4e4 | 14563 | char *rslt = nullptr; |
409873ef | 14564 | |
a18ba4e4 SM |
14565 | if (next_cmd < this_utp->cmd_strings.size ()) |
14566 | { | |
67aa1f3c | 14567 | rslt = this_utp->cmd_strings[next_cmd].get (); |
a18ba4e4 SM |
14568 | next_cmd++; |
14569 | } | |
409873ef SS |
14570 | |
14571 | return rslt; | |
14572 | } | |
14573 | ||
00bf0b85 SS |
14574 | /* Given information about a tracepoint as recorded on a target (which |
14575 | can be either a live system or a trace file), attempt to create an | |
14576 | equivalent GDB tracepoint. This is not a reliable process, since | |
14577 | the target does not necessarily have all the information used when | |
14578 | the tracepoint was originally defined. */ | |
14579 | ||
d9b3f62e | 14580 | struct tracepoint * |
00bf0b85 | 14581 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14582 | { |
f2fc3015 TT |
14583 | const char *addr_str; |
14584 | char small_buf[100]; | |
d9b3f62e | 14585 | struct tracepoint *tp; |
fd9b8c24 | 14586 | |
409873ef | 14587 | if (utp->at_string) |
67aa1f3c | 14588 | addr_str = utp->at_string.get (); |
409873ef SS |
14589 | else |
14590 | { | |
14591 | /* In the absence of a source location, fall back to raw | |
14592 | address. Since there is no way to confirm that the address | |
14593 | means the same thing as when the trace was started, warn the | |
14594 | user. */ | |
3e43a32a MS |
14595 | warning (_("Uploaded tracepoint %d has no " |
14596 | "source location, using raw address"), | |
409873ef | 14597 | utp->number); |
8c042590 | 14598 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14599 | addr_str = small_buf; |
14600 | } | |
14601 | ||
14602 | /* There's not much we can do with a sequence of bytecodes. */ | |
14603 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14604 | warning (_("Uploaded tracepoint %d condition " |
14605 | "has no source form, ignoring it"), | |
409873ef | 14606 | utp->number); |
d5551862 | 14607 | |
ffc2605c TT |
14608 | event_location_up location = string_to_event_location (&addr_str, |
14609 | current_language); | |
8cdf0e15 | 14610 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14611 | location.get (), |
67aa1f3c | 14612 | utp->cond_string.get (), -1, addr_str, |
e7e0cddf | 14613 | 0 /* parse cond/thread */, |
8cdf0e15 | 14614 | 0 /* tempflag */, |
0fb4aa4b | 14615 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14616 | 0 /* Ignore count */, |
14617 | pending_break_support, | |
348d480f | 14618 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14619 | 0 /* from_tty */, |
84f4c1fe | 14620 | utp->enabled /* enabled */, |
44f238bb PA |
14621 | 0 /* internal */, |
14622 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14623 | return NULL; |
fd9b8c24 | 14624 | |
409873ef | 14625 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14626 | tp = get_tracepoint (tracepoint_count); |
14627 | gdb_assert (tp != NULL); | |
d5551862 | 14628 | |
00bf0b85 SS |
14629 | if (utp->pass > 0) |
14630 | { | |
8c042590 | 14631 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14632 | tp->number); |
00bf0b85 | 14633 | |
409873ef | 14634 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14635 | } |
14636 | ||
409873ef SS |
14637 | /* If we have uploaded versions of the original commands, set up a |
14638 | special-purpose "reader" function and call the usual command line | |
14639 | reader, then pass the result to the breakpoint command-setting | |
14640 | function. */ | |
a18ba4e4 | 14641 | if (!utp->cmd_strings.empty ()) |
00bf0b85 | 14642 | { |
12973681 | 14643 | counted_command_line cmd_list; |
00bf0b85 | 14644 | |
409873ef | 14645 | this_utp = utp; |
3149d8c1 | 14646 | next_cmd = 0; |
d5551862 | 14647 | |
60b3cef2 | 14648 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
409873ef | 14649 | |
c1fc2657 | 14650 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14651 | } |
a18ba4e4 SM |
14652 | else if (!utp->actions.empty () |
14653 | || !utp->step_actions.empty ()) | |
3e43a32a MS |
14654 | warning (_("Uploaded tracepoint %d actions " |
14655 | "have no source form, ignoring them"), | |
409873ef | 14656 | utp->number); |
00bf0b85 | 14657 | |
f196051f | 14658 | /* Copy any status information that might be available. */ |
c1fc2657 | 14659 | tp->hit_count = utp->hit_count; |
f196051f SS |
14660 | tp->traceframe_usage = utp->traceframe_usage; |
14661 | ||
00bf0b85 | 14662 | return tp; |
d9b3f62e | 14663 | } |
00bf0b85 | 14664 | |
1042e4c0 SS |
14665 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14666 | omitted. */ | |
14667 | ||
14668 | static void | |
1d12d88f | 14669 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 14670 | { |
79a45e25 | 14671 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14672 | int num_printed; |
1042e4c0 | 14673 | |
5c458ae8 | 14674 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
d77f58be SS |
14675 | |
14676 | if (num_printed == 0) | |
1042e4c0 | 14677 | { |
e5a67952 | 14678 | if (args == NULL || *args == '\0') |
112e8700 | 14679 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14680 | else |
112e8700 | 14681 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14682 | } |
ad443146 SS |
14683 | |
14684 | default_collect_info (); | |
1042e4c0 SS |
14685 | } |
14686 | ||
4a64f543 | 14687 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14688 | Not supported by all targets. */ |
14689 | static void | |
5fed81ff | 14690 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14691 | { |
14692 | enable_command (args, from_tty); | |
14693 | } | |
14694 | ||
4a64f543 | 14695 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14696 | Not supported by all targets. */ |
14697 | static void | |
5fed81ff | 14698 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14699 | { |
14700 | disable_command (args, from_tty); | |
14701 | } | |
14702 | ||
4a64f543 | 14703 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 14704 | static void |
4495129a | 14705 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 14706 | { |
35df4500 | 14707 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14708 | |
14709 | dont_repeat (); | |
14710 | ||
14711 | if (arg == 0) | |
14712 | { | |
14713 | int breaks_to_delete = 0; | |
14714 | ||
14715 | /* Delete all breakpoints if no argument. | |
14716 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14717 | have to be deleted with an explicit breakpoint number |
14718 | argument. */ | |
1042e4c0 | 14719 | ALL_TRACEPOINTS (b) |
46c6471b | 14720 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14721 | { |
14722 | breaks_to_delete = 1; | |
14723 | break; | |
14724 | } | |
1042e4c0 SS |
14725 | |
14726 | /* Ask user only if there are some breakpoints to delete. */ | |
14727 | if (!from_tty | |
14728 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14729 | { | |
35df4500 | 14730 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14731 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14732 | delete_breakpoint (b); |
1042e4c0 SS |
14733 | } |
14734 | } | |
14735 | else | |
48649e1b | 14736 | map_breakpoint_numbers |
b926417a | 14737 | (arg, [&] (breakpoint *br) |
48649e1b | 14738 | { |
b926417a | 14739 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 14740 | }); |
1042e4c0 SS |
14741 | } |
14742 | ||
197f0a60 TT |
14743 | /* Helper function for trace_pass_command. */ |
14744 | ||
14745 | static void | |
d9b3f62e | 14746 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14747 | { |
d9b3f62e | 14748 | tp->pass_count = count; |
76727919 | 14749 | gdb::observers::breakpoint_modified.notify (tp); |
197f0a60 TT |
14750 | if (from_tty) |
14751 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 14752 | tp->number, count); |
197f0a60 TT |
14753 | } |
14754 | ||
1042e4c0 SS |
14755 | /* Set passcount for tracepoint. |
14756 | ||
14757 | First command argument is passcount, second is tracepoint number. | |
14758 | If tracepoint number omitted, apply to most recently defined. | |
14759 | Also accepts special argument "all". */ | |
14760 | ||
14761 | static void | |
0b39b52e | 14762 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 14763 | { |
d9b3f62e | 14764 | struct tracepoint *t1; |
0b39b52e | 14765 | ULONGEST count; |
1042e4c0 SS |
14766 | |
14767 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14768 | error (_("passcount command requires an " |
14769 | "argument (count + optional TP num)")); | |
1042e4c0 | 14770 | |
0b39b52e | 14771 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 14772 | |
529480d0 | 14773 | args = skip_spaces (args); |
1042e4c0 SS |
14774 | if (*args && strncasecmp (args, "all", 3) == 0) |
14775 | { | |
d9b3f62e PA |
14776 | struct breakpoint *b; |
14777 | ||
1042e4c0 | 14778 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
14779 | if (*args) |
14780 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 14781 | |
d9b3f62e | 14782 | ALL_TRACEPOINTS (b) |
197f0a60 | 14783 | { |
d9b3f62e | 14784 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
14785 | trace_pass_set_count (t1, count, from_tty); |
14786 | } | |
14787 | } | |
14788 | else if (*args == '\0') | |
1042e4c0 | 14789 | { |
5fa1d40e | 14790 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 14791 | if (t1) |
197f0a60 TT |
14792 | trace_pass_set_count (t1, count, from_tty); |
14793 | } | |
14794 | else | |
14795 | { | |
bfd28288 PA |
14796 | number_or_range_parser parser (args); |
14797 | while (!parser.finished ()) | |
1042e4c0 | 14798 | { |
bfd28288 | 14799 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
14800 | if (t1) |
14801 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14802 | } |
14803 | } | |
1042e4c0 SS |
14804 | } |
14805 | ||
d9b3f62e | 14806 | struct tracepoint * |
1042e4c0 SS |
14807 | get_tracepoint (int num) |
14808 | { | |
14809 | struct breakpoint *t; | |
14810 | ||
14811 | ALL_TRACEPOINTS (t) | |
14812 | if (t->number == num) | |
d9b3f62e | 14813 | return (struct tracepoint *) t; |
1042e4c0 SS |
14814 | |
14815 | return NULL; | |
14816 | } | |
14817 | ||
d5551862 SS |
14818 | /* Find the tracepoint with the given target-side number (which may be |
14819 | different from the tracepoint number after disconnecting and | |
14820 | reconnecting). */ | |
14821 | ||
d9b3f62e | 14822 | struct tracepoint * |
d5551862 SS |
14823 | get_tracepoint_by_number_on_target (int num) |
14824 | { | |
d9b3f62e | 14825 | struct breakpoint *b; |
d5551862 | 14826 | |
d9b3f62e PA |
14827 | ALL_TRACEPOINTS (b) |
14828 | { | |
14829 | struct tracepoint *t = (struct tracepoint *) b; | |
14830 | ||
14831 | if (t->number_on_target == num) | |
14832 | return t; | |
14833 | } | |
d5551862 SS |
14834 | |
14835 | return NULL; | |
14836 | } | |
14837 | ||
1042e4c0 | 14838 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 14839 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
14840 | If the argument is missing, the most recent tracepoint |
14841 | (tracepoint_count) is returned. */ | |
14842 | ||
d9b3f62e | 14843 | struct tracepoint * |
0b39b52e | 14844 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 14845 | number_or_range_parser *parser) |
1042e4c0 | 14846 | { |
1042e4c0 SS |
14847 | struct breakpoint *t; |
14848 | int tpnum; | |
0b39b52e | 14849 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 14850 | |
bfd28288 | 14851 | if (parser != NULL) |
197f0a60 | 14852 | { |
bfd28288 PA |
14853 | gdb_assert (!parser->finished ()); |
14854 | tpnum = parser->get_number (); | |
197f0a60 TT |
14855 | } |
14856 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 14857 | tpnum = tracepoint_count; |
1042e4c0 | 14858 | else |
197f0a60 | 14859 | tpnum = get_number (arg); |
1042e4c0 SS |
14860 | |
14861 | if (tpnum <= 0) | |
14862 | { | |
14863 | if (instring && *instring) | |
14864 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
14865 | instring); | |
14866 | else | |
5fa1d40e | 14867 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
14868 | return NULL; |
14869 | } | |
14870 | ||
14871 | ALL_TRACEPOINTS (t) | |
14872 | if (t->number == tpnum) | |
14873 | { | |
d9b3f62e | 14874 | return (struct tracepoint *) t; |
1042e4c0 SS |
14875 | } |
14876 | ||
1042e4c0 SS |
14877 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
14878 | return NULL; | |
14879 | } | |
14880 | ||
d9b3f62e PA |
14881 | void |
14882 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14883 | { | |
14884 | if (b->thread != -1) | |
14885 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
14886 | ||
14887 | if (b->task != 0) | |
14888 | fprintf_unfiltered (fp, " task %d", b->task); | |
14889 | ||
14890 | fprintf_unfiltered (fp, "\n"); | |
14891 | } | |
14892 | ||
6149aea9 PA |
14893 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14894 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14895 | on each breakpoint and only include the ones for which it returns | |
f2478a7e | 14896 | true. */ |
6149aea9 | 14897 | |
1042e4c0 | 14898 | static void |
4495129a | 14899 | save_breakpoints (const char *filename, int from_tty, |
f2478a7e | 14900 | bool (*filter) (const struct breakpoint *)) |
1042e4c0 SS |
14901 | { |
14902 | struct breakpoint *tp; | |
6149aea9 | 14903 | int any = 0; |
6149aea9 | 14904 | int extra_trace_bits = 0; |
1042e4c0 | 14905 | |
6149aea9 PA |
14906 | if (filename == 0 || *filename == 0) |
14907 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14908 | |
14909 | /* See if we have anything to save. */ | |
6149aea9 | 14910 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14911 | { |
6149aea9 | 14912 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14913 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
14914 | continue; |
14915 | ||
14916 | /* If we have a filter, only save the breakpoints it accepts. */ | |
14917 | if (filter && !filter (tp)) | |
14918 | continue; | |
14919 | ||
14920 | any = 1; | |
14921 | ||
14922 | if (is_tracepoint (tp)) | |
14923 | { | |
14924 | extra_trace_bits = 1; | |
14925 | ||
14926 | /* We can stop searching. */ | |
14927 | break; | |
14928 | } | |
1042e4c0 | 14929 | } |
6149aea9 PA |
14930 | |
14931 | if (!any) | |
1042e4c0 | 14932 | { |
6149aea9 | 14933 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14934 | return; |
14935 | } | |
14936 | ||
ee0c3293 | 14937 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
14938 | |
14939 | stdio_file fp; | |
14940 | ||
ee0c3293 | 14941 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 14942 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 14943 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 14944 | |
6149aea9 | 14945 | if (extra_trace_bits) |
d7e74731 | 14946 | save_trace_state_variables (&fp); |
8bf6485c | 14947 | |
6149aea9 | 14948 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14949 | { |
6149aea9 | 14950 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14951 | if (!user_breakpoint_p (tp)) |
6149aea9 | 14952 | continue; |
8bf6485c | 14953 | |
6149aea9 PA |
14954 | /* If we have a filter, only save the breakpoints it accepts. */ |
14955 | if (filter && !filter (tp)) | |
14956 | continue; | |
14957 | ||
d7e74731 | 14958 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 14959 | |
6149aea9 PA |
14960 | /* Note, we can't rely on tp->number for anything, as we can't |
14961 | assume the recreated breakpoint numbers will match. Use $bpnum | |
14962 | instead. */ | |
14963 | ||
14964 | if (tp->cond_string) | |
d7e74731 | 14965 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
14966 | |
14967 | if (tp->ignore_count) | |
d7e74731 | 14968 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 14969 | |
2d9442cc | 14970 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 14971 | { |
d7e74731 | 14972 | fp.puts (" commands\n"); |
a7bdde9e | 14973 | |
d7e74731 | 14974 | current_uiout->redirect (&fp); |
a70b8144 | 14975 | try |
1042e4c0 | 14976 | { |
d1b0a7bf | 14977 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 14978 | } |
230d2906 | 14979 | catch (const gdb_exception &ex) |
492d29ea | 14980 | { |
112e8700 | 14981 | current_uiout->redirect (NULL); |
eedc3f4f | 14982 | throw; |
492d29ea | 14983 | } |
1042e4c0 | 14984 | |
112e8700 | 14985 | current_uiout->redirect (NULL); |
d7e74731 | 14986 | fp.puts (" end\n"); |
1042e4c0 | 14987 | } |
6149aea9 PA |
14988 | |
14989 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 14990 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
14991 | |
14992 | /* If this is a multi-location breakpoint, check if the locations | |
14993 | should be individually disabled. Watchpoint locations are | |
14994 | special, and not user visible. */ | |
14995 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
14996 | { | |
14997 | struct bp_location *loc; | |
14998 | int n = 1; | |
14999 | ||
15000 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15001 | if (!loc->enabled) | |
d7e74731 | 15002 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15003 | } |
1042e4c0 | 15004 | } |
8bf6485c | 15005 | |
6149aea9 | 15006 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15007 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15008 | |
1042e4c0 | 15009 | if (from_tty) |
ee0c3293 | 15010 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15011 | } |
15012 | ||
15013 | /* The `save breakpoints' command. */ | |
15014 | ||
15015 | static void | |
4495129a | 15016 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
15017 | { |
15018 | save_breakpoints (args, from_tty, NULL); | |
15019 | } | |
15020 | ||
15021 | /* The `save tracepoints' command. */ | |
15022 | ||
15023 | static void | |
4495129a | 15024 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
15025 | { |
15026 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15027 | } |
15028 | ||
15029 | /* Create a vector of all tracepoints. */ | |
15030 | ||
f51e0e20 | 15031 | std::vector<breakpoint *> |
eeae04df | 15032 | all_tracepoints (void) |
1042e4c0 | 15033 | { |
f51e0e20 | 15034 | std::vector<breakpoint *> tp_vec; |
1042e4c0 SS |
15035 | struct breakpoint *tp; |
15036 | ||
15037 | ALL_TRACEPOINTS (tp) | |
15038 | { | |
f51e0e20 | 15039 | tp_vec.push_back (tp); |
1042e4c0 SS |
15040 | } |
15041 | ||
15042 | return tp_vec; | |
15043 | } | |
15044 | ||
c906108c | 15045 | \f |
629500fa KS |
15046 | /* This help string is used to consolidate all the help string for specifying |
15047 | locations used by several commands. */ | |
15048 | ||
15049 | #define LOCATION_HELP_STRING \ | |
15050 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15051 | source filename, function name, label name, and line number.\n\ | |
15052 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15053 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15054 | \"factorial.c:fact:the_top\".\n\ | |
15055 | \n\ | |
15056 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15057 | program. Example: To specify the fourth byte past the start function\n\ | |
15058 | \"main\", use \"*main + 4\".\n\ | |
15059 | \n\ | |
15060 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15061 | syntax to specify location parameters.\n\ | |
15062 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15063 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
15064 | -function fact -label the_top\".\n\ |
15065 | \n\ | |
15066 | By default, a specified function is matched against the program's\n\ | |
15067 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
15068 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
15069 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
15070 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
89549d7f | 15071 | specified name as a complete fully-qualified name instead." |
629500fa | 15072 | |
4a64f543 MS |
15073 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15074 | commands. It is defined as a macro to prevent duplication. | |
15075 | COMMAND should be a string constant containing the name of the | |
15076 | command. */ | |
629500fa | 15077 | |
31e2b00f | 15078 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15079 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15080 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15081 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15082 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15083 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15084 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15085 | below.\n\ | |
15086 | \n\ | |
dc10affe PA |
15087 | With no LOCATION, uses current execution address of the selected\n\ |
15088 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15089 | \n\ |
15090 | THREADNUM is the number from \"info threads\".\n\ | |
15091 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15092 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15093 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15094 | conditions are different.\n\ | |
31e2b00f AS |
15095 | \n\ |
15096 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15097 | ||
44feb3ce TT |
15098 | /* List of subcommands for "catch". */ |
15099 | static struct cmd_list_element *catch_cmdlist; | |
15100 | ||
15101 | /* List of subcommands for "tcatch". */ | |
15102 | static struct cmd_list_element *tcatch_cmdlist; | |
15103 | ||
9ac4176b | 15104 | void |
a121b7c1 | 15105 | add_catch_command (const char *name, const char *docstring, |
eb4c3f4a | 15106 | cmd_const_sfunc_ftype *sfunc, |
625e8578 | 15107 | completer_ftype *completer, |
44feb3ce TT |
15108 | void *user_data_catch, |
15109 | void *user_data_tcatch) | |
15110 | { | |
15111 | struct cmd_list_element *command; | |
15112 | ||
0450cc4c | 15113 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15114 | &catch_cmdlist); |
15115 | set_cmd_sfunc (command, sfunc); | |
15116 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15117 | set_cmd_completer (command, completer); |
44feb3ce | 15118 | |
0450cc4c | 15119 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15120 | &tcatch_cmdlist); |
15121 | set_cmd_sfunc (command, sfunc); | |
15122 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15123 | set_cmd_completer (command, completer); |
44feb3ce TT |
15124 | } |
15125 | ||
6149aea9 | 15126 | static void |
981a3fb3 | 15127 | save_command (const char *arg, int from_tty) |
6149aea9 | 15128 | { |
3e43a32a MS |
15129 | printf_unfiltered (_("\"save\" must be followed by " |
15130 | "the name of a save subcommand.\n")); | |
635c7e8a | 15131 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15132 | } |
15133 | ||
84f4c1fe PM |
15134 | struct breakpoint * |
15135 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15136 | void *data) | |
15137 | { | |
35df4500 | 15138 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15139 | |
35df4500 | 15140 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15141 | { |
15142 | if ((*callback) (b, data)) | |
15143 | return b; | |
15144 | } | |
15145 | ||
15146 | return NULL; | |
15147 | } | |
15148 | ||
0574c78f GB |
15149 | /* Zero if any of the breakpoint's locations could be a location where |
15150 | functions have been inlined, nonzero otherwise. */ | |
15151 | ||
15152 | static int | |
15153 | is_non_inline_function (struct breakpoint *b) | |
15154 | { | |
15155 | /* The shared library event breakpoint is set on the address of a | |
15156 | non-inline function. */ | |
15157 | if (b->type == bp_shlib_event) | |
15158 | return 1; | |
15159 | ||
15160 | return 0; | |
15161 | } | |
15162 | ||
15163 | /* Nonzero if the specified PC cannot be a location where functions | |
15164 | have been inlined. */ | |
15165 | ||
15166 | int | |
accd0bcd | 15167 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
09ac7c10 | 15168 | const struct target_waitstatus *ws) |
0574c78f GB |
15169 | { |
15170 | struct breakpoint *b; | |
15171 | struct bp_location *bl; | |
15172 | ||
15173 | ALL_BREAKPOINTS (b) | |
15174 | { | |
15175 | if (!is_non_inline_function (b)) | |
15176 | continue; | |
15177 | ||
15178 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15179 | { | |
15180 | if (!bl->shlib_disabled | |
09ac7c10 | 15181 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15182 | return 1; |
15183 | } | |
15184 | } | |
15185 | ||
15186 | return 0; | |
15187 | } | |
15188 | ||
2f202fde JK |
15189 | /* Remove any references to OBJFILE which is going to be freed. */ |
15190 | ||
15191 | void | |
15192 | breakpoint_free_objfile (struct objfile *objfile) | |
15193 | { | |
15194 | struct bp_location **locp, *loc; | |
15195 | ||
15196 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15197 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15198 | loc->symtab = NULL; |
15199 | } | |
15200 | ||
2060206e PA |
15201 | void |
15202 | initialize_breakpoint_ops (void) | |
15203 | { | |
15204 | static int initialized = 0; | |
15205 | ||
15206 | struct breakpoint_ops *ops; | |
15207 | ||
15208 | if (initialized) | |
15209 | return; | |
15210 | initialized = 1; | |
15211 | ||
15212 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15213 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15214 | internal and momentary breakpoints, etc.). */ | |
15215 | ops = &bkpt_base_breakpoint_ops; | |
15216 | *ops = base_breakpoint_ops; | |
15217 | ops->re_set = bkpt_re_set; | |
15218 | ops->insert_location = bkpt_insert_location; | |
15219 | ops->remove_location = bkpt_remove_location; | |
15220 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15221 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15222 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15223 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15224 | |
15225 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15226 | ops = &bkpt_breakpoint_ops; | |
15227 | *ops = bkpt_base_breakpoint_ops; | |
15228 | ops->re_set = bkpt_re_set; | |
15229 | ops->resources_needed = bkpt_resources_needed; | |
15230 | ops->print_it = bkpt_print_it; | |
15231 | ops->print_mention = bkpt_print_mention; | |
15232 | ops->print_recreate = bkpt_print_recreate; | |
15233 | ||
15234 | /* Ranged breakpoints. */ | |
15235 | ops = &ranged_breakpoint_ops; | |
15236 | *ops = bkpt_breakpoint_ops; | |
15237 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15238 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15239 | ops->print_it = print_it_ranged_breakpoint; | |
15240 | ops->print_one = print_one_ranged_breakpoint; | |
15241 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15242 | ops->print_mention = print_mention_ranged_breakpoint; | |
15243 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15244 | ||
15245 | /* Internal breakpoints. */ | |
15246 | ops = &internal_breakpoint_ops; | |
15247 | *ops = bkpt_base_breakpoint_ops; | |
15248 | ops->re_set = internal_bkpt_re_set; | |
15249 | ops->check_status = internal_bkpt_check_status; | |
15250 | ops->print_it = internal_bkpt_print_it; | |
15251 | ops->print_mention = internal_bkpt_print_mention; | |
15252 | ||
15253 | /* Momentary breakpoints. */ | |
15254 | ops = &momentary_breakpoint_ops; | |
15255 | *ops = bkpt_base_breakpoint_ops; | |
15256 | ops->re_set = momentary_bkpt_re_set; | |
15257 | ops->check_status = momentary_bkpt_check_status; | |
15258 | ops->print_it = momentary_bkpt_print_it; | |
15259 | ops->print_mention = momentary_bkpt_print_mention; | |
15260 | ||
55aa24fb SDJ |
15261 | /* Probe breakpoints. */ |
15262 | ops = &bkpt_probe_breakpoint_ops; | |
15263 | *ops = bkpt_breakpoint_ops; | |
15264 | ops->insert_location = bkpt_probe_insert_location; | |
15265 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15266 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15267 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15268 | |
2060206e PA |
15269 | /* Watchpoints. */ |
15270 | ops = &watchpoint_breakpoint_ops; | |
15271 | *ops = base_breakpoint_ops; | |
15272 | ops->re_set = re_set_watchpoint; | |
15273 | ops->insert_location = insert_watchpoint; | |
15274 | ops->remove_location = remove_watchpoint; | |
15275 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15276 | ops->check_status = check_status_watchpoint; | |
15277 | ops->resources_needed = resources_needed_watchpoint; | |
15278 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15279 | ops->print_it = print_it_watchpoint; | |
15280 | ops->print_mention = print_mention_watchpoint; | |
15281 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15282 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15283 | |
15284 | /* Masked watchpoints. */ | |
15285 | ops = &masked_watchpoint_breakpoint_ops; | |
15286 | *ops = watchpoint_breakpoint_ops; | |
15287 | ops->insert_location = insert_masked_watchpoint; | |
15288 | ops->remove_location = remove_masked_watchpoint; | |
15289 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15290 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15291 | ops->print_it = print_it_masked_watchpoint; | |
15292 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15293 | ops->print_mention = print_mention_masked_watchpoint; | |
15294 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15295 | ||
15296 | /* Tracepoints. */ | |
15297 | ops = &tracepoint_breakpoint_ops; | |
15298 | *ops = base_breakpoint_ops; | |
15299 | ops->re_set = tracepoint_re_set; | |
15300 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15301 | ops->print_one_detail = tracepoint_print_one_detail; | |
15302 | ops->print_mention = tracepoint_print_mention; | |
15303 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15304 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15305 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15306 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15307 | |
55aa24fb SDJ |
15308 | /* Probe tracepoints. */ |
15309 | ops = &tracepoint_probe_breakpoint_ops; | |
15310 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15311 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15312 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15313 | |
983af33b SDJ |
15314 | /* Static tracepoints with marker (`-m'). */ |
15315 | ops = &strace_marker_breakpoint_ops; | |
15316 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15317 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15318 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15319 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15320 | |
15321 | /* Fork catchpoints. */ | |
15322 | ops = &catch_fork_breakpoint_ops; | |
15323 | *ops = base_breakpoint_ops; | |
15324 | ops->insert_location = insert_catch_fork; | |
15325 | ops->remove_location = remove_catch_fork; | |
15326 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15327 | ops->print_it = print_it_catch_fork; | |
15328 | ops->print_one = print_one_catch_fork; | |
15329 | ops->print_mention = print_mention_catch_fork; | |
15330 | ops->print_recreate = print_recreate_catch_fork; | |
15331 | ||
15332 | /* Vfork catchpoints. */ | |
15333 | ops = &catch_vfork_breakpoint_ops; | |
15334 | *ops = base_breakpoint_ops; | |
15335 | ops->insert_location = insert_catch_vfork; | |
15336 | ops->remove_location = remove_catch_vfork; | |
15337 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15338 | ops->print_it = print_it_catch_vfork; | |
15339 | ops->print_one = print_one_catch_vfork; | |
15340 | ops->print_mention = print_mention_catch_vfork; | |
15341 | ops->print_recreate = print_recreate_catch_vfork; | |
15342 | ||
15343 | /* Exec catchpoints. */ | |
15344 | ops = &catch_exec_breakpoint_ops; | |
15345 | *ops = base_breakpoint_ops; | |
2060206e PA |
15346 | ops->insert_location = insert_catch_exec; |
15347 | ops->remove_location = remove_catch_exec; | |
15348 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15349 | ops->print_it = print_it_catch_exec; | |
15350 | ops->print_one = print_one_catch_exec; | |
15351 | ops->print_mention = print_mention_catch_exec; | |
15352 | ops->print_recreate = print_recreate_catch_exec; | |
15353 | ||
edcc5120 TT |
15354 | /* Solib-related catchpoints. */ |
15355 | ops = &catch_solib_breakpoint_ops; | |
15356 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15357 | ops->insert_location = insert_catch_solib; |
15358 | ops->remove_location = remove_catch_solib; | |
15359 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15360 | ops->check_status = check_status_catch_solib; | |
15361 | ops->print_it = print_it_catch_solib; | |
15362 | ops->print_one = print_one_catch_solib; | |
15363 | ops->print_mention = print_mention_catch_solib; | |
15364 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15365 | |
15366 | ops = &dprintf_breakpoint_ops; | |
15367 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15368 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15369 | ops->resources_needed = bkpt_resources_needed; |
15370 | ops->print_it = bkpt_print_it; | |
15371 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15372 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15373 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15374 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15375 | } |
15376 | ||
8bfd80db YQ |
15377 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15378 | ||
15379 | static struct cmd_list_element *enablebreaklist = NULL; | |
15380 | ||
8588b356 SM |
15381 | /* See breakpoint.h. */ |
15382 | ||
15383 | cmd_list_element *commands_cmd_element = nullptr; | |
15384 | ||
c906108c | 15385 | void |
fba45db2 | 15386 | _initialize_breakpoint (void) |
c906108c SS |
15387 | { |
15388 | struct cmd_list_element *c; | |
15389 | ||
2060206e PA |
15390 | initialize_breakpoint_ops (); |
15391 | ||
76727919 TT |
15392 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib); |
15393 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile); | |
15394 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change); | |
84acb35a | 15395 | |
c906108c SS |
15396 | breakpoint_chain = 0; |
15397 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15398 | before a breakpoint is set. */ | |
15399 | breakpoint_count = 0; | |
15400 | ||
1042e4c0 SS |
15401 | tracepoint_count = 0; |
15402 | ||
1bedd215 AC |
15403 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15404 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15405 | Usage is `ignore N COUNT'.")); | |
c906108c | 15406 | |
8588b356 SM |
15407 | commands_cmd_element = add_com ("commands", class_breakpoint, |
15408 | commands_command, _("\ | |
18da0c51 MG |
15409 | Set commands to be executed when the given breakpoints are hit.\n\ |
15410 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15411 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15412 | (e.g. `5-7').\n\ | |
c906108c SS |
15413 | With no argument, the targeted breakpoint is the last one set.\n\ |
15414 | The commands themselves follow starting on the next line.\n\ | |
15415 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15416 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15417 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15418 | |
d55637df | 15419 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15420 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15421 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15422 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15423 | set_cmd_completer (c, condition_completer); |
c906108c | 15424 | |
1bedd215 | 15425 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15426 | Set a temporary breakpoint.\n\ |
c906108c SS |
15427 | Like \"break\" except the breakpoint is only temporary,\n\ |
15428 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15429 | by using \"enable delete\" on the breakpoint number.\n\ |
15430 | \n" | |
15431 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15432 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15433 | |
1bedd215 | 15434 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15435 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15436 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15437 | some target hardware may not have this support.\n\ |
15438 | \n" | |
15439 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15440 | set_cmd_completer (c, location_completer); |
c906108c | 15441 | |
1bedd215 | 15442 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15443 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15444 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15445 | so it will be deleted when hit.\n\ |
15446 | \n" | |
15447 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15448 | set_cmd_completer (c, location_completer); |
c906108c | 15449 | |
1bedd215 | 15450 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
590042fc PW |
15451 | Enable all or some breakpoints.\n\ |
15452 | Usage: enable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15453 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15454 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15455 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15456 | With a subcommand you can enable temporarily."), |
c906108c | 15457 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15458 | |
15459 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15460 | ||
84951ab5 | 15461 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
590042fc PW |
15462 | Enable all or some breakpoints.\n\ |
15463 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15464 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15465 | This is used to cancel the effect of the \"disable\" command.\n\ | |
89549d7f | 15466 | May be abbreviated to simply \"enable\"."), |
c5aa993b | 15467 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15468 | |
1a966eab | 15469 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15470 | Enable some breakpoints for one hit.\n\ |
15471 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ | |
1a966eab | 15472 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
c906108c SS |
15473 | &enablebreaklist); |
15474 | ||
1a966eab | 15475 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15476 | Enable some breakpoints and delete when hit.\n\ |
15477 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ | |
1a966eab | 15478 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15479 | &enablebreaklist); |
15480 | ||
816338b5 | 15481 | add_cmd ("count", no_class, enable_count_command, _("\ |
590042fc PW |
15482 | Enable some breakpoints for COUNT hits.\n\ |
15483 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15484 | If a breakpoint is hit while enabled in this fashion,\n\ |
15485 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15486 | &enablebreaklist); | |
15487 | ||
1a966eab | 15488 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15489 | Enable some breakpoints and delete when hit.\n\ |
15490 | Usage: enable delete BREAKPOINTNUM...\n\ | |
1a966eab | 15491 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15492 | &enablelist); |
15493 | ||
1a966eab | 15494 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15495 | Enable some breakpoints for one hit.\n\ |
15496 | Usage: enable once BREAKPOINTNUM...\n\ | |
1a966eab | 15497 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
816338b5 SS |
15498 | &enablelist); |
15499 | ||
15500 | add_cmd ("count", no_class, enable_count_command, _("\ | |
590042fc PW |
15501 | Enable some breakpoints for COUNT hits.\n\ |
15502 | Usage: enable count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15503 | If a breakpoint is hit while enabled in this fashion,\n\ |
15504 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15505 | &enablelist); |
15506 | ||
1bedd215 | 15507 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
590042fc PW |
15508 | Disable all or some breakpoints.\n\ |
15509 | Usage: disable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15510 | Arguments are breakpoint numbers with spaces in between.\n\ |
15511 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15512 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15513 | &disablelist, "disable ", 1, &cmdlist); |
15514 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15515 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15516 | |
1a966eab | 15517 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
590042fc PW |
15518 | Disable all or some breakpoints.\n\ |
15519 | Usage: disable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15520 | Arguments are breakpoint numbers with spaces in between.\n\ |
15521 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15522 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15523 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15524 | &disablelist); |
15525 | ||
1bedd215 | 15526 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
590042fc PW |
15527 | Delete all or some breakpoints.\n\ |
15528 | Usage: delete [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15529 | Arguments are breakpoint numbers with spaces in between.\n\ |
15530 | To delete all breakpoints, give no argument.\n\ | |
15531 | \n\ | |
590042fc | 15532 | Also a prefix command for deletion of other GDB objects."), |
c906108c SS |
15533 | &deletelist, "delete ", 1, &cmdlist); |
15534 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15535 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15536 | |
1a966eab | 15537 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
590042fc PW |
15538 | Delete all or some breakpoints or auto-display expressions.\n\ |
15539 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15540 | Arguments are breakpoint numbers with spaces in between.\n\ |
15541 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15542 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15543 | &deletelist); |
15544 | ||
1bedd215 | 15545 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15546 | Clear breakpoint at specified location.\n\ |
15547 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15548 | \n\ |
15549 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa | 15550 | is executing in.\n" |
89549d7f | 15551 | "\n" LOCATION_HELP_STRING "\n\n\ |
1bedd215 | 15552 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15553 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15554 | |
1bedd215 | 15555 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15556 | Set breakpoint at specified location.\n" |
31e2b00f | 15557 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15558 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15559 | |
c906108c SS |
15560 | add_com_alias ("b", "break", class_run, 1); |
15561 | add_com_alias ("br", "break", class_run, 1); | |
15562 | add_com_alias ("bre", "break", class_run, 1); | |
15563 | add_com_alias ("brea", "break", class_run, 1); | |
15564 | ||
c906108c SS |
15565 | if (dbx_commands) |
15566 | { | |
1bedd215 AC |
15567 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15568 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15569 | &stoplist, "stop ", 1, &cmdlist); |
15570 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15571 | _("Break in function or address."), &stoplist); |
c5aa993b | 15572 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15573 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15574 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15575 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15576 | The \"Type\" column indicates one of:\n\ |
15577 | \tbreakpoint - normal breakpoint\n\ | |
15578 | \twatchpoint - watchpoint\n\ | |
15579 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15580 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15581 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15582 | address and file/line number respectively.\n\ |
15583 | \n\ | |
15584 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15585 | are set to the address of the last breakpoint listed unless the command\n\ |
15586 | is prefixed with \"server \".\n\n\ | |
c906108c | 15587 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15588 | breakpoint set.")); |
c906108c SS |
15589 | } |
15590 | ||
11db9430 | 15591 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15592 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15593 | The \"Type\" column indicates one of:\n\ |
15594 | \tbreakpoint - normal breakpoint\n\ | |
15595 | \twatchpoint - watchpoint\n\ | |
15596 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15597 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15598 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15599 | address and file/line number respectively.\n\ |
15600 | \n\ | |
15601 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15602 | are set to the address of the last breakpoint listed unless the command\n\ |
15603 | is prefixed with \"server \".\n\n\ | |
c906108c | 15604 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15605 | breakpoint set.")); |
c906108c | 15606 | |
6b04bdb7 MS |
15607 | add_info_alias ("b", "breakpoints", 1); |
15608 | ||
1a966eab AC |
15609 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15610 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15611 | The \"Type\" column indicates one of:\n\ |
15612 | \tbreakpoint - normal breakpoint\n\ | |
15613 | \twatchpoint - watchpoint\n\ | |
15614 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15615 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15616 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15617 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15618 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15619 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15620 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15621 | address and file/line number respectively.\n\ |
15622 | \n\ | |
15623 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15624 | are set to the address of the last breakpoint listed unless the command\n\ |
15625 | is prefixed with \"server \".\n\n\ | |
c906108c | 15626 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15627 | breakpoint set."), |
c906108c SS |
15628 | &maintenanceinfolist); |
15629 | ||
44feb3ce TT |
15630 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15631 | Set catchpoints to catch events."), | |
15632 | &catch_cmdlist, "catch ", | |
15633 | 0/*allow-unknown*/, &cmdlist); | |
15634 | ||
15635 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15636 | Set temporary catchpoints to catch events."), | |
15637 | &tcatch_cmdlist, "tcatch ", | |
15638 | 0/*allow-unknown*/, &cmdlist); | |
15639 | ||
44feb3ce TT |
15640 | add_catch_command ("fork", _("Catch calls to fork."), |
15641 | catch_fork_command_1, | |
a96d9b2e | 15642 | NULL, |
44feb3ce TT |
15643 | (void *) (uintptr_t) catch_fork_permanent, |
15644 | (void *) (uintptr_t) catch_fork_temporary); | |
15645 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15646 | catch_fork_command_1, | |
a96d9b2e | 15647 | NULL, |
44feb3ce TT |
15648 | (void *) (uintptr_t) catch_vfork_permanent, |
15649 | (void *) (uintptr_t) catch_vfork_temporary); | |
15650 | add_catch_command ("exec", _("Catch calls to exec."), | |
15651 | catch_exec_command_1, | |
a96d9b2e SDJ |
15652 | NULL, |
15653 | CATCH_PERMANENT, | |
15654 | CATCH_TEMPORARY); | |
edcc5120 TT |
15655 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15656 | Usage: catch load [REGEX]\n\ | |
15657 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15658 | catch_load_command_1, | |
15659 | NULL, | |
15660 | CATCH_PERMANENT, | |
15661 | CATCH_TEMPORARY); | |
15662 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15663 | Usage: catch unload [REGEX]\n\ | |
15664 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15665 | catch_unload_command_1, | |
15666 | NULL, | |
15667 | CATCH_PERMANENT, | |
15668 | CATCH_TEMPORARY); | |
c5aa993b | 15669 | |
1bedd215 AC |
15670 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15671 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15672 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15673 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15674 | an expression changes.\n\ |
15675 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15676 | the memory to which it refers.")); | |
65d12d83 | 15677 | set_cmd_completer (c, expression_completer); |
c906108c | 15678 | |
1bedd215 AC |
15679 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15680 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15681 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15682 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15683 | an expression is read.\n\ |
15684 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15685 | the memory to which it refers.")); | |
65d12d83 | 15686 | set_cmd_completer (c, expression_completer); |
c906108c | 15687 | |
1bedd215 AC |
15688 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15689 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15690 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15691 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15692 | an expression is either read or written.\n\ |
15693 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15694 | the memory to which it refers.")); | |
65d12d83 | 15695 | set_cmd_completer (c, expression_completer); |
c906108c | 15696 | |
11db9430 | 15697 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15698 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15699 | |
920d2a44 AC |
15700 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15701 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15702 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15703 | &can_use_hw_watchpoints, _("\ | |
15704 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15705 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15706 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15707 | such is available. (However, any hardware watchpoints that were\n\ | |
15708 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15709 | hardware.)"), |
15710 | NULL, | |
920d2a44 | 15711 | show_can_use_hw_watchpoints, |
85c07804 | 15712 | &setlist, &showlist); |
c906108c SS |
15713 | |
15714 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15715 | |
1042e4c0 SS |
15716 | /* Tracepoint manipulation commands. */ |
15717 | ||
15718 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 15719 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
15720 | \n" |
15721 | BREAK_ARGS_HELP ("trace") "\n\ | |
15722 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15723 | set_cmd_completer (c, location_completer); | |
15724 | ||
15725 | add_com_alias ("tp", "trace", class_alias, 0); | |
15726 | add_com_alias ("tr", "trace", class_alias, 1); | |
15727 | add_com_alias ("tra", "trace", class_alias, 1); | |
15728 | add_com_alias ("trac", "trace", class_alias, 1); | |
15729 | ||
7a697b8d | 15730 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 15731 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
15732 | \n" |
15733 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15734 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15735 | set_cmd_completer (c, location_completer); | |
15736 | ||
0fb4aa4b | 15737 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 15738 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
15739 | \n\ |
15740 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
15741 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
15742 | or -m MARKER_ID.\n\n\ | |
15743 | If a marker id is specified, probe the marker with that name. With\n\ | |
15744 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
15745 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
15746 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15747 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15748 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15749 | \n\ | |
15750 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15751 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15752 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15753 | conditions are different.\n\ | |
0fb4aa4b PA |
15754 | \n\ |
15755 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15756 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15757 | set_cmd_completer (c, location_completer); | |
15758 | ||
11db9430 | 15759 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 15760 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15761 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15762 | last tracepoint set.")); | |
15763 | ||
15764 | add_info_alias ("tp", "tracepoints", 1); | |
15765 | ||
15766 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
15767 | Delete specified tracepoints.\n\ | |
15768 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15769 | No argument means delete all tracepoints."), | |
15770 | &deletelist); | |
7e20dfcd | 15771 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
15772 | |
15773 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15774 | Disable specified tracepoints.\n\ | |
15775 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15776 | No argument means disable all tracepoints."), | |
15777 | &disablelist); | |
15778 | deprecate_cmd (c, "disable"); | |
15779 | ||
15780 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15781 | Enable specified tracepoints.\n\ | |
15782 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15783 | No argument means enable all tracepoints."), | |
15784 | &enablelist); | |
15785 | deprecate_cmd (c, "enable"); | |
15786 | ||
15787 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
15788 | Set the passcount for a tracepoint.\n\ | |
15789 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
15790 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
15791 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
15792 | ||
6149aea9 PA |
15793 | add_prefix_cmd ("save", class_breakpoint, save_command, |
15794 | _("Save breakpoint definitions as a script."), | |
15795 | &save_cmdlist, "save ", | |
15796 | 0/*allow-unknown*/, &cmdlist); | |
15797 | ||
15798 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
15799 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 15800 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
15801 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
15802 | session to restore them."), | |
15803 | &save_cmdlist); | |
15804 | set_cmd_completer (c, filename_completer); | |
15805 | ||
15806 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 15807 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
15808 | Use the 'source' command in another debug session to restore them."), |
15809 | &save_cmdlist); | |
1042e4c0 SS |
15810 | set_cmd_completer (c, filename_completer); |
15811 | ||
6149aea9 PA |
15812 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
15813 | deprecate_cmd (c, "save tracepoints"); | |
15814 | ||
1bedd215 | 15815 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
590042fc | 15816 | Breakpoint specific settings.\n\ |
fa8d40ab | 15817 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15818 | pending breakpoint behavior."), |
fa8d40ab JJ |
15819 | &breakpoint_set_cmdlist, "set breakpoint ", |
15820 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 15821 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
590042fc | 15822 | Breakpoint specific settings.\n\ |
fa8d40ab | 15823 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15824 | pending breakpoint behavior."), |
fa8d40ab JJ |
15825 | &breakpoint_show_cmdlist, "show breakpoint ", |
15826 | 0/*allow-unknown*/, &showlist); | |
15827 | ||
7915a72c AC |
15828 | add_setshow_auto_boolean_cmd ("pending", no_class, |
15829 | &pending_break_support, _("\ | |
15830 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
15831 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
15832 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
15833 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
15834 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 15835 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 15836 | NULL, |
920d2a44 | 15837 | show_pending_break_support, |
6e1d7d6c AC |
15838 | &breakpoint_set_cmdlist, |
15839 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
15840 | |
15841 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
15842 | |
15843 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
15844 | &automatic_hardware_breakpoints, _("\ | |
15845 | Set automatic usage of hardware breakpoints."), _("\ | |
15846 | Show automatic usage of hardware breakpoints."), _("\ | |
15847 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
15848 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
15849 | a warning will be emitted for such breakpoints."), | |
15850 | NULL, | |
15851 | show_automatic_hardware_breakpoints, | |
15852 | &breakpoint_set_cmdlist, | |
15853 | &breakpoint_show_cmdlist); | |
74960c60 | 15854 | |
a25a5a45 PA |
15855 | add_setshow_boolean_cmd ("always-inserted", class_support, |
15856 | &always_inserted_mode, _("\ | |
74960c60 VP |
15857 | Set mode for inserting breakpoints."), _("\ |
15858 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
15859 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
15860 | they're created, kept inserted even when execution stops, and removed\n\ | |
15861 | only when the user deletes them. When this mode is off (the default),\n\ | |
15862 | breakpoints are inserted only when execution continues, and removed\n\ | |
15863 | when execution stops."), | |
72d0e2c5 YQ |
15864 | NULL, |
15865 | &show_always_inserted_mode, | |
15866 | &breakpoint_set_cmdlist, | |
15867 | &breakpoint_show_cmdlist); | |
f1310107 | 15868 | |
b775012e LM |
15869 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
15870 | condition_evaluation_enums, | |
15871 | &condition_evaluation_mode_1, _("\ | |
15872 | Set mode of breakpoint condition evaluation."), _("\ | |
15873 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 15874 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
15875 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
15876 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
15877 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
15878 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
15879 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
15880 | be set to \"gdb\""), | |
15881 | &set_condition_evaluation_mode, | |
15882 | &show_condition_evaluation_mode, | |
15883 | &breakpoint_set_cmdlist, | |
15884 | &breakpoint_show_cmdlist); | |
15885 | ||
f1310107 TJB |
15886 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
15887 | Set a breakpoint for an address range.\n\ | |
15888 | break-range START-LOCATION, END-LOCATION\n\ | |
15889 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
15890 | LINENUM, for that line in the current file,\n\ | |
15891 | FILE:LINENUM, for that line in that file,\n\ | |
15892 | +OFFSET, for that number of lines after the current line\n\ | |
15893 | or the start of the range\n\ | |
15894 | FUNCTION, for the first line in that function,\n\ | |
15895 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
15896 | *ADDRESS, for the instruction at that address.\n\ | |
15897 | \n\ | |
15898 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
15899 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
15900 | range (including START-LOCATION and END-LOCATION).")); | |
15901 | ||
e7e0cddf | 15902 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 15903 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 15904 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
15905 | location may be a linespec, explicit, or address location.\n" |
15906 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
15907 | set_cmd_completer (c, location_completer); |
15908 | ||
15909 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
15910 | dprintf_style_enums, &dprintf_style, _("\ | |
15911 | Set the style of usage for dynamic printf."), _("\ | |
15912 | Show the style of usage for dynamic printf."), _("\ | |
15913 | This setting chooses how GDB will do a dynamic printf.\n\ | |
15914 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
15915 | console, as with the \"printf\" command.\n\ | |
15916 | If the value is \"call\", the print is done by calling a function in your\n\ | |
15917 | program; by default printf(), but you can choose a different function or\n\ | |
15918 | output stream by setting dprintf-function and dprintf-channel."), | |
15919 | update_dprintf_commands, NULL, | |
15920 | &setlist, &showlist); | |
15921 | ||
15922 | dprintf_function = xstrdup ("printf"); | |
15923 | add_setshow_string_cmd ("dprintf-function", class_support, | |
15924 | &dprintf_function, _("\ | |
590042fc PW |
15925 | Set the function to use for dynamic printf."), _("\ |
15926 | Show the function to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15927 | update_dprintf_commands, NULL, |
15928 | &setlist, &showlist); | |
15929 | ||
15930 | dprintf_channel = xstrdup (""); | |
15931 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
15932 | &dprintf_channel, _("\ | |
590042fc PW |
15933 | Set the channel to use for dynamic printf."), _("\ |
15934 | Show the channel to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15935 | update_dprintf_commands, NULL, |
15936 | &setlist, &showlist); | |
15937 | ||
d3ce09f5 SS |
15938 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
15939 | &disconnected_dprintf, _("\ | |
15940 | Set whether dprintf continues after GDB disconnects."), _("\ | |
15941 | Show whether dprintf continues after GDB disconnects."), _("\ | |
15942 | Use this to let dprintf commands continue to hit and produce output\n\ | |
15943 | even if GDB disconnects or detaches from the target."), | |
15944 | NULL, | |
15945 | NULL, | |
15946 | &setlist, &showlist); | |
15947 | ||
15948 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
590042fc PW |
15949 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
15950 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ | |
15951 | This supports most C printf format specifications, like %s, %d, etc.\n\ | |
15952 | This is useful for formatted output in user-defined commands.")); | |
d3ce09f5 | 15953 | |
491144b5 | 15954 | automatic_hardware_breakpoints = true; |
f3b1572e | 15955 | |
76727919 TT |
15956 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed); |
15957 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints); | |
c906108c | 15958 | } |