]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
b811d2c2 | 3 | Copyright (C) 1986-2020 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 | 91 | static void |
626d2320 | 92 | create_sals_from_location_default (struct event_location *location, |
f00aae0f KS |
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 | 106 | static std::vector<symtab_and_line> decode_location_default |
626d2320 | 107 | (struct breakpoint *b, struct event_location *location, |
6c5b2ebe | 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, | |
dda83cd7 | 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 | ||
7f32a4d5 PA |
147 | static int breakpoint_locations_match (struct bp_location *loc1, |
148 | struct bp_location *loc2, | |
149 | bool sw_hw_bps_match = false); | |
150 | ||
f1310107 | 151 | static int breakpoint_location_address_match (struct bp_location *bl, |
accd0bcd | 152 | const struct address_space *aspace, |
f1310107 TJB |
153 | CORE_ADDR addr); |
154 | ||
d35ae833 | 155 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
accd0bcd | 156 | const address_space *, |
d35ae833 PA |
157 | CORE_ADDR, int); |
158 | ||
834c0d03 | 159 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 160 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 161 | |
e514a9d6 | 162 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 163 | |
a14ed312 | 164 | static int hw_breakpoint_used_count (void); |
c906108c | 165 | |
a1398e0c PA |
166 | static int hw_watchpoint_use_count (struct breakpoint *); |
167 | ||
168 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
169 | enum bptype type, | |
170 | int *other_type_used); | |
c906108c | 171 | |
816338b5 SS |
172 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
173 | int count); | |
c906108c | 174 | |
fe3f5fa8 | 175 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
176 | static void incref_bp_location (struct bp_location *loc); |
177 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 178 | |
39d61571 | 179 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 180 | |
44702360 PA |
181 | /* update_global_location_list's modes of operation wrt to whether to |
182 | insert locations now. */ | |
183 | enum ugll_insert_mode | |
184 | { | |
185 | /* Don't insert any breakpoint locations into the inferior, only | |
186 | remove already-inserted locations that no longer should be | |
187 | inserted. Functions that delete a breakpoint or breakpoints | |
188 | should specify this mode, so that deleting a breakpoint doesn't | |
189 | have the side effect of inserting the locations of other | |
190 | breakpoints that are marked not-inserted, but should_be_inserted | |
191 | returns true on them. | |
192 | ||
193 | This behavior is useful is situations close to tear-down -- e.g., | |
194 | after an exec, while the target still has execution, but | |
195 | breakpoint shadows of the previous executable image should *NOT* | |
196 | be restored to the new image; or before detaching, where the | |
197 | target still has execution and wants to delete breakpoints from | |
198 | GDB's lists, and all breakpoints had already been removed from | |
199 | the inferior. */ | |
200 | UGLL_DONT_INSERT, | |
201 | ||
a25a5a45 PA |
202 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
203 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
204 | UGLL_MAY_INSERT, |
205 | ||
a25a5a45 PA |
206 | /* Insert locations now, irrespective of |
207 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
208 | stopped right now, and the user did "continue". We need to | |
209 | insert breakpoints _before_ resuming the target, but | |
210 | UGLL_MAY_INSERT wouldn't insert them, because | |
211 | breakpoints_should_be_inserted_now returns false at that point, | |
212 | as no thread is running yet. */ | |
04086b45 | 213 | UGLL_INSERT |
44702360 PA |
214 | }; |
215 | ||
216 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 217 | |
44702360 | 218 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 219 | |
74960c60 | 220 | static void insert_breakpoint_locations (void); |
a5606eee | 221 | |
0b39b52e | 222 | static void trace_pass_command (const char *, int); |
1042e4c0 | 223 | |
558a9d82 YQ |
224 | static void set_tracepoint_count (int num); |
225 | ||
f2478a7e | 226 | static bool is_masked_watchpoint (const struct breakpoint *b); |
9c06b0b4 | 227 | |
b775012e LM |
228 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
229 | ||
983af33b SDJ |
230 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
231 | otherwise. */ | |
232 | ||
233 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 234 | |
2060206e PA |
235 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
236 | that are implemented on top of software or hardware breakpoints | |
237 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
238 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
239 | ||
240 | /* Internal breakpoints class type. */ | |
06edf0c0 | 241 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
242 | |
243 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
244 | static struct breakpoint_ops momentary_breakpoint_ops; |
245 | ||
2060206e PA |
246 | /* The breakpoint_ops structure to be used in regular user created |
247 | breakpoints. */ | |
248 | struct breakpoint_ops bkpt_breakpoint_ops; | |
249 | ||
55aa24fb SDJ |
250 | /* Breakpoints set on probes. */ |
251 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
252 | ||
bac7c5cf GB |
253 | /* Tracepoints set on probes. */ |
254 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
255 | ||
e7e0cddf | 256 | /* Dynamic printf class type. */ |
c5867ab6 | 257 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 258 | |
d3ce09f5 SS |
259 | /* The style in which to perform a dynamic printf. This is a user |
260 | option because different output options have different tradeoffs; | |
261 | if GDB does the printing, there is better error handling if there | |
262 | is a problem with any of the arguments, but using an inferior | |
263 | function lets you have special-purpose printers and sending of | |
264 | output to the same place as compiled-in print functions. */ | |
265 | ||
266 | static const char dprintf_style_gdb[] = "gdb"; | |
267 | static const char dprintf_style_call[] = "call"; | |
268 | static const char dprintf_style_agent[] = "agent"; | |
269 | static const char *const dprintf_style_enums[] = { | |
270 | dprintf_style_gdb, | |
271 | dprintf_style_call, | |
272 | dprintf_style_agent, | |
273 | NULL | |
274 | }; | |
275 | static const char *dprintf_style = dprintf_style_gdb; | |
276 | ||
277 | /* The function to use for dynamic printf if the preferred style is to | |
278 | call into the inferior. The value is simply a string that is | |
279 | copied into the command, so it can be anything that GDB can | |
280 | evaluate to a callable address, not necessarily a function name. */ | |
281 | ||
bde6261a | 282 | static char *dprintf_function; |
d3ce09f5 SS |
283 | |
284 | /* The channel to use for dynamic printf if the preferred style is to | |
285 | call into the inferior; if a nonempty string, it will be passed to | |
286 | the call as the first argument, with the format string as the | |
287 | second. As with the dprintf function, this can be anything that | |
288 | GDB knows how to evaluate, so in addition to common choices like | |
289 | "stderr", this could be an app-specific expression like | |
290 | "mystreams[curlogger]". */ | |
291 | ||
bde6261a | 292 | static char *dprintf_channel; |
d3ce09f5 SS |
293 | |
294 | /* True if dprintf commands should continue to operate even if GDB | |
295 | has disconnected. */ | |
491144b5 | 296 | static bool disconnected_dprintf = true; |
d3ce09f5 | 297 | |
5cea2a26 PA |
298 | struct command_line * |
299 | breakpoint_commands (struct breakpoint *b) | |
300 | { | |
d1b0a7bf | 301 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 302 | } |
3daf8fe5 | 303 | |
f3b1572e PA |
304 | /* Flag indicating that a command has proceeded the inferior past the |
305 | current breakpoint. */ | |
306 | ||
491144b5 | 307 | static bool breakpoint_proceeded; |
f3b1572e | 308 | |
956a9fb9 | 309 | const char * |
2cec12e5 AR |
310 | bpdisp_text (enum bpdisp disp) |
311 | { | |
4a64f543 MS |
312 | /* NOTE: the following values are a part of MI protocol and |
313 | represent values of 'disp' field returned when inferior stops at | |
314 | a breakpoint. */ | |
bc043ef3 | 315 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 316 | |
2cec12e5 AR |
317 | return bpdisps[(int) disp]; |
318 | } | |
c906108c | 319 | |
4a64f543 | 320 | /* Prototypes for exported functions. */ |
c906108c | 321 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 322 | if such is available. */ |
c906108c SS |
323 | static int can_use_hw_watchpoints; |
324 | ||
920d2a44 AC |
325 | static void |
326 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
327 | struct cmd_list_element *c, | |
328 | const char *value) | |
329 | { | |
3e43a32a MS |
330 | fprintf_filtered (file, |
331 | _("Debugger's willingness to use " | |
332 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
333 | value); |
334 | } | |
335 | ||
fa8d40ab JJ |
336 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
337 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 338 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
339 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
340 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
341 | static void |
342 | show_pending_break_support (struct ui_file *file, int from_tty, | |
343 | struct cmd_list_element *c, | |
344 | const char *value) | |
345 | { | |
3e43a32a MS |
346 | fprintf_filtered (file, |
347 | _("Debugger's behavior regarding " | |
348 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
349 | value); |
350 | } | |
fa8d40ab | 351 | |
491144b5 | 352 | /* If true, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 353 | set with "break" but falling in read-only memory. |
491144b5 | 354 | If false, gdb will warn about such breakpoints, but won't automatically |
765dc015 | 355 | use hardware breakpoints. */ |
491144b5 | 356 | static bool automatic_hardware_breakpoints; |
765dc015 VP |
357 | static void |
358 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
359 | struct cmd_list_element *c, | |
360 | const char *value) | |
361 | { | |
3e43a32a MS |
362 | fprintf_filtered (file, |
363 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
364 | value); |
365 | } | |
366 | ||
a25a5a45 PA |
367 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
368 | stopped, and immediately inserts any new breakpoints as soon as | |
369 | they're created. If off (default), GDB keeps breakpoints off of | |
370 | the target as long as possible. That is, it delays inserting | |
371 | breakpoints until the next resume, and removes them again when the | |
372 | target fully stops. This is a bit safer in case GDB crashes while | |
373 | processing user input. */ | |
491144b5 | 374 | static bool always_inserted_mode = false; |
72d0e2c5 | 375 | |
33e5cbd6 | 376 | static void |
74960c60 | 377 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 378 | struct cmd_list_element *c, const char *value) |
74960c60 | 379 | { |
a25a5a45 PA |
380 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
381 | value); | |
74960c60 VP |
382 | } |
383 | ||
b57bacec PA |
384 | /* See breakpoint.h. */ |
385 | ||
33e5cbd6 | 386 | int |
a25a5a45 | 387 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 388 | { |
a25a5a45 PA |
389 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
390 | { | |
391 | /* If breakpoints are global, they should be inserted even if no | |
392 | thread under gdb's control is running, or even if there are | |
393 | no threads under GDB's control yet. */ | |
394 | return 1; | |
395 | } | |
5b6d1e4f | 396 | else |
a25a5a45 | 397 | { |
a25a5a45 PA |
398 | if (always_inserted_mode) |
399 | { | |
400 | /* The user wants breakpoints inserted even if all threads | |
401 | are stopped. */ | |
402 | return 1; | |
403 | } | |
404 | ||
5b6d1e4f PA |
405 | for (inferior *inf : all_inferiors ()) |
406 | if (inf->has_execution () | |
407 | && threads_are_executing (inf->process_target ())) | |
408 | return 1; | |
372316f1 PA |
409 | |
410 | /* Don't remove breakpoints yet if, even though all threads are | |
411 | stopped, we still have events to process. */ | |
08036331 | 412 | for (thread_info *tp : all_non_exited_threads ()) |
372316f1 PA |
413 | if (tp->resumed |
414 | && tp->suspend.waitstatus_pending_p) | |
415 | return 1; | |
a25a5a45 PA |
416 | } |
417 | return 0; | |
33e5cbd6 | 418 | } |
765dc015 | 419 | |
b775012e LM |
420 | static const char condition_evaluation_both[] = "host or target"; |
421 | ||
422 | /* Modes for breakpoint condition evaluation. */ | |
423 | static const char condition_evaluation_auto[] = "auto"; | |
424 | static const char condition_evaluation_host[] = "host"; | |
425 | static const char condition_evaluation_target[] = "target"; | |
426 | static const char *const condition_evaluation_enums[] = { | |
427 | condition_evaluation_auto, | |
428 | condition_evaluation_host, | |
429 | condition_evaluation_target, | |
430 | NULL | |
431 | }; | |
432 | ||
433 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
434 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
435 | ||
436 | /* Global that we use to display information to the user (gets its value from | |
437 | condition_evaluation_mode_1. */ | |
438 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
439 | ||
440 | /* Translate a condition evaluation mode MODE into either "host" | |
441 | or "target". This is used mostly to translate from "auto" to the | |
442 | real setting that is being used. It returns the translated | |
443 | evaluation mode. */ | |
444 | ||
445 | static const char * | |
446 | translate_condition_evaluation_mode (const char *mode) | |
447 | { | |
448 | if (mode == condition_evaluation_auto) | |
449 | { | |
450 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
451 | return condition_evaluation_target; | |
452 | else | |
453 | return condition_evaluation_host; | |
454 | } | |
455 | else | |
456 | return mode; | |
457 | } | |
458 | ||
459 | /* Discovers what condition_evaluation_auto translates to. */ | |
460 | ||
461 | static const char * | |
462 | breakpoint_condition_evaluation_mode (void) | |
463 | { | |
464 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
465 | } | |
466 | ||
467 | /* Return true if GDB should evaluate breakpoint conditions or false | |
468 | otherwise. */ | |
469 | ||
470 | static int | |
471 | gdb_evaluates_breakpoint_condition_p (void) | |
472 | { | |
473 | const char *mode = breakpoint_condition_evaluation_mode (); | |
474 | ||
475 | return (mode == condition_evaluation_host); | |
476 | } | |
477 | ||
c906108c SS |
478 | /* Are we executing breakpoint commands? */ |
479 | static int executing_breakpoint_commands; | |
480 | ||
c02f5703 MS |
481 | /* Are overlay event breakpoints enabled? */ |
482 | static int overlay_events_enabled; | |
483 | ||
e09342b5 | 484 | /* See description in breakpoint.h. */ |
491144b5 | 485 | bool target_exact_watchpoints = false; |
e09342b5 | 486 | |
c906108c | 487 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 488 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 489 | current breakpoint. */ |
c906108c | 490 | |
5c44784c | 491 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 492 | |
5c44784c JM |
493 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
494 | for (B = breakpoint_chain; \ | |
495 | B ? (TMP=B->next, 1): 0; \ | |
496 | B = TMP) | |
c906108c | 497 | |
4a64f543 MS |
498 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
499 | not provided so update_global_location_list must not be called | |
500 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 501 | |
876fa593 | 502 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
503 | for (BP_TMP = bp_locations; \ |
504 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 505 | BP_TMP++) |
7cc221ef | 506 | |
b775012e LM |
507 | /* Iterates through locations with address ADDRESS for the currently selected |
508 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
509 | to where the loop should start from. | |
510 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
511 | appropriate location to start with. */ | |
512 | ||
513 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
514 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
515 | BP_LOCP_TMP = BP_LOCP_START; \ | |
516 | BP_LOCP_START \ | |
f5336ca5 | 517 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
518 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
519 | BP_LOCP_TMP++) | |
520 | ||
1042e4c0 SS |
521 | /* Iterator for tracepoints only. */ |
522 | ||
523 | #define ALL_TRACEPOINTS(B) \ | |
524 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 525 | if (is_tracepoint (B)) |
1042e4c0 | 526 | |
7cc221ef | 527 | /* Chains of all breakpoints defined. */ |
c906108c | 528 | |
81e6b8eb | 529 | static struct breakpoint *breakpoint_chain; |
c906108c | 530 | |
39ef2f62 | 531 | /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ |
876fa593 | 532 | |
f5336ca5 | 533 | static struct bp_location **bp_locations; |
876fa593 | 534 | |
f5336ca5 | 535 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 536 | |
f5336ca5 | 537 | static unsigned bp_locations_count; |
876fa593 | 538 | |
4a64f543 | 539 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 540 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 541 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 542 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 543 | an address you need to read. */ |
876fa593 | 544 | |
f5336ca5 | 545 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 546 | |
4a64f543 MS |
547 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
548 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
549 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
550 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 551 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 552 | |
f5336ca5 | 553 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 554 | |
4a64f543 | 555 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
556 | from the bp_locations array, but for which a hit may still be |
557 | reported by a target. */ | |
1123588c | 558 | static std::vector<bp_location *> moribund_locations; |
20874c92 | 559 | |
c906108c SS |
560 | /* Number of last breakpoint made. */ |
561 | ||
95a42b64 TT |
562 | static int breakpoint_count; |
563 | ||
86b17b60 PA |
564 | /* The value of `breakpoint_count' before the last command that |
565 | created breakpoints. If the last (break-like) command created more | |
566 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
567 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
568 | static int prev_breakpoint_count; | |
c906108c | 569 | |
1042e4c0 SS |
570 | /* Number of last tracepoint made. */ |
571 | ||
95a42b64 | 572 | static int tracepoint_count; |
1042e4c0 | 573 | |
6149aea9 PA |
574 | static struct cmd_list_element *breakpoint_set_cmdlist; |
575 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 576 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 577 | |
badd37ce SDJ |
578 | /* See declaration at breakpoint.h. */ |
579 | ||
580 | struct breakpoint * | |
581 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
582 | void *user_data) | |
583 | { | |
584 | struct breakpoint *b = NULL; | |
585 | ||
586 | ALL_BREAKPOINTS (b) | |
587 | { | |
588 | if (func (b, user_data) != 0) | |
589 | break; | |
590 | } | |
591 | ||
592 | return b; | |
593 | } | |
594 | ||
468d015d JJ |
595 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
596 | static int | |
597 | breakpoint_enabled (struct breakpoint *b) | |
598 | { | |
0d381245 | 599 | return (b->enable_state == bp_enabled); |
468d015d JJ |
600 | } |
601 | ||
c906108c SS |
602 | /* Set breakpoint count to NUM. */ |
603 | ||
95a42b64 | 604 | static void |
fba45db2 | 605 | set_breakpoint_count (int num) |
c906108c | 606 | { |
86b17b60 | 607 | prev_breakpoint_count = breakpoint_count; |
c906108c | 608 | breakpoint_count = num; |
4fa62494 | 609 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
610 | } |
611 | ||
86b17b60 PA |
612 | /* Used by `start_rbreak_breakpoints' below, to record the current |
613 | breakpoint count before "rbreak" creates any breakpoint. */ | |
614 | static int rbreak_start_breakpoint_count; | |
615 | ||
95a42b64 TT |
616 | /* Called at the start an "rbreak" command to record the first |
617 | breakpoint made. */ | |
86b17b60 | 618 | |
c80049d3 | 619 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
95a42b64 | 620 | { |
86b17b60 | 621 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
622 | } |
623 | ||
624 | /* Called at the end of an "rbreak" command to record the last | |
625 | breakpoint made. */ | |
86b17b60 | 626 | |
c80049d3 | 627 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
95a42b64 | 628 | { |
86b17b60 | 629 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
630 | } |
631 | ||
4a64f543 | 632 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
633 | |
634 | void | |
fba45db2 | 635 | clear_breakpoint_hit_counts (void) |
c906108c SS |
636 | { |
637 | struct breakpoint *b; | |
638 | ||
639 | ALL_BREAKPOINTS (b) | |
640 | b->hit_count = 0; | |
641 | } | |
642 | ||
c906108c | 643 | \f |
48cb2d85 VP |
644 | /* Return the breakpoint with the specified number, or NULL |
645 | if the number does not refer to an existing breakpoint. */ | |
646 | ||
647 | struct breakpoint * | |
648 | get_breakpoint (int num) | |
649 | { | |
650 | struct breakpoint *b; | |
651 | ||
652 | ALL_BREAKPOINTS (b) | |
653 | if (b->number == num) | |
654 | return b; | |
655 | ||
656 | return NULL; | |
657 | } | |
5c44784c | 658 | |
c906108c | 659 | \f |
adc36818 | 660 | |
b775012e LM |
661 | /* Mark locations as "conditions have changed" in case the target supports |
662 | evaluating conditions on its side. */ | |
663 | ||
664 | static void | |
665 | mark_breakpoint_modified (struct breakpoint *b) | |
666 | { | |
667 | struct bp_location *loc; | |
668 | ||
669 | /* This is only meaningful if the target is | |
670 | evaluating conditions and if the user has | |
671 | opted for condition evaluation on the target's | |
672 | side. */ | |
673 | if (gdb_evaluates_breakpoint_condition_p () | |
674 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
675 | return; | |
676 | ||
677 | if (!is_breakpoint (b)) | |
678 | return; | |
679 | ||
680 | for (loc = b->loc; loc; loc = loc->next) | |
681 | loc->condition_changed = condition_modified; | |
682 | } | |
683 | ||
684 | /* Mark location as "conditions have changed" in case the target supports | |
685 | evaluating conditions on its side. */ | |
686 | ||
687 | static void | |
688 | mark_breakpoint_location_modified (struct bp_location *loc) | |
689 | { | |
690 | /* This is only meaningful if the target is | |
691 | evaluating conditions and if the user has | |
692 | opted for condition evaluation on the target's | |
693 | side. */ | |
694 | if (gdb_evaluates_breakpoint_condition_p () | |
695 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
696 | ||
697 | return; | |
698 | ||
699 | if (!is_breakpoint (loc->owner)) | |
700 | return; | |
701 | ||
702 | loc->condition_changed = condition_modified; | |
703 | } | |
704 | ||
705 | /* Sets the condition-evaluation mode using the static global | |
706 | condition_evaluation_mode. */ | |
707 | ||
708 | static void | |
eb4c3f4a | 709 | set_condition_evaluation_mode (const char *args, int from_tty, |
b775012e LM |
710 | struct cmd_list_element *c) |
711 | { | |
b775012e LM |
712 | const char *old_mode, *new_mode; |
713 | ||
714 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
715 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
716 | { | |
717 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
718 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
719 | "Using host evaluation mode instead.")); | |
720 | return; | |
721 | } | |
722 | ||
723 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
724 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
725 | ||
abf1152a JK |
726 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
727 | settings was "auto". */ | |
728 | condition_evaluation_mode = condition_evaluation_mode_1; | |
729 | ||
b775012e LM |
730 | /* Only update the mode if the user picked a different one. */ |
731 | if (new_mode != old_mode) | |
732 | { | |
733 | struct bp_location *loc, **loc_tmp; | |
734 | /* If the user switched to a different evaluation mode, we | |
735 | need to synch the changes with the target as follows: | |
736 | ||
737 | "host" -> "target": Send all (valid) conditions to the target. | |
738 | "target" -> "host": Remove all the conditions from the target. | |
739 | */ | |
740 | ||
b775012e LM |
741 | if (new_mode == condition_evaluation_target) |
742 | { | |
743 | /* Mark everything modified and synch conditions with the | |
744 | target. */ | |
745 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
746 | mark_breakpoint_location_modified (loc); | |
747 | } | |
748 | else | |
749 | { | |
750 | /* Manually mark non-duplicate locations to synch conditions | |
751 | with the target. We do this to remove all the conditions the | |
752 | target knows about. */ | |
753 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
754 | if (is_breakpoint (loc->owner) && loc->inserted) | |
755 | loc->needs_update = 1; | |
756 | } | |
757 | ||
758 | /* Do the update. */ | |
44702360 | 759 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
760 | } |
761 | ||
762 | return; | |
763 | } | |
764 | ||
765 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
766 | what "auto" is translating to. */ | |
767 | ||
768 | static void | |
769 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
770 | struct cmd_list_element *c, const char *value) | |
771 | { | |
772 | if (condition_evaluation_mode == condition_evaluation_auto) | |
773 | fprintf_filtered (file, | |
774 | _("Breakpoint condition evaluation " | |
775 | "mode is %s (currently %s).\n"), | |
776 | value, | |
777 | breakpoint_condition_evaluation_mode ()); | |
778 | else | |
779 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
780 | value); | |
781 | } | |
782 | ||
783 | /* A comparison function for bp_location AP and BP that is used by | |
784 | bsearch. This comparison function only cares about addresses, unlike | |
39ef2f62 | 785 | the more general bp_location_is_less_than function. */ |
b775012e LM |
786 | |
787 | static int | |
f5336ca5 | 788 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 789 | { |
9a3c8263 SM |
790 | const struct bp_location *a = *(const struct bp_location **) ap; |
791 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
792 | |
793 | if (a->address == b->address) | |
794 | return 0; | |
795 | else | |
796 | return ((a->address > b->address) - (a->address < b->address)); | |
797 | } | |
798 | ||
799 | /* Helper function to skip all bp_locations with addresses | |
800 | less than ADDRESS. It returns the first bp_location that | |
801 | is greater than or equal to ADDRESS. If none is found, just | |
802 | return NULL. */ | |
803 | ||
804 | static struct bp_location ** | |
805 | get_first_locp_gte_addr (CORE_ADDR address) | |
806 | { | |
807 | struct bp_location dummy_loc; | |
808 | struct bp_location *dummy_locp = &dummy_loc; | |
809 | struct bp_location **locp_found = NULL; | |
810 | ||
811 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
812 | dummy_loc.address = address; |
813 | ||
814 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 815 | locp_found = ((struct bp_location **) |
f5336ca5 | 816 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 817 | sizeof (struct bp_location **), |
f5336ca5 | 818 | bp_locations_compare_addrs)); |
b775012e LM |
819 | |
820 | /* Nothing was found, nothing left to do. */ | |
821 | if (locp_found == NULL) | |
822 | return NULL; | |
823 | ||
824 | /* We may have found a location that is at ADDRESS but is not the first in the | |
825 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 826 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
827 | && (*(locp_found - 1))->address == address) |
828 | locp_found--; | |
829 | ||
830 | return locp_found; | |
831 | } | |
832 | ||
b5fa468f TBA |
833 | /* Parse COND_STRING in the context of LOC and set as the condition |
834 | expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is | |
835 | the number of LOC within its owner. In case of parsing error, mark | |
836 | LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */ | |
837 | ||
838 | static void | |
839 | set_breakpoint_location_condition (const char *cond_string, bp_location *loc, | |
840 | int bp_num, int loc_num) | |
841 | { | |
842 | bool has_junk = false; | |
843 | try | |
844 | { | |
845 | expression_up new_exp = parse_exp_1 (&cond_string, loc->address, | |
846 | block_for_pc (loc->address), 0); | |
847 | if (*cond_string != 0) | |
848 | has_junk = true; | |
849 | else | |
850 | { | |
851 | loc->cond = std::move (new_exp); | |
852 | if (loc->disabled_by_cond && loc->enabled) | |
853 | printf_filtered (_("Breakpoint %d's condition is now valid at " | |
854 | "location %d, enabling.\n"), | |
855 | bp_num, loc_num); | |
856 | ||
857 | loc->disabled_by_cond = false; | |
858 | } | |
859 | } | |
860 | catch (const gdb_exception_error &e) | |
861 | { | |
862 | if (loc->enabled) | |
863 | { | |
864 | /* Warn if a user-enabled location is now becoming disabled-by-cond. | |
865 | BP_NUM is 0 if the breakpoint is being defined for the first | |
866 | time using the "break ... if ..." command, and non-zero if | |
867 | already defined. */ | |
868 | if (bp_num != 0) | |
869 | warning (_("failed to validate condition at location %d.%d, " | |
870 | "disabling:\n %s"), bp_num, loc_num, e.what ()); | |
871 | else | |
872 | warning (_("failed to validate condition at location %d, " | |
873 | "disabling:\n %s"), loc_num, e.what ()); | |
874 | } | |
875 | ||
876 | loc->disabled_by_cond = true; | |
877 | } | |
878 | ||
879 | if (has_junk) | |
880 | error (_("Garbage '%s' follows condition"), cond_string); | |
881 | } | |
882 | ||
adc36818 | 883 | void |
7a26bd4d | 884 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
733d554a | 885 | int from_tty, bool force) |
adc36818 | 886 | { |
4c55e970 | 887 | if (*exp == 0) |
3a5c3e22 | 888 | { |
4c55e970 TBA |
889 | xfree (b->cond_string); |
890 | b->cond_string = nullptr; | |
3a5c3e22 | 891 | |
4c55e970 | 892 | if (is_watchpoint (b)) |
78319c15 | 893 | static_cast<watchpoint *> (b)->cond_exp.reset (); |
4c55e970 TBA |
894 | else |
895 | { | |
b5fa468f | 896 | int loc_num = 1; |
78319c15 | 897 | for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) |
4c55e970 TBA |
898 | { |
899 | loc->cond.reset (); | |
b5fa468f TBA |
900 | if (loc->disabled_by_cond && loc->enabled) |
901 | printf_filtered (_("Breakpoint %d's condition is now valid at " | |
902 | "location %d, enabling.\n"), | |
903 | b->number, loc_num); | |
904 | loc->disabled_by_cond = false; | |
905 | loc_num++; | |
4c55e970 TBA |
906 | |
907 | /* No need to free the condition agent expression | |
908 | bytecode (if we have one). We will handle this | |
909 | when we go through update_global_location_list. */ | |
910 | } | |
911 | } | |
1e620590 | 912 | |
adc36818 PM |
913 | if (from_tty) |
914 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
915 | } | |
916 | else | |
917 | { | |
adc36818 PM |
918 | if (is_watchpoint (b)) |
919 | { | |
699bd4cf | 920 | innermost_block_tracker tracker; |
78319c15 | 921 | const char *arg = exp; |
4c55e970 | 922 | expression_up new_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
78319c15 | 923 | if (*arg != 0) |
adc36818 | 924 | error (_("Junk at end of expression")); |
78319c15 | 925 | watchpoint *w = static_cast<watchpoint *> (b); |
4c55e970 | 926 | w->cond_exp = std::move (new_exp); |
699bd4cf | 927 | w->cond_exp_valid_block = tracker.block (); |
adc36818 PM |
928 | } |
929 | else | |
930 | { | |
4c55e970 TBA |
931 | /* Parse and set condition expressions. We make two passes. |
932 | In the first, we parse the condition string to see if it | |
b5fa468f TBA |
933 | is valid in at least one location. If so, the condition |
934 | would be accepted. So we go ahead and set the locations' | |
935 | conditions. In case no valid case is found, we throw | |
4c55e970 TBA |
936 | the error and the condition string will be rejected. |
937 | This two-pass approach is taken to avoid setting the | |
938 | state of locations in case of a reject. */ | |
78319c15 | 939 | for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) |
4c55e970 | 940 | { |
b5fa468f TBA |
941 | try |
942 | { | |
943 | const char *arg = exp; | |
944 | parse_exp_1 (&arg, loc->address, | |
945 | block_for_pc (loc->address), 0); | |
946 | if (*arg != 0) | |
947 | error (_("Junk at end of expression")); | |
948 | break; | |
949 | } | |
950 | catch (const gdb_exception_error &e) | |
951 | { | |
952 | /* Condition string is invalid. If this happens to | |
733d554a TBA |
953 | be the last loc, abandon (if not forced) or continue |
954 | (if forced). */ | |
955 | if (loc->next == nullptr && !force) | |
b5fa468f TBA |
956 | throw; |
957 | } | |
4c55e970 TBA |
958 | } |
959 | ||
b5fa468f | 960 | /* If we reach here, the condition is valid at some locations. */ |
dda83cd7 SM |
961 | int loc_num = 1; |
962 | for (bp_location *loc = b->loc; loc != nullptr; | |
963 | loc = loc->next, loc_num++) | |
964 | set_breakpoint_location_condition (exp, loc, b->number, loc_num); | |
adc36818 | 965 | } |
1e620590 TBA |
966 | |
967 | /* We know that the new condition parsed successfully. The | |
968 | condition string of the breakpoint can be safely updated. */ | |
969 | xfree (b->cond_string); | |
970 | b->cond_string = xstrdup (exp); | |
971 | b->condition_not_parsed = 0; | |
adc36818 | 972 | } |
b775012e LM |
973 | mark_breakpoint_modified (b); |
974 | ||
76727919 | 975 | gdb::observers::breakpoint_modified.notify (b); |
adc36818 PM |
976 | } |
977 | ||
b1d4d8d1 TBA |
978 | /* The options for the "condition" command. */ |
979 | ||
980 | struct condition_command_opts | |
981 | { | |
982 | /* For "-force". */ | |
983 | bool force_condition = false; | |
984 | }; | |
985 | ||
986 | static const gdb::option::option_def condition_command_option_defs[] = { | |
987 | ||
988 | gdb::option::flag_option_def<condition_command_opts> { | |
989 | "force", | |
990 | [] (condition_command_opts *opts) { return &opts->force_condition; }, | |
991 | N_("Set the condition even if it is invalid for all current locations."), | |
992 | }, | |
993 | ||
994 | }; | |
995 | ||
996 | /* Create an option_def_group for the "condition" options, with | |
997 | CC_OPTS as context. */ | |
998 | ||
999 | static inline gdb::option::option_def_group | |
1000 | make_condition_command_options_def_group (condition_command_opts *cc_opts) | |
1001 | { | |
1002 | return {{condition_command_option_defs}, cc_opts}; | |
1003 | } | |
1004 | ||
d55637df TT |
1005 | /* Completion for the "condition" command. */ |
1006 | ||
eb3ff9a5 | 1007 | static void |
6f937416 | 1008 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 1009 | completion_tracker &tracker, |
b1d4d8d1 | 1010 | const char *text, const char * /*word*/) |
d55637df | 1011 | { |
b1d4d8d1 TBA |
1012 | bool has_no_arguments = (*text == '\0'); |
1013 | condition_command_opts cc_opts; | |
1014 | const auto group = make_condition_command_options_def_group (&cc_opts); | |
1015 | if (gdb::option::complete_options | |
1016 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group)) | |
1017 | return; | |
d55637df | 1018 | |
f1735a53 | 1019 | text = skip_spaces (text); |
b1d4d8d1 | 1020 | const char *space = skip_to_space (text); |
d55637df TT |
1021 | if (*space == '\0') |
1022 | { | |
1023 | int len; | |
1024 | struct breakpoint *b; | |
d55637df TT |
1025 | |
1026 | if (text[0] == '$') | |
1027 | { | |
b1d4d8d1 | 1028 | tracker.advance_custom_word_point_by (1); |
d55637df | 1029 | /* We don't support completion of history indices. */ |
eb3ff9a5 PA |
1030 | if (!isdigit (text[1])) |
1031 | complete_internalvar (tracker, &text[1]); | |
1032 | return; | |
d55637df TT |
1033 | } |
1034 | ||
b1d4d8d1 TBA |
1035 | /* Suggest the "-force" flag if no arguments are given. If |
1036 | arguments were passed, they either already include the flag, | |
1037 | or we are beyond the point of suggesting it because it's | |
1038 | positionally the first argument. */ | |
1039 | if (has_no_arguments) | |
1040 | gdb::option::complete_on_all_options (tracker, group); | |
1041 | ||
d55637df TT |
1042 | /* We're completing the breakpoint number. */ |
1043 | len = strlen (text); | |
1044 | ||
1045 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1046 | { |
1047 | char number[50]; | |
1048 | ||
1049 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1050 | ||
1051 | if (strncmp (number, text, len) == 0) | |
b02f78f9 | 1052 | tracker.add_completion (make_unique_xstrdup (number)); |
58ce7251 | 1053 | } |
d55637df | 1054 | |
eb3ff9a5 | 1055 | return; |
d55637df TT |
1056 | } |
1057 | ||
b1d4d8d1 TBA |
1058 | /* We're completing the expression part. Skip the breakpoint num. */ |
1059 | const char *exp_start = skip_spaces (space); | |
1060 | tracker.advance_custom_word_point_by (exp_start - text); | |
1061 | text = exp_start; | |
1062 | const char *word = advance_to_expression_complete_word_point (tracker, text); | |
eb3ff9a5 | 1063 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
1064 | } |
1065 | ||
c906108c SS |
1066 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1067 | ||
1068 | static void | |
0b39b52e | 1069 | condition_command (const char *arg, int from_tty) |
c906108c | 1070 | { |
52f0bd74 | 1071 | struct breakpoint *b; |
0b39b52e | 1072 | const char *p; |
52f0bd74 | 1073 | int bnum; |
c906108c SS |
1074 | |
1075 | if (arg == 0) | |
e2e0b3e5 | 1076 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1077 | |
1078 | p = arg; | |
733d554a TBA |
1079 | |
1080 | /* Check if the "-force" flag was passed. */ | |
b1d4d8d1 TBA |
1081 | condition_command_opts cc_opts; |
1082 | const auto group = make_condition_command_options_def_group (&cc_opts); | |
1083 | gdb::option::process_options | |
1084 | (&p, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group); | |
733d554a | 1085 | |
c906108c | 1086 | bnum = get_number (&p); |
5c44784c | 1087 | if (bnum == 0) |
8a3fe4f8 | 1088 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1089 | |
1090 | ALL_BREAKPOINTS (b) | |
1091 | if (b->number == bnum) | |
2f069f6f | 1092 | { |
6dddc817 DE |
1093 | /* Check if this breakpoint has a "stop" method implemented in an |
1094 | extension language. This method and conditions entered into GDB | |
1095 | from the CLI are mutually exclusive. */ | |
1096 | const struct extension_language_defn *extlang | |
1097 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1098 | ||
1099 | if (extlang != NULL) | |
1100 | { | |
1101 | error (_("Only one stop condition allowed. There is currently" | |
1102 | " a %s stop condition defined for this breakpoint."), | |
1103 | ext_lang_capitalized_name (extlang)); | |
1104 | } | |
b1d4d8d1 | 1105 | set_breakpoint_condition (b, p, from_tty, cc_opts.force_condition); |
b775012e LM |
1106 | |
1107 | if (is_breakpoint (b)) | |
44702360 | 1108 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1109 | |
2f069f6f JB |
1110 | return; |
1111 | } | |
c906108c | 1112 | |
8a3fe4f8 | 1113 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1114 | } |
1115 | ||
a7bdde9e VP |
1116 | /* Check that COMMAND do not contain commands that are suitable |
1117 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1118 | Throw if any such commands is found. */ |
1119 | ||
a7bdde9e VP |
1120 | static void |
1121 | check_no_tracepoint_commands (struct command_line *commands) | |
1122 | { | |
1123 | struct command_line *c; | |
cc59ec59 | 1124 | |
a7bdde9e VP |
1125 | for (c = commands; c; c = c->next) |
1126 | { | |
a7bdde9e | 1127 | if (c->control_type == while_stepping_control) |
3e43a32a MS |
1128 | error (_("The 'while-stepping' command can " |
1129 | "only be used for tracepoints")); | |
a7bdde9e | 1130 | |
12973681 TT |
1131 | check_no_tracepoint_commands (c->body_list_0.get ()); |
1132 | check_no_tracepoint_commands (c->body_list_1.get ()); | |
a7bdde9e VP |
1133 | |
1134 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1135 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1136 | command directly. */ |
1137 | if (strstr (c->line, "collect ") == c->line) | |
1138 | error (_("The 'collect' command can only be used for tracepoints")); | |
1139 | ||
51661e93 VP |
1140 | if (strstr (c->line, "teval ") == c->line) |
1141 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1142 | } |
1143 | } | |
1144 | ||
c1fc2657 | 1145 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1146 | { |
c1fc2657 | 1147 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1148 | }; |
1149 | ||
d77f58be SS |
1150 | /* Encapsulate tests for different types of tracepoints. */ |
1151 | ||
3b0871f4 SM |
1152 | static bool |
1153 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1154 | { |
1155 | return (type == bp_tracepoint | |
1156 | || type == bp_fast_tracepoint | |
1157 | || type == bp_static_tracepoint); | |
1158 | } | |
1159 | ||
3b0871f4 SM |
1160 | static bool |
1161 | is_longjmp_type (bptype type) | |
1162 | { | |
1163 | return type == bp_longjmp || type == bp_exception; | |
1164 | } | |
1165 | ||
f2478a7e SM |
1166 | /* See breakpoint.h. */ |
1167 | ||
1168 | bool | |
d77f58be | 1169 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1170 | { |
d9b3f62e | 1171 | return is_tracepoint_type (b->type); |
a7bdde9e | 1172 | } |
d9b3f62e | 1173 | |
a5e364af SM |
1174 | /* Factory function to create an appropriate instance of breakpoint given |
1175 | TYPE. */ | |
1176 | ||
1177 | static std::unique_ptr<breakpoint> | |
1178 | new_breakpoint_from_type (bptype type) | |
1179 | { | |
1180 | breakpoint *b; | |
1181 | ||
1182 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1183 | b = new tracepoint (); |
3b0871f4 | 1184 | else if (is_longjmp_type (type)) |
c1fc2657 | 1185 | b = new longjmp_breakpoint (); |
a5e364af SM |
1186 | else |
1187 | b = new breakpoint (); | |
1188 | ||
1189 | return std::unique_ptr<breakpoint> (b); | |
1190 | } | |
1191 | ||
e5dd4106 | 1192 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1193 | breakpoint. This function will throw an exception if a problem is |
1194 | found. */ | |
48cb2d85 | 1195 | |
95a42b64 TT |
1196 | static void |
1197 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1198 | struct command_line *commands) | |
48cb2d85 | 1199 | { |
d77f58be | 1200 | if (is_tracepoint (b)) |
a7bdde9e | 1201 | { |
c9a6ce02 | 1202 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1203 | struct command_line *c; |
1204 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1205 | |
1206 | /* Reset the while-stepping step count. The previous commands | |
dda83cd7 SM |
1207 | might have included a while-stepping action, while the new |
1208 | ones might not. */ | |
c9a6ce02 PA |
1209 | t->step_count = 0; |
1210 | ||
1211 | /* We need to verify that each top-level element of commands is | |
1212 | valid for tracepoints, that there's at most one | |
1213 | while-stepping element, and that the while-stepping's body | |
1214 | has valid tracing commands excluding nested while-stepping. | |
1215 | We also need to validate the tracepoint action line in the | |
1216 | context of the tracepoint --- validate_actionline actually | |
1217 | has side effects, like setting the tracepoint's | |
1218 | while-stepping STEP_COUNT, in addition to checking if the | |
1219 | collect/teval actions parse and make sense in the | |
1220 | tracepoint's context. */ | |
a7bdde9e VP |
1221 | for (c = commands; c; c = c->next) |
1222 | { | |
a7bdde9e VP |
1223 | if (c->control_type == while_stepping_control) |
1224 | { | |
1225 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1226 | error (_("The 'while-stepping' command " |
1227 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1228 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1229 | error (_("The 'while-stepping' command " |
1230 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1231 | |
1232 | if (while_stepping) | |
3e43a32a MS |
1233 | error (_("The 'while-stepping' command " |
1234 | "can be used only once")); | |
a7bdde9e VP |
1235 | else |
1236 | while_stepping = c; | |
1237 | } | |
c9a6ce02 PA |
1238 | |
1239 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1240 | } |
1241 | if (while_stepping) | |
1242 | { | |
1243 | struct command_line *c2; | |
1244 | ||
12973681 TT |
1245 | gdb_assert (while_stepping->body_list_1 == nullptr); |
1246 | c2 = while_stepping->body_list_0.get (); | |
a7bdde9e VP |
1247 | for (; c2; c2 = c2->next) |
1248 | { | |
a7bdde9e VP |
1249 | if (c2->control_type == while_stepping_control) |
1250 | error (_("The 'while-stepping' command cannot be nested")); | |
1251 | } | |
1252 | } | |
1253 | } | |
1254 | else | |
1255 | { | |
1256 | check_no_tracepoint_commands (commands); | |
1257 | } | |
95a42b64 TT |
1258 | } |
1259 | ||
0fb4aa4b PA |
1260 | /* Return a vector of all the static tracepoints set at ADDR. The |
1261 | caller is responsible for releasing the vector. */ | |
1262 | ||
f51e0e20 | 1263 | std::vector<breakpoint *> |
0fb4aa4b PA |
1264 | static_tracepoints_here (CORE_ADDR addr) |
1265 | { | |
1266 | struct breakpoint *b; | |
f51e0e20 | 1267 | std::vector<breakpoint *> found; |
0fb4aa4b PA |
1268 | struct bp_location *loc; |
1269 | ||
1270 | ALL_BREAKPOINTS (b) | |
1271 | if (b->type == bp_static_tracepoint) | |
1272 | { | |
1273 | for (loc = b->loc; loc; loc = loc->next) | |
1274 | if (loc->address == addr) | |
f51e0e20 | 1275 | found.push_back (b); |
0fb4aa4b PA |
1276 | } |
1277 | ||
1278 | return found; | |
1279 | } | |
1280 | ||
95a42b64 | 1281 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1282 | validate that only allowed commands are included. */ |
95a42b64 TT |
1283 | |
1284 | void | |
4a64f543 | 1285 | breakpoint_set_commands (struct breakpoint *b, |
12973681 | 1286 | counted_command_line &&commands) |
95a42b64 | 1287 | { |
93921405 | 1288 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1289 | |
d1b0a7bf | 1290 | b->commands = std::move (commands); |
76727919 | 1291 | gdb::observers::breakpoint_modified.notify (b); |
48cb2d85 VP |
1292 | } |
1293 | ||
45a43567 TT |
1294 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1295 | is not the same as the "silent" that may appear in the breakpoint's | |
1296 | commands. */ | |
1297 | ||
1298 | void | |
1299 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1300 | { | |
1301 | int old_silent = b->silent; | |
1302 | ||
1303 | b->silent = silent; | |
1304 | if (old_silent != silent) | |
76727919 | 1305 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1306 | } |
1307 | ||
1308 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1309 | breakpoint work for any thread. */ | |
1310 | ||
1311 | void | |
1312 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1313 | { | |
1314 | int old_thread = b->thread; | |
1315 | ||
1316 | b->thread = thread; | |
1317 | if (old_thread != thread) | |
76727919 | 1318 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1319 | } |
1320 | ||
1321 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1322 | breakpoint work for any task. */ | |
1323 | ||
1324 | void | |
1325 | breakpoint_set_task (struct breakpoint *b, int task) | |
1326 | { | |
1327 | int old_task = b->task; | |
1328 | ||
1329 | b->task = task; | |
1330 | if (old_task != task) | |
76727919 | 1331 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1332 | } |
1333 | ||
95a42b64 | 1334 | static void |
896b6bda | 1335 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1336 | struct command_line *control) |
95a42b64 | 1337 | { |
d1b0a7bf | 1338 | counted_command_line cmd; |
999700cd PW |
1339 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
1340 | NULL after the call to read_command_lines if the user provides an empty | |
1341 | list of command by just typing "end". */ | |
1342 | bool cmd_read = false; | |
95a42b64 | 1343 | |
896b6bda PA |
1344 | std::string new_arg; |
1345 | ||
95a42b64 TT |
1346 | if (arg == NULL || !*arg) |
1347 | { | |
da1df1db | 1348 | /* Argument not explicitly given. Synthesize it. */ |
86b17b60 | 1349 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1350 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1351 | breakpoint_count); | |
95a42b64 | 1352 | else if (breakpoint_count > 0) |
896b6bda | 1353 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b | 1354 | } |
da1df1db TBA |
1355 | else |
1356 | { | |
1357 | /* Create a copy of ARG. This is needed because the "commands" | |
1358 | command may be coming from a script. In that case, the read | |
1359 | line buffer is going to be overwritten in the lambda of | |
1360 | 'map_breakpoint_numbers' below when reading the next line | |
1361 | before we are are done parsing the breakpoint numbers. */ | |
1362 | new_arg = arg; | |
1363 | } | |
1364 | arg = new_arg.c_str (); | |
48649e1b TT |
1365 | |
1366 | map_breakpoint_numbers | |
1367 | (arg, [&] (breakpoint *b) | |
1368 | { | |
999700cd | 1369 | if (!cmd_read) |
48649e1b | 1370 | { |
999700cd | 1371 | gdb_assert (cmd == NULL); |
48649e1b | 1372 | if (control != NULL) |
12973681 | 1373 | cmd = control->body_list_0; |
48649e1b TT |
1374 | else |
1375 | { | |
81b1e71c TT |
1376 | std::string str |
1377 | = string_printf (_("Type commands for breakpoint(s) " | |
1378 | "%s, one per line."), | |
1379 | arg); | |
48649e1b | 1380 | |
60b3cef2 TT |
1381 | auto do_validate = [=] (const char *line) |
1382 | { | |
1383 | validate_actionline (line, b); | |
1384 | }; | |
1385 | gdb::function_view<void (const char *)> validator; | |
1386 | if (is_tracepoint (b)) | |
1387 | validator = do_validate; | |
1388 | ||
1389 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); | |
48649e1b | 1390 | } |
999700cd | 1391 | cmd_read = true; |
48649e1b TT |
1392 | } |
1393 | ||
1394 | /* If a breakpoint was on the list more than once, we don't need to | |
1395 | do anything. */ | |
1396 | if (b->commands != cmd) | |
1397 | { | |
d1b0a7bf | 1398 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b | 1399 | b->commands = cmd; |
76727919 | 1400 | gdb::observers::breakpoint_modified.notify (b); |
48649e1b TT |
1401 | } |
1402 | }); | |
95a42b64 TT |
1403 | } |
1404 | ||
1405 | static void | |
0b39b52e | 1406 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1407 | { |
1408 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1409 | } |
40c03ae8 EZ |
1410 | |
1411 | /* Like commands_command, but instead of reading the commands from | |
1412 | input stream, takes them from an already parsed command structure. | |
1413 | ||
1414 | This is used by cli-script.c to DTRT with breakpoint commands | |
1415 | that are part of if and while bodies. */ | |
1416 | enum command_control_type | |
896b6bda | 1417 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1418 | { |
95a42b64 TT |
1419 | commands_command_1 (arg, 0, cmd); |
1420 | return simple_control; | |
40c03ae8 | 1421 | } |
876fa593 JK |
1422 | |
1423 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1424 | ||
1425 | static int | |
1426 | bp_location_has_shadow (struct bp_location *bl) | |
1427 | { | |
1428 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1429 | return 0; | |
1430 | if (!bl->inserted) | |
1431 | return 0; | |
1432 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1433 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1434 | return 0; |
1435 | return 1; | |
1436 | } | |
1437 | ||
9d497a19 PA |
1438 | /* Update BUF, which is LEN bytes read from the target address |
1439 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1440 | contents. | |
1441 | ||
1442 | If READBUF is not NULL, this buffer must not overlap with the of | |
1443 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1444 | failed assertion internal error will be raised. */ | |
1445 | ||
1446 | static void | |
1447 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1448 | const gdb_byte *writebuf_org, | |
1449 | ULONGEST memaddr, LONGEST len, | |
1450 | struct bp_target_info *target_info, | |
1451 | struct gdbarch *gdbarch) | |
1452 | { | |
1453 | /* Now do full processing of the found relevant range of elements. */ | |
1454 | CORE_ADDR bp_addr = 0; | |
1455 | int bp_size = 0; | |
1456 | int bptoffset = 0; | |
1457 | ||
1458 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1459 | current_program_space->aspace, 0)) | |
1460 | { | |
1461 | /* The breakpoint is inserted in a different address space. */ | |
1462 | return; | |
1463 | } | |
1464 | ||
1465 | /* Addresses and length of the part of the breakpoint that | |
1466 | we need to copy. */ | |
1467 | bp_addr = target_info->placed_address; | |
1468 | bp_size = target_info->shadow_len; | |
1469 | ||
1470 | if (bp_addr + bp_size <= memaddr) | |
1471 | { | |
1472 | /* The breakpoint is entirely before the chunk of memory we are | |
1473 | reading. */ | |
1474 | return; | |
1475 | } | |
1476 | ||
1477 | if (bp_addr >= memaddr + len) | |
1478 | { | |
1479 | /* The breakpoint is entirely after the chunk of memory we are | |
1480 | reading. */ | |
1481 | return; | |
1482 | } | |
1483 | ||
1484 | /* Offset within shadow_contents. */ | |
1485 | if (bp_addr < memaddr) | |
1486 | { | |
1487 | /* Only copy the second part of the breakpoint. */ | |
1488 | bp_size -= memaddr - bp_addr; | |
1489 | bptoffset = memaddr - bp_addr; | |
1490 | bp_addr = memaddr; | |
1491 | } | |
1492 | ||
1493 | if (bp_addr + bp_size > memaddr + len) | |
1494 | { | |
1495 | /* Only copy the first part of the breakpoint. */ | |
1496 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1497 | } | |
1498 | ||
1499 | if (readbuf != NULL) | |
1500 | { | |
1501 | /* Verify that the readbuf buffer does not overlap with the | |
1502 | shadow_contents buffer. */ | |
1503 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1504 | || readbuf >= (target_info->shadow_contents | |
1505 | + target_info->shadow_len)); | |
1506 | ||
1507 | /* Update the read buffer with this inserted breakpoint's | |
1508 | shadow. */ | |
1509 | memcpy (readbuf + bp_addr - memaddr, | |
1510 | target_info->shadow_contents + bptoffset, bp_size); | |
1511 | } | |
1512 | else | |
1513 | { | |
1514 | const unsigned char *bp; | |
0d5ed153 MR |
1515 | CORE_ADDR addr = target_info->reqstd_address; |
1516 | int placed_size; | |
9d497a19 PA |
1517 | |
1518 | /* Update the shadow with what we want to write to memory. */ | |
1519 | memcpy (target_info->shadow_contents + bptoffset, | |
1520 | writebuf_org + bp_addr - memaddr, bp_size); | |
1521 | ||
1522 | /* Determine appropriate breakpoint contents and size for this | |
1523 | address. */ | |
0d5ed153 | 1524 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1525 | |
1526 | /* Update the final write buffer with this inserted | |
1527 | breakpoint's INSN. */ | |
1528 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1529 | } | |
1530 | } | |
1531 | ||
8defab1a | 1532 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1533 | by replacing any memory breakpoints with their shadowed contents. |
1534 | ||
35c63cd8 JB |
1535 | If READBUF is not NULL, this buffer must not overlap with any of |
1536 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1537 | a failed assertion internal error will be raised. | |
1538 | ||
876fa593 | 1539 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1540 | bl->address - bp_locations_placed_address_before_address_max |
1541 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1542 | The range we were requested to resolve shadows for is: |
1543 | memaddr ... memaddr + len | |
1544 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1545 | memaddr + len <= (bl->address |
f5336ca5 | 1546 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1547 | and: |
f5336ca5 | 1548 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1549 | |
8defab1a | 1550 | void |
f0ba3972 PA |
1551 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1552 | const gdb_byte *writebuf_org, | |
1553 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1554 | { |
4a64f543 MS |
1555 | /* Left boundary, right boundary and median element of our binary |
1556 | search. */ | |
876fa593 JK |
1557 | unsigned bc_l, bc_r, bc; |
1558 | ||
4a64f543 MS |
1559 | /* Find BC_L which is a leftmost element which may affect BUF |
1560 | content. It is safe to report lower value but a failure to | |
1561 | report higher one. */ | |
876fa593 JK |
1562 | |
1563 | bc_l = 0; | |
f5336ca5 | 1564 | bc_r = bp_locations_count; |
876fa593 JK |
1565 | while (bc_l + 1 < bc_r) |
1566 | { | |
35df4500 | 1567 | struct bp_location *bl; |
876fa593 JK |
1568 | |
1569 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1570 | bl = bp_locations[bc]; |
876fa593 | 1571 | |
4a64f543 MS |
1572 | /* Check first BL->ADDRESS will not overflow due to the added |
1573 | constant. Then advance the left boundary only if we are sure | |
1574 | the BC element can in no way affect the BUF content (MEMADDR | |
1575 | to MEMADDR + LEN range). | |
876fa593 | 1576 | |
f5336ca5 | 1577 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1578 | offset so that we cannot miss a breakpoint with its shadow |
1579 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1580 | |
f5336ca5 | 1581 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1582 | >= bl->address) |
f5336ca5 | 1583 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1584 | <= memaddr)) |
876fa593 JK |
1585 | bc_l = bc; |
1586 | else | |
1587 | bc_r = bc; | |
1588 | } | |
1589 | ||
128070bb PA |
1590 | /* Due to the binary search above, we need to make sure we pick the |
1591 | first location that's at BC_L's address. E.g., if there are | |
1592 | multiple locations at the same address, BC_L may end up pointing | |
1593 | at a duplicate location, and miss the "master"/"inserted" | |
1594 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1595 | B: | |
1596 | ||
1597 | L1@A, L2@A, L3@B, ... | |
1598 | ||
1599 | BC_L could end up pointing at location L2, while the "master" | |
1600 | location could be L1. Since the `loc->inserted' flag is only set | |
1601 | on "master" locations, we'd forget to restore the shadow of L1 | |
1602 | and L2. */ | |
1603 | while (bc_l > 0 | |
f5336ca5 | 1604 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1605 | bc_l--; |
1606 | ||
876fa593 JK |
1607 | /* Now do full processing of the found relevant range of elements. */ |
1608 | ||
f5336ca5 | 1609 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1610 | { |
f5336ca5 | 1611 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1612 | |
35df4500 TJB |
1613 | /* bp_location array has BL->OWNER always non-NULL. */ |
1614 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1615 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1616 | bl->owner->number); |
ffce0d52 | 1617 | |
e5dd4106 | 1618 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1619 | content. */ |
1620 | ||
f5336ca5 PA |
1621 | if (bl->address >= bp_locations_placed_address_before_address_max |
1622 | && memaddr + len <= (bl->address | |
1623 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1624 | break; |
1625 | ||
35df4500 | 1626 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1627 | continue; |
6c95b8df | 1628 | |
9d497a19 PA |
1629 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1630 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1631 | } | |
c906108c | 1632 | } |
9d497a19 | 1633 | |
f2478a7e | 1634 | /* See breakpoint.h. */ |
b775012e | 1635 | |
f2478a7e | 1636 | bool |
b775012e LM |
1637 | is_breakpoint (const struct breakpoint *bpt) |
1638 | { | |
1639 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1640 | || bpt->type == bp_hardware_breakpoint |
1641 | || bpt->type == bp_dprintf); | |
b775012e LM |
1642 | } |
1643 | ||
60e1c644 PA |
1644 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1645 | ||
f2478a7e | 1646 | static bool |
d77f58be | 1647 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1648 | { |
1649 | return (bpt->type == bp_hardware_watchpoint | |
1650 | || bpt->type == bp_read_watchpoint | |
1651 | || bpt->type == bp_access_watchpoint); | |
1652 | } | |
7270d8f2 | 1653 | |
f2478a7e | 1654 | /* See breakpoint.h. */ |
60e1c644 | 1655 | |
f2478a7e | 1656 | bool |
d77f58be | 1657 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1658 | { |
1659 | return (is_hardware_watchpoint (bpt) | |
1660 | || bpt->type == bp_watchpoint); | |
1661 | } | |
1662 | ||
3a5c3e22 PA |
1663 | /* Returns true if the current thread and its running state are safe |
1664 | to evaluate or update watchpoint B. Watchpoints on local | |
1665 | expressions need to be evaluated in the context of the thread that | |
1666 | was current when the watchpoint was created, and, that thread needs | |
1667 | to be stopped to be able to select the correct frame context. | |
1668 | Watchpoints on global expressions can be evaluated on any thread, | |
1669 | and in any state. It is presently left to the target allowing | |
1670 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1671 | |
1672 | static int | |
3a5c3e22 | 1673 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1674 | { |
c1fc2657 | 1675 | return (b->pspace == current_program_space |
d7e15655 TT |
1676 | && (b->watchpoint_thread == null_ptid |
1677 | || (inferior_ptid == b->watchpoint_thread | |
00431a78 | 1678 | && !inferior_thread ()->executing))); |
f6bc2008 PA |
1679 | } |
1680 | ||
d0fb5eae JK |
1681 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1682 | associated bp_watchpoint_scope breakpoint. */ | |
1683 | ||
1684 | static void | |
3a5c3e22 | 1685 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1686 | { |
c1fc2657 | 1687 | if (w->related_breakpoint != w) |
d0fb5eae | 1688 | { |
c1fc2657 SM |
1689 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1690 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1691 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1692 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1693 | w->related_breakpoint = w; | |
d0fb5eae | 1694 | } |
c1fc2657 | 1695 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1696 | } |
1697 | ||
bb9d5f81 PP |
1698 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1699 | watchpoint W. */ | |
1700 | ||
1701 | static struct value * | |
1702 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1703 | { | |
1704 | struct value *bit_val; | |
1705 | ||
1706 | if (val == NULL) | |
1707 | return NULL; | |
1708 | ||
1709 | bit_val = allocate_value (value_type (val)); | |
1710 | ||
1711 | unpack_value_bitfield (bit_val, | |
1712 | w->val_bitpos, | |
1713 | w->val_bitsize, | |
1714 | value_contents_for_printing (val), | |
1715 | value_offset (val), | |
1716 | val); | |
1717 | ||
1718 | return bit_val; | |
1719 | } | |
1720 | ||
c6d81124 PA |
1721 | /* Allocate a dummy location and add it to B, which must be a software |
1722 | watchpoint. This is required because even if a software watchpoint | |
1723 | is not watching any memory, bpstat_stop_status requires a location | |
1724 | to be able to report stops. */ | |
1725 | ||
1726 | static void | |
1727 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1728 | struct program_space *pspace) | |
1729 | { | |
1730 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1731 | ||
1732 | b->loc = allocate_bp_location (b); | |
1733 | b->loc->pspace = pspace; | |
1734 | b->loc->address = -1; | |
1735 | b->loc->length = -1; | |
1736 | } | |
1737 | ||
1738 | /* Returns true if B is a software watchpoint that is not watching any | |
1739 | memory (e.g., "watch $pc"). */ | |
1740 | ||
f2478a7e | 1741 | static bool |
c6d81124 PA |
1742 | is_no_memory_software_watchpoint (struct breakpoint *b) |
1743 | { | |
1744 | return (b->type == bp_watchpoint | |
1745 | && b->loc != NULL | |
1746 | && b->loc->next == NULL | |
1747 | && b->loc->address == -1 | |
1748 | && b->loc->length == -1); | |
1749 | } | |
1750 | ||
567e1b4e JB |
1751 | /* Assuming that B is a watchpoint: |
1752 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1753 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1754 | - Evaluate the condition if there is one, and store the result |
1755 | in b->loc->cond. | |
a5606eee VP |
1756 | - Update the list of values that must be watched in B->loc. |
1757 | ||
4a64f543 MS |
1758 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1759 | nothing. If this is local watchpoint that is out of scope, delete | |
1760 | it. | |
1761 | ||
1762 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1763 | removed + inserted on each stop here. Normal breakpoints must | |
1764 | never be removed because they might be missed by a running thread | |
1765 | when debugging in non-stop mode. On the other hand, hardware | |
1766 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1767 | to each LWP since they are stored in each LWP's hardware debug | |
1768 | registers. Therefore, such LWP must be stopped first in order to | |
1769 | be able to modify its hardware watchpoints. | |
1770 | ||
1771 | Hardware watchpoints must be reset exactly once after being | |
1772 | presented to the user. It cannot be done sooner, because it would | |
1773 | reset the data used to present the watchpoint hit to the user. And | |
1774 | it must not be done later because it could display the same single | |
1775 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1776 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1777 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1778 | not user-visible - its hit is suppressed if the memory content has | |
1779 | not changed. | |
1780 | ||
1781 | The following constraints influence the location where we can reset | |
1782 | hardware watchpoints: | |
1783 | ||
1784 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1785 | called several times when GDB stops. | |
1786 | ||
1787 | [linux] | |
1788 | * Multiple hardware watchpoints can be hit at the same time, | |
1789 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1790 | hit at a time as the reason for stopping, and all the other hits | |
1791 | are presented later, one after the other, each time the user | |
1792 | requests the execution to be resumed. Execution is not resumed | |
1793 | for the threads still having pending hit event stored in | |
1794 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1795 | the inferior on the first stop the thread hit event is kept being | |
1796 | reported from its cached value by linux_nat_stopped_data_address | |
1797 | until the real thread resume happens after the watchpoint gets | |
1798 | presented and thus its LWP_INFO->STATUS gets reset. | |
1799 | ||
1800 | Therefore the hardware watchpoint hit can get safely reset on the | |
1801 | watchpoint removal from inferior. */ | |
a79d3c27 | 1802 | |
b40ce68a | 1803 | static void |
3a5c3e22 | 1804 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1805 | { |
a5606eee | 1806 | int within_current_scope; |
a5606eee | 1807 | struct frame_id saved_frame_id; |
66076460 | 1808 | int frame_saved; |
a5606eee | 1809 | |
f6bc2008 PA |
1810 | /* If this is a local watchpoint, we only want to check if the |
1811 | watchpoint frame is in scope if the current thread is the thread | |
1812 | that was used to create the watchpoint. */ | |
1813 | if (!watchpoint_in_thread_scope (b)) | |
1814 | return; | |
1815 | ||
c1fc2657 | 1816 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1817 | return; |
1818 | ||
66076460 | 1819 | frame_saved = 0; |
a5606eee VP |
1820 | |
1821 | /* Determine if the watchpoint is within scope. */ | |
1822 | if (b->exp_valid_block == NULL) | |
1823 | within_current_scope = 1; | |
1824 | else | |
1825 | { | |
b5db5dfc UW |
1826 | struct frame_info *fi = get_current_frame (); |
1827 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1828 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1829 | ||
c9cf6e20 MG |
1830 | /* If we're at a point where the stack has been destroyed |
1831 | (e.g. in a function epilogue), unwinding may not work | |
1832 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1833 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1834 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1835 | return; |
66076460 DJ |
1836 | |
1837 | /* Save the current frame's ID so we can restore it after | |
dda83cd7 | 1838 | evaluating the watchpoint expression on its own frame. */ |
66076460 | 1839 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
dda83cd7 SM |
1840 | took a frame parameter, so that we didn't have to change the |
1841 | selected frame. */ | |
66076460 DJ |
1842 | frame_saved = 1; |
1843 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1844 | ||
a5606eee VP |
1845 | fi = frame_find_by_id (b->watchpoint_frame); |
1846 | within_current_scope = (fi != NULL); | |
1847 | if (within_current_scope) | |
1848 | select_frame (fi); | |
1849 | } | |
1850 | ||
b5db5dfc UW |
1851 | /* We don't free locations. They are stored in the bp_location array |
1852 | and update_global_location_list will eventually delete them and | |
1853 | remove breakpoints if needed. */ | |
c1fc2657 | 1854 | b->loc = NULL; |
b5db5dfc | 1855 | |
a5606eee VP |
1856 | if (within_current_scope && reparse) |
1857 | { | |
bbc13ae3 | 1858 | const char *s; |
d63d0675 | 1859 | |
4d01a485 | 1860 | b->exp.reset (); |
d63d0675 | 1861 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1862 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1863 | /* If the meaning of expression itself changed, the old value is |
1864 | no longer relevant. We don't want to report a watchpoint hit | |
1865 | to the user when the old value and the new value may actually | |
1866 | be completely different objects. */ | |
fa4727a6 | 1867 | b->val = NULL; |
4c1d86d9 | 1868 | b->val_valid = false; |
60e1c644 PA |
1869 | |
1870 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1871 | expression is stored in the breakpoint object, not in the | |
1872 | locations (re)created below. */ | |
c1fc2657 | 1873 | if (b->cond_string != NULL) |
60e1c644 | 1874 | { |
4d01a485 | 1875 | b->cond_exp.reset (); |
60e1c644 | 1876 | |
c1fc2657 | 1877 | s = b->cond_string; |
1bb9788d | 1878 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1879 | } |
a5606eee | 1880 | } |
a5606eee VP |
1881 | |
1882 | /* If we failed to parse the expression, for example because | |
1883 | it refers to a global variable in a not-yet-loaded shared library, | |
1884 | don't try to insert watchpoint. We don't automatically delete | |
1885 | such watchpoint, though, since failure to parse expression | |
1886 | is different from out-of-scope watchpoint. */ | |
55f6301a | 1887 | if (!target_has_execution ()) |
2d134ed3 PA |
1888 | { |
1889 | /* Without execution, memory can't change. No use to try and | |
1890 | set watchpoint locations. The watchpoint will be reset when | |
1891 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1892 | if (!can_use_hw_watchpoints) |
1893 | { | |
c1fc2657 SM |
1894 | if (b->ops->works_in_software_mode (b)) |
1895 | b->type = bp_watchpoint; | |
e8369a73 | 1896 | else |
638aa5a1 AB |
1897 | error (_("Can't set read/access watchpoint when " |
1898 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1899 | } |
2d134ed3 PA |
1900 | } |
1901 | else if (within_current_scope && b->exp) | |
a5606eee | 1902 | { |
0cf6dd15 | 1903 | int pc = 0; |
a6535de1 | 1904 | std::vector<value_ref_ptr> val_chain; |
8d49165d | 1905 | struct value *v, *result; |
2d134ed3 | 1906 | struct program_space *frame_pspace; |
a5606eee | 1907 | |
4d01a485 | 1908 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1909 | |
a5606eee VP |
1910 | /* Avoid setting b->val if it's already set. The meaning of |
1911 | b->val is 'the last value' user saw, and we should update | |
1912 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1913 | happens, the code that reports it updates b->val directly. |
1914 | We don't keep track of the memory value for masked | |
1915 | watchpoints. */ | |
c1fc2657 | 1916 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1917 | { |
bb9d5f81 | 1918 | if (b->val_bitsize != 0) |
850645cf TT |
1919 | v = extract_bitfield_from_watchpoint_value (b, v); |
1920 | b->val = release_value (v); | |
4c1d86d9 | 1921 | b->val_valid = true; |
fa4727a6 | 1922 | } |
a5606eee | 1923 | |
2d134ed3 PA |
1924 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1925 | ||
a5606eee | 1926 | /* Look at each value on the value chain. */ |
a6535de1 TT |
1927 | gdb_assert (!val_chain.empty ()); |
1928 | for (const value_ref_ptr &iter : val_chain) | |
a5606eee | 1929 | { |
a6535de1 TT |
1930 | v = iter.get (); |
1931 | ||
a5606eee VP |
1932 | /* If it's a memory location, and GDB actually needed |
1933 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1934 | must watch it. If the first value returned is |
1935 | still lazy, that means an error occurred reading it; | |
1936 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1937 | if (VALUE_LVAL (v) == lval_memory |
a6535de1 | 1938 | && (v == val_chain[0] || ! value_lazy (v))) |
a5606eee VP |
1939 | { |
1940 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1941 | |
a5606eee VP |
1942 | /* We only watch structs and arrays if user asked |
1943 | for it explicitly, never if they just happen to | |
1944 | appear in the middle of some value chain. */ | |
fa4727a6 | 1945 | if (v == result |
78134374 SM |
1946 | || (vtype->code () != TYPE_CODE_STRUCT |
1947 | && vtype->code () != TYPE_CODE_ARRAY)) | |
a5606eee VP |
1948 | { |
1949 | CORE_ADDR addr; | |
f486487f | 1950 | enum target_hw_bp_type type; |
a5606eee | 1951 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1952 | int bitpos = 0, bitsize = 0; |
1953 | ||
1954 | if (value_bitsize (v) != 0) | |
1955 | { | |
1956 | /* Extract the bit parameters out from the bitfield | |
1957 | sub-expression. */ | |
1958 | bitpos = value_bitpos (v); | |
1959 | bitsize = value_bitsize (v); | |
1960 | } | |
1961 | else if (v == result && b->val_bitsize != 0) | |
1962 | { | |
1963 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1964 | lvalue whose bit parameters are saved in the fields | |
1965 | VAL_BITPOS and VAL_BITSIZE. */ | |
1966 | bitpos = b->val_bitpos; | |
1967 | bitsize = b->val_bitsize; | |
1968 | } | |
a5606eee | 1969 | |
42ae5230 | 1970 | addr = value_address (v); |
bb9d5f81 PP |
1971 | if (bitsize != 0) |
1972 | { | |
1973 | /* Skip the bytes that don't contain the bitfield. */ | |
1974 | addr += bitpos / 8; | |
1975 | } | |
1976 | ||
a5606eee | 1977 | type = hw_write; |
c1fc2657 | 1978 | if (b->type == bp_read_watchpoint) |
a5606eee | 1979 | type = hw_read; |
c1fc2657 | 1980 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1981 | type = hw_access; |
3a5c3e22 | 1982 | |
c1fc2657 SM |
1983 | loc = allocate_bp_location (b); |
1984 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1985 | ; |
1986 | *tmp = loc; | |
a6d9a66e | 1987 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1988 | |
1989 | loc->pspace = frame_pspace; | |
f17d9474 | 1990 | loc->address = address_significant (loc->gdbarch, addr); |
bb9d5f81 PP |
1991 | |
1992 | if (bitsize != 0) | |
1993 | { | |
1994 | /* Just cover the bytes that make up the bitfield. */ | |
1995 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1996 | } | |
1997 | else | |
1998 | loc->length = TYPE_LENGTH (value_type (v)); | |
1999 | ||
a5606eee VP |
2000 | loc->watchpoint_type = type; |
2001 | } | |
2002 | } | |
9fa40276 TJB |
2003 | } |
2004 | ||
2005 | /* Change the type of breakpoint between hardware assisted or | |
2006 | an ordinary watchpoint depending on the hardware support | |
2007 | and free hardware slots. REPARSE is set when the inferior | |
2008 | is started. */ | |
a9634178 | 2009 | if (reparse) |
9fa40276 | 2010 | { |
e09342b5 | 2011 | int reg_cnt; |
9fa40276 TJB |
2012 | enum bp_loc_type loc_type; |
2013 | struct bp_location *bl; | |
a5606eee | 2014 | |
a9634178 | 2015 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2016 | |
2017 | if (reg_cnt) | |
9fa40276 TJB |
2018 | { |
2019 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2020 | enum bptype type; |
9fa40276 | 2021 | |
a9634178 TJB |
2022 | /* Use an exact watchpoint when there's only one memory region to be |
2023 | watched, and only one debug register is needed to watch it. */ | |
2024 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2025 | ||
9fa40276 | 2026 | /* We need to determine how many resources are already |
e09342b5 TJB |
2027 | used for all other hardware watchpoints plus this one |
2028 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2029 | this watchpoint in as well. */ |
2030 | ||
2031 | /* If this is a software watchpoint, we try to turn it | |
2032 | to a hardware one -- count resources as if B was of | |
2033 | hardware watchpoint type. */ | |
c1fc2657 | 2034 | type = b->type; |
a1398e0c PA |
2035 | if (type == bp_watchpoint) |
2036 | type = bp_hardware_watchpoint; | |
2037 | ||
2038 | /* This watchpoint may or may not have been placed on | |
2039 | the list yet at this point (it won't be in the list | |
2040 | if we're trying to create it for the first time, | |
2041 | through watch_command), so always account for it | |
2042 | manually. */ | |
2043 | ||
2044 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 2045 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
2046 | |
2047 | /* Add in the resources needed for B. */ | |
c1fc2657 | 2048 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
2049 | |
2050 | target_resources_ok | |
2051 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2052 | if (target_resources_ok <= 0) |
a9634178 | 2053 | { |
c1fc2657 | 2054 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
2055 | |
2056 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2057 | error (_("Target does not support this type of " |
2058 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2059 | else if (target_resources_ok < 0 && !sw_mode) |
2060 | error (_("There are not enough available hardware " | |
2061 | "resources for this watchpoint.")); | |
a1398e0c PA |
2062 | |
2063 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 2064 | b->type = bp_watchpoint; |
a1398e0c PA |
2065 | } |
2066 | else | |
2067 | { | |
2068 | /* If this was a software watchpoint, we've just | |
2069 | found we have enough resources to turn it to a | |
2070 | hardware watchpoint. Otherwise, this is a | |
2071 | nop. */ | |
c1fc2657 | 2072 | b->type = type; |
a9634178 | 2073 | } |
9fa40276 | 2074 | } |
c1fc2657 | 2075 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
2076 | { |
2077 | if (!can_use_hw_watchpoints) | |
2078 | error (_("Can't set read/access watchpoint when " | |
2079 | "hardware watchpoints are disabled.")); | |
2080 | else | |
2081 | error (_("Expression cannot be implemented with " | |
2082 | "read/access watchpoint.")); | |
2083 | } | |
9fa40276 | 2084 | else |
c1fc2657 | 2085 | b->type = bp_watchpoint; |
9fa40276 | 2086 | |
c1fc2657 | 2087 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 2088 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 2089 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
2090 | bl->loc_type = loc_type; |
2091 | } | |
2092 | ||
c7437ca6 PA |
2093 | /* If a software watchpoint is not watching any memory, then the |
2094 | above left it without any location set up. But, | |
2095 | bpstat_stop_status requires a location to be able to report | |
2096 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
2097 | if (b->type == bp_watchpoint && b->loc == NULL) |
2098 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
2099 | } |
2100 | else if (!within_current_scope) | |
7270d8f2 | 2101 | { |
ac74f770 MS |
2102 | printf_filtered (_("\ |
2103 | Watchpoint %d deleted because the program has left the block\n\ | |
2104 | in which its expression is valid.\n"), | |
c1fc2657 | 2105 | b->number); |
d0fb5eae | 2106 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2107 | } |
a5606eee VP |
2108 | |
2109 | /* Restore the selected frame. */ | |
66076460 DJ |
2110 | if (frame_saved) |
2111 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2112 | } |
2113 | ||
a5606eee | 2114 | |
74960c60 | 2115 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2116 | inserted in the inferior. We don't differentiate the type of BL's owner |
2117 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2118 | breakpoint_ops is not defined, because in insert_bp_location, | |
2119 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2120 | static int |
35df4500 | 2121 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2122 | { |
35df4500 | 2123 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2124 | return 0; |
2125 | ||
35df4500 | 2126 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2127 | return 0; |
2128 | ||
b5fa468f TBA |
2129 | if (!bl->enabled || bl->disabled_by_cond |
2130 | || bl->shlib_disabled || bl->duplicate) | |
74960c60 VP |
2131 | return 0; |
2132 | ||
f8eba3c6 TT |
2133 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2134 | return 0; | |
2135 | ||
56710373 PA |
2136 | /* This is set for example, when we're attached to the parent of a |
2137 | vfork, and have detached from the child. The child is running | |
2138 | free, and we expect it to do an exec or exit, at which point the | |
2139 | OS makes the parent schedulable again (and the target reports | |
2140 | that the vfork is done). Until the child is done with the shared | |
2141 | memory region, do not insert breakpoints in the parent, otherwise | |
2142 | the child could still trip on the parent's breakpoints. Since | |
2143 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2144 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2145 | return 0; |
2146 | ||
31e77af2 | 2147 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2148 | location, except if the breakpoint is a single-step breakpoint, |
2149 | and the breakpoint's thread is the thread which is stepping past | |
2150 | a breakpoint. */ | |
31e77af2 PA |
2151 | if ((bl->loc_type == bp_loc_software_breakpoint |
2152 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2153 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2154 | bl->address) |
2155 | /* The single-step breakpoint may be inserted at the location | |
2156 | we're trying to step if the instruction branches to itself. | |
2157 | However, the instruction won't be executed at all and it may | |
2158 | break the semantics of the instruction, for example, the | |
2159 | instruction is a conditional branch or updates some flags. | |
2160 | We can't fix it unless GDB is able to emulate the instruction | |
2161 | or switch to displaced stepping. */ | |
2162 | && !(bl->owner->type == bp_single_step | |
2163 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 | 2164 | { |
1eb8556f SM |
2165 | infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s", |
2166 | paddress (bl->gdbarch, bl->address)); | |
e558d7c1 PA |
2167 | return 0; |
2168 | } | |
31e77af2 | 2169 | |
963f9c80 PA |
2170 | /* Don't insert watchpoints if we're trying to step past the |
2171 | instruction that triggered one. */ | |
2172 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2173 | && stepping_past_nonsteppable_watchpoint ()) | |
2174 | { | |
1eb8556f SM |
2175 | infrun_debug_printf ("stepping past non-steppable watchpoint. " |
2176 | "skipping watchpoint at %s:%d\n", | |
2177 | paddress (bl->gdbarch, bl->address), bl->length); | |
963f9c80 PA |
2178 | return 0; |
2179 | } | |
2180 | ||
74960c60 VP |
2181 | return 1; |
2182 | } | |
2183 | ||
934709f0 PW |
2184 | /* Same as should_be_inserted but does the check assuming |
2185 | that the location is not duplicated. */ | |
2186 | ||
2187 | static int | |
2188 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2189 | { | |
2190 | int result; | |
2191 | const int save_duplicate = bl->duplicate; | |
2192 | ||
2193 | bl->duplicate = 0; | |
2194 | result = should_be_inserted (bl); | |
2195 | bl->duplicate = save_duplicate; | |
2196 | return result; | |
2197 | } | |
2198 | ||
b775012e LM |
2199 | /* Parses a conditional described by an expression COND into an |
2200 | agent expression bytecode suitable for evaluation | |
2201 | by the bytecode interpreter. Return NULL if there was | |
2202 | any error during parsing. */ | |
2203 | ||
833177a4 | 2204 | static agent_expr_up |
b775012e LM |
2205 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2206 | { | |
833177a4 | 2207 | if (cond == NULL) |
b775012e LM |
2208 | return NULL; |
2209 | ||
833177a4 PA |
2210 | agent_expr_up aexpr; |
2211 | ||
b775012e LM |
2212 | /* We don't want to stop processing, so catch any errors |
2213 | that may show up. */ | |
a70b8144 | 2214 | try |
b775012e | 2215 | { |
036e657b | 2216 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2217 | } |
2218 | ||
230d2906 | 2219 | catch (const gdb_exception_error &ex) |
b775012e LM |
2220 | { |
2221 | /* If we got here, it means the condition could not be parsed to a valid | |
2222 | bytecode expression and thus can't be evaluated on the target's side. | |
2223 | It's no use iterating through the conditions. */ | |
b775012e LM |
2224 | } |
2225 | ||
2226 | /* We have a valid agent expression. */ | |
2227 | return aexpr; | |
2228 | } | |
2229 | ||
2230 | /* Based on location BL, create a list of breakpoint conditions to be | |
2231 | passed on to the target. If we have duplicated locations with different | |
2232 | conditions, we will add such conditions to the list. The idea is that the | |
2233 | target will evaluate the list of conditions and will only notify GDB when | |
2234 | one of them is true. */ | |
2235 | ||
2236 | static void | |
2237 | build_target_condition_list (struct bp_location *bl) | |
2238 | { | |
2239 | struct bp_location **locp = NULL, **loc2p; | |
2240 | int null_condition_or_parse_error = 0; | |
2241 | int modified = bl->needs_update; | |
2242 | struct bp_location *loc; | |
2243 | ||
8b4f3082 | 2244 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2245 | bl->target_info.conditions.clear (); |
8b4f3082 | 2246 | |
b775012e LM |
2247 | /* This is only meaningful if the target is |
2248 | evaluating conditions and if the user has | |
2249 | opted for condition evaluation on the target's | |
2250 | side. */ | |
2251 | if (gdb_evaluates_breakpoint_condition_p () | |
2252 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2253 | return; | |
2254 | ||
2255 | /* Do a first pass to check for locations with no assigned | |
7f32a4d5 PA |
2256 | conditions or conditions that fail to parse to a valid agent |
2257 | expression bytecode. If any of these happen, then it's no use to | |
2258 | send conditions to the target since this location will always | |
2259 | trigger and generate a response back to GDB. Note we consider | |
2260 | all locations at the same address irrespective of type, i.e., | |
2261 | even if the locations aren't considered duplicates (e.g., | |
2262 | software breakpoint and hardware breakpoint at the same | |
2263 | address). */ | |
b775012e LM |
2264 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
2265 | { | |
2266 | loc = (*loc2p); | |
2267 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2268 | { | |
2269 | if (modified) | |
2270 | { | |
b775012e LM |
2271 | /* Re-parse the conditions since something changed. In that |
2272 | case we already freed the condition bytecodes (see | |
2273 | force_breakpoint_reinsertion). We just | |
2274 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2275 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2276 | loc->cond.get ()); | |
b775012e LM |
2277 | } |
2278 | ||
2279 | /* If we have a NULL bytecode expression, it means something | |
2280 | went wrong or we have a null condition expression. */ | |
2281 | if (!loc->cond_bytecode) | |
2282 | { | |
2283 | null_condition_or_parse_error = 1; | |
2284 | break; | |
2285 | } | |
2286 | } | |
2287 | } | |
2288 | ||
2289 | /* If any of these happened, it means we will have to evaluate the conditions | |
2290 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2291 | for all the other duplicate locations, thus we free all of them here. | |
2292 | ||
2293 | This is so we have a finer control over which locations' conditions are | |
2294 | being evaluated by GDB or the remote stub. */ | |
2295 | if (null_condition_or_parse_error) | |
2296 | { | |
2297 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2298 | { | |
2299 | loc = (*loc2p); | |
2300 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2301 | { | |
2302 | /* Only go as far as the first NULL bytecode is | |
2303 | located. */ | |
2304 | if (!loc->cond_bytecode) | |
2305 | return; | |
2306 | ||
833177a4 | 2307 | loc->cond_bytecode.reset (); |
b775012e LM |
2308 | } |
2309 | } | |
2310 | } | |
2311 | ||
7f32a4d5 PA |
2312 | /* No NULL conditions or failed bytecode generation. Build a |
2313 | condition list for this location's address. If we have software | |
2314 | and hardware locations at the same address, they aren't | |
2315 | considered duplicates, but we still marge all the conditions | |
2316 | anyway, as it's simpler, and doesn't really make a practical | |
2317 | difference. */ | |
b775012e LM |
2318 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
2319 | { | |
2320 | loc = (*loc2p); | |
2321 | if (loc->cond | |
2322 | && is_breakpoint (loc->owner) | |
2323 | && loc->pspace->num == bl->pspace->num | |
2324 | && loc->owner->enable_state == bp_enabled | |
b5fa468f TBA |
2325 | && loc->enabled |
2326 | && !loc->disabled_by_cond) | |
3cde5c42 PA |
2327 | { |
2328 | /* Add the condition to the vector. This will be used later | |
2329 | to send the conditions to the target. */ | |
2330 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2331 | } | |
b775012e LM |
2332 | } |
2333 | ||
2334 | return; | |
2335 | } | |
2336 | ||
d3ce09f5 SS |
2337 | /* Parses a command described by string CMD into an agent expression |
2338 | bytecode suitable for evaluation by the bytecode interpreter. | |
2339 | Return NULL if there was any error during parsing. */ | |
2340 | ||
833177a4 | 2341 | static agent_expr_up |
d3ce09f5 SS |
2342 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2343 | { | |
bbc13ae3 KS |
2344 | const char *cmdrest; |
2345 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2346 | struct gdbarch *gdbarch = get_current_arch (); |
2347 | ||
833177a4 | 2348 | if (cmd == NULL) |
d3ce09f5 SS |
2349 | return NULL; |
2350 | ||
2351 | cmdrest = cmd; | |
2352 | ||
2353 | if (*cmdrest == ',') | |
2354 | ++cmdrest; | |
f1735a53 | 2355 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2356 | |
2357 | if (*cmdrest++ != '"') | |
2358 | error (_("No format string following the location")); | |
2359 | ||
2360 | format_start = cmdrest; | |
2361 | ||
8e481c3b | 2362 | format_pieces fpieces (&cmdrest); |
d3ce09f5 SS |
2363 | |
2364 | format_end = cmdrest; | |
2365 | ||
2366 | if (*cmdrest++ != '"') | |
2367 | error (_("Bad format string, non-terminated '\"'.")); | |
2368 | ||
f1735a53 | 2369 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2370 | |
2371 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2372 | error (_("Invalid argument syntax")); | |
2373 | ||
2374 | if (*cmdrest == ',') | |
2375 | cmdrest++; | |
f1735a53 | 2376 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2377 | |
2378 | /* For each argument, make an expression. */ | |
2379 | ||
8e481c3b | 2380 | std::vector<struct expression *> argvec; |
d3ce09f5 SS |
2381 | while (*cmdrest != '\0') |
2382 | { | |
bbc13ae3 | 2383 | const char *cmd1; |
d3ce09f5 SS |
2384 | |
2385 | cmd1 = cmdrest; | |
4d01a485 | 2386 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
8e481c3b | 2387 | argvec.push_back (expr.release ()); |
d3ce09f5 SS |
2388 | cmdrest = cmd1; |
2389 | if (*cmdrest == ',') | |
2390 | ++cmdrest; | |
2391 | } | |
2392 | ||
833177a4 PA |
2393 | agent_expr_up aexpr; |
2394 | ||
d3ce09f5 SS |
2395 | /* We don't want to stop processing, so catch any errors |
2396 | that may show up. */ | |
a70b8144 | 2397 | try |
d3ce09f5 | 2398 | { |
036e657b JB |
2399 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2400 | format_start, format_end - format_start, | |
8e481c3b | 2401 | argvec.size (), argvec.data ()); |
d3ce09f5 | 2402 | } |
230d2906 | 2403 | catch (const gdb_exception_error &ex) |
d3ce09f5 SS |
2404 | { |
2405 | /* If we got here, it means the command could not be parsed to a valid | |
2406 | bytecode expression and thus can't be evaluated on the target's side. | |
2407 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2408 | } |
492d29ea | 2409 | |
d3ce09f5 SS |
2410 | /* We have a valid agent expression, return it. */ |
2411 | return aexpr; | |
2412 | } | |
2413 | ||
2414 | /* Based on location BL, create a list of breakpoint commands to be | |
2415 | passed on to the target. If we have duplicated locations with | |
2416 | different commands, we will add any such to the list. */ | |
2417 | ||
2418 | static void | |
2419 | build_target_command_list (struct bp_location *bl) | |
2420 | { | |
2421 | struct bp_location **locp = NULL, **loc2p; | |
2422 | int null_command_or_parse_error = 0; | |
2423 | int modified = bl->needs_update; | |
2424 | struct bp_location *loc; | |
2425 | ||
3cde5c42 PA |
2426 | /* Clear commands left over from a previous insert. */ |
2427 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2428 | |
41fac0cf | 2429 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2430 | return; |
2431 | ||
41fac0cf PA |
2432 | /* For now, limit to agent-style dprintf breakpoints. */ |
2433 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2434 | return; |
2435 | ||
7f32a4d5 PA |
2436 | /* For now, if we have any location at the same address that isn't a |
2437 | dprintf, don't install the target-side commands, as that would | |
2438 | make the breakpoint not be reported to the core, and we'd lose | |
41fac0cf PA |
2439 | control. */ |
2440 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2441 | { | |
2442 | loc = (*loc2p); | |
2443 | if (is_breakpoint (loc->owner) | |
2444 | && loc->pspace->num == bl->pspace->num | |
2445 | && loc->owner->type != bp_dprintf) | |
2446 | return; | |
2447 | } | |
2448 | ||
d3ce09f5 SS |
2449 | /* Do a first pass to check for locations with no assigned |
2450 | conditions or conditions that fail to parse to a valid agent expression | |
2451 | bytecode. If any of these happen, then it's no use to send conditions | |
2452 | to the target since this location will always trigger and generate a | |
2453 | response back to GDB. */ | |
2454 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2455 | { | |
2456 | loc = (*loc2p); | |
2457 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2458 | { | |
2459 | if (modified) | |
2460 | { | |
d3ce09f5 SS |
2461 | /* Re-parse the commands since something changed. In that |
2462 | case we already freed the command bytecodes (see | |
2463 | force_breakpoint_reinsertion). We just | |
2464 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2465 | loc->cmd_bytecode |
2466 | = parse_cmd_to_aexpr (bl->address, | |
2467 | loc->owner->extra_string); | |
d3ce09f5 SS |
2468 | } |
2469 | ||
2470 | /* If we have a NULL bytecode expression, it means something | |
2471 | went wrong or we have a null command expression. */ | |
2472 | if (!loc->cmd_bytecode) | |
2473 | { | |
2474 | null_command_or_parse_error = 1; | |
2475 | break; | |
2476 | } | |
2477 | } | |
2478 | } | |
2479 | ||
2480 | /* If anything failed, then we're not doing target-side commands, | |
2481 | and so clean up. */ | |
2482 | if (null_command_or_parse_error) | |
2483 | { | |
2484 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2485 | { | |
2486 | loc = (*loc2p); | |
2487 | if (is_breakpoint (loc->owner) | |
2488 | && loc->pspace->num == bl->pspace->num) | |
2489 | { | |
2490 | /* Only go as far as the first NULL bytecode is | |
2491 | located. */ | |
40fb6c5e | 2492 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2493 | return; |
2494 | ||
833177a4 | 2495 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2496 | } |
2497 | } | |
2498 | } | |
2499 | ||
7f32a4d5 PA |
2500 | /* No NULL commands or failed bytecode generation. Build a command |
2501 | list for all duplicate locations at this location's address. | |
2502 | Note that here we must care for whether the breakpoint location | |
2503 | types are considered duplicates, otherwise, say, if we have a | |
2504 | software and hardware location at the same address, the target | |
2505 | could end up running the commands twice. For the moment, we only | |
2506 | support targets-side commands with dprintf, but it doesn't hurt | |
2507 | to be pedantically correct in case that changes. */ | |
d3ce09f5 SS |
2508 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
2509 | { | |
2510 | loc = (*loc2p); | |
7f32a4d5 PA |
2511 | if (breakpoint_locations_match (bl, loc) |
2512 | && loc->owner->extra_string | |
d3ce09f5 SS |
2513 | && is_breakpoint (loc->owner) |
2514 | && loc->pspace->num == bl->pspace->num | |
2515 | && loc->owner->enable_state == bp_enabled | |
b5fa468f TBA |
2516 | && loc->enabled |
2517 | && !loc->disabled_by_cond) | |
3cde5c42 PA |
2518 | { |
2519 | /* Add the command to the vector. This will be used later | |
2520 | to send the commands to the target. */ | |
2521 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2522 | } | |
d3ce09f5 SS |
2523 | } |
2524 | ||
2525 | bl->target_info.persist = 0; | |
2526 | /* Maybe flag this location as persistent. */ | |
2527 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2528 | bl->target_info.persist = 1; | |
2529 | } | |
2530 | ||
833b7ab5 YQ |
2531 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2532 | of breakpoint according to ADDR except single-step breakpoint. | |
2533 | Get the kind of single-step breakpoint according to the current | |
2534 | registers state. */ | |
cd6c3b4f YQ |
2535 | |
2536 | static int | |
2537 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2538 | { | |
833b7ab5 YQ |
2539 | if (bl->owner->type == bp_single_step) |
2540 | { | |
2541 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2542 | struct regcache *regcache; | |
2543 | ||
00431a78 | 2544 | regcache = get_thread_regcache (thr); |
833b7ab5 YQ |
2545 | |
2546 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2547 | regcache, addr); | |
2548 | } | |
2549 | else | |
2550 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2551 | } |
2552 | ||
35df4500 TJB |
2553 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2554 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2555 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2556 | Returns 0 for success, 1 if the bp_location type is not supported or |
2557 | -1 for failure. | |
879bfdc2 | 2558 | |
4a64f543 MS |
2559 | NOTE drow/2003-09-09: This routine could be broken down to an |
2560 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2561 | static int |
35df4500 | 2562 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2563 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2564 | int *disabled_breaks, |
dd61ec5c MW |
2565 | int *hw_breakpoint_error, |
2566 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2567 | { |
cc06b668 | 2568 | gdb_exception bp_excpt; |
879bfdc2 | 2569 | |
b775012e | 2570 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2571 | return 0; |
2572 | ||
35c63cd8 JB |
2573 | /* Note we don't initialize bl->target_info, as that wipes out |
2574 | the breakpoint location's shadow_contents if the breakpoint | |
2575 | is still inserted at that location. This in turn breaks | |
2576 | target_read_memory which depends on these buffers when | |
2577 | a memory read is requested at the breakpoint location: | |
2578 | Once the target_info has been wiped, we fail to see that | |
2579 | we have a breakpoint inserted at that address and thus | |
2580 | read the breakpoint instead of returning the data saved in | |
2581 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2582 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2583 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2584 | bl->target_info.length = bl->length; |
8181d85f | 2585 | |
b775012e LM |
2586 | /* When working with target-side conditions, we must pass all the conditions |
2587 | for the same breakpoint address down to the target since GDB will not | |
2588 | insert those locations. With a list of breakpoint conditions, the target | |
2589 | can decide when to stop and notify GDB. */ | |
2590 | ||
2591 | if (is_breakpoint (bl->owner)) | |
2592 | { | |
2593 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2594 | build_target_command_list (bl); |
2595 | /* Reset the modification marker. */ | |
b775012e LM |
2596 | bl->needs_update = 0; |
2597 | } | |
2598 | ||
7f32a4d5 PA |
2599 | /* If "set breakpoint auto-hw" is "on" and a software breakpoint was |
2600 | set at a read-only address, then a breakpoint location will have | |
2601 | been changed to hardware breakpoint before we get here. If it is | |
2602 | "off" however, error out before actually trying to insert the | |
2603 | breakpoint, with a nicer error message. */ | |
35df4500 | 2604 | if (bl->loc_type == bp_loc_software_breakpoint |
7f32a4d5 | 2605 | && !automatic_hardware_breakpoints) |
879bfdc2 | 2606 | { |
7f32a4d5 | 2607 | mem_region *mr = lookup_mem_region (bl->address); |
cc59ec59 | 2608 | |
7f32a4d5 PA |
2609 | if (mr != nullptr && mr->attrib.mode != MEM_RW) |
2610 | { | |
2611 | fprintf_unfiltered (tmp_error_stream, | |
2612 | _("Cannot insert breakpoint %d.\n" | |
2613 | "Cannot set software breakpoint " | |
2614 | "at read-only address %s\n"), | |
2615 | bl->owner->number, | |
2616 | paddress (bl->gdbarch, bl->address)); | |
2617 | return 1; | |
765dc015 | 2618 | } |
7f32a4d5 PA |
2619 | } |
2620 | ||
2621 | if (bl->loc_type == bp_loc_software_breakpoint | |
2622 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2623 | { | |
879bfdc2 DJ |
2624 | /* First check to see if we have to handle an overlay. */ |
2625 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2626 | || bl->section == NULL |
2627 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2628 | { |
2629 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2630 | try |
dd61ec5c | 2631 | { |
0000e5cc PA |
2632 | int val; |
2633 | ||
dd61ec5c | 2634 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2635 | if (val) |
688fca4f | 2636 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2637 | } |
94aeb44b | 2638 | catch (gdb_exception &e) |
dd61ec5c | 2639 | { |
94aeb44b | 2640 | bp_excpt = std::move (e); |
dd61ec5c | 2641 | } |
879bfdc2 DJ |
2642 | } |
2643 | else | |
2644 | { | |
4a64f543 | 2645 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2646 | Shall we set a breakpoint at the LMA? */ |
2647 | if (!overlay_events_enabled) | |
2648 | { | |
2649 | /* Yes -- overlay event support is not active, | |
2650 | so we must try to set a breakpoint at the LMA. | |
2651 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2652 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2653 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2654 | bl->owner->number); |
879bfdc2 DJ |
2655 | else |
2656 | { | |
35df4500 TJB |
2657 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2658 | bl->section); | |
879bfdc2 | 2659 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2660 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2661 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2662 | |
2663 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2664 | try |
0000e5cc PA |
2665 | { |
2666 | int val; | |
2667 | ||
579c6ad9 | 2668 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2669 | = breakpoint_kind (bl, &addr); |
2670 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2671 | val = target_insert_breakpoint (bl->gdbarch, |
2672 | &bl->overlay_target_info); | |
2673 | if (val) | |
688fca4f PA |
2674 | bp_excpt |
2675 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2676 | } |
94aeb44b | 2677 | catch (gdb_exception &e) |
0000e5cc | 2678 | { |
94aeb44b | 2679 | bp_excpt = std::move (e); |
0000e5cc PA |
2680 | } |
2681 | ||
688fca4f | 2682 | if (bp_excpt.reason != 0) |
99361f52 | 2683 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2684 | "Overlay breakpoint %d " |
2685 | "failed: in ROM?\n", | |
35df4500 | 2686 | bl->owner->number); |
879bfdc2 DJ |
2687 | } |
2688 | } | |
2689 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2690 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2691 | { |
2692 | /* Yes. This overlay section is mapped into memory. */ | |
a70b8144 | 2693 | try |
dda83cd7 | 2694 | { |
0000e5cc PA |
2695 | int val; |
2696 | ||
dda83cd7 | 2697 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2698 | if (val) |
688fca4f | 2699 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dda83cd7 | 2700 | } |
94aeb44b | 2701 | catch (gdb_exception &e) |
dda83cd7 | 2702 | { |
94aeb44b | 2703 | bp_excpt = std::move (e); |
dda83cd7 | 2704 | } |
879bfdc2 DJ |
2705 | } |
2706 | else | |
2707 | { | |
2708 | /* No. This breakpoint will not be inserted. | |
2709 | No error, but do not mark the bp as 'inserted'. */ | |
2710 | return 0; | |
2711 | } | |
2712 | } | |
2713 | ||
688fca4f | 2714 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2715 | { |
2716 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2717 | |
2718 | /* In some cases, we might not be able to insert a | |
2719 | breakpoint in a shared library that has already been | |
2720 | removed, but we have not yet processed the shlib unload | |
2721 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2722 | breakpoint insertion themselves can't tell why the |
2723 | breakpoint insertion failed (e.g., the remote target | |
2724 | doesn't define error codes), so we must treat generic | |
2725 | errors as memory errors. */ | |
688fca4f PA |
2726 | if (bp_excpt.reason == RETURN_ERROR |
2727 | && (bp_excpt.error == GENERIC_ERROR | |
2728 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2729 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2730 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2731 | || shared_objfile_contains_address_p (bl->pspace, |
2732 | bl->address))) | |
879bfdc2 | 2733 | { |
4a64f543 | 2734 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2735 | bl->shlib_disabled = 1; |
76727919 | 2736 | gdb::observers::breakpoint_modified.notify (bl->owner); |
3fbb6ffa TJB |
2737 | if (!*disabled_breaks) |
2738 | { | |
2739 | fprintf_unfiltered (tmp_error_stream, | |
2740 | "Cannot insert breakpoint %d.\n", | |
2741 | bl->owner->number); | |
2742 | fprintf_unfiltered (tmp_error_stream, | |
2743 | "Temporarily disabling shared " | |
2744 | "library breakpoints:\n"); | |
2745 | } | |
2746 | *disabled_breaks = 1; | |
879bfdc2 | 2747 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2748 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2749 | return 0; |
879bfdc2 DJ |
2750 | } |
2751 | else | |
879bfdc2 | 2752 | { |
35df4500 | 2753 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2754 | { |
0000e5cc | 2755 | *hw_breakpoint_error = 1; |
688fca4f | 2756 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
dda83cd7 SM |
2757 | fprintf_unfiltered (tmp_error_stream, |
2758 | "Cannot insert hardware breakpoint %d%s", | |
2759 | bl->owner->number, | |
688fca4f | 2760 | bp_excpt.message ? ":" : ".\n"); |
dda83cd7 SM |
2761 | if (bp_excpt.message != NULL) |
2762 | fprintf_unfiltered (tmp_error_stream, "%s.\n", | |
3d6e9d23 | 2763 | bp_excpt.what ()); |
879bfdc2 DJ |
2764 | } |
2765 | else | |
2766 | { | |
688fca4f | 2767 | if (bp_excpt.message == NULL) |
0000e5cc | 2768 | { |
1ccbe998 | 2769 | std::string message |
0000e5cc PA |
2770 | = memory_error_message (TARGET_XFER_E_IO, |
2771 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2772 | |
2773 | fprintf_unfiltered (tmp_error_stream, | |
2774 | "Cannot insert breakpoint %d.\n" | |
2775 | "%s\n", | |
1ccbe998 | 2776 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2777 | } |
2778 | else | |
2779 | { | |
2780 | fprintf_unfiltered (tmp_error_stream, | |
2781 | "Cannot insert breakpoint %d: %s\n", | |
2782 | bl->owner->number, | |
3d6e9d23 | 2783 | bp_excpt.what ()); |
0000e5cc | 2784 | } |
879bfdc2 | 2785 | } |
0000e5cc | 2786 | return 1; |
879bfdc2 DJ |
2787 | |
2788 | } | |
2789 | } | |
2790 | else | |
35df4500 | 2791 | bl->inserted = 1; |
879bfdc2 | 2792 | |
0000e5cc | 2793 | return 0; |
879bfdc2 DJ |
2794 | } |
2795 | ||
35df4500 | 2796 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2797 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2798 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2799 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2800 | { |
0000e5cc PA |
2801 | int val; |
2802 | ||
77b06cd7 TJB |
2803 | gdb_assert (bl->owner->ops != NULL |
2804 | && bl->owner->ops->insert_location != NULL); | |
2805 | ||
2806 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2807 | |
2808 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2809 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2810 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2811 | { |
2812 | struct bp_location *loc, **loc_temp; | |
2813 | ||
2814 | /* But don't try to insert it, if there's already another | |
2815 | hw_access location that would be considered a duplicate | |
2816 | of this one. */ | |
2817 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2818 | if (loc != bl |
85d721b8 | 2819 | && loc->watchpoint_type == hw_access |
35df4500 | 2820 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2821 | { |
35df4500 TJB |
2822 | bl->duplicate = 1; |
2823 | bl->inserted = 1; | |
2824 | bl->target_info = loc->target_info; | |
2825 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2826 | val = 0; |
2827 | break; | |
2828 | } | |
2829 | ||
2830 | if (val == 1) | |
2831 | { | |
77b06cd7 TJB |
2832 | bl->watchpoint_type = hw_access; |
2833 | val = bl->owner->ops->insert_location (bl); | |
2834 | ||
2835 | if (val) | |
2836 | /* Back to the original value. */ | |
2837 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2838 | } |
2839 | } | |
2840 | ||
35df4500 | 2841 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2842 | } |
2843 | ||
35df4500 | 2844 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2845 | { |
0000e5cc PA |
2846 | int val; |
2847 | ||
77b06cd7 TJB |
2848 | gdb_assert (bl->owner->ops != NULL |
2849 | && bl->owner->ops->insert_location != NULL); | |
2850 | ||
2851 | val = bl->owner->ops->insert_location (bl); | |
2852 | if (val) | |
2853 | { | |
2854 | bl->owner->enable_state = bp_disabled; | |
2855 | ||
2856 | if (val == 1) | |
2857 | warning (_("\ | |
2858 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2859 | of catchpoint."), bl->owner->number); | |
2860 | else | |
2861 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2862 | } | |
2863 | ||
2864 | bl->inserted = (val == 0); | |
1640b821 DJ |
2865 | |
2866 | /* We've already printed an error message if there was a problem | |
2867 | inserting this catchpoint, and we've disabled the catchpoint, | |
2868 | so just return success. */ | |
2869 | return 0; | |
879bfdc2 DJ |
2870 | } |
2871 | ||
2872 | return 0; | |
2873 | } | |
2874 | ||
6c95b8df PA |
2875 | /* This function is called when program space PSPACE is about to be |
2876 | deleted. It takes care of updating breakpoints to not reference | |
2877 | PSPACE anymore. */ | |
2878 | ||
2879 | void | |
2880 | breakpoint_program_space_exit (struct program_space *pspace) | |
2881 | { | |
2882 | struct breakpoint *b, *b_temp; | |
876fa593 | 2883 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2884 | |
2885 | /* Remove any breakpoint that was set through this program space. */ | |
2886 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2887 | { | |
2888 | if (b->pspace == pspace) | |
2889 | delete_breakpoint (b); | |
2890 | } | |
2891 | ||
2892 | /* Breakpoints set through other program spaces could have locations | |
2893 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2894 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2895 | { |
2896 | struct bp_location *tmp; | |
2897 | ||
2898 | if (loc->pspace == pspace) | |
2899 | { | |
2bdf28a0 | 2900 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2901 | if (loc->owner->loc == loc) |
2902 | loc->owner->loc = loc->next; | |
2903 | else | |
2904 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2905 | if (tmp->next == loc) | |
2906 | { | |
2907 | tmp->next = loc->next; | |
2908 | break; | |
2909 | } | |
2910 | } | |
2911 | } | |
2912 | ||
2913 | /* Now update the global location list to permanently delete the | |
2914 | removed locations above. */ | |
44702360 | 2915 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2916 | } |
2917 | ||
74960c60 VP |
2918 | /* Make sure all breakpoints are inserted in inferior. |
2919 | Throws exception on any error. | |
2920 | A breakpoint that is already inserted won't be inserted | |
2921 | again, so calling this function twice is safe. */ | |
2922 | void | |
2923 | insert_breakpoints (void) | |
2924 | { | |
2925 | struct breakpoint *bpt; | |
2926 | ||
2927 | ALL_BREAKPOINTS (bpt) | |
2928 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2929 | { |
2930 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2931 | ||
2932 | update_watchpoint (w, 0 /* don't reparse. */); | |
2933 | } | |
74960c60 | 2934 | |
04086b45 PA |
2935 | /* Updating watchpoints creates new locations, so update the global |
2936 | location list. Explicitly tell ugll to insert locations and | |
7f32a4d5 PA |
2937 | ignore breakpoints_always_inserted_mode. Also, |
2938 | update_global_location_list tries to "upgrade" software | |
2939 | breakpoints to hardware breakpoints to handle "set breakpoint | |
2940 | auto-hw", so we need to call it even if we don't have new | |
2941 | locations. */ | |
04086b45 | 2942 | update_global_location_list (UGLL_INSERT); |
74960c60 VP |
2943 | } |
2944 | ||
20388dd6 YQ |
2945 | /* Invoke CALLBACK for each of bp_location. */ |
2946 | ||
2947 | void | |
2948 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2949 | { | |
2950 | struct bp_location *loc, **loc_tmp; | |
2951 | ||
2952 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2953 | { | |
2954 | callback (loc, NULL); | |
2955 | } | |
2956 | } | |
2957 | ||
b775012e LM |
2958 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2959 | target. It is the case with deleting and disabling of breakpoints when using | |
2960 | always-inserted mode. */ | |
2961 | ||
2962 | static void | |
2963 | update_inserted_breakpoint_locations (void) | |
2964 | { | |
2965 | struct bp_location *bl, **blp_tmp; | |
2966 | int error_flag = 0; | |
2967 | int val = 0; | |
2968 | int disabled_breaks = 0; | |
2969 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2970 | int hw_bp_details_reported = 0; |
b775012e | 2971 | |
d7e74731 | 2972 | string_file tmp_error_stream; |
b775012e LM |
2973 | |
2974 | /* Explicitly mark the warning -- this will only be printed if | |
2975 | there was an error. */ | |
d7e74731 | 2976 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2977 | |
5ed8105e | 2978 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2979 | |
2980 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2981 | { | |
2982 | /* We only want to update software breakpoints and hardware | |
2983 | breakpoints. */ | |
2984 | if (!is_breakpoint (bl->owner)) | |
2985 | continue; | |
2986 | ||
2987 | /* We only want to update locations that are already inserted | |
2988 | and need updating. This is to avoid unwanted insertion during | |
2989 | deletion of breakpoints. */ | |
4daf1902 | 2990 | if (!bl->inserted || !bl->needs_update) |
b775012e LM |
2991 | continue; |
2992 | ||
2993 | switch_to_program_space_and_thread (bl->pspace); | |
2994 | ||
2995 | /* For targets that support global breakpoints, there's no need | |
2996 | to select an inferior to insert breakpoint to. In fact, even | |
2997 | if we aren't attached to any process yet, we should still | |
2998 | insert breakpoints. */ | |
f5656ead | 2999 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
55f6301a | 3000 | && (inferior_ptid == null_ptid || !target_has_execution ())) |
b775012e LM |
3001 | continue; |
3002 | ||
d7e74731 | 3003 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3004 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3005 | if (val) |
3006 | error_flag = val; | |
3007 | } | |
3008 | ||
3009 | if (error_flag) | |
3010 | { | |
223ffa71 | 3011 | target_terminal::ours_for_output (); |
b775012e LM |
3012 | error_stream (tmp_error_stream); |
3013 | } | |
b775012e LM |
3014 | } |
3015 | ||
c30eee59 | 3016 | /* Used when starting or continuing the program. */ |
c906108c | 3017 | |
74960c60 VP |
3018 | static void |
3019 | insert_breakpoint_locations (void) | |
c906108c | 3020 | { |
a5606eee | 3021 | struct breakpoint *bpt; |
35df4500 | 3022 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3023 | int error_flag = 0; |
c906108c | 3024 | int val = 0; |
3fbb6ffa | 3025 | int disabled_breaks = 0; |
81d0cc19 | 3026 | int hw_breakpoint_error = 0; |
dd61ec5c | 3027 | int hw_bp_error_explained_already = 0; |
c906108c | 3028 | |
d7e74731 PA |
3029 | string_file tmp_error_stream; |
3030 | ||
81d0cc19 GS |
3031 | /* Explicitly mark the warning -- this will only be printed if |
3032 | there was an error. */ | |
d7e74731 | 3033 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3034 | |
5ed8105e | 3035 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3036 | |
35df4500 | 3037 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3038 | { |
b775012e | 3039 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3040 | continue; |
3041 | ||
4a64f543 MS |
3042 | /* There is no point inserting thread-specific breakpoints if |
3043 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3044 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3045 | if (bl->owner->thread != -1 |
5d5658a1 | 3046 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3047 | continue; |
3048 | ||
35df4500 | 3049 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3050 | |
3051 | /* For targets that support global breakpoints, there's no need | |
3052 | to select an inferior to insert breakpoint to. In fact, even | |
3053 | if we aren't attached to any process yet, we should still | |
3054 | insert breakpoints. */ | |
f5656ead | 3055 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
55f6301a | 3056 | && (inferior_ptid == null_ptid || !target_has_execution ())) |
6c95b8df PA |
3057 | continue; |
3058 | ||
d7e74731 | 3059 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3060 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3061 | if (val) |
eacd795a | 3062 | error_flag = val; |
879bfdc2 | 3063 | } |
c906108c | 3064 | |
4a64f543 MS |
3065 | /* If we failed to insert all locations of a watchpoint, remove |
3066 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3067 | ALL_BREAKPOINTS (bpt) |
3068 | { | |
3069 | int some_failed = 0; | |
3070 | struct bp_location *loc; | |
3071 | ||
3072 | if (!is_hardware_watchpoint (bpt)) | |
3073 | continue; | |
3074 | ||
d6b74ac4 | 3075 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3076 | continue; |
74960c60 VP |
3077 | |
3078 | if (bpt->disposition == disp_del_at_next_stop) | |
3079 | continue; | |
a5606eee VP |
3080 | |
3081 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3082 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3083 | { |
3084 | some_failed = 1; | |
3085 | break; | |
3086 | } | |
3087 | if (some_failed) | |
3088 | { | |
3089 | for (loc = bpt->loc; loc; loc = loc->next) | |
3090 | if (loc->inserted) | |
834c0d03 | 3091 | remove_breakpoint (loc); |
a5606eee VP |
3092 | |
3093 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3094 | tmp_error_stream.printf ("Could not insert " |
3095 | "hardware watchpoint %d.\n", | |
3096 | bpt->number); | |
eacd795a | 3097 | error_flag = -1; |
a5606eee VP |
3098 | } |
3099 | } | |
3100 | ||
eacd795a | 3101 | if (error_flag) |
81d0cc19 GS |
3102 | { |
3103 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
dda83cd7 | 3104 | message about possibly exhausted resources. */ |
dd61ec5c | 3105 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3106 | { |
d7e74731 | 3107 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3108 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3109 | } |
223ffa71 | 3110 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3111 | error_stream (tmp_error_stream); |
3112 | } | |
c906108c SS |
3113 | } |
3114 | ||
c30eee59 TJB |
3115 | /* Used when the program stops. |
3116 | Returns zero if successful, or non-zero if there was a problem | |
3117 | removing a breakpoint location. */ | |
3118 | ||
c906108c | 3119 | int |
fba45db2 | 3120 | remove_breakpoints (void) |
c906108c | 3121 | { |
35df4500 | 3122 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3123 | int val = 0; |
c906108c | 3124 | |
35df4500 | 3125 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3126 | { |
1e4d1764 | 3127 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3128 | val |= remove_breakpoint (bl); |
c5aa993b | 3129 | } |
3a1bae8e | 3130 | return val; |
c906108c SS |
3131 | } |
3132 | ||
49fa26b0 PA |
3133 | /* When a thread exits, remove breakpoints that are related to |
3134 | that thread. */ | |
3135 | ||
3136 | static void | |
3137 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3138 | { | |
3139 | struct breakpoint *b, *b_tmp; | |
3140 | ||
3141 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3142 | { | |
5d5658a1 | 3143 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3144 | { |
3145 | b->disposition = disp_del_at_next_stop; | |
3146 | ||
3147 | printf_filtered (_("\ | |
43792cf0 PA |
3148 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3149 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3150 | |
3151 | /* Hide it from the user. */ | |
3152 | b->number = 0; | |
3153 | } | |
3154 | } | |
3155 | } | |
3156 | ||
f3869b1a | 3157 | /* See breakpoint.h. */ |
6c95b8df | 3158 | |
f3869b1a | 3159 | void |
00431a78 | 3160 | remove_breakpoints_inf (inferior *inf) |
6c95b8df | 3161 | { |
35df4500 | 3162 | struct bp_location *bl, **blp_tmp; |
6c95b8df | 3163 | int val; |
6c95b8df | 3164 | |
35df4500 | 3165 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3166 | { |
35df4500 | 3167 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3168 | continue; |
3169 | ||
fc126975 | 3170 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3171 | { |
834c0d03 | 3172 | val = remove_breakpoint (bl); |
6c95b8df | 3173 | if (val != 0) |
f3869b1a | 3174 | return; |
6c95b8df PA |
3175 | } |
3176 | } | |
6c95b8df PA |
3177 | } |
3178 | ||
e58b0e63 PA |
3179 | static int internal_breakpoint_number = -1; |
3180 | ||
84f4c1fe PM |
3181 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3182 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3183 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3184 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3185 | breakpoint_count and that value incremented. Internal breakpoints |
3186 | do not set the internal var bpnum. */ | |
3187 | static void | |
3188 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3189 | { | |
3190 | if (internal) | |
3191 | b->number = internal_breakpoint_number--; | |
3192 | else | |
3193 | { | |
3194 | set_breakpoint_count (breakpoint_count + 1); | |
3195 | b->number = breakpoint_count; | |
3196 | } | |
3197 | } | |
3198 | ||
e62c965a | 3199 | static struct breakpoint * |
a6d9a66e | 3200 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3201 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3202 | const struct breakpoint_ops *ops) |
e62c965a | 3203 | { |
51abb421 | 3204 | symtab_and_line sal; |
e62c965a PP |
3205 | sal.pc = address; |
3206 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3207 | sal.pspace = current_program_space; |
e62c965a | 3208 | |
51abb421 | 3209 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3210 | b->number = internal_breakpoint_number--; |
3211 | b->disposition = disp_donttouch; | |
3212 | ||
3213 | return b; | |
3214 | } | |
3215 | ||
17450429 PP |
3216 | static const char *const longjmp_names[] = |
3217 | { | |
3218 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3219 | }; | |
3220 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3221 | ||
3222 | /* Per-objfile data private to breakpoint.c. */ | |
3223 | struct breakpoint_objfile_data | |
3224 | { | |
3225 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
43dce439 | 3226 | struct bound_minimal_symbol overlay_msym {}; |
17450429 PP |
3227 | |
3228 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
43dce439 | 3229 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
17450429 | 3230 | |
28106bc2 | 3231 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3232 | int longjmp_searched = 0; |
28106bc2 | 3233 | |
45461e0d SM |
3234 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3235 | references. */ | |
3236 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3237 | |
17450429 | 3238 | /* Minimal symbol for "std::terminate()" (if any). */ |
43dce439 | 3239 | struct bound_minimal_symbol terminate_msym {}; |
17450429 PP |
3240 | |
3241 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
43dce439 | 3242 | struct bound_minimal_symbol exception_msym {}; |
28106bc2 SDJ |
3243 | |
3244 | /* True if we have looked for exception probes. */ | |
43dce439 | 3245 | int exception_searched = 0; |
28106bc2 | 3246 | |
45461e0d SM |
3247 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3248 | references. */ | |
3249 | std::vector<probe *> exception_probes; | |
17450429 PP |
3250 | }; |
3251 | ||
51d3063a TT |
3252 | static const struct objfile_key<breakpoint_objfile_data> |
3253 | breakpoint_objfile_key; | |
17450429 PP |
3254 | |
3255 | /* Minimal symbol not found sentinel. */ | |
3256 | static struct minimal_symbol msym_not_found; | |
3257 | ||
3258 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3259 | ||
3260 | static int | |
3261 | msym_not_found_p (const struct minimal_symbol *msym) | |
3262 | { | |
3263 | return msym == &msym_not_found; | |
3264 | } | |
3265 | ||
3266 | /* Return per-objfile data needed by breakpoint.c. | |
3267 | Allocate the data if necessary. */ | |
3268 | ||
3269 | static struct breakpoint_objfile_data * | |
3270 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3271 | { | |
3272 | struct breakpoint_objfile_data *bp_objfile_data; | |
3273 | ||
51d3063a | 3274 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
17450429 | 3275 | if (bp_objfile_data == NULL) |
51d3063a | 3276 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
17450429 PP |
3277 | return bp_objfile_data; |
3278 | } | |
3279 | ||
e62c965a | 3280 | static void |
af02033e | 3281 | create_overlay_event_breakpoint (void) |
e62c965a | 3282 | { |
af02033e | 3283 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3284 | |
2030c079 | 3285 | for (objfile *objfile : current_program_space->objfiles ()) |
69de3c6a PP |
3286 | { |
3287 | struct breakpoint *b; | |
17450429 PP |
3288 | struct breakpoint_objfile_data *bp_objfile_data; |
3289 | CORE_ADDR addr; | |
67994074 | 3290 | struct explicit_location explicit_loc; |
69de3c6a | 3291 | |
17450429 PP |
3292 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3293 | ||
3b7344d5 | 3294 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3295 | continue; |
3296 | ||
3b7344d5 | 3297 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3298 | { |
3b7344d5 | 3299 | struct bound_minimal_symbol m; |
17450429 PP |
3300 | |
3301 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3302 | if (m.minsym == NULL) |
17450429 PP |
3303 | { |
3304 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3305 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3306 | continue; |
3307 | } | |
3308 | bp_objfile_data->overlay_msym = m; | |
3309 | } | |
e62c965a | 3310 | |
77e371c0 | 3311 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
08feed99 | 3312 | b = create_internal_breakpoint (objfile->arch (), addr, |
dda83cd7 | 3313 | bp_overlay_event, |
06edf0c0 | 3314 | &internal_breakpoint_ops); |
67994074 KS |
3315 | initialize_explicit_location (&explicit_loc); |
3316 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3317 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3318 | |
69de3c6a | 3319 | if (overlay_debugging == ovly_auto) |
dda83cd7 SM |
3320 | { |
3321 | b->enable_state = bp_enabled; | |
3322 | overlay_events_enabled = 1; | |
3323 | } | |
69de3c6a PP |
3324 | else |
3325 | { | |
dda83cd7 SM |
3326 | b->enable_state = bp_disabled; |
3327 | overlay_events_enabled = 0; | |
69de3c6a | 3328 | } |
e62c965a | 3329 | } |
e62c965a PP |
3330 | } |
3331 | ||
0fd8e87f | 3332 | static void |
af02033e | 3333 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3334 | { |
5ed8105e | 3335 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3336 | |
94c93c35 TT |
3337 | for (struct program_space *pspace : program_spaces) |
3338 | { | |
3339 | set_current_program_space (pspace); | |
af02033e | 3340 | |
94c93c35 TT |
3341 | for (objfile *objfile : current_program_space->objfiles ()) |
3342 | { | |
3343 | int i; | |
3344 | struct gdbarch *gdbarch; | |
3345 | struct breakpoint_objfile_data *bp_objfile_data; | |
0fd8e87f | 3346 | |
94c93c35 | 3347 | gdbarch = objfile->arch (); |
0fd8e87f | 3348 | |
94c93c35 | 3349 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
17450429 | 3350 | |
94c93c35 TT |
3351 | if (!bp_objfile_data->longjmp_searched) |
3352 | { | |
3353 | std::vector<probe *> ret | |
3354 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
25f9533e | 3355 | |
94c93c35 TT |
3356 | if (!ret.empty ()) |
3357 | { | |
3358 | /* We are only interested in checking one element. */ | |
3359 | probe *p = ret[0]; | |
aed57c53 | 3360 | |
94c93c35 TT |
3361 | if (!p->can_evaluate_arguments ()) |
3362 | { | |
3363 | /* We cannot use the probe interface here, | |
3364 | because it does not know how to evaluate | |
3365 | arguments. */ | |
3366 | ret.clear (); | |
3367 | } | |
3368 | } | |
3369 | bp_objfile_data->longjmp_probes = ret; | |
3370 | bp_objfile_data->longjmp_searched = 1; | |
3371 | } | |
25f9533e | 3372 | |
94c93c35 TT |
3373 | if (!bp_objfile_data->longjmp_probes.empty ()) |
3374 | { | |
3375 | for (probe *p : bp_objfile_data->longjmp_probes) | |
3376 | { | |
3377 | struct breakpoint *b; | |
3378 | ||
3379 | b = create_internal_breakpoint (gdbarch, | |
3380 | p->get_relocated_address (objfile), | |
3381 | bp_longjmp_master, | |
3382 | &internal_breakpoint_ops); | |
3383 | b->location = new_probe_location ("-probe-stap libc:longjmp"); | |
3384 | b->enable_state = bp_disabled; | |
3385 | } | |
28106bc2 | 3386 | |
94c93c35 TT |
3387 | continue; |
3388 | } | |
28106bc2 | 3389 | |
94c93c35 TT |
3390 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3391 | continue; | |
28106bc2 | 3392 | |
94c93c35 TT |
3393 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
3394 | { | |
3395 | struct breakpoint *b; | |
3396 | const char *func_name; | |
3397 | CORE_ADDR addr; | |
3398 | struct explicit_location explicit_loc; | |
0fd8e87f | 3399 | |
94c93c35 TT |
3400 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
3401 | continue; | |
17450429 | 3402 | |
94c93c35 TT |
3403 | func_name = longjmp_names[i]; |
3404 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) | |
3405 | { | |
3406 | struct bound_minimal_symbol m; | |
aed57c53 | 3407 | |
94c93c35 TT |
3408 | m = lookup_minimal_symbol_text (func_name, objfile); |
3409 | if (m.minsym == NULL) | |
3410 | { | |
3411 | /* Prevent future lookups in this objfile. */ | |
3412 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; | |
3413 | continue; | |
3414 | } | |
3415 | bp_objfile_data->longjmp_msym[i] = m; | |
3416 | } | |
17450429 | 3417 | |
94c93c35 TT |
3418 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
3419 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, | |
3420 | &internal_breakpoint_ops); | |
3421 | initialize_explicit_location (&explicit_loc); | |
3422 | explicit_loc.function_name = ASTRDUP (func_name); | |
3423 | b->location = new_explicit_location (&explicit_loc); | |
3424 | b->enable_state = bp_disabled; | |
3425 | } | |
3426 | } | |
3427 | } | |
0fd8e87f UW |
3428 | } |
3429 | ||
af02033e | 3430 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3431 | static void |
af02033e | 3432 | create_std_terminate_master_breakpoint (void) |
aa7d318d | 3433 | { |
af02033e | 3434 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3435 | |
5ed8105e | 3436 | scoped_restore_current_program_space restore_pspace; |
aa7d318d | 3437 | |
94c93c35 TT |
3438 | for (struct program_space *pspace : program_spaces) |
3439 | { | |
3440 | CORE_ADDR addr; | |
17450429 | 3441 | |
94c93c35 | 3442 | set_current_program_space (pspace); |
17450429 | 3443 | |
94c93c35 TT |
3444 | for (objfile *objfile : current_program_space->objfiles ()) |
3445 | { | |
3446 | struct breakpoint *b; | |
3447 | struct breakpoint_objfile_data *bp_objfile_data; | |
3448 | struct explicit_location explicit_loc; | |
aa7d318d | 3449 | |
94c93c35 | 3450 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3451 | |
94c93c35 TT |
3452 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
3453 | continue; | |
17450429 | 3454 | |
94c93c35 TT |
3455 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
3456 | { | |
3457 | struct bound_minimal_symbol m; | |
17450429 | 3458 | |
94c93c35 TT |
3459 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
3460 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text | |
3461 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
3462 | { | |
3463 | /* Prevent future lookups in this objfile. */ | |
3464 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; | |
3465 | continue; | |
3466 | } | |
3467 | bp_objfile_data->terminate_msym = m; | |
3468 | } | |
aa7d318d | 3469 | |
94c93c35 TT |
3470 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3471 | b = create_internal_breakpoint (objfile->arch (), addr, | |
3472 | bp_std_terminate_master, | |
3473 | &internal_breakpoint_ops); | |
3474 | initialize_explicit_location (&explicit_loc); | |
3475 | explicit_loc.function_name = ASTRDUP (func_name); | |
3476 | b->location = new_explicit_location (&explicit_loc); | |
3477 | b->enable_state = bp_disabled; | |
3478 | } | |
3479 | } | |
aa7d318d TT |
3480 | } |
3481 | ||
186c406b TT |
3482 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3483 | ||
70221824 | 3484 | static void |
186c406b TT |
3485 | create_exception_master_breakpoint (void) |
3486 | { | |
17450429 | 3487 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b | 3488 | |
2030c079 | 3489 | for (objfile *objfile : current_program_space->objfiles ()) |
186c406b | 3490 | { |
17450429 PP |
3491 | struct breakpoint *b; |
3492 | struct gdbarch *gdbarch; | |
3493 | struct breakpoint_objfile_data *bp_objfile_data; | |
3494 | CORE_ADDR addr; | |
67994074 | 3495 | struct explicit_location explicit_loc; |
17450429 PP |
3496 | |
3497 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3498 | ||
28106bc2 SDJ |
3499 | /* We prefer the SystemTap probe point if it exists. */ |
3500 | if (!bp_objfile_data->exception_searched) | |
3501 | { | |
45461e0d SM |
3502 | std::vector<probe *> ret |
3503 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
25f9533e | 3504 | |
45461e0d | 3505 | if (!ret.empty ()) |
25f9533e SDJ |
3506 | { |
3507 | /* We are only interested in checking one element. */ | |
45461e0d | 3508 | probe *p = ret[0]; |
25f9533e | 3509 | |
935676c9 | 3510 | if (!p->can_evaluate_arguments ()) |
25f9533e SDJ |
3511 | { |
3512 | /* We cannot use the probe interface here, because it does | |
3513 | not know how to evaluate arguments. */ | |
45461e0d | 3514 | ret.clear (); |
25f9533e SDJ |
3515 | } |
3516 | } | |
3517 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3518 | bp_objfile_data->exception_searched = 1; |
3519 | } | |
3520 | ||
45461e0d | 3521 | if (!bp_objfile_data->exception_probes.empty ()) |
28106bc2 | 3522 | { |
08feed99 | 3523 | gdbarch = objfile->arch (); |
45461e0d SM |
3524 | |
3525 | for (probe *p : bp_objfile_data->exception_probes) | |
28106bc2 | 3526 | { |
729662a5 | 3527 | b = create_internal_breakpoint (gdbarch, |
935676c9 | 3528 | p->get_relocated_address (objfile), |
28106bc2 SDJ |
3529 | bp_exception_master, |
3530 | &internal_breakpoint_ops); | |
d28cd78a | 3531 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3532 | b->enable_state = bp_disabled; |
3533 | } | |
3534 | ||
3535 | continue; | |
3536 | } | |
3537 | ||
3538 | /* Otherwise, try the hook function. */ | |
3539 | ||
3b7344d5 | 3540 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3541 | continue; |
3542 | ||
08feed99 | 3543 | gdbarch = objfile->arch (); |
186c406b | 3544 | |
3b7344d5 | 3545 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3546 | { |
3b7344d5 | 3547 | struct bound_minimal_symbol debug_hook; |
186c406b | 3548 | |
17450429 | 3549 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3550 | if (debug_hook.minsym == NULL) |
17450429 | 3551 | { |
3b7344d5 | 3552 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3553 | continue; |
3554 | } | |
3555 | ||
3556 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3557 | } |
17450429 | 3558 | |
77e371c0 | 3559 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
8b88a78e PA |
3560 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3561 | current_top_target ()); | |
06edf0c0 PA |
3562 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3563 | &internal_breakpoint_ops); | |
67994074 KS |
3564 | initialize_explicit_location (&explicit_loc); |
3565 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3566 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3567 | b->enable_state = bp_disabled; |
186c406b | 3568 | } |
186c406b TT |
3569 | } |
3570 | ||
9ef9e6a6 KS |
3571 | /* Does B have a location spec? */ |
3572 | ||
3573 | static int | |
3574 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3575 | { | |
d28cd78a | 3576 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3577 | } |
3578 | ||
c906108c | 3579 | void |
fba45db2 | 3580 | update_breakpoints_after_exec (void) |
c906108c | 3581 | { |
35df4500 | 3582 | struct breakpoint *b, *b_tmp; |
876fa593 | 3583 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3584 | |
25b22b0a PA |
3585 | /* We're about to delete breakpoints from GDB's lists. If the |
3586 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3587 | writing the breakpoints' "shadow contents" back into memory. The | |
3588 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3589 | do that. Instead, the target is responsible from marking | |
3590 | breakpoints out as soon as it detects an exec. We don't do that | |
3591 | here instead, because there may be other attempts to delete | |
3592 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3593 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3594 | if (bploc->pspace == current_program_space) |
3595 | gdb_assert (!bploc->inserted); | |
c906108c | 3596 | |
35df4500 | 3597 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3598 | { |
6c95b8df PA |
3599 | if (b->pspace != current_program_space) |
3600 | continue; | |
3601 | ||
4a64f543 | 3602 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3603 | if (b->type == bp_shlib_event) |
3604 | { | |
3605 | delete_breakpoint (b); | |
3606 | continue; | |
3607 | } | |
c906108c | 3608 | |
4a64f543 | 3609 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3610 | if (b->type == bp_jit_event) |
3611 | { | |
3612 | delete_breakpoint (b); | |
3613 | continue; | |
3614 | } | |
3615 | ||
1900040c | 3616 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3617 | as must overlay event and longjmp master breakpoints. */ |
3618 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3619 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3620 | || b->type == bp_exception_master) | |
c4093a6a JM |
3621 | { |
3622 | delete_breakpoint (b); | |
3623 | continue; | |
3624 | } | |
3625 | ||
4a64f543 | 3626 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3627 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3628 | { |
3629 | delete_breakpoint (b); | |
3630 | continue; | |
3631 | } | |
3632 | ||
7c16b83e PA |
3633 | /* Just like single-step breakpoints. */ |
3634 | if (b->type == bp_single_step) | |
3635 | { | |
3636 | delete_breakpoint (b); | |
3637 | continue; | |
3638 | } | |
3639 | ||
611c83ae PA |
3640 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3641 | after an exec. */ | |
186c406b | 3642 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3643 | || b->type == bp_longjmp_call_dummy |
186c406b | 3644 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3645 | { |
3646 | delete_breakpoint (b); | |
3647 | continue; | |
3648 | } | |
3649 | ||
ce78b96d JB |
3650 | if (b->type == bp_catchpoint) |
3651 | { | |
dda83cd7 SM |
3652 | /* For now, none of the bp_catchpoint breakpoints need to |
3653 | do anything at this point. In the future, if some of | |
3654 | the catchpoints need to something, we will need to add | |
3655 | a new method, and call this method from here. */ | |
3656 | continue; | |
ce78b96d JB |
3657 | } |
3658 | ||
c5aa993b JM |
3659 | /* bp_finish is a special case. The only way we ought to be able |
3660 | to see one of these when an exec() has happened, is if the user | |
3661 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3662 | carries them to the call-site of the current callee, by setting | |
3663 | a temporary bp there and resuming. But in this case, the finish | |
3664 | will carry them entirely through the vfork & exec. | |
3665 | ||
3666 | We don't want to allow a bp_finish to remain inserted now. But | |
3667 | we can't safely delete it, 'cause finish_command has a handle to | |
3668 | the bp on a bpstat, and will later want to delete it. There's a | |
3669 | chance (and I've seen it happen) that if we delete the bp_finish | |
3670 | here, that its storage will get reused by the time finish_command | |
3671 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3672 | We really must allow finish_command to delete a bp_finish. | |
3673 | ||
e5dd4106 | 3674 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3675 | it's safe to delete something others may have handles to?" |
3676 | problem, what we'll do here is just uninsert the bp_finish, and | |
3677 | let finish_command delete it. | |
3678 | ||
3679 | (We know the bp_finish is "doomed" in the sense that it's | |
3680 | momentary, and will be deleted as soon as finish_command sees | |
3681 | the inferior stopped. So it doesn't matter that the bp's | |
3682 | address is probably bogus in the new a.out, unlike e.g., the | |
3683 | solib breakpoints.) */ | |
c5aa993b | 3684 | |
c5aa993b JM |
3685 | if (b->type == bp_finish) |
3686 | { | |
3687 | continue; | |
3688 | } | |
3689 | ||
3690 | /* Without a symbolic address, we have little hope of the | |
3691 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3692 | a.out. */ |
9ef9e6a6 | 3693 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3694 | { |
3695 | delete_breakpoint (b); | |
3696 | continue; | |
3697 | } | |
c5aa993b | 3698 | } |
c906108c SS |
3699 | } |
3700 | ||
3701 | int | |
d80ee84f | 3702 | detach_breakpoints (ptid_t ptid) |
c906108c | 3703 | { |
35df4500 | 3704 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3705 | int val = 0; |
2989a365 | 3706 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3707 | struct inferior *inf = current_inferior (); |
c5aa993b | 3708 | |
e99b03dc | 3709 | if (ptid.pid () == inferior_ptid.pid ()) |
8a3fe4f8 | 3710 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3711 | |
6c95b8df | 3712 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3713 | inferior_ptid = ptid; |
35df4500 | 3714 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3715 | { |
35df4500 | 3716 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3717 | continue; |
3718 | ||
bd9673a4 PW |
3719 | /* This function must physically remove breakpoints locations |
3720 | from the specified ptid, without modifying the breakpoint | |
3721 | package's state. Locations of type bp_loc_other are only | |
3722 | maintained at GDB side. So, there is no need to remove | |
3723 | these bp_loc_other locations. Moreover, removing these | |
3724 | would modify the breakpoint package's state. */ | |
3725 | if (bl->loc_type == bp_loc_other) | |
3726 | continue; | |
3727 | ||
35df4500 | 3728 | if (bl->inserted) |
b2b6a7da | 3729 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3730 | } |
d03285ec | 3731 | |
3a1bae8e | 3732 | return val; |
c906108c SS |
3733 | } |
3734 | ||
35df4500 | 3735 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3736 | Note that this is used to detach breakpoints from a child fork. |
3737 | When we get here, the child isn't in the inferior list, and neither | |
3738 | do we have objects to represent its address space --- we should | |
35df4500 | 3739 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3740 | |
c906108c | 3741 | static int |
b2b6a7da | 3742 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3743 | { |
3744 | int val; | |
c5aa993b | 3745 | |
35df4500 TJB |
3746 | /* BL is never in moribund_locations by our callers. */ |
3747 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3748 | |
74960c60 VP |
3749 | /* The type of none suggests that owner is actually deleted. |
3750 | This should not ever happen. */ | |
35df4500 | 3751 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3752 | |
35df4500 TJB |
3753 | if (bl->loc_type == bp_loc_software_breakpoint |
3754 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3755 | { |
c02f5703 MS |
3756 | /* "Normal" instruction breakpoint: either the standard |
3757 | trap-instruction bp (bp_breakpoint), or a | |
3758 | bp_hardware_breakpoint. */ | |
3759 | ||
3760 | /* First check to see if we have to handle an overlay. */ | |
3761 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3762 | || bl->section == NULL |
3763 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3764 | { |
3765 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3766 | |
3767 | /* If we're trying to uninsert a memory breakpoint that we | |
3768 | know is set in a dynamic object that is marked | |
3769 | shlib_disabled, then either the dynamic object was | |
3770 | removed with "remove-symbol-file" or with | |
3771 | "nosharedlibrary". In the former case, we don't know | |
3772 | whether another dynamic object might have loaded over the | |
3773 | breakpoint's address -- the user might well let us know | |
3774 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3775 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3776 | list of dynamically loaded objects). If we have the |
3777 | breakpoint's shadow memory, that is, this is a software | |
3778 | breakpoint managed by GDB, check whether the breakpoint | |
3779 | is still inserted in memory, to avoid overwriting wrong | |
3780 | code with stale saved shadow contents. Note that HW | |
3781 | breakpoints don't have shadow memory, as they're | |
3782 | implemented using a mechanism that is not dependent on | |
3783 | being able to modify the target's memory, and as such | |
3784 | they should always be removed. */ | |
3785 | if (bl->shlib_disabled | |
3786 | && bl->target_info.shadow_len != 0 | |
3787 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3788 | val = 0; | |
3789 | else | |
73971819 | 3790 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3791 | } |
c906108c SS |
3792 | else |
3793 | { | |
4a64f543 | 3794 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3795 | Did we set a breakpoint at the LMA? */ |
3796 | if (!overlay_events_enabled) | |
3797 | { | |
3798 | /* Yes -- overlay event support is not active, so we | |
3799 | should have set a breakpoint at the LMA. Remove it. | |
3800 | */ | |
c02f5703 MS |
3801 | /* Ignore any failures: if the LMA is in ROM, we will |
3802 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3803 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3804 | target_remove_hw_breakpoint (bl->gdbarch, | |
3805 | &bl->overlay_target_info); | |
c02f5703 | 3806 | else |
35df4500 | 3807 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3808 | &bl->overlay_target_info, |
3809 | reason); | |
c02f5703 MS |
3810 | } |
3811 | /* Did we set a breakpoint at the VMA? | |
3812 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3813 | if (bl->inserted) |
c906108c | 3814 | { |
c02f5703 MS |
3815 | /* Yes -- remove it. Previously we did not bother to |
3816 | remove the breakpoint if the section had been | |
3817 | unmapped, but let's not rely on that being safe. We | |
3818 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3819 | |
3820 | /* However, we should remove *software* breakpoints only | |
3821 | if the section is still mapped, or else we overwrite | |
3822 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3823 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3824 | || section_is_mapped (bl->section)) | |
73971819 | 3825 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3826 | else |
3827 | val = 0; | |
c906108c | 3828 | } |
c02f5703 MS |
3829 | else |
3830 | { | |
3831 | /* No -- not inserted, so no need to remove. No error. */ | |
3832 | val = 0; | |
3833 | } | |
c906108c | 3834 | } |
879d1e6b | 3835 | |
08351840 PA |
3836 | /* In some cases, we might not be able to remove a breakpoint in |
3837 | a shared library that has already been removed, but we have | |
3838 | not yet processed the shlib unload event. Similarly for an | |
3839 | unloaded add-symbol-file object - the user might not yet have | |
3840 | had the chance to remove-symbol-file it. shlib_disabled will | |
3841 | be set if the library/object has already been removed, but | |
3842 | the breakpoint hasn't been uninserted yet, e.g., after | |
3843 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3844 | always-inserted mode. */ | |
076855f9 | 3845 | if (val |
08351840 PA |
3846 | && (bl->loc_type == bp_loc_software_breakpoint |
3847 | && (bl->shlib_disabled | |
3848 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3849 | || shared_objfile_contains_address_p (bl->pspace, |
3850 | bl->address)))) | |
879d1e6b UW |
3851 | val = 0; |
3852 | ||
c906108c SS |
3853 | if (val) |
3854 | return val; | |
b2b6a7da | 3855 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3856 | } |
35df4500 | 3857 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3858 | { |
77b06cd7 TJB |
3859 | gdb_assert (bl->owner->ops != NULL |
3860 | && bl->owner->ops->remove_location != NULL); | |
3861 | ||
b2b6a7da | 3862 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3863 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3864 | |
c906108c | 3865 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3866 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3867 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3868 | bl->owner->number); |
c906108c | 3869 | } |
35df4500 | 3870 | else if (bl->owner->type == bp_catchpoint |
dda83cd7 SM |
3871 | && breakpoint_enabled (bl->owner) |
3872 | && !bl->duplicate) | |
ce78b96d | 3873 | { |
77b06cd7 TJB |
3874 | gdb_assert (bl->owner->ops != NULL |
3875 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3876 | |
73971819 | 3877 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3878 | if (val) |
3879 | return val; | |
77b06cd7 | 3880 | |
b2b6a7da | 3881 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3882 | } |
c906108c SS |
3883 | |
3884 | return 0; | |
3885 | } | |
3886 | ||
6c95b8df | 3887 | static int |
834c0d03 | 3888 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3889 | { |
35df4500 TJB |
3890 | /* BL is never in moribund_locations by our callers. */ |
3891 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3892 | |
6c95b8df PA |
3893 | /* The type of none suggests that owner is actually deleted. |
3894 | This should not ever happen. */ | |
35df4500 | 3895 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3896 | |
5ed8105e | 3897 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3898 | |
35df4500 | 3899 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3900 | |
5ed8105e | 3901 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3902 | } |
3903 | ||
c906108c SS |
3904 | /* Clear the "inserted" flag in all breakpoints. */ |
3905 | ||
25b22b0a | 3906 | void |
fba45db2 | 3907 | mark_breakpoints_out (void) |
c906108c | 3908 | { |
35df4500 | 3909 | struct bp_location *bl, **blp_tmp; |
c906108c | 3910 | |
35df4500 | 3911 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3912 | if (bl->pspace == current_program_space) |
35df4500 | 3913 | bl->inserted = 0; |
c906108c SS |
3914 | } |
3915 | ||
53a5351d JM |
3916 | /* Clear the "inserted" flag in all breakpoints and delete any |
3917 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3918 | |
3919 | Plus other such housekeeping that has to be done for breakpoints | |
3920 | between runs. | |
3921 | ||
53a5351d JM |
3922 | Note: this function gets called at the end of a run (by |
3923 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3924 | init_wait_for_inferior). */ |
c906108c SS |
3925 | |
3926 | ||
3927 | ||
3928 | void | |
fba45db2 | 3929 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3930 | { |
35df4500 | 3931 | struct breakpoint *b, *b_tmp; |
6c95b8df | 3932 | struct program_space *pspace = current_program_space; |
c906108c | 3933 | |
50c71eaf PA |
3934 | /* If breakpoint locations are shared across processes, then there's |
3935 | nothing to do. */ | |
f5656ead | 3936 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3937 | return; |
3938 | ||
1a853c52 | 3939 | mark_breakpoints_out (); |
075f6582 | 3940 | |
35df4500 | 3941 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3942 | { |
6c95b8df PA |
3943 | if (b->loc && b->loc->pspace != pspace) |
3944 | continue; | |
3945 | ||
c5aa993b JM |
3946 | switch (b->type) |
3947 | { | |
3948 | case bp_call_dummy: | |
e2e4d78b | 3949 | case bp_longjmp_call_dummy: |
c906108c | 3950 | |
c5aa993b | 3951 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3952 | cause problems when the inferior is rerun, so we better get |
3953 | rid of it. */ | |
3954 | ||
3955 | case bp_watchpoint_scope: | |
3956 | ||
3957 | /* Also get rid of scope breakpoints. */ | |
3958 | ||
3959 | case bp_shlib_event: | |
3960 | ||
3961 | /* Also remove solib event breakpoints. Their addresses may | |
3962 | have changed since the last time we ran the program. | |
3963 | Actually we may now be debugging against different target; | |
3964 | and so the solib backend that installed this breakpoint may | |
3965 | not be used in by the target. E.g., | |
3966 | ||
3967 | (gdb) file prog-linux | |
3968 | (gdb) run # native linux target | |
3969 | ... | |
3970 | (gdb) kill | |
3971 | (gdb) file prog-win.exe | |
3972 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3973 | */ | |
c906108c | 3974 | |
f59f708a PA |
3975 | case bp_step_resume: |
3976 | ||
3977 | /* Also remove step-resume breakpoints. */ | |
3978 | ||
7c16b83e PA |
3979 | case bp_single_step: |
3980 | ||
3981 | /* Also remove single-step breakpoints. */ | |
3982 | ||
c5aa993b JM |
3983 | delete_breakpoint (b); |
3984 | break; | |
c906108c | 3985 | |
c5aa993b JM |
3986 | case bp_watchpoint: |
3987 | case bp_hardware_watchpoint: | |
3988 | case bp_read_watchpoint: | |
3989 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3990 | { |
3991 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3992 | |
3a5c3e22 PA |
3993 | /* Likewise for watchpoints on local expressions. */ |
3994 | if (w->exp_valid_block != NULL) | |
3995 | delete_breakpoint (b); | |
63000888 | 3996 | else |
3a5c3e22 | 3997 | { |
63000888 PA |
3998 | /* Get rid of existing locations, which are no longer |
3999 | valid. New ones will be created in | |
4000 | update_watchpoint, when the inferior is restarted. | |
4001 | The next update_global_location_list call will | |
4002 | garbage collect them. */ | |
4003 | b->loc = NULL; | |
4004 | ||
4005 | if (context == inf_starting) | |
4006 | { | |
4007 | /* Reset val field to force reread of starting value in | |
4008 | insert_breakpoints. */ | |
850645cf | 4009 | w->val.reset (nullptr); |
4c1d86d9 | 4010 | w->val_valid = false; |
63000888 PA |
4011 | } |
4012 | } | |
3a5c3e22 | 4013 | } |
c5aa993b JM |
4014 | break; |
4015 | default: | |
c5aa993b JM |
4016 | break; |
4017 | } | |
4018 | } | |
1c5cfe86 PA |
4019 | |
4020 | /* Get rid of the moribund locations. */ | |
1123588c | 4021 | for (bp_location *bl : moribund_locations) |
35df4500 | 4022 | decref_bp_location (&bl); |
1123588c | 4023 | moribund_locations.clear (); |
c906108c SS |
4024 | } |
4025 | ||
6c95b8df PA |
4026 | /* These functions concern about actual breakpoints inserted in the |
4027 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4028 | we need to hop over the bkpt --- so we check for address space | |
4029 | match, not program space. */ | |
4030 | ||
c2c6d25f JM |
4031 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4032 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4033 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4034 | permanent breakpoint. | |
4035 | - When continuing from a location with an ordinary breakpoint, we | |
4036 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4037 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4038 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4039 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4040 | |
c2c6d25f | 4041 | enum breakpoint_here |
accd0bcd | 4042 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4043 | { |
35df4500 | 4044 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4045 | int any_breakpoint_here = 0; |
c906108c | 4046 | |
35df4500 | 4047 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4048 | { |
35df4500 TJB |
4049 | if (bl->loc_type != bp_loc_software_breakpoint |
4050 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4051 | continue; |
4052 | ||
f1310107 | 4053 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4054 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4055 | || bl->permanent) |
f1310107 | 4056 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4057 | { |
4058 | if (overlay_debugging | |
35df4500 TJB |
4059 | && section_is_overlay (bl->section) |
4060 | && !section_is_mapped (bl->section)) | |
075f6582 | 4061 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4062 | else if (bl->permanent) |
075f6582 DJ |
4063 | return permanent_breakpoint_here; |
4064 | else | |
4065 | any_breakpoint_here = 1; | |
4066 | } | |
4067 | } | |
c906108c | 4068 | |
f486487f | 4069 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4070 | } |
4071 | ||
d35ae833 PA |
4072 | /* See breakpoint.h. */ |
4073 | ||
4074 | int | |
accd0bcd | 4075 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
4076 | CORE_ADDR addr, ULONGEST len) |
4077 | { | |
4078 | struct bp_location *bl, **blp_tmp; | |
4079 | ||
4080 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4081 | { | |
4082 | if (bl->loc_type != bp_loc_software_breakpoint | |
4083 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4084 | continue; | |
4085 | ||
4086 | if ((breakpoint_enabled (bl->owner) | |
4087 | || bl->permanent) | |
4088 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4089 | addr, len)) | |
4090 | { | |
4091 | if (overlay_debugging | |
4092 | && section_is_overlay (bl->section) | |
4093 | && !section_is_mapped (bl->section)) | |
4094 | { | |
4095 | /* Unmapped overlay -- can't be a match. */ | |
4096 | continue; | |
4097 | } | |
4098 | ||
4099 | return 1; | |
4100 | } | |
4101 | } | |
4102 | ||
4103 | return 0; | |
4104 | } | |
4105 | ||
1c5cfe86 PA |
4106 | /* Return true if there's a moribund breakpoint at PC. */ |
4107 | ||
4108 | int | |
accd0bcd | 4109 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 | 4110 | { |
1123588c | 4111 | for (bp_location *loc : moribund_locations) |
f1310107 | 4112 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4113 | return 1; |
4114 | ||
4115 | return 0; | |
4116 | } | |
c2c6d25f | 4117 | |
f7ce857f PA |
4118 | /* Returns non-zero iff BL is inserted at PC, in address space |
4119 | ASPACE. */ | |
4120 | ||
4121 | static int | |
4122 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 4123 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
4124 | { |
4125 | if (bl->inserted | |
4126 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4127 | aspace, pc)) | |
4128 | { | |
4129 | if (overlay_debugging | |
4130 | && section_is_overlay (bl->section) | |
4131 | && !section_is_mapped (bl->section)) | |
4132 | return 0; /* unmapped overlay -- can't be a match */ | |
4133 | else | |
4134 | return 1; | |
4135 | } | |
4136 | return 0; | |
4137 | } | |
4138 | ||
a1fd2fa5 | 4139 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4140 | |
4141 | int | |
accd0bcd | 4142 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4143 | { |
f7ce857f | 4144 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4145 | |
f7ce857f | 4146 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4147 | { |
f7ce857f PA |
4148 | struct bp_location *bl = *blp; |
4149 | ||
35df4500 TJB |
4150 | if (bl->loc_type != bp_loc_software_breakpoint |
4151 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4152 | continue; |
4153 | ||
f7ce857f PA |
4154 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4155 | return 1; | |
c5aa993b | 4156 | } |
c36b740a VP |
4157 | return 0; |
4158 | } | |
4159 | ||
a1fd2fa5 PA |
4160 | /* This function returns non-zero iff there is a software breakpoint |
4161 | inserted at PC. */ | |
c36b740a VP |
4162 | |
4163 | int | |
accd0bcd | 4164 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4165 | CORE_ADDR pc) |
4fa8626c | 4166 | { |
f7ce857f | 4167 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4168 | |
f7ce857f | 4169 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4170 | { |
f7ce857f PA |
4171 | struct bp_location *bl = *blp; |
4172 | ||
35df4500 | 4173 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4174 | continue; |
4175 | ||
f7ce857f PA |
4176 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4177 | return 1; | |
4fa8626c DJ |
4178 | } |
4179 | ||
4180 | return 0; | |
9c02b525 PA |
4181 | } |
4182 | ||
4183 | /* See breakpoint.h. */ | |
4184 | ||
4185 | int | |
accd0bcd | 4186 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4187 | CORE_ADDR pc) |
4188 | { | |
4189 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4190 | |
4191 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4192 | { | |
4193 | struct bp_location *bl = *blp; | |
4194 | ||
4195 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4196 | continue; | |
4197 | ||
4198 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4199 | return 1; | |
4200 | } | |
4201 | ||
4202 | return 0; | |
4fa8626c DJ |
4203 | } |
4204 | ||
9093389c | 4205 | int |
accd0bcd | 4206 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4207 | CORE_ADDR addr, ULONGEST len) |
4208 | { | |
4209 | struct breakpoint *bpt; | |
4210 | ||
4211 | ALL_BREAKPOINTS (bpt) | |
4212 | { | |
4213 | struct bp_location *loc; | |
4214 | ||
4215 | if (bpt->type != bp_hardware_watchpoint | |
4216 | && bpt->type != bp_access_watchpoint) | |
4217 | continue; | |
4218 | ||
4219 | if (!breakpoint_enabled (bpt)) | |
4220 | continue; | |
4221 | ||
4222 | for (loc = bpt->loc; loc; loc = loc->next) | |
4223 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4224 | { | |
4225 | CORE_ADDR l, h; | |
4226 | ||
4227 | /* Check for intersection. */ | |
768adc05 PA |
4228 | l = std::max<CORE_ADDR> (loc->address, addr); |
4229 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4230 | if (l < h) |
4231 | return 1; | |
4232 | } | |
4233 | } | |
4234 | return 0; | |
4235 | } | |
c5aa993b | 4236 | |
f2478a7e | 4237 | /* See breakpoint.h. */ |
c906108c | 4238 | |
f2478a7e SM |
4239 | bool |
4240 | is_catchpoint (struct breakpoint *b) | |
c906108c | 4241 | { |
f2478a7e | 4242 | return (b->type == bp_catchpoint); |
c906108c SS |
4243 | } |
4244 | ||
f431efe5 PA |
4245 | /* Frees any storage that is part of a bpstat. Does not walk the |
4246 | 'next' chain. */ | |
4247 | ||
04afa70c | 4248 | bpstats::~bpstats () |
198757a8 | 4249 | { |
04afa70c TT |
4250 | if (bp_location_at != NULL) |
4251 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4252 | } |
4253 | ||
c906108c SS |
4254 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4255 | Also free any storage that is part of a bpstat. */ | |
4256 | ||
4257 | void | |
fba45db2 | 4258 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4259 | { |
4260 | bpstat p; | |
4261 | bpstat q; | |
4262 | ||
4263 | if (bsp == 0) | |
4264 | return; | |
4265 | p = *bsp; | |
4266 | while (p != NULL) | |
4267 | { | |
4268 | q = p->next; | |
04afa70c | 4269 | delete p; |
c906108c SS |
4270 | p = q; |
4271 | } | |
4272 | *bsp = NULL; | |
4273 | } | |
4274 | ||
04afa70c TT |
4275 | bpstats::bpstats (const bpstats &other) |
4276 | : next (NULL), | |
4277 | bp_location_at (other.bp_location_at), | |
4278 | breakpoint_at (other.breakpoint_at), | |
4279 | commands (other.commands), | |
04afa70c TT |
4280 | print (other.print), |
4281 | stop (other.stop), | |
4282 | print_it (other.print_it) | |
4283 | { | |
850645cf TT |
4284 | if (other.old_val != NULL) |
4285 | old_val = release_value (value_copy (other.old_val.get ())); | |
04afa70c | 4286 | incref_bp_location (bp_location_at); |
04afa70c TT |
4287 | } |
4288 | ||
c906108c SS |
4289 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4290 | is part of the bpstat is copied as well. */ | |
4291 | ||
4292 | bpstat | |
fba45db2 | 4293 | bpstat_copy (bpstat bs) |
c906108c SS |
4294 | { |
4295 | bpstat p = NULL; | |
4296 | bpstat tmp; | |
4297 | bpstat retval = NULL; | |
4298 | ||
4299 | if (bs == NULL) | |
4300 | return bs; | |
4301 | ||
4302 | for (; bs != NULL; bs = bs->next) | |
4303 | { | |
04afa70c | 4304 | tmp = new bpstats (*bs); |
31cc81e9 | 4305 | |
c906108c SS |
4306 | if (p == NULL) |
4307 | /* This is the first thing in the chain. */ | |
4308 | retval = tmp; | |
4309 | else | |
4310 | p->next = tmp; | |
4311 | p = tmp; | |
4312 | } | |
4313 | p->next = NULL; | |
4314 | return retval; | |
4315 | } | |
4316 | ||
4a64f543 | 4317 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4318 | |
4319 | bpstat | |
fba45db2 | 4320 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4321 | { |
c5aa993b JM |
4322 | if (bsp == NULL) |
4323 | return NULL; | |
c906108c | 4324 | |
c5aa993b JM |
4325 | for (; bsp != NULL; bsp = bsp->next) |
4326 | { | |
f431efe5 | 4327 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4328 | return bsp; |
4329 | } | |
c906108c SS |
4330 | return NULL; |
4331 | } | |
4332 | ||
ab04a2af TT |
4333 | /* See breakpoint.h. */ |
4334 | ||
4c462cb0 | 4335 | bool |
427cd150 | 4336 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4337 | { |
ab04a2af TT |
4338 | for (; bsp != NULL; bsp = bsp->next) |
4339 | { | |
427cd150 TT |
4340 | if (bsp->breakpoint_at == NULL) |
4341 | { | |
4342 | /* A moribund location can never explain a signal other than | |
4343 | GDB_SIGNAL_TRAP. */ | |
4344 | if (sig == GDB_SIGNAL_TRAP) | |
4c462cb0 | 4345 | return true; |
427cd150 TT |
4346 | } |
4347 | else | |
47591c29 PA |
4348 | { |
4349 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4350 | sig)) | |
4c462cb0 | 4351 | return true; |
47591c29 | 4352 | } |
ab04a2af TT |
4353 | } |
4354 | ||
4c462cb0 | 4355 | return false; |
ab04a2af TT |
4356 | } |
4357 | ||
4a64f543 MS |
4358 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4359 | stopped at. *BSP upon return is a bpstat which points to the | |
4360 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4361 | good for anything but further calls to bpstat_num). | |
4362 | ||
8671a17b PA |
4363 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4364 | Return -1 if stopped at a breakpoint that has been deleted since | |
4365 | we set it. | |
4366 | Return 1 otherwise. */ | |
c906108c SS |
4367 | |
4368 | int | |
8671a17b | 4369 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4370 | { |
4371 | struct breakpoint *b; | |
4372 | ||
4373 | if ((*bsp) == NULL) | |
4374 | return 0; /* No more breakpoint values */ | |
8671a17b | 4375 | |
4a64f543 MS |
4376 | /* We assume we'll never have several bpstats that correspond to a |
4377 | single breakpoint -- otherwise, this function might return the | |
4378 | same number more than once and this will look ugly. */ | |
f431efe5 | 4379 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4380 | *bsp = (*bsp)->next; |
4381 | if (b == NULL) | |
4382 | return -1; /* breakpoint that's been deleted since */ | |
4383 | ||
4384 | *num = b->number; /* We have its number */ | |
4385 | return 1; | |
c906108c SS |
4386 | } |
4387 | ||
e93ca019 | 4388 | /* See breakpoint.h. */ |
c906108c SS |
4389 | |
4390 | void | |
e93ca019 | 4391 | bpstat_clear_actions (void) |
c906108c | 4392 | { |
e93ca019 JK |
4393 | bpstat bs; |
4394 | ||
00431a78 | 4395 | if (inferior_ptid == null_ptid) |
e93ca019 JK |
4396 | return; |
4397 | ||
00431a78 | 4398 | thread_info *tp = inferior_thread (); |
e93ca019 | 4399 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
c906108c | 4400 | { |
d1b0a7bf | 4401 | bs->commands = NULL; |
850645cf | 4402 | bs->old_val.reset (nullptr); |
c906108c SS |
4403 | } |
4404 | } | |
4405 | ||
f3b1572e PA |
4406 | /* Called when a command is about to proceed the inferior. */ |
4407 | ||
4408 | static void | |
4409 | breakpoint_about_to_proceed (void) | |
4410 | { | |
d7e15655 | 4411 | if (inferior_ptid != null_ptid) |
f3b1572e PA |
4412 | { |
4413 | struct thread_info *tp = inferior_thread (); | |
4414 | ||
4415 | /* Allow inferior function calls in breakpoint commands to not | |
4416 | interrupt the command list. When the call finishes | |
4417 | successfully, the inferior will be standing at the same | |
4418 | breakpoint as if nothing happened. */ | |
16c381f0 | 4419 | if (tp->control.in_infcall) |
f3b1572e PA |
4420 | return; |
4421 | } | |
4422 | ||
4423 | breakpoint_proceeded = 1; | |
4424 | } | |
4425 | ||
abf85f46 JK |
4426 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4427 | or its equivalent. */ | |
4428 | ||
4429 | static int | |
4430 | command_line_is_silent (struct command_line *cmd) | |
4431 | { | |
4f45d445 | 4432 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4433 | } |
4434 | ||
4a64f543 MS |
4435 | /* Execute all the commands associated with all the breakpoints at |
4436 | this location. Any of these commands could cause the process to | |
4437 | proceed beyond this point, etc. We look out for such changes by | |
4438 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4439 | |
347bddb7 PA |
4440 | Returns true if a breakpoint command resumed the inferior. In that |
4441 | case, it is the caller's responsibility to recall it again with the | |
4442 | bpstat of the current thread. */ | |
4443 | ||
4444 | static int | |
4445 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4446 | { |
4447 | bpstat bs; | |
347bddb7 | 4448 | int again = 0; |
c906108c SS |
4449 | |
4450 | /* Avoid endless recursion if a `source' command is contained | |
4451 | in bs->commands. */ | |
4452 | if (executing_breakpoint_commands) | |
347bddb7 | 4453 | return 0; |
c906108c | 4454 | |
81b1e71c TT |
4455 | scoped_restore save_executing |
4456 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4457 | |
1ac32117 | 4458 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4459 | |
4a64f543 | 4460 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4461 | bs = *bsp; |
4462 | ||
4463 | breakpoint_proceeded = 0; | |
4464 | for (; bs != NULL; bs = bs->next) | |
4465 | { | |
d1b0a7bf | 4466 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4467 | |
4468 | /* Take ownership of the BSP's command tree, if it has one. | |
4469 | ||
dda83cd7 SM |
4470 | The command tree could legitimately contain commands like |
4471 | 'step' and 'next', which call clear_proceed_status, which | |
4472 | frees stop_bpstat's command tree. To make sure this doesn't | |
4473 | free the tree we're executing out from under us, we need to | |
4474 | take ownership of the tree ourselves. Since a given bpstat's | |
4475 | commands are only executed once, we don't need to copy it; we | |
4476 | can clear the pointer in the bpstat, and make sure we free | |
4477 | the tree when we're done. */ | |
d1b0a7bf | 4478 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4479 | bs->commands = NULL; |
d1b0a7bf TT |
4480 | if (ccmd != NULL) |
4481 | cmd = ccmd.get (); | |
abf85f46 JK |
4482 | if (command_line_is_silent (cmd)) |
4483 | { | |
4484 | /* The action has been already done by bpstat_stop_status. */ | |
4485 | cmd = cmd->next; | |
4486 | } | |
6c50ab1c | 4487 | |
c906108c SS |
4488 | while (cmd != NULL) |
4489 | { | |
4490 | execute_control_command (cmd); | |
4491 | ||
4492 | if (breakpoint_proceeded) | |
4493 | break; | |
4494 | else | |
4495 | cmd = cmd->next; | |
4496 | } | |
6c50ab1c | 4497 | |
c906108c | 4498 | if (breakpoint_proceeded) |
32c1e744 | 4499 | { |
cb814510 | 4500 | if (current_ui->async) |
347bddb7 PA |
4501 | /* If we are in async mode, then the target might be still |
4502 | running, not stopped at any breakpoint, so nothing for | |
4503 | us to do here -- just return to the event loop. */ | |
4504 | ; | |
32c1e744 VP |
4505 | else |
4506 | /* In sync mode, when execute_control_command returns | |
4507 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4508 | Breakpoint commands for that stop were not run, since |
4509 | execute_command does not run breakpoint commands -- | |
4510 | only command_line_handler does, but that one is not | |
4511 | involved in execution of breakpoint commands. So, we | |
4512 | can now execute breakpoint commands. It should be | |
4513 | noted that making execute_command do bpstat actions is | |
4514 | not an option -- in this case we'll have recursive | |
4515 | invocation of bpstat for each breakpoint with a | |
4516 | command, and can easily blow up GDB stack. Instead, we | |
4517 | return true, which will trigger the caller to recall us | |
4518 | with the new stop_bpstat. */ | |
4519 | again = 1; | |
4520 | break; | |
32c1e744 | 4521 | } |
c906108c | 4522 | } |
347bddb7 PA |
4523 | return again; |
4524 | } | |
4525 | ||
00431a78 PA |
4526 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
4527 | one, is alive and has execution. Return NULL otherwise. */ | |
4528 | ||
4529 | static thread_info * | |
4530 | get_bpstat_thread () | |
4531 | { | |
55f6301a | 4532 | if (inferior_ptid == null_ptid || !target_has_execution ()) |
00431a78 PA |
4533 | return NULL; |
4534 | ||
4535 | thread_info *tp = inferior_thread (); | |
4536 | if (tp->state == THREAD_EXITED || tp->executing) | |
4537 | return NULL; | |
4538 | return tp; | |
4539 | } | |
4540 | ||
347bddb7 PA |
4541 | void |
4542 | bpstat_do_actions (void) | |
4543 | { | |
694c6bf5 | 4544 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
00431a78 | 4545 | thread_info *tp; |
353d1d73 | 4546 | |
347bddb7 | 4547 | /* Do any commands attached to breakpoint we are stopped at. */ |
00431a78 PA |
4548 | while ((tp = get_bpstat_thread ()) != NULL) |
4549 | { | |
4550 | /* Since in sync mode, bpstat_do_actions may resume the | |
4551 | inferior, and only return when it is stopped at the next | |
4552 | breakpoint, we keep doing breakpoint actions until it returns | |
4553 | false to indicate the inferior was not resumed. */ | |
4554 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) | |
4555 | break; | |
4556 | } | |
353d1d73 | 4557 | |
694c6bf5 | 4558 | cleanup_if_error.release (); |
c906108c SS |
4559 | } |
4560 | ||
fa4727a6 DJ |
4561 | /* Print out the (old or new) value associated with a watchpoint. */ |
4562 | ||
4563 | static void | |
4564 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4565 | { | |
4566 | if (val == NULL) | |
7f6aba03 | 4567 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
fa4727a6 | 4568 | else |
79a45b7d TT |
4569 | { |
4570 | struct value_print_options opts; | |
4571 | get_user_print_options (&opts); | |
4572 | value_print (val, stream, &opts); | |
4573 | } | |
fa4727a6 DJ |
4574 | } |
4575 | ||
f303dbd6 PA |
4576 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4577 | debugging multiple threads. */ | |
4578 | ||
4579 | void | |
4580 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4581 | { | |
112e8700 | 4582 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4583 | return; |
4584 | ||
112e8700 | 4585 | uiout->text ("\n"); |
f303dbd6 PA |
4586 | |
4587 | if (show_thread_that_caused_stop ()) | |
4588 | { | |
4589 | const char *name; | |
4590 | struct thread_info *thr = inferior_thread (); | |
4591 | ||
112e8700 | 4592 | uiout->text ("Thread "); |
33eca680 | 4593 | uiout->field_string ("thread-id", print_thread_id (thr)); |
f303dbd6 PA |
4594 | |
4595 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4596 | if (name != NULL) | |
4597 | { | |
112e8700 | 4598 | uiout->text (" \""); |
33eca680 | 4599 | uiout->field_string ("name", name); |
112e8700 | 4600 | uiout->text ("\""); |
f303dbd6 PA |
4601 | } |
4602 | ||
112e8700 | 4603 | uiout->text (" hit "); |
f303dbd6 PA |
4604 | } |
4605 | } | |
4606 | ||
e514a9d6 | 4607 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4608 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4609 | 'print_it' in the bpstat structure. Under some circumstances we |
4610 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4611 | normal_stop(). */ |
e514a9d6 JM |
4612 | |
4613 | static enum print_stop_action | |
4614 | print_bp_stop_message (bpstat bs) | |
4615 | { | |
4616 | switch (bs->print_it) | |
4617 | { | |
4618 | case print_it_noop: | |
4a64f543 | 4619 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4620 | return PRINT_UNKNOWN; |
4621 | break; | |
4622 | ||
4623 | case print_it_done: | |
4624 | /* We still want to print the frame, but we already printed the | |
dda83cd7 | 4625 | relevant messages. */ |
e514a9d6 JM |
4626 | return PRINT_SRC_AND_LOC; |
4627 | break; | |
4628 | ||
4629 | case print_it_normal: | |
4f8d1dc6 | 4630 | { |
f431efe5 PA |
4631 | struct breakpoint *b = bs->breakpoint_at; |
4632 | ||
1a6a67de TJB |
4633 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4634 | which has since been deleted. */ | |
4635 | if (b == NULL) | |
4636 | return PRINT_UNKNOWN; | |
4637 | ||
348d480f PA |
4638 | /* Normal case. Call the breakpoint's print_it method. */ |
4639 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4640 | } |
348d480f | 4641 | break; |
3086aeae | 4642 | |
e514a9d6 | 4643 | default: |
8e65ff28 | 4644 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4645 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4646 | break; |
c906108c | 4647 | } |
c906108c SS |
4648 | } |
4649 | ||
edcc5120 TT |
4650 | /* A helper function that prints a shared library stopped event. */ |
4651 | ||
4652 | static void | |
4653 | print_solib_event (int is_catchpoint) | |
4654 | { | |
6fb16ce6 | 4655 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
bcb430e4 | 4656 | bool any_added = !current_program_space->added_solibs.empty (); |
edcc5120 TT |
4657 | |
4658 | if (!is_catchpoint) | |
4659 | { | |
4660 | if (any_added || any_deleted) | |
112e8700 | 4661 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4662 | else |
112e8700 SM |
4663 | current_uiout->text (_("Stopped due to shared library event (no " |
4664 | "libraries added or removed)\n")); | |
edcc5120 TT |
4665 | } |
4666 | ||
112e8700 SM |
4667 | if (current_uiout->is_mi_like_p ()) |
4668 | current_uiout->field_string ("reason", | |
4669 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4670 | |
4671 | if (any_deleted) | |
4672 | { | |
112e8700 | 4673 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4674 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
6fb16ce6 | 4675 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
edcc5120 | 4676 | { |
6fb16ce6 SM |
4677 | const std::string &name = current_program_space->deleted_solibs[ix]; |
4678 | ||
edcc5120 | 4679 | if (ix > 0) |
112e8700 SM |
4680 | current_uiout->text (" "); |
4681 | current_uiout->field_string ("library", name); | |
4682 | current_uiout->text ("\n"); | |
edcc5120 | 4683 | } |
edcc5120 TT |
4684 | } |
4685 | ||
4686 | if (any_added) | |
4687 | { | |
112e8700 | 4688 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4689 | ui_out_emit_list list_emitter (current_uiout, "added"); |
bcb430e4 | 4690 | bool first = true; |
52941706 | 4691 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 | 4692 | { |
bcb430e4 | 4693 | if (!first) |
112e8700 | 4694 | current_uiout->text (" "); |
bcb430e4 | 4695 | first = false; |
112e8700 SM |
4696 | current_uiout->field_string ("library", iter->so_name); |
4697 | current_uiout->text ("\n"); | |
edcc5120 | 4698 | } |
edcc5120 TT |
4699 | } |
4700 | } | |
4701 | ||
e514a9d6 JM |
4702 | /* Print a message indicating what happened. This is called from |
4703 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4704 | list - a list of the eventpoints that caused this stop. KIND is |
4705 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4706 | routine calls the generic print routine for printing a message |
4707 | about reasons for stopping. This will print (for example) the | |
4708 | "Breakpoint n," part of the output. The return value of this | |
4709 | routine is one of: | |
c906108c | 4710 | |
4a64f543 | 4711 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4712 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4713 | code to print the location. An example is |
c5aa993b JM |
4714 | "Breakpoint 1, " which should be followed by |
4715 | the location. | |
917317f4 | 4716 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4717 | to also print the location part of the message. |
4718 | An example is the catch/throw messages, which | |
4a64f543 | 4719 | don't require a location appended to the end. |
917317f4 | 4720 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4721 | further info to be printed. */ |
c906108c | 4722 | |
917317f4 | 4723 | enum print_stop_action |
36dfb11c | 4724 | bpstat_print (bpstat bs, int kind) |
c906108c | 4725 | { |
f486487f | 4726 | enum print_stop_action val; |
c5aa993b | 4727 | |
c906108c | 4728 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4729 | (Currently all watchpoints go on the bpstat whether hit or not. |
4730 | That probably could (should) be changed, provided care is taken | |
c906108c | 4731 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4732 | for (; bs; bs = bs->next) |
4733 | { | |
4734 | val = print_bp_stop_message (bs); | |
4735 | if (val == PRINT_SRC_ONLY | |
4736 | || val == PRINT_SRC_AND_LOC | |
4737 | || val == PRINT_NOTHING) | |
4738 | return val; | |
4739 | } | |
c906108c | 4740 | |
36dfb11c TT |
4741 | /* If we had hit a shared library event breakpoint, |
4742 | print_bp_stop_message would print out this message. If we hit an | |
4743 | OS-level shared library event, do the same thing. */ | |
4744 | if (kind == TARGET_WAITKIND_LOADED) | |
4745 | { | |
edcc5120 | 4746 | print_solib_event (0); |
36dfb11c TT |
4747 | return PRINT_NOTHING; |
4748 | } | |
4749 | ||
e514a9d6 | 4750 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4751 | with and nothing was printed. */ |
917317f4 | 4752 | return PRINT_UNKNOWN; |
c906108c SS |
4753 | } |
4754 | ||
bf469271 | 4755 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4756 | |
bf469271 PA |
4757 | static bool |
4758 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4759 | { |
278cd55f | 4760 | struct value *mark = value_mark (); |
bf469271 | 4761 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4762 | |
c906108c | 4763 | value_free_to_mark (mark); |
bf469271 | 4764 | return res; |
c906108c SS |
4765 | } |
4766 | ||
5760d0ab | 4767 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4768 | |
04afa70c TT |
4769 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4770 | : next (NULL), | |
4771 | bp_location_at (bl), | |
4772 | breakpoint_at (bl->owner), | |
4773 | commands (NULL), | |
04afa70c TT |
4774 | print (0), |
4775 | stop (0), | |
4776 | print_it (print_it_normal) | |
c906108c | 4777 | { |
f431efe5 | 4778 | incref_bp_location (bl); |
04afa70c TT |
4779 | **bs_link_pointer = this; |
4780 | *bs_link_pointer = &next; | |
4781 | } | |
4782 | ||
4783 | bpstats::bpstats () | |
4784 | : next (NULL), | |
4785 | bp_location_at (NULL), | |
4786 | breakpoint_at (NULL), | |
4787 | commands (NULL), | |
04afa70c TT |
4788 | print (0), |
4789 | stop (0), | |
4790 | print_it (print_it_normal) | |
4791 | { | |
c906108c SS |
4792 | } |
4793 | \f | |
d983da9c DJ |
4794 | /* The target has stopped with waitstatus WS. Check if any hardware |
4795 | watchpoints have triggered, according to the target. */ | |
4796 | ||
4797 | int | |
4798 | watchpoints_triggered (struct target_waitstatus *ws) | |
4799 | { | |
57810aa7 | 4800 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4801 | CORE_ADDR addr; |
4802 | struct breakpoint *b; | |
4803 | ||
4804 | if (!stopped_by_watchpoint) | |
4805 | { | |
4806 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4807 | as not triggered. */ | |
4808 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4809 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4810 | { |
4811 | struct watchpoint *w = (struct watchpoint *) b; | |
4812 | ||
4813 | w->watchpoint_triggered = watch_triggered_no; | |
4814 | } | |
d983da9c DJ |
4815 | |
4816 | return 0; | |
4817 | } | |
4818 | ||
8b88a78e | 4819 | if (!target_stopped_data_address (current_top_target (), &addr)) |
d983da9c DJ |
4820 | { |
4821 | /* We were stopped by a watchpoint, but we don't know where. | |
4822 | Mark all watchpoints as unknown. */ | |
4823 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4824 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4825 | { |
4826 | struct watchpoint *w = (struct watchpoint *) b; | |
4827 | ||
4828 | w->watchpoint_triggered = watch_triggered_unknown; | |
4829 | } | |
d983da9c | 4830 | |
3c4797ba | 4831 | return 1; |
d983da9c DJ |
4832 | } |
4833 | ||
4834 | /* The target could report the data address. Mark watchpoints | |
4835 | affected by this data address as triggered, and all others as not | |
4836 | triggered. */ | |
4837 | ||
4838 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4839 | if (is_hardware_watchpoint (b)) |
d983da9c | 4840 | { |
3a5c3e22 | 4841 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4842 | struct bp_location *loc; |
d983da9c | 4843 | |
3a5c3e22 | 4844 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4845 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4846 | { |
3a5c3e22 | 4847 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4848 | { |
3a5c3e22 PA |
4849 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4850 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4851 | |
4852 | if (newaddr == start) | |
4853 | { | |
3a5c3e22 | 4854 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4855 | break; |
4856 | } | |
4857 | } | |
4858 | /* Exact match not required. Within range is sufficient. */ | |
8b88a78e | 4859 | else if (target_watchpoint_addr_within_range (current_top_target (), |
9c06b0b4 TJB |
4860 | addr, loc->address, |
4861 | loc->length)) | |
4862 | { | |
3a5c3e22 | 4863 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4864 | break; |
4865 | } | |
4866 | } | |
d983da9c DJ |
4867 | } |
4868 | ||
4869 | return 1; | |
4870 | } | |
4871 | ||
bf469271 PA |
4872 | /* Possible return values for watchpoint_check. */ |
4873 | enum wp_check_result | |
4874 | { | |
4875 | /* The watchpoint has been deleted. */ | |
4876 | WP_DELETED = 1, | |
4877 | ||
4878 | /* The value has changed. */ | |
4879 | WP_VALUE_CHANGED = 2, | |
4880 | ||
4881 | /* The value has not changed. */ | |
4882 | WP_VALUE_NOT_CHANGED = 3, | |
4883 | ||
4884 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4885 | WP_IGNORE = 4, | |
4886 | }; | |
c906108c SS |
4887 | |
4888 | #define BP_TEMPFLAG 1 | |
4889 | #define BP_HARDWAREFLAG 2 | |
4890 | ||
4a64f543 | 4891 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4892 | changed. */ |
553e4c11 | 4893 | |
bf469271 PA |
4894 | static wp_check_result |
4895 | watchpoint_check (bpstat bs) | |
c906108c | 4896 | { |
3a5c3e22 | 4897 | struct watchpoint *b; |
c906108c SS |
4898 | struct frame_info *fr; |
4899 | int within_current_scope; | |
4900 | ||
f431efe5 | 4901 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4902 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4903 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4904 | |
f6bc2008 PA |
4905 | /* If this is a local watchpoint, we only want to check if the |
4906 | watchpoint frame is in scope if the current thread is the thread | |
4907 | that was used to create the watchpoint. */ | |
4908 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4909 | return WP_IGNORE; |
f6bc2008 | 4910 | |
c906108c SS |
4911 | if (b->exp_valid_block == NULL) |
4912 | within_current_scope = 1; | |
4913 | else | |
4914 | { | |
edb3359d DJ |
4915 | struct frame_info *frame = get_current_frame (); |
4916 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4917 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4918 | ||
c9cf6e20 | 4919 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4920 | still in the function but the stack frame has already been |
4921 | invalidated. Since we can't rely on the values of local | |
4922 | variables after the stack has been destroyed, we are treating | |
4923 | the watchpoint in that state as `not changed' without further | |
4924 | checking. Don't mark watchpoints as changed if the current | |
4925 | frame is in an epilogue - even if they are in some other | |
4926 | frame, our view of the stack is likely to be wrong and | |
4927 | frame_find_by_id could error out. */ | |
c9cf6e20 | 4928 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 4929 | return WP_IGNORE; |
a0f49112 | 4930 | |
101dcfbe | 4931 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4932 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4933 | |
4934 | /* If we've gotten confused in the unwinder, we might have | |
4935 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4936 | if (within_current_scope) |
4937 | { | |
4938 | struct symbol *function; | |
4939 | ||
4940 | function = get_frame_function (fr); | |
4941 | if (function == NULL | |
4942 | || !contained_in (b->exp_valid_block, | |
4943 | SYMBOL_BLOCK_VALUE (function))) | |
4944 | within_current_scope = 0; | |
4945 | } | |
69fbadd5 | 4946 | |
edb3359d | 4947 | if (within_current_scope) |
c906108c SS |
4948 | /* If we end up stopping, the current frame will get selected |
4949 | in normal_stop. So this call to select_frame won't affect | |
4950 | the user. */ | |
0f7d239c | 4951 | select_frame (fr); |
c906108c | 4952 | } |
c5aa993b | 4953 | |
c906108c SS |
4954 | if (within_current_scope) |
4955 | { | |
4a64f543 | 4956 | /* We use value_{,free_to_}mark because it could be a *long* |
dda83cd7 SM |
4957 | time before we return to the command level and call |
4958 | free_all_values. We can't call free_all_values because we | |
4959 | might be in the middle of evaluating a function call. */ | |
c906108c | 4960 | |
0cf6dd15 | 4961 | int pc = 0; |
9c06b0b4 | 4962 | struct value *mark; |
fa4727a6 DJ |
4963 | struct value *new_val; |
4964 | ||
c1fc2657 | 4965 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
4966 | /* Since we don't know the exact trigger address (from |
4967 | stopped_data_address), just tell the user we've triggered | |
4968 | a mask watchpoint. */ | |
4969 | return WP_VALUE_CHANGED; | |
4970 | ||
4971 | mark = value_mark (); | |
4d01a485 | 4972 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4973 | |
bb9d5f81 PP |
4974 | if (b->val_bitsize != 0) |
4975 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
4976 | ||
4a64f543 MS |
4977 | /* We use value_equal_contents instead of value_equal because |
4978 | the latter coerces an array to a pointer, thus comparing just | |
4979 | the address of the array instead of its contents. This is | |
4980 | not what we want. */ | |
fa4727a6 | 4981 | if ((b->val != NULL) != (new_val != NULL) |
850645cf TT |
4982 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
4983 | new_val))) | |
c906108c | 4984 | { |
c906108c | 4985 | bs->old_val = b->val; |
850645cf | 4986 | b->val = release_value (new_val); |
4c1d86d9 | 4987 | b->val_valid = true; |
850645cf TT |
4988 | if (new_val != NULL) |
4989 | value_free_to_mark (mark); | |
c906108c SS |
4990 | return WP_VALUE_CHANGED; |
4991 | } | |
4992 | else | |
4993 | { | |
60e1c644 | 4994 | /* Nothing changed. */ |
c906108c | 4995 | value_free_to_mark (mark); |
c906108c SS |
4996 | return WP_VALUE_NOT_CHANGED; |
4997 | } | |
4998 | } | |
4999 | else | |
5000 | { | |
5001 | /* This seems like the only logical thing to do because | |
dda83cd7 SM |
5002 | if we temporarily ignored the watchpoint, then when |
5003 | we reenter the block in which it is valid it contains | |
5004 | garbage (in the case of a function, it may have two | |
5005 | garbage values, one before and one after the prologue). | |
5006 | So we can't even detect the first assignment to it and | |
5007 | watch after that (since the garbage may or may not equal | |
5008 | the first value assigned). */ | |
348d480f PA |
5009 | /* We print all the stop information in |
5010 | breakpoint_ops->print_it, but in this case, by the time we | |
5011 | call breakpoint_ops->print_it this bp will be deleted | |
5012 | already. So we have no choice but print the information | |
5013 | here. */ | |
468afe6c | 5014 | |
0e454242 | 5015 | SWITCH_THRU_ALL_UIS () |
dda83cd7 | 5016 | { |
468afe6c PA |
5017 | struct ui_out *uiout = current_uiout; |
5018 | ||
112e8700 SM |
5019 | if (uiout->is_mi_like_p ()) |
5020 | uiout->field_string | |
5021 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
6a831f06 PA |
5022 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
5023 | "left the block in\n" | |
5024 | "which its expression is valid.\n", | |
5025 | signed_field ("wpnum", b->number)); | |
468afe6c | 5026 | } |
4ce44c66 | 5027 | |
cdac0397 | 5028 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 5029 | b->commands = NULL; |
d0fb5eae | 5030 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5031 | |
5032 | return WP_DELETED; | |
5033 | } | |
5034 | } | |
5035 | ||
18a18393 | 5036 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5037 | breakpoint location BL. This function does not check if we should |
5038 | stop, only if BL explains the stop. */ | |
5039 | ||
18a18393 | 5040 | static int |
6c95b8df | 5041 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 5042 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5043 | const struct target_waitstatus *ws) |
18a18393 VP |
5044 | { |
5045 | struct breakpoint *b = bl->owner; | |
5046 | ||
348d480f | 5047 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5048 | gdb_assert (b != NULL); |
5049 | ||
bd522513 | 5050 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5051 | } |
5052 | ||
3a5c3e22 PA |
5053 | /* Determine if the watched values have actually changed, and we |
5054 | should stop. If not, set BS->stop to 0. */ | |
5055 | ||
18a18393 VP |
5056 | static void |
5057 | bpstat_check_watchpoint (bpstat bs) | |
5058 | { | |
2bdf28a0 | 5059 | const struct bp_location *bl; |
3a5c3e22 | 5060 | struct watchpoint *b; |
2bdf28a0 JK |
5061 | |
5062 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5063 | bl = bs->bp_location_at; |
2bdf28a0 | 5064 | gdb_assert (bl != NULL); |
3a5c3e22 | 5065 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5066 | gdb_assert (b != NULL); |
18a18393 | 5067 | |
18a18393 | 5068 | { |
18a18393 VP |
5069 | int must_check_value = 0; |
5070 | ||
c1fc2657 | 5071 | if (b->type == bp_watchpoint) |
18a18393 VP |
5072 | /* For a software watchpoint, we must always check the |
5073 | watched value. */ | |
5074 | must_check_value = 1; | |
5075 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5076 | /* We have a hardware watchpoint (read, write, or access) | |
5077 | and the target earlier reported an address watched by | |
5078 | this watchpoint. */ | |
5079 | must_check_value = 1; | |
5080 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5081 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5082 | /* We were stopped by a hardware watchpoint, but the target could |
5083 | not report the data address. We must check the watchpoint's | |
5084 | value. Access and read watchpoints are out of luck; without | |
5085 | a data address, we can't figure it out. */ | |
5086 | must_check_value = 1; | |
3a5c3e22 | 5087 | |
18a18393 VP |
5088 | if (must_check_value) |
5089 | { | |
bf469271 PA |
5090 | wp_check_result e; |
5091 | ||
a70b8144 | 5092 | try |
bf469271 PA |
5093 | { |
5094 | e = watchpoint_check (bs); | |
5095 | } | |
230d2906 | 5096 | catch (const gdb_exception &ex) |
bf469271 PA |
5097 | { |
5098 | exception_fprintf (gdb_stderr, ex, | |
5099 | "Error evaluating expression " | |
5100 | "for watchpoint %d\n", | |
5101 | b->number); | |
5102 | ||
5103 | SWITCH_THRU_ALL_UIS () | |
5104 | { | |
5105 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5106 | b->number); | |
5107 | } | |
5108 | watchpoint_del_at_next_stop (b); | |
5109 | e = WP_DELETED; | |
5110 | } | |
bf469271 | 5111 | |
18a18393 VP |
5112 | switch (e) |
5113 | { | |
5114 | case WP_DELETED: | |
5115 | /* We've already printed what needs to be printed. */ | |
5116 | bs->print_it = print_it_done; | |
5117 | /* Stop. */ | |
5118 | break; | |
60e1c644 PA |
5119 | case WP_IGNORE: |
5120 | bs->print_it = print_it_noop; | |
5121 | bs->stop = 0; | |
5122 | break; | |
18a18393 | 5123 | case WP_VALUE_CHANGED: |
c1fc2657 | 5124 | if (b->type == bp_read_watchpoint) |
18a18393 | 5125 | { |
85d721b8 PA |
5126 | /* There are two cases to consider here: |
5127 | ||
4a64f543 | 5128 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5129 | In that case, trust the target, and always report |
5130 | the watchpoint hit to the user. Even though | |
5131 | reads don't cause value changes, the value may | |
5132 | have changed since the last time it was read, and | |
5133 | since we're not trapping writes, we will not see | |
5134 | those, and as such we should ignore our notion of | |
5135 | old value. | |
5136 | ||
4a64f543 | 5137 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5138 | reads and writes. There are two ways this may |
5139 | happen: | |
5140 | ||
4a64f543 | 5141 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5142 | reads only, but can break on accesses (reads or |
5143 | writes), such as e.g., x86. We detect this case | |
5144 | at the time we try to insert read watchpoints. | |
5145 | ||
4a64f543 | 5146 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5147 | watchpoints, but, the user set an access or write |
5148 | watchpoint watching the same memory as this read | |
5149 | watchpoint. | |
5150 | ||
5151 | If we're watching memory writes as well as reads, | |
5152 | ignore watchpoint hits when we find that the | |
5153 | value hasn't changed, as reads don't cause | |
5154 | changes. This still gives false positives when | |
5155 | the program writes the same value to memory as | |
5156 | what there was already in memory (we will confuse | |
5157 | it for a read), but it's much better than | |
5158 | nothing. */ | |
5159 | ||
5160 | int other_write_watchpoint = 0; | |
5161 | ||
5162 | if (bl->watchpoint_type == hw_read) | |
5163 | { | |
5164 | struct breakpoint *other_b; | |
5165 | ||
5166 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5167 | if (other_b->type == bp_hardware_watchpoint |
5168 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5169 | { |
3a5c3e22 PA |
5170 | struct watchpoint *other_w = |
5171 | (struct watchpoint *) other_b; | |
5172 | ||
5173 | if (other_w->watchpoint_triggered | |
5174 | == watch_triggered_yes) | |
5175 | { | |
5176 | other_write_watchpoint = 1; | |
5177 | break; | |
5178 | } | |
85d721b8 PA |
5179 | } |
5180 | } | |
5181 | ||
5182 | if (other_write_watchpoint | |
5183 | || bl->watchpoint_type == hw_access) | |
5184 | { | |
5185 | /* We're watching the same memory for writes, | |
5186 | and the value changed since the last time we | |
5187 | updated it, so this trap must be for a write. | |
5188 | Ignore it. */ | |
5189 | bs->print_it = print_it_noop; | |
5190 | bs->stop = 0; | |
5191 | } | |
18a18393 VP |
5192 | } |
5193 | break; | |
5194 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5195 | if (b->type == bp_hardware_watchpoint |
5196 | || b->type == bp_watchpoint) | |
18a18393 VP |
5197 | { |
5198 | /* Don't stop: write watchpoints shouldn't fire if | |
5199 | the value hasn't changed. */ | |
5200 | bs->print_it = print_it_noop; | |
5201 | bs->stop = 0; | |
5202 | } | |
5203 | /* Stop. */ | |
5204 | break; | |
5205 | default: | |
5206 | /* Can't happen. */ | |
18a18393 VP |
5207 | break; |
5208 | } | |
5209 | } | |
5210 | else /* must_check_value == 0 */ | |
5211 | { | |
5212 | /* This is a case where some watchpoint(s) triggered, but | |
5213 | not at the address of this watchpoint, or else no | |
5214 | watchpoint triggered after all. So don't print | |
5215 | anything for this watchpoint. */ | |
5216 | bs->print_it = print_it_noop; | |
5217 | bs->stop = 0; | |
5218 | } | |
5219 | } | |
5220 | } | |
5221 | ||
7d4df6a4 DE |
5222 | /* For breakpoints that are currently marked as telling gdb to stop, |
5223 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5224 | of breakpoint referred to by BS. If we should not stop for this |
5225 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5226 | |
18a18393 | 5227 | static void |
00431a78 | 5228 | bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread) |
18a18393 | 5229 | { |
2bdf28a0 JK |
5230 | const struct bp_location *bl; |
5231 | struct breakpoint *b; | |
bf469271 PA |
5232 | /* Assume stop. */ |
5233 | bool condition_result = true; | |
7d4df6a4 DE |
5234 | struct expression *cond; |
5235 | ||
5236 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5237 | |
5238 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5239 | bl = bs->bp_location_at; |
2bdf28a0 | 5240 | gdb_assert (bl != NULL); |
f431efe5 | 5241 | b = bs->breakpoint_at; |
2bdf28a0 | 5242 | gdb_assert (b != NULL); |
18a18393 | 5243 | |
b775012e LM |
5244 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5245 | need to do so again since GDB does not know if we stopped due to a | |
5246 | breakpoint or a single step breakpoint. */ | |
5247 | ||
18a18393 | 5248 | if (frame_id_p (b->frame_id) |
edb3359d | 5249 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5250 | { |
7d4df6a4 DE |
5251 | bs->stop = 0; |
5252 | return; | |
5253 | } | |
60e1c644 | 5254 | |
12ab52e9 PA |
5255 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5256 | evaluating the condition if this isn't the specified | |
5257 | thread/task. */ | |
00431a78 PA |
5258 | if ((b->thread != -1 && b->thread != thread->global_num) |
5259 | || (b->task != 0 && b->task != ada_get_task_number (thread))) | |
6c1b0f7b DE |
5260 | { |
5261 | bs->stop = 0; | |
5262 | return; | |
5263 | } | |
5264 | ||
6dddc817 DE |
5265 | /* Evaluate extension language breakpoints that have a "stop" method |
5266 | implemented. */ | |
5267 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5268 | |
7d4df6a4 DE |
5269 | if (is_watchpoint (b)) |
5270 | { | |
5271 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5272 | |
4d01a485 | 5273 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5274 | } |
5275 | else | |
4d01a485 | 5276 | cond = bl->cond.get (); |
60e1c644 | 5277 | |
7d4df6a4 DE |
5278 | if (cond && b->disposition != disp_del_at_next_stop) |
5279 | { | |
5280 | int within_current_scope = 1; | |
5281 | struct watchpoint * w; | |
60e1c644 | 5282 | |
7d4df6a4 DE |
5283 | /* We use value_mark and value_free_to_mark because it could |
5284 | be a long time before we return to the command level and | |
5285 | call free_all_values. We can't call free_all_values | |
5286 | because we might be in the middle of evaluating a | |
5287 | function call. */ | |
5288 | struct value *mark = value_mark (); | |
5289 | ||
5290 | if (is_watchpoint (b)) | |
5291 | w = (struct watchpoint *) b; | |
5292 | else | |
5293 | w = NULL; | |
5294 | ||
5295 | /* Need to select the frame, with all that implies so that | |
5296 | the conditions will have the right context. Because we | |
5297 | use the frame, we will not see an inlined function's | |
5298 | variables when we arrive at a breakpoint at the start | |
5299 | of the inlined function; the current frame will be the | |
5300 | call site. */ | |
5301 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5302 | select_frame (get_current_frame ()); | |
5303 | else | |
18a18393 | 5304 | { |
7d4df6a4 DE |
5305 | struct frame_info *frame; |
5306 | ||
5307 | /* For local watchpoint expressions, which particular | |
5308 | instance of a local is being watched matters, so we | |
5309 | keep track of the frame to evaluate the expression | |
5310 | in. To evaluate the condition however, it doesn't | |
5311 | really matter which instantiation of the function | |
5312 | where the condition makes sense triggers the | |
5313 | watchpoint. This allows an expression like "watch | |
5314 | global if q > 10" set in `func', catch writes to | |
5315 | global on all threads that call `func', or catch | |
5316 | writes on all recursive calls of `func' by a single | |
5317 | thread. We simply always evaluate the condition in | |
5318 | the innermost frame that's executing where it makes | |
5319 | sense to evaluate the condition. It seems | |
5320 | intuitive. */ | |
5321 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5322 | if (frame != NULL) | |
5323 | select_frame (frame); | |
5324 | else | |
5325 | within_current_scope = 0; | |
18a18393 | 5326 | } |
7d4df6a4 | 5327 | if (within_current_scope) |
bf469271 | 5328 | { |
a70b8144 | 5329 | try |
bf469271 PA |
5330 | { |
5331 | condition_result = breakpoint_cond_eval (cond); | |
5332 | } | |
230d2906 | 5333 | catch (const gdb_exception &ex) |
bf469271 PA |
5334 | { |
5335 | exception_fprintf (gdb_stderr, ex, | |
5336 | "Error in testing breakpoint condition:\n"); | |
5337 | } | |
bf469271 | 5338 | } |
7d4df6a4 | 5339 | else |
18a18393 | 5340 | { |
7d4df6a4 DE |
5341 | warning (_("Watchpoint condition cannot be tested " |
5342 | "in the current scope")); | |
5343 | /* If we failed to set the right context for this | |
5344 | watchpoint, unconditionally report it. */ | |
18a18393 | 5345 | } |
7d4df6a4 DE |
5346 | /* FIXME-someday, should give breakpoint #. */ |
5347 | value_free_to_mark (mark); | |
18a18393 | 5348 | } |
7d4df6a4 | 5349 | |
bf469271 | 5350 | if (cond && !condition_result) |
7d4df6a4 DE |
5351 | { |
5352 | bs->stop = 0; | |
5353 | } | |
7d4df6a4 DE |
5354 | else if (b->ignore_count > 0) |
5355 | { | |
5356 | b->ignore_count--; | |
5357 | bs->stop = 0; | |
5358 | /* Increase the hit count even though we don't stop. */ | |
5359 | ++(b->hit_count); | |
76727919 | 5360 | gdb::observers::breakpoint_modified.notify (b); |
7d4df6a4 | 5361 | } |
18a18393 VP |
5362 | } |
5363 | ||
1cf4d951 PA |
5364 | /* Returns true if we need to track moribund locations of LOC's type |
5365 | on the current target. */ | |
5366 | ||
5367 | static int | |
5368 | need_moribund_for_location_type (struct bp_location *loc) | |
5369 | { | |
5370 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5371 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5372 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5373 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5374 | } | |
5375 | ||
ddfe970e | 5376 | /* See breakpoint.h. */ |
c906108c SS |
5377 | |
5378 | bpstat | |
ddfe970e | 5379 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5380 | const struct target_waitstatus *ws) |
c906108c | 5381 | { |
ddfe970e | 5382 | struct breakpoint *b; |
5760d0ab | 5383 | bpstat bs_head = NULL, *bs_link = &bs_head; |
c5aa993b | 5384 | |
429374b8 JK |
5385 | ALL_BREAKPOINTS (b) |
5386 | { | |
1a853c52 | 5387 | if (!breakpoint_enabled (b)) |
429374b8 | 5388 | continue; |
a5606eee | 5389 | |
ddfe970e | 5390 | for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) |
429374b8 | 5391 | { |
4a64f543 MS |
5392 | /* For hardware watchpoints, we look only at the first |
5393 | location. The watchpoint_check function will work on the | |
5394 | entire expression, not the individual locations. For | |
5395 | read watchpoints, the watchpoints_triggered function has | |
5396 | checked all locations already. */ | |
429374b8 JK |
5397 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5398 | break; | |
18a18393 | 5399 | |
b5fa468f | 5400 | if (!bl->enabled || bl->disabled_by_cond || bl->shlib_disabled) |
429374b8 | 5401 | continue; |
c5aa993b | 5402 | |
09ac7c10 | 5403 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5404 | continue; |
c5aa993b | 5405 | |
4a64f543 MS |
5406 | /* Come here if it's a watchpoint, or if the break address |
5407 | matches. */ | |
c5aa993b | 5408 | |
ddfe970e KS |
5409 | bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
5410 | explain stop. */ | |
c5aa993b | 5411 | |
f431efe5 PA |
5412 | /* Assume we stop. Should we find a watchpoint that is not |
5413 | actually triggered, or if the condition of the breakpoint | |
5414 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5415 | bs->stop = 1; |
5416 | bs->print = 1; | |
d983da9c | 5417 | |
f431efe5 PA |
5418 | /* If this is a scope breakpoint, mark the associated |
5419 | watchpoint as triggered so that we will handle the | |
5420 | out-of-scope event. We'll get to the watchpoint next | |
5421 | iteration. */ | |
d0fb5eae | 5422 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5423 | { |
5424 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5425 | ||
5426 | w->watchpoint_triggered = watch_triggered_yes; | |
5427 | } | |
f431efe5 PA |
5428 | } |
5429 | } | |
5430 | ||
7c16b83e | 5431 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5432 | if (!target_supports_stopped_by_sw_breakpoint () |
5433 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5434 | { |
1123588c | 5435 | for (bp_location *loc : moribund_locations) |
f431efe5 | 5436 | { |
1cf4d951 PA |
5437 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5438 | && need_moribund_for_location_type (loc)) | |
5439 | { | |
ddfe970e | 5440 | bpstat bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5441 | /* For hits of moribund locations, we should just proceed. */ |
5442 | bs->stop = 0; | |
5443 | bs->print = 0; | |
5444 | bs->print_it = print_it_noop; | |
5445 | } | |
f431efe5 PA |
5446 | } |
5447 | } | |
5448 | ||
ddfe970e KS |
5449 | return bs_head; |
5450 | } | |
5451 | ||
5452 | /* See breakpoint.h. */ | |
5453 | ||
5454 | bpstat | |
5455 | bpstat_stop_status (const address_space *aspace, | |
00431a78 | 5456 | CORE_ADDR bp_addr, thread_info *thread, |
ddfe970e KS |
5457 | const struct target_waitstatus *ws, |
5458 | bpstat stop_chain) | |
5459 | { | |
5460 | struct breakpoint *b = NULL; | |
5461 | /* First item of allocated bpstat's. */ | |
5462 | bpstat bs_head = stop_chain; | |
5463 | bpstat bs; | |
5464 | int need_remove_insert; | |
5465 | int removed_any; | |
5466 | ||
5467 | /* First, build the bpstat chain with locations that explain a | |
5468 | target stop, while being careful to not set the target running, | |
5469 | as that may invalidate locations (in particular watchpoint | |
5470 | locations are recreated). Resuming will happen here with | |
5471 | breakpoint conditions or watchpoint expressions that include | |
5472 | inferior function calls. */ | |
5473 | if (bs_head == NULL) | |
5474 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); | |
5475 | ||
edcc5120 TT |
5476 | /* A bit of special processing for shlib breakpoints. We need to |
5477 | process solib loading here, so that the lists of loaded and | |
5478 | unloaded libraries are correct before we handle "catch load" and | |
5479 | "catch unload". */ | |
5480 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5481 | { | |
5d268276 | 5482 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5483 | { |
5484 | handle_solib_event (); | |
5485 | break; | |
5486 | } | |
5487 | } | |
5488 | ||
f431efe5 PA |
5489 | /* Now go through the locations that caused the target to stop, and |
5490 | check whether we're interested in reporting this stop to higher | |
5491 | layers, or whether we should resume the target transparently. */ | |
5492 | ||
5493 | removed_any = 0; | |
5494 | ||
5760d0ab | 5495 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5496 | { |
5497 | if (!bs->stop) | |
5498 | continue; | |
5499 | ||
f431efe5 | 5500 | b = bs->breakpoint_at; |
348d480f PA |
5501 | b->ops->check_status (bs); |
5502 | if (bs->stop) | |
28010a5d | 5503 | { |
00431a78 | 5504 | bpstat_check_breakpoint_conditions (bs, thread); |
f431efe5 | 5505 | |
429374b8 JK |
5506 | if (bs->stop) |
5507 | { | |
5508 | ++(b->hit_count); | |
76727919 | 5509 | gdb::observers::breakpoint_modified.notify (b); |
c906108c | 5510 | |
4a64f543 | 5511 | /* We will stop here. */ |
429374b8 JK |
5512 | if (b->disposition == disp_disable) |
5513 | { | |
816338b5 | 5514 | --(b->enable_count); |
1a853c52 | 5515 | if (b->enable_count <= 0) |
429374b8 | 5516 | b->enable_state = bp_disabled; |
f431efe5 | 5517 | removed_any = 1; |
429374b8 JK |
5518 | } |
5519 | if (b->silent) | |
5520 | bs->print = 0; | |
5521 | bs->commands = b->commands; | |
abf85f46 | 5522 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5523 | ? bs->commands.get () : NULL)) |
abf85f46 | 5524 | bs->print = 0; |
9d6e6e84 HZ |
5525 | |
5526 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5527 | } |
5528 | ||
348d480f | 5529 | } |
a9b3a50f PA |
5530 | |
5531 | /* Print nothing for this entry if we don't stop or don't | |
5532 | print. */ | |
5533 | if (!bs->stop || !bs->print) | |
5534 | bs->print_it = print_it_noop; | |
429374b8 | 5535 | } |
876fa593 | 5536 | |
d983da9c DJ |
5537 | /* If we aren't stopping, the value of some hardware watchpoint may |
5538 | not have changed, but the intermediate memory locations we are | |
5539 | watching may have. Don't bother if we're stopping; this will get | |
5540 | done later. */ | |
d832cb68 | 5541 | need_remove_insert = 0; |
5760d0ab JK |
5542 | if (! bpstat_causes_stop (bs_head)) |
5543 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5544 | if (!bs->stop |
f431efe5 PA |
5545 | && bs->breakpoint_at |
5546 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5547 | { |
3a5c3e22 PA |
5548 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5549 | ||
5550 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5551 | need_remove_insert = 1; |
d983da9c DJ |
5552 | } |
5553 | ||
d832cb68 | 5554 | if (need_remove_insert) |
44702360 | 5555 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5556 | else if (removed_any) |
44702360 | 5557 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5558 | |
5760d0ab | 5559 | return bs_head; |
c906108c | 5560 | } |
628fe4e4 JK |
5561 | |
5562 | static void | |
61c26be8 | 5563 | handle_jit_event (CORE_ADDR address) |
628fe4e4 | 5564 | { |
628fe4e4 JK |
5565 | struct gdbarch *gdbarch; |
5566 | ||
1eb8556f | 5567 | infrun_debug_printf ("handling bp_jit_event"); |
243a9253 | 5568 | |
628fe4e4 JK |
5569 | /* Switch terminal for any messages produced by |
5570 | breakpoint_re_set. */ | |
223ffa71 | 5571 | target_terminal::ours_for_output (); |
628fe4e4 | 5572 | |
61c26be8 MS |
5573 | gdbarch = get_frame_arch (get_current_frame ()); |
5574 | /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`, | |
5575 | thus it is expected that its objectfile can be found through | |
5576 | minimal symbol lookup. If it doesn't work (and assert fails), it | |
5577 | most likely means that `jit_breakpoint_re_set` was changes and this | |
5578 | function needs to be updated too. */ | |
5579 | bound_minimal_symbol jit_bp_sym = lookup_minimal_symbol_by_pc (address); | |
5580 | gdb_assert (jit_bp_sym.objfile != nullptr); | |
5581 | jit_event_handler (gdbarch, jit_bp_sym.objfile); | |
628fe4e4 | 5582 | |
223ffa71 | 5583 | target_terminal::inferior (); |
628fe4e4 JK |
5584 | } |
5585 | ||
5586 | /* Prepare WHAT final decision for infrun. */ | |
5587 | ||
5588 | /* Decide what infrun needs to do with this bpstat. */ | |
5589 | ||
c906108c | 5590 | struct bpstat_what |
0e30163f | 5591 | bpstat_what (bpstat bs_head) |
c906108c | 5592 | { |
c906108c | 5593 | struct bpstat_what retval; |
0e30163f | 5594 | bpstat bs; |
c906108c | 5595 | |
628fe4e4 | 5596 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5597 | retval.call_dummy = STOP_NONE; |
e2d0f980 | 5598 | retval.is_longjmp = false; |
628fe4e4 | 5599 | |
0e30163f | 5600 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5601 | { |
628fe4e4 JK |
5602 | /* Extract this BS's action. After processing each BS, we check |
5603 | if its action overrides all we've seem so far. */ | |
5604 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5605 | enum bptype bptype; | |
5606 | ||
c906108c | 5607 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5608 | { |
5609 | /* I suspect this can happen if it was a momentary | |
5610 | breakpoint which has since been deleted. */ | |
5611 | bptype = bp_none; | |
5612 | } | |
20874c92 | 5613 | else |
f431efe5 | 5614 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5615 | |
5616 | switch (bptype) | |
c906108c SS |
5617 | { |
5618 | case bp_none: | |
628fe4e4 | 5619 | break; |
c906108c SS |
5620 | case bp_breakpoint: |
5621 | case bp_hardware_breakpoint: | |
7c16b83e | 5622 | case bp_single_step: |
c906108c SS |
5623 | case bp_until: |
5624 | case bp_finish: | |
a9b3a50f | 5625 | case bp_shlib_event: |
c906108c SS |
5626 | if (bs->stop) |
5627 | { | |
5628 | if (bs->print) | |
628fe4e4 | 5629 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5630 | else |
628fe4e4 | 5631 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5632 | } |
5633 | else | |
628fe4e4 | 5634 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5635 | break; |
5636 | case bp_watchpoint: | |
5637 | case bp_hardware_watchpoint: | |
5638 | case bp_read_watchpoint: | |
5639 | case bp_access_watchpoint: | |
5640 | if (bs->stop) | |
5641 | { | |
5642 | if (bs->print) | |
628fe4e4 | 5643 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5644 | else |
628fe4e4 | 5645 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5646 | } |
5647 | else | |
628fe4e4 JK |
5648 | { |
5649 | /* There was a watchpoint, but we're not stopping. | |
5650 | This requires no further action. */ | |
5651 | } | |
c906108c SS |
5652 | break; |
5653 | case bp_longjmp: | |
e2e4d78b | 5654 | case bp_longjmp_call_dummy: |
186c406b | 5655 | case bp_exception: |
0a39bb32 PA |
5656 | if (bs->stop) |
5657 | { | |
5658 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5659 | retval.is_longjmp = bptype != bp_exception; | |
5660 | } | |
5661 | else | |
5662 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5663 | break; |
5664 | case bp_longjmp_resume: | |
186c406b | 5665 | case bp_exception_resume: |
0a39bb32 PA |
5666 | if (bs->stop) |
5667 | { | |
5668 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5669 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5670 | } | |
5671 | else | |
5672 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5673 | break; |
5674 | case bp_step_resume: | |
5675 | if (bs->stop) | |
628fe4e4 JK |
5676 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5677 | else | |
c906108c | 5678 | { |
628fe4e4 JK |
5679 | /* It is for the wrong frame. */ |
5680 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5681 | } |
c906108c | 5682 | break; |
2c03e5be PA |
5683 | case bp_hp_step_resume: |
5684 | if (bs->stop) | |
5685 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5686 | else | |
5687 | { | |
5688 | /* It is for the wrong frame. */ | |
5689 | this_action = BPSTAT_WHAT_SINGLE; | |
5690 | } | |
5691 | break; | |
c906108c | 5692 | case bp_watchpoint_scope: |
c4093a6a | 5693 | case bp_thread_event: |
1900040c | 5694 | case bp_overlay_event: |
0fd8e87f | 5695 | case bp_longjmp_master: |
aa7d318d | 5696 | case bp_std_terminate_master: |
186c406b | 5697 | case bp_exception_master: |
628fe4e4 | 5698 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5699 | break; |
ce78b96d | 5700 | case bp_catchpoint: |
c5aa993b JM |
5701 | if (bs->stop) |
5702 | { | |
5703 | if (bs->print) | |
628fe4e4 | 5704 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5705 | else |
628fe4e4 | 5706 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5707 | } |
5708 | else | |
628fe4e4 | 5709 | { |
cb1e4e32 PA |
5710 | /* Some catchpoints are implemented with breakpoints. |
5711 | For those, we need to step over the breakpoint. */ | |
5712 | if (bs->bp_location_at->loc_type != bp_loc_other) | |
5713 | this_action = BPSTAT_WHAT_SINGLE; | |
628fe4e4 JK |
5714 | } |
5715 | break; | |
628fe4e4 | 5716 | case bp_jit_event: |
628fe4e4 | 5717 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5718 | break; |
c906108c | 5719 | case bp_call_dummy: |
53a5351d JM |
5720 | /* Make sure the action is stop (silent or noisy), |
5721 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5722 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5723 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5724 | break; |
5725 | case bp_std_terminate: | |
5726 | /* Make sure the action is stop (silent or noisy), | |
5727 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5728 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5729 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5730 | break; |
1042e4c0 | 5731 | case bp_tracepoint: |
7a697b8d | 5732 | case bp_fast_tracepoint: |
0fb4aa4b | 5733 | case bp_static_tracepoint: |
1042e4c0 SS |
5734 | /* Tracepoint hits should not be reported back to GDB, and |
5735 | if one got through somehow, it should have been filtered | |
5736 | out already. */ | |
5737 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5738 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5739 | break; |
5740 | case bp_gnu_ifunc_resolver: | |
5741 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5742 | this_action = BPSTAT_WHAT_SINGLE; | |
5743 | break; | |
5744 | case bp_gnu_ifunc_resolver_return: | |
5745 | /* The breakpoint will be removed, execution will restart from the | |
5746 | PC of the former breakpoint. */ | |
5747 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5748 | break; | |
e7e0cddf SS |
5749 | |
5750 | case bp_dprintf: | |
a11cfd87 HZ |
5751 | if (bs->stop) |
5752 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5753 | else | |
5754 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5755 | break; |
5756 | ||
628fe4e4 JK |
5757 | default: |
5758 | internal_error (__FILE__, __LINE__, | |
5759 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5760 | } |
628fe4e4 | 5761 | |
325fac50 | 5762 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5763 | } |
628fe4e4 | 5764 | |
243a9253 PA |
5765 | return retval; |
5766 | } | |
628fe4e4 | 5767 | |
243a9253 PA |
5768 | void |
5769 | bpstat_run_callbacks (bpstat bs_head) | |
5770 | { | |
5771 | bpstat bs; | |
628fe4e4 | 5772 | |
0e30163f JK |
5773 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5774 | { | |
5775 | struct breakpoint *b = bs->breakpoint_at; | |
5776 | ||
5777 | if (b == NULL) | |
5778 | continue; | |
5779 | switch (b->type) | |
5780 | { | |
243a9253 | 5781 | case bp_jit_event: |
61c26be8 | 5782 | handle_jit_event (bs->bp_location_at->address); |
243a9253 | 5783 | break; |
0e30163f JK |
5784 | case bp_gnu_ifunc_resolver: |
5785 | gnu_ifunc_resolver_stop (b); | |
5786 | break; | |
5787 | case bp_gnu_ifunc_resolver_return: | |
5788 | gnu_ifunc_resolver_return_stop (b); | |
5789 | break; | |
5790 | } | |
5791 | } | |
c906108c SS |
5792 | } |
5793 | ||
4c462cb0 | 5794 | /* See breakpoint.h. */ |
c906108c | 5795 | |
4c462cb0 SM |
5796 | bool |
5797 | bpstat_should_step () | |
c906108c SS |
5798 | { |
5799 | struct breakpoint *b; | |
cc59ec59 | 5800 | |
c906108c | 5801 | ALL_BREAKPOINTS (b) |
717a8278 | 5802 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
4c462cb0 SM |
5803 | return true; |
5804 | return false; | |
c906108c SS |
5805 | } |
5806 | ||
4c462cb0 SM |
5807 | /* See breakpoint.h. */ |
5808 | ||
5809 | bool | |
67822962 PA |
5810 | bpstat_causes_stop (bpstat bs) |
5811 | { | |
5812 | for (; bs != NULL; bs = bs->next) | |
5813 | if (bs->stop) | |
4c462cb0 | 5814 | return true; |
67822962 | 5815 | |
4c462cb0 | 5816 | return false; |
67822962 PA |
5817 | } |
5818 | ||
c906108c | 5819 | \f |
c5aa993b | 5820 | |
170b53b2 UW |
5821 | /* Compute a string of spaces suitable to indent the next line |
5822 | so it starts at the position corresponding to the table column | |
5823 | named COL_NAME in the currently active table of UIOUT. */ | |
5824 | ||
5825 | static char * | |
5826 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5827 | { | |
5828 | static char wrap_indent[80]; | |
5829 | int i, total_width, width, align; | |
c5209615 | 5830 | const char *text; |
170b53b2 UW |
5831 | |
5832 | total_width = 0; | |
112e8700 | 5833 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5834 | { |
5835 | if (strcmp (text, col_name) == 0) | |
5836 | { | |
5837 | gdb_assert (total_width < sizeof wrap_indent); | |
5838 | memset (wrap_indent, ' ', total_width); | |
5839 | wrap_indent[total_width] = 0; | |
5840 | ||
5841 | return wrap_indent; | |
5842 | } | |
5843 | ||
5844 | total_width += width + 1; | |
5845 | } | |
5846 | ||
5847 | return NULL; | |
5848 | } | |
5849 | ||
b775012e LM |
5850 | /* Determine if the locations of this breakpoint will have their conditions |
5851 | evaluated by the target, host or a mix of both. Returns the following: | |
5852 | ||
5853 | "host": Host evals condition. | |
5854 | "host or target": Host or Target evals condition. | |
5855 | "target": Target evals condition. | |
5856 | */ | |
5857 | ||
5858 | static const char * | |
5859 | bp_condition_evaluator (struct breakpoint *b) | |
5860 | { | |
5861 | struct bp_location *bl; | |
5862 | char host_evals = 0; | |
5863 | char target_evals = 0; | |
5864 | ||
5865 | if (!b) | |
5866 | return NULL; | |
5867 | ||
5868 | if (!is_breakpoint (b)) | |
5869 | return NULL; | |
5870 | ||
5871 | if (gdb_evaluates_breakpoint_condition_p () | |
5872 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5873 | return condition_evaluation_host; | |
5874 | ||
5875 | for (bl = b->loc; bl; bl = bl->next) | |
5876 | { | |
5877 | if (bl->cond_bytecode) | |
5878 | target_evals++; | |
5879 | else | |
5880 | host_evals++; | |
5881 | } | |
5882 | ||
5883 | if (host_evals && target_evals) | |
5884 | return condition_evaluation_both; | |
5885 | else if (target_evals) | |
5886 | return condition_evaluation_target; | |
5887 | else | |
5888 | return condition_evaluation_host; | |
5889 | } | |
5890 | ||
5891 | /* Determine the breakpoint location's condition evaluator. This is | |
5892 | similar to bp_condition_evaluator, but for locations. */ | |
5893 | ||
5894 | static const char * | |
5895 | bp_location_condition_evaluator (struct bp_location *bl) | |
5896 | { | |
5897 | if (bl && !is_breakpoint (bl->owner)) | |
5898 | return NULL; | |
5899 | ||
5900 | if (gdb_evaluates_breakpoint_condition_p () | |
5901 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5902 | return condition_evaluation_host; | |
5903 | ||
5904 | if (bl && bl->cond_bytecode) | |
5905 | return condition_evaluation_target; | |
5906 | else | |
5907 | return condition_evaluation_host; | |
5908 | } | |
5909 | ||
859825b8 JK |
5910 | /* Print the LOC location out of the list of B->LOC locations. */ |
5911 | ||
170b53b2 UW |
5912 | static void |
5913 | print_breakpoint_location (struct breakpoint *b, | |
5914 | struct bp_location *loc) | |
0d381245 | 5915 | { |
79a45e25 | 5916 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5917 | |
5918 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5919 | |
859825b8 JK |
5920 | if (loc != NULL && loc->shlib_disabled) |
5921 | loc = NULL; | |
5922 | ||
6c95b8df PA |
5923 | if (loc != NULL) |
5924 | set_current_program_space (loc->pspace); | |
5925 | ||
56435ebe | 5926 | if (b->display_canonical) |
d28cd78a | 5927 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 5928 | else if (loc && loc->symtab) |
0d381245 | 5929 | { |
4a27f119 KS |
5930 | const struct symbol *sym = loc->symbol; |
5931 | ||
0d381245 VP |
5932 | if (sym) |
5933 | { | |
112e8700 | 5934 | uiout->text ("in "); |
987012b8 | 5935 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 5936 | function_name_style.style ()); |
112e8700 SM |
5937 | uiout->text (" "); |
5938 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
5939 | uiout->text ("at "); | |
0d381245 | 5940 | } |
112e8700 | 5941 | uiout->field_string ("file", |
cbe56571 | 5942 | symtab_to_filename_for_display (loc->symtab), |
e43b10e1 | 5943 | file_name_style.style ()); |
112e8700 | 5944 | uiout->text (":"); |
05cba821 | 5945 | |
112e8700 SM |
5946 | if (uiout->is_mi_like_p ()) |
5947 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 5948 | |
381befee | 5949 | uiout->field_signed ("line", loc->line_number); |
0d381245 | 5950 | } |
859825b8 | 5951 | else if (loc) |
0d381245 | 5952 | { |
d7e74731 | 5953 | string_file stb; |
170b53b2 | 5954 | |
d7e74731 | 5955 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 5956 | demangle, ""); |
112e8700 | 5957 | uiout->field_stream ("at", stb); |
0d381245 | 5958 | } |
859825b8 | 5959 | else |
f00aae0f | 5960 | { |
d28cd78a TT |
5961 | uiout->field_string ("pending", |
5962 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
5963 | /* If extra_string is available, it could be holding a condition |
5964 | or dprintf arguments. In either case, make sure it is printed, | |
5965 | too, but only for non-MI streams. */ | |
112e8700 | 5966 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
5967 | { |
5968 | if (b->type == bp_dprintf) | |
112e8700 | 5969 | uiout->text (","); |
f00aae0f | 5970 | else |
112e8700 SM |
5971 | uiout->text (" "); |
5972 | uiout->text (b->extra_string); | |
f00aae0f KS |
5973 | } |
5974 | } | |
6c95b8df | 5975 | |
b775012e LM |
5976 | if (loc && is_breakpoint (b) |
5977 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5978 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5979 | { | |
112e8700 SM |
5980 | uiout->text (" ("); |
5981 | uiout->field_string ("evaluated-by", | |
b775012e | 5982 | bp_location_condition_evaluator (loc)); |
112e8700 | 5983 | uiout->text (")"); |
b775012e | 5984 | } |
0d381245 VP |
5985 | } |
5986 | ||
269b11a2 PA |
5987 | static const char * |
5988 | bptype_string (enum bptype type) | |
c906108c | 5989 | { |
c4093a6a JM |
5990 | struct ep_type_description |
5991 | { | |
5992 | enum bptype type; | |
a121b7c1 | 5993 | const char *description; |
c4093a6a JM |
5994 | }; |
5995 | static struct ep_type_description bptypes[] = | |
c906108c | 5996 | { |
c5aa993b JM |
5997 | {bp_none, "?deleted?"}, |
5998 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5999 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6000 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6001 | {bp_until, "until"}, |
6002 | {bp_finish, "finish"}, | |
6003 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6004 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6005 | {bp_read_watchpoint, "read watchpoint"}, |
6006 | {bp_access_watchpoint, "acc watchpoint"}, | |
6007 | {bp_longjmp, "longjmp"}, | |
6008 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6009 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6010 | {bp_exception, "exception"}, |
6011 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6012 | {bp_step_resume, "step resume"}, |
2c03e5be | 6013 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6014 | {bp_watchpoint_scope, "watchpoint scope"}, |
6015 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6016 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6017 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6018 | {bp_thread_event, "thread events"}, |
1900040c | 6019 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6020 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6021 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6022 | {bp_exception_master, "exception master"}, |
ce78b96d | 6023 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6024 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6025 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6026 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6027 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6028 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6029 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6030 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6031 | }; |
269b11a2 PA |
6032 | |
6033 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6034 | || ((int) type != bptypes[(int) type].type)) | |
6035 | internal_error (__FILE__, __LINE__, | |
6036 | _("bptypes table does not describe type #%d."), | |
6037 | (int) type); | |
6038 | ||
6039 | return bptypes[(int) type].description; | |
6040 | } | |
6041 | ||
998580f1 MK |
6042 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6043 | For CLI, prefix the list with the string 'inf'. */ | |
6044 | ||
6045 | static void | |
6046 | output_thread_groups (struct ui_out *uiout, | |
6047 | const char *field_name, | |
5c632425 | 6048 | const std::vector<int> &inf_nums, |
998580f1 MK |
6049 | int mi_only) |
6050 | { | |
112e8700 | 6051 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6052 | |
6053 | /* For backward compatibility, don't display inferiors in CLI unless | |
6054 | there are several. Always display them for MI. */ | |
6055 | if (!is_mi && mi_only) | |
6056 | return; | |
6057 | ||
10f489e5 | 6058 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6059 | |
5c632425 | 6060 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
6061 | { |
6062 | if (is_mi) | |
6063 | { | |
6064 | char mi_group[10]; | |
6065 | ||
5c632425 | 6066 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 6067 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6068 | } |
6069 | else | |
6070 | { | |
6071 | if (i == 0) | |
112e8700 | 6072 | uiout->text (" inf "); |
998580f1 | 6073 | else |
112e8700 | 6074 | uiout->text (", "); |
998580f1 | 6075 | |
5c632425 | 6076 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
6077 | } |
6078 | } | |
998580f1 MK |
6079 | } |
6080 | ||
a38118e5 PA |
6081 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
6082 | instead of going via breakpoint_ops::print_one. This makes "maint | |
6083 | info breakpoints" show the software breakpoint locations of | |
6084 | catchpoints, which are considered internal implementation | |
6085 | detail. */ | |
269b11a2 PA |
6086 | |
6087 | static void | |
6088 | print_one_breakpoint_location (struct breakpoint *b, | |
6089 | struct bp_location *loc, | |
6090 | int loc_number, | |
6091 | struct bp_location **last_loc, | |
a38118e5 | 6092 | int allflag, bool raw_loc) |
269b11a2 PA |
6093 | { |
6094 | struct command_line *l; | |
c2c6d25f | 6095 | static char bpenables[] = "nynny"; |
c906108c | 6096 | |
79a45e25 | 6097 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6098 | int header_of_multiple = 0; |
6099 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6100 | struct value_print_options opts; |
6101 | ||
6102 | get_user_print_options (&opts); | |
0d381245 VP |
6103 | |
6104 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6105 | /* See comment in print_one_breakpoint concerning treatment of |
6106 | breakpoints with single disabled location. */ | |
0d381245 VP |
6107 | if (loc == NULL |
6108 | && (b->loc != NULL | |
b5fa468f TBA |
6109 | && (b->loc->next != NULL |
6110 | || !b->loc->enabled || b->loc->disabled_by_cond))) | |
0d381245 VP |
6111 | header_of_multiple = 1; |
6112 | if (loc == NULL) | |
6113 | loc = b->loc; | |
6114 | ||
c4093a6a JM |
6115 | annotate_record (); |
6116 | ||
6117 | /* 1 */ | |
6118 | annotate_field (0); | |
0d381245 | 6119 | if (part_of_multiple) |
528e1572 | 6120 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
0d381245 | 6121 | else |
381befee | 6122 | uiout->field_signed ("number", b->number); |
c4093a6a JM |
6123 | |
6124 | /* 2 */ | |
6125 | annotate_field (1); | |
0d381245 | 6126 | if (part_of_multiple) |
112e8700 | 6127 | uiout->field_skip ("type"); |
269b11a2 | 6128 | else |
112e8700 | 6129 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6130 | |
6131 | /* 3 */ | |
6132 | annotate_field (2); | |
0d381245 | 6133 | if (part_of_multiple) |
112e8700 | 6134 | uiout->field_skip ("disp"); |
0d381245 | 6135 | else |
112e8700 | 6136 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6137 | |
c4093a6a JM |
6138 | /* 4 */ |
6139 | annotate_field (3); | |
0d381245 | 6140 | if (part_of_multiple) |
b5fa468f TBA |
6141 | uiout->field_string ("enabled", (loc->disabled_by_cond ? "N*" |
6142 | : (loc->enabled ? "y" : "n"))); | |
0d381245 | 6143 | else |
112e8700 | 6144 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
0d381245 | 6145 | |
c4093a6a | 6146 | /* 5 and 6 */ |
a38118e5 | 6147 | if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL) |
b58a68fe | 6148 | b->ops->print_one (b, last_loc); |
3086aeae | 6149 | else |
a38118e5 PA |
6150 | { |
6151 | if (is_watchpoint (b)) | |
3a5c3e22 PA |
6152 | { |
6153 | struct watchpoint *w = (struct watchpoint *) b; | |
6154 | ||
6155 | /* Field 4, the address, is omitted (which makes the columns | |
6156 | not line up too nicely with the headers, but the effect | |
6157 | is relatively readable). */ | |
6158 | if (opts.addressprint) | |
112e8700 | 6159 | uiout->field_skip ("addr"); |
3a5c3e22 | 6160 | annotate_field (5); |
112e8700 | 6161 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6162 | } |
f06f1252 TT |
6163 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
6164 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6165 | { |
6166 | if (opts.addressprint) | |
6167 | { | |
6168 | annotate_field (4); | |
6169 | if (header_of_multiple) | |
7f6aba03 TT |
6170 | uiout->field_string ("addr", "<MULTIPLE>", |
6171 | metadata_style.style ()); | |
a38118e5 | 6172 | else if (b->loc == NULL || loc->shlib_disabled) |
7f6aba03 TT |
6173 | uiout->field_string ("addr", "<PENDING>", |
6174 | metadata_style.style ()); | |
a38118e5 PA |
6175 | else |
6176 | uiout->field_core_addr ("addr", | |
6177 | loc->gdbarch, loc->address); | |
6178 | } | |
6179 | annotate_field (5); | |
6180 | if (!header_of_multiple) | |
6181 | print_breakpoint_location (b, loc); | |
6182 | if (b->loc) | |
6183 | *last_loc = b->loc; | |
6184 | } | |
6185 | } | |
6c95b8df | 6186 | |
998580f1 | 6187 | if (loc != NULL && !header_of_multiple) |
6c95b8df | 6188 | { |
5c632425 | 6189 | std::vector<int> inf_nums; |
998580f1 | 6190 | int mi_only = 1; |
6c95b8df | 6191 | |
08036331 | 6192 | for (inferior *inf : all_inferiors ()) |
6c95b8df PA |
6193 | { |
6194 | if (inf->pspace == loc->pspace) | |
5c632425 | 6195 | inf_nums.push_back (inf->num); |
6c95b8df | 6196 | } |
998580f1 | 6197 | |
dda83cd7 | 6198 | /* For backward compatibility, don't display inferiors in CLI unless |
998580f1 MK |
6199 | there are several. Always display for MI. */ |
6200 | if (allflag | |
6201 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
94c93c35 | 6202 | && (program_spaces.size () > 1 |
998580f1 MK |
6203 | || number_of_inferiors () > 1) |
6204 | /* LOC is for existing B, it cannot be in | |
6205 | moribund_locations and thus having NULL OWNER. */ | |
6206 | && loc->owner->type != bp_catchpoint)) | |
6207 | mi_only = 0; | |
5c632425 | 6208 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6209 | } |
6210 | ||
4a306c9a | 6211 | if (!part_of_multiple) |
c4093a6a | 6212 | { |
4a306c9a JB |
6213 | if (b->thread != -1) |
6214 | { | |
6215 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6216 | "stop only in" line a little further down. */ |
112e8700 | 6217 | uiout->text (" thread "); |
381befee | 6218 | uiout->field_signed ("thread", b->thread); |
4a306c9a JB |
6219 | } |
6220 | else if (b->task != 0) | |
6221 | { | |
112e8700 | 6222 | uiout->text (" task "); |
381befee | 6223 | uiout->field_signed ("task", b->task); |
4a306c9a | 6224 | } |
c4093a6a | 6225 | } |
f1310107 | 6226 | |
112e8700 | 6227 | uiout->text ("\n"); |
f1310107 | 6228 | |
348d480f | 6229 | if (!part_of_multiple) |
f1310107 TJB |
6230 | b->ops->print_one_detail (b, uiout); |
6231 | ||
0d381245 | 6232 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6233 | { |
6234 | annotate_field (6); | |
112e8700 | 6235 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6236 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
dda83cd7 | 6237 | the frame ID. */ |
112e8700 | 6238 | uiout->field_core_addr ("frame", |
5af949e3 | 6239 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6240 | uiout->text ("\n"); |
c4093a6a JM |
6241 | } |
6242 | ||
28010a5d | 6243 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6244 | { |
6245 | annotate_field (7); | |
d77f58be | 6246 | if (is_tracepoint (b)) |
112e8700 | 6247 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6248 | else |
112e8700 SM |
6249 | uiout->text ("\tstop only if "); |
6250 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6251 | |
6252 | /* Print whether the target is doing the breakpoint's condition | |
6253 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6254 | if (is_breakpoint (b) | |
6255 | && breakpoint_condition_evaluation_mode () | |
6256 | == condition_evaluation_target) | |
6257 | { | |
6a831f06 PA |
6258 | uiout->message (" (%pF evals)", |
6259 | string_field ("evaluated-by", | |
6260 | bp_condition_evaluator (b))); | |
b775012e | 6261 | } |
112e8700 | 6262 | uiout->text ("\n"); |
0101ce28 JJ |
6263 | } |
6264 | ||
0d381245 | 6265 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6266 | { |
4a64f543 | 6267 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6268 | uiout->text ("\tstop only in thread "); |
6269 | if (uiout->is_mi_like_p ()) | |
381befee | 6270 | uiout->field_signed ("thread", b->thread); |
5d5658a1 PA |
6271 | else |
6272 | { | |
6273 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6274 | ||
112e8700 | 6275 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6276 | } |
112e8700 | 6277 | uiout->text ("\n"); |
c4093a6a JM |
6278 | } |
6279 | ||
556ec64d YQ |
6280 | if (!part_of_multiple) |
6281 | { | |
6282 | if (b->hit_count) | |
31f56a27 YQ |
6283 | { |
6284 | /* FIXME should make an annotation for this. */ | |
6285 | if (is_catchpoint (b)) | |
112e8700 | 6286 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6287 | else if (is_tracepoint (b)) |
112e8700 | 6288 | uiout->text ("\ttracepoint"); |
31f56a27 | 6289 | else |
112e8700 SM |
6290 | uiout->text ("\tbreakpoint"); |
6291 | uiout->text (" already hit "); | |
381befee | 6292 | uiout->field_signed ("times", b->hit_count); |
31f56a27 | 6293 | if (b->hit_count == 1) |
112e8700 | 6294 | uiout->text (" time\n"); |
31f56a27 | 6295 | else |
112e8700 | 6296 | uiout->text (" times\n"); |
31f56a27 | 6297 | } |
556ec64d YQ |
6298 | else |
6299 | { | |
31f56a27 | 6300 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 | 6301 | if (uiout->is_mi_like_p ()) |
381befee | 6302 | uiout->field_signed ("times", b->hit_count); |
556ec64d YQ |
6303 | } |
6304 | } | |
8b93c638 | 6305 | |
0d381245 | 6306 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6307 | { |
6308 | annotate_field (8); | |
6a831f06 PA |
6309 | uiout->message ("\tignore next %pF hits\n", |
6310 | signed_field ("ignore", b->ignore_count)); | |
c4093a6a | 6311 | } |
059fb39f | 6312 | |
816338b5 SS |
6313 | /* Note that an enable count of 1 corresponds to "enable once" |
6314 | behavior, which is reported by the combination of enablement and | |
6315 | disposition, so we don't need to mention it here. */ | |
6316 | if (!part_of_multiple && b->enable_count > 1) | |
6317 | { | |
6318 | annotate_field (8); | |
112e8700 | 6319 | uiout->text ("\tdisable after "); |
816338b5 SS |
6320 | /* Tweak the wording to clarify that ignore and enable counts |
6321 | are distinct, and have additive effect. */ | |
6322 | if (b->ignore_count) | |
112e8700 | 6323 | uiout->text ("additional "); |
816338b5 | 6324 | else |
112e8700 | 6325 | uiout->text ("next "); |
381befee | 6326 | uiout->field_signed ("enable", b->enable_count); |
112e8700 | 6327 | uiout->text (" hits\n"); |
816338b5 SS |
6328 | } |
6329 | ||
f196051f SS |
6330 | if (!part_of_multiple && is_tracepoint (b)) |
6331 | { | |
6332 | struct tracepoint *tp = (struct tracepoint *) b; | |
6333 | ||
6334 | if (tp->traceframe_usage) | |
6335 | { | |
112e8700 | 6336 | uiout->text ("\ttrace buffer usage "); |
381befee | 6337 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
112e8700 | 6338 | uiout->text (" bytes\n"); |
f196051f SS |
6339 | } |
6340 | } | |
d3ce09f5 | 6341 | |
d1b0a7bf | 6342 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6343 | if (!part_of_multiple && l) |
c4093a6a JM |
6344 | { |
6345 | annotate_field (9); | |
2e783024 | 6346 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6347 | print_command_lines (uiout, l, 4); |
c4093a6a | 6348 | } |
d24317b4 | 6349 | |
d9b3f62e | 6350 | if (is_tracepoint (b)) |
1042e4c0 | 6351 | { |
d9b3f62e PA |
6352 | struct tracepoint *t = (struct tracepoint *) b; |
6353 | ||
6354 | if (!part_of_multiple && t->pass_count) | |
6355 | { | |
6356 | annotate_field (10); | |
112e8700 | 6357 | uiout->text ("\tpass count "); |
381befee | 6358 | uiout->field_signed ("pass", t->pass_count); |
112e8700 | 6359 | uiout->text (" \n"); |
d9b3f62e | 6360 | } |
f2a8bc8a YQ |
6361 | |
6362 | /* Don't display it when tracepoint or tracepoint location is | |
6363 | pending. */ | |
6364 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6365 | { | |
6366 | annotate_field (11); | |
6367 | ||
112e8700 SM |
6368 | if (uiout->is_mi_like_p ()) |
6369 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6370 | loc->inserted ? "y" : "n"); |
6371 | else | |
6372 | { | |
6373 | if (loc->inserted) | |
112e8700 | 6374 | uiout->text ("\t"); |
f2a8bc8a | 6375 | else |
112e8700 SM |
6376 | uiout->text ("\tnot "); |
6377 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6378 | } |
6379 | } | |
1042e4c0 SS |
6380 | } |
6381 | ||
112e8700 | 6382 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6383 | { |
3a5c3e22 PA |
6384 | if (is_watchpoint (b)) |
6385 | { | |
6386 | struct watchpoint *w = (struct watchpoint *) b; | |
6387 | ||
112e8700 | 6388 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6389 | } |
f00aae0f | 6390 | else if (b->location != NULL |
d28cd78a | 6391 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6392 | uiout->field_string ("original-location", |
d28cd78a | 6393 | event_location_to_string (b->location.get ())); |
d24317b4 | 6394 | } |
c4093a6a | 6395 | } |
c5aa993b | 6396 | |
13674803 SM |
6397 | /* See breakpoint.h. */ |
6398 | ||
6399 | bool fix_multi_location_breakpoint_output_globally = false; | |
6400 | ||
0d381245 VP |
6401 | static void |
6402 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6403 | struct bp_location **last_loc, |
6c95b8df | 6404 | int allflag) |
0d381245 | 6405 | { |
79a45e25 | 6406 | struct ui_out *uiout = current_uiout; |
13674803 SM |
6407 | bool use_fixed_output |
6408 | = (uiout->test_flags (fix_multi_location_breakpoint_output) | |
6409 | || fix_multi_location_breakpoint_output_globally); | |
8d3788bd | 6410 | |
b4be1b06 | 6411 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
a38118e5 | 6412 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false); |
8d3788bd | 6413 | |
b4be1b06 SM |
6414 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
6415 | are outside. */ | |
6416 | if (!use_fixed_output) | |
6417 | bkpt_tuple_emitter.reset (); | |
0d381245 VP |
6418 | |
6419 | /* If this breakpoint has custom print function, | |
6420 | it's already printed. Otherwise, print individual | |
6421 | locations, if any. */ | |
a38118e5 PA |
6422 | if (b->ops == NULL |
6423 | || b->ops->print_one == NULL | |
6424 | || allflag) | |
0d381245 | 6425 | { |
4a64f543 MS |
6426 | /* If breakpoint has a single location that is disabled, we |
6427 | print it as if it had several locations, since otherwise it's | |
6428 | hard to represent "breakpoint enabled, location disabled" | |
6429 | situation. | |
6430 | ||
6431 | Note that while hardware watchpoints have several locations | |
a38118e5 PA |
6432 | internally, that's not a property exposed to users. |
6433 | ||
6434 | Likewise, while catchpoints may be implemented with | |
6435 | breakpoints (e.g., catch throw), that's not a property | |
6436 | exposed to users. We do however display the internal | |
6437 | breakpoint locations with "maint info breakpoints". */ | |
6438 | if (!is_hardware_watchpoint (b) | |
f06f1252 TT |
6439 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
6440 | || is_ada_exception_catchpoint (b)) | |
a38118e5 | 6441 | && (allflag |
b5fa468f TBA |
6442 | || (b->loc && (b->loc->next |
6443 | || !b->loc->enabled | |
6444 | || b->loc->disabled_by_cond)))) | |
0d381245 | 6445 | { |
b4be1b06 SM |
6446 | gdb::optional<ui_out_emit_list> locations_list; |
6447 | ||
6448 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid | |
6449 | MI record. For later versions, place breakpoint locations in a | |
6450 | list. */ | |
6451 | if (uiout->is_mi_like_p () && use_fixed_output) | |
6452 | locations_list.emplace (uiout, "locations"); | |
8d3788bd | 6453 | |
b4be1b06 SM |
6454 | int n = 1; |
6455 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) | |
8d3788bd | 6456 | { |
b4be1b06 | 6457 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
a38118e5 PA |
6458 | print_one_breakpoint_location (b, loc, n, last_loc, |
6459 | allflag, allflag); | |
8d3788bd | 6460 | } |
0d381245 VP |
6461 | } |
6462 | } | |
6463 | } | |
6464 | ||
a6d9a66e UW |
6465 | static int |
6466 | breakpoint_address_bits (struct breakpoint *b) | |
6467 | { | |
6468 | int print_address_bits = 0; | |
6469 | struct bp_location *loc; | |
6470 | ||
c6d81124 PA |
6471 | /* Software watchpoints that aren't watching memory don't have an |
6472 | address to print. */ | |
6473 | if (is_no_memory_software_watchpoint (b)) | |
6474 | return 0; | |
6475 | ||
a6d9a66e UW |
6476 | for (loc = b->loc; loc; loc = loc->next) |
6477 | { | |
c7437ca6 PA |
6478 | int addr_bit; |
6479 | ||
c7437ca6 | 6480 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6481 | if (addr_bit > print_address_bits) |
6482 | print_address_bits = addr_bit; | |
6483 | } | |
6484 | ||
6485 | return print_address_bits; | |
6486 | } | |
0d381245 | 6487 | |
65630365 | 6488 | /* See breakpoint.h. */ |
c5aa993b | 6489 | |
65630365 PA |
6490 | void |
6491 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6492 | { |
a6d9a66e | 6493 | struct bp_location *dummy_loc = NULL; |
65630365 | 6494 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6495 | } |
c5aa993b | 6496 | |
09d682a4 TT |
6497 | /* Return true if this breakpoint was set by the user, false if it is |
6498 | internal or momentary. */ | |
6499 | ||
6500 | int | |
6501 | user_breakpoint_p (struct breakpoint *b) | |
6502 | { | |
46c6471b | 6503 | return b->number > 0; |
09d682a4 TT |
6504 | } |
6505 | ||
93daf339 TT |
6506 | /* See breakpoint.h. */ |
6507 | ||
6508 | int | |
6509 | pending_breakpoint_p (struct breakpoint *b) | |
6510 | { | |
6511 | return b->loc == NULL; | |
6512 | } | |
6513 | ||
5c458ae8 SM |
6514 | /* Print information on breakpoints (including watchpoints and tracepoints). |
6515 | ||
6516 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as | |
6517 | understood by number_or_range_parser. Only breakpoints included in this | |
6518 | list are then printed. | |
6519 | ||
6520 | If SHOW_INTERNAL is true, print internal breakpoints. | |
6521 | ||
6522 | If FILTER is non-NULL, call it on each breakpoint and only include the | |
6523 | ones for which it returns true. | |
6524 | ||
6525 | Return the total number of breakpoints listed. */ | |
c906108c | 6526 | |
d77f58be | 6527 | static int |
5c458ae8 | 6528 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
f2478a7e | 6529 | bool (*filter) (const struct breakpoint *)) |
c4093a6a | 6530 | { |
52f0bd74 | 6531 | struct breakpoint *b; |
a6d9a66e | 6532 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6533 | int nr_printable_breakpoints; |
79a45b7d | 6534 | struct value_print_options opts; |
a6d9a66e | 6535 | int print_address_bits = 0; |
269b11a2 | 6536 | int print_type_col_width = 14; |
79a45e25 | 6537 | struct ui_out *uiout = current_uiout; |
b5fa468f | 6538 | bool has_disabled_by_cond_location = false; |
269b11a2 | 6539 | |
79a45b7d TT |
6540 | get_user_print_options (&opts); |
6541 | ||
4a64f543 MS |
6542 | /* Compute the number of rows in the table, as well as the size |
6543 | required for address fields. */ | |
7f3b0473 AC |
6544 | nr_printable_breakpoints = 0; |
6545 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6546 | { |
6547 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6548 | if (filter && !filter (b)) | |
6549 | continue; | |
6550 | ||
5c458ae8 | 6551 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
e5a67952 | 6552 | accept. Skip the others. */ |
5c458ae8 | 6553 | if (bp_num_list != NULL && *bp_num_list != '\0') |
e5a67952 | 6554 | { |
5c458ae8 | 6555 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
e5a67952 | 6556 | continue; |
5c458ae8 | 6557 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
e5a67952 MS |
6558 | continue; |
6559 | } | |
269b11a2 | 6560 | |
5c458ae8 | 6561 | if (show_internal || user_breakpoint_p (b)) |
e5a67952 MS |
6562 | { |
6563 | int addr_bit, type_len; | |
a6d9a66e | 6564 | |
e5a67952 MS |
6565 | addr_bit = breakpoint_address_bits (b); |
6566 | if (addr_bit > print_address_bits) | |
6567 | print_address_bits = addr_bit; | |
269b11a2 | 6568 | |
e5a67952 MS |
6569 | type_len = strlen (bptype_string (b->type)); |
6570 | if (type_len > print_type_col_width) | |
6571 | print_type_col_width = type_len; | |
6572 | ||
6573 | nr_printable_breakpoints++; | |
6574 | } | |
6575 | } | |
7f3b0473 | 6576 | |
4a2b031d TT |
6577 | { |
6578 | ui_out_emit_table table_emitter (uiout, | |
6579 | opts.addressprint ? 6 : 5, | |
6580 | nr_printable_breakpoints, | |
6581 | "BreakpointTable"); | |
6582 | ||
6583 | if (nr_printable_breakpoints > 0) | |
6584 | annotate_breakpoints_headers (); | |
6585 | if (nr_printable_breakpoints > 0) | |
6586 | annotate_field (0); | |
6587 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6588 | if (nr_printable_breakpoints > 0) | |
6589 | annotate_field (1); | |
6590 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6591 | if (nr_printable_breakpoints > 0) | |
6592 | annotate_field (2); | |
6593 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6594 | if (nr_printable_breakpoints > 0) | |
6595 | annotate_field (3); | |
6596 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6597 | if (opts.addressprint) | |
6598 | { | |
6599 | if (nr_printable_breakpoints > 0) | |
6600 | annotate_field (4); | |
6601 | if (print_address_bits <= 32) | |
6602 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6603 | else | |
6604 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6605 | } | |
6606 | if (nr_printable_breakpoints > 0) | |
6607 | annotate_field (5); | |
6608 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6609 | uiout->table_body (); | |
6610 | if (nr_printable_breakpoints > 0) | |
6611 | annotate_breakpoints_table (); | |
6612 | ||
6613 | ALL_BREAKPOINTS (b) | |
6614 | { | |
6615 | QUIT; | |
6616 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6617 | if (filter && !filter (b)) | |
6618 | continue; | |
e5a67952 | 6619 | |
5c458ae8 | 6620 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
4a2b031d | 6621 | accept. Skip the others. */ |
e5a67952 | 6622 | |
5c458ae8 | 6623 | if (bp_num_list != NULL && *bp_num_list != '\0') |
4a2b031d | 6624 | { |
5c458ae8 | 6625 | if (show_internal) /* maintenance info breakpoint */ |
4a2b031d | 6626 | { |
5c458ae8 | 6627 | if (parse_and_eval_long (bp_num_list) != b->number) |
4a2b031d TT |
6628 | continue; |
6629 | } | |
6630 | else /* all others */ | |
6631 | { | |
5c458ae8 | 6632 | if (!number_is_in_list (bp_num_list, b->number)) |
4a2b031d TT |
6633 | continue; |
6634 | } | |
6635 | } | |
6636 | /* We only print out user settable breakpoints unless the | |
5c458ae8 SM |
6637 | show_internal is set. */ |
6638 | if (show_internal || user_breakpoint_p (b)) | |
b5fa468f TBA |
6639 | { |
6640 | print_one_breakpoint (b, &last_loc, show_internal); | |
6641 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
6642 | if (loc->disabled_by_cond) | |
6643 | has_disabled_by_cond_location = true; | |
6644 | } | |
4a2b031d TT |
6645 | } |
6646 | } | |
698384cd | 6647 | |
7f3b0473 | 6648 | if (nr_printable_breakpoints == 0) |
c906108c | 6649 | { |
4a64f543 MS |
6650 | /* If there's a filter, let the caller decide how to report |
6651 | empty list. */ | |
d77f58be SS |
6652 | if (!filter) |
6653 | { | |
5c458ae8 | 6654 | if (bp_num_list == NULL || *bp_num_list == '\0') |
112e8700 | 6655 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6656 | else |
112e8700 | 6657 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
5c458ae8 | 6658 | bp_num_list); |
d77f58be | 6659 | } |
c906108c SS |
6660 | } |
6661 | else | |
c4093a6a | 6662 | { |
a6d9a66e UW |
6663 | if (last_loc && !server_command) |
6664 | set_next_address (last_loc->gdbarch, last_loc->address); | |
b5fa468f TBA |
6665 | |
6666 | if (has_disabled_by_cond_location) | |
6667 | uiout->message (_("(*): Breakpoint condition is invalid at this " | |
6668 | "location.\n")); | |
c4093a6a | 6669 | } |
c906108c | 6670 | |
4a64f543 | 6671 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6672 | there have been breakpoints? */ |
c906108c | 6673 | annotate_breakpoints_table_end (); |
d77f58be SS |
6674 | |
6675 | return nr_printable_breakpoints; | |
c906108c SS |
6676 | } |
6677 | ||
ad443146 SS |
6678 | /* Display the value of default-collect in a way that is generally |
6679 | compatible with the breakpoint list. */ | |
6680 | ||
6681 | static void | |
6682 | default_collect_info (void) | |
6683 | { | |
79a45e25 PA |
6684 | struct ui_out *uiout = current_uiout; |
6685 | ||
ad443146 SS |
6686 | /* If it has no value (which is frequently the case), say nothing; a |
6687 | message like "No default-collect." gets in user's face when it's | |
6688 | not wanted. */ | |
6689 | if (!*default_collect) | |
6690 | return; | |
6691 | ||
6692 | /* The following phrase lines up nicely with per-tracepoint collect | |
6693 | actions. */ | |
112e8700 SM |
6694 | uiout->text ("default collect "); |
6695 | uiout->field_string ("default-collect", default_collect); | |
6696 | uiout->text (" \n"); | |
ad443146 SS |
6697 | } |
6698 | ||
c906108c | 6699 | static void |
0b39b52e | 6700 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6701 | { |
5c458ae8 | 6702 | breakpoint_1 (args, false, NULL); |
ad443146 SS |
6703 | |
6704 | default_collect_info (); | |
d77f58be SS |
6705 | } |
6706 | ||
6707 | static void | |
1d12d88f | 6708 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6709 | { |
5c458ae8 | 6710 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
79a45e25 | 6711 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6712 | |
6713 | if (num_printed == 0) | |
6714 | { | |
e5a67952 | 6715 | if (args == NULL || *args == '\0') |
112e8700 | 6716 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6717 | else |
112e8700 | 6718 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6719 | } |
c906108c SS |
6720 | } |
6721 | ||
7a292a7a | 6722 | static void |
4495129a | 6723 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6724 | { |
5c458ae8 | 6725 | breakpoint_1 (args, true, NULL); |
ad443146 SS |
6726 | |
6727 | default_collect_info (); | |
c906108c SS |
6728 | } |
6729 | ||
0d381245 | 6730 | static int |
714835d5 | 6731 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6732 | struct program_space *pspace, |
714835d5 | 6733 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6734 | { |
6735 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6736 | |
0d381245 VP |
6737 | for (; bl; bl = bl->next) |
6738 | { | |
6c95b8df PA |
6739 | if (bl->pspace == pspace |
6740 | && bl->address == pc | |
0d381245 VP |
6741 | && (!overlay_debugging || bl->section == section)) |
6742 | return 1; | |
6743 | } | |
6744 | return 0; | |
6745 | } | |
6746 | ||
672f9b60 | 6747 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6748 | concerns with logical breakpoints, so we match program spaces, not |
6749 | address spaces. */ | |
c906108c SS |
6750 | |
6751 | static void | |
6c95b8df PA |
6752 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6753 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6754 | struct obj_section *section, int thread) |
c906108c | 6755 | { |
52f0bd74 AC |
6756 | int others = 0; |
6757 | struct breakpoint *b; | |
c906108c SS |
6758 | |
6759 | ALL_BREAKPOINTS (b) | |
672f9b60 | 6760 | others += (user_breakpoint_p (b) |
dda83cd7 | 6761 | && breakpoint_has_pc (b, pspace, pc, section)); |
c906108c SS |
6762 | if (others > 0) |
6763 | { | |
a3f17187 AC |
6764 | if (others == 1) |
6765 | printf_filtered (_("Note: breakpoint ")); | |
6766 | else /* if (others == ???) */ | |
6767 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6768 | ALL_BREAKPOINTS (b) |
672f9b60 | 6769 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6770 | { |
6771 | others--; | |
6772 | printf_filtered ("%d", b->number); | |
6773 | if (b->thread == -1 && thread != -1) | |
6774 | printf_filtered (" (all threads)"); | |
6775 | else if (b->thread != -1) | |
6776 | printf_filtered (" (thread %d)", b->thread); | |
6777 | printf_filtered ("%s%s ", | |
059fb39f | 6778 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6779 | || b->enable_state == bp_call_disabled) |
0d381245 | 6780 | ? " (disabled)" |
0d381245 VP |
6781 | : ""), |
6782 | (others > 1) ? "," | |
6783 | : ((others == 1) ? " and" : "")); | |
6784 | } | |
6a831f06 PA |
6785 | current_uiout->message (_("also set at pc %ps.\n"), |
6786 | styled_string (address_style.style (), | |
6787 | paddress (gdbarch, pc))); | |
c906108c SS |
6788 | } |
6789 | } | |
6790 | \f | |
c906108c | 6791 | |
cb1e4e32 PA |
6792 | /* Return true iff it is meaningful to use the address member of LOC. |
6793 | For some breakpoint types, the locations' address members are | |
6794 | irrelevant and it makes no sense to attempt to compare them to | |
6795 | other addresses (or use them for any other purpose either). | |
2d134ed3 | 6796 | |
cb1e4e32 PA |
6797 | More specifically, software watchpoints and catchpoints that are |
6798 | not backed by breakpoints always have a zero valued location | |
6799 | address and we don't want to mark breakpoints of any of these types | |
6800 | to be a duplicate of an actual breakpoint location at address | |
6801 | zero. */ | |
e4f237da | 6802 | |
cb1e4e32 PA |
6803 | static bool |
6804 | bl_address_is_meaningful (bp_location *loc) | |
e4f237da | 6805 | { |
cb1e4e32 | 6806 | return loc->loc_type != bp_loc_other; |
2d134ed3 PA |
6807 | } |
6808 | ||
6809 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6810 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6811 | ||
6812 | static int | |
4a64f543 MS |
6813 | watchpoint_locations_match (struct bp_location *loc1, |
6814 | struct bp_location *loc2) | |
2d134ed3 | 6815 | { |
3a5c3e22 PA |
6816 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6817 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6818 | ||
6819 | /* Both of them must exist. */ | |
6820 | gdb_assert (w1 != NULL); | |
6821 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6822 | |
4a64f543 MS |
6823 | /* If the target can evaluate the condition expression in hardware, |
6824 | then we we need to insert both watchpoints even if they are at | |
6825 | the same place. Otherwise the watchpoint will only trigger when | |
6826 | the condition of whichever watchpoint was inserted evaluates to | |
6827 | true, not giving a chance for GDB to check the condition of the | |
6828 | other watchpoint. */ | |
3a5c3e22 | 6829 | if ((w1->cond_exp |
4a64f543 MS |
6830 | && target_can_accel_watchpoint_condition (loc1->address, |
6831 | loc1->length, | |
0cf6dd15 | 6832 | loc1->watchpoint_type, |
4d01a485 | 6833 | w1->cond_exp.get ())) |
3a5c3e22 | 6834 | || (w2->cond_exp |
4a64f543 MS |
6835 | && target_can_accel_watchpoint_condition (loc2->address, |
6836 | loc2->length, | |
0cf6dd15 | 6837 | loc2->watchpoint_type, |
4d01a485 | 6838 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6839 | return 0; |
6840 | ||
85d721b8 PA |
6841 | /* Note that this checks the owner's type, not the location's. In |
6842 | case the target does not support read watchpoints, but does | |
6843 | support access watchpoints, we'll have bp_read_watchpoint | |
6844 | watchpoints with hw_access locations. Those should be considered | |
6845 | duplicates of hw_read locations. The hw_read locations will | |
6846 | become hw_access locations later. */ | |
2d134ed3 PA |
6847 | return (loc1->owner->type == loc2->owner->type |
6848 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6849 | && loc1->address == loc2->address | |
6850 | && loc1->length == loc2->length); | |
e4f237da KB |
6851 | } |
6852 | ||
31e77af2 | 6853 | /* See breakpoint.h. */ |
6c95b8df | 6854 | |
31e77af2 | 6855 | int |
accd0bcd YQ |
6856 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6857 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6858 | { |
f5656ead | 6859 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6860 | || aspace1 == aspace2) |
6861 | && addr1 == addr2); | |
6862 | } | |
6863 | ||
f1310107 TJB |
6864 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6865 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6866 | matches ASPACE2. On targets that have global breakpoints, the address | |
6867 | space doesn't really matter. */ | |
6868 | ||
6869 | static int | |
accd0bcd YQ |
6870 | breakpoint_address_match_range (const address_space *aspace1, |
6871 | CORE_ADDR addr1, | |
6872 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6873 | CORE_ADDR addr2) |
6874 | { | |
f5656ead | 6875 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6876 | || aspace1 == aspace2) |
6877 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6878 | } | |
6879 | ||
6880 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6881 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6882 | matches the breakpoint's address space. On targets that have global | |
6883 | breakpoints, the address space doesn't really matter. */ | |
6884 | ||
6885 | static int | |
6886 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6887 | const address_space *aspace, |
f1310107 TJB |
6888 | CORE_ADDR addr) |
6889 | { | |
6890 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6891 | aspace, addr) | |
6892 | || (bl->length | |
6893 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6894 | bl->address, bl->length, | |
6895 | aspace, addr))); | |
6896 | } | |
6897 | ||
d35ae833 PA |
6898 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6899 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6900 | match happens only if ASPACE matches the breakpoint's address | |
6901 | space. On targets that have global breakpoints, the address space | |
6902 | doesn't really matter. */ | |
6903 | ||
6904 | static int | |
6905 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6906 | const address_space *aspace, |
d35ae833 PA |
6907 | CORE_ADDR addr, int len) |
6908 | { | |
6909 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6910 | || bl->pspace->aspace == aspace) | |
6911 | { | |
6912 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6913 | ||
6914 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
6915 | return 1; | |
6916 | } | |
6917 | return 0; | |
6918 | } | |
6919 | ||
1e4d1764 YQ |
6920 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6921 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6922 | true, otherwise returns false. */ | |
6923 | ||
6924 | static int | |
6925 | tracepoint_locations_match (struct bp_location *loc1, | |
6926 | struct bp_location *loc2) | |
6927 | { | |
6928 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6929 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6930 | locations at the same address of different tracepoints are regarded as | |
6931 | different locations. */ | |
6932 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6933 | else | |
6934 | return 0; | |
6935 | } | |
6936 | ||
2d134ed3 | 6937 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
cb1e4e32 | 6938 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
7f32a4d5 PA |
6939 | the same location. If SW_HW_BPS_MATCH is true, then software |
6940 | breakpoint locations and hardware breakpoint locations match, | |
6941 | otherwise they don't. */ | |
2d134ed3 PA |
6942 | |
6943 | static int | |
7f32a4d5 PA |
6944 | breakpoint_locations_match (struct bp_location *loc1, |
6945 | struct bp_location *loc2, | |
6946 | bool sw_hw_bps_match) | |
2d134ed3 | 6947 | { |
2bdf28a0 JK |
6948 | int hw_point1, hw_point2; |
6949 | ||
6950 | /* Both of them must not be in moribund_locations. */ | |
6951 | gdb_assert (loc1->owner != NULL); | |
6952 | gdb_assert (loc2->owner != NULL); | |
6953 | ||
6954 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6955 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6956 | |
6957 | if (hw_point1 != hw_point2) | |
6958 | return 0; | |
6959 | else if (hw_point1) | |
6960 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6961 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6962 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6963 | else |
7f32a4d5 PA |
6964 | /* We compare bp_location.length in order to cover ranged |
6965 | breakpoints. Keep this in sync with | |
6966 | bp_location_is_less_than. */ | |
f1310107 TJB |
6967 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
6968 | loc2->pspace->aspace, loc2->address) | |
7f32a4d5 | 6969 | && (loc1->loc_type == loc2->loc_type || sw_hw_bps_match) |
f1310107 | 6970 | && loc1->length == loc2->length); |
2d134ed3 PA |
6971 | } |
6972 | ||
76897487 KB |
6973 | static void |
6974 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
dda83cd7 | 6975 | int bnum, int have_bnum) |
76897487 | 6976 | { |
f63fbe86 MS |
6977 | /* The longest string possibly returned by hex_string_custom |
6978 | is 50 chars. These must be at least that big for safety. */ | |
6979 | char astr1[64]; | |
6980 | char astr2[64]; | |
76897487 | 6981 | |
bb599908 PH |
6982 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6983 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6984 | if (have_bnum) |
8a3fe4f8 | 6985 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
dda83cd7 | 6986 | bnum, astr1, astr2); |
76897487 | 6987 | else |
8a3fe4f8 | 6988 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6989 | } |
6990 | ||
4a64f543 MS |
6991 | /* Adjust a breakpoint's address to account for architectural |
6992 | constraints on breakpoint placement. Return the adjusted address. | |
6993 | Note: Very few targets require this kind of adjustment. For most | |
6994 | targets, this function is simply the identity function. */ | |
76897487 KB |
6995 | |
6996 | static CORE_ADDR | |
a6d9a66e UW |
6997 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6998 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6999 | { |
a0de8c21 YQ |
7000 | if (bptype == bp_watchpoint |
7001 | || bptype == bp_hardware_watchpoint | |
7002 | || bptype == bp_read_watchpoint | |
7003 | || bptype == bp_access_watchpoint | |
7004 | || bptype == bp_catchpoint) | |
88f7da05 KB |
7005 | { |
7006 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
dda83cd7 | 7007 | have their addresses modified. */ |
88f7da05 KB |
7008 | return bpaddr; |
7009 | } | |
7c16b83e PA |
7010 | else if (bptype == bp_single_step) |
7011 | { | |
7012 | /* Single-step breakpoints should not have their addresses | |
7013 | modified. If there's any architectural constrain that | |
7014 | applies to this address, then it should have already been | |
7015 | taken into account when the breakpoint was created in the | |
7016 | first place. If we didn't do this, stepping through e.g., | |
7017 | Thumb-2 IT blocks would break. */ | |
7018 | return bpaddr; | |
7019 | } | |
76897487 KB |
7020 | else |
7021 | { | |
a0de8c21 YQ |
7022 | CORE_ADDR adjusted_bpaddr = bpaddr; |
7023 | ||
7024 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) | |
7025 | { | |
7026 | /* Some targets have architectural constraints on the placement | |
7027 | of breakpoint instructions. Obtain the adjusted address. */ | |
7028 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); | |
7029 | } | |
76897487 | 7030 | |
a0de8c21 | 7031 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
76897487 KB |
7032 | |
7033 | /* An adjusted breakpoint address can significantly alter | |
dda83cd7 | 7034 | a user's expectations. Print a warning if an adjustment |
76897487 KB |
7035 | is required. */ |
7036 | if (adjusted_bpaddr != bpaddr) | |
7037 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7038 | ||
7039 | return adjusted_bpaddr; | |
7040 | } | |
7041 | } | |
7042 | ||
cb1e4e32 PA |
7043 | static bp_loc_type |
7044 | bp_location_from_bp_type (bptype type) | |
7cc221ef | 7045 | { |
cb1e4e32 | 7046 | switch (type) |
e049a4b5 DJ |
7047 | { |
7048 | case bp_breakpoint: | |
7c16b83e | 7049 | case bp_single_step: |
e049a4b5 DJ |
7050 | case bp_until: |
7051 | case bp_finish: | |
7052 | case bp_longjmp: | |
7053 | case bp_longjmp_resume: | |
e2e4d78b | 7054 | case bp_longjmp_call_dummy: |
186c406b TT |
7055 | case bp_exception: |
7056 | case bp_exception_resume: | |
e049a4b5 | 7057 | case bp_step_resume: |
2c03e5be | 7058 | case bp_hp_step_resume: |
e049a4b5 DJ |
7059 | case bp_watchpoint_scope: |
7060 | case bp_call_dummy: | |
aa7d318d | 7061 | case bp_std_terminate: |
e049a4b5 DJ |
7062 | case bp_shlib_event: |
7063 | case bp_thread_event: | |
7064 | case bp_overlay_event: | |
4efc6507 | 7065 | case bp_jit_event: |
0fd8e87f | 7066 | case bp_longjmp_master: |
aa7d318d | 7067 | case bp_std_terminate_master: |
186c406b | 7068 | case bp_exception_master: |
0e30163f JK |
7069 | case bp_gnu_ifunc_resolver: |
7070 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7071 | case bp_dprintf: |
cb1e4e32 | 7072 | return bp_loc_software_breakpoint; |
e049a4b5 | 7073 | case bp_hardware_breakpoint: |
cb1e4e32 | 7074 | return bp_loc_hardware_breakpoint; |
e049a4b5 DJ |
7075 | case bp_hardware_watchpoint: |
7076 | case bp_read_watchpoint: | |
7077 | case bp_access_watchpoint: | |
cb1e4e32 | 7078 | return bp_loc_hardware_watchpoint; |
e049a4b5 | 7079 | case bp_watchpoint: |
ce78b96d | 7080 | case bp_catchpoint: |
15c3d785 PA |
7081 | case bp_tracepoint: |
7082 | case bp_fast_tracepoint: | |
0fb4aa4b | 7083 | case bp_static_tracepoint: |
cb1e4e32 | 7084 | return bp_loc_other; |
e049a4b5 | 7085 | default: |
e2e0b3e5 | 7086 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 | 7087 | } |
cb1e4e32 PA |
7088 | } |
7089 | ||
7090 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) | |
7091 | { | |
7092 | this->owner = owner; | |
7093 | this->cond_bytecode = NULL; | |
7094 | this->shlib_disabled = 0; | |
7095 | this->enabled = 1; | |
b5fa468f | 7096 | this->disabled_by_cond = false; |
cb1e4e32 PA |
7097 | |
7098 | this->loc_type = type; | |
e049a4b5 | 7099 | |
cb1e4e32 PA |
7100 | if (this->loc_type == bp_loc_software_breakpoint |
7101 | || this->loc_type == bp_loc_hardware_breakpoint) | |
7102 | mark_breakpoint_location_modified (this); | |
7103 | ||
7104 | this->refc = 1; | |
7105 | } | |
7106 | ||
7107 | bp_location::bp_location (breakpoint *owner) | |
7108 | : bp_location::bp_location (owner, | |
7109 | bp_location_from_bp_type (owner->type)) | |
7110 | { | |
28010a5d PA |
7111 | } |
7112 | ||
7113 | /* Allocate a struct bp_location. */ | |
7114 | ||
7115 | static struct bp_location * | |
7116 | allocate_bp_location (struct breakpoint *bpt) | |
7117 | { | |
348d480f PA |
7118 | return bpt->ops->allocate_location (bpt); |
7119 | } | |
7cc221ef | 7120 | |
f431efe5 PA |
7121 | static void |
7122 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7123 | { |
4d01a485 | 7124 | delete loc; |
fe3f5fa8 VP |
7125 | } |
7126 | ||
f431efe5 PA |
7127 | /* Increment reference count. */ |
7128 | ||
7129 | static void | |
7130 | incref_bp_location (struct bp_location *bl) | |
7131 | { | |
7132 | ++bl->refc; | |
7133 | } | |
7134 | ||
7135 | /* Decrement reference count. If the reference count reaches 0, | |
7136 | destroy the bp_location. Sets *BLP to NULL. */ | |
7137 | ||
7138 | static void | |
7139 | decref_bp_location (struct bp_location **blp) | |
7140 | { | |
0807b50c PA |
7141 | gdb_assert ((*blp)->refc > 0); |
7142 | ||
f431efe5 PA |
7143 | if (--(*blp)->refc == 0) |
7144 | free_bp_location (*blp); | |
7145 | *blp = NULL; | |
7146 | } | |
7147 | ||
346774a9 | 7148 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7149 | |
b270e6f9 TT |
7150 | static breakpoint * |
7151 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7152 | { |
346774a9 | 7153 | struct breakpoint *b1; |
b270e6f9 | 7154 | struct breakpoint *result = b.get (); |
c906108c | 7155 | |
346774a9 PA |
7156 | /* Add this breakpoint to the end of the chain so that a list of |
7157 | breakpoints will come out in order of increasing numbers. */ | |
7158 | ||
7159 | b1 = breakpoint_chain; | |
7160 | if (b1 == 0) | |
b270e6f9 | 7161 | breakpoint_chain = b.release (); |
346774a9 PA |
7162 | else |
7163 | { | |
7164 | while (b1->next) | |
7165 | b1 = b1->next; | |
b270e6f9 | 7166 | b1->next = b.release (); |
346774a9 | 7167 | } |
b270e6f9 TT |
7168 | |
7169 | return result; | |
346774a9 PA |
7170 | } |
7171 | ||
7172 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7173 | ||
7174 | static void | |
7175 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7176 | struct gdbarch *gdbarch, | |
28010a5d | 7177 | enum bptype bptype, |
c0a91b2b | 7178 | const struct breakpoint_ops *ops) |
346774a9 | 7179 | { |
348d480f PA |
7180 | gdb_assert (ops != NULL); |
7181 | ||
28010a5d | 7182 | b->ops = ops; |
4d28f7a8 | 7183 | b->type = bptype; |
a6d9a66e | 7184 | b->gdbarch = gdbarch; |
c906108c SS |
7185 | b->language = current_language->la_language; |
7186 | b->input_radix = input_radix; | |
d0fb5eae | 7187 | b->related_breakpoint = b; |
346774a9 PA |
7188 | } |
7189 | ||
7190 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7191 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7192 | |
7193 | static struct breakpoint * | |
7194 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7195 | enum bptype bptype, |
c0a91b2b | 7196 | const struct breakpoint_ops *ops) |
346774a9 | 7197 | { |
3b0871f4 | 7198 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7199 | |
3b0871f4 | 7200 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7201 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7202 | } |
7203 | ||
0ba852ab | 7204 | /* Initialize loc->function_name. */ |
0e30163f | 7205 | |
0d381245 | 7206 | static void |
0ba852ab | 7207 | set_breakpoint_location_function (struct bp_location *loc) |
0d381245 | 7208 | { |
2bdf28a0 JK |
7209 | gdb_assert (loc->owner != NULL); |
7210 | ||
0d381245 | 7211 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7212 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7213 | || is_tracepoint (loc->owner)) |
0d381245 | 7214 | { |
2c02bd72 | 7215 | const char *function_name; |
0e30163f | 7216 | |
3467ec66 | 7217 | if (loc->msymbol != NULL |
f50776aa | 7218 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
0ba852ab | 7219 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)) |
0e30163f JK |
7220 | { |
7221 | struct breakpoint *b = loc->owner; | |
7222 | ||
c9d95fa3 | 7223 | function_name = loc->msymbol->linkage_name (); |
3467ec66 PA |
7224 | |
7225 | if (b->type == bp_breakpoint && b->loc == loc | |
7226 | && loc->next == NULL && b->related_breakpoint == b) | |
0e30163f JK |
7227 | { |
7228 | /* Create only the whole new breakpoint of this type but do not | |
7229 | mess more complicated breakpoints with multiple locations. */ | |
7230 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b | 7231 | /* Remember the resolver's address for use by the return |
dda83cd7 | 7232 | breakpoint. */ |
3467ec66 | 7233 | loc->related_address = loc->address; |
0e30163f JK |
7234 | } |
7235 | } | |
3467ec66 PA |
7236 | else |
7237 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); | |
0e30163f | 7238 | |
2c02bd72 DE |
7239 | if (function_name) |
7240 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7241 | } |
7242 | } | |
7243 | ||
a6d9a66e | 7244 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7245 | struct gdbarch * |
a6d9a66e UW |
7246 | get_sal_arch (struct symtab_and_line sal) |
7247 | { | |
7248 | if (sal.section) | |
08feed99 | 7249 | return sal.section->objfile->arch (); |
a6d9a66e | 7250 | if (sal.symtab) |
08feed99 | 7251 | return SYMTAB_OBJFILE (sal.symtab)->arch (); |
a6d9a66e UW |
7252 | |
7253 | return NULL; | |
7254 | } | |
7255 | ||
346774a9 PA |
7256 | /* Low level routine for partially initializing a breakpoint of type |
7257 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7258 | file name, and line number are provided by SAL. |
0d381245 VP |
7259 | |
7260 | It is expected that the caller will complete the initialization of | |
7261 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7262 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7263 | |
346774a9 PA |
7264 | static void |
7265 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7266 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7267 | const struct breakpoint_ops *ops) |
0d381245 | 7268 | { |
28010a5d | 7269 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7270 | |
3742cc8b | 7271 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7272 | |
6c95b8df PA |
7273 | if (bptype != bp_catchpoint) |
7274 | gdb_assert (sal.pspace != NULL); | |
7275 | ||
f8eba3c6 TT |
7276 | /* Store the program space that was used to set the breakpoint, |
7277 | except for ordinary breakpoints, which are independent of the | |
7278 | program space. */ | |
7279 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7280 | b->pspace = sal.pspace; | |
346774a9 | 7281 | } |
c906108c | 7282 | |
346774a9 PA |
7283 | /* set_raw_breakpoint is a low level routine for allocating and |
7284 | partially initializing a breakpoint of type BPTYPE. The newly | |
7285 | created breakpoint's address, section, source file name, and line | |
7286 | number are provided by SAL. The newly created and partially | |
7287 | initialized breakpoint is added to the breakpoint chain and | |
7288 | is also returned as the value of this function. | |
7289 | ||
7290 | It is expected that the caller will complete the initialization of | |
7291 | the newly created breakpoint struct as well as output any status | |
7292 | information regarding the creation of a new breakpoint. In | |
7293 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7294 | number! Care should be taken to not allow an error to occur | |
7295 | prior to completing the initialization of the breakpoint. If this | |
7296 | should happen, a bogus breakpoint will be left on the chain. */ | |
7297 | ||
7298 | struct breakpoint * | |
7299 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7300 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7301 | const struct breakpoint_ops *ops) |
346774a9 | 7302 | { |
3b0871f4 | 7303 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7304 | |
3b0871f4 | 7305 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7306 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7307 | } |
7308 | ||
53a5351d | 7309 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7310 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7311 | initiated the operation. */ | |
c906108c SS |
7312 | |
7313 | void | |
186c406b | 7314 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7315 | { |
35df4500 | 7316 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7317 | int thread = tp->global_num; |
0fd8e87f UW |
7318 | |
7319 | /* To avoid having to rescan all objfile symbols at every step, | |
7320 | we maintain a list of continually-inserted but always disabled | |
7321 | longjmp "master" breakpoints. Here, we simply create momentary | |
7322 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7323 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7324 | if (b->pspace == current_program_space |
186c406b TT |
7325 | && (b->type == bp_longjmp_master |
7326 | || b->type == bp_exception_master)) | |
0fd8e87f | 7327 | { |
06edf0c0 PA |
7328 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7329 | struct breakpoint *clone; | |
cc59ec59 | 7330 | |
e2e4d78b JK |
7331 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7332 | after their removal. */ | |
06edf0c0 | 7333 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7334 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7335 | clone->thread = thread; |
7336 | } | |
186c406b TT |
7337 | |
7338 | tp->initiating_frame = frame; | |
c906108c SS |
7339 | } |
7340 | ||
611c83ae | 7341 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7342 | void |
611c83ae | 7343 | delete_longjmp_breakpoint (int thread) |
c906108c | 7344 | { |
35df4500 | 7345 | struct breakpoint *b, *b_tmp; |
c906108c | 7346 | |
35df4500 | 7347 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7348 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7349 | { |
7350 | if (b->thread == thread) | |
7351 | delete_breakpoint (b); | |
7352 | } | |
c906108c SS |
7353 | } |
7354 | ||
f59f708a PA |
7355 | void |
7356 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7357 | { | |
7358 | struct breakpoint *b, *b_tmp; | |
7359 | ||
7360 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7361 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7362 | { | |
7363 | if (b->thread == thread) | |
7364 | b->disposition = disp_del_at_next_stop; | |
7365 | } | |
7366 | } | |
7367 | ||
e2e4d78b JK |
7368 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7369 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7370 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7371 | breakpoints. */ | |
7372 | ||
7373 | struct breakpoint * | |
7374 | set_longjmp_breakpoint_for_call_dummy (void) | |
7375 | { | |
7376 | struct breakpoint *b, *retval = NULL; | |
7377 | ||
7378 | ALL_BREAKPOINTS (b) | |
7379 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7380 | { | |
7381 | struct breakpoint *new_b; | |
7382 | ||
7383 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7384 | &momentary_breakpoint_ops, |
7385 | 1); | |
00431a78 | 7386 | new_b->thread = inferior_thread ()->global_num; |
e2e4d78b JK |
7387 | |
7388 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7389 | ||
7390 | gdb_assert (new_b->related_breakpoint == new_b); | |
7391 | if (retval == NULL) | |
7392 | retval = new_b; | |
7393 | new_b->related_breakpoint = retval; | |
7394 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7395 | retval = retval->related_breakpoint; | |
7396 | retval->related_breakpoint = new_b; | |
7397 | } | |
7398 | ||
7399 | return retval; | |
7400 | } | |
7401 | ||
7402 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7403 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7404 | stack. |
7405 | ||
7406 | You should call this function only at places where it is safe to currently | |
7407 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7408 | frames. */ | |
7409 | ||
7410 | void | |
b67a2c6f | 7411 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7412 | { |
7413 | struct breakpoint *b, *b_tmp; | |
7414 | ||
7415 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7416 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7417 | { |
7418 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7419 | ||
7420 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7421 | dummy_b = dummy_b->related_breakpoint; | |
7422 | if (dummy_b->type != bp_call_dummy | |
7423 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7424 | continue; | |
7425 | ||
00431a78 | 7426 | dummy_frame_discard (dummy_b->frame_id, tp); |
e2e4d78b JK |
7427 | |
7428 | while (b->related_breakpoint != b) | |
7429 | { | |
7430 | if (b_tmp == b->related_breakpoint) | |
7431 | b_tmp = b->related_breakpoint->next; | |
7432 | delete_breakpoint (b->related_breakpoint); | |
7433 | } | |
7434 | delete_breakpoint (b); | |
7435 | } | |
7436 | } | |
7437 | ||
1900040c MS |
7438 | void |
7439 | enable_overlay_breakpoints (void) | |
7440 | { | |
52f0bd74 | 7441 | struct breakpoint *b; |
1900040c MS |
7442 | |
7443 | ALL_BREAKPOINTS (b) | |
7444 | if (b->type == bp_overlay_event) | |
7445 | { | |
7446 | b->enable_state = bp_enabled; | |
44702360 | 7447 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7448 | overlay_events_enabled = 1; |
1900040c MS |
7449 | } |
7450 | } | |
7451 | ||
7452 | void | |
7453 | disable_overlay_breakpoints (void) | |
7454 | { | |
52f0bd74 | 7455 | struct breakpoint *b; |
1900040c MS |
7456 | |
7457 | ALL_BREAKPOINTS (b) | |
7458 | if (b->type == bp_overlay_event) | |
7459 | { | |
7460 | b->enable_state = bp_disabled; | |
44702360 | 7461 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7462 | overlay_events_enabled = 0; |
1900040c MS |
7463 | } |
7464 | } | |
7465 | ||
aa7d318d TT |
7466 | /* Set an active std::terminate breakpoint for each std::terminate |
7467 | master breakpoint. */ | |
7468 | void | |
7469 | set_std_terminate_breakpoint (void) | |
7470 | { | |
35df4500 | 7471 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7472 | |
35df4500 | 7473 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7474 | if (b->pspace == current_program_space |
7475 | && b->type == bp_std_terminate_master) | |
7476 | { | |
06edf0c0 | 7477 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7478 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7479 | } |
7480 | } | |
7481 | ||
7482 | /* Delete all the std::terminate breakpoints. */ | |
7483 | void | |
7484 | delete_std_terminate_breakpoint (void) | |
7485 | { | |
35df4500 | 7486 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7487 | |
35df4500 | 7488 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7489 | if (b->type == bp_std_terminate) |
7490 | delete_breakpoint (b); | |
7491 | } | |
7492 | ||
c4093a6a | 7493 | struct breakpoint * |
a6d9a66e | 7494 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7495 | { |
7496 | struct breakpoint *b; | |
c4093a6a | 7497 | |
06edf0c0 PA |
7498 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7499 | &internal_breakpoint_ops); | |
7500 | ||
b5de0fa7 | 7501 | b->enable_state = bp_enabled; |
f00aae0f | 7502 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7503 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7504 | |
44702360 | 7505 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7506 | |
c4093a6a JM |
7507 | return b; |
7508 | } | |
7509 | ||
0101ce28 JJ |
7510 | struct lang_and_radix |
7511 | { | |
7512 | enum language lang; | |
7513 | int radix; | |
7514 | }; | |
7515 | ||
4efc6507 DE |
7516 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7517 | ||
7518 | struct breakpoint * | |
7519 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7520 | { | |
2a7f3dff PA |
7521 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7522 | &internal_breakpoint_ops); | |
4efc6507 | 7523 | } |
0101ce28 | 7524 | |
03673fc7 PP |
7525 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7526 | ||
7527 | void | |
7528 | remove_jit_event_breakpoints (void) | |
7529 | { | |
7530 | struct breakpoint *b, *b_tmp; | |
7531 | ||
7532 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7533 | if (b->type == bp_jit_event | |
7534 | && b->loc->pspace == current_program_space) | |
7535 | delete_breakpoint (b); | |
7536 | } | |
7537 | ||
cae688ec JJ |
7538 | void |
7539 | remove_solib_event_breakpoints (void) | |
7540 | { | |
35df4500 | 7541 | struct breakpoint *b, *b_tmp; |
cae688ec | 7542 | |
35df4500 | 7543 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7544 | if (b->type == bp_shlib_event |
7545 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7546 | delete_breakpoint (b); |
7547 | } | |
7548 | ||
f37f681c PA |
7549 | /* See breakpoint.h. */ |
7550 | ||
7551 | void | |
7552 | remove_solib_event_breakpoints_at_next_stop (void) | |
7553 | { | |
7554 | struct breakpoint *b, *b_tmp; | |
7555 | ||
7556 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7557 | if (b->type == bp_shlib_event | |
7558 | && b->loc->pspace == current_program_space) | |
7559 | b->disposition = disp_del_at_next_stop; | |
7560 | } | |
7561 | ||
04086b45 PA |
7562 | /* Helper for create_solib_event_breakpoint / |
7563 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7564 | INSERT_MODE to pass through to update_global_location_list. */ | |
7565 | ||
7566 | static struct breakpoint * | |
7567 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7568 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7569 | { |
7570 | struct breakpoint *b; | |
7571 | ||
06edf0c0 PA |
7572 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7573 | &internal_breakpoint_ops); | |
04086b45 | 7574 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7575 | return b; |
7576 | } | |
7577 | ||
04086b45 PA |
7578 | struct breakpoint * |
7579 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7580 | { | |
7581 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7582 | } | |
7583 | ||
f37f681c PA |
7584 | /* See breakpoint.h. */ |
7585 | ||
7586 | struct breakpoint * | |
7587 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7588 | { | |
7589 | struct breakpoint *b; | |
7590 | ||
04086b45 PA |
7591 | /* Explicitly tell update_global_location_list to insert |
7592 | locations. */ | |
7593 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7594 | if (!b->loc->inserted) |
7595 | { | |
7596 | delete_breakpoint (b); | |
7597 | return NULL; | |
7598 | } | |
7599 | return b; | |
7600 | } | |
7601 | ||
cae688ec JJ |
7602 | /* Disable any breakpoints that are on code in shared libraries. Only |
7603 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7604 | ||
7605 | void | |
cb851954 | 7606 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7607 | { |
876fa593 | 7608 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7609 | |
876fa593 | 7610 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7611 | { |
2bdf28a0 | 7612 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7613 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7614 | |
4a64f543 MS |
7615 | /* We apply the check to all breakpoints, including disabled for |
7616 | those with loc->duplicate set. This is so that when breakpoint | |
7617 | becomes enabled, or the duplicate is removed, gdb will try to | |
7618 | insert all breakpoints. If we don't set shlib_disabled here, | |
7619 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7620 | if (((b->type == bp_breakpoint) |
508ccb1f | 7621 | || (b->type == bp_jit_event) |
1042e4c0 | 7622 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7623 | || (is_tracepoint (b))) |
6c95b8df | 7624 | && loc->pspace == current_program_space |
0d381245 | 7625 | && !loc->shlib_disabled |
6c95b8df | 7626 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7627 | ) |
0d381245 VP |
7628 | { |
7629 | loc->shlib_disabled = 1; | |
7630 | } | |
cae688ec JJ |
7631 | } |
7632 | } | |
7633 | ||
63644780 NB |
7634 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7635 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7636 | disabled ones can just stay disabled. */ | |
84acb35a | 7637 | |
75149521 | 7638 | static void |
84acb35a JJ |
7639 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7640 | { | |
876fa593 | 7641 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7642 | int disabled_shlib_breaks = 0; |
7643 | ||
876fa593 | 7644 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7645 | { |
2bdf28a0 | 7646 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7647 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7648 | |
1e4d1764 | 7649 | if (solib->pspace == loc->pspace |
e2dd7057 | 7650 | && !loc->shlib_disabled |
1e4d1764 YQ |
7651 | && (((b->type == bp_breakpoint |
7652 | || b->type == bp_jit_event | |
7653 | || b->type == bp_hardware_breakpoint) | |
7654 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7655 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7656 | || is_tracepoint (b)) | |
e2dd7057 | 7657 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7658 | { |
e2dd7057 PP |
7659 | loc->shlib_disabled = 1; |
7660 | /* At this point, we cannot rely on remove_breakpoint | |
7661 | succeeding so we must mark the breakpoint as not inserted | |
7662 | to prevent future errors occurring in remove_breakpoints. */ | |
7663 | loc->inserted = 0; | |
8d3788bd VP |
7664 | |
7665 | /* This may cause duplicate notifications for the same breakpoint. */ | |
76727919 | 7666 | gdb::observers::breakpoint_modified.notify (b); |
8d3788bd | 7667 | |
e2dd7057 PP |
7668 | if (!disabled_shlib_breaks) |
7669 | { | |
223ffa71 | 7670 | target_terminal::ours_for_output (); |
3e43a32a MS |
7671 | warning (_("Temporarily disabling breakpoints " |
7672 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7673 | solib->so_name); |
84acb35a | 7674 | } |
e2dd7057 | 7675 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7676 | } |
7677 | } | |
84acb35a JJ |
7678 | } |
7679 | ||
63644780 NB |
7680 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7681 | notification of free_objfile. Only apply to enabled breakpoints, | |
7682 | disabled ones can just stay disabled. */ | |
7683 | ||
7684 | static void | |
7685 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7686 | { | |
7687 | struct breakpoint *b; | |
7688 | ||
7689 | if (objfile == NULL) | |
7690 | return; | |
7691 | ||
d03de421 PA |
7692 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7693 | managed by the user with add-symbol-file/remove-symbol-file. | |
7694 | Similarly to how breakpoints in shared libraries are handled in | |
7695 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7696 | shlib_disabled so they end up uninserted on the next global |
7697 | location list update. Shared libraries not loaded by the user | |
7698 | aren't handled here -- they're already handled in | |
7699 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7700 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7701 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7702 | main objfile). */ | |
7703 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7704 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7705 | return; |
7706 | ||
7707 | ALL_BREAKPOINTS (b) | |
7708 | { | |
7709 | struct bp_location *loc; | |
7710 | int bp_modified = 0; | |
7711 | ||
7712 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7713 | continue; | |
7714 | ||
7715 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7716 | { | |
7717 | CORE_ADDR loc_addr = loc->address; | |
7718 | ||
7719 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7720 | && loc->loc_type != bp_loc_software_breakpoint) | |
7721 | continue; | |
7722 | ||
7723 | if (loc->shlib_disabled != 0) | |
7724 | continue; | |
7725 | ||
7726 | if (objfile->pspace != loc->pspace) | |
7727 | continue; | |
7728 | ||
7729 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7730 | && loc->loc_type != bp_loc_software_breakpoint) | |
7731 | continue; | |
7732 | ||
7733 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7734 | { | |
7735 | loc->shlib_disabled = 1; | |
08351840 PA |
7736 | /* At this point, we don't know whether the object was |
7737 | unmapped from the inferior or not, so leave the | |
7738 | inserted flag alone. We'll handle failure to | |
7739 | uninsert quietly, in case the object was indeed | |
7740 | unmapped. */ | |
63644780 NB |
7741 | |
7742 | mark_breakpoint_location_modified (loc); | |
7743 | ||
7744 | bp_modified = 1; | |
7745 | } | |
7746 | } | |
7747 | ||
7748 | if (bp_modified) | |
76727919 | 7749 | gdb::observers::breakpoint_modified.notify (b); |
63644780 NB |
7750 | } |
7751 | } | |
7752 | ||
ce78b96d JB |
7753 | /* FORK & VFORK catchpoints. */ |
7754 | ||
e29a4733 | 7755 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7756 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7757 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7758 | |
c1fc2657 | 7759 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7760 | { |
e29a4733 PA |
7761 | /* Process id of a child process whose forking triggered this |
7762 | catchpoint. This field is only valid immediately after this | |
7763 | catchpoint has triggered. */ | |
7764 | ptid_t forked_inferior_pid; | |
7765 | }; | |
7766 | ||
4a64f543 MS |
7767 | /* Implement the "insert" breakpoint_ops method for fork |
7768 | catchpoints. */ | |
ce78b96d | 7769 | |
77b06cd7 TJB |
7770 | static int |
7771 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7772 | { |
e99b03dc | 7773 | return target_insert_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7774 | } |
7775 | ||
4a64f543 MS |
7776 | /* Implement the "remove" breakpoint_ops method for fork |
7777 | catchpoints. */ | |
ce78b96d JB |
7778 | |
7779 | static int | |
73971819 | 7780 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7781 | { |
e99b03dc | 7782 | return target_remove_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7783 | } |
7784 | ||
7785 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7786 | catchpoints. */ | |
7787 | ||
7788 | static int | |
f1310107 | 7789 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
bd522513 | 7790 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7791 | const struct target_waitstatus *ws) |
ce78b96d | 7792 | { |
e29a4733 PA |
7793 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7794 | ||
f90263c1 TT |
7795 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7796 | return 0; | |
7797 | ||
7798 | c->forked_inferior_pid = ws->value.related_pid; | |
7799 | return 1; | |
ce78b96d JB |
7800 | } |
7801 | ||
4a64f543 MS |
7802 | /* Implement the "print_it" breakpoint_ops method for fork |
7803 | catchpoints. */ | |
ce78b96d JB |
7804 | |
7805 | static enum print_stop_action | |
348d480f | 7806 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7807 | { |
36dfb11c | 7808 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7809 | struct breakpoint *b = bs->breakpoint_at; |
7810 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7811 | |
ce78b96d | 7812 | annotate_catchpoint (b->number); |
f303dbd6 | 7813 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7814 | if (b->disposition == disp_del) |
112e8700 | 7815 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7816 | else |
112e8700 SM |
7817 | uiout->text ("Catchpoint "); |
7818 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7819 | { |
112e8700 SM |
7820 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7821 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7822 | } |
381befee | 7823 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7824 | uiout->text (" (forked process "); |
381befee | 7825 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7826 | uiout->text ("), "); |
ce78b96d JB |
7827 | return PRINT_SRC_AND_LOC; |
7828 | } | |
7829 | ||
4a64f543 MS |
7830 | /* Implement the "print_one" breakpoint_ops method for fork |
7831 | catchpoints. */ | |
ce78b96d JB |
7832 | |
7833 | static void | |
a6d9a66e | 7834 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7835 | { |
e29a4733 | 7836 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7837 | struct value_print_options opts; |
79a45e25 | 7838 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7839 | |
7840 | get_user_print_options (&opts); | |
7841 | ||
4a64f543 MS |
7842 | /* Field 4, the address, is omitted (which makes the columns not |
7843 | line up too nicely with the headers, but the effect is relatively | |
7844 | readable). */ | |
79a45b7d | 7845 | if (opts.addressprint) |
112e8700 | 7846 | uiout->field_skip ("addr"); |
ce78b96d | 7847 | annotate_field (5); |
112e8700 | 7848 | uiout->text ("fork"); |
d7e15655 | 7849 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7850 | { |
112e8700 | 7851 | uiout->text (", process "); |
381befee | 7852 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7853 | uiout->spaces (1); |
ce78b96d | 7854 | } |
8ac3646f | 7855 | |
112e8700 SM |
7856 | if (uiout->is_mi_like_p ()) |
7857 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
7858 | } |
7859 | ||
7860 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7861 | catchpoints. */ | |
7862 | ||
7863 | static void | |
7864 | print_mention_catch_fork (struct breakpoint *b) | |
7865 | { | |
7866 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7867 | } | |
7868 | ||
6149aea9 PA |
7869 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7870 | catchpoints. */ | |
7871 | ||
7872 | static void | |
7873 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7874 | { | |
7875 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7876 | print_recreate_thread (b, fp); |
6149aea9 PA |
7877 | } |
7878 | ||
ce78b96d JB |
7879 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7880 | ||
2060206e | 7881 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7882 | |
4a64f543 MS |
7883 | /* Implement the "insert" breakpoint_ops method for vfork |
7884 | catchpoints. */ | |
ce78b96d | 7885 | |
77b06cd7 TJB |
7886 | static int |
7887 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7888 | { |
e99b03dc | 7889 | return target_insert_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7890 | } |
7891 | ||
4a64f543 MS |
7892 | /* Implement the "remove" breakpoint_ops method for vfork |
7893 | catchpoints. */ | |
ce78b96d JB |
7894 | |
7895 | static int | |
73971819 | 7896 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7897 | { |
e99b03dc | 7898 | return target_remove_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7899 | } |
7900 | ||
7901 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7902 | catchpoints. */ | |
7903 | ||
7904 | static int | |
f1310107 | 7905 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
bd522513 | 7906 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7907 | const struct target_waitstatus *ws) |
ce78b96d | 7908 | { |
e29a4733 PA |
7909 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7910 | ||
f90263c1 TT |
7911 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7912 | return 0; | |
7913 | ||
7914 | c->forked_inferior_pid = ws->value.related_pid; | |
7915 | return 1; | |
ce78b96d JB |
7916 | } |
7917 | ||
4a64f543 MS |
7918 | /* Implement the "print_it" breakpoint_ops method for vfork |
7919 | catchpoints. */ | |
ce78b96d JB |
7920 | |
7921 | static enum print_stop_action | |
348d480f | 7922 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7923 | { |
36dfb11c | 7924 | struct ui_out *uiout = current_uiout; |
348d480f | 7925 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7926 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7927 | ||
ce78b96d | 7928 | annotate_catchpoint (b->number); |
f303dbd6 | 7929 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7930 | if (b->disposition == disp_del) |
112e8700 | 7931 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7932 | else |
112e8700 SM |
7933 | uiout->text ("Catchpoint "); |
7934 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7935 | { |
112e8700 SM |
7936 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
7937 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7938 | } |
381befee | 7939 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7940 | uiout->text (" (vforked process "); |
381befee | 7941 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7942 | uiout->text ("), "); |
ce78b96d JB |
7943 | return PRINT_SRC_AND_LOC; |
7944 | } | |
7945 | ||
4a64f543 MS |
7946 | /* Implement the "print_one" breakpoint_ops method for vfork |
7947 | catchpoints. */ | |
ce78b96d JB |
7948 | |
7949 | static void | |
a6d9a66e | 7950 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7951 | { |
e29a4733 | 7952 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7953 | struct value_print_options opts; |
79a45e25 | 7954 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7955 | |
7956 | get_user_print_options (&opts); | |
4a64f543 MS |
7957 | /* Field 4, the address, is omitted (which makes the columns not |
7958 | line up too nicely with the headers, but the effect is relatively | |
7959 | readable). */ | |
79a45b7d | 7960 | if (opts.addressprint) |
112e8700 | 7961 | uiout->field_skip ("addr"); |
ce78b96d | 7962 | annotate_field (5); |
112e8700 | 7963 | uiout->text ("vfork"); |
d7e15655 | 7964 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7965 | { |
112e8700 | 7966 | uiout->text (", process "); |
381befee | 7967 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7968 | uiout->spaces (1); |
ce78b96d | 7969 | } |
8ac3646f | 7970 | |
112e8700 SM |
7971 | if (uiout->is_mi_like_p ()) |
7972 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
7973 | } |
7974 | ||
7975 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7976 | catchpoints. */ | |
7977 | ||
7978 | static void | |
7979 | print_mention_catch_vfork (struct breakpoint *b) | |
7980 | { | |
7981 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7982 | } | |
7983 | ||
6149aea9 PA |
7984 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7985 | catchpoints. */ | |
7986 | ||
7987 | static void | |
7988 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7989 | { | |
7990 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7991 | print_recreate_thread (b, fp); |
6149aea9 PA |
7992 | } |
7993 | ||
ce78b96d JB |
7994 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7995 | ||
2060206e | 7996 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7997 | |
edcc5120 | 7998 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 7999 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
8000 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
8001 | ||
c1fc2657 | 8002 | struct solib_catchpoint : public breakpoint |
edcc5120 | 8003 | { |
c1fc2657 | 8004 | ~solib_catchpoint () override; |
edcc5120 TT |
8005 | |
8006 | /* True for "catch load", false for "catch unload". */ | |
b650a282 | 8007 | bool is_load; |
edcc5120 TT |
8008 | |
8009 | /* Regular expression to match, if any. COMPILED is only valid when | |
8010 | REGEX is non-NULL. */ | |
8011 | char *regex; | |
2d7cc5c7 | 8012 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
8013 | }; |
8014 | ||
c1fc2657 | 8015 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 8016 | { |
c1fc2657 | 8017 | xfree (this->regex); |
edcc5120 TT |
8018 | } |
8019 | ||
8020 | static int | |
8021 | insert_catch_solib (struct bp_location *ignore) | |
8022 | { | |
8023 | return 0; | |
8024 | } | |
8025 | ||
8026 | static int | |
73971819 | 8027 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8028 | { |
8029 | return 0; | |
8030 | } | |
8031 | ||
8032 | static int | |
8033 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
bd522513 | 8034 | const address_space *aspace, |
edcc5120 TT |
8035 | CORE_ADDR bp_addr, |
8036 | const struct target_waitstatus *ws) | |
8037 | { | |
8038 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8039 | struct breakpoint *other; | |
8040 | ||
8041 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8042 | return 1; | |
8043 | ||
8044 | ALL_BREAKPOINTS (other) | |
8045 | { | |
8046 | struct bp_location *other_bl; | |
8047 | ||
8048 | if (other == bl->owner) | |
8049 | continue; | |
8050 | ||
8051 | if (other->type != bp_shlib_event) | |
8052 | continue; | |
8053 | ||
c1fc2657 | 8054 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
8055 | continue; |
8056 | ||
8057 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8058 | { | |
8059 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8060 | return 1; | |
8061 | } | |
8062 | } | |
8063 | ||
8064 | return 0; | |
8065 | } | |
8066 | ||
8067 | static void | |
8068 | check_status_catch_solib (struct bpstats *bs) | |
8069 | { | |
8070 | struct solib_catchpoint *self | |
8071 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
edcc5120 TT |
8072 | |
8073 | if (self->is_load) | |
8074 | { | |
52941706 | 8075 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 TT |
8076 | { |
8077 | if (!self->regex | |
2d7cc5c7 | 8078 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
8079 | return; |
8080 | } | |
8081 | } | |
8082 | else | |
8083 | { | |
6fb16ce6 | 8084 | for (const std::string &iter : current_program_space->deleted_solibs) |
edcc5120 TT |
8085 | { |
8086 | if (!self->regex | |
6fb16ce6 | 8087 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
edcc5120 TT |
8088 | return; |
8089 | } | |
8090 | } | |
8091 | ||
8092 | bs->stop = 0; | |
8093 | bs->print_it = print_it_noop; | |
8094 | } | |
8095 | ||
8096 | static enum print_stop_action | |
8097 | print_it_catch_solib (bpstat bs) | |
8098 | { | |
8099 | struct breakpoint *b = bs->breakpoint_at; | |
8100 | struct ui_out *uiout = current_uiout; | |
8101 | ||
8102 | annotate_catchpoint (b->number); | |
f303dbd6 | 8103 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8104 | if (b->disposition == disp_del) |
112e8700 | 8105 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8106 | else |
112e8700 | 8107 | uiout->text ("Catchpoint "); |
381befee | 8108 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
8109 | uiout->text ("\n"); |
8110 | if (uiout->is_mi_like_p ()) | |
8111 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8112 | print_solib_event (1); |
8113 | return PRINT_SRC_AND_LOC; | |
8114 | } | |
8115 | ||
8116 | static void | |
8117 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8118 | { | |
8119 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8120 | struct value_print_options opts; | |
8121 | struct ui_out *uiout = current_uiout; | |
edcc5120 TT |
8122 | |
8123 | get_user_print_options (&opts); | |
8124 | /* Field 4, the address, is omitted (which makes the columns not | |
8125 | line up too nicely with the headers, but the effect is relatively | |
8126 | readable). */ | |
8127 | if (opts.addressprint) | |
8128 | { | |
8129 | annotate_field (4); | |
112e8700 | 8130 | uiout->field_skip ("addr"); |
edcc5120 TT |
8131 | } |
8132 | ||
528e1572 | 8133 | std::string msg; |
edcc5120 TT |
8134 | annotate_field (5); |
8135 | if (self->is_load) | |
8136 | { | |
8137 | if (self->regex) | |
528e1572 | 8138 | msg = string_printf (_("load of library matching %s"), self->regex); |
edcc5120 | 8139 | else |
528e1572 | 8140 | msg = _("load of library"); |
edcc5120 TT |
8141 | } |
8142 | else | |
8143 | { | |
8144 | if (self->regex) | |
528e1572 | 8145 | msg = string_printf (_("unload of library matching %s"), self->regex); |
edcc5120 | 8146 | else |
528e1572 | 8147 | msg = _("unload of library"); |
edcc5120 | 8148 | } |
112e8700 | 8149 | uiout->field_string ("what", msg); |
8ac3646f | 8150 | |
112e8700 SM |
8151 | if (uiout->is_mi_like_p ()) |
8152 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8153 | } |
8154 | ||
8155 | static void | |
8156 | print_mention_catch_solib (struct breakpoint *b) | |
8157 | { | |
8158 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8159 | ||
8160 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8161 | self->is_load ? "load" : "unload"); | |
8162 | } | |
8163 | ||
8164 | static void | |
8165 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8166 | { | |
8167 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8168 | ||
8169 | fprintf_unfiltered (fp, "%s %s", | |
8170 | b->disposition == disp_del ? "tcatch" : "catch", | |
8171 | self->is_load ? "load" : "unload"); | |
8172 | if (self->regex) | |
8173 | fprintf_unfiltered (fp, " %s", self->regex); | |
8174 | fprintf_unfiltered (fp, "\n"); | |
8175 | } | |
8176 | ||
8177 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8178 | ||
b650a282 | 8179 | /* See breakpoint.h. */ |
edcc5120 | 8180 | |
91985142 | 8181 | void |
b650a282 | 8182 | add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled) |
edcc5120 | 8183 | { |
edcc5120 | 8184 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8185 | |
edcc5120 TT |
8186 | if (!arg) |
8187 | arg = ""; | |
f1735a53 | 8188 | arg = skip_spaces (arg); |
edcc5120 | 8189 | |
36bd8eaa | 8190 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8191 | |
8192 | if (*arg != '\0') | |
8193 | { | |
2d7cc5c7 PA |
8194 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8195 | _("Invalid regexp"))); | |
edcc5120 TT |
8196 | c->regex = xstrdup (arg); |
8197 | } | |
8198 | ||
8199 | c->is_load = is_load; | |
36bd8eaa | 8200 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8201 | &catch_solib_breakpoint_ops); |
8202 | ||
c1fc2657 | 8203 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8204 | |
b270e6f9 | 8205 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8206 | } |
8207 | ||
91985142 MG |
8208 | /* A helper function that does all the work for "catch load" and |
8209 | "catch unload". */ | |
8210 | ||
8211 | static void | |
eb4c3f4a | 8212 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
91985142 MG |
8213 | struct cmd_list_element *command) |
8214 | { | |
91985142 | 8215 | const int enabled = 1; |
b650a282 | 8216 | bool temp = get_cmd_context (command) == CATCH_TEMPORARY; |
91985142 | 8217 | |
b650a282 | 8218 | add_solib_catchpoint (arg, is_load, temp, enabled); |
91985142 MG |
8219 | } |
8220 | ||
edcc5120 | 8221 | static void |
eb4c3f4a | 8222 | catch_load_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8223 | struct cmd_list_element *command) |
8224 | { | |
8225 | catch_load_or_unload (arg, from_tty, 1, command); | |
8226 | } | |
8227 | ||
8228 | static void | |
eb4c3f4a | 8229 | catch_unload_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8230 | struct cmd_list_element *command) |
8231 | { | |
8232 | catch_load_or_unload (arg, from_tty, 0, command); | |
8233 | } | |
8234 | ||
b650a282 | 8235 | /* See breakpoint.h. */ |
ce78b96d | 8236 | |
ab04a2af | 8237 | void |
346774a9 | 8238 | init_catchpoint (struct breakpoint *b, |
b650a282 | 8239 | struct gdbarch *gdbarch, bool temp, |
63160a43 | 8240 | const char *cond_string, |
c0a91b2b | 8241 | const struct breakpoint_ops *ops) |
c906108c | 8242 | { |
51abb421 | 8243 | symtab_and_line sal; |
6c95b8df | 8244 | sal.pspace = current_program_space; |
c5aa993b | 8245 | |
28010a5d | 8246 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8247 | |
1b36a34b | 8248 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b650a282 | 8249 | b->disposition = temp ? disp_del : disp_donttouch; |
346774a9 PA |
8250 | } |
8251 | ||
28010a5d | 8252 | void |
b270e6f9 | 8253 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8254 | { |
b270e6f9 | 8255 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8256 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8257 | if (is_tracepoint (b)) |
8258 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8259 | if (!internal) |
8260 | mention (b); | |
76727919 | 8261 | gdb::observers::breakpoint_created.notify (b); |
3ea46bff YQ |
8262 | |
8263 | if (update_gll) | |
44702360 | 8264 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8265 | } |
8266 | ||
9b70b993 | 8267 | static void |
a6d9a66e | 8268 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
b650a282 | 8269 | bool temp, const char *cond_string, |
dda83cd7 | 8270 | const struct breakpoint_ops *ops) |
c906108c | 8271 | { |
b270e6f9 | 8272 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8273 | |
b650a282 | 8274 | init_catchpoint (c.get (), gdbarch, temp, cond_string, ops); |
e29a4733 PA |
8275 | |
8276 | c->forked_inferior_pid = null_ptid; | |
8277 | ||
b270e6f9 | 8278 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8279 | } |
8280 | ||
fe798b75 JB |
8281 | /* Exec catchpoints. */ |
8282 | ||
b4d90040 | 8283 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8284 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8285 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8286 | ||
c1fc2657 | 8287 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8288 | { |
c1fc2657 | 8289 | ~exec_catchpoint () override; |
b4d90040 PA |
8290 | |
8291 | /* Filename of a program whose exec triggered this catchpoint. | |
8292 | This field is only valid immediately after this catchpoint has | |
8293 | triggered. */ | |
8294 | char *exec_pathname; | |
8295 | }; | |
8296 | ||
c1fc2657 | 8297 | /* Exec catchpoint destructor. */ |
b4d90040 | 8298 | |
c1fc2657 | 8299 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8300 | { |
c1fc2657 | 8301 | xfree (this->exec_pathname); |
b4d90040 PA |
8302 | } |
8303 | ||
77b06cd7 TJB |
8304 | static int |
8305 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8306 | { |
e99b03dc | 8307 | return target_insert_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8308 | } |
c906108c | 8309 | |
fe798b75 | 8310 | static int |
73971819 | 8311 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8312 | { |
e99b03dc | 8313 | return target_remove_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8314 | } |
c906108c | 8315 | |
fe798b75 | 8316 | static int |
f1310107 | 8317 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
bd522513 | 8318 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 8319 | const struct target_waitstatus *ws) |
fe798b75 | 8320 | { |
b4d90040 PA |
8321 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8322 | ||
f90263c1 TT |
8323 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8324 | return 0; | |
8325 | ||
8326 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8327 | return 1; | |
fe798b75 | 8328 | } |
c906108c | 8329 | |
fe798b75 | 8330 | static enum print_stop_action |
348d480f | 8331 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8332 | { |
36dfb11c | 8333 | struct ui_out *uiout = current_uiout; |
348d480f | 8334 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8335 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8336 | ||
fe798b75 | 8337 | annotate_catchpoint (b->number); |
f303dbd6 | 8338 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8339 | if (b->disposition == disp_del) |
112e8700 | 8340 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8341 | else |
112e8700 SM |
8342 | uiout->text ("Catchpoint "); |
8343 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8344 | { |
112e8700 SM |
8345 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8346 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8347 | } |
381befee | 8348 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
8349 | uiout->text (" (exec'd "); |
8350 | uiout->field_string ("new-exec", c->exec_pathname); | |
8351 | uiout->text ("), "); | |
36dfb11c | 8352 | |
fe798b75 | 8353 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8354 | } |
8355 | ||
fe798b75 | 8356 | static void |
a6d9a66e | 8357 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8358 | { |
b4d90040 | 8359 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8360 | struct value_print_options opts; |
79a45e25 | 8361 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8362 | |
8363 | get_user_print_options (&opts); | |
8364 | ||
8365 | /* Field 4, the address, is omitted (which makes the columns | |
8366 | not line up too nicely with the headers, but the effect | |
8367 | is relatively readable). */ | |
8368 | if (opts.addressprint) | |
112e8700 | 8369 | uiout->field_skip ("addr"); |
fe798b75 | 8370 | annotate_field (5); |
112e8700 | 8371 | uiout->text ("exec"); |
b4d90040 | 8372 | if (c->exec_pathname != NULL) |
fe798b75 | 8373 | { |
112e8700 SM |
8374 | uiout->text (", program \""); |
8375 | uiout->field_string ("what", c->exec_pathname); | |
8376 | uiout->text ("\" "); | |
fe798b75 | 8377 | } |
8ac3646f | 8378 | |
112e8700 SM |
8379 | if (uiout->is_mi_like_p ()) |
8380 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8381 | } |
8382 | ||
8383 | static void | |
8384 | print_mention_catch_exec (struct breakpoint *b) | |
8385 | { | |
8386 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8387 | } | |
8388 | ||
6149aea9 PA |
8389 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8390 | catchpoints. */ | |
8391 | ||
8392 | static void | |
8393 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8394 | { | |
8395 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8396 | print_recreate_thread (b, fp); |
6149aea9 PA |
8397 | } |
8398 | ||
2060206e | 8399 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8400 | |
c906108c | 8401 | static int |
fba45db2 | 8402 | hw_breakpoint_used_count (void) |
c906108c | 8403 | { |
c906108c | 8404 | int i = 0; |
f1310107 TJB |
8405 | struct breakpoint *b; |
8406 | struct bp_location *bl; | |
c906108c SS |
8407 | |
8408 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8409 | { |
d6b74ac4 | 8410 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8411 | for (bl = b->loc; bl; bl = bl->next) |
8412 | { | |
8413 | /* Special types of hardware breakpoints may use more than | |
8414 | one register. */ | |
348d480f | 8415 | i += b->ops->resources_needed (bl); |
f1310107 | 8416 | } |
c5aa993b | 8417 | } |
c906108c SS |
8418 | |
8419 | return i; | |
8420 | } | |
8421 | ||
a1398e0c PA |
8422 | /* Returns the resources B would use if it were a hardware |
8423 | watchpoint. */ | |
8424 | ||
c906108c | 8425 | static int |
a1398e0c | 8426 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8427 | { |
c906108c | 8428 | int i = 0; |
e09342b5 | 8429 | struct bp_location *bl; |
c906108c | 8430 | |
a1398e0c PA |
8431 | if (!breakpoint_enabled (b)) |
8432 | return 0; | |
8433 | ||
8434 | for (bl = b->loc; bl; bl = bl->next) | |
8435 | { | |
8436 | /* Special types of hardware watchpoints may use more than | |
8437 | one register. */ | |
8438 | i += b->ops->resources_needed (bl); | |
8439 | } | |
8440 | ||
8441 | return i; | |
8442 | } | |
8443 | ||
8444 | /* Returns the sum the used resources of all hardware watchpoints of | |
8445 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8446 | the sum of the used resources of all hardware watchpoints of other | |
8447 | types _not_ TYPE. */ | |
8448 | ||
8449 | static int | |
8450 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8451 | enum bptype type, int *other_type_used) | |
8452 | { | |
8453 | int i = 0; | |
8454 | struct breakpoint *b; | |
8455 | ||
c906108c SS |
8456 | *other_type_used = 0; |
8457 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8458 | { |
a1398e0c PA |
8459 | if (b == except) |
8460 | continue; | |
e09342b5 TJB |
8461 | if (!breakpoint_enabled (b)) |
8462 | continue; | |
8463 | ||
a1398e0c PA |
8464 | if (b->type == type) |
8465 | i += hw_watchpoint_use_count (b); | |
8466 | else if (is_hardware_watchpoint (b)) | |
8467 | *other_type_used = 1; | |
e09342b5 TJB |
8468 | } |
8469 | ||
c906108c SS |
8470 | return i; |
8471 | } | |
8472 | ||
c906108c | 8473 | void |
fba45db2 | 8474 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8475 | { |
c5aa993b | 8476 | struct breakpoint *b; |
c906108c SS |
8477 | |
8478 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8479 | { |
cc60f2e3 | 8480 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8481 | { |
b5de0fa7 | 8482 | b->enable_state = bp_call_disabled; |
44702360 | 8483 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8484 | } |
8485 | } | |
c906108c SS |
8486 | } |
8487 | ||
8488 | void | |
fba45db2 | 8489 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8490 | { |
c5aa993b | 8491 | struct breakpoint *b; |
c906108c SS |
8492 | |
8493 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8494 | { |
cc60f2e3 | 8495 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8496 | { |
b5de0fa7 | 8497 | b->enable_state = bp_enabled; |
44702360 | 8498 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8499 | } |
8500 | } | |
c906108c SS |
8501 | } |
8502 | ||
8bea4e01 UW |
8503 | void |
8504 | disable_breakpoints_before_startup (void) | |
8505 | { | |
6c95b8df | 8506 | current_program_space->executing_startup = 1; |
44702360 | 8507 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8508 | } |
8509 | ||
8510 | void | |
8511 | enable_breakpoints_after_startup (void) | |
8512 | { | |
6c95b8df | 8513 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8514 | breakpoint_re_set (); |
8bea4e01 UW |
8515 | } |
8516 | ||
7c16b83e PA |
8517 | /* Create a new single-step breakpoint for thread THREAD, with no |
8518 | locations. */ | |
c906108c | 8519 | |
7c16b83e PA |
8520 | static struct breakpoint * |
8521 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8522 | { | |
b270e6f9 | 8523 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8524 | |
b270e6f9 | 8525 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8526 | &momentary_breakpoint_ops); |
8527 | ||
8528 | b->disposition = disp_donttouch; | |
8529 | b->frame_id = null_frame_id; | |
8530 | ||
8531 | b->thread = thread; | |
8532 | gdb_assert (b->thread != 0); | |
8533 | ||
b270e6f9 | 8534 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8535 | } |
8536 | ||
8537 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8538 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8539 | frame. */ | |
c906108c | 8540 | |
454dafbd | 8541 | breakpoint_up |
a6d9a66e UW |
8542 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8543 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8544 | { |
52f0bd74 | 8545 | struct breakpoint *b; |
edb3359d | 8546 | |
193facb3 JK |
8547 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8548 | tail-called one. */ | |
8549 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8550 | |
06edf0c0 | 8551 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8552 | b->enable_state = bp_enabled; |
8553 | b->disposition = disp_donttouch; | |
818dd999 | 8554 | b->frame_id = frame_id; |
c906108c | 8555 | |
00431a78 | 8556 | b->thread = inferior_thread ()->global_num; |
c906108c | 8557 | |
44702360 | 8558 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8559 | |
454dafbd | 8560 | return breakpoint_up (b); |
c906108c | 8561 | } |
611c83ae | 8562 | |
06edf0c0 | 8563 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8564 | The new breakpoint will have type TYPE, use OPS as its |
8565 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8566 | |
06edf0c0 PA |
8567 | static struct breakpoint * |
8568 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8569 | enum bptype type, | |
a1aa2221 LM |
8570 | const struct breakpoint_ops *ops, |
8571 | int loc_enabled) | |
e58b0e63 PA |
8572 | { |
8573 | struct breakpoint *copy; | |
8574 | ||
06edf0c0 | 8575 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8576 | copy->loc = allocate_bp_location (copy); |
0ba852ab | 8577 | set_breakpoint_location_function (copy->loc); |
e58b0e63 | 8578 | |
a6d9a66e | 8579 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8580 | copy->loc->requested_address = orig->loc->requested_address; |
8581 | copy->loc->address = orig->loc->address; | |
8582 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8583 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8584 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8585 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8586 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8587 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8588 | copy->frame_id = orig->frame_id; |
8589 | copy->thread = orig->thread; | |
6c95b8df | 8590 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8591 | |
8592 | copy->enable_state = bp_enabled; | |
8593 | copy->disposition = disp_donttouch; | |
8594 | copy->number = internal_breakpoint_number--; | |
8595 | ||
44702360 | 8596 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8597 | return copy; |
8598 | } | |
8599 | ||
06edf0c0 PA |
8600 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8601 | ORIG is NULL. */ | |
8602 | ||
8603 | struct breakpoint * | |
8604 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8605 | { | |
8606 | /* If there's nothing to clone, then return nothing. */ | |
8607 | if (orig == NULL) | |
8608 | return NULL; | |
8609 | ||
a1aa2221 | 8610 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8611 | } |
8612 | ||
454dafbd | 8613 | breakpoint_up |
a6d9a66e UW |
8614 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8615 | enum bptype type) | |
611c83ae PA |
8616 | { |
8617 | struct symtab_and_line sal; | |
8618 | ||
8619 | sal = find_pc_line (pc, 0); | |
8620 | sal.pc = pc; | |
8621 | sal.section = find_pc_overlay (pc); | |
8622 | sal.explicit_pc = 1; | |
8623 | ||
a6d9a66e | 8624 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8625 | } |
c906108c | 8626 | \f |
c5aa993b | 8627 | |
c906108c SS |
8628 | /* Tell the user we have just set a breakpoint B. */ |
8629 | ||
8630 | static void | |
fba45db2 | 8631 | mention (struct breakpoint *b) |
c906108c | 8632 | { |
348d480f | 8633 | b->ops->print_mention (b); |
2d33446d | 8634 | current_uiout->text ("\n"); |
c906108c | 8635 | } |
c906108c | 8636 | \f |
c5aa993b | 8637 | |
5133a315 | 8638 | static bool bp_loc_is_permanent (struct bp_location *loc); |
1a853c52 | 8639 | |
7f32a4d5 PA |
8640 | /* Handle "set breakpoint auto-hw on". |
8641 | ||
8642 | If the explicitly specified breakpoint type is not hardware | |
8643 | breakpoint, check the memory map to see whether the breakpoint | |
8644 | address is in read-only memory. | |
8645 | ||
8646 | - location type is not hardware breakpoint, memory is read-only. | |
8647 | We change the type of the location to hardware breakpoint. | |
8648 | ||
8649 | - location type is hardware breakpoint, memory is read-write. This | |
8650 | means we've previously made the location hardware one, but then the | |
8651 | memory map changed, so we undo. | |
8652 | */ | |
8653 | ||
8654 | static void | |
8655 | handle_automatic_hardware_breakpoints (bp_location *bl) | |
8656 | { | |
8657 | if (automatic_hardware_breakpoints | |
8658 | && bl->owner->type != bp_hardware_breakpoint | |
8659 | && (bl->loc_type == bp_loc_software_breakpoint | |
8660 | || bl->loc_type == bp_loc_hardware_breakpoint)) | |
8661 | { | |
8662 | /* When breakpoints are removed, remove_breakpoints will use | |
8663 | location types we've just set here, the only possible problem | |
8664 | is that memory map has changed during running program, but | |
8665 | it's not going to work anyway with current gdb. */ | |
8666 | mem_region *mr = lookup_mem_region (bl->address); | |
8667 | ||
8668 | if (mr != nullptr) | |
8669 | { | |
8670 | enum bp_loc_type new_type; | |
8671 | ||
8672 | if (mr->attrib.mode != MEM_RW) | |
8673 | new_type = bp_loc_hardware_breakpoint; | |
8674 | else | |
8675 | new_type = bp_loc_software_breakpoint; | |
8676 | ||
8677 | if (new_type != bl->loc_type) | |
8678 | { | |
8679 | static bool said = false; | |
8680 | ||
8681 | bl->loc_type = new_type; | |
8682 | if (!said) | |
8683 | { | |
8684 | fprintf_filtered (gdb_stdout, | |
8685 | _("Note: automatically using " | |
8686 | "hardware breakpoints for " | |
8687 | "read-only addresses.\n")); | |
8688 | said = true; | |
8689 | } | |
8690 | } | |
8691 | } | |
8692 | } | |
8693 | } | |
8694 | ||
0d381245 | 8695 | static struct bp_location * |
39d61571 | 8696 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8697 | const struct symtab_and_line *sal) |
8698 | { | |
8699 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8700 | CORE_ADDR adjusted_address; |
8701 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8702 | ||
8703 | if (loc_gdbarch == NULL) | |
8704 | loc_gdbarch = b->gdbarch; | |
8705 | ||
8706 | /* Adjust the breakpoint's address prior to allocating a location. | |
8707 | Once we call allocate_bp_location(), that mostly uninitialized | |
8708 | location will be placed on the location chain. Adjustment of the | |
8709 | breakpoint may cause target_read_memory() to be called and we do | |
8710 | not want its scan of the location chain to find a breakpoint and | |
8711 | location that's only been partially initialized. */ | |
8712 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8713 | sal->pc, b->type); | |
0d381245 | 8714 | |
d30113d4 | 8715 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8716 | loc = allocate_bp_location (b); |
d30113d4 JK |
8717 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8718 | tmp = &((*tmp)->next)) | |
0d381245 | 8719 | ; |
d30113d4 | 8720 | loc->next = *tmp; |
0d381245 | 8721 | *tmp = loc; |
3742cc8b | 8722 | |
0d381245 | 8723 | loc->requested_address = sal->pc; |
3742cc8b | 8724 | loc->address = adjusted_address; |
6c95b8df | 8725 | loc->pspace = sal->pspace; |
935676c9 | 8726 | loc->probe.prob = sal->prob; |
729662a5 | 8727 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8728 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8729 | loc->section = sal->section; |
3742cc8b | 8730 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8731 | loc->line_number = sal->line; |
2f202fde | 8732 | loc->symtab = sal->symtab; |
4a27f119 | 8733 | loc->symbol = sal->symbol; |
3467ec66 PA |
8734 | loc->msymbol = sal->msymbol; |
8735 | loc->objfile = sal->objfile; | |
f8eba3c6 | 8736 | |
0ba852ab | 8737 | set_breakpoint_location_function (loc); |
1a853c52 | 8738 | |
6ae88661 LM |
8739 | /* While by definition, permanent breakpoints are already present in the |
8740 | code, we don't mark the location as inserted. Normally one would expect | |
8741 | that GDB could rely on that breakpoint instruction to stop the program, | |
8742 | thus removing the need to insert its own breakpoint, except that executing | |
8743 | the breakpoint instruction can kill the target instead of reporting a | |
8744 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8745 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8746 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8747 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8748 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8749 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8750 | it manually increments the PC, thus avoiding executing the breakpoint | |
8751 | instruction.) */ | |
1a853c52 | 8752 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8753 | loc->permanent = 1; |
1a853c52 | 8754 | |
0d381245 VP |
8755 | return loc; |
8756 | } | |
514f746b AR |
8757 | \f |
8758 | ||
5133a315 LM |
8759 | /* Return true if LOC is pointing to a permanent breakpoint, |
8760 | return false otherwise. */ | |
1cf4d951 | 8761 | |
5133a315 | 8762 | static bool |
1cf4d951 PA |
8763 | bp_loc_is_permanent (struct bp_location *loc) |
8764 | { | |
514f746b AR |
8765 | gdb_assert (loc != NULL); |
8766 | ||
cb1e4e32 PA |
8767 | /* If we have a non-breakpoint-backed catchpoint or a software |
8768 | watchpoint, just return 0. We should not attempt to read from | |
8769 | the addresses the locations of these breakpoint types point to. | |
5133a315 | 8770 | gdbarch_program_breakpoint_here_p, below, will attempt to read |
244558af | 8771 | memory. */ |
cb1e4e32 | 8772 | if (!bl_address_is_meaningful (loc)) |
5133a315 | 8773 | return false; |
244558af | 8774 | |
5ed8105e | 8775 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8776 | switch_to_program_space_and_thread (loc->pspace); |
5133a315 | 8777 | return gdbarch_program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8778 | } |
8779 | ||
e7e0cddf SS |
8780 | /* Build a command list for the dprintf corresponding to the current |
8781 | settings of the dprintf style options. */ | |
8782 | ||
8783 | static void | |
8784 | update_dprintf_command_list (struct breakpoint *b) | |
8785 | { | |
8786 | char *dprintf_args = b->extra_string; | |
8787 | char *printf_line = NULL; | |
8788 | ||
8789 | if (!dprintf_args) | |
8790 | return; | |
8791 | ||
8792 | dprintf_args = skip_spaces (dprintf_args); | |
8793 | ||
8794 | /* Allow a comma, as it may have terminated a location, but don't | |
8795 | insist on it. */ | |
8796 | if (*dprintf_args == ',') | |
8797 | ++dprintf_args; | |
8798 | dprintf_args = skip_spaces (dprintf_args); | |
8799 | ||
8800 | if (*dprintf_args != '"') | |
8801 | error (_("Bad format string, missing '\"'.")); | |
8802 | ||
d3ce09f5 | 8803 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8804 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8805 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8806 | { |
8807 | if (!dprintf_function) | |
8808 | error (_("No function supplied for dprintf call")); | |
8809 | ||
8810 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8811 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8812 | dprintf_function, | |
8813 | dprintf_channel, | |
8814 | dprintf_args); | |
8815 | else | |
8816 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8817 | dprintf_function, | |
8818 | dprintf_args); | |
8819 | } | |
d3ce09f5 SS |
8820 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8821 | { | |
8822 | if (target_can_run_breakpoint_commands ()) | |
8823 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8824 | else | |
8825 | { | |
8826 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8827 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8828 | } | |
8829 | } | |
e7e0cddf SS |
8830 | else |
8831 | internal_error (__FILE__, __LINE__, | |
8832 | _("Invalid dprintf style.")); | |
8833 | ||
f28045c2 | 8834 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8835 | |
12973681 TT |
8836 | /* Manufacture a printf sequence. */ |
8837 | struct command_line *printf_cmd_line | |
8838 | = new struct command_line (simple_control, printf_line); | |
8839 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, | |
8840 | command_lines_deleter ())); | |
e7e0cddf SS |
8841 | } |
8842 | ||
8843 | /* Update all dprintf commands, making their command lists reflect | |
8844 | current style settings. */ | |
8845 | ||
8846 | static void | |
eb4c3f4a | 8847 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8848 | struct cmd_list_element *c) |
8849 | { | |
8850 | struct breakpoint *b; | |
8851 | ||
8852 | ALL_BREAKPOINTS (b) | |
8853 | { | |
8854 | if (b->type == bp_dprintf) | |
8855 | update_dprintf_command_list (b); | |
8856 | } | |
8857 | } | |
c3f6f71d | 8858 | |
f00aae0f KS |
8859 | /* Create a breakpoint with SAL as location. Use LOCATION |
8860 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8861 | as condition expression. If LOCATION is NULL then create an |
8862 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8863 | |
8864 | static void | |
d9b3f62e | 8865 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8866 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8867 | event_location_up &&location, |
e1e01040 PA |
8868 | gdb::unique_xmalloc_ptr<char> filter, |
8869 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8870 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8871 | enum bptype type, enum bpdisp disposition, |
8872 | int thread, int task, int ignore_count, | |
c0a91b2b | 8873 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8874 | int enabled, int internal, unsigned flags, |
8875 | int display_canonical) | |
018d34a4 | 8876 | { |
0d381245 | 8877 | int i; |
018d34a4 VP |
8878 | |
8879 | if (type == bp_hardware_breakpoint) | |
8880 | { | |
fbbd034e AS |
8881 | int target_resources_ok; |
8882 | ||
8883 | i = hw_breakpoint_used_count (); | |
8884 | target_resources_ok = | |
8885 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8886 | i + 1, 0); |
8887 | if (target_resources_ok == 0) | |
8888 | error (_("No hardware breakpoint support in the target.")); | |
8889 | else if (target_resources_ok < 0) | |
8890 | error (_("Hardware breakpoints used exceeds limit.")); | |
8891 | } | |
8892 | ||
6c5b2ebe | 8893 | gdb_assert (!sals.empty ()); |
6c95b8df | 8894 | |
6c5b2ebe | 8895 | for (const auto &sal : sals) |
0d381245 | 8896 | { |
0d381245 VP |
8897 | struct bp_location *loc; |
8898 | ||
8899 | if (from_tty) | |
5af949e3 UW |
8900 | { |
8901 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8902 | if (!loc_gdbarch) | |
8903 | loc_gdbarch = gdbarch; | |
8904 | ||
8905 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8906 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8907 | } |
0d381245 | 8908 | |
6c5b2ebe | 8909 | if (&sal == &sals[0]) |
0d381245 | 8910 | { |
d9b3f62e | 8911 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8912 | b->thread = thread; |
4a306c9a | 8913 | b->task = task; |
855a6e68 | 8914 | |
e1e01040 PA |
8915 | b->cond_string = cond_string.release (); |
8916 | b->extra_string = extra_string.release (); | |
0d381245 | 8917 | b->ignore_count = ignore_count; |
41447f92 | 8918 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8919 | b->disposition = disposition; |
6c95b8df | 8920 | |
44f238bb PA |
8921 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8922 | b->loc->inserted = 1; | |
8923 | ||
0fb4aa4b PA |
8924 | if (type == bp_static_tracepoint) |
8925 | { | |
d9b3f62e | 8926 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8927 | struct static_tracepoint_marker marker; |
8928 | ||
983af33b | 8929 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8930 | { |
8931 | /* We already know the marker exists, otherwise, we | |
8932 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8933 | const char *p |
8934 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8935 | const char *endp; |
0fb4aa4b | 8936 | |
f1735a53 | 8937 | p = skip_spaces (p); |
0fb4aa4b | 8938 | |
f1735a53 | 8939 | endp = skip_to_space (p); |
0fb4aa4b | 8940 | |
5d9310c4 | 8941 | t->static_trace_marker_id.assign (p, endp - p); |
0fb4aa4b | 8942 | |
3e43a32a MS |
8943 | printf_filtered (_("Probed static tracepoint " |
8944 | "marker \"%s\"\n"), | |
5d9310c4 | 8945 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8946 | } |
8947 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8948 | { | |
5d9310c4 | 8949 | t->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b | 8950 | |
3e43a32a MS |
8951 | printf_filtered (_("Probed static tracepoint " |
8952 | "marker \"%s\"\n"), | |
5d9310c4 | 8953 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8954 | } |
8955 | else | |
3e43a32a MS |
8956 | warning (_("Couldn't determine the static " |
8957 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8958 | } |
8959 | ||
0d381245 VP |
8960 | loc = b->loc; |
8961 | } | |
8962 | else | |
018d34a4 | 8963 | { |
39d61571 | 8964 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8965 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8966 | loc->inserted = 1; | |
0d381245 VP |
8967 | } |
8968 | ||
b5fa468f TBA |
8969 | /* Do not set breakpoint locations conditions yet. As locations |
8970 | are inserted, they get sorted based on their addresses. Let | |
8971 | the list stabilize to have reliable location numbers. */ | |
e7e0cddf SS |
8972 | |
8973 | /* Dynamic printf requires and uses additional arguments on the | |
8974 | command line, otherwise it's an error. */ | |
8975 | if (type == bp_dprintf) | |
8976 | { | |
8977 | if (b->extra_string) | |
8978 | update_dprintf_command_list (b); | |
8979 | else | |
8980 | error (_("Format string required")); | |
8981 | } | |
8982 | else if (b->extra_string) | |
588ae58c | 8983 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 8984 | } |
018d34a4 | 8985 | |
b5fa468f TBA |
8986 | |
8987 | /* The order of the locations is now stable. Set the location | |
8988 | condition using the location's number. */ | |
8989 | int loc_num = 1; | |
8990 | for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) | |
8991 | { | |
8992 | if (b->cond_string != nullptr) | |
8993 | set_breakpoint_location_condition (b->cond_string, loc, b->number, | |
8994 | loc_num); | |
8995 | ||
8996 | ++loc_num; | |
8997 | } | |
8998 | ||
56435ebe | 8999 | b->display_canonical = display_canonical; |
f00aae0f | 9000 | if (location != NULL) |
d28cd78a | 9001 | b->location = std::move (location); |
018d34a4 | 9002 | else |
d28cd78a | 9003 | b->location = new_address_location (b->loc->address, NULL, 0); |
c0e8dcd8 | 9004 | b->filter = std::move (filter); |
d9b3f62e | 9005 | } |
018d34a4 | 9006 | |
d9b3f62e PA |
9007 | static void |
9008 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 9009 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9010 | event_location_up &&location, |
e1e01040 PA |
9011 | gdb::unique_xmalloc_ptr<char> filter, |
9012 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9013 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9014 | enum bptype type, enum bpdisp disposition, |
9015 | int thread, int task, int ignore_count, | |
c0a91b2b | 9016 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9017 | int enabled, int internal, unsigned flags, |
9018 | int display_canonical) | |
d9b3f62e | 9019 | { |
a5e364af | 9020 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 9021 | |
a5e364af | 9022 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 9023 | sals, std::move (location), |
e1e01040 PA |
9024 | std::move (filter), |
9025 | std::move (cond_string), | |
9026 | std::move (extra_string), | |
d9b3f62e PA |
9027 | type, disposition, |
9028 | thread, task, ignore_count, | |
9029 | ops, from_tty, | |
44f238bb PA |
9030 | enabled, internal, flags, |
9031 | display_canonical); | |
d9b3f62e | 9032 | |
b270e6f9 | 9033 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
9034 | } |
9035 | ||
9036 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9037 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9038 | value. COND_STRING, if not NULL, specified the condition to be | |
9039 | used for all breakpoints. Essentially the only case where | |
9040 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9041 | function. In that case, it's still not possible to specify | |
9042 | separate conditions for different overloaded functions, so | |
9043 | we take just a single condition string. | |
9044 | ||
c3f6f71d | 9045 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9046 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9047 | array contents). If the function fails (error() is called), the |
9048 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9049 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9050 | |
9051 | static void | |
8cdf0e15 | 9052 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9053 | struct linespec_result *canonical, |
e1e01040 PA |
9054 | gdb::unique_xmalloc_ptr<char> cond_string, |
9055 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
9056 | enum bptype type, enum bpdisp disposition, |
9057 | int thread, int task, int ignore_count, | |
c0a91b2b | 9058 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9059 | int enabled, int internal, unsigned flags) |
c906108c | 9060 | { |
f8eba3c6 | 9061 | if (canonical->pre_expanded) |
6c5b2ebe | 9062 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 9063 | |
6c5b2ebe | 9064 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 9065 | { |
f00aae0f | 9066 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9067 | 'break', without arguments. */ |
ffc2605c | 9068 | event_location_up location |
f00aae0f | 9069 | = (canonical->location != NULL |
8e9e35b1 | 9070 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 9071 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 9072 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 9073 | |
6c5b2ebe | 9074 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 9075 | std::move (location), |
e1e01040 PA |
9076 | std::move (filter_string), |
9077 | std::move (cond_string), | |
9078 | std::move (extra_string), | |
e7e0cddf | 9079 | type, disposition, |
84f4c1fe | 9080 | thread, task, ignore_count, ops, |
44f238bb | 9081 | from_tty, enabled, internal, flags, |
56435ebe | 9082 | canonical->special_display); |
c3f6f71d | 9083 | } |
c3f6f71d | 9084 | } |
c906108c | 9085 | |
f00aae0f | 9086 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9087 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9088 | addresses found. LOCATION points to the end of the SAL (for |
9089 | linespec locations). | |
9998af43 TJB |
9090 | |
9091 | The array and the line spec strings are allocated on the heap, it is | |
9092 | the caller's responsibility to free them. */ | |
c906108c | 9093 | |
b9362cc7 | 9094 | static void |
626d2320 | 9095 | parse_breakpoint_sals (struct event_location *location, |
58438ac1 | 9096 | struct linespec_result *canonical) |
c3f6f71d | 9097 | { |
f00aae0f KS |
9098 | struct symtab_and_line cursal; |
9099 | ||
9100 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9101 | { | |
a20714ff | 9102 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 9103 | |
a20714ff | 9104 | if (spec == NULL) |
f00aae0f KS |
9105 | { |
9106 | /* The last displayed codepoint, if it's valid, is our default | |
9107 | breakpoint address. */ | |
9108 | if (last_displayed_sal_is_valid ()) | |
9109 | { | |
f00aae0f KS |
9110 | /* Set sal's pspace, pc, symtab, and line to the values |
9111 | corresponding to the last call to print_frame_info. | |
9112 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9113 | as the breakpoint line number is inappropriate otherwise. | |
9114 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
9115 | symtab_and_line sal = get_last_displayed_sal (); |
9116 | CORE_ADDR pc = sal.pc; | |
9117 | ||
f00aae0f KS |
9118 | sal = find_pc_line (pc, 0); |
9119 | ||
9120 | /* "break" without arguments is equivalent to "break *PC" | |
9121 | where PC is the last displayed codepoint's address. So | |
9122 | make sure to set sal.explicit_pc to prevent GDB from | |
9123 | trying to expand the list of sals to include all other | |
9124 | instances with the same symtab and line. */ | |
9125 | sal.pc = pc; | |
9126 | sal.explicit_pc = 1; | |
9127 | ||
6c5b2ebe PA |
9128 | struct linespec_sals lsal; |
9129 | lsal.sals = {sal}; | |
f00aae0f KS |
9130 | lsal.canonical = NULL; |
9131 | ||
6c5b2ebe | 9132 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
9133 | return; |
9134 | } | |
9135 | else | |
9136 | error (_("No default breakpoint address now.")); | |
c906108c | 9137 | } |
c906108c | 9138 | } |
f00aae0f KS |
9139 | |
9140 | /* Force almost all breakpoints to be in terms of the | |
9141 | current_source_symtab (which is decode_line_1's default). | |
9142 | This should produce the results we want almost all of the | |
9143 | time while leaving default_breakpoint_* alone. | |
9144 | ||
9145 | ObjC: However, don't match an Objective-C method name which | |
9146 | may have a '+' or '-' succeeded by a '['. */ | |
9147 | cursal = get_current_source_symtab_and_line (); | |
9148 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9149 | { |
a20714ff | 9150 | const char *spec = NULL; |
cc80f267 | 9151 | |
f00aae0f | 9152 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 9153 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 9154 | |
f00aae0f | 9155 | if (!cursal.symtab |
a20714ff PA |
9156 | || (spec != NULL |
9157 | && strchr ("+-", spec[0]) != NULL | |
9158 | && spec[1] != '[')) | |
f00aae0f | 9159 | { |
c2f4122d | 9160 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9161 | get_last_displayed_symtab (), |
9162 | get_last_displayed_line (), | |
9163 | canonical, NULL, NULL); | |
9164 | return; | |
9165 | } | |
c906108c | 9166 | } |
f00aae0f | 9167 | |
c2f4122d | 9168 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9169 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9170 | } |
c906108c | 9171 | |
c906108c | 9172 | |
c3f6f71d | 9173 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9174 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9175 | |
b9362cc7 | 9176 | static void |
6c5b2ebe | 9177 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9178 | { |
6c5b2ebe PA |
9179 | for (auto &sal : sals) |
9180 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9181 | } |
9182 | ||
7a697b8d SS |
9183 | /* Fast tracepoints may have restrictions on valid locations. For |
9184 | instance, a fast tracepoint using a jump instead of a trap will | |
9185 | likely have to overwrite more bytes than a trap would, and so can | |
9186 | only be placed where the instruction is longer than the jump, or a | |
9187 | multi-instruction sequence does not have a jump into the middle of | |
9188 | it, etc. */ | |
9189 | ||
9190 | static void | |
9191 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9192 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9193 | { |
6c5b2ebe | 9194 | for (const auto &sal : sals) |
7a697b8d | 9195 | { |
f8eba3c6 TT |
9196 | struct gdbarch *sarch; |
9197 | ||
6c5b2ebe | 9198 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9199 | /* We fall back to GDBARCH if there is no architecture |
9200 | associated with SAL. */ | |
9201 | if (sarch == NULL) | |
9202 | sarch = gdbarch; | |
281d762b TT |
9203 | std::string msg; |
9204 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) | |
53c3572a | 9205 | error (_("May not have a fast tracepoint at %s%s"), |
281d762b | 9206 | paddress (sarch, sal.pc), msg.c_str ()); |
7a697b8d SS |
9207 | } |
9208 | } | |
9209 | ||
018d34a4 VP |
9210 | /* Given TOK, a string specification of condition and thread, as |
9211 | accepted by the 'break' command, extract the condition | |
9212 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9213 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9214 | If no condition is found, *COND_STRING is set to NULL. |
9215 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9216 | |
9217 | static void | |
bbc13ae3 | 9218 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9219 | char **cond_string, int *thread, int *task, |
9220 | char **rest) | |
018d34a4 VP |
9221 | { |
9222 | *cond_string = NULL; | |
9223 | *thread = -1; | |
ed1d1739 KS |
9224 | *task = 0; |
9225 | *rest = NULL; | |
733d554a | 9226 | bool force = false; |
ed1d1739 | 9227 | |
018d34a4 VP |
9228 | while (tok && *tok) |
9229 | { | |
bbc13ae3 | 9230 | const char *end_tok; |
018d34a4 | 9231 | int toklen; |
bbc13ae3 KS |
9232 | const char *cond_start = NULL; |
9233 | const char *cond_end = NULL; | |
cc59ec59 | 9234 | |
f1735a53 | 9235 | tok = skip_spaces (tok); |
e7e0cddf SS |
9236 | |
9237 | if ((*tok == '"' || *tok == ',') && rest) | |
9238 | { | |
9239 | *rest = savestring (tok, strlen (tok)); | |
9240 | return; | |
9241 | } | |
9242 | ||
f1735a53 | 9243 | end_tok = skip_to_space (tok); |
d634f2de | 9244 | |
018d34a4 | 9245 | toklen = end_tok - tok; |
d634f2de | 9246 | |
018d34a4 VP |
9247 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9248 | { | |
9249 | tok = cond_start = end_tok + 1; | |
733d554a TBA |
9250 | try |
9251 | { | |
9252 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); | |
9253 | } | |
9254 | catch (const gdb_exception_error &) | |
9255 | { | |
9256 | if (!force) | |
9257 | throw; | |
9258 | else | |
9259 | tok = tok + strlen (tok); | |
9260 | } | |
018d34a4 | 9261 | cond_end = tok; |
d634f2de | 9262 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 | 9263 | } |
733d554a TBA |
9264 | else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0) |
9265 | { | |
9266 | tok = cond_start = end_tok + 1; | |
9267 | force = true; | |
9268 | } | |
018d34a4 VP |
9269 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
9270 | { | |
5d5658a1 PA |
9271 | const char *tmptok; |
9272 | struct thread_info *thr; | |
d634f2de | 9273 | |
018d34a4 | 9274 | tok = end_tok + 1; |
5d5658a1 | 9275 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9276 | if (tok == tmptok) |
9277 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9278 | *thread = thr->global_num; |
bbc13ae3 | 9279 | tok = tmptok; |
018d34a4 | 9280 | } |
4a306c9a JB |
9281 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9282 | { | |
9283 | char *tmptok; | |
9284 | ||
9285 | tok = end_tok + 1; | |
bbc13ae3 | 9286 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9287 | if (tok == tmptok) |
9288 | error (_("Junk after task keyword.")); | |
9289 | if (!valid_task_id (*task)) | |
b6199126 | 9290 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9291 | tok = tmptok; |
4a306c9a | 9292 | } |
e7e0cddf SS |
9293 | else if (rest) |
9294 | { | |
9295 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9296 | return; |
e7e0cddf | 9297 | } |
018d34a4 VP |
9298 | else |
9299 | error (_("Junk at end of arguments.")); | |
9300 | } | |
9301 | } | |
9302 | ||
b5fa468f TBA |
9303 | /* Call 'find_condition_and_thread' for each sal in SALS until a parse |
9304 | succeeds. The parsed values are written to COND_STRING, THREAD, | |
9305 | TASK, and REST. See the comment of 'find_condition_and_thread' | |
9306 | for the description of these parameters and INPUT. */ | |
9307 | ||
9308 | static void | |
9309 | find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals, | |
9310 | const char *input, char **cond_string, | |
9311 | int *thread, int *task, char **rest) | |
9312 | { | |
9313 | int num_failures = 0; | |
9314 | for (auto &sal : sals) | |
9315 | { | |
9316 | char *cond = nullptr; | |
9317 | int thread_id = 0; | |
9318 | int task_id = 0; | |
9319 | char *remaining = nullptr; | |
9320 | ||
9321 | /* Here we want to parse 'arg' to separate condition from thread | |
9322 | number. But because parsing happens in a context and the | |
9323 | contexts of sals might be different, try each until there is | |
9324 | success. Finding one successful parse is sufficient for our | |
9325 | goal. When setting the breakpoint we'll re-parse the | |
9326 | condition in the context of each sal. */ | |
9327 | try | |
9328 | { | |
9329 | find_condition_and_thread (input, sal.pc, &cond, &thread_id, | |
9330 | &task_id, &remaining); | |
9331 | *cond_string = cond; | |
9332 | *thread = thread_id; | |
9333 | *task = task_id; | |
9334 | *rest = remaining; | |
9335 | break; | |
9336 | } | |
9337 | catch (const gdb_exception_error &e) | |
9338 | { | |
9339 | num_failures++; | |
9340 | /* If no sal remains, do not continue. */ | |
9341 | if (num_failures == sals.size ()) | |
9342 | throw; | |
9343 | } | |
9344 | } | |
9345 | } | |
9346 | ||
0fb4aa4b PA |
9347 | /* Decode a static tracepoint marker spec. */ |
9348 | ||
6c5b2ebe | 9349 | static std::vector<symtab_and_line> |
f00aae0f | 9350 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b | 9351 | { |
f00aae0f KS |
9352 | const char *p = &(*arg_p)[3]; |
9353 | const char *endp; | |
0fb4aa4b | 9354 | |
f1735a53 | 9355 | p = skip_spaces (p); |
0fb4aa4b | 9356 | |
f1735a53 | 9357 | endp = skip_to_space (p); |
0fb4aa4b | 9358 | |
81b1e71c | 9359 | std::string marker_str (p, endp - p); |
0fb4aa4b | 9360 | |
5d9310c4 SM |
9361 | std::vector<static_tracepoint_marker> markers |
9362 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); | |
9363 | if (markers.empty ()) | |
81b1e71c TT |
9364 | error (_("No known static tracepoint marker named %s"), |
9365 | marker_str.c_str ()); | |
0fb4aa4b | 9366 | |
6c5b2ebe | 9367 | std::vector<symtab_and_line> sals; |
5d9310c4 | 9368 | sals.reserve (markers.size ()); |
0fb4aa4b | 9369 | |
5d9310c4 | 9370 | for (const static_tracepoint_marker &marker : markers) |
0fb4aa4b | 9371 | { |
5d9310c4 SM |
9372 | symtab_and_line sal = find_pc_line (marker.address, 0); |
9373 | sal.pc = marker.address; | |
6c5b2ebe | 9374 | sals.push_back (sal); |
5d9310c4 | 9375 | } |
0fb4aa4b | 9376 | |
0fb4aa4b PA |
9377 | *arg_p = endp; |
9378 | return sals; | |
9379 | } | |
9380 | ||
bac7c5cf GB |
9381 | /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and |
9382 | according to IS_TRACEPOINT. */ | |
9383 | ||
9384 | static const struct breakpoint_ops * | |
9385 | breakpoint_ops_for_event_location_type (enum event_location_type location_type, | |
9386 | bool is_tracepoint) | |
9387 | { | |
9388 | if (is_tracepoint) | |
9389 | { | |
9390 | if (location_type == PROBE_LOCATION) | |
9391 | return &tracepoint_probe_breakpoint_ops; | |
9392 | else | |
9393 | return &tracepoint_breakpoint_ops; | |
9394 | } | |
9395 | else | |
9396 | { | |
9397 | if (location_type == PROBE_LOCATION) | |
9398 | return &bkpt_probe_breakpoint_ops; | |
9399 | else | |
9400 | return &bkpt_breakpoint_ops; | |
9401 | } | |
9402 | } | |
9403 | ||
9404 | /* See breakpoint.h. */ | |
9405 | ||
9406 | const struct breakpoint_ops * | |
9407 | breakpoint_ops_for_event_location (const struct event_location *location, | |
9408 | bool is_tracepoint) | |
9409 | { | |
9410 | if (location != nullptr) | |
9411 | return breakpoint_ops_for_event_location_type | |
9412 | (event_location_type (location), is_tracepoint); | |
9413 | return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops; | |
9414 | } | |
9415 | ||
f00aae0f | 9416 | /* See breakpoint.h. */ |
0101ce28 | 9417 | |
8cdf0e15 VP |
9418 | int |
9419 | create_breakpoint (struct gdbarch *gdbarch, | |
626d2320 | 9420 | struct event_location *location, |
e1e01040 PA |
9421 | const char *cond_string, |
9422 | int thread, const char *extra_string, | |
f00aae0f | 9423 | int parse_extra, |
0fb4aa4b | 9424 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9425 | int ignore_count, |
9426 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9427 | const struct breakpoint_ops *ops, |
44f238bb PA |
9428 | int from_tty, int enabled, int internal, |
9429 | unsigned flags) | |
c3f6f71d | 9430 | { |
7efd8fc2 | 9431 | struct linespec_result canonical; |
0101ce28 | 9432 | int pending = 0; |
4a306c9a | 9433 | int task = 0; |
86b17b60 | 9434 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9435 | |
348d480f PA |
9436 | gdb_assert (ops != NULL); |
9437 | ||
f00aae0f KS |
9438 | /* If extra_string isn't useful, set it to NULL. */ |
9439 | if (extra_string != NULL && *extra_string == '\0') | |
9440 | extra_string = NULL; | |
9441 | ||
a70b8144 | 9442 | try |
b78a6381 | 9443 | { |
f00aae0f | 9444 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9445 | } |
230d2906 | 9446 | catch (const gdb_exception_error &e) |
0101ce28 | 9447 | { |
492d29ea PA |
9448 | /* If caller is interested in rc value from parse, set |
9449 | value. */ | |
9450 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9451 | { |
05ff989b AC |
9452 | /* If pending breakpoint support is turned off, throw |
9453 | error. */ | |
fa8d40ab JJ |
9454 | |
9455 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
eedc3f4f | 9456 | throw; |
723a2275 VP |
9457 | |
9458 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9459 | |
dda83cd7 | 9460 | /* If pending breakpoint support is auto query and the user |
05ff989b | 9461 | selects no, then simply return the error code. */ |
059fb39f | 9462 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9463 | && !nquery (_("Make %s pending on future shared library load? "), |
9464 | bptype_string (type_wanted))) | |
fd9b8c24 | 9465 | return 0; |
fa8d40ab | 9466 | |
05ff989b AC |
9467 | /* At this point, either the user was queried about setting |
9468 | a pending breakpoint and selected yes, or pending | |
9469 | breakpoint behavior is on and thus a pending breakpoint | |
9470 | is defaulted on behalf of the user. */ | |
f00aae0f | 9471 | pending = 1; |
0101ce28 | 9472 | } |
492d29ea | 9473 | else |
eedc3f4f | 9474 | throw; |
0101ce28 | 9475 | } |
492d29ea | 9476 | |
6c5b2ebe | 9477 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9478 | return 0; |
c3f6f71d | 9479 | |
c3f6f71d JM |
9480 | /* Resolve all line numbers to PC's and verify that the addresses |
9481 | are ok for the target. */ | |
0101ce28 | 9482 | if (!pending) |
f8eba3c6 | 9483 | { |
6c5b2ebe PA |
9484 | for (auto &lsal : canonical.lsals) |
9485 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9486 | } |
c3f6f71d | 9487 | |
7a697b8d | 9488 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9489 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9490 | { |
6c5b2ebe PA |
9491 | for (const auto &lsal : canonical.lsals) |
9492 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9493 | } |
7a697b8d | 9494 | |
c3f6f71d JM |
9495 | /* Verify that condition can be parsed, before setting any |
9496 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9497 | breakpoint. */ |
0101ce28 | 9498 | if (!pending) |
c3f6f71d | 9499 | { |
e1e01040 PA |
9500 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9501 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9502 | ||
f00aae0f | 9503 | if (parse_extra) |
dda83cd7 | 9504 | { |
0878d0fa | 9505 | char *rest; |
e1e01040 | 9506 | char *cond; |
52d361e1 | 9507 | |
6c5b2ebe | 9508 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9509 | |
b5fa468f TBA |
9510 | find_condition_and_thread_for_sals (lsal.sals, extra_string, |
9511 | &cond, &thread, &task, &rest); | |
e1e01040 PA |
9512 | cond_string_copy.reset (cond); |
9513 | extra_string_copy.reset (rest); | |
dda83cd7 | 9514 | } |
2f069f6f | 9515 | else |
dda83cd7 | 9516 | { |
f00aae0f KS |
9517 | if (type_wanted != bp_dprintf |
9518 | && extra_string != NULL && *extra_string != '\0') | |
9519 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9520 | |
9521 | /* Create a private copy of condition string. */ | |
9522 | if (cond_string) | |
e1e01040 | 9523 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9524 | /* Create a private copy of any extra string. */ |
9525 | if (extra_string) | |
e1e01040 | 9526 | extra_string_copy.reset (xstrdup (extra_string)); |
dda83cd7 | 9527 | } |
0fb4aa4b | 9528 | |
52d361e1 | 9529 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9530 | std::move (cond_string_copy), |
9531 | std::move (extra_string_copy), | |
9532 | type_wanted, | |
d9b3f62e PA |
9533 | tempflag ? disp_del : disp_donttouch, |
9534 | thread, task, ignore_count, ops, | |
44f238bb | 9535 | from_tty, enabled, internal, flags); |
c906108c | 9536 | } |
0101ce28 JJ |
9537 | else |
9538 | { | |
a5e364af | 9539 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9540 | |
a5e364af | 9541 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9542 | b->location = copy_event_location (location); |
bfccc43c | 9543 | |
f00aae0f KS |
9544 | if (parse_extra) |
9545 | b->cond_string = NULL; | |
e12c7713 MK |
9546 | else |
9547 | { | |
9548 | /* Create a private copy of condition string. */ | |
e1e01040 | 9549 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9550 | b->thread = thread; |
e12c7713 | 9551 | } |
f00aae0f KS |
9552 | |
9553 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9554 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9555 | b->ignore_count = ignore_count; |
0101ce28 | 9556 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9557 | b->condition_not_parsed = 1; |
41447f92 | 9558 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 | 9559 | if ((type_wanted != bp_breakpoint |
dda83cd7 | 9560 | && type_wanted != bp_hardware_breakpoint) || thread != -1) |
f8eba3c6 | 9561 | b->pspace = current_program_space; |
8bea4e01 | 9562 | |
b270e6f9 | 9563 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9564 | } |
9565 | ||
6c5b2ebe | 9566 | if (canonical.lsals.size () > 1) |
95a42b64 | 9567 | { |
3e43a32a MS |
9568 | warning (_("Multiple breakpoints were set.\nUse the " |
9569 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9570 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9571 | } |
9572 | ||
44702360 | 9573 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9574 | |
9575 | return 1; | |
c3f6f71d | 9576 | } |
c906108c | 9577 | |
348d480f | 9578 | /* Set a breakpoint. |
72b2ff0e VP |
9579 | ARG is a string describing breakpoint address, |
9580 | condition, and thread. | |
9581 | FLAG specifies if a breakpoint is hardware on, | |
9582 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9583 | and BP_TEMPFLAG. */ | |
348d480f | 9584 | |
98deb0da | 9585 | static void |
f2fc3015 | 9586 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9587 | { |
72b2ff0e | 9588 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9589 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9590 | ? bp_hardware_breakpoint | |
9591 | : bp_breakpoint); | |
f00aae0f | 9592 | |
ffc2605c | 9593 | event_location_up location = string_to_event_location (&arg, current_language); |
bac7c5cf GB |
9594 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
9595 | (location.get (), false /* is_tracepoint */); | |
c3f6f71d | 9596 | |
8cdf0e15 | 9597 | create_breakpoint (get_current_arch (), |
ffc2605c | 9598 | location.get (), |
f00aae0f | 9599 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9600 | tempflag, type_wanted, |
8cdf0e15 VP |
9601 | 0 /* Ignore count */, |
9602 | pending_break_support, | |
55aa24fb | 9603 | ops, |
8cdf0e15 | 9604 | from_tty, |
84f4c1fe | 9605 | 1 /* enabled */, |
44f238bb PA |
9606 | 0 /* internal */, |
9607 | 0); | |
c906108c SS |
9608 | } |
9609 | ||
c906108c SS |
9610 | /* Helper function for break_command_1 and disassemble_command. */ |
9611 | ||
9612 | void | |
fba45db2 | 9613 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9614 | { |
9615 | CORE_ADDR pc; | |
9616 | ||
9617 | if (sal->pc == 0 && sal->symtab != NULL) | |
9618 | { | |
9619 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9620 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9621 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9622 | sal->pc = pc; |
6a048695 | 9623 | |
4a64f543 | 9624 | /* If this SAL corresponds to a breakpoint inserted using a line |
dda83cd7 | 9625 | number, then skip the function prologue if necessary. */ |
6a048695 | 9626 | if (sal->explicit_line) |
059acae7 | 9627 | skip_prologue_sal (sal); |
c906108c SS |
9628 | } |
9629 | ||
9630 | if (sal->section == 0 && sal->symtab != NULL) | |
9631 | { | |
346d1dfe | 9632 | const struct blockvector *bv; |
3977b71f | 9633 | const struct block *b; |
c5aa993b | 9634 | struct symbol *sym; |
c906108c | 9635 | |
43f3e411 DE |
9636 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9637 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9638 | if (bv != NULL) |
9639 | { | |
7f0df278 | 9640 | sym = block_linkage_function (b); |
c906108c SS |
9641 | if (sym != NULL) |
9642 | { | |
eb822aa6 DE |
9643 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9644 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9645 | sym); | |
c906108c SS |
9646 | } |
9647 | else | |
9648 | { | |
4a64f543 | 9649 | /* It really is worthwhile to have the section, so we'll |
dda83cd7 SM |
9650 | just have to look harder. This case can be executed |
9651 | if we have line numbers but no functions (as can | |
9652 | happen in assembly source). */ | |
c906108c | 9653 | |
5ed8105e | 9654 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9655 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9656 | |
5ed8105e | 9657 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9658 | if (msym.minsym) |
efd66ac6 | 9659 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9660 | } |
9661 | } | |
9662 | } | |
9663 | } | |
9664 | ||
9665 | void | |
0b39b52e | 9666 | break_command (const char *arg, int from_tty) |
c906108c | 9667 | { |
db107f19 | 9668 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9669 | } |
9670 | ||
c906108c | 9671 | void |
0b39b52e | 9672 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9673 | { |
db107f19 | 9674 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9675 | } |
9676 | ||
c906108c | 9677 | static void |
0b39b52e | 9678 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9679 | { |
db107f19 | 9680 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9681 | } |
9682 | ||
9683 | static void | |
0b39b52e | 9684 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9685 | { |
db107f19 | 9686 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9687 | } |
9688 | ||
9689 | static void | |
ee7ddd71 | 9690 | stop_command (const char *arg, int from_tty) |
c906108c | 9691 | { |
a3f17187 | 9692 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9693 | Usage: stop in <function | address>\n\ |
a3f17187 | 9694 | stop at <line>\n")); |
c906108c SS |
9695 | } |
9696 | ||
9697 | static void | |
4495129a | 9698 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9699 | { |
9700 | int badInput = 0; | |
9701 | ||
cafb3438 | 9702 | if (arg == NULL) |
c906108c SS |
9703 | badInput = 1; |
9704 | else if (*arg != '*') | |
9705 | { | |
4495129a | 9706 | const char *argptr = arg; |
c906108c SS |
9707 | int hasColon = 0; |
9708 | ||
4a64f543 | 9709 | /* Look for a ':'. If this is a line number specification, then |
dda83cd7 SM |
9710 | say it is bad, otherwise, it should be an address or |
9711 | function/method name. */ | |
c906108c | 9712 | while (*argptr && !hasColon) |
c5aa993b JM |
9713 | { |
9714 | hasColon = (*argptr == ':'); | |
9715 | argptr++; | |
9716 | } | |
c906108c SS |
9717 | |
9718 | if (hasColon) | |
c5aa993b | 9719 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9720 | else |
c5aa993b | 9721 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9722 | } |
9723 | ||
9724 | if (badInput) | |
a3f17187 | 9725 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9726 | else |
db107f19 | 9727 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9728 | } |
9729 | ||
9730 | static void | |
4495129a | 9731 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9732 | { |
9733 | int badInput = 0; | |
9734 | ||
cafb3438 | 9735 | if (arg == NULL || *arg == '*') /* no line number */ |
c906108c SS |
9736 | badInput = 1; |
9737 | else | |
9738 | { | |
4495129a | 9739 | const char *argptr = arg; |
c906108c SS |
9740 | int hasColon = 0; |
9741 | ||
4a64f543 | 9742 | /* Look for a ':'. If there is a '::' then get out, otherwise |
dda83cd7 | 9743 | it is probably a line number. */ |
c906108c | 9744 | while (*argptr && !hasColon) |
c5aa993b JM |
9745 | { |
9746 | hasColon = (*argptr == ':'); | |
9747 | argptr++; | |
9748 | } | |
c906108c SS |
9749 | |
9750 | if (hasColon) | |
c5aa993b | 9751 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9752 | else |
c5aa993b | 9753 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9754 | } |
9755 | ||
9756 | if (badInput) | |
65e65158 | 9757 | printf_filtered (_("Usage: stop at LINE\n")); |
c906108c | 9758 | else |
db107f19 | 9759 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9760 | } |
9761 | ||
e7e0cddf SS |
9762 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9763 | with a prewired command list consisting of a single output command, | |
9764 | built from extra arguments supplied on the dprintf command | |
9765 | line. */ | |
9766 | ||
da821c7b | 9767 | static void |
0b39b52e | 9768 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9769 | { |
ffc2605c | 9770 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9771 | |
9772 | /* If non-NULL, ARG should have been advanced past the location; | |
9773 | the next character must be ','. */ | |
9774 | if (arg != NULL) | |
9775 | { | |
9776 | if (arg[0] != ',' || arg[1] == '\0') | |
9777 | error (_("Format string required")); | |
9778 | else | |
9779 | { | |
9780 | /* Skip the comma. */ | |
9781 | ++arg; | |
9782 | } | |
9783 | } | |
9784 | ||
e7e0cddf | 9785 | create_breakpoint (get_current_arch (), |
ffc2605c | 9786 | location.get (), |
f00aae0f | 9787 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9788 | 0, bp_dprintf, |
9789 | 0 /* Ignore count */, | |
9790 | pending_break_support, | |
9791 | &dprintf_breakpoint_ops, | |
9792 | from_tty, | |
9793 | 1 /* enabled */, | |
9794 | 0 /* internal */, | |
9795 | 0); | |
9796 | } | |
9797 | ||
d3ce09f5 | 9798 | static void |
0b39b52e | 9799 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9800 | { |
9801 | error (_("May only run agent-printf on the target")); | |
9802 | } | |
9803 | ||
f1310107 TJB |
9804 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9805 | ranged breakpoints. */ | |
9806 | ||
9807 | static int | |
9808 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
bd522513 | 9809 | const address_space *aspace, |
09ac7c10 TT |
9810 | CORE_ADDR bp_addr, |
9811 | const struct target_waitstatus *ws) | |
f1310107 | 9812 | { |
09ac7c10 | 9813 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9814 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9815 | return 0; |
9816 | ||
f1310107 TJB |
9817 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9818 | bl->length, aspace, bp_addr); | |
9819 | } | |
9820 | ||
9821 | /* Implement the "resources_needed" breakpoint_ops method for | |
9822 | ranged breakpoints. */ | |
9823 | ||
9824 | static int | |
9825 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9826 | { | |
9827 | return target_ranged_break_num_registers (); | |
9828 | } | |
9829 | ||
9830 | /* Implement the "print_it" breakpoint_ops method for | |
9831 | ranged breakpoints. */ | |
9832 | ||
9833 | static enum print_stop_action | |
348d480f | 9834 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9835 | { |
348d480f | 9836 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9837 | struct bp_location *bl = b->loc; |
79a45e25 | 9838 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9839 | |
9840 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9841 | ||
9842 | /* Ranged breakpoints have only one location. */ | |
9843 | gdb_assert (bl && bl->next == NULL); | |
9844 | ||
9845 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9846 | |
9847 | maybe_print_thread_hit_breakpoint (uiout); | |
9848 | ||
f1310107 | 9849 | if (b->disposition == disp_del) |
112e8700 | 9850 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9851 | else |
112e8700 SM |
9852 | uiout->text ("Ranged breakpoint "); |
9853 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9854 | { |
112e8700 | 9855 | uiout->field_string ("reason", |
f1310107 | 9856 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9857 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9858 | } |
381befee | 9859 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 9860 | uiout->text (", "); |
f1310107 TJB |
9861 | |
9862 | return PRINT_SRC_AND_LOC; | |
9863 | } | |
9864 | ||
9865 | /* Implement the "print_one" breakpoint_ops method for | |
9866 | ranged breakpoints. */ | |
9867 | ||
9868 | static void | |
9869 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9870 | struct bp_location **last_loc) | |
9871 | { | |
9872 | struct bp_location *bl = b->loc; | |
9873 | struct value_print_options opts; | |
79a45e25 | 9874 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9875 | |
9876 | /* Ranged breakpoints have only one location. */ | |
9877 | gdb_assert (bl && bl->next == NULL); | |
9878 | ||
9879 | get_user_print_options (&opts); | |
9880 | ||
9881 | if (opts.addressprint) | |
9882 | /* We don't print the address range here, it will be printed later | |
9883 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9884 | uiout->field_skip ("addr"); |
f1310107 TJB |
9885 | annotate_field (5); |
9886 | print_breakpoint_location (b, bl); | |
9887 | *last_loc = bl; | |
9888 | } | |
9889 | ||
9890 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9891 | ranged breakpoints. */ | |
9892 | ||
9893 | static void | |
9894 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9895 | struct ui_out *uiout) | |
9896 | { | |
9897 | CORE_ADDR address_start, address_end; | |
9898 | struct bp_location *bl = b->loc; | |
d7e74731 | 9899 | string_file stb; |
f1310107 TJB |
9900 | |
9901 | gdb_assert (bl); | |
9902 | ||
9903 | address_start = bl->address; | |
9904 | address_end = address_start + bl->length - 1; | |
9905 | ||
112e8700 | 9906 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9907 | stb.printf ("[%s, %s]", |
9908 | print_core_address (bl->gdbarch, address_start), | |
9909 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9910 | uiout->field_stream ("addr", stb); |
9911 | uiout->text ("\n"); | |
f1310107 TJB |
9912 | } |
9913 | ||
9914 | /* Implement the "print_mention" breakpoint_ops method for | |
9915 | ranged breakpoints. */ | |
9916 | ||
9917 | static void | |
9918 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9919 | { | |
9920 | struct bp_location *bl = b->loc; | |
79a45e25 | 9921 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9922 | |
9923 | gdb_assert (bl); | |
9924 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9925 | ||
2d33446d TT |
9926 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
9927 | b->number, paddress (bl->gdbarch, bl->address), | |
9928 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
f1310107 TJB |
9929 | } |
9930 | ||
9931 | /* Implement the "print_recreate" breakpoint_ops method for | |
9932 | ranged breakpoints. */ | |
9933 | ||
9934 | static void | |
9935 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9936 | { | |
f00aae0f | 9937 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9938 | event_location_to_string (b->location.get ()), |
9939 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9940 | print_recreate_thread (b, fp); |
f1310107 TJB |
9941 | } |
9942 | ||
9943 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9944 | ||
2060206e | 9945 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9946 | |
9947 | /* Find the address where the end of the breakpoint range should be | |
9948 | placed, given the SAL of the end of the range. This is so that if | |
9949 | the user provides a line number, the end of the range is set to the | |
9950 | last instruction of the given line. */ | |
9951 | ||
9952 | static CORE_ADDR | |
9953 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9954 | { | |
9955 | CORE_ADDR end; | |
9956 | ||
9957 | /* If the user provided a PC value, use it. Otherwise, | |
9958 | find the address of the end of the given location. */ | |
9959 | if (sal.explicit_pc) | |
9960 | end = sal.pc; | |
9961 | else | |
9962 | { | |
9963 | int ret; | |
9964 | CORE_ADDR start; | |
9965 | ||
9966 | ret = find_line_pc_range (sal, &start, &end); | |
9967 | if (!ret) | |
9968 | error (_("Could not find location of the end of the range.")); | |
9969 | ||
9970 | /* find_line_pc_range returns the start of the next line. */ | |
9971 | end--; | |
9972 | } | |
9973 | ||
9974 | return end; | |
9975 | } | |
9976 | ||
9977 | /* Implement the "break-range" CLI command. */ | |
9978 | ||
9979 | static void | |
0b39b52e | 9980 | break_range_command (const char *arg, int from_tty) |
f1310107 | 9981 | { |
f2fc3015 | 9982 | const char *arg_start; |
f1310107 TJB |
9983 | struct linespec_result canonical_start, canonical_end; |
9984 | int bp_count, can_use_bp, length; | |
9985 | CORE_ADDR end; | |
9986 | struct breakpoint *b; | |
f1310107 TJB |
9987 | |
9988 | /* We don't support software ranged breakpoints. */ | |
9989 | if (target_ranged_break_num_registers () < 0) | |
9990 | error (_("This target does not support hardware ranged breakpoints.")); | |
9991 | ||
9992 | bp_count = hw_breakpoint_used_count (); | |
9993 | bp_count += target_ranged_break_num_registers (); | |
9994 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9995 | bp_count, 0); | |
9996 | if (can_use_bp < 0) | |
9997 | error (_("Hardware breakpoints used exceeds limit.")); | |
9998 | ||
f8eba3c6 | 9999 | arg = skip_spaces (arg); |
f1310107 TJB |
10000 | if (arg == NULL || arg[0] == '\0') |
10001 | error(_("No address range specified.")); | |
10002 | ||
f8eba3c6 | 10003 | arg_start = arg; |
ffc2605c TT |
10004 | event_location_up start_location = string_to_event_location (&arg, |
10005 | current_language); | |
10006 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
10007 | |
10008 | if (arg[0] != ',') | |
10009 | error (_("Too few arguments.")); | |
6c5b2ebe | 10010 | else if (canonical_start.lsals.empty ()) |
f1310107 | 10011 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 10012 | |
6c5b2ebe | 10013 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 10014 | |
6c5b2ebe PA |
10015 | if (canonical_start.lsals.size () > 1 |
10016 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
10017 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10018 | ||
6c5b2ebe | 10019 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 10020 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
10021 | |
10022 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10023 | arg = skip_spaces (arg); |
f1310107 TJB |
10024 | |
10025 | /* Parse the end location. */ | |
10026 | ||
f1310107 TJB |
10027 | arg_start = arg; |
10028 | ||
f8eba3c6 | 10029 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10030 | parse_breakpoint_sals because we need to specify the start location's |
10031 | symtab and line as the default symtab and line for the end of the | |
10032 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10033 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
10034 | event_location_up end_location = string_to_event_location (&arg, |
10035 | current_language); | |
10036 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
10037 | sal_start.symtab, sal_start.line, |
10038 | &canonical_end, NULL, NULL); | |
10039 | ||
6c5b2ebe | 10040 | if (canonical_end.lsals.empty ()) |
f1310107 | 10041 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 10042 | |
6c5b2ebe PA |
10043 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
10044 | if (canonical_end.lsals.size () > 1 | |
10045 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
10046 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10047 | ||
6c5b2ebe | 10048 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
10049 | |
10050 | end = find_breakpoint_range_end (sal_end); | |
10051 | if (sal_start.pc > end) | |
177b42fe | 10052 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10053 | |
10054 | length = end - sal_start.pc + 1; | |
10055 | if (length < 0) | |
10056 | /* Length overflowed. */ | |
10057 | error (_("Address range too large.")); | |
10058 | else if (length == 1) | |
10059 | { | |
10060 | /* This range is simple enough to be handled by | |
10061 | the `hbreak' command. */ | |
81b1e71c | 10062 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
10063 | |
10064 | return; | |
10065 | } | |
10066 | ||
10067 | /* Now set up the breakpoint. */ | |
10068 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10069 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10070 | set_breakpoint_count (breakpoint_count + 1); |
10071 | b->number = breakpoint_count; | |
10072 | b->disposition = disp_donttouch; | |
d28cd78a TT |
10073 | b->location = std::move (start_location); |
10074 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
10075 | b->loc->length = length; |
10076 | ||
f1310107 | 10077 | mention (b); |
76727919 | 10078 | gdb::observers::breakpoint_created.notify (b); |
44702360 | 10079 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10080 | } |
10081 | ||
4a64f543 MS |
10082 | /* Return non-zero if EXP is verified as constant. Returned zero |
10083 | means EXP is variable. Also the constant detection may fail for | |
10084 | some constant expressions and in such case still falsely return | |
10085 | zero. */ | |
2e6e3d9c | 10086 | |
65d79d4b SDJ |
10087 | static int |
10088 | watchpoint_exp_is_const (const struct expression *exp) | |
10089 | { | |
10090 | int i = exp->nelts; | |
10091 | ||
10092 | while (i > 0) | |
10093 | { | |
10094 | int oplenp, argsp; | |
10095 | ||
10096 | /* We are only interested in the descriptor of each element. */ | |
10097 | operator_length (exp, i, &oplenp, &argsp); | |
10098 | i -= oplenp; | |
10099 | ||
10100 | switch (exp->elts[i].opcode) | |
10101 | { | |
10102 | case BINOP_ADD: | |
10103 | case BINOP_SUB: | |
10104 | case BINOP_MUL: | |
10105 | case BINOP_DIV: | |
10106 | case BINOP_REM: | |
10107 | case BINOP_MOD: | |
10108 | case BINOP_LSH: | |
10109 | case BINOP_RSH: | |
10110 | case BINOP_LOGICAL_AND: | |
10111 | case BINOP_LOGICAL_OR: | |
10112 | case BINOP_BITWISE_AND: | |
10113 | case BINOP_BITWISE_IOR: | |
10114 | case BINOP_BITWISE_XOR: | |
10115 | case BINOP_EQUAL: | |
10116 | case BINOP_NOTEQUAL: | |
10117 | case BINOP_LESS: | |
10118 | case BINOP_GTR: | |
10119 | case BINOP_LEQ: | |
10120 | case BINOP_GEQ: | |
10121 | case BINOP_REPEAT: | |
10122 | case BINOP_COMMA: | |
10123 | case BINOP_EXP: | |
10124 | case BINOP_MIN: | |
10125 | case BINOP_MAX: | |
10126 | case BINOP_INTDIV: | |
10127 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10128 | case TERNOP_COND: |
10129 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10130 | |
10131 | case OP_LONG: | |
edd079d9 | 10132 | case OP_FLOAT: |
65d79d4b SDJ |
10133 | case OP_LAST: |
10134 | case OP_COMPLEX: | |
10135 | case OP_STRING: | |
65d79d4b SDJ |
10136 | case OP_ARRAY: |
10137 | case OP_TYPE: | |
608b4967 TT |
10138 | case OP_TYPEOF: |
10139 | case OP_DECLTYPE: | |
6e72ca20 | 10140 | case OP_TYPEID: |
65d79d4b SDJ |
10141 | case OP_NAME: |
10142 | case OP_OBJC_NSSTRING: | |
10143 | ||
10144 | case UNOP_NEG: | |
10145 | case UNOP_LOGICAL_NOT: | |
10146 | case UNOP_COMPLEMENT: | |
10147 | case UNOP_ADDR: | |
10148 | case UNOP_HIGH: | |
aeaa2474 | 10149 | case UNOP_CAST: |
9eaf6705 TT |
10150 | |
10151 | case UNOP_CAST_TYPE: | |
10152 | case UNOP_REINTERPRET_CAST: | |
10153 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10154 | /* Unary, binary and ternary operators: We have to check |
10155 | their operands. If they are constant, then so is the | |
10156 | result of that operation. For instance, if A and B are | |
10157 | determined to be constants, then so is "A + B". | |
10158 | ||
10159 | UNOP_IND is one exception to the rule above, because the | |
10160 | value of *ADDR is not necessarily a constant, even when | |
10161 | ADDR is. */ | |
65d79d4b SDJ |
10162 | break; |
10163 | ||
10164 | case OP_VAR_VALUE: | |
10165 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10166 | |
65d79d4b | 10167 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10168 | possible that a buggy compiler could mark a variable as |
10169 | constant even when it is not, and TYPE_CONST would return | |
10170 | true in this case, while SYMBOL_CLASS wouldn't. | |
10171 | ||
10172 | We also have to check for function symbols because they | |
10173 | are always constant. */ | |
65d79d4b SDJ |
10174 | { |
10175 | struct symbol *s = exp->elts[i + 2].symbol; | |
10176 | ||
10177 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10178 | && SYMBOL_CLASS (s) != LOC_CONST | |
10179 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10180 | return 0; | |
10181 | break; | |
10182 | } | |
10183 | ||
10184 | /* The default action is to return 0 because we are using | |
10185 | the optimistic approach here: If we don't know something, | |
10186 | then it is not a constant. */ | |
10187 | default: | |
10188 | return 0; | |
10189 | } | |
10190 | } | |
10191 | ||
10192 | return 1; | |
10193 | } | |
10194 | ||
c1fc2657 | 10195 | /* Watchpoint destructor. */ |
3a5c3e22 | 10196 | |
c1fc2657 | 10197 | watchpoint::~watchpoint () |
3a5c3e22 | 10198 | { |
c1fc2657 SM |
10199 | xfree (this->exp_string); |
10200 | xfree (this->exp_string_reparse); | |
3a5c3e22 PA |
10201 | } |
10202 | ||
348d480f PA |
10203 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10204 | ||
10205 | static void | |
10206 | re_set_watchpoint (struct breakpoint *b) | |
10207 | { | |
3a5c3e22 PA |
10208 | struct watchpoint *w = (struct watchpoint *) b; |
10209 | ||
348d480f PA |
10210 | /* Watchpoint can be either on expression using entirely global |
10211 | variables, or it can be on local variables. | |
10212 | ||
10213 | Watchpoints of the first kind are never auto-deleted, and even | |
10214 | persist across program restarts. Since they can use variables | |
10215 | from shared libraries, we need to reparse expression as libraries | |
10216 | are loaded and unloaded. | |
10217 | ||
10218 | Watchpoints on local variables can also change meaning as result | |
10219 | of solib event. For example, if a watchpoint uses both a local | |
10220 | and a global variables in expression, it's a local watchpoint, | |
10221 | but unloading of a shared library will make the expression | |
10222 | invalid. This is not a very common use case, but we still | |
10223 | re-evaluate expression, to avoid surprises to the user. | |
10224 | ||
10225 | Note that for local watchpoints, we re-evaluate it only if | |
10226 | watchpoints frame id is still valid. If it's not, it means the | |
10227 | watchpoint is out of scope and will be deleted soon. In fact, | |
10228 | I'm not sure we'll ever be called in this case. | |
10229 | ||
10230 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10231 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10232 | |
3a5c3e22 PA |
10233 | Don't do anything about disabled watchpoints, since they will be |
10234 | reevaluated again when enabled. */ | |
10235 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10236 | } |
10237 | ||
77b06cd7 TJB |
10238 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10239 | ||
10240 | static int | |
10241 | insert_watchpoint (struct bp_location *bl) | |
10242 | { | |
3a5c3e22 PA |
10243 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10244 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10245 | |
10246 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10247 | w->cond_exp.get ()); |
77b06cd7 TJB |
10248 | } |
10249 | ||
10250 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10251 | ||
10252 | static int | |
73971819 | 10253 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10254 | { |
3a5c3e22 PA |
10255 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10256 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10257 | |
10258 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10259 | w->cond_exp.get ()); |
e09342b5 TJB |
10260 | } |
10261 | ||
e09342b5 | 10262 | static int |
348d480f | 10263 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
bd522513 | 10264 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 10265 | const struct target_waitstatus *ws) |
e09342b5 | 10266 | { |
348d480f | 10267 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10268 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10269 | |
348d480f PA |
10270 | /* Continuable hardware watchpoints are treated as non-existent if the |
10271 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10272 | some data address). Otherwise gdb won't stop on a break instruction | |
10273 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10274 | been defined. Also skip watchpoints which we know did not trigger | |
10275 | (did not match the data address). */ | |
10276 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10277 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10278 | return 0; |
9c06b0b4 | 10279 | |
348d480f | 10280 | return 1; |
9c06b0b4 TJB |
10281 | } |
10282 | ||
348d480f PA |
10283 | static void |
10284 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10285 | { |
348d480f | 10286 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10287 | |
348d480f | 10288 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10289 | } |
10290 | ||
10291 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10292 | hardware watchpoints. */ |
9c06b0b4 TJB |
10293 | |
10294 | static int | |
348d480f | 10295 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10296 | { |
3a5c3e22 PA |
10297 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10298 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10299 | |
10300 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10301 | } |
10302 | ||
10303 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10304 | hardware watchpoints. */ |
9c06b0b4 TJB |
10305 | |
10306 | static int | |
348d480f | 10307 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10308 | { |
efa80663 PA |
10309 | /* Read and access watchpoints only work with hardware support. */ |
10310 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10311 | } |
10312 | ||
9c06b0b4 | 10313 | static enum print_stop_action |
348d480f | 10314 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10315 | { |
348d480f | 10316 | struct breakpoint *b; |
348d480f | 10317 | enum print_stop_action result; |
3a5c3e22 | 10318 | struct watchpoint *w; |
79a45e25 | 10319 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10320 | |
10321 | gdb_assert (bs->bp_location_at != NULL); | |
10322 | ||
348d480f | 10323 | b = bs->breakpoint_at; |
3a5c3e22 | 10324 | w = (struct watchpoint *) b; |
348d480f | 10325 | |
f303dbd6 PA |
10326 | annotate_watchpoint (b->number); |
10327 | maybe_print_thread_hit_breakpoint (uiout); | |
10328 | ||
d7e74731 PA |
10329 | string_file stb; |
10330 | ||
76f9c9cf | 10331 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10332 | switch (b->type) |
10333 | { | |
348d480f | 10334 | case bp_watchpoint: |
9c06b0b4 | 10335 | case bp_hardware_watchpoint: |
112e8700 SM |
10336 | if (uiout->is_mi_like_p ()) |
10337 | uiout->field_string | |
10338 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10339 | mention (b); |
76f9c9cf | 10340 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10341 | uiout->text ("\nOld value = "); |
850645cf | 10342 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10343 | uiout->field_stream ("old", stb); |
10344 | uiout->text ("\nNew value = "); | |
850645cf | 10345 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10346 | uiout->field_stream ("new", stb); |
10347 | uiout->text ("\n"); | |
348d480f PA |
10348 | /* More than one watchpoint may have been triggered. */ |
10349 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10350 | break; |
10351 | ||
10352 | case bp_read_watchpoint: | |
112e8700 SM |
10353 | if (uiout->is_mi_like_p ()) |
10354 | uiout->field_string | |
10355 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10356 | mention (b); |
76f9c9cf | 10357 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10358 | uiout->text ("\nValue = "); |
850645cf | 10359 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10360 | uiout->field_stream ("value", stb); |
10361 | uiout->text ("\n"); | |
348d480f | 10362 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10363 | break; |
10364 | ||
10365 | case bp_access_watchpoint: | |
348d480f PA |
10366 | if (bs->old_val != NULL) |
10367 | { | |
112e8700 SM |
10368 | if (uiout->is_mi_like_p ()) |
10369 | uiout->field_string | |
10370 | ("reason", | |
348d480f PA |
10371 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10372 | mention (b); | |
76f9c9cf | 10373 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10374 | uiout->text ("\nOld value = "); |
850645cf | 10375 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10376 | uiout->field_stream ("old", stb); |
10377 | uiout->text ("\nNew value = "); | |
348d480f PA |
10378 | } |
10379 | else | |
10380 | { | |
10381 | mention (b); | |
112e8700 SM |
10382 | if (uiout->is_mi_like_p ()) |
10383 | uiout->field_string | |
10384 | ("reason", | |
348d480f | 10385 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10386 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10387 | uiout->text ("\nValue = "); |
348d480f | 10388 | } |
850645cf | 10389 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10390 | uiout->field_stream ("new", stb); |
10391 | uiout->text ("\n"); | |
348d480f | 10392 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10393 | break; |
10394 | default: | |
348d480f | 10395 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10396 | } |
10397 | ||
348d480f PA |
10398 | return result; |
10399 | } | |
10400 | ||
10401 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10402 | watchpoints. */ | |
10403 | ||
10404 | static void | |
10405 | print_mention_watchpoint (struct breakpoint *b) | |
10406 | { | |
3a5c3e22 | 10407 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10408 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10409 | const char *tuple_name; |
348d480f PA |
10410 | |
10411 | switch (b->type) | |
10412 | { | |
10413 | case bp_watchpoint: | |
112e8700 | 10414 | uiout->text ("Watchpoint "); |
46b9c129 | 10415 | tuple_name = "wpt"; |
348d480f PA |
10416 | break; |
10417 | case bp_hardware_watchpoint: | |
112e8700 | 10418 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10419 | tuple_name = "wpt"; |
348d480f PA |
10420 | break; |
10421 | case bp_read_watchpoint: | |
112e8700 | 10422 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10423 | tuple_name = "hw-rwpt"; |
348d480f PA |
10424 | break; |
10425 | case bp_access_watchpoint: | |
112e8700 | 10426 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10427 | tuple_name = "hw-awpt"; |
348d480f PA |
10428 | break; |
10429 | default: | |
10430 | internal_error (__FILE__, __LINE__, | |
10431 | _("Invalid hardware watchpoint type.")); | |
10432 | } | |
10433 | ||
46b9c129 | 10434 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10435 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10436 | uiout->text (": "); |
10437 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10438 | } |
10439 | ||
10440 | /* Implement the "print_recreate" breakpoint_ops method for | |
10441 | watchpoints. */ | |
10442 | ||
10443 | static void | |
10444 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10445 | { | |
3a5c3e22 PA |
10446 | struct watchpoint *w = (struct watchpoint *) b; |
10447 | ||
348d480f PA |
10448 | switch (b->type) |
10449 | { | |
10450 | case bp_watchpoint: | |
10451 | case bp_hardware_watchpoint: | |
10452 | fprintf_unfiltered (fp, "watch"); | |
10453 | break; | |
10454 | case bp_read_watchpoint: | |
10455 | fprintf_unfiltered (fp, "rwatch"); | |
10456 | break; | |
10457 | case bp_access_watchpoint: | |
10458 | fprintf_unfiltered (fp, "awatch"); | |
10459 | break; | |
10460 | default: | |
10461 | internal_error (__FILE__, __LINE__, | |
10462 | _("Invalid watchpoint type.")); | |
10463 | } | |
10464 | ||
3a5c3e22 | 10465 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10466 | print_recreate_thread (b, fp); |
348d480f PA |
10467 | } |
10468 | ||
427cd150 TT |
10469 | /* Implement the "explains_signal" breakpoint_ops method for |
10470 | watchpoints. */ | |
10471 | ||
47591c29 | 10472 | static int |
427cd150 TT |
10473 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10474 | { | |
10475 | /* A software watchpoint cannot cause a signal other than | |
10476 | GDB_SIGNAL_TRAP. */ | |
10477 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10478 | return 0; |
427cd150 | 10479 | |
47591c29 | 10480 | return 1; |
427cd150 TT |
10481 | } |
10482 | ||
348d480f PA |
10483 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10484 | ||
2060206e | 10485 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10486 | |
10487 | /* Implement the "insert" breakpoint_ops method for | |
10488 | masked hardware watchpoints. */ | |
10489 | ||
10490 | static int | |
10491 | insert_masked_watchpoint (struct bp_location *bl) | |
10492 | { | |
3a5c3e22 PA |
10493 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10494 | ||
10495 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10496 | bl->watchpoint_type); |
10497 | } | |
10498 | ||
10499 | /* Implement the "remove" breakpoint_ops method for | |
10500 | masked hardware watchpoints. */ | |
10501 | ||
10502 | static int | |
73971819 | 10503 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10504 | { |
3a5c3e22 PA |
10505 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10506 | ||
10507 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
dda83cd7 | 10508 | bl->watchpoint_type); |
348d480f PA |
10509 | } |
10510 | ||
10511 | /* Implement the "resources_needed" breakpoint_ops method for | |
10512 | masked hardware watchpoints. */ | |
10513 | ||
10514 | static int | |
10515 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10516 | { | |
3a5c3e22 PA |
10517 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10518 | ||
10519 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10520 | } |
10521 | ||
10522 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10523 | masked hardware watchpoints. */ | |
10524 | ||
10525 | static int | |
10526 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10527 | { | |
10528 | return 0; | |
10529 | } | |
10530 | ||
10531 | /* Implement the "print_it" breakpoint_ops method for | |
10532 | masked hardware watchpoints. */ | |
10533 | ||
10534 | static enum print_stop_action | |
10535 | print_it_masked_watchpoint (bpstat bs) | |
10536 | { | |
10537 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10538 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10539 | |
10540 | /* Masked watchpoints have only one location. */ | |
10541 | gdb_assert (b->loc && b->loc->next == NULL); | |
10542 | ||
f303dbd6 PA |
10543 | annotate_watchpoint (b->number); |
10544 | maybe_print_thread_hit_breakpoint (uiout); | |
10545 | ||
348d480f PA |
10546 | switch (b->type) |
10547 | { | |
10548 | case bp_hardware_watchpoint: | |
112e8700 SM |
10549 | if (uiout->is_mi_like_p ()) |
10550 | uiout->field_string | |
10551 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10552 | break; |
10553 | ||
10554 | case bp_read_watchpoint: | |
112e8700 SM |
10555 | if (uiout->is_mi_like_p ()) |
10556 | uiout->field_string | |
10557 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10558 | break; |
10559 | ||
10560 | case bp_access_watchpoint: | |
112e8700 SM |
10561 | if (uiout->is_mi_like_p ()) |
10562 | uiout->field_string | |
10563 | ("reason", | |
348d480f PA |
10564 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10565 | break; | |
10566 | default: | |
10567 | internal_error (__FILE__, __LINE__, | |
10568 | _("Invalid hardware watchpoint type.")); | |
10569 | } | |
10570 | ||
10571 | mention (b); | |
112e8700 | 10572 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10573 | Check the underlying instruction at PC for the memory\n\ |
10574 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10575 | uiout->text ("\n"); |
9c06b0b4 TJB |
10576 | |
10577 | /* More than one watchpoint may have been triggered. */ | |
10578 | return PRINT_UNKNOWN; | |
10579 | } | |
10580 | ||
10581 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10582 | masked hardware watchpoints. */ | |
10583 | ||
10584 | static void | |
10585 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10586 | struct ui_out *uiout) | |
10587 | { | |
3a5c3e22 PA |
10588 | struct watchpoint *w = (struct watchpoint *) b; |
10589 | ||
9c06b0b4 TJB |
10590 | /* Masked watchpoints have only one location. */ |
10591 | gdb_assert (b->loc && b->loc->next == NULL); | |
10592 | ||
112e8700 SM |
10593 | uiout->text ("\tmask "); |
10594 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10595 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10596 | } |
10597 | ||
10598 | /* Implement the "print_mention" breakpoint_ops method for | |
10599 | masked hardware watchpoints. */ | |
10600 | ||
10601 | static void | |
10602 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10603 | { | |
3a5c3e22 | 10604 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10605 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10606 | const char *tuple_name; |
9c06b0b4 TJB |
10607 | |
10608 | switch (b->type) | |
10609 | { | |
10610 | case bp_hardware_watchpoint: | |
112e8700 | 10611 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10612 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10613 | break; |
10614 | case bp_read_watchpoint: | |
112e8700 | 10615 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10616 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10617 | break; |
10618 | case bp_access_watchpoint: | |
112e8700 | 10619 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10620 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10621 | break; |
10622 | default: | |
10623 | internal_error (__FILE__, __LINE__, | |
10624 | _("Invalid hardware watchpoint type.")); | |
10625 | } | |
10626 | ||
46b9c129 | 10627 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10628 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10629 | uiout->text (": "); |
10630 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10631 | } |
10632 | ||
10633 | /* Implement the "print_recreate" breakpoint_ops method for | |
10634 | masked hardware watchpoints. */ | |
10635 | ||
10636 | static void | |
10637 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10638 | { | |
3a5c3e22 | 10639 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10640 | |
10641 | switch (b->type) | |
10642 | { | |
10643 | case bp_hardware_watchpoint: | |
10644 | fprintf_unfiltered (fp, "watch"); | |
10645 | break; | |
10646 | case bp_read_watchpoint: | |
10647 | fprintf_unfiltered (fp, "rwatch"); | |
10648 | break; | |
10649 | case bp_access_watchpoint: | |
10650 | fprintf_unfiltered (fp, "awatch"); | |
10651 | break; | |
10652 | default: | |
10653 | internal_error (__FILE__, __LINE__, | |
10654 | _("Invalid hardware watchpoint type.")); | |
10655 | } | |
10656 | ||
53807e9f TT |
10657 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, |
10658 | phex (w->hw_wp_mask, sizeof (CORE_ADDR))); | |
d9b3f62e | 10659 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10660 | } |
10661 | ||
10662 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10663 | ||
2060206e | 10664 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10665 | |
10666 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10667 | ||
f2478a7e | 10668 | static bool |
9c06b0b4 TJB |
10669 | is_masked_watchpoint (const struct breakpoint *b) |
10670 | { | |
10671 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10672 | } | |
10673 | ||
53a5351d | 10674 | /* accessflag: hw_write: watch write, |
dda83cd7 | 10675 | hw_read: watch read, |
53a5351d | 10676 | hw_access: watch access (read or write) */ |
c906108c | 10677 | static void |
bbc13ae3 | 10678 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10679 | int just_location, int internal) |
c906108c | 10680 | { |
c1fc2657 | 10681 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10682 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
b926417a | 10683 | struct value *result; |
bb9d5f81 | 10684 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10685 | const char *exp_start = NULL; |
10686 | const char *exp_end = NULL; | |
10687 | const char *tok, *end_tok; | |
9c06b0b4 | 10688 | int toklen = -1; |
bbc13ae3 KS |
10689 | const char *cond_start = NULL; |
10690 | const char *cond_end = NULL; | |
c906108c | 10691 | enum bptype bp_type; |
37e4754d | 10692 | int thread = -1; |
0cf6dd15 | 10693 | int pc = 0; |
9c06b0b4 TJB |
10694 | /* Flag to indicate whether we are going to use masks for |
10695 | the hardware watchpoint. */ | |
10696 | int use_mask = 0; | |
10697 | CORE_ADDR mask = 0; | |
c906108c | 10698 | |
37e4754d LM |
10699 | /* Make sure that we actually have parameters to parse. */ |
10700 | if (arg != NULL && arg[0] != '\0') | |
10701 | { | |
bbc13ae3 KS |
10702 | const char *value_start; |
10703 | ||
10704 | exp_end = arg + strlen (arg); | |
37e4754d | 10705 | |
9c06b0b4 TJB |
10706 | /* Look for "parameter value" pairs at the end |
10707 | of the arguments string. */ | |
bbc13ae3 | 10708 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10709 | { |
10710 | /* Skip whitespace at the end of the argument list. */ | |
10711 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10712 | tok--; | |
10713 | ||
10714 | /* Find the beginning of the last token. | |
10715 | This is the value of the parameter. */ | |
10716 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10717 | tok--; | |
10718 | value_start = tok + 1; | |
10719 | ||
10720 | /* Skip whitespace. */ | |
10721 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10722 | tok--; | |
10723 | ||
10724 | end_tok = tok; | |
10725 | ||
10726 | /* Find the beginning of the second to last token. | |
10727 | This is the parameter itself. */ | |
10728 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10729 | tok--; | |
10730 | tok++; | |
10731 | toklen = end_tok - tok + 1; | |
10732 | ||
61012eef | 10733 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10734 | { |
5d5658a1 | 10735 | struct thread_info *thr; |
9c06b0b4 TJB |
10736 | /* At this point we've found a "thread" token, which means |
10737 | the user is trying to set a watchpoint that triggers | |
10738 | only in a specific thread. */ | |
5d5658a1 | 10739 | const char *endp; |
37e4754d | 10740 | |
9c06b0b4 TJB |
10741 | if (thread != -1) |
10742 | error(_("You can specify only one thread.")); | |
37e4754d | 10743 | |
9c06b0b4 | 10744 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10745 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10746 | |
5d5658a1 | 10747 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10748 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10749 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10750 | |
5d5658a1 | 10751 | thread = thr->global_num; |
9c06b0b4 | 10752 | } |
61012eef | 10753 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10754 | { |
10755 | /* We've found a "mask" token, which means the user wants to | |
10756 | create a hardware watchpoint that is going to have the mask | |
10757 | facility. */ | |
10758 | struct value *mask_value, *mark; | |
37e4754d | 10759 | |
9c06b0b4 TJB |
10760 | if (use_mask) |
10761 | error(_("You can specify only one mask.")); | |
37e4754d | 10762 | |
9c06b0b4 | 10763 | use_mask = just_location = 1; |
37e4754d | 10764 | |
9c06b0b4 TJB |
10765 | mark = value_mark (); |
10766 | mask_value = parse_to_comma_and_eval (&value_start); | |
10767 | mask = value_as_address (mask_value); | |
10768 | value_free_to_mark (mark); | |
10769 | } | |
10770 | else | |
10771 | /* We didn't recognize what we found. We should stop here. */ | |
10772 | break; | |
37e4754d | 10773 | |
9c06b0b4 TJB |
10774 | /* Truncate the string and get rid of the "parameter value" pair before |
10775 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10776 | exp_end = tok; |
9c06b0b4 | 10777 | } |
37e4754d | 10778 | } |
bbc13ae3 KS |
10779 | else |
10780 | exp_end = arg; | |
37e4754d | 10781 | |
bbc13ae3 KS |
10782 | /* Parse the rest of the arguments. From here on out, everything |
10783 | is in terms of a newly allocated string instead of the original | |
10784 | ARG. */ | |
81b1e71c TT |
10785 | std::string expression (arg, exp_end - arg); |
10786 | exp_start = arg = expression.c_str (); | |
699bd4cf TT |
10787 | innermost_block_tracker tracker; |
10788 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); | |
c906108c | 10789 | exp_end = arg; |
fa8a61dc TT |
10790 | /* Remove trailing whitespace from the expression before saving it. |
10791 | This makes the eventual display of the expression string a bit | |
10792 | prettier. */ | |
10793 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10794 | --exp_end; | |
10795 | ||
65d79d4b | 10796 | /* Checking if the expression is not constant. */ |
4d01a485 | 10797 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10798 | { |
10799 | int len; | |
10800 | ||
10801 | len = exp_end - exp_start; | |
10802 | while (len > 0 && isspace (exp_start[len - 1])) | |
10803 | len--; | |
10804 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10805 | } | |
10806 | ||
699bd4cf | 10807 | exp_valid_block = tracker.block (); |
b926417a | 10808 | struct value *mark = value_mark (); |
850645cf TT |
10809 | struct value *val_as_value = nullptr; |
10810 | fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL, | |
10811 | just_location); | |
06a64a0b | 10812 | |
850645cf | 10813 | if (val_as_value != NULL && just_location) |
bb9d5f81 | 10814 | { |
850645cf TT |
10815 | saved_bitpos = value_bitpos (val_as_value); |
10816 | saved_bitsize = value_bitsize (val_as_value); | |
bb9d5f81 PP |
10817 | } |
10818 | ||
850645cf | 10819 | value_ref_ptr val; |
06a64a0b TT |
10820 | if (just_location) |
10821 | { | |
9c06b0b4 TJB |
10822 | int ret; |
10823 | ||
06a64a0b | 10824 | exp_valid_block = NULL; |
850645cf | 10825 | val = release_value (value_addr (result)); |
06a64a0b | 10826 | value_free_to_mark (mark); |
9c06b0b4 TJB |
10827 | |
10828 | if (use_mask) | |
10829 | { | |
850645cf | 10830 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
9c06b0b4 TJB |
10831 | mask); |
10832 | if (ret == -1) | |
10833 | error (_("This target does not support masked watchpoints.")); | |
10834 | else if (ret == -2) | |
10835 | error (_("Invalid mask or memory region.")); | |
10836 | } | |
06a64a0b | 10837 | } |
850645cf TT |
10838 | else if (val_as_value != NULL) |
10839 | val = release_value (val_as_value); | |
c906108c | 10840 | |
f1735a53 TT |
10841 | tok = skip_spaces (arg); |
10842 | end_tok = skip_to_space (tok); | |
c906108c SS |
10843 | |
10844 | toklen = end_tok - tok; | |
10845 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10846 | { | |
10847 | tok = cond_start = end_tok + 1; | |
699bd4cf TT |
10848 | innermost_block_tracker if_tracker; |
10849 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); | |
60e1c644 PA |
10850 | |
10851 | /* The watchpoint expression may not be local, but the condition | |
10852 | may still be. E.g.: `watch global if local > 0'. */ | |
699bd4cf | 10853 | cond_exp_valid_block = if_tracker.block (); |
60e1c644 | 10854 | |
c906108c SS |
10855 | cond_end = tok; |
10856 | } | |
10857 | if (*tok) | |
8a3fe4f8 | 10858 | error (_("Junk at end of command.")); |
c906108c | 10859 | |
441d7c93 PA |
10860 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10861 | ||
10862 | /* Save this because create_internal_breakpoint below invalidates | |
10863 | 'wp_frame'. */ | |
10864 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10865 | |
10866 | /* If the expression is "local", then set up a "watchpoint scope" | |
10867 | breakpoint at the point where we've left the scope of the watchpoint | |
10868 | expression. Create the scope breakpoint before the watchpoint, so | |
10869 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10870 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10871 | { |
441d7c93 PA |
10872 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10873 | ||
10874 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10875 | { |
441d7c93 PA |
10876 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10877 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10878 | ||
edb3359d | 10879 | scope_breakpoint |
441d7c93 | 10880 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10881 | bp_watchpoint_scope, |
10882 | &momentary_breakpoint_ops); | |
d983da9c | 10883 | |
441d7c93 PA |
10884 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10885 | wp_frame = NULL; | |
10886 | ||
edb3359d | 10887 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10888 | |
edb3359d DJ |
10889 | /* Automatically delete the breakpoint when it hits. */ |
10890 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10891 | |
edb3359d | 10892 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10893 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10894 | |
edb3359d | 10895 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10896 | scope_breakpoint->loc->gdbarch = caller_arch; |
10897 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10898 | scope_breakpoint->loc->address |
a6d9a66e UW |
10899 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10900 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10901 | scope_breakpoint->type); |
10902 | } | |
d983da9c DJ |
10903 | } |
10904 | ||
e8369a73 AB |
10905 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10906 | watchpoints here even if hardware watchpoints are turned off, a call | |
10907 | to update_watchpoint later in this function will cause the type to | |
10908 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10909 | ||
10910 | if (accessflag == hw_read) | |
10911 | bp_type = bp_read_watchpoint; | |
10912 | else if (accessflag == hw_access) | |
10913 | bp_type = bp_access_watchpoint; | |
10914 | else | |
10915 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10916 | |
b270e6f9 | 10917 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10918 | |
348d480f | 10919 | if (use_mask) |
b270e6f9 | 10920 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10921 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10922 | else |
b270e6f9 | 10923 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10924 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
10925 | w->thread = thread; |
10926 | w->disposition = disp_donttouch; | |
10927 | w->pspace = current_program_space; | |
b22e99fd | 10928 | w->exp = std::move (exp); |
3a5c3e22 PA |
10929 | w->exp_valid_block = exp_valid_block; |
10930 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10931 | if (just_location) |
10932 | { | |
850645cf TT |
10933 | struct type *t = value_type (val.get ()); |
10934 | CORE_ADDR addr = value_as_address (val.get ()); | |
06a64a0b | 10935 | |
43cc5389 | 10936 | w->exp_string_reparse |
f16a9f57 | 10937 | = current_language->watch_location_expression (t, addr).release (); |
06a64a0b | 10938 | |
3a5c3e22 | 10939 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 10940 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
10941 | } |
10942 | else | |
3a5c3e22 | 10943 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10944 | |
10945 | if (use_mask) | |
10946 | { | |
3a5c3e22 | 10947 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10948 | } |
10949 | else | |
10950 | { | |
3a5c3e22 | 10951 | w->val = val; |
bb9d5f81 PP |
10952 | w->val_bitpos = saved_bitpos; |
10953 | w->val_bitsize = saved_bitsize; | |
4c1d86d9 | 10954 | w->val_valid = true; |
9c06b0b4 | 10955 | } |
77b06cd7 | 10956 | |
c906108c | 10957 | if (cond_start) |
c1fc2657 | 10958 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 10959 | else |
c1fc2657 | 10960 | w->cond_string = 0; |
c5aa993b | 10961 | |
441d7c93 | 10962 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 10963 | { |
441d7c93 | 10964 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 10965 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 10966 | } |
c906108c | 10967 | else |
f6bc2008 | 10968 | { |
3a5c3e22 PA |
10969 | w->watchpoint_frame = null_frame_id; |
10970 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10971 | } |
c906108c | 10972 | |
d983da9c | 10973 | if (scope_breakpoint != NULL) |
c906108c | 10974 | { |
d983da9c DJ |
10975 | /* The scope breakpoint is related to the watchpoint. We will |
10976 | need to act on them together. */ | |
c1fc2657 | 10977 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 10978 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 10979 | } |
d983da9c | 10980 | |
06a64a0b TT |
10981 | if (!just_location) |
10982 | value_free_to_mark (mark); | |
2d134ed3 | 10983 | |
b270e6f9 TT |
10984 | /* Finally update the new watchpoint. This creates the locations |
10985 | that should be inserted. */ | |
10986 | update_watchpoint (w.get (), 1); | |
a9634178 | 10987 | |
b270e6f9 | 10988 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
10989 | } |
10990 | ||
e09342b5 | 10991 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10992 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10993 | |
c906108c | 10994 | static int |
a6535de1 | 10995 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
c906108c SS |
10996 | { |
10997 | int found_memory_cnt = 0; | |
10998 | ||
10999 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11000 | if (!can_use_hw_watchpoints) |
c906108c | 11001 | return 0; |
c5aa993b | 11002 | |
a6535de1 TT |
11003 | gdb_assert (!vals.empty ()); |
11004 | struct value *head = vals[0].get (); | |
11005 | ||
5c44784c JM |
11006 | /* Make sure that the value of the expression depends only upon |
11007 | memory contents, and values computed from them within GDB. If we | |
11008 | find any register references or function calls, we can't use a | |
11009 | hardware watchpoint. | |
11010 | ||
11011 | The idea here is that evaluating an expression generates a series | |
11012 | of values, one holding the value of every subexpression. (The | |
11013 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11014 | a*b+c.) GDB's values hold almost enough information to establish | |
11015 | the criteria given above --- they identify memory lvalues, | |
11016 | register lvalues, computed values, etcetera. So we can evaluate | |
11017 | the expression, and then scan the chain of values that leaves | |
11018 | behind to decide whether we can detect any possible change to the | |
11019 | expression's final value using only hardware watchpoints. | |
11020 | ||
11021 | However, I don't think that the values returned by inferior | |
11022 | function calls are special in any way. So this function may not | |
11023 | notice that an expression involving an inferior function call | |
11024 | can't be watched with hardware watchpoints. FIXME. */ | |
a6535de1 | 11025 | for (const value_ref_ptr &iter : vals) |
c906108c | 11026 | { |
a6535de1 TT |
11027 | struct value *v = iter.get (); |
11028 | ||
5c44784c | 11029 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11030 | { |
8464be76 DJ |
11031 | if (v != head && value_lazy (v)) |
11032 | /* A lazy memory lvalue in the chain is one that GDB never | |
11033 | needed to fetch; we either just used its address (e.g., | |
11034 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11035 | in `a,b'). This doesn't apply to HEAD; if that is | |
11036 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11037 | ; |
53a5351d | 11038 | else |
5c44784c JM |
11039 | { |
11040 | /* Ahh, memory we actually used! Check if we can cover | |
dda83cd7 | 11041 | it with hardware watchpoints. */ |
df407dfe | 11042 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11043 | |
11044 | /* We only watch structs and arrays if user asked for it | |
11045 | explicitly, never if they just happen to appear in a | |
11046 | middle of some value chain. */ | |
11047 | if (v == head | |
78134374 SM |
11048 | || (vtype->code () != TYPE_CODE_STRUCT |
11049 | && vtype->code () != TYPE_CODE_ARRAY)) | |
2e70b7b9 | 11050 | { |
42ae5230 | 11051 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11052 | int len; |
11053 | int num_regs; | |
11054 | ||
a9634178 | 11055 | len = (target_exact_watchpoints |
e09342b5 TJB |
11056 | && is_scalar_type_recursive (vtype))? |
11057 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11058 | |
e09342b5 TJB |
11059 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11060 | if (!num_regs) | |
2e70b7b9 MS |
11061 | return 0; |
11062 | else | |
e09342b5 | 11063 | found_memory_cnt += num_regs; |
2e70b7b9 | 11064 | } |
5c44784c | 11065 | } |
c5aa993b | 11066 | } |
5086187c AC |
11067 | else if (VALUE_LVAL (v) != not_lval |
11068 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11069 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11070 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11071 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11072 | } |
11073 | ||
11074 | /* The expression itself looks suitable for using a hardware | |
11075 | watchpoint, but give the target machine a chance to reject it. */ | |
11076 | return found_memory_cnt; | |
11077 | } | |
11078 | ||
8b93c638 | 11079 | void |
f2fc3015 | 11080 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 11081 | { |
84f4c1fe | 11082 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11083 | } |
11084 | ||
06a64a0b TT |
11085 | /* A helper function that looks for the "-location" argument and then |
11086 | calls watch_command_1. */ | |
11087 | ||
11088 | static void | |
0b39b52e | 11089 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b TT |
11090 | { |
11091 | int just_location = 0; | |
11092 | ||
11093 | if (arg | |
11094 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11095 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
cbba3ecd | 11096 | just_location = 1; |
06a64a0b | 11097 | |
84f4c1fe | 11098 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11099 | } |
8926118c | 11100 | |
c5aa993b | 11101 | static void |
0b39b52e | 11102 | watch_command (const char *arg, int from_tty) |
c906108c | 11103 | { |
06a64a0b | 11104 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11105 | } |
11106 | ||
8b93c638 | 11107 | void |
f2fc3015 | 11108 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 11109 | { |
84f4c1fe | 11110 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11111 | } |
8926118c | 11112 | |
c5aa993b | 11113 | static void |
0b39b52e | 11114 | rwatch_command (const char *arg, int from_tty) |
c906108c | 11115 | { |
06a64a0b | 11116 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11117 | } |
11118 | ||
8b93c638 | 11119 | void |
f2fc3015 | 11120 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 11121 | { |
84f4c1fe | 11122 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11123 | } |
8926118c | 11124 | |
c5aa993b | 11125 | static void |
0b39b52e | 11126 | awatch_command (const char *arg, int from_tty) |
c906108c | 11127 | { |
06a64a0b | 11128 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11129 | } |
c906108c | 11130 | \f |
c5aa993b | 11131 | |
cfc31633 PA |
11132 | /* Data for the FSM that manages the until(location)/advance commands |
11133 | in infcmd.c. Here because it uses the mechanisms of | |
11134 | breakpoints. */ | |
c906108c | 11135 | |
46e3ed7f | 11136 | struct until_break_fsm : public thread_fsm |
bfec99b2 | 11137 | { |
46e3ed7f | 11138 | /* The thread that was current when the command was executed. */ |
cfc31633 PA |
11139 | int thread; |
11140 | ||
df631783 PA |
11141 | /* The breakpoint set at the return address in the caller frame, |
11142 | plus breakpoints at all the destination locations. */ | |
11143 | std::vector<breakpoint_up> breakpoints; | |
cfc31633 | 11144 | |
46e3ed7f | 11145 | until_break_fsm (struct interp *cmd_interp, int thread, |
df631783 | 11146 | std::vector<breakpoint_up> &&breakpoints) |
46e3ed7f TT |
11147 | : thread_fsm (cmd_interp), |
11148 | thread (thread), | |
df631783 | 11149 | breakpoints (std::move (breakpoints)) |
46e3ed7f TT |
11150 | { |
11151 | } | |
cfc31633 | 11152 | |
46e3ed7f TT |
11153 | void clean_up (struct thread_info *thread) override; |
11154 | bool should_stop (struct thread_info *thread) override; | |
11155 | enum async_reply_reason do_async_reply_reason () override; | |
cfc31633 PA |
11156 | }; |
11157 | ||
cfc31633 PA |
11158 | /* Implementation of the 'should_stop' FSM method for the |
11159 | until(location)/advance commands. */ | |
11160 | ||
46e3ed7f TT |
11161 | bool |
11162 | until_break_fsm::should_stop (struct thread_info *tp) | |
cfc31633 | 11163 | { |
df631783 PA |
11164 | for (const breakpoint_up &bp : breakpoints) |
11165 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11166 | bp.get ()) != NULL) | |
11167 | { | |
11168 | set_finished (); | |
11169 | break; | |
11170 | } | |
cfc31633 | 11171 | |
46e3ed7f | 11172 | return true; |
cfc31633 PA |
11173 | } |
11174 | ||
11175 | /* Implementation of the 'clean_up' FSM method for the | |
11176 | until(location)/advance commands. */ | |
11177 | ||
46e3ed7f TT |
11178 | void |
11179 | until_break_fsm::clean_up (struct thread_info *) | |
43ff13b4 | 11180 | { |
cfc31633 | 11181 | /* Clean up our temporary breakpoints. */ |
df631783 | 11182 | breakpoints.clear (); |
46e3ed7f | 11183 | delete_longjmp_breakpoint (thread); |
cfc31633 PA |
11184 | } |
11185 | ||
11186 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11187 | until(location)/advance commands. */ | |
11188 | ||
46e3ed7f TT |
11189 | enum async_reply_reason |
11190 | until_break_fsm::do_async_reply_reason () | |
cfc31633 PA |
11191 | { |
11192 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11193 | } |
11194 | ||
c906108c | 11195 | void |
f2fc3015 | 11196 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 11197 | { |
8556afb4 PA |
11198 | struct frame_info *frame; |
11199 | struct gdbarch *frame_gdbarch; | |
11200 | struct frame_id stack_frame_id; | |
11201 | struct frame_id caller_frame_id; | |
186c406b TT |
11202 | int thread; |
11203 | struct thread_info *tp; | |
c906108c | 11204 | |
70509625 | 11205 | clear_proceed_status (0); |
c906108c SS |
11206 | |
11207 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11208 | this function. */ |
c5aa993b | 11209 | |
ffc2605c | 11210 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11211 | |
6c5b2ebe PA |
11212 | std::vector<symtab_and_line> sals |
11213 | = (last_displayed_sal_is_valid () | |
11214 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
11215 | get_last_displayed_symtab (), | |
11216 | get_last_displayed_line ()) | |
11217 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
cafb3438 | 11218 | NULL, NULL, 0)); |
c5aa993b | 11219 | |
df631783 | 11220 | if (sals.empty ()) |
8a3fe4f8 | 11221 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11222 | |
c906108c | 11223 | if (*arg) |
8a3fe4f8 | 11224 | error (_("Junk at end of arguments.")); |
c5aa993b | 11225 | |
186c406b | 11226 | tp = inferior_thread (); |
5d5658a1 | 11227 | thread = tp->global_num; |
186c406b | 11228 | |
8556afb4 PA |
11229 | /* Note linespec handling above invalidates the frame chain. |
11230 | Installing a breakpoint also invalidates the frame chain (as it | |
11231 | may need to switch threads), so do any frame handling before | |
11232 | that. */ | |
11233 | ||
11234 | frame = get_selected_frame (NULL); | |
11235 | frame_gdbarch = get_frame_arch (frame); | |
11236 | stack_frame_id = get_stack_frame_id (frame); | |
11237 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11238 | |
ae66c1fc EZ |
11239 | /* Keep within the current frame, or in frames called by the current |
11240 | one. */ | |
edb3359d | 11241 | |
df631783 | 11242 | std::vector<breakpoint_up> breakpoints; |
5419bdae TT |
11243 | |
11244 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; | |
11245 | ||
883bc8d1 | 11246 | if (frame_id_p (caller_frame_id)) |
c906108c | 11247 | { |
883bc8d1 | 11248 | struct symtab_and_line sal2; |
cfc31633 | 11249 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11250 | |
11251 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11252 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 | 11253 | caller_gdbarch = frame_unwind_caller_arch (frame); |
df631783 PA |
11254 | |
11255 | breakpoint_up caller_breakpoint | |
11256 | = set_momentary_breakpoint (caller_gdbarch, sal2, | |
11257 | caller_frame_id, bp_until); | |
11258 | breakpoints.emplace_back (std::move (caller_breakpoint)); | |
186c406b | 11259 | |
883bc8d1 | 11260 | set_longjmp_breakpoint (tp, caller_frame_id); |
5419bdae | 11261 | lj_deleter.emplace (thread); |
c906108c | 11262 | } |
c5aa993b | 11263 | |
c70a6932 JK |
11264 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11265 | frame = NULL; | |
11266 | ||
df631783 PA |
11267 | /* If the user told us to continue until a specified location, we |
11268 | don't specify a frame at which we need to stop. Otherwise, | |
11269 | specify the selected frame, because we want to stop only at the | |
11270 | very same frame. */ | |
11271 | frame_id stop_frame_id = anywhere ? null_frame_id : stack_frame_id; | |
11272 | ||
11273 | for (symtab_and_line &sal : sals) | |
11274 | { | |
11275 | resolve_sal_pc (&sal); | |
11276 | ||
11277 | breakpoint_up location_breakpoint | |
11278 | = set_momentary_breakpoint (frame_gdbarch, sal, | |
11279 | stop_frame_id, bp_until); | |
11280 | breakpoints.emplace_back (std::move (location_breakpoint)); | |
11281 | } | |
883bc8d1 | 11282 | |
46e3ed7f | 11283 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
df631783 | 11284 | std::move (breakpoints)); |
f107f563 | 11285 | |
5419bdae TT |
11286 | if (lj_deleter) |
11287 | lj_deleter->release (); | |
f107f563 | 11288 | |
cfc31633 | 11289 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11290 | } |
ae66c1fc | 11291 | |
c906108c SS |
11292 | /* This function attempts to parse an optional "if <cond>" clause |
11293 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11294 | |
c906108c SS |
11295 | Else, it returns a pointer to the condition string. (It does not |
11296 | attempt to evaluate the string against a particular block.) And, | |
11297 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11298 | if clause in the arg string. */ |
53a5351d | 11299 | |
63160a43 PA |
11300 | const char * |
11301 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11302 | { |
63160a43 | 11303 | const char *cond_string; |
c5aa993b JM |
11304 | |
11305 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11306 | return NULL; |
c5aa993b | 11307 | |
4a64f543 | 11308 | /* Skip the "if" keyword. */ |
c906108c | 11309 | (*arg) += 2; |
c5aa993b | 11310 | |
c906108c | 11311 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11312 | condition string. */ |
f1735a53 | 11313 | *arg = skip_spaces (*arg); |
c906108c | 11314 | cond_string = *arg; |
c5aa993b | 11315 | |
4a64f543 MS |
11316 | /* Assume that the condition occupies the remainder of the arg |
11317 | string. */ | |
c906108c | 11318 | (*arg) += strlen (cond_string); |
c5aa993b | 11319 | |
c906108c SS |
11320 | return cond_string; |
11321 | } | |
c5aa993b | 11322 | |
c906108c SS |
11323 | /* Commands to deal with catching events, such as signals, exceptions, |
11324 | process start/exit, etc. */ | |
c5aa993b JM |
11325 | |
11326 | typedef enum | |
11327 | { | |
44feb3ce TT |
11328 | catch_fork_temporary, catch_vfork_temporary, |
11329 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11330 | } |
11331 | catch_fork_kind; | |
11332 | ||
c906108c | 11333 | static void |
eb4c3f4a | 11334 | catch_fork_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11335 | struct cmd_list_element *command) |
c906108c | 11336 | { |
a6d9a66e | 11337 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11338 | const char *cond_string = NULL; |
44feb3ce | 11339 | catch_fork_kind fork_kind; |
44feb3ce TT |
11340 | |
11341 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
b650a282 SM |
11342 | bool temp = (fork_kind == catch_fork_temporary |
11343 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11344 | |
44feb3ce TT |
11345 | if (!arg) |
11346 | arg = ""; | |
f1735a53 | 11347 | arg = skip_spaces (arg); |
c5aa993b | 11348 | |
c906108c | 11349 | /* The allowed syntax is: |
c5aa993b JM |
11350 | catch [v]fork |
11351 | catch [v]fork if <cond> | |
11352 | ||
4a64f543 | 11353 | First, check if there's an if clause. */ |
c906108c | 11354 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11355 | |
c906108c | 11356 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11357 | error (_("Junk at end of arguments.")); |
c5aa993b | 11358 | |
c906108c | 11359 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11360 | and enable reporting of such events. */ |
c5aa993b JM |
11361 | switch (fork_kind) |
11362 | { | |
44feb3ce TT |
11363 | case catch_fork_temporary: |
11364 | case catch_fork_permanent: | |
b650a282 | 11365 | create_fork_vfork_event_catchpoint (gdbarch, temp, cond_string, |
dda83cd7 | 11366 | &catch_fork_breakpoint_ops); |
c906108c | 11367 | break; |
44feb3ce TT |
11368 | case catch_vfork_temporary: |
11369 | case catch_vfork_permanent: | |
b650a282 | 11370 | create_fork_vfork_event_catchpoint (gdbarch, temp, cond_string, |
dda83cd7 | 11371 | &catch_vfork_breakpoint_ops); |
c906108c | 11372 | break; |
c5aa993b | 11373 | default: |
8a3fe4f8 | 11374 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11375 | break; |
c5aa993b | 11376 | } |
c906108c SS |
11377 | } |
11378 | ||
11379 | static void | |
eb4c3f4a | 11380 | catch_exec_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11381 | struct cmd_list_element *command) |
c906108c | 11382 | { |
a6d9a66e | 11383 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11384 | const char *cond_string = NULL; |
b650a282 | 11385 | bool temp = get_cmd_context (command) == CATCH_TEMPORARY; |
44feb3ce TT |
11386 | |
11387 | if (!arg) | |
11388 | arg = ""; | |
f1735a53 | 11389 | arg = skip_spaces (arg); |
c906108c SS |
11390 | |
11391 | /* The allowed syntax is: | |
c5aa993b JM |
11392 | catch exec |
11393 | catch exec if <cond> | |
c906108c | 11394 | |
4a64f543 | 11395 | First, check if there's an if clause. */ |
c906108c SS |
11396 | cond_string = ep_parse_optional_if_clause (&arg); |
11397 | ||
11398 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11399 | error (_("Junk at end of arguments.")); |
c906108c | 11400 | |
b270e6f9 | 11401 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
b650a282 | 11402 | init_catchpoint (c.get (), gdbarch, temp, cond_string, |
b4d90040 PA |
11403 | &catch_exec_breakpoint_ops); |
11404 | c->exec_pathname = NULL; | |
11405 | ||
b270e6f9 | 11406 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11407 | } |
c5aa993b | 11408 | |
9ac4176b | 11409 | void |
28010a5d PA |
11410 | init_ada_exception_breakpoint (struct breakpoint *b, |
11411 | struct gdbarch *gdbarch, | |
11412 | struct symtab_and_line sal, | |
f2fc3015 | 11413 | const char *addr_string, |
c0a91b2b | 11414 | const struct breakpoint_ops *ops, |
28010a5d | 11415 | int tempflag, |
349774ef | 11416 | int enabled, |
28010a5d | 11417 | int from_tty) |
f7f9143b | 11418 | { |
f7f9143b JB |
11419 | if (from_tty) |
11420 | { | |
5af949e3 UW |
11421 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11422 | if (!loc_gdbarch) | |
11423 | loc_gdbarch = gdbarch; | |
11424 | ||
6c95b8df PA |
11425 | describe_other_breakpoints (loc_gdbarch, |
11426 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b | 11427 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
dda83cd7 SM |
11428 | version for exception catchpoints, because two catchpoints |
11429 | used for different exception names will use the same address. | |
11430 | In this case, a "breakpoint ... also set at..." warning is | |
11431 | unproductive. Besides, the warning phrasing is also a bit | |
11432 | inappropriate, we should use the word catchpoint, and tell | |
11433 | the user what type of catchpoint it is. The above is good | |
11434 | enough for now, though. */ | |
f7f9143b JB |
11435 | } |
11436 | ||
f06f1252 | 11437 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
f7f9143b | 11438 | |
349774ef | 11439 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11440 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11441 | b->location = string_to_event_location (&addr_string, |
11442 | language_def (language_ada)); | |
f7f9143b | 11443 | b->language = language_ada; |
f7f9143b JB |
11444 | } |
11445 | ||
c906108c SS |
11446 | \f |
11447 | ||
81b1e71c | 11448 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
11449 | |
11450 | static int | |
81b1e71c | 11451 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 11452 | { |
81b1e71c TT |
11453 | uintptr_t ua = (uintptr_t) a; |
11454 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 11455 | |
81b1e71c | 11456 | if (a->number < b->number) |
8a2c437b | 11457 | return -1; |
81b1e71c | 11458 | else if (a->number > b->number) |
8a2c437b TT |
11459 | return 1; |
11460 | ||
11461 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11462 | the number 0. */ | |
11463 | if (ua < ub) | |
11464 | return -1; | |
94b0e70d | 11465 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11466 | } |
11467 | ||
80f8a6eb | 11468 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11469 | |
11470 | static void | |
0b39b52e | 11471 | clear_command (const char *arg, int from_tty) |
c906108c | 11472 | { |
81b1e71c | 11473 | struct breakpoint *b; |
c906108c | 11474 | int default_match; |
c906108c | 11475 | |
6c5b2ebe PA |
11476 | std::vector<symtab_and_line> decoded_sals; |
11477 | symtab_and_line last_sal; | |
11478 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11479 | if (arg) |
11480 | { | |
6c5b2ebe PA |
11481 | decoded_sals |
11482 | = decode_line_with_current_source (arg, | |
11483 | (DECODE_LINE_FUNFIRSTLINE | |
11484 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11485 | default_match = 0; |
6c5b2ebe | 11486 | sals = decoded_sals; |
c906108c SS |
11487 | } |
11488 | else | |
11489 | { | |
1bfeeb0f JL |
11490 | /* Set sal's line, symtab, pc, and pspace to the values |
11491 | corresponding to the last call to print_frame_info. If the | |
11492 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11493 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11494 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11495 | error (_("No source file specified.")); |
c906108c | 11496 | |
c906108c | 11497 | default_match = 1; |
6c5b2ebe | 11498 | sals = last_sal; |
c906108c SS |
11499 | } |
11500 | ||
4a64f543 MS |
11501 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11502 | seems, because all existing breakpoints typically have both | |
11503 | file/line and pc set. So, if clear is given file/line, we can | |
11504 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11505 | |
11506 | We only support clearing given the address explicitly | |
11507 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11508 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11509 | due to optimization, all in one block. |
4a64f543 MS |
11510 | |
11511 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11512 | PC corresponding to the same file:line, the breakpoint won't |
11513 | be cleared. We probably can still clear the breakpoint, but | |
11514 | since the other PC value is never presented to user, user | |
11515 | can only find it by guessing, and it does not seem important | |
11516 | to support that. */ | |
11517 | ||
4a64f543 MS |
11518 | /* For each line spec given, delete bps which correspond to it. Do |
11519 | it in two passes, solely to preserve the current behavior that | |
11520 | from_tty is forced true if we delete more than one | |
11521 | breakpoint. */ | |
c906108c | 11522 | |
81b1e71c | 11523 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 11524 | for (const auto &sal : sals) |
c906108c | 11525 | { |
05cba821 JK |
11526 | const char *sal_fullname; |
11527 | ||
c906108c | 11528 | /* If exact pc given, clear bpts at that pc. |
dda83cd7 SM |
11529 | If line given (pc == 0), clear all bpts on specified line. |
11530 | If defaulting, clear all bpts on default line | |
11531 | or at default pc. | |
c5aa993b | 11532 | |
dda83cd7 | 11533 | defaulting sal.pc != 0 tests to do |
c5aa993b | 11534 | |
dda83cd7 SM |
11535 | 0 1 pc |
11536 | 1 1 pc _and_ line | |
11537 | 0 0 line | |
11538 | 1 0 <can't happen> */ | |
c906108c | 11539 | |
05cba821 JK |
11540 | sal_fullname = (sal.symtab == NULL |
11541 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11542 | |
4a64f543 | 11543 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11544 | ALL_BREAKPOINTS (b) |
c5aa993b | 11545 | { |
0d381245 | 11546 | int match = 0; |
4a64f543 | 11547 | /* Are we going to delete b? */ |
cc60f2e3 | 11548 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11549 | { |
11550 | struct bp_location *loc = b->loc; | |
11551 | for (; loc; loc = loc->next) | |
11552 | { | |
f8eba3c6 TT |
11553 | /* If the user specified file:line, don't allow a PC |
11554 | match. This matches historical gdb behavior. */ | |
11555 | int pc_match = (!sal.explicit_line | |
11556 | && sal.pc | |
11557 | && (loc->pspace == sal.pspace) | |
11558 | && (loc->address == sal.pc) | |
11559 | && (!section_is_overlay (loc->section) | |
11560 | || loc->section == sal.section)); | |
4aac40c8 TT |
11561 | int line_match = 0; |
11562 | ||
11563 | if ((default_match || sal.explicit_line) | |
2f202fde | 11564 | && loc->symtab != NULL |
05cba821 | 11565 | && sal_fullname != NULL |
4aac40c8 | 11566 | && sal.pspace == loc->pspace |
05cba821 JK |
11567 | && loc->line_number == sal.line |
11568 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11569 | sal_fullname) == 0) | |
11570 | line_match = 1; | |
4aac40c8 | 11571 | |
0d381245 VP |
11572 | if (pc_match || line_match) |
11573 | { | |
11574 | match = 1; | |
11575 | break; | |
11576 | } | |
11577 | } | |
11578 | } | |
11579 | ||
11580 | if (match) | |
81b1e71c | 11581 | found.push_back (b); |
c906108c | 11582 | } |
80f8a6eb | 11583 | } |
8a2c437b | 11584 | |
80f8a6eb | 11585 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 11586 | if (found.empty ()) |
80f8a6eb MS |
11587 | { |
11588 | if (arg) | |
8a3fe4f8 | 11589 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11590 | else |
8a3fe4f8 | 11591 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11592 | } |
c906108c | 11593 | |
8a2c437b | 11594 | /* Remove duplicates from the vec. */ |
81b1e71c | 11595 | std::sort (found.begin (), found.end (), |
b926417a | 11596 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11597 | { |
b926417a | 11598 | return compare_breakpoints (bp_a, bp_b) < 0; |
81b1e71c TT |
11599 | }); |
11600 | found.erase (std::unique (found.begin (), found.end (), | |
b926417a | 11601 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11602 | { |
b926417a | 11603 | return compare_breakpoints (bp_a, bp_b) == 0; |
81b1e71c TT |
11604 | }), |
11605 | found.end ()); | |
8a2c437b | 11606 | |
81b1e71c | 11607 | if (found.size () > 1) |
4a64f543 | 11608 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11609 | if (from_tty) |
a3f17187 | 11610 | { |
81b1e71c | 11611 | if (found.size () == 1) |
a3f17187 AC |
11612 | printf_unfiltered (_("Deleted breakpoint ")); |
11613 | else | |
11614 | printf_unfiltered (_("Deleted breakpoints ")); | |
11615 | } | |
d6e956e5 | 11616 | |
81b1e71c | 11617 | for (breakpoint *iter : found) |
80f8a6eb | 11618 | { |
c5aa993b | 11619 | if (from_tty) |
81b1e71c TT |
11620 | printf_unfiltered ("%d ", iter->number); |
11621 | delete_breakpoint (iter); | |
c906108c | 11622 | } |
80f8a6eb MS |
11623 | if (from_tty) |
11624 | putchar_unfiltered ('\n'); | |
c906108c SS |
11625 | } |
11626 | \f | |
11627 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11628 | all breakpoints that are marked for deletion, whether hit or not. | |
11629 | This is called after any breakpoint is hit, or after errors. */ | |
11630 | ||
11631 | void | |
fba45db2 | 11632 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11633 | { |
35df4500 | 11634 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11635 | |
11636 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11637 | if (bs->breakpoint_at |
11638 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11639 | && bs->stop) |
f431efe5 | 11640 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11641 | |
35df4500 | 11642 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11643 | { |
b5de0fa7 | 11644 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11645 | delete_breakpoint (b); |
11646 | } | |
c906108c SS |
11647 | } |
11648 | ||
4a64f543 | 11649 | /* A comparison function for bp_location AP and BP being interfaced to |
39ef2f62 | 11650 | std::sort. Sort elements primarily by their ADDRESS (no matter what |
cb1e4e32 PA |
11651 | bl_address_is_meaningful says), secondarily by ordering first |
11652 | permanent elements and terciarily just ensuring the array is sorted | |
39ef2f62 | 11653 | stable way despite std::sort being an unstable algorithm. */ |
876fa593 JK |
11654 | |
11655 | static int | |
39ef2f62 | 11656 | bp_location_is_less_than (const bp_location *a, const bp_location *b) |
876fa593 | 11657 | { |
876fa593 | 11658 | if (a->address != b->address) |
39ef2f62 | 11659 | return a->address < b->address; |
876fa593 | 11660 | |
dea2aa5f LM |
11661 | /* Sort locations at the same address by their pspace number, keeping |
11662 | locations of the same inferior (in a multi-inferior environment) | |
11663 | grouped. */ | |
11664 | ||
11665 | if (a->pspace->num != b->pspace->num) | |
39ef2f62 | 11666 | return a->pspace->num < b->pspace->num; |
dea2aa5f | 11667 | |
876fa593 | 11668 | /* Sort permanent breakpoints first. */ |
1a853c52 | 11669 | if (a->permanent != b->permanent) |
39ef2f62 | 11670 | return a->permanent > b->permanent; |
876fa593 | 11671 | |
7f32a4d5 PA |
11672 | /* Sort by type in order to make duplicate determination easier. |
11673 | See update_global_location_list. This is kept in sync with | |
11674 | breakpoint_locations_match. */ | |
11675 | if (a->loc_type < b->loc_type) | |
11676 | return true; | |
11677 | ||
11678 | /* Likewise, for range-breakpoints, sort by length. */ | |
11679 | if (a->loc_type == bp_loc_hardware_breakpoint | |
11680 | && b->loc_type == bp_loc_hardware_breakpoint | |
11681 | && a->length < b->length) | |
11682 | return true; | |
11683 | ||
c56a97f9 JK |
11684 | /* Make the internal GDB representation stable across GDB runs |
11685 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11686 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11687 | |
11688 | if (a->owner->number != b->owner->number) | |
39ef2f62 | 11689 | return a->owner->number < b->owner->number; |
876fa593 | 11690 | |
39ef2f62 | 11691 | return a < b; |
876fa593 JK |
11692 | } |
11693 | ||
f5336ca5 PA |
11694 | /* Set bp_locations_placed_address_before_address_max and |
11695 | bp_locations_shadow_len_after_address_max according to the current | |
11696 | content of the bp_locations array. */ | |
f7545552 TT |
11697 | |
11698 | static void | |
f5336ca5 | 11699 | bp_locations_target_extensions_update (void) |
f7545552 | 11700 | { |
876fa593 JK |
11701 | struct bp_location *bl, **blp_tmp; |
11702 | ||
f5336ca5 PA |
11703 | bp_locations_placed_address_before_address_max = 0; |
11704 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11705 | |
11706 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11707 | { | |
11708 | CORE_ADDR start, end, addr; | |
11709 | ||
11710 | if (!bp_location_has_shadow (bl)) | |
11711 | continue; | |
11712 | ||
11713 | start = bl->target_info.placed_address; | |
11714 | end = start + bl->target_info.shadow_len; | |
11715 | ||
11716 | gdb_assert (bl->address >= start); | |
11717 | addr = bl->address - start; | |
f5336ca5 PA |
11718 | if (addr > bp_locations_placed_address_before_address_max) |
11719 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11720 | |
11721 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11722 | ||
11723 | gdb_assert (bl->address < end); | |
11724 | addr = end - bl->address; | |
f5336ca5 PA |
11725 | if (addr > bp_locations_shadow_len_after_address_max) |
11726 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11727 | } |
f7545552 TT |
11728 | } |
11729 | ||
1e4d1764 YQ |
11730 | /* Download tracepoint locations if they haven't been. */ |
11731 | ||
11732 | static void | |
11733 | download_tracepoint_locations (void) | |
11734 | { | |
7ed2c994 | 11735 | struct breakpoint *b; |
dd2e65cc | 11736 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11737 | |
5ed8105e | 11738 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11739 | |
7ed2c994 | 11740 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11741 | { |
7ed2c994 | 11742 | struct bp_location *bl; |
1e4d1764 | 11743 | struct tracepoint *t; |
f2a8bc8a | 11744 | int bp_location_downloaded = 0; |
1e4d1764 | 11745 | |
7ed2c994 | 11746 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11747 | ? !may_insert_fast_tracepoints |
11748 | : !may_insert_tracepoints)) | |
11749 | continue; | |
11750 | ||
dd2e65cc YQ |
11751 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11752 | { | |
11753 | if (target_can_download_tracepoint ()) | |
11754 | can_download_tracepoint = TRIBOOL_TRUE; | |
11755 | else | |
11756 | can_download_tracepoint = TRIBOOL_FALSE; | |
11757 | } | |
11758 | ||
11759 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11760 | break; | |
11761 | ||
7ed2c994 YQ |
11762 | for (bl = b->loc; bl; bl = bl->next) |
11763 | { | |
11764 | /* In tracepoint, locations are _never_ duplicated, so | |
11765 | should_be_inserted is equivalent to | |
11766 | unduplicated_should_be_inserted. */ | |
11767 | if (!should_be_inserted (bl) || bl->inserted) | |
11768 | continue; | |
1e4d1764 | 11769 | |
7ed2c994 | 11770 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11771 | |
7ed2c994 | 11772 | target_download_tracepoint (bl); |
1e4d1764 | 11773 | |
7ed2c994 | 11774 | bl->inserted = 1; |
f2a8bc8a | 11775 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11776 | } |
11777 | t = (struct tracepoint *) b; | |
11778 | t->number_on_target = b->number; | |
f2a8bc8a | 11779 | if (bp_location_downloaded) |
76727919 | 11780 | gdb::observers::breakpoint_modified.notify (b); |
1e4d1764 | 11781 | } |
1e4d1764 YQ |
11782 | } |
11783 | ||
934709f0 PW |
11784 | /* Swap the insertion/duplication state between two locations. */ |
11785 | ||
11786 | static void | |
11787 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11788 | { | |
11789 | const int left_inserted = left->inserted; | |
11790 | const int left_duplicate = left->duplicate; | |
b775012e | 11791 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11792 | const struct bp_target_info left_target_info = left->target_info; |
11793 | ||
1e4d1764 YQ |
11794 | /* Locations of tracepoints can never be duplicated. */ |
11795 | if (is_tracepoint (left->owner)) | |
11796 | gdb_assert (!left->duplicate); | |
11797 | if (is_tracepoint (right->owner)) | |
11798 | gdb_assert (!right->duplicate); | |
11799 | ||
934709f0 PW |
11800 | left->inserted = right->inserted; |
11801 | left->duplicate = right->duplicate; | |
b775012e | 11802 | left->needs_update = right->needs_update; |
934709f0 PW |
11803 | left->target_info = right->target_info; |
11804 | right->inserted = left_inserted; | |
11805 | right->duplicate = left_duplicate; | |
b775012e | 11806 | right->needs_update = left_needs_update; |
934709f0 PW |
11807 | right->target_info = left_target_info; |
11808 | } | |
11809 | ||
b775012e LM |
11810 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11811 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11812 | conditions on the target's side. Such conditions need to be updated on | |
11813 | the target. */ | |
11814 | ||
11815 | static void | |
11816 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11817 | { | |
11818 | struct bp_location **locp = NULL, **loc2p; | |
11819 | struct bp_location *loc; | |
11820 | CORE_ADDR address = 0; | |
11821 | int pspace_num; | |
11822 | ||
11823 | address = bl->address; | |
11824 | pspace_num = bl->pspace->num; | |
11825 | ||
11826 | /* This is only meaningful if the target is | |
11827 | evaluating conditions and if the user has | |
11828 | opted for condition evaluation on the target's | |
11829 | side. */ | |
11830 | if (gdb_evaluates_breakpoint_condition_p () | |
11831 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11832 | return; | |
11833 | ||
11834 | /* Flag all breakpoint locations with this address and | |
11835 | the same program space as the location | |
11836 | as "its condition has changed". We need to | |
11837 | update the conditions on the target's side. */ | |
11838 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11839 | { | |
11840 | loc = *loc2p; | |
11841 | ||
11842 | if (!is_breakpoint (loc->owner) | |
11843 | || pspace_num != loc->pspace->num) | |
11844 | continue; | |
11845 | ||
11846 | /* Flag the location appropriately. We use a different state to | |
11847 | let everyone know that we already updated the set of locations | |
11848 | with addr bl->address and program space bl->pspace. This is so | |
11849 | we don't have to keep calling these functions just to mark locations | |
11850 | that have already been marked. */ | |
11851 | loc->condition_changed = condition_updated; | |
11852 | ||
11853 | /* Free the agent expression bytecode as well. We will compute | |
11854 | it later on. */ | |
833177a4 | 11855 | loc->cond_bytecode.reset (); |
b775012e LM |
11856 | } |
11857 | } | |
7f32a4d5 | 11858 | |
44702360 PA |
11859 | /* Called whether new breakpoints are created, or existing breakpoints |
11860 | deleted, to update the global location list and recompute which | |
11861 | locations are duplicate of which. | |
b775012e | 11862 | |
04086b45 PA |
11863 | The INSERT_MODE flag determines whether locations may not, may, or |
11864 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11865 | info. */ | |
b60e7edf | 11866 | |
0d381245 | 11867 | static void |
44702360 | 11868 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11869 | { |
74960c60 | 11870 | struct breakpoint *b; |
876fa593 | 11871 | struct bp_location **locp, *loc; |
b775012e LM |
11872 | /* Last breakpoint location address that was marked for update. */ |
11873 | CORE_ADDR last_addr = 0; | |
11874 | /* Last breakpoint location program space that was marked for update. */ | |
11875 | int last_pspace_num = -1; | |
f7545552 | 11876 | |
2d134ed3 PA |
11877 | /* Used in the duplicates detection below. When iterating over all |
11878 | bp_locations, points to the first bp_location of a given address. | |
11879 | Breakpoints and watchpoints of different types are never | |
11880 | duplicates of each other. Keep one pointer for each type of | |
11881 | breakpoint/watchpoint, so we only need to loop over all locations | |
11882 | once. */ | |
11883 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11884 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11885 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11886 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11887 | |
f5336ca5 PA |
11888 | /* Saved former bp_locations array which we compare against the newly |
11889 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
81b1e71c | 11890 | struct bp_location **old_locp; |
f5336ca5 | 11891 | unsigned old_locations_count; |
81b1e71c | 11892 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
876fa593 | 11893 | |
f5336ca5 PA |
11894 | old_locations_count = bp_locations_count; |
11895 | bp_locations = NULL; | |
11896 | bp_locations_count = 0; | |
0d381245 | 11897 | |
74960c60 | 11898 | ALL_BREAKPOINTS (b) |
876fa593 | 11899 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 11900 | bp_locations_count++; |
876fa593 | 11901 | |
f5336ca5 PA |
11902 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
11903 | locp = bp_locations; | |
876fa593 JK |
11904 | ALL_BREAKPOINTS (b) |
11905 | for (loc = b->loc; loc; loc = loc->next) | |
11906 | *locp++ = loc; | |
7f32a4d5 PA |
11907 | |
11908 | /* See if we need to "upgrade" a software breakpoint to a hardware | |
11909 | breakpoint. Do this before deciding whether locations are | |
11910 | duplicates. Also do this before sorting because sorting order | |
11911 | depends on location type. */ | |
11912 | for (locp = bp_locations; | |
11913 | locp < bp_locations + bp_locations_count; | |
11914 | locp++) | |
11915 | { | |
11916 | loc = *locp; | |
11917 | if (!loc->inserted && should_be_inserted (loc)) | |
11918 | handle_automatic_hardware_breakpoints (loc); | |
11919 | } | |
11920 | ||
39ef2f62 CB |
11921 | std::sort (bp_locations, bp_locations + bp_locations_count, |
11922 | bp_location_is_less_than); | |
876fa593 | 11923 | |
f5336ca5 | 11924 | bp_locations_target_extensions_update (); |
74960c60 | 11925 | |
4a64f543 MS |
11926 | /* Identify bp_location instances that are no longer present in the |
11927 | new list, and therefore should be freed. Note that it's not | |
11928 | necessary that those locations should be removed from inferior -- | |
11929 | if there's another location at the same address (previously | |
11930 | marked as duplicate), we don't need to remove/insert the | |
11931 | location. | |
876fa593 | 11932 | |
4a64f543 MS |
11933 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11934 | and former bp_location array state respectively. */ | |
876fa593 | 11935 | |
f5336ca5 | 11936 | locp = bp_locations; |
81b1e71c TT |
11937 | for (old_locp = old_locations.get (); |
11938 | old_locp < old_locations.get () + old_locations_count; | |
876fa593 | 11939 | old_locp++) |
74960c60 | 11940 | { |
876fa593 | 11941 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11942 | struct bp_location **loc2p; |
876fa593 | 11943 | |
e5dd4106 | 11944 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11945 | not, we have to free it. */ |
c7d46a38 | 11946 | int found_object = 0; |
20874c92 VP |
11947 | /* Tells if the location should remain inserted in the target. */ |
11948 | int keep_in_target = 0; | |
11949 | int removed = 0; | |
876fa593 | 11950 | |
4a64f543 MS |
11951 | /* Skip LOCP entries which will definitely never be needed. |
11952 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 11953 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 11954 | && (*locp)->address < old_loc->address) |
876fa593 | 11955 | locp++; |
c7d46a38 PA |
11956 | |
11957 | for (loc2p = locp; | |
f5336ca5 | 11958 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
11959 | && (*loc2p)->address == old_loc->address); |
11960 | loc2p++) | |
11961 | { | |
b775012e LM |
11962 | /* Check if this is a new/duplicated location or a duplicated |
11963 | location that had its condition modified. If so, we want to send | |
11964 | its condition to the target if evaluation of conditions is taking | |
11965 | place there. */ | |
11966 | if ((*loc2p)->condition_changed == condition_modified | |
11967 | && (last_addr != old_loc->address | |
11968 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11969 | { |
b775012e LM |
11970 | force_breakpoint_reinsertion (*loc2p); |
11971 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11972 | } |
b775012e LM |
11973 | |
11974 | if (*loc2p == old_loc) | |
11975 | found_object = 1; | |
c7d46a38 | 11976 | } |
74960c60 | 11977 | |
b775012e LM |
11978 | /* We have already handled this address, update it so that we don't |
11979 | have to go through updates again. */ | |
11980 | last_addr = old_loc->address; | |
11981 | ||
11982 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11983 | if (!found_object) | |
11984 | force_breakpoint_reinsertion (old_loc); | |
11985 | ||
4a64f543 MS |
11986 | /* If this location is no longer present, and inserted, look if |
11987 | there's maybe a new location at the same address. If so, | |
11988 | mark that one inserted, and don't remove this one. This is | |
11989 | needed so that we don't have a time window where a breakpoint | |
11990 | at certain location is not inserted. */ | |
74960c60 | 11991 | |
876fa593 | 11992 | if (old_loc->inserted) |
0d381245 | 11993 | { |
4a64f543 MS |
11994 | /* If the location is inserted now, we might have to remove |
11995 | it. */ | |
74960c60 | 11996 | |
876fa593 | 11997 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11998 | { |
4a64f543 MS |
11999 | /* The location is still present in the location list, |
12000 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12001 | keep_in_target = 1; |
74960c60 VP |
12002 | } |
12003 | else | |
12004 | { | |
b775012e LM |
12005 | /* This location still exists, but it won't be kept in the |
12006 | target since it may have been disabled. We proceed to | |
12007 | remove its target-side condition. */ | |
12008 | ||
4a64f543 MS |
12009 | /* The location is either no longer present, or got |
12010 | disabled. See if there's another location at the | |
12011 | same address, in which case we don't need to remove | |
12012 | this one from the target. */ | |
876fa593 | 12013 | |
2bdf28a0 | 12014 | /* OLD_LOC comes from existing struct breakpoint. */ |
cb1e4e32 | 12015 | if (bl_address_is_meaningful (old_loc)) |
876fa593 | 12016 | { |
876fa593 | 12017 | for (loc2p = locp; |
f5336ca5 | 12018 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 12019 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
12020 | loc2p++) |
12021 | { | |
12022 | struct bp_location *loc2 = *loc2p; | |
12023 | ||
7f32a4d5 PA |
12024 | if (loc2 == old_loc) |
12025 | continue; | |
12026 | ||
2d134ed3 | 12027 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12028 | { |
85d721b8 PA |
12029 | /* Read watchpoint locations are switched to |
12030 | access watchpoints, if the former are not | |
12031 | supported, but the latter are. */ | |
12032 | if (is_hardware_watchpoint (old_loc->owner)) | |
12033 | { | |
12034 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12035 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12036 | } | |
12037 | ||
934709f0 PW |
12038 | /* loc2 is a duplicated location. We need to check |
12039 | if it should be inserted in case it will be | |
12040 | unduplicated. */ | |
7f32a4d5 | 12041 | if (unduplicated_should_be_inserted (loc2)) |
c7d46a38 | 12042 | { |
934709f0 | 12043 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12044 | keep_in_target = 1; |
12045 | break; | |
12046 | } | |
876fa593 JK |
12047 | } |
12048 | } | |
12049 | } | |
74960c60 VP |
12050 | } |
12051 | ||
20874c92 VP |
12052 | if (!keep_in_target) |
12053 | { | |
834c0d03 | 12054 | if (remove_breakpoint (old_loc)) |
20874c92 | 12055 | { |
4a64f543 MS |
12056 | /* This is just about all we can do. We could keep |
12057 | this location on the global list, and try to | |
12058 | remove it next time, but there's no particular | |
12059 | reason why we will succeed next time. | |
20874c92 | 12060 | |
4a64f543 MS |
12061 | Note that at this point, old_loc->owner is still |
12062 | valid, as delete_breakpoint frees the breakpoint | |
12063 | only after calling us. */ | |
3e43a32a MS |
12064 | printf_filtered (_("warning: Error removing " |
12065 | "breakpoint %d\n"), | |
876fa593 | 12066 | old_loc->owner->number); |
20874c92 VP |
12067 | } |
12068 | removed = 1; | |
12069 | } | |
0d381245 | 12070 | } |
74960c60 VP |
12071 | |
12072 | if (!found_object) | |
1c5cfe86 | 12073 | { |
fbea99ea | 12074 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12075 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12076 | { |
db82e815 PA |
12077 | /* This location was removed from the target. In |
12078 | non-stop mode, a race condition is possible where | |
12079 | we've removed a breakpoint, but stop events for that | |
12080 | breakpoint are already queued and will arrive later. | |
12081 | We apply an heuristic to be able to distinguish such | |
12082 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12083 | breakpoint location for a bit, and will retire it | |
12084 | after we see some number of events. The theory here | |
12085 | is that reporting of events should, "on the average", | |
12086 | be fair, so after a while we'll see events from all | |
12087 | threads that have anything of interest, and no longer | |
12088 | need to keep this breakpoint location around. We | |
12089 | don't hold locations forever so to reduce chances of | |
12090 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12091 | SIGTRAP. | |
12092 | ||
12093 | The heuristic failing can be disastrous on | |
12094 | decr_pc_after_break targets. | |
12095 | ||
12096 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12097 | if we fail to recognize a late breakpoint SIGTRAP, | |
12098 | because events_till_retirement has reached 0 too | |
12099 | soon, we'll fail to do the PC adjustment, and report | |
12100 | a random SIGTRAP to the user. When the user resumes | |
12101 | the inferior, it will most likely immediately crash | |
2dec564e | 12102 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12103 | corrupted, because of being resumed e.g., in the |
12104 | middle of a multi-byte instruction, or skipped a | |
12105 | one-byte instruction. This was actually seen happen | |
12106 | on native x86-linux, and should be less rare on | |
12107 | targets that do not support new thread events, like | |
12108 | remote, due to the heuristic depending on | |
12109 | thread_count. | |
12110 | ||
12111 | Mistaking a random SIGTRAP for a breakpoint trap | |
12112 | causes similar symptoms (PC adjustment applied when | |
12113 | it shouldn't), but then again, playing with SIGTRAPs | |
12114 | behind the debugger's back is asking for trouble. | |
12115 | ||
12116 | Since hardware watchpoint traps are always | |
12117 | distinguishable from other traps, so we don't need to | |
12118 | apply keep hardware watchpoint moribund locations | |
12119 | around. We simply always ignore hardware watchpoint | |
12120 | traps we can no longer explain. */ | |
12121 | ||
5b6d1e4f PA |
12122 | process_stratum_target *proc_target = nullptr; |
12123 | for (inferior *inf : all_inferiors ()) | |
12124 | if (inf->pspace == old_loc->pspace) | |
12125 | { | |
12126 | proc_target = inf->process_target (); | |
12127 | break; | |
12128 | } | |
12129 | if (proc_target != nullptr) | |
12130 | old_loc->events_till_retirement | |
12131 | = 3 * (thread_count (proc_target) + 1); | |
12132 | else | |
12133 | old_loc->events_till_retirement = 1; | |
876fa593 | 12134 | old_loc->owner = NULL; |
20874c92 | 12135 | |
1123588c | 12136 | moribund_locations.push_back (old_loc); |
1c5cfe86 PA |
12137 | } |
12138 | else | |
f431efe5 PA |
12139 | { |
12140 | old_loc->owner = NULL; | |
12141 | decref_bp_location (&old_loc); | |
12142 | } | |
20874c92 | 12143 | } |
74960c60 | 12144 | } |
1c5cfe86 | 12145 | |
348d480f PA |
12146 | /* Rescan breakpoints at the same address and section, marking the |
12147 | first one as "first" and any others as "duplicates". This is so | |
12148 | that the bpt instruction is only inserted once. If we have a | |
12149 | permanent breakpoint at the same place as BPT, make that one the | |
12150 | official one, and the rest as duplicates. Permanent breakpoints | |
12151 | are sorted first for the same address. | |
12152 | ||
12153 | Do the same for hardware watchpoints, but also considering the | |
12154 | watchpoint's type (regular/access/read) and length. */ | |
12155 | ||
12156 | bp_loc_first = NULL; | |
12157 | wp_loc_first = NULL; | |
12158 | awp_loc_first = NULL; | |
12159 | rwp_loc_first = NULL; | |
12160 | ALL_BP_LOCATIONS (loc, locp) | |
12161 | { | |
12162 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12163 | non-NULL. */ | |
348d480f | 12164 | struct bp_location **loc_first_p; |
d3fbdd86 | 12165 | b = loc->owner; |
348d480f | 12166 | |
6f380991 | 12167 | if (!unduplicated_should_be_inserted (loc) |
cb1e4e32 | 12168 | || !bl_address_is_meaningful (loc) |
1e4d1764 YQ |
12169 | /* Don't detect duplicate for tracepoint locations because they are |
12170 | never duplicated. See the comments in field `duplicate' of | |
12171 | `struct bp_location'. */ | |
348d480f | 12172 | || is_tracepoint (b)) |
b775012e LM |
12173 | { |
12174 | /* Clear the condition modification flag. */ | |
12175 | loc->condition_changed = condition_unchanged; | |
12176 | continue; | |
12177 | } | |
348d480f | 12178 | |
348d480f PA |
12179 | if (b->type == bp_hardware_watchpoint) |
12180 | loc_first_p = &wp_loc_first; | |
12181 | else if (b->type == bp_read_watchpoint) | |
12182 | loc_first_p = &rwp_loc_first; | |
12183 | else if (b->type == bp_access_watchpoint) | |
12184 | loc_first_p = &awp_loc_first; | |
12185 | else | |
12186 | loc_first_p = &bp_loc_first; | |
12187 | ||
12188 | if (*loc_first_p == NULL | |
12189 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12190 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12191 | { | |
12192 | *loc_first_p = loc; | |
12193 | loc->duplicate = 0; | |
b775012e LM |
12194 | |
12195 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12196 | { | |
12197 | loc->needs_update = 1; | |
12198 | /* Clear the condition modification flag. */ | |
12199 | loc->condition_changed = condition_unchanged; | |
12200 | } | |
348d480f PA |
12201 | continue; |
12202 | } | |
12203 | ||
934709f0 PW |
12204 | |
12205 | /* This and the above ensure the invariant that the first location | |
12206 | is not duplicated, and is the inserted one. | |
12207 | All following are marked as duplicated, and are not inserted. */ | |
12208 | if (loc->inserted) | |
12209 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12210 | loc->duplicate = 1; |
12211 | ||
b775012e LM |
12212 | /* Clear the condition modification flag. */ |
12213 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12214 | } |
12215 | ||
a25a5a45 | 12216 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12217 | { |
04086b45 | 12218 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12219 | insert_breakpoint_locations (); |
12220 | else | |
12221 | { | |
44702360 PA |
12222 | /* Even though the caller told us to not insert new |
12223 | locations, we may still need to update conditions on the | |
12224 | target's side of breakpoints that were already inserted | |
12225 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12226 | only update conditions for locations that are marked |
12227 | "needs_update". */ | |
12228 | update_inserted_breakpoint_locations (); | |
12229 | } | |
12230 | } | |
348d480f | 12231 | |
04086b45 | 12232 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 12233 | download_tracepoint_locations (); |
348d480f PA |
12234 | } |
12235 | ||
12236 | void | |
12237 | breakpoint_retire_moribund (void) | |
12238 | { | |
1123588c TT |
12239 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
12240 | { | |
12241 | struct bp_location *loc = moribund_locations[ix]; | |
12242 | if (--(loc->events_till_retirement) == 0) | |
12243 | { | |
12244 | decref_bp_location (&loc); | |
12245 | unordered_remove (moribund_locations, ix); | |
12246 | --ix; | |
12247 | } | |
12248 | } | |
348d480f PA |
12249 | } |
12250 | ||
12251 | static void | |
44702360 | 12252 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12253 | { |
348d480f | 12254 | |
a70b8144 | 12255 | try |
492d29ea PA |
12256 | { |
12257 | update_global_location_list (insert_mode); | |
12258 | } | |
230d2906 | 12259 | catch (const gdb_exception_error &e) |
492d29ea PA |
12260 | { |
12261 | } | |
348d480f PA |
12262 | } |
12263 | ||
12264 | /* Clear BKP from a BPS. */ | |
12265 | ||
12266 | static void | |
12267 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12268 | { | |
12269 | bpstat bs; | |
12270 | ||
12271 | for (bs = bps; bs; bs = bs->next) | |
12272 | if (bs->breakpoint_at == bpt) | |
12273 | { | |
12274 | bs->breakpoint_at = NULL; | |
12275 | bs->old_val = NULL; | |
12276 | /* bs->commands will be freed later. */ | |
12277 | } | |
12278 | } | |
12279 | ||
12280 | /* Callback for iterate_over_threads. */ | |
12281 | static int | |
12282 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12283 | { | |
9a3c8263 | 12284 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12285 | |
12286 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12287 | return 0; | |
12288 | } | |
12289 | ||
12290 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12291 | callbacks. */ | |
12292 | ||
12293 | static void | |
12294 | say_where (struct breakpoint *b) | |
12295 | { | |
12296 | struct value_print_options opts; | |
12297 | ||
12298 | get_user_print_options (&opts); | |
12299 | ||
12300 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12301 | single string. */ | |
12302 | if (b->loc == NULL) | |
12303 | { | |
f00aae0f KS |
12304 | /* For pending locations, the output differs slightly based |
12305 | on b->extra_string. If this is non-NULL, it contains either | |
12306 | a condition or dprintf arguments. */ | |
12307 | if (b->extra_string == NULL) | |
12308 | { | |
12309 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12310 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12311 | } |
12312 | else if (b->type == bp_dprintf) | |
12313 | { | |
12314 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12315 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12316 | b->extra_string); |
12317 | } | |
12318 | else | |
12319 | { | |
12320 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12321 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12322 | b->extra_string); |
12323 | } | |
348d480f PA |
12324 | } |
12325 | else | |
12326 | { | |
2f202fde | 12327 | if (opts.addressprint || b->loc->symtab == NULL) |
6a831f06 PA |
12328 | printf_filtered (" at %ps", |
12329 | styled_string (address_style.style (), | |
12330 | paddress (b->loc->gdbarch, | |
12331 | b->loc->address))); | |
2f202fde | 12332 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12333 | { |
12334 | /* If there is a single location, we can print the location | |
12335 | more nicely. */ | |
12336 | if (b->loc->next == NULL) | |
0bb296cb | 12337 | { |
6a831f06 PA |
12338 | const char *filename |
12339 | = symtab_to_filename_for_display (b->loc->symtab); | |
12340 | printf_filtered (": file %ps, line %d.", | |
12341 | styled_string (file_name_style.style (), | |
12342 | filename), | |
0bb296cb TT |
12343 | b->loc->line_number); |
12344 | } | |
f8eba3c6 TT |
12345 | else |
12346 | /* This is not ideal, but each location may have a | |
12347 | different file name, and this at least reflects the | |
12348 | real situation somewhat. */ | |
f00aae0f | 12349 | printf_filtered (": %s.", |
d28cd78a | 12350 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12351 | } |
348d480f PA |
12352 | |
12353 | if (b->loc->next) | |
12354 | { | |
12355 | struct bp_location *loc = b->loc; | |
12356 | int n = 0; | |
12357 | for (; loc; loc = loc->next) | |
12358 | ++n; | |
12359 | printf_filtered (" (%d locations)", n); | |
12360 | } | |
12361 | } | |
12362 | } | |
12363 | ||
5f486660 | 12364 | bp_location::~bp_location () |
348d480f | 12365 | { |
5f486660 | 12366 | xfree (function_name); |
348d480f PA |
12367 | } |
12368 | ||
c1fc2657 | 12369 | /* Destructor for the breakpoint base class. */ |
348d480f | 12370 | |
c1fc2657 | 12371 | breakpoint::~breakpoint () |
348d480f | 12372 | { |
c1fc2657 SM |
12373 | xfree (this->cond_string); |
12374 | xfree (this->extra_string); | |
348d480f PA |
12375 | } |
12376 | ||
2060206e PA |
12377 | static struct bp_location * |
12378 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12379 | { |
5f486660 | 12380 | return new bp_location (self); |
348d480f PA |
12381 | } |
12382 | ||
2060206e PA |
12383 | static void |
12384 | base_breakpoint_re_set (struct breakpoint *b) | |
12385 | { | |
12386 | /* Nothing to re-set. */ | |
12387 | } | |
12388 | ||
12389 | #define internal_error_pure_virtual_called() \ | |
12390 | gdb_assert_not_reached ("pure virtual function called") | |
12391 | ||
12392 | static int | |
12393 | base_breakpoint_insert_location (struct bp_location *bl) | |
12394 | { | |
12395 | internal_error_pure_virtual_called (); | |
12396 | } | |
12397 | ||
12398 | static int | |
73971819 PA |
12399 | base_breakpoint_remove_location (struct bp_location *bl, |
12400 | enum remove_bp_reason reason) | |
2060206e PA |
12401 | { |
12402 | internal_error_pure_virtual_called (); | |
12403 | } | |
12404 | ||
12405 | static int | |
12406 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12407 | const address_space *aspace, |
09ac7c10 TT |
12408 | CORE_ADDR bp_addr, |
12409 | const struct target_waitstatus *ws) | |
2060206e PA |
12410 | { |
12411 | internal_error_pure_virtual_called (); | |
12412 | } | |
12413 | ||
12414 | static void | |
12415 | base_breakpoint_check_status (bpstat bs) | |
12416 | { | |
12417 | /* Always stop. */ | |
12418 | } | |
12419 | ||
12420 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12421 | errors. */ | |
12422 | ||
12423 | static int | |
12424 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12425 | { | |
12426 | internal_error_pure_virtual_called (); | |
12427 | } | |
12428 | ||
12429 | /* A "resources_needed" breakpoint_ops method that just internal | |
12430 | errors. */ | |
12431 | ||
12432 | static int | |
12433 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12434 | { | |
12435 | internal_error_pure_virtual_called (); | |
12436 | } | |
12437 | ||
12438 | static enum print_stop_action | |
12439 | base_breakpoint_print_it (bpstat bs) | |
12440 | { | |
12441 | internal_error_pure_virtual_called (); | |
12442 | } | |
12443 | ||
12444 | static void | |
12445 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12446 | struct ui_out *uiout) | |
12447 | { | |
12448 | /* nothing */ | |
12449 | } | |
12450 | ||
12451 | static void | |
12452 | base_breakpoint_print_mention (struct breakpoint *b) | |
12453 | { | |
12454 | internal_error_pure_virtual_called (); | |
12455 | } | |
12456 | ||
12457 | static void | |
12458 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12459 | { | |
12460 | internal_error_pure_virtual_called (); | |
12461 | } | |
12462 | ||
983af33b | 12463 | static void |
f00aae0f | 12464 | base_breakpoint_create_sals_from_location |
626d2320 | 12465 | (struct event_location *location, |
f00aae0f KS |
12466 | struct linespec_result *canonical, |
12467 | enum bptype type_wanted) | |
983af33b SDJ |
12468 | { |
12469 | internal_error_pure_virtual_called (); | |
12470 | } | |
12471 | ||
12472 | static void | |
12473 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12474 | struct linespec_result *c, | |
e1e01040 PA |
12475 | gdb::unique_xmalloc_ptr<char> cond_string, |
12476 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12477 | enum bptype type_wanted, |
12478 | enum bpdisp disposition, | |
12479 | int thread, | |
12480 | int task, int ignore_count, | |
12481 | const struct breakpoint_ops *o, | |
12482 | int from_tty, int enabled, | |
44f238bb | 12483 | int internal, unsigned flags) |
983af33b SDJ |
12484 | { |
12485 | internal_error_pure_virtual_called (); | |
12486 | } | |
12487 | ||
6c5b2ebe | 12488 | static std::vector<symtab_and_line> |
f00aae0f | 12489 | base_breakpoint_decode_location (struct breakpoint *b, |
626d2320 | 12490 | struct event_location *location, |
6c5b2ebe | 12491 | struct program_space *search_pspace) |
983af33b SDJ |
12492 | { |
12493 | internal_error_pure_virtual_called (); | |
12494 | } | |
12495 | ||
ab04a2af TT |
12496 | /* The default 'explains_signal' method. */ |
12497 | ||
47591c29 | 12498 | static int |
427cd150 | 12499 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12500 | { |
47591c29 | 12501 | return 1; |
ab04a2af TT |
12502 | } |
12503 | ||
9d6e6e84 HZ |
12504 | /* The default "after_condition_true" method. */ |
12505 | ||
12506 | static void | |
12507 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12508 | { | |
12509 | /* Nothing to do. */ | |
12510 | } | |
12511 | ||
ab04a2af | 12512 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12513 | { |
2060206e PA |
12514 | base_breakpoint_allocate_location, |
12515 | base_breakpoint_re_set, | |
12516 | base_breakpoint_insert_location, | |
12517 | base_breakpoint_remove_location, | |
12518 | base_breakpoint_breakpoint_hit, | |
12519 | base_breakpoint_check_status, | |
12520 | base_breakpoint_resources_needed, | |
12521 | base_breakpoint_works_in_software_mode, | |
12522 | base_breakpoint_print_it, | |
12523 | NULL, | |
12524 | base_breakpoint_print_one_detail, | |
12525 | base_breakpoint_print_mention, | |
983af33b | 12526 | base_breakpoint_print_recreate, |
5f700d83 | 12527 | base_breakpoint_create_sals_from_location, |
983af33b | 12528 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12529 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12530 | base_breakpoint_explains_signal, |
12531 | base_breakpoint_after_condition_true, | |
2060206e PA |
12532 | }; |
12533 | ||
12534 | /* Default breakpoint_ops methods. */ | |
12535 | ||
12536 | static void | |
348d480f PA |
12537 | bkpt_re_set (struct breakpoint *b) |
12538 | { | |
06edf0c0 | 12539 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12540 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12541 | { |
f00aae0f | 12542 | /* Anything without a location can't be re-set. */ |
348d480f | 12543 | delete_breakpoint (b); |
06edf0c0 | 12544 | return; |
348d480f | 12545 | } |
06edf0c0 PA |
12546 | |
12547 | breakpoint_re_set_default (b); | |
348d480f PA |
12548 | } |
12549 | ||
2060206e | 12550 | static int |
348d480f PA |
12551 | bkpt_insert_location (struct bp_location *bl) |
12552 | { | |
cd6c3b4f YQ |
12553 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12554 | ||
579c6ad9 | 12555 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12556 | bl->target_info.placed_address = addr; |
12557 | ||
348d480f | 12558 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12559 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12560 | else |
7c16b83e | 12561 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12562 | } |
12563 | ||
2060206e | 12564 | static int |
73971819 | 12565 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12566 | { |
12567 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12568 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12569 | else | |
73971819 | 12570 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12571 | } |
12572 | ||
2060206e | 12573 | static int |
348d480f | 12574 | bkpt_breakpoint_hit (const struct bp_location *bl, |
bd522513 | 12575 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12576 | const struct target_waitstatus *ws) |
348d480f | 12577 | { |
09ac7c10 | 12578 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12579 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12580 | return 0; |
12581 | ||
348d480f PA |
12582 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12583 | aspace, bp_addr)) | |
12584 | return 0; | |
12585 | ||
12586 | if (overlay_debugging /* unmapped overlay section */ | |
12587 | && section_is_overlay (bl->section) | |
12588 | && !section_is_mapped (bl->section)) | |
12589 | return 0; | |
12590 | ||
12591 | return 1; | |
12592 | } | |
12593 | ||
cd1608cc PA |
12594 | static int |
12595 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12596 | const address_space *aspace, CORE_ADDR bp_addr, |
cd1608cc PA |
12597 | const struct target_waitstatus *ws) |
12598 | { | |
12599 | if (dprintf_style == dprintf_style_agent | |
12600 | && target_can_run_breakpoint_commands ()) | |
12601 | { | |
12602 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12603 | for this address it must be for a breakpoint that happens to | |
12604 | be set at the same address. */ | |
12605 | return 0; | |
12606 | } | |
12607 | ||
12608 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12609 | } | |
12610 | ||
2060206e | 12611 | static int |
348d480f PA |
12612 | bkpt_resources_needed (const struct bp_location *bl) |
12613 | { | |
12614 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12615 | ||
12616 | return 1; | |
12617 | } | |
12618 | ||
2060206e | 12619 | static enum print_stop_action |
348d480f PA |
12620 | bkpt_print_it (bpstat bs) |
12621 | { | |
348d480f PA |
12622 | struct breakpoint *b; |
12623 | const struct bp_location *bl; | |
001c8c33 | 12624 | int bp_temp; |
79a45e25 | 12625 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12626 | |
12627 | gdb_assert (bs->bp_location_at != NULL); | |
12628 | ||
12629 | bl = bs->bp_location_at; | |
12630 | b = bs->breakpoint_at; | |
12631 | ||
001c8c33 PA |
12632 | bp_temp = b->disposition == disp_del; |
12633 | if (bl->address != bl->requested_address) | |
12634 | breakpoint_adjustment_warning (bl->requested_address, | |
12635 | bl->address, | |
12636 | b->number, 1); | |
12637 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12638 | maybe_print_thread_hit_breakpoint (uiout); |
12639 | ||
112e8700 | 12640 | if (uiout->is_mi_like_p ()) |
348d480f | 12641 | { |
112e8700 | 12642 | uiout->field_string ("reason", |
001c8c33 | 12643 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12644 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12645 | } |
6a831f06 PA |
12646 | if (bp_temp) |
12647 | uiout->message ("Temporary breakpoint %pF, ", | |
12648 | signed_field ("bkptno", b->number)); | |
12649 | else | |
12650 | uiout->message ("Breakpoint %pF, ", | |
12651 | signed_field ("bkptno", b->number)); | |
06edf0c0 | 12652 | |
001c8c33 | 12653 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12654 | } |
12655 | ||
2060206e | 12656 | static void |
06edf0c0 PA |
12657 | bkpt_print_mention (struct breakpoint *b) |
12658 | { | |
112e8700 | 12659 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12660 | return; |
12661 | ||
12662 | switch (b->type) | |
12663 | { | |
12664 | case bp_breakpoint: | |
12665 | case bp_gnu_ifunc_resolver: | |
12666 | if (b->disposition == disp_del) | |
12667 | printf_filtered (_("Temporary breakpoint")); | |
12668 | else | |
12669 | printf_filtered (_("Breakpoint")); | |
12670 | printf_filtered (_(" %d"), b->number); | |
12671 | if (b->type == bp_gnu_ifunc_resolver) | |
12672 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12673 | break; | |
12674 | case bp_hardware_breakpoint: | |
12675 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12676 | break; | |
e7e0cddf SS |
12677 | case bp_dprintf: |
12678 | printf_filtered (_("Dprintf %d"), b->number); | |
12679 | break; | |
06edf0c0 PA |
12680 | } |
12681 | ||
12682 | say_where (b); | |
12683 | } | |
12684 | ||
2060206e | 12685 | static void |
06edf0c0 PA |
12686 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12687 | { | |
12688 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12689 | fprintf_unfiltered (fp, "tbreak"); | |
12690 | else if (tp->type == bp_breakpoint) | |
12691 | fprintf_unfiltered (fp, "break"); | |
12692 | else if (tp->type == bp_hardware_breakpoint | |
12693 | && tp->disposition == disp_del) | |
12694 | fprintf_unfiltered (fp, "thbreak"); | |
12695 | else if (tp->type == bp_hardware_breakpoint) | |
12696 | fprintf_unfiltered (fp, "hbreak"); | |
12697 | else | |
12698 | internal_error (__FILE__, __LINE__, | |
12699 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12700 | ||
f00aae0f | 12701 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12702 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12703 | |
12704 | /* Print out extra_string if this breakpoint is pending. It might | |
12705 | contain, for example, conditions that were set by the user. */ | |
12706 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12707 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12708 | ||
dd11a36c | 12709 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12710 | } |
12711 | ||
983af33b | 12712 | static void |
626d2320 | 12713 | bkpt_create_sals_from_location (struct event_location *location, |
f00aae0f KS |
12714 | struct linespec_result *canonical, |
12715 | enum bptype type_wanted) | |
983af33b | 12716 | { |
f00aae0f | 12717 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12718 | } |
12719 | ||
12720 | static void | |
12721 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12722 | struct linespec_result *canonical, | |
e1e01040 PA |
12723 | gdb::unique_xmalloc_ptr<char> cond_string, |
12724 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12725 | enum bptype type_wanted, |
12726 | enum bpdisp disposition, | |
12727 | int thread, | |
12728 | int task, int ignore_count, | |
12729 | const struct breakpoint_ops *ops, | |
12730 | int from_tty, int enabled, | |
44f238bb | 12731 | int internal, unsigned flags) |
983af33b | 12732 | { |
023fa29b | 12733 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12734 | std::move (cond_string), |
12735 | std::move (extra_string), | |
e7e0cddf | 12736 | type_wanted, |
983af33b SDJ |
12737 | disposition, thread, task, |
12738 | ignore_count, ops, from_tty, | |
44f238bb | 12739 | enabled, internal, flags); |
983af33b SDJ |
12740 | } |
12741 | ||
6c5b2ebe | 12742 | static std::vector<symtab_and_line> |
f00aae0f | 12743 | bkpt_decode_location (struct breakpoint *b, |
626d2320 | 12744 | struct event_location *location, |
6c5b2ebe | 12745 | struct program_space *search_pspace) |
983af33b | 12746 | { |
6c5b2ebe | 12747 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12748 | } |
12749 | ||
06edf0c0 PA |
12750 | /* Virtual table for internal breakpoints. */ |
12751 | ||
12752 | static void | |
12753 | internal_bkpt_re_set (struct breakpoint *b) | |
12754 | { | |
12755 | switch (b->type) | |
12756 | { | |
12757 | /* Delete overlay event and longjmp master breakpoints; they | |
12758 | will be reset later by breakpoint_re_set. */ | |
12759 | case bp_overlay_event: | |
12760 | case bp_longjmp_master: | |
12761 | case bp_std_terminate_master: | |
12762 | case bp_exception_master: | |
12763 | delete_breakpoint (b); | |
12764 | break; | |
12765 | ||
12766 | /* This breakpoint is special, it's set up when the inferior | |
dda83cd7 | 12767 | starts and we really don't want to touch it. */ |
06edf0c0 PA |
12768 | case bp_shlib_event: |
12769 | ||
12770 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12771 | it is set up, we do not want to touch it. */ | |
12772 | case bp_thread_event: | |
12773 | break; | |
12774 | } | |
12775 | } | |
12776 | ||
12777 | static void | |
12778 | internal_bkpt_check_status (bpstat bs) | |
12779 | { | |
a9b3a50f PA |
12780 | if (bs->breakpoint_at->type == bp_shlib_event) |
12781 | { | |
12782 | /* If requested, stop when the dynamic linker notifies GDB of | |
12783 | events. This allows the user to get control and place | |
12784 | breakpoints in initializer routines for dynamically loaded | |
12785 | objects (among other things). */ | |
12786 | bs->stop = stop_on_solib_events; | |
12787 | bs->print = stop_on_solib_events; | |
12788 | } | |
12789 | else | |
12790 | bs->stop = 0; | |
06edf0c0 PA |
12791 | } |
12792 | ||
12793 | static enum print_stop_action | |
12794 | internal_bkpt_print_it (bpstat bs) | |
12795 | { | |
06edf0c0 | 12796 | struct breakpoint *b; |
06edf0c0 | 12797 | |
06edf0c0 PA |
12798 | b = bs->breakpoint_at; |
12799 | ||
06edf0c0 PA |
12800 | switch (b->type) |
12801 | { | |
348d480f PA |
12802 | case bp_shlib_event: |
12803 | /* Did we stop because the user set the stop_on_solib_events | |
12804 | variable? (If so, we report this as a generic, "Stopped due | |
12805 | to shlib event" message.) */ | |
edcc5120 | 12806 | print_solib_event (0); |
348d480f PA |
12807 | break; |
12808 | ||
12809 | case bp_thread_event: | |
12810 | /* Not sure how we will get here. | |
12811 | GDB should not stop for these breakpoints. */ | |
12812 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12813 | break; |
12814 | ||
12815 | case bp_overlay_event: | |
12816 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12817 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12818 | break; |
12819 | ||
12820 | case bp_longjmp_master: | |
12821 | /* These should never be enabled. */ | |
12822 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12823 | break; |
12824 | ||
12825 | case bp_std_terminate_master: | |
12826 | /* These should never be enabled. */ | |
12827 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12828 | "gdb should not stop!\n")); | |
348d480f PA |
12829 | break; |
12830 | ||
12831 | case bp_exception_master: | |
12832 | /* These should never be enabled. */ | |
12833 | printf_filtered (_("Exception Master Breakpoint: " | |
12834 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12835 | break; |
12836 | } | |
12837 | ||
001c8c33 | 12838 | return PRINT_NOTHING; |
06edf0c0 PA |
12839 | } |
12840 | ||
12841 | static void | |
12842 | internal_bkpt_print_mention (struct breakpoint *b) | |
12843 | { | |
12844 | /* Nothing to mention. These breakpoints are internal. */ | |
12845 | } | |
12846 | ||
06edf0c0 PA |
12847 | /* Virtual table for momentary breakpoints */ |
12848 | ||
12849 | static void | |
12850 | momentary_bkpt_re_set (struct breakpoint *b) | |
12851 | { | |
12852 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12853 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12854 | Otherwise these should have been blown away via the cleanup chain |
12855 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12856 | } | |
12857 | ||
12858 | static void | |
12859 | momentary_bkpt_check_status (bpstat bs) | |
12860 | { | |
12861 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12862 | } | |
12863 | ||
12864 | static enum print_stop_action | |
12865 | momentary_bkpt_print_it (bpstat bs) | |
12866 | { | |
001c8c33 | 12867 | return PRINT_UNKNOWN; |
348d480f PA |
12868 | } |
12869 | ||
06edf0c0 PA |
12870 | static void |
12871 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12872 | { |
06edf0c0 | 12873 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12874 | } |
12875 | ||
e2e4d78b JK |
12876 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12877 | ||
12878 | It gets cleared already on the removal of the first one of such placed | |
12879 | breakpoints. This is OK as they get all removed altogether. */ | |
12880 | ||
c1fc2657 | 12881 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 12882 | { |
c1fc2657 | 12883 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 12884 | |
c1fc2657 | 12885 | if (tp != NULL) |
e2e4d78b | 12886 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
12887 | } |
12888 | ||
55aa24fb SDJ |
12889 | /* Specific methods for probe breakpoints. */ |
12890 | ||
12891 | static int | |
12892 | bkpt_probe_insert_location (struct bp_location *bl) | |
12893 | { | |
12894 | int v = bkpt_insert_location (bl); | |
12895 | ||
12896 | if (v == 0) | |
12897 | { | |
12898 | /* The insertion was successful, now let's set the probe's semaphore | |
12899 | if needed. */ | |
935676c9 | 12900 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb SDJ |
12901 | } |
12902 | ||
12903 | return v; | |
12904 | } | |
12905 | ||
12906 | static int | |
73971819 PA |
12907 | bkpt_probe_remove_location (struct bp_location *bl, |
12908 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
12909 | { |
12910 | /* Let's clear the semaphore before removing the location. */ | |
935676c9 | 12911 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb | 12912 | |
73971819 | 12913 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
12914 | } |
12915 | ||
12916 | static void | |
626d2320 | 12917 | bkpt_probe_create_sals_from_location (struct event_location *location, |
5f700d83 | 12918 | struct linespec_result *canonical, |
f00aae0f | 12919 | enum bptype type_wanted) |
55aa24fb SDJ |
12920 | { |
12921 | struct linespec_sals lsal; | |
12922 | ||
c2f4122d | 12923 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
12924 | lsal.canonical |
12925 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12926 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
12927 | } |
12928 | ||
6c5b2ebe | 12929 | static std::vector<symtab_and_line> |
f00aae0f | 12930 | bkpt_probe_decode_location (struct breakpoint *b, |
626d2320 | 12931 | struct event_location *location, |
6c5b2ebe | 12932 | struct program_space *search_pspace) |
55aa24fb | 12933 | { |
6c5b2ebe PA |
12934 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
12935 | if (sals.empty ()) | |
55aa24fb | 12936 | error (_("probe not found")); |
6c5b2ebe | 12937 | return sals; |
55aa24fb SDJ |
12938 | } |
12939 | ||
348d480f | 12940 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12941 | |
348d480f PA |
12942 | static void |
12943 | tracepoint_re_set (struct breakpoint *b) | |
12944 | { | |
12945 | breakpoint_re_set_default (b); | |
12946 | } | |
876fa593 | 12947 | |
348d480f PA |
12948 | static int |
12949 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12950 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12951 | const struct target_waitstatus *ws) |
348d480f PA |
12952 | { |
12953 | /* By definition, the inferior does not report stops at | |
12954 | tracepoints. */ | |
12955 | return 0; | |
74960c60 VP |
12956 | } |
12957 | ||
12958 | static void | |
348d480f PA |
12959 | tracepoint_print_one_detail (const struct breakpoint *self, |
12960 | struct ui_out *uiout) | |
74960c60 | 12961 | { |
d9b3f62e | 12962 | struct tracepoint *tp = (struct tracepoint *) self; |
5d9310c4 | 12963 | if (!tp->static_trace_marker_id.empty ()) |
348d480f PA |
12964 | { |
12965 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12966 | |
6a831f06 PA |
12967 | uiout->message ("\tmarker id is %pF\n", |
12968 | string_field ("static-tracepoint-marker-string-id", | |
12969 | tp->static_trace_marker_id.c_str ())); | |
348d480f | 12970 | } |
0d381245 VP |
12971 | } |
12972 | ||
a474d7c2 | 12973 | static void |
348d480f | 12974 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12975 | { |
112e8700 | 12976 | if (current_uiout->is_mi_like_p ()) |
348d480f | 12977 | return; |
cc59ec59 | 12978 | |
348d480f PA |
12979 | switch (b->type) |
12980 | { | |
12981 | case bp_tracepoint: | |
12982 | printf_filtered (_("Tracepoint")); | |
12983 | printf_filtered (_(" %d"), b->number); | |
12984 | break; | |
12985 | case bp_fast_tracepoint: | |
12986 | printf_filtered (_("Fast tracepoint")); | |
12987 | printf_filtered (_(" %d"), b->number); | |
12988 | break; | |
12989 | case bp_static_tracepoint: | |
12990 | printf_filtered (_("Static tracepoint")); | |
12991 | printf_filtered (_(" %d"), b->number); | |
12992 | break; | |
12993 | default: | |
12994 | internal_error (__FILE__, __LINE__, | |
12995 | _("unhandled tracepoint type %d"), (int) b->type); | |
12996 | } | |
12997 | ||
12998 | say_where (b); | |
a474d7c2 PA |
12999 | } |
13000 | ||
348d480f | 13001 | static void |
d9b3f62e | 13002 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13003 | { |
d9b3f62e PA |
13004 | struct tracepoint *tp = (struct tracepoint *) self; |
13005 | ||
13006 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13007 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13008 | else if (self->type == bp_static_tracepoint) |
348d480f | 13009 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13010 | else if (self->type == bp_tracepoint) |
348d480f PA |
13011 | fprintf_unfiltered (fp, "trace"); |
13012 | else | |
13013 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13014 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13015 | |
f00aae0f | 13016 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13017 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
13018 | print_recreate_thread (self, fp); |
13019 | ||
13020 | if (tp->pass_count) | |
13021 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13022 | } |
13023 | ||
983af33b | 13024 | static void |
626d2320 | 13025 | tracepoint_create_sals_from_location (struct event_location *location, |
f00aae0f KS |
13026 | struct linespec_result *canonical, |
13027 | enum bptype type_wanted) | |
983af33b | 13028 | { |
f00aae0f | 13029 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13030 | } |
13031 | ||
13032 | static void | |
13033 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13034 | struct linespec_result *canonical, | |
e1e01040 PA |
13035 | gdb::unique_xmalloc_ptr<char> cond_string, |
13036 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13037 | enum bptype type_wanted, |
13038 | enum bpdisp disposition, | |
13039 | int thread, | |
13040 | int task, int ignore_count, | |
13041 | const struct breakpoint_ops *ops, | |
13042 | int from_tty, int enabled, | |
44f238bb | 13043 | int internal, unsigned flags) |
983af33b | 13044 | { |
023fa29b | 13045 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13046 | std::move (cond_string), |
13047 | std::move (extra_string), | |
e7e0cddf | 13048 | type_wanted, |
983af33b SDJ |
13049 | disposition, thread, task, |
13050 | ignore_count, ops, from_tty, | |
44f238bb | 13051 | enabled, internal, flags); |
983af33b SDJ |
13052 | } |
13053 | ||
6c5b2ebe | 13054 | static std::vector<symtab_and_line> |
f00aae0f | 13055 | tracepoint_decode_location (struct breakpoint *b, |
626d2320 | 13056 | struct event_location *location, |
6c5b2ebe | 13057 | struct program_space *search_pspace) |
983af33b | 13058 | { |
6c5b2ebe | 13059 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
13060 | } |
13061 | ||
2060206e | 13062 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13063 | |
bac7c5cf | 13064 | /* Virtual table for tracepoints on static probes. */ |
55aa24fb SDJ |
13065 | |
13066 | static void | |
f00aae0f | 13067 | tracepoint_probe_create_sals_from_location |
626d2320 | 13068 | (struct event_location *location, |
f00aae0f KS |
13069 | struct linespec_result *canonical, |
13070 | enum bptype type_wanted) | |
55aa24fb SDJ |
13071 | { |
13072 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13073 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13074 | } |
13075 | ||
6c5b2ebe | 13076 | static std::vector<symtab_and_line> |
f00aae0f | 13077 | tracepoint_probe_decode_location (struct breakpoint *b, |
626d2320 | 13078 | struct event_location *location, |
6c5b2ebe | 13079 | struct program_space *search_pspace) |
55aa24fb SDJ |
13080 | { |
13081 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 13082 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
13083 | } |
13084 | ||
5c2b4418 HZ |
13085 | /* Dprintf breakpoint_ops methods. */ |
13086 | ||
13087 | static void | |
13088 | dprintf_re_set (struct breakpoint *b) | |
13089 | { | |
13090 | breakpoint_re_set_default (b); | |
13091 | ||
f00aae0f KS |
13092 | /* extra_string should never be non-NULL for dprintf. */ |
13093 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13094 | |
13095 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13096 | 2 - create a dprintf, which resolves fine. | |
13097 | 3 - disconnect from target 1 | |
13098 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13099 | ||
13100 | After steps #3/#4, you'll want the dprintf command list to | |
13101 | be updated, because target 1 and 2 may well return different | |
13102 | answers for target_can_run_breakpoint_commands(). | |
13103 | Given absence of finer grained resetting, we get to do | |
13104 | it all the time. */ | |
13105 | if (b->extra_string != NULL) | |
13106 | update_dprintf_command_list (b); | |
13107 | } | |
13108 | ||
2d9442cc HZ |
13109 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13110 | ||
13111 | static void | |
13112 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13113 | { | |
f00aae0f | 13114 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 13115 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
13116 | tp->extra_string); |
13117 | print_recreate_thread (tp, fp); | |
13118 | } | |
13119 | ||
9d6e6e84 HZ |
13120 | /* Implement the "after_condition_true" breakpoint_ops method for |
13121 | dprintf. | |
13122 | ||
13123 | dprintf's are implemented with regular commands in their command | |
13124 | list, but we run the commands here instead of before presenting the | |
13125 | stop to the user, as dprintf's don't actually cause a stop. This | |
13126 | also makes it so that the commands of multiple dprintfs at the same | |
13127 | address are all handled. */ | |
13128 | ||
13129 | static void | |
13130 | dprintf_after_condition_true (struct bpstats *bs) | |
13131 | { | |
04afa70c | 13132 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
13133 | struct bpstats *tmp_bs_p = &tmp_bs; |
13134 | ||
13135 | /* dprintf's never cause a stop. This wasn't set in the | |
13136 | check_status hook instead because that would make the dprintf's | |
13137 | condition not be evaluated. */ | |
13138 | bs->stop = 0; | |
13139 | ||
13140 | /* Run the command list here. Take ownership of it instead of | |
13141 | copying. We never want these commands to run later in | |
13142 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13143 | be set at same address as this dprintf, or even if running the | |
13144 | commands here throws. */ | |
13145 | tmp_bs.commands = bs->commands; | |
13146 | bs->commands = NULL; | |
9d6e6e84 HZ |
13147 | |
13148 | bpstat_do_actions_1 (&tmp_bs_p); | |
13149 | ||
13150 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13151 | bpstat_do_actions_1 may return early without processing the whole | |
13152 | list. */ | |
9d6e6e84 HZ |
13153 | } |
13154 | ||
983af33b SDJ |
13155 | /* The breakpoint_ops structure to be used on static tracepoints with |
13156 | markers (`-m'). */ | |
13157 | ||
13158 | static void | |
626d2320 | 13159 | strace_marker_create_sals_from_location (struct event_location *location, |
5f700d83 | 13160 | struct linespec_result *canonical, |
f00aae0f | 13161 | enum bptype type_wanted) |
983af33b SDJ |
13162 | { |
13163 | struct linespec_sals lsal; | |
f00aae0f | 13164 | const char *arg_start, *arg; |
983af33b | 13165 | |
a20714ff | 13166 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 13167 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 13168 | |
f2fc3015 TT |
13169 | std::string str (arg_start, arg - arg_start); |
13170 | const char *ptr = str.c_str (); | |
a20714ff PA |
13171 | canonical->location |
13172 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 13173 | |
8e9e35b1 TT |
13174 | lsal.canonical |
13175 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13176 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
13177 | } |
13178 | ||
13179 | static void | |
13180 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13181 | struct linespec_result *canonical, | |
e1e01040 PA |
13182 | gdb::unique_xmalloc_ptr<char> cond_string, |
13183 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13184 | enum bptype type_wanted, |
13185 | enum bpdisp disposition, | |
13186 | int thread, | |
13187 | int task, int ignore_count, | |
13188 | const struct breakpoint_ops *ops, | |
13189 | int from_tty, int enabled, | |
44f238bb | 13190 | int internal, unsigned flags) |
983af33b | 13191 | { |
6c5b2ebe | 13192 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
13193 | |
13194 | /* If the user is creating a static tracepoint by marker id | |
13195 | (strace -m MARKER_ID), then store the sals index, so that | |
13196 | breakpoint_re_set can try to match up which of the newly | |
13197 | found markers corresponds to this one, and, don't try to | |
13198 | expand multiple locations for each sal, given than SALS | |
13199 | already should contain all sals for MARKER_ID. */ | |
13200 | ||
6c5b2ebe | 13201 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 13202 | { |
6c5b2ebe PA |
13203 | event_location_up location |
13204 | = copy_event_location (canonical->location.get ()); | |
983af33b | 13205 | |
b270e6f9 | 13206 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 13207 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 13208 | std::move (location), NULL, |
e1e01040 PA |
13209 | std::move (cond_string), |
13210 | std::move (extra_string), | |
e7e0cddf | 13211 | type_wanted, disposition, |
983af33b | 13212 | thread, task, ignore_count, ops, |
44f238bb | 13213 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13214 | canonical->special_display); |
13215 | /* Given that its possible to have multiple markers with | |
13216 | the same string id, if the user is creating a static | |
13217 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13218 | store the sals index, so that breakpoint_re_set can | |
13219 | try to match up which of the newly found markers | |
13220 | corresponds to this one */ | |
13221 | tp->static_trace_marker_id_idx = i; | |
13222 | ||
b270e6f9 | 13223 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
13224 | } |
13225 | } | |
13226 | ||
6c5b2ebe | 13227 | static std::vector<symtab_and_line> |
f00aae0f | 13228 | strace_marker_decode_location (struct breakpoint *b, |
626d2320 | 13229 | struct event_location *location, |
6c5b2ebe | 13230 | struct program_space *search_pspace) |
983af33b SDJ |
13231 | { |
13232 | struct tracepoint *tp = (struct tracepoint *) b; | |
a20714ff | 13233 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 13234 | |
6c5b2ebe PA |
13235 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
13236 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 13237 | { |
6c5b2ebe PA |
13238 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
13239 | sals.resize (1); | |
13240 | return sals; | |
983af33b SDJ |
13241 | } |
13242 | else | |
5d9310c4 | 13243 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
983af33b SDJ |
13244 | } |
13245 | ||
13246 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13247 | ||
13248 | static int | |
13249 | strace_marker_p (struct breakpoint *b) | |
13250 | { | |
13251 | return b->ops == &strace_marker_breakpoint_ops; | |
13252 | } | |
13253 | ||
53a5351d | 13254 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13255 | structures. */ |
c906108c SS |
13256 | |
13257 | void | |
fba45db2 | 13258 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13259 | { |
52f0bd74 | 13260 | struct breakpoint *b; |
c906108c | 13261 | |
8a3fe4f8 | 13262 | gdb_assert (bpt != NULL); |
c906108c | 13263 | |
4a64f543 MS |
13264 | /* Has this bp already been deleted? This can happen because |
13265 | multiple lists can hold pointers to bp's. bpstat lists are | |
13266 | especial culprits. | |
13267 | ||
13268 | One example of this happening is a watchpoint's scope bp. When | |
13269 | the scope bp triggers, we notice that the watchpoint is out of | |
13270 | scope, and delete it. We also delete its scope bp. But the | |
13271 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13272 | That bpstat is then checked for auto-deleting bp's, which are | |
13273 | deleted. | |
13274 | ||
13275 | A real solution to this problem might involve reference counts in | |
13276 | bp's, and/or giving them pointers back to their referencing | |
13277 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13278 | storage when no more references were extent. A cheaper bandaid | |
13279 | was chosen. */ | |
c906108c SS |
13280 | if (bpt->type == bp_none) |
13281 | return; | |
13282 | ||
4a64f543 MS |
13283 | /* At least avoid this stale reference until the reference counting |
13284 | of breakpoints gets resolved. */ | |
d0fb5eae | 13285 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13286 | { |
d0fb5eae | 13287 | struct breakpoint *related; |
3a5c3e22 | 13288 | struct watchpoint *w; |
d0fb5eae JK |
13289 | |
13290 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13291 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13292 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13293 | w = (struct watchpoint *) bpt; |
13294 | else | |
13295 | w = NULL; | |
13296 | if (w != NULL) | |
13297 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13298 | |
13299 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13300 | for (related = bpt; related->related_breakpoint != bpt; | |
13301 | related = related->related_breakpoint); | |
13302 | related->related_breakpoint = bpt->related_breakpoint; | |
13303 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13304 | } |
13305 | ||
a9634178 TJB |
13306 | /* watch_command_1 creates a watchpoint but only sets its number if |
13307 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13308 | a problem in that process, we'll be asked to delete the half-created | |
13309 | watchpoint. In that case, don't announce the deletion. */ | |
13310 | if (bpt->number) | |
76727919 | 13311 | gdb::observers::breakpoint_deleted.notify (bpt); |
c906108c | 13312 | |
c906108c SS |
13313 | if (breakpoint_chain == bpt) |
13314 | breakpoint_chain = bpt->next; | |
13315 | ||
c906108c SS |
13316 | ALL_BREAKPOINTS (b) |
13317 | if (b->next == bpt) | |
c5aa993b JM |
13318 | { |
13319 | b->next = bpt->next; | |
13320 | break; | |
13321 | } | |
c906108c | 13322 | |
f431efe5 PA |
13323 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13324 | been freed. */ | |
13325 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13326 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13327 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13328 | commands are associated with the bpstat; if we remove it here, | |
13329 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13330 | event-top.c won't do anything, and temporary breakpoints with | |
13331 | commands won't work. */ | |
13332 | ||
13333 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13334 | ||
4a64f543 MS |
13335 | /* Now that breakpoint is removed from breakpoint list, update the |
13336 | global location list. This will remove locations that used to | |
13337 | belong to this breakpoint. Do this before freeing the breakpoint | |
13338 | itself, since remove_breakpoint looks at location's owner. It | |
13339 | might be better design to have location completely | |
13340 | self-contained, but it's not the case now. */ | |
44702360 | 13341 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13342 | |
4a64f543 MS |
13343 | /* On the chance that someone will soon try again to delete this |
13344 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13345 | bpt->type = bp_none; |
4d01a485 | 13346 | delete bpt; |
c906108c SS |
13347 | } |
13348 | ||
51be5b68 PA |
13349 | /* Iterator function to call a user-provided callback function once |
13350 | for each of B and its related breakpoints. */ | |
13351 | ||
13352 | static void | |
13353 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13354 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13355 | { |
13356 | struct breakpoint *related; | |
13357 | ||
13358 | related = b; | |
13359 | do | |
13360 | { | |
13361 | struct breakpoint *next; | |
13362 | ||
13363 | /* FUNCTION may delete RELATED. */ | |
13364 | next = related->related_breakpoint; | |
13365 | ||
13366 | if (next == related) | |
13367 | { | |
13368 | /* RELATED is the last ring entry. */ | |
48649e1b | 13369 | function (related); |
51be5b68 PA |
13370 | |
13371 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13372 | B. There's nothing left to do anyway, so just break | |
13373 | out. */ | |
13374 | break; | |
13375 | } | |
13376 | else | |
48649e1b | 13377 | function (related); |
51be5b68 PA |
13378 | |
13379 | related = next; | |
13380 | } | |
13381 | while (related != b); | |
13382 | } | |
95a42b64 | 13383 | |
4495129a | 13384 | static void |
981a3fb3 | 13385 | delete_command (const char *arg, int from_tty) |
c906108c | 13386 | { |
35df4500 | 13387 | struct breakpoint *b, *b_tmp; |
c906108c | 13388 | |
ea9365bb TT |
13389 | dont_repeat (); |
13390 | ||
c906108c SS |
13391 | if (arg == 0) |
13392 | { | |
13393 | int breaks_to_delete = 0; | |
13394 | ||
46c6471b | 13395 | /* Delete all breakpoints if no argument. Do not delete |
dda83cd7 SM |
13396 | internal breakpoints, these have to be deleted with an |
13397 | explicit breakpoint number argument. */ | |
c5aa993b | 13398 | ALL_BREAKPOINTS (b) |
46c6471b | 13399 | if (user_breakpoint_p (b)) |
973d738b DJ |
13400 | { |
13401 | breaks_to_delete = 1; | |
13402 | break; | |
13403 | } | |
c906108c SS |
13404 | |
13405 | /* Ask user only if there are some breakpoints to delete. */ | |
13406 | if (!from_tty | |
e2e0b3e5 | 13407 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13408 | { |
35df4500 | 13409 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13410 | if (user_breakpoint_p (b)) |
c5aa993b | 13411 | delete_breakpoint (b); |
c906108c SS |
13412 | } |
13413 | } | |
13414 | else | |
48649e1b | 13415 | map_breakpoint_numbers |
b926417a | 13416 | (arg, [&] (breakpoint *br) |
48649e1b | 13417 | { |
b926417a | 13418 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 13419 | }); |
c906108c SS |
13420 | } |
13421 | ||
c2f4122d PA |
13422 | /* Return true if all locations of B bound to PSPACE are pending. If |
13423 | PSPACE is NULL, all locations of all program spaces are | |
13424 | considered. */ | |
13425 | ||
0d381245 | 13426 | static int |
c2f4122d | 13427 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13428 | { |
c2f4122d PA |
13429 | struct bp_location *loc; |
13430 | ||
13431 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13432 | if ((pspace == NULL | |
13433 | || loc->pspace == pspace) | |
13434 | && !loc->shlib_disabled | |
8645ff69 | 13435 | && !loc->pspace->executing_startup) |
0d381245 VP |
13436 | return 0; |
13437 | return 1; | |
fe3f5fa8 VP |
13438 | } |
13439 | ||
776592bf DE |
13440 | /* Subroutine of update_breakpoint_locations to simplify it. |
13441 | Return non-zero if multiple fns in list LOC have the same name. | |
13442 | Null names are ignored. */ | |
13443 | ||
13444 | static int | |
13445 | ambiguous_names_p (struct bp_location *loc) | |
13446 | { | |
13447 | struct bp_location *l; | |
c1fb9836 TT |
13448 | htab_up htab (htab_create_alloc (13, htab_hash_string, streq_hash, NULL, |
13449 | xcalloc, xfree)); | |
776592bf DE |
13450 | |
13451 | for (l = loc; l != NULL; l = l->next) | |
13452 | { | |
13453 | const char **slot; | |
13454 | const char *name = l->function_name; | |
13455 | ||
13456 | /* Allow for some names to be NULL, ignore them. */ | |
13457 | if (name == NULL) | |
13458 | continue; | |
13459 | ||
c1fb9836 | 13460 | slot = (const char **) htab_find_slot (htab.get (), (const void *) name, |
776592bf | 13461 | INSERT); |
4a64f543 MS |
13462 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13463 | returns NULL. */ | |
776592bf | 13464 | if (*slot != NULL) |
c1fb9836 | 13465 | return 1; |
776592bf DE |
13466 | *slot = name; |
13467 | } | |
13468 | ||
776592bf DE |
13469 | return 0; |
13470 | } | |
13471 | ||
0fb4aa4b PA |
13472 | /* When symbols change, it probably means the sources changed as well, |
13473 | and it might mean the static tracepoint markers are no longer at | |
13474 | the same address or line numbers they used to be at last we | |
13475 | checked. Losing your static tracepoints whenever you rebuild is | |
13476 | undesirable. This function tries to resync/rematch gdb static | |
13477 | tracepoints with the markers on the target, for static tracepoints | |
13478 | that have not been set by marker id. Static tracepoint that have | |
13479 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13480 | The heuristic is: | |
13481 | ||
13482 | 1) For a tracepoint set at a specific address, look for a marker at | |
13483 | the old PC. If one is found there, assume to be the same marker. | |
13484 | If the name / string id of the marker found is different from the | |
13485 | previous known name, assume that means the user renamed the marker | |
13486 | in the sources, and output a warning. | |
13487 | ||
13488 | 2) For a tracepoint set at a given line number, look for a marker | |
13489 | at the new address of the old line number. If one is found there, | |
13490 | assume to be the same marker. If the name / string id of the | |
13491 | marker found is different from the previous known name, assume that | |
13492 | means the user renamed the marker in the sources, and output a | |
13493 | warning. | |
13494 | ||
13495 | 3) If a marker is no longer found at the same address or line, it | |
13496 | may mean the marker no longer exists. But it may also just mean | |
13497 | the code changed a bit. Maybe the user added a few lines of code | |
13498 | that made the marker move up or down (in line number terms). Ask | |
13499 | the target for info about the marker with the string id as we knew | |
13500 | it. If found, update line number and address in the matching | |
13501 | static tracepoint. This will get confused if there's more than one | |
13502 | marker with the same ID (possible in UST, although unadvised | |
13503 | precisely because it confuses tools). */ | |
13504 | ||
13505 | static struct symtab_and_line | |
13506 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13507 | { | |
d9b3f62e | 13508 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13509 | struct static_tracepoint_marker marker; |
13510 | CORE_ADDR pc; | |
0fb4aa4b PA |
13511 | |
13512 | pc = sal.pc; | |
13513 | if (sal.line) | |
13514 | find_line_pc (sal.symtab, sal.line, &pc); | |
13515 | ||
13516 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13517 | { | |
5d9310c4 | 13518 | if (tp->static_trace_marker_id != marker.str_id) |
0fb4aa4b | 13519 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
5d9310c4 SM |
13520 | b->number, tp->static_trace_marker_id.c_str (), |
13521 | marker.str_id.c_str ()); | |
0fb4aa4b | 13522 | |
5d9310c4 | 13523 | tp->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b PA |
13524 | |
13525 | return sal; | |
13526 | } | |
13527 | ||
13528 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13529 | by string ID. */ | |
13530 | if (!sal.explicit_pc | |
13531 | && sal.line != 0 | |
13532 | && sal.symtab != NULL | |
5d9310c4 | 13533 | && !tp->static_trace_marker_id.empty ()) |
0fb4aa4b | 13534 | { |
5d9310c4 SM |
13535 | std::vector<static_tracepoint_marker> markers |
13536 | = target_static_tracepoint_markers_by_strid | |
13537 | (tp->static_trace_marker_id.c_str ()); | |
0fb4aa4b | 13538 | |
5d9310c4 | 13539 | if (!markers.empty ()) |
0fb4aa4b | 13540 | { |
0fb4aa4b | 13541 | struct symbol *sym; |
80e1d417 | 13542 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13543 | struct ui_out *uiout = current_uiout; |
67994074 | 13544 | struct explicit_location explicit_loc; |
0fb4aa4b | 13545 | |
5d9310c4 | 13546 | tpmarker = &markers[0]; |
0fb4aa4b | 13547 | |
5d9310c4 | 13548 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
0fb4aa4b PA |
13549 | |
13550 | warning (_("marker for static tracepoint %d (%s) not " | |
13551 | "found at previous line number"), | |
5d9310c4 | 13552 | b->number, tp->static_trace_marker_id.c_str ()); |
0fb4aa4b | 13553 | |
51abb421 | 13554 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13555 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13556 | uiout->text ("Now in "); |
0fb4aa4b PA |
13557 | if (sym) |
13558 | { | |
987012b8 | 13559 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 13560 | function_name_style.style ()); |
112e8700 | 13561 | uiout->text (" at "); |
0fb4aa4b | 13562 | } |
112e8700 | 13563 | uiout->field_string ("file", |
cbe56571 | 13564 | symtab_to_filename_for_display (sal2.symtab), |
e43b10e1 | 13565 | file_name_style.style ()); |
112e8700 | 13566 | uiout->text (":"); |
0fb4aa4b | 13567 | |
112e8700 | 13568 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13569 | { |
0b0865da | 13570 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13571 | |
112e8700 | 13572 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13573 | } |
13574 | ||
381befee | 13575 | uiout->field_signed ("line", sal2.line); |
112e8700 | 13576 | uiout->text ("\n"); |
0fb4aa4b | 13577 | |
80e1d417 | 13578 | b->loc->line_number = sal2.line; |
2f202fde | 13579 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13580 | |
d28cd78a | 13581 | b->location.reset (NULL); |
67994074 KS |
13582 | initialize_explicit_location (&explicit_loc); |
13583 | explicit_loc.source_filename | |
00e52e53 | 13584 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13585 | explicit_loc.line_offset.offset = b->loc->line_number; |
13586 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13587 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13588 | |
13589 | /* Might be nice to check if function changed, and warn if | |
13590 | so. */ | |
0fb4aa4b PA |
13591 | } |
13592 | } | |
13593 | return sal; | |
13594 | } | |
13595 | ||
8d3788bd VP |
13596 | /* Returns 1 iff locations A and B are sufficiently same that |
13597 | we don't need to report breakpoint as changed. */ | |
13598 | ||
13599 | static int | |
13600 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13601 | { | |
13602 | while (a && b) | |
13603 | { | |
13604 | if (a->address != b->address) | |
13605 | return 0; | |
13606 | ||
13607 | if (a->shlib_disabled != b->shlib_disabled) | |
13608 | return 0; | |
13609 | ||
13610 | if (a->enabled != b->enabled) | |
13611 | return 0; | |
13612 | ||
b5fa468f TBA |
13613 | if (a->disabled_by_cond != b->disabled_by_cond) |
13614 | return 0; | |
13615 | ||
8d3788bd VP |
13616 | a = a->next; |
13617 | b = b->next; | |
13618 | } | |
13619 | ||
13620 | if ((a == NULL) != (b == NULL)) | |
13621 | return 0; | |
13622 | ||
13623 | return 1; | |
13624 | } | |
13625 | ||
c2f4122d PA |
13626 | /* Split all locations of B that are bound to PSPACE out of B's |
13627 | location list to a separate list and return that list's head. If | |
13628 | PSPACE is NULL, hoist out all locations of B. */ | |
13629 | ||
13630 | static struct bp_location * | |
13631 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13632 | { | |
13633 | struct bp_location head; | |
13634 | struct bp_location *i = b->loc; | |
13635 | struct bp_location **i_link = &b->loc; | |
13636 | struct bp_location *hoisted = &head; | |
13637 | ||
13638 | if (pspace == NULL) | |
13639 | { | |
13640 | i = b->loc; | |
13641 | b->loc = NULL; | |
13642 | return i; | |
13643 | } | |
13644 | ||
13645 | head.next = NULL; | |
13646 | ||
13647 | while (i != NULL) | |
13648 | { | |
13649 | if (i->pspace == pspace) | |
13650 | { | |
13651 | *i_link = i->next; | |
13652 | i->next = NULL; | |
13653 | hoisted->next = i; | |
13654 | hoisted = i; | |
13655 | } | |
13656 | else | |
13657 | i_link = &i->next; | |
13658 | i = *i_link; | |
13659 | } | |
13660 | ||
13661 | return head.next; | |
13662 | } | |
13663 | ||
13664 | /* Create new breakpoint locations for B (a hardware or software | |
13665 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13666 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13667 | FILTER_PSPACE. Locations of other program spaces are left | |
13668 | untouched. */ | |
f1310107 | 13669 | |
0e30163f | 13670 | void |
0d381245 | 13671 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13672 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13673 | gdb::array_view<const symtab_and_line> sals, |
13674 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 13675 | { |
c2f4122d | 13676 | struct bp_location *existing_locations; |
0d381245 | 13677 | |
6c5b2ebe | 13678 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13679 | { |
13680 | /* Ranged breakpoints have only one start location and one end | |
13681 | location. */ | |
13682 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13683 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13684 | "multiple locations found\n"), | |
13685 | b->number); | |
13686 | return; | |
13687 | } | |
f1310107 | 13688 | |
4a64f543 MS |
13689 | /* If there's no new locations, and all existing locations are |
13690 | pending, don't do anything. This optimizes the common case where | |
13691 | all locations are in the same shared library, that was unloaded. | |
13692 | We'd like to retain the location, so that when the library is | |
13693 | loaded again, we don't loose the enabled/disabled status of the | |
13694 | individual locations. */ | |
6c5b2ebe | 13695 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13696 | return; |
13697 | ||
c2f4122d | 13698 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13699 | |
6c5b2ebe | 13700 | for (const auto &sal : sals) |
fe3f5fa8 | 13701 | { |
f8eba3c6 TT |
13702 | struct bp_location *new_loc; |
13703 | ||
6c5b2ebe | 13704 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13705 | |
6c5b2ebe | 13706 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13707 | |
0d381245 VP |
13708 | /* Reparse conditions, they might contain references to the |
13709 | old symtab. */ | |
13710 | if (b->cond_string != NULL) | |
13711 | { | |
bbc13ae3 | 13712 | const char *s; |
fe3f5fa8 | 13713 | |
0d381245 | 13714 | s = b->cond_string; |
a70b8144 | 13715 | try |
0d381245 | 13716 | { |
6c5b2ebe PA |
13717 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13718 | block_for_pc (sal.pc), | |
0d381245 VP |
13719 | 0); |
13720 | } | |
230d2906 | 13721 | catch (const gdb_exception_error &e) |
0d381245 | 13722 | { |
b5fa468f | 13723 | new_loc->disabled_by_cond = true; |
0d381245 VP |
13724 | } |
13725 | } | |
fe3f5fa8 | 13726 | |
6c5b2ebe | 13727 | if (!sals_end.empty ()) |
f1310107 | 13728 | { |
6c5b2ebe | 13729 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13730 | |
6c5b2ebe | 13731 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13732 | } |
0d381245 | 13733 | } |
fe3f5fa8 | 13734 | |
4a64f543 MS |
13735 | /* If possible, carry over 'disable' status from existing |
13736 | breakpoints. */ | |
0d381245 VP |
13737 | { |
13738 | struct bp_location *e = existing_locations; | |
776592bf DE |
13739 | /* If there are multiple breakpoints with the same function name, |
13740 | e.g. for inline functions, comparing function names won't work. | |
13741 | Instead compare pc addresses; this is just a heuristic as things | |
13742 | may have moved, but in practice it gives the correct answer | |
13743 | often enough until a better solution is found. */ | |
13744 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13745 | ||
0d381245 VP |
13746 | for (; e; e = e->next) |
13747 | { | |
b5fa468f | 13748 | if ((!e->enabled || e->disabled_by_cond) && e->function_name) |
0d381245 VP |
13749 | { |
13750 | struct bp_location *l = b->loc; | |
776592bf DE |
13751 | if (have_ambiguous_names) |
13752 | { | |
13753 | for (; l; l = l->next) | |
7f32a4d5 PA |
13754 | { |
13755 | /* Ignore software vs hardware location type at | |
13756 | this point, because with "set breakpoint | |
13757 | auto-hw", after a re-set, locations that were | |
13758 | hardware can end up as software, or vice versa. | |
13759 | As mentioned above, this is an heuristic and in | |
13760 | practice should give the correct answer often | |
13761 | enough. */ | |
13762 | if (breakpoint_locations_match (e, l, true)) | |
13763 | { | |
b5fa468f TBA |
13764 | l->enabled = e->enabled; |
13765 | l->disabled_by_cond = e->disabled_by_cond; | |
7f32a4d5 PA |
13766 | break; |
13767 | } | |
13768 | } | |
776592bf DE |
13769 | } |
13770 | else | |
13771 | { | |
13772 | for (; l; l = l->next) | |
13773 | if (l->function_name | |
13774 | && strcmp (e->function_name, l->function_name) == 0) | |
13775 | { | |
b5fa468f TBA |
13776 | l->enabled = e->enabled; |
13777 | l->disabled_by_cond = e->disabled_by_cond; | |
776592bf DE |
13778 | break; |
13779 | } | |
13780 | } | |
0d381245 VP |
13781 | } |
13782 | } | |
13783 | } | |
fe3f5fa8 | 13784 | |
8d3788bd | 13785 | if (!locations_are_equal (existing_locations, b->loc)) |
76727919 | 13786 | gdb::observers::breakpoint_modified.notify (b); |
fe3f5fa8 VP |
13787 | } |
13788 | ||
f00aae0f | 13789 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13790 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13791 | ||
6c5b2ebe | 13792 | static std::vector<symtab_and_line> |
f00aae0f | 13793 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13794 | struct program_space *search_pspace, int *found) |
ef23e705 | 13795 | { |
cc06b668 | 13796 | struct gdb_exception exception; |
ef23e705 | 13797 | |
983af33b | 13798 | gdb_assert (b->ops != NULL); |
ef23e705 | 13799 | |
6c5b2ebe PA |
13800 | std::vector<symtab_and_line> sals; |
13801 | ||
a70b8144 | 13802 | try |
ef23e705 | 13803 | { |
6c5b2ebe | 13804 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13805 | } |
94aeb44b | 13806 | catch (gdb_exception_error &e) |
ef23e705 TJB |
13807 | { |
13808 | int not_found_and_ok = 0; | |
492d29ea | 13809 | |
ef23e705 TJB |
13810 | /* For pending breakpoints, it's expected that parsing will |
13811 | fail until the right shared library is loaded. User has | |
13812 | already told to create pending breakpoints and don't need | |
13813 | extra messages. If breakpoint is in bp_shlib_disabled | |
13814 | state, then user already saw the message about that | |
13815 | breakpoint being disabled, and don't want to see more | |
13816 | errors. */ | |
58438ac1 | 13817 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13818 | && (b->condition_not_parsed |
13819 | || (b->loc != NULL | |
13820 | && search_pspace != NULL | |
13821 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13822 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13823 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13824 | || b->enable_state == bp_disabled)) |
13825 | not_found_and_ok = 1; | |
13826 | ||
13827 | if (!not_found_and_ok) | |
13828 | { | |
13829 | /* We surely don't want to warn about the same breakpoint | |
13830 | 10 times. One solution, implemented here, is disable | |
13831 | the breakpoint on error. Another solution would be to | |
13832 | have separate 'warning emitted' flag. Since this | |
13833 | happens only when a binary has changed, I don't know | |
13834 | which approach is better. */ | |
13835 | b->enable_state = bp_disabled; | |
eedc3f4f | 13836 | throw; |
ef23e705 | 13837 | } |
94aeb44b TT |
13838 | |
13839 | exception = std::move (e); | |
ef23e705 TJB |
13840 | } |
13841 | ||
492d29ea | 13842 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13843 | { |
6c5b2ebe PA |
13844 | for (auto &sal : sals) |
13845 | resolve_sal_pc (&sal); | |
f00aae0f | 13846 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13847 | { |
ed1d1739 KS |
13848 | char *cond_string, *extra_string; |
13849 | int thread, task; | |
ef23e705 | 13850 | |
b5fa468f TBA |
13851 | find_condition_and_thread_for_sals (sals, b->extra_string, |
13852 | &cond_string, &thread, | |
13853 | &task, &extra_string); | |
f00aae0f | 13854 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
13855 | if (cond_string) |
13856 | b->cond_string = cond_string; | |
13857 | b->thread = thread; | |
13858 | b->task = task; | |
e7e0cddf | 13859 | if (extra_string) |
f00aae0f KS |
13860 | { |
13861 | xfree (b->extra_string); | |
13862 | b->extra_string = extra_string; | |
13863 | } | |
ef23e705 TJB |
13864 | b->condition_not_parsed = 0; |
13865 | } | |
13866 | ||
983af33b | 13867 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 13868 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 13869 | |
58438ac1 TT |
13870 | *found = 1; |
13871 | } | |
13872 | else | |
13873 | *found = 0; | |
ef23e705 TJB |
13874 | |
13875 | return sals; | |
13876 | } | |
13877 | ||
348d480f PA |
13878 | /* The default re_set method, for typical hardware or software |
13879 | breakpoints. Reevaluate the breakpoint and recreate its | |
13880 | locations. */ | |
13881 | ||
13882 | static void | |
28010a5d | 13883 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 13884 | { |
c2f4122d | 13885 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 13886 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 13887 | |
6c5b2ebe PA |
13888 | int found; |
13889 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
13890 | filter_pspace, &found); | |
ef23e705 | 13891 | if (found) |
6c5b2ebe | 13892 | expanded = std::move (sals); |
ef23e705 | 13893 | |
f00aae0f | 13894 | if (b->location_range_end != NULL) |
f1310107 | 13895 | { |
6c5b2ebe PA |
13896 | std::vector<symtab_and_line> sals_end |
13897 | = location_to_sals (b, b->location_range_end.get (), | |
13898 | filter_pspace, &found); | |
f1310107 | 13899 | if (found) |
6c5b2ebe | 13900 | expanded_end = std::move (sals_end); |
f1310107 TJB |
13901 | } |
13902 | ||
c2f4122d | 13903 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
13904 | } |
13905 | ||
983af33b SDJ |
13906 | /* Default method for creating SALs from an address string. It basically |
13907 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13908 | ||
13909 | static void | |
626d2320 | 13910 | create_sals_from_location_default (struct event_location *location, |
f00aae0f KS |
13911 | struct linespec_result *canonical, |
13912 | enum bptype type_wanted) | |
983af33b | 13913 | { |
f00aae0f | 13914 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
13915 | } |
13916 | ||
13917 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13918 | function for the `create_breakpoints_sal' method of | |
13919 | breakpoint_ops. */ | |
13920 | ||
13921 | static void | |
13922 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13923 | struct linespec_result *canonical, | |
e1e01040 PA |
13924 | gdb::unique_xmalloc_ptr<char> cond_string, |
13925 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13926 | enum bptype type_wanted, |
13927 | enum bpdisp disposition, | |
13928 | int thread, | |
13929 | int task, int ignore_count, | |
13930 | const struct breakpoint_ops *ops, | |
13931 | int from_tty, int enabled, | |
44f238bb | 13932 | int internal, unsigned flags) |
983af33b | 13933 | { |
e1e01040 PA |
13934 | create_breakpoints_sal (gdbarch, canonical, |
13935 | std::move (cond_string), | |
13936 | std::move (extra_string), | |
983af33b SDJ |
13937 | type_wanted, disposition, |
13938 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13939 | enabled, internal, flags); |
983af33b SDJ |
13940 | } |
13941 | ||
13942 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 13943 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 13944 | |
6c5b2ebe | 13945 | static std::vector<symtab_and_line> |
f00aae0f | 13946 | decode_location_default (struct breakpoint *b, |
626d2320 | 13947 | struct event_location *location, |
6c5b2ebe | 13948 | struct program_space *search_pspace) |
983af33b SDJ |
13949 | { |
13950 | struct linespec_result canonical; | |
13951 | ||
c2f4122d | 13952 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
cafb3438 | 13953 | NULL, 0, &canonical, multiple_symbols_all, |
c0e8dcd8 | 13954 | b->filter.get ()); |
983af33b SDJ |
13955 | |
13956 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 13957 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 13958 | |
6c5b2ebe | 13959 | if (!canonical.lsals.empty ()) |
983af33b | 13960 | { |
6c5b2ebe PA |
13961 | const linespec_sals &lsal = canonical.lsals[0]; |
13962 | return std::move (lsal.sals); | |
983af33b | 13963 | } |
6c5b2ebe | 13964 | return {}; |
983af33b SDJ |
13965 | } |
13966 | ||
bf469271 | 13967 | /* Reset a breakpoint. */ |
c906108c | 13968 | |
bf469271 PA |
13969 | static void |
13970 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 13971 | { |
fdf44873 TT |
13972 | input_radix = b->input_radix; |
13973 | set_language (b->language); | |
c906108c | 13974 | |
348d480f | 13975 | b->ops->re_set (b); |
c906108c SS |
13976 | } |
13977 | ||
c2f4122d PA |
13978 | /* Re-set breakpoint locations for the current program space. |
13979 | Locations bound to other program spaces are left untouched. */ | |
13980 | ||
c906108c | 13981 | void |
69de3c6a | 13982 | breakpoint_re_set (void) |
c906108c | 13983 | { |
35df4500 | 13984 | struct breakpoint *b, *b_tmp; |
2a7f3dff | 13985 | |
c5aa993b | 13986 | { |
fdf44873 TT |
13987 | scoped_restore_current_language save_language; |
13988 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 13989 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 13990 | |
8e817061 JB |
13991 | /* breakpoint_re_set_one sets the current_language to the language |
13992 | of the breakpoint it is resetting (see prepare_re_set_context) | |
13993 | before re-evaluating the breakpoint's location. This change can | |
13994 | unfortunately get undone by accident if the language_mode is set | |
13995 | to auto, and we either switch frames, or more likely in this context, | |
13996 | we select the current frame. | |
13997 | ||
13998 | We prevent this by temporarily turning the language_mode to | |
13999 | language_mode_manual. We restore it once all breakpoints | |
14000 | have been reset. */ | |
14001 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); | |
14002 | language_mode = language_mode_manual; | |
14003 | ||
5ed8105e PA |
14004 | /* Note: we must not try to insert locations until after all |
14005 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14006 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14007 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 14008 | |
5ed8105e PA |
14009 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
14010 | { | |
a70b8144 | 14011 | try |
bf469271 PA |
14012 | { |
14013 | breakpoint_re_set_one (b); | |
14014 | } | |
230d2906 | 14015 | catch (const gdb_exception &ex) |
bf469271 PA |
14016 | { |
14017 | exception_fprintf (gdb_stderr, ex, | |
14018 | "Error in re-setting breakpoint %d: ", | |
14019 | b->number); | |
14020 | } | |
5ed8105e | 14021 | } |
5ed8105e PA |
14022 | |
14023 | jit_breakpoint_re_set (); | |
14024 | } | |
6c95b8df | 14025 | |
af02033e PP |
14026 | create_overlay_event_breakpoint (); |
14027 | create_longjmp_master_breakpoint (); | |
14028 | create_std_terminate_master_breakpoint (); | |
186c406b | 14029 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14030 | |
14031 | /* Now we can insert. */ | |
14032 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14033 | } |
14034 | \f | |
c906108c SS |
14035 | /* Reset the thread number of this breakpoint: |
14036 | ||
14037 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14038 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14039 | void |
fba45db2 | 14040 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14041 | { |
14042 | if (b->thread != -1) | |
14043 | { | |
00431a78 | 14044 | b->thread = inferior_thread ()->global_num; |
6c95b8df PA |
14045 | |
14046 | /* We're being called after following a fork. The new fork is | |
14047 | selected as current, and unless this was a vfork will have a | |
14048 | different program space from the original thread. Reset that | |
14049 | as well. */ | |
14050 | b->loc->pspace = current_program_space; | |
c906108c SS |
14051 | } |
14052 | } | |
14053 | ||
03ac34d5 MS |
14054 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14055 | If from_tty is nonzero, it prints a message to that effect, | |
14056 | which ends with a period (no newline). */ | |
14057 | ||
c906108c | 14058 | void |
fba45db2 | 14059 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14060 | { |
52f0bd74 | 14061 | struct breakpoint *b; |
c906108c SS |
14062 | |
14063 | if (count < 0) | |
14064 | count = 0; | |
14065 | ||
14066 | ALL_BREAKPOINTS (b) | |
14067 | if (b->number == bptnum) | |
c5aa993b | 14068 | { |
d77f58be SS |
14069 | if (is_tracepoint (b)) |
14070 | { | |
14071 | if (from_tty && count != 0) | |
14072 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14073 | bptnum); | |
14074 | return; | |
14075 | } | |
14076 | ||
c5aa993b | 14077 | b->ignore_count = count; |
221ea385 KS |
14078 | if (from_tty) |
14079 | { | |
14080 | if (count == 0) | |
3e43a32a MS |
14081 | printf_filtered (_("Will stop next time " |
14082 | "breakpoint %d is reached."), | |
221ea385 KS |
14083 | bptnum); |
14084 | else if (count == 1) | |
a3f17187 | 14085 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14086 | bptnum); |
14087 | else | |
3e43a32a MS |
14088 | printf_filtered (_("Will ignore next %d " |
14089 | "crossings of breakpoint %d."), | |
221ea385 KS |
14090 | count, bptnum); |
14091 | } | |
76727919 | 14092 | gdb::observers::breakpoint_modified.notify (b); |
c5aa993b JM |
14093 | return; |
14094 | } | |
c906108c | 14095 | |
8a3fe4f8 | 14096 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14097 | } |
14098 | ||
c906108c SS |
14099 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14100 | ||
14101 | static void | |
0b39b52e | 14102 | ignore_command (const char *args, int from_tty) |
c906108c | 14103 | { |
0b39b52e | 14104 | const char *p = args; |
52f0bd74 | 14105 | int num; |
c906108c SS |
14106 | |
14107 | if (p == 0) | |
e2e0b3e5 | 14108 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14109 | |
c906108c | 14110 | num = get_number (&p); |
5c44784c | 14111 | if (num == 0) |
8a3fe4f8 | 14112 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14113 | if (*p == 0) |
8a3fe4f8 | 14114 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14115 | |
14116 | set_ignore_count (num, | |
14117 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14118 | from_tty); | |
221ea385 KS |
14119 | if (from_tty) |
14120 | printf_filtered ("\n"); | |
c906108c SS |
14121 | } |
14122 | \f | |
d0fe4701 XR |
14123 | |
14124 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
14125 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
14126 | |
14127 | static void | |
d0fe4701 XR |
14128 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
14129 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 14130 | { |
d0fe4701 XR |
14131 | if (bp_num_range.first == 0) |
14132 | { | |
14133 | warning (_("bad breakpoint number at or near '%d'"), | |
14134 | bp_num_range.first); | |
14135 | } | |
14136 | else | |
c906108c | 14137 | { |
d0fe4701 | 14138 | struct breakpoint *b, *tmp; |
197f0a60 | 14139 | |
d0fe4701 | 14140 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 14141 | { |
d0fe4701 XR |
14142 | bool match = false; |
14143 | ||
5c44784c | 14144 | ALL_BREAKPOINTS_SAFE (b, tmp) |
d0fe4701 | 14145 | if (b->number == i) |
5c44784c | 14146 | { |
bfd28288 | 14147 | match = true; |
48649e1b | 14148 | function (b); |
11cf8741 | 14149 | break; |
5c44784c | 14150 | } |
bfd28288 | 14151 | if (!match) |
d0fe4701 | 14152 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
c5aa993b | 14153 | } |
c906108c SS |
14154 | } |
14155 | } | |
14156 | ||
d0fe4701 XR |
14157 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
14158 | ARGS. */ | |
14159 | ||
14160 | static void | |
14161 | map_breakpoint_numbers (const char *args, | |
14162 | gdb::function_view<void (breakpoint *)> function) | |
14163 | { | |
14164 | if (args == NULL || *args == '\0') | |
14165 | error_no_arg (_("one or more breakpoint numbers")); | |
14166 | ||
14167 | number_or_range_parser parser (args); | |
14168 | ||
14169 | while (!parser.finished ()) | |
14170 | { | |
14171 | int num = parser.get_number (); | |
14172 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
14173 | } | |
14174 | } | |
14175 | ||
14176 | /* Return the breakpoint location structure corresponding to the | |
14177 | BP_NUM and LOC_NUM values. */ | |
14178 | ||
0d381245 | 14179 | static struct bp_location * |
d0fe4701 | 14180 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 14181 | { |
0d381245 | 14182 | struct breakpoint *b; |
0d381245 VP |
14183 | |
14184 | ALL_BREAKPOINTS (b) | |
14185 | if (b->number == bp_num) | |
14186 | { | |
14187 | break; | |
14188 | } | |
14189 | ||
14190 | if (!b || b->number != bp_num) | |
d0fe4701 | 14191 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 14192 | |
0d381245 | 14193 | if (loc_num == 0) |
d0fe4701 | 14194 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 14195 | |
d0fe4701 XR |
14196 | int n = 0; |
14197 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
14198 | if (++n == loc_num) | |
14199 | return loc; | |
14200 | ||
14201 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
14202 | } |
14203 | ||
95e95a6d PA |
14204 | /* Modes of operation for extract_bp_num. */ |
14205 | enum class extract_bp_kind | |
14206 | { | |
14207 | /* Extracting a breakpoint number. */ | |
14208 | bp, | |
14209 | ||
14210 | /* Extracting a location number. */ | |
14211 | loc, | |
14212 | }; | |
14213 | ||
14214 | /* Extract a breakpoint or location number (as determined by KIND) | |
14215 | from the string starting at START. TRAILER is a character which | |
14216 | can be found after the number. If you don't want a trailer, use | |
14217 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
14218 | string. This always returns a positive integer. */ | |
14219 | ||
14220 | static int | |
14221 | extract_bp_num (extract_bp_kind kind, const char *start, | |
14222 | int trailer, const char **end_out = NULL) | |
14223 | { | |
14224 | const char *end = start; | |
14225 | int num = get_number_trailer (&end, trailer); | |
14226 | if (num < 0) | |
14227 | error (kind == extract_bp_kind::bp | |
14228 | ? _("Negative breakpoint number '%.*s'") | |
14229 | : _("Negative breakpoint location number '%.*s'"), | |
14230 | int (end - start), start); | |
14231 | if (num == 0) | |
14232 | error (kind == extract_bp_kind::bp | |
14233 | ? _("Bad breakpoint number '%.*s'") | |
14234 | : _("Bad breakpoint location number '%.*s'"), | |
14235 | int (end - start), start); | |
14236 | ||
14237 | if (end_out != NULL) | |
14238 | *end_out = end; | |
14239 | return num; | |
14240 | } | |
14241 | ||
14242 | /* Extract a breakpoint or location range (as determined by KIND) in | |
14243 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
14244 | representing the (inclusive) range. The returned pair's elements | |
14245 | are always positive integers. */ | |
14246 | ||
14247 | static std::pair<int, int> | |
14248 | extract_bp_or_bp_range (extract_bp_kind kind, | |
14249 | const std::string &arg, | |
14250 | std::string::size_type arg_offset) | |
14251 | { | |
14252 | std::pair<int, int> range; | |
14253 | const char *bp_loc = &arg[arg_offset]; | |
14254 | std::string::size_type dash = arg.find ('-', arg_offset); | |
14255 | if (dash != std::string::npos) | |
14256 | { | |
14257 | /* bp_loc is a range (x-z). */ | |
14258 | if (arg.length () == dash + 1) | |
14259 | error (kind == extract_bp_kind::bp | |
14260 | ? _("Bad breakpoint number at or near: '%s'") | |
14261 | : _("Bad breakpoint location number at or near: '%s'"), | |
14262 | bp_loc); | |
14263 | ||
14264 | const char *end; | |
14265 | const char *start_first = bp_loc; | |
14266 | const char *start_second = &arg[dash + 1]; | |
14267 | range.first = extract_bp_num (kind, start_first, '-'); | |
14268 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
14269 | ||
14270 | if (range.first > range.second) | |
14271 | error (kind == extract_bp_kind::bp | |
14272 | ? _("Inverted breakpoint range at '%.*s'") | |
14273 | : _("Inverted breakpoint location range at '%.*s'"), | |
14274 | int (end - start_first), start_first); | |
14275 | } | |
14276 | else | |
14277 | { | |
14278 | /* bp_loc is a single value. */ | |
14279 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
14280 | range.second = range.first; | |
14281 | } | |
14282 | return range; | |
14283 | } | |
14284 | ||
d0fe4701 XR |
14285 | /* Extract the breakpoint/location range specified by ARG. Returns |
14286 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
14287 | BP_LOC_RANGE. | |
14288 | ||
14289 | ARG may be in any of the following forms: | |
14290 | ||
14291 | x where 'x' is a breakpoint number. | |
14292 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
14293 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
14294 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
14295 | location number range. | |
14296 | */ | |
14297 | ||
cc638e86 | 14298 | static void |
d0fe4701 XR |
14299 | extract_bp_number_and_location (const std::string &arg, |
14300 | std::pair<int, int> &bp_num_range, | |
14301 | std::pair<int, int> &bp_loc_range) | |
14302 | { | |
14303 | std::string::size_type dot = arg.find ('.'); | |
14304 | ||
14305 | if (dot != std::string::npos) | |
14306 | { | |
14307 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
14308 | ||
14309 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 14310 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 14311 | |
95e95a6d PA |
14312 | bp_num_range.first |
14313 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
14314 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 14315 | |
95e95a6d PA |
14316 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
14317 | arg, dot + 1); | |
d0fe4701 XR |
14318 | } |
14319 | else | |
14320 | { | |
14321 | /* Handle x and x-y cases. */ | |
d0fe4701 | 14322 | |
95e95a6d | 14323 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
14324 | bp_loc_range.first = 0; |
14325 | bp_loc_range.second = 0; | |
14326 | } | |
d0fe4701 XR |
14327 | } |
14328 | ||
14329 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
14330 | specifies whether to enable or disable. */ | |
14331 | ||
14332 | static void | |
14333 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
14334 | { | |
14335 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
14336 | if (loc != NULL) | |
14337 | { | |
b5fa468f TBA |
14338 | if (loc->disabled_by_cond && enable) |
14339 | error (_("Breakpoint %d's condition is invalid at location %d, " | |
14340 | "cannot enable."), bp_num, loc_num); | |
14341 | ||
d0fe4701 XR |
14342 | if (loc->enabled != enable) |
14343 | { | |
14344 | loc->enabled = enable; | |
14345 | mark_breakpoint_location_modified (loc); | |
14346 | } | |
14347 | if (target_supports_enable_disable_tracepoint () | |
14348 | && current_trace_status ()->running && loc->owner | |
14349 | && is_tracepoint (loc->owner)) | |
14350 | target_disable_tracepoint (loc); | |
14351 | } | |
14352 | update_global_location_list (UGLL_DONT_INSERT); | |
d7154a8d JV |
14353 | |
14354 | gdb::observers::breakpoint_modified.notify (loc->owner); | |
d0fe4701 XR |
14355 | } |
14356 | ||
14357 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
14358 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
14359 | (inclusive) range of location numbers of that breakpoint to | |
14360 | enable/disable. ENABLE specifies whether to enable or disable the | |
14361 | location. */ | |
14362 | ||
14363 | static void | |
14364 | enable_disable_breakpoint_location_range (int bp_num, | |
14365 | std::pair<int, int> &bp_loc_range, | |
14366 | bool enable) | |
14367 | { | |
14368 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
14369 | enable_disable_bp_num_loc (bp_num, i, enable); | |
14370 | } | |
0d381245 | 14371 | |
1900040c MS |
14372 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14373 | If from_tty is nonzero, it prints a message to that effect, | |
14374 | which ends with a period (no newline). */ | |
14375 | ||
c906108c | 14376 | void |
fba45db2 | 14377 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14378 | { |
14379 | /* Never disable a watchpoint scope breakpoint; we want to | |
14380 | hit them when we leave scope so we can delete both the | |
14381 | watchpoint and its scope breakpoint at that time. */ | |
14382 | if (bpt->type == bp_watchpoint_scope) | |
14383 | return; | |
14384 | ||
b5de0fa7 | 14385 | bpt->enable_state = bp_disabled; |
c906108c | 14386 | |
b775012e LM |
14387 | /* Mark breakpoint locations modified. */ |
14388 | mark_breakpoint_modified (bpt); | |
14389 | ||
d248b706 KY |
14390 | if (target_supports_enable_disable_tracepoint () |
14391 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14392 | { | |
14393 | struct bp_location *location; | |
14394 | ||
14395 | for (location = bpt->loc; location; location = location->next) | |
14396 | target_disable_tracepoint (location); | |
14397 | } | |
14398 | ||
44702360 | 14399 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14400 | |
76727919 | 14401 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14402 | } |
14403 | ||
d0fe4701 XR |
14404 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
14405 | specified in ARGS. ARGS may be in any of the formats handled by | |
14406 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
14407 | or disable the breakpoints/locations. */ | |
14408 | ||
c906108c | 14409 | static void |
d0fe4701 | 14410 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 14411 | { |
c906108c | 14412 | if (args == 0) |
46c6471b PA |
14413 | { |
14414 | struct breakpoint *bpt; | |
14415 | ||
14416 | ALL_BREAKPOINTS (bpt) | |
14417 | if (user_breakpoint_p (bpt)) | |
d0fe4701 XR |
14418 | { |
14419 | if (enable) | |
14420 | enable_breakpoint (bpt); | |
14421 | else | |
14422 | disable_breakpoint (bpt); | |
14423 | } | |
46c6471b | 14424 | } |
9eaabc75 | 14425 | else |
0d381245 | 14426 | { |
cb791d59 | 14427 | std::string num = extract_arg (&args); |
9eaabc75 | 14428 | |
cb791d59 | 14429 | while (!num.empty ()) |
d248b706 | 14430 | { |
d0fe4701 | 14431 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 14432 | |
cc638e86 PA |
14433 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
14434 | ||
14435 | if (bp_loc_range.first == bp_loc_range.second | |
14436 | && bp_loc_range.first == 0) | |
d0fe4701 | 14437 | { |
cc638e86 PA |
14438 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
14439 | map_breakpoint_number_range (bp_num_range, | |
14440 | enable | |
14441 | ? enable_breakpoint | |
14442 | : disable_breakpoint); | |
14443 | } | |
14444 | else | |
14445 | { | |
14446 | /* Handle breakpoint ids with formats 'x.y' or | |
14447 | 'x.y-z'. */ | |
14448 | enable_disable_breakpoint_location_range | |
14449 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 14450 | } |
9eaabc75 | 14451 | num = extract_arg (&args); |
d248b706 | 14452 | } |
0d381245 | 14453 | } |
c906108c SS |
14454 | } |
14455 | ||
d0fe4701 XR |
14456 | /* The disable command disables the specified breakpoints/locations |
14457 | (or all defined breakpoints) so they're no longer effective in | |
14458 | stopping the inferior. ARGS may be in any of the forms defined in | |
14459 | extract_bp_number_and_location. */ | |
14460 | ||
14461 | static void | |
14462 | disable_command (const char *args, int from_tty) | |
14463 | { | |
14464 | enable_disable_command (args, from_tty, false); | |
14465 | } | |
14466 | ||
c906108c | 14467 | static void |
816338b5 SS |
14468 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14469 | int count) | |
c906108c | 14470 | { |
afe38095 | 14471 | int target_resources_ok; |
c906108c SS |
14472 | |
14473 | if (bpt->type == bp_hardware_breakpoint) | |
14474 | { | |
14475 | int i; | |
c5aa993b | 14476 | i = hw_breakpoint_used_count (); |
53a5351d | 14477 | target_resources_ok = |
d92524f1 | 14478 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14479 | i + 1, 0); |
c906108c | 14480 | if (target_resources_ok == 0) |
8a3fe4f8 | 14481 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14482 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14483 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14484 | } |
14485 | ||
cc60f2e3 | 14486 | if (is_watchpoint (bpt)) |
c906108c | 14487 | { |
d07205c2 | 14488 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14489 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14490 | |
a70b8144 | 14491 | try |
c906108c | 14492 | { |
3a5c3e22 PA |
14493 | struct watchpoint *w = (struct watchpoint *) bpt; |
14494 | ||
1e718ff1 TJB |
14495 | orig_enable_state = bpt->enable_state; |
14496 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14497 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14498 | } |
230d2906 | 14499 | catch (const gdb_exception &e) |
c5aa993b | 14500 | { |
1e718ff1 | 14501 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14502 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14503 | bpt->number); | |
14504 | return; | |
c5aa993b | 14505 | } |
c906108c | 14506 | } |
0101ce28 | 14507 | |
b775012e LM |
14508 | bpt->enable_state = bp_enabled; |
14509 | ||
14510 | /* Mark breakpoint locations modified. */ | |
14511 | mark_breakpoint_modified (bpt); | |
14512 | ||
d248b706 KY |
14513 | if (target_supports_enable_disable_tracepoint () |
14514 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14515 | { | |
14516 | struct bp_location *location; | |
14517 | ||
14518 | for (location = bpt->loc; location; location = location->next) | |
14519 | target_enable_tracepoint (location); | |
14520 | } | |
14521 | ||
b4c291bb | 14522 | bpt->disposition = disposition; |
816338b5 | 14523 | bpt->enable_count = count; |
44702360 | 14524 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14525 | |
76727919 | 14526 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14527 | } |
14528 | ||
fe3f5fa8 | 14529 | |
c906108c | 14530 | void |
fba45db2 | 14531 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14532 | { |
816338b5 | 14533 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14534 | } |
14535 | ||
d0fe4701 XR |
14536 | /* The enable command enables the specified breakpoints/locations (or |
14537 | all defined breakpoints) so they once again become (or continue to | |
14538 | be) effective in stopping the inferior. ARGS may be in any of the | |
14539 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 14540 | |
c906108c | 14541 | static void |
981a3fb3 | 14542 | enable_command (const char *args, int from_tty) |
c906108c | 14543 | { |
d0fe4701 | 14544 | enable_disable_command (args, from_tty, true); |
c906108c SS |
14545 | } |
14546 | ||
c906108c | 14547 | static void |
4495129a | 14548 | enable_once_command (const char *args, int from_tty) |
c906108c | 14549 | { |
48649e1b TT |
14550 | map_breakpoint_numbers |
14551 | (args, [&] (breakpoint *b) | |
14552 | { | |
14553 | iterate_over_related_breakpoints | |
14554 | (b, [&] (breakpoint *bpt) | |
14555 | { | |
14556 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14557 | }); | |
14558 | }); | |
816338b5 SS |
14559 | } |
14560 | ||
14561 | static void | |
4495129a | 14562 | enable_count_command (const char *args, int from_tty) |
816338b5 | 14563 | { |
b9d61307 SM |
14564 | int count; |
14565 | ||
14566 | if (args == NULL) | |
14567 | error_no_arg (_("hit count")); | |
14568 | ||
14569 | count = get_number (&args); | |
816338b5 | 14570 | |
48649e1b TT |
14571 | map_breakpoint_numbers |
14572 | (args, [&] (breakpoint *b) | |
14573 | { | |
14574 | iterate_over_related_breakpoints | |
14575 | (b, [&] (breakpoint *bpt) | |
14576 | { | |
14577 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14578 | }); | |
14579 | }); | |
c906108c SS |
14580 | } |
14581 | ||
c906108c | 14582 | static void |
4495129a | 14583 | enable_delete_command (const char *args, int from_tty) |
c906108c | 14584 | { |
48649e1b TT |
14585 | map_breakpoint_numbers |
14586 | (args, [&] (breakpoint *b) | |
14587 | { | |
14588 | iterate_over_related_breakpoints | |
14589 | (b, [&] (breakpoint *bpt) | |
14590 | { | |
14591 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14592 | }); | |
14593 | }); | |
c906108c SS |
14594 | } |
14595 | \f | |
1f3b5d1b PP |
14596 | /* Invalidate last known value of any hardware watchpoint if |
14597 | the memory which that value represents has been written to by | |
14598 | GDB itself. */ | |
14599 | ||
14600 | static void | |
8de0566d YQ |
14601 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14602 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14603 | const bfd_byte *data) |
14604 | { | |
14605 | struct breakpoint *bp; | |
14606 | ||
14607 | ALL_BREAKPOINTS (bp) | |
14608 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14609 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14610 | { |
3a5c3e22 | 14611 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14612 | |
850645cf | 14613 | if (wp->val_valid && wp->val != nullptr) |
3a5c3e22 PA |
14614 | { |
14615 | struct bp_location *loc; | |
14616 | ||
14617 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14618 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14619 | && loc->address + loc->length > addr | |
14620 | && addr + len > loc->address) | |
14621 | { | |
3a5c3e22 | 14622 | wp->val = NULL; |
4c1d86d9 | 14623 | wp->val_valid = false; |
3a5c3e22 PA |
14624 | } |
14625 | } | |
1f3b5d1b PP |
14626 | } |
14627 | } | |
14628 | ||
8181d85f DJ |
14629 | /* Create and insert a breakpoint for software single step. */ |
14630 | ||
14631 | void | |
6c95b8df | 14632 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 14633 | const address_space *aspace, |
4a64f543 | 14634 | CORE_ADDR next_pc) |
8181d85f | 14635 | { |
7c16b83e PA |
14636 | struct thread_info *tp = inferior_thread (); |
14637 | struct symtab_and_line sal; | |
14638 | CORE_ADDR pc = next_pc; | |
8181d85f | 14639 | |
34b7e8a6 PA |
14640 | if (tp->control.single_step_breakpoints == NULL) |
14641 | { | |
14642 | tp->control.single_step_breakpoints | |
5d5658a1 | 14643 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14644 | } |
8181d85f | 14645 | |
7c16b83e PA |
14646 | sal = find_pc_line (pc, 0); |
14647 | sal.pc = pc; | |
14648 | sal.section = find_pc_overlay (pc); | |
14649 | sal.explicit_pc = 1; | |
34b7e8a6 | 14650 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14651 | |
7c16b83e | 14652 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14653 | } |
14654 | ||
93f9a11f YQ |
14655 | /* Insert single step breakpoints according to the current state. */ |
14656 | ||
14657 | int | |
14658 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14659 | { | |
f5ea389a | 14660 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14661 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14662 | |
f5ea389a | 14663 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14664 | |
a0ff9e1a | 14665 | if (!next_pcs.empty ()) |
93f9a11f | 14666 | { |
f5ea389a | 14667 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 14668 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 14669 | |
a0ff9e1a | 14670 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14671 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14672 | ||
93f9a11f YQ |
14673 | return 1; |
14674 | } | |
14675 | else | |
14676 | return 0; | |
14677 | } | |
14678 | ||
34b7e8a6 | 14679 | /* See breakpoint.h. */ |
f02253f1 HZ |
14680 | |
14681 | int | |
7c16b83e | 14682 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 14683 | const address_space *aspace, |
7c16b83e | 14684 | CORE_ADDR pc) |
1aafd4da | 14685 | { |
7c16b83e | 14686 | struct bp_location *loc; |
1aafd4da | 14687 | |
7c16b83e PA |
14688 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14689 | if (loc->inserted | |
14690 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14691 | return 1; | |
1aafd4da | 14692 | |
7c16b83e | 14693 | return 0; |
ef370185 JB |
14694 | } |
14695 | ||
14696 | /* Check whether a software single-step breakpoint is inserted at | |
14697 | PC. */ | |
14698 | ||
14699 | int | |
accd0bcd | 14700 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
14701 | CORE_ADDR pc) |
14702 | { | |
34b7e8a6 PA |
14703 | struct breakpoint *bpt; |
14704 | ||
14705 | ALL_BREAKPOINTS (bpt) | |
14706 | { | |
14707 | if (bpt->type == bp_single_step | |
14708 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14709 | return 1; | |
14710 | } | |
14711 | return 0; | |
1aafd4da UW |
14712 | } |
14713 | ||
1042e4c0 SS |
14714 | /* Tracepoint-specific operations. */ |
14715 | ||
14716 | /* Set tracepoint count to NUM. */ | |
14717 | static void | |
14718 | set_tracepoint_count (int num) | |
14719 | { | |
14720 | tracepoint_count = num; | |
4fa62494 | 14721 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14722 | } |
14723 | ||
70221824 | 14724 | static void |
0b39b52e | 14725 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 14726 | { |
ffc2605c TT |
14727 | event_location_up location = string_to_event_location (&arg, |
14728 | current_language); | |
bac7c5cf GB |
14729 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
14730 | (location.get (), true /* is_tracepoint */); | |
55aa24fb | 14731 | |
558a9d82 | 14732 | create_breakpoint (get_current_arch (), |
ffc2605c | 14733 | location.get (), |
f00aae0f | 14734 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14735 | 0 /* tempflag */, |
14736 | bp_tracepoint /* type_wanted */, | |
14737 | 0 /* Ignore count */, | |
14738 | pending_break_support, | |
14739 | ops, | |
14740 | from_tty, | |
14741 | 1 /* enabled */, | |
14742 | 0 /* internal */, 0); | |
1042e4c0 SS |
14743 | } |
14744 | ||
70221824 | 14745 | static void |
0b39b52e | 14746 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 14747 | { |
ffc2605c TT |
14748 | event_location_up location = string_to_event_location (&arg, |
14749 | current_language); | |
558a9d82 | 14750 | create_breakpoint (get_current_arch (), |
ffc2605c | 14751 | location.get (), |
f00aae0f | 14752 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14753 | 0 /* tempflag */, |
14754 | bp_fast_tracepoint /* type_wanted */, | |
14755 | 0 /* Ignore count */, | |
14756 | pending_break_support, | |
14757 | &tracepoint_breakpoint_ops, | |
14758 | from_tty, | |
14759 | 1 /* enabled */, | |
14760 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14761 | } |
14762 | ||
14763 | /* strace command implementation. Creates a static tracepoint. */ | |
14764 | ||
70221824 | 14765 | static void |
0b39b52e | 14766 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 14767 | { |
983af33b | 14768 | struct breakpoint_ops *ops; |
ffc2605c | 14769 | event_location_up location; |
983af33b SDJ |
14770 | |
14771 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14772 | or with a normal static tracepoint. */ | |
61012eef | 14773 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14774 | { |
14775 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 14776 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
f00aae0f | 14777 | } |
983af33b | 14778 | else |
f00aae0f KS |
14779 | { |
14780 | ops = &tracepoint_breakpoint_ops; | |
14781 | location = string_to_event_location (&arg, current_language); | |
14782 | } | |
983af33b | 14783 | |
558a9d82 | 14784 | create_breakpoint (get_current_arch (), |
ffc2605c | 14785 | location.get (), |
f00aae0f | 14786 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14787 | 0 /* tempflag */, |
14788 | bp_static_tracepoint /* type_wanted */, | |
14789 | 0 /* Ignore count */, | |
14790 | pending_break_support, | |
14791 | ops, | |
14792 | from_tty, | |
14793 | 1 /* enabled */, | |
14794 | 0 /* internal */, 0); | |
7a697b8d SS |
14795 | } |
14796 | ||
409873ef SS |
14797 | /* Set up a fake reader function that gets command lines from a linked |
14798 | list that was acquired during tracepoint uploading. */ | |
14799 | ||
14800 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14801 | static int next_cmd; |
409873ef SS |
14802 | |
14803 | static char * | |
14804 | read_uploaded_action (void) | |
14805 | { | |
a18ba4e4 | 14806 | char *rslt = nullptr; |
409873ef | 14807 | |
a18ba4e4 SM |
14808 | if (next_cmd < this_utp->cmd_strings.size ()) |
14809 | { | |
67aa1f3c | 14810 | rslt = this_utp->cmd_strings[next_cmd].get (); |
a18ba4e4 SM |
14811 | next_cmd++; |
14812 | } | |
409873ef SS |
14813 | |
14814 | return rslt; | |
14815 | } | |
14816 | ||
00bf0b85 SS |
14817 | /* Given information about a tracepoint as recorded on a target (which |
14818 | can be either a live system or a trace file), attempt to create an | |
14819 | equivalent GDB tracepoint. This is not a reliable process, since | |
14820 | the target does not necessarily have all the information used when | |
14821 | the tracepoint was originally defined. */ | |
14822 | ||
d9b3f62e | 14823 | struct tracepoint * |
00bf0b85 | 14824 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14825 | { |
f2fc3015 TT |
14826 | const char *addr_str; |
14827 | char small_buf[100]; | |
d9b3f62e | 14828 | struct tracepoint *tp; |
fd9b8c24 | 14829 | |
409873ef | 14830 | if (utp->at_string) |
67aa1f3c | 14831 | addr_str = utp->at_string.get (); |
409873ef SS |
14832 | else |
14833 | { | |
14834 | /* In the absence of a source location, fall back to raw | |
14835 | address. Since there is no way to confirm that the address | |
14836 | means the same thing as when the trace was started, warn the | |
14837 | user. */ | |
3e43a32a MS |
14838 | warning (_("Uploaded tracepoint %d has no " |
14839 | "source location, using raw address"), | |
409873ef | 14840 | utp->number); |
8c042590 | 14841 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14842 | addr_str = small_buf; |
14843 | } | |
14844 | ||
14845 | /* There's not much we can do with a sequence of bytecodes. */ | |
14846 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14847 | warning (_("Uploaded tracepoint %d condition " |
14848 | "has no source form, ignoring it"), | |
409873ef | 14849 | utp->number); |
d5551862 | 14850 | |
ffc2605c TT |
14851 | event_location_up location = string_to_event_location (&addr_str, |
14852 | current_language); | |
8cdf0e15 | 14853 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14854 | location.get (), |
67aa1f3c | 14855 | utp->cond_string.get (), -1, addr_str, |
e7e0cddf | 14856 | 0 /* parse cond/thread */, |
8cdf0e15 | 14857 | 0 /* tempflag */, |
0fb4aa4b | 14858 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14859 | 0 /* Ignore count */, |
14860 | pending_break_support, | |
348d480f | 14861 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14862 | 0 /* from_tty */, |
84f4c1fe | 14863 | utp->enabled /* enabled */, |
44f238bb PA |
14864 | 0 /* internal */, |
14865 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14866 | return NULL; |
fd9b8c24 | 14867 | |
409873ef | 14868 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14869 | tp = get_tracepoint (tracepoint_count); |
14870 | gdb_assert (tp != NULL); | |
d5551862 | 14871 | |
00bf0b85 SS |
14872 | if (utp->pass > 0) |
14873 | { | |
8c042590 | 14874 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14875 | tp->number); |
00bf0b85 | 14876 | |
409873ef | 14877 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14878 | } |
14879 | ||
409873ef SS |
14880 | /* If we have uploaded versions of the original commands, set up a |
14881 | special-purpose "reader" function and call the usual command line | |
14882 | reader, then pass the result to the breakpoint command-setting | |
14883 | function. */ | |
a18ba4e4 | 14884 | if (!utp->cmd_strings.empty ()) |
00bf0b85 | 14885 | { |
12973681 | 14886 | counted_command_line cmd_list; |
00bf0b85 | 14887 | |
409873ef | 14888 | this_utp = utp; |
3149d8c1 | 14889 | next_cmd = 0; |
d5551862 | 14890 | |
60b3cef2 | 14891 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
409873ef | 14892 | |
c1fc2657 | 14893 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14894 | } |
a18ba4e4 SM |
14895 | else if (!utp->actions.empty () |
14896 | || !utp->step_actions.empty ()) | |
3e43a32a MS |
14897 | warning (_("Uploaded tracepoint %d actions " |
14898 | "have no source form, ignoring them"), | |
409873ef | 14899 | utp->number); |
00bf0b85 | 14900 | |
f196051f | 14901 | /* Copy any status information that might be available. */ |
c1fc2657 | 14902 | tp->hit_count = utp->hit_count; |
f196051f SS |
14903 | tp->traceframe_usage = utp->traceframe_usage; |
14904 | ||
00bf0b85 | 14905 | return tp; |
d9b3f62e | 14906 | } |
00bf0b85 | 14907 | |
1042e4c0 SS |
14908 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14909 | omitted. */ | |
14910 | ||
14911 | static void | |
1d12d88f | 14912 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 14913 | { |
79a45e25 | 14914 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14915 | int num_printed; |
1042e4c0 | 14916 | |
5c458ae8 | 14917 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
d77f58be SS |
14918 | |
14919 | if (num_printed == 0) | |
1042e4c0 | 14920 | { |
e5a67952 | 14921 | if (args == NULL || *args == '\0') |
112e8700 | 14922 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14923 | else |
112e8700 | 14924 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14925 | } |
ad443146 SS |
14926 | |
14927 | default_collect_info (); | |
1042e4c0 SS |
14928 | } |
14929 | ||
4a64f543 | 14930 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14931 | Not supported by all targets. */ |
14932 | static void | |
5fed81ff | 14933 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14934 | { |
14935 | enable_command (args, from_tty); | |
14936 | } | |
14937 | ||
4a64f543 | 14938 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14939 | Not supported by all targets. */ |
14940 | static void | |
5fed81ff | 14941 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14942 | { |
14943 | disable_command (args, from_tty); | |
14944 | } | |
14945 | ||
4a64f543 | 14946 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 14947 | static void |
4495129a | 14948 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 14949 | { |
35df4500 | 14950 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14951 | |
14952 | dont_repeat (); | |
14953 | ||
14954 | if (arg == 0) | |
14955 | { | |
14956 | int breaks_to_delete = 0; | |
14957 | ||
14958 | /* Delete all breakpoints if no argument. | |
dda83cd7 SM |
14959 | Do not delete internal or call-dummy breakpoints, these |
14960 | have to be deleted with an explicit breakpoint number | |
4a64f543 | 14961 | argument. */ |
1042e4c0 | 14962 | ALL_TRACEPOINTS (b) |
46c6471b | 14963 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14964 | { |
14965 | breaks_to_delete = 1; | |
14966 | break; | |
14967 | } | |
1042e4c0 SS |
14968 | |
14969 | /* Ask user only if there are some breakpoints to delete. */ | |
14970 | if (!from_tty | |
14971 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14972 | { | |
35df4500 | 14973 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14974 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14975 | delete_breakpoint (b); |
1042e4c0 SS |
14976 | } |
14977 | } | |
14978 | else | |
48649e1b | 14979 | map_breakpoint_numbers |
b926417a | 14980 | (arg, [&] (breakpoint *br) |
48649e1b | 14981 | { |
b926417a | 14982 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 14983 | }); |
1042e4c0 SS |
14984 | } |
14985 | ||
197f0a60 TT |
14986 | /* Helper function for trace_pass_command. */ |
14987 | ||
14988 | static void | |
d9b3f62e | 14989 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14990 | { |
d9b3f62e | 14991 | tp->pass_count = count; |
76727919 | 14992 | gdb::observers::breakpoint_modified.notify (tp); |
197f0a60 TT |
14993 | if (from_tty) |
14994 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 14995 | tp->number, count); |
197f0a60 TT |
14996 | } |
14997 | ||
1042e4c0 SS |
14998 | /* Set passcount for tracepoint. |
14999 | ||
15000 | First command argument is passcount, second is tracepoint number. | |
15001 | If tracepoint number omitted, apply to most recently defined. | |
15002 | Also accepts special argument "all". */ | |
15003 | ||
15004 | static void | |
0b39b52e | 15005 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 15006 | { |
d9b3f62e | 15007 | struct tracepoint *t1; |
0b39b52e | 15008 | ULONGEST count; |
1042e4c0 SS |
15009 | |
15010 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15011 | error (_("passcount command requires an " |
15012 | "argument (count + optional TP num)")); | |
1042e4c0 | 15013 | |
0b39b52e | 15014 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15015 | |
529480d0 | 15016 | args = skip_spaces (args); |
1042e4c0 SS |
15017 | if (*args && strncasecmp (args, "all", 3) == 0) |
15018 | { | |
d9b3f62e PA |
15019 | struct breakpoint *b; |
15020 | ||
1042e4c0 | 15021 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15022 | if (*args) |
15023 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15024 | |
d9b3f62e | 15025 | ALL_TRACEPOINTS (b) |
197f0a60 | 15026 | { |
d9b3f62e | 15027 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15028 | trace_pass_set_count (t1, count, from_tty); |
15029 | } | |
15030 | } | |
15031 | else if (*args == '\0') | |
1042e4c0 | 15032 | { |
5fa1d40e | 15033 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15034 | if (t1) |
197f0a60 TT |
15035 | trace_pass_set_count (t1, count, from_tty); |
15036 | } | |
15037 | else | |
15038 | { | |
bfd28288 PA |
15039 | number_or_range_parser parser (args); |
15040 | while (!parser.finished ()) | |
1042e4c0 | 15041 | { |
bfd28288 | 15042 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15043 | if (t1) |
15044 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15045 | } |
15046 | } | |
1042e4c0 SS |
15047 | } |
15048 | ||
d9b3f62e | 15049 | struct tracepoint * |
1042e4c0 SS |
15050 | get_tracepoint (int num) |
15051 | { | |
15052 | struct breakpoint *t; | |
15053 | ||
15054 | ALL_TRACEPOINTS (t) | |
15055 | if (t->number == num) | |
d9b3f62e | 15056 | return (struct tracepoint *) t; |
1042e4c0 SS |
15057 | |
15058 | return NULL; | |
15059 | } | |
15060 | ||
d5551862 SS |
15061 | /* Find the tracepoint with the given target-side number (which may be |
15062 | different from the tracepoint number after disconnecting and | |
15063 | reconnecting). */ | |
15064 | ||
d9b3f62e | 15065 | struct tracepoint * |
d5551862 SS |
15066 | get_tracepoint_by_number_on_target (int num) |
15067 | { | |
d9b3f62e | 15068 | struct breakpoint *b; |
d5551862 | 15069 | |
d9b3f62e PA |
15070 | ALL_TRACEPOINTS (b) |
15071 | { | |
15072 | struct tracepoint *t = (struct tracepoint *) b; | |
15073 | ||
15074 | if (t->number_on_target == num) | |
15075 | return t; | |
15076 | } | |
d5551862 SS |
15077 | |
15078 | return NULL; | |
15079 | } | |
15080 | ||
1042e4c0 | 15081 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15082 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15083 | If the argument is missing, the most recent tracepoint |
15084 | (tracepoint_count) is returned. */ | |
15085 | ||
d9b3f62e | 15086 | struct tracepoint * |
0b39b52e | 15087 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 15088 | number_or_range_parser *parser) |
1042e4c0 | 15089 | { |
1042e4c0 SS |
15090 | struct breakpoint *t; |
15091 | int tpnum; | |
0b39b52e | 15092 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 15093 | |
bfd28288 | 15094 | if (parser != NULL) |
197f0a60 | 15095 | { |
bfd28288 PA |
15096 | gdb_assert (!parser->finished ()); |
15097 | tpnum = parser->get_number (); | |
197f0a60 TT |
15098 | } |
15099 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15100 | tpnum = tracepoint_count; |
1042e4c0 | 15101 | else |
197f0a60 | 15102 | tpnum = get_number (arg); |
1042e4c0 SS |
15103 | |
15104 | if (tpnum <= 0) | |
15105 | { | |
15106 | if (instring && *instring) | |
15107 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15108 | instring); | |
15109 | else | |
5fa1d40e | 15110 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15111 | return NULL; |
15112 | } | |
15113 | ||
15114 | ALL_TRACEPOINTS (t) | |
15115 | if (t->number == tpnum) | |
15116 | { | |
d9b3f62e | 15117 | return (struct tracepoint *) t; |
1042e4c0 SS |
15118 | } |
15119 | ||
1042e4c0 SS |
15120 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15121 | return NULL; | |
15122 | } | |
15123 | ||
d9b3f62e PA |
15124 | void |
15125 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15126 | { | |
15127 | if (b->thread != -1) | |
15128 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15129 | ||
15130 | if (b->task != 0) | |
15131 | fprintf_unfiltered (fp, " task %d", b->task); | |
15132 | ||
15133 | fprintf_unfiltered (fp, "\n"); | |
15134 | } | |
15135 | ||
6149aea9 PA |
15136 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15137 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15138 | on each breakpoint and only include the ones for which it returns | |
f2478a7e | 15139 | true. */ |
6149aea9 | 15140 | |
1042e4c0 | 15141 | static void |
4495129a | 15142 | save_breakpoints (const char *filename, int from_tty, |
f2478a7e | 15143 | bool (*filter) (const struct breakpoint *)) |
1042e4c0 SS |
15144 | { |
15145 | struct breakpoint *tp; | |
6149aea9 | 15146 | int any = 0; |
6149aea9 | 15147 | int extra_trace_bits = 0; |
1042e4c0 | 15148 | |
6149aea9 PA |
15149 | if (filename == 0 || *filename == 0) |
15150 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15151 | |
15152 | /* See if we have anything to save. */ | |
6149aea9 | 15153 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15154 | { |
6149aea9 | 15155 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15156 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15157 | continue; |
15158 | ||
15159 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15160 | if (filter && !filter (tp)) | |
15161 | continue; | |
15162 | ||
15163 | any = 1; | |
15164 | ||
15165 | if (is_tracepoint (tp)) | |
15166 | { | |
15167 | extra_trace_bits = 1; | |
15168 | ||
15169 | /* We can stop searching. */ | |
15170 | break; | |
15171 | } | |
1042e4c0 | 15172 | } |
6149aea9 PA |
15173 | |
15174 | if (!any) | |
1042e4c0 | 15175 | { |
6149aea9 | 15176 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15177 | return; |
15178 | } | |
15179 | ||
ee0c3293 | 15180 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
15181 | |
15182 | stdio_file fp; | |
15183 | ||
ee0c3293 | 15184 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 15185 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 15186 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 15187 | |
6149aea9 | 15188 | if (extra_trace_bits) |
d7e74731 | 15189 | save_trace_state_variables (&fp); |
8bf6485c | 15190 | |
6149aea9 | 15191 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15192 | { |
6149aea9 | 15193 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15194 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15195 | continue; |
8bf6485c | 15196 | |
6149aea9 PA |
15197 | /* If we have a filter, only save the breakpoints it accepts. */ |
15198 | if (filter && !filter (tp)) | |
15199 | continue; | |
15200 | ||
d7e74731 | 15201 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15202 | |
6149aea9 PA |
15203 | /* Note, we can't rely on tp->number for anything, as we can't |
15204 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15205 | instead. */ | |
15206 | ||
15207 | if (tp->cond_string) | |
d7e74731 | 15208 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15209 | |
15210 | if (tp->ignore_count) | |
d7e74731 | 15211 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15212 | |
2d9442cc | 15213 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15214 | { |
d7e74731 | 15215 | fp.puts (" commands\n"); |
a7bdde9e | 15216 | |
d7e74731 | 15217 | current_uiout->redirect (&fp); |
a70b8144 | 15218 | try |
1042e4c0 | 15219 | { |
d1b0a7bf | 15220 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 15221 | } |
230d2906 | 15222 | catch (const gdb_exception &ex) |
492d29ea | 15223 | { |
112e8700 | 15224 | current_uiout->redirect (NULL); |
eedc3f4f | 15225 | throw; |
492d29ea | 15226 | } |
1042e4c0 | 15227 | |
112e8700 | 15228 | current_uiout->redirect (NULL); |
d7e74731 | 15229 | fp.puts (" end\n"); |
1042e4c0 | 15230 | } |
6149aea9 PA |
15231 | |
15232 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15233 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15234 | |
15235 | /* If this is a multi-location breakpoint, check if the locations | |
15236 | should be individually disabled. Watchpoint locations are | |
15237 | special, and not user visible. */ | |
15238 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15239 | { | |
15240 | struct bp_location *loc; | |
15241 | int n = 1; | |
15242 | ||
15243 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15244 | if (!loc->enabled) | |
d7e74731 | 15245 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15246 | } |
1042e4c0 | 15247 | } |
8bf6485c | 15248 | |
6149aea9 | 15249 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15250 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15251 | |
1042e4c0 | 15252 | if (from_tty) |
ee0c3293 | 15253 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15254 | } |
15255 | ||
15256 | /* The `save breakpoints' command. */ | |
15257 | ||
15258 | static void | |
4495129a | 15259 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
15260 | { |
15261 | save_breakpoints (args, from_tty, NULL); | |
15262 | } | |
15263 | ||
15264 | /* The `save tracepoints' command. */ | |
15265 | ||
15266 | static void | |
4495129a | 15267 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
15268 | { |
15269 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15270 | } |
15271 | ||
15272 | /* Create a vector of all tracepoints. */ | |
15273 | ||
f51e0e20 | 15274 | std::vector<breakpoint *> |
eeae04df | 15275 | all_tracepoints (void) |
1042e4c0 | 15276 | { |
f51e0e20 | 15277 | std::vector<breakpoint *> tp_vec; |
1042e4c0 SS |
15278 | struct breakpoint *tp; |
15279 | ||
15280 | ALL_TRACEPOINTS (tp) | |
15281 | { | |
f51e0e20 | 15282 | tp_vec.push_back (tp); |
1042e4c0 SS |
15283 | } |
15284 | ||
15285 | return tp_vec; | |
15286 | } | |
15287 | ||
c906108c | 15288 | \f |
629500fa KS |
15289 | /* This help string is used to consolidate all the help string for specifying |
15290 | locations used by several commands. */ | |
15291 | ||
15292 | #define LOCATION_HELP_STRING \ | |
15293 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15294 | source filename, function name, label name, and line number.\n\ | |
15295 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15296 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15297 | \"factorial.c:fact:the_top\".\n\ | |
15298 | \n\ | |
15299 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15300 | program. Example: To specify the fourth byte past the start function\n\ | |
15301 | \"main\", use \"*main + 4\".\n\ | |
15302 | \n\ | |
15303 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15304 | syntax to specify location parameters.\n\ | |
15305 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15306 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
15307 | -function fact -label the_top\".\n\ |
15308 | \n\ | |
15309 | By default, a specified function is matched against the program's\n\ | |
15310 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
15311 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
15312 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
15313 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
89549d7f | 15314 | specified name as a complete fully-qualified name instead." |
629500fa | 15315 | |
4a64f543 MS |
15316 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15317 | commands. It is defined as a macro to prevent duplication. | |
15318 | COMMAND should be a string constant containing the name of the | |
15319 | command. */ | |
629500fa | 15320 | |
31e2b00f | 15321 | #define BREAK_ARGS_HELP(command) \ |
733d554a TBA |
15322 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\ |
15323 | \t[-force-condition] [if CONDITION]\n\ | |
fb7b5af4 SDJ |
15324 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ |
15325 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15326 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15327 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15328 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15329 | below.\n\ | |
15330 | \n\ | |
dc10affe PA |
15331 | With no LOCATION, uses current execution address of the selected\n\ |
15332 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15333 | \n\ |
15334 | THREADNUM is the number from \"info threads\".\n\ | |
15335 | CONDITION is a boolean expression.\n\ | |
733d554a TBA |
15336 | \n\ |
15337 | With the \"-force-condition\" flag, the condition is defined even when\n\ | |
15338 | it is invalid for all current locations.\n\ | |
89549d7f | 15339 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15340 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15341 | conditions are different.\n\ | |
31e2b00f AS |
15342 | \n\ |
15343 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15344 | ||
44feb3ce TT |
15345 | /* List of subcommands for "catch". */ |
15346 | static struct cmd_list_element *catch_cmdlist; | |
15347 | ||
15348 | /* List of subcommands for "tcatch". */ | |
15349 | static struct cmd_list_element *tcatch_cmdlist; | |
15350 | ||
9ac4176b | 15351 | void |
a121b7c1 | 15352 | add_catch_command (const char *name, const char *docstring, |
eb4c3f4a | 15353 | cmd_const_sfunc_ftype *sfunc, |
625e8578 | 15354 | completer_ftype *completer, |
44feb3ce TT |
15355 | void *user_data_catch, |
15356 | void *user_data_tcatch) | |
15357 | { | |
15358 | struct cmd_list_element *command; | |
15359 | ||
0450cc4c | 15360 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15361 | &catch_cmdlist); |
15362 | set_cmd_sfunc (command, sfunc); | |
15363 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15364 | set_cmd_completer (command, completer); |
44feb3ce | 15365 | |
0450cc4c | 15366 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15367 | &tcatch_cmdlist); |
15368 | set_cmd_sfunc (command, sfunc); | |
15369 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15370 | set_cmd_completer (command, completer); |
44feb3ce TT |
15371 | } |
15372 | ||
84f4c1fe | 15373 | struct breakpoint * |
95da600f | 15374 | iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback) |
84f4c1fe | 15375 | { |
35df4500 | 15376 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15377 | |
35df4500 | 15378 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe | 15379 | { |
95da600f | 15380 | if (callback (b)) |
84f4c1fe PM |
15381 | return b; |
15382 | } | |
15383 | ||
15384 | return NULL; | |
15385 | } | |
15386 | ||
0574c78f GB |
15387 | /* Zero if any of the breakpoint's locations could be a location where |
15388 | functions have been inlined, nonzero otherwise. */ | |
15389 | ||
15390 | static int | |
15391 | is_non_inline_function (struct breakpoint *b) | |
15392 | { | |
15393 | /* The shared library event breakpoint is set on the address of a | |
15394 | non-inline function. */ | |
15395 | if (b->type == bp_shlib_event) | |
15396 | return 1; | |
15397 | ||
15398 | return 0; | |
15399 | } | |
15400 | ||
15401 | /* Nonzero if the specified PC cannot be a location where functions | |
15402 | have been inlined. */ | |
15403 | ||
15404 | int | |
accd0bcd | 15405 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
09ac7c10 | 15406 | const struct target_waitstatus *ws) |
0574c78f GB |
15407 | { |
15408 | struct breakpoint *b; | |
15409 | struct bp_location *bl; | |
15410 | ||
15411 | ALL_BREAKPOINTS (b) | |
15412 | { | |
15413 | if (!is_non_inline_function (b)) | |
15414 | continue; | |
15415 | ||
15416 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15417 | { | |
15418 | if (!bl->shlib_disabled | |
09ac7c10 | 15419 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15420 | return 1; |
15421 | } | |
15422 | } | |
15423 | ||
15424 | return 0; | |
15425 | } | |
15426 | ||
2f202fde JK |
15427 | /* Remove any references to OBJFILE which is going to be freed. */ |
15428 | ||
15429 | void | |
15430 | breakpoint_free_objfile (struct objfile *objfile) | |
15431 | { | |
15432 | struct bp_location **locp, *loc; | |
15433 | ||
15434 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15435 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15436 | loc->symtab = NULL; |
15437 | } | |
15438 | ||
2060206e PA |
15439 | void |
15440 | initialize_breakpoint_ops (void) | |
15441 | { | |
15442 | static int initialized = 0; | |
15443 | ||
15444 | struct breakpoint_ops *ops; | |
15445 | ||
15446 | if (initialized) | |
15447 | return; | |
15448 | initialized = 1; | |
15449 | ||
15450 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15451 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15452 | internal and momentary breakpoints, etc.). */ | |
15453 | ops = &bkpt_base_breakpoint_ops; | |
15454 | *ops = base_breakpoint_ops; | |
15455 | ops->re_set = bkpt_re_set; | |
15456 | ops->insert_location = bkpt_insert_location; | |
15457 | ops->remove_location = bkpt_remove_location; | |
15458 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15459 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15460 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15461 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15462 | |
15463 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15464 | ops = &bkpt_breakpoint_ops; | |
15465 | *ops = bkpt_base_breakpoint_ops; | |
15466 | ops->re_set = bkpt_re_set; | |
15467 | ops->resources_needed = bkpt_resources_needed; | |
15468 | ops->print_it = bkpt_print_it; | |
15469 | ops->print_mention = bkpt_print_mention; | |
15470 | ops->print_recreate = bkpt_print_recreate; | |
15471 | ||
15472 | /* Ranged breakpoints. */ | |
15473 | ops = &ranged_breakpoint_ops; | |
15474 | *ops = bkpt_breakpoint_ops; | |
15475 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15476 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15477 | ops->print_it = print_it_ranged_breakpoint; | |
15478 | ops->print_one = print_one_ranged_breakpoint; | |
15479 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15480 | ops->print_mention = print_mention_ranged_breakpoint; | |
15481 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15482 | ||
15483 | /* Internal breakpoints. */ | |
15484 | ops = &internal_breakpoint_ops; | |
15485 | *ops = bkpt_base_breakpoint_ops; | |
15486 | ops->re_set = internal_bkpt_re_set; | |
15487 | ops->check_status = internal_bkpt_check_status; | |
15488 | ops->print_it = internal_bkpt_print_it; | |
15489 | ops->print_mention = internal_bkpt_print_mention; | |
15490 | ||
15491 | /* Momentary breakpoints. */ | |
15492 | ops = &momentary_breakpoint_ops; | |
15493 | *ops = bkpt_base_breakpoint_ops; | |
15494 | ops->re_set = momentary_bkpt_re_set; | |
15495 | ops->check_status = momentary_bkpt_check_status; | |
15496 | ops->print_it = momentary_bkpt_print_it; | |
15497 | ops->print_mention = momentary_bkpt_print_mention; | |
15498 | ||
55aa24fb SDJ |
15499 | /* Probe breakpoints. */ |
15500 | ops = &bkpt_probe_breakpoint_ops; | |
15501 | *ops = bkpt_breakpoint_ops; | |
15502 | ops->insert_location = bkpt_probe_insert_location; | |
15503 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15504 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15505 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15506 | |
2060206e PA |
15507 | /* Watchpoints. */ |
15508 | ops = &watchpoint_breakpoint_ops; | |
15509 | *ops = base_breakpoint_ops; | |
15510 | ops->re_set = re_set_watchpoint; | |
15511 | ops->insert_location = insert_watchpoint; | |
15512 | ops->remove_location = remove_watchpoint; | |
15513 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15514 | ops->check_status = check_status_watchpoint; | |
15515 | ops->resources_needed = resources_needed_watchpoint; | |
15516 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15517 | ops->print_it = print_it_watchpoint; | |
15518 | ops->print_mention = print_mention_watchpoint; | |
15519 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15520 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15521 | |
15522 | /* Masked watchpoints. */ | |
15523 | ops = &masked_watchpoint_breakpoint_ops; | |
15524 | *ops = watchpoint_breakpoint_ops; | |
15525 | ops->insert_location = insert_masked_watchpoint; | |
15526 | ops->remove_location = remove_masked_watchpoint; | |
15527 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15528 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15529 | ops->print_it = print_it_masked_watchpoint; | |
15530 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15531 | ops->print_mention = print_mention_masked_watchpoint; | |
15532 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15533 | ||
15534 | /* Tracepoints. */ | |
15535 | ops = &tracepoint_breakpoint_ops; | |
15536 | *ops = base_breakpoint_ops; | |
15537 | ops->re_set = tracepoint_re_set; | |
15538 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15539 | ops->print_one_detail = tracepoint_print_one_detail; | |
15540 | ops->print_mention = tracepoint_print_mention; | |
15541 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15542 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15543 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15544 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15545 | |
55aa24fb SDJ |
15546 | /* Probe tracepoints. */ |
15547 | ops = &tracepoint_probe_breakpoint_ops; | |
15548 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15549 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15550 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15551 | |
983af33b SDJ |
15552 | /* Static tracepoints with marker (`-m'). */ |
15553 | ops = &strace_marker_breakpoint_ops; | |
15554 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15555 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15556 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15557 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15558 | |
15559 | /* Fork catchpoints. */ | |
15560 | ops = &catch_fork_breakpoint_ops; | |
15561 | *ops = base_breakpoint_ops; | |
15562 | ops->insert_location = insert_catch_fork; | |
15563 | ops->remove_location = remove_catch_fork; | |
15564 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15565 | ops->print_it = print_it_catch_fork; | |
15566 | ops->print_one = print_one_catch_fork; | |
15567 | ops->print_mention = print_mention_catch_fork; | |
15568 | ops->print_recreate = print_recreate_catch_fork; | |
15569 | ||
15570 | /* Vfork catchpoints. */ | |
15571 | ops = &catch_vfork_breakpoint_ops; | |
15572 | *ops = base_breakpoint_ops; | |
15573 | ops->insert_location = insert_catch_vfork; | |
15574 | ops->remove_location = remove_catch_vfork; | |
15575 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15576 | ops->print_it = print_it_catch_vfork; | |
15577 | ops->print_one = print_one_catch_vfork; | |
15578 | ops->print_mention = print_mention_catch_vfork; | |
15579 | ops->print_recreate = print_recreate_catch_vfork; | |
15580 | ||
15581 | /* Exec catchpoints. */ | |
15582 | ops = &catch_exec_breakpoint_ops; | |
15583 | *ops = base_breakpoint_ops; | |
2060206e PA |
15584 | ops->insert_location = insert_catch_exec; |
15585 | ops->remove_location = remove_catch_exec; | |
15586 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15587 | ops->print_it = print_it_catch_exec; | |
15588 | ops->print_one = print_one_catch_exec; | |
15589 | ops->print_mention = print_mention_catch_exec; | |
15590 | ops->print_recreate = print_recreate_catch_exec; | |
15591 | ||
edcc5120 TT |
15592 | /* Solib-related catchpoints. */ |
15593 | ops = &catch_solib_breakpoint_ops; | |
15594 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15595 | ops->insert_location = insert_catch_solib; |
15596 | ops->remove_location = remove_catch_solib; | |
15597 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15598 | ops->check_status = check_status_catch_solib; | |
15599 | ops->print_it = print_it_catch_solib; | |
15600 | ops->print_one = print_one_catch_solib; | |
15601 | ops->print_mention = print_mention_catch_solib; | |
15602 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15603 | |
15604 | ops = &dprintf_breakpoint_ops; | |
15605 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15606 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15607 | ops->resources_needed = bkpt_resources_needed; |
15608 | ops->print_it = bkpt_print_it; | |
15609 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15610 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15611 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15612 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15613 | } |
15614 | ||
8bfd80db YQ |
15615 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15616 | ||
15617 | static struct cmd_list_element *enablebreaklist = NULL; | |
15618 | ||
8588b356 SM |
15619 | /* See breakpoint.h. */ |
15620 | ||
15621 | cmd_list_element *commands_cmd_element = nullptr; | |
15622 | ||
6c265988 | 15623 | void _initialize_breakpoint (); |
c906108c | 15624 | void |
6c265988 | 15625 | _initialize_breakpoint () |
c906108c SS |
15626 | { |
15627 | struct cmd_list_element *c; | |
15628 | ||
2060206e PA |
15629 | initialize_breakpoint_ops (); |
15630 | ||
76727919 TT |
15631 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib); |
15632 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile); | |
15633 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change); | |
84acb35a | 15634 | |
c906108c SS |
15635 | breakpoint_chain = 0; |
15636 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15637 | before a breakpoint is set. */ | |
15638 | breakpoint_count = 0; | |
15639 | ||
1042e4c0 SS |
15640 | tracepoint_count = 0; |
15641 | ||
1bedd215 AC |
15642 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15643 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15644 | Usage is `ignore N COUNT'.")); | |
c906108c | 15645 | |
8588b356 SM |
15646 | commands_cmd_element = add_com ("commands", class_breakpoint, |
15647 | commands_command, _("\ | |
18da0c51 MG |
15648 | Set commands to be executed when the given breakpoints are hit.\n\ |
15649 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15650 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15651 | (e.g. `5-7').\n\ | |
c906108c SS |
15652 | With no argument, the targeted breakpoint is the last one set.\n\ |
15653 | The commands themselves follow starting on the next line.\n\ | |
15654 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15655 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15656 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15657 | |
b1d4d8d1 TBA |
15658 | const auto cc_opts = make_condition_command_options_def_group (nullptr); |
15659 | static std::string condition_command_help | |
15660 | = gdb::option::build_help (_("\ | |
1bedd215 | 15661 | Specify breakpoint number N to break only if COND is true.\n\ |
b1d4d8d1 | 15662 | Usage is `condition [OPTION] N COND', where N is an integer and COND\n\ |
733d554a | 15663 | is an expression to be evaluated whenever breakpoint N is reached.\n\ |
b1d4d8d1 TBA |
15664 | \n\ |
15665 | Options:\n\ | |
15666 | %OPTIONS%"), cc_opts); | |
15667 | ||
15668 | c = add_com ("condition", class_breakpoint, condition_command, | |
15669 | condition_command_help.c_str ()); | |
15670 | set_cmd_completer_handle_brkchars (c, condition_completer); | |
c906108c | 15671 | |
1bedd215 | 15672 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15673 | Set a temporary breakpoint.\n\ |
c906108c SS |
15674 | Like \"break\" except the breakpoint is only temporary,\n\ |
15675 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15676 | by using \"enable delete\" on the breakpoint number.\n\ |
15677 | \n" | |
15678 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15679 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15680 | |
1bedd215 | 15681 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15682 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15683 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15684 | some target hardware may not have this support.\n\ |
15685 | \n" | |
15686 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15687 | set_cmd_completer (c, location_completer); |
c906108c | 15688 | |
1bedd215 | 15689 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15690 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15691 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15692 | so it will be deleted when hit.\n\ |
15693 | \n" | |
15694 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15695 | set_cmd_completer (c, location_completer); |
c906108c | 15696 | |
1bedd215 | 15697 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
590042fc PW |
15698 | Enable all or some breakpoints.\n\ |
15699 | Usage: enable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15700 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15701 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15702 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15703 | With a subcommand you can enable temporarily."), |
c906108c | 15704 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15705 | |
15706 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15707 | ||
84951ab5 | 15708 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
590042fc PW |
15709 | Enable all or some breakpoints.\n\ |
15710 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15711 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15712 | This is used to cancel the effect of the \"disable\" command.\n\ | |
89549d7f | 15713 | May be abbreviated to simply \"enable\"."), |
c5aa993b | 15714 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15715 | |
1a966eab | 15716 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15717 | Enable some breakpoints for one hit.\n\ |
15718 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ | |
1a966eab | 15719 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
c906108c SS |
15720 | &enablebreaklist); |
15721 | ||
1a966eab | 15722 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15723 | Enable some breakpoints and delete when hit.\n\ |
15724 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ | |
1a966eab | 15725 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15726 | &enablebreaklist); |
15727 | ||
816338b5 | 15728 | add_cmd ("count", no_class, enable_count_command, _("\ |
590042fc PW |
15729 | Enable some breakpoints for COUNT hits.\n\ |
15730 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15731 | If a breakpoint is hit while enabled in this fashion,\n\ |
15732 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15733 | &enablebreaklist); | |
15734 | ||
1a966eab | 15735 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15736 | Enable some breakpoints and delete when hit.\n\ |
15737 | Usage: enable delete BREAKPOINTNUM...\n\ | |
1a966eab | 15738 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15739 | &enablelist); |
15740 | ||
1a966eab | 15741 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15742 | Enable some breakpoints for one hit.\n\ |
15743 | Usage: enable once BREAKPOINTNUM...\n\ | |
1a966eab | 15744 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
816338b5 SS |
15745 | &enablelist); |
15746 | ||
15747 | add_cmd ("count", no_class, enable_count_command, _("\ | |
590042fc PW |
15748 | Enable some breakpoints for COUNT hits.\n\ |
15749 | Usage: enable count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15750 | If a breakpoint is hit while enabled in this fashion,\n\ |
15751 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15752 | &enablelist); |
15753 | ||
1bedd215 | 15754 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
590042fc PW |
15755 | Disable all or some breakpoints.\n\ |
15756 | Usage: disable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15757 | Arguments are breakpoint numbers with spaces in between.\n\ |
15758 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15759 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15760 | &disablelist, "disable ", 1, &cmdlist); |
15761 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15762 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15763 | |
57b4f16e | 15764 | add_cmd ("breakpoints", class_breakpoint, disable_command, _("\ |
590042fc PW |
15765 | Disable all or some breakpoints.\n\ |
15766 | Usage: disable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15767 | Arguments are breakpoint numbers with spaces in between.\n\ |
15768 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15769 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15770 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15771 | &disablelist); |
15772 | ||
1bedd215 | 15773 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
590042fc PW |
15774 | Delete all or some breakpoints.\n\ |
15775 | Usage: delete [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15776 | Arguments are breakpoint numbers with spaces in between.\n\ |
15777 | To delete all breakpoints, give no argument.\n\ | |
15778 | \n\ | |
590042fc | 15779 | Also a prefix command for deletion of other GDB objects."), |
c906108c SS |
15780 | &deletelist, "delete ", 1, &cmdlist); |
15781 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15782 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15783 | |
57b4f16e | 15784 | add_cmd ("breakpoints", class_breakpoint, delete_command, _("\ |
590042fc PW |
15785 | Delete all or some breakpoints or auto-display expressions.\n\ |
15786 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15787 | Arguments are breakpoint numbers with spaces in between.\n\ |
15788 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15789 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15790 | &deletelist); |
15791 | ||
1bedd215 | 15792 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15793 | Clear breakpoint at specified location.\n\ |
15794 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15795 | \n\ |
15796 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa | 15797 | is executing in.\n" |
89549d7f | 15798 | "\n" LOCATION_HELP_STRING "\n\n\ |
1bedd215 | 15799 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15800 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15801 | |
1bedd215 | 15802 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15803 | Set breakpoint at specified location.\n" |
31e2b00f | 15804 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15805 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15806 | |
c906108c SS |
15807 | add_com_alias ("b", "break", class_run, 1); |
15808 | add_com_alias ("br", "break", class_run, 1); | |
15809 | add_com_alias ("bre", "break", class_run, 1); | |
15810 | add_com_alias ("brea", "break", class_run, 1); | |
15811 | ||
c906108c SS |
15812 | if (dbx_commands) |
15813 | { | |
1bedd215 AC |
15814 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15815 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15816 | &stoplist, "stop ", 1, &cmdlist); |
15817 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15818 | _("Break in function or address."), &stoplist); |
c5aa993b | 15819 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15820 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15821 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15822 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15823 | The \"Type\" column indicates one of:\n\ |
15824 | \tbreakpoint - normal breakpoint\n\ | |
15825 | \twatchpoint - watchpoint\n\ | |
15826 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15827 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15828 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15829 | address and file/line number respectively.\n\ |
15830 | \n\ | |
15831 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15832 | are set to the address of the last breakpoint listed unless the command\n\ |
15833 | is prefixed with \"server \".\n\n\ | |
c906108c | 15834 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15835 | breakpoint set.")); |
c906108c SS |
15836 | } |
15837 | ||
11db9430 | 15838 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15839 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15840 | The \"Type\" column indicates one of:\n\ |
15841 | \tbreakpoint - normal breakpoint\n\ | |
15842 | \twatchpoint - watchpoint\n\ | |
15843 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15844 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15845 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15846 | address and file/line number respectively.\n\ |
15847 | \n\ | |
15848 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15849 | are set to the address of the last breakpoint listed unless the command\n\ |
15850 | is prefixed with \"server \".\n\n\ | |
c906108c | 15851 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15852 | breakpoint set.")); |
c906108c | 15853 | |
6b04bdb7 MS |
15854 | add_info_alias ("b", "breakpoints", 1); |
15855 | ||
1a966eab AC |
15856 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15857 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15858 | The \"Type\" column indicates one of:\n\ |
15859 | \tbreakpoint - normal breakpoint\n\ | |
15860 | \twatchpoint - watchpoint\n\ | |
15861 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15862 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15863 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15864 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15865 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15866 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15867 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15868 | address and file/line number respectively.\n\ |
15869 | \n\ | |
15870 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15871 | are set to the address of the last breakpoint listed unless the command\n\ |
15872 | is prefixed with \"server \".\n\n\ | |
c906108c | 15873 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15874 | breakpoint set."), |
c906108c SS |
15875 | &maintenanceinfolist); |
15876 | ||
3b6acaee | 15877 | add_basic_prefix_cmd ("catch", class_breakpoint, _("\ |
44feb3ce | 15878 | Set catchpoints to catch events."), |
3b6acaee TT |
15879 | &catch_cmdlist, "catch ", |
15880 | 0/*allow-unknown*/, &cmdlist); | |
44feb3ce | 15881 | |
3b6acaee | 15882 | add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\ |
44feb3ce | 15883 | Set temporary catchpoints to catch events."), |
3b6acaee TT |
15884 | &tcatch_cmdlist, "tcatch ", |
15885 | 0/*allow-unknown*/, &cmdlist); | |
44feb3ce | 15886 | |
44feb3ce TT |
15887 | add_catch_command ("fork", _("Catch calls to fork."), |
15888 | catch_fork_command_1, | |
dda83cd7 | 15889 | NULL, |
44feb3ce TT |
15890 | (void *) (uintptr_t) catch_fork_permanent, |
15891 | (void *) (uintptr_t) catch_fork_temporary); | |
15892 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15893 | catch_fork_command_1, | |
dda83cd7 | 15894 | NULL, |
44feb3ce TT |
15895 | (void *) (uintptr_t) catch_vfork_permanent, |
15896 | (void *) (uintptr_t) catch_vfork_temporary); | |
15897 | add_catch_command ("exec", _("Catch calls to exec."), | |
15898 | catch_exec_command_1, | |
dda83cd7 | 15899 | NULL, |
a96d9b2e SDJ |
15900 | CATCH_PERMANENT, |
15901 | CATCH_TEMPORARY); | |
edcc5120 TT |
15902 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15903 | Usage: catch load [REGEX]\n\ | |
15904 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15905 | catch_load_command_1, | |
15906 | NULL, | |
15907 | CATCH_PERMANENT, | |
15908 | CATCH_TEMPORARY); | |
15909 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15910 | Usage: catch unload [REGEX]\n\ | |
15911 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15912 | catch_unload_command_1, | |
15913 | NULL, | |
15914 | CATCH_PERMANENT, | |
15915 | CATCH_TEMPORARY); | |
c5aa993b | 15916 | |
1bedd215 AC |
15917 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15918 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15919 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15920 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15921 | an expression changes.\n\ |
15922 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15923 | the memory to which it refers.")); | |
65d12d83 | 15924 | set_cmd_completer (c, expression_completer); |
c906108c | 15925 | |
1bedd215 AC |
15926 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15927 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15928 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15929 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15930 | an expression is read.\n\ |
15931 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15932 | the memory to which it refers.")); | |
65d12d83 | 15933 | set_cmd_completer (c, expression_completer); |
c906108c | 15934 | |
1bedd215 AC |
15935 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15936 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15937 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15938 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15939 | an expression is either read or written.\n\ |
15940 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15941 | the memory to which it refers.")); | |
65d12d83 | 15942 | set_cmd_completer (c, expression_completer); |
c906108c | 15943 | |
11db9430 | 15944 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15945 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15946 | |
920d2a44 AC |
15947 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15948 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15949 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15950 | &can_use_hw_watchpoints, _("\ | |
15951 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15952 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15953 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15954 | such is available. (However, any hardware watchpoints that were\n\ | |
15955 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15956 | hardware.)"), |
15957 | NULL, | |
920d2a44 | 15958 | show_can_use_hw_watchpoints, |
85c07804 | 15959 | &setlist, &showlist); |
c906108c SS |
15960 | |
15961 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15962 | |
1042e4c0 SS |
15963 | /* Tracepoint manipulation commands. */ |
15964 | ||
15965 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 15966 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
15967 | \n" |
15968 | BREAK_ARGS_HELP ("trace") "\n\ | |
15969 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15970 | set_cmd_completer (c, location_completer); | |
15971 | ||
57b4f16e PW |
15972 | add_com_alias ("tp", "trace", class_breakpoint, 0); |
15973 | add_com_alias ("tr", "trace", class_breakpoint, 1); | |
15974 | add_com_alias ("tra", "trace", class_breakpoint, 1); | |
15975 | add_com_alias ("trac", "trace", class_breakpoint, 1); | |
1042e4c0 | 15976 | |
7a697b8d | 15977 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 15978 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
15979 | \n" |
15980 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15981 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15982 | set_cmd_completer (c, location_completer); | |
15983 | ||
0fb4aa4b | 15984 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 15985 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
15986 | \n\ |
15987 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
15988 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
15989 | or -m MARKER_ID.\n\n\ | |
15990 | If a marker id is specified, probe the marker with that name. With\n\ | |
15991 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
15992 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
15993 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15994 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15995 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15996 | \n\ | |
15997 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15998 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15999 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16000 | conditions are different.\n\ | |
0fb4aa4b PA |
16001 | \n\ |
16002 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16003 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16004 | set_cmd_completer (c, location_completer); | |
16005 | ||
11db9430 | 16006 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 16007 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16008 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16009 | last tracepoint set.")); | |
16010 | ||
16011 | add_info_alias ("tp", "tracepoints", 1); | |
16012 | ||
16013 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16014 | Delete specified tracepoints.\n\ | |
16015 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16016 | No argument means delete all tracepoints."), | |
16017 | &deletelist); | |
7e20dfcd | 16018 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16019 | |
16020 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16021 | Disable specified tracepoints.\n\ | |
16022 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16023 | No argument means disable all tracepoints."), | |
16024 | &disablelist); | |
16025 | deprecate_cmd (c, "disable"); | |
16026 | ||
16027 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16028 | Enable specified tracepoints.\n\ | |
16029 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16030 | No argument means enable all tracepoints."), | |
16031 | &enablelist); | |
16032 | deprecate_cmd (c, "enable"); | |
16033 | ||
16034 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16035 | Set the passcount for a tracepoint.\n\ | |
16036 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16037 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16038 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16039 | ||
0743fc83 TT |
16040 | add_basic_prefix_cmd ("save", class_breakpoint, |
16041 | _("Save breakpoint definitions as a script."), | |
16042 | &save_cmdlist, "save ", | |
16043 | 0/*allow-unknown*/, &cmdlist); | |
6149aea9 PA |
16044 | |
16045 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16046 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16047 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16048 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16049 | session to restore them."), | |
16050 | &save_cmdlist); | |
16051 | set_cmd_completer (c, filename_completer); | |
16052 | ||
16053 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16054 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16055 | Use the 'source' command in another debug session to restore them."), |
16056 | &save_cmdlist); | |
1042e4c0 SS |
16057 | set_cmd_completer (c, filename_completer); |
16058 | ||
6149aea9 PA |
16059 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16060 | deprecate_cmd (c, "save tracepoints"); | |
16061 | ||
3b6acaee | 16062 | add_basic_prefix_cmd ("breakpoint", class_maintenance, _("\ |
590042fc | 16063 | Breakpoint specific settings.\n\ |
fa8d40ab | 16064 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 16065 | pending breakpoint behavior."), |
3b6acaee TT |
16066 | &breakpoint_set_cmdlist, "set breakpoint ", |
16067 | 0/*allow-unknown*/, &setlist); | |
16068 | add_show_prefix_cmd ("breakpoint", class_maintenance, _("\ | |
590042fc | 16069 | Breakpoint specific settings.\n\ |
fa8d40ab | 16070 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 16071 | pending breakpoint behavior."), |
3b6acaee TT |
16072 | &breakpoint_show_cmdlist, "show breakpoint ", |
16073 | 0/*allow-unknown*/, &showlist); | |
fa8d40ab | 16074 | |
7915a72c AC |
16075 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16076 | &pending_break_support, _("\ | |
16077 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16078 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16079 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16080 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16081 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16082 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16083 | NULL, |
920d2a44 | 16084 | show_pending_break_support, |
6e1d7d6c AC |
16085 | &breakpoint_set_cmdlist, |
16086 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16087 | |
16088 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16089 | |
16090 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16091 | &automatic_hardware_breakpoints, _("\ | |
16092 | Set automatic usage of hardware breakpoints."), _("\ | |
16093 | Show automatic usage of hardware breakpoints."), _("\ | |
16094 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16095 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16096 | a warning will be emitted for such breakpoints."), | |
16097 | NULL, | |
16098 | show_automatic_hardware_breakpoints, | |
16099 | &breakpoint_set_cmdlist, | |
16100 | &breakpoint_show_cmdlist); | |
74960c60 | 16101 | |
a25a5a45 PA |
16102 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16103 | &always_inserted_mode, _("\ | |
74960c60 VP |
16104 | Set mode for inserting breakpoints."), _("\ |
16105 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16106 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16107 | they're created, kept inserted even when execution stops, and removed\n\ | |
16108 | only when the user deletes them. When this mode is off (the default),\n\ | |
16109 | breakpoints are inserted only when execution continues, and removed\n\ | |
16110 | when execution stops."), | |
72d0e2c5 YQ |
16111 | NULL, |
16112 | &show_always_inserted_mode, | |
16113 | &breakpoint_set_cmdlist, | |
16114 | &breakpoint_show_cmdlist); | |
f1310107 | 16115 | |
b775012e LM |
16116 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16117 | condition_evaluation_enums, | |
16118 | &condition_evaluation_mode_1, _("\ | |
16119 | Set mode of breakpoint condition evaluation."), _("\ | |
16120 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16121 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16122 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16123 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16124 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16125 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16126 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
7a4e8e7d | 16127 | be set to \"host\"."), |
b775012e LM |
16128 | &set_condition_evaluation_mode, |
16129 | &show_condition_evaluation_mode, | |
16130 | &breakpoint_set_cmdlist, | |
16131 | &breakpoint_show_cmdlist); | |
16132 | ||
f1310107 TJB |
16133 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16134 | Set a breakpoint for an address range.\n\ | |
16135 | break-range START-LOCATION, END-LOCATION\n\ | |
16136 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16137 | LINENUM, for that line in the current file,\n\ | |
16138 | FILE:LINENUM, for that line in that file,\n\ | |
16139 | +OFFSET, for that number of lines after the current line\n\ | |
dda83cd7 | 16140 | or the start of the range\n\ |
f1310107 TJB |
16141 | FUNCTION, for the first line in that function,\n\ |
16142 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16143 | *ADDRESS, for the instruction at that address.\n\ | |
16144 | \n\ | |
16145 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16146 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16147 | range (including START-LOCATION and END-LOCATION).")); | |
16148 | ||
e7e0cddf | 16149 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16150 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16151 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16152 | location may be a linespec, explicit, or address location.\n" |
16153 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16154 | set_cmd_completer (c, location_completer); |
16155 | ||
16156 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16157 | dprintf_style_enums, &dprintf_style, _("\ | |
16158 | Set the style of usage for dynamic printf."), _("\ | |
16159 | Show the style of usage for dynamic printf."), _("\ | |
16160 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16161 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16162 | console, as with the \"printf\" command.\n\ | |
16163 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16164 | program; by default printf(), but you can choose a different function or\n\ | |
16165 | output stream by setting dprintf-function and dprintf-channel."), | |
16166 | update_dprintf_commands, NULL, | |
16167 | &setlist, &showlist); | |
16168 | ||
16169 | dprintf_function = xstrdup ("printf"); | |
16170 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16171 | &dprintf_function, _("\ | |
590042fc PW |
16172 | Set the function to use for dynamic printf."), _("\ |
16173 | Show the function to use for dynamic printf."), NULL, | |
e7e0cddf SS |
16174 | update_dprintf_commands, NULL, |
16175 | &setlist, &showlist); | |
16176 | ||
16177 | dprintf_channel = xstrdup (""); | |
16178 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16179 | &dprintf_channel, _("\ | |
590042fc PW |
16180 | Set the channel to use for dynamic printf."), _("\ |
16181 | Show the channel to use for dynamic printf."), NULL, | |
e7e0cddf SS |
16182 | update_dprintf_commands, NULL, |
16183 | &setlist, &showlist); | |
16184 | ||
d3ce09f5 SS |
16185 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16186 | &disconnected_dprintf, _("\ | |
16187 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16188 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16189 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16190 | even if GDB disconnects or detaches from the target."), | |
16191 | NULL, | |
16192 | NULL, | |
16193 | &setlist, &showlist); | |
16194 | ||
16195 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
590042fc PW |
16196 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
16197 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ | |
16198 | This supports most C printf format specifications, like %s, %d, etc.\n\ | |
16199 | This is useful for formatted output in user-defined commands.")); | |
d3ce09f5 | 16200 | |
491144b5 | 16201 | automatic_hardware_breakpoints = true; |
f3b1572e | 16202 | |
76727919 TT |
16203 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed); |
16204 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints); | |
c906108c | 16205 | } |