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 | 61 | #include "cli/cli-utils.h" |
d55e5aa6 | 62 | #include "stack.h" |
4de283e4 TT |
63 | #include "ax-gdb.h" |
64 | #include "dummy-frame.h" | |
65 | #include "interps.h" | |
268a13a5 | 66 | #include "gdbsupport/format.h" |
cfc31633 | 67 | #include "thread-fsm.h" |
5d5658a1 | 68 | #include "tid-parse.h" |
4de283e4 | 69 | #include "cli/cli-style.h" |
d3ce09f5 | 70 | |
1042e4c0 | 71 | /* readline include files */ |
073bbbb0 | 72 | #include "readline/tilde.h" |
1042e4c0 SS |
73 | |
74 | /* readline defines this. */ | |
75 | #undef savestring | |
76 | ||
034dad6f | 77 | #include "mi/mi-common.h" |
6dddc817 | 78 | #include "extension.h" |
325fac50 | 79 | #include <algorithm> |
5ed8105e | 80 | #include "progspace-and-thread.h" |
268a13a5 TT |
81 | #include "gdbsupport/array-view.h" |
82 | #include "gdbsupport/gdb_optional.h" | |
104c1213 | 83 | |
4a64f543 | 84 | /* Prototypes for local functions. */ |
c906108c | 85 | |
896b6bda | 86 | static void map_breakpoint_numbers (const char *, |
48649e1b | 87 | gdb::function_view<void (breakpoint *)>); |
c906108c | 88 | |
348d480f PA |
89 | static void breakpoint_re_set_default (struct breakpoint *); |
90 | ||
f00aae0f KS |
91 | static void |
92 | create_sals_from_location_default (const struct event_location *location, | |
93 | struct linespec_result *canonical, | |
94 | enum bptype type_wanted); | |
983af33b SDJ |
95 | |
96 | static void create_breakpoints_sal_default (struct gdbarch *, | |
97 | struct linespec_result *, | |
e1e01040 PA |
98 | gdb::unique_xmalloc_ptr<char>, |
99 | gdb::unique_xmalloc_ptr<char>, | |
100 | enum bptype, | |
983af33b SDJ |
101 | enum bpdisp, int, int, |
102 | int, | |
103 | const struct breakpoint_ops *, | |
44f238bb | 104 | int, int, int, unsigned); |
983af33b | 105 | |
6c5b2ebe PA |
106 | static std::vector<symtab_and_line> decode_location_default |
107 | (struct breakpoint *b, const struct event_location *location, | |
108 | struct program_space *search_pspace); | |
983af33b | 109 | |
a6535de1 TT |
110 | static int can_use_hardware_watchpoint |
111 | (const std::vector<value_ref_ptr> &vals); | |
c906108c | 112 | |
a14ed312 | 113 | static void mention (struct breakpoint *); |
c906108c | 114 | |
348d480f PA |
115 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
116 | enum bptype, | |
c0a91b2b | 117 | const struct breakpoint_ops *); |
3742cc8b YQ |
118 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
119 | const struct symtab_and_line *); | |
120 | ||
4a64f543 MS |
121 | /* This function is used in gdbtk sources and thus can not be made |
122 | static. */ | |
63c252f8 | 123 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 124 | struct symtab_and_line, |
c0a91b2b TT |
125 | enum bptype, |
126 | const struct breakpoint_ops *); | |
c906108c | 127 | |
06edf0c0 PA |
128 | static struct breakpoint * |
129 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
130 | enum bptype type, | |
a1aa2221 LM |
131 | const struct breakpoint_ops *ops, |
132 | int loc_enabled); | |
06edf0c0 | 133 | |
76897487 KB |
134 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
135 | ||
a6d9a66e UW |
136 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
137 | CORE_ADDR bpaddr, | |
88f7da05 | 138 | enum bptype bptype); |
76897487 | 139 | |
6c95b8df PA |
140 | static void describe_other_breakpoints (struct gdbarch *, |
141 | struct program_space *, CORE_ADDR, | |
5af949e3 | 142 | struct obj_section *, int); |
c906108c | 143 | |
85d721b8 PA |
144 | static int watchpoint_locations_match (struct bp_location *loc1, |
145 | struct bp_location *loc2); | |
146 | ||
f1310107 | 147 | static int breakpoint_location_address_match (struct bp_location *bl, |
accd0bcd | 148 | const struct address_space *aspace, |
f1310107 TJB |
149 | CORE_ADDR addr); |
150 | ||
d35ae833 | 151 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
accd0bcd | 152 | const address_space *, |
d35ae833 PA |
153 | CORE_ADDR, int); |
154 | ||
834c0d03 | 155 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 156 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 157 | |
e514a9d6 | 158 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 159 | |
a14ed312 | 160 | static int hw_breakpoint_used_count (void); |
c906108c | 161 | |
a1398e0c PA |
162 | static int hw_watchpoint_use_count (struct breakpoint *); |
163 | ||
164 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
165 | enum bptype type, | |
166 | int *other_type_used); | |
c906108c | 167 | |
816338b5 SS |
168 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
169 | int count); | |
c906108c | 170 | |
fe3f5fa8 | 171 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
172 | static void incref_bp_location (struct bp_location *loc); |
173 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 174 | |
39d61571 | 175 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 176 | |
44702360 PA |
177 | /* update_global_location_list's modes of operation wrt to whether to |
178 | insert locations now. */ | |
179 | enum ugll_insert_mode | |
180 | { | |
181 | /* Don't insert any breakpoint locations into the inferior, only | |
182 | remove already-inserted locations that no longer should be | |
183 | inserted. Functions that delete a breakpoint or breakpoints | |
184 | should specify this mode, so that deleting a breakpoint doesn't | |
185 | have the side effect of inserting the locations of other | |
186 | breakpoints that are marked not-inserted, but should_be_inserted | |
187 | returns true on them. | |
188 | ||
189 | This behavior is useful is situations close to tear-down -- e.g., | |
190 | after an exec, while the target still has execution, but | |
191 | breakpoint shadows of the previous executable image should *NOT* | |
192 | be restored to the new image; or before detaching, where the | |
193 | target still has execution and wants to delete breakpoints from | |
194 | GDB's lists, and all breakpoints had already been removed from | |
195 | the inferior. */ | |
196 | UGLL_DONT_INSERT, | |
197 | ||
a25a5a45 PA |
198 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
199 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
200 | UGLL_MAY_INSERT, |
201 | ||
a25a5a45 PA |
202 | /* Insert locations now, irrespective of |
203 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
204 | stopped right now, and the user did "continue". We need to | |
205 | insert breakpoints _before_ resuming the target, but | |
206 | UGLL_MAY_INSERT wouldn't insert them, because | |
207 | breakpoints_should_be_inserted_now returns false at that point, | |
208 | as no thread is running yet. */ | |
04086b45 | 209 | UGLL_INSERT |
44702360 PA |
210 | }; |
211 | ||
212 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 213 | |
44702360 | 214 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 215 | |
74960c60 | 216 | static void insert_breakpoint_locations (void); |
a5606eee | 217 | |
0b39b52e | 218 | static void trace_pass_command (const char *, int); |
1042e4c0 | 219 | |
558a9d82 YQ |
220 | static void set_tracepoint_count (int num); |
221 | ||
f2478a7e | 222 | static bool is_masked_watchpoint (const struct breakpoint *b); |
9c06b0b4 | 223 | |
b775012e LM |
224 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
225 | ||
983af33b SDJ |
226 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
227 | otherwise. */ | |
228 | ||
229 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 230 | |
2060206e PA |
231 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
232 | that are implemented on top of software or hardware breakpoints | |
233 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
234 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
235 | ||
236 | /* Internal breakpoints class type. */ | |
06edf0c0 | 237 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
238 | |
239 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
240 | static struct breakpoint_ops momentary_breakpoint_ops; |
241 | ||
2060206e PA |
242 | /* The breakpoint_ops structure to be used in regular user created |
243 | breakpoints. */ | |
244 | struct breakpoint_ops bkpt_breakpoint_ops; | |
245 | ||
55aa24fb SDJ |
246 | /* Breakpoints set on probes. */ |
247 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
248 | ||
e7e0cddf | 249 | /* Dynamic printf class type. */ |
c5867ab6 | 250 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 251 | |
d3ce09f5 SS |
252 | /* The style in which to perform a dynamic printf. This is a user |
253 | option because different output options have different tradeoffs; | |
254 | if GDB does the printing, there is better error handling if there | |
255 | is a problem with any of the arguments, but using an inferior | |
256 | function lets you have special-purpose printers and sending of | |
257 | output to the same place as compiled-in print functions. */ | |
258 | ||
259 | static const char dprintf_style_gdb[] = "gdb"; | |
260 | static const char dprintf_style_call[] = "call"; | |
261 | static const char dprintf_style_agent[] = "agent"; | |
262 | static const char *const dprintf_style_enums[] = { | |
263 | dprintf_style_gdb, | |
264 | dprintf_style_call, | |
265 | dprintf_style_agent, | |
266 | NULL | |
267 | }; | |
268 | static const char *dprintf_style = dprintf_style_gdb; | |
269 | ||
270 | /* The function to use for dynamic printf if the preferred style is to | |
271 | call into the inferior. The value is simply a string that is | |
272 | copied into the command, so it can be anything that GDB can | |
273 | evaluate to a callable address, not necessarily a function name. */ | |
274 | ||
bde6261a | 275 | static char *dprintf_function; |
d3ce09f5 SS |
276 | |
277 | /* The channel to use for dynamic printf if the preferred style is to | |
278 | call into the inferior; if a nonempty string, it will be passed to | |
279 | the call as the first argument, with the format string as the | |
280 | second. As with the dprintf function, this can be anything that | |
281 | GDB knows how to evaluate, so in addition to common choices like | |
282 | "stderr", this could be an app-specific expression like | |
283 | "mystreams[curlogger]". */ | |
284 | ||
bde6261a | 285 | static char *dprintf_channel; |
d3ce09f5 SS |
286 | |
287 | /* True if dprintf commands should continue to operate even if GDB | |
288 | has disconnected. */ | |
491144b5 | 289 | static bool disconnected_dprintf = true; |
d3ce09f5 | 290 | |
5cea2a26 PA |
291 | struct command_line * |
292 | breakpoint_commands (struct breakpoint *b) | |
293 | { | |
d1b0a7bf | 294 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 295 | } |
3daf8fe5 | 296 | |
f3b1572e PA |
297 | /* Flag indicating that a command has proceeded the inferior past the |
298 | current breakpoint. */ | |
299 | ||
491144b5 | 300 | static bool breakpoint_proceeded; |
f3b1572e | 301 | |
956a9fb9 | 302 | const char * |
2cec12e5 AR |
303 | bpdisp_text (enum bpdisp disp) |
304 | { | |
4a64f543 MS |
305 | /* NOTE: the following values are a part of MI protocol and |
306 | represent values of 'disp' field returned when inferior stops at | |
307 | a breakpoint. */ | |
bc043ef3 | 308 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 309 | |
2cec12e5 AR |
310 | return bpdisps[(int) disp]; |
311 | } | |
c906108c | 312 | |
4a64f543 | 313 | /* Prototypes for exported functions. */ |
c906108c | 314 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 315 | if such is available. */ |
c906108c SS |
316 | static int can_use_hw_watchpoints; |
317 | ||
920d2a44 AC |
318 | static void |
319 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
320 | struct cmd_list_element *c, | |
321 | const char *value) | |
322 | { | |
3e43a32a MS |
323 | fprintf_filtered (file, |
324 | _("Debugger's willingness to use " | |
325 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
326 | value); |
327 | } | |
328 | ||
fa8d40ab JJ |
329 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
330 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 331 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
332 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
333 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
334 | static void |
335 | show_pending_break_support (struct ui_file *file, int from_tty, | |
336 | struct cmd_list_element *c, | |
337 | const char *value) | |
338 | { | |
3e43a32a MS |
339 | fprintf_filtered (file, |
340 | _("Debugger's behavior regarding " | |
341 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
342 | value); |
343 | } | |
fa8d40ab | 344 | |
491144b5 | 345 | /* If true, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 346 | set with "break" but falling in read-only memory. |
491144b5 | 347 | If false, gdb will warn about such breakpoints, but won't automatically |
765dc015 | 348 | use hardware breakpoints. */ |
491144b5 | 349 | static bool automatic_hardware_breakpoints; |
765dc015 VP |
350 | static void |
351 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
352 | struct cmd_list_element *c, | |
353 | const char *value) | |
354 | { | |
3e43a32a MS |
355 | fprintf_filtered (file, |
356 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
357 | value); |
358 | } | |
359 | ||
a25a5a45 PA |
360 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
361 | stopped, and immediately inserts any new breakpoints as soon as | |
362 | they're created. If off (default), GDB keeps breakpoints off of | |
363 | the target as long as possible. That is, it delays inserting | |
364 | breakpoints until the next resume, and removes them again when the | |
365 | target fully stops. This is a bit safer in case GDB crashes while | |
366 | processing user input. */ | |
491144b5 | 367 | static bool always_inserted_mode = false; |
72d0e2c5 | 368 | |
33e5cbd6 | 369 | static void |
74960c60 | 370 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 371 | struct cmd_list_element *c, const char *value) |
74960c60 | 372 | { |
a25a5a45 PA |
373 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
374 | value); | |
74960c60 VP |
375 | } |
376 | ||
b57bacec PA |
377 | /* See breakpoint.h. */ |
378 | ||
33e5cbd6 | 379 | int |
a25a5a45 | 380 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 381 | { |
a25a5a45 PA |
382 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
383 | { | |
384 | /* If breakpoints are global, they should be inserted even if no | |
385 | thread under gdb's control is running, or even if there are | |
386 | no threads under GDB's control yet. */ | |
387 | return 1; | |
388 | } | |
389 | else if (target_has_execution) | |
390 | { | |
a25a5a45 PA |
391 | if (always_inserted_mode) |
392 | { | |
393 | /* The user wants breakpoints inserted even if all threads | |
394 | are stopped. */ | |
395 | return 1; | |
396 | } | |
397 | ||
b57bacec PA |
398 | if (threads_are_executing ()) |
399 | return 1; | |
372316f1 PA |
400 | |
401 | /* Don't remove breakpoints yet if, even though all threads are | |
402 | stopped, we still have events to process. */ | |
08036331 | 403 | for (thread_info *tp : all_non_exited_threads ()) |
372316f1 PA |
404 | if (tp->resumed |
405 | && tp->suspend.waitstatus_pending_p) | |
406 | return 1; | |
a25a5a45 PA |
407 | } |
408 | return 0; | |
33e5cbd6 | 409 | } |
765dc015 | 410 | |
b775012e LM |
411 | static const char condition_evaluation_both[] = "host or target"; |
412 | ||
413 | /* Modes for breakpoint condition evaluation. */ | |
414 | static const char condition_evaluation_auto[] = "auto"; | |
415 | static const char condition_evaluation_host[] = "host"; | |
416 | static const char condition_evaluation_target[] = "target"; | |
417 | static const char *const condition_evaluation_enums[] = { | |
418 | condition_evaluation_auto, | |
419 | condition_evaluation_host, | |
420 | condition_evaluation_target, | |
421 | NULL | |
422 | }; | |
423 | ||
424 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
425 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
426 | ||
427 | /* Global that we use to display information to the user (gets its value from | |
428 | condition_evaluation_mode_1. */ | |
429 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
430 | ||
431 | /* Translate a condition evaluation mode MODE into either "host" | |
432 | or "target". This is used mostly to translate from "auto" to the | |
433 | real setting that is being used. It returns the translated | |
434 | evaluation mode. */ | |
435 | ||
436 | static const char * | |
437 | translate_condition_evaluation_mode (const char *mode) | |
438 | { | |
439 | if (mode == condition_evaluation_auto) | |
440 | { | |
441 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
442 | return condition_evaluation_target; | |
443 | else | |
444 | return condition_evaluation_host; | |
445 | } | |
446 | else | |
447 | return mode; | |
448 | } | |
449 | ||
450 | /* Discovers what condition_evaluation_auto translates to. */ | |
451 | ||
452 | static const char * | |
453 | breakpoint_condition_evaluation_mode (void) | |
454 | { | |
455 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
456 | } | |
457 | ||
458 | /* Return true if GDB should evaluate breakpoint conditions or false | |
459 | otherwise. */ | |
460 | ||
461 | static int | |
462 | gdb_evaluates_breakpoint_condition_p (void) | |
463 | { | |
464 | const char *mode = breakpoint_condition_evaluation_mode (); | |
465 | ||
466 | return (mode == condition_evaluation_host); | |
467 | } | |
468 | ||
c906108c SS |
469 | /* Are we executing breakpoint commands? */ |
470 | static int executing_breakpoint_commands; | |
471 | ||
c02f5703 MS |
472 | /* Are overlay event breakpoints enabled? */ |
473 | static int overlay_events_enabled; | |
474 | ||
e09342b5 | 475 | /* See description in breakpoint.h. */ |
491144b5 | 476 | bool target_exact_watchpoints = false; |
e09342b5 | 477 | |
c906108c | 478 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 479 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 480 | current breakpoint. */ |
c906108c | 481 | |
5c44784c | 482 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 483 | |
5c44784c JM |
484 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
485 | for (B = breakpoint_chain; \ | |
486 | B ? (TMP=B->next, 1): 0; \ | |
487 | B = TMP) | |
c906108c | 488 | |
4a64f543 MS |
489 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
490 | not provided so update_global_location_list must not be called | |
491 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 492 | |
876fa593 | 493 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
494 | for (BP_TMP = bp_locations; \ |
495 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 496 | BP_TMP++) |
7cc221ef | 497 | |
b775012e LM |
498 | /* Iterates through locations with address ADDRESS for the currently selected |
499 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
500 | to where the loop should start from. | |
501 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
502 | appropriate location to start with. */ | |
503 | ||
504 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
505 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
506 | BP_LOCP_TMP = BP_LOCP_START; \ | |
507 | BP_LOCP_START \ | |
f5336ca5 | 508 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
509 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
510 | BP_LOCP_TMP++) | |
511 | ||
1042e4c0 SS |
512 | /* Iterator for tracepoints only. */ |
513 | ||
514 | #define ALL_TRACEPOINTS(B) \ | |
515 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 516 | if (is_tracepoint (B)) |
1042e4c0 | 517 | |
7cc221ef | 518 | /* Chains of all breakpoints defined. */ |
c906108c | 519 | |
81e6b8eb | 520 | static struct breakpoint *breakpoint_chain; |
c906108c | 521 | |
39ef2f62 | 522 | /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ |
876fa593 | 523 | |
f5336ca5 | 524 | static struct bp_location **bp_locations; |
876fa593 | 525 | |
f5336ca5 | 526 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 527 | |
f5336ca5 | 528 | static unsigned bp_locations_count; |
876fa593 | 529 | |
4a64f543 | 530 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 531 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 532 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 533 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 534 | an address you need to read. */ |
876fa593 | 535 | |
f5336ca5 | 536 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 537 | |
4a64f543 MS |
538 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
539 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
540 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
541 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 542 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 543 | |
f5336ca5 | 544 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 545 | |
4a64f543 | 546 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
547 | from the bp_locations array, but for which a hit may still be |
548 | reported by a target. */ | |
1123588c | 549 | static std::vector<bp_location *> moribund_locations; |
20874c92 | 550 | |
c906108c SS |
551 | /* Number of last breakpoint made. */ |
552 | ||
95a42b64 TT |
553 | static int breakpoint_count; |
554 | ||
86b17b60 PA |
555 | /* The value of `breakpoint_count' before the last command that |
556 | created breakpoints. If the last (break-like) command created more | |
557 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
558 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
559 | static int prev_breakpoint_count; | |
c906108c | 560 | |
1042e4c0 SS |
561 | /* Number of last tracepoint made. */ |
562 | ||
95a42b64 | 563 | static int tracepoint_count; |
1042e4c0 | 564 | |
6149aea9 PA |
565 | static struct cmd_list_element *breakpoint_set_cmdlist; |
566 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 567 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 568 | |
badd37ce SDJ |
569 | /* See declaration at breakpoint.h. */ |
570 | ||
571 | struct breakpoint * | |
572 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
573 | void *user_data) | |
574 | { | |
575 | struct breakpoint *b = NULL; | |
576 | ||
577 | ALL_BREAKPOINTS (b) | |
578 | { | |
579 | if (func (b, user_data) != 0) | |
580 | break; | |
581 | } | |
582 | ||
583 | return b; | |
584 | } | |
585 | ||
468d015d JJ |
586 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
587 | static int | |
588 | breakpoint_enabled (struct breakpoint *b) | |
589 | { | |
0d381245 | 590 | return (b->enable_state == bp_enabled); |
468d015d JJ |
591 | } |
592 | ||
c906108c SS |
593 | /* Set breakpoint count to NUM. */ |
594 | ||
95a42b64 | 595 | static void |
fba45db2 | 596 | set_breakpoint_count (int num) |
c906108c | 597 | { |
86b17b60 | 598 | prev_breakpoint_count = breakpoint_count; |
c906108c | 599 | breakpoint_count = num; |
4fa62494 | 600 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
601 | } |
602 | ||
86b17b60 PA |
603 | /* Used by `start_rbreak_breakpoints' below, to record the current |
604 | breakpoint count before "rbreak" creates any breakpoint. */ | |
605 | static int rbreak_start_breakpoint_count; | |
606 | ||
95a42b64 TT |
607 | /* Called at the start an "rbreak" command to record the first |
608 | breakpoint made. */ | |
86b17b60 | 609 | |
c80049d3 | 610 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
95a42b64 | 611 | { |
86b17b60 | 612 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
613 | } |
614 | ||
615 | /* Called at the end of an "rbreak" command to record the last | |
616 | breakpoint made. */ | |
86b17b60 | 617 | |
c80049d3 | 618 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
95a42b64 | 619 | { |
86b17b60 | 620 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
621 | } |
622 | ||
4a64f543 | 623 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
624 | |
625 | void | |
fba45db2 | 626 | clear_breakpoint_hit_counts (void) |
c906108c SS |
627 | { |
628 | struct breakpoint *b; | |
629 | ||
630 | ALL_BREAKPOINTS (b) | |
631 | b->hit_count = 0; | |
632 | } | |
633 | ||
c906108c | 634 | \f |
48cb2d85 VP |
635 | /* Return the breakpoint with the specified number, or NULL |
636 | if the number does not refer to an existing breakpoint. */ | |
637 | ||
638 | struct breakpoint * | |
639 | get_breakpoint (int num) | |
640 | { | |
641 | struct breakpoint *b; | |
642 | ||
643 | ALL_BREAKPOINTS (b) | |
644 | if (b->number == num) | |
645 | return b; | |
646 | ||
647 | return NULL; | |
648 | } | |
5c44784c | 649 | |
c906108c | 650 | \f |
adc36818 | 651 | |
b775012e LM |
652 | /* Mark locations as "conditions have changed" in case the target supports |
653 | evaluating conditions on its side. */ | |
654 | ||
655 | static void | |
656 | mark_breakpoint_modified (struct breakpoint *b) | |
657 | { | |
658 | struct bp_location *loc; | |
659 | ||
660 | /* This is only meaningful if the target is | |
661 | evaluating conditions and if the user has | |
662 | opted for condition evaluation on the target's | |
663 | side. */ | |
664 | if (gdb_evaluates_breakpoint_condition_p () | |
665 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
666 | return; | |
667 | ||
668 | if (!is_breakpoint (b)) | |
669 | return; | |
670 | ||
671 | for (loc = b->loc; loc; loc = loc->next) | |
672 | loc->condition_changed = condition_modified; | |
673 | } | |
674 | ||
675 | /* Mark location as "conditions have changed" in case the target supports | |
676 | evaluating conditions on its side. */ | |
677 | ||
678 | static void | |
679 | mark_breakpoint_location_modified (struct bp_location *loc) | |
680 | { | |
681 | /* This is only meaningful if the target is | |
682 | evaluating conditions and if the user has | |
683 | opted for condition evaluation on the target's | |
684 | side. */ | |
685 | if (gdb_evaluates_breakpoint_condition_p () | |
686 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
687 | ||
688 | return; | |
689 | ||
690 | if (!is_breakpoint (loc->owner)) | |
691 | return; | |
692 | ||
693 | loc->condition_changed = condition_modified; | |
694 | } | |
695 | ||
696 | /* Sets the condition-evaluation mode using the static global | |
697 | condition_evaluation_mode. */ | |
698 | ||
699 | static void | |
eb4c3f4a | 700 | set_condition_evaluation_mode (const char *args, int from_tty, |
b775012e LM |
701 | struct cmd_list_element *c) |
702 | { | |
b775012e LM |
703 | const char *old_mode, *new_mode; |
704 | ||
705 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
706 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
707 | { | |
708 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
709 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
710 | "Using host evaluation mode instead.")); | |
711 | return; | |
712 | } | |
713 | ||
714 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
715 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
716 | ||
abf1152a JK |
717 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
718 | settings was "auto". */ | |
719 | condition_evaluation_mode = condition_evaluation_mode_1; | |
720 | ||
b775012e LM |
721 | /* Only update the mode if the user picked a different one. */ |
722 | if (new_mode != old_mode) | |
723 | { | |
724 | struct bp_location *loc, **loc_tmp; | |
725 | /* If the user switched to a different evaluation mode, we | |
726 | need to synch the changes with the target as follows: | |
727 | ||
728 | "host" -> "target": Send all (valid) conditions to the target. | |
729 | "target" -> "host": Remove all the conditions from the target. | |
730 | */ | |
731 | ||
b775012e LM |
732 | if (new_mode == condition_evaluation_target) |
733 | { | |
734 | /* Mark everything modified and synch conditions with the | |
735 | target. */ | |
736 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
737 | mark_breakpoint_location_modified (loc); | |
738 | } | |
739 | else | |
740 | { | |
741 | /* Manually mark non-duplicate locations to synch conditions | |
742 | with the target. We do this to remove all the conditions the | |
743 | target knows about. */ | |
744 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
745 | if (is_breakpoint (loc->owner) && loc->inserted) | |
746 | loc->needs_update = 1; | |
747 | } | |
748 | ||
749 | /* Do the update. */ | |
44702360 | 750 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
751 | } |
752 | ||
753 | return; | |
754 | } | |
755 | ||
756 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
757 | what "auto" is translating to. */ | |
758 | ||
759 | static void | |
760 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
761 | struct cmd_list_element *c, const char *value) | |
762 | { | |
763 | if (condition_evaluation_mode == condition_evaluation_auto) | |
764 | fprintf_filtered (file, | |
765 | _("Breakpoint condition evaluation " | |
766 | "mode is %s (currently %s).\n"), | |
767 | value, | |
768 | breakpoint_condition_evaluation_mode ()); | |
769 | else | |
770 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
771 | value); | |
772 | } | |
773 | ||
774 | /* A comparison function for bp_location AP and BP that is used by | |
775 | bsearch. This comparison function only cares about addresses, unlike | |
39ef2f62 | 776 | the more general bp_location_is_less_than function. */ |
b775012e LM |
777 | |
778 | static int | |
f5336ca5 | 779 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 780 | { |
9a3c8263 SM |
781 | const struct bp_location *a = *(const struct bp_location **) ap; |
782 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
783 | |
784 | if (a->address == b->address) | |
785 | return 0; | |
786 | else | |
787 | return ((a->address > b->address) - (a->address < b->address)); | |
788 | } | |
789 | ||
790 | /* Helper function to skip all bp_locations with addresses | |
791 | less than ADDRESS. It returns the first bp_location that | |
792 | is greater than or equal to ADDRESS. If none is found, just | |
793 | return NULL. */ | |
794 | ||
795 | static struct bp_location ** | |
796 | get_first_locp_gte_addr (CORE_ADDR address) | |
797 | { | |
798 | struct bp_location dummy_loc; | |
799 | struct bp_location *dummy_locp = &dummy_loc; | |
800 | struct bp_location **locp_found = NULL; | |
801 | ||
802 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
803 | dummy_loc.address = address; |
804 | ||
805 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 806 | locp_found = ((struct bp_location **) |
f5336ca5 | 807 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 808 | sizeof (struct bp_location **), |
f5336ca5 | 809 | bp_locations_compare_addrs)); |
b775012e LM |
810 | |
811 | /* Nothing was found, nothing left to do. */ | |
812 | if (locp_found == NULL) | |
813 | return NULL; | |
814 | ||
815 | /* We may have found a location that is at ADDRESS but is not the first in the | |
816 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 817 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
818 | && (*(locp_found - 1))->address == address) |
819 | locp_found--; | |
820 | ||
821 | return locp_found; | |
822 | } | |
823 | ||
adc36818 | 824 | void |
7a26bd4d | 825 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
826 | int from_tty) |
827 | { | |
3a5c3e22 PA |
828 | xfree (b->cond_string); |
829 | b->cond_string = NULL; | |
adc36818 | 830 | |
3a5c3e22 | 831 | if (is_watchpoint (b)) |
adc36818 | 832 | { |
3a5c3e22 PA |
833 | struct watchpoint *w = (struct watchpoint *) b; |
834 | ||
4d01a485 | 835 | w->cond_exp.reset (); |
3a5c3e22 PA |
836 | } |
837 | else | |
838 | { | |
839 | struct bp_location *loc; | |
840 | ||
841 | for (loc = b->loc; loc; loc = loc->next) | |
842 | { | |
4d01a485 | 843 | loc->cond.reset (); |
b775012e LM |
844 | |
845 | /* No need to free the condition agent expression | |
846 | bytecode (if we have one). We will handle this | |
847 | when we go through update_global_location_list. */ | |
3a5c3e22 | 848 | } |
adc36818 | 849 | } |
adc36818 PM |
850 | |
851 | if (*exp == 0) | |
852 | { | |
853 | if (from_tty) | |
854 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
855 | } | |
856 | else | |
857 | { | |
bbc13ae3 | 858 | const char *arg = exp; |
cc59ec59 | 859 | |
adc36818 PM |
860 | /* I don't know if it matters whether this is the string the user |
861 | typed in or the decompiled expression. */ | |
862 | b->cond_string = xstrdup (arg); | |
863 | b->condition_not_parsed = 0; | |
864 | ||
865 | if (is_watchpoint (b)) | |
866 | { | |
3a5c3e22 PA |
867 | struct watchpoint *w = (struct watchpoint *) b; |
868 | ||
699bd4cf | 869 | innermost_block_tracker tracker; |
adc36818 | 870 | arg = exp; |
699bd4cf | 871 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
adc36818 PM |
872 | if (*arg) |
873 | error (_("Junk at end of expression")); | |
699bd4cf | 874 | w->cond_exp_valid_block = tracker.block (); |
adc36818 PM |
875 | } |
876 | else | |
877 | { | |
3a5c3e22 PA |
878 | struct bp_location *loc; |
879 | ||
adc36818 PM |
880 | for (loc = b->loc; loc; loc = loc->next) |
881 | { | |
882 | arg = exp; | |
883 | loc->cond = | |
1bb9788d TT |
884 | parse_exp_1 (&arg, loc->address, |
885 | block_for_pc (loc->address), 0); | |
adc36818 PM |
886 | if (*arg) |
887 | error (_("Junk at end of expression")); | |
888 | } | |
889 | } | |
890 | } | |
b775012e LM |
891 | mark_breakpoint_modified (b); |
892 | ||
76727919 | 893 | gdb::observers::breakpoint_modified.notify (b); |
adc36818 PM |
894 | } |
895 | ||
d55637df TT |
896 | /* Completion for the "condition" command. */ |
897 | ||
eb3ff9a5 | 898 | static void |
6f937416 | 899 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 900 | completion_tracker &tracker, |
6f937416 | 901 | const char *text, const char *word) |
d55637df | 902 | { |
6f937416 | 903 | const char *space; |
d55637df | 904 | |
f1735a53 TT |
905 | text = skip_spaces (text); |
906 | space = skip_to_space (text); | |
d55637df TT |
907 | if (*space == '\0') |
908 | { | |
909 | int len; | |
910 | struct breakpoint *b; | |
d55637df TT |
911 | |
912 | if (text[0] == '$') | |
913 | { | |
914 | /* We don't support completion of history indices. */ | |
eb3ff9a5 PA |
915 | if (!isdigit (text[1])) |
916 | complete_internalvar (tracker, &text[1]); | |
917 | return; | |
d55637df TT |
918 | } |
919 | ||
920 | /* We're completing the breakpoint number. */ | |
921 | len = strlen (text); | |
922 | ||
923 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
924 | { |
925 | char number[50]; | |
926 | ||
927 | xsnprintf (number, sizeof (number), "%d", b->number); | |
928 | ||
929 | if (strncmp (number, text, len) == 0) | |
b02f78f9 | 930 | tracker.add_completion (make_unique_xstrdup (number)); |
58ce7251 | 931 | } |
d55637df | 932 | |
eb3ff9a5 | 933 | return; |
d55637df TT |
934 | } |
935 | ||
936 | /* We're completing the expression part. */ | |
f1735a53 | 937 | text = skip_spaces (space); |
eb3ff9a5 | 938 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
939 | } |
940 | ||
c906108c SS |
941 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
942 | ||
943 | static void | |
0b39b52e | 944 | condition_command (const char *arg, int from_tty) |
c906108c | 945 | { |
52f0bd74 | 946 | struct breakpoint *b; |
0b39b52e | 947 | const char *p; |
52f0bd74 | 948 | int bnum; |
c906108c SS |
949 | |
950 | if (arg == 0) | |
e2e0b3e5 | 951 | error_no_arg (_("breakpoint number")); |
c906108c SS |
952 | |
953 | p = arg; | |
954 | bnum = get_number (&p); | |
5c44784c | 955 | if (bnum == 0) |
8a3fe4f8 | 956 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
957 | |
958 | ALL_BREAKPOINTS (b) | |
959 | if (b->number == bnum) | |
2f069f6f | 960 | { |
6dddc817 DE |
961 | /* Check if this breakpoint has a "stop" method implemented in an |
962 | extension language. This method and conditions entered into GDB | |
963 | from the CLI are mutually exclusive. */ | |
964 | const struct extension_language_defn *extlang | |
965 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
966 | ||
967 | if (extlang != NULL) | |
968 | { | |
969 | error (_("Only one stop condition allowed. There is currently" | |
970 | " a %s stop condition defined for this breakpoint."), | |
971 | ext_lang_capitalized_name (extlang)); | |
972 | } | |
2566ad2d | 973 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
974 | |
975 | if (is_breakpoint (b)) | |
44702360 | 976 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 977 | |
2f069f6f JB |
978 | return; |
979 | } | |
c906108c | 980 | |
8a3fe4f8 | 981 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
982 | } |
983 | ||
a7bdde9e VP |
984 | /* Check that COMMAND do not contain commands that are suitable |
985 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
986 | Throw if any such commands is found. */ |
987 | ||
a7bdde9e VP |
988 | static void |
989 | check_no_tracepoint_commands (struct command_line *commands) | |
990 | { | |
991 | struct command_line *c; | |
cc59ec59 | 992 | |
a7bdde9e VP |
993 | for (c = commands; c; c = c->next) |
994 | { | |
a7bdde9e | 995 | if (c->control_type == while_stepping_control) |
3e43a32a MS |
996 | error (_("The 'while-stepping' command can " |
997 | "only be used for tracepoints")); | |
a7bdde9e | 998 | |
12973681 TT |
999 | check_no_tracepoint_commands (c->body_list_0.get ()); |
1000 | check_no_tracepoint_commands (c->body_list_1.get ()); | |
a7bdde9e VP |
1001 | |
1002 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1003 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1004 | command directly. */ |
1005 | if (strstr (c->line, "collect ") == c->line) | |
1006 | error (_("The 'collect' command can only be used for tracepoints")); | |
1007 | ||
51661e93 VP |
1008 | if (strstr (c->line, "teval ") == c->line) |
1009 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1010 | } |
1011 | } | |
1012 | ||
c1fc2657 | 1013 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1014 | { |
c1fc2657 | 1015 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1016 | }; |
1017 | ||
d77f58be SS |
1018 | /* Encapsulate tests for different types of tracepoints. */ |
1019 | ||
3b0871f4 SM |
1020 | static bool |
1021 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1022 | { |
1023 | return (type == bp_tracepoint | |
1024 | || type == bp_fast_tracepoint | |
1025 | || type == bp_static_tracepoint); | |
1026 | } | |
1027 | ||
3b0871f4 SM |
1028 | static bool |
1029 | is_longjmp_type (bptype type) | |
1030 | { | |
1031 | return type == bp_longjmp || type == bp_exception; | |
1032 | } | |
1033 | ||
f2478a7e SM |
1034 | /* See breakpoint.h. */ |
1035 | ||
1036 | bool | |
d77f58be | 1037 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1038 | { |
d9b3f62e | 1039 | return is_tracepoint_type (b->type); |
a7bdde9e | 1040 | } |
d9b3f62e | 1041 | |
a5e364af SM |
1042 | /* Factory function to create an appropriate instance of breakpoint given |
1043 | TYPE. */ | |
1044 | ||
1045 | static std::unique_ptr<breakpoint> | |
1046 | new_breakpoint_from_type (bptype type) | |
1047 | { | |
1048 | breakpoint *b; | |
1049 | ||
1050 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1051 | b = new tracepoint (); |
3b0871f4 | 1052 | else if (is_longjmp_type (type)) |
c1fc2657 | 1053 | b = new longjmp_breakpoint (); |
a5e364af SM |
1054 | else |
1055 | b = new breakpoint (); | |
1056 | ||
1057 | return std::unique_ptr<breakpoint> (b); | |
1058 | } | |
1059 | ||
e5dd4106 | 1060 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1061 | breakpoint. This function will throw an exception if a problem is |
1062 | found. */ | |
48cb2d85 | 1063 | |
95a42b64 TT |
1064 | static void |
1065 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1066 | struct command_line *commands) | |
48cb2d85 | 1067 | { |
d77f58be | 1068 | if (is_tracepoint (b)) |
a7bdde9e | 1069 | { |
c9a6ce02 | 1070 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1071 | struct command_line *c; |
1072 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1073 | |
1074 | /* Reset the while-stepping step count. The previous commands | |
1075 | might have included a while-stepping action, while the new | |
1076 | ones might not. */ | |
1077 | t->step_count = 0; | |
1078 | ||
1079 | /* We need to verify that each top-level element of commands is | |
1080 | valid for tracepoints, that there's at most one | |
1081 | while-stepping element, and that the while-stepping's body | |
1082 | has valid tracing commands excluding nested while-stepping. | |
1083 | We also need to validate the tracepoint action line in the | |
1084 | context of the tracepoint --- validate_actionline actually | |
1085 | has side effects, like setting the tracepoint's | |
1086 | while-stepping STEP_COUNT, in addition to checking if the | |
1087 | collect/teval actions parse and make sense in the | |
1088 | tracepoint's context. */ | |
a7bdde9e VP |
1089 | for (c = commands; c; c = c->next) |
1090 | { | |
a7bdde9e VP |
1091 | if (c->control_type == while_stepping_control) |
1092 | { | |
1093 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1094 | error (_("The 'while-stepping' command " |
1095 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1096 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1097 | error (_("The 'while-stepping' command " |
1098 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1099 | |
1100 | if (while_stepping) | |
3e43a32a MS |
1101 | error (_("The 'while-stepping' command " |
1102 | "can be used only once")); | |
a7bdde9e VP |
1103 | else |
1104 | while_stepping = c; | |
1105 | } | |
c9a6ce02 PA |
1106 | |
1107 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1108 | } |
1109 | if (while_stepping) | |
1110 | { | |
1111 | struct command_line *c2; | |
1112 | ||
12973681 TT |
1113 | gdb_assert (while_stepping->body_list_1 == nullptr); |
1114 | c2 = while_stepping->body_list_0.get (); | |
a7bdde9e VP |
1115 | for (; c2; c2 = c2->next) |
1116 | { | |
a7bdde9e VP |
1117 | if (c2->control_type == while_stepping_control) |
1118 | error (_("The 'while-stepping' command cannot be nested")); | |
1119 | } | |
1120 | } | |
1121 | } | |
1122 | else | |
1123 | { | |
1124 | check_no_tracepoint_commands (commands); | |
1125 | } | |
95a42b64 TT |
1126 | } |
1127 | ||
0fb4aa4b PA |
1128 | /* Return a vector of all the static tracepoints set at ADDR. The |
1129 | caller is responsible for releasing the vector. */ | |
1130 | ||
f51e0e20 | 1131 | std::vector<breakpoint *> |
0fb4aa4b PA |
1132 | static_tracepoints_here (CORE_ADDR addr) |
1133 | { | |
1134 | struct breakpoint *b; | |
f51e0e20 | 1135 | std::vector<breakpoint *> found; |
0fb4aa4b PA |
1136 | struct bp_location *loc; |
1137 | ||
1138 | ALL_BREAKPOINTS (b) | |
1139 | if (b->type == bp_static_tracepoint) | |
1140 | { | |
1141 | for (loc = b->loc; loc; loc = loc->next) | |
1142 | if (loc->address == addr) | |
f51e0e20 | 1143 | found.push_back (b); |
0fb4aa4b PA |
1144 | } |
1145 | ||
1146 | return found; | |
1147 | } | |
1148 | ||
95a42b64 | 1149 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1150 | validate that only allowed commands are included. */ |
95a42b64 TT |
1151 | |
1152 | void | |
4a64f543 | 1153 | breakpoint_set_commands (struct breakpoint *b, |
12973681 | 1154 | counted_command_line &&commands) |
95a42b64 | 1155 | { |
93921405 | 1156 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1157 | |
d1b0a7bf | 1158 | b->commands = std::move (commands); |
76727919 | 1159 | gdb::observers::breakpoint_modified.notify (b); |
48cb2d85 VP |
1160 | } |
1161 | ||
45a43567 TT |
1162 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1163 | is not the same as the "silent" that may appear in the breakpoint's | |
1164 | commands. */ | |
1165 | ||
1166 | void | |
1167 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1168 | { | |
1169 | int old_silent = b->silent; | |
1170 | ||
1171 | b->silent = silent; | |
1172 | if (old_silent != silent) | |
76727919 | 1173 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1174 | } |
1175 | ||
1176 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1177 | breakpoint work for any thread. */ | |
1178 | ||
1179 | void | |
1180 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1181 | { | |
1182 | int old_thread = b->thread; | |
1183 | ||
1184 | b->thread = thread; | |
1185 | if (old_thread != thread) | |
76727919 | 1186 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1187 | } |
1188 | ||
1189 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1190 | breakpoint work for any task. */ | |
1191 | ||
1192 | void | |
1193 | breakpoint_set_task (struct breakpoint *b, int task) | |
1194 | { | |
1195 | int old_task = b->task; | |
1196 | ||
1197 | b->task = task; | |
1198 | if (old_task != task) | |
76727919 | 1199 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1200 | } |
1201 | ||
95a42b64 | 1202 | static void |
896b6bda | 1203 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1204 | struct command_line *control) |
95a42b64 | 1205 | { |
d1b0a7bf | 1206 | counted_command_line cmd; |
999700cd PW |
1207 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
1208 | NULL after the call to read_command_lines if the user provides an empty | |
1209 | list of command by just typing "end". */ | |
1210 | bool cmd_read = false; | |
95a42b64 | 1211 | |
896b6bda PA |
1212 | std::string new_arg; |
1213 | ||
95a42b64 TT |
1214 | if (arg == NULL || !*arg) |
1215 | { | |
86b17b60 | 1216 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1217 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1218 | breakpoint_count); | |
95a42b64 | 1219 | else if (breakpoint_count > 0) |
896b6bda | 1220 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b TT |
1221 | arg = new_arg.c_str (); |
1222 | } | |
1223 | ||
1224 | map_breakpoint_numbers | |
1225 | (arg, [&] (breakpoint *b) | |
1226 | { | |
999700cd | 1227 | if (!cmd_read) |
48649e1b | 1228 | { |
999700cd | 1229 | gdb_assert (cmd == NULL); |
48649e1b | 1230 | if (control != NULL) |
12973681 | 1231 | cmd = control->body_list_0; |
48649e1b TT |
1232 | else |
1233 | { | |
81b1e71c TT |
1234 | std::string str |
1235 | = string_printf (_("Type commands for breakpoint(s) " | |
1236 | "%s, one per line."), | |
1237 | arg); | |
48649e1b | 1238 | |
60b3cef2 TT |
1239 | auto do_validate = [=] (const char *line) |
1240 | { | |
1241 | validate_actionline (line, b); | |
1242 | }; | |
1243 | gdb::function_view<void (const char *)> validator; | |
1244 | if (is_tracepoint (b)) | |
1245 | validator = do_validate; | |
1246 | ||
1247 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); | |
48649e1b | 1248 | } |
999700cd | 1249 | cmd_read = true; |
48649e1b TT |
1250 | } |
1251 | ||
1252 | /* If a breakpoint was on the list more than once, we don't need to | |
1253 | do anything. */ | |
1254 | if (b->commands != cmd) | |
1255 | { | |
d1b0a7bf | 1256 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b | 1257 | b->commands = cmd; |
76727919 | 1258 | gdb::observers::breakpoint_modified.notify (b); |
48649e1b TT |
1259 | } |
1260 | }); | |
95a42b64 TT |
1261 | } |
1262 | ||
1263 | static void | |
0b39b52e | 1264 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1265 | { |
1266 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1267 | } |
40c03ae8 EZ |
1268 | |
1269 | /* Like commands_command, but instead of reading the commands from | |
1270 | input stream, takes them from an already parsed command structure. | |
1271 | ||
1272 | This is used by cli-script.c to DTRT with breakpoint commands | |
1273 | that are part of if and while bodies. */ | |
1274 | enum command_control_type | |
896b6bda | 1275 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1276 | { |
95a42b64 TT |
1277 | commands_command_1 (arg, 0, cmd); |
1278 | return simple_control; | |
40c03ae8 | 1279 | } |
876fa593 JK |
1280 | |
1281 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1282 | ||
1283 | static int | |
1284 | bp_location_has_shadow (struct bp_location *bl) | |
1285 | { | |
1286 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1287 | return 0; | |
1288 | if (!bl->inserted) | |
1289 | return 0; | |
1290 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1291 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1292 | return 0; |
1293 | return 1; | |
1294 | } | |
1295 | ||
9d497a19 PA |
1296 | /* Update BUF, which is LEN bytes read from the target address |
1297 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1298 | contents. | |
1299 | ||
1300 | If READBUF is not NULL, this buffer must not overlap with the of | |
1301 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1302 | failed assertion internal error will be raised. */ | |
1303 | ||
1304 | static void | |
1305 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1306 | const gdb_byte *writebuf_org, | |
1307 | ULONGEST memaddr, LONGEST len, | |
1308 | struct bp_target_info *target_info, | |
1309 | struct gdbarch *gdbarch) | |
1310 | { | |
1311 | /* Now do full processing of the found relevant range of elements. */ | |
1312 | CORE_ADDR bp_addr = 0; | |
1313 | int bp_size = 0; | |
1314 | int bptoffset = 0; | |
1315 | ||
1316 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1317 | current_program_space->aspace, 0)) | |
1318 | { | |
1319 | /* The breakpoint is inserted in a different address space. */ | |
1320 | return; | |
1321 | } | |
1322 | ||
1323 | /* Addresses and length of the part of the breakpoint that | |
1324 | we need to copy. */ | |
1325 | bp_addr = target_info->placed_address; | |
1326 | bp_size = target_info->shadow_len; | |
1327 | ||
1328 | if (bp_addr + bp_size <= memaddr) | |
1329 | { | |
1330 | /* The breakpoint is entirely before the chunk of memory we are | |
1331 | reading. */ | |
1332 | return; | |
1333 | } | |
1334 | ||
1335 | if (bp_addr >= memaddr + len) | |
1336 | { | |
1337 | /* The breakpoint is entirely after the chunk of memory we are | |
1338 | reading. */ | |
1339 | return; | |
1340 | } | |
1341 | ||
1342 | /* Offset within shadow_contents. */ | |
1343 | if (bp_addr < memaddr) | |
1344 | { | |
1345 | /* Only copy the second part of the breakpoint. */ | |
1346 | bp_size -= memaddr - bp_addr; | |
1347 | bptoffset = memaddr - bp_addr; | |
1348 | bp_addr = memaddr; | |
1349 | } | |
1350 | ||
1351 | if (bp_addr + bp_size > memaddr + len) | |
1352 | { | |
1353 | /* Only copy the first part of the breakpoint. */ | |
1354 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1355 | } | |
1356 | ||
1357 | if (readbuf != NULL) | |
1358 | { | |
1359 | /* Verify that the readbuf buffer does not overlap with the | |
1360 | shadow_contents buffer. */ | |
1361 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1362 | || readbuf >= (target_info->shadow_contents | |
1363 | + target_info->shadow_len)); | |
1364 | ||
1365 | /* Update the read buffer with this inserted breakpoint's | |
1366 | shadow. */ | |
1367 | memcpy (readbuf + bp_addr - memaddr, | |
1368 | target_info->shadow_contents + bptoffset, bp_size); | |
1369 | } | |
1370 | else | |
1371 | { | |
1372 | const unsigned char *bp; | |
0d5ed153 MR |
1373 | CORE_ADDR addr = target_info->reqstd_address; |
1374 | int placed_size; | |
9d497a19 PA |
1375 | |
1376 | /* Update the shadow with what we want to write to memory. */ | |
1377 | memcpy (target_info->shadow_contents + bptoffset, | |
1378 | writebuf_org + bp_addr - memaddr, bp_size); | |
1379 | ||
1380 | /* Determine appropriate breakpoint contents and size for this | |
1381 | address. */ | |
0d5ed153 | 1382 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1383 | |
1384 | /* Update the final write buffer with this inserted | |
1385 | breakpoint's INSN. */ | |
1386 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1387 | } | |
1388 | } | |
1389 | ||
8defab1a | 1390 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1391 | by replacing any memory breakpoints with their shadowed contents. |
1392 | ||
35c63cd8 JB |
1393 | If READBUF is not NULL, this buffer must not overlap with any of |
1394 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1395 | a failed assertion internal error will be raised. | |
1396 | ||
876fa593 | 1397 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1398 | bl->address - bp_locations_placed_address_before_address_max |
1399 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1400 | The range we were requested to resolve shadows for is: |
1401 | memaddr ... memaddr + len | |
1402 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1403 | memaddr + len <= (bl->address |
f5336ca5 | 1404 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1405 | and: |
f5336ca5 | 1406 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1407 | |
8defab1a | 1408 | void |
f0ba3972 PA |
1409 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1410 | const gdb_byte *writebuf_org, | |
1411 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1412 | { |
4a64f543 MS |
1413 | /* Left boundary, right boundary and median element of our binary |
1414 | search. */ | |
876fa593 JK |
1415 | unsigned bc_l, bc_r, bc; |
1416 | ||
4a64f543 MS |
1417 | /* Find BC_L which is a leftmost element which may affect BUF |
1418 | content. It is safe to report lower value but a failure to | |
1419 | report higher one. */ | |
876fa593 JK |
1420 | |
1421 | bc_l = 0; | |
f5336ca5 | 1422 | bc_r = bp_locations_count; |
876fa593 JK |
1423 | while (bc_l + 1 < bc_r) |
1424 | { | |
35df4500 | 1425 | struct bp_location *bl; |
876fa593 JK |
1426 | |
1427 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1428 | bl = bp_locations[bc]; |
876fa593 | 1429 | |
4a64f543 MS |
1430 | /* Check first BL->ADDRESS will not overflow due to the added |
1431 | constant. Then advance the left boundary only if we are sure | |
1432 | the BC element can in no way affect the BUF content (MEMADDR | |
1433 | to MEMADDR + LEN range). | |
876fa593 | 1434 | |
f5336ca5 | 1435 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1436 | offset so that we cannot miss a breakpoint with its shadow |
1437 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1438 | |
f5336ca5 | 1439 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1440 | >= bl->address) |
f5336ca5 | 1441 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1442 | <= memaddr)) |
876fa593 JK |
1443 | bc_l = bc; |
1444 | else | |
1445 | bc_r = bc; | |
1446 | } | |
1447 | ||
128070bb PA |
1448 | /* Due to the binary search above, we need to make sure we pick the |
1449 | first location that's at BC_L's address. E.g., if there are | |
1450 | multiple locations at the same address, BC_L may end up pointing | |
1451 | at a duplicate location, and miss the "master"/"inserted" | |
1452 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1453 | B: | |
1454 | ||
1455 | L1@A, L2@A, L3@B, ... | |
1456 | ||
1457 | BC_L could end up pointing at location L2, while the "master" | |
1458 | location could be L1. Since the `loc->inserted' flag is only set | |
1459 | on "master" locations, we'd forget to restore the shadow of L1 | |
1460 | and L2. */ | |
1461 | while (bc_l > 0 | |
f5336ca5 | 1462 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1463 | bc_l--; |
1464 | ||
876fa593 JK |
1465 | /* Now do full processing of the found relevant range of elements. */ |
1466 | ||
f5336ca5 | 1467 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1468 | { |
f5336ca5 | 1469 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1470 | |
35df4500 TJB |
1471 | /* bp_location array has BL->OWNER always non-NULL. */ |
1472 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1473 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1474 | bl->owner->number); |
ffce0d52 | 1475 | |
e5dd4106 | 1476 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1477 | content. */ |
1478 | ||
f5336ca5 PA |
1479 | if (bl->address >= bp_locations_placed_address_before_address_max |
1480 | && memaddr + len <= (bl->address | |
1481 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1482 | break; |
1483 | ||
35df4500 | 1484 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1485 | continue; |
6c95b8df | 1486 | |
9d497a19 PA |
1487 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1488 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1489 | } | |
c906108c | 1490 | } |
9d497a19 | 1491 | |
f2478a7e | 1492 | /* See breakpoint.h. */ |
b775012e | 1493 | |
f2478a7e | 1494 | bool |
b775012e LM |
1495 | is_breakpoint (const struct breakpoint *bpt) |
1496 | { | |
1497 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1498 | || bpt->type == bp_hardware_breakpoint |
1499 | || bpt->type == bp_dprintf); | |
b775012e LM |
1500 | } |
1501 | ||
60e1c644 PA |
1502 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1503 | ||
f2478a7e | 1504 | static bool |
d77f58be | 1505 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1506 | { |
1507 | return (bpt->type == bp_hardware_watchpoint | |
1508 | || bpt->type == bp_read_watchpoint | |
1509 | || bpt->type == bp_access_watchpoint); | |
1510 | } | |
7270d8f2 | 1511 | |
f2478a7e | 1512 | /* See breakpoint.h. */ |
60e1c644 | 1513 | |
f2478a7e | 1514 | bool |
d77f58be | 1515 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1516 | { |
1517 | return (is_hardware_watchpoint (bpt) | |
1518 | || bpt->type == bp_watchpoint); | |
1519 | } | |
1520 | ||
3a5c3e22 PA |
1521 | /* Returns true if the current thread and its running state are safe |
1522 | to evaluate or update watchpoint B. Watchpoints on local | |
1523 | expressions need to be evaluated in the context of the thread that | |
1524 | was current when the watchpoint was created, and, that thread needs | |
1525 | to be stopped to be able to select the correct frame context. | |
1526 | Watchpoints on global expressions can be evaluated on any thread, | |
1527 | and in any state. It is presently left to the target allowing | |
1528 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1529 | |
1530 | static int | |
3a5c3e22 | 1531 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1532 | { |
c1fc2657 | 1533 | return (b->pspace == current_program_space |
d7e15655 TT |
1534 | && (b->watchpoint_thread == null_ptid |
1535 | || (inferior_ptid == b->watchpoint_thread | |
00431a78 | 1536 | && !inferior_thread ()->executing))); |
f6bc2008 PA |
1537 | } |
1538 | ||
d0fb5eae JK |
1539 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1540 | associated bp_watchpoint_scope breakpoint. */ | |
1541 | ||
1542 | static void | |
3a5c3e22 | 1543 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1544 | { |
c1fc2657 | 1545 | if (w->related_breakpoint != w) |
d0fb5eae | 1546 | { |
c1fc2657 SM |
1547 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1548 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1549 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1550 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1551 | w->related_breakpoint = w; | |
d0fb5eae | 1552 | } |
c1fc2657 | 1553 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1554 | } |
1555 | ||
bb9d5f81 PP |
1556 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1557 | watchpoint W. */ | |
1558 | ||
1559 | static struct value * | |
1560 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1561 | { | |
1562 | struct value *bit_val; | |
1563 | ||
1564 | if (val == NULL) | |
1565 | return NULL; | |
1566 | ||
1567 | bit_val = allocate_value (value_type (val)); | |
1568 | ||
1569 | unpack_value_bitfield (bit_val, | |
1570 | w->val_bitpos, | |
1571 | w->val_bitsize, | |
1572 | value_contents_for_printing (val), | |
1573 | value_offset (val), | |
1574 | val); | |
1575 | ||
1576 | return bit_val; | |
1577 | } | |
1578 | ||
c6d81124 PA |
1579 | /* Allocate a dummy location and add it to B, which must be a software |
1580 | watchpoint. This is required because even if a software watchpoint | |
1581 | is not watching any memory, bpstat_stop_status requires a location | |
1582 | to be able to report stops. */ | |
1583 | ||
1584 | static void | |
1585 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1586 | struct program_space *pspace) | |
1587 | { | |
1588 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1589 | ||
1590 | b->loc = allocate_bp_location (b); | |
1591 | b->loc->pspace = pspace; | |
1592 | b->loc->address = -1; | |
1593 | b->loc->length = -1; | |
1594 | } | |
1595 | ||
1596 | /* Returns true if B is a software watchpoint that is not watching any | |
1597 | memory (e.g., "watch $pc"). */ | |
1598 | ||
f2478a7e | 1599 | static bool |
c6d81124 PA |
1600 | is_no_memory_software_watchpoint (struct breakpoint *b) |
1601 | { | |
1602 | return (b->type == bp_watchpoint | |
1603 | && b->loc != NULL | |
1604 | && b->loc->next == NULL | |
1605 | && b->loc->address == -1 | |
1606 | && b->loc->length == -1); | |
1607 | } | |
1608 | ||
567e1b4e JB |
1609 | /* Assuming that B is a watchpoint: |
1610 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1611 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1612 | - Evaluate the condition if there is one, and store the result |
1613 | in b->loc->cond. | |
a5606eee VP |
1614 | - Update the list of values that must be watched in B->loc. |
1615 | ||
4a64f543 MS |
1616 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1617 | nothing. If this is local watchpoint that is out of scope, delete | |
1618 | it. | |
1619 | ||
1620 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1621 | removed + inserted on each stop here. Normal breakpoints must | |
1622 | never be removed because they might be missed by a running thread | |
1623 | when debugging in non-stop mode. On the other hand, hardware | |
1624 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1625 | to each LWP since they are stored in each LWP's hardware debug | |
1626 | registers. Therefore, such LWP must be stopped first in order to | |
1627 | be able to modify its hardware watchpoints. | |
1628 | ||
1629 | Hardware watchpoints must be reset exactly once after being | |
1630 | presented to the user. It cannot be done sooner, because it would | |
1631 | reset the data used to present the watchpoint hit to the user. And | |
1632 | it must not be done later because it could display the same single | |
1633 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1634 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1635 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1636 | not user-visible - its hit is suppressed if the memory content has | |
1637 | not changed. | |
1638 | ||
1639 | The following constraints influence the location where we can reset | |
1640 | hardware watchpoints: | |
1641 | ||
1642 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1643 | called several times when GDB stops. | |
1644 | ||
1645 | [linux] | |
1646 | * Multiple hardware watchpoints can be hit at the same time, | |
1647 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1648 | hit at a time as the reason for stopping, and all the other hits | |
1649 | are presented later, one after the other, each time the user | |
1650 | requests the execution to be resumed. Execution is not resumed | |
1651 | for the threads still having pending hit event stored in | |
1652 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1653 | the inferior on the first stop the thread hit event is kept being | |
1654 | reported from its cached value by linux_nat_stopped_data_address | |
1655 | until the real thread resume happens after the watchpoint gets | |
1656 | presented and thus its LWP_INFO->STATUS gets reset. | |
1657 | ||
1658 | Therefore the hardware watchpoint hit can get safely reset on the | |
1659 | watchpoint removal from inferior. */ | |
a79d3c27 | 1660 | |
b40ce68a | 1661 | static void |
3a5c3e22 | 1662 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1663 | { |
a5606eee | 1664 | int within_current_scope; |
a5606eee | 1665 | struct frame_id saved_frame_id; |
66076460 | 1666 | int frame_saved; |
a5606eee | 1667 | |
f6bc2008 PA |
1668 | /* If this is a local watchpoint, we only want to check if the |
1669 | watchpoint frame is in scope if the current thread is the thread | |
1670 | that was used to create the watchpoint. */ | |
1671 | if (!watchpoint_in_thread_scope (b)) | |
1672 | return; | |
1673 | ||
c1fc2657 | 1674 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1675 | return; |
1676 | ||
66076460 | 1677 | frame_saved = 0; |
a5606eee VP |
1678 | |
1679 | /* Determine if the watchpoint is within scope. */ | |
1680 | if (b->exp_valid_block == NULL) | |
1681 | within_current_scope = 1; | |
1682 | else | |
1683 | { | |
b5db5dfc UW |
1684 | struct frame_info *fi = get_current_frame (); |
1685 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1686 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1687 | ||
c9cf6e20 MG |
1688 | /* If we're at a point where the stack has been destroyed |
1689 | (e.g. in a function epilogue), unwinding may not work | |
1690 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1691 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1692 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1693 | return; |
66076460 DJ |
1694 | |
1695 | /* Save the current frame's ID so we can restore it after | |
1696 | evaluating the watchpoint expression on its own frame. */ | |
1697 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1698 | took a frame parameter, so that we didn't have to change the | |
1699 | selected frame. */ | |
1700 | frame_saved = 1; | |
1701 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1702 | ||
a5606eee VP |
1703 | fi = frame_find_by_id (b->watchpoint_frame); |
1704 | within_current_scope = (fi != NULL); | |
1705 | if (within_current_scope) | |
1706 | select_frame (fi); | |
1707 | } | |
1708 | ||
b5db5dfc UW |
1709 | /* We don't free locations. They are stored in the bp_location array |
1710 | and update_global_location_list will eventually delete them and | |
1711 | remove breakpoints if needed. */ | |
c1fc2657 | 1712 | b->loc = NULL; |
b5db5dfc | 1713 | |
a5606eee VP |
1714 | if (within_current_scope && reparse) |
1715 | { | |
bbc13ae3 | 1716 | const char *s; |
d63d0675 | 1717 | |
4d01a485 | 1718 | b->exp.reset (); |
d63d0675 | 1719 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1720 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1721 | /* If the meaning of expression itself changed, the old value is |
1722 | no longer relevant. We don't want to report a watchpoint hit | |
1723 | to the user when the old value and the new value may actually | |
1724 | be completely different objects. */ | |
fa4727a6 | 1725 | b->val = NULL; |
4c1d86d9 | 1726 | b->val_valid = false; |
60e1c644 PA |
1727 | |
1728 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1729 | expression is stored in the breakpoint object, not in the | |
1730 | locations (re)created below. */ | |
c1fc2657 | 1731 | if (b->cond_string != NULL) |
60e1c644 | 1732 | { |
4d01a485 | 1733 | b->cond_exp.reset (); |
60e1c644 | 1734 | |
c1fc2657 | 1735 | s = b->cond_string; |
1bb9788d | 1736 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1737 | } |
a5606eee | 1738 | } |
a5606eee VP |
1739 | |
1740 | /* If we failed to parse the expression, for example because | |
1741 | it refers to a global variable in a not-yet-loaded shared library, | |
1742 | don't try to insert watchpoint. We don't automatically delete | |
1743 | such watchpoint, though, since failure to parse expression | |
1744 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1745 | if (!target_has_execution) |
2d134ed3 PA |
1746 | { |
1747 | /* Without execution, memory can't change. No use to try and | |
1748 | set watchpoint locations. The watchpoint will be reset when | |
1749 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1750 | if (!can_use_hw_watchpoints) |
1751 | { | |
c1fc2657 SM |
1752 | if (b->ops->works_in_software_mode (b)) |
1753 | b->type = bp_watchpoint; | |
e8369a73 | 1754 | else |
638aa5a1 AB |
1755 | error (_("Can't set read/access watchpoint when " |
1756 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1757 | } |
2d134ed3 PA |
1758 | } |
1759 | else if (within_current_scope && b->exp) | |
a5606eee | 1760 | { |
0cf6dd15 | 1761 | int pc = 0; |
a6535de1 | 1762 | std::vector<value_ref_ptr> val_chain; |
8d49165d | 1763 | struct value *v, *result; |
2d134ed3 | 1764 | struct program_space *frame_pspace; |
a5606eee | 1765 | |
4d01a485 | 1766 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1767 | |
a5606eee VP |
1768 | /* Avoid setting b->val if it's already set. The meaning of |
1769 | b->val is 'the last value' user saw, and we should update | |
1770 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1771 | happens, the code that reports it updates b->val directly. |
1772 | We don't keep track of the memory value for masked | |
1773 | watchpoints. */ | |
c1fc2657 | 1774 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1775 | { |
bb9d5f81 | 1776 | if (b->val_bitsize != 0) |
850645cf TT |
1777 | v = extract_bitfield_from_watchpoint_value (b, v); |
1778 | b->val = release_value (v); | |
4c1d86d9 | 1779 | b->val_valid = true; |
fa4727a6 | 1780 | } |
a5606eee | 1781 | |
2d134ed3 PA |
1782 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1783 | ||
a5606eee | 1784 | /* Look at each value on the value chain. */ |
a6535de1 TT |
1785 | gdb_assert (!val_chain.empty ()); |
1786 | for (const value_ref_ptr &iter : val_chain) | |
a5606eee | 1787 | { |
a6535de1 TT |
1788 | v = iter.get (); |
1789 | ||
a5606eee VP |
1790 | /* If it's a memory location, and GDB actually needed |
1791 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1792 | must watch it. If the first value returned is |
1793 | still lazy, that means an error occurred reading it; | |
1794 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1795 | if (VALUE_LVAL (v) == lval_memory |
a6535de1 | 1796 | && (v == val_chain[0] || ! value_lazy (v))) |
a5606eee VP |
1797 | { |
1798 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1799 | |
a5606eee VP |
1800 | /* We only watch structs and arrays if user asked |
1801 | for it explicitly, never if they just happen to | |
1802 | appear in the middle of some value chain. */ | |
fa4727a6 | 1803 | if (v == result |
a5606eee VP |
1804 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1805 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1806 | { | |
1807 | CORE_ADDR addr; | |
f486487f | 1808 | enum target_hw_bp_type type; |
a5606eee | 1809 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1810 | int bitpos = 0, bitsize = 0; |
1811 | ||
1812 | if (value_bitsize (v) != 0) | |
1813 | { | |
1814 | /* Extract the bit parameters out from the bitfield | |
1815 | sub-expression. */ | |
1816 | bitpos = value_bitpos (v); | |
1817 | bitsize = value_bitsize (v); | |
1818 | } | |
1819 | else if (v == result && b->val_bitsize != 0) | |
1820 | { | |
1821 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1822 | lvalue whose bit parameters are saved in the fields | |
1823 | VAL_BITPOS and VAL_BITSIZE. */ | |
1824 | bitpos = b->val_bitpos; | |
1825 | bitsize = b->val_bitsize; | |
1826 | } | |
a5606eee | 1827 | |
42ae5230 | 1828 | addr = value_address (v); |
bb9d5f81 PP |
1829 | if (bitsize != 0) |
1830 | { | |
1831 | /* Skip the bytes that don't contain the bitfield. */ | |
1832 | addr += bitpos / 8; | |
1833 | } | |
1834 | ||
a5606eee | 1835 | type = hw_write; |
c1fc2657 | 1836 | if (b->type == bp_read_watchpoint) |
a5606eee | 1837 | type = hw_read; |
c1fc2657 | 1838 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1839 | type = hw_access; |
3a5c3e22 | 1840 | |
c1fc2657 SM |
1841 | loc = allocate_bp_location (b); |
1842 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1843 | ; |
1844 | *tmp = loc; | |
a6d9a66e | 1845 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1846 | |
1847 | loc->pspace = frame_pspace; | |
f17d9474 | 1848 | loc->address = address_significant (loc->gdbarch, addr); |
bb9d5f81 PP |
1849 | |
1850 | if (bitsize != 0) | |
1851 | { | |
1852 | /* Just cover the bytes that make up the bitfield. */ | |
1853 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1854 | } | |
1855 | else | |
1856 | loc->length = TYPE_LENGTH (value_type (v)); | |
1857 | ||
a5606eee VP |
1858 | loc->watchpoint_type = type; |
1859 | } | |
1860 | } | |
9fa40276 TJB |
1861 | } |
1862 | ||
1863 | /* Change the type of breakpoint between hardware assisted or | |
1864 | an ordinary watchpoint depending on the hardware support | |
1865 | and free hardware slots. REPARSE is set when the inferior | |
1866 | is started. */ | |
a9634178 | 1867 | if (reparse) |
9fa40276 | 1868 | { |
e09342b5 | 1869 | int reg_cnt; |
9fa40276 TJB |
1870 | enum bp_loc_type loc_type; |
1871 | struct bp_location *bl; | |
a5606eee | 1872 | |
a9634178 | 1873 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1874 | |
1875 | if (reg_cnt) | |
9fa40276 TJB |
1876 | { |
1877 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1878 | enum bptype type; |
9fa40276 | 1879 | |
a9634178 TJB |
1880 | /* Use an exact watchpoint when there's only one memory region to be |
1881 | watched, and only one debug register is needed to watch it. */ | |
1882 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1883 | ||
9fa40276 | 1884 | /* We need to determine how many resources are already |
e09342b5 TJB |
1885 | used for all other hardware watchpoints plus this one |
1886 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1887 | this watchpoint in as well. */ |
1888 | ||
1889 | /* If this is a software watchpoint, we try to turn it | |
1890 | to a hardware one -- count resources as if B was of | |
1891 | hardware watchpoint type. */ | |
c1fc2657 | 1892 | type = b->type; |
a1398e0c PA |
1893 | if (type == bp_watchpoint) |
1894 | type = bp_hardware_watchpoint; | |
1895 | ||
1896 | /* This watchpoint may or may not have been placed on | |
1897 | the list yet at this point (it won't be in the list | |
1898 | if we're trying to create it for the first time, | |
1899 | through watch_command), so always account for it | |
1900 | manually. */ | |
1901 | ||
1902 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 1903 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
1904 | |
1905 | /* Add in the resources needed for B. */ | |
c1fc2657 | 1906 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
1907 | |
1908 | target_resources_ok | |
1909 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1910 | if (target_resources_ok <= 0) |
a9634178 | 1911 | { |
c1fc2657 | 1912 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
1913 | |
1914 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1915 | error (_("Target does not support this type of " |
1916 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1917 | else if (target_resources_ok < 0 && !sw_mode) |
1918 | error (_("There are not enough available hardware " | |
1919 | "resources for this watchpoint.")); | |
a1398e0c PA |
1920 | |
1921 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 1922 | b->type = bp_watchpoint; |
a1398e0c PA |
1923 | } |
1924 | else | |
1925 | { | |
1926 | /* If this was a software watchpoint, we've just | |
1927 | found we have enough resources to turn it to a | |
1928 | hardware watchpoint. Otherwise, this is a | |
1929 | nop. */ | |
c1fc2657 | 1930 | b->type = type; |
a9634178 | 1931 | } |
9fa40276 | 1932 | } |
c1fc2657 | 1933 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
1934 | { |
1935 | if (!can_use_hw_watchpoints) | |
1936 | error (_("Can't set read/access watchpoint when " | |
1937 | "hardware watchpoints are disabled.")); | |
1938 | else | |
1939 | error (_("Expression cannot be implemented with " | |
1940 | "read/access watchpoint.")); | |
1941 | } | |
9fa40276 | 1942 | else |
c1fc2657 | 1943 | b->type = bp_watchpoint; |
9fa40276 | 1944 | |
c1fc2657 | 1945 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 1946 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 1947 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
1948 | bl->loc_type = loc_type; |
1949 | } | |
1950 | ||
c7437ca6 PA |
1951 | /* If a software watchpoint is not watching any memory, then the |
1952 | above left it without any location set up. But, | |
1953 | bpstat_stop_status requires a location to be able to report | |
1954 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
1955 | if (b->type == bp_watchpoint && b->loc == NULL) |
1956 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
1957 | } |
1958 | else if (!within_current_scope) | |
7270d8f2 | 1959 | { |
ac74f770 MS |
1960 | printf_filtered (_("\ |
1961 | Watchpoint %d deleted because the program has left the block\n\ | |
1962 | in which its expression is valid.\n"), | |
c1fc2657 | 1963 | b->number); |
d0fb5eae | 1964 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1965 | } |
a5606eee VP |
1966 | |
1967 | /* Restore the selected frame. */ | |
66076460 DJ |
1968 | if (frame_saved) |
1969 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1970 | } |
1971 | ||
a5606eee | 1972 | |
74960c60 | 1973 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1974 | inserted in the inferior. We don't differentiate the type of BL's owner |
1975 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1976 | breakpoint_ops is not defined, because in insert_bp_location, | |
1977 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1978 | static int |
35df4500 | 1979 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1980 | { |
35df4500 | 1981 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1982 | return 0; |
1983 | ||
35df4500 | 1984 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1985 | return 0; |
1986 | ||
35df4500 | 1987 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1988 | return 0; |
1989 | ||
f8eba3c6 TT |
1990 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
1991 | return 0; | |
1992 | ||
56710373 PA |
1993 | /* This is set for example, when we're attached to the parent of a |
1994 | vfork, and have detached from the child. The child is running | |
1995 | free, and we expect it to do an exec or exit, at which point the | |
1996 | OS makes the parent schedulable again (and the target reports | |
1997 | that the vfork is done). Until the child is done with the shared | |
1998 | memory region, do not insert breakpoints in the parent, otherwise | |
1999 | the child could still trip on the parent's breakpoints. Since | |
2000 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2001 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2002 | return 0; |
2003 | ||
31e77af2 | 2004 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2005 | location, except if the breakpoint is a single-step breakpoint, |
2006 | and the breakpoint's thread is the thread which is stepping past | |
2007 | a breakpoint. */ | |
31e77af2 PA |
2008 | if ((bl->loc_type == bp_loc_software_breakpoint |
2009 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2010 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2011 | bl->address) |
2012 | /* The single-step breakpoint may be inserted at the location | |
2013 | we're trying to step if the instruction branches to itself. | |
2014 | However, the instruction won't be executed at all and it may | |
2015 | break the semantics of the instruction, for example, the | |
2016 | instruction is a conditional branch or updates some flags. | |
2017 | We can't fix it unless GDB is able to emulate the instruction | |
2018 | or switch to displaced stepping. */ | |
2019 | && !(bl->owner->type == bp_single_step | |
2020 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2021 | { |
2022 | if (debug_infrun) | |
2023 | { | |
2024 | fprintf_unfiltered (gdb_stdlog, | |
2025 | "infrun: skipping breakpoint: " | |
2026 | "stepping past insn at: %s\n", | |
2027 | paddress (bl->gdbarch, bl->address)); | |
2028 | } | |
2029 | return 0; | |
2030 | } | |
31e77af2 | 2031 | |
963f9c80 PA |
2032 | /* Don't insert watchpoints if we're trying to step past the |
2033 | instruction that triggered one. */ | |
2034 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2035 | && stepping_past_nonsteppable_watchpoint ()) | |
2036 | { | |
2037 | if (debug_infrun) | |
2038 | { | |
2039 | fprintf_unfiltered (gdb_stdlog, | |
2040 | "infrun: stepping past non-steppable watchpoint. " | |
2041 | "skipping watchpoint at %s:%d\n", | |
2042 | paddress (bl->gdbarch, bl->address), | |
2043 | bl->length); | |
2044 | } | |
2045 | return 0; | |
2046 | } | |
2047 | ||
74960c60 VP |
2048 | return 1; |
2049 | } | |
2050 | ||
934709f0 PW |
2051 | /* Same as should_be_inserted but does the check assuming |
2052 | that the location is not duplicated. */ | |
2053 | ||
2054 | static int | |
2055 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2056 | { | |
2057 | int result; | |
2058 | const int save_duplicate = bl->duplicate; | |
2059 | ||
2060 | bl->duplicate = 0; | |
2061 | result = should_be_inserted (bl); | |
2062 | bl->duplicate = save_duplicate; | |
2063 | return result; | |
2064 | } | |
2065 | ||
b775012e LM |
2066 | /* Parses a conditional described by an expression COND into an |
2067 | agent expression bytecode suitable for evaluation | |
2068 | by the bytecode interpreter. Return NULL if there was | |
2069 | any error during parsing. */ | |
2070 | ||
833177a4 | 2071 | static agent_expr_up |
b775012e LM |
2072 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2073 | { | |
833177a4 | 2074 | if (cond == NULL) |
b775012e LM |
2075 | return NULL; |
2076 | ||
833177a4 PA |
2077 | agent_expr_up aexpr; |
2078 | ||
b775012e LM |
2079 | /* We don't want to stop processing, so catch any errors |
2080 | that may show up. */ | |
a70b8144 | 2081 | try |
b775012e | 2082 | { |
036e657b | 2083 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2084 | } |
2085 | ||
230d2906 | 2086 | catch (const gdb_exception_error &ex) |
b775012e LM |
2087 | { |
2088 | /* If we got here, it means the condition could not be parsed to a valid | |
2089 | bytecode expression and thus can't be evaluated on the target's side. | |
2090 | It's no use iterating through the conditions. */ | |
b775012e LM |
2091 | } |
2092 | ||
2093 | /* We have a valid agent expression. */ | |
2094 | return aexpr; | |
2095 | } | |
2096 | ||
2097 | /* Based on location BL, create a list of breakpoint conditions to be | |
2098 | passed on to the target. If we have duplicated locations with different | |
2099 | conditions, we will add such conditions to the list. The idea is that the | |
2100 | target will evaluate the list of conditions and will only notify GDB when | |
2101 | one of them is true. */ | |
2102 | ||
2103 | static void | |
2104 | build_target_condition_list (struct bp_location *bl) | |
2105 | { | |
2106 | struct bp_location **locp = NULL, **loc2p; | |
2107 | int null_condition_or_parse_error = 0; | |
2108 | int modified = bl->needs_update; | |
2109 | struct bp_location *loc; | |
2110 | ||
8b4f3082 | 2111 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2112 | bl->target_info.conditions.clear (); |
8b4f3082 | 2113 | |
b775012e LM |
2114 | /* This is only meaningful if the target is |
2115 | evaluating conditions and if the user has | |
2116 | opted for condition evaluation on the target's | |
2117 | side. */ | |
2118 | if (gdb_evaluates_breakpoint_condition_p () | |
2119 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2120 | return; | |
2121 | ||
2122 | /* Do a first pass to check for locations with no assigned | |
2123 | conditions or conditions that fail to parse to a valid agent expression | |
2124 | bytecode. If any of these happen, then it's no use to send conditions | |
2125 | to the target since this location will always trigger and generate a | |
2126 | response back to GDB. */ | |
2127 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2128 | { | |
2129 | loc = (*loc2p); | |
2130 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2131 | { | |
2132 | if (modified) | |
2133 | { | |
b775012e LM |
2134 | /* Re-parse the conditions since something changed. In that |
2135 | case we already freed the condition bytecodes (see | |
2136 | force_breakpoint_reinsertion). We just | |
2137 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2138 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2139 | loc->cond.get ()); | |
b775012e LM |
2140 | } |
2141 | ||
2142 | /* If we have a NULL bytecode expression, it means something | |
2143 | went wrong or we have a null condition expression. */ | |
2144 | if (!loc->cond_bytecode) | |
2145 | { | |
2146 | null_condition_or_parse_error = 1; | |
2147 | break; | |
2148 | } | |
2149 | } | |
2150 | } | |
2151 | ||
2152 | /* If any of these happened, it means we will have to evaluate the conditions | |
2153 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2154 | for all the other duplicate locations, thus we free all of them here. | |
2155 | ||
2156 | This is so we have a finer control over which locations' conditions are | |
2157 | being evaluated by GDB or the remote stub. */ | |
2158 | if (null_condition_or_parse_error) | |
2159 | { | |
2160 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2161 | { | |
2162 | loc = (*loc2p); | |
2163 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2164 | { | |
2165 | /* Only go as far as the first NULL bytecode is | |
2166 | located. */ | |
2167 | if (!loc->cond_bytecode) | |
2168 | return; | |
2169 | ||
833177a4 | 2170 | loc->cond_bytecode.reset (); |
b775012e LM |
2171 | } |
2172 | } | |
2173 | } | |
2174 | ||
2175 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2176 | for this location's address. */ | |
2177 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2178 | { | |
2179 | loc = (*loc2p); | |
2180 | if (loc->cond | |
2181 | && is_breakpoint (loc->owner) | |
2182 | && loc->pspace->num == bl->pspace->num | |
2183 | && loc->owner->enable_state == bp_enabled | |
2184 | && loc->enabled) | |
3cde5c42 PA |
2185 | { |
2186 | /* Add the condition to the vector. This will be used later | |
2187 | to send the conditions to the target. */ | |
2188 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2189 | } | |
b775012e LM |
2190 | } |
2191 | ||
2192 | return; | |
2193 | } | |
2194 | ||
d3ce09f5 SS |
2195 | /* Parses a command described by string CMD into an agent expression |
2196 | bytecode suitable for evaluation by the bytecode interpreter. | |
2197 | Return NULL if there was any error during parsing. */ | |
2198 | ||
833177a4 | 2199 | static agent_expr_up |
d3ce09f5 SS |
2200 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2201 | { | |
bbc13ae3 KS |
2202 | const char *cmdrest; |
2203 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2204 | struct gdbarch *gdbarch = get_current_arch (); |
2205 | ||
833177a4 | 2206 | if (cmd == NULL) |
d3ce09f5 SS |
2207 | return NULL; |
2208 | ||
2209 | cmdrest = cmd; | |
2210 | ||
2211 | if (*cmdrest == ',') | |
2212 | ++cmdrest; | |
f1735a53 | 2213 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2214 | |
2215 | if (*cmdrest++ != '"') | |
2216 | error (_("No format string following the location")); | |
2217 | ||
2218 | format_start = cmdrest; | |
2219 | ||
8e481c3b | 2220 | format_pieces fpieces (&cmdrest); |
d3ce09f5 SS |
2221 | |
2222 | format_end = cmdrest; | |
2223 | ||
2224 | if (*cmdrest++ != '"') | |
2225 | error (_("Bad format string, non-terminated '\"'.")); | |
2226 | ||
f1735a53 | 2227 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2228 | |
2229 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2230 | error (_("Invalid argument syntax")); | |
2231 | ||
2232 | if (*cmdrest == ',') | |
2233 | cmdrest++; | |
f1735a53 | 2234 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2235 | |
2236 | /* For each argument, make an expression. */ | |
2237 | ||
8e481c3b | 2238 | std::vector<struct expression *> argvec; |
d3ce09f5 SS |
2239 | while (*cmdrest != '\0') |
2240 | { | |
bbc13ae3 | 2241 | const char *cmd1; |
d3ce09f5 SS |
2242 | |
2243 | cmd1 = cmdrest; | |
4d01a485 | 2244 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
8e481c3b | 2245 | argvec.push_back (expr.release ()); |
d3ce09f5 SS |
2246 | cmdrest = cmd1; |
2247 | if (*cmdrest == ',') | |
2248 | ++cmdrest; | |
2249 | } | |
2250 | ||
833177a4 PA |
2251 | agent_expr_up aexpr; |
2252 | ||
d3ce09f5 SS |
2253 | /* We don't want to stop processing, so catch any errors |
2254 | that may show up. */ | |
a70b8144 | 2255 | try |
d3ce09f5 | 2256 | { |
036e657b JB |
2257 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2258 | format_start, format_end - format_start, | |
8e481c3b | 2259 | argvec.size (), argvec.data ()); |
d3ce09f5 | 2260 | } |
230d2906 | 2261 | catch (const gdb_exception_error &ex) |
d3ce09f5 SS |
2262 | { |
2263 | /* If we got here, it means the command could not be parsed to a valid | |
2264 | bytecode expression and thus can't be evaluated on the target's side. | |
2265 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2266 | } |
492d29ea | 2267 | |
d3ce09f5 SS |
2268 | /* We have a valid agent expression, return it. */ |
2269 | return aexpr; | |
2270 | } | |
2271 | ||
2272 | /* Based on location BL, create a list of breakpoint commands to be | |
2273 | passed on to the target. If we have duplicated locations with | |
2274 | different commands, we will add any such to the list. */ | |
2275 | ||
2276 | static void | |
2277 | build_target_command_list (struct bp_location *bl) | |
2278 | { | |
2279 | struct bp_location **locp = NULL, **loc2p; | |
2280 | int null_command_or_parse_error = 0; | |
2281 | int modified = bl->needs_update; | |
2282 | struct bp_location *loc; | |
2283 | ||
3cde5c42 PA |
2284 | /* Clear commands left over from a previous insert. */ |
2285 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2286 | |
41fac0cf | 2287 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2288 | return; |
2289 | ||
41fac0cf PA |
2290 | /* For now, limit to agent-style dprintf breakpoints. */ |
2291 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2292 | return; |
2293 | ||
41fac0cf PA |
2294 | /* For now, if we have any duplicate location that isn't a dprintf, |
2295 | don't install the target-side commands, as that would make the | |
2296 | breakpoint not be reported to the core, and we'd lose | |
2297 | control. */ | |
2298 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2299 | { | |
2300 | loc = (*loc2p); | |
2301 | if (is_breakpoint (loc->owner) | |
2302 | && loc->pspace->num == bl->pspace->num | |
2303 | && loc->owner->type != bp_dprintf) | |
2304 | return; | |
2305 | } | |
2306 | ||
d3ce09f5 SS |
2307 | /* Do a first pass to check for locations with no assigned |
2308 | conditions or conditions that fail to parse to a valid agent expression | |
2309 | bytecode. If any of these happen, then it's no use to send conditions | |
2310 | to the target since this location will always trigger and generate a | |
2311 | response back to GDB. */ | |
2312 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2313 | { | |
2314 | loc = (*loc2p); | |
2315 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2316 | { | |
2317 | if (modified) | |
2318 | { | |
d3ce09f5 SS |
2319 | /* Re-parse the commands since something changed. In that |
2320 | case we already freed the command bytecodes (see | |
2321 | force_breakpoint_reinsertion). We just | |
2322 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2323 | loc->cmd_bytecode |
2324 | = parse_cmd_to_aexpr (bl->address, | |
2325 | loc->owner->extra_string); | |
d3ce09f5 SS |
2326 | } |
2327 | ||
2328 | /* If we have a NULL bytecode expression, it means something | |
2329 | went wrong or we have a null command expression. */ | |
2330 | if (!loc->cmd_bytecode) | |
2331 | { | |
2332 | null_command_or_parse_error = 1; | |
2333 | break; | |
2334 | } | |
2335 | } | |
2336 | } | |
2337 | ||
2338 | /* If anything failed, then we're not doing target-side commands, | |
2339 | and so clean up. */ | |
2340 | if (null_command_or_parse_error) | |
2341 | { | |
2342 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2343 | { | |
2344 | loc = (*loc2p); | |
2345 | if (is_breakpoint (loc->owner) | |
2346 | && loc->pspace->num == bl->pspace->num) | |
2347 | { | |
2348 | /* Only go as far as the first NULL bytecode is | |
2349 | located. */ | |
40fb6c5e | 2350 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2351 | return; |
2352 | ||
833177a4 | 2353 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2354 | } |
2355 | } | |
2356 | } | |
2357 | ||
2358 | /* No NULL commands or failed bytecode generation. Build a command list | |
2359 | for this location's address. */ | |
2360 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2361 | { | |
2362 | loc = (*loc2p); | |
2363 | if (loc->owner->extra_string | |
2364 | && is_breakpoint (loc->owner) | |
2365 | && loc->pspace->num == bl->pspace->num | |
2366 | && loc->owner->enable_state == bp_enabled | |
2367 | && loc->enabled) | |
3cde5c42 PA |
2368 | { |
2369 | /* Add the command to the vector. This will be used later | |
2370 | to send the commands to the target. */ | |
2371 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2372 | } | |
d3ce09f5 SS |
2373 | } |
2374 | ||
2375 | bl->target_info.persist = 0; | |
2376 | /* Maybe flag this location as persistent. */ | |
2377 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2378 | bl->target_info.persist = 1; | |
2379 | } | |
2380 | ||
833b7ab5 YQ |
2381 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2382 | of breakpoint according to ADDR except single-step breakpoint. | |
2383 | Get the kind of single-step breakpoint according to the current | |
2384 | registers state. */ | |
cd6c3b4f YQ |
2385 | |
2386 | static int | |
2387 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2388 | { | |
833b7ab5 YQ |
2389 | if (bl->owner->type == bp_single_step) |
2390 | { | |
2391 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2392 | struct regcache *regcache; | |
2393 | ||
00431a78 | 2394 | regcache = get_thread_regcache (thr); |
833b7ab5 YQ |
2395 | |
2396 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2397 | regcache, addr); | |
2398 | } | |
2399 | else | |
2400 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2401 | } |
2402 | ||
35df4500 TJB |
2403 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2404 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2405 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2406 | Returns 0 for success, 1 if the bp_location type is not supported or |
2407 | -1 for failure. | |
879bfdc2 | 2408 | |
4a64f543 MS |
2409 | NOTE drow/2003-09-09: This routine could be broken down to an |
2410 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2411 | static int |
35df4500 | 2412 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2413 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2414 | int *disabled_breaks, |
dd61ec5c MW |
2415 | int *hw_breakpoint_error, |
2416 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2417 | { |
cc06b668 | 2418 | gdb_exception bp_excpt; |
879bfdc2 | 2419 | |
b775012e | 2420 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2421 | return 0; |
2422 | ||
35c63cd8 JB |
2423 | /* Note we don't initialize bl->target_info, as that wipes out |
2424 | the breakpoint location's shadow_contents if the breakpoint | |
2425 | is still inserted at that location. This in turn breaks | |
2426 | target_read_memory which depends on these buffers when | |
2427 | a memory read is requested at the breakpoint location: | |
2428 | Once the target_info has been wiped, we fail to see that | |
2429 | we have a breakpoint inserted at that address and thus | |
2430 | read the breakpoint instead of returning the data saved in | |
2431 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2432 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2433 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2434 | bl->target_info.length = bl->length; |
8181d85f | 2435 | |
b775012e LM |
2436 | /* When working with target-side conditions, we must pass all the conditions |
2437 | for the same breakpoint address down to the target since GDB will not | |
2438 | insert those locations. With a list of breakpoint conditions, the target | |
2439 | can decide when to stop and notify GDB. */ | |
2440 | ||
2441 | if (is_breakpoint (bl->owner)) | |
2442 | { | |
2443 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2444 | build_target_command_list (bl); |
2445 | /* Reset the modification marker. */ | |
b775012e LM |
2446 | bl->needs_update = 0; |
2447 | } | |
2448 | ||
35df4500 TJB |
2449 | if (bl->loc_type == bp_loc_software_breakpoint |
2450 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2451 | { |
35df4500 | 2452 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2453 | { |
2454 | /* If the explicitly specified breakpoint type | |
2455 | is not hardware breakpoint, check the memory map to see | |
2456 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2457 | |
765dc015 VP |
2458 | Two important cases are: |
2459 | - location type is not hardware breakpoint, memory | |
2460 | is readonly. We change the type of the location to | |
2461 | hardware breakpoint. | |
4a64f543 MS |
2462 | - location type is hardware breakpoint, memory is |
2463 | read-write. This means we've previously made the | |
2464 | location hardware one, but then the memory map changed, | |
2465 | so we undo. | |
765dc015 | 2466 | |
4a64f543 MS |
2467 | When breakpoints are removed, remove_breakpoints will use |
2468 | location types we've just set here, the only possible | |
2469 | problem is that memory map has changed during running | |
2470 | program, but it's not going to work anyway with current | |
2471 | gdb. */ | |
765dc015 | 2472 | struct mem_region *mr |
0d5ed153 | 2473 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2474 | |
2475 | if (mr) | |
2476 | { | |
2477 | if (automatic_hardware_breakpoints) | |
2478 | { | |
765dc015 VP |
2479 | enum bp_loc_type new_type; |
2480 | ||
2481 | if (mr->attrib.mode != MEM_RW) | |
2482 | new_type = bp_loc_hardware_breakpoint; | |
2483 | else | |
2484 | new_type = bp_loc_software_breakpoint; | |
2485 | ||
35df4500 | 2486 | if (new_type != bl->loc_type) |
765dc015 VP |
2487 | { |
2488 | static int said = 0; | |
cc59ec59 | 2489 | |
35df4500 | 2490 | bl->loc_type = new_type; |
765dc015 VP |
2491 | if (!said) |
2492 | { | |
3e43a32a MS |
2493 | fprintf_filtered (gdb_stdout, |
2494 | _("Note: automatically using " | |
2495 | "hardware breakpoints for " | |
2496 | "read-only addresses.\n")); | |
765dc015 VP |
2497 | said = 1; |
2498 | } | |
2499 | } | |
2500 | } | |
35df4500 | 2501 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2502 | && mr->attrib.mode != MEM_RW) |
2503 | { | |
2504 | fprintf_unfiltered (tmp_error_stream, | |
2505 | _("Cannot insert breakpoint %d.\n" | |
2506 | "Cannot set software breakpoint " | |
2507 | "at read-only address %s\n"), | |
2508 | bl->owner->number, | |
2509 | paddress (bl->gdbarch, bl->address)); | |
2510 | return 1; | |
2511 | } | |
765dc015 VP |
2512 | } |
2513 | } | |
2514 | ||
879bfdc2 DJ |
2515 | /* First check to see if we have to handle an overlay. */ |
2516 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2517 | || bl->section == NULL |
2518 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2519 | { |
2520 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2521 | try |
dd61ec5c | 2522 | { |
0000e5cc PA |
2523 | int val; |
2524 | ||
dd61ec5c | 2525 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2526 | if (val) |
688fca4f | 2527 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2528 | } |
94aeb44b | 2529 | catch (gdb_exception &e) |
dd61ec5c | 2530 | { |
94aeb44b | 2531 | bp_excpt = std::move (e); |
dd61ec5c | 2532 | } |
879bfdc2 DJ |
2533 | } |
2534 | else | |
2535 | { | |
4a64f543 | 2536 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2537 | Shall we set a breakpoint at the LMA? */ |
2538 | if (!overlay_events_enabled) | |
2539 | { | |
2540 | /* Yes -- overlay event support is not active, | |
2541 | so we must try to set a breakpoint at the LMA. | |
2542 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2543 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2544 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2545 | bl->owner->number); |
879bfdc2 DJ |
2546 | else |
2547 | { | |
35df4500 TJB |
2548 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2549 | bl->section); | |
879bfdc2 | 2550 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2551 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2552 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2553 | |
2554 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2555 | try |
0000e5cc PA |
2556 | { |
2557 | int val; | |
2558 | ||
579c6ad9 | 2559 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2560 | = breakpoint_kind (bl, &addr); |
2561 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2562 | val = target_insert_breakpoint (bl->gdbarch, |
2563 | &bl->overlay_target_info); | |
2564 | if (val) | |
688fca4f PA |
2565 | bp_excpt |
2566 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2567 | } |
94aeb44b | 2568 | catch (gdb_exception &e) |
0000e5cc | 2569 | { |
94aeb44b | 2570 | bp_excpt = std::move (e); |
0000e5cc PA |
2571 | } |
2572 | ||
688fca4f | 2573 | if (bp_excpt.reason != 0) |
99361f52 | 2574 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2575 | "Overlay breakpoint %d " |
2576 | "failed: in ROM?\n", | |
35df4500 | 2577 | bl->owner->number); |
879bfdc2 DJ |
2578 | } |
2579 | } | |
2580 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2581 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2582 | { |
2583 | /* Yes. This overlay section is mapped into memory. */ | |
a70b8144 | 2584 | try |
dd61ec5c | 2585 | { |
0000e5cc PA |
2586 | int val; |
2587 | ||
dd61ec5c | 2588 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2589 | if (val) |
688fca4f | 2590 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2591 | } |
94aeb44b | 2592 | catch (gdb_exception &e) |
dd61ec5c | 2593 | { |
94aeb44b | 2594 | bp_excpt = std::move (e); |
dd61ec5c | 2595 | } |
879bfdc2 DJ |
2596 | } |
2597 | else | |
2598 | { | |
2599 | /* No. This breakpoint will not be inserted. | |
2600 | No error, but do not mark the bp as 'inserted'. */ | |
2601 | return 0; | |
2602 | } | |
2603 | } | |
2604 | ||
688fca4f | 2605 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2606 | { |
2607 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2608 | |
2609 | /* In some cases, we might not be able to insert a | |
2610 | breakpoint in a shared library that has already been | |
2611 | removed, but we have not yet processed the shlib unload | |
2612 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2613 | breakpoint insertion themselves can't tell why the |
2614 | breakpoint insertion failed (e.g., the remote target | |
2615 | doesn't define error codes), so we must treat generic | |
2616 | errors as memory errors. */ | |
688fca4f PA |
2617 | if (bp_excpt.reason == RETURN_ERROR |
2618 | && (bp_excpt.error == GENERIC_ERROR | |
2619 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2620 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2621 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2622 | || shared_objfile_contains_address_p (bl->pspace, |
2623 | bl->address))) | |
879bfdc2 | 2624 | { |
4a64f543 | 2625 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2626 | bl->shlib_disabled = 1; |
76727919 | 2627 | gdb::observers::breakpoint_modified.notify (bl->owner); |
3fbb6ffa TJB |
2628 | if (!*disabled_breaks) |
2629 | { | |
2630 | fprintf_unfiltered (tmp_error_stream, | |
2631 | "Cannot insert breakpoint %d.\n", | |
2632 | bl->owner->number); | |
2633 | fprintf_unfiltered (tmp_error_stream, | |
2634 | "Temporarily disabling shared " | |
2635 | "library breakpoints:\n"); | |
2636 | } | |
2637 | *disabled_breaks = 1; | |
879bfdc2 | 2638 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2639 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2640 | return 0; |
879bfdc2 DJ |
2641 | } |
2642 | else | |
879bfdc2 | 2643 | { |
35df4500 | 2644 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2645 | { |
0000e5cc | 2646 | *hw_breakpoint_error = 1; |
688fca4f | 2647 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
dd61ec5c MW |
2648 | fprintf_unfiltered (tmp_error_stream, |
2649 | "Cannot insert hardware breakpoint %d%s", | |
688fca4f PA |
2650 | bl->owner->number, |
2651 | bp_excpt.message ? ":" : ".\n"); | |
2652 | if (bp_excpt.message != NULL) | |
2653 | fprintf_unfiltered (tmp_error_stream, "%s.\n", | |
3d6e9d23 | 2654 | bp_excpt.what ()); |
879bfdc2 DJ |
2655 | } |
2656 | else | |
2657 | { | |
688fca4f | 2658 | if (bp_excpt.message == NULL) |
0000e5cc | 2659 | { |
1ccbe998 | 2660 | std::string message |
0000e5cc PA |
2661 | = memory_error_message (TARGET_XFER_E_IO, |
2662 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2663 | |
2664 | fprintf_unfiltered (tmp_error_stream, | |
2665 | "Cannot insert breakpoint %d.\n" | |
2666 | "%s\n", | |
1ccbe998 | 2667 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2668 | } |
2669 | else | |
2670 | { | |
2671 | fprintf_unfiltered (tmp_error_stream, | |
2672 | "Cannot insert breakpoint %d: %s\n", | |
2673 | bl->owner->number, | |
3d6e9d23 | 2674 | bp_excpt.what ()); |
0000e5cc | 2675 | } |
879bfdc2 | 2676 | } |
0000e5cc | 2677 | return 1; |
879bfdc2 DJ |
2678 | |
2679 | } | |
2680 | } | |
2681 | else | |
35df4500 | 2682 | bl->inserted = 1; |
879bfdc2 | 2683 | |
0000e5cc | 2684 | return 0; |
879bfdc2 DJ |
2685 | } |
2686 | ||
35df4500 | 2687 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2688 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2689 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2690 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2691 | { |
0000e5cc PA |
2692 | int val; |
2693 | ||
77b06cd7 TJB |
2694 | gdb_assert (bl->owner->ops != NULL |
2695 | && bl->owner->ops->insert_location != NULL); | |
2696 | ||
2697 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2698 | |
2699 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2700 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2701 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2702 | { |
2703 | struct bp_location *loc, **loc_temp; | |
2704 | ||
2705 | /* But don't try to insert it, if there's already another | |
2706 | hw_access location that would be considered a duplicate | |
2707 | of this one. */ | |
2708 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2709 | if (loc != bl |
85d721b8 | 2710 | && loc->watchpoint_type == hw_access |
35df4500 | 2711 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2712 | { |
35df4500 TJB |
2713 | bl->duplicate = 1; |
2714 | bl->inserted = 1; | |
2715 | bl->target_info = loc->target_info; | |
2716 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2717 | val = 0; |
2718 | break; | |
2719 | } | |
2720 | ||
2721 | if (val == 1) | |
2722 | { | |
77b06cd7 TJB |
2723 | bl->watchpoint_type = hw_access; |
2724 | val = bl->owner->ops->insert_location (bl); | |
2725 | ||
2726 | if (val) | |
2727 | /* Back to the original value. */ | |
2728 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2729 | } |
2730 | } | |
2731 | ||
35df4500 | 2732 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2733 | } |
2734 | ||
35df4500 | 2735 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2736 | { |
0000e5cc PA |
2737 | int val; |
2738 | ||
77b06cd7 TJB |
2739 | gdb_assert (bl->owner->ops != NULL |
2740 | && bl->owner->ops->insert_location != NULL); | |
2741 | ||
2742 | val = bl->owner->ops->insert_location (bl); | |
2743 | if (val) | |
2744 | { | |
2745 | bl->owner->enable_state = bp_disabled; | |
2746 | ||
2747 | if (val == 1) | |
2748 | warning (_("\ | |
2749 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2750 | of catchpoint."), bl->owner->number); | |
2751 | else | |
2752 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2753 | } | |
2754 | ||
2755 | bl->inserted = (val == 0); | |
1640b821 DJ |
2756 | |
2757 | /* We've already printed an error message if there was a problem | |
2758 | inserting this catchpoint, and we've disabled the catchpoint, | |
2759 | so just return success. */ | |
2760 | return 0; | |
879bfdc2 DJ |
2761 | } |
2762 | ||
2763 | return 0; | |
2764 | } | |
2765 | ||
6c95b8df PA |
2766 | /* This function is called when program space PSPACE is about to be |
2767 | deleted. It takes care of updating breakpoints to not reference | |
2768 | PSPACE anymore. */ | |
2769 | ||
2770 | void | |
2771 | breakpoint_program_space_exit (struct program_space *pspace) | |
2772 | { | |
2773 | struct breakpoint *b, *b_temp; | |
876fa593 | 2774 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2775 | |
2776 | /* Remove any breakpoint that was set through this program space. */ | |
2777 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2778 | { | |
2779 | if (b->pspace == pspace) | |
2780 | delete_breakpoint (b); | |
2781 | } | |
2782 | ||
2783 | /* Breakpoints set through other program spaces could have locations | |
2784 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2785 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2786 | { |
2787 | struct bp_location *tmp; | |
2788 | ||
2789 | if (loc->pspace == pspace) | |
2790 | { | |
2bdf28a0 | 2791 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2792 | if (loc->owner->loc == loc) |
2793 | loc->owner->loc = loc->next; | |
2794 | else | |
2795 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2796 | if (tmp->next == loc) | |
2797 | { | |
2798 | tmp->next = loc->next; | |
2799 | break; | |
2800 | } | |
2801 | } | |
2802 | } | |
2803 | ||
2804 | /* Now update the global location list to permanently delete the | |
2805 | removed locations above. */ | |
44702360 | 2806 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2807 | } |
2808 | ||
74960c60 VP |
2809 | /* Make sure all breakpoints are inserted in inferior. |
2810 | Throws exception on any error. | |
2811 | A breakpoint that is already inserted won't be inserted | |
2812 | again, so calling this function twice is safe. */ | |
2813 | void | |
2814 | insert_breakpoints (void) | |
2815 | { | |
2816 | struct breakpoint *bpt; | |
2817 | ||
2818 | ALL_BREAKPOINTS (bpt) | |
2819 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2820 | { |
2821 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2822 | ||
2823 | update_watchpoint (w, 0 /* don't reparse. */); | |
2824 | } | |
74960c60 | 2825 | |
04086b45 PA |
2826 | /* Updating watchpoints creates new locations, so update the global |
2827 | location list. Explicitly tell ugll to insert locations and | |
2828 | ignore breakpoints_always_inserted_mode. */ | |
2829 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
2830 | } |
2831 | ||
20388dd6 YQ |
2832 | /* Invoke CALLBACK for each of bp_location. */ |
2833 | ||
2834 | void | |
2835 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2836 | { | |
2837 | struct bp_location *loc, **loc_tmp; | |
2838 | ||
2839 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2840 | { | |
2841 | callback (loc, NULL); | |
2842 | } | |
2843 | } | |
2844 | ||
b775012e LM |
2845 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2846 | target. It is the case with deleting and disabling of breakpoints when using | |
2847 | always-inserted mode. */ | |
2848 | ||
2849 | static void | |
2850 | update_inserted_breakpoint_locations (void) | |
2851 | { | |
2852 | struct bp_location *bl, **blp_tmp; | |
2853 | int error_flag = 0; | |
2854 | int val = 0; | |
2855 | int disabled_breaks = 0; | |
2856 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2857 | int hw_bp_details_reported = 0; |
b775012e | 2858 | |
d7e74731 | 2859 | string_file tmp_error_stream; |
b775012e LM |
2860 | |
2861 | /* Explicitly mark the warning -- this will only be printed if | |
2862 | there was an error. */ | |
d7e74731 | 2863 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2864 | |
5ed8105e | 2865 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2866 | |
2867 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2868 | { | |
2869 | /* We only want to update software breakpoints and hardware | |
2870 | breakpoints. */ | |
2871 | if (!is_breakpoint (bl->owner)) | |
2872 | continue; | |
2873 | ||
2874 | /* We only want to update locations that are already inserted | |
2875 | and need updating. This is to avoid unwanted insertion during | |
2876 | deletion of breakpoints. */ | |
4daf1902 | 2877 | if (!bl->inserted || !bl->needs_update) |
b775012e LM |
2878 | continue; |
2879 | ||
2880 | switch_to_program_space_and_thread (bl->pspace); | |
2881 | ||
2882 | /* For targets that support global breakpoints, there's no need | |
2883 | to select an inferior to insert breakpoint to. In fact, even | |
2884 | if we aren't attached to any process yet, we should still | |
2885 | insert breakpoints. */ | |
f5656ead | 2886 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
d7e15655 | 2887 | && inferior_ptid == null_ptid) |
b775012e LM |
2888 | continue; |
2889 | ||
d7e74731 | 2890 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2891 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2892 | if (val) |
2893 | error_flag = val; | |
2894 | } | |
2895 | ||
2896 | if (error_flag) | |
2897 | { | |
223ffa71 | 2898 | target_terminal::ours_for_output (); |
b775012e LM |
2899 | error_stream (tmp_error_stream); |
2900 | } | |
b775012e LM |
2901 | } |
2902 | ||
c30eee59 | 2903 | /* Used when starting or continuing the program. */ |
c906108c | 2904 | |
74960c60 VP |
2905 | static void |
2906 | insert_breakpoint_locations (void) | |
c906108c | 2907 | { |
a5606eee | 2908 | struct breakpoint *bpt; |
35df4500 | 2909 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2910 | int error_flag = 0; |
c906108c | 2911 | int val = 0; |
3fbb6ffa | 2912 | int disabled_breaks = 0; |
81d0cc19 | 2913 | int hw_breakpoint_error = 0; |
dd61ec5c | 2914 | int hw_bp_error_explained_already = 0; |
c906108c | 2915 | |
d7e74731 PA |
2916 | string_file tmp_error_stream; |
2917 | ||
81d0cc19 GS |
2918 | /* Explicitly mark the warning -- this will only be printed if |
2919 | there was an error. */ | |
d7e74731 | 2920 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 2921 | |
5ed8105e | 2922 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 2923 | |
35df4500 | 2924 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2925 | { |
b775012e | 2926 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2927 | continue; |
2928 | ||
4a64f543 MS |
2929 | /* There is no point inserting thread-specific breakpoints if |
2930 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2931 | has BL->OWNER always non-NULL. */ | |
35df4500 | 2932 | if (bl->owner->thread != -1 |
5d5658a1 | 2933 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
2934 | continue; |
2935 | ||
35df4500 | 2936 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2937 | |
2938 | /* For targets that support global breakpoints, there's no need | |
2939 | to select an inferior to insert breakpoint to. In fact, even | |
2940 | if we aren't attached to any process yet, we should still | |
2941 | insert breakpoints. */ | |
f5656ead | 2942 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
d7e15655 | 2943 | && inferior_ptid == null_ptid) |
6c95b8df PA |
2944 | continue; |
2945 | ||
d7e74731 | 2946 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2947 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2948 | if (val) |
eacd795a | 2949 | error_flag = val; |
879bfdc2 | 2950 | } |
c906108c | 2951 | |
4a64f543 MS |
2952 | /* If we failed to insert all locations of a watchpoint, remove |
2953 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2954 | ALL_BREAKPOINTS (bpt) |
2955 | { | |
2956 | int some_failed = 0; | |
2957 | struct bp_location *loc; | |
2958 | ||
2959 | if (!is_hardware_watchpoint (bpt)) | |
2960 | continue; | |
2961 | ||
d6b74ac4 | 2962 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2963 | continue; |
74960c60 VP |
2964 | |
2965 | if (bpt->disposition == disp_del_at_next_stop) | |
2966 | continue; | |
a5606eee VP |
2967 | |
2968 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2969 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2970 | { |
2971 | some_failed = 1; | |
2972 | break; | |
2973 | } | |
2974 | if (some_failed) | |
2975 | { | |
2976 | for (loc = bpt->loc; loc; loc = loc->next) | |
2977 | if (loc->inserted) | |
834c0d03 | 2978 | remove_breakpoint (loc); |
a5606eee VP |
2979 | |
2980 | hw_breakpoint_error = 1; | |
d7e74731 PA |
2981 | tmp_error_stream.printf ("Could not insert " |
2982 | "hardware watchpoint %d.\n", | |
2983 | bpt->number); | |
eacd795a | 2984 | error_flag = -1; |
a5606eee VP |
2985 | } |
2986 | } | |
2987 | ||
eacd795a | 2988 | if (error_flag) |
81d0cc19 GS |
2989 | { |
2990 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2991 | message about possibly exhausted resources. */ | |
dd61ec5c | 2992 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2993 | { |
d7e74731 | 2994 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 2995 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 2996 | } |
223ffa71 | 2997 | target_terminal::ours_for_output (); |
81d0cc19 GS |
2998 | error_stream (tmp_error_stream); |
2999 | } | |
c906108c SS |
3000 | } |
3001 | ||
c30eee59 TJB |
3002 | /* Used when the program stops. |
3003 | Returns zero if successful, or non-zero if there was a problem | |
3004 | removing a breakpoint location. */ | |
3005 | ||
c906108c | 3006 | int |
fba45db2 | 3007 | remove_breakpoints (void) |
c906108c | 3008 | { |
35df4500 | 3009 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3010 | int val = 0; |
c906108c | 3011 | |
35df4500 | 3012 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3013 | { |
1e4d1764 | 3014 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3015 | val |= remove_breakpoint (bl); |
c5aa993b | 3016 | } |
3a1bae8e | 3017 | return val; |
c906108c SS |
3018 | } |
3019 | ||
49fa26b0 PA |
3020 | /* When a thread exits, remove breakpoints that are related to |
3021 | that thread. */ | |
3022 | ||
3023 | static void | |
3024 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3025 | { | |
3026 | struct breakpoint *b, *b_tmp; | |
3027 | ||
3028 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3029 | { | |
5d5658a1 | 3030 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3031 | { |
3032 | b->disposition = disp_del_at_next_stop; | |
3033 | ||
3034 | printf_filtered (_("\ | |
43792cf0 PA |
3035 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3036 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3037 | |
3038 | /* Hide it from the user. */ | |
3039 | b->number = 0; | |
3040 | } | |
3041 | } | |
3042 | } | |
3043 | ||
f3869b1a | 3044 | /* See breakpoint.h. */ |
6c95b8df | 3045 | |
f3869b1a | 3046 | void |
00431a78 | 3047 | remove_breakpoints_inf (inferior *inf) |
6c95b8df | 3048 | { |
35df4500 | 3049 | struct bp_location *bl, **blp_tmp; |
6c95b8df | 3050 | int val; |
6c95b8df | 3051 | |
35df4500 | 3052 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3053 | { |
35df4500 | 3054 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3055 | continue; |
3056 | ||
fc126975 | 3057 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3058 | { |
834c0d03 | 3059 | val = remove_breakpoint (bl); |
6c95b8df | 3060 | if (val != 0) |
f3869b1a | 3061 | return; |
6c95b8df PA |
3062 | } |
3063 | } | |
6c95b8df PA |
3064 | } |
3065 | ||
e58b0e63 PA |
3066 | static int internal_breakpoint_number = -1; |
3067 | ||
84f4c1fe PM |
3068 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3069 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3070 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3071 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3072 | breakpoint_count and that value incremented. Internal breakpoints |
3073 | do not set the internal var bpnum. */ | |
3074 | static void | |
3075 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3076 | { | |
3077 | if (internal) | |
3078 | b->number = internal_breakpoint_number--; | |
3079 | else | |
3080 | { | |
3081 | set_breakpoint_count (breakpoint_count + 1); | |
3082 | b->number = breakpoint_count; | |
3083 | } | |
3084 | } | |
3085 | ||
e62c965a | 3086 | static struct breakpoint * |
a6d9a66e | 3087 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3088 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3089 | const struct breakpoint_ops *ops) |
e62c965a | 3090 | { |
51abb421 | 3091 | symtab_and_line sal; |
e62c965a PP |
3092 | sal.pc = address; |
3093 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3094 | sal.pspace = current_program_space; |
e62c965a | 3095 | |
51abb421 | 3096 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3097 | b->number = internal_breakpoint_number--; |
3098 | b->disposition = disp_donttouch; | |
3099 | ||
3100 | return b; | |
3101 | } | |
3102 | ||
17450429 PP |
3103 | static const char *const longjmp_names[] = |
3104 | { | |
3105 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3106 | }; | |
3107 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3108 | ||
3109 | /* Per-objfile data private to breakpoint.c. */ | |
3110 | struct breakpoint_objfile_data | |
3111 | { | |
3112 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
43dce439 | 3113 | struct bound_minimal_symbol overlay_msym {}; |
17450429 PP |
3114 | |
3115 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
43dce439 | 3116 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
17450429 | 3117 | |
28106bc2 | 3118 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3119 | int longjmp_searched = 0; |
28106bc2 | 3120 | |
45461e0d SM |
3121 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3122 | references. */ | |
3123 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3124 | |
17450429 | 3125 | /* Minimal symbol for "std::terminate()" (if any). */ |
43dce439 | 3126 | struct bound_minimal_symbol terminate_msym {}; |
17450429 PP |
3127 | |
3128 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
43dce439 | 3129 | struct bound_minimal_symbol exception_msym {}; |
28106bc2 SDJ |
3130 | |
3131 | /* True if we have looked for exception probes. */ | |
43dce439 | 3132 | int exception_searched = 0; |
28106bc2 | 3133 | |
45461e0d SM |
3134 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3135 | references. */ | |
3136 | std::vector<probe *> exception_probes; | |
17450429 PP |
3137 | }; |
3138 | ||
51d3063a TT |
3139 | static const struct objfile_key<breakpoint_objfile_data> |
3140 | breakpoint_objfile_key; | |
17450429 PP |
3141 | |
3142 | /* Minimal symbol not found sentinel. */ | |
3143 | static struct minimal_symbol msym_not_found; | |
3144 | ||
3145 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3146 | ||
3147 | static int | |
3148 | msym_not_found_p (const struct minimal_symbol *msym) | |
3149 | { | |
3150 | return msym == &msym_not_found; | |
3151 | } | |
3152 | ||
3153 | /* Return per-objfile data needed by breakpoint.c. | |
3154 | Allocate the data if necessary. */ | |
3155 | ||
3156 | static struct breakpoint_objfile_data * | |
3157 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3158 | { | |
3159 | struct breakpoint_objfile_data *bp_objfile_data; | |
3160 | ||
51d3063a | 3161 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
17450429 | 3162 | if (bp_objfile_data == NULL) |
51d3063a | 3163 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
17450429 PP |
3164 | return bp_objfile_data; |
3165 | } | |
3166 | ||
e62c965a | 3167 | static void |
af02033e | 3168 | create_overlay_event_breakpoint (void) |
e62c965a | 3169 | { |
af02033e | 3170 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3171 | |
2030c079 | 3172 | for (objfile *objfile : current_program_space->objfiles ()) |
69de3c6a PP |
3173 | { |
3174 | struct breakpoint *b; | |
17450429 PP |
3175 | struct breakpoint_objfile_data *bp_objfile_data; |
3176 | CORE_ADDR addr; | |
67994074 | 3177 | struct explicit_location explicit_loc; |
69de3c6a | 3178 | |
17450429 PP |
3179 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3180 | ||
3b7344d5 | 3181 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3182 | continue; |
3183 | ||
3b7344d5 | 3184 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3185 | { |
3b7344d5 | 3186 | struct bound_minimal_symbol m; |
17450429 PP |
3187 | |
3188 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3189 | if (m.minsym == NULL) |
17450429 PP |
3190 | { |
3191 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3192 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3193 | continue; |
3194 | } | |
3195 | bp_objfile_data->overlay_msym = m; | |
3196 | } | |
e62c965a | 3197 | |
77e371c0 | 3198 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3199 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3200 | bp_overlay_event, |
3201 | &internal_breakpoint_ops); | |
67994074 KS |
3202 | initialize_explicit_location (&explicit_loc); |
3203 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3204 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3205 | |
69de3c6a PP |
3206 | if (overlay_debugging == ovly_auto) |
3207 | { | |
3208 | b->enable_state = bp_enabled; | |
3209 | overlay_events_enabled = 1; | |
3210 | } | |
3211 | else | |
3212 | { | |
3213 | b->enable_state = bp_disabled; | |
3214 | overlay_events_enabled = 0; | |
3215 | } | |
e62c965a | 3216 | } |
e62c965a PP |
3217 | } |
3218 | ||
0fd8e87f | 3219 | static void |
af02033e | 3220 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3221 | { |
6c95b8df | 3222 | struct program_space *pspace; |
6c95b8df | 3223 | |
5ed8105e | 3224 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3225 | |
6c95b8df | 3226 | ALL_PSPACES (pspace) |
af02033e | 3227 | { |
af02033e PP |
3228 | set_current_program_space (pspace); |
3229 | ||
2030c079 | 3230 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
3231 | { |
3232 | int i; | |
3233 | struct gdbarch *gdbarch; | |
3234 | struct breakpoint_objfile_data *bp_objfile_data; | |
0fd8e87f | 3235 | |
aed57c53 | 3236 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3237 | |
aed57c53 | 3238 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
17450429 | 3239 | |
aed57c53 TT |
3240 | if (!bp_objfile_data->longjmp_searched) |
3241 | { | |
3242 | std::vector<probe *> ret | |
3243 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
25f9533e | 3244 | |
aed57c53 TT |
3245 | if (!ret.empty ()) |
3246 | { | |
3247 | /* We are only interested in checking one element. */ | |
3248 | probe *p = ret[0]; | |
3249 | ||
3250 | if (!p->can_evaluate_arguments ()) | |
3251 | { | |
3252 | /* We cannot use the probe interface here, because it does | |
3253 | not know how to evaluate arguments. */ | |
3254 | ret.clear (); | |
3255 | } | |
3256 | } | |
3257 | bp_objfile_data->longjmp_probes = ret; | |
3258 | bp_objfile_data->longjmp_searched = 1; | |
3259 | } | |
25f9533e | 3260 | |
aed57c53 TT |
3261 | if (!bp_objfile_data->longjmp_probes.empty ()) |
3262 | { | |
3263 | for (probe *p : bp_objfile_data->longjmp_probes) | |
3264 | { | |
3265 | struct breakpoint *b; | |
3266 | ||
3267 | b = create_internal_breakpoint (gdbarch, | |
3268 | p->get_relocated_address (objfile), | |
3269 | bp_longjmp_master, | |
3270 | &internal_breakpoint_ops); | |
3271 | b->location = new_probe_location ("-probe-stap libc:longjmp"); | |
3272 | b->enable_state = bp_disabled; | |
3273 | } | |
28106bc2 | 3274 | |
aed57c53 TT |
3275 | continue; |
3276 | } | |
28106bc2 | 3277 | |
aed57c53 | 3278 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
28106bc2 | 3279 | continue; |
28106bc2 | 3280 | |
aed57c53 TT |
3281 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
3282 | { | |
3283 | struct breakpoint *b; | |
3284 | const char *func_name; | |
3285 | CORE_ADDR addr; | |
3286 | struct explicit_location explicit_loc; | |
0fd8e87f | 3287 | |
aed57c53 TT |
3288 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
3289 | continue; | |
17450429 | 3290 | |
aed57c53 TT |
3291 | func_name = longjmp_names[i]; |
3292 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) | |
3293 | { | |
3294 | struct bound_minimal_symbol m; | |
3295 | ||
3296 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3297 | if (m.minsym == NULL) | |
3298 | { | |
3299 | /* Prevent future lookups in this objfile. */ | |
3300 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; | |
3301 | continue; | |
3302 | } | |
3303 | bp_objfile_data->longjmp_msym[i] = m; | |
3304 | } | |
17450429 | 3305 | |
aed57c53 TT |
3306 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
3307 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, | |
3308 | &internal_breakpoint_ops); | |
3309 | initialize_explicit_location (&explicit_loc); | |
3310 | explicit_loc.function_name = ASTRDUP (func_name); | |
3311 | b->location = new_explicit_location (&explicit_loc); | |
3312 | b->enable_state = bp_disabled; | |
3313 | } | |
3314 | } | |
af02033e | 3315 | } |
0fd8e87f UW |
3316 | } |
3317 | ||
af02033e | 3318 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3319 | static void |
af02033e | 3320 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3321 | { |
3322 | struct program_space *pspace; | |
af02033e | 3323 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3324 | |
5ed8105e | 3325 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3326 | |
3327 | ALL_PSPACES (pspace) | |
17450429 | 3328 | { |
17450429 PP |
3329 | CORE_ADDR addr; |
3330 | ||
3331 | set_current_program_space (pspace); | |
3332 | ||
2030c079 | 3333 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
3334 | { |
3335 | struct breakpoint *b; | |
3336 | struct breakpoint_objfile_data *bp_objfile_data; | |
3337 | struct explicit_location explicit_loc; | |
aa7d318d | 3338 | |
aed57c53 | 3339 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3340 | |
aed57c53 TT |
3341 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
3342 | continue; | |
17450429 | 3343 | |
aed57c53 TT |
3344 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
3345 | { | |
3346 | struct bound_minimal_symbol m; | |
17450429 | 3347 | |
aed57c53 TT |
3348 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
3349 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text | |
3350 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
3351 | { | |
3352 | /* Prevent future lookups in this objfile. */ | |
3353 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; | |
3354 | continue; | |
3355 | } | |
3356 | bp_objfile_data->terminate_msym = m; | |
3357 | } | |
aa7d318d | 3358 | |
aed57c53 TT |
3359 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3360 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
3361 | bp_std_terminate_master, | |
3362 | &internal_breakpoint_ops); | |
3363 | initialize_explicit_location (&explicit_loc); | |
3364 | explicit_loc.function_name = ASTRDUP (func_name); | |
3365 | b->location = new_explicit_location (&explicit_loc); | |
3366 | b->enable_state = bp_disabled; | |
3367 | } | |
17450429 | 3368 | } |
aa7d318d TT |
3369 | } |
3370 | ||
186c406b TT |
3371 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3372 | ||
70221824 | 3373 | static void |
186c406b TT |
3374 | create_exception_master_breakpoint (void) |
3375 | { | |
17450429 | 3376 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b | 3377 | |
2030c079 | 3378 | for (objfile *objfile : current_program_space->objfiles ()) |
186c406b | 3379 | { |
17450429 PP |
3380 | struct breakpoint *b; |
3381 | struct gdbarch *gdbarch; | |
3382 | struct breakpoint_objfile_data *bp_objfile_data; | |
3383 | CORE_ADDR addr; | |
67994074 | 3384 | struct explicit_location explicit_loc; |
17450429 PP |
3385 | |
3386 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3387 | ||
28106bc2 SDJ |
3388 | /* We prefer the SystemTap probe point if it exists. */ |
3389 | if (!bp_objfile_data->exception_searched) | |
3390 | { | |
45461e0d SM |
3391 | std::vector<probe *> ret |
3392 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
25f9533e | 3393 | |
45461e0d | 3394 | if (!ret.empty ()) |
25f9533e SDJ |
3395 | { |
3396 | /* We are only interested in checking one element. */ | |
45461e0d | 3397 | probe *p = ret[0]; |
25f9533e | 3398 | |
935676c9 | 3399 | if (!p->can_evaluate_arguments ()) |
25f9533e SDJ |
3400 | { |
3401 | /* We cannot use the probe interface here, because it does | |
3402 | not know how to evaluate arguments. */ | |
45461e0d | 3403 | ret.clear (); |
25f9533e SDJ |
3404 | } |
3405 | } | |
3406 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3407 | bp_objfile_data->exception_searched = 1; |
3408 | } | |
3409 | ||
45461e0d | 3410 | if (!bp_objfile_data->exception_probes.empty ()) |
28106bc2 | 3411 | { |
b926417a | 3412 | gdbarch = get_objfile_arch (objfile); |
45461e0d SM |
3413 | |
3414 | for (probe *p : bp_objfile_data->exception_probes) | |
28106bc2 | 3415 | { |
729662a5 | 3416 | b = create_internal_breakpoint (gdbarch, |
935676c9 | 3417 | p->get_relocated_address (objfile), |
28106bc2 SDJ |
3418 | bp_exception_master, |
3419 | &internal_breakpoint_ops); | |
d28cd78a | 3420 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3421 | b->enable_state = bp_disabled; |
3422 | } | |
3423 | ||
3424 | continue; | |
3425 | } | |
3426 | ||
3427 | /* Otherwise, try the hook function. */ | |
3428 | ||
3b7344d5 | 3429 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3430 | continue; |
3431 | ||
3432 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3433 | |
3b7344d5 | 3434 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3435 | { |
3b7344d5 | 3436 | struct bound_minimal_symbol debug_hook; |
186c406b | 3437 | |
17450429 | 3438 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3439 | if (debug_hook.minsym == NULL) |
17450429 | 3440 | { |
3b7344d5 | 3441 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3442 | continue; |
3443 | } | |
3444 | ||
3445 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3446 | } |
17450429 | 3447 | |
77e371c0 | 3448 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
8b88a78e PA |
3449 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3450 | current_top_target ()); | |
06edf0c0 PA |
3451 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3452 | &internal_breakpoint_ops); | |
67994074 KS |
3453 | initialize_explicit_location (&explicit_loc); |
3454 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3455 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3456 | b->enable_state = bp_disabled; |
186c406b | 3457 | } |
186c406b TT |
3458 | } |
3459 | ||
9ef9e6a6 KS |
3460 | /* Does B have a location spec? */ |
3461 | ||
3462 | static int | |
3463 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3464 | { | |
d28cd78a | 3465 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3466 | } |
3467 | ||
c906108c | 3468 | void |
fba45db2 | 3469 | update_breakpoints_after_exec (void) |
c906108c | 3470 | { |
35df4500 | 3471 | struct breakpoint *b, *b_tmp; |
876fa593 | 3472 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3473 | |
25b22b0a PA |
3474 | /* We're about to delete breakpoints from GDB's lists. If the |
3475 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3476 | writing the breakpoints' "shadow contents" back into memory. The | |
3477 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3478 | do that. Instead, the target is responsible from marking | |
3479 | breakpoints out as soon as it detects an exec. We don't do that | |
3480 | here instead, because there may be other attempts to delete | |
3481 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3482 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3483 | if (bploc->pspace == current_program_space) |
3484 | gdb_assert (!bploc->inserted); | |
c906108c | 3485 | |
35df4500 | 3486 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3487 | { |
6c95b8df PA |
3488 | if (b->pspace != current_program_space) |
3489 | continue; | |
3490 | ||
4a64f543 | 3491 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3492 | if (b->type == bp_shlib_event) |
3493 | { | |
3494 | delete_breakpoint (b); | |
3495 | continue; | |
3496 | } | |
c906108c | 3497 | |
4a64f543 | 3498 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3499 | if (b->type == bp_jit_event) |
3500 | { | |
3501 | delete_breakpoint (b); | |
3502 | continue; | |
3503 | } | |
3504 | ||
1900040c | 3505 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3506 | as must overlay event and longjmp master breakpoints. */ |
3507 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3508 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3509 | || b->type == bp_exception_master) | |
c4093a6a JM |
3510 | { |
3511 | delete_breakpoint (b); | |
3512 | continue; | |
3513 | } | |
3514 | ||
4a64f543 | 3515 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3516 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3517 | { |
3518 | delete_breakpoint (b); | |
3519 | continue; | |
3520 | } | |
3521 | ||
7c16b83e PA |
3522 | /* Just like single-step breakpoints. */ |
3523 | if (b->type == bp_single_step) | |
3524 | { | |
3525 | delete_breakpoint (b); | |
3526 | continue; | |
3527 | } | |
3528 | ||
611c83ae PA |
3529 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3530 | after an exec. */ | |
186c406b | 3531 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3532 | || b->type == bp_longjmp_call_dummy |
186c406b | 3533 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3534 | { |
3535 | delete_breakpoint (b); | |
3536 | continue; | |
3537 | } | |
3538 | ||
ce78b96d JB |
3539 | if (b->type == bp_catchpoint) |
3540 | { | |
3541 | /* For now, none of the bp_catchpoint breakpoints need to | |
3542 | do anything at this point. In the future, if some of | |
3543 | the catchpoints need to something, we will need to add | |
3544 | a new method, and call this method from here. */ | |
3545 | continue; | |
3546 | } | |
3547 | ||
c5aa993b JM |
3548 | /* bp_finish is a special case. The only way we ought to be able |
3549 | to see one of these when an exec() has happened, is if the user | |
3550 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3551 | carries them to the call-site of the current callee, by setting | |
3552 | a temporary bp there and resuming. But in this case, the finish | |
3553 | will carry them entirely through the vfork & exec. | |
3554 | ||
3555 | We don't want to allow a bp_finish to remain inserted now. But | |
3556 | we can't safely delete it, 'cause finish_command has a handle to | |
3557 | the bp on a bpstat, and will later want to delete it. There's a | |
3558 | chance (and I've seen it happen) that if we delete the bp_finish | |
3559 | here, that its storage will get reused by the time finish_command | |
3560 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3561 | We really must allow finish_command to delete a bp_finish. | |
3562 | ||
e5dd4106 | 3563 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3564 | it's safe to delete something others may have handles to?" |
3565 | problem, what we'll do here is just uninsert the bp_finish, and | |
3566 | let finish_command delete it. | |
3567 | ||
3568 | (We know the bp_finish is "doomed" in the sense that it's | |
3569 | momentary, and will be deleted as soon as finish_command sees | |
3570 | the inferior stopped. So it doesn't matter that the bp's | |
3571 | address is probably bogus in the new a.out, unlike e.g., the | |
3572 | solib breakpoints.) */ | |
c5aa993b | 3573 | |
c5aa993b JM |
3574 | if (b->type == bp_finish) |
3575 | { | |
3576 | continue; | |
3577 | } | |
3578 | ||
3579 | /* Without a symbolic address, we have little hope of the | |
3580 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3581 | a.out. */ |
9ef9e6a6 | 3582 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3583 | { |
3584 | delete_breakpoint (b); | |
3585 | continue; | |
3586 | } | |
c5aa993b | 3587 | } |
c906108c SS |
3588 | } |
3589 | ||
3590 | int | |
d80ee84f | 3591 | detach_breakpoints (ptid_t ptid) |
c906108c | 3592 | { |
35df4500 | 3593 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3594 | int val = 0; |
2989a365 | 3595 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3596 | struct inferior *inf = current_inferior (); |
c5aa993b | 3597 | |
e99b03dc | 3598 | if (ptid.pid () == inferior_ptid.pid ()) |
8a3fe4f8 | 3599 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3600 | |
6c95b8df | 3601 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3602 | inferior_ptid = ptid; |
35df4500 | 3603 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3604 | { |
35df4500 | 3605 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3606 | continue; |
3607 | ||
bd9673a4 PW |
3608 | /* This function must physically remove breakpoints locations |
3609 | from the specified ptid, without modifying the breakpoint | |
3610 | package's state. Locations of type bp_loc_other are only | |
3611 | maintained at GDB side. So, there is no need to remove | |
3612 | these bp_loc_other locations. Moreover, removing these | |
3613 | would modify the breakpoint package's state. */ | |
3614 | if (bl->loc_type == bp_loc_other) | |
3615 | continue; | |
3616 | ||
35df4500 | 3617 | if (bl->inserted) |
b2b6a7da | 3618 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3619 | } |
d03285ec | 3620 | |
3a1bae8e | 3621 | return val; |
c906108c SS |
3622 | } |
3623 | ||
35df4500 | 3624 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3625 | Note that this is used to detach breakpoints from a child fork. |
3626 | When we get here, the child isn't in the inferior list, and neither | |
3627 | do we have objects to represent its address space --- we should | |
35df4500 | 3628 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3629 | |
c906108c | 3630 | static int |
b2b6a7da | 3631 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3632 | { |
3633 | int val; | |
c5aa993b | 3634 | |
35df4500 TJB |
3635 | /* BL is never in moribund_locations by our callers. */ |
3636 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3637 | |
74960c60 VP |
3638 | /* The type of none suggests that owner is actually deleted. |
3639 | This should not ever happen. */ | |
35df4500 | 3640 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3641 | |
35df4500 TJB |
3642 | if (bl->loc_type == bp_loc_software_breakpoint |
3643 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3644 | { |
c02f5703 MS |
3645 | /* "Normal" instruction breakpoint: either the standard |
3646 | trap-instruction bp (bp_breakpoint), or a | |
3647 | bp_hardware_breakpoint. */ | |
3648 | ||
3649 | /* First check to see if we have to handle an overlay. */ | |
3650 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3651 | || bl->section == NULL |
3652 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3653 | { |
3654 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3655 | |
3656 | /* If we're trying to uninsert a memory breakpoint that we | |
3657 | know is set in a dynamic object that is marked | |
3658 | shlib_disabled, then either the dynamic object was | |
3659 | removed with "remove-symbol-file" or with | |
3660 | "nosharedlibrary". In the former case, we don't know | |
3661 | whether another dynamic object might have loaded over the | |
3662 | breakpoint's address -- the user might well let us know | |
3663 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3664 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3665 | list of dynamically loaded objects). If we have the |
3666 | breakpoint's shadow memory, that is, this is a software | |
3667 | breakpoint managed by GDB, check whether the breakpoint | |
3668 | is still inserted in memory, to avoid overwriting wrong | |
3669 | code with stale saved shadow contents. Note that HW | |
3670 | breakpoints don't have shadow memory, as they're | |
3671 | implemented using a mechanism that is not dependent on | |
3672 | being able to modify the target's memory, and as such | |
3673 | they should always be removed. */ | |
3674 | if (bl->shlib_disabled | |
3675 | && bl->target_info.shadow_len != 0 | |
3676 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3677 | val = 0; | |
3678 | else | |
73971819 | 3679 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3680 | } |
c906108c SS |
3681 | else |
3682 | { | |
4a64f543 | 3683 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3684 | Did we set a breakpoint at the LMA? */ |
3685 | if (!overlay_events_enabled) | |
3686 | { | |
3687 | /* Yes -- overlay event support is not active, so we | |
3688 | should have set a breakpoint at the LMA. Remove it. | |
3689 | */ | |
c02f5703 MS |
3690 | /* Ignore any failures: if the LMA is in ROM, we will |
3691 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3692 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3693 | target_remove_hw_breakpoint (bl->gdbarch, | |
3694 | &bl->overlay_target_info); | |
c02f5703 | 3695 | else |
35df4500 | 3696 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3697 | &bl->overlay_target_info, |
3698 | reason); | |
c02f5703 MS |
3699 | } |
3700 | /* Did we set a breakpoint at the VMA? | |
3701 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3702 | if (bl->inserted) |
c906108c | 3703 | { |
c02f5703 MS |
3704 | /* Yes -- remove it. Previously we did not bother to |
3705 | remove the breakpoint if the section had been | |
3706 | unmapped, but let's not rely on that being safe. We | |
3707 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3708 | |
3709 | /* However, we should remove *software* breakpoints only | |
3710 | if the section is still mapped, or else we overwrite | |
3711 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3712 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3713 | || section_is_mapped (bl->section)) | |
73971819 | 3714 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3715 | else |
3716 | val = 0; | |
c906108c | 3717 | } |
c02f5703 MS |
3718 | else |
3719 | { | |
3720 | /* No -- not inserted, so no need to remove. No error. */ | |
3721 | val = 0; | |
3722 | } | |
c906108c | 3723 | } |
879d1e6b | 3724 | |
08351840 PA |
3725 | /* In some cases, we might not be able to remove a breakpoint in |
3726 | a shared library that has already been removed, but we have | |
3727 | not yet processed the shlib unload event. Similarly for an | |
3728 | unloaded add-symbol-file object - the user might not yet have | |
3729 | had the chance to remove-symbol-file it. shlib_disabled will | |
3730 | be set if the library/object has already been removed, but | |
3731 | the breakpoint hasn't been uninserted yet, e.g., after | |
3732 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3733 | always-inserted mode. */ | |
076855f9 | 3734 | if (val |
08351840 PA |
3735 | && (bl->loc_type == bp_loc_software_breakpoint |
3736 | && (bl->shlib_disabled | |
3737 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3738 | || shared_objfile_contains_address_p (bl->pspace, |
3739 | bl->address)))) | |
879d1e6b UW |
3740 | val = 0; |
3741 | ||
c906108c SS |
3742 | if (val) |
3743 | return val; | |
b2b6a7da | 3744 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3745 | } |
35df4500 | 3746 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3747 | { |
77b06cd7 TJB |
3748 | gdb_assert (bl->owner->ops != NULL |
3749 | && bl->owner->ops->remove_location != NULL); | |
3750 | ||
b2b6a7da | 3751 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3752 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3753 | |
c906108c | 3754 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3755 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3756 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3757 | bl->owner->number); |
c906108c | 3758 | } |
35df4500 TJB |
3759 | else if (bl->owner->type == bp_catchpoint |
3760 | && breakpoint_enabled (bl->owner) | |
3761 | && !bl->duplicate) | |
ce78b96d | 3762 | { |
77b06cd7 TJB |
3763 | gdb_assert (bl->owner->ops != NULL |
3764 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3765 | |
73971819 | 3766 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3767 | if (val) |
3768 | return val; | |
77b06cd7 | 3769 | |
b2b6a7da | 3770 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3771 | } |
c906108c SS |
3772 | |
3773 | return 0; | |
3774 | } | |
3775 | ||
6c95b8df | 3776 | static int |
834c0d03 | 3777 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3778 | { |
35df4500 TJB |
3779 | /* BL is never in moribund_locations by our callers. */ |
3780 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3781 | |
6c95b8df PA |
3782 | /* The type of none suggests that owner is actually deleted. |
3783 | This should not ever happen. */ | |
35df4500 | 3784 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3785 | |
5ed8105e | 3786 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3787 | |
35df4500 | 3788 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3789 | |
5ed8105e | 3790 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3791 | } |
3792 | ||
c906108c SS |
3793 | /* Clear the "inserted" flag in all breakpoints. */ |
3794 | ||
25b22b0a | 3795 | void |
fba45db2 | 3796 | mark_breakpoints_out (void) |
c906108c | 3797 | { |
35df4500 | 3798 | struct bp_location *bl, **blp_tmp; |
c906108c | 3799 | |
35df4500 | 3800 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3801 | if (bl->pspace == current_program_space) |
35df4500 | 3802 | bl->inserted = 0; |
c906108c SS |
3803 | } |
3804 | ||
53a5351d JM |
3805 | /* Clear the "inserted" flag in all breakpoints and delete any |
3806 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3807 | |
3808 | Plus other such housekeeping that has to be done for breakpoints | |
3809 | between runs. | |
3810 | ||
53a5351d JM |
3811 | Note: this function gets called at the end of a run (by |
3812 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3813 | init_wait_for_inferior). */ |
c906108c SS |
3814 | |
3815 | ||
3816 | ||
3817 | void | |
fba45db2 | 3818 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3819 | { |
35df4500 | 3820 | struct breakpoint *b, *b_tmp; |
6c95b8df | 3821 | struct program_space *pspace = current_program_space; |
c906108c | 3822 | |
50c71eaf PA |
3823 | /* If breakpoint locations are shared across processes, then there's |
3824 | nothing to do. */ | |
f5656ead | 3825 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3826 | return; |
3827 | ||
1a853c52 | 3828 | mark_breakpoints_out (); |
075f6582 | 3829 | |
35df4500 | 3830 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3831 | { |
6c95b8df PA |
3832 | if (b->loc && b->loc->pspace != pspace) |
3833 | continue; | |
3834 | ||
c5aa993b JM |
3835 | switch (b->type) |
3836 | { | |
3837 | case bp_call_dummy: | |
e2e4d78b | 3838 | case bp_longjmp_call_dummy: |
c906108c | 3839 | |
c5aa993b | 3840 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3841 | cause problems when the inferior is rerun, so we better get |
3842 | rid of it. */ | |
3843 | ||
3844 | case bp_watchpoint_scope: | |
3845 | ||
3846 | /* Also get rid of scope breakpoints. */ | |
3847 | ||
3848 | case bp_shlib_event: | |
3849 | ||
3850 | /* Also remove solib event breakpoints. Their addresses may | |
3851 | have changed since the last time we ran the program. | |
3852 | Actually we may now be debugging against different target; | |
3853 | and so the solib backend that installed this breakpoint may | |
3854 | not be used in by the target. E.g., | |
3855 | ||
3856 | (gdb) file prog-linux | |
3857 | (gdb) run # native linux target | |
3858 | ... | |
3859 | (gdb) kill | |
3860 | (gdb) file prog-win.exe | |
3861 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3862 | */ | |
c906108c | 3863 | |
f59f708a PA |
3864 | case bp_step_resume: |
3865 | ||
3866 | /* Also remove step-resume breakpoints. */ | |
3867 | ||
7c16b83e PA |
3868 | case bp_single_step: |
3869 | ||
3870 | /* Also remove single-step breakpoints. */ | |
3871 | ||
c5aa993b JM |
3872 | delete_breakpoint (b); |
3873 | break; | |
c906108c | 3874 | |
c5aa993b JM |
3875 | case bp_watchpoint: |
3876 | case bp_hardware_watchpoint: | |
3877 | case bp_read_watchpoint: | |
3878 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3879 | { |
3880 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3881 | |
3a5c3e22 PA |
3882 | /* Likewise for watchpoints on local expressions. */ |
3883 | if (w->exp_valid_block != NULL) | |
3884 | delete_breakpoint (b); | |
63000888 | 3885 | else |
3a5c3e22 | 3886 | { |
63000888 PA |
3887 | /* Get rid of existing locations, which are no longer |
3888 | valid. New ones will be created in | |
3889 | update_watchpoint, when the inferior is restarted. | |
3890 | The next update_global_location_list call will | |
3891 | garbage collect them. */ | |
3892 | b->loc = NULL; | |
3893 | ||
3894 | if (context == inf_starting) | |
3895 | { | |
3896 | /* Reset val field to force reread of starting value in | |
3897 | insert_breakpoints. */ | |
850645cf | 3898 | w->val.reset (nullptr); |
4c1d86d9 | 3899 | w->val_valid = false; |
63000888 PA |
3900 | } |
3901 | } | |
3a5c3e22 | 3902 | } |
c5aa993b JM |
3903 | break; |
3904 | default: | |
c5aa993b JM |
3905 | break; |
3906 | } | |
3907 | } | |
1c5cfe86 PA |
3908 | |
3909 | /* Get rid of the moribund locations. */ | |
1123588c | 3910 | for (bp_location *bl : moribund_locations) |
35df4500 | 3911 | decref_bp_location (&bl); |
1123588c | 3912 | moribund_locations.clear (); |
c906108c SS |
3913 | } |
3914 | ||
6c95b8df PA |
3915 | /* These functions concern about actual breakpoints inserted in the |
3916 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3917 | we need to hop over the bkpt --- so we check for address space | |
3918 | match, not program space. */ | |
3919 | ||
c2c6d25f JM |
3920 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3921 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3922 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3923 | permanent breakpoint. | |
3924 | - When continuing from a location with an ordinary breakpoint, we | |
3925 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3926 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3927 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3928 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3929 | |
c2c6d25f | 3930 | enum breakpoint_here |
accd0bcd | 3931 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 3932 | { |
35df4500 | 3933 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3934 | int any_breakpoint_here = 0; |
c906108c | 3935 | |
35df4500 | 3936 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3937 | { |
35df4500 TJB |
3938 | if (bl->loc_type != bp_loc_software_breakpoint |
3939 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3940 | continue; |
3941 | ||
f1310107 | 3942 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 3943 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 3944 | || bl->permanent) |
f1310107 | 3945 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3946 | { |
3947 | if (overlay_debugging | |
35df4500 TJB |
3948 | && section_is_overlay (bl->section) |
3949 | && !section_is_mapped (bl->section)) | |
075f6582 | 3950 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 3951 | else if (bl->permanent) |
075f6582 DJ |
3952 | return permanent_breakpoint_here; |
3953 | else | |
3954 | any_breakpoint_here = 1; | |
3955 | } | |
3956 | } | |
c906108c | 3957 | |
f486487f | 3958 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
3959 | } |
3960 | ||
d35ae833 PA |
3961 | /* See breakpoint.h. */ |
3962 | ||
3963 | int | |
accd0bcd | 3964 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
3965 | CORE_ADDR addr, ULONGEST len) |
3966 | { | |
3967 | struct bp_location *bl, **blp_tmp; | |
3968 | ||
3969 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3970 | { | |
3971 | if (bl->loc_type != bp_loc_software_breakpoint | |
3972 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
3973 | continue; | |
3974 | ||
3975 | if ((breakpoint_enabled (bl->owner) | |
3976 | || bl->permanent) | |
3977 | && breakpoint_location_address_range_overlap (bl, aspace, | |
3978 | addr, len)) | |
3979 | { | |
3980 | if (overlay_debugging | |
3981 | && section_is_overlay (bl->section) | |
3982 | && !section_is_mapped (bl->section)) | |
3983 | { | |
3984 | /* Unmapped overlay -- can't be a match. */ | |
3985 | continue; | |
3986 | } | |
3987 | ||
3988 | return 1; | |
3989 | } | |
3990 | } | |
3991 | ||
3992 | return 0; | |
3993 | } | |
3994 | ||
1c5cfe86 PA |
3995 | /* Return true if there's a moribund breakpoint at PC. */ |
3996 | ||
3997 | int | |
accd0bcd | 3998 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 | 3999 | { |
1123588c | 4000 | for (bp_location *loc : moribund_locations) |
f1310107 | 4001 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4002 | return 1; |
4003 | ||
4004 | return 0; | |
4005 | } | |
c2c6d25f | 4006 | |
f7ce857f PA |
4007 | /* Returns non-zero iff BL is inserted at PC, in address space |
4008 | ASPACE. */ | |
4009 | ||
4010 | static int | |
4011 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 4012 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
4013 | { |
4014 | if (bl->inserted | |
4015 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4016 | aspace, pc)) | |
4017 | { | |
4018 | if (overlay_debugging | |
4019 | && section_is_overlay (bl->section) | |
4020 | && !section_is_mapped (bl->section)) | |
4021 | return 0; /* unmapped overlay -- can't be a match */ | |
4022 | else | |
4023 | return 1; | |
4024 | } | |
4025 | return 0; | |
4026 | } | |
4027 | ||
a1fd2fa5 | 4028 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4029 | |
4030 | int | |
accd0bcd | 4031 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4032 | { |
f7ce857f | 4033 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4034 | |
f7ce857f | 4035 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4036 | { |
f7ce857f PA |
4037 | struct bp_location *bl = *blp; |
4038 | ||
35df4500 TJB |
4039 | if (bl->loc_type != bp_loc_software_breakpoint |
4040 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4041 | continue; |
4042 | ||
f7ce857f PA |
4043 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4044 | return 1; | |
c5aa993b | 4045 | } |
c36b740a VP |
4046 | return 0; |
4047 | } | |
4048 | ||
a1fd2fa5 PA |
4049 | /* This function returns non-zero iff there is a software breakpoint |
4050 | inserted at PC. */ | |
c36b740a VP |
4051 | |
4052 | int | |
accd0bcd | 4053 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4054 | CORE_ADDR pc) |
4fa8626c | 4055 | { |
f7ce857f | 4056 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4057 | |
f7ce857f | 4058 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4059 | { |
f7ce857f PA |
4060 | struct bp_location *bl = *blp; |
4061 | ||
35df4500 | 4062 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4063 | continue; |
4064 | ||
f7ce857f PA |
4065 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4066 | return 1; | |
4fa8626c DJ |
4067 | } |
4068 | ||
4069 | return 0; | |
9c02b525 PA |
4070 | } |
4071 | ||
4072 | /* See breakpoint.h. */ | |
4073 | ||
4074 | int | |
accd0bcd | 4075 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4076 | CORE_ADDR pc) |
4077 | { | |
4078 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4079 | |
4080 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4081 | { | |
4082 | struct bp_location *bl = *blp; | |
4083 | ||
4084 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4085 | continue; | |
4086 | ||
4087 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4088 | return 1; | |
4089 | } | |
4090 | ||
4091 | return 0; | |
4fa8626c DJ |
4092 | } |
4093 | ||
9093389c | 4094 | int |
accd0bcd | 4095 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4096 | CORE_ADDR addr, ULONGEST len) |
4097 | { | |
4098 | struct breakpoint *bpt; | |
4099 | ||
4100 | ALL_BREAKPOINTS (bpt) | |
4101 | { | |
4102 | struct bp_location *loc; | |
4103 | ||
4104 | if (bpt->type != bp_hardware_watchpoint | |
4105 | && bpt->type != bp_access_watchpoint) | |
4106 | continue; | |
4107 | ||
4108 | if (!breakpoint_enabled (bpt)) | |
4109 | continue; | |
4110 | ||
4111 | for (loc = bpt->loc; loc; loc = loc->next) | |
4112 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4113 | { | |
4114 | CORE_ADDR l, h; | |
4115 | ||
4116 | /* Check for intersection. */ | |
768adc05 PA |
4117 | l = std::max<CORE_ADDR> (loc->address, addr); |
4118 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4119 | if (l < h) |
4120 | return 1; | |
4121 | } | |
4122 | } | |
4123 | return 0; | |
4124 | } | |
c5aa993b | 4125 | |
f2478a7e | 4126 | /* See breakpoint.h. */ |
c906108c | 4127 | |
f2478a7e SM |
4128 | bool |
4129 | is_catchpoint (struct breakpoint *b) | |
c906108c | 4130 | { |
f2478a7e | 4131 | return (b->type == bp_catchpoint); |
c906108c SS |
4132 | } |
4133 | ||
f431efe5 PA |
4134 | /* Frees any storage that is part of a bpstat. Does not walk the |
4135 | 'next' chain. */ | |
4136 | ||
04afa70c | 4137 | bpstats::~bpstats () |
198757a8 | 4138 | { |
04afa70c TT |
4139 | if (bp_location_at != NULL) |
4140 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4141 | } |
4142 | ||
c906108c SS |
4143 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4144 | Also free any storage that is part of a bpstat. */ | |
4145 | ||
4146 | void | |
fba45db2 | 4147 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4148 | { |
4149 | bpstat p; | |
4150 | bpstat q; | |
4151 | ||
4152 | if (bsp == 0) | |
4153 | return; | |
4154 | p = *bsp; | |
4155 | while (p != NULL) | |
4156 | { | |
4157 | q = p->next; | |
04afa70c | 4158 | delete p; |
c906108c SS |
4159 | p = q; |
4160 | } | |
4161 | *bsp = NULL; | |
4162 | } | |
4163 | ||
04afa70c TT |
4164 | bpstats::bpstats (const bpstats &other) |
4165 | : next (NULL), | |
4166 | bp_location_at (other.bp_location_at), | |
4167 | breakpoint_at (other.breakpoint_at), | |
4168 | commands (other.commands), | |
04afa70c TT |
4169 | print (other.print), |
4170 | stop (other.stop), | |
4171 | print_it (other.print_it) | |
4172 | { | |
850645cf TT |
4173 | if (other.old_val != NULL) |
4174 | old_val = release_value (value_copy (other.old_val.get ())); | |
04afa70c | 4175 | incref_bp_location (bp_location_at); |
04afa70c TT |
4176 | } |
4177 | ||
c906108c SS |
4178 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4179 | is part of the bpstat is copied as well. */ | |
4180 | ||
4181 | bpstat | |
fba45db2 | 4182 | bpstat_copy (bpstat bs) |
c906108c SS |
4183 | { |
4184 | bpstat p = NULL; | |
4185 | bpstat tmp; | |
4186 | bpstat retval = NULL; | |
4187 | ||
4188 | if (bs == NULL) | |
4189 | return bs; | |
4190 | ||
4191 | for (; bs != NULL; bs = bs->next) | |
4192 | { | |
04afa70c | 4193 | tmp = new bpstats (*bs); |
31cc81e9 | 4194 | |
c906108c SS |
4195 | if (p == NULL) |
4196 | /* This is the first thing in the chain. */ | |
4197 | retval = tmp; | |
4198 | else | |
4199 | p->next = tmp; | |
4200 | p = tmp; | |
4201 | } | |
4202 | p->next = NULL; | |
4203 | return retval; | |
4204 | } | |
4205 | ||
4a64f543 | 4206 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4207 | |
4208 | bpstat | |
fba45db2 | 4209 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4210 | { |
c5aa993b JM |
4211 | if (bsp == NULL) |
4212 | return NULL; | |
c906108c | 4213 | |
c5aa993b JM |
4214 | for (; bsp != NULL; bsp = bsp->next) |
4215 | { | |
f431efe5 | 4216 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4217 | return bsp; |
4218 | } | |
c906108c SS |
4219 | return NULL; |
4220 | } | |
4221 | ||
ab04a2af TT |
4222 | /* See breakpoint.h. */ |
4223 | ||
4c462cb0 | 4224 | bool |
427cd150 | 4225 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4226 | { |
ab04a2af TT |
4227 | for (; bsp != NULL; bsp = bsp->next) |
4228 | { | |
427cd150 TT |
4229 | if (bsp->breakpoint_at == NULL) |
4230 | { | |
4231 | /* A moribund location can never explain a signal other than | |
4232 | GDB_SIGNAL_TRAP. */ | |
4233 | if (sig == GDB_SIGNAL_TRAP) | |
4c462cb0 | 4234 | return true; |
427cd150 TT |
4235 | } |
4236 | else | |
47591c29 PA |
4237 | { |
4238 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4239 | sig)) | |
4c462cb0 | 4240 | return true; |
47591c29 | 4241 | } |
ab04a2af TT |
4242 | } |
4243 | ||
4c462cb0 | 4244 | return false; |
ab04a2af TT |
4245 | } |
4246 | ||
4a64f543 MS |
4247 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4248 | stopped at. *BSP upon return is a bpstat which points to the | |
4249 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4250 | good for anything but further calls to bpstat_num). | |
4251 | ||
8671a17b PA |
4252 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4253 | Return -1 if stopped at a breakpoint that has been deleted since | |
4254 | we set it. | |
4255 | Return 1 otherwise. */ | |
c906108c SS |
4256 | |
4257 | int | |
8671a17b | 4258 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4259 | { |
4260 | struct breakpoint *b; | |
4261 | ||
4262 | if ((*bsp) == NULL) | |
4263 | return 0; /* No more breakpoint values */ | |
8671a17b | 4264 | |
4a64f543 MS |
4265 | /* We assume we'll never have several bpstats that correspond to a |
4266 | single breakpoint -- otherwise, this function might return the | |
4267 | same number more than once and this will look ugly. */ | |
f431efe5 | 4268 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4269 | *bsp = (*bsp)->next; |
4270 | if (b == NULL) | |
4271 | return -1; /* breakpoint that's been deleted since */ | |
4272 | ||
4273 | *num = b->number; /* We have its number */ | |
4274 | return 1; | |
c906108c SS |
4275 | } |
4276 | ||
e93ca019 | 4277 | /* See breakpoint.h. */ |
c906108c SS |
4278 | |
4279 | void | |
e93ca019 | 4280 | bpstat_clear_actions (void) |
c906108c | 4281 | { |
e93ca019 JK |
4282 | bpstat bs; |
4283 | ||
00431a78 | 4284 | if (inferior_ptid == null_ptid) |
e93ca019 JK |
4285 | return; |
4286 | ||
00431a78 | 4287 | thread_info *tp = inferior_thread (); |
e93ca019 | 4288 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
c906108c | 4289 | { |
d1b0a7bf | 4290 | bs->commands = NULL; |
850645cf | 4291 | bs->old_val.reset (nullptr); |
c906108c SS |
4292 | } |
4293 | } | |
4294 | ||
f3b1572e PA |
4295 | /* Called when a command is about to proceed the inferior. */ |
4296 | ||
4297 | static void | |
4298 | breakpoint_about_to_proceed (void) | |
4299 | { | |
d7e15655 | 4300 | if (inferior_ptid != null_ptid) |
f3b1572e PA |
4301 | { |
4302 | struct thread_info *tp = inferior_thread (); | |
4303 | ||
4304 | /* Allow inferior function calls in breakpoint commands to not | |
4305 | interrupt the command list. When the call finishes | |
4306 | successfully, the inferior will be standing at the same | |
4307 | breakpoint as if nothing happened. */ | |
16c381f0 | 4308 | if (tp->control.in_infcall) |
f3b1572e PA |
4309 | return; |
4310 | } | |
4311 | ||
4312 | breakpoint_proceeded = 1; | |
4313 | } | |
4314 | ||
abf85f46 JK |
4315 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4316 | or its equivalent. */ | |
4317 | ||
4318 | static int | |
4319 | command_line_is_silent (struct command_line *cmd) | |
4320 | { | |
4f45d445 | 4321 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4322 | } |
4323 | ||
4a64f543 MS |
4324 | /* Execute all the commands associated with all the breakpoints at |
4325 | this location. Any of these commands could cause the process to | |
4326 | proceed beyond this point, etc. We look out for such changes by | |
4327 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4328 | |
347bddb7 PA |
4329 | Returns true if a breakpoint command resumed the inferior. In that |
4330 | case, it is the caller's responsibility to recall it again with the | |
4331 | bpstat of the current thread. */ | |
4332 | ||
4333 | static int | |
4334 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4335 | { |
4336 | bpstat bs; | |
347bddb7 | 4337 | int again = 0; |
c906108c SS |
4338 | |
4339 | /* Avoid endless recursion if a `source' command is contained | |
4340 | in bs->commands. */ | |
4341 | if (executing_breakpoint_commands) | |
347bddb7 | 4342 | return 0; |
c906108c | 4343 | |
81b1e71c TT |
4344 | scoped_restore save_executing |
4345 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4346 | |
1ac32117 | 4347 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4348 | |
4a64f543 | 4349 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4350 | bs = *bsp; |
4351 | ||
4352 | breakpoint_proceeded = 0; | |
4353 | for (; bs != NULL; bs = bs->next) | |
4354 | { | |
d1b0a7bf | 4355 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4356 | |
4357 | /* Take ownership of the BSP's command tree, if it has one. | |
4358 | ||
4359 | The command tree could legitimately contain commands like | |
4360 | 'step' and 'next', which call clear_proceed_status, which | |
4361 | frees stop_bpstat's command tree. To make sure this doesn't | |
4362 | free the tree we're executing out from under us, we need to | |
4363 | take ownership of the tree ourselves. Since a given bpstat's | |
4364 | commands are only executed once, we don't need to copy it; we | |
4365 | can clear the pointer in the bpstat, and make sure we free | |
4366 | the tree when we're done. */ | |
d1b0a7bf | 4367 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4368 | bs->commands = NULL; |
d1b0a7bf TT |
4369 | if (ccmd != NULL) |
4370 | cmd = ccmd.get (); | |
abf85f46 JK |
4371 | if (command_line_is_silent (cmd)) |
4372 | { | |
4373 | /* The action has been already done by bpstat_stop_status. */ | |
4374 | cmd = cmd->next; | |
4375 | } | |
6c50ab1c | 4376 | |
c906108c SS |
4377 | while (cmd != NULL) |
4378 | { | |
4379 | execute_control_command (cmd); | |
4380 | ||
4381 | if (breakpoint_proceeded) | |
4382 | break; | |
4383 | else | |
4384 | cmd = cmd->next; | |
4385 | } | |
6c50ab1c | 4386 | |
c906108c | 4387 | if (breakpoint_proceeded) |
32c1e744 | 4388 | { |
cb814510 | 4389 | if (current_ui->async) |
347bddb7 PA |
4390 | /* If we are in async mode, then the target might be still |
4391 | running, not stopped at any breakpoint, so nothing for | |
4392 | us to do here -- just return to the event loop. */ | |
4393 | ; | |
32c1e744 VP |
4394 | else |
4395 | /* In sync mode, when execute_control_command returns | |
4396 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4397 | Breakpoint commands for that stop were not run, since |
4398 | execute_command does not run breakpoint commands -- | |
4399 | only command_line_handler does, but that one is not | |
4400 | involved in execution of breakpoint commands. So, we | |
4401 | can now execute breakpoint commands. It should be | |
4402 | noted that making execute_command do bpstat actions is | |
4403 | not an option -- in this case we'll have recursive | |
4404 | invocation of bpstat for each breakpoint with a | |
4405 | command, and can easily blow up GDB stack. Instead, we | |
4406 | return true, which will trigger the caller to recall us | |
4407 | with the new stop_bpstat. */ | |
4408 | again = 1; | |
4409 | break; | |
32c1e744 | 4410 | } |
c906108c | 4411 | } |
347bddb7 PA |
4412 | return again; |
4413 | } | |
4414 | ||
00431a78 PA |
4415 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
4416 | one, is alive and has execution. Return NULL otherwise. */ | |
4417 | ||
4418 | static thread_info * | |
4419 | get_bpstat_thread () | |
4420 | { | |
4421 | if (inferior_ptid == null_ptid || !target_has_execution) | |
4422 | return NULL; | |
4423 | ||
4424 | thread_info *tp = inferior_thread (); | |
4425 | if (tp->state == THREAD_EXITED || tp->executing) | |
4426 | return NULL; | |
4427 | return tp; | |
4428 | } | |
4429 | ||
347bddb7 PA |
4430 | void |
4431 | bpstat_do_actions (void) | |
4432 | { | |
694c6bf5 | 4433 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
00431a78 | 4434 | thread_info *tp; |
353d1d73 | 4435 | |
347bddb7 | 4436 | /* Do any commands attached to breakpoint we are stopped at. */ |
00431a78 PA |
4437 | while ((tp = get_bpstat_thread ()) != NULL) |
4438 | { | |
4439 | /* Since in sync mode, bpstat_do_actions may resume the | |
4440 | inferior, and only return when it is stopped at the next | |
4441 | breakpoint, we keep doing breakpoint actions until it returns | |
4442 | false to indicate the inferior was not resumed. */ | |
4443 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) | |
4444 | break; | |
4445 | } | |
353d1d73 | 4446 | |
694c6bf5 | 4447 | cleanup_if_error.release (); |
c906108c SS |
4448 | } |
4449 | ||
fa4727a6 DJ |
4450 | /* Print out the (old or new) value associated with a watchpoint. */ |
4451 | ||
4452 | static void | |
4453 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4454 | { | |
4455 | if (val == NULL) | |
7f6aba03 | 4456 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
fa4727a6 | 4457 | else |
79a45b7d TT |
4458 | { |
4459 | struct value_print_options opts; | |
4460 | get_user_print_options (&opts); | |
4461 | value_print (val, stream, &opts); | |
4462 | } | |
fa4727a6 DJ |
4463 | } |
4464 | ||
f303dbd6 PA |
4465 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4466 | debugging multiple threads. */ | |
4467 | ||
4468 | void | |
4469 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4470 | { | |
112e8700 | 4471 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4472 | return; |
4473 | ||
112e8700 | 4474 | uiout->text ("\n"); |
f303dbd6 PA |
4475 | |
4476 | if (show_thread_that_caused_stop ()) | |
4477 | { | |
4478 | const char *name; | |
4479 | struct thread_info *thr = inferior_thread (); | |
4480 | ||
112e8700 | 4481 | uiout->text ("Thread "); |
33eca680 | 4482 | uiout->field_string ("thread-id", print_thread_id (thr)); |
f303dbd6 PA |
4483 | |
4484 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4485 | if (name != NULL) | |
4486 | { | |
112e8700 | 4487 | uiout->text (" \""); |
33eca680 | 4488 | uiout->field_string ("name", name); |
112e8700 | 4489 | uiout->text ("\""); |
f303dbd6 PA |
4490 | } |
4491 | ||
112e8700 | 4492 | uiout->text (" hit "); |
f303dbd6 PA |
4493 | } |
4494 | } | |
4495 | ||
e514a9d6 | 4496 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4497 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4498 | 'print_it' in the bpstat structure. Under some circumstances we |
4499 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4500 | normal_stop(). */ |
e514a9d6 JM |
4501 | |
4502 | static enum print_stop_action | |
4503 | print_bp_stop_message (bpstat bs) | |
4504 | { | |
4505 | switch (bs->print_it) | |
4506 | { | |
4507 | case print_it_noop: | |
4a64f543 | 4508 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4509 | return PRINT_UNKNOWN; |
4510 | break; | |
4511 | ||
4512 | case print_it_done: | |
4513 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4514 | relevant messages. */ |
e514a9d6 JM |
4515 | return PRINT_SRC_AND_LOC; |
4516 | break; | |
4517 | ||
4518 | case print_it_normal: | |
4f8d1dc6 | 4519 | { |
f431efe5 PA |
4520 | struct breakpoint *b = bs->breakpoint_at; |
4521 | ||
1a6a67de TJB |
4522 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4523 | which has since been deleted. */ | |
4524 | if (b == NULL) | |
4525 | return PRINT_UNKNOWN; | |
4526 | ||
348d480f PA |
4527 | /* Normal case. Call the breakpoint's print_it method. */ |
4528 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4529 | } |
348d480f | 4530 | break; |
3086aeae | 4531 | |
e514a9d6 | 4532 | default: |
8e65ff28 | 4533 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4534 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4535 | break; |
c906108c | 4536 | } |
c906108c SS |
4537 | } |
4538 | ||
edcc5120 TT |
4539 | /* A helper function that prints a shared library stopped event. */ |
4540 | ||
4541 | static void | |
4542 | print_solib_event (int is_catchpoint) | |
4543 | { | |
6fb16ce6 | 4544 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
bcb430e4 | 4545 | bool any_added = !current_program_space->added_solibs.empty (); |
edcc5120 TT |
4546 | |
4547 | if (!is_catchpoint) | |
4548 | { | |
4549 | if (any_added || any_deleted) | |
112e8700 | 4550 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4551 | else |
112e8700 SM |
4552 | current_uiout->text (_("Stopped due to shared library event (no " |
4553 | "libraries added or removed)\n")); | |
edcc5120 TT |
4554 | } |
4555 | ||
112e8700 SM |
4556 | if (current_uiout->is_mi_like_p ()) |
4557 | current_uiout->field_string ("reason", | |
4558 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4559 | |
4560 | if (any_deleted) | |
4561 | { | |
112e8700 | 4562 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4563 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
6fb16ce6 | 4564 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
edcc5120 | 4565 | { |
6fb16ce6 SM |
4566 | const std::string &name = current_program_space->deleted_solibs[ix]; |
4567 | ||
edcc5120 | 4568 | if (ix > 0) |
112e8700 SM |
4569 | current_uiout->text (" "); |
4570 | current_uiout->field_string ("library", name); | |
4571 | current_uiout->text ("\n"); | |
edcc5120 | 4572 | } |
edcc5120 TT |
4573 | } |
4574 | ||
4575 | if (any_added) | |
4576 | { | |
112e8700 | 4577 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4578 | ui_out_emit_list list_emitter (current_uiout, "added"); |
bcb430e4 | 4579 | bool first = true; |
52941706 | 4580 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 | 4581 | { |
bcb430e4 | 4582 | if (!first) |
112e8700 | 4583 | current_uiout->text (" "); |
bcb430e4 | 4584 | first = false; |
112e8700 SM |
4585 | current_uiout->field_string ("library", iter->so_name); |
4586 | current_uiout->text ("\n"); | |
edcc5120 | 4587 | } |
edcc5120 TT |
4588 | } |
4589 | } | |
4590 | ||
e514a9d6 JM |
4591 | /* Print a message indicating what happened. This is called from |
4592 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4593 | list - a list of the eventpoints that caused this stop. KIND is |
4594 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4595 | routine calls the generic print routine for printing a message |
4596 | about reasons for stopping. This will print (for example) the | |
4597 | "Breakpoint n," part of the output. The return value of this | |
4598 | routine is one of: | |
c906108c | 4599 | |
4a64f543 | 4600 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4601 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4602 | code to print the location. An example is |
c5aa993b JM |
4603 | "Breakpoint 1, " which should be followed by |
4604 | the location. | |
917317f4 | 4605 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4606 | to also print the location part of the message. |
4607 | An example is the catch/throw messages, which | |
4a64f543 | 4608 | don't require a location appended to the end. |
917317f4 | 4609 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4610 | further info to be printed. */ |
c906108c | 4611 | |
917317f4 | 4612 | enum print_stop_action |
36dfb11c | 4613 | bpstat_print (bpstat bs, int kind) |
c906108c | 4614 | { |
f486487f | 4615 | enum print_stop_action val; |
c5aa993b | 4616 | |
c906108c | 4617 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4618 | (Currently all watchpoints go on the bpstat whether hit or not. |
4619 | That probably could (should) be changed, provided care is taken | |
c906108c | 4620 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4621 | for (; bs; bs = bs->next) |
4622 | { | |
4623 | val = print_bp_stop_message (bs); | |
4624 | if (val == PRINT_SRC_ONLY | |
4625 | || val == PRINT_SRC_AND_LOC | |
4626 | || val == PRINT_NOTHING) | |
4627 | return val; | |
4628 | } | |
c906108c | 4629 | |
36dfb11c TT |
4630 | /* If we had hit a shared library event breakpoint, |
4631 | print_bp_stop_message would print out this message. If we hit an | |
4632 | OS-level shared library event, do the same thing. */ | |
4633 | if (kind == TARGET_WAITKIND_LOADED) | |
4634 | { | |
edcc5120 | 4635 | print_solib_event (0); |
36dfb11c TT |
4636 | return PRINT_NOTHING; |
4637 | } | |
4638 | ||
e514a9d6 | 4639 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4640 | with and nothing was printed. */ |
917317f4 | 4641 | return PRINT_UNKNOWN; |
c906108c SS |
4642 | } |
4643 | ||
bf469271 | 4644 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4645 | |
bf469271 PA |
4646 | static bool |
4647 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4648 | { |
278cd55f | 4649 | struct value *mark = value_mark (); |
bf469271 | 4650 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4651 | |
c906108c | 4652 | value_free_to_mark (mark); |
bf469271 | 4653 | return res; |
c906108c SS |
4654 | } |
4655 | ||
5760d0ab | 4656 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4657 | |
04afa70c TT |
4658 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4659 | : next (NULL), | |
4660 | bp_location_at (bl), | |
4661 | breakpoint_at (bl->owner), | |
4662 | commands (NULL), | |
04afa70c TT |
4663 | print (0), |
4664 | stop (0), | |
4665 | print_it (print_it_normal) | |
c906108c | 4666 | { |
f431efe5 | 4667 | incref_bp_location (bl); |
04afa70c TT |
4668 | **bs_link_pointer = this; |
4669 | *bs_link_pointer = &next; | |
4670 | } | |
4671 | ||
4672 | bpstats::bpstats () | |
4673 | : next (NULL), | |
4674 | bp_location_at (NULL), | |
4675 | breakpoint_at (NULL), | |
4676 | commands (NULL), | |
04afa70c TT |
4677 | print (0), |
4678 | stop (0), | |
4679 | print_it (print_it_normal) | |
4680 | { | |
c906108c SS |
4681 | } |
4682 | \f | |
d983da9c DJ |
4683 | /* The target has stopped with waitstatus WS. Check if any hardware |
4684 | watchpoints have triggered, according to the target. */ | |
4685 | ||
4686 | int | |
4687 | watchpoints_triggered (struct target_waitstatus *ws) | |
4688 | { | |
57810aa7 | 4689 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4690 | CORE_ADDR addr; |
4691 | struct breakpoint *b; | |
4692 | ||
4693 | if (!stopped_by_watchpoint) | |
4694 | { | |
4695 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4696 | as not triggered. */ | |
4697 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4698 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4699 | { |
4700 | struct watchpoint *w = (struct watchpoint *) b; | |
4701 | ||
4702 | w->watchpoint_triggered = watch_triggered_no; | |
4703 | } | |
d983da9c DJ |
4704 | |
4705 | return 0; | |
4706 | } | |
4707 | ||
8b88a78e | 4708 | if (!target_stopped_data_address (current_top_target (), &addr)) |
d983da9c DJ |
4709 | { |
4710 | /* We were stopped by a watchpoint, but we don't know where. | |
4711 | Mark all watchpoints as unknown. */ | |
4712 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4713 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4714 | { |
4715 | struct watchpoint *w = (struct watchpoint *) b; | |
4716 | ||
4717 | w->watchpoint_triggered = watch_triggered_unknown; | |
4718 | } | |
d983da9c | 4719 | |
3c4797ba | 4720 | return 1; |
d983da9c DJ |
4721 | } |
4722 | ||
4723 | /* The target could report the data address. Mark watchpoints | |
4724 | affected by this data address as triggered, and all others as not | |
4725 | triggered. */ | |
4726 | ||
4727 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4728 | if (is_hardware_watchpoint (b)) |
d983da9c | 4729 | { |
3a5c3e22 | 4730 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4731 | struct bp_location *loc; |
d983da9c | 4732 | |
3a5c3e22 | 4733 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4734 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4735 | { |
3a5c3e22 | 4736 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4737 | { |
3a5c3e22 PA |
4738 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4739 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4740 | |
4741 | if (newaddr == start) | |
4742 | { | |
3a5c3e22 | 4743 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4744 | break; |
4745 | } | |
4746 | } | |
4747 | /* Exact match not required. Within range is sufficient. */ | |
8b88a78e | 4748 | else if (target_watchpoint_addr_within_range (current_top_target (), |
9c06b0b4 TJB |
4749 | addr, loc->address, |
4750 | loc->length)) | |
4751 | { | |
3a5c3e22 | 4752 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4753 | break; |
4754 | } | |
4755 | } | |
d983da9c DJ |
4756 | } |
4757 | ||
4758 | return 1; | |
4759 | } | |
4760 | ||
bf469271 PA |
4761 | /* Possible return values for watchpoint_check. */ |
4762 | enum wp_check_result | |
4763 | { | |
4764 | /* The watchpoint has been deleted. */ | |
4765 | WP_DELETED = 1, | |
4766 | ||
4767 | /* The value has changed. */ | |
4768 | WP_VALUE_CHANGED = 2, | |
4769 | ||
4770 | /* The value has not changed. */ | |
4771 | WP_VALUE_NOT_CHANGED = 3, | |
4772 | ||
4773 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4774 | WP_IGNORE = 4, | |
4775 | }; | |
c906108c SS |
4776 | |
4777 | #define BP_TEMPFLAG 1 | |
4778 | #define BP_HARDWAREFLAG 2 | |
4779 | ||
4a64f543 | 4780 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4781 | changed. */ |
553e4c11 | 4782 | |
bf469271 PA |
4783 | static wp_check_result |
4784 | watchpoint_check (bpstat bs) | |
c906108c | 4785 | { |
3a5c3e22 | 4786 | struct watchpoint *b; |
c906108c SS |
4787 | struct frame_info *fr; |
4788 | int within_current_scope; | |
4789 | ||
f431efe5 | 4790 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4791 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4792 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4793 | |
f6bc2008 PA |
4794 | /* If this is a local watchpoint, we only want to check if the |
4795 | watchpoint frame is in scope if the current thread is the thread | |
4796 | that was used to create the watchpoint. */ | |
4797 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4798 | return WP_IGNORE; |
f6bc2008 | 4799 | |
c906108c SS |
4800 | if (b->exp_valid_block == NULL) |
4801 | within_current_scope = 1; | |
4802 | else | |
4803 | { | |
edb3359d DJ |
4804 | struct frame_info *frame = get_current_frame (); |
4805 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4806 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4807 | ||
c9cf6e20 | 4808 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4809 | still in the function but the stack frame has already been |
4810 | invalidated. Since we can't rely on the values of local | |
4811 | variables after the stack has been destroyed, we are treating | |
4812 | the watchpoint in that state as `not changed' without further | |
4813 | checking. Don't mark watchpoints as changed if the current | |
4814 | frame is in an epilogue - even if they are in some other | |
4815 | frame, our view of the stack is likely to be wrong and | |
4816 | frame_find_by_id could error out. */ | |
c9cf6e20 | 4817 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 4818 | return WP_IGNORE; |
a0f49112 | 4819 | |
101dcfbe | 4820 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4821 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4822 | |
4823 | /* If we've gotten confused in the unwinder, we might have | |
4824 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4825 | if (within_current_scope) |
4826 | { | |
4827 | struct symbol *function; | |
4828 | ||
4829 | function = get_frame_function (fr); | |
4830 | if (function == NULL | |
4831 | || !contained_in (b->exp_valid_block, | |
4832 | SYMBOL_BLOCK_VALUE (function))) | |
4833 | within_current_scope = 0; | |
4834 | } | |
69fbadd5 | 4835 | |
edb3359d | 4836 | if (within_current_scope) |
c906108c SS |
4837 | /* If we end up stopping, the current frame will get selected |
4838 | in normal_stop. So this call to select_frame won't affect | |
4839 | the user. */ | |
0f7d239c | 4840 | select_frame (fr); |
c906108c | 4841 | } |
c5aa993b | 4842 | |
c906108c SS |
4843 | if (within_current_scope) |
4844 | { | |
4a64f543 MS |
4845 | /* We use value_{,free_to_}mark because it could be a *long* |
4846 | time before we return to the command level and call | |
4847 | free_all_values. We can't call free_all_values because we | |
4848 | might be in the middle of evaluating a function call. */ | |
c906108c | 4849 | |
0cf6dd15 | 4850 | int pc = 0; |
9c06b0b4 | 4851 | struct value *mark; |
fa4727a6 DJ |
4852 | struct value *new_val; |
4853 | ||
c1fc2657 | 4854 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
4855 | /* Since we don't know the exact trigger address (from |
4856 | stopped_data_address), just tell the user we've triggered | |
4857 | a mask watchpoint. */ | |
4858 | return WP_VALUE_CHANGED; | |
4859 | ||
4860 | mark = value_mark (); | |
4d01a485 | 4861 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4862 | |
bb9d5f81 PP |
4863 | if (b->val_bitsize != 0) |
4864 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
4865 | ||
4a64f543 MS |
4866 | /* We use value_equal_contents instead of value_equal because |
4867 | the latter coerces an array to a pointer, thus comparing just | |
4868 | the address of the array instead of its contents. This is | |
4869 | not what we want. */ | |
fa4727a6 | 4870 | if ((b->val != NULL) != (new_val != NULL) |
850645cf TT |
4871 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
4872 | new_val))) | |
c906108c | 4873 | { |
c906108c | 4874 | bs->old_val = b->val; |
850645cf | 4875 | b->val = release_value (new_val); |
4c1d86d9 | 4876 | b->val_valid = true; |
850645cf TT |
4877 | if (new_val != NULL) |
4878 | value_free_to_mark (mark); | |
c906108c SS |
4879 | return WP_VALUE_CHANGED; |
4880 | } | |
4881 | else | |
4882 | { | |
60e1c644 | 4883 | /* Nothing changed. */ |
c906108c | 4884 | value_free_to_mark (mark); |
c906108c SS |
4885 | return WP_VALUE_NOT_CHANGED; |
4886 | } | |
4887 | } | |
4888 | else | |
4889 | { | |
4890 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
4891 | if we temporarily ignored the watchpoint, then when |
4892 | we reenter the block in which it is valid it contains | |
4893 | garbage (in the case of a function, it may have two | |
4894 | garbage values, one before and one after the prologue). | |
4895 | So we can't even detect the first assignment to it and | |
4896 | watch after that (since the garbage may or may not equal | |
4897 | the first value assigned). */ | |
348d480f PA |
4898 | /* We print all the stop information in |
4899 | breakpoint_ops->print_it, but in this case, by the time we | |
4900 | call breakpoint_ops->print_it this bp will be deleted | |
4901 | already. So we have no choice but print the information | |
4902 | here. */ | |
468afe6c | 4903 | |
0e454242 | 4904 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
4905 | { |
4906 | struct ui_out *uiout = current_uiout; | |
4907 | ||
112e8700 SM |
4908 | if (uiout->is_mi_like_p ()) |
4909 | uiout->field_string | |
4910 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
6a831f06 PA |
4911 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
4912 | "left the block in\n" | |
4913 | "which its expression is valid.\n", | |
4914 | signed_field ("wpnum", b->number)); | |
468afe6c | 4915 | } |
4ce44c66 | 4916 | |
cdac0397 | 4917 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 4918 | b->commands = NULL; |
d0fb5eae | 4919 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4920 | |
4921 | return WP_DELETED; | |
4922 | } | |
4923 | } | |
4924 | ||
18a18393 | 4925 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4926 | breakpoint location BL. This function does not check if we should |
4927 | stop, only if BL explains the stop. */ | |
4928 | ||
18a18393 | 4929 | static int |
6c95b8df | 4930 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 4931 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 4932 | const struct target_waitstatus *ws) |
18a18393 VP |
4933 | { |
4934 | struct breakpoint *b = bl->owner; | |
4935 | ||
348d480f | 4936 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4937 | gdb_assert (b != NULL); |
4938 | ||
bd522513 | 4939 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4940 | } |
4941 | ||
3a5c3e22 PA |
4942 | /* Determine if the watched values have actually changed, and we |
4943 | should stop. If not, set BS->stop to 0. */ | |
4944 | ||
18a18393 VP |
4945 | static void |
4946 | bpstat_check_watchpoint (bpstat bs) | |
4947 | { | |
2bdf28a0 | 4948 | const struct bp_location *bl; |
3a5c3e22 | 4949 | struct watchpoint *b; |
2bdf28a0 JK |
4950 | |
4951 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4952 | bl = bs->bp_location_at; |
2bdf28a0 | 4953 | gdb_assert (bl != NULL); |
3a5c3e22 | 4954 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4955 | gdb_assert (b != NULL); |
18a18393 | 4956 | |
18a18393 | 4957 | { |
18a18393 VP |
4958 | int must_check_value = 0; |
4959 | ||
c1fc2657 | 4960 | if (b->type == bp_watchpoint) |
18a18393 VP |
4961 | /* For a software watchpoint, we must always check the |
4962 | watched value. */ | |
4963 | must_check_value = 1; | |
4964 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4965 | /* We have a hardware watchpoint (read, write, or access) | |
4966 | and the target earlier reported an address watched by | |
4967 | this watchpoint. */ | |
4968 | must_check_value = 1; | |
4969 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 4970 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
4971 | /* We were stopped by a hardware watchpoint, but the target could |
4972 | not report the data address. We must check the watchpoint's | |
4973 | value. Access and read watchpoints are out of luck; without | |
4974 | a data address, we can't figure it out. */ | |
4975 | must_check_value = 1; | |
3a5c3e22 | 4976 | |
18a18393 VP |
4977 | if (must_check_value) |
4978 | { | |
bf469271 PA |
4979 | wp_check_result e; |
4980 | ||
a70b8144 | 4981 | try |
bf469271 PA |
4982 | { |
4983 | e = watchpoint_check (bs); | |
4984 | } | |
230d2906 | 4985 | catch (const gdb_exception &ex) |
bf469271 PA |
4986 | { |
4987 | exception_fprintf (gdb_stderr, ex, | |
4988 | "Error evaluating expression " | |
4989 | "for watchpoint %d\n", | |
4990 | b->number); | |
4991 | ||
4992 | SWITCH_THRU_ALL_UIS () | |
4993 | { | |
4994 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
4995 | b->number); | |
4996 | } | |
4997 | watchpoint_del_at_next_stop (b); | |
4998 | e = WP_DELETED; | |
4999 | } | |
bf469271 | 5000 | |
18a18393 VP |
5001 | switch (e) |
5002 | { | |
5003 | case WP_DELETED: | |
5004 | /* We've already printed what needs to be printed. */ | |
5005 | bs->print_it = print_it_done; | |
5006 | /* Stop. */ | |
5007 | break; | |
60e1c644 PA |
5008 | case WP_IGNORE: |
5009 | bs->print_it = print_it_noop; | |
5010 | bs->stop = 0; | |
5011 | break; | |
18a18393 | 5012 | case WP_VALUE_CHANGED: |
c1fc2657 | 5013 | if (b->type == bp_read_watchpoint) |
18a18393 | 5014 | { |
85d721b8 PA |
5015 | /* There are two cases to consider here: |
5016 | ||
4a64f543 | 5017 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5018 | In that case, trust the target, and always report |
5019 | the watchpoint hit to the user. Even though | |
5020 | reads don't cause value changes, the value may | |
5021 | have changed since the last time it was read, and | |
5022 | since we're not trapping writes, we will not see | |
5023 | those, and as such we should ignore our notion of | |
5024 | old value. | |
5025 | ||
4a64f543 | 5026 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5027 | reads and writes. There are two ways this may |
5028 | happen: | |
5029 | ||
4a64f543 | 5030 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5031 | reads only, but can break on accesses (reads or |
5032 | writes), such as e.g., x86. We detect this case | |
5033 | at the time we try to insert read watchpoints. | |
5034 | ||
4a64f543 | 5035 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5036 | watchpoints, but, the user set an access or write |
5037 | watchpoint watching the same memory as this read | |
5038 | watchpoint. | |
5039 | ||
5040 | If we're watching memory writes as well as reads, | |
5041 | ignore watchpoint hits when we find that the | |
5042 | value hasn't changed, as reads don't cause | |
5043 | changes. This still gives false positives when | |
5044 | the program writes the same value to memory as | |
5045 | what there was already in memory (we will confuse | |
5046 | it for a read), but it's much better than | |
5047 | nothing. */ | |
5048 | ||
5049 | int other_write_watchpoint = 0; | |
5050 | ||
5051 | if (bl->watchpoint_type == hw_read) | |
5052 | { | |
5053 | struct breakpoint *other_b; | |
5054 | ||
5055 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5056 | if (other_b->type == bp_hardware_watchpoint |
5057 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5058 | { |
3a5c3e22 PA |
5059 | struct watchpoint *other_w = |
5060 | (struct watchpoint *) other_b; | |
5061 | ||
5062 | if (other_w->watchpoint_triggered | |
5063 | == watch_triggered_yes) | |
5064 | { | |
5065 | other_write_watchpoint = 1; | |
5066 | break; | |
5067 | } | |
85d721b8 PA |
5068 | } |
5069 | } | |
5070 | ||
5071 | if (other_write_watchpoint | |
5072 | || bl->watchpoint_type == hw_access) | |
5073 | { | |
5074 | /* We're watching the same memory for writes, | |
5075 | and the value changed since the last time we | |
5076 | updated it, so this trap must be for a write. | |
5077 | Ignore it. */ | |
5078 | bs->print_it = print_it_noop; | |
5079 | bs->stop = 0; | |
5080 | } | |
18a18393 VP |
5081 | } |
5082 | break; | |
5083 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5084 | if (b->type == bp_hardware_watchpoint |
5085 | || b->type == bp_watchpoint) | |
18a18393 VP |
5086 | { |
5087 | /* Don't stop: write watchpoints shouldn't fire if | |
5088 | the value hasn't changed. */ | |
5089 | bs->print_it = print_it_noop; | |
5090 | bs->stop = 0; | |
5091 | } | |
5092 | /* Stop. */ | |
5093 | break; | |
5094 | default: | |
5095 | /* Can't happen. */ | |
18a18393 VP |
5096 | break; |
5097 | } | |
5098 | } | |
5099 | else /* must_check_value == 0 */ | |
5100 | { | |
5101 | /* This is a case where some watchpoint(s) triggered, but | |
5102 | not at the address of this watchpoint, or else no | |
5103 | watchpoint triggered after all. So don't print | |
5104 | anything for this watchpoint. */ | |
5105 | bs->print_it = print_it_noop; | |
5106 | bs->stop = 0; | |
5107 | } | |
5108 | } | |
5109 | } | |
5110 | ||
7d4df6a4 DE |
5111 | /* For breakpoints that are currently marked as telling gdb to stop, |
5112 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5113 | of breakpoint referred to by BS. If we should not stop for this |
5114 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5115 | |
18a18393 | 5116 | static void |
00431a78 | 5117 | bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread) |
18a18393 | 5118 | { |
2bdf28a0 JK |
5119 | const struct bp_location *bl; |
5120 | struct breakpoint *b; | |
bf469271 PA |
5121 | /* Assume stop. */ |
5122 | bool condition_result = true; | |
7d4df6a4 DE |
5123 | struct expression *cond; |
5124 | ||
5125 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5126 | |
5127 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5128 | bl = bs->bp_location_at; |
2bdf28a0 | 5129 | gdb_assert (bl != NULL); |
f431efe5 | 5130 | b = bs->breakpoint_at; |
2bdf28a0 | 5131 | gdb_assert (b != NULL); |
18a18393 | 5132 | |
b775012e LM |
5133 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5134 | need to do so again since GDB does not know if we stopped due to a | |
5135 | breakpoint or a single step breakpoint. */ | |
5136 | ||
18a18393 | 5137 | if (frame_id_p (b->frame_id) |
edb3359d | 5138 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5139 | { |
7d4df6a4 DE |
5140 | bs->stop = 0; |
5141 | return; | |
5142 | } | |
60e1c644 | 5143 | |
12ab52e9 PA |
5144 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5145 | evaluating the condition if this isn't the specified | |
5146 | thread/task. */ | |
00431a78 PA |
5147 | if ((b->thread != -1 && b->thread != thread->global_num) |
5148 | || (b->task != 0 && b->task != ada_get_task_number (thread))) | |
6c1b0f7b DE |
5149 | { |
5150 | bs->stop = 0; | |
5151 | return; | |
5152 | } | |
5153 | ||
6dddc817 DE |
5154 | /* Evaluate extension language breakpoints that have a "stop" method |
5155 | implemented. */ | |
5156 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5157 | |
7d4df6a4 DE |
5158 | if (is_watchpoint (b)) |
5159 | { | |
5160 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5161 | |
4d01a485 | 5162 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5163 | } |
5164 | else | |
4d01a485 | 5165 | cond = bl->cond.get (); |
60e1c644 | 5166 | |
7d4df6a4 DE |
5167 | if (cond && b->disposition != disp_del_at_next_stop) |
5168 | { | |
5169 | int within_current_scope = 1; | |
5170 | struct watchpoint * w; | |
60e1c644 | 5171 | |
7d4df6a4 DE |
5172 | /* We use value_mark and value_free_to_mark because it could |
5173 | be a long time before we return to the command level and | |
5174 | call free_all_values. We can't call free_all_values | |
5175 | because we might be in the middle of evaluating a | |
5176 | function call. */ | |
5177 | struct value *mark = value_mark (); | |
5178 | ||
5179 | if (is_watchpoint (b)) | |
5180 | w = (struct watchpoint *) b; | |
5181 | else | |
5182 | w = NULL; | |
5183 | ||
5184 | /* Need to select the frame, with all that implies so that | |
5185 | the conditions will have the right context. Because we | |
5186 | use the frame, we will not see an inlined function's | |
5187 | variables when we arrive at a breakpoint at the start | |
5188 | of the inlined function; the current frame will be the | |
5189 | call site. */ | |
5190 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5191 | select_frame (get_current_frame ()); | |
5192 | else | |
18a18393 | 5193 | { |
7d4df6a4 DE |
5194 | struct frame_info *frame; |
5195 | ||
5196 | /* For local watchpoint expressions, which particular | |
5197 | instance of a local is being watched matters, so we | |
5198 | keep track of the frame to evaluate the expression | |
5199 | in. To evaluate the condition however, it doesn't | |
5200 | really matter which instantiation of the function | |
5201 | where the condition makes sense triggers the | |
5202 | watchpoint. This allows an expression like "watch | |
5203 | global if q > 10" set in `func', catch writes to | |
5204 | global on all threads that call `func', or catch | |
5205 | writes on all recursive calls of `func' by a single | |
5206 | thread. We simply always evaluate the condition in | |
5207 | the innermost frame that's executing where it makes | |
5208 | sense to evaluate the condition. It seems | |
5209 | intuitive. */ | |
5210 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5211 | if (frame != NULL) | |
5212 | select_frame (frame); | |
5213 | else | |
5214 | within_current_scope = 0; | |
18a18393 | 5215 | } |
7d4df6a4 | 5216 | if (within_current_scope) |
bf469271 | 5217 | { |
a70b8144 | 5218 | try |
bf469271 PA |
5219 | { |
5220 | condition_result = breakpoint_cond_eval (cond); | |
5221 | } | |
230d2906 | 5222 | catch (const gdb_exception &ex) |
bf469271 PA |
5223 | { |
5224 | exception_fprintf (gdb_stderr, ex, | |
5225 | "Error in testing breakpoint condition:\n"); | |
5226 | } | |
bf469271 | 5227 | } |
7d4df6a4 | 5228 | else |
18a18393 | 5229 | { |
7d4df6a4 DE |
5230 | warning (_("Watchpoint condition cannot be tested " |
5231 | "in the current scope")); | |
5232 | /* If we failed to set the right context for this | |
5233 | watchpoint, unconditionally report it. */ | |
18a18393 | 5234 | } |
7d4df6a4 DE |
5235 | /* FIXME-someday, should give breakpoint #. */ |
5236 | value_free_to_mark (mark); | |
18a18393 | 5237 | } |
7d4df6a4 | 5238 | |
bf469271 | 5239 | if (cond && !condition_result) |
7d4df6a4 DE |
5240 | { |
5241 | bs->stop = 0; | |
5242 | } | |
7d4df6a4 DE |
5243 | else if (b->ignore_count > 0) |
5244 | { | |
5245 | b->ignore_count--; | |
5246 | bs->stop = 0; | |
5247 | /* Increase the hit count even though we don't stop. */ | |
5248 | ++(b->hit_count); | |
76727919 | 5249 | gdb::observers::breakpoint_modified.notify (b); |
7d4df6a4 | 5250 | } |
18a18393 VP |
5251 | } |
5252 | ||
1cf4d951 PA |
5253 | /* Returns true if we need to track moribund locations of LOC's type |
5254 | on the current target. */ | |
5255 | ||
5256 | static int | |
5257 | need_moribund_for_location_type (struct bp_location *loc) | |
5258 | { | |
5259 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5260 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5261 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5262 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5263 | } | |
5264 | ||
ddfe970e | 5265 | /* See breakpoint.h. */ |
c906108c SS |
5266 | |
5267 | bpstat | |
ddfe970e | 5268 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5269 | const struct target_waitstatus *ws) |
c906108c | 5270 | { |
ddfe970e | 5271 | struct breakpoint *b; |
5760d0ab | 5272 | bpstat bs_head = NULL, *bs_link = &bs_head; |
c5aa993b | 5273 | |
429374b8 JK |
5274 | ALL_BREAKPOINTS (b) |
5275 | { | |
1a853c52 | 5276 | if (!breakpoint_enabled (b)) |
429374b8 | 5277 | continue; |
a5606eee | 5278 | |
ddfe970e | 5279 | for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) |
429374b8 | 5280 | { |
4a64f543 MS |
5281 | /* For hardware watchpoints, we look only at the first |
5282 | location. The watchpoint_check function will work on the | |
5283 | entire expression, not the individual locations. For | |
5284 | read watchpoints, the watchpoints_triggered function has | |
5285 | checked all locations already. */ | |
429374b8 JK |
5286 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5287 | break; | |
18a18393 | 5288 | |
f6592439 | 5289 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5290 | continue; |
c5aa993b | 5291 | |
09ac7c10 | 5292 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5293 | continue; |
c5aa993b | 5294 | |
4a64f543 MS |
5295 | /* Come here if it's a watchpoint, or if the break address |
5296 | matches. */ | |
c5aa993b | 5297 | |
ddfe970e KS |
5298 | bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
5299 | explain stop. */ | |
c5aa993b | 5300 | |
f431efe5 PA |
5301 | /* Assume we stop. Should we find a watchpoint that is not |
5302 | actually triggered, or if the condition of the breakpoint | |
5303 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5304 | bs->stop = 1; |
5305 | bs->print = 1; | |
d983da9c | 5306 | |
f431efe5 PA |
5307 | /* If this is a scope breakpoint, mark the associated |
5308 | watchpoint as triggered so that we will handle the | |
5309 | out-of-scope event. We'll get to the watchpoint next | |
5310 | iteration. */ | |
d0fb5eae | 5311 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5312 | { |
5313 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5314 | ||
5315 | w->watchpoint_triggered = watch_triggered_yes; | |
5316 | } | |
f431efe5 PA |
5317 | } |
5318 | } | |
5319 | ||
7c16b83e | 5320 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5321 | if (!target_supports_stopped_by_sw_breakpoint () |
5322 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5323 | { |
1123588c | 5324 | for (bp_location *loc : moribund_locations) |
f431efe5 | 5325 | { |
1cf4d951 PA |
5326 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5327 | && need_moribund_for_location_type (loc)) | |
5328 | { | |
ddfe970e | 5329 | bpstat bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5330 | /* For hits of moribund locations, we should just proceed. */ |
5331 | bs->stop = 0; | |
5332 | bs->print = 0; | |
5333 | bs->print_it = print_it_noop; | |
5334 | } | |
f431efe5 PA |
5335 | } |
5336 | } | |
5337 | ||
ddfe970e KS |
5338 | return bs_head; |
5339 | } | |
5340 | ||
5341 | /* See breakpoint.h. */ | |
5342 | ||
5343 | bpstat | |
5344 | bpstat_stop_status (const address_space *aspace, | |
00431a78 | 5345 | CORE_ADDR bp_addr, thread_info *thread, |
ddfe970e KS |
5346 | const struct target_waitstatus *ws, |
5347 | bpstat stop_chain) | |
5348 | { | |
5349 | struct breakpoint *b = NULL; | |
5350 | /* First item of allocated bpstat's. */ | |
5351 | bpstat bs_head = stop_chain; | |
5352 | bpstat bs; | |
5353 | int need_remove_insert; | |
5354 | int removed_any; | |
5355 | ||
5356 | /* First, build the bpstat chain with locations that explain a | |
5357 | target stop, while being careful to not set the target running, | |
5358 | as that may invalidate locations (in particular watchpoint | |
5359 | locations are recreated). Resuming will happen here with | |
5360 | breakpoint conditions or watchpoint expressions that include | |
5361 | inferior function calls. */ | |
5362 | if (bs_head == NULL) | |
5363 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); | |
5364 | ||
edcc5120 TT |
5365 | /* A bit of special processing for shlib breakpoints. We need to |
5366 | process solib loading here, so that the lists of loaded and | |
5367 | unloaded libraries are correct before we handle "catch load" and | |
5368 | "catch unload". */ | |
5369 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5370 | { | |
5d268276 | 5371 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5372 | { |
5373 | handle_solib_event (); | |
5374 | break; | |
5375 | } | |
5376 | } | |
5377 | ||
f431efe5 PA |
5378 | /* Now go through the locations that caused the target to stop, and |
5379 | check whether we're interested in reporting this stop to higher | |
5380 | layers, or whether we should resume the target transparently. */ | |
5381 | ||
5382 | removed_any = 0; | |
5383 | ||
5760d0ab | 5384 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5385 | { |
5386 | if (!bs->stop) | |
5387 | continue; | |
5388 | ||
f431efe5 | 5389 | b = bs->breakpoint_at; |
348d480f PA |
5390 | b->ops->check_status (bs); |
5391 | if (bs->stop) | |
28010a5d | 5392 | { |
00431a78 | 5393 | bpstat_check_breakpoint_conditions (bs, thread); |
f431efe5 | 5394 | |
429374b8 JK |
5395 | if (bs->stop) |
5396 | { | |
5397 | ++(b->hit_count); | |
76727919 | 5398 | gdb::observers::breakpoint_modified.notify (b); |
c906108c | 5399 | |
4a64f543 | 5400 | /* We will stop here. */ |
429374b8 JK |
5401 | if (b->disposition == disp_disable) |
5402 | { | |
816338b5 | 5403 | --(b->enable_count); |
1a853c52 | 5404 | if (b->enable_count <= 0) |
429374b8 | 5405 | b->enable_state = bp_disabled; |
f431efe5 | 5406 | removed_any = 1; |
429374b8 JK |
5407 | } |
5408 | if (b->silent) | |
5409 | bs->print = 0; | |
5410 | bs->commands = b->commands; | |
abf85f46 | 5411 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5412 | ? bs->commands.get () : NULL)) |
abf85f46 | 5413 | bs->print = 0; |
9d6e6e84 HZ |
5414 | |
5415 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5416 | } |
5417 | ||
348d480f | 5418 | } |
a9b3a50f PA |
5419 | |
5420 | /* Print nothing for this entry if we don't stop or don't | |
5421 | print. */ | |
5422 | if (!bs->stop || !bs->print) | |
5423 | bs->print_it = print_it_noop; | |
429374b8 | 5424 | } |
876fa593 | 5425 | |
d983da9c DJ |
5426 | /* If we aren't stopping, the value of some hardware watchpoint may |
5427 | not have changed, but the intermediate memory locations we are | |
5428 | watching may have. Don't bother if we're stopping; this will get | |
5429 | done later. */ | |
d832cb68 | 5430 | need_remove_insert = 0; |
5760d0ab JK |
5431 | if (! bpstat_causes_stop (bs_head)) |
5432 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5433 | if (!bs->stop |
f431efe5 PA |
5434 | && bs->breakpoint_at |
5435 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5436 | { |
3a5c3e22 PA |
5437 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5438 | ||
5439 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5440 | need_remove_insert = 1; |
d983da9c DJ |
5441 | } |
5442 | ||
d832cb68 | 5443 | if (need_remove_insert) |
44702360 | 5444 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5445 | else if (removed_any) |
44702360 | 5446 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5447 | |
5760d0ab | 5448 | return bs_head; |
c906108c | 5449 | } |
628fe4e4 JK |
5450 | |
5451 | static void | |
5452 | handle_jit_event (void) | |
5453 | { | |
5454 | struct frame_info *frame; | |
5455 | struct gdbarch *gdbarch; | |
5456 | ||
243a9253 PA |
5457 | if (debug_infrun) |
5458 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5459 | ||
628fe4e4 JK |
5460 | /* Switch terminal for any messages produced by |
5461 | breakpoint_re_set. */ | |
223ffa71 | 5462 | target_terminal::ours_for_output (); |
628fe4e4 JK |
5463 | |
5464 | frame = get_current_frame (); | |
5465 | gdbarch = get_frame_arch (frame); | |
5466 | ||
5467 | jit_event_handler (gdbarch); | |
5468 | ||
223ffa71 | 5469 | target_terminal::inferior (); |
628fe4e4 JK |
5470 | } |
5471 | ||
5472 | /* Prepare WHAT final decision for infrun. */ | |
5473 | ||
5474 | /* Decide what infrun needs to do with this bpstat. */ | |
5475 | ||
c906108c | 5476 | struct bpstat_what |
0e30163f | 5477 | bpstat_what (bpstat bs_head) |
c906108c | 5478 | { |
c906108c | 5479 | struct bpstat_what retval; |
0e30163f | 5480 | bpstat bs; |
c906108c | 5481 | |
628fe4e4 | 5482 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5483 | retval.call_dummy = STOP_NONE; |
e2d0f980 | 5484 | retval.is_longjmp = false; |
628fe4e4 | 5485 | |
0e30163f | 5486 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5487 | { |
628fe4e4 JK |
5488 | /* Extract this BS's action. After processing each BS, we check |
5489 | if its action overrides all we've seem so far. */ | |
5490 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5491 | enum bptype bptype; | |
5492 | ||
c906108c | 5493 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5494 | { |
5495 | /* I suspect this can happen if it was a momentary | |
5496 | breakpoint which has since been deleted. */ | |
5497 | bptype = bp_none; | |
5498 | } | |
20874c92 | 5499 | else |
f431efe5 | 5500 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5501 | |
5502 | switch (bptype) | |
c906108c SS |
5503 | { |
5504 | case bp_none: | |
628fe4e4 | 5505 | break; |
c906108c SS |
5506 | case bp_breakpoint: |
5507 | case bp_hardware_breakpoint: | |
7c16b83e | 5508 | case bp_single_step: |
c906108c SS |
5509 | case bp_until: |
5510 | case bp_finish: | |
a9b3a50f | 5511 | case bp_shlib_event: |
c906108c SS |
5512 | if (bs->stop) |
5513 | { | |
5514 | if (bs->print) | |
628fe4e4 | 5515 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5516 | else |
628fe4e4 | 5517 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5518 | } |
5519 | else | |
628fe4e4 | 5520 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5521 | break; |
5522 | case bp_watchpoint: | |
5523 | case bp_hardware_watchpoint: | |
5524 | case bp_read_watchpoint: | |
5525 | case bp_access_watchpoint: | |
5526 | if (bs->stop) | |
5527 | { | |
5528 | if (bs->print) | |
628fe4e4 | 5529 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5530 | else |
628fe4e4 | 5531 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5532 | } |
5533 | else | |
628fe4e4 JK |
5534 | { |
5535 | /* There was a watchpoint, but we're not stopping. | |
5536 | This requires no further action. */ | |
5537 | } | |
c906108c SS |
5538 | break; |
5539 | case bp_longjmp: | |
e2e4d78b | 5540 | case bp_longjmp_call_dummy: |
186c406b | 5541 | case bp_exception: |
0a39bb32 PA |
5542 | if (bs->stop) |
5543 | { | |
5544 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5545 | retval.is_longjmp = bptype != bp_exception; | |
5546 | } | |
5547 | else | |
5548 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5549 | break; |
5550 | case bp_longjmp_resume: | |
186c406b | 5551 | case bp_exception_resume: |
0a39bb32 PA |
5552 | if (bs->stop) |
5553 | { | |
5554 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5555 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5556 | } | |
5557 | else | |
5558 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5559 | break; |
5560 | case bp_step_resume: | |
5561 | if (bs->stop) | |
628fe4e4 JK |
5562 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5563 | else | |
c906108c | 5564 | { |
628fe4e4 JK |
5565 | /* It is for the wrong frame. */ |
5566 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5567 | } |
c906108c | 5568 | break; |
2c03e5be PA |
5569 | case bp_hp_step_resume: |
5570 | if (bs->stop) | |
5571 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5572 | else | |
5573 | { | |
5574 | /* It is for the wrong frame. */ | |
5575 | this_action = BPSTAT_WHAT_SINGLE; | |
5576 | } | |
5577 | break; | |
c906108c | 5578 | case bp_watchpoint_scope: |
c4093a6a | 5579 | case bp_thread_event: |
1900040c | 5580 | case bp_overlay_event: |
0fd8e87f | 5581 | case bp_longjmp_master: |
aa7d318d | 5582 | case bp_std_terminate_master: |
186c406b | 5583 | case bp_exception_master: |
628fe4e4 | 5584 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5585 | break; |
ce78b96d | 5586 | case bp_catchpoint: |
c5aa993b JM |
5587 | if (bs->stop) |
5588 | { | |
5589 | if (bs->print) | |
628fe4e4 | 5590 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5591 | else |
628fe4e4 | 5592 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5593 | } |
5594 | else | |
628fe4e4 | 5595 | { |
cb1e4e32 PA |
5596 | /* Some catchpoints are implemented with breakpoints. |
5597 | For those, we need to step over the breakpoint. */ | |
5598 | if (bs->bp_location_at->loc_type != bp_loc_other) | |
5599 | this_action = BPSTAT_WHAT_SINGLE; | |
628fe4e4 JK |
5600 | } |
5601 | break; | |
628fe4e4 | 5602 | case bp_jit_event: |
628fe4e4 | 5603 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5604 | break; |
c906108c | 5605 | case bp_call_dummy: |
53a5351d JM |
5606 | /* Make sure the action is stop (silent or noisy), |
5607 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5608 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5609 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5610 | break; |
5611 | case bp_std_terminate: | |
5612 | /* Make sure the action is stop (silent or noisy), | |
5613 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5614 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5615 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5616 | break; |
1042e4c0 | 5617 | case bp_tracepoint: |
7a697b8d | 5618 | case bp_fast_tracepoint: |
0fb4aa4b | 5619 | case bp_static_tracepoint: |
1042e4c0 SS |
5620 | /* Tracepoint hits should not be reported back to GDB, and |
5621 | if one got through somehow, it should have been filtered | |
5622 | out already. */ | |
5623 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5624 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5625 | break; |
5626 | case bp_gnu_ifunc_resolver: | |
5627 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5628 | this_action = BPSTAT_WHAT_SINGLE; | |
5629 | break; | |
5630 | case bp_gnu_ifunc_resolver_return: | |
5631 | /* The breakpoint will be removed, execution will restart from the | |
5632 | PC of the former breakpoint. */ | |
5633 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5634 | break; | |
e7e0cddf SS |
5635 | |
5636 | case bp_dprintf: | |
a11cfd87 HZ |
5637 | if (bs->stop) |
5638 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5639 | else | |
5640 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5641 | break; |
5642 | ||
628fe4e4 JK |
5643 | default: |
5644 | internal_error (__FILE__, __LINE__, | |
5645 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5646 | } |
628fe4e4 | 5647 | |
325fac50 | 5648 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5649 | } |
628fe4e4 | 5650 | |
243a9253 PA |
5651 | return retval; |
5652 | } | |
628fe4e4 | 5653 | |
243a9253 PA |
5654 | void |
5655 | bpstat_run_callbacks (bpstat bs_head) | |
5656 | { | |
5657 | bpstat bs; | |
628fe4e4 | 5658 | |
0e30163f JK |
5659 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5660 | { | |
5661 | struct breakpoint *b = bs->breakpoint_at; | |
5662 | ||
5663 | if (b == NULL) | |
5664 | continue; | |
5665 | switch (b->type) | |
5666 | { | |
243a9253 PA |
5667 | case bp_jit_event: |
5668 | handle_jit_event (); | |
5669 | break; | |
0e30163f JK |
5670 | case bp_gnu_ifunc_resolver: |
5671 | gnu_ifunc_resolver_stop (b); | |
5672 | break; | |
5673 | case bp_gnu_ifunc_resolver_return: | |
5674 | gnu_ifunc_resolver_return_stop (b); | |
5675 | break; | |
5676 | } | |
5677 | } | |
c906108c SS |
5678 | } |
5679 | ||
4c462cb0 | 5680 | /* See breakpoint.h. */ |
c906108c | 5681 | |
4c462cb0 SM |
5682 | bool |
5683 | bpstat_should_step () | |
c906108c SS |
5684 | { |
5685 | struct breakpoint *b; | |
cc59ec59 | 5686 | |
c906108c | 5687 | ALL_BREAKPOINTS (b) |
717a8278 | 5688 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
4c462cb0 SM |
5689 | return true; |
5690 | return false; | |
c906108c SS |
5691 | } |
5692 | ||
4c462cb0 SM |
5693 | /* See breakpoint.h. */ |
5694 | ||
5695 | bool | |
67822962 PA |
5696 | bpstat_causes_stop (bpstat bs) |
5697 | { | |
5698 | for (; bs != NULL; bs = bs->next) | |
5699 | if (bs->stop) | |
4c462cb0 | 5700 | return true; |
67822962 | 5701 | |
4c462cb0 | 5702 | return false; |
67822962 PA |
5703 | } |
5704 | ||
c906108c | 5705 | \f |
c5aa993b | 5706 | |
170b53b2 UW |
5707 | /* Compute a string of spaces suitable to indent the next line |
5708 | so it starts at the position corresponding to the table column | |
5709 | named COL_NAME in the currently active table of UIOUT. */ | |
5710 | ||
5711 | static char * | |
5712 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5713 | { | |
5714 | static char wrap_indent[80]; | |
5715 | int i, total_width, width, align; | |
c5209615 | 5716 | const char *text; |
170b53b2 UW |
5717 | |
5718 | total_width = 0; | |
112e8700 | 5719 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5720 | { |
5721 | if (strcmp (text, col_name) == 0) | |
5722 | { | |
5723 | gdb_assert (total_width < sizeof wrap_indent); | |
5724 | memset (wrap_indent, ' ', total_width); | |
5725 | wrap_indent[total_width] = 0; | |
5726 | ||
5727 | return wrap_indent; | |
5728 | } | |
5729 | ||
5730 | total_width += width + 1; | |
5731 | } | |
5732 | ||
5733 | return NULL; | |
5734 | } | |
5735 | ||
b775012e LM |
5736 | /* Determine if the locations of this breakpoint will have their conditions |
5737 | evaluated by the target, host or a mix of both. Returns the following: | |
5738 | ||
5739 | "host": Host evals condition. | |
5740 | "host or target": Host or Target evals condition. | |
5741 | "target": Target evals condition. | |
5742 | */ | |
5743 | ||
5744 | static const char * | |
5745 | bp_condition_evaluator (struct breakpoint *b) | |
5746 | { | |
5747 | struct bp_location *bl; | |
5748 | char host_evals = 0; | |
5749 | char target_evals = 0; | |
5750 | ||
5751 | if (!b) | |
5752 | return NULL; | |
5753 | ||
5754 | if (!is_breakpoint (b)) | |
5755 | return NULL; | |
5756 | ||
5757 | if (gdb_evaluates_breakpoint_condition_p () | |
5758 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5759 | return condition_evaluation_host; | |
5760 | ||
5761 | for (bl = b->loc; bl; bl = bl->next) | |
5762 | { | |
5763 | if (bl->cond_bytecode) | |
5764 | target_evals++; | |
5765 | else | |
5766 | host_evals++; | |
5767 | } | |
5768 | ||
5769 | if (host_evals && target_evals) | |
5770 | return condition_evaluation_both; | |
5771 | else if (target_evals) | |
5772 | return condition_evaluation_target; | |
5773 | else | |
5774 | return condition_evaluation_host; | |
5775 | } | |
5776 | ||
5777 | /* Determine the breakpoint location's condition evaluator. This is | |
5778 | similar to bp_condition_evaluator, but for locations. */ | |
5779 | ||
5780 | static const char * | |
5781 | bp_location_condition_evaluator (struct bp_location *bl) | |
5782 | { | |
5783 | if (bl && !is_breakpoint (bl->owner)) | |
5784 | return NULL; | |
5785 | ||
5786 | if (gdb_evaluates_breakpoint_condition_p () | |
5787 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5788 | return condition_evaluation_host; | |
5789 | ||
5790 | if (bl && bl->cond_bytecode) | |
5791 | return condition_evaluation_target; | |
5792 | else | |
5793 | return condition_evaluation_host; | |
5794 | } | |
5795 | ||
859825b8 JK |
5796 | /* Print the LOC location out of the list of B->LOC locations. */ |
5797 | ||
170b53b2 UW |
5798 | static void |
5799 | print_breakpoint_location (struct breakpoint *b, | |
5800 | struct bp_location *loc) | |
0d381245 | 5801 | { |
79a45e25 | 5802 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5803 | |
5804 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5805 | |
859825b8 JK |
5806 | if (loc != NULL && loc->shlib_disabled) |
5807 | loc = NULL; | |
5808 | ||
6c95b8df PA |
5809 | if (loc != NULL) |
5810 | set_current_program_space (loc->pspace); | |
5811 | ||
56435ebe | 5812 | if (b->display_canonical) |
d28cd78a | 5813 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 5814 | else if (loc && loc->symtab) |
0d381245 | 5815 | { |
4a27f119 KS |
5816 | const struct symbol *sym = loc->symbol; |
5817 | ||
0d381245 VP |
5818 | if (sym) |
5819 | { | |
112e8700 | 5820 | uiout->text ("in "); |
987012b8 | 5821 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 5822 | function_name_style.style ()); |
112e8700 SM |
5823 | uiout->text (" "); |
5824 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
5825 | uiout->text ("at "); | |
0d381245 | 5826 | } |
112e8700 | 5827 | uiout->field_string ("file", |
cbe56571 | 5828 | symtab_to_filename_for_display (loc->symtab), |
e43b10e1 | 5829 | file_name_style.style ()); |
112e8700 | 5830 | uiout->text (":"); |
05cba821 | 5831 | |
112e8700 SM |
5832 | if (uiout->is_mi_like_p ()) |
5833 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 5834 | |
381befee | 5835 | uiout->field_signed ("line", loc->line_number); |
0d381245 | 5836 | } |
859825b8 | 5837 | else if (loc) |
0d381245 | 5838 | { |
d7e74731 | 5839 | string_file stb; |
170b53b2 | 5840 | |
d7e74731 | 5841 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 5842 | demangle, ""); |
112e8700 | 5843 | uiout->field_stream ("at", stb); |
0d381245 | 5844 | } |
859825b8 | 5845 | else |
f00aae0f | 5846 | { |
d28cd78a TT |
5847 | uiout->field_string ("pending", |
5848 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
5849 | /* If extra_string is available, it could be holding a condition |
5850 | or dprintf arguments. In either case, make sure it is printed, | |
5851 | too, but only for non-MI streams. */ | |
112e8700 | 5852 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
5853 | { |
5854 | if (b->type == bp_dprintf) | |
112e8700 | 5855 | uiout->text (","); |
f00aae0f | 5856 | else |
112e8700 SM |
5857 | uiout->text (" "); |
5858 | uiout->text (b->extra_string); | |
f00aae0f KS |
5859 | } |
5860 | } | |
6c95b8df | 5861 | |
b775012e LM |
5862 | if (loc && is_breakpoint (b) |
5863 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5864 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5865 | { | |
112e8700 SM |
5866 | uiout->text (" ("); |
5867 | uiout->field_string ("evaluated-by", | |
b775012e | 5868 | bp_location_condition_evaluator (loc)); |
112e8700 | 5869 | uiout->text (")"); |
b775012e | 5870 | } |
0d381245 VP |
5871 | } |
5872 | ||
269b11a2 PA |
5873 | static const char * |
5874 | bptype_string (enum bptype type) | |
c906108c | 5875 | { |
c4093a6a JM |
5876 | struct ep_type_description |
5877 | { | |
5878 | enum bptype type; | |
a121b7c1 | 5879 | const char *description; |
c4093a6a JM |
5880 | }; |
5881 | static struct ep_type_description bptypes[] = | |
c906108c | 5882 | { |
c5aa993b JM |
5883 | {bp_none, "?deleted?"}, |
5884 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5885 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 5886 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
5887 | {bp_until, "until"}, |
5888 | {bp_finish, "finish"}, | |
5889 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5890 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5891 | {bp_read_watchpoint, "read watchpoint"}, |
5892 | {bp_access_watchpoint, "acc watchpoint"}, | |
5893 | {bp_longjmp, "longjmp"}, | |
5894 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5895 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5896 | {bp_exception, "exception"}, |
5897 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5898 | {bp_step_resume, "step resume"}, |
2c03e5be | 5899 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5900 | {bp_watchpoint_scope, "watchpoint scope"}, |
5901 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5902 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5903 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5904 | {bp_thread_event, "thread events"}, |
1900040c | 5905 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5906 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5907 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5908 | {bp_exception_master, "exception master"}, |
ce78b96d | 5909 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5910 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5911 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5912 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5913 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5914 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5915 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5916 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5917 | }; |
269b11a2 PA |
5918 | |
5919 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5920 | || ((int) type != bptypes[(int) type].type)) | |
5921 | internal_error (__FILE__, __LINE__, | |
5922 | _("bptypes table does not describe type #%d."), | |
5923 | (int) type); | |
5924 | ||
5925 | return bptypes[(int) type].description; | |
5926 | } | |
5927 | ||
998580f1 MK |
5928 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5929 | For CLI, prefix the list with the string 'inf'. */ | |
5930 | ||
5931 | static void | |
5932 | output_thread_groups (struct ui_out *uiout, | |
5933 | const char *field_name, | |
5c632425 | 5934 | const std::vector<int> &inf_nums, |
998580f1 MK |
5935 | int mi_only) |
5936 | { | |
112e8700 | 5937 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
5938 | |
5939 | /* For backward compatibility, don't display inferiors in CLI unless | |
5940 | there are several. Always display them for MI. */ | |
5941 | if (!is_mi && mi_only) | |
5942 | return; | |
5943 | ||
10f489e5 | 5944 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 5945 | |
5c632425 | 5946 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
5947 | { |
5948 | if (is_mi) | |
5949 | { | |
5950 | char mi_group[10]; | |
5951 | ||
5c632425 | 5952 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 5953 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
5954 | } |
5955 | else | |
5956 | { | |
5957 | if (i == 0) | |
112e8700 | 5958 | uiout->text (" inf "); |
998580f1 | 5959 | else |
112e8700 | 5960 | uiout->text (", "); |
998580f1 | 5961 | |
5c632425 | 5962 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
5963 | } |
5964 | } | |
998580f1 MK |
5965 | } |
5966 | ||
a38118e5 PA |
5967 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
5968 | instead of going via breakpoint_ops::print_one. This makes "maint | |
5969 | info breakpoints" show the software breakpoint locations of | |
5970 | catchpoints, which are considered internal implementation | |
5971 | detail. */ | |
269b11a2 PA |
5972 | |
5973 | static void | |
5974 | print_one_breakpoint_location (struct breakpoint *b, | |
5975 | struct bp_location *loc, | |
5976 | int loc_number, | |
5977 | struct bp_location **last_loc, | |
a38118e5 | 5978 | int allflag, bool raw_loc) |
269b11a2 PA |
5979 | { |
5980 | struct command_line *l; | |
c2c6d25f | 5981 | static char bpenables[] = "nynny"; |
c906108c | 5982 | |
79a45e25 | 5983 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5984 | int header_of_multiple = 0; |
5985 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5986 | struct value_print_options opts; |
5987 | ||
5988 | get_user_print_options (&opts); | |
0d381245 VP |
5989 | |
5990 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5991 | /* See comment in print_one_breakpoint concerning treatment of |
5992 | breakpoints with single disabled location. */ | |
0d381245 VP |
5993 | if (loc == NULL |
5994 | && (b->loc != NULL | |
5995 | && (b->loc->next != NULL || !b->loc->enabled))) | |
5996 | header_of_multiple = 1; | |
5997 | if (loc == NULL) | |
5998 | loc = b->loc; | |
5999 | ||
c4093a6a JM |
6000 | annotate_record (); |
6001 | ||
6002 | /* 1 */ | |
6003 | annotate_field (0); | |
0d381245 | 6004 | if (part_of_multiple) |
528e1572 | 6005 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
0d381245 | 6006 | else |
381befee | 6007 | uiout->field_signed ("number", b->number); |
c4093a6a JM |
6008 | |
6009 | /* 2 */ | |
6010 | annotate_field (1); | |
0d381245 | 6011 | if (part_of_multiple) |
112e8700 | 6012 | uiout->field_skip ("type"); |
269b11a2 | 6013 | else |
112e8700 | 6014 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6015 | |
6016 | /* 3 */ | |
6017 | annotate_field (2); | |
0d381245 | 6018 | if (part_of_multiple) |
112e8700 | 6019 | uiout->field_skip ("disp"); |
0d381245 | 6020 | else |
112e8700 | 6021 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6022 | |
c4093a6a JM |
6023 | /* 4 */ |
6024 | annotate_field (3); | |
0d381245 | 6025 | if (part_of_multiple) |
112e8700 | 6026 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6027 | else |
112e8700 | 6028 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
0d381245 | 6029 | |
c4093a6a | 6030 | /* 5 and 6 */ |
a38118e5 | 6031 | if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL) |
b58a68fe | 6032 | b->ops->print_one (b, last_loc); |
3086aeae | 6033 | else |
a38118e5 PA |
6034 | { |
6035 | if (is_watchpoint (b)) | |
3a5c3e22 PA |
6036 | { |
6037 | struct watchpoint *w = (struct watchpoint *) b; | |
6038 | ||
6039 | /* Field 4, the address, is omitted (which makes the columns | |
6040 | not line up too nicely with the headers, but the effect | |
6041 | is relatively readable). */ | |
6042 | if (opts.addressprint) | |
112e8700 | 6043 | uiout->field_skip ("addr"); |
3a5c3e22 | 6044 | annotate_field (5); |
112e8700 | 6045 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6046 | } |
f06f1252 TT |
6047 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
6048 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6049 | { |
6050 | if (opts.addressprint) | |
6051 | { | |
6052 | annotate_field (4); | |
6053 | if (header_of_multiple) | |
7f6aba03 TT |
6054 | uiout->field_string ("addr", "<MULTIPLE>", |
6055 | metadata_style.style ()); | |
a38118e5 | 6056 | else if (b->loc == NULL || loc->shlib_disabled) |
7f6aba03 TT |
6057 | uiout->field_string ("addr", "<PENDING>", |
6058 | metadata_style.style ()); | |
a38118e5 PA |
6059 | else |
6060 | uiout->field_core_addr ("addr", | |
6061 | loc->gdbarch, loc->address); | |
6062 | } | |
6063 | annotate_field (5); | |
6064 | if (!header_of_multiple) | |
6065 | print_breakpoint_location (b, loc); | |
6066 | if (b->loc) | |
6067 | *last_loc = b->loc; | |
6068 | } | |
6069 | } | |
6c95b8df | 6070 | |
998580f1 | 6071 | if (loc != NULL && !header_of_multiple) |
6c95b8df | 6072 | { |
5c632425 | 6073 | std::vector<int> inf_nums; |
998580f1 | 6074 | int mi_only = 1; |
6c95b8df | 6075 | |
08036331 | 6076 | for (inferior *inf : all_inferiors ()) |
6c95b8df PA |
6077 | { |
6078 | if (inf->pspace == loc->pspace) | |
5c632425 | 6079 | inf_nums.push_back (inf->num); |
6c95b8df | 6080 | } |
998580f1 MK |
6081 | |
6082 | /* For backward compatibility, don't display inferiors in CLI unless | |
6083 | there are several. Always display for MI. */ | |
6084 | if (allflag | |
6085 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6086 | && (number_of_program_spaces () > 1 | |
6087 | || number_of_inferiors () > 1) | |
6088 | /* LOC is for existing B, it cannot be in | |
6089 | moribund_locations and thus having NULL OWNER. */ | |
6090 | && loc->owner->type != bp_catchpoint)) | |
6091 | mi_only = 0; | |
5c632425 | 6092 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6093 | } |
6094 | ||
4a306c9a | 6095 | if (!part_of_multiple) |
c4093a6a | 6096 | { |
4a306c9a JB |
6097 | if (b->thread != -1) |
6098 | { | |
6099 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6100 | "stop only in" line a little further down. */ |
112e8700 | 6101 | uiout->text (" thread "); |
381befee | 6102 | uiout->field_signed ("thread", b->thread); |
4a306c9a JB |
6103 | } |
6104 | else if (b->task != 0) | |
6105 | { | |
112e8700 | 6106 | uiout->text (" task "); |
381befee | 6107 | uiout->field_signed ("task", b->task); |
4a306c9a | 6108 | } |
c4093a6a | 6109 | } |
f1310107 | 6110 | |
112e8700 | 6111 | uiout->text ("\n"); |
f1310107 | 6112 | |
348d480f | 6113 | if (!part_of_multiple) |
f1310107 TJB |
6114 | b->ops->print_one_detail (b, uiout); |
6115 | ||
0d381245 | 6116 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6117 | { |
6118 | annotate_field (6); | |
112e8700 | 6119 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6120 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6121 | the frame ID. */ |
112e8700 | 6122 | uiout->field_core_addr ("frame", |
5af949e3 | 6123 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6124 | uiout->text ("\n"); |
c4093a6a JM |
6125 | } |
6126 | ||
28010a5d | 6127 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6128 | { |
6129 | annotate_field (7); | |
d77f58be | 6130 | if (is_tracepoint (b)) |
112e8700 | 6131 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6132 | else |
112e8700 SM |
6133 | uiout->text ("\tstop only if "); |
6134 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6135 | |
6136 | /* Print whether the target is doing the breakpoint's condition | |
6137 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6138 | if (is_breakpoint (b) | |
6139 | && breakpoint_condition_evaluation_mode () | |
6140 | == condition_evaluation_target) | |
6141 | { | |
6a831f06 PA |
6142 | uiout->message (" (%pF evals)", |
6143 | string_field ("evaluated-by", | |
6144 | bp_condition_evaluator (b))); | |
b775012e | 6145 | } |
112e8700 | 6146 | uiout->text ("\n"); |
0101ce28 JJ |
6147 | } |
6148 | ||
0d381245 | 6149 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6150 | { |
4a64f543 | 6151 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6152 | uiout->text ("\tstop only in thread "); |
6153 | if (uiout->is_mi_like_p ()) | |
381befee | 6154 | uiout->field_signed ("thread", b->thread); |
5d5658a1 PA |
6155 | else |
6156 | { | |
6157 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6158 | ||
112e8700 | 6159 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6160 | } |
112e8700 | 6161 | uiout->text ("\n"); |
c4093a6a JM |
6162 | } |
6163 | ||
556ec64d YQ |
6164 | if (!part_of_multiple) |
6165 | { | |
6166 | if (b->hit_count) | |
31f56a27 YQ |
6167 | { |
6168 | /* FIXME should make an annotation for this. */ | |
6169 | if (is_catchpoint (b)) | |
112e8700 | 6170 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6171 | else if (is_tracepoint (b)) |
112e8700 | 6172 | uiout->text ("\ttracepoint"); |
31f56a27 | 6173 | else |
112e8700 SM |
6174 | uiout->text ("\tbreakpoint"); |
6175 | uiout->text (" already hit "); | |
381befee | 6176 | uiout->field_signed ("times", b->hit_count); |
31f56a27 | 6177 | if (b->hit_count == 1) |
112e8700 | 6178 | uiout->text (" time\n"); |
31f56a27 | 6179 | else |
112e8700 | 6180 | uiout->text (" times\n"); |
31f56a27 | 6181 | } |
556ec64d YQ |
6182 | else |
6183 | { | |
31f56a27 | 6184 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 | 6185 | if (uiout->is_mi_like_p ()) |
381befee | 6186 | uiout->field_signed ("times", b->hit_count); |
556ec64d YQ |
6187 | } |
6188 | } | |
8b93c638 | 6189 | |
0d381245 | 6190 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6191 | { |
6192 | annotate_field (8); | |
6a831f06 PA |
6193 | uiout->message ("\tignore next %pF hits\n", |
6194 | signed_field ("ignore", b->ignore_count)); | |
c4093a6a | 6195 | } |
059fb39f | 6196 | |
816338b5 SS |
6197 | /* Note that an enable count of 1 corresponds to "enable once" |
6198 | behavior, which is reported by the combination of enablement and | |
6199 | disposition, so we don't need to mention it here. */ | |
6200 | if (!part_of_multiple && b->enable_count > 1) | |
6201 | { | |
6202 | annotate_field (8); | |
112e8700 | 6203 | uiout->text ("\tdisable after "); |
816338b5 SS |
6204 | /* Tweak the wording to clarify that ignore and enable counts |
6205 | are distinct, and have additive effect. */ | |
6206 | if (b->ignore_count) | |
112e8700 | 6207 | uiout->text ("additional "); |
816338b5 | 6208 | else |
112e8700 | 6209 | uiout->text ("next "); |
381befee | 6210 | uiout->field_signed ("enable", b->enable_count); |
112e8700 | 6211 | uiout->text (" hits\n"); |
816338b5 SS |
6212 | } |
6213 | ||
f196051f SS |
6214 | if (!part_of_multiple && is_tracepoint (b)) |
6215 | { | |
6216 | struct tracepoint *tp = (struct tracepoint *) b; | |
6217 | ||
6218 | if (tp->traceframe_usage) | |
6219 | { | |
112e8700 | 6220 | uiout->text ("\ttrace buffer usage "); |
381befee | 6221 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
112e8700 | 6222 | uiout->text (" bytes\n"); |
f196051f SS |
6223 | } |
6224 | } | |
d3ce09f5 | 6225 | |
d1b0a7bf | 6226 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6227 | if (!part_of_multiple && l) |
c4093a6a JM |
6228 | { |
6229 | annotate_field (9); | |
2e783024 | 6230 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6231 | print_command_lines (uiout, l, 4); |
c4093a6a | 6232 | } |
d24317b4 | 6233 | |
d9b3f62e | 6234 | if (is_tracepoint (b)) |
1042e4c0 | 6235 | { |
d9b3f62e PA |
6236 | struct tracepoint *t = (struct tracepoint *) b; |
6237 | ||
6238 | if (!part_of_multiple && t->pass_count) | |
6239 | { | |
6240 | annotate_field (10); | |
112e8700 | 6241 | uiout->text ("\tpass count "); |
381befee | 6242 | uiout->field_signed ("pass", t->pass_count); |
112e8700 | 6243 | uiout->text (" \n"); |
d9b3f62e | 6244 | } |
f2a8bc8a YQ |
6245 | |
6246 | /* Don't display it when tracepoint or tracepoint location is | |
6247 | pending. */ | |
6248 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6249 | { | |
6250 | annotate_field (11); | |
6251 | ||
112e8700 SM |
6252 | if (uiout->is_mi_like_p ()) |
6253 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6254 | loc->inserted ? "y" : "n"); |
6255 | else | |
6256 | { | |
6257 | if (loc->inserted) | |
112e8700 | 6258 | uiout->text ("\t"); |
f2a8bc8a | 6259 | else |
112e8700 SM |
6260 | uiout->text ("\tnot "); |
6261 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6262 | } |
6263 | } | |
1042e4c0 SS |
6264 | } |
6265 | ||
112e8700 | 6266 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6267 | { |
3a5c3e22 PA |
6268 | if (is_watchpoint (b)) |
6269 | { | |
6270 | struct watchpoint *w = (struct watchpoint *) b; | |
6271 | ||
112e8700 | 6272 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6273 | } |
f00aae0f | 6274 | else if (b->location != NULL |
d28cd78a | 6275 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6276 | uiout->field_string ("original-location", |
d28cd78a | 6277 | event_location_to_string (b->location.get ())); |
d24317b4 | 6278 | } |
c4093a6a | 6279 | } |
c5aa993b | 6280 | |
13674803 SM |
6281 | /* See breakpoint.h. */ |
6282 | ||
6283 | bool fix_multi_location_breakpoint_output_globally = false; | |
6284 | ||
0d381245 VP |
6285 | static void |
6286 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6287 | struct bp_location **last_loc, |
6c95b8df | 6288 | int allflag) |
0d381245 | 6289 | { |
79a45e25 | 6290 | struct ui_out *uiout = current_uiout; |
13674803 SM |
6291 | bool use_fixed_output |
6292 | = (uiout->test_flags (fix_multi_location_breakpoint_output) | |
6293 | || fix_multi_location_breakpoint_output_globally); | |
8d3788bd | 6294 | |
b4be1b06 | 6295 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
a38118e5 | 6296 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false); |
8d3788bd | 6297 | |
b4be1b06 SM |
6298 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
6299 | are outside. */ | |
6300 | if (!use_fixed_output) | |
6301 | bkpt_tuple_emitter.reset (); | |
0d381245 VP |
6302 | |
6303 | /* If this breakpoint has custom print function, | |
6304 | it's already printed. Otherwise, print individual | |
6305 | locations, if any. */ | |
a38118e5 PA |
6306 | if (b->ops == NULL |
6307 | || b->ops->print_one == NULL | |
6308 | || allflag) | |
0d381245 | 6309 | { |
4a64f543 MS |
6310 | /* If breakpoint has a single location that is disabled, we |
6311 | print it as if it had several locations, since otherwise it's | |
6312 | hard to represent "breakpoint enabled, location disabled" | |
6313 | situation. | |
6314 | ||
6315 | Note that while hardware watchpoints have several locations | |
a38118e5 PA |
6316 | internally, that's not a property exposed to users. |
6317 | ||
6318 | Likewise, while catchpoints may be implemented with | |
6319 | breakpoints (e.g., catch throw), that's not a property | |
6320 | exposed to users. We do however display the internal | |
6321 | breakpoint locations with "maint info breakpoints". */ | |
6322 | if (!is_hardware_watchpoint (b) | |
f06f1252 TT |
6323 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
6324 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6325 | && (allflag |
6326 | || (b->loc && (b->loc->next || !b->loc->enabled)))) | |
0d381245 | 6327 | { |
b4be1b06 SM |
6328 | gdb::optional<ui_out_emit_list> locations_list; |
6329 | ||
6330 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid | |
6331 | MI record. For later versions, place breakpoint locations in a | |
6332 | list. */ | |
6333 | if (uiout->is_mi_like_p () && use_fixed_output) | |
6334 | locations_list.emplace (uiout, "locations"); | |
8d3788bd | 6335 | |
b4be1b06 SM |
6336 | int n = 1; |
6337 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) | |
8d3788bd | 6338 | { |
b4be1b06 | 6339 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
a38118e5 PA |
6340 | print_one_breakpoint_location (b, loc, n, last_loc, |
6341 | allflag, allflag); | |
8d3788bd | 6342 | } |
0d381245 VP |
6343 | } |
6344 | } | |
6345 | } | |
6346 | ||
a6d9a66e UW |
6347 | static int |
6348 | breakpoint_address_bits (struct breakpoint *b) | |
6349 | { | |
6350 | int print_address_bits = 0; | |
6351 | struct bp_location *loc; | |
6352 | ||
c6d81124 PA |
6353 | /* Software watchpoints that aren't watching memory don't have an |
6354 | address to print. */ | |
6355 | if (is_no_memory_software_watchpoint (b)) | |
6356 | return 0; | |
6357 | ||
a6d9a66e UW |
6358 | for (loc = b->loc; loc; loc = loc->next) |
6359 | { | |
c7437ca6 PA |
6360 | int addr_bit; |
6361 | ||
c7437ca6 | 6362 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6363 | if (addr_bit > print_address_bits) |
6364 | print_address_bits = addr_bit; | |
6365 | } | |
6366 | ||
6367 | return print_address_bits; | |
6368 | } | |
0d381245 | 6369 | |
65630365 | 6370 | /* See breakpoint.h. */ |
c5aa993b | 6371 | |
65630365 PA |
6372 | void |
6373 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6374 | { |
a6d9a66e | 6375 | struct bp_location *dummy_loc = NULL; |
65630365 | 6376 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6377 | } |
c5aa993b | 6378 | |
09d682a4 TT |
6379 | /* Return true if this breakpoint was set by the user, false if it is |
6380 | internal or momentary. */ | |
6381 | ||
6382 | int | |
6383 | user_breakpoint_p (struct breakpoint *b) | |
6384 | { | |
46c6471b | 6385 | return b->number > 0; |
09d682a4 TT |
6386 | } |
6387 | ||
93daf339 TT |
6388 | /* See breakpoint.h. */ |
6389 | ||
6390 | int | |
6391 | pending_breakpoint_p (struct breakpoint *b) | |
6392 | { | |
6393 | return b->loc == NULL; | |
6394 | } | |
6395 | ||
5c458ae8 SM |
6396 | /* Print information on breakpoints (including watchpoints and tracepoints). |
6397 | ||
6398 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as | |
6399 | understood by number_or_range_parser. Only breakpoints included in this | |
6400 | list are then printed. | |
6401 | ||
6402 | If SHOW_INTERNAL is true, print internal breakpoints. | |
6403 | ||
6404 | If FILTER is non-NULL, call it on each breakpoint and only include the | |
6405 | ones for which it returns true. | |
6406 | ||
6407 | Return the total number of breakpoints listed. */ | |
c906108c | 6408 | |
d77f58be | 6409 | static int |
5c458ae8 | 6410 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
f2478a7e | 6411 | bool (*filter) (const struct breakpoint *)) |
c4093a6a | 6412 | { |
52f0bd74 | 6413 | struct breakpoint *b; |
a6d9a66e | 6414 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6415 | int nr_printable_breakpoints; |
79a45b7d | 6416 | struct value_print_options opts; |
a6d9a66e | 6417 | int print_address_bits = 0; |
269b11a2 | 6418 | int print_type_col_width = 14; |
79a45e25 | 6419 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6420 | |
79a45b7d TT |
6421 | get_user_print_options (&opts); |
6422 | ||
4a64f543 MS |
6423 | /* Compute the number of rows in the table, as well as the size |
6424 | required for address fields. */ | |
7f3b0473 AC |
6425 | nr_printable_breakpoints = 0; |
6426 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6427 | { |
6428 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6429 | if (filter && !filter (b)) | |
6430 | continue; | |
6431 | ||
5c458ae8 | 6432 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
e5a67952 | 6433 | accept. Skip the others. */ |
5c458ae8 | 6434 | if (bp_num_list != NULL && *bp_num_list != '\0') |
e5a67952 | 6435 | { |
5c458ae8 | 6436 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
e5a67952 | 6437 | continue; |
5c458ae8 | 6438 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
e5a67952 MS |
6439 | continue; |
6440 | } | |
269b11a2 | 6441 | |
5c458ae8 | 6442 | if (show_internal || user_breakpoint_p (b)) |
e5a67952 MS |
6443 | { |
6444 | int addr_bit, type_len; | |
a6d9a66e | 6445 | |
e5a67952 MS |
6446 | addr_bit = breakpoint_address_bits (b); |
6447 | if (addr_bit > print_address_bits) | |
6448 | print_address_bits = addr_bit; | |
269b11a2 | 6449 | |
e5a67952 MS |
6450 | type_len = strlen (bptype_string (b->type)); |
6451 | if (type_len > print_type_col_width) | |
6452 | print_type_col_width = type_len; | |
6453 | ||
6454 | nr_printable_breakpoints++; | |
6455 | } | |
6456 | } | |
7f3b0473 | 6457 | |
4a2b031d TT |
6458 | { |
6459 | ui_out_emit_table table_emitter (uiout, | |
6460 | opts.addressprint ? 6 : 5, | |
6461 | nr_printable_breakpoints, | |
6462 | "BreakpointTable"); | |
6463 | ||
6464 | if (nr_printable_breakpoints > 0) | |
6465 | annotate_breakpoints_headers (); | |
6466 | if (nr_printable_breakpoints > 0) | |
6467 | annotate_field (0); | |
6468 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6469 | if (nr_printable_breakpoints > 0) | |
6470 | annotate_field (1); | |
6471 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6472 | if (nr_printable_breakpoints > 0) | |
6473 | annotate_field (2); | |
6474 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6475 | if (nr_printable_breakpoints > 0) | |
6476 | annotate_field (3); | |
6477 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6478 | if (opts.addressprint) | |
6479 | { | |
6480 | if (nr_printable_breakpoints > 0) | |
6481 | annotate_field (4); | |
6482 | if (print_address_bits <= 32) | |
6483 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6484 | else | |
6485 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6486 | } | |
6487 | if (nr_printable_breakpoints > 0) | |
6488 | annotate_field (5); | |
6489 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6490 | uiout->table_body (); | |
6491 | if (nr_printable_breakpoints > 0) | |
6492 | annotate_breakpoints_table (); | |
6493 | ||
6494 | ALL_BREAKPOINTS (b) | |
6495 | { | |
6496 | QUIT; | |
6497 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6498 | if (filter && !filter (b)) | |
6499 | continue; | |
e5a67952 | 6500 | |
5c458ae8 | 6501 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
4a2b031d | 6502 | accept. Skip the others. */ |
e5a67952 | 6503 | |
5c458ae8 | 6504 | if (bp_num_list != NULL && *bp_num_list != '\0') |
4a2b031d | 6505 | { |
5c458ae8 | 6506 | if (show_internal) /* maintenance info breakpoint */ |
4a2b031d | 6507 | { |
5c458ae8 | 6508 | if (parse_and_eval_long (bp_num_list) != b->number) |
4a2b031d TT |
6509 | continue; |
6510 | } | |
6511 | else /* all others */ | |
6512 | { | |
5c458ae8 | 6513 | if (!number_is_in_list (bp_num_list, b->number)) |
4a2b031d TT |
6514 | continue; |
6515 | } | |
6516 | } | |
6517 | /* We only print out user settable breakpoints unless the | |
5c458ae8 SM |
6518 | show_internal is set. */ |
6519 | if (show_internal || user_breakpoint_p (b)) | |
6520 | print_one_breakpoint (b, &last_loc, show_internal); | |
4a2b031d TT |
6521 | } |
6522 | } | |
698384cd | 6523 | |
7f3b0473 | 6524 | if (nr_printable_breakpoints == 0) |
c906108c | 6525 | { |
4a64f543 MS |
6526 | /* If there's a filter, let the caller decide how to report |
6527 | empty list. */ | |
d77f58be SS |
6528 | if (!filter) |
6529 | { | |
5c458ae8 | 6530 | if (bp_num_list == NULL || *bp_num_list == '\0') |
112e8700 | 6531 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6532 | else |
112e8700 | 6533 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
5c458ae8 | 6534 | bp_num_list); |
d77f58be | 6535 | } |
c906108c SS |
6536 | } |
6537 | else | |
c4093a6a | 6538 | { |
a6d9a66e UW |
6539 | if (last_loc && !server_command) |
6540 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6541 | } |
c906108c | 6542 | |
4a64f543 | 6543 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6544 | there have been breakpoints? */ |
c906108c | 6545 | annotate_breakpoints_table_end (); |
d77f58be SS |
6546 | |
6547 | return nr_printable_breakpoints; | |
c906108c SS |
6548 | } |
6549 | ||
ad443146 SS |
6550 | /* Display the value of default-collect in a way that is generally |
6551 | compatible with the breakpoint list. */ | |
6552 | ||
6553 | static void | |
6554 | default_collect_info (void) | |
6555 | { | |
79a45e25 PA |
6556 | struct ui_out *uiout = current_uiout; |
6557 | ||
ad443146 SS |
6558 | /* If it has no value (which is frequently the case), say nothing; a |
6559 | message like "No default-collect." gets in user's face when it's | |
6560 | not wanted. */ | |
6561 | if (!*default_collect) | |
6562 | return; | |
6563 | ||
6564 | /* The following phrase lines up nicely with per-tracepoint collect | |
6565 | actions. */ | |
112e8700 SM |
6566 | uiout->text ("default collect "); |
6567 | uiout->field_string ("default-collect", default_collect); | |
6568 | uiout->text (" \n"); | |
ad443146 SS |
6569 | } |
6570 | ||
c906108c | 6571 | static void |
0b39b52e | 6572 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6573 | { |
5c458ae8 | 6574 | breakpoint_1 (args, false, NULL); |
ad443146 SS |
6575 | |
6576 | default_collect_info (); | |
d77f58be SS |
6577 | } |
6578 | ||
6579 | static void | |
1d12d88f | 6580 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6581 | { |
5c458ae8 | 6582 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
79a45e25 | 6583 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6584 | |
6585 | if (num_printed == 0) | |
6586 | { | |
e5a67952 | 6587 | if (args == NULL || *args == '\0') |
112e8700 | 6588 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6589 | else |
112e8700 | 6590 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6591 | } |
c906108c SS |
6592 | } |
6593 | ||
7a292a7a | 6594 | static void |
4495129a | 6595 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6596 | { |
5c458ae8 | 6597 | breakpoint_1 (args, true, NULL); |
ad443146 SS |
6598 | |
6599 | default_collect_info (); | |
c906108c SS |
6600 | } |
6601 | ||
0d381245 | 6602 | static int |
714835d5 | 6603 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6604 | struct program_space *pspace, |
714835d5 | 6605 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6606 | { |
6607 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6608 | |
0d381245 VP |
6609 | for (; bl; bl = bl->next) |
6610 | { | |
6c95b8df PA |
6611 | if (bl->pspace == pspace |
6612 | && bl->address == pc | |
0d381245 VP |
6613 | && (!overlay_debugging || bl->section == section)) |
6614 | return 1; | |
6615 | } | |
6616 | return 0; | |
6617 | } | |
6618 | ||
672f9b60 | 6619 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6620 | concerns with logical breakpoints, so we match program spaces, not |
6621 | address spaces. */ | |
c906108c SS |
6622 | |
6623 | static void | |
6c95b8df PA |
6624 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6625 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6626 | struct obj_section *section, int thread) |
c906108c | 6627 | { |
52f0bd74 AC |
6628 | int others = 0; |
6629 | struct breakpoint *b; | |
c906108c SS |
6630 | |
6631 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6632 | others += (user_breakpoint_p (b) |
6633 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6634 | if (others > 0) |
6635 | { | |
a3f17187 AC |
6636 | if (others == 1) |
6637 | printf_filtered (_("Note: breakpoint ")); | |
6638 | else /* if (others == ???) */ | |
6639 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6640 | ALL_BREAKPOINTS (b) |
672f9b60 | 6641 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6642 | { |
6643 | others--; | |
6644 | printf_filtered ("%d", b->number); | |
6645 | if (b->thread == -1 && thread != -1) | |
6646 | printf_filtered (" (all threads)"); | |
6647 | else if (b->thread != -1) | |
6648 | printf_filtered (" (thread %d)", b->thread); | |
6649 | printf_filtered ("%s%s ", | |
059fb39f | 6650 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6651 | || b->enable_state == bp_call_disabled) |
0d381245 | 6652 | ? " (disabled)" |
0d381245 VP |
6653 | : ""), |
6654 | (others > 1) ? "," | |
6655 | : ((others == 1) ? " and" : "")); | |
6656 | } | |
6a831f06 PA |
6657 | current_uiout->message (_("also set at pc %ps.\n"), |
6658 | styled_string (address_style.style (), | |
6659 | paddress (gdbarch, pc))); | |
c906108c SS |
6660 | } |
6661 | } | |
6662 | \f | |
c906108c | 6663 | |
cb1e4e32 PA |
6664 | /* Return true iff it is meaningful to use the address member of LOC. |
6665 | For some breakpoint types, the locations' address members are | |
6666 | irrelevant and it makes no sense to attempt to compare them to | |
6667 | other addresses (or use them for any other purpose either). | |
2d134ed3 | 6668 | |
cb1e4e32 PA |
6669 | More specifically, software watchpoints and catchpoints that are |
6670 | not backed by breakpoints always have a zero valued location | |
6671 | address and we don't want to mark breakpoints of any of these types | |
6672 | to be a duplicate of an actual breakpoint location at address | |
6673 | zero. */ | |
e4f237da | 6674 | |
cb1e4e32 PA |
6675 | static bool |
6676 | bl_address_is_meaningful (bp_location *loc) | |
e4f237da | 6677 | { |
cb1e4e32 | 6678 | return loc->loc_type != bp_loc_other; |
2d134ed3 PA |
6679 | } |
6680 | ||
6681 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6682 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6683 | ||
6684 | static int | |
4a64f543 MS |
6685 | watchpoint_locations_match (struct bp_location *loc1, |
6686 | struct bp_location *loc2) | |
2d134ed3 | 6687 | { |
3a5c3e22 PA |
6688 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6689 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6690 | ||
6691 | /* Both of them must exist. */ | |
6692 | gdb_assert (w1 != NULL); | |
6693 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6694 | |
4a64f543 MS |
6695 | /* If the target can evaluate the condition expression in hardware, |
6696 | then we we need to insert both watchpoints even if they are at | |
6697 | the same place. Otherwise the watchpoint will only trigger when | |
6698 | the condition of whichever watchpoint was inserted evaluates to | |
6699 | true, not giving a chance for GDB to check the condition of the | |
6700 | other watchpoint. */ | |
3a5c3e22 | 6701 | if ((w1->cond_exp |
4a64f543 MS |
6702 | && target_can_accel_watchpoint_condition (loc1->address, |
6703 | loc1->length, | |
0cf6dd15 | 6704 | loc1->watchpoint_type, |
4d01a485 | 6705 | w1->cond_exp.get ())) |
3a5c3e22 | 6706 | || (w2->cond_exp |
4a64f543 MS |
6707 | && target_can_accel_watchpoint_condition (loc2->address, |
6708 | loc2->length, | |
0cf6dd15 | 6709 | loc2->watchpoint_type, |
4d01a485 | 6710 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6711 | return 0; |
6712 | ||
85d721b8 PA |
6713 | /* Note that this checks the owner's type, not the location's. In |
6714 | case the target does not support read watchpoints, but does | |
6715 | support access watchpoints, we'll have bp_read_watchpoint | |
6716 | watchpoints with hw_access locations. Those should be considered | |
6717 | duplicates of hw_read locations. The hw_read locations will | |
6718 | become hw_access locations later. */ | |
2d134ed3 PA |
6719 | return (loc1->owner->type == loc2->owner->type |
6720 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6721 | && loc1->address == loc2->address | |
6722 | && loc1->length == loc2->length); | |
e4f237da KB |
6723 | } |
6724 | ||
31e77af2 | 6725 | /* See breakpoint.h. */ |
6c95b8df | 6726 | |
31e77af2 | 6727 | int |
accd0bcd YQ |
6728 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6729 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6730 | { |
f5656ead | 6731 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6732 | || aspace1 == aspace2) |
6733 | && addr1 == addr2); | |
6734 | } | |
6735 | ||
f1310107 TJB |
6736 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6737 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6738 | matches ASPACE2. On targets that have global breakpoints, the address | |
6739 | space doesn't really matter. */ | |
6740 | ||
6741 | static int | |
accd0bcd YQ |
6742 | breakpoint_address_match_range (const address_space *aspace1, |
6743 | CORE_ADDR addr1, | |
6744 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6745 | CORE_ADDR addr2) |
6746 | { | |
f5656ead | 6747 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6748 | || aspace1 == aspace2) |
6749 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6750 | } | |
6751 | ||
6752 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6753 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6754 | matches the breakpoint's address space. On targets that have global | |
6755 | breakpoints, the address space doesn't really matter. */ | |
6756 | ||
6757 | static int | |
6758 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6759 | const address_space *aspace, |
f1310107 TJB |
6760 | CORE_ADDR addr) |
6761 | { | |
6762 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6763 | aspace, addr) | |
6764 | || (bl->length | |
6765 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6766 | bl->address, bl->length, | |
6767 | aspace, addr))); | |
6768 | } | |
6769 | ||
d35ae833 PA |
6770 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6771 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6772 | match happens only if ASPACE matches the breakpoint's address | |
6773 | space. On targets that have global breakpoints, the address space | |
6774 | doesn't really matter. */ | |
6775 | ||
6776 | static int | |
6777 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6778 | const address_space *aspace, |
d35ae833 PA |
6779 | CORE_ADDR addr, int len) |
6780 | { | |
6781 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6782 | || bl->pspace->aspace == aspace) | |
6783 | { | |
6784 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6785 | ||
6786 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
6787 | return 1; | |
6788 | } | |
6789 | return 0; | |
6790 | } | |
6791 | ||
1e4d1764 YQ |
6792 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6793 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6794 | true, otherwise returns false. */ | |
6795 | ||
6796 | static int | |
6797 | tracepoint_locations_match (struct bp_location *loc1, | |
6798 | struct bp_location *loc2) | |
6799 | { | |
6800 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6801 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6802 | locations at the same address of different tracepoints are regarded as | |
6803 | different locations. */ | |
6804 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6805 | else | |
6806 | return 0; | |
6807 | } | |
6808 | ||
2d134ed3 | 6809 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
cb1e4e32 PA |
6810 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
6811 | the same location. */ | |
2d134ed3 PA |
6812 | |
6813 | static int | |
4a64f543 MS |
6814 | breakpoint_locations_match (struct bp_location *loc1, |
6815 | struct bp_location *loc2) | |
2d134ed3 | 6816 | { |
2bdf28a0 JK |
6817 | int hw_point1, hw_point2; |
6818 | ||
6819 | /* Both of them must not be in moribund_locations. */ | |
6820 | gdb_assert (loc1->owner != NULL); | |
6821 | gdb_assert (loc2->owner != NULL); | |
6822 | ||
6823 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6824 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6825 | |
6826 | if (hw_point1 != hw_point2) | |
6827 | return 0; | |
6828 | else if (hw_point1) | |
6829 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6830 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6831 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6832 | else |
f1310107 TJB |
6833 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6834 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6835 | loc2->pspace->aspace, loc2->address) | |
6836 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6837 | } |
6838 | ||
76897487 KB |
6839 | static void |
6840 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6841 | int bnum, int have_bnum) | |
6842 | { | |
f63fbe86 MS |
6843 | /* The longest string possibly returned by hex_string_custom |
6844 | is 50 chars. These must be at least that big for safety. */ | |
6845 | char astr1[64]; | |
6846 | char astr2[64]; | |
76897487 | 6847 | |
bb599908 PH |
6848 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6849 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6850 | if (have_bnum) |
8a3fe4f8 | 6851 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6852 | bnum, astr1, astr2); |
6853 | else | |
8a3fe4f8 | 6854 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6855 | } |
6856 | ||
4a64f543 MS |
6857 | /* Adjust a breakpoint's address to account for architectural |
6858 | constraints on breakpoint placement. Return the adjusted address. | |
6859 | Note: Very few targets require this kind of adjustment. For most | |
6860 | targets, this function is simply the identity function. */ | |
76897487 KB |
6861 | |
6862 | static CORE_ADDR | |
a6d9a66e UW |
6863 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6864 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6865 | { |
a0de8c21 YQ |
6866 | if (bptype == bp_watchpoint |
6867 | || bptype == bp_hardware_watchpoint | |
6868 | || bptype == bp_read_watchpoint | |
6869 | || bptype == bp_access_watchpoint | |
6870 | || bptype == bp_catchpoint) | |
88f7da05 KB |
6871 | { |
6872 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6873 | have their addresses modified. */ | |
6874 | return bpaddr; | |
6875 | } | |
7c16b83e PA |
6876 | else if (bptype == bp_single_step) |
6877 | { | |
6878 | /* Single-step breakpoints should not have their addresses | |
6879 | modified. If there's any architectural constrain that | |
6880 | applies to this address, then it should have already been | |
6881 | taken into account when the breakpoint was created in the | |
6882 | first place. If we didn't do this, stepping through e.g., | |
6883 | Thumb-2 IT blocks would break. */ | |
6884 | return bpaddr; | |
6885 | } | |
76897487 KB |
6886 | else |
6887 | { | |
a0de8c21 YQ |
6888 | CORE_ADDR adjusted_bpaddr = bpaddr; |
6889 | ||
6890 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) | |
6891 | { | |
6892 | /* Some targets have architectural constraints on the placement | |
6893 | of breakpoint instructions. Obtain the adjusted address. */ | |
6894 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); | |
6895 | } | |
76897487 | 6896 | |
a0de8c21 | 6897 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
76897487 KB |
6898 | |
6899 | /* An adjusted breakpoint address can significantly alter | |
6900 | a user's expectations. Print a warning if an adjustment | |
6901 | is required. */ | |
6902 | if (adjusted_bpaddr != bpaddr) | |
6903 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6904 | ||
6905 | return adjusted_bpaddr; | |
6906 | } | |
6907 | } | |
6908 | ||
cb1e4e32 PA |
6909 | static bp_loc_type |
6910 | bp_location_from_bp_type (bptype type) | |
7cc221ef | 6911 | { |
cb1e4e32 | 6912 | switch (type) |
e049a4b5 DJ |
6913 | { |
6914 | case bp_breakpoint: | |
7c16b83e | 6915 | case bp_single_step: |
e049a4b5 DJ |
6916 | case bp_until: |
6917 | case bp_finish: | |
6918 | case bp_longjmp: | |
6919 | case bp_longjmp_resume: | |
e2e4d78b | 6920 | case bp_longjmp_call_dummy: |
186c406b TT |
6921 | case bp_exception: |
6922 | case bp_exception_resume: | |
e049a4b5 | 6923 | case bp_step_resume: |
2c03e5be | 6924 | case bp_hp_step_resume: |
e049a4b5 DJ |
6925 | case bp_watchpoint_scope: |
6926 | case bp_call_dummy: | |
aa7d318d | 6927 | case bp_std_terminate: |
e049a4b5 DJ |
6928 | case bp_shlib_event: |
6929 | case bp_thread_event: | |
6930 | case bp_overlay_event: | |
4efc6507 | 6931 | case bp_jit_event: |
0fd8e87f | 6932 | case bp_longjmp_master: |
aa7d318d | 6933 | case bp_std_terminate_master: |
186c406b | 6934 | case bp_exception_master: |
0e30163f JK |
6935 | case bp_gnu_ifunc_resolver: |
6936 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6937 | case bp_dprintf: |
cb1e4e32 | 6938 | return bp_loc_software_breakpoint; |
e049a4b5 | 6939 | case bp_hardware_breakpoint: |
cb1e4e32 | 6940 | return bp_loc_hardware_breakpoint; |
e049a4b5 DJ |
6941 | case bp_hardware_watchpoint: |
6942 | case bp_read_watchpoint: | |
6943 | case bp_access_watchpoint: | |
cb1e4e32 | 6944 | return bp_loc_hardware_watchpoint; |
e049a4b5 | 6945 | case bp_watchpoint: |
ce78b96d | 6946 | case bp_catchpoint: |
15c3d785 PA |
6947 | case bp_tracepoint: |
6948 | case bp_fast_tracepoint: | |
0fb4aa4b | 6949 | case bp_static_tracepoint: |
cb1e4e32 | 6950 | return bp_loc_other; |
e049a4b5 | 6951 | default: |
e2e0b3e5 | 6952 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 | 6953 | } |
cb1e4e32 PA |
6954 | } |
6955 | ||
6956 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) | |
6957 | { | |
6958 | this->owner = owner; | |
6959 | this->cond_bytecode = NULL; | |
6960 | this->shlib_disabled = 0; | |
6961 | this->enabled = 1; | |
6962 | ||
6963 | this->loc_type = type; | |
e049a4b5 | 6964 | |
cb1e4e32 PA |
6965 | if (this->loc_type == bp_loc_software_breakpoint |
6966 | || this->loc_type == bp_loc_hardware_breakpoint) | |
6967 | mark_breakpoint_location_modified (this); | |
6968 | ||
6969 | this->refc = 1; | |
6970 | } | |
6971 | ||
6972 | bp_location::bp_location (breakpoint *owner) | |
6973 | : bp_location::bp_location (owner, | |
6974 | bp_location_from_bp_type (owner->type)) | |
6975 | { | |
28010a5d PA |
6976 | } |
6977 | ||
6978 | /* Allocate a struct bp_location. */ | |
6979 | ||
6980 | static struct bp_location * | |
6981 | allocate_bp_location (struct breakpoint *bpt) | |
6982 | { | |
348d480f PA |
6983 | return bpt->ops->allocate_location (bpt); |
6984 | } | |
7cc221ef | 6985 | |
f431efe5 PA |
6986 | static void |
6987 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6988 | { |
4d01a485 | 6989 | delete loc; |
fe3f5fa8 VP |
6990 | } |
6991 | ||
f431efe5 PA |
6992 | /* Increment reference count. */ |
6993 | ||
6994 | static void | |
6995 | incref_bp_location (struct bp_location *bl) | |
6996 | { | |
6997 | ++bl->refc; | |
6998 | } | |
6999 | ||
7000 | /* Decrement reference count. If the reference count reaches 0, | |
7001 | destroy the bp_location. Sets *BLP to NULL. */ | |
7002 | ||
7003 | static void | |
7004 | decref_bp_location (struct bp_location **blp) | |
7005 | { | |
0807b50c PA |
7006 | gdb_assert ((*blp)->refc > 0); |
7007 | ||
f431efe5 PA |
7008 | if (--(*blp)->refc == 0) |
7009 | free_bp_location (*blp); | |
7010 | *blp = NULL; | |
7011 | } | |
7012 | ||
346774a9 | 7013 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7014 | |
b270e6f9 TT |
7015 | static breakpoint * |
7016 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7017 | { |
346774a9 | 7018 | struct breakpoint *b1; |
b270e6f9 | 7019 | struct breakpoint *result = b.get (); |
c906108c | 7020 | |
346774a9 PA |
7021 | /* Add this breakpoint to the end of the chain so that a list of |
7022 | breakpoints will come out in order of increasing numbers. */ | |
7023 | ||
7024 | b1 = breakpoint_chain; | |
7025 | if (b1 == 0) | |
b270e6f9 | 7026 | breakpoint_chain = b.release (); |
346774a9 PA |
7027 | else |
7028 | { | |
7029 | while (b1->next) | |
7030 | b1 = b1->next; | |
b270e6f9 | 7031 | b1->next = b.release (); |
346774a9 | 7032 | } |
b270e6f9 TT |
7033 | |
7034 | return result; | |
346774a9 PA |
7035 | } |
7036 | ||
7037 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7038 | ||
7039 | static void | |
7040 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7041 | struct gdbarch *gdbarch, | |
28010a5d | 7042 | enum bptype bptype, |
c0a91b2b | 7043 | const struct breakpoint_ops *ops) |
346774a9 | 7044 | { |
348d480f PA |
7045 | gdb_assert (ops != NULL); |
7046 | ||
28010a5d | 7047 | b->ops = ops; |
4d28f7a8 | 7048 | b->type = bptype; |
a6d9a66e | 7049 | b->gdbarch = gdbarch; |
c906108c SS |
7050 | b->language = current_language->la_language; |
7051 | b->input_radix = input_radix; | |
d0fb5eae | 7052 | b->related_breakpoint = b; |
346774a9 PA |
7053 | } |
7054 | ||
7055 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7056 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7057 | |
7058 | static struct breakpoint * | |
7059 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7060 | enum bptype bptype, |
c0a91b2b | 7061 | const struct breakpoint_ops *ops) |
346774a9 | 7062 | { |
3b0871f4 | 7063 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7064 | |
3b0871f4 | 7065 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7066 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7067 | } |
7068 | ||
0ba852ab | 7069 | /* Initialize loc->function_name. */ |
0e30163f | 7070 | |
0d381245 | 7071 | static void |
0ba852ab | 7072 | set_breakpoint_location_function (struct bp_location *loc) |
0d381245 | 7073 | { |
2bdf28a0 JK |
7074 | gdb_assert (loc->owner != NULL); |
7075 | ||
0d381245 | 7076 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7077 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7078 | || is_tracepoint (loc->owner)) |
0d381245 | 7079 | { |
2c02bd72 | 7080 | const char *function_name; |
0e30163f | 7081 | |
3467ec66 | 7082 | if (loc->msymbol != NULL |
f50776aa | 7083 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
0ba852ab | 7084 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)) |
0e30163f JK |
7085 | { |
7086 | struct breakpoint *b = loc->owner; | |
7087 | ||
c9d95fa3 | 7088 | function_name = loc->msymbol->linkage_name (); |
3467ec66 PA |
7089 | |
7090 | if (b->type == bp_breakpoint && b->loc == loc | |
7091 | && loc->next == NULL && b->related_breakpoint == b) | |
0e30163f JK |
7092 | { |
7093 | /* Create only the whole new breakpoint of this type but do not | |
7094 | mess more complicated breakpoints with multiple locations. */ | |
7095 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7096 | /* Remember the resolver's address for use by the return |
7097 | breakpoint. */ | |
3467ec66 | 7098 | loc->related_address = loc->address; |
0e30163f JK |
7099 | } |
7100 | } | |
3467ec66 PA |
7101 | else |
7102 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); | |
0e30163f | 7103 | |
2c02bd72 DE |
7104 | if (function_name) |
7105 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7106 | } |
7107 | } | |
7108 | ||
a6d9a66e | 7109 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7110 | struct gdbarch * |
a6d9a66e UW |
7111 | get_sal_arch (struct symtab_and_line sal) |
7112 | { | |
7113 | if (sal.section) | |
7114 | return get_objfile_arch (sal.section->objfile); | |
7115 | if (sal.symtab) | |
eb822aa6 | 7116 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7117 | |
7118 | return NULL; | |
7119 | } | |
7120 | ||
346774a9 PA |
7121 | /* Low level routine for partially initializing a breakpoint of type |
7122 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7123 | file name, and line number are provided by SAL. |
0d381245 VP |
7124 | |
7125 | It is expected that the caller will complete the initialization of | |
7126 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7127 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7128 | |
346774a9 PA |
7129 | static void |
7130 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7131 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7132 | const struct breakpoint_ops *ops) |
0d381245 | 7133 | { |
28010a5d | 7134 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7135 | |
3742cc8b | 7136 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7137 | |
6c95b8df PA |
7138 | if (bptype != bp_catchpoint) |
7139 | gdb_assert (sal.pspace != NULL); | |
7140 | ||
f8eba3c6 TT |
7141 | /* Store the program space that was used to set the breakpoint, |
7142 | except for ordinary breakpoints, which are independent of the | |
7143 | program space. */ | |
7144 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7145 | b->pspace = sal.pspace; | |
346774a9 | 7146 | } |
c906108c | 7147 | |
346774a9 PA |
7148 | /* set_raw_breakpoint is a low level routine for allocating and |
7149 | partially initializing a breakpoint of type BPTYPE. The newly | |
7150 | created breakpoint's address, section, source file name, and line | |
7151 | number are provided by SAL. The newly created and partially | |
7152 | initialized breakpoint is added to the breakpoint chain and | |
7153 | is also returned as the value of this function. | |
7154 | ||
7155 | It is expected that the caller will complete the initialization of | |
7156 | the newly created breakpoint struct as well as output any status | |
7157 | information regarding the creation of a new breakpoint. In | |
7158 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7159 | number! Care should be taken to not allow an error to occur | |
7160 | prior to completing the initialization of the breakpoint. If this | |
7161 | should happen, a bogus breakpoint will be left on the chain. */ | |
7162 | ||
7163 | struct breakpoint * | |
7164 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7165 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7166 | const struct breakpoint_ops *ops) |
346774a9 | 7167 | { |
3b0871f4 | 7168 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7169 | |
3b0871f4 | 7170 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7171 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7172 | } |
7173 | ||
53a5351d | 7174 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7175 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7176 | initiated the operation. */ | |
c906108c SS |
7177 | |
7178 | void | |
186c406b | 7179 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7180 | { |
35df4500 | 7181 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7182 | int thread = tp->global_num; |
0fd8e87f UW |
7183 | |
7184 | /* To avoid having to rescan all objfile symbols at every step, | |
7185 | we maintain a list of continually-inserted but always disabled | |
7186 | longjmp "master" breakpoints. Here, we simply create momentary | |
7187 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7188 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7189 | if (b->pspace == current_program_space |
186c406b TT |
7190 | && (b->type == bp_longjmp_master |
7191 | || b->type == bp_exception_master)) | |
0fd8e87f | 7192 | { |
06edf0c0 PA |
7193 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7194 | struct breakpoint *clone; | |
cc59ec59 | 7195 | |
e2e4d78b JK |
7196 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7197 | after their removal. */ | |
06edf0c0 | 7198 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7199 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7200 | clone->thread = thread; |
7201 | } | |
186c406b TT |
7202 | |
7203 | tp->initiating_frame = frame; | |
c906108c SS |
7204 | } |
7205 | ||
611c83ae | 7206 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7207 | void |
611c83ae | 7208 | delete_longjmp_breakpoint (int thread) |
c906108c | 7209 | { |
35df4500 | 7210 | struct breakpoint *b, *b_tmp; |
c906108c | 7211 | |
35df4500 | 7212 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7213 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7214 | { |
7215 | if (b->thread == thread) | |
7216 | delete_breakpoint (b); | |
7217 | } | |
c906108c SS |
7218 | } |
7219 | ||
f59f708a PA |
7220 | void |
7221 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7222 | { | |
7223 | struct breakpoint *b, *b_tmp; | |
7224 | ||
7225 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7226 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7227 | { | |
7228 | if (b->thread == thread) | |
7229 | b->disposition = disp_del_at_next_stop; | |
7230 | } | |
7231 | } | |
7232 | ||
e2e4d78b JK |
7233 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7234 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7235 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7236 | breakpoints. */ | |
7237 | ||
7238 | struct breakpoint * | |
7239 | set_longjmp_breakpoint_for_call_dummy (void) | |
7240 | { | |
7241 | struct breakpoint *b, *retval = NULL; | |
7242 | ||
7243 | ALL_BREAKPOINTS (b) | |
7244 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7245 | { | |
7246 | struct breakpoint *new_b; | |
7247 | ||
7248 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7249 | &momentary_breakpoint_ops, |
7250 | 1); | |
00431a78 | 7251 | new_b->thread = inferior_thread ()->global_num; |
e2e4d78b JK |
7252 | |
7253 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7254 | ||
7255 | gdb_assert (new_b->related_breakpoint == new_b); | |
7256 | if (retval == NULL) | |
7257 | retval = new_b; | |
7258 | new_b->related_breakpoint = retval; | |
7259 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7260 | retval = retval->related_breakpoint; | |
7261 | retval->related_breakpoint = new_b; | |
7262 | } | |
7263 | ||
7264 | return retval; | |
7265 | } | |
7266 | ||
7267 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7268 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7269 | stack. |
7270 | ||
7271 | You should call this function only at places where it is safe to currently | |
7272 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7273 | frames. */ | |
7274 | ||
7275 | void | |
b67a2c6f | 7276 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7277 | { |
7278 | struct breakpoint *b, *b_tmp; | |
7279 | ||
7280 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7281 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7282 | { |
7283 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7284 | ||
7285 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7286 | dummy_b = dummy_b->related_breakpoint; | |
7287 | if (dummy_b->type != bp_call_dummy | |
7288 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7289 | continue; | |
7290 | ||
00431a78 | 7291 | dummy_frame_discard (dummy_b->frame_id, tp); |
e2e4d78b JK |
7292 | |
7293 | while (b->related_breakpoint != b) | |
7294 | { | |
7295 | if (b_tmp == b->related_breakpoint) | |
7296 | b_tmp = b->related_breakpoint->next; | |
7297 | delete_breakpoint (b->related_breakpoint); | |
7298 | } | |
7299 | delete_breakpoint (b); | |
7300 | } | |
7301 | } | |
7302 | ||
1900040c MS |
7303 | void |
7304 | enable_overlay_breakpoints (void) | |
7305 | { | |
52f0bd74 | 7306 | struct breakpoint *b; |
1900040c MS |
7307 | |
7308 | ALL_BREAKPOINTS (b) | |
7309 | if (b->type == bp_overlay_event) | |
7310 | { | |
7311 | b->enable_state = bp_enabled; | |
44702360 | 7312 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7313 | overlay_events_enabled = 1; |
1900040c MS |
7314 | } |
7315 | } | |
7316 | ||
7317 | void | |
7318 | disable_overlay_breakpoints (void) | |
7319 | { | |
52f0bd74 | 7320 | struct breakpoint *b; |
1900040c MS |
7321 | |
7322 | ALL_BREAKPOINTS (b) | |
7323 | if (b->type == bp_overlay_event) | |
7324 | { | |
7325 | b->enable_state = bp_disabled; | |
44702360 | 7326 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7327 | overlay_events_enabled = 0; |
1900040c MS |
7328 | } |
7329 | } | |
7330 | ||
aa7d318d TT |
7331 | /* Set an active std::terminate breakpoint for each std::terminate |
7332 | master breakpoint. */ | |
7333 | void | |
7334 | set_std_terminate_breakpoint (void) | |
7335 | { | |
35df4500 | 7336 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7337 | |
35df4500 | 7338 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7339 | if (b->pspace == current_program_space |
7340 | && b->type == bp_std_terminate_master) | |
7341 | { | |
06edf0c0 | 7342 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7343 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7344 | } |
7345 | } | |
7346 | ||
7347 | /* Delete all the std::terminate breakpoints. */ | |
7348 | void | |
7349 | delete_std_terminate_breakpoint (void) | |
7350 | { | |
35df4500 | 7351 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7352 | |
35df4500 | 7353 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7354 | if (b->type == bp_std_terminate) |
7355 | delete_breakpoint (b); | |
7356 | } | |
7357 | ||
c4093a6a | 7358 | struct breakpoint * |
a6d9a66e | 7359 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7360 | { |
7361 | struct breakpoint *b; | |
c4093a6a | 7362 | |
06edf0c0 PA |
7363 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7364 | &internal_breakpoint_ops); | |
7365 | ||
b5de0fa7 | 7366 | b->enable_state = bp_enabled; |
f00aae0f | 7367 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7368 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7369 | |
44702360 | 7370 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7371 | |
c4093a6a JM |
7372 | return b; |
7373 | } | |
7374 | ||
0101ce28 JJ |
7375 | struct lang_and_radix |
7376 | { | |
7377 | enum language lang; | |
7378 | int radix; | |
7379 | }; | |
7380 | ||
4efc6507 DE |
7381 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7382 | ||
7383 | struct breakpoint * | |
7384 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7385 | { | |
2a7f3dff PA |
7386 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7387 | &internal_breakpoint_ops); | |
4efc6507 | 7388 | } |
0101ce28 | 7389 | |
03673fc7 PP |
7390 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7391 | ||
7392 | void | |
7393 | remove_jit_event_breakpoints (void) | |
7394 | { | |
7395 | struct breakpoint *b, *b_tmp; | |
7396 | ||
7397 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7398 | if (b->type == bp_jit_event | |
7399 | && b->loc->pspace == current_program_space) | |
7400 | delete_breakpoint (b); | |
7401 | } | |
7402 | ||
cae688ec JJ |
7403 | void |
7404 | remove_solib_event_breakpoints (void) | |
7405 | { | |
35df4500 | 7406 | struct breakpoint *b, *b_tmp; |
cae688ec | 7407 | |
35df4500 | 7408 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7409 | if (b->type == bp_shlib_event |
7410 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7411 | delete_breakpoint (b); |
7412 | } | |
7413 | ||
f37f681c PA |
7414 | /* See breakpoint.h. */ |
7415 | ||
7416 | void | |
7417 | remove_solib_event_breakpoints_at_next_stop (void) | |
7418 | { | |
7419 | struct breakpoint *b, *b_tmp; | |
7420 | ||
7421 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7422 | if (b->type == bp_shlib_event | |
7423 | && b->loc->pspace == current_program_space) | |
7424 | b->disposition = disp_del_at_next_stop; | |
7425 | } | |
7426 | ||
04086b45 PA |
7427 | /* Helper for create_solib_event_breakpoint / |
7428 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7429 | INSERT_MODE to pass through to update_global_location_list. */ | |
7430 | ||
7431 | static struct breakpoint * | |
7432 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7433 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7434 | { |
7435 | struct breakpoint *b; | |
7436 | ||
06edf0c0 PA |
7437 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7438 | &internal_breakpoint_ops); | |
04086b45 | 7439 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7440 | return b; |
7441 | } | |
7442 | ||
04086b45 PA |
7443 | struct breakpoint * |
7444 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7445 | { | |
7446 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7447 | } | |
7448 | ||
f37f681c PA |
7449 | /* See breakpoint.h. */ |
7450 | ||
7451 | struct breakpoint * | |
7452 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7453 | { | |
7454 | struct breakpoint *b; | |
7455 | ||
04086b45 PA |
7456 | /* Explicitly tell update_global_location_list to insert |
7457 | locations. */ | |
7458 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7459 | if (!b->loc->inserted) |
7460 | { | |
7461 | delete_breakpoint (b); | |
7462 | return NULL; | |
7463 | } | |
7464 | return b; | |
7465 | } | |
7466 | ||
cae688ec JJ |
7467 | /* Disable any breakpoints that are on code in shared libraries. Only |
7468 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7469 | ||
7470 | void | |
cb851954 | 7471 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7472 | { |
876fa593 | 7473 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7474 | |
876fa593 | 7475 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7476 | { |
2bdf28a0 | 7477 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7478 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7479 | |
4a64f543 MS |
7480 | /* We apply the check to all breakpoints, including disabled for |
7481 | those with loc->duplicate set. This is so that when breakpoint | |
7482 | becomes enabled, or the duplicate is removed, gdb will try to | |
7483 | insert all breakpoints. If we don't set shlib_disabled here, | |
7484 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7485 | if (((b->type == bp_breakpoint) |
508ccb1f | 7486 | || (b->type == bp_jit_event) |
1042e4c0 | 7487 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7488 | || (is_tracepoint (b))) |
6c95b8df | 7489 | && loc->pspace == current_program_space |
0d381245 | 7490 | && !loc->shlib_disabled |
6c95b8df | 7491 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7492 | ) |
0d381245 VP |
7493 | { |
7494 | loc->shlib_disabled = 1; | |
7495 | } | |
cae688ec JJ |
7496 | } |
7497 | } | |
7498 | ||
63644780 NB |
7499 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7500 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7501 | disabled ones can just stay disabled. */ | |
84acb35a | 7502 | |
75149521 | 7503 | static void |
84acb35a JJ |
7504 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7505 | { | |
876fa593 | 7506 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7507 | int disabled_shlib_breaks = 0; |
7508 | ||
876fa593 | 7509 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7510 | { |
2bdf28a0 | 7511 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7512 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7513 | |
1e4d1764 | 7514 | if (solib->pspace == loc->pspace |
e2dd7057 | 7515 | && !loc->shlib_disabled |
1e4d1764 YQ |
7516 | && (((b->type == bp_breakpoint |
7517 | || b->type == bp_jit_event | |
7518 | || b->type == bp_hardware_breakpoint) | |
7519 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7520 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7521 | || is_tracepoint (b)) | |
e2dd7057 | 7522 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7523 | { |
e2dd7057 PP |
7524 | loc->shlib_disabled = 1; |
7525 | /* At this point, we cannot rely on remove_breakpoint | |
7526 | succeeding so we must mark the breakpoint as not inserted | |
7527 | to prevent future errors occurring in remove_breakpoints. */ | |
7528 | loc->inserted = 0; | |
8d3788bd VP |
7529 | |
7530 | /* This may cause duplicate notifications for the same breakpoint. */ | |
76727919 | 7531 | gdb::observers::breakpoint_modified.notify (b); |
8d3788bd | 7532 | |
e2dd7057 PP |
7533 | if (!disabled_shlib_breaks) |
7534 | { | |
223ffa71 | 7535 | target_terminal::ours_for_output (); |
3e43a32a MS |
7536 | warning (_("Temporarily disabling breakpoints " |
7537 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7538 | solib->so_name); |
84acb35a | 7539 | } |
e2dd7057 | 7540 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7541 | } |
7542 | } | |
84acb35a JJ |
7543 | } |
7544 | ||
63644780 NB |
7545 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7546 | notification of free_objfile. Only apply to enabled breakpoints, | |
7547 | disabled ones can just stay disabled. */ | |
7548 | ||
7549 | static void | |
7550 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7551 | { | |
7552 | struct breakpoint *b; | |
7553 | ||
7554 | if (objfile == NULL) | |
7555 | return; | |
7556 | ||
d03de421 PA |
7557 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7558 | managed by the user with add-symbol-file/remove-symbol-file. | |
7559 | Similarly to how breakpoints in shared libraries are handled in | |
7560 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7561 | shlib_disabled so they end up uninserted on the next global |
7562 | location list update. Shared libraries not loaded by the user | |
7563 | aren't handled here -- they're already handled in | |
7564 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7565 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7566 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7567 | main objfile). */ | |
7568 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7569 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7570 | return; |
7571 | ||
7572 | ALL_BREAKPOINTS (b) | |
7573 | { | |
7574 | struct bp_location *loc; | |
7575 | int bp_modified = 0; | |
7576 | ||
7577 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7578 | continue; | |
7579 | ||
7580 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7581 | { | |
7582 | CORE_ADDR loc_addr = loc->address; | |
7583 | ||
7584 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7585 | && loc->loc_type != bp_loc_software_breakpoint) | |
7586 | continue; | |
7587 | ||
7588 | if (loc->shlib_disabled != 0) | |
7589 | continue; | |
7590 | ||
7591 | if (objfile->pspace != loc->pspace) | |
7592 | continue; | |
7593 | ||
7594 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7595 | && loc->loc_type != bp_loc_software_breakpoint) | |
7596 | continue; | |
7597 | ||
7598 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7599 | { | |
7600 | loc->shlib_disabled = 1; | |
08351840 PA |
7601 | /* At this point, we don't know whether the object was |
7602 | unmapped from the inferior or not, so leave the | |
7603 | inserted flag alone. We'll handle failure to | |
7604 | uninsert quietly, in case the object was indeed | |
7605 | unmapped. */ | |
63644780 NB |
7606 | |
7607 | mark_breakpoint_location_modified (loc); | |
7608 | ||
7609 | bp_modified = 1; | |
7610 | } | |
7611 | } | |
7612 | ||
7613 | if (bp_modified) | |
76727919 | 7614 | gdb::observers::breakpoint_modified.notify (b); |
63644780 NB |
7615 | } |
7616 | } | |
7617 | ||
ce78b96d JB |
7618 | /* FORK & VFORK catchpoints. */ |
7619 | ||
e29a4733 | 7620 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7621 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7622 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7623 | |
c1fc2657 | 7624 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7625 | { |
e29a4733 PA |
7626 | /* Process id of a child process whose forking triggered this |
7627 | catchpoint. This field is only valid immediately after this | |
7628 | catchpoint has triggered. */ | |
7629 | ptid_t forked_inferior_pid; | |
7630 | }; | |
7631 | ||
4a64f543 MS |
7632 | /* Implement the "insert" breakpoint_ops method for fork |
7633 | catchpoints. */ | |
ce78b96d | 7634 | |
77b06cd7 TJB |
7635 | static int |
7636 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7637 | { |
e99b03dc | 7638 | return target_insert_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7639 | } |
7640 | ||
4a64f543 MS |
7641 | /* Implement the "remove" breakpoint_ops method for fork |
7642 | catchpoints. */ | |
ce78b96d JB |
7643 | |
7644 | static int | |
73971819 | 7645 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7646 | { |
e99b03dc | 7647 | return target_remove_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7648 | } |
7649 | ||
7650 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7651 | catchpoints. */ | |
7652 | ||
7653 | static int | |
f1310107 | 7654 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
bd522513 | 7655 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7656 | const struct target_waitstatus *ws) |
ce78b96d | 7657 | { |
e29a4733 PA |
7658 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7659 | ||
f90263c1 TT |
7660 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7661 | return 0; | |
7662 | ||
7663 | c->forked_inferior_pid = ws->value.related_pid; | |
7664 | return 1; | |
ce78b96d JB |
7665 | } |
7666 | ||
4a64f543 MS |
7667 | /* Implement the "print_it" breakpoint_ops method for fork |
7668 | catchpoints. */ | |
ce78b96d JB |
7669 | |
7670 | static enum print_stop_action | |
348d480f | 7671 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7672 | { |
36dfb11c | 7673 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7674 | struct breakpoint *b = bs->breakpoint_at; |
7675 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7676 | |
ce78b96d | 7677 | annotate_catchpoint (b->number); |
f303dbd6 | 7678 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7679 | if (b->disposition == disp_del) |
112e8700 | 7680 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7681 | else |
112e8700 SM |
7682 | uiout->text ("Catchpoint "); |
7683 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7684 | { |
112e8700 SM |
7685 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7686 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7687 | } |
381befee | 7688 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7689 | uiout->text (" (forked process "); |
381befee | 7690 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7691 | uiout->text ("), "); |
ce78b96d JB |
7692 | return PRINT_SRC_AND_LOC; |
7693 | } | |
7694 | ||
4a64f543 MS |
7695 | /* Implement the "print_one" breakpoint_ops method for fork |
7696 | catchpoints. */ | |
ce78b96d JB |
7697 | |
7698 | static void | |
a6d9a66e | 7699 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7700 | { |
e29a4733 | 7701 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7702 | struct value_print_options opts; |
79a45e25 | 7703 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7704 | |
7705 | get_user_print_options (&opts); | |
7706 | ||
4a64f543 MS |
7707 | /* Field 4, the address, is omitted (which makes the columns not |
7708 | line up too nicely with the headers, but the effect is relatively | |
7709 | readable). */ | |
79a45b7d | 7710 | if (opts.addressprint) |
112e8700 | 7711 | uiout->field_skip ("addr"); |
ce78b96d | 7712 | annotate_field (5); |
112e8700 | 7713 | uiout->text ("fork"); |
d7e15655 | 7714 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7715 | { |
112e8700 | 7716 | uiout->text (", process "); |
381befee | 7717 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7718 | uiout->spaces (1); |
ce78b96d | 7719 | } |
8ac3646f | 7720 | |
112e8700 SM |
7721 | if (uiout->is_mi_like_p ()) |
7722 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
7723 | } |
7724 | ||
7725 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7726 | catchpoints. */ | |
7727 | ||
7728 | static void | |
7729 | print_mention_catch_fork (struct breakpoint *b) | |
7730 | { | |
7731 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7732 | } | |
7733 | ||
6149aea9 PA |
7734 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7735 | catchpoints. */ | |
7736 | ||
7737 | static void | |
7738 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7739 | { | |
7740 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7741 | print_recreate_thread (b, fp); |
6149aea9 PA |
7742 | } |
7743 | ||
ce78b96d JB |
7744 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7745 | ||
2060206e | 7746 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7747 | |
4a64f543 MS |
7748 | /* Implement the "insert" breakpoint_ops method for vfork |
7749 | catchpoints. */ | |
ce78b96d | 7750 | |
77b06cd7 TJB |
7751 | static int |
7752 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7753 | { |
e99b03dc | 7754 | return target_insert_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7755 | } |
7756 | ||
4a64f543 MS |
7757 | /* Implement the "remove" breakpoint_ops method for vfork |
7758 | catchpoints. */ | |
ce78b96d JB |
7759 | |
7760 | static int | |
73971819 | 7761 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7762 | { |
e99b03dc | 7763 | return target_remove_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7764 | } |
7765 | ||
7766 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7767 | catchpoints. */ | |
7768 | ||
7769 | static int | |
f1310107 | 7770 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
bd522513 | 7771 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7772 | const struct target_waitstatus *ws) |
ce78b96d | 7773 | { |
e29a4733 PA |
7774 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7775 | ||
f90263c1 TT |
7776 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7777 | return 0; | |
7778 | ||
7779 | c->forked_inferior_pid = ws->value.related_pid; | |
7780 | return 1; | |
ce78b96d JB |
7781 | } |
7782 | ||
4a64f543 MS |
7783 | /* Implement the "print_it" breakpoint_ops method for vfork |
7784 | catchpoints. */ | |
ce78b96d JB |
7785 | |
7786 | static enum print_stop_action | |
348d480f | 7787 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7788 | { |
36dfb11c | 7789 | struct ui_out *uiout = current_uiout; |
348d480f | 7790 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7791 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7792 | ||
ce78b96d | 7793 | annotate_catchpoint (b->number); |
f303dbd6 | 7794 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7795 | if (b->disposition == disp_del) |
112e8700 | 7796 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7797 | else |
112e8700 SM |
7798 | uiout->text ("Catchpoint "); |
7799 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7800 | { |
112e8700 SM |
7801 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
7802 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7803 | } |
381befee | 7804 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7805 | uiout->text (" (vforked process "); |
381befee | 7806 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7807 | uiout->text ("), "); |
ce78b96d JB |
7808 | return PRINT_SRC_AND_LOC; |
7809 | } | |
7810 | ||
4a64f543 MS |
7811 | /* Implement the "print_one" breakpoint_ops method for vfork |
7812 | catchpoints. */ | |
ce78b96d JB |
7813 | |
7814 | static void | |
a6d9a66e | 7815 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7816 | { |
e29a4733 | 7817 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7818 | struct value_print_options opts; |
79a45e25 | 7819 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7820 | |
7821 | get_user_print_options (&opts); | |
4a64f543 MS |
7822 | /* Field 4, the address, is omitted (which makes the columns not |
7823 | line up too nicely with the headers, but the effect is relatively | |
7824 | readable). */ | |
79a45b7d | 7825 | if (opts.addressprint) |
112e8700 | 7826 | uiout->field_skip ("addr"); |
ce78b96d | 7827 | annotate_field (5); |
112e8700 | 7828 | uiout->text ("vfork"); |
d7e15655 | 7829 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7830 | { |
112e8700 | 7831 | uiout->text (", process "); |
381befee | 7832 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7833 | uiout->spaces (1); |
ce78b96d | 7834 | } |
8ac3646f | 7835 | |
112e8700 SM |
7836 | if (uiout->is_mi_like_p ()) |
7837 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
7838 | } |
7839 | ||
7840 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7841 | catchpoints. */ | |
7842 | ||
7843 | static void | |
7844 | print_mention_catch_vfork (struct breakpoint *b) | |
7845 | { | |
7846 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7847 | } | |
7848 | ||
6149aea9 PA |
7849 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7850 | catchpoints. */ | |
7851 | ||
7852 | static void | |
7853 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7854 | { | |
7855 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7856 | print_recreate_thread (b, fp); |
6149aea9 PA |
7857 | } |
7858 | ||
ce78b96d JB |
7859 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7860 | ||
2060206e | 7861 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7862 | |
edcc5120 | 7863 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 7864 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
7865 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
7866 | ||
c1fc2657 | 7867 | struct solib_catchpoint : public breakpoint |
edcc5120 | 7868 | { |
c1fc2657 | 7869 | ~solib_catchpoint () override; |
edcc5120 TT |
7870 | |
7871 | /* True for "catch load", false for "catch unload". */ | |
7872 | unsigned char is_load; | |
7873 | ||
7874 | /* Regular expression to match, if any. COMPILED is only valid when | |
7875 | REGEX is non-NULL. */ | |
7876 | char *regex; | |
2d7cc5c7 | 7877 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
7878 | }; |
7879 | ||
c1fc2657 | 7880 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 7881 | { |
c1fc2657 | 7882 | xfree (this->regex); |
edcc5120 TT |
7883 | } |
7884 | ||
7885 | static int | |
7886 | insert_catch_solib (struct bp_location *ignore) | |
7887 | { | |
7888 | return 0; | |
7889 | } | |
7890 | ||
7891 | static int | |
73971819 | 7892 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
7893 | { |
7894 | return 0; | |
7895 | } | |
7896 | ||
7897 | static int | |
7898 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
bd522513 | 7899 | const address_space *aspace, |
edcc5120 TT |
7900 | CORE_ADDR bp_addr, |
7901 | const struct target_waitstatus *ws) | |
7902 | { | |
7903 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7904 | struct breakpoint *other; | |
7905 | ||
7906 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7907 | return 1; | |
7908 | ||
7909 | ALL_BREAKPOINTS (other) | |
7910 | { | |
7911 | struct bp_location *other_bl; | |
7912 | ||
7913 | if (other == bl->owner) | |
7914 | continue; | |
7915 | ||
7916 | if (other->type != bp_shlib_event) | |
7917 | continue; | |
7918 | ||
c1fc2657 | 7919 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
7920 | continue; |
7921 | ||
7922 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7923 | { | |
7924 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7925 | return 1; | |
7926 | } | |
7927 | } | |
7928 | ||
7929 | return 0; | |
7930 | } | |
7931 | ||
7932 | static void | |
7933 | check_status_catch_solib (struct bpstats *bs) | |
7934 | { | |
7935 | struct solib_catchpoint *self | |
7936 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
edcc5120 TT |
7937 | |
7938 | if (self->is_load) | |
7939 | { | |
52941706 | 7940 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 TT |
7941 | { |
7942 | if (!self->regex | |
2d7cc5c7 | 7943 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
7944 | return; |
7945 | } | |
7946 | } | |
7947 | else | |
7948 | { | |
6fb16ce6 | 7949 | for (const std::string &iter : current_program_space->deleted_solibs) |
edcc5120 TT |
7950 | { |
7951 | if (!self->regex | |
6fb16ce6 | 7952 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
edcc5120 TT |
7953 | return; |
7954 | } | |
7955 | } | |
7956 | ||
7957 | bs->stop = 0; | |
7958 | bs->print_it = print_it_noop; | |
7959 | } | |
7960 | ||
7961 | static enum print_stop_action | |
7962 | print_it_catch_solib (bpstat bs) | |
7963 | { | |
7964 | struct breakpoint *b = bs->breakpoint_at; | |
7965 | struct ui_out *uiout = current_uiout; | |
7966 | ||
7967 | annotate_catchpoint (b->number); | |
f303dbd6 | 7968 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 7969 | if (b->disposition == disp_del) |
112e8700 | 7970 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 7971 | else |
112e8700 | 7972 | uiout->text ("Catchpoint "); |
381befee | 7973 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
7974 | uiout->text ("\n"); |
7975 | if (uiout->is_mi_like_p ()) | |
7976 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
7977 | print_solib_event (1); |
7978 | return PRINT_SRC_AND_LOC; | |
7979 | } | |
7980 | ||
7981 | static void | |
7982 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7983 | { | |
7984 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7985 | struct value_print_options opts; | |
7986 | struct ui_out *uiout = current_uiout; | |
edcc5120 TT |
7987 | |
7988 | get_user_print_options (&opts); | |
7989 | /* Field 4, the address, is omitted (which makes the columns not | |
7990 | line up too nicely with the headers, but the effect is relatively | |
7991 | readable). */ | |
7992 | if (opts.addressprint) | |
7993 | { | |
7994 | annotate_field (4); | |
112e8700 | 7995 | uiout->field_skip ("addr"); |
edcc5120 TT |
7996 | } |
7997 | ||
528e1572 | 7998 | std::string msg; |
edcc5120 TT |
7999 | annotate_field (5); |
8000 | if (self->is_load) | |
8001 | { | |
8002 | if (self->regex) | |
528e1572 | 8003 | msg = string_printf (_("load of library matching %s"), self->regex); |
edcc5120 | 8004 | else |
528e1572 | 8005 | msg = _("load of library"); |
edcc5120 TT |
8006 | } |
8007 | else | |
8008 | { | |
8009 | if (self->regex) | |
528e1572 | 8010 | msg = string_printf (_("unload of library matching %s"), self->regex); |
edcc5120 | 8011 | else |
528e1572 | 8012 | msg = _("unload of library"); |
edcc5120 | 8013 | } |
112e8700 | 8014 | uiout->field_string ("what", msg); |
8ac3646f | 8015 | |
112e8700 SM |
8016 | if (uiout->is_mi_like_p ()) |
8017 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8018 | } |
8019 | ||
8020 | static void | |
8021 | print_mention_catch_solib (struct breakpoint *b) | |
8022 | { | |
8023 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8024 | ||
8025 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8026 | self->is_load ? "load" : "unload"); | |
8027 | } | |
8028 | ||
8029 | static void | |
8030 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8031 | { | |
8032 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8033 | ||
8034 | fprintf_unfiltered (fp, "%s %s", | |
8035 | b->disposition == disp_del ? "tcatch" : "catch", | |
8036 | self->is_load ? "load" : "unload"); | |
8037 | if (self->regex) | |
8038 | fprintf_unfiltered (fp, " %s", self->regex); | |
8039 | fprintf_unfiltered (fp, "\n"); | |
8040 | } | |
8041 | ||
8042 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8043 | ||
91985142 MG |
8044 | /* Shared helper function (MI and CLI) for creating and installing |
8045 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8046 | the events to be caught are load events, otherwise they are | |
8047 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8048 | temporary one. If ENABLED is non-zero the catchpoint is | |
8049 | created in an enabled state. */ | |
edcc5120 | 8050 | |
91985142 | 8051 | void |
a121b7c1 | 8052 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8053 | { |
edcc5120 | 8054 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8055 | |
edcc5120 TT |
8056 | if (!arg) |
8057 | arg = ""; | |
f1735a53 | 8058 | arg = skip_spaces (arg); |
edcc5120 | 8059 | |
36bd8eaa | 8060 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8061 | |
8062 | if (*arg != '\0') | |
8063 | { | |
2d7cc5c7 PA |
8064 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8065 | _("Invalid regexp"))); | |
edcc5120 TT |
8066 | c->regex = xstrdup (arg); |
8067 | } | |
8068 | ||
8069 | c->is_load = is_load; | |
36bd8eaa | 8070 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8071 | &catch_solib_breakpoint_ops); |
8072 | ||
c1fc2657 | 8073 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8074 | |
b270e6f9 | 8075 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8076 | } |
8077 | ||
91985142 MG |
8078 | /* A helper function that does all the work for "catch load" and |
8079 | "catch unload". */ | |
8080 | ||
8081 | static void | |
eb4c3f4a | 8082 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
91985142 MG |
8083 | struct cmd_list_element *command) |
8084 | { | |
8085 | int tempflag; | |
8086 | const int enabled = 1; | |
8087 | ||
8088 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8089 | ||
8090 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8091 | } | |
8092 | ||
edcc5120 | 8093 | static void |
eb4c3f4a | 8094 | catch_load_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8095 | struct cmd_list_element *command) |
8096 | { | |
8097 | catch_load_or_unload (arg, from_tty, 1, command); | |
8098 | } | |
8099 | ||
8100 | static void | |
eb4c3f4a | 8101 | catch_unload_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8102 | struct cmd_list_element *command) |
8103 | { | |
8104 | catch_load_or_unload (arg, from_tty, 0, command); | |
8105 | } | |
8106 | ||
346774a9 PA |
8107 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8108 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8109 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8110 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8111 | |
ab04a2af | 8112 | void |
346774a9 PA |
8113 | init_catchpoint (struct breakpoint *b, |
8114 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8115 | const char *cond_string, |
c0a91b2b | 8116 | const struct breakpoint_ops *ops) |
c906108c | 8117 | { |
51abb421 | 8118 | symtab_and_line sal; |
6c95b8df | 8119 | sal.pspace = current_program_space; |
c5aa993b | 8120 | |
28010a5d | 8121 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8122 | |
1b36a34b | 8123 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8124 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8125 | } |
8126 | ||
28010a5d | 8127 | void |
b270e6f9 | 8128 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8129 | { |
b270e6f9 | 8130 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8131 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8132 | if (is_tracepoint (b)) |
8133 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8134 | if (!internal) |
8135 | mention (b); | |
76727919 | 8136 | gdb::observers::breakpoint_created.notify (b); |
3ea46bff YQ |
8137 | |
8138 | if (update_gll) | |
44702360 | 8139 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8140 | } |
8141 | ||
9b70b993 | 8142 | static void |
a6d9a66e | 8143 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8144 | int tempflag, const char *cond_string, |
c0a91b2b | 8145 | const struct breakpoint_ops *ops) |
c906108c | 8146 | { |
b270e6f9 | 8147 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8148 | |
b270e6f9 | 8149 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8150 | |
8151 | c->forked_inferior_pid = null_ptid; | |
8152 | ||
b270e6f9 | 8153 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8154 | } |
8155 | ||
fe798b75 JB |
8156 | /* Exec catchpoints. */ |
8157 | ||
b4d90040 | 8158 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8159 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8160 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8161 | ||
c1fc2657 | 8162 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8163 | { |
c1fc2657 | 8164 | ~exec_catchpoint () override; |
b4d90040 PA |
8165 | |
8166 | /* Filename of a program whose exec triggered this catchpoint. | |
8167 | This field is only valid immediately after this catchpoint has | |
8168 | triggered. */ | |
8169 | char *exec_pathname; | |
8170 | }; | |
8171 | ||
c1fc2657 | 8172 | /* Exec catchpoint destructor. */ |
b4d90040 | 8173 | |
c1fc2657 | 8174 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8175 | { |
c1fc2657 | 8176 | xfree (this->exec_pathname); |
b4d90040 PA |
8177 | } |
8178 | ||
77b06cd7 TJB |
8179 | static int |
8180 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8181 | { |
e99b03dc | 8182 | return target_insert_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8183 | } |
c906108c | 8184 | |
fe798b75 | 8185 | static int |
73971819 | 8186 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8187 | { |
e99b03dc | 8188 | return target_remove_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8189 | } |
c906108c | 8190 | |
fe798b75 | 8191 | static int |
f1310107 | 8192 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
bd522513 | 8193 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 8194 | const struct target_waitstatus *ws) |
fe798b75 | 8195 | { |
b4d90040 PA |
8196 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8197 | ||
f90263c1 TT |
8198 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8199 | return 0; | |
8200 | ||
8201 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8202 | return 1; | |
fe798b75 | 8203 | } |
c906108c | 8204 | |
fe798b75 | 8205 | static enum print_stop_action |
348d480f | 8206 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8207 | { |
36dfb11c | 8208 | struct ui_out *uiout = current_uiout; |
348d480f | 8209 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8210 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8211 | ||
fe798b75 | 8212 | annotate_catchpoint (b->number); |
f303dbd6 | 8213 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8214 | if (b->disposition == disp_del) |
112e8700 | 8215 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8216 | else |
112e8700 SM |
8217 | uiout->text ("Catchpoint "); |
8218 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8219 | { |
112e8700 SM |
8220 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8221 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8222 | } |
381befee | 8223 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
8224 | uiout->text (" (exec'd "); |
8225 | uiout->field_string ("new-exec", c->exec_pathname); | |
8226 | uiout->text ("), "); | |
36dfb11c | 8227 | |
fe798b75 | 8228 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8229 | } |
8230 | ||
fe798b75 | 8231 | static void |
a6d9a66e | 8232 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8233 | { |
b4d90040 | 8234 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8235 | struct value_print_options opts; |
79a45e25 | 8236 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8237 | |
8238 | get_user_print_options (&opts); | |
8239 | ||
8240 | /* Field 4, the address, is omitted (which makes the columns | |
8241 | not line up too nicely with the headers, but the effect | |
8242 | is relatively readable). */ | |
8243 | if (opts.addressprint) | |
112e8700 | 8244 | uiout->field_skip ("addr"); |
fe798b75 | 8245 | annotate_field (5); |
112e8700 | 8246 | uiout->text ("exec"); |
b4d90040 | 8247 | if (c->exec_pathname != NULL) |
fe798b75 | 8248 | { |
112e8700 SM |
8249 | uiout->text (", program \""); |
8250 | uiout->field_string ("what", c->exec_pathname); | |
8251 | uiout->text ("\" "); | |
fe798b75 | 8252 | } |
8ac3646f | 8253 | |
112e8700 SM |
8254 | if (uiout->is_mi_like_p ()) |
8255 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8256 | } |
8257 | ||
8258 | static void | |
8259 | print_mention_catch_exec (struct breakpoint *b) | |
8260 | { | |
8261 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8262 | } | |
8263 | ||
6149aea9 PA |
8264 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8265 | catchpoints. */ | |
8266 | ||
8267 | static void | |
8268 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8269 | { | |
8270 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8271 | print_recreate_thread (b, fp); |
6149aea9 PA |
8272 | } |
8273 | ||
2060206e | 8274 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8275 | |
c906108c | 8276 | static int |
fba45db2 | 8277 | hw_breakpoint_used_count (void) |
c906108c | 8278 | { |
c906108c | 8279 | int i = 0; |
f1310107 TJB |
8280 | struct breakpoint *b; |
8281 | struct bp_location *bl; | |
c906108c SS |
8282 | |
8283 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8284 | { |
d6b74ac4 | 8285 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8286 | for (bl = b->loc; bl; bl = bl->next) |
8287 | { | |
8288 | /* Special types of hardware breakpoints may use more than | |
8289 | one register. */ | |
348d480f | 8290 | i += b->ops->resources_needed (bl); |
f1310107 | 8291 | } |
c5aa993b | 8292 | } |
c906108c SS |
8293 | |
8294 | return i; | |
8295 | } | |
8296 | ||
a1398e0c PA |
8297 | /* Returns the resources B would use if it were a hardware |
8298 | watchpoint. */ | |
8299 | ||
c906108c | 8300 | static int |
a1398e0c | 8301 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8302 | { |
c906108c | 8303 | int i = 0; |
e09342b5 | 8304 | struct bp_location *bl; |
c906108c | 8305 | |
a1398e0c PA |
8306 | if (!breakpoint_enabled (b)) |
8307 | return 0; | |
8308 | ||
8309 | for (bl = b->loc; bl; bl = bl->next) | |
8310 | { | |
8311 | /* Special types of hardware watchpoints may use more than | |
8312 | one register. */ | |
8313 | i += b->ops->resources_needed (bl); | |
8314 | } | |
8315 | ||
8316 | return i; | |
8317 | } | |
8318 | ||
8319 | /* Returns the sum the used resources of all hardware watchpoints of | |
8320 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8321 | the sum of the used resources of all hardware watchpoints of other | |
8322 | types _not_ TYPE. */ | |
8323 | ||
8324 | static int | |
8325 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8326 | enum bptype type, int *other_type_used) | |
8327 | { | |
8328 | int i = 0; | |
8329 | struct breakpoint *b; | |
8330 | ||
c906108c SS |
8331 | *other_type_used = 0; |
8332 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8333 | { |
a1398e0c PA |
8334 | if (b == except) |
8335 | continue; | |
e09342b5 TJB |
8336 | if (!breakpoint_enabled (b)) |
8337 | continue; | |
8338 | ||
a1398e0c PA |
8339 | if (b->type == type) |
8340 | i += hw_watchpoint_use_count (b); | |
8341 | else if (is_hardware_watchpoint (b)) | |
8342 | *other_type_used = 1; | |
e09342b5 TJB |
8343 | } |
8344 | ||
c906108c SS |
8345 | return i; |
8346 | } | |
8347 | ||
c906108c | 8348 | void |
fba45db2 | 8349 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8350 | { |
c5aa993b | 8351 | struct breakpoint *b; |
c906108c SS |
8352 | |
8353 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8354 | { |
cc60f2e3 | 8355 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8356 | { |
b5de0fa7 | 8357 | b->enable_state = bp_call_disabled; |
44702360 | 8358 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8359 | } |
8360 | } | |
c906108c SS |
8361 | } |
8362 | ||
8363 | void | |
fba45db2 | 8364 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8365 | { |
c5aa993b | 8366 | struct breakpoint *b; |
c906108c SS |
8367 | |
8368 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8369 | { |
cc60f2e3 | 8370 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8371 | { |
b5de0fa7 | 8372 | b->enable_state = bp_enabled; |
44702360 | 8373 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8374 | } |
8375 | } | |
c906108c SS |
8376 | } |
8377 | ||
8bea4e01 UW |
8378 | void |
8379 | disable_breakpoints_before_startup (void) | |
8380 | { | |
6c95b8df | 8381 | current_program_space->executing_startup = 1; |
44702360 | 8382 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8383 | } |
8384 | ||
8385 | void | |
8386 | enable_breakpoints_after_startup (void) | |
8387 | { | |
6c95b8df | 8388 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8389 | breakpoint_re_set (); |
8bea4e01 UW |
8390 | } |
8391 | ||
7c16b83e PA |
8392 | /* Create a new single-step breakpoint for thread THREAD, with no |
8393 | locations. */ | |
c906108c | 8394 | |
7c16b83e PA |
8395 | static struct breakpoint * |
8396 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8397 | { | |
b270e6f9 | 8398 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8399 | |
b270e6f9 | 8400 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8401 | &momentary_breakpoint_ops); |
8402 | ||
8403 | b->disposition = disp_donttouch; | |
8404 | b->frame_id = null_frame_id; | |
8405 | ||
8406 | b->thread = thread; | |
8407 | gdb_assert (b->thread != 0); | |
8408 | ||
b270e6f9 | 8409 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8410 | } |
8411 | ||
8412 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8413 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8414 | frame. */ | |
c906108c | 8415 | |
454dafbd | 8416 | breakpoint_up |
a6d9a66e UW |
8417 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8418 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8419 | { |
52f0bd74 | 8420 | struct breakpoint *b; |
edb3359d | 8421 | |
193facb3 JK |
8422 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8423 | tail-called one. */ | |
8424 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8425 | |
06edf0c0 | 8426 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8427 | b->enable_state = bp_enabled; |
8428 | b->disposition = disp_donttouch; | |
818dd999 | 8429 | b->frame_id = frame_id; |
c906108c | 8430 | |
00431a78 | 8431 | b->thread = inferior_thread ()->global_num; |
c906108c | 8432 | |
44702360 | 8433 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8434 | |
454dafbd | 8435 | return breakpoint_up (b); |
c906108c | 8436 | } |
611c83ae | 8437 | |
06edf0c0 | 8438 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8439 | The new breakpoint will have type TYPE, use OPS as its |
8440 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8441 | |
06edf0c0 PA |
8442 | static struct breakpoint * |
8443 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8444 | enum bptype type, | |
a1aa2221 LM |
8445 | const struct breakpoint_ops *ops, |
8446 | int loc_enabled) | |
e58b0e63 PA |
8447 | { |
8448 | struct breakpoint *copy; | |
8449 | ||
06edf0c0 | 8450 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8451 | copy->loc = allocate_bp_location (copy); |
0ba852ab | 8452 | set_breakpoint_location_function (copy->loc); |
e58b0e63 | 8453 | |
a6d9a66e | 8454 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8455 | copy->loc->requested_address = orig->loc->requested_address; |
8456 | copy->loc->address = orig->loc->address; | |
8457 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8458 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8459 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8460 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8461 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8462 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8463 | copy->frame_id = orig->frame_id; |
8464 | copy->thread = orig->thread; | |
6c95b8df | 8465 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8466 | |
8467 | copy->enable_state = bp_enabled; | |
8468 | copy->disposition = disp_donttouch; | |
8469 | copy->number = internal_breakpoint_number--; | |
8470 | ||
44702360 | 8471 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8472 | return copy; |
8473 | } | |
8474 | ||
06edf0c0 PA |
8475 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8476 | ORIG is NULL. */ | |
8477 | ||
8478 | struct breakpoint * | |
8479 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8480 | { | |
8481 | /* If there's nothing to clone, then return nothing. */ | |
8482 | if (orig == NULL) | |
8483 | return NULL; | |
8484 | ||
a1aa2221 | 8485 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8486 | } |
8487 | ||
454dafbd | 8488 | breakpoint_up |
a6d9a66e UW |
8489 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8490 | enum bptype type) | |
611c83ae PA |
8491 | { |
8492 | struct symtab_and_line sal; | |
8493 | ||
8494 | sal = find_pc_line (pc, 0); | |
8495 | sal.pc = pc; | |
8496 | sal.section = find_pc_overlay (pc); | |
8497 | sal.explicit_pc = 1; | |
8498 | ||
a6d9a66e | 8499 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8500 | } |
c906108c | 8501 | \f |
c5aa993b | 8502 | |
c906108c SS |
8503 | /* Tell the user we have just set a breakpoint B. */ |
8504 | ||
8505 | static void | |
fba45db2 | 8506 | mention (struct breakpoint *b) |
c906108c | 8507 | { |
348d480f | 8508 | b->ops->print_mention (b); |
2d33446d | 8509 | current_uiout->text ("\n"); |
c906108c | 8510 | } |
c906108c | 8511 | \f |
c5aa993b | 8512 | |
1a853c52 PA |
8513 | static int bp_loc_is_permanent (struct bp_location *loc); |
8514 | ||
0d381245 | 8515 | static struct bp_location * |
39d61571 | 8516 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8517 | const struct symtab_and_line *sal) |
8518 | { | |
8519 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8520 | CORE_ADDR adjusted_address; |
8521 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8522 | ||
8523 | if (loc_gdbarch == NULL) | |
8524 | loc_gdbarch = b->gdbarch; | |
8525 | ||
8526 | /* Adjust the breakpoint's address prior to allocating a location. | |
8527 | Once we call allocate_bp_location(), that mostly uninitialized | |
8528 | location will be placed on the location chain. Adjustment of the | |
8529 | breakpoint may cause target_read_memory() to be called and we do | |
8530 | not want its scan of the location chain to find a breakpoint and | |
8531 | location that's only been partially initialized. */ | |
8532 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8533 | sal->pc, b->type); | |
0d381245 | 8534 | |
d30113d4 | 8535 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8536 | loc = allocate_bp_location (b); |
d30113d4 JK |
8537 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8538 | tmp = &((*tmp)->next)) | |
0d381245 | 8539 | ; |
d30113d4 | 8540 | loc->next = *tmp; |
0d381245 | 8541 | *tmp = loc; |
3742cc8b | 8542 | |
0d381245 | 8543 | loc->requested_address = sal->pc; |
3742cc8b | 8544 | loc->address = adjusted_address; |
6c95b8df | 8545 | loc->pspace = sal->pspace; |
935676c9 | 8546 | loc->probe.prob = sal->prob; |
729662a5 | 8547 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8548 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8549 | loc->section = sal->section; |
3742cc8b | 8550 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8551 | loc->line_number = sal->line; |
2f202fde | 8552 | loc->symtab = sal->symtab; |
4a27f119 | 8553 | loc->symbol = sal->symbol; |
3467ec66 PA |
8554 | loc->msymbol = sal->msymbol; |
8555 | loc->objfile = sal->objfile; | |
f8eba3c6 | 8556 | |
0ba852ab | 8557 | set_breakpoint_location_function (loc); |
1a853c52 | 8558 | |
6ae88661 LM |
8559 | /* While by definition, permanent breakpoints are already present in the |
8560 | code, we don't mark the location as inserted. Normally one would expect | |
8561 | that GDB could rely on that breakpoint instruction to stop the program, | |
8562 | thus removing the need to insert its own breakpoint, except that executing | |
8563 | the breakpoint instruction can kill the target instead of reporting a | |
8564 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8565 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8566 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8567 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8568 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8569 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8570 | it manually increments the PC, thus avoiding executing the breakpoint | |
8571 | instruction.) */ | |
1a853c52 | 8572 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8573 | loc->permanent = 1; |
1a853c52 | 8574 | |
0d381245 VP |
8575 | return loc; |
8576 | } | |
514f746b AR |
8577 | \f |
8578 | ||
1cf4d951 | 8579 | /* See breakpoint.h. */ |
514f746b | 8580 | |
1cf4d951 PA |
8581 | int |
8582 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8583 | { |
8584 | int len; | |
8585 | CORE_ADDR addr; | |
1afeeb75 | 8586 | const gdb_byte *bpoint; |
514f746b AR |
8587 | gdb_byte *target_mem; |
8588 | ||
1cf4d951 PA |
8589 | addr = address; |
8590 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8591 | ||
8592 | /* Software breakpoints unsupported? */ | |
8593 | if (bpoint == NULL) | |
8594 | return 0; | |
8595 | ||
224c3ddb | 8596 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
8597 | |
8598 | /* Enable the automatic memory restoration from breakpoints while | |
8599 | we read the memory. Otherwise we could say about our temporary | |
8600 | breakpoints they are permanent. */ | |
cb85b21b TT |
8601 | scoped_restore restore_memory |
8602 | = make_scoped_restore_show_memory_breakpoints (0); | |
1cf4d951 PA |
8603 | |
8604 | if (target_read_memory (address, target_mem, len) == 0 | |
8605 | && memcmp (target_mem, bpoint, len) == 0) | |
cb85b21b | 8606 | return 1; |
1cf4d951 | 8607 | |
cb85b21b | 8608 | return 0; |
1cf4d951 PA |
8609 | } |
8610 | ||
8611 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8612 | return 0 otherwise. */ | |
8613 | ||
8614 | static int | |
8615 | bp_loc_is_permanent (struct bp_location *loc) | |
8616 | { | |
514f746b AR |
8617 | gdb_assert (loc != NULL); |
8618 | ||
cb1e4e32 PA |
8619 | /* If we have a non-breakpoint-backed catchpoint or a software |
8620 | watchpoint, just return 0. We should not attempt to read from | |
8621 | the addresses the locations of these breakpoint types point to. | |
8622 | program_breakpoint_here_p, below, will attempt to read | |
244558af | 8623 | memory. */ |
cb1e4e32 | 8624 | if (!bl_address_is_meaningful (loc)) |
244558af LM |
8625 | return 0; |
8626 | ||
5ed8105e | 8627 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8628 | switch_to_program_space_and_thread (loc->pspace); |
5ed8105e | 8629 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8630 | } |
8631 | ||
e7e0cddf SS |
8632 | /* Build a command list for the dprintf corresponding to the current |
8633 | settings of the dprintf style options. */ | |
8634 | ||
8635 | static void | |
8636 | update_dprintf_command_list (struct breakpoint *b) | |
8637 | { | |
8638 | char *dprintf_args = b->extra_string; | |
8639 | char *printf_line = NULL; | |
8640 | ||
8641 | if (!dprintf_args) | |
8642 | return; | |
8643 | ||
8644 | dprintf_args = skip_spaces (dprintf_args); | |
8645 | ||
8646 | /* Allow a comma, as it may have terminated a location, but don't | |
8647 | insist on it. */ | |
8648 | if (*dprintf_args == ',') | |
8649 | ++dprintf_args; | |
8650 | dprintf_args = skip_spaces (dprintf_args); | |
8651 | ||
8652 | if (*dprintf_args != '"') | |
8653 | error (_("Bad format string, missing '\"'.")); | |
8654 | ||
d3ce09f5 | 8655 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8656 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8657 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8658 | { |
8659 | if (!dprintf_function) | |
8660 | error (_("No function supplied for dprintf call")); | |
8661 | ||
8662 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8663 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8664 | dprintf_function, | |
8665 | dprintf_channel, | |
8666 | dprintf_args); | |
8667 | else | |
8668 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8669 | dprintf_function, | |
8670 | dprintf_args); | |
8671 | } | |
d3ce09f5 SS |
8672 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8673 | { | |
8674 | if (target_can_run_breakpoint_commands ()) | |
8675 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8676 | else | |
8677 | { | |
8678 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8679 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8680 | } | |
8681 | } | |
e7e0cddf SS |
8682 | else |
8683 | internal_error (__FILE__, __LINE__, | |
8684 | _("Invalid dprintf style.")); | |
8685 | ||
f28045c2 | 8686 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8687 | |
12973681 TT |
8688 | /* Manufacture a printf sequence. */ |
8689 | struct command_line *printf_cmd_line | |
8690 | = new struct command_line (simple_control, printf_line); | |
8691 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, | |
8692 | command_lines_deleter ())); | |
e7e0cddf SS |
8693 | } |
8694 | ||
8695 | /* Update all dprintf commands, making their command lists reflect | |
8696 | current style settings. */ | |
8697 | ||
8698 | static void | |
eb4c3f4a | 8699 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8700 | struct cmd_list_element *c) |
8701 | { | |
8702 | struct breakpoint *b; | |
8703 | ||
8704 | ALL_BREAKPOINTS (b) | |
8705 | { | |
8706 | if (b->type == bp_dprintf) | |
8707 | update_dprintf_command_list (b); | |
8708 | } | |
8709 | } | |
c3f6f71d | 8710 | |
f00aae0f KS |
8711 | /* Create a breakpoint with SAL as location. Use LOCATION |
8712 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8713 | as condition expression. If LOCATION is NULL then create an |
8714 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8715 | |
8716 | static void | |
d9b3f62e | 8717 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8718 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8719 | event_location_up &&location, |
e1e01040 PA |
8720 | gdb::unique_xmalloc_ptr<char> filter, |
8721 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8722 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8723 | enum bptype type, enum bpdisp disposition, |
8724 | int thread, int task, int ignore_count, | |
c0a91b2b | 8725 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8726 | int enabled, int internal, unsigned flags, |
8727 | int display_canonical) | |
018d34a4 | 8728 | { |
0d381245 | 8729 | int i; |
018d34a4 VP |
8730 | |
8731 | if (type == bp_hardware_breakpoint) | |
8732 | { | |
fbbd034e AS |
8733 | int target_resources_ok; |
8734 | ||
8735 | i = hw_breakpoint_used_count (); | |
8736 | target_resources_ok = | |
8737 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8738 | i + 1, 0); |
8739 | if (target_resources_ok == 0) | |
8740 | error (_("No hardware breakpoint support in the target.")); | |
8741 | else if (target_resources_ok < 0) | |
8742 | error (_("Hardware breakpoints used exceeds limit.")); | |
8743 | } | |
8744 | ||
6c5b2ebe | 8745 | gdb_assert (!sals.empty ()); |
6c95b8df | 8746 | |
6c5b2ebe | 8747 | for (const auto &sal : sals) |
0d381245 | 8748 | { |
0d381245 VP |
8749 | struct bp_location *loc; |
8750 | ||
8751 | if (from_tty) | |
5af949e3 UW |
8752 | { |
8753 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8754 | if (!loc_gdbarch) | |
8755 | loc_gdbarch = gdbarch; | |
8756 | ||
8757 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8758 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8759 | } |
0d381245 | 8760 | |
6c5b2ebe | 8761 | if (&sal == &sals[0]) |
0d381245 | 8762 | { |
d9b3f62e | 8763 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8764 | b->thread = thread; |
4a306c9a | 8765 | b->task = task; |
855a6e68 | 8766 | |
e1e01040 PA |
8767 | b->cond_string = cond_string.release (); |
8768 | b->extra_string = extra_string.release (); | |
0d381245 | 8769 | b->ignore_count = ignore_count; |
41447f92 | 8770 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8771 | b->disposition = disposition; |
6c95b8df | 8772 | |
44f238bb PA |
8773 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8774 | b->loc->inserted = 1; | |
8775 | ||
0fb4aa4b PA |
8776 | if (type == bp_static_tracepoint) |
8777 | { | |
d9b3f62e | 8778 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8779 | struct static_tracepoint_marker marker; |
8780 | ||
983af33b | 8781 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8782 | { |
8783 | /* We already know the marker exists, otherwise, we | |
8784 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8785 | const char *p |
8786 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8787 | const char *endp; |
0fb4aa4b | 8788 | |
f1735a53 | 8789 | p = skip_spaces (p); |
0fb4aa4b | 8790 | |
f1735a53 | 8791 | endp = skip_to_space (p); |
0fb4aa4b | 8792 | |
5d9310c4 | 8793 | t->static_trace_marker_id.assign (p, endp - p); |
0fb4aa4b | 8794 | |
3e43a32a MS |
8795 | printf_filtered (_("Probed static tracepoint " |
8796 | "marker \"%s\"\n"), | |
5d9310c4 | 8797 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8798 | } |
8799 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8800 | { | |
5d9310c4 | 8801 | t->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b | 8802 | |
3e43a32a MS |
8803 | printf_filtered (_("Probed static tracepoint " |
8804 | "marker \"%s\"\n"), | |
5d9310c4 | 8805 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8806 | } |
8807 | else | |
3e43a32a MS |
8808 | warning (_("Couldn't determine the static " |
8809 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8810 | } |
8811 | ||
0d381245 VP |
8812 | loc = b->loc; |
8813 | } | |
8814 | else | |
018d34a4 | 8815 | { |
39d61571 | 8816 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8817 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8818 | loc->inserted = 1; | |
0d381245 VP |
8819 | } |
8820 | ||
8821 | if (b->cond_string) | |
8822 | { | |
bbc13ae3 KS |
8823 | const char *arg = b->cond_string; |
8824 | ||
1bb9788d TT |
8825 | loc->cond = parse_exp_1 (&arg, loc->address, |
8826 | block_for_pc (loc->address), 0); | |
0d381245 | 8827 | if (*arg) |
588ae58c | 8828 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 8829 | } |
e7e0cddf SS |
8830 | |
8831 | /* Dynamic printf requires and uses additional arguments on the | |
8832 | command line, otherwise it's an error. */ | |
8833 | if (type == bp_dprintf) | |
8834 | { | |
8835 | if (b->extra_string) | |
8836 | update_dprintf_command_list (b); | |
8837 | else | |
8838 | error (_("Format string required")); | |
8839 | } | |
8840 | else if (b->extra_string) | |
588ae58c | 8841 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 8842 | } |
018d34a4 | 8843 | |
56435ebe | 8844 | b->display_canonical = display_canonical; |
f00aae0f | 8845 | if (location != NULL) |
d28cd78a | 8846 | b->location = std::move (location); |
018d34a4 | 8847 | else |
d28cd78a | 8848 | b->location = new_address_location (b->loc->address, NULL, 0); |
c0e8dcd8 | 8849 | b->filter = std::move (filter); |
d9b3f62e | 8850 | } |
018d34a4 | 8851 | |
d9b3f62e PA |
8852 | static void |
8853 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 8854 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8855 | event_location_up &&location, |
e1e01040 PA |
8856 | gdb::unique_xmalloc_ptr<char> filter, |
8857 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8858 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8859 | enum bptype type, enum bpdisp disposition, |
8860 | int thread, int task, int ignore_count, | |
c0a91b2b | 8861 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8862 | int enabled, int internal, unsigned flags, |
8863 | int display_canonical) | |
d9b3f62e | 8864 | { |
a5e364af | 8865 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 8866 | |
a5e364af | 8867 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 8868 | sals, std::move (location), |
e1e01040 PA |
8869 | std::move (filter), |
8870 | std::move (cond_string), | |
8871 | std::move (extra_string), | |
d9b3f62e PA |
8872 | type, disposition, |
8873 | thread, task, ignore_count, | |
8874 | ops, from_tty, | |
44f238bb PA |
8875 | enabled, internal, flags, |
8876 | display_canonical); | |
d9b3f62e | 8877 | |
b270e6f9 | 8878 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
8879 | } |
8880 | ||
8881 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8882 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8883 | value. COND_STRING, if not NULL, specified the condition to be | |
8884 | used for all breakpoints. Essentially the only case where | |
8885 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8886 | function. In that case, it's still not possible to specify | |
8887 | separate conditions for different overloaded functions, so | |
8888 | we take just a single condition string. | |
8889 | ||
c3f6f71d | 8890 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8891 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8892 | array contents). If the function fails (error() is called), the |
8893 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8894 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8895 | |
8896 | static void | |
8cdf0e15 | 8897 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8898 | struct linespec_result *canonical, |
e1e01040 PA |
8899 | gdb::unique_xmalloc_ptr<char> cond_string, |
8900 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
8901 | enum bptype type, enum bpdisp disposition, |
8902 | int thread, int task, int ignore_count, | |
c0a91b2b | 8903 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 8904 | int enabled, int internal, unsigned flags) |
c906108c | 8905 | { |
f8eba3c6 | 8906 | if (canonical->pre_expanded) |
6c5b2ebe | 8907 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 8908 | |
6c5b2ebe | 8909 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 8910 | { |
f00aae0f | 8911 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 8912 | 'break', without arguments. */ |
ffc2605c | 8913 | event_location_up location |
f00aae0f | 8914 | = (canonical->location != NULL |
8e9e35b1 | 8915 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 8916 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 8917 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 8918 | |
6c5b2ebe | 8919 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 8920 | std::move (location), |
e1e01040 PA |
8921 | std::move (filter_string), |
8922 | std::move (cond_string), | |
8923 | std::move (extra_string), | |
e7e0cddf | 8924 | type, disposition, |
84f4c1fe | 8925 | thread, task, ignore_count, ops, |
44f238bb | 8926 | from_tty, enabled, internal, flags, |
56435ebe | 8927 | canonical->special_display); |
c3f6f71d | 8928 | } |
c3f6f71d | 8929 | } |
c906108c | 8930 | |
f00aae0f | 8931 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 8932 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
8933 | addresses found. LOCATION points to the end of the SAL (for |
8934 | linespec locations). | |
9998af43 TJB |
8935 | |
8936 | The array and the line spec strings are allocated on the heap, it is | |
8937 | the caller's responsibility to free them. */ | |
c906108c | 8938 | |
b9362cc7 | 8939 | static void |
f00aae0f | 8940 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 8941 | struct linespec_result *canonical) |
c3f6f71d | 8942 | { |
f00aae0f KS |
8943 | struct symtab_and_line cursal; |
8944 | ||
8945 | if (event_location_type (location) == LINESPEC_LOCATION) | |
8946 | { | |
a20714ff | 8947 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 8948 | |
a20714ff | 8949 | if (spec == NULL) |
f00aae0f KS |
8950 | { |
8951 | /* The last displayed codepoint, if it's valid, is our default | |
8952 | breakpoint address. */ | |
8953 | if (last_displayed_sal_is_valid ()) | |
8954 | { | |
f00aae0f KS |
8955 | /* Set sal's pspace, pc, symtab, and line to the values |
8956 | corresponding to the last call to print_frame_info. | |
8957 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
8958 | as the breakpoint line number is inappropriate otherwise. | |
8959 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
8960 | symtab_and_line sal = get_last_displayed_sal (); |
8961 | CORE_ADDR pc = sal.pc; | |
8962 | ||
f00aae0f KS |
8963 | sal = find_pc_line (pc, 0); |
8964 | ||
8965 | /* "break" without arguments is equivalent to "break *PC" | |
8966 | where PC is the last displayed codepoint's address. So | |
8967 | make sure to set sal.explicit_pc to prevent GDB from | |
8968 | trying to expand the list of sals to include all other | |
8969 | instances with the same symtab and line. */ | |
8970 | sal.pc = pc; | |
8971 | sal.explicit_pc = 1; | |
8972 | ||
6c5b2ebe PA |
8973 | struct linespec_sals lsal; |
8974 | lsal.sals = {sal}; | |
f00aae0f KS |
8975 | lsal.canonical = NULL; |
8976 | ||
6c5b2ebe | 8977 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
8978 | return; |
8979 | } | |
8980 | else | |
8981 | error (_("No default breakpoint address now.")); | |
c906108c | 8982 | } |
c906108c | 8983 | } |
f00aae0f KS |
8984 | |
8985 | /* Force almost all breakpoints to be in terms of the | |
8986 | current_source_symtab (which is decode_line_1's default). | |
8987 | This should produce the results we want almost all of the | |
8988 | time while leaving default_breakpoint_* alone. | |
8989 | ||
8990 | ObjC: However, don't match an Objective-C method name which | |
8991 | may have a '+' or '-' succeeded by a '['. */ | |
8992 | cursal = get_current_source_symtab_and_line (); | |
8993 | if (last_displayed_sal_is_valid ()) | |
c906108c | 8994 | { |
a20714ff | 8995 | const char *spec = NULL; |
cc80f267 | 8996 | |
f00aae0f | 8997 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 8998 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 8999 | |
f00aae0f | 9000 | if (!cursal.symtab |
a20714ff PA |
9001 | || (spec != NULL |
9002 | && strchr ("+-", spec[0]) != NULL | |
9003 | && spec[1] != '[')) | |
f00aae0f | 9004 | { |
c2f4122d | 9005 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9006 | get_last_displayed_symtab (), |
9007 | get_last_displayed_line (), | |
9008 | canonical, NULL, NULL); | |
9009 | return; | |
9010 | } | |
c906108c | 9011 | } |
f00aae0f | 9012 | |
c2f4122d | 9013 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9014 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9015 | } |
c906108c | 9016 | |
c906108c | 9017 | |
c3f6f71d | 9018 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9019 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9020 | |
b9362cc7 | 9021 | static void |
6c5b2ebe | 9022 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9023 | { |
6c5b2ebe PA |
9024 | for (auto &sal : sals) |
9025 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9026 | } |
9027 | ||
7a697b8d SS |
9028 | /* Fast tracepoints may have restrictions on valid locations. For |
9029 | instance, a fast tracepoint using a jump instead of a trap will | |
9030 | likely have to overwrite more bytes than a trap would, and so can | |
9031 | only be placed where the instruction is longer than the jump, or a | |
9032 | multi-instruction sequence does not have a jump into the middle of | |
9033 | it, etc. */ | |
9034 | ||
9035 | static void | |
9036 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9037 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9038 | { |
6c5b2ebe | 9039 | for (const auto &sal : sals) |
7a697b8d | 9040 | { |
f8eba3c6 TT |
9041 | struct gdbarch *sarch; |
9042 | ||
6c5b2ebe | 9043 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9044 | /* We fall back to GDBARCH if there is no architecture |
9045 | associated with SAL. */ | |
9046 | if (sarch == NULL) | |
9047 | sarch = gdbarch; | |
281d762b TT |
9048 | std::string msg; |
9049 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) | |
53c3572a | 9050 | error (_("May not have a fast tracepoint at %s%s"), |
281d762b | 9051 | paddress (sarch, sal.pc), msg.c_str ()); |
7a697b8d SS |
9052 | } |
9053 | } | |
9054 | ||
018d34a4 VP |
9055 | /* Given TOK, a string specification of condition and thread, as |
9056 | accepted by the 'break' command, extract the condition | |
9057 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9058 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9059 | If no condition is found, *COND_STRING is set to NULL. |
9060 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9061 | |
9062 | static void | |
bbc13ae3 | 9063 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9064 | char **cond_string, int *thread, int *task, |
9065 | char **rest) | |
018d34a4 VP |
9066 | { |
9067 | *cond_string = NULL; | |
9068 | *thread = -1; | |
ed1d1739 KS |
9069 | *task = 0; |
9070 | *rest = NULL; | |
9071 | ||
018d34a4 VP |
9072 | while (tok && *tok) |
9073 | { | |
bbc13ae3 | 9074 | const char *end_tok; |
018d34a4 | 9075 | int toklen; |
bbc13ae3 KS |
9076 | const char *cond_start = NULL; |
9077 | const char *cond_end = NULL; | |
cc59ec59 | 9078 | |
f1735a53 | 9079 | tok = skip_spaces (tok); |
e7e0cddf SS |
9080 | |
9081 | if ((*tok == '"' || *tok == ',') && rest) | |
9082 | { | |
9083 | *rest = savestring (tok, strlen (tok)); | |
9084 | return; | |
9085 | } | |
9086 | ||
f1735a53 | 9087 | end_tok = skip_to_space (tok); |
d634f2de | 9088 | |
018d34a4 | 9089 | toklen = end_tok - tok; |
d634f2de | 9090 | |
018d34a4 VP |
9091 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9092 | { | |
9093 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9094 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9095 | cond_end = tok; |
d634f2de | 9096 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9097 | } |
9098 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9099 | { | |
5d5658a1 PA |
9100 | const char *tmptok; |
9101 | struct thread_info *thr; | |
d634f2de | 9102 | |
018d34a4 | 9103 | tok = end_tok + 1; |
5d5658a1 | 9104 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9105 | if (tok == tmptok) |
9106 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9107 | *thread = thr->global_num; |
bbc13ae3 | 9108 | tok = tmptok; |
018d34a4 | 9109 | } |
4a306c9a JB |
9110 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9111 | { | |
9112 | char *tmptok; | |
9113 | ||
9114 | tok = end_tok + 1; | |
bbc13ae3 | 9115 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9116 | if (tok == tmptok) |
9117 | error (_("Junk after task keyword.")); | |
9118 | if (!valid_task_id (*task)) | |
b6199126 | 9119 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9120 | tok = tmptok; |
4a306c9a | 9121 | } |
e7e0cddf SS |
9122 | else if (rest) |
9123 | { | |
9124 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9125 | return; |
e7e0cddf | 9126 | } |
018d34a4 VP |
9127 | else |
9128 | error (_("Junk at end of arguments.")); | |
9129 | } | |
9130 | } | |
9131 | ||
0fb4aa4b PA |
9132 | /* Decode a static tracepoint marker spec. */ |
9133 | ||
6c5b2ebe | 9134 | static std::vector<symtab_and_line> |
f00aae0f | 9135 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b | 9136 | { |
f00aae0f KS |
9137 | const char *p = &(*arg_p)[3]; |
9138 | const char *endp; | |
0fb4aa4b | 9139 | |
f1735a53 | 9140 | p = skip_spaces (p); |
0fb4aa4b | 9141 | |
f1735a53 | 9142 | endp = skip_to_space (p); |
0fb4aa4b | 9143 | |
81b1e71c | 9144 | std::string marker_str (p, endp - p); |
0fb4aa4b | 9145 | |
5d9310c4 SM |
9146 | std::vector<static_tracepoint_marker> markers |
9147 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); | |
9148 | if (markers.empty ()) | |
81b1e71c TT |
9149 | error (_("No known static tracepoint marker named %s"), |
9150 | marker_str.c_str ()); | |
0fb4aa4b | 9151 | |
6c5b2ebe | 9152 | std::vector<symtab_and_line> sals; |
5d9310c4 | 9153 | sals.reserve (markers.size ()); |
0fb4aa4b | 9154 | |
5d9310c4 | 9155 | for (const static_tracepoint_marker &marker : markers) |
0fb4aa4b | 9156 | { |
5d9310c4 SM |
9157 | symtab_and_line sal = find_pc_line (marker.address, 0); |
9158 | sal.pc = marker.address; | |
6c5b2ebe | 9159 | sals.push_back (sal); |
5d9310c4 | 9160 | } |
0fb4aa4b | 9161 | |
0fb4aa4b PA |
9162 | *arg_p = endp; |
9163 | return sals; | |
9164 | } | |
9165 | ||
f00aae0f | 9166 | /* See breakpoint.h. */ |
0101ce28 | 9167 | |
8cdf0e15 VP |
9168 | int |
9169 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9170 | const struct event_location *location, |
9171 | const char *cond_string, | |
9172 | int thread, const char *extra_string, | |
f00aae0f | 9173 | int parse_extra, |
0fb4aa4b | 9174 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9175 | int ignore_count, |
9176 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9177 | const struct breakpoint_ops *ops, |
44f238bb PA |
9178 | int from_tty, int enabled, int internal, |
9179 | unsigned flags) | |
c3f6f71d | 9180 | { |
7efd8fc2 | 9181 | struct linespec_result canonical; |
0101ce28 | 9182 | int pending = 0; |
4a306c9a | 9183 | int task = 0; |
86b17b60 | 9184 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9185 | |
348d480f PA |
9186 | gdb_assert (ops != NULL); |
9187 | ||
f00aae0f KS |
9188 | /* If extra_string isn't useful, set it to NULL. */ |
9189 | if (extra_string != NULL && *extra_string == '\0') | |
9190 | extra_string = NULL; | |
9191 | ||
a70b8144 | 9192 | try |
b78a6381 | 9193 | { |
f00aae0f | 9194 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9195 | } |
230d2906 | 9196 | catch (const gdb_exception_error &e) |
0101ce28 | 9197 | { |
492d29ea PA |
9198 | /* If caller is interested in rc value from parse, set |
9199 | value. */ | |
9200 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9201 | { |
05ff989b AC |
9202 | /* If pending breakpoint support is turned off, throw |
9203 | error. */ | |
fa8d40ab JJ |
9204 | |
9205 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
eedc3f4f | 9206 | throw; |
723a2275 VP |
9207 | |
9208 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9209 | |
05ff989b AC |
9210 | /* If pending breakpoint support is auto query and the user |
9211 | selects no, then simply return the error code. */ | |
059fb39f | 9212 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9213 | && !nquery (_("Make %s pending on future shared library load? "), |
9214 | bptype_string (type_wanted))) | |
fd9b8c24 | 9215 | return 0; |
fa8d40ab | 9216 | |
05ff989b AC |
9217 | /* At this point, either the user was queried about setting |
9218 | a pending breakpoint and selected yes, or pending | |
9219 | breakpoint behavior is on and thus a pending breakpoint | |
9220 | is defaulted on behalf of the user. */ | |
f00aae0f | 9221 | pending = 1; |
0101ce28 | 9222 | } |
492d29ea | 9223 | else |
eedc3f4f | 9224 | throw; |
0101ce28 | 9225 | } |
492d29ea | 9226 | |
6c5b2ebe | 9227 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9228 | return 0; |
c3f6f71d | 9229 | |
c3f6f71d JM |
9230 | /* Resolve all line numbers to PC's and verify that the addresses |
9231 | are ok for the target. */ | |
0101ce28 | 9232 | if (!pending) |
f8eba3c6 | 9233 | { |
6c5b2ebe PA |
9234 | for (auto &lsal : canonical.lsals) |
9235 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9236 | } |
c3f6f71d | 9237 | |
7a697b8d | 9238 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9239 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9240 | { |
6c5b2ebe PA |
9241 | for (const auto &lsal : canonical.lsals) |
9242 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9243 | } |
7a697b8d | 9244 | |
c3f6f71d JM |
9245 | /* Verify that condition can be parsed, before setting any |
9246 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9247 | breakpoint. */ |
0101ce28 | 9248 | if (!pending) |
c3f6f71d | 9249 | { |
e1e01040 PA |
9250 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9251 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9252 | ||
f00aae0f | 9253 | if (parse_extra) |
72b2ff0e | 9254 | { |
0878d0fa | 9255 | char *rest; |
e1e01040 | 9256 | char *cond; |
52d361e1 | 9257 | |
6c5b2ebe | 9258 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9259 | |
0878d0fa YQ |
9260 | /* Here we only parse 'arg' to separate condition |
9261 | from thread number, so parsing in context of first | |
9262 | sal is OK. When setting the breakpoint we'll | |
9263 | re-parse it in context of each sal. */ | |
9264 | ||
6c5b2ebe | 9265 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9266 | &cond, &thread, &task, &rest); |
9267 | cond_string_copy.reset (cond); | |
9268 | extra_string_copy.reset (rest); | |
72b2ff0e | 9269 | } |
2f069f6f | 9270 | else |
72b2ff0e | 9271 | { |
f00aae0f KS |
9272 | if (type_wanted != bp_dprintf |
9273 | && extra_string != NULL && *extra_string != '\0') | |
9274 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9275 | |
9276 | /* Create a private copy of condition string. */ | |
9277 | if (cond_string) | |
e1e01040 | 9278 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9279 | /* Create a private copy of any extra string. */ |
9280 | if (extra_string) | |
e1e01040 | 9281 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9282 | } |
0fb4aa4b | 9283 | |
52d361e1 | 9284 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9285 | std::move (cond_string_copy), |
9286 | std::move (extra_string_copy), | |
9287 | type_wanted, | |
d9b3f62e PA |
9288 | tempflag ? disp_del : disp_donttouch, |
9289 | thread, task, ignore_count, ops, | |
44f238bb | 9290 | from_tty, enabled, internal, flags); |
c906108c | 9291 | } |
0101ce28 JJ |
9292 | else |
9293 | { | |
a5e364af | 9294 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9295 | |
a5e364af | 9296 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9297 | b->location = copy_event_location (location); |
bfccc43c | 9298 | |
f00aae0f KS |
9299 | if (parse_extra) |
9300 | b->cond_string = NULL; | |
e12c7713 MK |
9301 | else |
9302 | { | |
9303 | /* Create a private copy of condition string. */ | |
e1e01040 | 9304 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9305 | b->thread = thread; |
e12c7713 | 9306 | } |
f00aae0f KS |
9307 | |
9308 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9309 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9310 | b->ignore_count = ignore_count; |
0101ce28 | 9311 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9312 | b->condition_not_parsed = 1; |
41447f92 | 9313 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9314 | if ((type_wanted != bp_breakpoint |
9315 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9316 | b->pspace = current_program_space; |
8bea4e01 | 9317 | |
b270e6f9 | 9318 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9319 | } |
9320 | ||
6c5b2ebe | 9321 | if (canonical.lsals.size () > 1) |
95a42b64 | 9322 | { |
3e43a32a MS |
9323 | warning (_("Multiple breakpoints were set.\nUse the " |
9324 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9325 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9326 | } |
9327 | ||
44702360 | 9328 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9329 | |
9330 | return 1; | |
c3f6f71d | 9331 | } |
c906108c | 9332 | |
348d480f | 9333 | /* Set a breakpoint. |
72b2ff0e VP |
9334 | ARG is a string describing breakpoint address, |
9335 | condition, and thread. | |
9336 | FLAG specifies if a breakpoint is hardware on, | |
9337 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9338 | and BP_TEMPFLAG. */ | |
348d480f | 9339 | |
98deb0da | 9340 | static void |
f2fc3015 | 9341 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9342 | { |
72b2ff0e | 9343 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9344 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9345 | ? bp_hardware_breakpoint | |
9346 | : bp_breakpoint); | |
55aa24fb | 9347 | struct breakpoint_ops *ops; |
f00aae0f | 9348 | |
ffc2605c | 9349 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9350 | |
9351 | /* Matching breakpoints on probes. */ | |
5b56227b | 9352 | if (location != NULL |
ffc2605c | 9353 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9354 | ops = &bkpt_probe_breakpoint_ops; |
9355 | else | |
9356 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9357 | |
8cdf0e15 | 9358 | create_breakpoint (get_current_arch (), |
ffc2605c | 9359 | location.get (), |
f00aae0f | 9360 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9361 | tempflag, type_wanted, |
8cdf0e15 VP |
9362 | 0 /* Ignore count */, |
9363 | pending_break_support, | |
55aa24fb | 9364 | ops, |
8cdf0e15 | 9365 | from_tty, |
84f4c1fe | 9366 | 1 /* enabled */, |
44f238bb PA |
9367 | 0 /* internal */, |
9368 | 0); | |
c906108c SS |
9369 | } |
9370 | ||
c906108c SS |
9371 | /* Helper function for break_command_1 and disassemble_command. */ |
9372 | ||
9373 | void | |
fba45db2 | 9374 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9375 | { |
9376 | CORE_ADDR pc; | |
9377 | ||
9378 | if (sal->pc == 0 && sal->symtab != NULL) | |
9379 | { | |
9380 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9381 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9382 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9383 | sal->pc = pc; |
6a048695 | 9384 | |
4a64f543 MS |
9385 | /* If this SAL corresponds to a breakpoint inserted using a line |
9386 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9387 | if (sal->explicit_line) |
059acae7 | 9388 | skip_prologue_sal (sal); |
c906108c SS |
9389 | } |
9390 | ||
9391 | if (sal->section == 0 && sal->symtab != NULL) | |
9392 | { | |
346d1dfe | 9393 | const struct blockvector *bv; |
3977b71f | 9394 | const struct block *b; |
c5aa993b | 9395 | struct symbol *sym; |
c906108c | 9396 | |
43f3e411 DE |
9397 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9398 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9399 | if (bv != NULL) |
9400 | { | |
7f0df278 | 9401 | sym = block_linkage_function (b); |
c906108c SS |
9402 | if (sym != NULL) |
9403 | { | |
eb822aa6 DE |
9404 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9405 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9406 | sym); | |
c906108c SS |
9407 | } |
9408 | else | |
9409 | { | |
4a64f543 MS |
9410 | /* It really is worthwhile to have the section, so we'll |
9411 | just have to look harder. This case can be executed | |
9412 | if we have line numbers but no functions (as can | |
9413 | happen in assembly source). */ | |
c906108c | 9414 | |
5ed8105e | 9415 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9416 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9417 | |
5ed8105e | 9418 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9419 | if (msym.minsym) |
efd66ac6 | 9420 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9421 | } |
9422 | } | |
9423 | } | |
9424 | } | |
9425 | ||
9426 | void | |
0b39b52e | 9427 | break_command (const char *arg, int from_tty) |
c906108c | 9428 | { |
db107f19 | 9429 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9430 | } |
9431 | ||
c906108c | 9432 | void |
0b39b52e | 9433 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9434 | { |
db107f19 | 9435 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9436 | } |
9437 | ||
c906108c | 9438 | static void |
0b39b52e | 9439 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9440 | { |
db107f19 | 9441 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9442 | } |
9443 | ||
9444 | static void | |
0b39b52e | 9445 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9446 | { |
db107f19 | 9447 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9448 | } |
9449 | ||
9450 | static void | |
ee7ddd71 | 9451 | stop_command (const char *arg, int from_tty) |
c906108c | 9452 | { |
a3f17187 | 9453 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9454 | Usage: stop in <function | address>\n\ |
a3f17187 | 9455 | stop at <line>\n")); |
c906108c SS |
9456 | } |
9457 | ||
9458 | static void | |
4495129a | 9459 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9460 | { |
9461 | int badInput = 0; | |
9462 | ||
cafb3438 | 9463 | if (arg == NULL) |
c906108c SS |
9464 | badInput = 1; |
9465 | else if (*arg != '*') | |
9466 | { | |
4495129a | 9467 | const char *argptr = arg; |
c906108c SS |
9468 | int hasColon = 0; |
9469 | ||
4a64f543 | 9470 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9471 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9472 | function/method name. */ |
c906108c | 9473 | while (*argptr && !hasColon) |
c5aa993b JM |
9474 | { |
9475 | hasColon = (*argptr == ':'); | |
9476 | argptr++; | |
9477 | } | |
c906108c SS |
9478 | |
9479 | if (hasColon) | |
c5aa993b | 9480 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9481 | else |
c5aa993b | 9482 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9483 | } |
9484 | ||
9485 | if (badInput) | |
a3f17187 | 9486 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9487 | else |
db107f19 | 9488 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9489 | } |
9490 | ||
9491 | static void | |
4495129a | 9492 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9493 | { |
9494 | int badInput = 0; | |
9495 | ||
cafb3438 | 9496 | if (arg == NULL || *arg == '*') /* no line number */ |
c906108c SS |
9497 | badInput = 1; |
9498 | else | |
9499 | { | |
4495129a | 9500 | const char *argptr = arg; |
c906108c SS |
9501 | int hasColon = 0; |
9502 | ||
4a64f543 MS |
9503 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9504 | it is probably a line number. */ | |
c906108c | 9505 | while (*argptr && !hasColon) |
c5aa993b JM |
9506 | { |
9507 | hasColon = (*argptr == ':'); | |
9508 | argptr++; | |
9509 | } | |
c906108c SS |
9510 | |
9511 | if (hasColon) | |
c5aa993b | 9512 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9513 | else |
c5aa993b | 9514 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9515 | } |
9516 | ||
9517 | if (badInput) | |
65e65158 | 9518 | printf_filtered (_("Usage: stop at LINE\n")); |
c906108c | 9519 | else |
db107f19 | 9520 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9521 | } |
9522 | ||
e7e0cddf SS |
9523 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9524 | with a prewired command list consisting of a single output command, | |
9525 | built from extra arguments supplied on the dprintf command | |
9526 | line. */ | |
9527 | ||
da821c7b | 9528 | static void |
0b39b52e | 9529 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9530 | { |
ffc2605c | 9531 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9532 | |
9533 | /* If non-NULL, ARG should have been advanced past the location; | |
9534 | the next character must be ','. */ | |
9535 | if (arg != NULL) | |
9536 | { | |
9537 | if (arg[0] != ',' || arg[1] == '\0') | |
9538 | error (_("Format string required")); | |
9539 | else | |
9540 | { | |
9541 | /* Skip the comma. */ | |
9542 | ++arg; | |
9543 | } | |
9544 | } | |
9545 | ||
e7e0cddf | 9546 | create_breakpoint (get_current_arch (), |
ffc2605c | 9547 | location.get (), |
f00aae0f | 9548 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9549 | 0, bp_dprintf, |
9550 | 0 /* Ignore count */, | |
9551 | pending_break_support, | |
9552 | &dprintf_breakpoint_ops, | |
9553 | from_tty, | |
9554 | 1 /* enabled */, | |
9555 | 0 /* internal */, | |
9556 | 0); | |
9557 | } | |
9558 | ||
d3ce09f5 | 9559 | static void |
0b39b52e | 9560 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9561 | { |
9562 | error (_("May only run agent-printf on the target")); | |
9563 | } | |
9564 | ||
f1310107 TJB |
9565 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9566 | ranged breakpoints. */ | |
9567 | ||
9568 | static int | |
9569 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
bd522513 | 9570 | const address_space *aspace, |
09ac7c10 TT |
9571 | CORE_ADDR bp_addr, |
9572 | const struct target_waitstatus *ws) | |
f1310107 | 9573 | { |
09ac7c10 | 9574 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9575 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9576 | return 0; |
9577 | ||
f1310107 TJB |
9578 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9579 | bl->length, aspace, bp_addr); | |
9580 | } | |
9581 | ||
9582 | /* Implement the "resources_needed" breakpoint_ops method for | |
9583 | ranged breakpoints. */ | |
9584 | ||
9585 | static int | |
9586 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9587 | { | |
9588 | return target_ranged_break_num_registers (); | |
9589 | } | |
9590 | ||
9591 | /* Implement the "print_it" breakpoint_ops method for | |
9592 | ranged breakpoints. */ | |
9593 | ||
9594 | static enum print_stop_action | |
348d480f | 9595 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9596 | { |
348d480f | 9597 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9598 | struct bp_location *bl = b->loc; |
79a45e25 | 9599 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9600 | |
9601 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9602 | ||
9603 | /* Ranged breakpoints have only one location. */ | |
9604 | gdb_assert (bl && bl->next == NULL); | |
9605 | ||
9606 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9607 | |
9608 | maybe_print_thread_hit_breakpoint (uiout); | |
9609 | ||
f1310107 | 9610 | if (b->disposition == disp_del) |
112e8700 | 9611 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9612 | else |
112e8700 SM |
9613 | uiout->text ("Ranged breakpoint "); |
9614 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9615 | { |
112e8700 | 9616 | uiout->field_string ("reason", |
f1310107 | 9617 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9618 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9619 | } |
381befee | 9620 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 9621 | uiout->text (", "); |
f1310107 TJB |
9622 | |
9623 | return PRINT_SRC_AND_LOC; | |
9624 | } | |
9625 | ||
9626 | /* Implement the "print_one" breakpoint_ops method for | |
9627 | ranged breakpoints. */ | |
9628 | ||
9629 | static void | |
9630 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9631 | struct bp_location **last_loc) | |
9632 | { | |
9633 | struct bp_location *bl = b->loc; | |
9634 | struct value_print_options opts; | |
79a45e25 | 9635 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9636 | |
9637 | /* Ranged breakpoints have only one location. */ | |
9638 | gdb_assert (bl && bl->next == NULL); | |
9639 | ||
9640 | get_user_print_options (&opts); | |
9641 | ||
9642 | if (opts.addressprint) | |
9643 | /* We don't print the address range here, it will be printed later | |
9644 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9645 | uiout->field_skip ("addr"); |
f1310107 TJB |
9646 | annotate_field (5); |
9647 | print_breakpoint_location (b, bl); | |
9648 | *last_loc = bl; | |
9649 | } | |
9650 | ||
9651 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9652 | ranged breakpoints. */ | |
9653 | ||
9654 | static void | |
9655 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9656 | struct ui_out *uiout) | |
9657 | { | |
9658 | CORE_ADDR address_start, address_end; | |
9659 | struct bp_location *bl = b->loc; | |
d7e74731 | 9660 | string_file stb; |
f1310107 TJB |
9661 | |
9662 | gdb_assert (bl); | |
9663 | ||
9664 | address_start = bl->address; | |
9665 | address_end = address_start + bl->length - 1; | |
9666 | ||
112e8700 | 9667 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9668 | stb.printf ("[%s, %s]", |
9669 | print_core_address (bl->gdbarch, address_start), | |
9670 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9671 | uiout->field_stream ("addr", stb); |
9672 | uiout->text ("\n"); | |
f1310107 TJB |
9673 | } |
9674 | ||
9675 | /* Implement the "print_mention" breakpoint_ops method for | |
9676 | ranged breakpoints. */ | |
9677 | ||
9678 | static void | |
9679 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9680 | { | |
9681 | struct bp_location *bl = b->loc; | |
79a45e25 | 9682 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9683 | |
9684 | gdb_assert (bl); | |
9685 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9686 | ||
2d33446d TT |
9687 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
9688 | b->number, paddress (bl->gdbarch, bl->address), | |
9689 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
f1310107 TJB |
9690 | } |
9691 | ||
9692 | /* Implement the "print_recreate" breakpoint_ops method for | |
9693 | ranged breakpoints. */ | |
9694 | ||
9695 | static void | |
9696 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9697 | { | |
f00aae0f | 9698 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9699 | event_location_to_string (b->location.get ()), |
9700 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9701 | print_recreate_thread (b, fp); |
f1310107 TJB |
9702 | } |
9703 | ||
9704 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9705 | ||
2060206e | 9706 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9707 | |
9708 | /* Find the address where the end of the breakpoint range should be | |
9709 | placed, given the SAL of the end of the range. This is so that if | |
9710 | the user provides a line number, the end of the range is set to the | |
9711 | last instruction of the given line. */ | |
9712 | ||
9713 | static CORE_ADDR | |
9714 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9715 | { | |
9716 | CORE_ADDR end; | |
9717 | ||
9718 | /* If the user provided a PC value, use it. Otherwise, | |
9719 | find the address of the end of the given location. */ | |
9720 | if (sal.explicit_pc) | |
9721 | end = sal.pc; | |
9722 | else | |
9723 | { | |
9724 | int ret; | |
9725 | CORE_ADDR start; | |
9726 | ||
9727 | ret = find_line_pc_range (sal, &start, &end); | |
9728 | if (!ret) | |
9729 | error (_("Could not find location of the end of the range.")); | |
9730 | ||
9731 | /* find_line_pc_range returns the start of the next line. */ | |
9732 | end--; | |
9733 | } | |
9734 | ||
9735 | return end; | |
9736 | } | |
9737 | ||
9738 | /* Implement the "break-range" CLI command. */ | |
9739 | ||
9740 | static void | |
0b39b52e | 9741 | break_range_command (const char *arg, int from_tty) |
f1310107 | 9742 | { |
f2fc3015 | 9743 | const char *arg_start; |
f1310107 TJB |
9744 | struct linespec_result canonical_start, canonical_end; |
9745 | int bp_count, can_use_bp, length; | |
9746 | CORE_ADDR end; | |
9747 | struct breakpoint *b; | |
f1310107 TJB |
9748 | |
9749 | /* We don't support software ranged breakpoints. */ | |
9750 | if (target_ranged_break_num_registers () < 0) | |
9751 | error (_("This target does not support hardware ranged breakpoints.")); | |
9752 | ||
9753 | bp_count = hw_breakpoint_used_count (); | |
9754 | bp_count += target_ranged_break_num_registers (); | |
9755 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9756 | bp_count, 0); | |
9757 | if (can_use_bp < 0) | |
9758 | error (_("Hardware breakpoints used exceeds limit.")); | |
9759 | ||
f8eba3c6 | 9760 | arg = skip_spaces (arg); |
f1310107 TJB |
9761 | if (arg == NULL || arg[0] == '\0') |
9762 | error(_("No address range specified.")); | |
9763 | ||
f8eba3c6 | 9764 | arg_start = arg; |
ffc2605c TT |
9765 | event_location_up start_location = string_to_event_location (&arg, |
9766 | current_language); | |
9767 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
9768 | |
9769 | if (arg[0] != ',') | |
9770 | error (_("Too few arguments.")); | |
6c5b2ebe | 9771 | else if (canonical_start.lsals.empty ()) |
f1310107 | 9772 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 9773 | |
6c5b2ebe | 9774 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 9775 | |
6c5b2ebe PA |
9776 | if (canonical_start.lsals.size () > 1 |
9777 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
9778 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9779 | ||
6c5b2ebe | 9780 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 9781 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
9782 | |
9783 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9784 | arg = skip_spaces (arg); |
f1310107 TJB |
9785 | |
9786 | /* Parse the end location. */ | |
9787 | ||
f1310107 TJB |
9788 | arg_start = arg; |
9789 | ||
f8eba3c6 | 9790 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9791 | parse_breakpoint_sals because we need to specify the start location's |
9792 | symtab and line as the default symtab and line for the end of the | |
9793 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9794 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
9795 | event_location_up end_location = string_to_event_location (&arg, |
9796 | current_language); | |
9797 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
9798 | sal_start.symtab, sal_start.line, |
9799 | &canonical_end, NULL, NULL); | |
9800 | ||
6c5b2ebe | 9801 | if (canonical_end.lsals.empty ()) |
f1310107 | 9802 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 9803 | |
6c5b2ebe PA |
9804 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
9805 | if (canonical_end.lsals.size () > 1 | |
9806 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
9807 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9808 | ||
6c5b2ebe | 9809 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
9810 | |
9811 | end = find_breakpoint_range_end (sal_end); | |
9812 | if (sal_start.pc > end) | |
177b42fe | 9813 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9814 | |
9815 | length = end - sal_start.pc + 1; | |
9816 | if (length < 0) | |
9817 | /* Length overflowed. */ | |
9818 | error (_("Address range too large.")); | |
9819 | else if (length == 1) | |
9820 | { | |
9821 | /* This range is simple enough to be handled by | |
9822 | the `hbreak' command. */ | |
81b1e71c | 9823 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
9824 | |
9825 | return; | |
9826 | } | |
9827 | ||
9828 | /* Now set up the breakpoint. */ | |
9829 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 9830 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
9831 | set_breakpoint_count (breakpoint_count + 1); |
9832 | b->number = breakpoint_count; | |
9833 | b->disposition = disp_donttouch; | |
d28cd78a TT |
9834 | b->location = std::move (start_location); |
9835 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
9836 | b->loc->length = length; |
9837 | ||
f1310107 | 9838 | mention (b); |
76727919 | 9839 | gdb::observers::breakpoint_created.notify (b); |
44702360 | 9840 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
9841 | } |
9842 | ||
4a64f543 MS |
9843 | /* Return non-zero if EXP is verified as constant. Returned zero |
9844 | means EXP is variable. Also the constant detection may fail for | |
9845 | some constant expressions and in such case still falsely return | |
9846 | zero. */ | |
2e6e3d9c | 9847 | |
65d79d4b SDJ |
9848 | static int |
9849 | watchpoint_exp_is_const (const struct expression *exp) | |
9850 | { | |
9851 | int i = exp->nelts; | |
9852 | ||
9853 | while (i > 0) | |
9854 | { | |
9855 | int oplenp, argsp; | |
9856 | ||
9857 | /* We are only interested in the descriptor of each element. */ | |
9858 | operator_length (exp, i, &oplenp, &argsp); | |
9859 | i -= oplenp; | |
9860 | ||
9861 | switch (exp->elts[i].opcode) | |
9862 | { | |
9863 | case BINOP_ADD: | |
9864 | case BINOP_SUB: | |
9865 | case BINOP_MUL: | |
9866 | case BINOP_DIV: | |
9867 | case BINOP_REM: | |
9868 | case BINOP_MOD: | |
9869 | case BINOP_LSH: | |
9870 | case BINOP_RSH: | |
9871 | case BINOP_LOGICAL_AND: | |
9872 | case BINOP_LOGICAL_OR: | |
9873 | case BINOP_BITWISE_AND: | |
9874 | case BINOP_BITWISE_IOR: | |
9875 | case BINOP_BITWISE_XOR: | |
9876 | case BINOP_EQUAL: | |
9877 | case BINOP_NOTEQUAL: | |
9878 | case BINOP_LESS: | |
9879 | case BINOP_GTR: | |
9880 | case BINOP_LEQ: | |
9881 | case BINOP_GEQ: | |
9882 | case BINOP_REPEAT: | |
9883 | case BINOP_COMMA: | |
9884 | case BINOP_EXP: | |
9885 | case BINOP_MIN: | |
9886 | case BINOP_MAX: | |
9887 | case BINOP_INTDIV: | |
9888 | case BINOP_CONCAT: | |
65d79d4b SDJ |
9889 | case TERNOP_COND: |
9890 | case TERNOP_SLICE: | |
65d79d4b SDJ |
9891 | |
9892 | case OP_LONG: | |
edd079d9 | 9893 | case OP_FLOAT: |
65d79d4b SDJ |
9894 | case OP_LAST: |
9895 | case OP_COMPLEX: | |
9896 | case OP_STRING: | |
65d79d4b SDJ |
9897 | case OP_ARRAY: |
9898 | case OP_TYPE: | |
608b4967 TT |
9899 | case OP_TYPEOF: |
9900 | case OP_DECLTYPE: | |
6e72ca20 | 9901 | case OP_TYPEID: |
65d79d4b SDJ |
9902 | case OP_NAME: |
9903 | case OP_OBJC_NSSTRING: | |
9904 | ||
9905 | case UNOP_NEG: | |
9906 | case UNOP_LOGICAL_NOT: | |
9907 | case UNOP_COMPLEMENT: | |
9908 | case UNOP_ADDR: | |
9909 | case UNOP_HIGH: | |
aeaa2474 | 9910 | case UNOP_CAST: |
9eaf6705 TT |
9911 | |
9912 | case UNOP_CAST_TYPE: | |
9913 | case UNOP_REINTERPRET_CAST: | |
9914 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
9915 | /* Unary, binary and ternary operators: We have to check |
9916 | their operands. If they are constant, then so is the | |
9917 | result of that operation. For instance, if A and B are | |
9918 | determined to be constants, then so is "A + B". | |
9919 | ||
9920 | UNOP_IND is one exception to the rule above, because the | |
9921 | value of *ADDR is not necessarily a constant, even when | |
9922 | ADDR is. */ | |
65d79d4b SDJ |
9923 | break; |
9924 | ||
9925 | case OP_VAR_VALUE: | |
9926 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 9927 | |
65d79d4b | 9928 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
9929 | possible that a buggy compiler could mark a variable as |
9930 | constant even when it is not, and TYPE_CONST would return | |
9931 | true in this case, while SYMBOL_CLASS wouldn't. | |
9932 | ||
9933 | We also have to check for function symbols because they | |
9934 | are always constant. */ | |
65d79d4b SDJ |
9935 | { |
9936 | struct symbol *s = exp->elts[i + 2].symbol; | |
9937 | ||
9938 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
9939 | && SYMBOL_CLASS (s) != LOC_CONST | |
9940 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
9941 | return 0; | |
9942 | break; | |
9943 | } | |
9944 | ||
9945 | /* The default action is to return 0 because we are using | |
9946 | the optimistic approach here: If we don't know something, | |
9947 | then it is not a constant. */ | |
9948 | default: | |
9949 | return 0; | |
9950 | } | |
9951 | } | |
9952 | ||
9953 | return 1; | |
9954 | } | |
9955 | ||
c1fc2657 | 9956 | /* Watchpoint destructor. */ |
3a5c3e22 | 9957 | |
c1fc2657 | 9958 | watchpoint::~watchpoint () |
3a5c3e22 | 9959 | { |
c1fc2657 SM |
9960 | xfree (this->exp_string); |
9961 | xfree (this->exp_string_reparse); | |
3a5c3e22 PA |
9962 | } |
9963 | ||
348d480f PA |
9964 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
9965 | ||
9966 | static void | |
9967 | re_set_watchpoint (struct breakpoint *b) | |
9968 | { | |
3a5c3e22 PA |
9969 | struct watchpoint *w = (struct watchpoint *) b; |
9970 | ||
348d480f PA |
9971 | /* Watchpoint can be either on expression using entirely global |
9972 | variables, or it can be on local variables. | |
9973 | ||
9974 | Watchpoints of the first kind are never auto-deleted, and even | |
9975 | persist across program restarts. Since they can use variables | |
9976 | from shared libraries, we need to reparse expression as libraries | |
9977 | are loaded and unloaded. | |
9978 | ||
9979 | Watchpoints on local variables can also change meaning as result | |
9980 | of solib event. For example, if a watchpoint uses both a local | |
9981 | and a global variables in expression, it's a local watchpoint, | |
9982 | but unloading of a shared library will make the expression | |
9983 | invalid. This is not a very common use case, but we still | |
9984 | re-evaluate expression, to avoid surprises to the user. | |
9985 | ||
9986 | Note that for local watchpoints, we re-evaluate it only if | |
9987 | watchpoints frame id is still valid. If it's not, it means the | |
9988 | watchpoint is out of scope and will be deleted soon. In fact, | |
9989 | I'm not sure we'll ever be called in this case. | |
9990 | ||
9991 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 9992 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 9993 | |
3a5c3e22 PA |
9994 | Don't do anything about disabled watchpoints, since they will be |
9995 | reevaluated again when enabled. */ | |
9996 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
9997 | } |
9998 | ||
77b06cd7 TJB |
9999 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10000 | ||
10001 | static int | |
10002 | insert_watchpoint (struct bp_location *bl) | |
10003 | { | |
3a5c3e22 PA |
10004 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10005 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10006 | |
10007 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10008 | w->cond_exp.get ()); |
77b06cd7 TJB |
10009 | } |
10010 | ||
10011 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10012 | ||
10013 | static int | |
73971819 | 10014 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10015 | { |
3a5c3e22 PA |
10016 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10017 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10018 | |
10019 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10020 | w->cond_exp.get ()); |
e09342b5 TJB |
10021 | } |
10022 | ||
e09342b5 | 10023 | static int |
348d480f | 10024 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
bd522513 | 10025 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 10026 | const struct target_waitstatus *ws) |
e09342b5 | 10027 | { |
348d480f | 10028 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10029 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10030 | |
348d480f PA |
10031 | /* Continuable hardware watchpoints are treated as non-existent if the |
10032 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10033 | some data address). Otherwise gdb won't stop on a break instruction | |
10034 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10035 | been defined. Also skip watchpoints which we know did not trigger | |
10036 | (did not match the data address). */ | |
10037 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10038 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10039 | return 0; |
9c06b0b4 | 10040 | |
348d480f | 10041 | return 1; |
9c06b0b4 TJB |
10042 | } |
10043 | ||
348d480f PA |
10044 | static void |
10045 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10046 | { |
348d480f | 10047 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10048 | |
348d480f | 10049 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10050 | } |
10051 | ||
10052 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10053 | hardware watchpoints. */ |
9c06b0b4 TJB |
10054 | |
10055 | static int | |
348d480f | 10056 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10057 | { |
3a5c3e22 PA |
10058 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10059 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10060 | |
10061 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10062 | } |
10063 | ||
10064 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10065 | hardware watchpoints. */ |
9c06b0b4 TJB |
10066 | |
10067 | static int | |
348d480f | 10068 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10069 | { |
efa80663 PA |
10070 | /* Read and access watchpoints only work with hardware support. */ |
10071 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10072 | } |
10073 | ||
9c06b0b4 | 10074 | static enum print_stop_action |
348d480f | 10075 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10076 | { |
348d480f | 10077 | struct breakpoint *b; |
348d480f | 10078 | enum print_stop_action result; |
3a5c3e22 | 10079 | struct watchpoint *w; |
79a45e25 | 10080 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10081 | |
10082 | gdb_assert (bs->bp_location_at != NULL); | |
10083 | ||
348d480f | 10084 | b = bs->breakpoint_at; |
3a5c3e22 | 10085 | w = (struct watchpoint *) b; |
348d480f | 10086 | |
f303dbd6 PA |
10087 | annotate_watchpoint (b->number); |
10088 | maybe_print_thread_hit_breakpoint (uiout); | |
10089 | ||
d7e74731 PA |
10090 | string_file stb; |
10091 | ||
76f9c9cf | 10092 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10093 | switch (b->type) |
10094 | { | |
348d480f | 10095 | case bp_watchpoint: |
9c06b0b4 | 10096 | case bp_hardware_watchpoint: |
112e8700 SM |
10097 | if (uiout->is_mi_like_p ()) |
10098 | uiout->field_string | |
10099 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10100 | mention (b); |
76f9c9cf | 10101 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10102 | uiout->text ("\nOld value = "); |
850645cf | 10103 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10104 | uiout->field_stream ("old", stb); |
10105 | uiout->text ("\nNew value = "); | |
850645cf | 10106 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10107 | uiout->field_stream ("new", stb); |
10108 | uiout->text ("\n"); | |
348d480f PA |
10109 | /* More than one watchpoint may have been triggered. */ |
10110 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10111 | break; |
10112 | ||
10113 | case bp_read_watchpoint: | |
112e8700 SM |
10114 | if (uiout->is_mi_like_p ()) |
10115 | uiout->field_string | |
10116 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10117 | mention (b); |
76f9c9cf | 10118 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10119 | uiout->text ("\nValue = "); |
850645cf | 10120 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10121 | uiout->field_stream ("value", stb); |
10122 | uiout->text ("\n"); | |
348d480f | 10123 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10124 | break; |
10125 | ||
10126 | case bp_access_watchpoint: | |
348d480f PA |
10127 | if (bs->old_val != NULL) |
10128 | { | |
112e8700 SM |
10129 | if (uiout->is_mi_like_p ()) |
10130 | uiout->field_string | |
10131 | ("reason", | |
348d480f PA |
10132 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10133 | mention (b); | |
76f9c9cf | 10134 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10135 | uiout->text ("\nOld value = "); |
850645cf | 10136 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10137 | uiout->field_stream ("old", stb); |
10138 | uiout->text ("\nNew value = "); | |
348d480f PA |
10139 | } |
10140 | else | |
10141 | { | |
10142 | mention (b); | |
112e8700 SM |
10143 | if (uiout->is_mi_like_p ()) |
10144 | uiout->field_string | |
10145 | ("reason", | |
348d480f | 10146 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10147 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10148 | uiout->text ("\nValue = "); |
348d480f | 10149 | } |
850645cf | 10150 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10151 | uiout->field_stream ("new", stb); |
10152 | uiout->text ("\n"); | |
348d480f | 10153 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10154 | break; |
10155 | default: | |
348d480f | 10156 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10157 | } |
10158 | ||
348d480f PA |
10159 | return result; |
10160 | } | |
10161 | ||
10162 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10163 | watchpoints. */ | |
10164 | ||
10165 | static void | |
10166 | print_mention_watchpoint (struct breakpoint *b) | |
10167 | { | |
3a5c3e22 | 10168 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10169 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10170 | const char *tuple_name; |
348d480f PA |
10171 | |
10172 | switch (b->type) | |
10173 | { | |
10174 | case bp_watchpoint: | |
112e8700 | 10175 | uiout->text ("Watchpoint "); |
46b9c129 | 10176 | tuple_name = "wpt"; |
348d480f PA |
10177 | break; |
10178 | case bp_hardware_watchpoint: | |
112e8700 | 10179 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10180 | tuple_name = "wpt"; |
348d480f PA |
10181 | break; |
10182 | case bp_read_watchpoint: | |
112e8700 | 10183 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10184 | tuple_name = "hw-rwpt"; |
348d480f PA |
10185 | break; |
10186 | case bp_access_watchpoint: | |
112e8700 | 10187 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10188 | tuple_name = "hw-awpt"; |
348d480f PA |
10189 | break; |
10190 | default: | |
10191 | internal_error (__FILE__, __LINE__, | |
10192 | _("Invalid hardware watchpoint type.")); | |
10193 | } | |
10194 | ||
46b9c129 | 10195 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10196 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10197 | uiout->text (": "); |
10198 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10199 | } |
10200 | ||
10201 | /* Implement the "print_recreate" breakpoint_ops method for | |
10202 | watchpoints. */ | |
10203 | ||
10204 | static void | |
10205 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10206 | { | |
3a5c3e22 PA |
10207 | struct watchpoint *w = (struct watchpoint *) b; |
10208 | ||
348d480f PA |
10209 | switch (b->type) |
10210 | { | |
10211 | case bp_watchpoint: | |
10212 | case bp_hardware_watchpoint: | |
10213 | fprintf_unfiltered (fp, "watch"); | |
10214 | break; | |
10215 | case bp_read_watchpoint: | |
10216 | fprintf_unfiltered (fp, "rwatch"); | |
10217 | break; | |
10218 | case bp_access_watchpoint: | |
10219 | fprintf_unfiltered (fp, "awatch"); | |
10220 | break; | |
10221 | default: | |
10222 | internal_error (__FILE__, __LINE__, | |
10223 | _("Invalid watchpoint type.")); | |
10224 | } | |
10225 | ||
3a5c3e22 | 10226 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10227 | print_recreate_thread (b, fp); |
348d480f PA |
10228 | } |
10229 | ||
427cd150 TT |
10230 | /* Implement the "explains_signal" breakpoint_ops method for |
10231 | watchpoints. */ | |
10232 | ||
47591c29 | 10233 | static int |
427cd150 TT |
10234 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10235 | { | |
10236 | /* A software watchpoint cannot cause a signal other than | |
10237 | GDB_SIGNAL_TRAP. */ | |
10238 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10239 | return 0; |
427cd150 | 10240 | |
47591c29 | 10241 | return 1; |
427cd150 TT |
10242 | } |
10243 | ||
348d480f PA |
10244 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10245 | ||
2060206e | 10246 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10247 | |
10248 | /* Implement the "insert" breakpoint_ops method for | |
10249 | masked hardware watchpoints. */ | |
10250 | ||
10251 | static int | |
10252 | insert_masked_watchpoint (struct bp_location *bl) | |
10253 | { | |
3a5c3e22 PA |
10254 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10255 | ||
10256 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10257 | bl->watchpoint_type); |
10258 | } | |
10259 | ||
10260 | /* Implement the "remove" breakpoint_ops method for | |
10261 | masked hardware watchpoints. */ | |
10262 | ||
10263 | static int | |
73971819 | 10264 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10265 | { |
3a5c3e22 PA |
10266 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10267 | ||
10268 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10269 | bl->watchpoint_type); |
10270 | } | |
10271 | ||
10272 | /* Implement the "resources_needed" breakpoint_ops method for | |
10273 | masked hardware watchpoints. */ | |
10274 | ||
10275 | static int | |
10276 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10277 | { | |
3a5c3e22 PA |
10278 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10279 | ||
10280 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10281 | } |
10282 | ||
10283 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10284 | masked hardware watchpoints. */ | |
10285 | ||
10286 | static int | |
10287 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10288 | { | |
10289 | return 0; | |
10290 | } | |
10291 | ||
10292 | /* Implement the "print_it" breakpoint_ops method for | |
10293 | masked hardware watchpoints. */ | |
10294 | ||
10295 | static enum print_stop_action | |
10296 | print_it_masked_watchpoint (bpstat bs) | |
10297 | { | |
10298 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10299 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10300 | |
10301 | /* Masked watchpoints have only one location. */ | |
10302 | gdb_assert (b->loc && b->loc->next == NULL); | |
10303 | ||
f303dbd6 PA |
10304 | annotate_watchpoint (b->number); |
10305 | maybe_print_thread_hit_breakpoint (uiout); | |
10306 | ||
348d480f PA |
10307 | switch (b->type) |
10308 | { | |
10309 | case bp_hardware_watchpoint: | |
112e8700 SM |
10310 | if (uiout->is_mi_like_p ()) |
10311 | uiout->field_string | |
10312 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10313 | break; |
10314 | ||
10315 | case bp_read_watchpoint: | |
112e8700 SM |
10316 | if (uiout->is_mi_like_p ()) |
10317 | uiout->field_string | |
10318 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10319 | break; |
10320 | ||
10321 | case bp_access_watchpoint: | |
112e8700 SM |
10322 | if (uiout->is_mi_like_p ()) |
10323 | uiout->field_string | |
10324 | ("reason", | |
348d480f PA |
10325 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10326 | break; | |
10327 | default: | |
10328 | internal_error (__FILE__, __LINE__, | |
10329 | _("Invalid hardware watchpoint type.")); | |
10330 | } | |
10331 | ||
10332 | mention (b); | |
112e8700 | 10333 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10334 | Check the underlying instruction at PC for the memory\n\ |
10335 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10336 | uiout->text ("\n"); |
9c06b0b4 TJB |
10337 | |
10338 | /* More than one watchpoint may have been triggered. */ | |
10339 | return PRINT_UNKNOWN; | |
10340 | } | |
10341 | ||
10342 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10343 | masked hardware watchpoints. */ | |
10344 | ||
10345 | static void | |
10346 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10347 | struct ui_out *uiout) | |
10348 | { | |
3a5c3e22 PA |
10349 | struct watchpoint *w = (struct watchpoint *) b; |
10350 | ||
9c06b0b4 TJB |
10351 | /* Masked watchpoints have only one location. */ |
10352 | gdb_assert (b->loc && b->loc->next == NULL); | |
10353 | ||
112e8700 SM |
10354 | uiout->text ("\tmask "); |
10355 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10356 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10357 | } |
10358 | ||
10359 | /* Implement the "print_mention" breakpoint_ops method for | |
10360 | masked hardware watchpoints. */ | |
10361 | ||
10362 | static void | |
10363 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10364 | { | |
3a5c3e22 | 10365 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10366 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10367 | const char *tuple_name; |
9c06b0b4 TJB |
10368 | |
10369 | switch (b->type) | |
10370 | { | |
10371 | case bp_hardware_watchpoint: | |
112e8700 | 10372 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10373 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10374 | break; |
10375 | case bp_read_watchpoint: | |
112e8700 | 10376 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10377 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10378 | break; |
10379 | case bp_access_watchpoint: | |
112e8700 | 10380 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10381 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10382 | break; |
10383 | default: | |
10384 | internal_error (__FILE__, __LINE__, | |
10385 | _("Invalid hardware watchpoint type.")); | |
10386 | } | |
10387 | ||
46b9c129 | 10388 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10389 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10390 | uiout->text (": "); |
10391 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10392 | } |
10393 | ||
10394 | /* Implement the "print_recreate" breakpoint_ops method for | |
10395 | masked hardware watchpoints. */ | |
10396 | ||
10397 | static void | |
10398 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10399 | { | |
3a5c3e22 | 10400 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10401 | char tmp[40]; |
10402 | ||
10403 | switch (b->type) | |
10404 | { | |
10405 | case bp_hardware_watchpoint: | |
10406 | fprintf_unfiltered (fp, "watch"); | |
10407 | break; | |
10408 | case bp_read_watchpoint: | |
10409 | fprintf_unfiltered (fp, "rwatch"); | |
10410 | break; | |
10411 | case bp_access_watchpoint: | |
10412 | fprintf_unfiltered (fp, "awatch"); | |
10413 | break; | |
10414 | default: | |
10415 | internal_error (__FILE__, __LINE__, | |
10416 | _("Invalid hardware watchpoint type.")); | |
10417 | } | |
10418 | ||
3a5c3e22 PA |
10419 | sprintf_vma (tmp, w->hw_wp_mask); |
10420 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10421 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10422 | } |
10423 | ||
10424 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10425 | ||
2060206e | 10426 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10427 | |
10428 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10429 | ||
f2478a7e | 10430 | static bool |
9c06b0b4 TJB |
10431 | is_masked_watchpoint (const struct breakpoint *b) |
10432 | { | |
10433 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10434 | } | |
10435 | ||
53a5351d JM |
10436 | /* accessflag: hw_write: watch write, |
10437 | hw_read: watch read, | |
10438 | hw_access: watch access (read or write) */ | |
c906108c | 10439 | static void |
bbc13ae3 | 10440 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10441 | int just_location, int internal) |
c906108c | 10442 | { |
c1fc2657 | 10443 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10444 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
b926417a | 10445 | struct value *result; |
bb9d5f81 | 10446 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10447 | const char *exp_start = NULL; |
10448 | const char *exp_end = NULL; | |
10449 | const char *tok, *end_tok; | |
9c06b0b4 | 10450 | int toklen = -1; |
bbc13ae3 KS |
10451 | const char *cond_start = NULL; |
10452 | const char *cond_end = NULL; | |
c906108c | 10453 | enum bptype bp_type; |
37e4754d | 10454 | int thread = -1; |
0cf6dd15 | 10455 | int pc = 0; |
9c06b0b4 TJB |
10456 | /* Flag to indicate whether we are going to use masks for |
10457 | the hardware watchpoint. */ | |
10458 | int use_mask = 0; | |
10459 | CORE_ADDR mask = 0; | |
c906108c | 10460 | |
37e4754d LM |
10461 | /* Make sure that we actually have parameters to parse. */ |
10462 | if (arg != NULL && arg[0] != '\0') | |
10463 | { | |
bbc13ae3 KS |
10464 | const char *value_start; |
10465 | ||
10466 | exp_end = arg + strlen (arg); | |
37e4754d | 10467 | |
9c06b0b4 TJB |
10468 | /* Look for "parameter value" pairs at the end |
10469 | of the arguments string. */ | |
bbc13ae3 | 10470 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10471 | { |
10472 | /* Skip whitespace at the end of the argument list. */ | |
10473 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10474 | tok--; | |
10475 | ||
10476 | /* Find the beginning of the last token. | |
10477 | This is the value of the parameter. */ | |
10478 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10479 | tok--; | |
10480 | value_start = tok + 1; | |
10481 | ||
10482 | /* Skip whitespace. */ | |
10483 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10484 | tok--; | |
10485 | ||
10486 | end_tok = tok; | |
10487 | ||
10488 | /* Find the beginning of the second to last token. | |
10489 | This is the parameter itself. */ | |
10490 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10491 | tok--; | |
10492 | tok++; | |
10493 | toklen = end_tok - tok + 1; | |
10494 | ||
61012eef | 10495 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10496 | { |
5d5658a1 | 10497 | struct thread_info *thr; |
9c06b0b4 TJB |
10498 | /* At this point we've found a "thread" token, which means |
10499 | the user is trying to set a watchpoint that triggers | |
10500 | only in a specific thread. */ | |
5d5658a1 | 10501 | const char *endp; |
37e4754d | 10502 | |
9c06b0b4 TJB |
10503 | if (thread != -1) |
10504 | error(_("You can specify only one thread.")); | |
37e4754d | 10505 | |
9c06b0b4 | 10506 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10507 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10508 | |
5d5658a1 | 10509 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10510 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10511 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10512 | |
5d5658a1 | 10513 | thread = thr->global_num; |
9c06b0b4 | 10514 | } |
61012eef | 10515 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10516 | { |
10517 | /* We've found a "mask" token, which means the user wants to | |
10518 | create a hardware watchpoint that is going to have the mask | |
10519 | facility. */ | |
10520 | struct value *mask_value, *mark; | |
37e4754d | 10521 | |
9c06b0b4 TJB |
10522 | if (use_mask) |
10523 | error(_("You can specify only one mask.")); | |
37e4754d | 10524 | |
9c06b0b4 | 10525 | use_mask = just_location = 1; |
37e4754d | 10526 | |
9c06b0b4 TJB |
10527 | mark = value_mark (); |
10528 | mask_value = parse_to_comma_and_eval (&value_start); | |
10529 | mask = value_as_address (mask_value); | |
10530 | value_free_to_mark (mark); | |
10531 | } | |
10532 | else | |
10533 | /* We didn't recognize what we found. We should stop here. */ | |
10534 | break; | |
37e4754d | 10535 | |
9c06b0b4 TJB |
10536 | /* Truncate the string and get rid of the "parameter value" pair before |
10537 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10538 | exp_end = tok; |
9c06b0b4 | 10539 | } |
37e4754d | 10540 | } |
bbc13ae3 KS |
10541 | else |
10542 | exp_end = arg; | |
37e4754d | 10543 | |
bbc13ae3 KS |
10544 | /* Parse the rest of the arguments. From here on out, everything |
10545 | is in terms of a newly allocated string instead of the original | |
10546 | ARG. */ | |
81b1e71c TT |
10547 | std::string expression (arg, exp_end - arg); |
10548 | exp_start = arg = expression.c_str (); | |
699bd4cf TT |
10549 | innermost_block_tracker tracker; |
10550 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); | |
c906108c | 10551 | exp_end = arg; |
fa8a61dc TT |
10552 | /* Remove trailing whitespace from the expression before saving it. |
10553 | This makes the eventual display of the expression string a bit | |
10554 | prettier. */ | |
10555 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10556 | --exp_end; | |
10557 | ||
65d79d4b | 10558 | /* Checking if the expression is not constant. */ |
4d01a485 | 10559 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10560 | { |
10561 | int len; | |
10562 | ||
10563 | len = exp_end - exp_start; | |
10564 | while (len > 0 && isspace (exp_start[len - 1])) | |
10565 | len--; | |
10566 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10567 | } | |
10568 | ||
699bd4cf | 10569 | exp_valid_block = tracker.block (); |
b926417a | 10570 | struct value *mark = value_mark (); |
850645cf TT |
10571 | struct value *val_as_value = nullptr; |
10572 | fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL, | |
10573 | just_location); | |
06a64a0b | 10574 | |
850645cf | 10575 | if (val_as_value != NULL && just_location) |
bb9d5f81 | 10576 | { |
850645cf TT |
10577 | saved_bitpos = value_bitpos (val_as_value); |
10578 | saved_bitsize = value_bitsize (val_as_value); | |
bb9d5f81 PP |
10579 | } |
10580 | ||
850645cf | 10581 | value_ref_ptr val; |
06a64a0b TT |
10582 | if (just_location) |
10583 | { | |
9c06b0b4 TJB |
10584 | int ret; |
10585 | ||
06a64a0b | 10586 | exp_valid_block = NULL; |
850645cf | 10587 | val = release_value (value_addr (result)); |
06a64a0b | 10588 | value_free_to_mark (mark); |
9c06b0b4 TJB |
10589 | |
10590 | if (use_mask) | |
10591 | { | |
850645cf | 10592 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
9c06b0b4 TJB |
10593 | mask); |
10594 | if (ret == -1) | |
10595 | error (_("This target does not support masked watchpoints.")); | |
10596 | else if (ret == -2) | |
10597 | error (_("Invalid mask or memory region.")); | |
10598 | } | |
06a64a0b | 10599 | } |
850645cf TT |
10600 | else if (val_as_value != NULL) |
10601 | val = release_value (val_as_value); | |
c906108c | 10602 | |
f1735a53 TT |
10603 | tok = skip_spaces (arg); |
10604 | end_tok = skip_to_space (tok); | |
c906108c SS |
10605 | |
10606 | toklen = end_tok - tok; | |
10607 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10608 | { | |
10609 | tok = cond_start = end_tok + 1; | |
699bd4cf TT |
10610 | innermost_block_tracker if_tracker; |
10611 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); | |
60e1c644 PA |
10612 | |
10613 | /* The watchpoint expression may not be local, but the condition | |
10614 | may still be. E.g.: `watch global if local > 0'. */ | |
699bd4cf | 10615 | cond_exp_valid_block = if_tracker.block (); |
60e1c644 | 10616 | |
c906108c SS |
10617 | cond_end = tok; |
10618 | } | |
10619 | if (*tok) | |
8a3fe4f8 | 10620 | error (_("Junk at end of command.")); |
c906108c | 10621 | |
441d7c93 PA |
10622 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10623 | ||
10624 | /* Save this because create_internal_breakpoint below invalidates | |
10625 | 'wp_frame'. */ | |
10626 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10627 | |
10628 | /* If the expression is "local", then set up a "watchpoint scope" | |
10629 | breakpoint at the point where we've left the scope of the watchpoint | |
10630 | expression. Create the scope breakpoint before the watchpoint, so | |
10631 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10632 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10633 | { |
441d7c93 PA |
10634 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10635 | ||
10636 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10637 | { |
441d7c93 PA |
10638 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10639 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10640 | ||
edb3359d | 10641 | scope_breakpoint |
441d7c93 | 10642 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10643 | bp_watchpoint_scope, |
10644 | &momentary_breakpoint_ops); | |
d983da9c | 10645 | |
441d7c93 PA |
10646 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10647 | wp_frame = NULL; | |
10648 | ||
edb3359d | 10649 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10650 | |
edb3359d DJ |
10651 | /* Automatically delete the breakpoint when it hits. */ |
10652 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10653 | |
edb3359d | 10654 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10655 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10656 | |
edb3359d | 10657 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10658 | scope_breakpoint->loc->gdbarch = caller_arch; |
10659 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10660 | scope_breakpoint->loc->address |
a6d9a66e UW |
10661 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10662 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10663 | scope_breakpoint->type); |
10664 | } | |
d983da9c DJ |
10665 | } |
10666 | ||
e8369a73 AB |
10667 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10668 | watchpoints here even if hardware watchpoints are turned off, a call | |
10669 | to update_watchpoint later in this function will cause the type to | |
10670 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10671 | ||
10672 | if (accessflag == hw_read) | |
10673 | bp_type = bp_read_watchpoint; | |
10674 | else if (accessflag == hw_access) | |
10675 | bp_type = bp_access_watchpoint; | |
10676 | else | |
10677 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10678 | |
b270e6f9 | 10679 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10680 | |
348d480f | 10681 | if (use_mask) |
b270e6f9 | 10682 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10683 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10684 | else |
b270e6f9 | 10685 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10686 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
10687 | w->thread = thread; |
10688 | w->disposition = disp_donttouch; | |
10689 | w->pspace = current_program_space; | |
b22e99fd | 10690 | w->exp = std::move (exp); |
3a5c3e22 PA |
10691 | w->exp_valid_block = exp_valid_block; |
10692 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10693 | if (just_location) |
10694 | { | |
850645cf TT |
10695 | struct type *t = value_type (val.get ()); |
10696 | CORE_ADDR addr = value_as_address (val.get ()); | |
06a64a0b | 10697 | |
43cc5389 TT |
10698 | w->exp_string_reparse |
10699 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 10700 | |
3a5c3e22 | 10701 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 10702 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
10703 | } |
10704 | else | |
3a5c3e22 | 10705 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10706 | |
10707 | if (use_mask) | |
10708 | { | |
3a5c3e22 | 10709 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10710 | } |
10711 | else | |
10712 | { | |
3a5c3e22 | 10713 | w->val = val; |
bb9d5f81 PP |
10714 | w->val_bitpos = saved_bitpos; |
10715 | w->val_bitsize = saved_bitsize; | |
4c1d86d9 | 10716 | w->val_valid = true; |
9c06b0b4 | 10717 | } |
77b06cd7 | 10718 | |
c906108c | 10719 | if (cond_start) |
c1fc2657 | 10720 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 10721 | else |
c1fc2657 | 10722 | w->cond_string = 0; |
c5aa993b | 10723 | |
441d7c93 | 10724 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 10725 | { |
441d7c93 | 10726 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 10727 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 10728 | } |
c906108c | 10729 | else |
f6bc2008 | 10730 | { |
3a5c3e22 PA |
10731 | w->watchpoint_frame = null_frame_id; |
10732 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10733 | } |
c906108c | 10734 | |
d983da9c | 10735 | if (scope_breakpoint != NULL) |
c906108c | 10736 | { |
d983da9c DJ |
10737 | /* The scope breakpoint is related to the watchpoint. We will |
10738 | need to act on them together. */ | |
c1fc2657 | 10739 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 10740 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 10741 | } |
d983da9c | 10742 | |
06a64a0b TT |
10743 | if (!just_location) |
10744 | value_free_to_mark (mark); | |
2d134ed3 | 10745 | |
b270e6f9 TT |
10746 | /* Finally update the new watchpoint. This creates the locations |
10747 | that should be inserted. */ | |
10748 | update_watchpoint (w.get (), 1); | |
a9634178 | 10749 | |
b270e6f9 | 10750 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
10751 | } |
10752 | ||
e09342b5 | 10753 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10754 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10755 | |
c906108c | 10756 | static int |
a6535de1 | 10757 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
c906108c SS |
10758 | { |
10759 | int found_memory_cnt = 0; | |
10760 | ||
10761 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10762 | if (!can_use_hw_watchpoints) |
c906108c | 10763 | return 0; |
c5aa993b | 10764 | |
a6535de1 TT |
10765 | gdb_assert (!vals.empty ()); |
10766 | struct value *head = vals[0].get (); | |
10767 | ||
5c44784c JM |
10768 | /* Make sure that the value of the expression depends only upon |
10769 | memory contents, and values computed from them within GDB. If we | |
10770 | find any register references or function calls, we can't use a | |
10771 | hardware watchpoint. | |
10772 | ||
10773 | The idea here is that evaluating an expression generates a series | |
10774 | of values, one holding the value of every subexpression. (The | |
10775 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10776 | a*b+c.) GDB's values hold almost enough information to establish | |
10777 | the criteria given above --- they identify memory lvalues, | |
10778 | register lvalues, computed values, etcetera. So we can evaluate | |
10779 | the expression, and then scan the chain of values that leaves | |
10780 | behind to decide whether we can detect any possible change to the | |
10781 | expression's final value using only hardware watchpoints. | |
10782 | ||
10783 | However, I don't think that the values returned by inferior | |
10784 | function calls are special in any way. So this function may not | |
10785 | notice that an expression involving an inferior function call | |
10786 | can't be watched with hardware watchpoints. FIXME. */ | |
a6535de1 | 10787 | for (const value_ref_ptr &iter : vals) |
c906108c | 10788 | { |
a6535de1 TT |
10789 | struct value *v = iter.get (); |
10790 | ||
5c44784c | 10791 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10792 | { |
8464be76 DJ |
10793 | if (v != head && value_lazy (v)) |
10794 | /* A lazy memory lvalue in the chain is one that GDB never | |
10795 | needed to fetch; we either just used its address (e.g., | |
10796 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10797 | in `a,b'). This doesn't apply to HEAD; if that is | |
10798 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10799 | ; |
53a5351d | 10800 | else |
5c44784c JM |
10801 | { |
10802 | /* Ahh, memory we actually used! Check if we can cover | |
10803 | it with hardware watchpoints. */ | |
df407dfe | 10804 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10805 | |
10806 | /* We only watch structs and arrays if user asked for it | |
10807 | explicitly, never if they just happen to appear in a | |
10808 | middle of some value chain. */ | |
10809 | if (v == head | |
10810 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
10811 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
10812 | { | |
42ae5230 | 10813 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10814 | int len; |
10815 | int num_regs; | |
10816 | ||
a9634178 | 10817 | len = (target_exact_watchpoints |
e09342b5 TJB |
10818 | && is_scalar_type_recursive (vtype))? |
10819 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10820 | |
e09342b5 TJB |
10821 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10822 | if (!num_regs) | |
2e70b7b9 MS |
10823 | return 0; |
10824 | else | |
e09342b5 | 10825 | found_memory_cnt += num_regs; |
2e70b7b9 | 10826 | } |
5c44784c | 10827 | } |
c5aa993b | 10828 | } |
5086187c AC |
10829 | else if (VALUE_LVAL (v) != not_lval |
10830 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10831 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10832 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10833 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10834 | } |
10835 | ||
10836 | /* The expression itself looks suitable for using a hardware | |
10837 | watchpoint, but give the target machine a chance to reject it. */ | |
10838 | return found_memory_cnt; | |
10839 | } | |
10840 | ||
8b93c638 | 10841 | void |
f2fc3015 | 10842 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10843 | { |
84f4c1fe | 10844 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10845 | } |
10846 | ||
06a64a0b TT |
10847 | /* A helper function that looks for the "-location" argument and then |
10848 | calls watch_command_1. */ | |
10849 | ||
10850 | static void | |
0b39b52e | 10851 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b TT |
10852 | { |
10853 | int just_location = 0; | |
10854 | ||
10855 | if (arg | |
10856 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
10857 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
cbba3ecd | 10858 | just_location = 1; |
06a64a0b | 10859 | |
84f4c1fe | 10860 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 10861 | } |
8926118c | 10862 | |
c5aa993b | 10863 | static void |
0b39b52e | 10864 | watch_command (const char *arg, int from_tty) |
c906108c | 10865 | { |
06a64a0b | 10866 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10867 | } |
10868 | ||
8b93c638 | 10869 | void |
f2fc3015 | 10870 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10871 | { |
84f4c1fe | 10872 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10873 | } |
8926118c | 10874 | |
c5aa993b | 10875 | static void |
0b39b52e | 10876 | rwatch_command (const char *arg, int from_tty) |
c906108c | 10877 | { |
06a64a0b | 10878 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10879 | } |
10880 | ||
8b93c638 | 10881 | void |
f2fc3015 | 10882 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10883 | { |
84f4c1fe | 10884 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10885 | } |
8926118c | 10886 | |
c5aa993b | 10887 | static void |
0b39b52e | 10888 | awatch_command (const char *arg, int from_tty) |
c906108c | 10889 | { |
06a64a0b | 10890 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10891 | } |
c906108c | 10892 | \f |
c5aa993b | 10893 | |
cfc31633 PA |
10894 | /* Data for the FSM that manages the until(location)/advance commands |
10895 | in infcmd.c. Here because it uses the mechanisms of | |
10896 | breakpoints. */ | |
c906108c | 10897 | |
46e3ed7f | 10898 | struct until_break_fsm : public thread_fsm |
bfec99b2 | 10899 | { |
46e3ed7f | 10900 | /* The thread that was current when the command was executed. */ |
cfc31633 PA |
10901 | int thread; |
10902 | ||
10903 | /* The breakpoint set at the destination location. */ | |
46e3ed7f | 10904 | breakpoint_up location_breakpoint; |
cfc31633 PA |
10905 | |
10906 | /* Breakpoint set at the return address in the caller frame. May be | |
10907 | NULL. */ | |
46e3ed7f | 10908 | breakpoint_up caller_breakpoint; |
cfc31633 | 10909 | |
46e3ed7f TT |
10910 | until_break_fsm (struct interp *cmd_interp, int thread, |
10911 | breakpoint_up &&location_breakpoint, | |
10912 | breakpoint_up &&caller_breakpoint) | |
10913 | : thread_fsm (cmd_interp), | |
10914 | thread (thread), | |
10915 | location_breakpoint (std::move (location_breakpoint)), | |
10916 | caller_breakpoint (std::move (caller_breakpoint)) | |
10917 | { | |
10918 | } | |
cfc31633 | 10919 | |
46e3ed7f TT |
10920 | void clean_up (struct thread_info *thread) override; |
10921 | bool should_stop (struct thread_info *thread) override; | |
10922 | enum async_reply_reason do_async_reply_reason () override; | |
cfc31633 PA |
10923 | }; |
10924 | ||
cfc31633 PA |
10925 | /* Implementation of the 'should_stop' FSM method for the |
10926 | until(location)/advance commands. */ | |
10927 | ||
46e3ed7f TT |
10928 | bool |
10929 | until_break_fsm::should_stop (struct thread_info *tp) | |
cfc31633 | 10930 | { |
cfc31633 | 10931 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10932 | location_breakpoint.get ()) != NULL |
10933 | || (caller_breakpoint != NULL | |
cfc31633 | 10934 | && bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10935 | caller_breakpoint.get ()) != NULL)) |
10936 | set_finished (); | |
cfc31633 | 10937 | |
46e3ed7f | 10938 | return true; |
cfc31633 PA |
10939 | } |
10940 | ||
10941 | /* Implementation of the 'clean_up' FSM method for the | |
10942 | until(location)/advance commands. */ | |
10943 | ||
46e3ed7f TT |
10944 | void |
10945 | until_break_fsm::clean_up (struct thread_info *) | |
43ff13b4 | 10946 | { |
cfc31633 | 10947 | /* Clean up our temporary breakpoints. */ |
46e3ed7f TT |
10948 | location_breakpoint.reset (); |
10949 | caller_breakpoint.reset (); | |
10950 | delete_longjmp_breakpoint (thread); | |
cfc31633 PA |
10951 | } |
10952 | ||
10953 | /* Implementation of the 'async_reply_reason' FSM method for the | |
10954 | until(location)/advance commands. */ | |
10955 | ||
46e3ed7f TT |
10956 | enum async_reply_reason |
10957 | until_break_fsm::do_async_reply_reason () | |
cfc31633 PA |
10958 | { |
10959 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
10960 | } |
10961 | ||
c906108c | 10962 | void |
f2fc3015 | 10963 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 10964 | { |
8556afb4 PA |
10965 | struct frame_info *frame; |
10966 | struct gdbarch *frame_gdbarch; | |
10967 | struct frame_id stack_frame_id; | |
10968 | struct frame_id caller_frame_id; | |
186c406b TT |
10969 | int thread; |
10970 | struct thread_info *tp; | |
c906108c | 10971 | |
70509625 | 10972 | clear_proceed_status (0); |
c906108c SS |
10973 | |
10974 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 10975 | this function. */ |
c5aa993b | 10976 | |
ffc2605c | 10977 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 10978 | |
6c5b2ebe PA |
10979 | std::vector<symtab_and_line> sals |
10980 | = (last_displayed_sal_is_valid () | |
10981 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
10982 | get_last_displayed_symtab (), | |
10983 | get_last_displayed_line ()) | |
10984 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
cafb3438 | 10985 | NULL, NULL, 0)); |
c5aa993b | 10986 | |
6c5b2ebe | 10987 | if (sals.size () != 1) |
8a3fe4f8 | 10988 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 10989 | |
6c5b2ebe | 10990 | symtab_and_line &sal = sals[0]; |
c5aa993b | 10991 | |
c906108c | 10992 | if (*arg) |
8a3fe4f8 | 10993 | error (_("Junk at end of arguments.")); |
c5aa993b | 10994 | |
c906108c | 10995 | resolve_sal_pc (&sal); |
c5aa993b | 10996 | |
186c406b | 10997 | tp = inferior_thread (); |
5d5658a1 | 10998 | thread = tp->global_num; |
186c406b | 10999 | |
8556afb4 PA |
11000 | /* Note linespec handling above invalidates the frame chain. |
11001 | Installing a breakpoint also invalidates the frame chain (as it | |
11002 | may need to switch threads), so do any frame handling before | |
11003 | that. */ | |
11004 | ||
11005 | frame = get_selected_frame (NULL); | |
11006 | frame_gdbarch = get_frame_arch (frame); | |
11007 | stack_frame_id = get_stack_frame_id (frame); | |
11008 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11009 | |
ae66c1fc EZ |
11010 | /* Keep within the current frame, or in frames called by the current |
11011 | one. */ | |
edb3359d | 11012 | |
454dafbd | 11013 | breakpoint_up caller_breakpoint; |
5419bdae TT |
11014 | |
11015 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; | |
11016 | ||
883bc8d1 | 11017 | if (frame_id_p (caller_frame_id)) |
c906108c | 11018 | { |
883bc8d1 | 11019 | struct symtab_and_line sal2; |
cfc31633 | 11020 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11021 | |
11022 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11023 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11024 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11025 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11026 | sal2, | |
11027 | caller_frame_id, | |
11028 | bp_until); | |
186c406b | 11029 | |
883bc8d1 | 11030 | set_longjmp_breakpoint (tp, caller_frame_id); |
5419bdae | 11031 | lj_deleter.emplace (thread); |
c906108c | 11032 | } |
c5aa993b | 11033 | |
c70a6932 JK |
11034 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11035 | frame = NULL; | |
11036 | ||
454dafbd | 11037 | breakpoint_up location_breakpoint; |
883bc8d1 PA |
11038 | if (anywhere) |
11039 | /* If the user told us to continue until a specified location, | |
11040 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11041 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11042 | null_frame_id, bp_until); | |
883bc8d1 PA |
11043 | else |
11044 | /* Otherwise, specify the selected frame, because we want to stop | |
11045 | only at the very same frame. */ | |
cfc31633 PA |
11046 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11047 | stack_frame_id, bp_until); | |
883bc8d1 | 11048 | |
46e3ed7f TT |
11049 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
11050 | std::move (location_breakpoint), | |
11051 | std::move (caller_breakpoint)); | |
f107f563 | 11052 | |
5419bdae TT |
11053 | if (lj_deleter) |
11054 | lj_deleter->release (); | |
f107f563 | 11055 | |
cfc31633 | 11056 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11057 | } |
ae66c1fc | 11058 | |
c906108c SS |
11059 | /* This function attempts to parse an optional "if <cond>" clause |
11060 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11061 | |
c906108c SS |
11062 | Else, it returns a pointer to the condition string. (It does not |
11063 | attempt to evaluate the string against a particular block.) And, | |
11064 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11065 | if clause in the arg string. */ |
53a5351d | 11066 | |
63160a43 PA |
11067 | const char * |
11068 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11069 | { |
63160a43 | 11070 | const char *cond_string; |
c5aa993b JM |
11071 | |
11072 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11073 | return NULL; |
c5aa993b | 11074 | |
4a64f543 | 11075 | /* Skip the "if" keyword. */ |
c906108c | 11076 | (*arg) += 2; |
c5aa993b | 11077 | |
c906108c | 11078 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11079 | condition string. */ |
f1735a53 | 11080 | *arg = skip_spaces (*arg); |
c906108c | 11081 | cond_string = *arg; |
c5aa993b | 11082 | |
4a64f543 MS |
11083 | /* Assume that the condition occupies the remainder of the arg |
11084 | string. */ | |
c906108c | 11085 | (*arg) += strlen (cond_string); |
c5aa993b | 11086 | |
c906108c SS |
11087 | return cond_string; |
11088 | } | |
c5aa993b | 11089 | |
c906108c SS |
11090 | /* Commands to deal with catching events, such as signals, exceptions, |
11091 | process start/exit, etc. */ | |
c5aa993b JM |
11092 | |
11093 | typedef enum | |
11094 | { | |
44feb3ce TT |
11095 | catch_fork_temporary, catch_vfork_temporary, |
11096 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11097 | } |
11098 | catch_fork_kind; | |
11099 | ||
c906108c | 11100 | static void |
eb4c3f4a | 11101 | catch_fork_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11102 | struct cmd_list_element *command) |
c906108c | 11103 | { |
a6d9a66e | 11104 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11105 | const char *cond_string = NULL; |
44feb3ce TT |
11106 | catch_fork_kind fork_kind; |
11107 | int tempflag; | |
11108 | ||
11109 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11110 | tempflag = (fork_kind == catch_fork_temporary | |
11111 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11112 | |
44feb3ce TT |
11113 | if (!arg) |
11114 | arg = ""; | |
f1735a53 | 11115 | arg = skip_spaces (arg); |
c5aa993b | 11116 | |
c906108c | 11117 | /* The allowed syntax is: |
c5aa993b JM |
11118 | catch [v]fork |
11119 | catch [v]fork if <cond> | |
11120 | ||
4a64f543 | 11121 | First, check if there's an if clause. */ |
c906108c | 11122 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11123 | |
c906108c | 11124 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11125 | error (_("Junk at end of arguments.")); |
c5aa993b | 11126 | |
c906108c | 11127 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11128 | and enable reporting of such events. */ |
c5aa993b JM |
11129 | switch (fork_kind) |
11130 | { | |
44feb3ce TT |
11131 | case catch_fork_temporary: |
11132 | case catch_fork_permanent: | |
a6d9a66e | 11133 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11134 | &catch_fork_breakpoint_ops); |
c906108c | 11135 | break; |
44feb3ce TT |
11136 | case catch_vfork_temporary: |
11137 | case catch_vfork_permanent: | |
a6d9a66e | 11138 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11139 | &catch_vfork_breakpoint_ops); |
c906108c | 11140 | break; |
c5aa993b | 11141 | default: |
8a3fe4f8 | 11142 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11143 | break; |
c5aa993b | 11144 | } |
c906108c SS |
11145 | } |
11146 | ||
11147 | static void | |
eb4c3f4a | 11148 | catch_exec_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11149 | struct cmd_list_element *command) |
c906108c | 11150 | { |
a6d9a66e | 11151 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11152 | int tempflag; |
63160a43 | 11153 | const char *cond_string = NULL; |
c906108c | 11154 | |
44feb3ce TT |
11155 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11156 | ||
11157 | if (!arg) | |
11158 | arg = ""; | |
f1735a53 | 11159 | arg = skip_spaces (arg); |
c906108c SS |
11160 | |
11161 | /* The allowed syntax is: | |
c5aa993b JM |
11162 | catch exec |
11163 | catch exec if <cond> | |
c906108c | 11164 | |
4a64f543 | 11165 | First, check if there's an if clause. */ |
c906108c SS |
11166 | cond_string = ep_parse_optional_if_clause (&arg); |
11167 | ||
11168 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11169 | error (_("Junk at end of arguments.")); |
c906108c | 11170 | |
b270e6f9 TT |
11171 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11172 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11173 | &catch_exec_breakpoint_ops); |
11174 | c->exec_pathname = NULL; | |
11175 | ||
b270e6f9 | 11176 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11177 | } |
c5aa993b | 11178 | |
9ac4176b | 11179 | void |
28010a5d PA |
11180 | init_ada_exception_breakpoint (struct breakpoint *b, |
11181 | struct gdbarch *gdbarch, | |
11182 | struct symtab_and_line sal, | |
f2fc3015 | 11183 | const char *addr_string, |
c0a91b2b | 11184 | const struct breakpoint_ops *ops, |
28010a5d | 11185 | int tempflag, |
349774ef | 11186 | int enabled, |
28010a5d | 11187 | int from_tty) |
f7f9143b | 11188 | { |
f7f9143b JB |
11189 | if (from_tty) |
11190 | { | |
5af949e3 UW |
11191 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11192 | if (!loc_gdbarch) | |
11193 | loc_gdbarch = gdbarch; | |
11194 | ||
6c95b8df PA |
11195 | describe_other_breakpoints (loc_gdbarch, |
11196 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11197 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11198 | version for exception catchpoints, because two catchpoints | |
11199 | used for different exception names will use the same address. | |
11200 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11201 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11202 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11203 | the user what type of catchpoint it is. The above is good |
11204 | enough for now, though. */ | |
11205 | } | |
11206 | ||
f06f1252 | 11207 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
f7f9143b | 11208 | |
349774ef | 11209 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11210 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11211 | b->location = string_to_event_location (&addr_string, |
11212 | language_def (language_ada)); | |
f7f9143b | 11213 | b->language = language_ada; |
f7f9143b JB |
11214 | } |
11215 | ||
c906108c | 11216 | static void |
981a3fb3 | 11217 | catch_command (const char *arg, int from_tty) |
c906108c | 11218 | { |
44feb3ce | 11219 | error (_("Catch requires an event name.")); |
c906108c SS |
11220 | } |
11221 | \f | |
11222 | ||
11223 | static void | |
981a3fb3 | 11224 | tcatch_command (const char *arg, int from_tty) |
c906108c | 11225 | { |
44feb3ce | 11226 | error (_("Catch requires an event name.")); |
c906108c SS |
11227 | } |
11228 | ||
81b1e71c | 11229 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
11230 | |
11231 | static int | |
81b1e71c | 11232 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 11233 | { |
81b1e71c TT |
11234 | uintptr_t ua = (uintptr_t) a; |
11235 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 11236 | |
81b1e71c | 11237 | if (a->number < b->number) |
8a2c437b | 11238 | return -1; |
81b1e71c | 11239 | else if (a->number > b->number) |
8a2c437b TT |
11240 | return 1; |
11241 | ||
11242 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11243 | the number 0. */ | |
11244 | if (ua < ub) | |
11245 | return -1; | |
94b0e70d | 11246 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11247 | } |
11248 | ||
80f8a6eb | 11249 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11250 | |
11251 | static void | |
0b39b52e | 11252 | clear_command (const char *arg, int from_tty) |
c906108c | 11253 | { |
81b1e71c | 11254 | struct breakpoint *b; |
c906108c | 11255 | int default_match; |
c906108c | 11256 | |
6c5b2ebe PA |
11257 | std::vector<symtab_and_line> decoded_sals; |
11258 | symtab_and_line last_sal; | |
11259 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11260 | if (arg) |
11261 | { | |
6c5b2ebe PA |
11262 | decoded_sals |
11263 | = decode_line_with_current_source (arg, | |
11264 | (DECODE_LINE_FUNFIRSTLINE | |
11265 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11266 | default_match = 0; |
6c5b2ebe | 11267 | sals = decoded_sals; |
c906108c SS |
11268 | } |
11269 | else | |
11270 | { | |
1bfeeb0f JL |
11271 | /* Set sal's line, symtab, pc, and pspace to the values |
11272 | corresponding to the last call to print_frame_info. If the | |
11273 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11274 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11275 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11276 | error (_("No source file specified.")); |
c906108c | 11277 | |
c906108c | 11278 | default_match = 1; |
6c5b2ebe | 11279 | sals = last_sal; |
c906108c SS |
11280 | } |
11281 | ||
4a64f543 MS |
11282 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11283 | seems, because all existing breakpoints typically have both | |
11284 | file/line and pc set. So, if clear is given file/line, we can | |
11285 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11286 | |
11287 | We only support clearing given the address explicitly | |
11288 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11289 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11290 | due to optimization, all in one block. |
4a64f543 MS |
11291 | |
11292 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11293 | PC corresponding to the same file:line, the breakpoint won't |
11294 | be cleared. We probably can still clear the breakpoint, but | |
11295 | since the other PC value is never presented to user, user | |
11296 | can only find it by guessing, and it does not seem important | |
11297 | to support that. */ | |
11298 | ||
4a64f543 MS |
11299 | /* For each line spec given, delete bps which correspond to it. Do |
11300 | it in two passes, solely to preserve the current behavior that | |
11301 | from_tty is forced true if we delete more than one | |
11302 | breakpoint. */ | |
c906108c | 11303 | |
81b1e71c | 11304 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 11305 | for (const auto &sal : sals) |
c906108c | 11306 | { |
05cba821 JK |
11307 | const char *sal_fullname; |
11308 | ||
c906108c | 11309 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11310 | If line given (pc == 0), clear all bpts on specified line. |
11311 | If defaulting, clear all bpts on default line | |
c906108c | 11312 | or at default pc. |
c5aa993b JM |
11313 | |
11314 | defaulting sal.pc != 0 tests to do | |
11315 | ||
11316 | 0 1 pc | |
11317 | 1 1 pc _and_ line | |
11318 | 0 0 line | |
11319 | 1 0 <can't happen> */ | |
c906108c | 11320 | |
05cba821 JK |
11321 | sal_fullname = (sal.symtab == NULL |
11322 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11323 | |
4a64f543 | 11324 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11325 | ALL_BREAKPOINTS (b) |
c5aa993b | 11326 | { |
0d381245 | 11327 | int match = 0; |
4a64f543 | 11328 | /* Are we going to delete b? */ |
cc60f2e3 | 11329 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11330 | { |
11331 | struct bp_location *loc = b->loc; | |
11332 | for (; loc; loc = loc->next) | |
11333 | { | |
f8eba3c6 TT |
11334 | /* If the user specified file:line, don't allow a PC |
11335 | match. This matches historical gdb behavior. */ | |
11336 | int pc_match = (!sal.explicit_line | |
11337 | && sal.pc | |
11338 | && (loc->pspace == sal.pspace) | |
11339 | && (loc->address == sal.pc) | |
11340 | && (!section_is_overlay (loc->section) | |
11341 | || loc->section == sal.section)); | |
4aac40c8 TT |
11342 | int line_match = 0; |
11343 | ||
11344 | if ((default_match || sal.explicit_line) | |
2f202fde | 11345 | && loc->symtab != NULL |
05cba821 | 11346 | && sal_fullname != NULL |
4aac40c8 | 11347 | && sal.pspace == loc->pspace |
05cba821 JK |
11348 | && loc->line_number == sal.line |
11349 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11350 | sal_fullname) == 0) | |
11351 | line_match = 1; | |
4aac40c8 | 11352 | |
0d381245 VP |
11353 | if (pc_match || line_match) |
11354 | { | |
11355 | match = 1; | |
11356 | break; | |
11357 | } | |
11358 | } | |
11359 | } | |
11360 | ||
11361 | if (match) | |
81b1e71c | 11362 | found.push_back (b); |
c906108c | 11363 | } |
80f8a6eb | 11364 | } |
8a2c437b | 11365 | |
80f8a6eb | 11366 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 11367 | if (found.empty ()) |
80f8a6eb MS |
11368 | { |
11369 | if (arg) | |
8a3fe4f8 | 11370 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11371 | else |
8a3fe4f8 | 11372 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11373 | } |
c906108c | 11374 | |
8a2c437b | 11375 | /* Remove duplicates from the vec. */ |
81b1e71c | 11376 | std::sort (found.begin (), found.end (), |
b926417a | 11377 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11378 | { |
b926417a | 11379 | return compare_breakpoints (bp_a, bp_b) < 0; |
81b1e71c TT |
11380 | }); |
11381 | found.erase (std::unique (found.begin (), found.end (), | |
b926417a | 11382 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11383 | { |
b926417a | 11384 | return compare_breakpoints (bp_a, bp_b) == 0; |
81b1e71c TT |
11385 | }), |
11386 | found.end ()); | |
8a2c437b | 11387 | |
81b1e71c | 11388 | if (found.size () > 1) |
4a64f543 | 11389 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11390 | if (from_tty) |
a3f17187 | 11391 | { |
81b1e71c | 11392 | if (found.size () == 1) |
a3f17187 AC |
11393 | printf_unfiltered (_("Deleted breakpoint ")); |
11394 | else | |
11395 | printf_unfiltered (_("Deleted breakpoints ")); | |
11396 | } | |
d6e956e5 | 11397 | |
81b1e71c | 11398 | for (breakpoint *iter : found) |
80f8a6eb | 11399 | { |
c5aa993b | 11400 | if (from_tty) |
81b1e71c TT |
11401 | printf_unfiltered ("%d ", iter->number); |
11402 | delete_breakpoint (iter); | |
c906108c | 11403 | } |
80f8a6eb MS |
11404 | if (from_tty) |
11405 | putchar_unfiltered ('\n'); | |
c906108c SS |
11406 | } |
11407 | \f | |
11408 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11409 | all breakpoints that are marked for deletion, whether hit or not. | |
11410 | This is called after any breakpoint is hit, or after errors. */ | |
11411 | ||
11412 | void | |
fba45db2 | 11413 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11414 | { |
35df4500 | 11415 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11416 | |
11417 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11418 | if (bs->breakpoint_at |
11419 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11420 | && bs->stop) |
f431efe5 | 11421 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11422 | |
35df4500 | 11423 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11424 | { |
b5de0fa7 | 11425 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11426 | delete_breakpoint (b); |
11427 | } | |
c906108c SS |
11428 | } |
11429 | ||
4a64f543 | 11430 | /* A comparison function for bp_location AP and BP being interfaced to |
39ef2f62 | 11431 | std::sort. Sort elements primarily by their ADDRESS (no matter what |
cb1e4e32 PA |
11432 | bl_address_is_meaningful says), secondarily by ordering first |
11433 | permanent elements and terciarily just ensuring the array is sorted | |
39ef2f62 | 11434 | stable way despite std::sort being an unstable algorithm. */ |
876fa593 JK |
11435 | |
11436 | static int | |
39ef2f62 | 11437 | bp_location_is_less_than (const bp_location *a, const bp_location *b) |
876fa593 | 11438 | { |
876fa593 | 11439 | if (a->address != b->address) |
39ef2f62 | 11440 | return a->address < b->address; |
876fa593 | 11441 | |
dea2aa5f LM |
11442 | /* Sort locations at the same address by their pspace number, keeping |
11443 | locations of the same inferior (in a multi-inferior environment) | |
11444 | grouped. */ | |
11445 | ||
11446 | if (a->pspace->num != b->pspace->num) | |
39ef2f62 | 11447 | return a->pspace->num < b->pspace->num; |
dea2aa5f | 11448 | |
876fa593 | 11449 | /* Sort permanent breakpoints first. */ |
1a853c52 | 11450 | if (a->permanent != b->permanent) |
39ef2f62 | 11451 | return a->permanent > b->permanent; |
876fa593 | 11452 | |
c56a97f9 JK |
11453 | /* Make the internal GDB representation stable across GDB runs |
11454 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11455 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11456 | |
11457 | if (a->owner->number != b->owner->number) | |
39ef2f62 | 11458 | return a->owner->number < b->owner->number; |
876fa593 | 11459 | |
39ef2f62 | 11460 | return a < b; |
876fa593 JK |
11461 | } |
11462 | ||
f5336ca5 PA |
11463 | /* Set bp_locations_placed_address_before_address_max and |
11464 | bp_locations_shadow_len_after_address_max according to the current | |
11465 | content of the bp_locations array. */ | |
f7545552 TT |
11466 | |
11467 | static void | |
f5336ca5 | 11468 | bp_locations_target_extensions_update (void) |
f7545552 | 11469 | { |
876fa593 JK |
11470 | struct bp_location *bl, **blp_tmp; |
11471 | ||
f5336ca5 PA |
11472 | bp_locations_placed_address_before_address_max = 0; |
11473 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11474 | |
11475 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11476 | { | |
11477 | CORE_ADDR start, end, addr; | |
11478 | ||
11479 | if (!bp_location_has_shadow (bl)) | |
11480 | continue; | |
11481 | ||
11482 | start = bl->target_info.placed_address; | |
11483 | end = start + bl->target_info.shadow_len; | |
11484 | ||
11485 | gdb_assert (bl->address >= start); | |
11486 | addr = bl->address - start; | |
f5336ca5 PA |
11487 | if (addr > bp_locations_placed_address_before_address_max) |
11488 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11489 | |
11490 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11491 | ||
11492 | gdb_assert (bl->address < end); | |
11493 | addr = end - bl->address; | |
f5336ca5 PA |
11494 | if (addr > bp_locations_shadow_len_after_address_max) |
11495 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11496 | } |
f7545552 TT |
11497 | } |
11498 | ||
1e4d1764 YQ |
11499 | /* Download tracepoint locations if they haven't been. */ |
11500 | ||
11501 | static void | |
11502 | download_tracepoint_locations (void) | |
11503 | { | |
7ed2c994 | 11504 | struct breakpoint *b; |
dd2e65cc | 11505 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11506 | |
5ed8105e | 11507 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11508 | |
7ed2c994 | 11509 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11510 | { |
7ed2c994 | 11511 | struct bp_location *bl; |
1e4d1764 | 11512 | struct tracepoint *t; |
f2a8bc8a | 11513 | int bp_location_downloaded = 0; |
1e4d1764 | 11514 | |
7ed2c994 | 11515 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11516 | ? !may_insert_fast_tracepoints |
11517 | : !may_insert_tracepoints)) | |
11518 | continue; | |
11519 | ||
dd2e65cc YQ |
11520 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11521 | { | |
11522 | if (target_can_download_tracepoint ()) | |
11523 | can_download_tracepoint = TRIBOOL_TRUE; | |
11524 | else | |
11525 | can_download_tracepoint = TRIBOOL_FALSE; | |
11526 | } | |
11527 | ||
11528 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11529 | break; | |
11530 | ||
7ed2c994 YQ |
11531 | for (bl = b->loc; bl; bl = bl->next) |
11532 | { | |
11533 | /* In tracepoint, locations are _never_ duplicated, so | |
11534 | should_be_inserted is equivalent to | |
11535 | unduplicated_should_be_inserted. */ | |
11536 | if (!should_be_inserted (bl) || bl->inserted) | |
11537 | continue; | |
1e4d1764 | 11538 | |
7ed2c994 | 11539 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11540 | |
7ed2c994 | 11541 | target_download_tracepoint (bl); |
1e4d1764 | 11542 | |
7ed2c994 | 11543 | bl->inserted = 1; |
f2a8bc8a | 11544 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11545 | } |
11546 | t = (struct tracepoint *) b; | |
11547 | t->number_on_target = b->number; | |
f2a8bc8a | 11548 | if (bp_location_downloaded) |
76727919 | 11549 | gdb::observers::breakpoint_modified.notify (b); |
1e4d1764 | 11550 | } |
1e4d1764 YQ |
11551 | } |
11552 | ||
934709f0 PW |
11553 | /* Swap the insertion/duplication state between two locations. */ |
11554 | ||
11555 | static void | |
11556 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11557 | { | |
11558 | const int left_inserted = left->inserted; | |
11559 | const int left_duplicate = left->duplicate; | |
b775012e | 11560 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11561 | const struct bp_target_info left_target_info = left->target_info; |
11562 | ||
1e4d1764 YQ |
11563 | /* Locations of tracepoints can never be duplicated. */ |
11564 | if (is_tracepoint (left->owner)) | |
11565 | gdb_assert (!left->duplicate); | |
11566 | if (is_tracepoint (right->owner)) | |
11567 | gdb_assert (!right->duplicate); | |
11568 | ||
934709f0 PW |
11569 | left->inserted = right->inserted; |
11570 | left->duplicate = right->duplicate; | |
b775012e | 11571 | left->needs_update = right->needs_update; |
934709f0 PW |
11572 | left->target_info = right->target_info; |
11573 | right->inserted = left_inserted; | |
11574 | right->duplicate = left_duplicate; | |
b775012e | 11575 | right->needs_update = left_needs_update; |
934709f0 PW |
11576 | right->target_info = left_target_info; |
11577 | } | |
11578 | ||
b775012e LM |
11579 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11580 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11581 | conditions on the target's side. Such conditions need to be updated on | |
11582 | the target. */ | |
11583 | ||
11584 | static void | |
11585 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11586 | { | |
11587 | struct bp_location **locp = NULL, **loc2p; | |
11588 | struct bp_location *loc; | |
11589 | CORE_ADDR address = 0; | |
11590 | int pspace_num; | |
11591 | ||
11592 | address = bl->address; | |
11593 | pspace_num = bl->pspace->num; | |
11594 | ||
11595 | /* This is only meaningful if the target is | |
11596 | evaluating conditions and if the user has | |
11597 | opted for condition evaluation on the target's | |
11598 | side. */ | |
11599 | if (gdb_evaluates_breakpoint_condition_p () | |
11600 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11601 | return; | |
11602 | ||
11603 | /* Flag all breakpoint locations with this address and | |
11604 | the same program space as the location | |
11605 | as "its condition has changed". We need to | |
11606 | update the conditions on the target's side. */ | |
11607 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11608 | { | |
11609 | loc = *loc2p; | |
11610 | ||
11611 | if (!is_breakpoint (loc->owner) | |
11612 | || pspace_num != loc->pspace->num) | |
11613 | continue; | |
11614 | ||
11615 | /* Flag the location appropriately. We use a different state to | |
11616 | let everyone know that we already updated the set of locations | |
11617 | with addr bl->address and program space bl->pspace. This is so | |
11618 | we don't have to keep calling these functions just to mark locations | |
11619 | that have already been marked. */ | |
11620 | loc->condition_changed = condition_updated; | |
11621 | ||
11622 | /* Free the agent expression bytecode as well. We will compute | |
11623 | it later on. */ | |
833177a4 | 11624 | loc->cond_bytecode.reset (); |
b775012e LM |
11625 | } |
11626 | } | |
44702360 PA |
11627 | /* Called whether new breakpoints are created, or existing breakpoints |
11628 | deleted, to update the global location list and recompute which | |
11629 | locations are duplicate of which. | |
b775012e | 11630 | |
04086b45 PA |
11631 | The INSERT_MODE flag determines whether locations may not, may, or |
11632 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11633 | info. */ | |
b60e7edf | 11634 | |
0d381245 | 11635 | static void |
44702360 | 11636 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11637 | { |
74960c60 | 11638 | struct breakpoint *b; |
876fa593 | 11639 | struct bp_location **locp, *loc; |
b775012e LM |
11640 | /* Last breakpoint location address that was marked for update. */ |
11641 | CORE_ADDR last_addr = 0; | |
11642 | /* Last breakpoint location program space that was marked for update. */ | |
11643 | int last_pspace_num = -1; | |
f7545552 | 11644 | |
2d134ed3 PA |
11645 | /* Used in the duplicates detection below. When iterating over all |
11646 | bp_locations, points to the first bp_location of a given address. | |
11647 | Breakpoints and watchpoints of different types are never | |
11648 | duplicates of each other. Keep one pointer for each type of | |
11649 | breakpoint/watchpoint, so we only need to loop over all locations | |
11650 | once. */ | |
11651 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11652 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11653 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11654 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11655 | |
f5336ca5 PA |
11656 | /* Saved former bp_locations array which we compare against the newly |
11657 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
81b1e71c | 11658 | struct bp_location **old_locp; |
f5336ca5 | 11659 | unsigned old_locations_count; |
81b1e71c | 11660 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
876fa593 | 11661 | |
f5336ca5 PA |
11662 | old_locations_count = bp_locations_count; |
11663 | bp_locations = NULL; | |
11664 | bp_locations_count = 0; | |
0d381245 | 11665 | |
74960c60 | 11666 | ALL_BREAKPOINTS (b) |
876fa593 | 11667 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 11668 | bp_locations_count++; |
876fa593 | 11669 | |
f5336ca5 PA |
11670 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
11671 | locp = bp_locations; | |
876fa593 JK |
11672 | ALL_BREAKPOINTS (b) |
11673 | for (loc = b->loc; loc; loc = loc->next) | |
11674 | *locp++ = loc; | |
39ef2f62 CB |
11675 | std::sort (bp_locations, bp_locations + bp_locations_count, |
11676 | bp_location_is_less_than); | |
876fa593 | 11677 | |
f5336ca5 | 11678 | bp_locations_target_extensions_update (); |
74960c60 | 11679 | |
4a64f543 MS |
11680 | /* Identify bp_location instances that are no longer present in the |
11681 | new list, and therefore should be freed. Note that it's not | |
11682 | necessary that those locations should be removed from inferior -- | |
11683 | if there's another location at the same address (previously | |
11684 | marked as duplicate), we don't need to remove/insert the | |
11685 | location. | |
876fa593 | 11686 | |
4a64f543 MS |
11687 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11688 | and former bp_location array state respectively. */ | |
876fa593 | 11689 | |
f5336ca5 | 11690 | locp = bp_locations; |
81b1e71c TT |
11691 | for (old_locp = old_locations.get (); |
11692 | old_locp < old_locations.get () + old_locations_count; | |
876fa593 | 11693 | old_locp++) |
74960c60 | 11694 | { |
876fa593 | 11695 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11696 | struct bp_location **loc2p; |
876fa593 | 11697 | |
e5dd4106 | 11698 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11699 | not, we have to free it. */ |
c7d46a38 | 11700 | int found_object = 0; |
20874c92 VP |
11701 | /* Tells if the location should remain inserted in the target. */ |
11702 | int keep_in_target = 0; | |
11703 | int removed = 0; | |
876fa593 | 11704 | |
4a64f543 MS |
11705 | /* Skip LOCP entries which will definitely never be needed. |
11706 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 11707 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 11708 | && (*locp)->address < old_loc->address) |
876fa593 | 11709 | locp++; |
c7d46a38 PA |
11710 | |
11711 | for (loc2p = locp; | |
f5336ca5 | 11712 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
11713 | && (*loc2p)->address == old_loc->address); |
11714 | loc2p++) | |
11715 | { | |
b775012e LM |
11716 | /* Check if this is a new/duplicated location or a duplicated |
11717 | location that had its condition modified. If so, we want to send | |
11718 | its condition to the target if evaluation of conditions is taking | |
11719 | place there. */ | |
11720 | if ((*loc2p)->condition_changed == condition_modified | |
11721 | && (last_addr != old_loc->address | |
11722 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11723 | { |
b775012e LM |
11724 | force_breakpoint_reinsertion (*loc2p); |
11725 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11726 | } |
b775012e LM |
11727 | |
11728 | if (*loc2p == old_loc) | |
11729 | found_object = 1; | |
c7d46a38 | 11730 | } |
74960c60 | 11731 | |
b775012e LM |
11732 | /* We have already handled this address, update it so that we don't |
11733 | have to go through updates again. */ | |
11734 | last_addr = old_loc->address; | |
11735 | ||
11736 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11737 | if (!found_object) | |
11738 | force_breakpoint_reinsertion (old_loc); | |
11739 | ||
4a64f543 MS |
11740 | /* If this location is no longer present, and inserted, look if |
11741 | there's maybe a new location at the same address. If so, | |
11742 | mark that one inserted, and don't remove this one. This is | |
11743 | needed so that we don't have a time window where a breakpoint | |
11744 | at certain location is not inserted. */ | |
74960c60 | 11745 | |
876fa593 | 11746 | if (old_loc->inserted) |
0d381245 | 11747 | { |
4a64f543 MS |
11748 | /* If the location is inserted now, we might have to remove |
11749 | it. */ | |
74960c60 | 11750 | |
876fa593 | 11751 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11752 | { |
4a64f543 MS |
11753 | /* The location is still present in the location list, |
11754 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11755 | keep_in_target = 1; |
74960c60 VP |
11756 | } |
11757 | else | |
11758 | { | |
b775012e LM |
11759 | /* This location still exists, but it won't be kept in the |
11760 | target since it may have been disabled. We proceed to | |
11761 | remove its target-side condition. */ | |
11762 | ||
4a64f543 MS |
11763 | /* The location is either no longer present, or got |
11764 | disabled. See if there's another location at the | |
11765 | same address, in which case we don't need to remove | |
11766 | this one from the target. */ | |
876fa593 | 11767 | |
2bdf28a0 | 11768 | /* OLD_LOC comes from existing struct breakpoint. */ |
cb1e4e32 | 11769 | if (bl_address_is_meaningful (old_loc)) |
876fa593 | 11770 | { |
876fa593 | 11771 | for (loc2p = locp; |
f5336ca5 | 11772 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 11773 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
11774 | loc2p++) |
11775 | { | |
11776 | struct bp_location *loc2 = *loc2p; | |
11777 | ||
2d134ed3 | 11778 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11779 | { |
85d721b8 PA |
11780 | /* Read watchpoint locations are switched to |
11781 | access watchpoints, if the former are not | |
11782 | supported, but the latter are. */ | |
11783 | if (is_hardware_watchpoint (old_loc->owner)) | |
11784 | { | |
11785 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11786 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11787 | } | |
11788 | ||
934709f0 PW |
11789 | /* loc2 is a duplicated location. We need to check |
11790 | if it should be inserted in case it will be | |
11791 | unduplicated. */ | |
11792 | if (loc2 != old_loc | |
11793 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 11794 | { |
934709f0 | 11795 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11796 | keep_in_target = 1; |
11797 | break; | |
11798 | } | |
876fa593 JK |
11799 | } |
11800 | } | |
11801 | } | |
74960c60 VP |
11802 | } |
11803 | ||
20874c92 VP |
11804 | if (!keep_in_target) |
11805 | { | |
834c0d03 | 11806 | if (remove_breakpoint (old_loc)) |
20874c92 | 11807 | { |
4a64f543 MS |
11808 | /* This is just about all we can do. We could keep |
11809 | this location on the global list, and try to | |
11810 | remove it next time, but there's no particular | |
11811 | reason why we will succeed next time. | |
20874c92 | 11812 | |
4a64f543 MS |
11813 | Note that at this point, old_loc->owner is still |
11814 | valid, as delete_breakpoint frees the breakpoint | |
11815 | only after calling us. */ | |
3e43a32a MS |
11816 | printf_filtered (_("warning: Error removing " |
11817 | "breakpoint %d\n"), | |
876fa593 | 11818 | old_loc->owner->number); |
20874c92 VP |
11819 | } |
11820 | removed = 1; | |
11821 | } | |
0d381245 | 11822 | } |
74960c60 VP |
11823 | |
11824 | if (!found_object) | |
1c5cfe86 | 11825 | { |
fbea99ea | 11826 | if (removed && target_is_non_stop_p () |
1cf4d951 | 11827 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 11828 | { |
db82e815 PA |
11829 | /* This location was removed from the target. In |
11830 | non-stop mode, a race condition is possible where | |
11831 | we've removed a breakpoint, but stop events for that | |
11832 | breakpoint are already queued and will arrive later. | |
11833 | We apply an heuristic to be able to distinguish such | |
11834 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11835 | breakpoint location for a bit, and will retire it | |
11836 | after we see some number of events. The theory here | |
11837 | is that reporting of events should, "on the average", | |
11838 | be fair, so after a while we'll see events from all | |
11839 | threads that have anything of interest, and no longer | |
11840 | need to keep this breakpoint location around. We | |
11841 | don't hold locations forever so to reduce chances of | |
11842 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11843 | SIGTRAP. | |
11844 | ||
11845 | The heuristic failing can be disastrous on | |
11846 | decr_pc_after_break targets. | |
11847 | ||
11848 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11849 | if we fail to recognize a late breakpoint SIGTRAP, | |
11850 | because events_till_retirement has reached 0 too | |
11851 | soon, we'll fail to do the PC adjustment, and report | |
11852 | a random SIGTRAP to the user. When the user resumes | |
11853 | the inferior, it will most likely immediately crash | |
2dec564e | 11854 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11855 | corrupted, because of being resumed e.g., in the |
11856 | middle of a multi-byte instruction, or skipped a | |
11857 | one-byte instruction. This was actually seen happen | |
11858 | on native x86-linux, and should be less rare on | |
11859 | targets that do not support new thread events, like | |
11860 | remote, due to the heuristic depending on | |
11861 | thread_count. | |
11862 | ||
11863 | Mistaking a random SIGTRAP for a breakpoint trap | |
11864 | causes similar symptoms (PC adjustment applied when | |
11865 | it shouldn't), but then again, playing with SIGTRAPs | |
11866 | behind the debugger's back is asking for trouble. | |
11867 | ||
11868 | Since hardware watchpoint traps are always | |
11869 | distinguishable from other traps, so we don't need to | |
11870 | apply keep hardware watchpoint moribund locations | |
11871 | around. We simply always ignore hardware watchpoint | |
11872 | traps we can no longer explain. */ | |
11873 | ||
876fa593 JK |
11874 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
11875 | old_loc->owner = NULL; | |
20874c92 | 11876 | |
1123588c | 11877 | moribund_locations.push_back (old_loc); |
1c5cfe86 PA |
11878 | } |
11879 | else | |
f431efe5 PA |
11880 | { |
11881 | old_loc->owner = NULL; | |
11882 | decref_bp_location (&old_loc); | |
11883 | } | |
20874c92 | 11884 | } |
74960c60 | 11885 | } |
1c5cfe86 | 11886 | |
348d480f PA |
11887 | /* Rescan breakpoints at the same address and section, marking the |
11888 | first one as "first" and any others as "duplicates". This is so | |
11889 | that the bpt instruction is only inserted once. If we have a | |
11890 | permanent breakpoint at the same place as BPT, make that one the | |
11891 | official one, and the rest as duplicates. Permanent breakpoints | |
11892 | are sorted first for the same address. | |
11893 | ||
11894 | Do the same for hardware watchpoints, but also considering the | |
11895 | watchpoint's type (regular/access/read) and length. */ | |
11896 | ||
11897 | bp_loc_first = NULL; | |
11898 | wp_loc_first = NULL; | |
11899 | awp_loc_first = NULL; | |
11900 | rwp_loc_first = NULL; | |
11901 | ALL_BP_LOCATIONS (loc, locp) | |
11902 | { | |
11903 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11904 | non-NULL. */ | |
348d480f | 11905 | struct bp_location **loc_first_p; |
d3fbdd86 | 11906 | b = loc->owner; |
348d480f | 11907 | |
6f380991 | 11908 | if (!unduplicated_should_be_inserted (loc) |
cb1e4e32 | 11909 | || !bl_address_is_meaningful (loc) |
1e4d1764 YQ |
11910 | /* Don't detect duplicate for tracepoint locations because they are |
11911 | never duplicated. See the comments in field `duplicate' of | |
11912 | `struct bp_location'. */ | |
348d480f | 11913 | || is_tracepoint (b)) |
b775012e LM |
11914 | { |
11915 | /* Clear the condition modification flag. */ | |
11916 | loc->condition_changed = condition_unchanged; | |
11917 | continue; | |
11918 | } | |
348d480f | 11919 | |
348d480f PA |
11920 | if (b->type == bp_hardware_watchpoint) |
11921 | loc_first_p = &wp_loc_first; | |
11922 | else if (b->type == bp_read_watchpoint) | |
11923 | loc_first_p = &rwp_loc_first; | |
11924 | else if (b->type == bp_access_watchpoint) | |
11925 | loc_first_p = &awp_loc_first; | |
11926 | else | |
11927 | loc_first_p = &bp_loc_first; | |
11928 | ||
11929 | if (*loc_first_p == NULL | |
11930 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
11931 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
11932 | { | |
11933 | *loc_first_p = loc; | |
11934 | loc->duplicate = 0; | |
b775012e LM |
11935 | |
11936 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
11937 | { | |
11938 | loc->needs_update = 1; | |
11939 | /* Clear the condition modification flag. */ | |
11940 | loc->condition_changed = condition_unchanged; | |
11941 | } | |
348d480f PA |
11942 | continue; |
11943 | } | |
11944 | ||
934709f0 PW |
11945 | |
11946 | /* This and the above ensure the invariant that the first location | |
11947 | is not duplicated, and is the inserted one. | |
11948 | All following are marked as duplicated, and are not inserted. */ | |
11949 | if (loc->inserted) | |
11950 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11951 | loc->duplicate = 1; |
11952 | ||
b775012e LM |
11953 | /* Clear the condition modification flag. */ |
11954 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
11955 | } |
11956 | ||
a25a5a45 | 11957 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 11958 | { |
04086b45 | 11959 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
11960 | insert_breakpoint_locations (); |
11961 | else | |
11962 | { | |
44702360 PA |
11963 | /* Even though the caller told us to not insert new |
11964 | locations, we may still need to update conditions on the | |
11965 | target's side of breakpoints that were already inserted | |
11966 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
11967 | only update conditions for locations that are marked |
11968 | "needs_update". */ | |
11969 | update_inserted_breakpoint_locations (); | |
11970 | } | |
11971 | } | |
348d480f | 11972 | |
04086b45 | 11973 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 11974 | download_tracepoint_locations (); |
348d480f PA |
11975 | } |
11976 | ||
11977 | void | |
11978 | breakpoint_retire_moribund (void) | |
11979 | { | |
1123588c TT |
11980 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
11981 | { | |
11982 | struct bp_location *loc = moribund_locations[ix]; | |
11983 | if (--(loc->events_till_retirement) == 0) | |
11984 | { | |
11985 | decref_bp_location (&loc); | |
11986 | unordered_remove (moribund_locations, ix); | |
11987 | --ix; | |
11988 | } | |
11989 | } | |
348d480f PA |
11990 | } |
11991 | ||
11992 | static void | |
44702360 | 11993 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 11994 | { |
348d480f | 11995 | |
a70b8144 | 11996 | try |
492d29ea PA |
11997 | { |
11998 | update_global_location_list (insert_mode); | |
11999 | } | |
230d2906 | 12000 | catch (const gdb_exception_error &e) |
492d29ea PA |
12001 | { |
12002 | } | |
348d480f PA |
12003 | } |
12004 | ||
12005 | /* Clear BKP from a BPS. */ | |
12006 | ||
12007 | static void | |
12008 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12009 | { | |
12010 | bpstat bs; | |
12011 | ||
12012 | for (bs = bps; bs; bs = bs->next) | |
12013 | if (bs->breakpoint_at == bpt) | |
12014 | { | |
12015 | bs->breakpoint_at = NULL; | |
12016 | bs->old_val = NULL; | |
12017 | /* bs->commands will be freed later. */ | |
12018 | } | |
12019 | } | |
12020 | ||
12021 | /* Callback for iterate_over_threads. */ | |
12022 | static int | |
12023 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12024 | { | |
9a3c8263 | 12025 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12026 | |
12027 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12028 | return 0; | |
12029 | } | |
12030 | ||
12031 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12032 | callbacks. */ | |
12033 | ||
12034 | static void | |
12035 | say_where (struct breakpoint *b) | |
12036 | { | |
12037 | struct value_print_options opts; | |
12038 | ||
12039 | get_user_print_options (&opts); | |
12040 | ||
12041 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12042 | single string. */ | |
12043 | if (b->loc == NULL) | |
12044 | { | |
f00aae0f KS |
12045 | /* For pending locations, the output differs slightly based |
12046 | on b->extra_string. If this is non-NULL, it contains either | |
12047 | a condition or dprintf arguments. */ | |
12048 | if (b->extra_string == NULL) | |
12049 | { | |
12050 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12051 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12052 | } |
12053 | else if (b->type == bp_dprintf) | |
12054 | { | |
12055 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12056 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12057 | b->extra_string); |
12058 | } | |
12059 | else | |
12060 | { | |
12061 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12062 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12063 | b->extra_string); |
12064 | } | |
348d480f PA |
12065 | } |
12066 | else | |
12067 | { | |
2f202fde | 12068 | if (opts.addressprint || b->loc->symtab == NULL) |
6a831f06 PA |
12069 | printf_filtered (" at %ps", |
12070 | styled_string (address_style.style (), | |
12071 | paddress (b->loc->gdbarch, | |
12072 | b->loc->address))); | |
2f202fde | 12073 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12074 | { |
12075 | /* If there is a single location, we can print the location | |
12076 | more nicely. */ | |
12077 | if (b->loc->next == NULL) | |
0bb296cb | 12078 | { |
6a831f06 PA |
12079 | const char *filename |
12080 | = symtab_to_filename_for_display (b->loc->symtab); | |
12081 | printf_filtered (": file %ps, line %d.", | |
12082 | styled_string (file_name_style.style (), | |
12083 | filename), | |
0bb296cb TT |
12084 | b->loc->line_number); |
12085 | } | |
f8eba3c6 TT |
12086 | else |
12087 | /* This is not ideal, but each location may have a | |
12088 | different file name, and this at least reflects the | |
12089 | real situation somewhat. */ | |
f00aae0f | 12090 | printf_filtered (": %s.", |
d28cd78a | 12091 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12092 | } |
348d480f PA |
12093 | |
12094 | if (b->loc->next) | |
12095 | { | |
12096 | struct bp_location *loc = b->loc; | |
12097 | int n = 0; | |
12098 | for (; loc; loc = loc->next) | |
12099 | ++n; | |
12100 | printf_filtered (" (%d locations)", n); | |
12101 | } | |
12102 | } | |
12103 | } | |
12104 | ||
5f486660 | 12105 | bp_location::~bp_location () |
348d480f | 12106 | { |
5f486660 | 12107 | xfree (function_name); |
348d480f PA |
12108 | } |
12109 | ||
c1fc2657 | 12110 | /* Destructor for the breakpoint base class. */ |
348d480f | 12111 | |
c1fc2657 | 12112 | breakpoint::~breakpoint () |
348d480f | 12113 | { |
c1fc2657 SM |
12114 | xfree (this->cond_string); |
12115 | xfree (this->extra_string); | |
348d480f PA |
12116 | } |
12117 | ||
2060206e PA |
12118 | static struct bp_location * |
12119 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12120 | { |
5f486660 | 12121 | return new bp_location (self); |
348d480f PA |
12122 | } |
12123 | ||
2060206e PA |
12124 | static void |
12125 | base_breakpoint_re_set (struct breakpoint *b) | |
12126 | { | |
12127 | /* Nothing to re-set. */ | |
12128 | } | |
12129 | ||
12130 | #define internal_error_pure_virtual_called() \ | |
12131 | gdb_assert_not_reached ("pure virtual function called") | |
12132 | ||
12133 | static int | |
12134 | base_breakpoint_insert_location (struct bp_location *bl) | |
12135 | { | |
12136 | internal_error_pure_virtual_called (); | |
12137 | } | |
12138 | ||
12139 | static int | |
73971819 PA |
12140 | base_breakpoint_remove_location (struct bp_location *bl, |
12141 | enum remove_bp_reason reason) | |
2060206e PA |
12142 | { |
12143 | internal_error_pure_virtual_called (); | |
12144 | } | |
12145 | ||
12146 | static int | |
12147 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12148 | const address_space *aspace, |
09ac7c10 TT |
12149 | CORE_ADDR bp_addr, |
12150 | const struct target_waitstatus *ws) | |
2060206e PA |
12151 | { |
12152 | internal_error_pure_virtual_called (); | |
12153 | } | |
12154 | ||
12155 | static void | |
12156 | base_breakpoint_check_status (bpstat bs) | |
12157 | { | |
12158 | /* Always stop. */ | |
12159 | } | |
12160 | ||
12161 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12162 | errors. */ | |
12163 | ||
12164 | static int | |
12165 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12166 | { | |
12167 | internal_error_pure_virtual_called (); | |
12168 | } | |
12169 | ||
12170 | /* A "resources_needed" breakpoint_ops method that just internal | |
12171 | errors. */ | |
12172 | ||
12173 | static int | |
12174 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12175 | { | |
12176 | internal_error_pure_virtual_called (); | |
12177 | } | |
12178 | ||
12179 | static enum print_stop_action | |
12180 | base_breakpoint_print_it (bpstat bs) | |
12181 | { | |
12182 | internal_error_pure_virtual_called (); | |
12183 | } | |
12184 | ||
12185 | static void | |
12186 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12187 | struct ui_out *uiout) | |
12188 | { | |
12189 | /* nothing */ | |
12190 | } | |
12191 | ||
12192 | static void | |
12193 | base_breakpoint_print_mention (struct breakpoint *b) | |
12194 | { | |
12195 | internal_error_pure_virtual_called (); | |
12196 | } | |
12197 | ||
12198 | static void | |
12199 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12200 | { | |
12201 | internal_error_pure_virtual_called (); | |
12202 | } | |
12203 | ||
983af33b | 12204 | static void |
f00aae0f KS |
12205 | base_breakpoint_create_sals_from_location |
12206 | (const struct event_location *location, | |
12207 | struct linespec_result *canonical, | |
12208 | enum bptype type_wanted) | |
983af33b SDJ |
12209 | { |
12210 | internal_error_pure_virtual_called (); | |
12211 | } | |
12212 | ||
12213 | static void | |
12214 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12215 | struct linespec_result *c, | |
e1e01040 PA |
12216 | gdb::unique_xmalloc_ptr<char> cond_string, |
12217 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12218 | enum bptype type_wanted, |
12219 | enum bpdisp disposition, | |
12220 | int thread, | |
12221 | int task, int ignore_count, | |
12222 | const struct breakpoint_ops *o, | |
12223 | int from_tty, int enabled, | |
44f238bb | 12224 | int internal, unsigned flags) |
983af33b SDJ |
12225 | { |
12226 | internal_error_pure_virtual_called (); | |
12227 | } | |
12228 | ||
6c5b2ebe | 12229 | static std::vector<symtab_and_line> |
f00aae0f KS |
12230 | base_breakpoint_decode_location (struct breakpoint *b, |
12231 | const struct event_location *location, | |
6c5b2ebe | 12232 | struct program_space *search_pspace) |
983af33b SDJ |
12233 | { |
12234 | internal_error_pure_virtual_called (); | |
12235 | } | |
12236 | ||
ab04a2af TT |
12237 | /* The default 'explains_signal' method. */ |
12238 | ||
47591c29 | 12239 | static int |
427cd150 | 12240 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12241 | { |
47591c29 | 12242 | return 1; |
ab04a2af TT |
12243 | } |
12244 | ||
9d6e6e84 HZ |
12245 | /* The default "after_condition_true" method. */ |
12246 | ||
12247 | static void | |
12248 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12249 | { | |
12250 | /* Nothing to do. */ | |
12251 | } | |
12252 | ||
ab04a2af | 12253 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12254 | { |
2060206e PA |
12255 | base_breakpoint_allocate_location, |
12256 | base_breakpoint_re_set, | |
12257 | base_breakpoint_insert_location, | |
12258 | base_breakpoint_remove_location, | |
12259 | base_breakpoint_breakpoint_hit, | |
12260 | base_breakpoint_check_status, | |
12261 | base_breakpoint_resources_needed, | |
12262 | base_breakpoint_works_in_software_mode, | |
12263 | base_breakpoint_print_it, | |
12264 | NULL, | |
12265 | base_breakpoint_print_one_detail, | |
12266 | base_breakpoint_print_mention, | |
983af33b | 12267 | base_breakpoint_print_recreate, |
5f700d83 | 12268 | base_breakpoint_create_sals_from_location, |
983af33b | 12269 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12270 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12271 | base_breakpoint_explains_signal, |
12272 | base_breakpoint_after_condition_true, | |
2060206e PA |
12273 | }; |
12274 | ||
12275 | /* Default breakpoint_ops methods. */ | |
12276 | ||
12277 | static void | |
348d480f PA |
12278 | bkpt_re_set (struct breakpoint *b) |
12279 | { | |
06edf0c0 | 12280 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12281 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12282 | { |
f00aae0f | 12283 | /* Anything without a location can't be re-set. */ |
348d480f | 12284 | delete_breakpoint (b); |
06edf0c0 | 12285 | return; |
348d480f | 12286 | } |
06edf0c0 PA |
12287 | |
12288 | breakpoint_re_set_default (b); | |
348d480f PA |
12289 | } |
12290 | ||
2060206e | 12291 | static int |
348d480f PA |
12292 | bkpt_insert_location (struct bp_location *bl) |
12293 | { | |
cd6c3b4f YQ |
12294 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12295 | ||
579c6ad9 | 12296 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12297 | bl->target_info.placed_address = addr; |
12298 | ||
348d480f | 12299 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12300 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12301 | else |
7c16b83e | 12302 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12303 | } |
12304 | ||
2060206e | 12305 | static int |
73971819 | 12306 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12307 | { |
12308 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12309 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12310 | else | |
73971819 | 12311 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12312 | } |
12313 | ||
2060206e | 12314 | static int |
348d480f | 12315 | bkpt_breakpoint_hit (const struct bp_location *bl, |
bd522513 | 12316 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12317 | const struct target_waitstatus *ws) |
348d480f | 12318 | { |
09ac7c10 | 12319 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12320 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12321 | return 0; |
12322 | ||
348d480f PA |
12323 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12324 | aspace, bp_addr)) | |
12325 | return 0; | |
12326 | ||
12327 | if (overlay_debugging /* unmapped overlay section */ | |
12328 | && section_is_overlay (bl->section) | |
12329 | && !section_is_mapped (bl->section)) | |
12330 | return 0; | |
12331 | ||
12332 | return 1; | |
12333 | } | |
12334 | ||
cd1608cc PA |
12335 | static int |
12336 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12337 | const address_space *aspace, CORE_ADDR bp_addr, |
cd1608cc PA |
12338 | const struct target_waitstatus *ws) |
12339 | { | |
12340 | if (dprintf_style == dprintf_style_agent | |
12341 | && target_can_run_breakpoint_commands ()) | |
12342 | { | |
12343 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12344 | for this address it must be for a breakpoint that happens to | |
12345 | be set at the same address. */ | |
12346 | return 0; | |
12347 | } | |
12348 | ||
12349 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12350 | } | |
12351 | ||
2060206e | 12352 | static int |
348d480f PA |
12353 | bkpt_resources_needed (const struct bp_location *bl) |
12354 | { | |
12355 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12356 | ||
12357 | return 1; | |
12358 | } | |
12359 | ||
2060206e | 12360 | static enum print_stop_action |
348d480f PA |
12361 | bkpt_print_it (bpstat bs) |
12362 | { | |
348d480f PA |
12363 | struct breakpoint *b; |
12364 | const struct bp_location *bl; | |
001c8c33 | 12365 | int bp_temp; |
79a45e25 | 12366 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12367 | |
12368 | gdb_assert (bs->bp_location_at != NULL); | |
12369 | ||
12370 | bl = bs->bp_location_at; | |
12371 | b = bs->breakpoint_at; | |
12372 | ||
001c8c33 PA |
12373 | bp_temp = b->disposition == disp_del; |
12374 | if (bl->address != bl->requested_address) | |
12375 | breakpoint_adjustment_warning (bl->requested_address, | |
12376 | bl->address, | |
12377 | b->number, 1); | |
12378 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12379 | maybe_print_thread_hit_breakpoint (uiout); |
12380 | ||
112e8700 | 12381 | if (uiout->is_mi_like_p ()) |
348d480f | 12382 | { |
112e8700 | 12383 | uiout->field_string ("reason", |
001c8c33 | 12384 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12385 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12386 | } |
6a831f06 PA |
12387 | if (bp_temp) |
12388 | uiout->message ("Temporary breakpoint %pF, ", | |
12389 | signed_field ("bkptno", b->number)); | |
12390 | else | |
12391 | uiout->message ("Breakpoint %pF, ", | |
12392 | signed_field ("bkptno", b->number)); | |
06edf0c0 | 12393 | |
001c8c33 | 12394 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12395 | } |
12396 | ||
2060206e | 12397 | static void |
06edf0c0 PA |
12398 | bkpt_print_mention (struct breakpoint *b) |
12399 | { | |
112e8700 | 12400 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12401 | return; |
12402 | ||
12403 | switch (b->type) | |
12404 | { | |
12405 | case bp_breakpoint: | |
12406 | case bp_gnu_ifunc_resolver: | |
12407 | if (b->disposition == disp_del) | |
12408 | printf_filtered (_("Temporary breakpoint")); | |
12409 | else | |
12410 | printf_filtered (_("Breakpoint")); | |
12411 | printf_filtered (_(" %d"), b->number); | |
12412 | if (b->type == bp_gnu_ifunc_resolver) | |
12413 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12414 | break; | |
12415 | case bp_hardware_breakpoint: | |
12416 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12417 | break; | |
e7e0cddf SS |
12418 | case bp_dprintf: |
12419 | printf_filtered (_("Dprintf %d"), b->number); | |
12420 | break; | |
06edf0c0 PA |
12421 | } |
12422 | ||
12423 | say_where (b); | |
12424 | } | |
12425 | ||
2060206e | 12426 | static void |
06edf0c0 PA |
12427 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12428 | { | |
12429 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12430 | fprintf_unfiltered (fp, "tbreak"); | |
12431 | else if (tp->type == bp_breakpoint) | |
12432 | fprintf_unfiltered (fp, "break"); | |
12433 | else if (tp->type == bp_hardware_breakpoint | |
12434 | && tp->disposition == disp_del) | |
12435 | fprintf_unfiltered (fp, "thbreak"); | |
12436 | else if (tp->type == bp_hardware_breakpoint) | |
12437 | fprintf_unfiltered (fp, "hbreak"); | |
12438 | else | |
12439 | internal_error (__FILE__, __LINE__, | |
12440 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12441 | ||
f00aae0f | 12442 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12443 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12444 | |
12445 | /* Print out extra_string if this breakpoint is pending. It might | |
12446 | contain, for example, conditions that were set by the user. */ | |
12447 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12448 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12449 | ||
dd11a36c | 12450 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12451 | } |
12452 | ||
983af33b | 12453 | static void |
f00aae0f KS |
12454 | bkpt_create_sals_from_location (const struct event_location *location, |
12455 | struct linespec_result *canonical, | |
12456 | enum bptype type_wanted) | |
983af33b | 12457 | { |
f00aae0f | 12458 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12459 | } |
12460 | ||
12461 | static void | |
12462 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12463 | struct linespec_result *canonical, | |
e1e01040 PA |
12464 | gdb::unique_xmalloc_ptr<char> cond_string, |
12465 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12466 | enum bptype type_wanted, |
12467 | enum bpdisp disposition, | |
12468 | int thread, | |
12469 | int task, int ignore_count, | |
12470 | const struct breakpoint_ops *ops, | |
12471 | int from_tty, int enabled, | |
44f238bb | 12472 | int internal, unsigned flags) |
983af33b | 12473 | { |
023fa29b | 12474 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12475 | std::move (cond_string), |
12476 | std::move (extra_string), | |
e7e0cddf | 12477 | type_wanted, |
983af33b SDJ |
12478 | disposition, thread, task, |
12479 | ignore_count, ops, from_tty, | |
44f238bb | 12480 | enabled, internal, flags); |
983af33b SDJ |
12481 | } |
12482 | ||
6c5b2ebe | 12483 | static std::vector<symtab_and_line> |
f00aae0f KS |
12484 | bkpt_decode_location (struct breakpoint *b, |
12485 | const struct event_location *location, | |
6c5b2ebe | 12486 | struct program_space *search_pspace) |
983af33b | 12487 | { |
6c5b2ebe | 12488 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12489 | } |
12490 | ||
06edf0c0 PA |
12491 | /* Virtual table for internal breakpoints. */ |
12492 | ||
12493 | static void | |
12494 | internal_bkpt_re_set (struct breakpoint *b) | |
12495 | { | |
12496 | switch (b->type) | |
12497 | { | |
12498 | /* Delete overlay event and longjmp master breakpoints; they | |
12499 | will be reset later by breakpoint_re_set. */ | |
12500 | case bp_overlay_event: | |
12501 | case bp_longjmp_master: | |
12502 | case bp_std_terminate_master: | |
12503 | case bp_exception_master: | |
12504 | delete_breakpoint (b); | |
12505 | break; | |
12506 | ||
12507 | /* This breakpoint is special, it's set up when the inferior | |
12508 | starts and we really don't want to touch it. */ | |
12509 | case bp_shlib_event: | |
12510 | ||
12511 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12512 | it is set up, we do not want to touch it. */ | |
12513 | case bp_thread_event: | |
12514 | break; | |
12515 | } | |
12516 | } | |
12517 | ||
12518 | static void | |
12519 | internal_bkpt_check_status (bpstat bs) | |
12520 | { | |
a9b3a50f PA |
12521 | if (bs->breakpoint_at->type == bp_shlib_event) |
12522 | { | |
12523 | /* If requested, stop when the dynamic linker notifies GDB of | |
12524 | events. This allows the user to get control and place | |
12525 | breakpoints in initializer routines for dynamically loaded | |
12526 | objects (among other things). */ | |
12527 | bs->stop = stop_on_solib_events; | |
12528 | bs->print = stop_on_solib_events; | |
12529 | } | |
12530 | else | |
12531 | bs->stop = 0; | |
06edf0c0 PA |
12532 | } |
12533 | ||
12534 | static enum print_stop_action | |
12535 | internal_bkpt_print_it (bpstat bs) | |
12536 | { | |
06edf0c0 | 12537 | struct breakpoint *b; |
06edf0c0 | 12538 | |
06edf0c0 PA |
12539 | b = bs->breakpoint_at; |
12540 | ||
06edf0c0 PA |
12541 | switch (b->type) |
12542 | { | |
348d480f PA |
12543 | case bp_shlib_event: |
12544 | /* Did we stop because the user set the stop_on_solib_events | |
12545 | variable? (If so, we report this as a generic, "Stopped due | |
12546 | to shlib event" message.) */ | |
edcc5120 | 12547 | print_solib_event (0); |
348d480f PA |
12548 | break; |
12549 | ||
12550 | case bp_thread_event: | |
12551 | /* Not sure how we will get here. | |
12552 | GDB should not stop for these breakpoints. */ | |
12553 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12554 | break; |
12555 | ||
12556 | case bp_overlay_event: | |
12557 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12558 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12559 | break; |
12560 | ||
12561 | case bp_longjmp_master: | |
12562 | /* These should never be enabled. */ | |
12563 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12564 | break; |
12565 | ||
12566 | case bp_std_terminate_master: | |
12567 | /* These should never be enabled. */ | |
12568 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12569 | "gdb should not stop!\n")); | |
348d480f PA |
12570 | break; |
12571 | ||
12572 | case bp_exception_master: | |
12573 | /* These should never be enabled. */ | |
12574 | printf_filtered (_("Exception Master Breakpoint: " | |
12575 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12576 | break; |
12577 | } | |
12578 | ||
001c8c33 | 12579 | return PRINT_NOTHING; |
06edf0c0 PA |
12580 | } |
12581 | ||
12582 | static void | |
12583 | internal_bkpt_print_mention (struct breakpoint *b) | |
12584 | { | |
12585 | /* Nothing to mention. These breakpoints are internal. */ | |
12586 | } | |
12587 | ||
06edf0c0 PA |
12588 | /* Virtual table for momentary breakpoints */ |
12589 | ||
12590 | static void | |
12591 | momentary_bkpt_re_set (struct breakpoint *b) | |
12592 | { | |
12593 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12594 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12595 | Otherwise these should have been blown away via the cleanup chain |
12596 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12597 | } | |
12598 | ||
12599 | static void | |
12600 | momentary_bkpt_check_status (bpstat bs) | |
12601 | { | |
12602 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12603 | } | |
12604 | ||
12605 | static enum print_stop_action | |
12606 | momentary_bkpt_print_it (bpstat bs) | |
12607 | { | |
001c8c33 | 12608 | return PRINT_UNKNOWN; |
348d480f PA |
12609 | } |
12610 | ||
06edf0c0 PA |
12611 | static void |
12612 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12613 | { |
06edf0c0 | 12614 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12615 | } |
12616 | ||
e2e4d78b JK |
12617 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12618 | ||
12619 | It gets cleared already on the removal of the first one of such placed | |
12620 | breakpoints. This is OK as they get all removed altogether. */ | |
12621 | ||
c1fc2657 | 12622 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 12623 | { |
c1fc2657 | 12624 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 12625 | |
c1fc2657 | 12626 | if (tp != NULL) |
e2e4d78b | 12627 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
12628 | } |
12629 | ||
55aa24fb SDJ |
12630 | /* Specific methods for probe breakpoints. */ |
12631 | ||
12632 | static int | |
12633 | bkpt_probe_insert_location (struct bp_location *bl) | |
12634 | { | |
12635 | int v = bkpt_insert_location (bl); | |
12636 | ||
12637 | if (v == 0) | |
12638 | { | |
12639 | /* The insertion was successful, now let's set the probe's semaphore | |
12640 | if needed. */ | |
935676c9 | 12641 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb SDJ |
12642 | } |
12643 | ||
12644 | return v; | |
12645 | } | |
12646 | ||
12647 | static int | |
73971819 PA |
12648 | bkpt_probe_remove_location (struct bp_location *bl, |
12649 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
12650 | { |
12651 | /* Let's clear the semaphore before removing the location. */ | |
935676c9 | 12652 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb | 12653 | |
73971819 | 12654 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
12655 | } |
12656 | ||
12657 | static void | |
f00aae0f | 12658 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12659 | struct linespec_result *canonical, |
f00aae0f | 12660 | enum bptype type_wanted) |
55aa24fb SDJ |
12661 | { |
12662 | struct linespec_sals lsal; | |
12663 | ||
c2f4122d | 12664 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
12665 | lsal.canonical |
12666 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12667 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
12668 | } |
12669 | ||
6c5b2ebe | 12670 | static std::vector<symtab_and_line> |
f00aae0f KS |
12671 | bkpt_probe_decode_location (struct breakpoint *b, |
12672 | const struct event_location *location, | |
6c5b2ebe | 12673 | struct program_space *search_pspace) |
55aa24fb | 12674 | { |
6c5b2ebe PA |
12675 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
12676 | if (sals.empty ()) | |
55aa24fb | 12677 | error (_("probe not found")); |
6c5b2ebe | 12678 | return sals; |
55aa24fb SDJ |
12679 | } |
12680 | ||
348d480f | 12681 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12682 | |
348d480f PA |
12683 | static void |
12684 | tracepoint_re_set (struct breakpoint *b) | |
12685 | { | |
12686 | breakpoint_re_set_default (b); | |
12687 | } | |
876fa593 | 12688 | |
348d480f PA |
12689 | static int |
12690 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12691 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12692 | const struct target_waitstatus *ws) |
348d480f PA |
12693 | { |
12694 | /* By definition, the inferior does not report stops at | |
12695 | tracepoints. */ | |
12696 | return 0; | |
74960c60 VP |
12697 | } |
12698 | ||
12699 | static void | |
348d480f PA |
12700 | tracepoint_print_one_detail (const struct breakpoint *self, |
12701 | struct ui_out *uiout) | |
74960c60 | 12702 | { |
d9b3f62e | 12703 | struct tracepoint *tp = (struct tracepoint *) self; |
5d9310c4 | 12704 | if (!tp->static_trace_marker_id.empty ()) |
348d480f PA |
12705 | { |
12706 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12707 | |
6a831f06 PA |
12708 | uiout->message ("\tmarker id is %pF\n", |
12709 | string_field ("static-tracepoint-marker-string-id", | |
12710 | tp->static_trace_marker_id.c_str ())); | |
348d480f | 12711 | } |
0d381245 VP |
12712 | } |
12713 | ||
a474d7c2 | 12714 | static void |
348d480f | 12715 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12716 | { |
112e8700 | 12717 | if (current_uiout->is_mi_like_p ()) |
348d480f | 12718 | return; |
cc59ec59 | 12719 | |
348d480f PA |
12720 | switch (b->type) |
12721 | { | |
12722 | case bp_tracepoint: | |
12723 | printf_filtered (_("Tracepoint")); | |
12724 | printf_filtered (_(" %d"), b->number); | |
12725 | break; | |
12726 | case bp_fast_tracepoint: | |
12727 | printf_filtered (_("Fast tracepoint")); | |
12728 | printf_filtered (_(" %d"), b->number); | |
12729 | break; | |
12730 | case bp_static_tracepoint: | |
12731 | printf_filtered (_("Static tracepoint")); | |
12732 | printf_filtered (_(" %d"), b->number); | |
12733 | break; | |
12734 | default: | |
12735 | internal_error (__FILE__, __LINE__, | |
12736 | _("unhandled tracepoint type %d"), (int) b->type); | |
12737 | } | |
12738 | ||
12739 | say_where (b); | |
a474d7c2 PA |
12740 | } |
12741 | ||
348d480f | 12742 | static void |
d9b3f62e | 12743 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12744 | { |
d9b3f62e PA |
12745 | struct tracepoint *tp = (struct tracepoint *) self; |
12746 | ||
12747 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12748 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 12749 | else if (self->type == bp_static_tracepoint) |
348d480f | 12750 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12751 | else if (self->type == bp_tracepoint) |
348d480f PA |
12752 | fprintf_unfiltered (fp, "trace"); |
12753 | else | |
12754 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12755 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12756 | |
f00aae0f | 12757 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12758 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
12759 | print_recreate_thread (self, fp); |
12760 | ||
12761 | if (tp->pass_count) | |
12762 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
12763 | } |
12764 | ||
983af33b | 12765 | static void |
f00aae0f KS |
12766 | tracepoint_create_sals_from_location (const struct event_location *location, |
12767 | struct linespec_result *canonical, | |
12768 | enum bptype type_wanted) | |
983af33b | 12769 | { |
f00aae0f | 12770 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12771 | } |
12772 | ||
12773 | static void | |
12774 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12775 | struct linespec_result *canonical, | |
e1e01040 PA |
12776 | gdb::unique_xmalloc_ptr<char> cond_string, |
12777 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12778 | enum bptype type_wanted, |
12779 | enum bpdisp disposition, | |
12780 | int thread, | |
12781 | int task, int ignore_count, | |
12782 | const struct breakpoint_ops *ops, | |
12783 | int from_tty, int enabled, | |
44f238bb | 12784 | int internal, unsigned flags) |
983af33b | 12785 | { |
023fa29b | 12786 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12787 | std::move (cond_string), |
12788 | std::move (extra_string), | |
e7e0cddf | 12789 | type_wanted, |
983af33b SDJ |
12790 | disposition, thread, task, |
12791 | ignore_count, ops, from_tty, | |
44f238bb | 12792 | enabled, internal, flags); |
983af33b SDJ |
12793 | } |
12794 | ||
6c5b2ebe | 12795 | static std::vector<symtab_and_line> |
f00aae0f KS |
12796 | tracepoint_decode_location (struct breakpoint *b, |
12797 | const struct event_location *location, | |
6c5b2ebe | 12798 | struct program_space *search_pspace) |
983af33b | 12799 | { |
6c5b2ebe | 12800 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12801 | } |
12802 | ||
2060206e | 12803 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 12804 | |
55aa24fb SDJ |
12805 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
12806 | static probe. */ | |
12807 | ||
12808 | static void | |
f00aae0f KS |
12809 | tracepoint_probe_create_sals_from_location |
12810 | (const struct event_location *location, | |
12811 | struct linespec_result *canonical, | |
12812 | enum bptype type_wanted) | |
55aa24fb SDJ |
12813 | { |
12814 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 12815 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
12816 | } |
12817 | ||
6c5b2ebe | 12818 | static std::vector<symtab_and_line> |
f00aae0f KS |
12819 | tracepoint_probe_decode_location (struct breakpoint *b, |
12820 | const struct event_location *location, | |
6c5b2ebe | 12821 | struct program_space *search_pspace) |
55aa24fb SDJ |
12822 | { |
12823 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 12824 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
12825 | } |
12826 | ||
12827 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
12828 | ||
5c2b4418 HZ |
12829 | /* Dprintf breakpoint_ops methods. */ |
12830 | ||
12831 | static void | |
12832 | dprintf_re_set (struct breakpoint *b) | |
12833 | { | |
12834 | breakpoint_re_set_default (b); | |
12835 | ||
f00aae0f KS |
12836 | /* extra_string should never be non-NULL for dprintf. */ |
12837 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
12838 | |
12839 | /* 1 - connect to target 1, that can run breakpoint commands. | |
12840 | 2 - create a dprintf, which resolves fine. | |
12841 | 3 - disconnect from target 1 | |
12842 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
12843 | ||
12844 | After steps #3/#4, you'll want the dprintf command list to | |
12845 | be updated, because target 1 and 2 may well return different | |
12846 | answers for target_can_run_breakpoint_commands(). | |
12847 | Given absence of finer grained resetting, we get to do | |
12848 | it all the time. */ | |
12849 | if (b->extra_string != NULL) | |
12850 | update_dprintf_command_list (b); | |
12851 | } | |
12852 | ||
2d9442cc HZ |
12853 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
12854 | ||
12855 | static void | |
12856 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
12857 | { | |
f00aae0f | 12858 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 12859 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
12860 | tp->extra_string); |
12861 | print_recreate_thread (tp, fp); | |
12862 | } | |
12863 | ||
9d6e6e84 HZ |
12864 | /* Implement the "after_condition_true" breakpoint_ops method for |
12865 | dprintf. | |
12866 | ||
12867 | dprintf's are implemented with regular commands in their command | |
12868 | list, but we run the commands here instead of before presenting the | |
12869 | stop to the user, as dprintf's don't actually cause a stop. This | |
12870 | also makes it so that the commands of multiple dprintfs at the same | |
12871 | address are all handled. */ | |
12872 | ||
12873 | static void | |
12874 | dprintf_after_condition_true (struct bpstats *bs) | |
12875 | { | |
04afa70c | 12876 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
12877 | struct bpstats *tmp_bs_p = &tmp_bs; |
12878 | ||
12879 | /* dprintf's never cause a stop. This wasn't set in the | |
12880 | check_status hook instead because that would make the dprintf's | |
12881 | condition not be evaluated. */ | |
12882 | bs->stop = 0; | |
12883 | ||
12884 | /* Run the command list here. Take ownership of it instead of | |
12885 | copying. We never want these commands to run later in | |
12886 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
12887 | be set at same address as this dprintf, or even if running the | |
12888 | commands here throws. */ | |
12889 | tmp_bs.commands = bs->commands; | |
12890 | bs->commands = NULL; | |
9d6e6e84 HZ |
12891 | |
12892 | bpstat_do_actions_1 (&tmp_bs_p); | |
12893 | ||
12894 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
12895 | bpstat_do_actions_1 may return early without processing the whole | |
12896 | list. */ | |
9d6e6e84 HZ |
12897 | } |
12898 | ||
983af33b SDJ |
12899 | /* The breakpoint_ops structure to be used on static tracepoints with |
12900 | markers (`-m'). */ | |
12901 | ||
12902 | static void | |
f00aae0f | 12903 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12904 | struct linespec_result *canonical, |
f00aae0f | 12905 | enum bptype type_wanted) |
983af33b SDJ |
12906 | { |
12907 | struct linespec_sals lsal; | |
f00aae0f | 12908 | const char *arg_start, *arg; |
983af33b | 12909 | |
a20714ff | 12910 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 12911 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 12912 | |
f2fc3015 TT |
12913 | std::string str (arg_start, arg - arg_start); |
12914 | const char *ptr = str.c_str (); | |
a20714ff PA |
12915 | canonical->location |
12916 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 12917 | |
8e9e35b1 TT |
12918 | lsal.canonical |
12919 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12920 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
12921 | } |
12922 | ||
12923 | static void | |
12924 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12925 | struct linespec_result *canonical, | |
e1e01040 PA |
12926 | gdb::unique_xmalloc_ptr<char> cond_string, |
12927 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12928 | enum bptype type_wanted, |
12929 | enum bpdisp disposition, | |
12930 | int thread, | |
12931 | int task, int ignore_count, | |
12932 | const struct breakpoint_ops *ops, | |
12933 | int from_tty, int enabled, | |
44f238bb | 12934 | int internal, unsigned flags) |
983af33b | 12935 | { |
6c5b2ebe | 12936 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
12937 | |
12938 | /* If the user is creating a static tracepoint by marker id | |
12939 | (strace -m MARKER_ID), then store the sals index, so that | |
12940 | breakpoint_re_set can try to match up which of the newly | |
12941 | found markers corresponds to this one, and, don't try to | |
12942 | expand multiple locations for each sal, given than SALS | |
12943 | already should contain all sals for MARKER_ID. */ | |
12944 | ||
6c5b2ebe | 12945 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 12946 | { |
6c5b2ebe PA |
12947 | event_location_up location |
12948 | = copy_event_location (canonical->location.get ()); | |
983af33b | 12949 | |
b270e6f9 | 12950 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 12951 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 12952 | std::move (location), NULL, |
e1e01040 PA |
12953 | std::move (cond_string), |
12954 | std::move (extra_string), | |
e7e0cddf | 12955 | type_wanted, disposition, |
983af33b | 12956 | thread, task, ignore_count, ops, |
44f238bb | 12957 | from_tty, enabled, internal, flags, |
983af33b SDJ |
12958 | canonical->special_display); |
12959 | /* Given that its possible to have multiple markers with | |
12960 | the same string id, if the user is creating a static | |
12961 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
12962 | store the sals index, so that breakpoint_re_set can | |
12963 | try to match up which of the newly found markers | |
12964 | corresponds to this one */ | |
12965 | tp->static_trace_marker_id_idx = i; | |
12966 | ||
b270e6f9 | 12967 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
12968 | } |
12969 | } | |
12970 | ||
6c5b2ebe | 12971 | static std::vector<symtab_and_line> |
f00aae0f KS |
12972 | strace_marker_decode_location (struct breakpoint *b, |
12973 | const struct event_location *location, | |
6c5b2ebe | 12974 | struct program_space *search_pspace) |
983af33b SDJ |
12975 | { |
12976 | struct tracepoint *tp = (struct tracepoint *) b; | |
a20714ff | 12977 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 12978 | |
6c5b2ebe PA |
12979 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
12980 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 12981 | { |
6c5b2ebe PA |
12982 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
12983 | sals.resize (1); | |
12984 | return sals; | |
983af33b SDJ |
12985 | } |
12986 | else | |
5d9310c4 | 12987 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
983af33b SDJ |
12988 | } |
12989 | ||
12990 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
12991 | ||
12992 | static int | |
12993 | strace_marker_p (struct breakpoint *b) | |
12994 | { | |
12995 | return b->ops == &strace_marker_breakpoint_ops; | |
12996 | } | |
12997 | ||
53a5351d | 12998 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 12999 | structures. */ |
c906108c SS |
13000 | |
13001 | void | |
fba45db2 | 13002 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13003 | { |
52f0bd74 | 13004 | struct breakpoint *b; |
c906108c | 13005 | |
8a3fe4f8 | 13006 | gdb_assert (bpt != NULL); |
c906108c | 13007 | |
4a64f543 MS |
13008 | /* Has this bp already been deleted? This can happen because |
13009 | multiple lists can hold pointers to bp's. bpstat lists are | |
13010 | especial culprits. | |
13011 | ||
13012 | One example of this happening is a watchpoint's scope bp. When | |
13013 | the scope bp triggers, we notice that the watchpoint is out of | |
13014 | scope, and delete it. We also delete its scope bp. But the | |
13015 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13016 | That bpstat is then checked for auto-deleting bp's, which are | |
13017 | deleted. | |
13018 | ||
13019 | A real solution to this problem might involve reference counts in | |
13020 | bp's, and/or giving them pointers back to their referencing | |
13021 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13022 | storage when no more references were extent. A cheaper bandaid | |
13023 | was chosen. */ | |
c906108c SS |
13024 | if (bpt->type == bp_none) |
13025 | return; | |
13026 | ||
4a64f543 MS |
13027 | /* At least avoid this stale reference until the reference counting |
13028 | of breakpoints gets resolved. */ | |
d0fb5eae | 13029 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13030 | { |
d0fb5eae | 13031 | struct breakpoint *related; |
3a5c3e22 | 13032 | struct watchpoint *w; |
d0fb5eae JK |
13033 | |
13034 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13035 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13036 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13037 | w = (struct watchpoint *) bpt; |
13038 | else | |
13039 | w = NULL; | |
13040 | if (w != NULL) | |
13041 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13042 | |
13043 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13044 | for (related = bpt; related->related_breakpoint != bpt; | |
13045 | related = related->related_breakpoint); | |
13046 | related->related_breakpoint = bpt->related_breakpoint; | |
13047 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13048 | } |
13049 | ||
a9634178 TJB |
13050 | /* watch_command_1 creates a watchpoint but only sets its number if |
13051 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13052 | a problem in that process, we'll be asked to delete the half-created | |
13053 | watchpoint. In that case, don't announce the deletion. */ | |
13054 | if (bpt->number) | |
76727919 | 13055 | gdb::observers::breakpoint_deleted.notify (bpt); |
c906108c | 13056 | |
c906108c SS |
13057 | if (breakpoint_chain == bpt) |
13058 | breakpoint_chain = bpt->next; | |
13059 | ||
c906108c SS |
13060 | ALL_BREAKPOINTS (b) |
13061 | if (b->next == bpt) | |
c5aa993b JM |
13062 | { |
13063 | b->next = bpt->next; | |
13064 | break; | |
13065 | } | |
c906108c | 13066 | |
f431efe5 PA |
13067 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13068 | been freed. */ | |
13069 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13070 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13071 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13072 | commands are associated with the bpstat; if we remove it here, | |
13073 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13074 | event-top.c won't do anything, and temporary breakpoints with | |
13075 | commands won't work. */ | |
13076 | ||
13077 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13078 | ||
4a64f543 MS |
13079 | /* Now that breakpoint is removed from breakpoint list, update the |
13080 | global location list. This will remove locations that used to | |
13081 | belong to this breakpoint. Do this before freeing the breakpoint | |
13082 | itself, since remove_breakpoint looks at location's owner. It | |
13083 | might be better design to have location completely | |
13084 | self-contained, but it's not the case now. */ | |
44702360 | 13085 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13086 | |
4a64f543 MS |
13087 | /* On the chance that someone will soon try again to delete this |
13088 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13089 | bpt->type = bp_none; |
4d01a485 | 13090 | delete bpt; |
c906108c SS |
13091 | } |
13092 | ||
51be5b68 PA |
13093 | /* Iterator function to call a user-provided callback function once |
13094 | for each of B and its related breakpoints. */ | |
13095 | ||
13096 | static void | |
13097 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13098 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13099 | { |
13100 | struct breakpoint *related; | |
13101 | ||
13102 | related = b; | |
13103 | do | |
13104 | { | |
13105 | struct breakpoint *next; | |
13106 | ||
13107 | /* FUNCTION may delete RELATED. */ | |
13108 | next = related->related_breakpoint; | |
13109 | ||
13110 | if (next == related) | |
13111 | { | |
13112 | /* RELATED is the last ring entry. */ | |
48649e1b | 13113 | function (related); |
51be5b68 PA |
13114 | |
13115 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13116 | B. There's nothing left to do anyway, so just break | |
13117 | out. */ | |
13118 | break; | |
13119 | } | |
13120 | else | |
48649e1b | 13121 | function (related); |
51be5b68 PA |
13122 | |
13123 | related = next; | |
13124 | } | |
13125 | while (related != b); | |
13126 | } | |
95a42b64 | 13127 | |
4495129a | 13128 | static void |
981a3fb3 | 13129 | delete_command (const char *arg, int from_tty) |
c906108c | 13130 | { |
35df4500 | 13131 | struct breakpoint *b, *b_tmp; |
c906108c | 13132 | |
ea9365bb TT |
13133 | dont_repeat (); |
13134 | ||
c906108c SS |
13135 | if (arg == 0) |
13136 | { | |
13137 | int breaks_to_delete = 0; | |
13138 | ||
46c6471b PA |
13139 | /* Delete all breakpoints if no argument. Do not delete |
13140 | internal breakpoints, these have to be deleted with an | |
13141 | explicit breakpoint number argument. */ | |
c5aa993b | 13142 | ALL_BREAKPOINTS (b) |
46c6471b | 13143 | if (user_breakpoint_p (b)) |
973d738b DJ |
13144 | { |
13145 | breaks_to_delete = 1; | |
13146 | break; | |
13147 | } | |
c906108c SS |
13148 | |
13149 | /* Ask user only if there are some breakpoints to delete. */ | |
13150 | if (!from_tty | |
e2e0b3e5 | 13151 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13152 | { |
35df4500 | 13153 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13154 | if (user_breakpoint_p (b)) |
c5aa993b | 13155 | delete_breakpoint (b); |
c906108c SS |
13156 | } |
13157 | } | |
13158 | else | |
48649e1b | 13159 | map_breakpoint_numbers |
b926417a | 13160 | (arg, [&] (breakpoint *br) |
48649e1b | 13161 | { |
b926417a | 13162 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 13163 | }); |
c906108c SS |
13164 | } |
13165 | ||
c2f4122d PA |
13166 | /* Return true if all locations of B bound to PSPACE are pending. If |
13167 | PSPACE is NULL, all locations of all program spaces are | |
13168 | considered. */ | |
13169 | ||
0d381245 | 13170 | static int |
c2f4122d | 13171 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13172 | { |
c2f4122d PA |
13173 | struct bp_location *loc; |
13174 | ||
13175 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13176 | if ((pspace == NULL | |
13177 | || loc->pspace == pspace) | |
13178 | && !loc->shlib_disabled | |
8645ff69 | 13179 | && !loc->pspace->executing_startup) |
0d381245 VP |
13180 | return 0; |
13181 | return 1; | |
fe3f5fa8 VP |
13182 | } |
13183 | ||
776592bf DE |
13184 | /* Subroutine of update_breakpoint_locations to simplify it. |
13185 | Return non-zero if multiple fns in list LOC have the same name. | |
13186 | Null names are ignored. */ | |
13187 | ||
13188 | static int | |
13189 | ambiguous_names_p (struct bp_location *loc) | |
13190 | { | |
13191 | struct bp_location *l; | |
459a2e4c TT |
13192 | htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL, |
13193 | xcalloc, xfree); | |
776592bf DE |
13194 | |
13195 | for (l = loc; l != NULL; l = l->next) | |
13196 | { | |
13197 | const char **slot; | |
13198 | const char *name = l->function_name; | |
13199 | ||
13200 | /* Allow for some names to be NULL, ignore them. */ | |
13201 | if (name == NULL) | |
13202 | continue; | |
13203 | ||
13204 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13205 | INSERT); | |
4a64f543 MS |
13206 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13207 | returns NULL. */ | |
776592bf DE |
13208 | if (*slot != NULL) |
13209 | { | |
13210 | htab_delete (htab); | |
13211 | return 1; | |
13212 | } | |
13213 | *slot = name; | |
13214 | } | |
13215 | ||
13216 | htab_delete (htab); | |
13217 | return 0; | |
13218 | } | |
13219 | ||
0fb4aa4b PA |
13220 | /* When symbols change, it probably means the sources changed as well, |
13221 | and it might mean the static tracepoint markers are no longer at | |
13222 | the same address or line numbers they used to be at last we | |
13223 | checked. Losing your static tracepoints whenever you rebuild is | |
13224 | undesirable. This function tries to resync/rematch gdb static | |
13225 | tracepoints with the markers on the target, for static tracepoints | |
13226 | that have not been set by marker id. Static tracepoint that have | |
13227 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13228 | The heuristic is: | |
13229 | ||
13230 | 1) For a tracepoint set at a specific address, look for a marker at | |
13231 | the old PC. If one is found there, assume to be the same marker. | |
13232 | If the name / string id of the marker found is different from the | |
13233 | previous known name, assume that means the user renamed the marker | |
13234 | in the sources, and output a warning. | |
13235 | ||
13236 | 2) For a tracepoint set at a given line number, look for a marker | |
13237 | at the new address of the old line number. If one is found there, | |
13238 | assume to be the same marker. If the name / string id of the | |
13239 | marker found is different from the previous known name, assume that | |
13240 | means the user renamed the marker in the sources, and output a | |
13241 | warning. | |
13242 | ||
13243 | 3) If a marker is no longer found at the same address or line, it | |
13244 | may mean the marker no longer exists. But it may also just mean | |
13245 | the code changed a bit. Maybe the user added a few lines of code | |
13246 | that made the marker move up or down (in line number terms). Ask | |
13247 | the target for info about the marker with the string id as we knew | |
13248 | it. If found, update line number and address in the matching | |
13249 | static tracepoint. This will get confused if there's more than one | |
13250 | marker with the same ID (possible in UST, although unadvised | |
13251 | precisely because it confuses tools). */ | |
13252 | ||
13253 | static struct symtab_and_line | |
13254 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13255 | { | |
d9b3f62e | 13256 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13257 | struct static_tracepoint_marker marker; |
13258 | CORE_ADDR pc; | |
0fb4aa4b PA |
13259 | |
13260 | pc = sal.pc; | |
13261 | if (sal.line) | |
13262 | find_line_pc (sal.symtab, sal.line, &pc); | |
13263 | ||
13264 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13265 | { | |
5d9310c4 | 13266 | if (tp->static_trace_marker_id != marker.str_id) |
0fb4aa4b | 13267 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
5d9310c4 SM |
13268 | b->number, tp->static_trace_marker_id.c_str (), |
13269 | marker.str_id.c_str ()); | |
0fb4aa4b | 13270 | |
5d9310c4 | 13271 | tp->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b PA |
13272 | |
13273 | return sal; | |
13274 | } | |
13275 | ||
13276 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13277 | by string ID. */ | |
13278 | if (!sal.explicit_pc | |
13279 | && sal.line != 0 | |
13280 | && sal.symtab != NULL | |
5d9310c4 | 13281 | && !tp->static_trace_marker_id.empty ()) |
0fb4aa4b | 13282 | { |
5d9310c4 SM |
13283 | std::vector<static_tracepoint_marker> markers |
13284 | = target_static_tracepoint_markers_by_strid | |
13285 | (tp->static_trace_marker_id.c_str ()); | |
0fb4aa4b | 13286 | |
5d9310c4 | 13287 | if (!markers.empty ()) |
0fb4aa4b | 13288 | { |
0fb4aa4b | 13289 | struct symbol *sym; |
80e1d417 | 13290 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13291 | struct ui_out *uiout = current_uiout; |
67994074 | 13292 | struct explicit_location explicit_loc; |
0fb4aa4b | 13293 | |
5d9310c4 | 13294 | tpmarker = &markers[0]; |
0fb4aa4b | 13295 | |
5d9310c4 | 13296 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
0fb4aa4b PA |
13297 | |
13298 | warning (_("marker for static tracepoint %d (%s) not " | |
13299 | "found at previous line number"), | |
5d9310c4 | 13300 | b->number, tp->static_trace_marker_id.c_str ()); |
0fb4aa4b | 13301 | |
51abb421 | 13302 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13303 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13304 | uiout->text ("Now in "); |
0fb4aa4b PA |
13305 | if (sym) |
13306 | { | |
987012b8 | 13307 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 13308 | function_name_style.style ()); |
112e8700 | 13309 | uiout->text (" at "); |
0fb4aa4b | 13310 | } |
112e8700 | 13311 | uiout->field_string ("file", |
cbe56571 | 13312 | symtab_to_filename_for_display (sal2.symtab), |
e43b10e1 | 13313 | file_name_style.style ()); |
112e8700 | 13314 | uiout->text (":"); |
0fb4aa4b | 13315 | |
112e8700 | 13316 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13317 | { |
0b0865da | 13318 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13319 | |
112e8700 | 13320 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13321 | } |
13322 | ||
381befee | 13323 | uiout->field_signed ("line", sal2.line); |
112e8700 | 13324 | uiout->text ("\n"); |
0fb4aa4b | 13325 | |
80e1d417 | 13326 | b->loc->line_number = sal2.line; |
2f202fde | 13327 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13328 | |
d28cd78a | 13329 | b->location.reset (NULL); |
67994074 KS |
13330 | initialize_explicit_location (&explicit_loc); |
13331 | explicit_loc.source_filename | |
00e52e53 | 13332 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13333 | explicit_loc.line_offset.offset = b->loc->line_number; |
13334 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13335 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13336 | |
13337 | /* Might be nice to check if function changed, and warn if | |
13338 | so. */ | |
0fb4aa4b PA |
13339 | } |
13340 | } | |
13341 | return sal; | |
13342 | } | |
13343 | ||
8d3788bd VP |
13344 | /* Returns 1 iff locations A and B are sufficiently same that |
13345 | we don't need to report breakpoint as changed. */ | |
13346 | ||
13347 | static int | |
13348 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13349 | { | |
13350 | while (a && b) | |
13351 | { | |
13352 | if (a->address != b->address) | |
13353 | return 0; | |
13354 | ||
13355 | if (a->shlib_disabled != b->shlib_disabled) | |
13356 | return 0; | |
13357 | ||
13358 | if (a->enabled != b->enabled) | |
13359 | return 0; | |
13360 | ||
13361 | a = a->next; | |
13362 | b = b->next; | |
13363 | } | |
13364 | ||
13365 | if ((a == NULL) != (b == NULL)) | |
13366 | return 0; | |
13367 | ||
13368 | return 1; | |
13369 | } | |
13370 | ||
c2f4122d PA |
13371 | /* Split all locations of B that are bound to PSPACE out of B's |
13372 | location list to a separate list and return that list's head. If | |
13373 | PSPACE is NULL, hoist out all locations of B. */ | |
13374 | ||
13375 | static struct bp_location * | |
13376 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13377 | { | |
13378 | struct bp_location head; | |
13379 | struct bp_location *i = b->loc; | |
13380 | struct bp_location **i_link = &b->loc; | |
13381 | struct bp_location *hoisted = &head; | |
13382 | ||
13383 | if (pspace == NULL) | |
13384 | { | |
13385 | i = b->loc; | |
13386 | b->loc = NULL; | |
13387 | return i; | |
13388 | } | |
13389 | ||
13390 | head.next = NULL; | |
13391 | ||
13392 | while (i != NULL) | |
13393 | { | |
13394 | if (i->pspace == pspace) | |
13395 | { | |
13396 | *i_link = i->next; | |
13397 | i->next = NULL; | |
13398 | hoisted->next = i; | |
13399 | hoisted = i; | |
13400 | } | |
13401 | else | |
13402 | i_link = &i->next; | |
13403 | i = *i_link; | |
13404 | } | |
13405 | ||
13406 | return head.next; | |
13407 | } | |
13408 | ||
13409 | /* Create new breakpoint locations for B (a hardware or software | |
13410 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13411 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13412 | FILTER_PSPACE. Locations of other program spaces are left | |
13413 | untouched. */ | |
f1310107 | 13414 | |
0e30163f | 13415 | void |
0d381245 | 13416 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13417 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13418 | gdb::array_view<const symtab_and_line> sals, |
13419 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 13420 | { |
c2f4122d | 13421 | struct bp_location *existing_locations; |
0d381245 | 13422 | |
6c5b2ebe | 13423 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13424 | { |
13425 | /* Ranged breakpoints have only one start location and one end | |
13426 | location. */ | |
13427 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13428 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13429 | "multiple locations found\n"), | |
13430 | b->number); | |
13431 | return; | |
13432 | } | |
f1310107 | 13433 | |
4a64f543 MS |
13434 | /* If there's no new locations, and all existing locations are |
13435 | pending, don't do anything. This optimizes the common case where | |
13436 | all locations are in the same shared library, that was unloaded. | |
13437 | We'd like to retain the location, so that when the library is | |
13438 | loaded again, we don't loose the enabled/disabled status of the | |
13439 | individual locations. */ | |
6c5b2ebe | 13440 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13441 | return; |
13442 | ||
c2f4122d | 13443 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13444 | |
6c5b2ebe | 13445 | for (const auto &sal : sals) |
fe3f5fa8 | 13446 | { |
f8eba3c6 TT |
13447 | struct bp_location *new_loc; |
13448 | ||
6c5b2ebe | 13449 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13450 | |
6c5b2ebe | 13451 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13452 | |
0d381245 VP |
13453 | /* Reparse conditions, they might contain references to the |
13454 | old symtab. */ | |
13455 | if (b->cond_string != NULL) | |
13456 | { | |
bbc13ae3 | 13457 | const char *s; |
fe3f5fa8 | 13458 | |
0d381245 | 13459 | s = b->cond_string; |
a70b8144 | 13460 | try |
0d381245 | 13461 | { |
6c5b2ebe PA |
13462 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13463 | block_for_pc (sal.pc), | |
0d381245 VP |
13464 | 0); |
13465 | } | |
230d2906 | 13466 | catch (const gdb_exception_error &e) |
0d381245 | 13467 | { |
3e43a32a MS |
13468 | warning (_("failed to reevaluate condition " |
13469 | "for breakpoint %d: %s"), | |
3d6e9d23 | 13470 | b->number, e.what ()); |
0d381245 VP |
13471 | new_loc->enabled = 0; |
13472 | } | |
13473 | } | |
fe3f5fa8 | 13474 | |
6c5b2ebe | 13475 | if (!sals_end.empty ()) |
f1310107 | 13476 | { |
6c5b2ebe | 13477 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13478 | |
6c5b2ebe | 13479 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13480 | } |
0d381245 | 13481 | } |
fe3f5fa8 | 13482 | |
4a64f543 MS |
13483 | /* If possible, carry over 'disable' status from existing |
13484 | breakpoints. */ | |
0d381245 VP |
13485 | { |
13486 | struct bp_location *e = existing_locations; | |
776592bf DE |
13487 | /* If there are multiple breakpoints with the same function name, |
13488 | e.g. for inline functions, comparing function names won't work. | |
13489 | Instead compare pc addresses; this is just a heuristic as things | |
13490 | may have moved, but in practice it gives the correct answer | |
13491 | often enough until a better solution is found. */ | |
13492 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13493 | ||
0d381245 VP |
13494 | for (; e; e = e->next) |
13495 | { | |
13496 | if (!e->enabled && e->function_name) | |
13497 | { | |
13498 | struct bp_location *l = b->loc; | |
776592bf DE |
13499 | if (have_ambiguous_names) |
13500 | { | |
13501 | for (; l; l = l->next) | |
f1310107 | 13502 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13503 | { |
13504 | l->enabled = 0; | |
13505 | break; | |
13506 | } | |
13507 | } | |
13508 | else | |
13509 | { | |
13510 | for (; l; l = l->next) | |
13511 | if (l->function_name | |
13512 | && strcmp (e->function_name, l->function_name) == 0) | |
13513 | { | |
13514 | l->enabled = 0; | |
13515 | break; | |
13516 | } | |
13517 | } | |
0d381245 VP |
13518 | } |
13519 | } | |
13520 | } | |
fe3f5fa8 | 13521 | |
8d3788bd | 13522 | if (!locations_are_equal (existing_locations, b->loc)) |
76727919 | 13523 | gdb::observers::breakpoint_modified.notify (b); |
fe3f5fa8 VP |
13524 | } |
13525 | ||
f00aae0f | 13526 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13527 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13528 | ||
6c5b2ebe | 13529 | static std::vector<symtab_and_line> |
f00aae0f | 13530 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13531 | struct program_space *search_pspace, int *found) |
ef23e705 | 13532 | { |
cc06b668 | 13533 | struct gdb_exception exception; |
ef23e705 | 13534 | |
983af33b | 13535 | gdb_assert (b->ops != NULL); |
ef23e705 | 13536 | |
6c5b2ebe PA |
13537 | std::vector<symtab_and_line> sals; |
13538 | ||
a70b8144 | 13539 | try |
ef23e705 | 13540 | { |
6c5b2ebe | 13541 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13542 | } |
94aeb44b | 13543 | catch (gdb_exception_error &e) |
ef23e705 TJB |
13544 | { |
13545 | int not_found_and_ok = 0; | |
492d29ea | 13546 | |
ef23e705 TJB |
13547 | /* For pending breakpoints, it's expected that parsing will |
13548 | fail until the right shared library is loaded. User has | |
13549 | already told to create pending breakpoints and don't need | |
13550 | extra messages. If breakpoint is in bp_shlib_disabled | |
13551 | state, then user already saw the message about that | |
13552 | breakpoint being disabled, and don't want to see more | |
13553 | errors. */ | |
58438ac1 | 13554 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13555 | && (b->condition_not_parsed |
13556 | || (b->loc != NULL | |
13557 | && search_pspace != NULL | |
13558 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13559 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13560 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13561 | || b->enable_state == bp_disabled)) |
13562 | not_found_and_ok = 1; | |
13563 | ||
13564 | if (!not_found_and_ok) | |
13565 | { | |
13566 | /* We surely don't want to warn about the same breakpoint | |
13567 | 10 times. One solution, implemented here, is disable | |
13568 | the breakpoint on error. Another solution would be to | |
13569 | have separate 'warning emitted' flag. Since this | |
13570 | happens only when a binary has changed, I don't know | |
13571 | which approach is better. */ | |
13572 | b->enable_state = bp_disabled; | |
eedc3f4f | 13573 | throw; |
ef23e705 | 13574 | } |
94aeb44b TT |
13575 | |
13576 | exception = std::move (e); | |
ef23e705 TJB |
13577 | } |
13578 | ||
492d29ea | 13579 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13580 | { |
6c5b2ebe PA |
13581 | for (auto &sal : sals) |
13582 | resolve_sal_pc (&sal); | |
f00aae0f | 13583 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13584 | { |
ed1d1739 KS |
13585 | char *cond_string, *extra_string; |
13586 | int thread, task; | |
ef23e705 | 13587 | |
6c5b2ebe | 13588 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
13589 | &cond_string, &thread, &task, |
13590 | &extra_string); | |
f00aae0f | 13591 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
13592 | if (cond_string) |
13593 | b->cond_string = cond_string; | |
13594 | b->thread = thread; | |
13595 | b->task = task; | |
e7e0cddf | 13596 | if (extra_string) |
f00aae0f KS |
13597 | { |
13598 | xfree (b->extra_string); | |
13599 | b->extra_string = extra_string; | |
13600 | } | |
ef23e705 TJB |
13601 | b->condition_not_parsed = 0; |
13602 | } | |
13603 | ||
983af33b | 13604 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 13605 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 13606 | |
58438ac1 TT |
13607 | *found = 1; |
13608 | } | |
13609 | else | |
13610 | *found = 0; | |
ef23e705 TJB |
13611 | |
13612 | return sals; | |
13613 | } | |
13614 | ||
348d480f PA |
13615 | /* The default re_set method, for typical hardware or software |
13616 | breakpoints. Reevaluate the breakpoint and recreate its | |
13617 | locations. */ | |
13618 | ||
13619 | static void | |
28010a5d | 13620 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 13621 | { |
c2f4122d | 13622 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 13623 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 13624 | |
6c5b2ebe PA |
13625 | int found; |
13626 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
13627 | filter_pspace, &found); | |
ef23e705 | 13628 | if (found) |
6c5b2ebe | 13629 | expanded = std::move (sals); |
ef23e705 | 13630 | |
f00aae0f | 13631 | if (b->location_range_end != NULL) |
f1310107 | 13632 | { |
6c5b2ebe PA |
13633 | std::vector<symtab_and_line> sals_end |
13634 | = location_to_sals (b, b->location_range_end.get (), | |
13635 | filter_pspace, &found); | |
f1310107 | 13636 | if (found) |
6c5b2ebe | 13637 | expanded_end = std::move (sals_end); |
f1310107 TJB |
13638 | } |
13639 | ||
c2f4122d | 13640 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
13641 | } |
13642 | ||
983af33b SDJ |
13643 | /* Default method for creating SALs from an address string. It basically |
13644 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13645 | ||
13646 | static void | |
f00aae0f KS |
13647 | create_sals_from_location_default (const struct event_location *location, |
13648 | struct linespec_result *canonical, | |
13649 | enum bptype type_wanted) | |
983af33b | 13650 | { |
f00aae0f | 13651 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
13652 | } |
13653 | ||
13654 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13655 | function for the `create_breakpoints_sal' method of | |
13656 | breakpoint_ops. */ | |
13657 | ||
13658 | static void | |
13659 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13660 | struct linespec_result *canonical, | |
e1e01040 PA |
13661 | gdb::unique_xmalloc_ptr<char> cond_string, |
13662 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13663 | enum bptype type_wanted, |
13664 | enum bpdisp disposition, | |
13665 | int thread, | |
13666 | int task, int ignore_count, | |
13667 | const struct breakpoint_ops *ops, | |
13668 | int from_tty, int enabled, | |
44f238bb | 13669 | int internal, unsigned flags) |
983af33b | 13670 | { |
e1e01040 PA |
13671 | create_breakpoints_sal (gdbarch, canonical, |
13672 | std::move (cond_string), | |
13673 | std::move (extra_string), | |
983af33b SDJ |
13674 | type_wanted, disposition, |
13675 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13676 | enabled, internal, flags); |
983af33b SDJ |
13677 | } |
13678 | ||
13679 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 13680 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 13681 | |
6c5b2ebe | 13682 | static std::vector<symtab_and_line> |
f00aae0f KS |
13683 | decode_location_default (struct breakpoint *b, |
13684 | const struct event_location *location, | |
6c5b2ebe | 13685 | struct program_space *search_pspace) |
983af33b SDJ |
13686 | { |
13687 | struct linespec_result canonical; | |
13688 | ||
c2f4122d | 13689 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
cafb3438 | 13690 | NULL, 0, &canonical, multiple_symbols_all, |
c0e8dcd8 | 13691 | b->filter.get ()); |
983af33b SDJ |
13692 | |
13693 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 13694 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 13695 | |
6c5b2ebe | 13696 | if (!canonical.lsals.empty ()) |
983af33b | 13697 | { |
6c5b2ebe PA |
13698 | const linespec_sals &lsal = canonical.lsals[0]; |
13699 | return std::move (lsal.sals); | |
983af33b | 13700 | } |
6c5b2ebe | 13701 | return {}; |
983af33b SDJ |
13702 | } |
13703 | ||
bf469271 | 13704 | /* Reset a breakpoint. */ |
c906108c | 13705 | |
bf469271 PA |
13706 | static void |
13707 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 13708 | { |
fdf44873 TT |
13709 | input_radix = b->input_radix; |
13710 | set_language (b->language); | |
c906108c | 13711 | |
348d480f | 13712 | b->ops->re_set (b); |
c906108c SS |
13713 | } |
13714 | ||
c2f4122d PA |
13715 | /* Re-set breakpoint locations for the current program space. |
13716 | Locations bound to other program spaces are left untouched. */ | |
13717 | ||
c906108c | 13718 | void |
69de3c6a | 13719 | breakpoint_re_set (void) |
c906108c | 13720 | { |
35df4500 | 13721 | struct breakpoint *b, *b_tmp; |
2a7f3dff | 13722 | |
c5aa993b | 13723 | { |
fdf44873 TT |
13724 | scoped_restore_current_language save_language; |
13725 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 13726 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 13727 | |
8e817061 JB |
13728 | /* breakpoint_re_set_one sets the current_language to the language |
13729 | of the breakpoint it is resetting (see prepare_re_set_context) | |
13730 | before re-evaluating the breakpoint's location. This change can | |
13731 | unfortunately get undone by accident if the language_mode is set | |
13732 | to auto, and we either switch frames, or more likely in this context, | |
13733 | we select the current frame. | |
13734 | ||
13735 | We prevent this by temporarily turning the language_mode to | |
13736 | language_mode_manual. We restore it once all breakpoints | |
13737 | have been reset. */ | |
13738 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); | |
13739 | language_mode = language_mode_manual; | |
13740 | ||
5ed8105e PA |
13741 | /* Note: we must not try to insert locations until after all |
13742 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
13743 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
13744 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 13745 | |
5ed8105e PA |
13746 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
13747 | { | |
a70b8144 | 13748 | try |
bf469271 PA |
13749 | { |
13750 | breakpoint_re_set_one (b); | |
13751 | } | |
230d2906 | 13752 | catch (const gdb_exception &ex) |
bf469271 PA |
13753 | { |
13754 | exception_fprintf (gdb_stderr, ex, | |
13755 | "Error in re-setting breakpoint %d: ", | |
13756 | b->number); | |
13757 | } | |
5ed8105e | 13758 | } |
5ed8105e PA |
13759 | |
13760 | jit_breakpoint_re_set (); | |
13761 | } | |
6c95b8df | 13762 | |
af02033e PP |
13763 | create_overlay_event_breakpoint (); |
13764 | create_longjmp_master_breakpoint (); | |
13765 | create_std_terminate_master_breakpoint (); | |
186c406b | 13766 | create_exception_master_breakpoint (); |
2a7f3dff PA |
13767 | |
13768 | /* Now we can insert. */ | |
13769 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
13770 | } |
13771 | \f | |
c906108c SS |
13772 | /* Reset the thread number of this breakpoint: |
13773 | ||
13774 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13775 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13776 | void |
fba45db2 | 13777 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13778 | { |
13779 | if (b->thread != -1) | |
13780 | { | |
00431a78 | 13781 | b->thread = inferior_thread ()->global_num; |
6c95b8df PA |
13782 | |
13783 | /* We're being called after following a fork. The new fork is | |
13784 | selected as current, and unless this was a vfork will have a | |
13785 | different program space from the original thread. Reset that | |
13786 | as well. */ | |
13787 | b->loc->pspace = current_program_space; | |
c906108c SS |
13788 | } |
13789 | } | |
13790 | ||
03ac34d5 MS |
13791 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13792 | If from_tty is nonzero, it prints a message to that effect, | |
13793 | which ends with a period (no newline). */ | |
13794 | ||
c906108c | 13795 | void |
fba45db2 | 13796 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13797 | { |
52f0bd74 | 13798 | struct breakpoint *b; |
c906108c SS |
13799 | |
13800 | if (count < 0) | |
13801 | count = 0; | |
13802 | ||
13803 | ALL_BREAKPOINTS (b) | |
13804 | if (b->number == bptnum) | |
c5aa993b | 13805 | { |
d77f58be SS |
13806 | if (is_tracepoint (b)) |
13807 | { | |
13808 | if (from_tty && count != 0) | |
13809 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
13810 | bptnum); | |
13811 | return; | |
13812 | } | |
13813 | ||
c5aa993b | 13814 | b->ignore_count = count; |
221ea385 KS |
13815 | if (from_tty) |
13816 | { | |
13817 | if (count == 0) | |
3e43a32a MS |
13818 | printf_filtered (_("Will stop next time " |
13819 | "breakpoint %d is reached."), | |
221ea385 KS |
13820 | bptnum); |
13821 | else if (count == 1) | |
a3f17187 | 13822 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
13823 | bptnum); |
13824 | else | |
3e43a32a MS |
13825 | printf_filtered (_("Will ignore next %d " |
13826 | "crossings of breakpoint %d."), | |
221ea385 KS |
13827 | count, bptnum); |
13828 | } | |
76727919 | 13829 | gdb::observers::breakpoint_modified.notify (b); |
c5aa993b JM |
13830 | return; |
13831 | } | |
c906108c | 13832 | |
8a3fe4f8 | 13833 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13834 | } |
13835 | ||
c906108c SS |
13836 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13837 | ||
13838 | static void | |
0b39b52e | 13839 | ignore_command (const char *args, int from_tty) |
c906108c | 13840 | { |
0b39b52e | 13841 | const char *p = args; |
52f0bd74 | 13842 | int num; |
c906108c SS |
13843 | |
13844 | if (p == 0) | |
e2e0b3e5 | 13845 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13846 | |
c906108c | 13847 | num = get_number (&p); |
5c44784c | 13848 | if (num == 0) |
8a3fe4f8 | 13849 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13850 | if (*p == 0) |
8a3fe4f8 | 13851 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13852 | |
13853 | set_ignore_count (num, | |
13854 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13855 | from_tty); | |
221ea385 KS |
13856 | if (from_tty) |
13857 | printf_filtered ("\n"); | |
c906108c SS |
13858 | } |
13859 | \f | |
d0fe4701 XR |
13860 | |
13861 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
13862 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
13863 | |
13864 | static void | |
d0fe4701 XR |
13865 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
13866 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 13867 | { |
d0fe4701 XR |
13868 | if (bp_num_range.first == 0) |
13869 | { | |
13870 | warning (_("bad breakpoint number at or near '%d'"), | |
13871 | bp_num_range.first); | |
13872 | } | |
13873 | else | |
c906108c | 13874 | { |
d0fe4701 | 13875 | struct breakpoint *b, *tmp; |
197f0a60 | 13876 | |
d0fe4701 | 13877 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 13878 | { |
d0fe4701 XR |
13879 | bool match = false; |
13880 | ||
5c44784c | 13881 | ALL_BREAKPOINTS_SAFE (b, tmp) |
d0fe4701 | 13882 | if (b->number == i) |
5c44784c | 13883 | { |
bfd28288 | 13884 | match = true; |
48649e1b | 13885 | function (b); |
11cf8741 | 13886 | break; |
5c44784c | 13887 | } |
bfd28288 | 13888 | if (!match) |
d0fe4701 | 13889 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
c5aa993b | 13890 | } |
c906108c SS |
13891 | } |
13892 | } | |
13893 | ||
d0fe4701 XR |
13894 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
13895 | ARGS. */ | |
13896 | ||
13897 | static void | |
13898 | map_breakpoint_numbers (const char *args, | |
13899 | gdb::function_view<void (breakpoint *)> function) | |
13900 | { | |
13901 | if (args == NULL || *args == '\0') | |
13902 | error_no_arg (_("one or more breakpoint numbers")); | |
13903 | ||
13904 | number_or_range_parser parser (args); | |
13905 | ||
13906 | while (!parser.finished ()) | |
13907 | { | |
13908 | int num = parser.get_number (); | |
13909 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
13910 | } | |
13911 | } | |
13912 | ||
13913 | /* Return the breakpoint location structure corresponding to the | |
13914 | BP_NUM and LOC_NUM values. */ | |
13915 | ||
0d381245 | 13916 | static struct bp_location * |
d0fe4701 | 13917 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 13918 | { |
0d381245 | 13919 | struct breakpoint *b; |
0d381245 VP |
13920 | |
13921 | ALL_BREAKPOINTS (b) | |
13922 | if (b->number == bp_num) | |
13923 | { | |
13924 | break; | |
13925 | } | |
13926 | ||
13927 | if (!b || b->number != bp_num) | |
d0fe4701 | 13928 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 13929 | |
0d381245 | 13930 | if (loc_num == 0) |
d0fe4701 | 13931 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 13932 | |
d0fe4701 XR |
13933 | int n = 0; |
13934 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
13935 | if (++n == loc_num) | |
13936 | return loc; | |
13937 | ||
13938 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
13939 | } |
13940 | ||
95e95a6d PA |
13941 | /* Modes of operation for extract_bp_num. */ |
13942 | enum class extract_bp_kind | |
13943 | { | |
13944 | /* Extracting a breakpoint number. */ | |
13945 | bp, | |
13946 | ||
13947 | /* Extracting a location number. */ | |
13948 | loc, | |
13949 | }; | |
13950 | ||
13951 | /* Extract a breakpoint or location number (as determined by KIND) | |
13952 | from the string starting at START. TRAILER is a character which | |
13953 | can be found after the number. If you don't want a trailer, use | |
13954 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
13955 | string. This always returns a positive integer. */ | |
13956 | ||
13957 | static int | |
13958 | extract_bp_num (extract_bp_kind kind, const char *start, | |
13959 | int trailer, const char **end_out = NULL) | |
13960 | { | |
13961 | const char *end = start; | |
13962 | int num = get_number_trailer (&end, trailer); | |
13963 | if (num < 0) | |
13964 | error (kind == extract_bp_kind::bp | |
13965 | ? _("Negative breakpoint number '%.*s'") | |
13966 | : _("Negative breakpoint location number '%.*s'"), | |
13967 | int (end - start), start); | |
13968 | if (num == 0) | |
13969 | error (kind == extract_bp_kind::bp | |
13970 | ? _("Bad breakpoint number '%.*s'") | |
13971 | : _("Bad breakpoint location number '%.*s'"), | |
13972 | int (end - start), start); | |
13973 | ||
13974 | if (end_out != NULL) | |
13975 | *end_out = end; | |
13976 | return num; | |
13977 | } | |
13978 | ||
13979 | /* Extract a breakpoint or location range (as determined by KIND) in | |
13980 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
13981 | representing the (inclusive) range. The returned pair's elements | |
13982 | are always positive integers. */ | |
13983 | ||
13984 | static std::pair<int, int> | |
13985 | extract_bp_or_bp_range (extract_bp_kind kind, | |
13986 | const std::string &arg, | |
13987 | std::string::size_type arg_offset) | |
13988 | { | |
13989 | std::pair<int, int> range; | |
13990 | const char *bp_loc = &arg[arg_offset]; | |
13991 | std::string::size_type dash = arg.find ('-', arg_offset); | |
13992 | if (dash != std::string::npos) | |
13993 | { | |
13994 | /* bp_loc is a range (x-z). */ | |
13995 | if (arg.length () == dash + 1) | |
13996 | error (kind == extract_bp_kind::bp | |
13997 | ? _("Bad breakpoint number at or near: '%s'") | |
13998 | : _("Bad breakpoint location number at or near: '%s'"), | |
13999 | bp_loc); | |
14000 | ||
14001 | const char *end; | |
14002 | const char *start_first = bp_loc; | |
14003 | const char *start_second = &arg[dash + 1]; | |
14004 | range.first = extract_bp_num (kind, start_first, '-'); | |
14005 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
14006 | ||
14007 | if (range.first > range.second) | |
14008 | error (kind == extract_bp_kind::bp | |
14009 | ? _("Inverted breakpoint range at '%.*s'") | |
14010 | : _("Inverted breakpoint location range at '%.*s'"), | |
14011 | int (end - start_first), start_first); | |
14012 | } | |
14013 | else | |
14014 | { | |
14015 | /* bp_loc is a single value. */ | |
14016 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
14017 | range.second = range.first; | |
14018 | } | |
14019 | return range; | |
14020 | } | |
14021 | ||
d0fe4701 XR |
14022 | /* Extract the breakpoint/location range specified by ARG. Returns |
14023 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
14024 | BP_LOC_RANGE. | |
14025 | ||
14026 | ARG may be in any of the following forms: | |
14027 | ||
14028 | x where 'x' is a breakpoint number. | |
14029 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
14030 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
14031 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
14032 | location number range. | |
14033 | */ | |
14034 | ||
cc638e86 | 14035 | static void |
d0fe4701 XR |
14036 | extract_bp_number_and_location (const std::string &arg, |
14037 | std::pair<int, int> &bp_num_range, | |
14038 | std::pair<int, int> &bp_loc_range) | |
14039 | { | |
14040 | std::string::size_type dot = arg.find ('.'); | |
14041 | ||
14042 | if (dot != std::string::npos) | |
14043 | { | |
14044 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
14045 | ||
14046 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 14047 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 14048 | |
95e95a6d PA |
14049 | bp_num_range.first |
14050 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
14051 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 14052 | |
95e95a6d PA |
14053 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
14054 | arg, dot + 1); | |
d0fe4701 XR |
14055 | } |
14056 | else | |
14057 | { | |
14058 | /* Handle x and x-y cases. */ | |
d0fe4701 | 14059 | |
95e95a6d | 14060 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
14061 | bp_loc_range.first = 0; |
14062 | bp_loc_range.second = 0; | |
14063 | } | |
d0fe4701 XR |
14064 | } |
14065 | ||
14066 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
14067 | specifies whether to enable or disable. */ | |
14068 | ||
14069 | static void | |
14070 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
14071 | { | |
14072 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
14073 | if (loc != NULL) | |
14074 | { | |
14075 | if (loc->enabled != enable) | |
14076 | { | |
14077 | loc->enabled = enable; | |
14078 | mark_breakpoint_location_modified (loc); | |
14079 | } | |
14080 | if (target_supports_enable_disable_tracepoint () | |
14081 | && current_trace_status ()->running && loc->owner | |
14082 | && is_tracepoint (loc->owner)) | |
14083 | target_disable_tracepoint (loc); | |
14084 | } | |
14085 | update_global_location_list (UGLL_DONT_INSERT); | |
d7154a8d JV |
14086 | |
14087 | gdb::observers::breakpoint_modified.notify (loc->owner); | |
d0fe4701 XR |
14088 | } |
14089 | ||
14090 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
14091 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
14092 | (inclusive) range of location numbers of that breakpoint to | |
14093 | enable/disable. ENABLE specifies whether to enable or disable the | |
14094 | location. */ | |
14095 | ||
14096 | static void | |
14097 | enable_disable_breakpoint_location_range (int bp_num, | |
14098 | std::pair<int, int> &bp_loc_range, | |
14099 | bool enable) | |
14100 | { | |
14101 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
14102 | enable_disable_bp_num_loc (bp_num, i, enable); | |
14103 | } | |
0d381245 | 14104 | |
1900040c MS |
14105 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14106 | If from_tty is nonzero, it prints a message to that effect, | |
14107 | which ends with a period (no newline). */ | |
14108 | ||
c906108c | 14109 | void |
fba45db2 | 14110 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14111 | { |
14112 | /* Never disable a watchpoint scope breakpoint; we want to | |
14113 | hit them when we leave scope so we can delete both the | |
14114 | watchpoint and its scope breakpoint at that time. */ | |
14115 | if (bpt->type == bp_watchpoint_scope) | |
14116 | return; | |
14117 | ||
b5de0fa7 | 14118 | bpt->enable_state = bp_disabled; |
c906108c | 14119 | |
b775012e LM |
14120 | /* Mark breakpoint locations modified. */ |
14121 | mark_breakpoint_modified (bpt); | |
14122 | ||
d248b706 KY |
14123 | if (target_supports_enable_disable_tracepoint () |
14124 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14125 | { | |
14126 | struct bp_location *location; | |
14127 | ||
14128 | for (location = bpt->loc; location; location = location->next) | |
14129 | target_disable_tracepoint (location); | |
14130 | } | |
14131 | ||
44702360 | 14132 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14133 | |
76727919 | 14134 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14135 | } |
14136 | ||
d0fe4701 XR |
14137 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
14138 | specified in ARGS. ARGS may be in any of the formats handled by | |
14139 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
14140 | or disable the breakpoints/locations. */ | |
14141 | ||
c906108c | 14142 | static void |
d0fe4701 | 14143 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 14144 | { |
c906108c | 14145 | if (args == 0) |
46c6471b PA |
14146 | { |
14147 | struct breakpoint *bpt; | |
14148 | ||
14149 | ALL_BREAKPOINTS (bpt) | |
14150 | if (user_breakpoint_p (bpt)) | |
d0fe4701 XR |
14151 | { |
14152 | if (enable) | |
14153 | enable_breakpoint (bpt); | |
14154 | else | |
14155 | disable_breakpoint (bpt); | |
14156 | } | |
46c6471b | 14157 | } |
9eaabc75 | 14158 | else |
0d381245 | 14159 | { |
cb791d59 | 14160 | std::string num = extract_arg (&args); |
9eaabc75 | 14161 | |
cb791d59 | 14162 | while (!num.empty ()) |
d248b706 | 14163 | { |
d0fe4701 | 14164 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 14165 | |
cc638e86 PA |
14166 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
14167 | ||
14168 | if (bp_loc_range.first == bp_loc_range.second | |
14169 | && bp_loc_range.first == 0) | |
d0fe4701 | 14170 | { |
cc638e86 PA |
14171 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
14172 | map_breakpoint_number_range (bp_num_range, | |
14173 | enable | |
14174 | ? enable_breakpoint | |
14175 | : disable_breakpoint); | |
14176 | } | |
14177 | else | |
14178 | { | |
14179 | /* Handle breakpoint ids with formats 'x.y' or | |
14180 | 'x.y-z'. */ | |
14181 | enable_disable_breakpoint_location_range | |
14182 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 14183 | } |
9eaabc75 | 14184 | num = extract_arg (&args); |
d248b706 | 14185 | } |
0d381245 | 14186 | } |
c906108c SS |
14187 | } |
14188 | ||
d0fe4701 XR |
14189 | /* The disable command disables the specified breakpoints/locations |
14190 | (or all defined breakpoints) so they're no longer effective in | |
14191 | stopping the inferior. ARGS may be in any of the forms defined in | |
14192 | extract_bp_number_and_location. */ | |
14193 | ||
14194 | static void | |
14195 | disable_command (const char *args, int from_tty) | |
14196 | { | |
14197 | enable_disable_command (args, from_tty, false); | |
14198 | } | |
14199 | ||
c906108c | 14200 | static void |
816338b5 SS |
14201 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14202 | int count) | |
c906108c | 14203 | { |
afe38095 | 14204 | int target_resources_ok; |
c906108c SS |
14205 | |
14206 | if (bpt->type == bp_hardware_breakpoint) | |
14207 | { | |
14208 | int i; | |
c5aa993b | 14209 | i = hw_breakpoint_used_count (); |
53a5351d | 14210 | target_resources_ok = |
d92524f1 | 14211 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14212 | i + 1, 0); |
c906108c | 14213 | if (target_resources_ok == 0) |
8a3fe4f8 | 14214 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14215 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14216 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14217 | } |
14218 | ||
cc60f2e3 | 14219 | if (is_watchpoint (bpt)) |
c906108c | 14220 | { |
d07205c2 | 14221 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14222 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14223 | |
a70b8144 | 14224 | try |
c906108c | 14225 | { |
3a5c3e22 PA |
14226 | struct watchpoint *w = (struct watchpoint *) bpt; |
14227 | ||
1e718ff1 TJB |
14228 | orig_enable_state = bpt->enable_state; |
14229 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14230 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14231 | } |
230d2906 | 14232 | catch (const gdb_exception &e) |
c5aa993b | 14233 | { |
1e718ff1 | 14234 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14235 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14236 | bpt->number); | |
14237 | return; | |
c5aa993b | 14238 | } |
c906108c | 14239 | } |
0101ce28 | 14240 | |
b775012e LM |
14241 | bpt->enable_state = bp_enabled; |
14242 | ||
14243 | /* Mark breakpoint locations modified. */ | |
14244 | mark_breakpoint_modified (bpt); | |
14245 | ||
d248b706 KY |
14246 | if (target_supports_enable_disable_tracepoint () |
14247 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14248 | { | |
14249 | struct bp_location *location; | |
14250 | ||
14251 | for (location = bpt->loc; location; location = location->next) | |
14252 | target_enable_tracepoint (location); | |
14253 | } | |
14254 | ||
b4c291bb | 14255 | bpt->disposition = disposition; |
816338b5 | 14256 | bpt->enable_count = count; |
44702360 | 14257 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14258 | |
76727919 | 14259 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14260 | } |
14261 | ||
fe3f5fa8 | 14262 | |
c906108c | 14263 | void |
fba45db2 | 14264 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14265 | { |
816338b5 | 14266 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14267 | } |
14268 | ||
d0fe4701 XR |
14269 | /* The enable command enables the specified breakpoints/locations (or |
14270 | all defined breakpoints) so they once again become (or continue to | |
14271 | be) effective in stopping the inferior. ARGS may be in any of the | |
14272 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 14273 | |
c906108c | 14274 | static void |
981a3fb3 | 14275 | enable_command (const char *args, int from_tty) |
c906108c | 14276 | { |
d0fe4701 | 14277 | enable_disable_command (args, from_tty, true); |
c906108c SS |
14278 | } |
14279 | ||
c906108c | 14280 | static void |
4495129a | 14281 | enable_once_command (const char *args, int from_tty) |
c906108c | 14282 | { |
48649e1b TT |
14283 | map_breakpoint_numbers |
14284 | (args, [&] (breakpoint *b) | |
14285 | { | |
14286 | iterate_over_related_breakpoints | |
14287 | (b, [&] (breakpoint *bpt) | |
14288 | { | |
14289 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14290 | }); | |
14291 | }); | |
816338b5 SS |
14292 | } |
14293 | ||
14294 | static void | |
4495129a | 14295 | enable_count_command (const char *args, int from_tty) |
816338b5 | 14296 | { |
b9d61307 SM |
14297 | int count; |
14298 | ||
14299 | if (args == NULL) | |
14300 | error_no_arg (_("hit count")); | |
14301 | ||
14302 | count = get_number (&args); | |
816338b5 | 14303 | |
48649e1b TT |
14304 | map_breakpoint_numbers |
14305 | (args, [&] (breakpoint *b) | |
14306 | { | |
14307 | iterate_over_related_breakpoints | |
14308 | (b, [&] (breakpoint *bpt) | |
14309 | { | |
14310 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14311 | }); | |
14312 | }); | |
c906108c SS |
14313 | } |
14314 | ||
c906108c | 14315 | static void |
4495129a | 14316 | enable_delete_command (const char *args, int from_tty) |
c906108c | 14317 | { |
48649e1b TT |
14318 | map_breakpoint_numbers |
14319 | (args, [&] (breakpoint *b) | |
14320 | { | |
14321 | iterate_over_related_breakpoints | |
14322 | (b, [&] (breakpoint *bpt) | |
14323 | { | |
14324 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14325 | }); | |
14326 | }); | |
c906108c SS |
14327 | } |
14328 | \f | |
fa8d40ab | 14329 | static void |
981a3fb3 | 14330 | set_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14331 | { |
14332 | } | |
14333 | ||
14334 | static void | |
981a3fb3 | 14335 | show_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14336 | { |
14337 | } | |
14338 | ||
1f3b5d1b PP |
14339 | /* Invalidate last known value of any hardware watchpoint if |
14340 | the memory which that value represents has been written to by | |
14341 | GDB itself. */ | |
14342 | ||
14343 | static void | |
8de0566d YQ |
14344 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14345 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14346 | const bfd_byte *data) |
14347 | { | |
14348 | struct breakpoint *bp; | |
14349 | ||
14350 | ALL_BREAKPOINTS (bp) | |
14351 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14352 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14353 | { |
3a5c3e22 | 14354 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14355 | |
850645cf | 14356 | if (wp->val_valid && wp->val != nullptr) |
3a5c3e22 PA |
14357 | { |
14358 | struct bp_location *loc; | |
14359 | ||
14360 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14361 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14362 | && loc->address + loc->length > addr | |
14363 | && addr + len > loc->address) | |
14364 | { | |
3a5c3e22 | 14365 | wp->val = NULL; |
4c1d86d9 | 14366 | wp->val_valid = false; |
3a5c3e22 PA |
14367 | } |
14368 | } | |
1f3b5d1b PP |
14369 | } |
14370 | } | |
14371 | ||
8181d85f DJ |
14372 | /* Create and insert a breakpoint for software single step. */ |
14373 | ||
14374 | void | |
6c95b8df | 14375 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 14376 | const address_space *aspace, |
4a64f543 | 14377 | CORE_ADDR next_pc) |
8181d85f | 14378 | { |
7c16b83e PA |
14379 | struct thread_info *tp = inferior_thread (); |
14380 | struct symtab_and_line sal; | |
14381 | CORE_ADDR pc = next_pc; | |
8181d85f | 14382 | |
34b7e8a6 PA |
14383 | if (tp->control.single_step_breakpoints == NULL) |
14384 | { | |
14385 | tp->control.single_step_breakpoints | |
5d5658a1 | 14386 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14387 | } |
8181d85f | 14388 | |
7c16b83e PA |
14389 | sal = find_pc_line (pc, 0); |
14390 | sal.pc = pc; | |
14391 | sal.section = find_pc_overlay (pc); | |
14392 | sal.explicit_pc = 1; | |
34b7e8a6 | 14393 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14394 | |
7c16b83e | 14395 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14396 | } |
14397 | ||
93f9a11f YQ |
14398 | /* Insert single step breakpoints according to the current state. */ |
14399 | ||
14400 | int | |
14401 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14402 | { | |
f5ea389a | 14403 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14404 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14405 | |
f5ea389a | 14406 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14407 | |
a0ff9e1a | 14408 | if (!next_pcs.empty ()) |
93f9a11f | 14409 | { |
f5ea389a | 14410 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 14411 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 14412 | |
a0ff9e1a | 14413 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14414 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14415 | ||
93f9a11f YQ |
14416 | return 1; |
14417 | } | |
14418 | else | |
14419 | return 0; | |
14420 | } | |
14421 | ||
34b7e8a6 | 14422 | /* See breakpoint.h. */ |
f02253f1 HZ |
14423 | |
14424 | int | |
7c16b83e | 14425 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 14426 | const address_space *aspace, |
7c16b83e | 14427 | CORE_ADDR pc) |
1aafd4da | 14428 | { |
7c16b83e | 14429 | struct bp_location *loc; |
1aafd4da | 14430 | |
7c16b83e PA |
14431 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14432 | if (loc->inserted | |
14433 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14434 | return 1; | |
1aafd4da | 14435 | |
7c16b83e | 14436 | return 0; |
ef370185 JB |
14437 | } |
14438 | ||
14439 | /* Check whether a software single-step breakpoint is inserted at | |
14440 | PC. */ | |
14441 | ||
14442 | int | |
accd0bcd | 14443 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
14444 | CORE_ADDR pc) |
14445 | { | |
34b7e8a6 PA |
14446 | struct breakpoint *bpt; |
14447 | ||
14448 | ALL_BREAKPOINTS (bpt) | |
14449 | { | |
14450 | if (bpt->type == bp_single_step | |
14451 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14452 | return 1; | |
14453 | } | |
14454 | return 0; | |
1aafd4da UW |
14455 | } |
14456 | ||
1042e4c0 SS |
14457 | /* Tracepoint-specific operations. */ |
14458 | ||
14459 | /* Set tracepoint count to NUM. */ | |
14460 | static void | |
14461 | set_tracepoint_count (int num) | |
14462 | { | |
14463 | tracepoint_count = num; | |
4fa62494 | 14464 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14465 | } |
14466 | ||
70221824 | 14467 | static void |
0b39b52e | 14468 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 14469 | { |
55aa24fb | 14470 | struct breakpoint_ops *ops; |
55aa24fb | 14471 | |
ffc2605c TT |
14472 | event_location_up location = string_to_event_location (&arg, |
14473 | current_language); | |
5b56227b | 14474 | if (location != NULL |
ffc2605c | 14475 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
14476 | ops = &tracepoint_probe_breakpoint_ops; |
14477 | else | |
14478 | ops = &tracepoint_breakpoint_ops; | |
14479 | ||
558a9d82 | 14480 | create_breakpoint (get_current_arch (), |
ffc2605c | 14481 | location.get (), |
f00aae0f | 14482 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14483 | 0 /* tempflag */, |
14484 | bp_tracepoint /* type_wanted */, | |
14485 | 0 /* Ignore count */, | |
14486 | pending_break_support, | |
14487 | ops, | |
14488 | from_tty, | |
14489 | 1 /* enabled */, | |
14490 | 0 /* internal */, 0); | |
1042e4c0 SS |
14491 | } |
14492 | ||
70221824 | 14493 | static void |
0b39b52e | 14494 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 14495 | { |
ffc2605c TT |
14496 | event_location_up location = string_to_event_location (&arg, |
14497 | current_language); | |
558a9d82 | 14498 | create_breakpoint (get_current_arch (), |
ffc2605c | 14499 | location.get (), |
f00aae0f | 14500 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14501 | 0 /* tempflag */, |
14502 | bp_fast_tracepoint /* type_wanted */, | |
14503 | 0 /* Ignore count */, | |
14504 | pending_break_support, | |
14505 | &tracepoint_breakpoint_ops, | |
14506 | from_tty, | |
14507 | 1 /* enabled */, | |
14508 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14509 | } |
14510 | ||
14511 | /* strace command implementation. Creates a static tracepoint. */ | |
14512 | ||
70221824 | 14513 | static void |
0b39b52e | 14514 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 14515 | { |
983af33b | 14516 | struct breakpoint_ops *ops; |
ffc2605c | 14517 | event_location_up location; |
983af33b SDJ |
14518 | |
14519 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14520 | or with a normal static tracepoint. */ | |
61012eef | 14521 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14522 | { |
14523 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 14524 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
f00aae0f | 14525 | } |
983af33b | 14526 | else |
f00aae0f KS |
14527 | { |
14528 | ops = &tracepoint_breakpoint_ops; | |
14529 | location = string_to_event_location (&arg, current_language); | |
14530 | } | |
983af33b | 14531 | |
558a9d82 | 14532 | create_breakpoint (get_current_arch (), |
ffc2605c | 14533 | location.get (), |
f00aae0f | 14534 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14535 | 0 /* tempflag */, |
14536 | bp_static_tracepoint /* type_wanted */, | |
14537 | 0 /* Ignore count */, | |
14538 | pending_break_support, | |
14539 | ops, | |
14540 | from_tty, | |
14541 | 1 /* enabled */, | |
14542 | 0 /* internal */, 0); | |
7a697b8d SS |
14543 | } |
14544 | ||
409873ef SS |
14545 | /* Set up a fake reader function that gets command lines from a linked |
14546 | list that was acquired during tracepoint uploading. */ | |
14547 | ||
14548 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14549 | static int next_cmd; |
409873ef SS |
14550 | |
14551 | static char * | |
14552 | read_uploaded_action (void) | |
14553 | { | |
a18ba4e4 | 14554 | char *rslt = nullptr; |
409873ef | 14555 | |
a18ba4e4 SM |
14556 | if (next_cmd < this_utp->cmd_strings.size ()) |
14557 | { | |
67aa1f3c | 14558 | rslt = this_utp->cmd_strings[next_cmd].get (); |
a18ba4e4 SM |
14559 | next_cmd++; |
14560 | } | |
409873ef SS |
14561 | |
14562 | return rslt; | |
14563 | } | |
14564 | ||
00bf0b85 SS |
14565 | /* Given information about a tracepoint as recorded on a target (which |
14566 | can be either a live system or a trace file), attempt to create an | |
14567 | equivalent GDB tracepoint. This is not a reliable process, since | |
14568 | the target does not necessarily have all the information used when | |
14569 | the tracepoint was originally defined. */ | |
14570 | ||
d9b3f62e | 14571 | struct tracepoint * |
00bf0b85 | 14572 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14573 | { |
f2fc3015 TT |
14574 | const char *addr_str; |
14575 | char small_buf[100]; | |
d9b3f62e | 14576 | struct tracepoint *tp; |
fd9b8c24 | 14577 | |
409873ef | 14578 | if (utp->at_string) |
67aa1f3c | 14579 | addr_str = utp->at_string.get (); |
409873ef SS |
14580 | else |
14581 | { | |
14582 | /* In the absence of a source location, fall back to raw | |
14583 | address. Since there is no way to confirm that the address | |
14584 | means the same thing as when the trace was started, warn the | |
14585 | user. */ | |
3e43a32a MS |
14586 | warning (_("Uploaded tracepoint %d has no " |
14587 | "source location, using raw address"), | |
409873ef | 14588 | utp->number); |
8c042590 | 14589 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14590 | addr_str = small_buf; |
14591 | } | |
14592 | ||
14593 | /* There's not much we can do with a sequence of bytecodes. */ | |
14594 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14595 | warning (_("Uploaded tracepoint %d condition " |
14596 | "has no source form, ignoring it"), | |
409873ef | 14597 | utp->number); |
d5551862 | 14598 | |
ffc2605c TT |
14599 | event_location_up location = string_to_event_location (&addr_str, |
14600 | current_language); | |
8cdf0e15 | 14601 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14602 | location.get (), |
67aa1f3c | 14603 | utp->cond_string.get (), -1, addr_str, |
e7e0cddf | 14604 | 0 /* parse cond/thread */, |
8cdf0e15 | 14605 | 0 /* tempflag */, |
0fb4aa4b | 14606 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14607 | 0 /* Ignore count */, |
14608 | pending_break_support, | |
348d480f | 14609 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14610 | 0 /* from_tty */, |
84f4c1fe | 14611 | utp->enabled /* enabled */, |
44f238bb PA |
14612 | 0 /* internal */, |
14613 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14614 | return NULL; |
fd9b8c24 | 14615 | |
409873ef | 14616 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14617 | tp = get_tracepoint (tracepoint_count); |
14618 | gdb_assert (tp != NULL); | |
d5551862 | 14619 | |
00bf0b85 SS |
14620 | if (utp->pass > 0) |
14621 | { | |
8c042590 | 14622 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14623 | tp->number); |
00bf0b85 | 14624 | |
409873ef | 14625 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14626 | } |
14627 | ||
409873ef SS |
14628 | /* If we have uploaded versions of the original commands, set up a |
14629 | special-purpose "reader" function and call the usual command line | |
14630 | reader, then pass the result to the breakpoint command-setting | |
14631 | function. */ | |
a18ba4e4 | 14632 | if (!utp->cmd_strings.empty ()) |
00bf0b85 | 14633 | { |
12973681 | 14634 | counted_command_line cmd_list; |
00bf0b85 | 14635 | |
409873ef | 14636 | this_utp = utp; |
3149d8c1 | 14637 | next_cmd = 0; |
d5551862 | 14638 | |
60b3cef2 | 14639 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
409873ef | 14640 | |
c1fc2657 | 14641 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14642 | } |
a18ba4e4 SM |
14643 | else if (!utp->actions.empty () |
14644 | || !utp->step_actions.empty ()) | |
3e43a32a MS |
14645 | warning (_("Uploaded tracepoint %d actions " |
14646 | "have no source form, ignoring them"), | |
409873ef | 14647 | utp->number); |
00bf0b85 | 14648 | |
f196051f | 14649 | /* Copy any status information that might be available. */ |
c1fc2657 | 14650 | tp->hit_count = utp->hit_count; |
f196051f SS |
14651 | tp->traceframe_usage = utp->traceframe_usage; |
14652 | ||
00bf0b85 | 14653 | return tp; |
d9b3f62e | 14654 | } |
00bf0b85 | 14655 | |
1042e4c0 SS |
14656 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14657 | omitted. */ | |
14658 | ||
14659 | static void | |
1d12d88f | 14660 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 14661 | { |
79a45e25 | 14662 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14663 | int num_printed; |
1042e4c0 | 14664 | |
5c458ae8 | 14665 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
d77f58be SS |
14666 | |
14667 | if (num_printed == 0) | |
1042e4c0 | 14668 | { |
e5a67952 | 14669 | if (args == NULL || *args == '\0') |
112e8700 | 14670 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14671 | else |
112e8700 | 14672 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14673 | } |
ad443146 SS |
14674 | |
14675 | default_collect_info (); | |
1042e4c0 SS |
14676 | } |
14677 | ||
4a64f543 | 14678 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14679 | Not supported by all targets. */ |
14680 | static void | |
5fed81ff | 14681 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14682 | { |
14683 | enable_command (args, from_tty); | |
14684 | } | |
14685 | ||
4a64f543 | 14686 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14687 | Not supported by all targets. */ |
14688 | static void | |
5fed81ff | 14689 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14690 | { |
14691 | disable_command (args, from_tty); | |
14692 | } | |
14693 | ||
4a64f543 | 14694 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 14695 | static void |
4495129a | 14696 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 14697 | { |
35df4500 | 14698 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14699 | |
14700 | dont_repeat (); | |
14701 | ||
14702 | if (arg == 0) | |
14703 | { | |
14704 | int breaks_to_delete = 0; | |
14705 | ||
14706 | /* Delete all breakpoints if no argument. | |
14707 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14708 | have to be deleted with an explicit breakpoint number |
14709 | argument. */ | |
1042e4c0 | 14710 | ALL_TRACEPOINTS (b) |
46c6471b | 14711 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14712 | { |
14713 | breaks_to_delete = 1; | |
14714 | break; | |
14715 | } | |
1042e4c0 SS |
14716 | |
14717 | /* Ask user only if there are some breakpoints to delete. */ | |
14718 | if (!from_tty | |
14719 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14720 | { | |
35df4500 | 14721 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14722 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14723 | delete_breakpoint (b); |
1042e4c0 SS |
14724 | } |
14725 | } | |
14726 | else | |
48649e1b | 14727 | map_breakpoint_numbers |
b926417a | 14728 | (arg, [&] (breakpoint *br) |
48649e1b | 14729 | { |
b926417a | 14730 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 14731 | }); |
1042e4c0 SS |
14732 | } |
14733 | ||
197f0a60 TT |
14734 | /* Helper function for trace_pass_command. */ |
14735 | ||
14736 | static void | |
d9b3f62e | 14737 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14738 | { |
d9b3f62e | 14739 | tp->pass_count = count; |
76727919 | 14740 | gdb::observers::breakpoint_modified.notify (tp); |
197f0a60 TT |
14741 | if (from_tty) |
14742 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 14743 | tp->number, count); |
197f0a60 TT |
14744 | } |
14745 | ||
1042e4c0 SS |
14746 | /* Set passcount for tracepoint. |
14747 | ||
14748 | First command argument is passcount, second is tracepoint number. | |
14749 | If tracepoint number omitted, apply to most recently defined. | |
14750 | Also accepts special argument "all". */ | |
14751 | ||
14752 | static void | |
0b39b52e | 14753 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 14754 | { |
d9b3f62e | 14755 | struct tracepoint *t1; |
0b39b52e | 14756 | ULONGEST count; |
1042e4c0 SS |
14757 | |
14758 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14759 | error (_("passcount command requires an " |
14760 | "argument (count + optional TP num)")); | |
1042e4c0 | 14761 | |
0b39b52e | 14762 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 14763 | |
529480d0 | 14764 | args = skip_spaces (args); |
1042e4c0 SS |
14765 | if (*args && strncasecmp (args, "all", 3) == 0) |
14766 | { | |
d9b3f62e PA |
14767 | struct breakpoint *b; |
14768 | ||
1042e4c0 | 14769 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
14770 | if (*args) |
14771 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 14772 | |
d9b3f62e | 14773 | ALL_TRACEPOINTS (b) |
197f0a60 | 14774 | { |
d9b3f62e | 14775 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
14776 | trace_pass_set_count (t1, count, from_tty); |
14777 | } | |
14778 | } | |
14779 | else if (*args == '\0') | |
1042e4c0 | 14780 | { |
5fa1d40e | 14781 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 14782 | if (t1) |
197f0a60 TT |
14783 | trace_pass_set_count (t1, count, from_tty); |
14784 | } | |
14785 | else | |
14786 | { | |
bfd28288 PA |
14787 | number_or_range_parser parser (args); |
14788 | while (!parser.finished ()) | |
1042e4c0 | 14789 | { |
bfd28288 | 14790 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
14791 | if (t1) |
14792 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14793 | } |
14794 | } | |
1042e4c0 SS |
14795 | } |
14796 | ||
d9b3f62e | 14797 | struct tracepoint * |
1042e4c0 SS |
14798 | get_tracepoint (int num) |
14799 | { | |
14800 | struct breakpoint *t; | |
14801 | ||
14802 | ALL_TRACEPOINTS (t) | |
14803 | if (t->number == num) | |
d9b3f62e | 14804 | return (struct tracepoint *) t; |
1042e4c0 SS |
14805 | |
14806 | return NULL; | |
14807 | } | |
14808 | ||
d5551862 SS |
14809 | /* Find the tracepoint with the given target-side number (which may be |
14810 | different from the tracepoint number after disconnecting and | |
14811 | reconnecting). */ | |
14812 | ||
d9b3f62e | 14813 | struct tracepoint * |
d5551862 SS |
14814 | get_tracepoint_by_number_on_target (int num) |
14815 | { | |
d9b3f62e | 14816 | struct breakpoint *b; |
d5551862 | 14817 | |
d9b3f62e PA |
14818 | ALL_TRACEPOINTS (b) |
14819 | { | |
14820 | struct tracepoint *t = (struct tracepoint *) b; | |
14821 | ||
14822 | if (t->number_on_target == num) | |
14823 | return t; | |
14824 | } | |
d5551862 SS |
14825 | |
14826 | return NULL; | |
14827 | } | |
14828 | ||
1042e4c0 | 14829 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 14830 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
14831 | If the argument is missing, the most recent tracepoint |
14832 | (tracepoint_count) is returned. */ | |
14833 | ||
d9b3f62e | 14834 | struct tracepoint * |
0b39b52e | 14835 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 14836 | number_or_range_parser *parser) |
1042e4c0 | 14837 | { |
1042e4c0 SS |
14838 | struct breakpoint *t; |
14839 | int tpnum; | |
0b39b52e | 14840 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 14841 | |
bfd28288 | 14842 | if (parser != NULL) |
197f0a60 | 14843 | { |
bfd28288 PA |
14844 | gdb_assert (!parser->finished ()); |
14845 | tpnum = parser->get_number (); | |
197f0a60 TT |
14846 | } |
14847 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 14848 | tpnum = tracepoint_count; |
1042e4c0 | 14849 | else |
197f0a60 | 14850 | tpnum = get_number (arg); |
1042e4c0 SS |
14851 | |
14852 | if (tpnum <= 0) | |
14853 | { | |
14854 | if (instring && *instring) | |
14855 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
14856 | instring); | |
14857 | else | |
5fa1d40e | 14858 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
14859 | return NULL; |
14860 | } | |
14861 | ||
14862 | ALL_TRACEPOINTS (t) | |
14863 | if (t->number == tpnum) | |
14864 | { | |
d9b3f62e | 14865 | return (struct tracepoint *) t; |
1042e4c0 SS |
14866 | } |
14867 | ||
1042e4c0 SS |
14868 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
14869 | return NULL; | |
14870 | } | |
14871 | ||
d9b3f62e PA |
14872 | void |
14873 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14874 | { | |
14875 | if (b->thread != -1) | |
14876 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
14877 | ||
14878 | if (b->task != 0) | |
14879 | fprintf_unfiltered (fp, " task %d", b->task); | |
14880 | ||
14881 | fprintf_unfiltered (fp, "\n"); | |
14882 | } | |
14883 | ||
6149aea9 PA |
14884 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14885 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14886 | on each breakpoint and only include the ones for which it returns | |
f2478a7e | 14887 | true. */ |
6149aea9 | 14888 | |
1042e4c0 | 14889 | static void |
4495129a | 14890 | save_breakpoints (const char *filename, int from_tty, |
f2478a7e | 14891 | bool (*filter) (const struct breakpoint *)) |
1042e4c0 SS |
14892 | { |
14893 | struct breakpoint *tp; | |
6149aea9 | 14894 | int any = 0; |
6149aea9 | 14895 | int extra_trace_bits = 0; |
1042e4c0 | 14896 | |
6149aea9 PA |
14897 | if (filename == 0 || *filename == 0) |
14898 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14899 | |
14900 | /* See if we have anything to save. */ | |
6149aea9 | 14901 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14902 | { |
6149aea9 | 14903 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14904 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
14905 | continue; |
14906 | ||
14907 | /* If we have a filter, only save the breakpoints it accepts. */ | |
14908 | if (filter && !filter (tp)) | |
14909 | continue; | |
14910 | ||
14911 | any = 1; | |
14912 | ||
14913 | if (is_tracepoint (tp)) | |
14914 | { | |
14915 | extra_trace_bits = 1; | |
14916 | ||
14917 | /* We can stop searching. */ | |
14918 | break; | |
14919 | } | |
1042e4c0 | 14920 | } |
6149aea9 PA |
14921 | |
14922 | if (!any) | |
1042e4c0 | 14923 | { |
6149aea9 | 14924 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14925 | return; |
14926 | } | |
14927 | ||
ee0c3293 | 14928 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
14929 | |
14930 | stdio_file fp; | |
14931 | ||
ee0c3293 | 14932 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 14933 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 14934 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 14935 | |
6149aea9 | 14936 | if (extra_trace_bits) |
d7e74731 | 14937 | save_trace_state_variables (&fp); |
8bf6485c | 14938 | |
6149aea9 | 14939 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14940 | { |
6149aea9 | 14941 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14942 | if (!user_breakpoint_p (tp)) |
6149aea9 | 14943 | continue; |
8bf6485c | 14944 | |
6149aea9 PA |
14945 | /* If we have a filter, only save the breakpoints it accepts. */ |
14946 | if (filter && !filter (tp)) | |
14947 | continue; | |
14948 | ||
d7e74731 | 14949 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 14950 | |
6149aea9 PA |
14951 | /* Note, we can't rely on tp->number for anything, as we can't |
14952 | assume the recreated breakpoint numbers will match. Use $bpnum | |
14953 | instead. */ | |
14954 | ||
14955 | if (tp->cond_string) | |
d7e74731 | 14956 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
14957 | |
14958 | if (tp->ignore_count) | |
d7e74731 | 14959 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 14960 | |
2d9442cc | 14961 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 14962 | { |
d7e74731 | 14963 | fp.puts (" commands\n"); |
a7bdde9e | 14964 | |
d7e74731 | 14965 | current_uiout->redirect (&fp); |
a70b8144 | 14966 | try |
1042e4c0 | 14967 | { |
d1b0a7bf | 14968 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 14969 | } |
230d2906 | 14970 | catch (const gdb_exception &ex) |
492d29ea | 14971 | { |
112e8700 | 14972 | current_uiout->redirect (NULL); |
eedc3f4f | 14973 | throw; |
492d29ea | 14974 | } |
1042e4c0 | 14975 | |
112e8700 | 14976 | current_uiout->redirect (NULL); |
d7e74731 | 14977 | fp.puts (" end\n"); |
1042e4c0 | 14978 | } |
6149aea9 PA |
14979 | |
14980 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 14981 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
14982 | |
14983 | /* If this is a multi-location breakpoint, check if the locations | |
14984 | should be individually disabled. Watchpoint locations are | |
14985 | special, and not user visible. */ | |
14986 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
14987 | { | |
14988 | struct bp_location *loc; | |
14989 | int n = 1; | |
14990 | ||
14991 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
14992 | if (!loc->enabled) | |
d7e74731 | 14993 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 14994 | } |
1042e4c0 | 14995 | } |
8bf6485c | 14996 | |
6149aea9 | 14997 | if (extra_trace_bits && *default_collect) |
d7e74731 | 14998 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 14999 | |
1042e4c0 | 15000 | if (from_tty) |
ee0c3293 | 15001 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15002 | } |
15003 | ||
15004 | /* The `save breakpoints' command. */ | |
15005 | ||
15006 | static void | |
4495129a | 15007 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
15008 | { |
15009 | save_breakpoints (args, from_tty, NULL); | |
15010 | } | |
15011 | ||
15012 | /* The `save tracepoints' command. */ | |
15013 | ||
15014 | static void | |
4495129a | 15015 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
15016 | { |
15017 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15018 | } |
15019 | ||
15020 | /* Create a vector of all tracepoints. */ | |
15021 | ||
f51e0e20 | 15022 | std::vector<breakpoint *> |
eeae04df | 15023 | all_tracepoints (void) |
1042e4c0 | 15024 | { |
f51e0e20 | 15025 | std::vector<breakpoint *> tp_vec; |
1042e4c0 SS |
15026 | struct breakpoint *tp; |
15027 | ||
15028 | ALL_TRACEPOINTS (tp) | |
15029 | { | |
f51e0e20 | 15030 | tp_vec.push_back (tp); |
1042e4c0 SS |
15031 | } |
15032 | ||
15033 | return tp_vec; | |
15034 | } | |
15035 | ||
c906108c | 15036 | \f |
629500fa KS |
15037 | /* This help string is used to consolidate all the help string for specifying |
15038 | locations used by several commands. */ | |
15039 | ||
15040 | #define LOCATION_HELP_STRING \ | |
15041 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15042 | source filename, function name, label name, and line number.\n\ | |
15043 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15044 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15045 | \"factorial.c:fact:the_top\".\n\ | |
15046 | \n\ | |
15047 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15048 | program. Example: To specify the fourth byte past the start function\n\ | |
15049 | \"main\", use \"*main + 4\".\n\ | |
15050 | \n\ | |
15051 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15052 | syntax to specify location parameters.\n\ | |
15053 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15054 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
15055 | -function fact -label the_top\".\n\ |
15056 | \n\ | |
15057 | By default, a specified function is matched against the program's\n\ | |
15058 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
15059 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
15060 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
15061 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
89549d7f | 15062 | specified name as a complete fully-qualified name instead." |
629500fa | 15063 | |
4a64f543 MS |
15064 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15065 | commands. It is defined as a macro to prevent duplication. | |
15066 | COMMAND should be a string constant containing the name of the | |
15067 | command. */ | |
629500fa | 15068 | |
31e2b00f | 15069 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15070 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15071 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15072 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15073 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15074 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15075 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15076 | below.\n\ | |
15077 | \n\ | |
dc10affe PA |
15078 | With no LOCATION, uses current execution address of the selected\n\ |
15079 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15080 | \n\ |
15081 | THREADNUM is the number from \"info threads\".\n\ | |
15082 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15083 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15084 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15085 | conditions are different.\n\ | |
31e2b00f AS |
15086 | \n\ |
15087 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15088 | ||
44feb3ce TT |
15089 | /* List of subcommands for "catch". */ |
15090 | static struct cmd_list_element *catch_cmdlist; | |
15091 | ||
15092 | /* List of subcommands for "tcatch". */ | |
15093 | static struct cmd_list_element *tcatch_cmdlist; | |
15094 | ||
9ac4176b | 15095 | void |
a121b7c1 | 15096 | add_catch_command (const char *name, const char *docstring, |
eb4c3f4a | 15097 | cmd_const_sfunc_ftype *sfunc, |
625e8578 | 15098 | completer_ftype *completer, |
44feb3ce TT |
15099 | void *user_data_catch, |
15100 | void *user_data_tcatch) | |
15101 | { | |
15102 | struct cmd_list_element *command; | |
15103 | ||
0450cc4c | 15104 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15105 | &catch_cmdlist); |
15106 | set_cmd_sfunc (command, sfunc); | |
15107 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15108 | set_cmd_completer (command, completer); |
44feb3ce | 15109 | |
0450cc4c | 15110 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15111 | &tcatch_cmdlist); |
15112 | set_cmd_sfunc (command, sfunc); | |
15113 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15114 | set_cmd_completer (command, completer); |
44feb3ce TT |
15115 | } |
15116 | ||
6149aea9 | 15117 | static void |
981a3fb3 | 15118 | save_command (const char *arg, int from_tty) |
6149aea9 | 15119 | { |
3e43a32a MS |
15120 | printf_unfiltered (_("\"save\" must be followed by " |
15121 | "the name of a save subcommand.\n")); | |
635c7e8a | 15122 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15123 | } |
15124 | ||
84f4c1fe | 15125 | struct breakpoint * |
95da600f | 15126 | iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback) |
84f4c1fe | 15127 | { |
35df4500 | 15128 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15129 | |
35df4500 | 15130 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe | 15131 | { |
95da600f | 15132 | if (callback (b)) |
84f4c1fe PM |
15133 | return b; |
15134 | } | |
15135 | ||
15136 | return NULL; | |
15137 | } | |
15138 | ||
0574c78f GB |
15139 | /* Zero if any of the breakpoint's locations could be a location where |
15140 | functions have been inlined, nonzero otherwise. */ | |
15141 | ||
15142 | static int | |
15143 | is_non_inline_function (struct breakpoint *b) | |
15144 | { | |
15145 | /* The shared library event breakpoint is set on the address of a | |
15146 | non-inline function. */ | |
15147 | if (b->type == bp_shlib_event) | |
15148 | return 1; | |
15149 | ||
15150 | return 0; | |
15151 | } | |
15152 | ||
15153 | /* Nonzero if the specified PC cannot be a location where functions | |
15154 | have been inlined. */ | |
15155 | ||
15156 | int | |
accd0bcd | 15157 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
09ac7c10 | 15158 | const struct target_waitstatus *ws) |
0574c78f GB |
15159 | { |
15160 | struct breakpoint *b; | |
15161 | struct bp_location *bl; | |
15162 | ||
15163 | ALL_BREAKPOINTS (b) | |
15164 | { | |
15165 | if (!is_non_inline_function (b)) | |
15166 | continue; | |
15167 | ||
15168 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15169 | { | |
15170 | if (!bl->shlib_disabled | |
09ac7c10 | 15171 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15172 | return 1; |
15173 | } | |
15174 | } | |
15175 | ||
15176 | return 0; | |
15177 | } | |
15178 | ||
2f202fde JK |
15179 | /* Remove any references to OBJFILE which is going to be freed. */ |
15180 | ||
15181 | void | |
15182 | breakpoint_free_objfile (struct objfile *objfile) | |
15183 | { | |
15184 | struct bp_location **locp, *loc; | |
15185 | ||
15186 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15187 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15188 | loc->symtab = NULL; |
15189 | } | |
15190 | ||
2060206e PA |
15191 | void |
15192 | initialize_breakpoint_ops (void) | |
15193 | { | |
15194 | static int initialized = 0; | |
15195 | ||
15196 | struct breakpoint_ops *ops; | |
15197 | ||
15198 | if (initialized) | |
15199 | return; | |
15200 | initialized = 1; | |
15201 | ||
15202 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15203 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15204 | internal and momentary breakpoints, etc.). */ | |
15205 | ops = &bkpt_base_breakpoint_ops; | |
15206 | *ops = base_breakpoint_ops; | |
15207 | ops->re_set = bkpt_re_set; | |
15208 | ops->insert_location = bkpt_insert_location; | |
15209 | ops->remove_location = bkpt_remove_location; | |
15210 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15211 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15212 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15213 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15214 | |
15215 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15216 | ops = &bkpt_breakpoint_ops; | |
15217 | *ops = bkpt_base_breakpoint_ops; | |
15218 | ops->re_set = bkpt_re_set; | |
15219 | ops->resources_needed = bkpt_resources_needed; | |
15220 | ops->print_it = bkpt_print_it; | |
15221 | ops->print_mention = bkpt_print_mention; | |
15222 | ops->print_recreate = bkpt_print_recreate; | |
15223 | ||
15224 | /* Ranged breakpoints. */ | |
15225 | ops = &ranged_breakpoint_ops; | |
15226 | *ops = bkpt_breakpoint_ops; | |
15227 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15228 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15229 | ops->print_it = print_it_ranged_breakpoint; | |
15230 | ops->print_one = print_one_ranged_breakpoint; | |
15231 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15232 | ops->print_mention = print_mention_ranged_breakpoint; | |
15233 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15234 | ||
15235 | /* Internal breakpoints. */ | |
15236 | ops = &internal_breakpoint_ops; | |
15237 | *ops = bkpt_base_breakpoint_ops; | |
15238 | ops->re_set = internal_bkpt_re_set; | |
15239 | ops->check_status = internal_bkpt_check_status; | |
15240 | ops->print_it = internal_bkpt_print_it; | |
15241 | ops->print_mention = internal_bkpt_print_mention; | |
15242 | ||
15243 | /* Momentary breakpoints. */ | |
15244 | ops = &momentary_breakpoint_ops; | |
15245 | *ops = bkpt_base_breakpoint_ops; | |
15246 | ops->re_set = momentary_bkpt_re_set; | |
15247 | ops->check_status = momentary_bkpt_check_status; | |
15248 | ops->print_it = momentary_bkpt_print_it; | |
15249 | ops->print_mention = momentary_bkpt_print_mention; | |
15250 | ||
55aa24fb SDJ |
15251 | /* Probe breakpoints. */ |
15252 | ops = &bkpt_probe_breakpoint_ops; | |
15253 | *ops = bkpt_breakpoint_ops; | |
15254 | ops->insert_location = bkpt_probe_insert_location; | |
15255 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15256 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15257 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15258 | |
2060206e PA |
15259 | /* Watchpoints. */ |
15260 | ops = &watchpoint_breakpoint_ops; | |
15261 | *ops = base_breakpoint_ops; | |
15262 | ops->re_set = re_set_watchpoint; | |
15263 | ops->insert_location = insert_watchpoint; | |
15264 | ops->remove_location = remove_watchpoint; | |
15265 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15266 | ops->check_status = check_status_watchpoint; | |
15267 | ops->resources_needed = resources_needed_watchpoint; | |
15268 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15269 | ops->print_it = print_it_watchpoint; | |
15270 | ops->print_mention = print_mention_watchpoint; | |
15271 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15272 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15273 | |
15274 | /* Masked watchpoints. */ | |
15275 | ops = &masked_watchpoint_breakpoint_ops; | |
15276 | *ops = watchpoint_breakpoint_ops; | |
15277 | ops->insert_location = insert_masked_watchpoint; | |
15278 | ops->remove_location = remove_masked_watchpoint; | |
15279 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15280 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15281 | ops->print_it = print_it_masked_watchpoint; | |
15282 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15283 | ops->print_mention = print_mention_masked_watchpoint; | |
15284 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15285 | ||
15286 | /* Tracepoints. */ | |
15287 | ops = &tracepoint_breakpoint_ops; | |
15288 | *ops = base_breakpoint_ops; | |
15289 | ops->re_set = tracepoint_re_set; | |
15290 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15291 | ops->print_one_detail = tracepoint_print_one_detail; | |
15292 | ops->print_mention = tracepoint_print_mention; | |
15293 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15294 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15295 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15296 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15297 | |
55aa24fb SDJ |
15298 | /* Probe tracepoints. */ |
15299 | ops = &tracepoint_probe_breakpoint_ops; | |
15300 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15301 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15302 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15303 | |
983af33b SDJ |
15304 | /* Static tracepoints with marker (`-m'). */ |
15305 | ops = &strace_marker_breakpoint_ops; | |
15306 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15307 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15308 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15309 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15310 | |
15311 | /* Fork catchpoints. */ | |
15312 | ops = &catch_fork_breakpoint_ops; | |
15313 | *ops = base_breakpoint_ops; | |
15314 | ops->insert_location = insert_catch_fork; | |
15315 | ops->remove_location = remove_catch_fork; | |
15316 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15317 | ops->print_it = print_it_catch_fork; | |
15318 | ops->print_one = print_one_catch_fork; | |
15319 | ops->print_mention = print_mention_catch_fork; | |
15320 | ops->print_recreate = print_recreate_catch_fork; | |
15321 | ||
15322 | /* Vfork catchpoints. */ | |
15323 | ops = &catch_vfork_breakpoint_ops; | |
15324 | *ops = base_breakpoint_ops; | |
15325 | ops->insert_location = insert_catch_vfork; | |
15326 | ops->remove_location = remove_catch_vfork; | |
15327 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15328 | ops->print_it = print_it_catch_vfork; | |
15329 | ops->print_one = print_one_catch_vfork; | |
15330 | ops->print_mention = print_mention_catch_vfork; | |
15331 | ops->print_recreate = print_recreate_catch_vfork; | |
15332 | ||
15333 | /* Exec catchpoints. */ | |
15334 | ops = &catch_exec_breakpoint_ops; | |
15335 | *ops = base_breakpoint_ops; | |
2060206e PA |
15336 | ops->insert_location = insert_catch_exec; |
15337 | ops->remove_location = remove_catch_exec; | |
15338 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15339 | ops->print_it = print_it_catch_exec; | |
15340 | ops->print_one = print_one_catch_exec; | |
15341 | ops->print_mention = print_mention_catch_exec; | |
15342 | ops->print_recreate = print_recreate_catch_exec; | |
15343 | ||
edcc5120 TT |
15344 | /* Solib-related catchpoints. */ |
15345 | ops = &catch_solib_breakpoint_ops; | |
15346 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15347 | ops->insert_location = insert_catch_solib; |
15348 | ops->remove_location = remove_catch_solib; | |
15349 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15350 | ops->check_status = check_status_catch_solib; | |
15351 | ops->print_it = print_it_catch_solib; | |
15352 | ops->print_one = print_one_catch_solib; | |
15353 | ops->print_mention = print_mention_catch_solib; | |
15354 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15355 | |
15356 | ops = &dprintf_breakpoint_ops; | |
15357 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15358 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15359 | ops->resources_needed = bkpt_resources_needed; |
15360 | ops->print_it = bkpt_print_it; | |
15361 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15362 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15363 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15364 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15365 | } |
15366 | ||
8bfd80db YQ |
15367 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15368 | ||
15369 | static struct cmd_list_element *enablebreaklist = NULL; | |
15370 | ||
8588b356 SM |
15371 | /* See breakpoint.h. */ |
15372 | ||
15373 | cmd_list_element *commands_cmd_element = nullptr; | |
15374 | ||
c906108c | 15375 | void |
fba45db2 | 15376 | _initialize_breakpoint (void) |
c906108c SS |
15377 | { |
15378 | struct cmd_list_element *c; | |
15379 | ||
2060206e PA |
15380 | initialize_breakpoint_ops (); |
15381 | ||
76727919 TT |
15382 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib); |
15383 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile); | |
15384 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change); | |
84acb35a | 15385 | |
c906108c SS |
15386 | breakpoint_chain = 0; |
15387 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15388 | before a breakpoint is set. */ | |
15389 | breakpoint_count = 0; | |
15390 | ||
1042e4c0 SS |
15391 | tracepoint_count = 0; |
15392 | ||
1bedd215 AC |
15393 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15394 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15395 | Usage is `ignore N COUNT'.")); | |
c906108c | 15396 | |
8588b356 SM |
15397 | commands_cmd_element = add_com ("commands", class_breakpoint, |
15398 | commands_command, _("\ | |
18da0c51 MG |
15399 | Set commands to be executed when the given breakpoints are hit.\n\ |
15400 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15401 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15402 | (e.g. `5-7').\n\ | |
c906108c SS |
15403 | With no argument, the targeted breakpoint is the last one set.\n\ |
15404 | The commands themselves follow starting on the next line.\n\ | |
15405 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15406 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15407 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15408 | |
d55637df | 15409 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15410 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15411 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15412 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15413 | set_cmd_completer (c, condition_completer); |
c906108c | 15414 | |
1bedd215 | 15415 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15416 | Set a temporary breakpoint.\n\ |
c906108c SS |
15417 | Like \"break\" except the breakpoint is only temporary,\n\ |
15418 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15419 | by using \"enable delete\" on the breakpoint number.\n\ |
15420 | \n" | |
15421 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15422 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15423 | |
1bedd215 | 15424 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15425 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15426 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15427 | some target hardware may not have this support.\n\ |
15428 | \n" | |
15429 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15430 | set_cmd_completer (c, location_completer); |
c906108c | 15431 | |
1bedd215 | 15432 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15433 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15434 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15435 | so it will be deleted when hit.\n\ |
15436 | \n" | |
15437 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15438 | set_cmd_completer (c, location_completer); |
c906108c | 15439 | |
1bedd215 | 15440 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
590042fc PW |
15441 | Enable all or some breakpoints.\n\ |
15442 | Usage: enable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15443 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15444 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15445 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15446 | With a subcommand you can enable temporarily."), |
c906108c | 15447 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15448 | |
15449 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15450 | ||
84951ab5 | 15451 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
590042fc PW |
15452 | Enable all or some breakpoints.\n\ |
15453 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15454 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15455 | This is used to cancel the effect of the \"disable\" command.\n\ | |
89549d7f | 15456 | May be abbreviated to simply \"enable\"."), |
c5aa993b | 15457 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15458 | |
1a966eab | 15459 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15460 | Enable some breakpoints for one hit.\n\ |
15461 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ | |
1a966eab | 15462 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
c906108c SS |
15463 | &enablebreaklist); |
15464 | ||
1a966eab | 15465 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15466 | Enable some breakpoints and delete when hit.\n\ |
15467 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ | |
1a966eab | 15468 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15469 | &enablebreaklist); |
15470 | ||
816338b5 | 15471 | add_cmd ("count", no_class, enable_count_command, _("\ |
590042fc PW |
15472 | Enable some breakpoints for COUNT hits.\n\ |
15473 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15474 | If a breakpoint is hit while enabled in this fashion,\n\ |
15475 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15476 | &enablebreaklist); | |
15477 | ||
1a966eab | 15478 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15479 | Enable some breakpoints and delete when hit.\n\ |
15480 | Usage: enable delete BREAKPOINTNUM...\n\ | |
1a966eab | 15481 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15482 | &enablelist); |
15483 | ||
1a966eab | 15484 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15485 | Enable some breakpoints for one hit.\n\ |
15486 | Usage: enable once BREAKPOINTNUM...\n\ | |
1a966eab | 15487 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
816338b5 SS |
15488 | &enablelist); |
15489 | ||
15490 | add_cmd ("count", no_class, enable_count_command, _("\ | |
590042fc PW |
15491 | Enable some breakpoints for COUNT hits.\n\ |
15492 | Usage: enable count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15493 | If a breakpoint is hit while enabled in this fashion,\n\ |
15494 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15495 | &enablelist); |
15496 | ||
1bedd215 | 15497 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
590042fc PW |
15498 | Disable all or some breakpoints.\n\ |
15499 | Usage: disable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15500 | Arguments are breakpoint numbers with spaces in between.\n\ |
15501 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15502 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15503 | &disablelist, "disable ", 1, &cmdlist); |
15504 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15505 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15506 | |
1a966eab | 15507 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
590042fc PW |
15508 | Disable all or some breakpoints.\n\ |
15509 | Usage: disable breakpoints [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.\n\ |
1a966eab | 15513 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15514 | &disablelist); |
15515 | ||
1bedd215 | 15516 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
590042fc PW |
15517 | Delete all or some breakpoints.\n\ |
15518 | Usage: delete [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15519 | Arguments are breakpoint numbers with spaces in between.\n\ |
15520 | To delete all breakpoints, give no argument.\n\ | |
15521 | \n\ | |
590042fc | 15522 | Also a prefix command for deletion of other GDB objects."), |
c906108c SS |
15523 | &deletelist, "delete ", 1, &cmdlist); |
15524 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15525 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15526 | |
1a966eab | 15527 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
590042fc PW |
15528 | Delete all or some breakpoints or auto-display expressions.\n\ |
15529 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15530 | Arguments are breakpoint numbers with spaces in between.\n\ |
15531 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15532 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15533 | &deletelist); |
15534 | ||
1bedd215 | 15535 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15536 | Clear breakpoint at specified location.\n\ |
15537 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15538 | \n\ |
15539 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa | 15540 | is executing in.\n" |
89549d7f | 15541 | "\n" LOCATION_HELP_STRING "\n\n\ |
1bedd215 | 15542 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15543 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15544 | |
1bedd215 | 15545 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15546 | Set breakpoint at specified location.\n" |
31e2b00f | 15547 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15548 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15549 | |
c906108c SS |
15550 | add_com_alias ("b", "break", class_run, 1); |
15551 | add_com_alias ("br", "break", class_run, 1); | |
15552 | add_com_alias ("bre", "break", class_run, 1); | |
15553 | add_com_alias ("brea", "break", class_run, 1); | |
15554 | ||
c906108c SS |
15555 | if (dbx_commands) |
15556 | { | |
1bedd215 AC |
15557 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15558 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15559 | &stoplist, "stop ", 1, &cmdlist); |
15560 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15561 | _("Break in function or address."), &stoplist); |
c5aa993b | 15562 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15563 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15564 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15565 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15566 | The \"Type\" column indicates one of:\n\ |
15567 | \tbreakpoint - normal breakpoint\n\ | |
15568 | \twatchpoint - watchpoint\n\ | |
15569 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15570 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15571 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15572 | address and file/line number respectively.\n\ |
15573 | \n\ | |
15574 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15575 | are set to the address of the last breakpoint listed unless the command\n\ |
15576 | is prefixed with \"server \".\n\n\ | |
c906108c | 15577 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15578 | breakpoint set.")); |
c906108c SS |
15579 | } |
15580 | ||
11db9430 | 15581 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15582 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15583 | The \"Type\" column indicates one of:\n\ |
15584 | \tbreakpoint - normal breakpoint\n\ | |
15585 | \twatchpoint - watchpoint\n\ | |
15586 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15587 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15588 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15589 | address and file/line number respectively.\n\ |
15590 | \n\ | |
15591 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15592 | are set to the address of the last breakpoint listed unless the command\n\ |
15593 | is prefixed with \"server \".\n\n\ | |
c906108c | 15594 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15595 | breakpoint set.")); |
c906108c | 15596 | |
6b04bdb7 MS |
15597 | add_info_alias ("b", "breakpoints", 1); |
15598 | ||
1a966eab AC |
15599 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15600 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15601 | The \"Type\" column indicates one of:\n\ |
15602 | \tbreakpoint - normal breakpoint\n\ | |
15603 | \twatchpoint - watchpoint\n\ | |
15604 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15605 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15606 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15607 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15608 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15609 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15610 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15611 | address and file/line number respectively.\n\ |
15612 | \n\ | |
15613 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15614 | are set to the address of the last breakpoint listed unless the command\n\ |
15615 | is prefixed with \"server \".\n\n\ | |
c906108c | 15616 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15617 | breakpoint set."), |
c906108c SS |
15618 | &maintenanceinfolist); |
15619 | ||
44feb3ce TT |
15620 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15621 | Set catchpoints to catch events."), | |
15622 | &catch_cmdlist, "catch ", | |
15623 | 0/*allow-unknown*/, &cmdlist); | |
15624 | ||
15625 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15626 | Set temporary catchpoints to catch events."), | |
15627 | &tcatch_cmdlist, "tcatch ", | |
15628 | 0/*allow-unknown*/, &cmdlist); | |
15629 | ||
44feb3ce TT |
15630 | add_catch_command ("fork", _("Catch calls to fork."), |
15631 | catch_fork_command_1, | |
a96d9b2e | 15632 | NULL, |
44feb3ce TT |
15633 | (void *) (uintptr_t) catch_fork_permanent, |
15634 | (void *) (uintptr_t) catch_fork_temporary); | |
15635 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15636 | catch_fork_command_1, | |
a96d9b2e | 15637 | NULL, |
44feb3ce TT |
15638 | (void *) (uintptr_t) catch_vfork_permanent, |
15639 | (void *) (uintptr_t) catch_vfork_temporary); | |
15640 | add_catch_command ("exec", _("Catch calls to exec."), | |
15641 | catch_exec_command_1, | |
a96d9b2e SDJ |
15642 | NULL, |
15643 | CATCH_PERMANENT, | |
15644 | CATCH_TEMPORARY); | |
edcc5120 TT |
15645 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15646 | Usage: catch load [REGEX]\n\ | |
15647 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15648 | catch_load_command_1, | |
15649 | NULL, | |
15650 | CATCH_PERMANENT, | |
15651 | CATCH_TEMPORARY); | |
15652 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15653 | Usage: catch unload [REGEX]\n\ | |
15654 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15655 | catch_unload_command_1, | |
15656 | NULL, | |
15657 | CATCH_PERMANENT, | |
15658 | CATCH_TEMPORARY); | |
c5aa993b | 15659 | |
1bedd215 AC |
15660 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15661 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15662 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15663 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15664 | an expression changes.\n\ |
15665 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15666 | the memory to which it refers.")); | |
65d12d83 | 15667 | set_cmd_completer (c, expression_completer); |
c906108c | 15668 | |
1bedd215 AC |
15669 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15670 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15671 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15672 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15673 | an expression is read.\n\ |
15674 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15675 | the memory to which it refers.")); | |
65d12d83 | 15676 | set_cmd_completer (c, expression_completer); |
c906108c | 15677 | |
1bedd215 AC |
15678 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15679 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15680 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15681 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15682 | an expression is either read or written.\n\ |
15683 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15684 | the memory to which it refers.")); | |
65d12d83 | 15685 | set_cmd_completer (c, expression_completer); |
c906108c | 15686 | |
11db9430 | 15687 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15688 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15689 | |
920d2a44 AC |
15690 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15691 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15692 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15693 | &can_use_hw_watchpoints, _("\ | |
15694 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15695 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15696 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15697 | such is available. (However, any hardware watchpoints that were\n\ | |
15698 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15699 | hardware.)"), |
15700 | NULL, | |
920d2a44 | 15701 | show_can_use_hw_watchpoints, |
85c07804 | 15702 | &setlist, &showlist); |
c906108c SS |
15703 | |
15704 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15705 | |
1042e4c0 SS |
15706 | /* Tracepoint manipulation commands. */ |
15707 | ||
15708 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 15709 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
15710 | \n" |
15711 | BREAK_ARGS_HELP ("trace") "\n\ | |
15712 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15713 | set_cmd_completer (c, location_completer); | |
15714 | ||
15715 | add_com_alias ("tp", "trace", class_alias, 0); | |
15716 | add_com_alias ("tr", "trace", class_alias, 1); | |
15717 | add_com_alias ("tra", "trace", class_alias, 1); | |
15718 | add_com_alias ("trac", "trace", class_alias, 1); | |
15719 | ||
7a697b8d | 15720 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 15721 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
15722 | \n" |
15723 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15724 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15725 | set_cmd_completer (c, location_completer); | |
15726 | ||
0fb4aa4b | 15727 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 15728 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
15729 | \n\ |
15730 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
15731 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
15732 | or -m MARKER_ID.\n\n\ | |
15733 | If a marker id is specified, probe the marker with that name. With\n\ | |
15734 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
15735 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
15736 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15737 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15738 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15739 | \n\ | |
15740 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15741 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15742 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15743 | conditions are different.\n\ | |
0fb4aa4b PA |
15744 | \n\ |
15745 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15746 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15747 | set_cmd_completer (c, location_completer); | |
15748 | ||
11db9430 | 15749 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 15750 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15751 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15752 | last tracepoint set.")); | |
15753 | ||
15754 | add_info_alias ("tp", "tracepoints", 1); | |
15755 | ||
15756 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
15757 | Delete specified tracepoints.\n\ | |
15758 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15759 | No argument means delete all tracepoints."), | |
15760 | &deletelist); | |
7e20dfcd | 15761 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
15762 | |
15763 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15764 | Disable specified tracepoints.\n\ | |
15765 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15766 | No argument means disable all tracepoints."), | |
15767 | &disablelist); | |
15768 | deprecate_cmd (c, "disable"); | |
15769 | ||
15770 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15771 | Enable specified tracepoints.\n\ | |
15772 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15773 | No argument means enable all tracepoints."), | |
15774 | &enablelist); | |
15775 | deprecate_cmd (c, "enable"); | |
15776 | ||
15777 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
15778 | Set the passcount for a tracepoint.\n\ | |
15779 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
15780 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
15781 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
15782 | ||
6149aea9 PA |
15783 | add_prefix_cmd ("save", class_breakpoint, save_command, |
15784 | _("Save breakpoint definitions as a script."), | |
15785 | &save_cmdlist, "save ", | |
15786 | 0/*allow-unknown*/, &cmdlist); | |
15787 | ||
15788 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
15789 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 15790 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
15791 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
15792 | session to restore them."), | |
15793 | &save_cmdlist); | |
15794 | set_cmd_completer (c, filename_completer); | |
15795 | ||
15796 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 15797 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
15798 | Use the 'source' command in another debug session to restore them."), |
15799 | &save_cmdlist); | |
1042e4c0 SS |
15800 | set_cmd_completer (c, filename_completer); |
15801 | ||
6149aea9 PA |
15802 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
15803 | deprecate_cmd (c, "save tracepoints"); | |
15804 | ||
1bedd215 | 15805 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
590042fc | 15806 | Breakpoint specific settings.\n\ |
fa8d40ab | 15807 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15808 | pending breakpoint behavior."), |
fa8d40ab JJ |
15809 | &breakpoint_set_cmdlist, "set breakpoint ", |
15810 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 15811 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
590042fc | 15812 | Breakpoint specific settings.\n\ |
fa8d40ab | 15813 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15814 | pending breakpoint behavior."), |
fa8d40ab JJ |
15815 | &breakpoint_show_cmdlist, "show breakpoint ", |
15816 | 0/*allow-unknown*/, &showlist); | |
15817 | ||
7915a72c AC |
15818 | add_setshow_auto_boolean_cmd ("pending", no_class, |
15819 | &pending_break_support, _("\ | |
15820 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
15821 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
15822 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
15823 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
15824 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 15825 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 15826 | NULL, |
920d2a44 | 15827 | show_pending_break_support, |
6e1d7d6c AC |
15828 | &breakpoint_set_cmdlist, |
15829 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
15830 | |
15831 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
15832 | |
15833 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
15834 | &automatic_hardware_breakpoints, _("\ | |
15835 | Set automatic usage of hardware breakpoints."), _("\ | |
15836 | Show automatic usage of hardware breakpoints."), _("\ | |
15837 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
15838 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
15839 | a warning will be emitted for such breakpoints."), | |
15840 | NULL, | |
15841 | show_automatic_hardware_breakpoints, | |
15842 | &breakpoint_set_cmdlist, | |
15843 | &breakpoint_show_cmdlist); | |
74960c60 | 15844 | |
a25a5a45 PA |
15845 | add_setshow_boolean_cmd ("always-inserted", class_support, |
15846 | &always_inserted_mode, _("\ | |
74960c60 VP |
15847 | Set mode for inserting breakpoints."), _("\ |
15848 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
15849 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
15850 | they're created, kept inserted even when execution stops, and removed\n\ | |
15851 | only when the user deletes them. When this mode is off (the default),\n\ | |
15852 | breakpoints are inserted only when execution continues, and removed\n\ | |
15853 | when execution stops."), | |
72d0e2c5 YQ |
15854 | NULL, |
15855 | &show_always_inserted_mode, | |
15856 | &breakpoint_set_cmdlist, | |
15857 | &breakpoint_show_cmdlist); | |
f1310107 | 15858 | |
b775012e LM |
15859 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
15860 | condition_evaluation_enums, | |
15861 | &condition_evaluation_mode_1, _("\ | |
15862 | Set mode of breakpoint condition evaluation."), _("\ | |
15863 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 15864 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
15865 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
15866 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
15867 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
15868 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
15869 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
15870 | be set to \"gdb\""), | |
15871 | &set_condition_evaluation_mode, | |
15872 | &show_condition_evaluation_mode, | |
15873 | &breakpoint_set_cmdlist, | |
15874 | &breakpoint_show_cmdlist); | |
15875 | ||
f1310107 TJB |
15876 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
15877 | Set a breakpoint for an address range.\n\ | |
15878 | break-range START-LOCATION, END-LOCATION\n\ | |
15879 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
15880 | LINENUM, for that line in the current file,\n\ | |
15881 | FILE:LINENUM, for that line in that file,\n\ | |
15882 | +OFFSET, for that number of lines after the current line\n\ | |
15883 | or the start of the range\n\ | |
15884 | FUNCTION, for the first line in that function,\n\ | |
15885 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
15886 | *ADDRESS, for the instruction at that address.\n\ | |
15887 | \n\ | |
15888 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
15889 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
15890 | range (including START-LOCATION and END-LOCATION).")); | |
15891 | ||
e7e0cddf | 15892 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 15893 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 15894 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
15895 | location may be a linespec, explicit, or address location.\n" |
15896 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
15897 | set_cmd_completer (c, location_completer); |
15898 | ||
15899 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
15900 | dprintf_style_enums, &dprintf_style, _("\ | |
15901 | Set the style of usage for dynamic printf."), _("\ | |
15902 | Show the style of usage for dynamic printf."), _("\ | |
15903 | This setting chooses how GDB will do a dynamic printf.\n\ | |
15904 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
15905 | console, as with the \"printf\" command.\n\ | |
15906 | If the value is \"call\", the print is done by calling a function in your\n\ | |
15907 | program; by default printf(), but you can choose a different function or\n\ | |
15908 | output stream by setting dprintf-function and dprintf-channel."), | |
15909 | update_dprintf_commands, NULL, | |
15910 | &setlist, &showlist); | |
15911 | ||
15912 | dprintf_function = xstrdup ("printf"); | |
15913 | add_setshow_string_cmd ("dprintf-function", class_support, | |
15914 | &dprintf_function, _("\ | |
590042fc PW |
15915 | Set the function to use for dynamic printf."), _("\ |
15916 | Show the function to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15917 | update_dprintf_commands, NULL, |
15918 | &setlist, &showlist); | |
15919 | ||
15920 | dprintf_channel = xstrdup (""); | |
15921 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
15922 | &dprintf_channel, _("\ | |
590042fc PW |
15923 | Set the channel to use for dynamic printf."), _("\ |
15924 | Show the channel to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15925 | update_dprintf_commands, NULL, |
15926 | &setlist, &showlist); | |
15927 | ||
d3ce09f5 SS |
15928 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
15929 | &disconnected_dprintf, _("\ | |
15930 | Set whether dprintf continues after GDB disconnects."), _("\ | |
15931 | Show whether dprintf continues after GDB disconnects."), _("\ | |
15932 | Use this to let dprintf commands continue to hit and produce output\n\ | |
15933 | even if GDB disconnects or detaches from the target."), | |
15934 | NULL, | |
15935 | NULL, | |
15936 | &setlist, &showlist); | |
15937 | ||
15938 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
590042fc PW |
15939 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
15940 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ | |
15941 | This supports most C printf format specifications, like %s, %d, etc.\n\ | |
15942 | This is useful for formatted output in user-defined commands.")); | |
d3ce09f5 | 15943 | |
491144b5 | 15944 | automatic_hardware_breakpoints = true; |
f3b1572e | 15945 | |
76727919 TT |
15946 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed); |
15947 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints); | |
c906108c | 15948 | } |